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