Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 2 | * This file is part of the zfcp device driver for |
| 3 | * FCP adapters for IBM System z9 and zSeries. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 5 | * (C) Copyright IBM Corp. 2002, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "zfcp_ext.h" |
| 23 | |
| 24 | static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *); |
| 25 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *); |
| 26 | static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *); |
| 27 | static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *); |
| 28 | static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *); |
| 29 | static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *); |
| 30 | static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *); |
| 31 | static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *); |
| 32 | static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *); |
| 33 | static int zfcp_fsf_send_fcp_command_task_management_handler( |
| 34 | struct zfcp_fsf_req *); |
| 35 | static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *); |
| 36 | static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *); |
| 37 | static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *); |
| 38 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *); |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 39 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static inline int zfcp_fsf_req_sbal_check( |
| 41 | unsigned long *, struct zfcp_qdio_queue *, int); |
| 42 | static inline int zfcp_use_one_sbal( |
| 43 | struct scatterlist *, int, struct scatterlist *, int); |
| 44 | static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 45 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *); |
| 47 | static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *); |
| 48 | static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 49 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 50 | struct fsf_link_down_info *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* association between FSF command and FSF QTCB type */ |
| 54 | static u32 fsf_qtcb_type[] = { |
| 55 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, |
| 56 | [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND, |
| 57 | [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND, |
| 58 | [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND, |
| 59 | [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND, |
| 60 | [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND, |
| 61 | [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND, |
| 62 | [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND, |
| 63 | [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND, |
| 64 | [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND, |
| 65 | [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND, |
| 66 | [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND, |
| 67 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND |
| 68 | }; |
| 69 | |
| 70 | static const char zfcp_act_subtable_type[5][8] = { |
| 71 | "unknown", "OS", "WWPN", "DID", "LUN" |
| 72 | }; |
| 73 | |
| 74 | /****************************************************************/ |
| 75 | /*************** FSF related Functions *************************/ |
| 76 | /****************************************************************/ |
| 77 | |
| 78 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF |
| 79 | |
| 80 | /* |
| 81 | * function: zfcp_fsf_req_alloc |
| 82 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 83 | * purpose: Obtains an fsf_req and potentially a qtcb (for all but |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * unsolicited requests) via helper functions |
| 85 | * Does some initial fsf request set-up. |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 86 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * returns: pointer to allocated fsf_req if successfull |
| 88 | * NULL otherwise |
| 89 | * |
| 90 | * locks: none |
| 91 | * |
| 92 | */ |
| 93 | static struct zfcp_fsf_req * |
| 94 | zfcp_fsf_req_alloc(mempool_t *pool, int req_flags) |
| 95 | { |
| 96 | size_t size; |
| 97 | void *ptr; |
| 98 | struct zfcp_fsf_req *fsf_req = NULL; |
| 99 | |
| 100 | if (req_flags & ZFCP_REQ_NO_QTCB) |
| 101 | size = sizeof(struct zfcp_fsf_req); |
| 102 | else |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 103 | size = sizeof(struct zfcp_fsf_req_qtcb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 105 | if (likely(pool)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | ptr = mempool_alloc(pool, GFP_ATOMIC); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 107 | else { |
| 108 | if (req_flags & ZFCP_REQ_NO_QTCB) |
| 109 | ptr = kmalloc(size, GFP_ATOMIC); |
| 110 | else |
| 111 | ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache, |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 112 | GFP_ATOMIC); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 115 | if (unlikely(!ptr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | goto out; |
| 117 | |
| 118 | memset(ptr, 0, size); |
| 119 | |
| 120 | if (req_flags & ZFCP_REQ_NO_QTCB) { |
| 121 | fsf_req = (struct zfcp_fsf_req *) ptr; |
| 122 | } else { |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 123 | fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req; |
| 124 | fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | fsf_req->pool = pool; |
| 128 | |
| 129 | out: |
| 130 | return fsf_req; |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * function: zfcp_fsf_req_free |
| 135 | * |
| 136 | * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or |
| 137 | * returns it into the pool via helper functions. |
| 138 | * |
| 139 | * returns: sod all |
| 140 | * |
| 141 | * locks: none |
| 142 | */ |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 143 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req) |
| 145 | { |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 146 | if (likely(fsf_req->pool)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | mempool_free(fsf_req, fsf_req->pool); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | |
| 151 | if (fsf_req->qtcb) { |
| 152 | kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | kfree(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 159 | /* |
| 160 | * Never ever call this without shutting down the adapter first. |
| 161 | * Otherwise the adapter would continue using and corrupting s390 storage. |
| 162 | * Included BUG_ON() call to ensure this is done. |
| 163 | * ERP is supposed to be the only user of this function. |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 164 | */ |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 165 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 166 | { |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 167 | struct zfcp_fsf_req *fsf_req, *tmp; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 168 | unsigned long flags; |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 169 | LIST_HEAD(remove_queue); |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 170 | unsigned int i; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 171 | |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 172 | BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 173 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 174 | for (i = 0; i < REQUEST_LIST_SIZE; i++) |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 175 | list_splice_init(&adapter->req_list[i], &remove_queue); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 176 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); |
| 177 | |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 178 | list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) { |
| 179 | list_del(&fsf_req->list); |
| 180 | fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
| 181 | zfcp_fsf_req_complete(fsf_req); |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 182 | } |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* |
| 186 | * function: zfcp_fsf_req_complete |
| 187 | * |
| 188 | * purpose: Updates active counts and timers for openfcp-reqs |
| 189 | * May cleanup request after req_eval returns |
| 190 | * |
| 191 | * returns: 0 - success |
| 192 | * !0 - failure |
| 193 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 194 | * context: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | */ |
| 196 | int |
| 197 | zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req) |
| 198 | { |
| 199 | int retval = 0; |
| 200 | int cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { |
| 203 | ZFCP_LOG_DEBUG("Status read response received\n"); |
| 204 | /* |
| 205 | * Note: all cleanup handling is done in the callchain of |
| 206 | * the function call-chain below. |
| 207 | */ |
| 208 | zfcp_fsf_status_read_handler(fsf_req); |
| 209 | goto out; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 210 | } else { |
| 211 | del_timer(&fsf_req->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | zfcp_fsf_protstatus_eval(fsf_req); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 216 | * fsf_req may be deleted due to waking up functions, so |
| 217 | * cleanup is saved here and used later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | */ |
| 219 | if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) |
| 220 | cleanup = 1; |
| 221 | else |
| 222 | cleanup = 0; |
| 223 | |
| 224 | fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED; |
| 225 | |
| 226 | /* cleanup request if requested by initiator */ |
| 227 | if (likely(cleanup)) { |
| 228 | ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req); |
| 229 | /* |
| 230 | * lock must not be held here since it will be |
| 231 | * grabed by the called routine, too |
| 232 | */ |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 233 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } else { |
| 235 | /* notify initiator waiting for the requests completion */ |
| 236 | ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req); |
| 237 | /* |
| 238 | * FIXME: Race! We must not access fsf_req here as it might have been |
| 239 | * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED |
| 240 | * flag. It's an improbable case. But, we have the same paranoia for |
| 241 | * the cleanup flag already. |
| 242 | * Might better be handled using complete()? |
| 243 | * (setting the flag and doing wakeup ought to be atomic |
| 244 | * with regard to checking the flag as long as waitqueue is |
| 245 | * part of the to be released structure) |
| 246 | */ |
| 247 | wake_up(&fsf_req->completion_wq); |
| 248 | } |
| 249 | |
| 250 | out: |
| 251 | return retval; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * function: zfcp_fsf_protstatus_eval |
| 256 | * |
| 257 | * purpose: evaluates the QTCB of the finished FSF request |
| 258 | * and initiates appropriate actions |
| 259 | * (usually calling FSF command specific handlers) |
| 260 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 261 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 263 | * context: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | * |
| 265 | * locks: |
| 266 | */ |
| 267 | static int |
| 268 | zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req) |
| 269 | { |
| 270 | int retval = 0; |
| 271 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 272 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
| 273 | union fsf_prot_status_qual *prot_status_qual = |
| 274 | &qtcb->prefix.prot_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 276 | zfcp_hba_dbf_event_fsf_response(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
| 279 | ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n", |
| 280 | (unsigned long) fsf_req); |
| 281 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 282 | ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | goto skip_protstatus; |
| 284 | } |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /* evaluate FSF Protocol Status */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 287 | switch (qtcb->prefix.prot_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | case FSF_PROT_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | case FSF_PROT_FSF_STATUS_PRESENTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | break; |
| 292 | |
| 293 | case FSF_PROT_QTCB_VERSION_ERROR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | ZFCP_LOG_NORMAL("error: The adapter %s contains " |
| 295 | "microcode of version 0x%x, the device driver " |
| 296 | "only supports 0x%x. Aborting.\n", |
| 297 | zfcp_get_busid_by_adapter(adapter), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 298 | prot_status_qual->version_error.fsf_version, |
| 299 | ZFCP_QTCB_VERSION); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 300 | zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 302 | break; |
| 303 | |
| 304 | case FSF_PROT_SEQ_NUMB_ERROR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | ZFCP_LOG_NORMAL("bug: Sequence number mismatch between " |
| 306 | "driver (0x%x) and adapter %s (0x%x). " |
| 307 | "Restarting all operations on this adapter.\n", |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 308 | qtcb->prefix.req_seq_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | zfcp_get_busid_by_adapter(adapter), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 310 | prot_status_qual->sequence_error.exp_req_seq_no); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 311 | zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; |
| 313 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 314 | break; |
| 315 | |
| 316 | case FSF_PROT_UNSUPP_QTCB_TYPE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | ZFCP_LOG_NORMAL("error: Packet header type used by the " |
| 318 | "device driver is incompatible with " |
| 319 | "that used on adapter %s. " |
| 320 | "Stopping all operations on this adapter.\n", |
| 321 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 322 | zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 324 | break; |
| 325 | |
| 326 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 328 | atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 329 | &(adapter->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | break; |
| 331 | |
| 332 | case FSF_PROT_DUPLICATE_REQUEST_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx " |
| 334 | "to the adapter %s is ambiguous. " |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 335 | "Stopping all operations on this adapter.\n", |
| 336 | *(unsigned long long*) |
| 337 | (&qtcb->bottom.support.req_handle), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 339 | zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 341 | break; |
| 342 | |
| 343 | case FSF_PROT_LINK_DOWN: |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 344 | zfcp_fsf_link_down_info_eval(fsf_req, 37, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 345 | &prot_status_qual->link_down_info); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 346 | /* FIXME: reopening adapter now? better wait for link up */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 347 | zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 349 | break; |
| 350 | |
| 351 | case FSF_PROT_REEST_QUEUE: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 352 | ZFCP_LOG_NORMAL("The local link to adapter with " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | "%s was re-plugged. " |
| 354 | "Re-starting operations on this adapter.\n", |
| 355 | zfcp_get_busid_by_adapter(adapter)); |
| 356 | /* All ports should be marked as ready to run again */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 357 | zfcp_erp_modify_adapter_status(adapter, 28, NULL, |
| 358 | ZFCP_STATUS_COMMON_RUNNING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | ZFCP_SET); |
| 360 | zfcp_erp_adapter_reopen(adapter, |
| 361 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 362 | | ZFCP_STATUS_COMMON_ERP_FAILED, |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 363 | 99, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 365 | break; |
| 366 | |
| 367 | case FSF_PROT_ERROR_STATE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | ZFCP_LOG_NORMAL("error: The adapter %s " |
| 369 | "has entered the error state. " |
| 370 | "Restarting all operations on this " |
| 371 | "adapter.\n", |
| 372 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 373 | zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; |
| 375 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 376 | break; |
| 377 | |
| 378 | default: |
| 379 | ZFCP_LOG_NORMAL("bug: Transfer protocol status information " |
| 380 | "provided by the adapter %s " |
| 381 | "is not compatible with the device driver. " |
| 382 | "Stopping all operations on this adapter. " |
| 383 | "(debug info 0x%x).\n", |
| 384 | zfcp_get_busid_by_adapter(adapter), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 385 | qtcb->prefix.prot_status); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 386 | zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 388 | } |
| 389 | |
| 390 | skip_protstatus: |
| 391 | /* |
| 392 | * always call specific handlers to give them a chance to do |
| 393 | * something meaningful even in error cases |
| 394 | */ |
| 395 | zfcp_fsf_fsfstatus_eval(fsf_req); |
| 396 | return retval; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * function: zfcp_fsf_fsfstatus_eval |
| 401 | * |
| 402 | * purpose: evaluates FSF status of completed FSF request |
| 403 | * and acts accordingly |
| 404 | * |
| 405 | * returns: |
| 406 | */ |
| 407 | static int |
| 408 | zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req) |
| 409 | { |
| 410 | int retval = 0; |
| 411 | |
| 412 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 413 | goto skip_fsfstatus; |
| 414 | } |
| 415 | |
| 416 | /* evaluate FSF Status */ |
| 417 | switch (fsf_req->qtcb->header.fsf_status) { |
| 418 | case FSF_UNKNOWN_COMMAND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | ZFCP_LOG_NORMAL("bug: Command issued by the device driver is " |
| 420 | "not known by the adapter %s " |
| 421 | "Stopping all operations on this adapter. " |
| 422 | "(debug info 0x%x).\n", |
| 423 | zfcp_get_busid_by_adapter(fsf_req->adapter), |
| 424 | fsf_req->qtcb->header.fsf_command); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 425 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 427 | break; |
| 428 | |
| 429 | case FSF_FCP_RSP_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | ZFCP_LOG_DEBUG("FCP Sense data will be presented to the " |
| 431 | "SCSI stack.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | break; |
| 433 | |
| 434 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | zfcp_fsf_fsfstatus_qual_eval(fsf_req); |
| 436 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | skip_fsfstatus: |
| 440 | /* |
| 441 | * always call specific handlers to give them a chance to do |
| 442 | * something meaningful even in error cases |
| 443 | */ |
| 444 | zfcp_fsf_req_dispatch(fsf_req); |
| 445 | |
| 446 | return retval; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | * function: zfcp_fsf_fsfstatus_qual_eval |
| 451 | * |
| 452 | * purpose: evaluates FSF status-qualifier of completed FSF request |
| 453 | * and acts accordingly |
| 454 | * |
| 455 | * returns: |
| 456 | */ |
| 457 | static int |
| 458 | zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req) |
| 459 | { |
| 460 | int retval = 0; |
| 461 | |
| 462 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
| 463 | case FSF_SQ_FCP_RSP_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | break; |
| 465 | case FSF_SQ_RETRY_IF_POSSIBLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* The SCSI-stack may now issue retries or escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 468 | break; |
| 469 | case FSF_SQ_COMMAND_ABORTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* Carry the aborted state on to upper layer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED; |
| 472 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 473 | break; |
| 474 | case FSF_SQ_NO_RECOM: |
Joe Perches | ceb3dfb | 2008-01-26 14:11:10 +0100 | [diff] [blame] | 475 | ZFCP_LOG_NORMAL("bug: No recommendation could be given for a " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | "problem on the adapter %s " |
| 477 | "Stopping all operations on this adapter. ", |
| 478 | zfcp_get_busid_by_adapter(fsf_req->adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 479 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 481 | break; |
| 482 | case FSF_SQ_ULP_PROGRAMMING_ERROR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer " |
| 484 | "(adapter %s)\n", |
| 485 | zfcp_get_busid_by_adapter(fsf_req->adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 487 | break; |
| 488 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 489 | case FSF_SQ_NO_RETRY_POSSIBLE: |
| 490 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 491 | /* dealt with in the respective functions */ |
| 492 | break; |
| 493 | default: |
| 494 | ZFCP_LOG_NORMAL("bug: Additional status info could " |
| 495 | "not be interpreted properly.\n"); |
| 496 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, |
| 497 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 498 | sizeof (union fsf_status_qual)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 500 | break; |
| 501 | } |
| 502 | |
| 503 | return retval; |
| 504 | } |
| 505 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 506 | /** |
| 507 | * zfcp_fsf_link_down_info_eval - evaluate link down information block |
| 508 | */ |
| 509 | static void |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 510 | zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 511 | struct fsf_link_down_info *link_down) |
| 512 | { |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 513 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 514 | |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 515 | if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, |
| 516 | &adapter->status)) |
| 517 | return; |
| 518 | |
| 519 | atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
| 520 | |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 521 | if (link_down == NULL) |
| 522 | goto out; |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 523 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 524 | switch (link_down->error_code) { |
| 525 | case FSF_PSQ_LINK_NO_LIGHT: |
| 526 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 527 | "(no light detected)\n", |
| 528 | zfcp_get_busid_by_adapter(adapter)); |
| 529 | break; |
| 530 | case FSF_PSQ_LINK_WRAP_PLUG: |
| 531 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 532 | "(wrap plug detected)\n", |
| 533 | zfcp_get_busid_by_adapter(adapter)); |
| 534 | break; |
| 535 | case FSF_PSQ_LINK_NO_FCP: |
| 536 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 537 | "(adjacent node on link does not support FCP)\n", |
| 538 | zfcp_get_busid_by_adapter(adapter)); |
| 539 | break; |
| 540 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: |
| 541 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 542 | "(firmware update in progress)\n", |
| 543 | zfcp_get_busid_by_adapter(adapter)); |
| 544 | break; |
| 545 | case FSF_PSQ_LINK_INVALID_WWPN: |
| 546 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 547 | "(duplicate or invalid WWPN detected)\n", |
| 548 | zfcp_get_busid_by_adapter(adapter)); |
| 549 | break; |
| 550 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: |
| 551 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 552 | "(no support for NPIV by Fabric)\n", |
| 553 | zfcp_get_busid_by_adapter(adapter)); |
| 554 | break; |
| 555 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: |
| 556 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 557 | "(out of resource in FCP daughtercard)\n", |
| 558 | zfcp_get_busid_by_adapter(adapter)); |
| 559 | break; |
| 560 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: |
| 561 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 562 | "(out of resource in Fabric)\n", |
| 563 | zfcp_get_busid_by_adapter(adapter)); |
| 564 | break; |
| 565 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: |
| 566 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 567 | "(unable to Fabric login)\n", |
| 568 | zfcp_get_busid_by_adapter(adapter)); |
| 569 | break; |
| 570 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: |
| 571 | ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n", |
| 572 | zfcp_get_busid_by_adapter(adapter)); |
| 573 | break; |
| 574 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: |
| 575 | ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n", |
| 576 | zfcp_get_busid_by_adapter(adapter)); |
| 577 | break; |
| 578 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: |
| 579 | ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n", |
| 580 | zfcp_get_busid_by_adapter(adapter)); |
| 581 | break; |
| 582 | default: |
| 583 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " |
| 584 | "(warning: unknown reason code %d)\n", |
| 585 | zfcp_get_busid_by_adapter(adapter), |
| 586 | link_down->error_code); |
| 587 | } |
| 588 | |
| 589 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 590 | ZFCP_LOG_DEBUG("Debug information to link down: " |
| 591 | "primary_status=0x%02x " |
| 592 | "ioerr_code=0x%02x " |
| 593 | "action_code=0x%02x " |
| 594 | "reason_code=0x%02x " |
| 595 | "explanation_code=0x%02x " |
| 596 | "vendor_specific_code=0x%02x\n", |
| 597 | link_down->primary_status, |
| 598 | link_down->ioerr_code, |
| 599 | link_down->action_code, |
| 600 | link_down->reason_code, |
| 601 | link_down->explanation_code, |
| 602 | link_down->vendor_specific_code); |
| 603 | |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 604 | out: |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 605 | zfcp_erp_adapter_failed(adapter, id, fsf_req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | /* |
| 609 | * function: zfcp_fsf_req_dispatch |
| 610 | * |
| 611 | * purpose: calls the appropriate command specific handler |
| 612 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 613 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | */ |
| 615 | static int |
| 616 | zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req) |
| 617 | { |
| 618 | struct zfcp_erp_action *erp_action = fsf_req->erp_action; |
| 619 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 620 | int retval = 0; |
| 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | switch (fsf_req->fsf_command) { |
| 624 | |
| 625 | case FSF_QTCB_FCP_CMND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | zfcp_fsf_send_fcp_command_handler(fsf_req); |
| 627 | break; |
| 628 | |
| 629 | case FSF_QTCB_ABORT_FCP_CMND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | zfcp_fsf_abort_fcp_command_handler(fsf_req); |
| 631 | break; |
| 632 | |
| 633 | case FSF_QTCB_SEND_GENERIC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | zfcp_fsf_send_ct_handler(fsf_req); |
| 635 | break; |
| 636 | |
| 637 | case FSF_QTCB_OPEN_PORT_WITH_DID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | zfcp_fsf_open_port_handler(fsf_req); |
| 639 | break; |
| 640 | |
| 641 | case FSF_QTCB_OPEN_LUN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | zfcp_fsf_open_unit_handler(fsf_req); |
| 643 | break; |
| 644 | |
| 645 | case FSF_QTCB_CLOSE_LUN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | zfcp_fsf_close_unit_handler(fsf_req); |
| 647 | break; |
| 648 | |
| 649 | case FSF_QTCB_CLOSE_PORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | zfcp_fsf_close_port_handler(fsf_req); |
| 651 | break; |
| 652 | |
| 653 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | zfcp_fsf_close_physical_port_handler(fsf_req); |
| 655 | break; |
| 656 | |
| 657 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | zfcp_fsf_exchange_config_data_handler(fsf_req); |
| 659 | break; |
| 660 | |
| 661 | case FSF_QTCB_EXCHANGE_PORT_DATA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | zfcp_fsf_exchange_port_data_handler(fsf_req); |
| 663 | break; |
| 664 | |
| 665 | case FSF_QTCB_SEND_ELS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | zfcp_fsf_send_els_handler(fsf_req); |
| 667 | break; |
| 668 | |
| 669 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | zfcp_fsf_control_file_handler(fsf_req); |
| 671 | break; |
| 672 | |
| 673 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | zfcp_fsf_control_file_handler(fsf_req); |
| 675 | break; |
| 676 | |
| 677 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 679 | ZFCP_LOG_NORMAL("bug: Command issued by the device driver is " |
| 680 | "not supported by the adapter %s\n", |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 681 | zfcp_get_busid_by_adapter(adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command) |
| 683 | ZFCP_LOG_NORMAL |
| 684 | ("bug: Command issued by the device driver differs " |
| 685 | "from the command returned by the adapter %s " |
| 686 | "(debug info 0x%x, 0x%x).\n", |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 687 | zfcp_get_busid_by_adapter(adapter), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | fsf_req->fsf_command, |
| 689 | fsf_req->qtcb->header.fsf_command); |
| 690 | } |
| 691 | |
| 692 | if (!erp_action) |
| 693 | return retval; |
| 694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | zfcp_erp_async_handler(erp_action, 0); |
| 696 | |
| 697 | return retval; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * function: zfcp_fsf_status_read |
| 702 | * |
| 703 | * purpose: initiates a Status Read command at the specified adapter |
| 704 | * |
| 705 | * returns: |
| 706 | */ |
| 707 | int |
| 708 | zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags) |
| 709 | { |
| 710 | struct zfcp_fsf_req *fsf_req; |
| 711 | struct fsf_status_read_buffer *status_buffer; |
| 712 | unsigned long lock_flags; |
| 713 | volatile struct qdio_buffer_element *sbale; |
Heiko Carstens | b214178 | 2008-05-19 12:17:39 +0200 | [diff] [blame] | 714 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | /* setup new FSF request */ |
| 717 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, |
| 718 | req_flags | ZFCP_REQ_NO_QTCB, |
| 719 | adapter->pool.fsf_req_status_read, |
| 720 | &lock_flags, &fsf_req); |
| 721 | if (retval < 0) { |
| 722 | ZFCP_LOG_INFO("error: Could not create unsolicited status " |
| 723 | "buffer for adapter %s.\n", |
| 724 | zfcp_get_busid_by_adapter(adapter)); |
| 725 | goto failed_req_create; |
| 726 | } |
| 727 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 728 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; |
| 730 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 731 | fsf_req->sbale_curr = 2; |
| 732 | |
Heiko Carstens | b214178 | 2008-05-19 12:17:39 +0200 | [diff] [blame] | 733 | retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | status_buffer = |
| 735 | mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); |
Heiko Carstens | b214178 | 2008-05-19 12:17:39 +0200 | [diff] [blame] | 736 | if (!status_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | goto failed_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer)); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 739 | fsf_req->data = (unsigned long) status_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | /* insert pointer to respective buffer */ |
| 742 | sbale = zfcp_qdio_sbale_curr(fsf_req); |
| 743 | sbale->addr = (void *) status_buffer; |
| 744 | sbale->length = sizeof(struct fsf_status_read_buffer); |
| 745 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 746 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (retval) { |
| 748 | ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status " |
| 749 | "environment.\n"); |
| 750 | goto failed_req_send; |
| 751 | } |
| 752 | |
| 753 | ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n", |
| 754 | zfcp_get_busid_by_adapter(adapter)); |
| 755 | goto out; |
| 756 | |
| 757 | failed_req_send: |
| 758 | mempool_free(status_buffer, adapter->pool.data_status_read); |
| 759 | |
| 760 | failed_buf: |
| 761 | zfcp_fsf_req_free(fsf_req); |
| 762 | failed_req_create: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 763 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 765 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return retval; |
| 767 | } |
| 768 | |
| 769 | static int |
| 770 | zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req) |
| 771 | { |
| 772 | struct fsf_status_read_buffer *status_buffer; |
| 773 | struct zfcp_adapter *adapter; |
| 774 | struct zfcp_port *port; |
| 775 | unsigned long flags; |
| 776 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 777 | status_buffer = (struct fsf_status_read_buffer *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | adapter = fsf_req->adapter; |
| 779 | |
| 780 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 781 | list_for_each_entry(port, &adapter->port_list_head, list) |
| 782 | if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK)) |
| 783 | break; |
| 784 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 785 | |
| 786 | if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) { |
Joe Perches | ceb3dfb | 2008-01-26 14:11:10 +0100 | [diff] [blame] | 787 | ZFCP_LOG_NORMAL("bug: Reopen port indication received for " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 788 | "nonexisting port with d_id 0x%06x on " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | "adapter %s. Ignored.\n", |
| 790 | status_buffer->d_id & ZFCP_DID_MASK, |
| 791 | zfcp_get_busid_by_adapter(adapter)); |
| 792 | goto out; |
| 793 | } |
| 794 | |
| 795 | switch (status_buffer->status_subtype) { |
| 796 | |
| 797 | case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 798 | zfcp_erp_port_reopen(port, 0, 101, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case FSF_STATUS_READ_SUB_ERROR_PORT: |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 802 | zfcp_erp_port_shutdown(port, 0, 122, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | ZFCP_LOG_NORMAL("bug: Undefined status subtype received " |
| 807 | "for a reopen indication on port with " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 808 | "d_id 0x%06x on the adapter %s. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | "Ignored. (debug info 0x%x)\n", |
| 810 | status_buffer->d_id, |
| 811 | zfcp_get_busid_by_adapter(adapter), |
| 812 | status_buffer->status_subtype); |
| 813 | } |
| 814 | out: |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /* |
| 819 | * function: zfcp_fsf_status_read_handler |
| 820 | * |
| 821 | * purpose: is called for finished Open Port command |
| 822 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 823 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | */ |
| 825 | static int |
| 826 | zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req) |
| 827 | { |
| 828 | int retval = 0; |
| 829 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 830 | struct fsf_status_read_buffer *status_buffer = |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 831 | (struct fsf_status_read_buffer *) fsf_req->data; |
Ralph Wuerthner | b7a52fa | 2006-05-22 18:21:28 +0200 | [diff] [blame] | 832 | struct fsf_bit_error_payload *fsf_bit_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 835 | zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | mempool_free(status_buffer, adapter->pool.data_status_read); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 837 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | goto out; |
| 839 | } |
| 840 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 841 | zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer); |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | switch (status_buffer->status_type) { |
| 844 | |
| 845 | case FSF_STATUS_READ_PORT_CLOSED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | zfcp_fsf_status_read_port_closed(fsf_req); |
| 847 | break; |
| 848 | |
| 849 | case FSF_STATUS_READ_INCOMING_ELS: |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 850 | zfcp_fc_incoming_els(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n", |
| 855 | zfcp_get_busid_by_adapter(adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | break; |
| 857 | |
| 858 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: |
Ralph Wuerthner | b7a52fa | 2006-05-22 18:21:28 +0200 | [diff] [blame] | 859 | fsf_bit_error = (struct fsf_bit_error_payload *) |
| 860 | status_buffer->payload; |
| 861 | ZFCP_LOG_NORMAL("Warning: bit error threshold data " |
| 862 | "received (adapter %s, " |
| 863 | "link failures = %i, loss of sync errors = %i, " |
| 864 | "loss of signal errors = %i, " |
| 865 | "primitive sequence errors = %i, " |
| 866 | "invalid transmission word errors = %i, " |
| 867 | "CRC errors = %i)\n", |
| 868 | zfcp_get_busid_by_adapter(adapter), |
| 869 | fsf_bit_error->link_failure_error_count, |
| 870 | fsf_bit_error->loss_of_sync_error_count, |
| 871 | fsf_bit_error->loss_of_signal_error_count, |
| 872 | fsf_bit_error->primitive_sequence_error_count, |
| 873 | fsf_bit_error->invalid_transmission_word_error_count, |
| 874 | fsf_bit_error->crc_error_count); |
| 875 | ZFCP_LOG_INFO("Additional bit error threshold data " |
| 876 | "(adapter %s, " |
| 877 | "primitive sequence event time-outs = %i, " |
| 878 | "elastic buffer overrun errors = %i, " |
| 879 | "advertised receive buffer-to-buffer credit = %i, " |
| 880 | "current receice buffer-to-buffer credit = %i, " |
| 881 | "advertised transmit buffer-to-buffer credit = %i, " |
| 882 | "current transmit buffer-to-buffer credit = %i)\n", |
| 883 | zfcp_get_busid_by_adapter(adapter), |
| 884 | fsf_bit_error->primitive_sequence_event_timeout_count, |
| 885 | fsf_bit_error->elastic_buffer_overrun_error_count, |
| 886 | fsf_bit_error->advertised_receive_b2b_credit, |
| 887 | fsf_bit_error->current_receive_b2b_credit, |
| 888 | fsf_bit_error->advertised_transmit_b2b_credit, |
| 889 | fsf_bit_error->current_transmit_b2b_credit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case FSF_STATUS_READ_LINK_DOWN: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 893 | switch (status_buffer->status_subtype) { |
| 894 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: |
| 895 | ZFCP_LOG_INFO("Physical link to adapter %s is down\n", |
| 896 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 897 | zfcp_fsf_link_down_info_eval(fsf_req, 38, |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 898 | (struct fsf_link_down_info *) |
| 899 | &status_buffer->payload); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 900 | break; |
| 901 | case FSF_STATUS_READ_SUB_FDISC_FAILED: |
| 902 | ZFCP_LOG_INFO("Local link to adapter %s is down " |
| 903 | "due to failed FDISC login\n", |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 904 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 905 | zfcp_fsf_link_down_info_eval(fsf_req, 39, |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 906 | (struct fsf_link_down_info *) |
| 907 | &status_buffer->payload); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 908 | break; |
| 909 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: |
| 910 | ZFCP_LOG_INFO("Local link to adapter %s is down " |
| 911 | "due to firmware update on adapter\n", |
| 912 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 913 | zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 914 | break; |
| 915 | default: |
| 916 | ZFCP_LOG_INFO("Local link to adapter %s is down " |
| 917 | "due to unknown reason\n", |
| 918 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 919 | zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 920 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case FSF_STATUS_READ_LINK_UP: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 924 | ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. " |
Maxim Shchetynin | ee69ab7 | 2005-12-01 02:48:41 +0100 | [diff] [blame] | 925 | "Restarting operations on this adapter\n", |
| 926 | zfcp_get_busid_by_adapter(adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | /* All ports should be marked as ready to run again */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 928 | zfcp_erp_modify_adapter_status(adapter, 30, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | ZFCP_STATUS_COMMON_RUNNING, |
| 930 | ZFCP_SET); |
| 931 | zfcp_erp_adapter_reopen(adapter, |
| 932 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 933 | | ZFCP_STATUS_COMMON_ERP_FAILED, |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 934 | 102, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | break; |
| 936 | |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 937 | case FSF_STATUS_READ_NOTIFICATION_LOST: |
| 938 | ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: " |
| 939 | "adapter %s%s%s%s%s%s%s%s%s\n", |
| 940 | zfcp_get_busid_by_adapter(adapter), |
| 941 | (status_buffer->status_subtype & |
| 942 | FSF_STATUS_READ_SUB_INCOMING_ELS) ? |
| 943 | ", incoming ELS" : "", |
| 944 | (status_buffer->status_subtype & |
| 945 | FSF_STATUS_READ_SUB_SENSE_DATA) ? |
| 946 | ", sense data" : "", |
| 947 | (status_buffer->status_subtype & |
| 948 | FSF_STATUS_READ_SUB_LINK_STATUS) ? |
| 949 | ", link status change" : "", |
| 950 | (status_buffer->status_subtype & |
| 951 | FSF_STATUS_READ_SUB_PORT_CLOSED) ? |
| 952 | ", port close" : "", |
| 953 | (status_buffer->status_subtype & |
| 954 | FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ? |
| 955 | ", bit error exception" : "", |
| 956 | (status_buffer->status_subtype & |
| 957 | FSF_STATUS_READ_SUB_ACT_UPDATED) ? |
| 958 | ", ACT update" : "", |
| 959 | (status_buffer->status_subtype & |
| 960 | FSF_STATUS_READ_SUB_ACT_HARDENED) ? |
| 961 | ", ACT hardening" : "", |
| 962 | (status_buffer->status_subtype & |
| 963 | FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ? |
| 964 | ", adapter feature change" : ""); |
| 965 | |
| 966 | if (status_buffer->status_subtype & |
| 967 | FSF_STATUS_READ_SUB_ACT_UPDATED) |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 968 | zfcp_erp_adapter_access_changed(adapter, 135, fsf_req); |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 969 | break; |
| 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | case FSF_STATUS_READ_CFDC_UPDATED: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 972 | ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 974 | zfcp_erp_adapter_access_changed(adapter, 136, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | break; |
| 976 | |
| 977 | case FSF_STATUS_READ_CFDC_HARDENED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | switch (status_buffer->status_subtype) { |
| 979 | case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 980 | ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | zfcp_get_busid_by_adapter(adapter)); |
| 982 | break; |
| 983 | case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 984 | ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | "to the secondary SE\n", |
| 986 | zfcp_get_busid_by_adapter(adapter)); |
| 987 | break; |
| 988 | default: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 989 | ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | zfcp_get_busid_by_adapter(adapter)); |
| 991 | } |
| 992 | break; |
| 993 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 994 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 995 | ZFCP_LOG_INFO("List of supported features on adapter %s has " |
| 996 | "been changed from 0x%08X to 0x%08X\n", |
| 997 | zfcp_get_busid_by_adapter(adapter), |
| 998 | *(u32*) (status_buffer->payload + 4), |
| 999 | *(u32*) (status_buffer->payload)); |
| 1000 | adapter->adapter_features = *(u32*) status_buffer->payload; |
| 1001 | break; |
| 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | default: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1004 | ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | "type was received (debug info 0x%x)\n", |
| 1006 | status_buffer->status_type); |
| 1007 | ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n", |
| 1008 | status_buffer); |
| 1009 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 1010 | (char *) status_buffer, |
| 1011 | sizeof (struct fsf_status_read_buffer)); |
| 1012 | break; |
| 1013 | } |
| 1014 | mempool_free(status_buffer, adapter->pool.data_status_read); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 1015 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | /* |
| 1017 | * recycle buffer and start new request repeat until outbound |
| 1018 | * queue is empty or adapter shutdown is requested |
| 1019 | */ |
| 1020 | /* |
| 1021 | * FIXME(qdio): |
| 1022 | * we may wait in the req_create for 5s during shutdown, so |
| 1023 | * qdio_cleanup will have to wait at least that long before returning |
| 1024 | * with failure to allow us a proper cleanup under all circumstances |
| 1025 | */ |
| 1026 | /* |
| 1027 | * FIXME: |
| 1028 | * allocation failure possible? (Is this code needed?) |
| 1029 | */ |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 1030 | |
| 1031 | atomic_inc(&adapter->stat_miss); |
| 1032 | schedule_work(&adapter->stat_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | out: |
| 1034 | return retval; |
| 1035 | } |
| 1036 | |
| 1037 | /* |
| 1038 | * function: zfcp_fsf_abort_fcp_command |
| 1039 | * |
| 1040 | * purpose: tells FSF to abort a running SCSI command |
| 1041 | * |
| 1042 | * returns: address of initiated FSF request |
| 1043 | * NULL - request could not be initiated |
| 1044 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1045 | * FIXME(design): should be watched by a timeout !!! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | * FIXME(design) shouldn't this be modified to return an int |
| 1047 | * also...don't know how though |
| 1048 | */ |
| 1049 | struct zfcp_fsf_req * |
| 1050 | zfcp_fsf_abort_fcp_command(unsigned long old_req_id, |
| 1051 | struct zfcp_adapter *adapter, |
| 1052 | struct zfcp_unit *unit, int req_flags) |
| 1053 | { |
| 1054 | volatile struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | struct zfcp_fsf_req *fsf_req = NULL; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1056 | unsigned long lock_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | int retval = 0; |
| 1058 | |
| 1059 | /* setup new FSF request */ |
| 1060 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, |
| 1061 | req_flags, adapter->pool.fsf_req_abort, |
| 1062 | &lock_flags, &fsf_req); |
| 1063 | if (retval < 0) { |
| 1064 | ZFCP_LOG_INFO("error: Failed to create an abort command " |
| 1065 | "request for lun 0x%016Lx on port 0x%016Lx " |
| 1066 | "on adapter %s.\n", |
| 1067 | unit->fcp_lun, |
| 1068 | unit->port->wwpn, |
| 1069 | zfcp_get_busid_by_adapter(adapter)); |
| 1070 | goto out; |
| 1071 | } |
| 1072 | |
Christof Schmitt | 951f746 | 2007-12-20 12:30:24 +0100 | [diff] [blame] | 1073 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, |
| 1074 | &unit->status))) |
| 1075 | goto unit_blocked; |
| 1076 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1077 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1079 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1080 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1081 | fsf_req->data = (unsigned long) unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | /* set handles of unit and its parent port in QTCB */ |
| 1084 | fsf_req->qtcb->header.lun_handle = unit->handle; |
| 1085 | fsf_req->qtcb->header.port_handle = unit->port->handle; |
| 1086 | |
| 1087 | /* set handle of request which should be aborted */ |
| 1088 | fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
| 1089 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1090 | zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT); |
| 1091 | retval = zfcp_fsf_req_send(fsf_req); |
Christof Schmitt | 951f746 | 2007-12-20 12:30:24 +0100 | [diff] [blame] | 1092 | if (!retval) |
| 1093 | goto out; |
| 1094 | |
| 1095 | unit_blocked: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | zfcp_fsf_req_free(fsf_req); |
| 1097 | fsf_req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1100 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | return fsf_req; |
| 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * function: zfcp_fsf_abort_fcp_command_handler |
| 1106 | * |
| 1107 | * purpose: is called for finished Abort FCP Command request |
| 1108 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1109 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | */ |
| 1111 | static int |
| 1112 | zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req) |
| 1113 | { |
| 1114 | int retval = -EINVAL; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1115 | struct zfcp_unit *unit; |
Christof Schmitt | 8627533 | 2007-12-20 12:30:23 +0100 | [diff] [blame] | 1116 | union fsf_status_qual *fsf_stat_qual = |
| 1117 | &new_fsf_req->qtcb->header.fsf_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 1120 | /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */ |
| 1121 | goto skip_fsfstatus; |
| 1122 | } |
| 1123 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1124 | unit = (struct zfcp_unit *) new_fsf_req->data; |
| 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | /* evaluate FSF status in QTCB */ |
| 1127 | switch (new_fsf_req->qtcb->header.fsf_status) { |
| 1128 | |
| 1129 | case FSF_PORT_HANDLE_NOT_VALID: |
Christof Schmitt | 8627533 | 2007-12-20 12:30:23 +0100 | [diff] [blame] | 1130 | if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | /* |
| 1132 | * In this case a command that was sent prior to a port |
| 1133 | * reopen was aborted (handles are different). This is |
| 1134 | * fine. |
| 1135 | */ |
| 1136 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for " |
| 1138 | "port 0x%016Lx on adapter %s invalid. " |
| 1139 | "This may happen occasionally.\n", |
| 1140 | unit->port->handle, |
| 1141 | unit->port->wwpn, |
| 1142 | zfcp_get_busid_by_unit(unit)); |
| 1143 | ZFCP_LOG_INFO("status qualifier:\n"); |
| 1144 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, |
| 1145 | (char *) &new_fsf_req->qtcb->header. |
| 1146 | fsf_status_qual, |
| 1147 | sizeof (union fsf_status_qual)); |
| 1148 | /* Let's hope this sorts out the mess */ |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1149 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1150 | new_fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1152 | } |
| 1153 | break; |
| 1154 | |
| 1155 | case FSF_LUN_HANDLE_NOT_VALID: |
Christof Schmitt | 8627533 | 2007-12-20 12:30:23 +0100 | [diff] [blame] | 1156 | if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | /* |
| 1158 | * In this case a command that was sent prior to a unit |
| 1159 | * reopen was aborted (handles are different). |
| 1160 | * This is fine. |
| 1161 | */ |
| 1162 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | ZFCP_LOG_INFO |
| 1164 | ("Warning: Temporary LUN identifier 0x%x of LUN " |
| 1165 | "0x%016Lx on port 0x%016Lx on adapter %s is " |
| 1166 | "invalid. This may happen in rare cases. " |
| 1167 | "Trying to re-establish link.\n", |
| 1168 | unit->handle, |
| 1169 | unit->fcp_lun, |
| 1170 | unit->port->wwpn, |
| 1171 | zfcp_get_busid_by_unit(unit)); |
| 1172 | ZFCP_LOG_DEBUG("Status qualifier data:\n"); |
| 1173 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 1174 | (char *) &new_fsf_req->qtcb->header. |
| 1175 | fsf_status_qual, |
| 1176 | sizeof (union fsf_status_qual)); |
| 1177 | /* Let's hope this sorts out the mess */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1178 | zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1180 | } |
| 1181 | break; |
| 1182 | |
| 1183 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
| 1186 | break; |
| 1187 | |
| 1188 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to " |
| 1190 | "be reopened\n", unit->port->wwpn, |
| 1191 | zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1192 | zfcp_erp_port_boxed(unit->port, 47, new_fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
| 1194 | | ZFCP_STATUS_FSFREQ_RETRY; |
| 1195 | break; |
| 1196 | |
| 1197 | case FSF_LUN_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | ZFCP_LOG_INFO( |
| 1199 | "unit 0x%016Lx on port 0x%016Lx on adapter %s needs " |
| 1200 | "to be reopened\n", |
| 1201 | unit->fcp_lun, unit->port->wwpn, |
| 1202 | zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1203 | zfcp_erp_unit_boxed(unit, 48, new_fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
| 1205 | | ZFCP_STATUS_FSFREQ_RETRY; |
| 1206 | break; |
| 1207 | |
| 1208 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
| 1210 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 1211 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1213 | break; |
| 1214 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | /* SCSI stack will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1217 | break; |
| 1218 | default: |
| 1219 | ZFCP_LOG_NORMAL |
| 1220 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 1221 | new_fsf_req->qtcb->header.fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | break; |
| 1223 | } |
| 1224 | break; |
| 1225 | |
| 1226 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | retval = 0; |
| 1228 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
| 1229 | break; |
| 1230 | |
| 1231 | default: |
| 1232 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 1233 | "(debug info 0x%x)\n", |
| 1234 | new_fsf_req->qtcb->header.fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | } |
| 1237 | skip_fsfstatus: |
| 1238 | return retval; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into |
| 1243 | * one SBALE |
| 1244 | * Two scatter-gather lists are passed, one for the reqeust and one for the |
| 1245 | * response. |
| 1246 | */ |
| 1247 | static inline int |
| 1248 | zfcp_use_one_sbal(struct scatterlist *req, int req_count, |
| 1249 | struct scatterlist *resp, int resp_count) |
| 1250 | { |
| 1251 | return ((req_count == 1) && |
| 1252 | (resp_count == 1) && |
| 1253 | (((unsigned long) zfcp_sg_to_address(&req[0]) & |
| 1254 | PAGE_MASK) == |
| 1255 | ((unsigned long) (zfcp_sg_to_address(&req[0]) + |
| 1256 | req[0].length - 1) & PAGE_MASK)) && |
| 1257 | (((unsigned long) zfcp_sg_to_address(&resp[0]) & |
| 1258 | PAGE_MASK) == |
| 1259 | ((unsigned long) (zfcp_sg_to_address(&resp[0]) + |
| 1260 | resp[0].length - 1) & PAGE_MASK))); |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
| 1265 | * @ct: pointer to struct zfcp_send_ct which conatins all needed data for |
| 1266 | * the request |
| 1267 | * @pool: pointer to memory pool, if non-null this pool is used to allocate |
| 1268 | * a struct zfcp_fsf_req |
| 1269 | * @erp_action: pointer to erp_action, if non-null the Generic Service request |
| 1270 | * is sent within error recovery |
| 1271 | */ |
| 1272 | int |
| 1273 | zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, |
| 1274 | struct zfcp_erp_action *erp_action) |
| 1275 | { |
| 1276 | volatile struct qdio_buffer_element *sbale; |
| 1277 | struct zfcp_port *port; |
| 1278 | struct zfcp_adapter *adapter; |
| 1279 | struct zfcp_fsf_req *fsf_req; |
| 1280 | unsigned long lock_flags; |
| 1281 | int bytes; |
| 1282 | int ret = 0; |
| 1283 | |
| 1284 | port = ct->port; |
| 1285 | adapter = port->adapter; |
| 1286 | |
| 1287 | ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, |
| 1288 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 1289 | pool, &lock_flags, &fsf_req); |
| 1290 | if (ret < 0) { |
| 1291 | ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for " |
| 1292 | "adapter: %s\n", |
| 1293 | zfcp_get_busid_by_adapter(adapter)); |
| 1294 | goto failed_req; |
| 1295 | } |
| 1296 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1297 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | if (zfcp_use_one_sbal(ct->req, ct->req_count, |
| 1299 | ct->resp, ct->resp_count)){ |
| 1300 | /* both request buffer and response buffer |
| 1301 | fit into one sbale each */ |
| 1302 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; |
| 1303 | sbale[2].addr = zfcp_sg_to_address(&ct->req[0]); |
| 1304 | sbale[2].length = ct->req[0].length; |
| 1305 | sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]); |
| 1306 | sbale[3].length = ct->resp[0].length; |
| 1307 | sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1308 | } else if (adapter->adapter_features & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | FSF_FEATURE_ELS_CT_CHAINED_SBALS) { |
| 1310 | /* try to use chained SBALs */ |
| 1311 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, |
| 1312 | SBAL_FLAGS0_TYPE_WRITE_READ, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1313 | ct->req, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | ZFCP_MAX_SBALS_PER_CT_REQ); |
| 1315 | if (bytes <= 0) { |
| 1316 | ZFCP_LOG_INFO("error: creation of CT request failed " |
| 1317 | "on adapter %s\n", |
| 1318 | zfcp_get_busid_by_adapter(adapter)); |
| 1319 | if (bytes == 0) |
| 1320 | ret = -ENOMEM; |
| 1321 | else |
| 1322 | ret = bytes; |
| 1323 | |
| 1324 | goto failed_send; |
| 1325 | } |
| 1326 | fsf_req->qtcb->bottom.support.req_buf_length = bytes; |
| 1327 | fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; |
| 1328 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, |
| 1329 | SBAL_FLAGS0_TYPE_WRITE_READ, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1330 | ct->resp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | ZFCP_MAX_SBALS_PER_CT_REQ); |
| 1332 | if (bytes <= 0) { |
| 1333 | ZFCP_LOG_INFO("error: creation of CT request failed " |
| 1334 | "on adapter %s\n", |
| 1335 | zfcp_get_busid_by_adapter(adapter)); |
| 1336 | if (bytes == 0) |
| 1337 | ret = -ENOMEM; |
| 1338 | else |
| 1339 | ret = bytes; |
| 1340 | |
| 1341 | goto failed_send; |
| 1342 | } |
| 1343 | fsf_req->qtcb->bottom.support.resp_buf_length = bytes; |
| 1344 | } else { |
| 1345 | /* reject send generic request */ |
| 1346 | ZFCP_LOG_INFO( |
| 1347 | "error: microcode does not support chained SBALs," |
| 1348 | "CT request too big (adapter %s)\n", |
| 1349 | zfcp_get_busid_by_adapter(adapter)); |
| 1350 | ret = -EOPNOTSUPP; |
| 1351 | goto failed_send; |
| 1352 | } |
| 1353 | |
| 1354 | /* settings in QTCB */ |
| 1355 | fsf_req->qtcb->header.port_handle = port->handle; |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 1356 | fsf_req->qtcb->bottom.support.service_class = |
| 1357 | ZFCP_FC_SERVICE_CLASS_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | fsf_req->qtcb->bottom.support.timeout = ct->timeout; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1359 | fsf_req->data = (unsigned long) ct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1361 | zfcp_san_dbf_event_ct_request(fsf_req); |
| 1362 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1363 | if (erp_action) { |
| 1364 | erp_action->fsf_req = fsf_req; |
| 1365 | fsf_req->erp_action = erp_action; |
| 1366 | zfcp_erp_start_timer(fsf_req); |
| 1367 | } else |
| 1368 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1369 | |
| 1370 | ret = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | if (ret) { |
| 1372 | ZFCP_LOG_DEBUG("error: initiation of CT request failed " |
| 1373 | "(adapter %s, port 0x%016Lx)\n", |
| 1374 | zfcp_get_busid_by_adapter(adapter), port->wwpn); |
| 1375 | goto failed_send; |
| 1376 | } |
| 1377 | |
| 1378 | ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n", |
| 1379 | zfcp_get_busid_by_adapter(adapter), port->wwpn); |
| 1380 | goto out; |
| 1381 | |
| 1382 | failed_send: |
| 1383 | zfcp_fsf_req_free(fsf_req); |
| 1384 | if (erp_action != NULL) { |
| 1385 | erp_action->fsf_req = NULL; |
| 1386 | } |
| 1387 | failed_req: |
| 1388 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1389 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | return ret; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * zfcp_fsf_send_ct_handler - handler for Generic Service requests |
| 1395 | * @fsf_req: pointer to struct zfcp_fsf_req |
| 1396 | * |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1397 | * Data specific for the Generic Service request is passed using |
| 1398 | * fsf_req->data. There we find the pointer to struct zfcp_send_ct. |
| 1399 | * Usually a specific handler for the CT request is called which is |
| 1400 | * found in this structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | */ |
| 1402 | static int |
| 1403 | zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req) |
| 1404 | { |
| 1405 | struct zfcp_port *port; |
| 1406 | struct zfcp_adapter *adapter; |
| 1407 | struct zfcp_send_ct *send_ct; |
| 1408 | struct fsf_qtcb_header *header; |
| 1409 | struct fsf_qtcb_bottom_support *bottom; |
| 1410 | int retval = -EINVAL; |
| 1411 | u16 subtable, rule, counter; |
| 1412 | |
| 1413 | adapter = fsf_req->adapter; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1414 | send_ct = (struct zfcp_send_ct *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | port = send_ct->port; |
| 1416 | header = &fsf_req->qtcb->header; |
| 1417 | bottom = &fsf_req->qtcb->bottom.support; |
| 1418 | |
| 1419 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1420 | goto skip_fsfstatus; |
| 1421 | |
| 1422 | /* evaluate FSF status in QTCB */ |
| 1423 | switch (header->fsf_status) { |
| 1424 | |
| 1425 | case FSF_GOOD: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1426 | zfcp_san_dbf_event_ct_response(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | retval = 0; |
| 1428 | break; |
| 1429 | |
| 1430 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 1431 | ZFCP_LOG_INFO("error: adapter %s does not support fc " |
| 1432 | "class %d.\n", |
| 1433 | zfcp_get_busid_by_port(port), |
| 1434 | ZFCP_FC_SERVICE_CLASS_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | /* stop operation for this adapter */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1436 | zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1438 | break; |
| 1439 | |
| 1440 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | switch (header->fsf_status_qual.word[0]){ |
| 1442 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | /* reopening link to port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | zfcp_test_link(port); |
| 1445 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1446 | break; |
| 1447 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | /* ERP strategy will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1450 | break; |
| 1451 | default: |
| 1452 | ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x " |
| 1453 | "arrived.\n", |
| 1454 | header->fsf_status_qual.word[0]); |
| 1455 | break; |
| 1456 | } |
| 1457 | break; |
| 1458 | |
| 1459 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | ZFCP_LOG_NORMAL("access denied, cannot send generic service " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1461 | "command (adapter %s, port d_id=0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | zfcp_get_busid_by_port(port), port->d_id); |
| 1463 | for (counter = 0; counter < 2; counter++) { |
| 1464 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 1465 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 1466 | switch (subtable) { |
| 1467 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 1468 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 1469 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 1470 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 1471 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 1472 | zfcp_act_subtable_type[subtable], rule); |
| 1473 | break; |
| 1474 | } |
| 1475 | } |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1476 | zfcp_erp_port_access_denied(port, 55, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1478 | break; |
| 1479 | |
| 1480 | case FSF_GENERIC_COMMAND_REJECTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | ZFCP_LOG_INFO("generic service command rejected " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1482 | "(adapter %s, port d_id=0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | zfcp_get_busid_by_port(port), port->d_id); |
| 1484 | ZFCP_LOG_INFO("status qualifier:\n"); |
| 1485 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, |
| 1486 | (char *) &header->fsf_status_qual, |
| 1487 | sizeof (union fsf_status_qual)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1489 | break; |
| 1490 | |
| 1491 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port " |
| 1493 | "0x%016Lx on adapter %s invalid. This may " |
| 1494 | "happen occasionally.\n", port->handle, |
| 1495 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 1496 | ZFCP_LOG_INFO("status qualifier:\n"); |
| 1497 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, |
| 1498 | (char *) &header->fsf_status_qual, |
| 1499 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1500 | zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1502 | break; |
| 1503 | |
| 1504 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | ZFCP_LOG_INFO("port needs to be reopened " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1506 | "(adapter %s, port d_id=0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | zfcp_get_busid_by_port(port), port->d_id); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1508 | zfcp_erp_port_boxed(port, 49, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
| 1510 | | ZFCP_STATUS_FSFREQ_RETRY; |
| 1511 | break; |
| 1512 | |
| 1513 | /* following states should never occure, all cases avoided |
| 1514 | in zfcp_fsf_send_ct - but who knows ... */ |
| 1515 | case FSF_PAYLOAD_SIZE_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | ZFCP_LOG_INFO("payload size mismatch (adapter: %s, " |
| 1517 | "req_buf_length=%d, resp_buf_length=%d)\n", |
| 1518 | zfcp_get_busid_by_adapter(adapter), |
| 1519 | bottom->req_buf_length, bottom->resp_buf_length); |
| 1520 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1521 | break; |
| 1522 | case FSF_REQUEST_SIZE_TOO_LARGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | ZFCP_LOG_INFO("request size too large (adapter: %s, " |
| 1524 | "req_buf_length=%d)\n", |
| 1525 | zfcp_get_busid_by_adapter(adapter), |
| 1526 | bottom->req_buf_length); |
| 1527 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1528 | break; |
| 1529 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | ZFCP_LOG_INFO("response size too large (adapter: %s, " |
| 1531 | "resp_buf_length=%d)\n", |
| 1532 | zfcp_get_busid_by_adapter(adapter), |
| 1533 | bottom->resp_buf_length); |
| 1534 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1535 | break; |
| 1536 | case FSF_SBAL_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, " |
| 1538 | "resp_buf_length=%d)\n", |
| 1539 | zfcp_get_busid_by_adapter(adapter), |
| 1540 | bottom->req_buf_length, bottom->resp_buf_length); |
| 1541 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1542 | break; |
| 1543 | |
| 1544 | default: |
| 1545 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 1546 | "(debug info 0x%x)\n", header->fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | break; |
| 1548 | } |
| 1549 | |
| 1550 | skip_fsfstatus: |
| 1551 | send_ct->status = retval; |
| 1552 | |
| 1553 | if (send_ct->handler != NULL) |
| 1554 | send_ct->handler(send_ct->handler_data); |
| 1555 | |
| 1556 | return retval; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) |
| 1561 | * @els: pointer to struct zfcp_send_els which contains all needed data for |
| 1562 | * the command. |
| 1563 | */ |
| 1564 | int |
| 1565 | zfcp_fsf_send_els(struct zfcp_send_els *els) |
| 1566 | { |
| 1567 | volatile struct qdio_buffer_element *sbale; |
| 1568 | struct zfcp_fsf_req *fsf_req; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 1569 | u32 d_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | struct zfcp_adapter *adapter; |
| 1571 | unsigned long lock_flags; |
| 1572 | int bytes; |
| 1573 | int ret = 0; |
| 1574 | |
| 1575 | d_id = els->d_id; |
| 1576 | adapter = els->adapter; |
| 1577 | |
| 1578 | ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, |
| 1579 | ZFCP_REQ_AUTO_CLEANUP, |
| 1580 | NULL, &lock_flags, &fsf_req); |
| 1581 | if (ret < 0) { |
| 1582 | ZFCP_LOG_INFO("error: creation of ELS request failed " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1583 | "(adapter %s, port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1585 | goto failed_req; |
| 1586 | } |
| 1587 | |
Christof Schmitt | 3f0ca62 | 2007-12-20 12:30:25 +0100 | [diff] [blame] | 1588 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, |
| 1589 | &els->port->status))) { |
| 1590 | ret = -EBUSY; |
| 1591 | goto port_blocked; |
| 1592 | } |
| 1593 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1594 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | if (zfcp_use_one_sbal(els->req, els->req_count, |
| 1596 | els->resp, els->resp_count)){ |
| 1597 | /* both request buffer and response buffer |
| 1598 | fit into one sbale each */ |
| 1599 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; |
| 1600 | sbale[2].addr = zfcp_sg_to_address(&els->req[0]); |
| 1601 | sbale[2].length = els->req[0].length; |
| 1602 | sbale[3].addr = zfcp_sg_to_address(&els->resp[0]); |
| 1603 | sbale[3].length = els->resp[0].length; |
| 1604 | sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1605 | } else if (adapter->adapter_features & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | FSF_FEATURE_ELS_CT_CHAINED_SBALS) { |
| 1607 | /* try to use chained SBALs */ |
| 1608 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, |
| 1609 | SBAL_FLAGS0_TYPE_WRITE_READ, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1610 | els->req, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | ZFCP_MAX_SBALS_PER_ELS_REQ); |
| 1612 | if (bytes <= 0) { |
| 1613 | ZFCP_LOG_INFO("error: creation of ELS request failed " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1614 | "(adapter %s, port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1616 | if (bytes == 0) { |
| 1617 | ret = -ENOMEM; |
| 1618 | } else { |
| 1619 | ret = bytes; |
| 1620 | } |
| 1621 | goto failed_send; |
| 1622 | } |
| 1623 | fsf_req->qtcb->bottom.support.req_buf_length = bytes; |
| 1624 | fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; |
| 1625 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, |
| 1626 | SBAL_FLAGS0_TYPE_WRITE_READ, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1627 | els->resp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | ZFCP_MAX_SBALS_PER_ELS_REQ); |
| 1629 | if (bytes <= 0) { |
| 1630 | ZFCP_LOG_INFO("error: creation of ELS request failed " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1631 | "(adapter %s, port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1633 | if (bytes == 0) { |
| 1634 | ret = -ENOMEM; |
| 1635 | } else { |
| 1636 | ret = bytes; |
| 1637 | } |
| 1638 | goto failed_send; |
| 1639 | } |
| 1640 | fsf_req->qtcb->bottom.support.resp_buf_length = bytes; |
| 1641 | } else { |
| 1642 | /* reject request */ |
| 1643 | ZFCP_LOG_INFO("error: microcode does not support chained SBALs" |
| 1644 | ", ELS request too big (adapter %s, " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1645 | "port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1647 | ret = -EOPNOTSUPP; |
| 1648 | goto failed_send; |
| 1649 | } |
| 1650 | |
| 1651 | /* settings in QTCB */ |
| 1652 | fsf_req->qtcb->bottom.support.d_id = d_id; |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 1653 | fsf_req->qtcb->bottom.support.service_class = |
| 1654 | ZFCP_FC_SERVICE_CLASS_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1656 | fsf_req->data = (unsigned long) els; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1658 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1660 | zfcp_san_dbf_event_els_request(fsf_req); |
| 1661 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1662 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1663 | ret = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | if (ret) { |
| 1665 | ZFCP_LOG_DEBUG("error: initiation of ELS request failed " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1666 | "(adapter %s, port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1668 | goto failed_send; |
| 1669 | } |
| 1670 | |
| 1671 | ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1672 | "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | goto out; |
| 1674 | |
Christof Schmitt | 3f0ca62 | 2007-12-20 12:30:25 +0100 | [diff] [blame] | 1675 | port_blocked: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | failed_send: |
| 1677 | zfcp_fsf_req_free(fsf_req); |
| 1678 | |
| 1679 | failed_req: |
| 1680 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1681 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
| 1683 | return ret; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * zfcp_fsf_send_els_handler - handler for ELS commands |
| 1688 | * @fsf_req: pointer to struct zfcp_fsf_req |
| 1689 | * |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1690 | * Data specific for the ELS command is passed using |
| 1691 | * fsf_req->data. There we find the pointer to struct zfcp_send_els. |
| 1692 | * Usually a specific handler for the ELS command is called which is |
| 1693 | * found in this structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | */ |
| 1695 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req) |
| 1696 | { |
| 1697 | struct zfcp_adapter *adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | struct zfcp_port *port; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 1699 | u32 d_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | struct fsf_qtcb_header *header; |
| 1701 | struct fsf_qtcb_bottom_support *bottom; |
| 1702 | struct zfcp_send_els *send_els; |
| 1703 | int retval = -EINVAL; |
| 1704 | u16 subtable, rule, counter; |
| 1705 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1706 | send_els = (struct zfcp_send_els *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | adapter = send_els->adapter; |
Andreas Herrmann | 64b29a13 | 2005-06-13 13:18:56 +0200 | [diff] [blame] | 1708 | port = send_els->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | d_id = send_els->d_id; |
| 1710 | header = &fsf_req->qtcb->header; |
| 1711 | bottom = &fsf_req->qtcb->bottom.support; |
| 1712 | |
| 1713 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1714 | goto skip_fsfstatus; |
| 1715 | |
| 1716 | switch (header->fsf_status) { |
| 1717 | |
| 1718 | case FSF_GOOD: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1719 | zfcp_san_dbf_event_els_response(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | retval = 0; |
| 1721 | break; |
| 1722 | |
| 1723 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 1724 | ZFCP_LOG_INFO("error: adapter %s does not support fc " |
| 1725 | "class %d.\n", |
| 1726 | zfcp_get_busid_by_adapter(adapter), |
| 1727 | ZFCP_FC_SERVICE_CLASS_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | /* stop operation for this adapter */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1729 | zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1731 | break; |
| 1732 | |
| 1733 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | switch (header->fsf_status_qual.word[0]){ |
| 1735 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Andreas Herrmann | 64b29a13 | 2005-06-13 13:18:56 +0200 | [diff] [blame] | 1736 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
| 1737 | zfcp_test_link(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1739 | break; |
| 1740 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | break; |
| 1743 | case FSF_SQ_RETRY_IF_POSSIBLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1745 | break; |
| 1746 | default: |
| 1747 | ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n", |
| 1748 | header->fsf_status_qual.word[0]); |
| 1749 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, |
| 1750 | (char*)header->fsf_status_qual.word, 16); |
| 1751 | } |
| 1752 | break; |
| 1753 | |
| 1754 | case FSF_ELS_COMMAND_REJECTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | ZFCP_LOG_INFO("ELS has been rejected because command filter " |
| 1756 | "prohibited sending " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1757 | "(adapter: %s, port d_id: 0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1759 | |
| 1760 | break; |
| 1761 | |
| 1762 | case FSF_PAYLOAD_SIZE_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | ZFCP_LOG_INFO( |
| 1764 | "ELS request size and ELS response size must be either " |
| 1765 | "both 0, or both greater than 0 " |
| 1766 | "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n", |
| 1767 | zfcp_get_busid_by_adapter(adapter), |
| 1768 | bottom->req_buf_length, |
| 1769 | bottom->resp_buf_length); |
| 1770 | break; |
| 1771 | |
| 1772 | case FSF_REQUEST_SIZE_TOO_LARGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | ZFCP_LOG_INFO( |
| 1774 | "Length of the ELS request buffer, " |
| 1775 | "specified in QTCB bottom, " |
| 1776 | "exceeds the size of the buffers " |
| 1777 | "that have been allocated for ELS request data " |
| 1778 | "(adapter: %s, req_buf_length=%d)\n", |
| 1779 | zfcp_get_busid_by_adapter(adapter), |
| 1780 | bottom->req_buf_length); |
| 1781 | break; |
| 1782 | |
| 1783 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | ZFCP_LOG_INFO( |
| 1785 | "Length of the ELS response buffer, " |
| 1786 | "specified in QTCB bottom, " |
| 1787 | "exceeds the size of the buffers " |
| 1788 | "that have been allocated for ELS response data " |
| 1789 | "(adapter: %s, resp_buf_length=%d)\n", |
| 1790 | zfcp_get_busid_by_adapter(adapter), |
| 1791 | bottom->resp_buf_length); |
| 1792 | break; |
| 1793 | |
| 1794 | case FSF_SBAL_MISMATCH: |
| 1795 | /* should never occure, avoided in zfcp_fsf_send_els */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, " |
| 1797 | "resp_buf_length=%d)\n", |
| 1798 | zfcp_get_busid_by_adapter(adapter), |
| 1799 | bottom->req_buf_length, bottom->resp_buf_length); |
| 1800 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1801 | break; |
| 1802 | |
| 1803 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | ZFCP_LOG_NORMAL("access denied, cannot send ELS command " |
Christof Schmitt | 1d589ed | 2007-05-08 11:14:41 +0200 | [diff] [blame] | 1805 | "(adapter %s, port d_id=0x%06x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | zfcp_get_busid_by_adapter(adapter), d_id); |
| 1807 | for (counter = 0; counter < 2; counter++) { |
| 1808 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 1809 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 1810 | switch (subtable) { |
| 1811 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 1812 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 1813 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 1814 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 1815 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 1816 | zfcp_act_subtable_type[subtable], rule); |
| 1817 | break; |
| 1818 | } |
| 1819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | if (port != NULL) |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1821 | zfcp_erp_port_access_denied(port, 56, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1823 | break; |
| 1824 | |
| 1825 | default: |
| 1826 | ZFCP_LOG_NORMAL( |
| 1827 | "bug: An unknown FSF Status was presented " |
| 1828 | "(adapter: %s, fsf_status=0x%08x)\n", |
| 1829 | zfcp_get_busid_by_adapter(adapter), |
| 1830 | header->fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | skip_fsfstatus: |
| 1836 | send_els->status = retval; |
| 1837 | |
Heiko Carstens | aa551da | 2007-07-18 10:55:10 +0200 | [diff] [blame] | 1838 | if (send_els->handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | send_els->handler(send_els->handler_data); |
| 1840 | |
| 1841 | return retval; |
| 1842 | } |
| 1843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | int |
| 1845 | zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
| 1846 | { |
| 1847 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1848 | struct zfcp_fsf_req *fsf_req; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1849 | struct zfcp_adapter *adapter = erp_action->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | unsigned long lock_flags; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1851 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* setup new FSF request */ |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1854 | retval = zfcp_fsf_req_create(adapter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | FSF_QTCB_EXCHANGE_CONFIG_DATA, |
| 1856 | ZFCP_REQ_AUTO_CLEANUP, |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1857 | adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1858 | &lock_flags, &fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1859 | if (retval) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | ZFCP_LOG_INFO("error: Could not create exchange configuration " |
| 1861 | "data request for adapter %s.\n", |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1862 | zfcp_get_busid_by_adapter(adapter)); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1863 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1864 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1867 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1868 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1869 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1871 | fsf_req->qtcb->bottom.config.feature_selection = |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1872 | FSF_FEATURE_CFDC | |
| 1873 | FSF_FEATURE_LUN_SHARING | |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 1874 | FSF_FEATURE_NOTIFICATION_LOST | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1875 | FSF_FEATURE_UPDATE_ALERT; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1876 | fsf_req->erp_action = erp_action; |
| 1877 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1879 | zfcp_erp_start_timer(fsf_req); |
| 1880 | retval = zfcp_fsf_req_send(fsf_req); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1881 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | if (retval) { |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1883 | ZFCP_LOG_INFO("error: Could not send exchange configuration " |
| 1884 | "data command on the adapter %s\n", |
| 1885 | zfcp_get_busid_by_adapter(adapter)); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 1886 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | erp_action->fsf_req = NULL; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1888 | } |
| 1889 | else |
| 1890 | ZFCP_LOG_DEBUG("exchange configuration data request initiated " |
| 1891 | "(adapter %s)\n", |
| 1892 | zfcp_get_busid_by_adapter(adapter)); |
| 1893 | |
| 1894 | return retval; |
| 1895 | } |
| 1896 | |
| 1897 | int |
| 1898 | zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, |
| 1899 | struct fsf_qtcb_bottom_config *data) |
| 1900 | { |
| 1901 | volatile struct qdio_buffer_element *sbale; |
| 1902 | struct zfcp_fsf_req *fsf_req; |
| 1903 | unsigned long lock_flags; |
| 1904 | int retval; |
| 1905 | |
| 1906 | /* setup new FSF request */ |
| 1907 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
Swen Schillig | aee6ef1 | 2008-04-24 19:35:52 +0200 | [diff] [blame] | 1908 | ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags, |
| 1909 | &fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1910 | if (retval) { |
| 1911 | ZFCP_LOG_INFO("error: Could not create exchange configuration " |
| 1912 | "data request for adapter %s.\n", |
| 1913 | zfcp_get_busid_by_adapter(adapter)); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1914 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1915 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1918 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1919 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1920 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1922 | fsf_req->qtcb->bottom.config.feature_selection = |
| 1923 | FSF_FEATURE_CFDC | |
| 1924 | FSF_FEATURE_LUN_SHARING | |
| 1925 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1926 | FSF_FEATURE_UPDATE_ALERT; |
| 1927 | |
| 1928 | if (data) |
| 1929 | fsf_req->data = (unsigned long) data; |
| 1930 | |
| 1931 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1932 | retval = zfcp_fsf_req_send(fsf_req); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 1933 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1934 | if (retval) |
| 1935 | ZFCP_LOG_INFO("error: Could not send exchange configuration " |
| 1936 | "data command on the adapter %s\n", |
| 1937 | zfcp_get_busid_by_adapter(adapter)); |
| 1938 | else |
| 1939 | wait_event(fsf_req->completion_wq, |
| 1940 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 1941 | |
| 1942 | zfcp_fsf_req_free(fsf_req); |
| 1943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | return retval; |
| 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * zfcp_fsf_exchange_config_evaluate |
| 1949 | * @fsf_req: fsf_req which belongs to xchg config data request |
| 1950 | * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1) |
| 1951 | * |
| 1952 | * returns: -EIO on error, 0 otherwise |
| 1953 | */ |
| 1954 | static int |
| 1955 | zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok) |
| 1956 | { |
| 1957 | struct fsf_qtcb_bottom_config *bottom; |
| 1958 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 1959 | struct Scsi_Host *shost = adapter->scsi_host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
| 1961 | bottom = &fsf_req->qtcb->bottom.config; |
| 1962 | ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n", |
| 1963 | bottom->low_qtcb_version, bottom->high_qtcb_version); |
| 1964 | adapter->fsf_lic_version = bottom->lic_version; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1965 | adapter->adapter_features = bottom->adapter_features; |
| 1966 | adapter->connection_features = bottom->connection_features; |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 1967 | adapter->peer_wwpn = 0; |
| 1968 | adapter->peer_wwnn = 0; |
| 1969 | adapter->peer_d_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
| 1971 | if (xchg_ok) { |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1972 | |
| 1973 | if (fsf_req->data) |
| 1974 | memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data, |
| 1975 | bottom, sizeof (struct fsf_qtcb_bottom_config)); |
| 1976 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 1977 | fc_host_node_name(shost) = bottom->nport_serv_param.wwnn; |
| 1978 | fc_host_port_name(shost) = bottom->nport_serv_param.wwpn; |
| 1979 | fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK; |
| 1980 | fc_host_speed(shost) = bottom->fc_link_speed; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 1981 | fc_host_supported_classes(shost) = |
| 1982 | FC_COS_CLASS2 | FC_COS_CLASS3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | adapter->hydra_version = bottom->adapter_type; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1984 | adapter->timer_ticks = bottom->timer_interval; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 1985 | if (fc_host_permanent_port_name(shost) == -1) |
| 1986 | fc_host_permanent_port_name(shost) = |
| 1987 | fc_host_port_name(shost); |
| 1988 | if (bottom->fc_topology == FSF_TOPO_P2P) { |
| 1989 | adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; |
| 1990 | adapter->peer_wwpn = bottom->plogi_payload.wwpn; |
| 1991 | adapter->peer_wwnn = bottom->plogi_payload.wwnn; |
| 1992 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
| 1993 | } else if (bottom->fc_topology == FSF_TOPO_FABRIC) |
| 1994 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 1995 | else if (bottom->fc_topology == FSF_TOPO_AL) |
| 1996 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
| 1997 | else |
| 1998 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | } else { |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2000 | fc_host_node_name(shost) = 0; |
| 2001 | fc_host_port_name(shost) = 0; |
| 2002 | fc_host_port_id(shost) = 0; |
| 2003 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 2004 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | adapter->hydra_version = 0; |
| 2006 | } |
| 2007 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2008 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | adapter->hardware_version = bottom->hardware_version; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2010 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
| 2011 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
| 2012 | EBCASC(fc_host_serial_number(shost), |
| 2013 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Swen Schillig | ec258fe | 2008-04-24 19:35:53 +0200 | [diff] [blame] | 2016 | if (fsf_req->erp_action) |
| 2017 | ZFCP_LOG_NORMAL("The adapter %s reported the following " |
| 2018 | "characteristics:\n" |
| 2019 | "WWNN 0x%016Lx, WWPN 0x%016Lx, " |
| 2020 | "S_ID 0x%06x,\n" |
| 2021 | "adapter version 0x%x, " |
| 2022 | "LIC version 0x%x, " |
| 2023 | "FC link speed %d Gb/s\n", |
| 2024 | zfcp_get_busid_by_adapter(adapter), |
| 2025 | (wwn_t) fc_host_node_name(shost), |
| 2026 | (wwn_t) fc_host_port_name(shost), |
| 2027 | fc_host_port_id(shost), |
| 2028 | adapter->hydra_version, |
| 2029 | adapter->fsf_lic_version, |
| 2030 | fc_host_speed(shost)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) { |
| 2032 | ZFCP_LOG_NORMAL("error: the adapter %s " |
| 2033 | "only supports newer control block " |
| 2034 | "versions in comparison to this device " |
| 2035 | "driver (try updated device driver)\n", |
| 2036 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2037 | zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | return -EIO; |
| 2039 | } |
| 2040 | if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) { |
| 2041 | ZFCP_LOG_NORMAL("error: the adapter %s " |
| 2042 | "only supports older control block " |
| 2043 | "versions than this device driver uses" |
| 2044 | "(consider a microcode upgrade)\n", |
| 2045 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2046 | zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | return -EIO; |
| 2048 | } |
| 2049 | return 0; |
| 2050 | } |
| 2051 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2052 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | * function: zfcp_fsf_exchange_config_data_handler |
| 2054 | * |
| 2055 | * purpose: is called for finished Exchange Configuration Data command |
| 2056 | * |
| 2057 | * returns: |
| 2058 | */ |
| 2059 | static int |
| 2060 | zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req) |
| 2061 | { |
| 2062 | struct fsf_qtcb_bottom_config *bottom; |
| 2063 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2064 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | |
| 2066 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 2067 | return -EIO; |
| 2068 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2069 | switch (qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | |
| 2071 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1)) |
| 2073 | return -EIO; |
| 2074 | |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 2075 | switch (fc_host_port_type(adapter->scsi_host)) { |
| 2076 | case FC_PORTTYPE_PTP: |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2077 | ZFCP_LOG_NORMAL("Point-to-Point fibrechannel " |
| 2078 | "configuration detected at adapter %s\n" |
| 2079 | "Peer WWNN 0x%016llx, " |
| 2080 | "peer WWPN 0x%016llx, " |
| 2081 | "peer d_id 0x%06x\n", |
| 2082 | zfcp_get_busid_by_adapter(adapter), |
| 2083 | adapter->peer_wwnn, |
| 2084 | adapter->peer_wwpn, |
| 2085 | adapter->peer_d_id); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2086 | break; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 2087 | case FC_PORTTYPE_NLPORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel " |
| 2089 | "topology detected at adapter %s " |
| 2090 | "unsupported, shutting down adapter\n", |
| 2091 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2092 | zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | return -EIO; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 2094 | case FC_PORTTYPE_NPORT: |
Swen Schillig | ec258fe | 2008-04-24 19:35:53 +0200 | [diff] [blame] | 2095 | if (fsf_req->erp_action) |
| 2096 | ZFCP_LOG_NORMAL("Switched fabric fibrechannel " |
| 2097 | "network detected at adapter " |
| 2098 | "%s.\n", |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2099 | zfcp_get_busid_by_adapter(adapter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | break; |
| 2101 | default: |
| 2102 | ZFCP_LOG_NORMAL("bug: The fibrechannel topology " |
| 2103 | "reported by the exchange " |
| 2104 | "configuration command for " |
| 2105 | "the adapter %s is not " |
| 2106 | "of a type known to the zfcp " |
| 2107 | "driver, shutting down adapter\n", |
| 2108 | zfcp_get_busid_by_adapter(adapter)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2109 | zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | return -EIO; |
| 2111 | } |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2112 | bottom = &qtcb->bottom.config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
| 2114 | ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) " |
| 2115 | "allowed by the adapter %s " |
| 2116 | "is lower than the minimum " |
| 2117 | "required by the driver (%ld bytes).\n", |
| 2118 | bottom->max_qtcb_size, |
| 2119 | zfcp_get_busid_by_adapter(adapter), |
| 2120 | sizeof(struct fsf_qtcb)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2121 | zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | return -EIO; |
| 2123 | } |
| 2124 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
| 2125 | &adapter->status); |
| 2126 | break; |
| 2127 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0)) |
| 2129 | return -EIO; |
| 2130 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2131 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
| 2132 | &adapter->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2133 | |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 2134 | zfcp_fsf_link_down_info_eval(fsf_req, 42, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2135 | &qtcb->header.fsf_status_qual.link_down_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | break; |
| 2137 | default: |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2138 | zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | return -EIO; |
| 2140 | } |
| 2141 | return 0; |
| 2142 | } |
| 2143 | |
| 2144 | /** |
| 2145 | * zfcp_fsf_exchange_port_data - request information about local port |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2146 | * @erp_action: ERP action for the adapter for which port data is requested |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | */ |
| 2148 | int |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2149 | zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | { |
| 2151 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2152 | struct zfcp_fsf_req *fsf_req; |
| 2153 | struct zfcp_adapter *adapter = erp_action->adapter; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2154 | unsigned long lock_flags; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2155 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2157 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | ZFCP_LOG_INFO("error: exchange port data " |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2159 | "command not supported by adapter %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | zfcp_get_busid_by_adapter(adapter)); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2161 | return -EOPNOTSUPP; |
| 2162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | /* setup new FSF request */ |
| 2165 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2166 | ZFCP_REQ_AUTO_CLEANUP, |
| 2167 | adapter->pool.fsf_req_erp, |
| 2168 | &lock_flags, &fsf_req); |
| 2169 | if (retval) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | ZFCP_LOG_INFO("error: Out of resources. Could not create an " |
Joe Perches | ceb3dfb | 2008-01-26 14:11:10 +0100 | [diff] [blame] | 2171 | "exchange port data request for " |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2172 | "the adapter %s.\n", |
| 2173 | zfcp_get_busid_by_adapter(adapter)); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2174 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2175 | return retval; |
| 2176 | } |
| 2177 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2178 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2179 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2180 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2181 | |
| 2182 | erp_action->fsf_req = fsf_req; |
| 2183 | fsf_req->erp_action = erp_action; |
| 2184 | zfcp_erp_start_timer(fsf_req); |
| 2185 | |
| 2186 | retval = zfcp_fsf_req_send(fsf_req); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2187 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2188 | |
| 2189 | if (retval) { |
| 2190 | ZFCP_LOG_INFO("error: Could not send an exchange port data " |
| 2191 | "command on the adapter %s\n", |
| 2192 | zfcp_get_busid_by_adapter(adapter)); |
| 2193 | zfcp_fsf_req_free(fsf_req); |
| 2194 | erp_action->fsf_req = NULL; |
| 2195 | } |
| 2196 | else |
| 2197 | ZFCP_LOG_DEBUG("exchange port data request initiated " |
| 2198 | "(adapter %s)\n", |
| 2199 | zfcp_get_busid_by_adapter(adapter)); |
| 2200 | return retval; |
| 2201 | } |
| 2202 | |
| 2203 | |
| 2204 | /** |
| 2205 | * zfcp_fsf_exchange_port_data_sync - request information about local port |
| 2206 | * and wait until information is ready |
| 2207 | */ |
| 2208 | int |
| 2209 | zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, |
| 2210 | struct fsf_qtcb_bottom_port *data) |
| 2211 | { |
| 2212 | volatile struct qdio_buffer_element *sbale; |
| 2213 | struct zfcp_fsf_req *fsf_req; |
| 2214 | unsigned long lock_flags; |
| 2215 | int retval; |
| 2216 | |
| 2217 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) { |
| 2218 | ZFCP_LOG_INFO("error: exchange port data " |
| 2219 | "command not supported by adapter %s\n", |
| 2220 | zfcp_get_busid_by_adapter(adapter)); |
| 2221 | return -EOPNOTSUPP; |
| 2222 | } |
| 2223 | |
| 2224 | /* setup new FSF request */ |
| 2225 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
| 2226 | 0, NULL, &lock_flags, &fsf_req); |
| 2227 | if (retval) { |
| 2228 | ZFCP_LOG_INFO("error: Out of resources. Could not create an " |
Joe Perches | ceb3dfb | 2008-01-26 14:11:10 +0100 | [diff] [blame] | 2229 | "exchange port data request for " |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2230 | "the adapter %s.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | zfcp_get_busid_by_adapter(adapter)); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2232 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2233 | return retval; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | if (data) |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2237 | fsf_req->data = (unsigned long) data; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2238 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2239 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2240 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2241 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2243 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2244 | retval = zfcp_fsf_req_send(fsf_req); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2245 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2247 | if (retval) |
| 2248 | ZFCP_LOG_INFO("error: Could not send an exchange port data " |
| 2249 | "command on the adapter %s\n", |
| 2250 | zfcp_get_busid_by_adapter(adapter)); |
| 2251 | else |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2252 | wait_event(fsf_req->completion_wq, |
| 2253 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2254 | |
| 2255 | zfcp_fsf_req_free(fsf_req); |
| 2256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | return retval; |
| 2258 | } |
| 2259 | |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2260 | /** |
| 2261 | * zfcp_fsf_exchange_port_evaluate |
| 2262 | * @fsf_req: fsf_req which belongs to xchg port data request |
| 2263 | * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1) |
| 2264 | */ |
| 2265 | static void |
| 2266 | zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok) |
| 2267 | { |
| 2268 | struct zfcp_adapter *adapter; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2269 | struct fsf_qtcb_bottom_port *bottom; |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2270 | struct Scsi_Host *shost; |
| 2271 | |
| 2272 | adapter = fsf_req->adapter; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2273 | bottom = &fsf_req->qtcb->bottom.port; |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2274 | shost = adapter->scsi_host; |
| 2275 | |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 2276 | if (fsf_req->data) |
| 2277 | memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom, |
| 2278 | sizeof(struct fsf_qtcb_bottom_port)); |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2279 | |
| 2280 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 2281 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
| 2282 | else |
| 2283 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
| 2284 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; |
| 2285 | fc_host_supported_speeds(shost) = bottom->supported_speed; |
| 2286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | |
| 2288 | /** |
| 2289 | * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request |
| 2290 | * @fsf_req: pointer to struct zfcp_fsf_req |
| 2291 | */ |
| 2292 | static void |
| 2293 | zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req) |
| 2294 | { |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2295 | struct zfcp_adapter *adapter; |
| 2296 | struct fsf_qtcb *qtcb; |
| 2297 | |
| 2298 | adapter = fsf_req->adapter; |
| 2299 | qtcb = fsf_req->qtcb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | |
| 2301 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 2302 | return; |
| 2303 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2304 | switch (qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | case FSF_GOOD: |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2306 | zfcp_fsf_exchange_port_evaluate(fsf_req, 1); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2307 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2308 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2309 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 2310 | zfcp_fsf_exchange_port_evaluate(fsf_req, 0); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2311 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 2312 | zfcp_fsf_link_down_info_eval(fsf_req, 43, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2313 | &qtcb->header.fsf_status_qual.link_down_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | |
| 2319 | /* |
| 2320 | * function: zfcp_fsf_open_port |
| 2321 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 2322 | * purpose: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | * |
| 2324 | * returns: address of initiated FSF request |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 2325 | * NULL - request could not be initiated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | */ |
| 2327 | int |
| 2328 | zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
| 2329 | { |
| 2330 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2331 | struct zfcp_fsf_req *fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | unsigned long lock_flags; |
| 2333 | int retval = 0; |
| 2334 | |
| 2335 | /* setup new FSF request */ |
| 2336 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2337 | FSF_QTCB_OPEN_PORT_WITH_DID, |
| 2338 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2339 | erp_action->adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2340 | &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | if (retval < 0) { |
| 2342 | ZFCP_LOG_INFO("error: Could not create open port request " |
| 2343 | "for port 0x%016Lx on adapter %s.\n", |
| 2344 | erp_action->port->wwpn, |
| 2345 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2346 | goto out; |
| 2347 | } |
| 2348 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2349 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2351 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2352 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2353 | fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2355 | fsf_req->data = (unsigned long) erp_action->port; |
| 2356 | fsf_req->erp_action = erp_action; |
| 2357 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2359 | zfcp_erp_start_timer(fsf_req); |
| 2360 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | if (retval) { |
| 2362 | ZFCP_LOG_INFO("error: Could not send open port request for " |
| 2363 | "port 0x%016Lx on adapter %s.\n", |
| 2364 | erp_action->port->wwpn, |
| 2365 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2366 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | erp_action->fsf_req = NULL; |
| 2368 | goto out; |
| 2369 | } |
| 2370 | |
| 2371 | ZFCP_LOG_DEBUG("open port request initiated " |
| 2372 | "(adapter %s, port 0x%016Lx)\n", |
| 2373 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2374 | erp_action->port->wwpn); |
| 2375 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2376 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | return retval; |
| 2378 | } |
| 2379 | |
| 2380 | /* |
| 2381 | * function: zfcp_fsf_open_port_handler |
| 2382 | * |
| 2383 | * purpose: is called for finished Open Port command |
| 2384 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 2385 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | */ |
| 2387 | static int |
| 2388 | zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2389 | { |
| 2390 | int retval = -EINVAL; |
| 2391 | struct zfcp_port *port; |
| 2392 | struct fsf_plogi *plogi; |
| 2393 | struct fsf_qtcb_header *header; |
| 2394 | u16 subtable, rule, counter; |
| 2395 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2396 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | header = &fsf_req->qtcb->header; |
| 2398 | |
| 2399 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2400 | /* don't change port status in our bookkeeping */ |
| 2401 | goto skip_fsfstatus; |
| 2402 | } |
| 2403 | |
| 2404 | /* evaluate FSF status in QTCB */ |
| 2405 | switch (header->fsf_status) { |
| 2406 | |
| 2407 | case FSF_PORT_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s " |
| 2409 | "is already open.\n", |
| 2410 | port->wwpn, zfcp_get_busid_by_port(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | /* |
| 2412 | * This is a bug, however operation should continue normally |
| 2413 | * if it is simply ignored |
| 2414 | */ |
| 2415 | break; |
| 2416 | |
| 2417 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx " |
| 2419 | "on adapter %s\n", |
| 2420 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2421 | for (counter = 0; counter < 2; counter++) { |
| 2422 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 2423 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 2424 | switch (subtable) { |
| 2425 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 2426 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 2427 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 2428 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 2429 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 2430 | zfcp_act_subtable_type[subtable], rule); |
| 2431 | break; |
| 2432 | } |
| 2433 | } |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2434 | zfcp_erp_port_access_denied(port, 57, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2436 | break; |
| 2437 | |
| 2438 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | ZFCP_LOG_INFO("error: The FSF adapter is out of resources. " |
| 2440 | "The remote port 0x%016Lx on adapter %s " |
| 2441 | "could not be opened. Disabling it.\n", |
| 2442 | port->wwpn, zfcp_get_busid_by_port(port)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2443 | zfcp_erp_port_failed(port, 31, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2445 | break; |
| 2446 | |
| 2447 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | switch (header->fsf_status_qual.word[0]) { |
| 2449 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | /* ERP strategy will escalate */ |
| 2451 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2452 | break; |
| 2453 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 2454 | /* ERP strategy will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2456 | break; |
| 2457 | case FSF_SQ_NO_RETRY_POSSIBLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | ZFCP_LOG_NORMAL("The remote port 0x%016Lx on " |
| 2459 | "adapter %s could not be opened. " |
| 2460 | "Disabling it.\n", |
| 2461 | port->wwpn, |
| 2462 | zfcp_get_busid_by_port(port)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2463 | zfcp_erp_port_failed(port, 32, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2465 | break; |
| 2466 | default: |
| 2467 | ZFCP_LOG_NORMAL |
| 2468 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 2469 | header->fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | break; |
| 2471 | } |
| 2472 | break; |
| 2473 | |
| 2474 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | /* save port handle assigned by FSF */ |
| 2476 | port->handle = header->port_handle; |
| 2477 | ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s " |
| 2478 | "was opened, it's port handle is 0x%x\n", |
| 2479 | port->wwpn, zfcp_get_busid_by_port(port), |
| 2480 | port->handle); |
| 2481 | /* mark port as open */ |
| 2482 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
| 2483 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 2484 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 2485 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
| 2486 | &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | retval = 0; |
| 2488 | /* check whether D_ID has changed during open */ |
| 2489 | /* |
| 2490 | * FIXME: This check is not airtight, as the FCP channel does |
| 2491 | * not monitor closures of target port connections caused on |
| 2492 | * the remote side. Thus, they might miss out on invalidating |
| 2493 | * locally cached WWPNs (and other N_Port parameters) of gone |
| 2494 | * target ports. So, our heroic attempt to make things safe |
| 2495 | * could be undermined by 'open port' response data tagged with |
| 2496 | * obsolete WWPNs. Another reason to monitor potential |
| 2497 | * connection closures ourself at least (by interpreting |
| 2498 | * incoming ELS' and unsolicited status). It just crosses my |
| 2499 | * mind that one should be able to cross-check by means of |
| 2500 | * another GID_PN straight after a port has been opened. |
| 2501 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
| 2502 | */ |
| 2503 | plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els; |
| 2504 | if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status)) |
| 2505 | { |
| 2506 | if (fsf_req->qtcb->bottom.support.els1_length < |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 2507 | sizeof (struct fsf_plogi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | ZFCP_LOG_INFO( |
| 2509 | "warning: insufficient length of " |
| 2510 | "PLOGI payload (%i)\n", |
| 2511 | fsf_req->qtcb->bottom.support.els1_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | /* skip sanity check and assume wwpn is ok */ |
| 2513 | } else { |
| 2514 | if (plogi->serv_param.wwpn != port->wwpn) { |
| 2515 | ZFCP_LOG_INFO("warning: d_id of port " |
| 2516 | "0x%016Lx changed during " |
| 2517 | "open\n", port->wwpn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | atomic_clear_mask( |
| 2519 | ZFCP_STATUS_PORT_DID_DID, |
| 2520 | &port->status); |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 2521 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | port->wwnn = plogi->serv_param.wwnn; |
Christof Schmitt | 24073b4 | 2008-06-10 18:20:54 +0200 | [diff] [blame] | 2523 | zfcp_fc_plogi_evaluate(port, plogi); |
Ralph Wuerthner | 75bfc28 | 2006-05-22 18:24:33 +0200 | [diff] [blame] | 2524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | break; |
| 2528 | |
| 2529 | case FSF_UNKNOWN_OP_SUBTYPE: |
| 2530 | /* should never occure, subtype not set in zfcp_fsf_open_port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, " |
| 2532 | "op_subtype=0x%x)\n", |
| 2533 | zfcp_get_busid_by_port(port), |
| 2534 | fsf_req->qtcb->bottom.support.operation_subtype); |
| 2535 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2536 | break; |
| 2537 | |
| 2538 | default: |
| 2539 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2540 | "(debug info 0x%x)\n", |
| 2541 | header->fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | break; |
| 2543 | } |
| 2544 | |
| 2545 | skip_fsfstatus: |
| 2546 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); |
| 2547 | return retval; |
| 2548 | } |
| 2549 | |
| 2550 | /* |
| 2551 | * function: zfcp_fsf_close_port |
| 2552 | * |
| 2553 | * purpose: submit FSF command "close port" |
| 2554 | * |
| 2555 | * returns: address of initiated FSF request |
| 2556 | * NULL - request could not be initiated |
| 2557 | */ |
| 2558 | int |
| 2559 | zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
| 2560 | { |
| 2561 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2562 | struct zfcp_fsf_req *fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | unsigned long lock_flags; |
| 2564 | int retval = 0; |
| 2565 | |
| 2566 | /* setup new FSF request */ |
| 2567 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2568 | FSF_QTCB_CLOSE_PORT, |
| 2569 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2570 | erp_action->adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2571 | &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | if (retval < 0) { |
| 2573 | ZFCP_LOG_INFO("error: Could not create a close port request " |
| 2574 | "for port 0x%016Lx on adapter %s.\n", |
| 2575 | erp_action->port->wwpn, |
| 2576 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2577 | goto out; |
| 2578 | } |
| 2579 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2580 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2582 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2583 | |
| 2584 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2585 | fsf_req->data = (unsigned long) erp_action->port; |
| 2586 | fsf_req->erp_action = erp_action; |
| 2587 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; |
| 2588 | fsf_req->erp_action = erp_action; |
| 2589 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2591 | zfcp_erp_start_timer(fsf_req); |
| 2592 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | if (retval) { |
| 2594 | ZFCP_LOG_INFO("error: Could not send a close port request for " |
| 2595 | "port 0x%016Lx on adapter %s.\n", |
| 2596 | erp_action->port->wwpn, |
| 2597 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2598 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | erp_action->fsf_req = NULL; |
| 2600 | goto out; |
| 2601 | } |
| 2602 | |
| 2603 | ZFCP_LOG_TRACE("close port request initiated " |
| 2604 | "(adapter %s, port 0x%016Lx)\n", |
| 2605 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2606 | erp_action->port->wwpn); |
| 2607 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2608 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | return retval; |
| 2610 | } |
| 2611 | |
| 2612 | /* |
| 2613 | * function: zfcp_fsf_close_port_handler |
| 2614 | * |
| 2615 | * purpose: is called for finished Close Port FSF command |
| 2616 | * |
| 2617 | * returns: |
| 2618 | */ |
| 2619 | static int |
| 2620 | zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2621 | { |
| 2622 | int retval = -EINVAL; |
| 2623 | struct zfcp_port *port; |
| 2624 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2625 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | |
| 2627 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2628 | /* don't change port status in our bookkeeping */ |
| 2629 | goto skip_fsfstatus; |
| 2630 | } |
| 2631 | |
| 2632 | /* evaluate FSF status in QTCB */ |
| 2633 | switch (fsf_req->qtcb->header.fsf_status) { |
| 2634 | |
| 2635 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 2637 | "0x%016Lx on adapter %s invalid. This may happen " |
| 2638 | "occasionally.\n", port->handle, |
| 2639 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2640 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 2641 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 2642 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 2643 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2644 | zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2646 | break; |
| 2647 | |
| 2648 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | /* Note: FSF has actually closed the port in this case. |
| 2650 | * The status code is just daft. Fingers crossed for a change |
| 2651 | */ |
| 2652 | retval = 0; |
| 2653 | break; |
| 2654 | |
| 2655 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, " |
| 2657 | "port handle 0x%x\n", port->wwpn, |
| 2658 | zfcp_get_busid_by_port(port), port->handle); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2659 | zfcp_erp_modify_port_status(port, 33, fsf_req, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | ZFCP_STATUS_COMMON_OPEN, |
| 2661 | ZFCP_CLEAR); |
| 2662 | retval = 0; |
| 2663 | break; |
| 2664 | |
| 2665 | default: |
| 2666 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2667 | "(debug info 0x%x)\n", |
| 2668 | fsf_req->qtcb->header.fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | break; |
| 2670 | } |
| 2671 | |
| 2672 | skip_fsfstatus: |
| 2673 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); |
| 2674 | return retval; |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | * function: zfcp_fsf_close_physical_port |
| 2679 | * |
| 2680 | * purpose: submit FSF command "close physical port" |
| 2681 | * |
| 2682 | * returns: address of initiated FSF request |
| 2683 | * NULL - request could not be initiated |
| 2684 | */ |
| 2685 | int |
| 2686 | zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
| 2687 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2689 | struct zfcp_fsf_req *fsf_req; |
| 2690 | unsigned long lock_flags; |
| 2691 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
| 2693 | /* setup new FSF request */ |
| 2694 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2695 | FSF_QTCB_CLOSE_PHYSICAL_PORT, |
| 2696 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2697 | erp_action->adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2698 | &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | if (retval < 0) { |
| 2700 | ZFCP_LOG_INFO("error: Could not create close physical port " |
| 2701 | "request (adapter %s, port 0x%016Lx)\n", |
| 2702 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2703 | erp_action->port->wwpn); |
| 2704 | |
| 2705 | goto out; |
| 2706 | } |
| 2707 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2708 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2710 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2711 | |
| 2712 | /* mark port as being closed */ |
| 2713 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, |
| 2714 | &erp_action->port->status); |
| 2715 | /* save a pointer to this port */ |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2716 | fsf_req->data = (unsigned long) erp_action->port; |
| 2717 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; |
| 2718 | fsf_req->erp_action = erp_action; |
| 2719 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2721 | zfcp_erp_start_timer(fsf_req); |
| 2722 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | if (retval) { |
| 2724 | ZFCP_LOG_INFO("error: Could not send close physical port " |
| 2725 | "request (adapter %s, port 0x%016Lx)\n", |
| 2726 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2727 | erp_action->port->wwpn); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2728 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | erp_action->fsf_req = NULL; |
| 2730 | goto out; |
| 2731 | } |
| 2732 | |
| 2733 | ZFCP_LOG_TRACE("close physical port request initiated " |
| 2734 | "(adapter %s, port 0x%016Lx)\n", |
| 2735 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2736 | erp_action->port->wwpn); |
| 2737 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2738 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | return retval; |
| 2740 | } |
| 2741 | |
| 2742 | /* |
| 2743 | * function: zfcp_fsf_close_physical_port_handler |
| 2744 | * |
| 2745 | * purpose: is called for finished Close Physical Port FSF command |
| 2746 | * |
| 2747 | * returns: |
| 2748 | */ |
| 2749 | static int |
| 2750 | zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2751 | { |
| 2752 | int retval = -EINVAL; |
| 2753 | struct zfcp_port *port; |
| 2754 | struct zfcp_unit *unit; |
| 2755 | struct fsf_qtcb_header *header; |
| 2756 | u16 subtable, rule, counter; |
| 2757 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2758 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | header = &fsf_req->qtcb->header; |
| 2760 | |
| 2761 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2762 | /* don't change port status in our bookkeeping */ |
| 2763 | goto skip_fsfstatus; |
| 2764 | } |
| 2765 | |
| 2766 | /* evaluate FSF status in QTCB */ |
| 2767 | switch (header->fsf_status) { |
| 2768 | |
| 2769 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid" |
| 2771 | "(adapter %s, port 0x%016Lx). " |
| 2772 | "This may happen occasionally.\n", |
| 2773 | port->handle, |
| 2774 | zfcp_get_busid_by_port(port), |
| 2775 | port->wwpn); |
| 2776 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 2777 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 2778 | (char *) &header->fsf_status_qual, |
| 2779 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2780 | zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2782 | break; |
| 2783 | |
| 2784 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | ZFCP_LOG_NORMAL("Access denied, cannot close " |
| 2786 | "physical port 0x%016Lx on adapter %s\n", |
| 2787 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2788 | for (counter = 0; counter < 2; counter++) { |
| 2789 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 2790 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 2791 | switch (subtable) { |
| 2792 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 2793 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 2794 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 2795 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 2796 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 2797 | zfcp_act_subtable_type[subtable], rule); |
| 2798 | break; |
| 2799 | } |
| 2800 | } |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2801 | zfcp_erp_port_access_denied(port, 58, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2803 | break; |
| 2804 | |
| 2805 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter " |
| 2807 | "%s needs to be reopened but it was attempted " |
| 2808 | "to close it physically.\n", |
| 2809 | port->wwpn, |
| 2810 | zfcp_get_busid_by_port(port)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2811 | zfcp_erp_port_boxed(port, 50, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2813 | ZFCP_STATUS_FSFREQ_RETRY; |
Christof Schmitt | 5c815d1 | 2008-03-10 16:18:54 +0100 | [diff] [blame] | 2814 | |
| 2815 | /* can't use generic zfcp_erp_modify_port_status because |
| 2816 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ |
| 2817 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 2818 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 2819 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 2820 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | break; |
| 2822 | |
| 2823 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | switch (header->fsf_status_qual.word[0]) { |
| 2825 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | /* This will now be escalated by ERP */ |
| 2827 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2828 | break; |
| 2829 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | /* ERP strategy will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2832 | break; |
| 2833 | default: |
| 2834 | ZFCP_LOG_NORMAL |
| 2835 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 2836 | header->fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | break; |
| 2838 | } |
| 2839 | break; |
| 2840 | |
| 2841 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s " |
| 2843 | "physically closed, port handle 0x%x\n", |
| 2844 | port->wwpn, |
| 2845 | zfcp_get_busid_by_port(port), port->handle); |
| 2846 | /* can't use generic zfcp_erp_modify_port_status because |
| 2847 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
| 2848 | */ |
| 2849 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 2850 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 2851 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 2852 | retval = 0; |
| 2853 | break; |
| 2854 | |
| 2855 | default: |
| 2856 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2857 | "(debug info 0x%x)\n", |
| 2858 | header->fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | |
| 2862 | skip_fsfstatus: |
| 2863 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); |
| 2864 | return retval; |
| 2865 | } |
| 2866 | |
| 2867 | /* |
| 2868 | * function: zfcp_fsf_open_unit |
| 2869 | * |
| 2870 | * purpose: |
| 2871 | * |
| 2872 | * returns: |
| 2873 | * |
| 2874 | * assumptions: This routine does not check whether the associated |
| 2875 | * remote port has already been opened. This should be |
| 2876 | * done by calling routines. Otherwise some status |
| 2877 | * may be presented by FSF |
| 2878 | */ |
| 2879 | int |
| 2880 | zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
| 2881 | { |
| 2882 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2883 | struct zfcp_fsf_req *fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | unsigned long lock_flags; |
| 2885 | int retval = 0; |
| 2886 | |
| 2887 | /* setup new FSF request */ |
| 2888 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2889 | FSF_QTCB_OPEN_LUN, |
| 2890 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2891 | erp_action->adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2892 | &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | if (retval < 0) { |
| 2894 | ZFCP_LOG_INFO("error: Could not create open unit request for " |
| 2895 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", |
| 2896 | erp_action->unit->fcp_lun, |
| 2897 | erp_action->unit->port->wwpn, |
| 2898 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2899 | goto out; |
| 2900 | } |
| 2901 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2902 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2904 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2905 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2906 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; |
| 2907 | fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2908 | if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2909 | fsf_req->qtcb->bottom.support.option = |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 2910 | FSF_OPEN_LUN_SUPPRESS_BOXING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2912 | fsf_req->data = (unsigned long) erp_action->unit; |
| 2913 | fsf_req->erp_action = erp_action; |
| 2914 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2916 | zfcp_erp_start_timer(fsf_req); |
| 2917 | retval = zfcp_fsf_req_send(erp_action->fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | if (retval) { |
| 2919 | ZFCP_LOG_INFO("error: Could not send an open unit request " |
| 2920 | "on the adapter %s, port 0x%016Lx for " |
| 2921 | "unit 0x%016Lx\n", |
| 2922 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2923 | erp_action->port->wwpn, |
| 2924 | erp_action->unit->fcp_lun); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 2925 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | erp_action->fsf_req = NULL; |
| 2927 | goto out; |
| 2928 | } |
| 2929 | |
| 2930 | ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, " |
| 2931 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 2932 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2933 | erp_action->port->wwpn, erp_action->unit->fcp_lun); |
| 2934 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 2935 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | return retval; |
| 2937 | } |
| 2938 | |
| 2939 | /* |
| 2940 | * function: zfcp_fsf_open_unit_handler |
| 2941 | * |
| 2942 | * purpose: is called for finished Open LUN command |
| 2943 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 2944 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | */ |
| 2946 | static int |
| 2947 | zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) |
| 2948 | { |
| 2949 | int retval = -EINVAL; |
| 2950 | struct zfcp_adapter *adapter; |
| 2951 | struct zfcp_unit *unit; |
| 2952 | struct fsf_qtcb_header *header; |
| 2953 | struct fsf_qtcb_bottom_support *bottom; |
| 2954 | struct fsf_queue_designator *queue_designator; |
| 2955 | u16 subtable, rule, counter; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2956 | int exclusive, readwrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2958 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | |
| 2960 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2961 | /* don't change unit status in our bookkeeping */ |
| 2962 | goto skip_fsfstatus; |
| 2963 | } |
| 2964 | |
| 2965 | adapter = fsf_req->adapter; |
| 2966 | header = &fsf_req->qtcb->header; |
| 2967 | bottom = &fsf_req->qtcb->bottom.support; |
| 2968 | queue_designator = &header->fsf_status_qual.fsf_queue_designator; |
| 2969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Heiko Carstens | b64ddf9 | 2007-05-08 11:19:57 +0200 | [diff] [blame] | 2971 | ZFCP_STATUS_COMMON_ACCESS_BOXED | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | ZFCP_STATUS_UNIT_SHARED | |
| 2973 | ZFCP_STATUS_UNIT_READONLY, |
| 2974 | &unit->status); |
| 2975 | |
| 2976 | /* evaluate FSF status in QTCB */ |
| 2977 | switch (header->fsf_status) { |
| 2978 | |
| 2979 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | ZFCP_LOG_INFO("Temporary port identifier 0x%x " |
| 2981 | "for port 0x%016Lx on adapter %s invalid " |
| 2982 | "This may happen occasionally\n", |
| 2983 | unit->port->handle, |
| 2984 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 2985 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 2986 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 2987 | (char *) &header->fsf_status_qual, |
| 2988 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 2989 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2991 | break; |
| 2992 | |
| 2993 | case FSF_LUN_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on " |
| 2995 | "remote port 0x%016Lx on adapter %s twice.\n", |
| 2996 | unit->fcp_lun, |
| 2997 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2999 | break; |
| 3000 | |
| 3001 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on " |
| 3003 | "remote port 0x%016Lx on adapter %s\n", |
| 3004 | unit->fcp_lun, unit->port->wwpn, |
| 3005 | zfcp_get_busid_by_unit(unit)); |
| 3006 | for (counter = 0; counter < 2; counter++) { |
| 3007 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 3008 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 3009 | switch (subtable) { |
| 3010 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3011 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3012 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3013 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3014 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 3015 | zfcp_act_subtable_type[subtable], rule); |
| 3016 | break; |
| 3017 | } |
| 3018 | } |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3019 | zfcp_erp_unit_access_denied(unit, 59, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 3021 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
| 3022 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3023 | break; |
| 3024 | |
| 3025 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3027 | "needs to be reopened\n", |
| 3028 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3029 | zfcp_erp_port_boxed(unit->port, 51, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3031 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3032 | break; |
| 3033 | |
| 3034 | case FSF_LUN_SHARING_VIOLATION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | if (header->fsf_status_qual.word[0] != 0) { |
| 3036 | ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port " |
| 3037 | "with WWPN 0x%Lx " |
| 3038 | "connected to the adapter %s " |
| 3039 | "is already in use in LPAR%d, CSS%d\n", |
| 3040 | unit->fcp_lun, |
| 3041 | unit->port->wwpn, |
| 3042 | zfcp_get_busid_by_unit(unit), |
| 3043 | queue_designator->hla, |
| 3044 | queue_designator->cssid); |
| 3045 | } else { |
| 3046 | subtable = header->fsf_status_qual.halfword[4]; |
| 3047 | rule = header->fsf_status_qual.halfword[5]; |
| 3048 | switch (subtable) { |
| 3049 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3050 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3051 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3052 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3053 | ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the " |
| 3054 | "remote port with WWPN 0x%Lx " |
| 3055 | "connected to the adapter %s " |
| 3056 | "is denied (%s rule %d)\n", |
| 3057 | unit->fcp_lun, |
| 3058 | unit->port->wwpn, |
| 3059 | zfcp_get_busid_by_unit(unit), |
| 3060 | zfcp_act_subtable_type[subtable], |
| 3061 | rule); |
| 3062 | break; |
| 3063 | } |
| 3064 | } |
| 3065 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3066 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3067 | (char *) &header->fsf_status_qual, |
| 3068 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3069 | zfcp_erp_unit_access_denied(unit, 60, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 3071 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
| 3072 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3073 | break; |
| 3074 | |
| 3075 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | ZFCP_LOG_INFO("error: The adapter ran out of resources. " |
| 3077 | "There is no handle (temporary port identifier) " |
| 3078 | "available for unit 0x%016Lx on port 0x%016Lx " |
| 3079 | "on adapter %s\n", |
| 3080 | unit->fcp_lun, |
| 3081 | unit->port->wwpn, |
| 3082 | zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3083 | zfcp_erp_unit_failed(unit, 34, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3085 | break; |
| 3086 | |
| 3087 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | switch (header->fsf_status_qual.word[0]) { |
| 3089 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | /* Re-establish link to port */ |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3091 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3093 | break; |
| 3094 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | /* ERP strategy will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3097 | break; |
| 3098 | default: |
| 3099 | ZFCP_LOG_NORMAL |
| 3100 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 3101 | header->fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | } |
| 3103 | break; |
| 3104 | |
| 3105 | case FSF_INVALID_COMMAND_OPTION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | ZFCP_LOG_NORMAL( |
| 3107 | "Invalid option 0x%x has been specified " |
| 3108 | "in QTCB bottom sent to the adapter %s\n", |
| 3109 | bottom->option, |
| 3110 | zfcp_get_busid_by_adapter(adapter)); |
| 3111 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3112 | retval = -EINVAL; |
| 3113 | break; |
| 3114 | |
| 3115 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | /* save LUN handle assigned by FSF */ |
| 3117 | unit->handle = header->lun_handle; |
| 3118 | ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on " |
| 3119 | "adapter %s opened, port handle 0x%x\n", |
| 3120 | unit->fcp_lun, |
| 3121 | unit->port->wwpn, |
| 3122 | zfcp_get_busid_by_unit(unit), |
| 3123 | unit->handle); |
| 3124 | /* mark unit as open */ |
| 3125 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 3126 | |
| 3127 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && |
| 3128 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && |
| 3129 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { |
| 3130 | exclusive = (bottom->lun_access_info & |
| 3131 | FSF_UNIT_ACCESS_EXCLUSIVE); |
| 3132 | readwrite = (bottom->lun_access_info & |
| 3133 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); |
| 3134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | if (!exclusive) |
| 3136 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, |
| 3137 | &unit->status); |
| 3138 | |
| 3139 | if (!readwrite) { |
| 3140 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, |
| 3141 | &unit->status); |
| 3142 | ZFCP_LOG_NORMAL("read-only access for unit " |
| 3143 | "(adapter %s, wwpn=0x%016Lx, " |
| 3144 | "fcp_lun=0x%016Lx)\n", |
| 3145 | zfcp_get_busid_by_unit(unit), |
| 3146 | unit->port->wwpn, |
| 3147 | unit->fcp_lun); |
| 3148 | } |
| 3149 | |
| 3150 | if (exclusive && !readwrite) { |
| 3151 | ZFCP_LOG_NORMAL("exclusive access of read-only " |
| 3152 | "unit not supported\n"); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3153 | zfcp_erp_unit_failed(unit, 35, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3155 | zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | } else if (!exclusive && readwrite) { |
| 3157 | ZFCP_LOG_NORMAL("shared access of read-write " |
| 3158 | "unit not supported\n"); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3159 | zfcp_erp_unit_failed(unit, 36, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3161 | zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | retval = 0; |
| 3166 | break; |
| 3167 | |
| 3168 | default: |
| 3169 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 3170 | "(debug info 0x%x)\n", |
| 3171 | header->fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | skip_fsfstatus: |
| 3176 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); |
| 3177 | return retval; |
| 3178 | } |
| 3179 | |
| 3180 | /* |
| 3181 | * function: zfcp_fsf_close_unit |
| 3182 | * |
| 3183 | * purpose: |
| 3184 | * |
| 3185 | * returns: address of fsf_req - request successfully initiated |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 3186 | * NULL - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | * |
| 3188 | * assumptions: This routine does not check whether the associated |
| 3189 | * remote port/lun has already been opened. This should be |
| 3190 | * done by calling routines. Otherwise some status |
| 3191 | * may be presented by FSF |
| 3192 | */ |
| 3193 | int |
| 3194 | zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
| 3195 | { |
| 3196 | volatile struct qdio_buffer_element *sbale; |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3197 | struct zfcp_fsf_req *fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | unsigned long lock_flags; |
| 3199 | int retval = 0; |
| 3200 | |
| 3201 | /* setup new FSF request */ |
| 3202 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 3203 | FSF_QTCB_CLOSE_LUN, |
| 3204 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 3205 | erp_action->adapter->pool.fsf_req_erp, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3206 | &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | if (retval < 0) { |
| 3208 | ZFCP_LOG_INFO("error: Could not create close unit request for " |
| 3209 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", |
| 3210 | erp_action->unit->fcp_lun, |
| 3211 | erp_action->port->wwpn, |
| 3212 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 3213 | goto out; |
| 3214 | } |
| 3215 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3216 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 3218 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 3219 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3220 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; |
| 3221 | fsf_req->qtcb->header.lun_handle = erp_action->unit->handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3223 | fsf_req->data = (unsigned long) erp_action->unit; |
| 3224 | fsf_req->erp_action = erp_action; |
| 3225 | erp_action->fsf_req = fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3227 | zfcp_erp_start_timer(fsf_req); |
| 3228 | retval = zfcp_fsf_req_send(erp_action->fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | if (retval) { |
| 3230 | ZFCP_LOG_INFO("error: Could not send a close unit request for " |
| 3231 | "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n", |
| 3232 | erp_action->unit->fcp_lun, |
| 3233 | erp_action->port->wwpn, |
| 3234 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3235 | zfcp_fsf_req_free(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | erp_action->fsf_req = NULL; |
| 3237 | goto out; |
| 3238 | } |
| 3239 | |
| 3240 | ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, " |
| 3241 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 3242 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 3243 | erp_action->port->wwpn, erp_action->unit->fcp_lun); |
| 3244 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3245 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | return retval; |
| 3247 | } |
| 3248 | |
| 3249 | /* |
| 3250 | * function: zfcp_fsf_close_unit_handler |
| 3251 | * |
| 3252 | * purpose: is called for finished Close LUN FSF command |
| 3253 | * |
| 3254 | * returns: |
| 3255 | */ |
| 3256 | static int |
| 3257 | zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req) |
| 3258 | { |
| 3259 | int retval = -EINVAL; |
| 3260 | struct zfcp_unit *unit; |
| 3261 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3262 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | |
| 3264 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 3265 | /* don't change unit status in our bookkeeping */ |
| 3266 | goto skip_fsfstatus; |
| 3267 | } |
| 3268 | |
| 3269 | /* evaluate FSF status in QTCB */ |
| 3270 | switch (fsf_req->qtcb->header.fsf_status) { |
| 3271 | |
| 3272 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 3274 | "0x%016Lx on adapter %s invalid. This may " |
| 3275 | "happen in rare circumstances\n", |
| 3276 | unit->port->handle, |
| 3277 | unit->port->wwpn, |
| 3278 | zfcp_get_busid_by_unit(unit)); |
| 3279 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3280 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3281 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 3282 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3283 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3285 | break; |
| 3286 | |
| 3287 | case FSF_LUN_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit " |
| 3289 | "0x%016Lx on port 0x%016Lx on adapter %s is " |
| 3290 | "invalid. This may happen occasionally.\n", |
| 3291 | unit->handle, |
| 3292 | unit->fcp_lun, |
| 3293 | unit->port->wwpn, |
| 3294 | zfcp_get_busid_by_unit(unit)); |
| 3295 | ZFCP_LOG_DEBUG("Status qualifier data:\n"); |
| 3296 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3297 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 3298 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3299 | zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3301 | break; |
| 3302 | |
| 3303 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3305 | "needs to be reopened\n", |
| 3306 | unit->port->wwpn, |
| 3307 | zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3308 | zfcp_erp_port_boxed(unit->port, 52, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3310 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3311 | break; |
| 3312 | |
| 3313 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
| 3315 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | /* re-establish link to port */ |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3317 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3319 | break; |
| 3320 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | /* ERP strategy will escalate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3323 | break; |
| 3324 | default: |
| 3325 | ZFCP_LOG_NORMAL |
| 3326 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 3327 | fsf_req->qtcb->header.fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | break; |
| 3329 | } |
| 3330 | break; |
| 3331 | |
| 3332 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s " |
| 3334 | "closed, port handle 0x%x\n", |
| 3335 | unit->fcp_lun, |
| 3336 | unit->port->wwpn, |
| 3337 | zfcp_get_busid_by_unit(unit), |
| 3338 | unit->handle); |
| 3339 | /* mark unit as closed */ |
| 3340 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 3341 | retval = 0; |
| 3342 | break; |
| 3343 | |
| 3344 | default: |
| 3345 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 3346 | "(debug info 0x%x)\n", |
| 3347 | fsf_req->qtcb->header.fsf_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | break; |
| 3349 | } |
| 3350 | |
| 3351 | skip_fsfstatus: |
| 3352 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); |
| 3353 | return retval; |
| 3354 | } |
| 3355 | |
| 3356 | /** |
| 3357 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) |
| 3358 | * @adapter: adapter where scsi command is issued |
| 3359 | * @unit: unit where command is sent to |
| 3360 | * @scsi_cmnd: scsi command to be sent |
| 3361 | * @timer: timer to be started when request is initiated |
| 3362 | * @req_flags: flags for fsf_request |
| 3363 | */ |
| 3364 | int |
| 3365 | zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, |
| 3366 | struct zfcp_unit *unit, |
| 3367 | struct scsi_cmnd * scsi_cmnd, |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3368 | int use_timer, int req_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | { |
| 3370 | struct zfcp_fsf_req *fsf_req = NULL; |
| 3371 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 3372 | unsigned int sbtype; |
| 3373 | unsigned long lock_flags; |
| 3374 | int real_bytes = 0; |
| 3375 | int retval = 0; |
| 3376 | int mask; |
| 3377 | |
| 3378 | /* setup new FSF request */ |
| 3379 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 3380 | adapter->pool.fsf_req_scsi, |
| 3381 | &lock_flags, &fsf_req); |
| 3382 | if (unlikely(retval < 0)) { |
| 3383 | ZFCP_LOG_DEBUG("error: Could not create FCP command request " |
| 3384 | "for unit 0x%016Lx on port 0x%016Lx on " |
| 3385 | "adapter %s\n", |
| 3386 | unit->fcp_lun, |
| 3387 | unit->port->wwpn, |
| 3388 | zfcp_get_busid_by_adapter(adapter)); |
| 3389 | goto failed_req_create; |
| 3390 | } |
| 3391 | |
Christof Schmitt | ba17242 | 2007-12-20 12:30:26 +0100 | [diff] [blame] | 3392 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, |
| 3393 | &unit->status))) { |
| 3394 | retval = -EBUSY; |
| 3395 | goto unit_blocked; |
| 3396 | } |
| 3397 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3398 | zfcp_unit_get(unit); |
| 3399 | fsf_req->unit = unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3401 | /* associate FSF request with SCSI request (for look up on abort) */ |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 3402 | scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3403 | |
| 3404 | /* associate SCSI command with FSF request */ |
| 3405 | fsf_req->data = (unsigned long) scsi_cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | |
| 3407 | /* set handles of unit and its parent port in QTCB */ |
| 3408 | fsf_req->qtcb->header.lun_handle = unit->handle; |
| 3409 | fsf_req->qtcb->header.port_handle = unit->port->handle; |
| 3410 | |
| 3411 | /* FSF does not define the structure of the FCP_CMND IU */ |
| 3412 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 3413 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 3414 | |
| 3415 | /* |
| 3416 | * set depending on data direction: |
| 3417 | * data direction bits in SBALE (SB Type) |
| 3418 | * data direction bits in QTCB |
| 3419 | * data direction bits in FCP_CMND IU |
| 3420 | */ |
| 3421 | switch (scsi_cmnd->sc_data_direction) { |
| 3422 | case DMA_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 3424 | /* |
| 3425 | * FIXME(qdio): |
| 3426 | * what is the correct type for commands |
| 3427 | * without 'real' data buffers? |
| 3428 | */ |
| 3429 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 3430 | break; |
| 3431 | case DMA_FROM_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
| 3433 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 3434 | fcp_cmnd_iu->rddata = 1; |
| 3435 | break; |
| 3436 | case DMA_TO_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; |
| 3438 | sbtype = SBAL_FLAGS0_TYPE_WRITE; |
| 3439 | fcp_cmnd_iu->wddata = 1; |
| 3440 | break; |
| 3441 | case DMA_BIDIRECTIONAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | default: |
| 3443 | /* |
| 3444 | * dummy, catch this condition earlier |
| 3445 | * in zfcp_scsi_queuecommand |
| 3446 | */ |
| 3447 | goto failed_scsi_cmnd; |
| 3448 | } |
| 3449 | |
| 3450 | /* set FC service class in QTCB (3 per default) */ |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 3451 | fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | |
| 3453 | /* set FCP_LUN in FCP_CMND IU in QTCB */ |
| 3454 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 3455 | |
| 3456 | mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED; |
| 3457 | |
| 3458 | /* set task attributes in FCP_CMND IU in QTCB */ |
| 3459 | if (likely((scsi_cmnd->device->simple_tags) || |
| 3460 | (atomic_test_mask(mask, &unit->status)))) |
| 3461 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; |
| 3462 | else |
| 3463 | fcp_cmnd_iu->task_attribute = UNTAGGED; |
| 3464 | |
| 3465 | /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */ |
| 3466 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) { |
| 3467 | fcp_cmnd_iu->add_fcp_cdb_length |
| 3468 | = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; |
| 3469 | ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, " |
| 3470 | "additional FCP_CDB length is 0x%x " |
| 3471 | "(shifted right 2 bits)\n", |
| 3472 | scsi_cmnd->cmd_len, |
| 3473 | fcp_cmnd_iu->add_fcp_cdb_length); |
| 3474 | } |
| 3475 | /* |
| 3476 | * copy SCSI CDB (including additional length, if any) to |
| 3477 | * FCP_CDB in FCP_CMND IU in QTCB |
| 3478 | */ |
| 3479 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 3480 | |
| 3481 | /* FCP CMND IU length in QTCB */ |
| 3482 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = |
| 3483 | sizeof (struct fcp_cmnd_iu) + |
| 3484 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t); |
| 3485 | |
| 3486 | /* generate SBALEs from data buffer */ |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3487 | real_bytes = zfcp_qdio_sbals_from_sg(fsf_req, sbtype, |
| 3488 | scsi_sglist(scsi_cmnd), |
| 3489 | ZFCP_MAX_SBALS_PER_REQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | if (unlikely(real_bytes < 0)) { |
| 3491 | if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) { |
| 3492 | ZFCP_LOG_DEBUG( |
| 3493 | "Data did not fit into available buffer(s), " |
| 3494 | "waiting for more...\n"); |
Christof Schmitt | 2282f65 | 2007-08-28 09:30:22 +0200 | [diff] [blame] | 3495 | retval = -EIO; |
| 3496 | } else { |
| 3497 | ZFCP_LOG_NORMAL("error: No truncation implemented but " |
| 3498 | "required. Shutting down unit " |
| 3499 | "(adapter %s, port 0x%016Lx, " |
| 3500 | "unit 0x%016Lx)\n", |
| 3501 | zfcp_get_busid_by_unit(unit), |
| 3502 | unit->port->wwpn, |
| 3503 | unit->fcp_lun); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3504 | zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req); |
Christof Schmitt | 2282f65 | 2007-08-28 09:30:22 +0200 | [diff] [blame] | 3505 | retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | } |
| 3507 | goto no_fit; |
| 3508 | } |
| 3509 | |
| 3510 | /* set length of FCP data length in FCP_CMND IU in QTCB */ |
| 3511 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
| 3512 | |
| 3513 | ZFCP_LOG_DEBUG("Sending SCSI command:\n"); |
| 3514 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3515 | (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 3516 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3517 | if (use_timer) |
| 3518 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 3519 | |
| 3520 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | if (unlikely(retval < 0)) { |
| 3522 | ZFCP_LOG_INFO("error: Could not send FCP command request " |
| 3523 | "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n", |
| 3524 | zfcp_get_busid_by_adapter(adapter), |
| 3525 | unit->port->wwpn, |
| 3526 | unit->fcp_lun); |
| 3527 | goto send_failed; |
| 3528 | } |
| 3529 | |
| 3530 | ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, " |
| 3531 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 3532 | zfcp_get_busid_by_adapter(adapter), |
| 3533 | unit->port->wwpn, |
| 3534 | unit->fcp_lun); |
| 3535 | goto success; |
| 3536 | |
| 3537 | send_failed: |
| 3538 | no_fit: |
| 3539 | failed_scsi_cmnd: |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3540 | zfcp_unit_put(unit); |
Christof Schmitt | 57b7658 | 2008-04-18 12:51:57 +0200 | [diff] [blame] | 3541 | unit_blocked: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | zfcp_fsf_req_free(fsf_req); |
| 3543 | fsf_req = NULL; |
| 3544 | scsi_cmnd->host_scribble = NULL; |
| 3545 | success: |
| 3546 | failed_req_create: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3547 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | return retval; |
| 3549 | } |
| 3550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | struct zfcp_fsf_req * |
| 3552 | zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter, |
| 3553 | struct zfcp_unit *unit, |
| 3554 | u8 tm_flags, int req_flags) |
| 3555 | { |
| 3556 | struct zfcp_fsf_req *fsf_req = NULL; |
| 3557 | int retval = 0; |
| 3558 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 3559 | unsigned long lock_flags; |
| 3560 | volatile struct qdio_buffer_element *sbale; |
| 3561 | |
| 3562 | /* setup new FSF request */ |
| 3563 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 3564 | adapter->pool.fsf_req_scsi, |
| 3565 | &lock_flags, &fsf_req); |
| 3566 | if (retval < 0) { |
| 3567 | ZFCP_LOG_INFO("error: Could not create FCP command (task " |
| 3568 | "management) request for adapter %s, port " |
| 3569 | " 0x%016Lx, unit 0x%016Lx.\n", |
| 3570 | zfcp_get_busid_by_adapter(adapter), |
| 3571 | unit->port->wwpn, unit->fcp_lun); |
| 3572 | goto out; |
| 3573 | } |
| 3574 | |
Christof Schmitt | fdf2345 | 2007-12-20 12:30:27 +0100 | [diff] [blame] | 3575 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, |
| 3576 | &unit->status))) |
| 3577 | goto unit_blocked; |
| 3578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | /* |
| 3580 | * Used to decide on proper handler in the return path, |
| 3581 | * could be either zfcp_fsf_send_fcp_command_task_handler or |
| 3582 | * zfcp_fsf_send_fcp_command_task_management_handler */ |
| 3583 | |
| 3584 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
| 3585 | |
| 3586 | /* |
| 3587 | * hold a pointer to the unit being target of this |
| 3588 | * task management request |
| 3589 | */ |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3590 | fsf_req->data = (unsigned long) unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | |
| 3592 | /* set FSF related fields in QTCB */ |
| 3593 | fsf_req->qtcb->header.lun_handle = unit->handle; |
| 3594 | fsf_req->qtcb->header.port_handle = unit->port->handle; |
| 3595 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 3596 | fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = |
| 3598 | sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t); |
| 3599 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3600 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; |
| 3602 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 3603 | |
| 3604 | /* set FCP related fields in FCP_CMND IU in QTCB */ |
| 3605 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 3606 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 3607 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 3608 | fcp_cmnd_iu->task_management_flags = tm_flags; |
| 3609 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 3610 | zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT); |
| 3611 | retval = zfcp_fsf_req_send(fsf_req); |
Christof Schmitt | fdf2345 | 2007-12-20 12:30:27 +0100 | [diff] [blame] | 3612 | if (!retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | |
Christof Schmitt | fdf2345 | 2007-12-20 12:30:27 +0100 | [diff] [blame] | 3615 | unit_blocked: |
| 3616 | zfcp_fsf_req_free(fsf_req); |
| 3617 | fsf_req = NULL; |
| 3618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | out: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 3620 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | return fsf_req; |
| 3622 | } |
| 3623 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 3624 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
| 3625 | { |
| 3626 | lat_rec->sum += lat; |
| 3627 | if (lat_rec->min > lat) |
| 3628 | lat_rec->min = lat; |
| 3629 | if (lat_rec->max < lat) |
| 3630 | lat_rec->max = lat; |
| 3631 | } |
| 3632 | |
| 3633 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req) |
| 3634 | { |
| 3635 | struct fsf_qual_latency_info *lat_inf; |
| 3636 | struct latency_cont *lat; |
| 3637 | struct zfcp_unit *unit; |
| 3638 | unsigned long flags; |
| 3639 | |
| 3640 | lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info; |
| 3641 | unit = fsf_req->unit; |
| 3642 | |
| 3643 | switch (fsf_req->qtcb->bottom.io.data_direction) { |
| 3644 | case FSF_DATADIR_READ: |
| 3645 | lat = &unit->latencies.read; |
| 3646 | break; |
| 3647 | case FSF_DATADIR_WRITE: |
| 3648 | lat = &unit->latencies.write; |
| 3649 | break; |
| 3650 | case FSF_DATADIR_CMND: |
| 3651 | lat = &unit->latencies.cmd; |
| 3652 | break; |
| 3653 | default: |
| 3654 | return; |
| 3655 | } |
| 3656 | |
| 3657 | spin_lock_irqsave(&unit->latencies.lock, flags); |
| 3658 | zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat); |
| 3659 | zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat); |
| 3660 | lat->counter++; |
| 3661 | spin_unlock_irqrestore(&unit->latencies.lock, flags); |
| 3662 | } |
| 3663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | /* |
| 3665 | * function: zfcp_fsf_send_fcp_command_handler |
| 3666 | * |
| 3667 | * purpose: is called for finished Send FCP Command |
| 3668 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 3669 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | */ |
| 3671 | static int |
| 3672 | zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req) |
| 3673 | { |
| 3674 | int retval = -EINVAL; |
| 3675 | struct zfcp_unit *unit; |
| 3676 | struct fsf_qtcb_header *header; |
| 3677 | u16 subtable, rule, counter; |
| 3678 | |
| 3679 | header = &fsf_req->qtcb->header; |
| 3680 | |
| 3681 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3682 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | else |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3684 | unit = fsf_req->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
| 3686 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 3687 | /* go directly to calls of special handlers */ |
| 3688 | goto skip_fsfstatus; |
| 3689 | } |
| 3690 | |
| 3691 | /* evaluate FSF status in QTCB */ |
| 3692 | switch (header->fsf_status) { |
| 3693 | |
| 3694 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 3696 | "0x%016Lx on adapter %s invalid\n", |
| 3697 | unit->port->handle, |
| 3698 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3699 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3700 | (char *) &header->fsf_status_qual, |
| 3701 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3702 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3704 | break; |
| 3705 | |
| 3706 | case FSF_LUN_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit " |
| 3708 | "0x%016Lx on port 0x%016Lx on adapter %s is " |
| 3709 | "invalid. This may happen occasionally.\n", |
| 3710 | unit->handle, |
| 3711 | unit->fcp_lun, |
| 3712 | unit->port->wwpn, |
| 3713 | zfcp_get_busid_by_unit(unit)); |
| 3714 | ZFCP_LOG_NORMAL("Status qualifier data:\n"); |
| 3715 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, |
| 3716 | (char *) &header->fsf_status_qual, |
| 3717 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3718 | zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3720 | break; |
| 3721 | |
| 3722 | case FSF_HANDLE_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed " |
| 3724 | "unexpectedly. (adapter %s, port 0x%016Lx, " |
| 3725 | "unit 0x%016Lx)\n", |
| 3726 | unit->port->handle, |
| 3727 | zfcp_get_busid_by_unit(unit), |
| 3728 | unit->port->wwpn, |
| 3729 | unit->fcp_lun); |
| 3730 | ZFCP_LOG_NORMAL("status qualifier:\n"); |
| 3731 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, |
| 3732 | (char *) &header->fsf_status_qual, |
| 3733 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3734 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3736 | break; |
| 3737 | |
| 3738 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
Andreas Herrmann | 06506d0 | 2006-05-22 18:18:19 +0200 | [diff] [blame] | 3739 | ZFCP_LOG_INFO("error: adapter %s does not support fc " |
| 3740 | "class %d.\n", |
| 3741 | zfcp_get_busid_by_unit(unit), |
| 3742 | ZFCP_FC_SERVICE_CLASS_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | /* stop operation for this adapter */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3744 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3746 | break; |
| 3747 | |
| 3748 | case FSF_FCPLUN_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on " |
| 3750 | "adapter %s does not have correct unit " |
| 3751 | "handle 0x%x\n", |
| 3752 | unit->fcp_lun, |
| 3753 | unit->port->wwpn, |
| 3754 | zfcp_get_busid_by_unit(unit), |
| 3755 | unit->handle); |
| 3756 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3757 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3758 | (char *) &header->fsf_status_qual, |
| 3759 | sizeof (union fsf_status_qual)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3760 | zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3762 | break; |
| 3763 | |
| 3764 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to " |
| 3766 | "unit 0x%016Lx on port 0x%016Lx on " |
| 3767 | "adapter %s\n", unit->fcp_lun, unit->port->wwpn, |
| 3768 | zfcp_get_busid_by_unit(unit)); |
| 3769 | for (counter = 0; counter < 2; counter++) { |
| 3770 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 3771 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 3772 | switch (subtable) { |
| 3773 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3774 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3775 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3776 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3777 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 3778 | zfcp_act_subtable_type[subtable], rule); |
| 3779 | break; |
| 3780 | } |
| 3781 | } |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3782 | zfcp_erp_unit_access_denied(unit, 61, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3784 | break; |
| 3785 | |
| 3786 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | ZFCP_LOG_INFO("bug: Invalid data direction given for unit " |
| 3788 | "0x%016Lx on port 0x%016Lx on adapter %s " |
| 3789 | "(debug info %d)\n", |
| 3790 | unit->fcp_lun, |
| 3791 | unit->port->wwpn, |
| 3792 | zfcp_get_busid_by_unit(unit), |
| 3793 | fsf_req->qtcb->bottom.io.data_direction); |
| 3794 | /* stop operation for this adapter */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3795 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3797 | break; |
| 3798 | |
| 3799 | case FSF_CMND_LENGTH_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | ZFCP_LOG_NORMAL |
| 3801 | ("bug: An invalid control-data-block length field " |
| 3802 | "was found in a command for unit 0x%016Lx on port " |
| 3803 | "0x%016Lx on adapter %s " "(debug info %d)\n", |
| 3804 | unit->fcp_lun, unit->port->wwpn, |
| 3805 | zfcp_get_busid_by_unit(unit), |
| 3806 | fsf_req->qtcb->bottom.io.fcp_cmnd_length); |
| 3807 | /* stop operation for this adapter */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3808 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3810 | break; |
| 3811 | |
| 3812 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3814 | "needs to be reopened\n", |
| 3815 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3816 | zfcp_erp_port_boxed(unit->port, 53, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3818 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3819 | break; |
| 3820 | |
| 3821 | case FSF_LUN_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, " |
| 3823 | "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n", |
| 3824 | zfcp_get_busid_by_unit(unit), |
| 3825 | unit->port->wwpn, unit->fcp_lun); |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 3826 | zfcp_erp_unit_boxed(unit, 54, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
| 3828 | | ZFCP_STATUS_FSFREQ_RETRY; |
| 3829 | break; |
| 3830 | |
| 3831 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | switch (header->fsf_status_qual.word[0]) { |
| 3833 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | /* re-establish link to port */ |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3835 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | break; |
| 3837 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | /* FIXME(hw) need proper specs for proper action */ |
| 3839 | /* let scsi stack deal with retries and escalation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | break; |
| 3841 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | ZFCP_LOG_NORMAL |
Andreas Herrmann | 516a420 | 2005-06-13 13:17:44 +0200 | [diff] [blame] | 3843 | ("Unknown status qualifier 0x%x arrived.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | header->fsf_status_qual.word[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | break; |
| 3846 | } |
Andreas Herrmann | 516a420 | 2005-06-13 13:17:44 +0200 | [diff] [blame] | 3847 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | break; |
| 3849 | |
| 3850 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | break; |
| 3852 | |
| 3853 | case FSF_FCP_RSP_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | skip_fsfstatus: |
| 3858 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) { |
| 3859 | retval = |
| 3860 | zfcp_fsf_send_fcp_command_task_management_handler(fsf_req); |
| 3861 | } else { |
| 3862 | retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3863 | fsf_req->unit = NULL; |
| 3864 | zfcp_unit_put(unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | } |
| 3866 | return retval; |
| 3867 | } |
| 3868 | |
| 3869 | /* |
| 3870 | * function: zfcp_fsf_send_fcp_command_task_handler |
| 3871 | * |
| 3872 | * purpose: evaluates FCP_RSP IU |
| 3873 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 3874 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | */ |
| 3876 | static int |
| 3877 | zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req) |
| 3878 | { |
| 3879 | int retval = 0; |
| 3880 | struct scsi_cmnd *scpnt; |
| 3881 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
| 3882 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 3883 | struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 3884 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 3885 | u32 sns_len; |
| 3886 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); |
| 3887 | unsigned long flags; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3888 | struct zfcp_unit *unit = fsf_req->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | |
| 3890 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3891 | scpnt = (struct scsi_cmnd *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | if (unlikely(!scpnt)) { |
| 3893 | ZFCP_LOG_DEBUG |
| 3894 | ("Command with fsf_req %p is not associated to " |
| 3895 | "a scsi command anymore. Aborted?\n", fsf_req); |
| 3896 | goto out; |
| 3897 | } |
| 3898 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
| 3899 | /* FIXME: (design) mid-layer should handle DID_ABORT like |
| 3900 | * DID_SOFT_ERROR by retrying the request for devices |
| 3901 | * that allow retries. |
| 3902 | */ |
| 3903 | ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n"); |
| 3904 | set_host_byte(&scpnt->result, DID_SOFT_ERROR); |
| 3905 | set_driver_byte(&scpnt->result, SUGGEST_RETRY); |
| 3906 | goto skip_fsfstatus; |
| 3907 | } |
| 3908 | |
| 3909 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 3910 | ZFCP_LOG_DEBUG("Setting DID_ERROR\n"); |
| 3911 | set_host_byte(&scpnt->result, DID_ERROR); |
| 3912 | goto skip_fsfstatus; |
| 3913 | } |
| 3914 | |
| 3915 | /* set message byte of result in SCSI command */ |
| 3916 | scpnt->result |= COMMAND_COMPLETE << 8; |
| 3917 | |
| 3918 | /* |
| 3919 | * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte |
| 3920 | * of result in SCSI command |
| 3921 | */ |
| 3922 | scpnt->result |= fcp_rsp_iu->scsi_status; |
| 3923 | if (unlikely(fcp_rsp_iu->scsi_status)) { |
| 3924 | /* DEBUG */ |
| 3925 | ZFCP_LOG_DEBUG("status for SCSI Command:\n"); |
| 3926 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3927 | scpnt->cmnd, scpnt->cmd_len); |
| 3928 | ZFCP_LOG_DEBUG("SCSI status code 0x%x\n", |
| 3929 | fcp_rsp_iu->scsi_status); |
| 3930 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3931 | (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu)); |
| 3932 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3933 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), |
| 3934 | fcp_rsp_iu->fcp_sns_len); |
| 3935 | } |
| 3936 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 3937 | if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) |
| 3938 | zfcp_fsf_req_latency(fsf_req); |
| 3939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | /* check FCP_RSP_INFO */ |
| 3941 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
| 3942 | ZFCP_LOG_DEBUG("rsp_len is valid\n"); |
| 3943 | switch (fcp_rsp_info[3]) { |
| 3944 | case RSP_CODE_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | /* ok, continue */ |
| 3946 | ZFCP_LOG_TRACE("no failure or Task Management " |
| 3947 | "Function complete\n"); |
| 3948 | set_host_byte(&scpnt->result, DID_OK); |
| 3949 | break; |
| 3950 | case RSP_CODE_LENGTH_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | /* hardware bug */ |
| 3952 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " |
| 3953 | "that the fibrechannel protocol data " |
| 3954 | "length differs from the burst length. " |
| 3955 | "The problem occured on unit 0x%016Lx " |
| 3956 | "on port 0x%016Lx on adapter %s", |
| 3957 | unit->fcp_lun, |
| 3958 | unit->port->wwpn, |
| 3959 | zfcp_get_busid_by_unit(unit)); |
| 3960 | /* dump SCSI CDB as prepared by zfcp */ |
| 3961 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3962 | (char *) &fsf_req->qtcb-> |
| 3963 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | set_host_byte(&scpnt->result, DID_ERROR); |
| 3965 | goto skip_fsfstatus; |
| 3966 | case RSP_CODE_FIELD_INVALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | /* driver or hardware bug */ |
| 3968 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " |
| 3969 | "that the fibrechannel protocol data " |
| 3970 | "fields were incorrectly set up. " |
| 3971 | "The problem occured on the unit " |
| 3972 | "0x%016Lx on port 0x%016Lx on " |
| 3973 | "adapter %s", |
| 3974 | unit->fcp_lun, |
| 3975 | unit->port->wwpn, |
| 3976 | zfcp_get_busid_by_unit(unit)); |
| 3977 | /* dump SCSI CDB as prepared by zfcp */ |
| 3978 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3979 | (char *) &fsf_req->qtcb-> |
| 3980 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
| 3981 | set_host_byte(&scpnt->result, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | goto skip_fsfstatus; |
| 3983 | case RSP_CODE_RO_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | /* hardware bug */ |
| 3985 | ZFCP_LOG_NORMAL("bug: The FCP response code indicates " |
| 3986 | "that conflicting values for the " |
| 3987 | "fibrechannel payload offset from the " |
| 3988 | "header were found. " |
| 3989 | "The problem occured on unit 0x%016Lx " |
| 3990 | "on port 0x%016Lx on adapter %s.\n", |
| 3991 | unit->fcp_lun, |
| 3992 | unit->port->wwpn, |
| 3993 | zfcp_get_busid_by_unit(unit)); |
| 3994 | /* dump SCSI CDB as prepared by zfcp */ |
| 3995 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3996 | (char *) &fsf_req->qtcb-> |
| 3997 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | set_host_byte(&scpnt->result, DID_ERROR); |
| 3999 | goto skip_fsfstatus; |
| 4000 | default: |
| 4001 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " |
| 4002 | "code was detected for a command. " |
| 4003 | "The problem occured on the unit " |
| 4004 | "0x%016Lx on port 0x%016Lx on " |
| 4005 | "adapter %s (debug info 0x%x)\n", |
| 4006 | unit->fcp_lun, |
| 4007 | unit->port->wwpn, |
| 4008 | zfcp_get_busid_by_unit(unit), |
| 4009 | fcp_rsp_info[3]); |
| 4010 | /* dump SCSI CDB as prepared by zfcp */ |
| 4011 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4012 | (char *) &fsf_req->qtcb-> |
| 4013 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | set_host_byte(&scpnt->result, DID_ERROR); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 4015 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | /* check for sense data */ |
| 4020 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
| 4021 | sns_len = FSF_FCP_RSP_SIZE - |
| 4022 | sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len; |
| 4023 | ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n", |
| 4024 | sns_len); |
| 4025 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
| 4026 | ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n", |
| 4027 | SCSI_SENSE_BUFFERSIZE); |
| 4028 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
| 4029 | ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n", |
| 4030 | scpnt->result); |
| 4031 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 4032 | scpnt->cmnd, scpnt->cmd_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | |
| 4034 | ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n", |
| 4035 | fcp_rsp_iu->fcp_sns_len); |
FUJITA Tomonori | 9d058ec | 2008-01-27 12:41:50 +0900 | [diff] [blame] | 4036 | memcpy(scpnt->sense_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
| 4038 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, |
FUJITA Tomonori | 9d058ec | 2008-01-27 12:41:50 +0900 | [diff] [blame] | 4039 | (void *)scpnt->sense_buffer, sns_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | /* check for overrun */ |
| 4043 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) { |
| 4044 | ZFCP_LOG_INFO("A data overrun was detected for a command. " |
| 4045 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " |
| 4046 | "The response data length is " |
| 4047 | "%d, the original length was %d.\n", |
| 4048 | unit->fcp_lun, |
| 4049 | unit->port->wwpn, |
| 4050 | zfcp_get_busid_by_unit(unit), |
| 4051 | fcp_rsp_iu->fcp_resid, |
| 4052 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); |
| 4053 | } |
| 4054 | |
| 4055 | /* check for underrun */ |
| 4056 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
| 4057 | ZFCP_LOG_INFO("A data underrun was detected for a command. " |
| 4058 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " |
| 4059 | "The response data length is " |
| 4060 | "%d, the original length was %d.\n", |
| 4061 | unit->fcp_lun, |
| 4062 | unit->port->wwpn, |
| 4063 | zfcp_get_busid_by_unit(unit), |
| 4064 | fcp_rsp_iu->fcp_resid, |
| 4065 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); |
| 4066 | |
FUJITA Tomonori | 7936a89 | 2007-07-29 16:46:28 +0900 | [diff] [blame] | 4067 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); |
| 4068 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < |
| 4069 | scpnt->underflow) |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 4070 | set_host_byte(&scpnt->result, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | skip_fsfstatus: |
| 4074 | ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result); |
| 4075 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4076 | if (scpnt->result != 0) |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 4077 | zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4078 | else if (scpnt->retries > 0) |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 4079 | zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4080 | else |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 4081 | zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | |
| 4083 | /* cleanup pointer (need this especially for abort) */ |
| 4084 | scpnt->host_scribble = NULL; |
| 4085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | /* always call back */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | (scpnt->scsi_done) (scpnt); |
| 4088 | |
| 4089 | /* |
| 4090 | * We must hold this lock until scsi_done has been called. |
| 4091 | * Otherwise we may call scsi_done after abort regarding this |
| 4092 | * command has completed. |
| 4093 | * Note: scsi_done must not block! |
| 4094 | */ |
| 4095 | out: |
| 4096 | read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags); |
| 4097 | return retval; |
| 4098 | } |
| 4099 | |
| 4100 | /* |
| 4101 | * function: zfcp_fsf_send_fcp_command_task_management_handler |
| 4102 | * |
| 4103 | * purpose: evaluates FCP_RSP IU |
| 4104 | * |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 4105 | * returns: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | */ |
| 4107 | static int |
| 4108 | zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req) |
| 4109 | { |
| 4110 | int retval = 0; |
| 4111 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
| 4112 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 4113 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 4114 | struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 4117 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4118 | goto skip_fsfstatus; |
| 4119 | } |
| 4120 | |
| 4121 | /* check FCP_RSP_INFO */ |
| 4122 | switch (fcp_rsp_info[3]) { |
| 4123 | case RSP_CODE_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | /* ok, continue */ |
| 4125 | ZFCP_LOG_DEBUG("no failure or Task Management " |
| 4126 | "Function complete\n"); |
| 4127 | break; |
| 4128 | case RSP_CODE_TASKMAN_UNSUPP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
| 4130 | "is not supported on the target device " |
| 4131 | "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ", |
| 4132 | unit->fcp_lun, |
| 4133 | unit->port->wwpn, |
| 4134 | zfcp_get_busid_by_unit(unit)); |
| 4135 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP; |
| 4136 | break; |
| 4137 | case RSP_CODE_TASKMAN_FAILED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
| 4139 | "failed to complete successfully. " |
| 4140 | "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n", |
| 4141 | unit->fcp_lun, |
| 4142 | unit->port->wwpn, |
| 4143 | zfcp_get_busid_by_unit(unit)); |
| 4144 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4145 | break; |
| 4146 | default: |
| 4147 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " |
| 4148 | "code was detected for a command. " |
| 4149 | "unit 0x%016Lx, port 0x%016Lx, adapter %s " |
| 4150 | "(debug info 0x%x)\n", |
| 4151 | unit->fcp_lun, |
| 4152 | unit->port->wwpn, |
| 4153 | zfcp_get_busid_by_unit(unit), |
| 4154 | fcp_rsp_info[3]); |
| 4155 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4156 | } |
| 4157 | |
| 4158 | skip_fsfstatus: |
| 4159 | return retval; |
| 4160 | } |
| 4161 | |
| 4162 | |
| 4163 | /* |
| 4164 | * function: zfcp_fsf_control_file |
| 4165 | * |
| 4166 | * purpose: Initiator of the control file upload/download FSF requests |
| 4167 | * |
| 4168 | * returns: 0 - FSF request is successfuly created and queued |
| 4169 | * -EOPNOTSUPP - The FCP adapter does not have Control File support |
| 4170 | * -EINVAL - Invalid direction specified |
| 4171 | * -ENOMEM - Insufficient memory |
| 4172 | * -EPERM - Cannot create FSF request or place it in QDIO queue |
| 4173 | */ |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4174 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
| 4175 | struct zfcp_fsf_cfdc *fsf_cfdc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | { |
| 4177 | struct zfcp_fsf_req *fsf_req; |
| 4178 | struct fsf_qtcb_bottom_support *bottom; |
| 4179 | volatile struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | unsigned long lock_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | int direction; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4182 | int retval; |
| 4183 | int bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4185 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) |
| 4186 | return ERR_PTR(-EOPNOTSUPP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4188 | switch (fsf_cfdc->command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 4190 | direction = SBAL_FLAGS0_TYPE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 4193 | direction = SBAL_FLAGS0_TYPE_READ; |
| 4194 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | default: |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4196 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | } |
| 4198 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4199 | retval = zfcp_fsf_req_create(adapter, fsf_cfdc->command, |
| 4200 | ZFCP_WAIT_FOR_SBAL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | NULL, &lock_flags, &fsf_req); |
| 4202 | if (retval < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | retval = -EPERM; |
| 4204 | goto unlock_queue_lock; |
| 4205 | } |
| 4206 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4207 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | sbale[0].flags |= direction; |
| 4209 | |
| 4210 | bottom = &fsf_req->qtcb->bottom.support; |
| 4211 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4212 | bottom->option = fsf_cfdc->option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4214 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4215 | fsf_cfdc->sg, |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4216 | ZFCP_MAX_SBALS_PER_REQ); |
| 4217 | if (bytes != ZFCP_CFDC_MAX_SIZE) { |
| 4218 | retval = -ENOMEM; |
| 4219 | goto free_fsf_req; |
| 4220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 4222 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 4223 | retval = zfcp_fsf_req_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | if (retval < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | retval = -EPERM; |
| 4226 | goto free_fsf_req; |
| 4227 | } |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4228 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | wait_event(fsf_req->completion_wq, |
| 4231 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 4232 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4233 | return fsf_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | |
| 4235 | free_fsf_req: |
| 4236 | zfcp_fsf_req_free(fsf_req); |
| 4237 | unlock_queue_lock: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4238 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4239 | return ERR_PTR(retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4242 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | { |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 4244 | if (fsf_req->qtcb->header.fsf_status != FSF_GOOD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | static inline int |
| 4249 | zfcp_fsf_req_sbal_check(unsigned long *flags, |
| 4250 | struct zfcp_qdio_queue *queue, int needed) |
| 4251 | { |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4252 | write_lock_irqsave(&queue->lock, *flags); |
| 4253 | if (likely(atomic_read(&queue->count) >= needed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | return 1; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4255 | write_unlock_irqrestore(&queue->lock, *flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | return 0; |
| 4257 | } |
| 4258 | |
| 4259 | /* |
| 4260 | * set qtcb pointer in fsf_req and initialize QTCB |
| 4261 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 4262 | static void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4263 | zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | { |
| 4265 | if (likely(fsf_req->qtcb != NULL)) { |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4266 | fsf_req->qtcb->prefix.req_seq_no = |
| 4267 | fsf_req->adapter->fsf_req_seq_no; |
| 4268 | fsf_req->qtcb->prefix.req_id = fsf_req->req_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4270 | fsf_req->qtcb->prefix.qtcb_type = |
| 4271 | fsf_qtcb_type[fsf_req->fsf_command]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4273 | fsf_req->qtcb->header.req_handle = fsf_req->req_id; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4274 | fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | /** |
| 4279 | * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue |
| 4280 | * @adapter: adapter for which request queue is examined |
| 4281 | * @req_flags: flags indicating whether to wait for needed SBAL or not |
| 4282 | * @lock_flags: lock_flags if queue_lock is taken |
| 4283 | * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4284 | * Locks: lock adapter->req_q->lock on success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | */ |
| 4286 | static int |
| 4287 | zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags, |
| 4288 | unsigned long *lock_flags) |
| 4289 | { |
| 4290 | long ret; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4291 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | |
| 4293 | if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) { |
| 4294 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4295 | zfcp_fsf_req_sbal_check(lock_flags, req_q, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | ZFCP_SBAL_TIMEOUT); |
| 4297 | if (ret < 0) |
| 4298 | return ret; |
| 4299 | if (!ret) |
| 4300 | return -EIO; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4301 | } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_q, 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | return -EIO; |
| 4303 | |
| 4304 | return 0; |
| 4305 | } |
| 4306 | |
| 4307 | /* |
| 4308 | * function: zfcp_fsf_req_create |
| 4309 | * |
| 4310 | * purpose: create an FSF request at the specified adapter and |
| 4311 | * setup common fields |
| 4312 | * |
| 4313 | * returns: -ENOMEM if there was insufficient memory for a request |
| 4314 | * -EIO if no qdio buffers could be allocate to the request |
| 4315 | * -EINVAL/-EPERM on bug conditions in req_dequeue |
| 4316 | * 0 in success |
| 4317 | * |
| 4318 | * note: The created request is returned by reference. |
| 4319 | * |
| 4320 | * locks: lock of concerned request queue must not be held, |
| 4321 | * but is held on completion (write, irqsave) |
| 4322 | */ |
| 4323 | int |
| 4324 | zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags, |
| 4325 | mempool_t *pool, unsigned long *lock_flags, |
| 4326 | struct zfcp_fsf_req **fsf_req_p) |
| 4327 | { |
| 4328 | volatile struct qdio_buffer_element *sbale; |
| 4329 | struct zfcp_fsf_req *fsf_req = NULL; |
| 4330 | int ret = 0; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4331 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | |
| 4333 | /* allocate new FSF request */ |
| 4334 | fsf_req = zfcp_fsf_req_alloc(pool, req_flags); |
| 4335 | if (unlikely(NULL == fsf_req)) { |
Joe Perches | ceb3dfb | 2008-01-26 14:11:10 +0100 | [diff] [blame] | 4336 | ZFCP_LOG_DEBUG("error: Could not put an FSF request into " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | "the outbound (send) queue.\n"); |
| 4338 | ret = -ENOMEM; |
| 4339 | goto failed_fsf_req; |
| 4340 | } |
| 4341 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4342 | fsf_req->adapter = adapter; |
| 4343 | fsf_req->fsf_command = fsf_cmd; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4344 | INIT_LIST_HEAD(&fsf_req->list); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 4345 | init_timer(&fsf_req->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 4347 | /* initialize waitqueue which may be used to wait on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | this request completion */ |
| 4349 | init_waitqueue_head(&fsf_req->completion_wq); |
| 4350 | |
| 4351 | ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); |
Christof Schmitt | 801e0ce | 2007-05-08 11:15:48 +0200 | [diff] [blame] | 4352 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | goto failed_sbals; |
Christof Schmitt | 801e0ce | 2007-05-08 11:15:48 +0200 | [diff] [blame] | 4354 | |
| 4355 | /* this is serialized (we are holding req_queue-lock of adapter) */ |
| 4356 | if (adapter->req_no == 0) |
| 4357 | adapter->req_no++; |
| 4358 | fsf_req->req_id = adapter->req_no++; |
| 4359 | |
| 4360 | zfcp_fsf_req_qtcb_init(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | |
| 4362 | /* |
| 4363 | * We hold queue_lock here. Check if QDIOUP is set and let request fail |
| 4364 | * if it is not set (see also *_open_qdio and *_close_qdio). |
| 4365 | */ |
| 4366 | |
| 4367 | if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) { |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4368 | write_unlock_irqrestore(&req_q->lock, *lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | ret = -EIO; |
| 4370 | goto failed_sbals; |
| 4371 | } |
| 4372 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4373 | if (fsf_req->qtcb) { |
| 4374 | fsf_req->seq_no = adapter->fsf_req_seq_no; |
| 4375 | fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
| 4376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | fsf_req->sbal_number = 1; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4378 | fsf_req->sbal_first = req_q->first; |
| 4379 | fsf_req->sbal_last = req_q->first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | fsf_req->sbale_curr = 1; |
| 4381 | |
| 4382 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) { |
| 4383 | fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
| 4384 | } |
| 4385 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4386 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | |
| 4388 | /* setup common SBALE fields */ |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4389 | sbale[0].addr = (void *) fsf_req->req_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; |
| 4391 | if (likely(fsf_req->qtcb != NULL)) { |
| 4392 | sbale[1].addr = (void *) fsf_req->qtcb; |
| 4393 | sbale[1].length = sizeof(struct fsf_qtcb); |
| 4394 | } |
| 4395 | |
| 4396 | ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n", |
| 4397 | fsf_req->sbal_number, fsf_req->sbal_first); |
| 4398 | |
| 4399 | goto success; |
| 4400 | |
| 4401 | failed_sbals: |
| 4402 | /* dequeue new FSF request previously enqueued */ |
| 4403 | zfcp_fsf_req_free(fsf_req); |
| 4404 | fsf_req = NULL; |
| 4405 | |
| 4406 | failed_fsf_req: |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4407 | write_lock_irqsave(&req_q->lock, *lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | success: |
| 4409 | *fsf_req_p = fsf_req; |
| 4410 | return ret; |
| 4411 | } |
| 4412 | |
| 4413 | /* |
| 4414 | * function: zfcp_fsf_req_send |
| 4415 | * |
| 4416 | * purpose: start transfer of FSF request via QDIO |
| 4417 | * |
| 4418 | * returns: 0 - request transfer succesfully started |
| 4419 | * !0 - start of request transfer failed |
| 4420 | */ |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 4421 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | { |
| 4423 | struct zfcp_adapter *adapter; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4424 | struct zfcp_qdio_queue *req_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | volatile struct qdio_buffer_element *sbale; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4426 | int inc_seq_no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | int retval = 0; |
| 4428 | |
| 4429 | adapter = fsf_req->adapter; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4430 | req_q = &adapter->req_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | |
| 4432 | |
| 4433 | /* FIXME(debug): remove it later */ |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4434 | sbale = zfcp_qdio_sbale_req(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags); |
| 4436 | ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n"); |
| 4437 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr, |
| 4438 | sbale[1].length); |
| 4439 | |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4440 | /* put allocated FSF request into hash table */ |
| 4441 | spin_lock(&adapter->req_list_lock); |
| 4442 | zfcp_reqlist_add(adapter, fsf_req); |
| 4443 | spin_unlock(&adapter->req_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4445 | inc_seq_no = (fsf_req->qtcb != NULL); |
| 4446 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4447 | fsf_req->issued = get_clock(); |
| 4448 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4449 | retval = zfcp_qdio_send(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | |
| 4451 | if (unlikely(retval)) { |
| 4452 | /* Queues are down..... */ |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 4453 | del_timer(&fsf_req->timer); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4454 | spin_lock(&adapter->req_list_lock); |
Heiko Carstens | ca2d02c | 2007-05-08 11:17:54 +0200 | [diff] [blame] | 4455 | zfcp_reqlist_remove(adapter, fsf_req); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 4456 | spin_unlock(&adapter->req_list_lock); |
| 4457 | /* undo changes in request queue made for this request */ |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4458 | atomic_add(fsf_req->sbal_number, &req_q->count); |
| 4459 | req_q->first -= fsf_req->sbal_number; |
| 4460 | req_q->first += QDIO_MAX_BUFFERS_PER_Q; |
| 4461 | req_q->first %= QDIO_MAX_BUFFERS_PER_Q; |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 4462 | zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame^] | 4463 | retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | /* |
| 4466 | * increase FSF sequence counter - |
| 4467 | * this must only be done for request successfully enqueued to |
| 4468 | * QDIO this rejected requests may be cleaned up by calling |
| 4469 | * routines resulting in missing sequence counter values |
| 4470 | * otherwise, |
| 4471 | */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | /* Don't increase for unsolicited status */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4474 | if (inc_seq_no) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | adapter->fsf_req_seq_no++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | } |
| 4477 | return retval; |
| 4478 | } |
| 4479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | #undef ZFCP_LOG_AREA |