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