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