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 | d736a27 | 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 | d736a27 | 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 | d736a27 | 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->hydra_version = bottom->adapter_type; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2047 | if (fc_host_permanent_port_name(shost) == -1) |
| 2048 | fc_host_permanent_port_name(shost) = |
| 2049 | fc_host_port_name(shost); |
| 2050 | if (bottom->fc_topology == FSF_TOPO_P2P) { |
| 2051 | adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; |
| 2052 | adapter->peer_wwpn = bottom->plogi_payload.wwpn; |
| 2053 | adapter->peer_wwnn = bottom->plogi_payload.wwnn; |
| 2054 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
| 2055 | } else if (bottom->fc_topology == FSF_TOPO_FABRIC) |
| 2056 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 2057 | else if (bottom->fc_topology == FSF_TOPO_AL) |
| 2058 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
| 2059 | else |
| 2060 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | } else { |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2062 | fc_host_node_name(shost) = 0; |
| 2063 | fc_host_port_name(shost) = 0; |
| 2064 | fc_host_port_id(shost) = 0; |
| 2065 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2066 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | adapter->hydra_version = 0; |
| 2068 | } |
| 2069 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2070 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | adapter->hardware_version = bottom->hardware_version; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2072 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
| 2073 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
| 2074 | EBCASC(fc_host_serial_number(shost), |
| 2075 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2078 | ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n" |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2079 | "WWNN 0x%016Lx, " |
| 2080 | "WWPN 0x%016Lx, " |
| 2081 | "S_ID 0x%08x,\n" |
| 2082 | "adapter version 0x%x, " |
| 2083 | "LIC version 0x%x, " |
| 2084 | "FC link speed %d Gb/s\n", |
| 2085 | zfcp_get_busid_by_adapter(adapter), |
| 2086 | (wwn_t) fc_host_node_name(shost), |
| 2087 | (wwn_t) fc_host_port_name(shost), |
| 2088 | fc_host_port_id(shost), |
| 2089 | adapter->hydra_version, |
| 2090 | adapter->fsf_lic_version, |
| 2091 | fc_host_speed(shost)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) { |
| 2093 | ZFCP_LOG_NORMAL("error: the adapter %s " |
| 2094 | "only supports newer control block " |
| 2095 | "versions in comparison to this device " |
| 2096 | "driver (try updated device driver)\n", |
| 2097 | zfcp_get_busid_by_adapter(adapter)); |
| 2098 | debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver"); |
| 2099 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2100 | return -EIO; |
| 2101 | } |
| 2102 | if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) { |
| 2103 | ZFCP_LOG_NORMAL("error: the adapter %s " |
| 2104 | "only supports older control block " |
| 2105 | "versions than this device driver uses" |
| 2106 | "(consider a microcode upgrade)\n", |
| 2107 | zfcp_get_busid_by_adapter(adapter)); |
| 2108 | debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver"); |
| 2109 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2110 | return -EIO; |
| 2111 | } |
| 2112 | return 0; |
| 2113 | } |
| 2114 | |
| 2115 | /* |
| 2116 | * function: zfcp_fsf_exchange_config_data_handler |
| 2117 | * |
| 2118 | * purpose: is called for finished Exchange Configuration Data command |
| 2119 | * |
| 2120 | * returns: |
| 2121 | */ |
| 2122 | static int |
| 2123 | zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req) |
| 2124 | { |
| 2125 | struct fsf_qtcb_bottom_config *bottom; |
| 2126 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2127 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
| 2129 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 2130 | return -EIO; |
| 2131 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2132 | switch (qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
| 2134 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1)) |
| 2136 | return -EIO; |
| 2137 | |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2138 | switch (fc_host_port_type(adapter->scsi_host)) { |
| 2139 | case FC_PORTTYPE_PTP: |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2140 | ZFCP_LOG_NORMAL("Point-to-Point fibrechannel " |
| 2141 | "configuration detected at adapter %s\n" |
| 2142 | "Peer WWNN 0x%016llx, " |
| 2143 | "peer WWPN 0x%016llx, " |
| 2144 | "peer d_id 0x%06x\n", |
| 2145 | zfcp_get_busid_by_adapter(adapter), |
| 2146 | adapter->peer_wwnn, |
| 2147 | adapter->peer_wwpn, |
| 2148 | adapter->peer_d_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2150 | "top-p-to-p"); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2151 | break; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2152 | case FC_PORTTYPE_NLPORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel " |
| 2154 | "topology detected at adapter %s " |
| 2155 | "unsupported, shutting down adapter\n", |
| 2156 | zfcp_get_busid_by_adapter(adapter)); |
| 2157 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2158 | "top-al"); |
| 2159 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2160 | return -EIO; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2161 | case FC_PORTTYPE_NPORT: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2162 | ZFCP_LOG_NORMAL("Switched fabric fibrechannel " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | "network detected at adapter %s.\n", |
| 2164 | zfcp_get_busid_by_adapter(adapter)); |
| 2165 | break; |
| 2166 | default: |
| 2167 | ZFCP_LOG_NORMAL("bug: The fibrechannel topology " |
| 2168 | "reported by the exchange " |
| 2169 | "configuration command for " |
| 2170 | "the adapter %s is not " |
| 2171 | "of a type known to the zfcp " |
| 2172 | "driver, shutting down adapter\n", |
| 2173 | zfcp_get_busid_by_adapter(adapter)); |
| 2174 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, |
| 2175 | "unknown-topo"); |
| 2176 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2177 | return -EIO; |
| 2178 | } |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2179 | bottom = &qtcb->bottom.config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
| 2181 | ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) " |
| 2182 | "allowed by the adapter %s " |
| 2183 | "is lower than the minimum " |
| 2184 | "required by the driver (%ld bytes).\n", |
| 2185 | bottom->max_qtcb_size, |
| 2186 | zfcp_get_busid_by_adapter(adapter), |
| 2187 | sizeof(struct fsf_qtcb)); |
| 2188 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2189 | "qtcb-size"); |
| 2190 | debug_event(fsf_req->adapter->erp_dbf, 0, |
| 2191 | &bottom->max_qtcb_size, sizeof (u32)); |
| 2192 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2193 | return -EIO; |
| 2194 | } |
| 2195 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
| 2196 | &adapter->status); |
| 2197 | break; |
| 2198 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
| 2199 | debug_text_event(adapter->erp_dbf, 0, "xchg-inco"); |
| 2200 | |
| 2201 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0)) |
| 2202 | return -EIO; |
| 2203 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2204 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status); |
| 2205 | |
| 2206 | zfcp_fsf_link_down_info_eval(adapter, |
| 2207 | &qtcb->header.fsf_status_qual.link_down_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | break; |
| 2209 | default: |
| 2210 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng"); |
| 2211 | debug_event(fsf_req->adapter->erp_dbf, 0, |
| 2212 | &fsf_req->qtcb->header.fsf_status, sizeof (u32)); |
| 2213 | zfcp_erp_adapter_shutdown(adapter, 0); |
| 2214 | return -EIO; |
| 2215 | } |
| 2216 | return 0; |
| 2217 | } |
| 2218 | |
| 2219 | /** |
| 2220 | * zfcp_fsf_exchange_port_data - request information about local port |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2221 | * @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] | 2222 | * @adapter: for which port data is requested |
| 2223 | * @data: response to exchange port data request |
| 2224 | */ |
| 2225 | int |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2226 | zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action, |
| 2227 | struct zfcp_adapter *adapter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | struct fsf_qtcb_bottom_port *data) |
| 2229 | { |
| 2230 | volatile struct qdio_buffer_element *sbale; |
| 2231 | int retval = 0; |
| 2232 | unsigned long lock_flags; |
| 2233 | struct zfcp_fsf_req *fsf_req; |
| 2234 | struct timer_list *timer; |
| 2235 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2236 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | ZFCP_LOG_INFO("error: exchange port data " |
| 2238 | "command not supported by adapter %s\n", |
| 2239 | zfcp_get_busid_by_adapter(adapter)); |
| 2240 | return -EOPNOTSUPP; |
| 2241 | } |
| 2242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | /* setup new FSF request */ |
| 2244 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2245 | erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0, |
| 2246 | 0, &lock_flags, &fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | if (retval < 0) { |
| 2248 | ZFCP_LOG_INFO("error: Out of resources. Could not create an " |
| 2249 | "exchange port data request for" |
| 2250 | "the adapter %s.\n", |
| 2251 | zfcp_get_busid_by_adapter(adapter)); |
| 2252 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, |
| 2253 | lock_flags); |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2254 | return retval; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | if (data) |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2258 | fsf_req->data = (unsigned long) data; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); |
| 2261 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2262 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2263 | |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2264 | if (erp_action) { |
| 2265 | erp_action->fsf_req = fsf_req; |
| 2266 | fsf_req->erp_action = erp_action; |
| 2267 | timer = &erp_action->timer; |
| 2268 | } else { |
| 2269 | timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC); |
| 2270 | if (!timer) { |
| 2271 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, |
| 2272 | lock_flags); |
| 2273 | zfcp_fsf_req_free(fsf_req); |
| 2274 | return -ENOMEM; |
| 2275 | } |
| 2276 | init_timer(timer); |
| 2277 | timer->function = zfcp_fsf_request_timeout_handler; |
| 2278 | timer->data = (unsigned long) adapter; |
| 2279 | timer->expires = ZFCP_FSF_REQUEST_TIMEOUT; |
| 2280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | |
| 2282 | retval = zfcp_fsf_req_send(fsf_req, timer); |
| 2283 | if (retval) { |
| 2284 | ZFCP_LOG_INFO("error: Could not send an exchange port data " |
| 2285 | "command on the adapter %s\n", |
| 2286 | zfcp_get_busid_by_adapter(adapter)); |
| 2287 | zfcp_fsf_req_free(fsf_req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2288 | if (erp_action) |
| 2289 | erp_action->fsf_req = NULL; |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2290 | else |
| 2291 | kfree(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, |
| 2293 | lock_flags); |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2294 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2297 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
Andreas Herrmann | 2448c45 | 2005-12-01 02:50:36 +0100 | [diff] [blame] | 2299 | if (!erp_action) { |
| 2300 | wait_event(fsf_req->completion_wq, |
| 2301 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 2302 | del_timer_sync(timer); |
| 2303 | zfcp_fsf_req_free(fsf_req); |
| 2304 | kfree(timer); |
| 2305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | return retval; |
| 2307 | } |
| 2308 | |
| 2309 | |
| 2310 | /** |
| 2311 | * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request |
| 2312 | * @fsf_req: pointer to struct zfcp_fsf_req |
| 2313 | */ |
| 2314 | static void |
| 2315 | zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req) |
| 2316 | { |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2317 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2318 | struct Scsi_Host *shost = adapter->scsi_host; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2319 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
| 2320 | struct fsf_qtcb_bottom_port *bottom, *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
| 2322 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 2323 | return; |
| 2324 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2325 | switch (qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | case FSF_GOOD: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2327 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
| 2328 | |
| 2329 | bottom = &qtcb->bottom.port; |
| 2330 | data = (struct fsf_qtcb_bottom_port*) fsf_req->data; |
| 2331 | if (data) |
| 2332 | memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port)); |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2333 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 2334 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
| 2335 | else |
| 2336 | fc_host_permanent_port_name(shost) = |
| 2337 | fc_host_port_name(shost); |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 2338 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame^] | 2339 | fc_host_supported_speeds(shost) = bottom->supported_speed; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2340 | break; |
| 2341 | |
| 2342 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
| 2343 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
| 2344 | |
| 2345 | zfcp_fsf_link_down_info_eval(adapter, |
| 2346 | &qtcb->header.fsf_status_qual.link_down_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | break; |
| 2348 | |
| 2349 | default: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2350 | debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng"); |
| 2351 | debug_event(adapter->erp_dbf, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | &fsf_req->qtcb->header.fsf_status, sizeof(u32)); |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | |
| 2357 | /* |
| 2358 | * function: zfcp_fsf_open_port |
| 2359 | * |
| 2360 | * purpose: |
| 2361 | * |
| 2362 | * returns: address of initiated FSF request |
| 2363 | * NULL - request could not be initiated |
| 2364 | */ |
| 2365 | int |
| 2366 | zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
| 2367 | { |
| 2368 | volatile struct qdio_buffer_element *sbale; |
| 2369 | unsigned long lock_flags; |
| 2370 | int retval = 0; |
| 2371 | |
| 2372 | /* setup new FSF request */ |
| 2373 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2374 | FSF_QTCB_OPEN_PORT_WITH_DID, |
| 2375 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2376 | erp_action->adapter->pool.fsf_req_erp, |
| 2377 | &lock_flags, &(erp_action->fsf_req)); |
| 2378 | if (retval < 0) { |
| 2379 | ZFCP_LOG_INFO("error: Could not create open port request " |
| 2380 | "for port 0x%016Lx on adapter %s.\n", |
| 2381 | erp_action->port->wwpn, |
| 2382 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2383 | goto out; |
| 2384 | } |
| 2385 | |
| 2386 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, |
| 2387 | erp_action->fsf_req->sbal_curr, 0); |
| 2388 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2389 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2390 | |
| 2391 | erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id; |
| 2392 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2393 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | erp_action->fsf_req->erp_action = erp_action; |
| 2395 | |
| 2396 | /* start QDIO request for this FSF request */ |
| 2397 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); |
| 2398 | if (retval) { |
| 2399 | ZFCP_LOG_INFO("error: Could not send open port request for " |
| 2400 | "port 0x%016Lx on adapter %s.\n", |
| 2401 | erp_action->port->wwpn, |
| 2402 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2403 | zfcp_fsf_req_free(erp_action->fsf_req); |
| 2404 | erp_action->fsf_req = NULL; |
| 2405 | goto out; |
| 2406 | } |
| 2407 | |
| 2408 | ZFCP_LOG_DEBUG("open port request initiated " |
| 2409 | "(adapter %s, port 0x%016Lx)\n", |
| 2410 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2411 | erp_action->port->wwpn); |
| 2412 | out: |
| 2413 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, |
| 2414 | lock_flags); |
| 2415 | return retval; |
| 2416 | } |
| 2417 | |
| 2418 | /* |
| 2419 | * function: zfcp_fsf_open_port_handler |
| 2420 | * |
| 2421 | * purpose: is called for finished Open Port command |
| 2422 | * |
| 2423 | * returns: |
| 2424 | */ |
| 2425 | static int |
| 2426 | zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2427 | { |
| 2428 | int retval = -EINVAL; |
| 2429 | struct zfcp_port *port; |
| 2430 | struct fsf_plogi *plogi; |
| 2431 | struct fsf_qtcb_header *header; |
| 2432 | u16 subtable, rule, counter; |
| 2433 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2434 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | header = &fsf_req->qtcb->header; |
| 2436 | |
| 2437 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2438 | /* don't change port status in our bookkeeping */ |
| 2439 | goto skip_fsfstatus; |
| 2440 | } |
| 2441 | |
| 2442 | /* evaluate FSF status in QTCB */ |
| 2443 | switch (header->fsf_status) { |
| 2444 | |
| 2445 | case FSF_PORT_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s " |
| 2447 | "is already open.\n", |
| 2448 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2449 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, |
| 2450 | "fsf_s_popen"); |
| 2451 | /* |
| 2452 | * This is a bug, however operation should continue normally |
| 2453 | * if it is simply ignored |
| 2454 | */ |
| 2455 | break; |
| 2456 | |
| 2457 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx " |
| 2459 | "on adapter %s\n", |
| 2460 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2461 | for (counter = 0; counter < 2; counter++) { |
| 2462 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 2463 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 2464 | switch (subtable) { |
| 2465 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 2466 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 2467 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 2468 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 2469 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 2470 | zfcp_act_subtable_type[subtable], rule); |
| 2471 | break; |
| 2472 | } |
| 2473 | } |
| 2474 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); |
| 2475 | zfcp_erp_port_access_denied(port); |
| 2476 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2477 | break; |
| 2478 | |
| 2479 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | ZFCP_LOG_INFO("error: The FSF adapter is out of resources. " |
| 2481 | "The remote port 0x%016Lx on adapter %s " |
| 2482 | "could not be opened. Disabling it.\n", |
| 2483 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2484 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2485 | "fsf_s_max_ports"); |
| 2486 | zfcp_erp_port_failed(port); |
| 2487 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2488 | break; |
| 2489 | |
| 2490 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | switch (header->fsf_status_qual.word[0]) { |
| 2492 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2494 | "fsf_sq_ltest"); |
| 2495 | /* ERP strategy will escalate */ |
| 2496 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2497 | break; |
| 2498 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 2499 | /* ERP strategy will escalate */ |
| 2500 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2501 | "fsf_sq_ulp"); |
| 2502 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2503 | break; |
| 2504 | case FSF_SQ_NO_RETRY_POSSIBLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | ZFCP_LOG_NORMAL("The remote port 0x%016Lx on " |
| 2506 | "adapter %s could not be opened. " |
| 2507 | "Disabling it.\n", |
| 2508 | port->wwpn, |
| 2509 | zfcp_get_busid_by_port(port)); |
| 2510 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, |
| 2511 | "fsf_sq_no_retry"); |
| 2512 | zfcp_erp_port_failed(port); |
| 2513 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2514 | break; |
| 2515 | default: |
| 2516 | ZFCP_LOG_NORMAL |
| 2517 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 2518 | header->fsf_status_qual.word[0]); |
| 2519 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2520 | "fsf_sq_inval:"); |
| 2521 | debug_exception( |
| 2522 | fsf_req->adapter->erp_dbf, 0, |
| 2523 | &header->fsf_status_qual.word[0], |
| 2524 | sizeof (u32)); |
| 2525 | break; |
| 2526 | } |
| 2527 | break; |
| 2528 | |
| 2529 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | /* save port handle assigned by FSF */ |
| 2531 | port->handle = header->port_handle; |
| 2532 | ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s " |
| 2533 | "was opened, it's port handle is 0x%x\n", |
| 2534 | port->wwpn, zfcp_get_busid_by_port(port), |
| 2535 | port->handle); |
| 2536 | /* mark port as open */ |
| 2537 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
| 2538 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 2539 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 2540 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
| 2541 | &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | retval = 0; |
| 2543 | /* check whether D_ID has changed during open */ |
| 2544 | /* |
| 2545 | * FIXME: This check is not airtight, as the FCP channel does |
| 2546 | * not monitor closures of target port connections caused on |
| 2547 | * the remote side. Thus, they might miss out on invalidating |
| 2548 | * locally cached WWPNs (and other N_Port parameters) of gone |
| 2549 | * target ports. So, our heroic attempt to make things safe |
| 2550 | * could be undermined by 'open port' response data tagged with |
| 2551 | * obsolete WWPNs. Another reason to monitor potential |
| 2552 | * connection closures ourself at least (by interpreting |
| 2553 | * incoming ELS' and unsolicited status). It just crosses my |
| 2554 | * mind that one should be able to cross-check by means of |
| 2555 | * another GID_PN straight after a port has been opened. |
| 2556 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
| 2557 | */ |
| 2558 | plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els; |
| 2559 | if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status)) |
| 2560 | { |
| 2561 | if (fsf_req->qtcb->bottom.support.els1_length < |
| 2562 | ((((unsigned long) &plogi->serv_param.wwpn) - |
| 2563 | ((unsigned long) plogi)) + sizeof (u64))) { |
| 2564 | ZFCP_LOG_INFO( |
| 2565 | "warning: insufficient length of " |
| 2566 | "PLOGI payload (%i)\n", |
| 2567 | fsf_req->qtcb->bottom.support.els1_length); |
| 2568 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2569 | "fsf_s_short_plogi:"); |
| 2570 | /* skip sanity check and assume wwpn is ok */ |
| 2571 | } else { |
| 2572 | if (plogi->serv_param.wwpn != port->wwpn) { |
| 2573 | ZFCP_LOG_INFO("warning: d_id of port " |
| 2574 | "0x%016Lx changed during " |
| 2575 | "open\n", port->wwpn); |
| 2576 | debug_text_event( |
| 2577 | fsf_req->adapter->erp_dbf, 0, |
| 2578 | "fsf_s_did_change:"); |
| 2579 | atomic_clear_mask( |
| 2580 | ZFCP_STATUS_PORT_DID_DID, |
| 2581 | &port->status); |
| 2582 | } else |
| 2583 | port->wwnn = plogi->serv_param.wwnn; |
| 2584 | } |
| 2585 | } |
| 2586 | break; |
| 2587 | |
| 2588 | case FSF_UNKNOWN_OP_SUBTYPE: |
| 2589 | /* should never occure, subtype not set in zfcp_fsf_open_port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, " |
| 2591 | "op_subtype=0x%x)\n", |
| 2592 | zfcp_get_busid_by_port(port), |
| 2593 | fsf_req->qtcb->bottom.support.operation_subtype); |
| 2594 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2595 | break; |
| 2596 | |
| 2597 | default: |
| 2598 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2599 | "(debug info 0x%x)\n", |
| 2600 | header->fsf_status); |
| 2601 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 2602 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 2603 | &header->fsf_status, sizeof (u32)); |
| 2604 | break; |
| 2605 | } |
| 2606 | |
| 2607 | skip_fsfstatus: |
| 2608 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); |
| 2609 | return retval; |
| 2610 | } |
| 2611 | |
| 2612 | /* |
| 2613 | * function: zfcp_fsf_close_port |
| 2614 | * |
| 2615 | * purpose: submit FSF command "close port" |
| 2616 | * |
| 2617 | * returns: address of initiated FSF request |
| 2618 | * NULL - request could not be initiated |
| 2619 | */ |
| 2620 | int |
| 2621 | zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
| 2622 | { |
| 2623 | volatile struct qdio_buffer_element *sbale; |
| 2624 | unsigned long lock_flags; |
| 2625 | int retval = 0; |
| 2626 | |
| 2627 | /* setup new FSF request */ |
| 2628 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2629 | FSF_QTCB_CLOSE_PORT, |
| 2630 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2631 | erp_action->adapter->pool.fsf_req_erp, |
| 2632 | &lock_flags, &(erp_action->fsf_req)); |
| 2633 | if (retval < 0) { |
| 2634 | ZFCP_LOG_INFO("error: Could not create a close port request " |
| 2635 | "for port 0x%016Lx on adapter %s.\n", |
| 2636 | erp_action->port->wwpn, |
| 2637 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2638 | goto out; |
| 2639 | } |
| 2640 | |
| 2641 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, |
| 2642 | erp_action->fsf_req->sbal_curr, 0); |
| 2643 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2644 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2645 | |
| 2646 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2647 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | erp_action->fsf_req->erp_action = erp_action; |
| 2649 | erp_action->fsf_req->qtcb->header.port_handle = |
| 2650 | erp_action->port->handle; |
| 2651 | |
| 2652 | /* start QDIO request for this FSF request */ |
| 2653 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); |
| 2654 | if (retval) { |
| 2655 | ZFCP_LOG_INFO("error: Could not send a close port request for " |
| 2656 | "port 0x%016Lx on adapter %s.\n", |
| 2657 | erp_action->port->wwpn, |
| 2658 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2659 | zfcp_fsf_req_free(erp_action->fsf_req); |
| 2660 | erp_action->fsf_req = NULL; |
| 2661 | goto out; |
| 2662 | } |
| 2663 | |
| 2664 | ZFCP_LOG_TRACE("close port request initiated " |
| 2665 | "(adapter %s, port 0x%016Lx)\n", |
| 2666 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2667 | erp_action->port->wwpn); |
| 2668 | out: |
| 2669 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, |
| 2670 | lock_flags); |
| 2671 | return retval; |
| 2672 | } |
| 2673 | |
| 2674 | /* |
| 2675 | * function: zfcp_fsf_close_port_handler |
| 2676 | * |
| 2677 | * purpose: is called for finished Close Port FSF command |
| 2678 | * |
| 2679 | * returns: |
| 2680 | */ |
| 2681 | static int |
| 2682 | zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2683 | { |
| 2684 | int retval = -EINVAL; |
| 2685 | struct zfcp_port *port; |
| 2686 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2687 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
| 2689 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2690 | /* don't change port status in our bookkeeping */ |
| 2691 | goto skip_fsfstatus; |
| 2692 | } |
| 2693 | |
| 2694 | /* evaluate FSF status in QTCB */ |
| 2695 | switch (fsf_req->qtcb->header.fsf_status) { |
| 2696 | |
| 2697 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 2699 | "0x%016Lx on adapter %s invalid. This may happen " |
| 2700 | "occasionally.\n", port->handle, |
| 2701 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2702 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 2703 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 2704 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 2705 | sizeof (union fsf_status_qual)); |
| 2706 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2707 | "fsf_s_phand_nv"); |
| 2708 | zfcp_erp_adapter_reopen(port->adapter, 0); |
| 2709 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2710 | break; |
| 2711 | |
| 2712 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | /* Note: FSF has actually closed the port in this case. |
| 2714 | * The status code is just daft. Fingers crossed for a change |
| 2715 | */ |
| 2716 | retval = 0; |
| 2717 | break; |
| 2718 | |
| 2719 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, " |
| 2721 | "port handle 0x%x\n", port->wwpn, |
| 2722 | zfcp_get_busid_by_port(port), port->handle); |
| 2723 | zfcp_erp_modify_port_status(port, |
| 2724 | ZFCP_STATUS_COMMON_OPEN, |
| 2725 | ZFCP_CLEAR); |
| 2726 | retval = 0; |
| 2727 | break; |
| 2728 | |
| 2729 | default: |
| 2730 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2731 | "(debug info 0x%x)\n", |
| 2732 | fsf_req->qtcb->header.fsf_status); |
| 2733 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 2734 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 2735 | &fsf_req->qtcb->header.fsf_status, |
| 2736 | sizeof (u32)); |
| 2737 | break; |
| 2738 | } |
| 2739 | |
| 2740 | skip_fsfstatus: |
| 2741 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); |
| 2742 | return retval; |
| 2743 | } |
| 2744 | |
| 2745 | /* |
| 2746 | * function: zfcp_fsf_close_physical_port |
| 2747 | * |
| 2748 | * purpose: submit FSF command "close physical port" |
| 2749 | * |
| 2750 | * returns: address of initiated FSF request |
| 2751 | * NULL - request could not be initiated |
| 2752 | */ |
| 2753 | int |
| 2754 | zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
| 2755 | { |
| 2756 | int retval = 0; |
| 2757 | unsigned long lock_flags; |
| 2758 | volatile struct qdio_buffer_element *sbale; |
| 2759 | |
| 2760 | /* setup new FSF request */ |
| 2761 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2762 | FSF_QTCB_CLOSE_PHYSICAL_PORT, |
| 2763 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2764 | erp_action->adapter->pool.fsf_req_erp, |
| 2765 | &lock_flags, &erp_action->fsf_req); |
| 2766 | if (retval < 0) { |
| 2767 | ZFCP_LOG_INFO("error: Could not create close physical port " |
| 2768 | "request (adapter %s, port 0x%016Lx)\n", |
| 2769 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2770 | erp_action->port->wwpn); |
| 2771 | |
| 2772 | goto out; |
| 2773 | } |
| 2774 | |
| 2775 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, |
| 2776 | erp_action->fsf_req->sbal_curr, 0); |
| 2777 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2778 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2779 | |
| 2780 | /* mark port as being closed */ |
| 2781 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, |
| 2782 | &erp_action->port->status); |
| 2783 | /* save a pointer to this port */ |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2784 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2785 | /* port to be closed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | erp_action->fsf_req->qtcb->header.port_handle = |
| 2787 | erp_action->port->handle; |
| 2788 | erp_action->fsf_req->erp_action = erp_action; |
| 2789 | |
| 2790 | /* start QDIO request for this FSF request */ |
| 2791 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); |
| 2792 | if (retval) { |
| 2793 | ZFCP_LOG_INFO("error: Could not send close physical port " |
| 2794 | "request (adapter %s, port 0x%016Lx)\n", |
| 2795 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2796 | erp_action->port->wwpn); |
| 2797 | zfcp_fsf_req_free(erp_action->fsf_req); |
| 2798 | erp_action->fsf_req = NULL; |
| 2799 | goto out; |
| 2800 | } |
| 2801 | |
| 2802 | ZFCP_LOG_TRACE("close physical port request initiated " |
| 2803 | "(adapter %s, port 0x%016Lx)\n", |
| 2804 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 2805 | erp_action->port->wwpn); |
| 2806 | out: |
| 2807 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, |
| 2808 | lock_flags); |
| 2809 | return retval; |
| 2810 | } |
| 2811 | |
| 2812 | /* |
| 2813 | * function: zfcp_fsf_close_physical_port_handler |
| 2814 | * |
| 2815 | * purpose: is called for finished Close Physical Port FSF command |
| 2816 | * |
| 2817 | * returns: |
| 2818 | */ |
| 2819 | static int |
| 2820 | zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req) |
| 2821 | { |
| 2822 | int retval = -EINVAL; |
| 2823 | struct zfcp_port *port; |
| 2824 | struct zfcp_unit *unit; |
| 2825 | struct fsf_qtcb_header *header; |
| 2826 | u16 subtable, rule, counter; |
| 2827 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2828 | port = (struct zfcp_port *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | header = &fsf_req->qtcb->header; |
| 2830 | |
| 2831 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 2832 | /* don't change port status in our bookkeeping */ |
| 2833 | goto skip_fsfstatus; |
| 2834 | } |
| 2835 | |
| 2836 | /* evaluate FSF status in QTCB */ |
| 2837 | switch (header->fsf_status) { |
| 2838 | |
| 2839 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid" |
| 2841 | "(adapter %s, port 0x%016Lx). " |
| 2842 | "This may happen occasionally.\n", |
| 2843 | port->handle, |
| 2844 | zfcp_get_busid_by_port(port), |
| 2845 | port->wwpn); |
| 2846 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 2847 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 2848 | (char *) &header->fsf_status_qual, |
| 2849 | sizeof (union fsf_status_qual)); |
| 2850 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2851 | "fsf_s_phand_nv"); |
| 2852 | zfcp_erp_adapter_reopen(port->adapter, 0); |
| 2853 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2854 | break; |
| 2855 | |
| 2856 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | ZFCP_LOG_NORMAL("Access denied, cannot close " |
| 2858 | "physical port 0x%016Lx on adapter %s\n", |
| 2859 | port->wwpn, zfcp_get_busid_by_port(port)); |
| 2860 | for (counter = 0; counter < 2; counter++) { |
| 2861 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 2862 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 2863 | switch (subtable) { |
| 2864 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 2865 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 2866 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 2867 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 2868 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 2869 | zfcp_act_subtable_type[subtable], rule); |
| 2870 | break; |
| 2871 | } |
| 2872 | } |
| 2873 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); |
| 2874 | zfcp_erp_port_access_denied(port); |
| 2875 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2876 | break; |
| 2877 | |
| 2878 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter " |
| 2880 | "%s needs to be reopened but it was attempted " |
| 2881 | "to close it physically.\n", |
| 2882 | port->wwpn, |
| 2883 | zfcp_get_busid_by_port(port)); |
| 2884 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed"); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 2885 | zfcp_erp_port_boxed(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2887 | ZFCP_STATUS_FSFREQ_RETRY; |
| 2888 | break; |
| 2889 | |
| 2890 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | switch (header->fsf_status_qual.word[0]) { |
| 2892 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2894 | "fsf_sq_ltest"); |
| 2895 | /* This will now be escalated by ERP */ |
| 2896 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2897 | break; |
| 2898 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | /* ERP strategy will escalate */ |
| 2900 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 2901 | "fsf_sq_ulp"); |
| 2902 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2903 | break; |
| 2904 | default: |
| 2905 | ZFCP_LOG_NORMAL |
| 2906 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 2907 | header->fsf_status_qual.word[0]); |
| 2908 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 2909 | "fsf_sq_inval:"); |
| 2910 | debug_exception( |
| 2911 | fsf_req->adapter->erp_dbf, 0, |
| 2912 | &header->fsf_status_qual.word[0], sizeof (u32)); |
| 2913 | break; |
| 2914 | } |
| 2915 | break; |
| 2916 | |
| 2917 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s " |
| 2919 | "physically closed, port handle 0x%x\n", |
| 2920 | port->wwpn, |
| 2921 | zfcp_get_busid_by_port(port), port->handle); |
| 2922 | /* can't use generic zfcp_erp_modify_port_status because |
| 2923 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
| 2924 | */ |
| 2925 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 2926 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 2927 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 2928 | retval = 0; |
| 2929 | break; |
| 2930 | |
| 2931 | default: |
| 2932 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 2933 | "(debug info 0x%x)\n", |
| 2934 | header->fsf_status); |
| 2935 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 2936 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 2937 | &header->fsf_status, sizeof (u32)); |
| 2938 | break; |
| 2939 | } |
| 2940 | |
| 2941 | skip_fsfstatus: |
| 2942 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); |
| 2943 | return retval; |
| 2944 | } |
| 2945 | |
| 2946 | /* |
| 2947 | * function: zfcp_fsf_open_unit |
| 2948 | * |
| 2949 | * purpose: |
| 2950 | * |
| 2951 | * returns: |
| 2952 | * |
| 2953 | * assumptions: This routine does not check whether the associated |
| 2954 | * remote port has already been opened. This should be |
| 2955 | * done by calling routines. Otherwise some status |
| 2956 | * may be presented by FSF |
| 2957 | */ |
| 2958 | int |
| 2959 | zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
| 2960 | { |
| 2961 | volatile struct qdio_buffer_element *sbale; |
| 2962 | unsigned long lock_flags; |
| 2963 | int retval = 0; |
| 2964 | |
| 2965 | /* setup new FSF request */ |
| 2966 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 2967 | FSF_QTCB_OPEN_LUN, |
| 2968 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 2969 | erp_action->adapter->pool.fsf_req_erp, |
| 2970 | &lock_flags, &(erp_action->fsf_req)); |
| 2971 | if (retval < 0) { |
| 2972 | ZFCP_LOG_INFO("error: Could not create open unit request for " |
| 2973 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", |
| 2974 | erp_action->unit->fcp_lun, |
| 2975 | erp_action->unit->port->wwpn, |
| 2976 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
| 2980 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, |
| 2981 | erp_action->fsf_req->sbal_curr, 0); |
| 2982 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 2983 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2984 | |
| 2985 | erp_action->fsf_req->qtcb->header.port_handle = |
| 2986 | erp_action->port->handle; |
| 2987 | erp_action->fsf_req->qtcb->bottom.support.fcp_lun = |
| 2988 | erp_action->unit->fcp_lun; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 2989 | if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | erp_action->fsf_req->qtcb->bottom.support.option = |
| 2991 | FSF_OPEN_LUN_SUPPRESS_BOXING; |
| 2992 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 2993 | erp_action->fsf_req->data = (unsigned long) erp_action->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | erp_action->fsf_req->erp_action = erp_action; |
| 2995 | |
| 2996 | /* start QDIO request for this FSF request */ |
| 2997 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); |
| 2998 | if (retval) { |
| 2999 | ZFCP_LOG_INFO("error: Could not send an open unit request " |
| 3000 | "on the adapter %s, port 0x%016Lx for " |
| 3001 | "unit 0x%016Lx\n", |
| 3002 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 3003 | erp_action->port->wwpn, |
| 3004 | erp_action->unit->fcp_lun); |
| 3005 | zfcp_fsf_req_free(erp_action->fsf_req); |
| 3006 | erp_action->fsf_req = NULL; |
| 3007 | goto out; |
| 3008 | } |
| 3009 | |
| 3010 | ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, " |
| 3011 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 3012 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 3013 | erp_action->port->wwpn, erp_action->unit->fcp_lun); |
| 3014 | out: |
| 3015 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, |
| 3016 | lock_flags); |
| 3017 | return retval; |
| 3018 | } |
| 3019 | |
| 3020 | /* |
| 3021 | * function: zfcp_fsf_open_unit_handler |
| 3022 | * |
| 3023 | * purpose: is called for finished Open LUN command |
| 3024 | * |
| 3025 | * returns: |
| 3026 | */ |
| 3027 | static int |
| 3028 | zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) |
| 3029 | { |
| 3030 | int retval = -EINVAL; |
| 3031 | struct zfcp_adapter *adapter; |
| 3032 | struct zfcp_unit *unit; |
| 3033 | struct fsf_qtcb_header *header; |
| 3034 | struct fsf_qtcb_bottom_support *bottom; |
| 3035 | struct fsf_queue_designator *queue_designator; |
| 3036 | u16 subtable, rule, counter; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 3037 | int exclusive, readwrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3039 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
| 3041 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 3042 | /* don't change unit status in our bookkeeping */ |
| 3043 | goto skip_fsfstatus; |
| 3044 | } |
| 3045 | |
| 3046 | adapter = fsf_req->adapter; |
| 3047 | header = &fsf_req->qtcb->header; |
| 3048 | bottom = &fsf_req->qtcb->bottom.support; |
| 3049 | queue_designator = &header->fsf_status_qual.fsf_queue_designator; |
| 3050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 3052 | ZFCP_STATUS_UNIT_SHARED | |
| 3053 | ZFCP_STATUS_UNIT_READONLY, |
| 3054 | &unit->status); |
| 3055 | |
| 3056 | /* evaluate FSF status in QTCB */ |
| 3057 | switch (header->fsf_status) { |
| 3058 | |
| 3059 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | ZFCP_LOG_INFO("Temporary port identifier 0x%x " |
| 3061 | "for port 0x%016Lx on adapter %s invalid " |
| 3062 | "This may happen occasionally\n", |
| 3063 | unit->port->handle, |
| 3064 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3065 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3066 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3067 | (char *) &header->fsf_status_qual, |
| 3068 | sizeof (union fsf_status_qual)); |
| 3069 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv"); |
| 3070 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); |
| 3071 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3072 | break; |
| 3073 | |
| 3074 | case FSF_LUN_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on " |
| 3076 | "remote port 0x%016Lx on adapter %s twice.\n", |
| 3077 | unit->fcp_lun, |
| 3078 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3079 | debug_text_exception(adapter->erp_dbf, 0, |
| 3080 | "fsf_s_uopen"); |
| 3081 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3082 | break; |
| 3083 | |
| 3084 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on " |
| 3086 | "remote port 0x%016Lx on adapter %s\n", |
| 3087 | unit->fcp_lun, unit->port->wwpn, |
| 3088 | zfcp_get_busid_by_unit(unit)); |
| 3089 | for (counter = 0; counter < 2; counter++) { |
| 3090 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 3091 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 3092 | switch (subtable) { |
| 3093 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3094 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3095 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3096 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3097 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 3098 | zfcp_act_subtable_type[subtable], rule); |
| 3099 | break; |
| 3100 | } |
| 3101 | } |
| 3102 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_access"); |
| 3103 | zfcp_erp_unit_access_denied(unit); |
| 3104 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 3105 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
| 3106 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3107 | break; |
| 3108 | |
| 3109 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3111 | "needs to be reopened\n", |
| 3112 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3113 | debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed"); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 3114 | zfcp_erp_port_boxed(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3116 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3117 | break; |
| 3118 | |
| 3119 | case FSF_LUN_SHARING_VIOLATION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | if (header->fsf_status_qual.word[0] != 0) { |
| 3121 | ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port " |
| 3122 | "with WWPN 0x%Lx " |
| 3123 | "connected to the adapter %s " |
| 3124 | "is already in use in LPAR%d, CSS%d\n", |
| 3125 | unit->fcp_lun, |
| 3126 | unit->port->wwpn, |
| 3127 | zfcp_get_busid_by_unit(unit), |
| 3128 | queue_designator->hla, |
| 3129 | queue_designator->cssid); |
| 3130 | } else { |
| 3131 | subtable = header->fsf_status_qual.halfword[4]; |
| 3132 | rule = header->fsf_status_qual.halfword[5]; |
| 3133 | switch (subtable) { |
| 3134 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3135 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3136 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3137 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3138 | ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the " |
| 3139 | "remote port with WWPN 0x%Lx " |
| 3140 | "connected to the adapter %s " |
| 3141 | "is denied (%s rule %d)\n", |
| 3142 | unit->fcp_lun, |
| 3143 | unit->port->wwpn, |
| 3144 | zfcp_get_busid_by_unit(unit), |
| 3145 | zfcp_act_subtable_type[subtable], |
| 3146 | rule); |
| 3147 | break; |
| 3148 | } |
| 3149 | } |
| 3150 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3151 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3152 | (char *) &header->fsf_status_qual, |
| 3153 | sizeof (union fsf_status_qual)); |
| 3154 | debug_text_event(adapter->erp_dbf, 2, |
| 3155 | "fsf_s_l_sh_vio"); |
| 3156 | zfcp_erp_unit_access_denied(unit); |
| 3157 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 3158 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
| 3159 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3160 | break; |
| 3161 | |
| 3162 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | ZFCP_LOG_INFO("error: The adapter ran out of resources. " |
| 3164 | "There is no handle (temporary port identifier) " |
| 3165 | "available for unit 0x%016Lx on port 0x%016Lx " |
| 3166 | "on adapter %s\n", |
| 3167 | unit->fcp_lun, |
| 3168 | unit->port->wwpn, |
| 3169 | zfcp_get_busid_by_unit(unit)); |
| 3170 | debug_text_event(adapter->erp_dbf, 1, |
| 3171 | "fsf_s_max_units"); |
| 3172 | zfcp_erp_unit_failed(unit); |
| 3173 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3174 | break; |
| 3175 | |
| 3176 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | switch (header->fsf_status_qual.word[0]) { |
| 3178 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | /* Re-establish link to port */ |
| 3180 | debug_text_event(adapter->erp_dbf, 1, |
| 3181 | "fsf_sq_ltest"); |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3182 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3184 | break; |
| 3185 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | /* ERP strategy will escalate */ |
| 3187 | debug_text_event(adapter->erp_dbf, 1, |
| 3188 | "fsf_sq_ulp"); |
| 3189 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3190 | break; |
| 3191 | default: |
| 3192 | ZFCP_LOG_NORMAL |
| 3193 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 3194 | header->fsf_status_qual.word[0]); |
| 3195 | debug_text_event(adapter->erp_dbf, 0, |
| 3196 | "fsf_sq_inval:"); |
| 3197 | debug_exception(adapter->erp_dbf, 0, |
| 3198 | &header->fsf_status_qual.word[0], |
| 3199 | sizeof (u32)); |
| 3200 | } |
| 3201 | break; |
| 3202 | |
| 3203 | case FSF_INVALID_COMMAND_OPTION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | ZFCP_LOG_NORMAL( |
| 3205 | "Invalid option 0x%x has been specified " |
| 3206 | "in QTCB bottom sent to the adapter %s\n", |
| 3207 | bottom->option, |
| 3208 | zfcp_get_busid_by_adapter(adapter)); |
| 3209 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3210 | retval = -EINVAL; |
| 3211 | break; |
| 3212 | |
| 3213 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | /* save LUN handle assigned by FSF */ |
| 3215 | unit->handle = header->lun_handle; |
| 3216 | ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on " |
| 3217 | "adapter %s opened, port handle 0x%x\n", |
| 3218 | unit->fcp_lun, |
| 3219 | unit->port->wwpn, |
| 3220 | zfcp_get_busid_by_unit(unit), |
| 3221 | unit->handle); |
| 3222 | /* mark unit as open */ |
| 3223 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 3224 | |
| 3225 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && |
| 3226 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && |
| 3227 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { |
| 3228 | exclusive = (bottom->lun_access_info & |
| 3229 | FSF_UNIT_ACCESS_EXCLUSIVE); |
| 3230 | readwrite = (bottom->lun_access_info & |
| 3231 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); |
| 3232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | if (!exclusive) |
| 3234 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, |
| 3235 | &unit->status); |
| 3236 | |
| 3237 | if (!readwrite) { |
| 3238 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, |
| 3239 | &unit->status); |
| 3240 | ZFCP_LOG_NORMAL("read-only access for unit " |
| 3241 | "(adapter %s, wwpn=0x%016Lx, " |
| 3242 | "fcp_lun=0x%016Lx)\n", |
| 3243 | zfcp_get_busid_by_unit(unit), |
| 3244 | unit->port->wwpn, |
| 3245 | unit->fcp_lun); |
| 3246 | } |
| 3247 | |
| 3248 | if (exclusive && !readwrite) { |
| 3249 | ZFCP_LOG_NORMAL("exclusive access of read-only " |
| 3250 | "unit not supported\n"); |
| 3251 | zfcp_erp_unit_failed(unit); |
| 3252 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3253 | zfcp_erp_unit_shutdown(unit, 0); |
| 3254 | } else if (!exclusive && readwrite) { |
| 3255 | ZFCP_LOG_NORMAL("shared access of read-write " |
| 3256 | "unit not supported\n"); |
| 3257 | zfcp_erp_unit_failed(unit); |
| 3258 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3259 | zfcp_erp_unit_shutdown(unit, 0); |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | retval = 0; |
| 3264 | break; |
| 3265 | |
| 3266 | default: |
| 3267 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 3268 | "(debug info 0x%x)\n", |
| 3269 | header->fsf_status); |
| 3270 | debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 3271 | debug_exception(adapter->erp_dbf, 0, |
| 3272 | &header->fsf_status, sizeof (u32)); |
| 3273 | break; |
| 3274 | } |
| 3275 | |
| 3276 | skip_fsfstatus: |
| 3277 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); |
| 3278 | return retval; |
| 3279 | } |
| 3280 | |
| 3281 | /* |
| 3282 | * function: zfcp_fsf_close_unit |
| 3283 | * |
| 3284 | * purpose: |
| 3285 | * |
| 3286 | * returns: address of fsf_req - request successfully initiated |
| 3287 | * NULL - |
| 3288 | * |
| 3289 | * assumptions: This routine does not check whether the associated |
| 3290 | * remote port/lun has already been opened. This should be |
| 3291 | * done by calling routines. Otherwise some status |
| 3292 | * may be presented by FSF |
| 3293 | */ |
| 3294 | int |
| 3295 | zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
| 3296 | { |
| 3297 | volatile struct qdio_buffer_element *sbale; |
| 3298 | unsigned long lock_flags; |
| 3299 | int retval = 0; |
| 3300 | |
| 3301 | /* setup new FSF request */ |
| 3302 | retval = zfcp_fsf_req_create(erp_action->adapter, |
| 3303 | FSF_QTCB_CLOSE_LUN, |
| 3304 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, |
| 3305 | erp_action->adapter->pool.fsf_req_erp, |
| 3306 | &lock_flags, &(erp_action->fsf_req)); |
| 3307 | if (retval < 0) { |
| 3308 | ZFCP_LOG_INFO("error: Could not create close unit request for " |
| 3309 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", |
| 3310 | erp_action->unit->fcp_lun, |
| 3311 | erp_action->port->wwpn, |
| 3312 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 3313 | goto out; |
| 3314 | } |
| 3315 | |
| 3316 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, |
| 3317 | erp_action->fsf_req->sbal_curr, 0); |
| 3318 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 3319 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 3320 | |
| 3321 | erp_action->fsf_req->qtcb->header.port_handle = |
| 3322 | erp_action->port->handle; |
| 3323 | erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle; |
| 3324 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3325 | erp_action->fsf_req->data = (unsigned long) erp_action->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | erp_action->fsf_req->erp_action = erp_action; |
| 3327 | |
| 3328 | /* start QDIO request for this FSF request */ |
| 3329 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); |
| 3330 | if (retval) { |
| 3331 | ZFCP_LOG_INFO("error: Could not send a close unit request for " |
| 3332 | "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n", |
| 3333 | erp_action->unit->fcp_lun, |
| 3334 | erp_action->port->wwpn, |
| 3335 | zfcp_get_busid_by_adapter(erp_action->adapter)); |
| 3336 | zfcp_fsf_req_free(erp_action->fsf_req); |
| 3337 | erp_action->fsf_req = NULL; |
| 3338 | goto out; |
| 3339 | } |
| 3340 | |
| 3341 | ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, " |
| 3342 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 3343 | zfcp_get_busid_by_adapter(erp_action->adapter), |
| 3344 | erp_action->port->wwpn, erp_action->unit->fcp_lun); |
| 3345 | out: |
| 3346 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, |
| 3347 | lock_flags); |
| 3348 | return retval; |
| 3349 | } |
| 3350 | |
| 3351 | /* |
| 3352 | * function: zfcp_fsf_close_unit_handler |
| 3353 | * |
| 3354 | * purpose: is called for finished Close LUN FSF command |
| 3355 | * |
| 3356 | * returns: |
| 3357 | */ |
| 3358 | static int |
| 3359 | zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req) |
| 3360 | { |
| 3361 | int retval = -EINVAL; |
| 3362 | struct zfcp_unit *unit; |
| 3363 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3364 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | |
| 3366 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 3367 | /* don't change unit status in our bookkeeping */ |
| 3368 | goto skip_fsfstatus; |
| 3369 | } |
| 3370 | |
| 3371 | /* evaluate FSF status in QTCB */ |
| 3372 | switch (fsf_req->qtcb->header.fsf_status) { |
| 3373 | |
| 3374 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 3376 | "0x%016Lx on adapter %s invalid. This may " |
| 3377 | "happen in rare circumstances\n", |
| 3378 | unit->port->handle, |
| 3379 | unit->port->wwpn, |
| 3380 | zfcp_get_busid_by_unit(unit)); |
| 3381 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3382 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3383 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 3384 | sizeof (union fsf_status_qual)); |
| 3385 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3386 | "fsf_s_phand_nv"); |
| 3387 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3389 | break; |
| 3390 | |
| 3391 | case FSF_LUN_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit " |
| 3393 | "0x%016Lx on port 0x%016Lx on adapter %s is " |
| 3394 | "invalid. This may happen occasionally.\n", |
| 3395 | unit->handle, |
| 3396 | unit->fcp_lun, |
| 3397 | unit->port->wwpn, |
| 3398 | zfcp_get_busid_by_unit(unit)); |
| 3399 | ZFCP_LOG_DEBUG("Status qualifier data:\n"); |
| 3400 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3401 | (char *) &fsf_req->qtcb->header.fsf_status_qual, |
| 3402 | sizeof (union fsf_status_qual)); |
| 3403 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3404 | "fsf_s_lhand_nv"); |
| 3405 | zfcp_erp_port_reopen(unit->port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3407 | break; |
| 3408 | |
| 3409 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3411 | "needs to be reopened\n", |
| 3412 | unit->port->wwpn, |
| 3413 | zfcp_get_busid_by_unit(unit)); |
| 3414 | debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed"); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 3415 | zfcp_erp_port_boxed(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3417 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3418 | break; |
| 3419 | |
| 3420 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
| 3422 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | /* re-establish link to port */ |
| 3424 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3425 | "fsf_sq_ltest"); |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3426 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3428 | break; |
| 3429 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | /* ERP strategy will escalate */ |
| 3431 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3432 | "fsf_sq_ulp"); |
| 3433 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3434 | break; |
| 3435 | default: |
| 3436 | ZFCP_LOG_NORMAL |
| 3437 | ("bug: Wrong status qualifier 0x%x arrived.\n", |
| 3438 | fsf_req->qtcb->header.fsf_status_qual.word[0]); |
| 3439 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 3440 | "fsf_sq_inval:"); |
| 3441 | debug_exception( |
| 3442 | fsf_req->adapter->erp_dbf, 0, |
| 3443 | &fsf_req->qtcb->header.fsf_status_qual.word[0], |
| 3444 | sizeof (u32)); |
| 3445 | break; |
| 3446 | } |
| 3447 | break; |
| 3448 | |
| 3449 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s " |
| 3451 | "closed, port handle 0x%x\n", |
| 3452 | unit->fcp_lun, |
| 3453 | unit->port->wwpn, |
| 3454 | zfcp_get_busid_by_unit(unit), |
| 3455 | unit->handle); |
| 3456 | /* mark unit as closed */ |
| 3457 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 3458 | retval = 0; |
| 3459 | break; |
| 3460 | |
| 3461 | default: |
| 3462 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " |
| 3463 | "(debug info 0x%x)\n", |
| 3464 | fsf_req->qtcb->header.fsf_status); |
| 3465 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 3466 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 3467 | &fsf_req->qtcb->header.fsf_status, |
| 3468 | sizeof (u32)); |
| 3469 | break; |
| 3470 | } |
| 3471 | |
| 3472 | skip_fsfstatus: |
| 3473 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); |
| 3474 | return retval; |
| 3475 | } |
| 3476 | |
| 3477 | /** |
| 3478 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) |
| 3479 | * @adapter: adapter where scsi command is issued |
| 3480 | * @unit: unit where command is sent to |
| 3481 | * @scsi_cmnd: scsi command to be sent |
| 3482 | * @timer: timer to be started when request is initiated |
| 3483 | * @req_flags: flags for fsf_request |
| 3484 | */ |
| 3485 | int |
| 3486 | zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, |
| 3487 | struct zfcp_unit *unit, |
| 3488 | struct scsi_cmnd * scsi_cmnd, |
| 3489 | struct timer_list *timer, int req_flags) |
| 3490 | { |
| 3491 | struct zfcp_fsf_req *fsf_req = NULL; |
| 3492 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 3493 | unsigned int sbtype; |
| 3494 | unsigned long lock_flags; |
| 3495 | int real_bytes = 0; |
| 3496 | int retval = 0; |
| 3497 | int mask; |
| 3498 | |
| 3499 | /* setup new FSF request */ |
| 3500 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 3501 | adapter->pool.fsf_req_scsi, |
| 3502 | &lock_flags, &fsf_req); |
| 3503 | if (unlikely(retval < 0)) { |
| 3504 | ZFCP_LOG_DEBUG("error: Could not create FCP command request " |
| 3505 | "for unit 0x%016Lx on port 0x%016Lx on " |
| 3506 | "adapter %s\n", |
| 3507 | unit->fcp_lun, |
| 3508 | unit->port->wwpn, |
| 3509 | zfcp_get_busid_by_adapter(adapter)); |
| 3510 | goto failed_req_create; |
| 3511 | } |
| 3512 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3513 | zfcp_unit_get(unit); |
| 3514 | fsf_req->unit = unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3516 | /* associate FSF request with SCSI request (for look up on abort) */ |
| 3517 | scsi_cmnd->host_scribble = (char *) fsf_req; |
| 3518 | |
| 3519 | /* associate SCSI command with FSF request */ |
| 3520 | fsf_req->data = (unsigned long) scsi_cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
| 3522 | /* set handles of unit and its parent port in QTCB */ |
| 3523 | fsf_req->qtcb->header.lun_handle = unit->handle; |
| 3524 | fsf_req->qtcb->header.port_handle = unit->port->handle; |
| 3525 | |
| 3526 | /* FSF does not define the structure of the FCP_CMND IU */ |
| 3527 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 3528 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 3529 | |
| 3530 | /* |
| 3531 | * set depending on data direction: |
| 3532 | * data direction bits in SBALE (SB Type) |
| 3533 | * data direction bits in QTCB |
| 3534 | * data direction bits in FCP_CMND IU |
| 3535 | */ |
| 3536 | switch (scsi_cmnd->sc_data_direction) { |
| 3537 | case DMA_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 3539 | /* |
| 3540 | * FIXME(qdio): |
| 3541 | * what is the correct type for commands |
| 3542 | * without 'real' data buffers? |
| 3543 | */ |
| 3544 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 3545 | break; |
| 3546 | case DMA_FROM_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
| 3548 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 3549 | fcp_cmnd_iu->rddata = 1; |
| 3550 | break; |
| 3551 | case DMA_TO_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; |
| 3553 | sbtype = SBAL_FLAGS0_TYPE_WRITE; |
| 3554 | fcp_cmnd_iu->wddata = 1; |
| 3555 | break; |
| 3556 | case DMA_BIDIRECTIONAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | default: |
| 3558 | /* |
| 3559 | * dummy, catch this condition earlier |
| 3560 | * in zfcp_scsi_queuecommand |
| 3561 | */ |
| 3562 | goto failed_scsi_cmnd; |
| 3563 | } |
| 3564 | |
| 3565 | /* set FC service class in QTCB (3 per default) */ |
| 3566 | fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class; |
| 3567 | |
| 3568 | /* set FCP_LUN in FCP_CMND IU in QTCB */ |
| 3569 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 3570 | |
| 3571 | mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED; |
| 3572 | |
| 3573 | /* set task attributes in FCP_CMND IU in QTCB */ |
| 3574 | if (likely((scsi_cmnd->device->simple_tags) || |
| 3575 | (atomic_test_mask(mask, &unit->status)))) |
| 3576 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; |
| 3577 | else |
| 3578 | fcp_cmnd_iu->task_attribute = UNTAGGED; |
| 3579 | |
| 3580 | /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */ |
| 3581 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) { |
| 3582 | fcp_cmnd_iu->add_fcp_cdb_length |
| 3583 | = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; |
| 3584 | ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, " |
| 3585 | "additional FCP_CDB length is 0x%x " |
| 3586 | "(shifted right 2 bits)\n", |
| 3587 | scsi_cmnd->cmd_len, |
| 3588 | fcp_cmnd_iu->add_fcp_cdb_length); |
| 3589 | } |
| 3590 | /* |
| 3591 | * copy SCSI CDB (including additional length, if any) to |
| 3592 | * FCP_CDB in FCP_CMND IU in QTCB |
| 3593 | */ |
| 3594 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 3595 | |
| 3596 | /* FCP CMND IU length in QTCB */ |
| 3597 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = |
| 3598 | sizeof (struct fcp_cmnd_iu) + |
| 3599 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t); |
| 3600 | |
| 3601 | /* generate SBALEs from data buffer */ |
| 3602 | real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd); |
| 3603 | if (unlikely(real_bytes < 0)) { |
| 3604 | if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) { |
| 3605 | ZFCP_LOG_DEBUG( |
| 3606 | "Data did not fit into available buffer(s), " |
| 3607 | "waiting for more...\n"); |
| 3608 | retval = -EIO; |
| 3609 | } else { |
| 3610 | ZFCP_LOG_NORMAL("error: No truncation implemented but " |
| 3611 | "required. Shutting down unit " |
| 3612 | "(adapter %s, port 0x%016Lx, " |
| 3613 | "unit 0x%016Lx)\n", |
| 3614 | zfcp_get_busid_by_unit(unit), |
| 3615 | unit->port->wwpn, |
| 3616 | unit->fcp_lun); |
| 3617 | zfcp_erp_unit_shutdown(unit, 0); |
| 3618 | retval = -EINVAL; |
| 3619 | } |
| 3620 | goto no_fit; |
| 3621 | } |
| 3622 | |
| 3623 | /* set length of FCP data length in FCP_CMND IU in QTCB */ |
| 3624 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
| 3625 | |
| 3626 | ZFCP_LOG_DEBUG("Sending SCSI command:\n"); |
| 3627 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3628 | (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 3629 | |
| 3630 | /* |
| 3631 | * start QDIO request for this FSF request |
| 3632 | * covered by an SBALE) |
| 3633 | */ |
| 3634 | retval = zfcp_fsf_req_send(fsf_req, timer); |
| 3635 | if (unlikely(retval < 0)) { |
| 3636 | ZFCP_LOG_INFO("error: Could not send FCP command request " |
| 3637 | "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n", |
| 3638 | zfcp_get_busid_by_adapter(adapter), |
| 3639 | unit->port->wwpn, |
| 3640 | unit->fcp_lun); |
| 3641 | goto send_failed; |
| 3642 | } |
| 3643 | |
| 3644 | ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, " |
| 3645 | "port 0x%016Lx, unit 0x%016Lx)\n", |
| 3646 | zfcp_get_busid_by_adapter(adapter), |
| 3647 | unit->port->wwpn, |
| 3648 | unit->fcp_lun); |
| 3649 | goto success; |
| 3650 | |
| 3651 | send_failed: |
| 3652 | no_fit: |
| 3653 | failed_scsi_cmnd: |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3654 | zfcp_unit_put(unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | zfcp_fsf_req_free(fsf_req); |
| 3656 | fsf_req = NULL; |
| 3657 | scsi_cmnd->host_scribble = NULL; |
| 3658 | success: |
| 3659 | failed_req_create: |
| 3660 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
| 3661 | return retval; |
| 3662 | } |
| 3663 | |
| 3664 | /* |
| 3665 | * function: zfcp_fsf_send_fcp_command_task_management |
| 3666 | * |
| 3667 | * purpose: |
| 3668 | * |
| 3669 | * returns: |
| 3670 | * |
| 3671 | * FIXME(design): should be watched by a timeout!!! |
| 3672 | * FIXME(design) shouldn't this be modified to return an int |
| 3673 | * also...don't know how though |
| 3674 | * |
| 3675 | */ |
| 3676 | struct zfcp_fsf_req * |
| 3677 | zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter, |
| 3678 | struct zfcp_unit *unit, |
| 3679 | u8 tm_flags, int req_flags) |
| 3680 | { |
| 3681 | struct zfcp_fsf_req *fsf_req = NULL; |
| 3682 | int retval = 0; |
| 3683 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 3684 | unsigned long lock_flags; |
| 3685 | volatile struct qdio_buffer_element *sbale; |
| 3686 | |
| 3687 | /* setup new FSF request */ |
| 3688 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 3689 | adapter->pool.fsf_req_scsi, |
| 3690 | &lock_flags, &fsf_req); |
| 3691 | if (retval < 0) { |
| 3692 | ZFCP_LOG_INFO("error: Could not create FCP command (task " |
| 3693 | "management) request for adapter %s, port " |
| 3694 | " 0x%016Lx, unit 0x%016Lx.\n", |
| 3695 | zfcp_get_busid_by_adapter(adapter), |
| 3696 | unit->port->wwpn, unit->fcp_lun); |
| 3697 | goto out; |
| 3698 | } |
| 3699 | |
| 3700 | /* |
| 3701 | * Used to decide on proper handler in the return path, |
| 3702 | * could be either zfcp_fsf_send_fcp_command_task_handler or |
| 3703 | * zfcp_fsf_send_fcp_command_task_management_handler */ |
| 3704 | |
| 3705 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
| 3706 | |
| 3707 | /* |
| 3708 | * hold a pointer to the unit being target of this |
| 3709 | * task management request |
| 3710 | */ |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3711 | fsf_req->data = (unsigned long) unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | |
| 3713 | /* set FSF related fields in QTCB */ |
| 3714 | fsf_req->qtcb->header.lun_handle = unit->handle; |
| 3715 | fsf_req->qtcb->header.port_handle = unit->port->handle; |
| 3716 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 3717 | fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class; |
| 3718 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = |
| 3719 | sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t); |
| 3720 | |
| 3721 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); |
| 3722 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; |
| 3723 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 3724 | |
| 3725 | /* set FCP related fields in FCP_CMND IU in QTCB */ |
| 3726 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 3727 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 3728 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 3729 | fcp_cmnd_iu->task_management_flags = tm_flags; |
| 3730 | |
| 3731 | /* start QDIO request for this FSF request */ |
| 3732 | zfcp_fsf_start_scsi_er_timer(adapter); |
| 3733 | retval = zfcp_fsf_req_send(fsf_req, NULL); |
| 3734 | if (retval) { |
| 3735 | del_timer(&adapter->scsi_er_timer); |
| 3736 | ZFCP_LOG_INFO("error: Could not send an FCP-command (task " |
| 3737 | "management) on adapter %s, port 0x%016Lx for " |
| 3738 | "unit LUN 0x%016Lx\n", |
| 3739 | zfcp_get_busid_by_adapter(adapter), |
| 3740 | unit->port->wwpn, |
| 3741 | unit->fcp_lun); |
| 3742 | zfcp_fsf_req_free(fsf_req); |
| 3743 | fsf_req = NULL; |
| 3744 | goto out; |
| 3745 | } |
| 3746 | |
| 3747 | ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated " |
| 3748 | "(adapter %s, port 0x%016Lx, unit 0x%016Lx, " |
| 3749 | "tm_flags=0x%x)\n", |
| 3750 | zfcp_get_busid_by_adapter(adapter), |
| 3751 | unit->port->wwpn, |
| 3752 | unit->fcp_lun, |
| 3753 | tm_flags); |
| 3754 | out: |
| 3755 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
| 3756 | return fsf_req; |
| 3757 | } |
| 3758 | |
| 3759 | /* |
| 3760 | * function: zfcp_fsf_send_fcp_command_handler |
| 3761 | * |
| 3762 | * purpose: is called for finished Send FCP Command |
| 3763 | * |
| 3764 | * returns: |
| 3765 | */ |
| 3766 | static int |
| 3767 | zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req) |
| 3768 | { |
| 3769 | int retval = -EINVAL; |
| 3770 | struct zfcp_unit *unit; |
| 3771 | struct fsf_qtcb_header *header; |
| 3772 | u16 subtable, rule, counter; |
| 3773 | |
| 3774 | header = &fsf_req->qtcb->header; |
| 3775 | |
| 3776 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3777 | unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | else |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3779 | unit = fsf_req->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | |
| 3781 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 3782 | /* go directly to calls of special handlers */ |
| 3783 | goto skip_fsfstatus; |
| 3784 | } |
| 3785 | |
| 3786 | /* evaluate FSF status in QTCB */ |
| 3787 | switch (header->fsf_status) { |
| 3788 | |
| 3789 | case FSF_PORT_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
| 3791 | "0x%016Lx on adapter %s invalid\n", |
| 3792 | unit->port->handle, |
| 3793 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3794 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3795 | (char *) &header->fsf_status_qual, |
| 3796 | sizeof (union fsf_status_qual)); |
| 3797 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3798 | "fsf_s_phand_nv"); |
| 3799 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); |
| 3800 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3801 | break; |
| 3802 | |
| 3803 | case FSF_LUN_HANDLE_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit " |
| 3805 | "0x%016Lx on port 0x%016Lx on adapter %s is " |
| 3806 | "invalid. This may happen occasionally.\n", |
| 3807 | unit->handle, |
| 3808 | unit->fcp_lun, |
| 3809 | unit->port->wwpn, |
| 3810 | zfcp_get_busid_by_unit(unit)); |
| 3811 | ZFCP_LOG_NORMAL("Status qualifier data:\n"); |
| 3812 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, |
| 3813 | (char *) &header->fsf_status_qual, |
| 3814 | sizeof (union fsf_status_qual)); |
| 3815 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3816 | "fsf_s_uhand_nv"); |
| 3817 | zfcp_erp_port_reopen(unit->port, 0); |
| 3818 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3819 | break; |
| 3820 | |
| 3821 | case FSF_HANDLE_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed " |
| 3823 | "unexpectedly. (adapter %s, port 0x%016Lx, " |
| 3824 | "unit 0x%016Lx)\n", |
| 3825 | unit->port->handle, |
| 3826 | zfcp_get_busid_by_unit(unit), |
| 3827 | unit->port->wwpn, |
| 3828 | unit->fcp_lun); |
| 3829 | ZFCP_LOG_NORMAL("status qualifier:\n"); |
| 3830 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, |
| 3831 | (char *) &header->fsf_status_qual, |
| 3832 | sizeof (union fsf_status_qual)); |
| 3833 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3834 | "fsf_s_hand_mis"); |
| 3835 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3837 | break; |
| 3838 | |
| 3839 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | if (fsf_req->adapter->fc_service_class <= 3) { |
| 3841 | ZFCP_LOG_NORMAL("error: The adapter %s does " |
| 3842 | "not support fibrechannel class %d.\n", |
| 3843 | zfcp_get_busid_by_unit(unit), |
| 3844 | fsf_req->adapter->fc_service_class); |
| 3845 | } else { |
| 3846 | ZFCP_LOG_NORMAL("bug: The fibrechannel class at " |
| 3847 | "adapter %s is invalid. " |
| 3848 | "(debug info %d)\n", |
| 3849 | zfcp_get_busid_by_unit(unit), |
| 3850 | fsf_req->adapter->fc_service_class); |
| 3851 | } |
| 3852 | /* stop operation for this adapter */ |
| 3853 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, |
| 3854 | "fsf_s_class_nsup"); |
| 3855 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3857 | break; |
| 3858 | |
| 3859 | case FSF_FCPLUN_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on " |
| 3861 | "adapter %s does not have correct unit " |
| 3862 | "handle 0x%x\n", |
| 3863 | unit->fcp_lun, |
| 3864 | unit->port->wwpn, |
| 3865 | zfcp_get_busid_by_unit(unit), |
| 3866 | unit->handle); |
| 3867 | ZFCP_LOG_DEBUG("status qualifier:\n"); |
| 3868 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 3869 | (char *) &header->fsf_status_qual, |
| 3870 | sizeof (union fsf_status_qual)); |
| 3871 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3872 | "fsf_s_fcp_lun_nv"); |
| 3873 | zfcp_erp_port_reopen(unit->port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3875 | break; |
| 3876 | |
| 3877 | case FSF_ACCESS_DENIED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to " |
| 3879 | "unit 0x%016Lx on port 0x%016Lx on " |
| 3880 | "adapter %s\n", unit->fcp_lun, unit->port->wwpn, |
| 3881 | zfcp_get_busid_by_unit(unit)); |
| 3882 | for (counter = 0; counter < 2; counter++) { |
| 3883 | subtable = header->fsf_status_qual.halfword[counter * 2]; |
| 3884 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; |
| 3885 | switch (subtable) { |
| 3886 | case FSF_SQ_CFDC_SUBTABLE_OS: |
| 3887 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: |
| 3888 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: |
| 3889 | case FSF_SQ_CFDC_SUBTABLE_LUN: |
| 3890 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", |
| 3891 | zfcp_act_subtable_type[subtable], rule); |
| 3892 | break; |
| 3893 | } |
| 3894 | } |
| 3895 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); |
| 3896 | zfcp_erp_unit_access_denied(unit); |
| 3897 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3898 | break; |
| 3899 | |
| 3900 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | ZFCP_LOG_INFO("bug: Invalid data direction given for unit " |
| 3902 | "0x%016Lx on port 0x%016Lx on adapter %s " |
| 3903 | "(debug info %d)\n", |
| 3904 | unit->fcp_lun, |
| 3905 | unit->port->wwpn, |
| 3906 | zfcp_get_busid_by_unit(unit), |
| 3907 | fsf_req->qtcb->bottom.io.data_direction); |
| 3908 | /* stop operation for this adapter */ |
| 3909 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 3910 | "fsf_s_dir_ind_nv"); |
| 3911 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3913 | break; |
| 3914 | |
| 3915 | case FSF_CMND_LENGTH_NOT_VALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | ZFCP_LOG_NORMAL |
| 3917 | ("bug: An invalid control-data-block length field " |
| 3918 | "was found in a command for unit 0x%016Lx on port " |
| 3919 | "0x%016Lx on adapter %s " "(debug info %d)\n", |
| 3920 | unit->fcp_lun, unit->port->wwpn, |
| 3921 | zfcp_get_busid_by_unit(unit), |
| 3922 | fsf_req->qtcb->bottom.io.fcp_cmnd_length); |
| 3923 | /* stop operation for this adapter */ |
| 3924 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 3925 | "fsf_s_cmd_len_nv"); |
| 3926 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 3928 | break; |
| 3929 | |
| 3930 | case FSF_PORT_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
| 3932 | "needs to be reopened\n", |
| 3933 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); |
| 3934 | debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed"); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 3935 | zfcp_erp_port_boxed(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 3937 | ZFCP_STATUS_FSFREQ_RETRY; |
| 3938 | break; |
| 3939 | |
| 3940 | case FSF_LUN_BOXED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, " |
| 3942 | "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n", |
| 3943 | zfcp_get_busid_by_unit(unit), |
| 3944 | unit->port->wwpn, unit->fcp_lun); |
| 3945 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed"); |
Andreas Herrmann | d736a27 | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 3946 | zfcp_erp_unit_boxed(unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
| 3948 | | ZFCP_STATUS_FSFREQ_RETRY; |
| 3949 | break; |
| 3950 | |
| 3951 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | switch (header->fsf_status_qual.word[0]) { |
| 3953 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | /* re-establish link to port */ |
| 3955 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3956 | "fsf_sq_ltest"); |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 3957 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | break; |
| 3959 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | /* FIXME(hw) need proper specs for proper action */ |
| 3961 | /* let scsi stack deal with retries and escalation */ |
| 3962 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
| 3963 | "fsf_sq_ulp"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | break; |
| 3965 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | ZFCP_LOG_NORMAL |
Andreas Herrmann | 516a420 | 2005-06-13 13:17:44 +0200 | [diff] [blame] | 3967 | ("Unknown status qualifier 0x%x arrived.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | header->fsf_status_qual.word[0]); |
| 3969 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
| 3970 | "fsf_sq_inval:"); |
| 3971 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 3972 | &header->fsf_status_qual.word[0], |
| 3973 | sizeof(u32)); |
| 3974 | break; |
| 3975 | } |
Andreas Herrmann | 516a420 | 2005-06-13 13:17:44 +0200 | [diff] [blame] | 3976 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | break; |
| 3978 | |
| 3979 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | break; |
| 3981 | |
| 3982 | case FSF_FCP_RSP_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | break; |
| 3984 | |
| 3985 | default: |
| 3986 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); |
| 3987 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 3988 | &header->fsf_status, sizeof(u32)); |
| 3989 | break; |
| 3990 | } |
| 3991 | |
| 3992 | skip_fsfstatus: |
| 3993 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) { |
| 3994 | retval = |
| 3995 | zfcp_fsf_send_fcp_command_task_management_handler(fsf_req); |
| 3996 | } else { |
| 3997 | retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 3998 | fsf_req->unit = NULL; |
| 3999 | zfcp_unit_put(unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | } |
| 4001 | return retval; |
| 4002 | } |
| 4003 | |
| 4004 | /* |
| 4005 | * function: zfcp_fsf_send_fcp_command_task_handler |
| 4006 | * |
| 4007 | * purpose: evaluates FCP_RSP IU |
| 4008 | * |
| 4009 | * returns: |
| 4010 | */ |
| 4011 | static int |
| 4012 | zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req) |
| 4013 | { |
| 4014 | int retval = 0; |
| 4015 | struct scsi_cmnd *scpnt; |
| 4016 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
| 4017 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 4018 | struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *) |
| 4019 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); |
| 4020 | u32 sns_len; |
| 4021 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); |
| 4022 | unsigned long flags; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 4023 | struct zfcp_unit *unit = fsf_req->unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | |
| 4025 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 4026 | scpnt = (struct scsi_cmnd *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | if (unlikely(!scpnt)) { |
| 4028 | ZFCP_LOG_DEBUG |
| 4029 | ("Command with fsf_req %p is not associated to " |
| 4030 | "a scsi command anymore. Aborted?\n", fsf_req); |
| 4031 | goto out; |
| 4032 | } |
| 4033 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
| 4034 | /* FIXME: (design) mid-layer should handle DID_ABORT like |
| 4035 | * DID_SOFT_ERROR by retrying the request for devices |
| 4036 | * that allow retries. |
| 4037 | */ |
| 4038 | ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n"); |
| 4039 | set_host_byte(&scpnt->result, DID_SOFT_ERROR); |
| 4040 | set_driver_byte(&scpnt->result, SUGGEST_RETRY); |
| 4041 | goto skip_fsfstatus; |
| 4042 | } |
| 4043 | |
| 4044 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 4045 | ZFCP_LOG_DEBUG("Setting DID_ERROR\n"); |
| 4046 | set_host_byte(&scpnt->result, DID_ERROR); |
| 4047 | goto skip_fsfstatus; |
| 4048 | } |
| 4049 | |
| 4050 | /* set message byte of result in SCSI command */ |
| 4051 | scpnt->result |= COMMAND_COMPLETE << 8; |
| 4052 | |
| 4053 | /* |
| 4054 | * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte |
| 4055 | * of result in SCSI command |
| 4056 | */ |
| 4057 | scpnt->result |= fcp_rsp_iu->scsi_status; |
| 4058 | if (unlikely(fcp_rsp_iu->scsi_status)) { |
| 4059 | /* DEBUG */ |
| 4060 | ZFCP_LOG_DEBUG("status for SCSI Command:\n"); |
| 4061 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4062 | scpnt->cmnd, scpnt->cmd_len); |
| 4063 | ZFCP_LOG_DEBUG("SCSI status code 0x%x\n", |
| 4064 | fcp_rsp_iu->scsi_status); |
| 4065 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4066 | (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu)); |
| 4067 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4068 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), |
| 4069 | fcp_rsp_iu->fcp_sns_len); |
| 4070 | } |
| 4071 | |
| 4072 | /* check FCP_RSP_INFO */ |
| 4073 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
| 4074 | ZFCP_LOG_DEBUG("rsp_len is valid\n"); |
| 4075 | switch (fcp_rsp_info[3]) { |
| 4076 | case RSP_CODE_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | /* ok, continue */ |
| 4078 | ZFCP_LOG_TRACE("no failure or Task Management " |
| 4079 | "Function complete\n"); |
| 4080 | set_host_byte(&scpnt->result, DID_OK); |
| 4081 | break; |
| 4082 | case RSP_CODE_LENGTH_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | /* hardware bug */ |
| 4084 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " |
| 4085 | "that the fibrechannel protocol data " |
| 4086 | "length differs from the burst length. " |
| 4087 | "The problem occured on unit 0x%016Lx " |
| 4088 | "on port 0x%016Lx on adapter %s", |
| 4089 | unit->fcp_lun, |
| 4090 | unit->port->wwpn, |
| 4091 | zfcp_get_busid_by_unit(unit)); |
| 4092 | /* dump SCSI CDB as prepared by zfcp */ |
| 4093 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4094 | (char *) &fsf_req->qtcb-> |
| 4095 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | set_host_byte(&scpnt->result, DID_ERROR); |
| 4097 | goto skip_fsfstatus; |
| 4098 | case RSP_CODE_FIELD_INVALID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | /* driver or hardware bug */ |
| 4100 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " |
| 4101 | "that the fibrechannel protocol data " |
| 4102 | "fields were incorrectly set up. " |
| 4103 | "The problem occured on the unit " |
| 4104 | "0x%016Lx on port 0x%016Lx on " |
| 4105 | "adapter %s", |
| 4106 | unit->fcp_lun, |
| 4107 | unit->port->wwpn, |
| 4108 | zfcp_get_busid_by_unit(unit)); |
| 4109 | /* dump SCSI CDB as prepared by zfcp */ |
| 4110 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4111 | (char *) &fsf_req->qtcb-> |
| 4112 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
| 4113 | set_host_byte(&scpnt->result, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | goto skip_fsfstatus; |
| 4115 | case RSP_CODE_RO_MISMATCH: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | /* hardware bug */ |
| 4117 | ZFCP_LOG_NORMAL("bug: The FCP response code indicates " |
| 4118 | "that conflicting values for the " |
| 4119 | "fibrechannel payload offset from the " |
| 4120 | "header were found. " |
| 4121 | "The problem occured on unit 0x%016Lx " |
| 4122 | "on port 0x%016Lx on adapter %s.\n", |
| 4123 | unit->fcp_lun, |
| 4124 | unit->port->wwpn, |
| 4125 | zfcp_get_busid_by_unit(unit)); |
| 4126 | /* dump SCSI CDB as prepared by zfcp */ |
| 4127 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4128 | (char *) &fsf_req->qtcb-> |
| 4129 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | set_host_byte(&scpnt->result, DID_ERROR); |
| 4131 | goto skip_fsfstatus; |
| 4132 | default: |
| 4133 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " |
| 4134 | "code was detected for a command. " |
| 4135 | "The problem occured on the unit " |
| 4136 | "0x%016Lx on port 0x%016Lx on " |
| 4137 | "adapter %s (debug info 0x%x)\n", |
| 4138 | unit->fcp_lun, |
| 4139 | unit->port->wwpn, |
| 4140 | zfcp_get_busid_by_unit(unit), |
| 4141 | fcp_rsp_info[3]); |
| 4142 | /* dump SCSI CDB as prepared by zfcp */ |
| 4143 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, |
| 4144 | (char *) &fsf_req->qtcb-> |
| 4145 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | set_host_byte(&scpnt->result, DID_ERROR); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 4147 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | /* check for sense data */ |
| 4152 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
| 4153 | sns_len = FSF_FCP_RSP_SIZE - |
| 4154 | sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len; |
| 4155 | ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n", |
| 4156 | sns_len); |
| 4157 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
| 4158 | ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n", |
| 4159 | SCSI_SENSE_BUFFERSIZE); |
| 4160 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
| 4161 | ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n", |
| 4162 | scpnt->result); |
| 4163 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, |
| 4164 | (void *) &scpnt->cmnd, scpnt->cmd_len); |
| 4165 | |
| 4166 | ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n", |
| 4167 | fcp_rsp_iu->fcp_sns_len); |
| 4168 | memcpy(&scpnt->sense_buffer, |
| 4169 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
| 4170 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, |
| 4171 | (void *) &scpnt->sense_buffer, sns_len); |
| 4172 | } |
| 4173 | |
| 4174 | /* check for overrun */ |
| 4175 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) { |
| 4176 | ZFCP_LOG_INFO("A data overrun was detected for a command. " |
| 4177 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " |
| 4178 | "The response data length is " |
| 4179 | "%d, the original length was %d.\n", |
| 4180 | unit->fcp_lun, |
| 4181 | unit->port->wwpn, |
| 4182 | zfcp_get_busid_by_unit(unit), |
| 4183 | fcp_rsp_iu->fcp_resid, |
| 4184 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); |
| 4185 | } |
| 4186 | |
| 4187 | /* check for underrun */ |
| 4188 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
| 4189 | ZFCP_LOG_INFO("A data underrun was detected for a command. " |
| 4190 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " |
| 4191 | "The response data length is " |
| 4192 | "%d, the original length was %d.\n", |
| 4193 | unit->fcp_lun, |
| 4194 | unit->port->wwpn, |
| 4195 | zfcp_get_busid_by_unit(unit), |
| 4196 | fcp_rsp_iu->fcp_resid, |
| 4197 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); |
| 4198 | |
| 4199 | scpnt->resid = fcp_rsp_iu->fcp_resid; |
| 4200 | if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow) |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 4201 | set_host_byte(&scpnt->result, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | skip_fsfstatus: |
| 4205 | ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result); |
| 4206 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4207 | if (scpnt->result != 0) |
| 4208 | zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt); |
| 4209 | else if (scpnt->retries > 0) |
| 4210 | zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt); |
| 4211 | else |
| 4212 | zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | |
| 4214 | /* cleanup pointer (need this especially for abort) */ |
| 4215 | scpnt->host_scribble = NULL; |
| 4216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | /* always call back */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | (scpnt->scsi_done) (scpnt); |
| 4219 | |
| 4220 | /* |
| 4221 | * We must hold this lock until scsi_done has been called. |
| 4222 | * Otherwise we may call scsi_done after abort regarding this |
| 4223 | * command has completed. |
| 4224 | * Note: scsi_done must not block! |
| 4225 | */ |
| 4226 | out: |
| 4227 | read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags); |
| 4228 | return retval; |
| 4229 | } |
| 4230 | |
| 4231 | /* |
| 4232 | * function: zfcp_fsf_send_fcp_command_task_management_handler |
| 4233 | * |
| 4234 | * purpose: evaluates FCP_RSP IU |
| 4235 | * |
| 4236 | * returns: |
| 4237 | */ |
| 4238 | static int |
| 4239 | zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req) |
| 4240 | { |
| 4241 | int retval = 0; |
| 4242 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
| 4243 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 4244 | 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] | 4245 | struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | |
| 4247 | del_timer(&fsf_req->adapter->scsi_er_timer); |
| 4248 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 4249 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4250 | goto skip_fsfstatus; |
| 4251 | } |
| 4252 | |
| 4253 | /* check FCP_RSP_INFO */ |
| 4254 | switch (fcp_rsp_info[3]) { |
| 4255 | case RSP_CODE_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | /* ok, continue */ |
| 4257 | ZFCP_LOG_DEBUG("no failure or Task Management " |
| 4258 | "Function complete\n"); |
| 4259 | break; |
| 4260 | case RSP_CODE_TASKMAN_UNSUPP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
| 4262 | "is not supported on the target device " |
| 4263 | "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ", |
| 4264 | unit->fcp_lun, |
| 4265 | unit->port->wwpn, |
| 4266 | zfcp_get_busid_by_unit(unit)); |
| 4267 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP; |
| 4268 | break; |
| 4269 | case RSP_CODE_TASKMAN_FAILED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
| 4271 | "failed to complete successfully. " |
| 4272 | "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n", |
| 4273 | unit->fcp_lun, |
| 4274 | unit->port->wwpn, |
| 4275 | zfcp_get_busid_by_unit(unit)); |
| 4276 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4277 | break; |
| 4278 | default: |
| 4279 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " |
| 4280 | "code was detected for a command. " |
| 4281 | "unit 0x%016Lx, port 0x%016Lx, adapter %s " |
| 4282 | "(debug info 0x%x)\n", |
| 4283 | unit->fcp_lun, |
| 4284 | unit->port->wwpn, |
| 4285 | zfcp_get_busid_by_unit(unit), |
| 4286 | fcp_rsp_info[3]); |
| 4287 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 4288 | } |
| 4289 | |
| 4290 | skip_fsfstatus: |
| 4291 | return retval; |
| 4292 | } |
| 4293 | |
| 4294 | |
| 4295 | /* |
| 4296 | * function: zfcp_fsf_control_file |
| 4297 | * |
| 4298 | * purpose: Initiator of the control file upload/download FSF requests |
| 4299 | * |
| 4300 | * returns: 0 - FSF request is successfuly created and queued |
| 4301 | * -EOPNOTSUPP - The FCP adapter does not have Control File support |
| 4302 | * -EINVAL - Invalid direction specified |
| 4303 | * -ENOMEM - Insufficient memory |
| 4304 | * -EPERM - Cannot create FSF request or place it in QDIO queue |
| 4305 | */ |
| 4306 | int |
| 4307 | zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
| 4308 | struct zfcp_fsf_req **fsf_req_ptr, |
| 4309 | u32 fsf_command, |
| 4310 | u32 option, |
| 4311 | struct zfcp_sg_list *sg_list) |
| 4312 | { |
| 4313 | struct zfcp_fsf_req *fsf_req; |
| 4314 | struct fsf_qtcb_bottom_support *bottom; |
| 4315 | volatile struct qdio_buffer_element *sbale; |
| 4316 | struct timer_list *timer; |
| 4317 | unsigned long lock_flags; |
| 4318 | int req_flags = 0; |
| 4319 | int direction; |
| 4320 | int retval = 0; |
| 4321 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 4322 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n", |
| 4324 | zfcp_get_busid_by_adapter(adapter)); |
| 4325 | retval = -EOPNOTSUPP; |
| 4326 | goto out; |
| 4327 | } |
| 4328 | |
| 4329 | switch (fsf_command) { |
| 4330 | |
| 4331 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 4332 | direction = SBAL_FLAGS0_TYPE_WRITE; |
| 4333 | if ((option != FSF_CFDC_OPTION_FULL_ACCESS) && |
| 4334 | (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS)) |
| 4335 | req_flags = ZFCP_WAIT_FOR_SBAL; |
| 4336 | break; |
| 4337 | |
| 4338 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 4339 | direction = SBAL_FLAGS0_TYPE_READ; |
| 4340 | break; |
| 4341 | |
| 4342 | default: |
| 4343 | ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command); |
| 4344 | retval = -EINVAL; |
| 4345 | goto out; |
| 4346 | } |
| 4347 | |
| 4348 | timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL); |
| 4349 | if (!timer) { |
| 4350 | retval = -ENOMEM; |
| 4351 | goto out; |
| 4352 | } |
| 4353 | |
| 4354 | retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags, |
| 4355 | NULL, &lock_flags, &fsf_req); |
| 4356 | if (retval < 0) { |
| 4357 | ZFCP_LOG_INFO("error: Could not create FSF request for the " |
| 4358 | "adapter %s\n", |
| 4359 | zfcp_get_busid_by_adapter(adapter)); |
| 4360 | retval = -EPERM; |
| 4361 | goto unlock_queue_lock; |
| 4362 | } |
| 4363 | |
| 4364 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); |
| 4365 | sbale[0].flags |= direction; |
| 4366 | |
| 4367 | bottom = &fsf_req->qtcb->bottom.support; |
| 4368 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; |
| 4369 | bottom->option = option; |
| 4370 | |
| 4371 | if (sg_list->count > 0) { |
| 4372 | int bytes; |
| 4373 | |
| 4374 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction, |
| 4375 | sg_list->sg, sg_list->count, |
| 4376 | ZFCP_MAX_SBALS_PER_REQ); |
| 4377 | if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) { |
| 4378 | ZFCP_LOG_INFO( |
| 4379 | "error: Could not create sufficient number of " |
| 4380 | "SBALS for an FSF request to the adapter %s\n", |
| 4381 | zfcp_get_busid_by_adapter(adapter)); |
| 4382 | retval = -ENOMEM; |
| 4383 | goto free_fsf_req; |
| 4384 | } |
| 4385 | } else |
| 4386 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 4387 | |
| 4388 | init_timer(timer); |
| 4389 | timer->function = zfcp_fsf_request_timeout_handler; |
| 4390 | timer->data = (unsigned long) adapter; |
| 4391 | timer->expires = ZFCP_FSF_REQUEST_TIMEOUT; |
| 4392 | |
| 4393 | retval = zfcp_fsf_req_send(fsf_req, timer); |
| 4394 | if (retval < 0) { |
| 4395 | ZFCP_LOG_INFO("initiation of cfdc up/download failed" |
| 4396 | "(adapter %s)\n", |
| 4397 | zfcp_get_busid_by_adapter(adapter)); |
| 4398 | retval = -EPERM; |
| 4399 | goto free_fsf_req; |
| 4400 | } |
| 4401 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
| 4402 | |
| 4403 | ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the " |
| 4404 | "adapter %s\n", |
| 4405 | fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ? |
| 4406 | "download" : "upload", |
| 4407 | zfcp_get_busid_by_adapter(adapter)); |
| 4408 | |
| 4409 | wait_event(fsf_req->completion_wq, |
| 4410 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 4411 | |
| 4412 | *fsf_req_ptr = fsf_req; |
| 4413 | del_timer_sync(timer); |
| 4414 | goto free_timer; |
| 4415 | |
| 4416 | free_fsf_req: |
| 4417 | zfcp_fsf_req_free(fsf_req); |
| 4418 | unlock_queue_lock: |
| 4419 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
| 4420 | free_timer: |
| 4421 | kfree(timer); |
| 4422 | out: |
| 4423 | return retval; |
| 4424 | } |
| 4425 | |
| 4426 | |
| 4427 | /* |
| 4428 | * function: zfcp_fsf_control_file_handler |
| 4429 | * |
| 4430 | * purpose: Handler of the control file upload/download FSF requests |
| 4431 | * |
| 4432 | * returns: 0 - FSF request successfuly processed |
| 4433 | * -EAGAIN - Operation has to be repeated because of a temporary problem |
| 4434 | * -EACCES - There is no permission to execute an operation |
| 4435 | * -EPERM - The control file is not in a right format |
| 4436 | * -EIO - There is a problem with the FCP adapter |
| 4437 | * -EINVAL - Invalid operation |
| 4438 | * -EFAULT - User space memory I/O operation fault |
| 4439 | */ |
| 4440 | static int |
| 4441 | zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req) |
| 4442 | { |
| 4443 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 4444 | struct fsf_qtcb_header *header = &fsf_req->qtcb->header; |
| 4445 | struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support; |
| 4446 | int retval = 0; |
| 4447 | |
| 4448 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 4449 | retval = -EINVAL; |
| 4450 | goto skip_fsfstatus; |
| 4451 | } |
| 4452 | |
| 4453 | switch (header->fsf_status) { |
| 4454 | |
| 4455 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | ZFCP_LOG_NORMAL( |
| 4457 | "The FSF request has been successfully completed " |
| 4458 | "on the adapter %s\n", |
| 4459 | zfcp_get_busid_by_adapter(adapter)); |
| 4460 | break; |
| 4461 | |
| 4462 | case FSF_OPERATION_PARTIALLY_SUCCESSFUL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) { |
| 4464 | switch (header->fsf_status_qual.word[0]) { |
| 4465 | |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 4466 | case FSF_SQ_CFDC_HARDENED_ON_SE: |
| 4467 | ZFCP_LOG_NORMAL( |
| 4468 | "CFDC on the adapter %s has being " |
| 4469 | "hardened on primary and secondary SE\n", |
| 4470 | zfcp_get_busid_by_adapter(adapter)); |
| 4471 | break; |
| 4472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE: |
| 4474 | ZFCP_LOG_NORMAL( |
| 4475 | "CFDC of the adapter %s could not " |
| 4476 | "be saved on the SE\n", |
| 4477 | zfcp_get_busid_by_adapter(adapter)); |
| 4478 | break; |
| 4479 | |
| 4480 | case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2: |
| 4481 | ZFCP_LOG_NORMAL( |
| 4482 | "CFDC of the adapter %s could not " |
| 4483 | "be copied to the secondary SE\n", |
| 4484 | zfcp_get_busid_by_adapter(adapter)); |
| 4485 | break; |
| 4486 | |
| 4487 | default: |
| 4488 | ZFCP_LOG_NORMAL( |
| 4489 | "CFDC could not be hardened " |
| 4490 | "on the adapter %s\n", |
| 4491 | zfcp_get_busid_by_adapter(adapter)); |
| 4492 | } |
| 4493 | } |
| 4494 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4495 | retval = -EAGAIN; |
| 4496 | break; |
| 4497 | |
| 4498 | case FSF_AUTHORIZATION_FAILURE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | ZFCP_LOG_NORMAL( |
| 4500 | "Adapter %s does not accept privileged commands\n", |
| 4501 | zfcp_get_busid_by_adapter(adapter)); |
| 4502 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4503 | retval = -EACCES; |
| 4504 | break; |
| 4505 | |
| 4506 | case FSF_CFDC_ERROR_DETECTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | ZFCP_LOG_NORMAL( |
| 4508 | "Error at position %d in the CFDC, " |
| 4509 | "CFDC is discarded by the adapter %s\n", |
| 4510 | header->fsf_status_qual.word[0], |
| 4511 | zfcp_get_busid_by_adapter(adapter)); |
| 4512 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4513 | retval = -EPERM; |
| 4514 | break; |
| 4515 | |
| 4516 | case FSF_CONTROL_FILE_UPDATE_ERROR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | ZFCP_LOG_NORMAL( |
| 4518 | "Adapter %s cannot harden the control file, " |
| 4519 | "file is discarded\n", |
| 4520 | zfcp_get_busid_by_adapter(adapter)); |
| 4521 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4522 | retval = -EIO; |
| 4523 | break; |
| 4524 | |
| 4525 | case FSF_CONTROL_FILE_TOO_LARGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | ZFCP_LOG_NORMAL( |
| 4527 | "Control file is too large, file is discarded " |
| 4528 | "by the adapter %s\n", |
| 4529 | zfcp_get_busid_by_adapter(adapter)); |
| 4530 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4531 | retval = -EIO; |
| 4532 | break; |
| 4533 | |
| 4534 | case FSF_ACCESS_CONFLICT_DETECTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) |
| 4536 | ZFCP_LOG_NORMAL( |
| 4537 | "CFDC has been discarded by the adapter %s, " |
| 4538 | "because activation would impact " |
| 4539 | "%d active connection(s)\n", |
| 4540 | zfcp_get_busid_by_adapter(adapter), |
| 4541 | header->fsf_status_qual.word[0]); |
| 4542 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4543 | retval = -EIO; |
| 4544 | break; |
| 4545 | |
| 4546 | case FSF_CONFLICTS_OVERRULED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) |
| 4548 | ZFCP_LOG_NORMAL( |
| 4549 | "CFDC has been activated on the adapter %s, " |
| 4550 | "but activation has impacted " |
| 4551 | "%d active connection(s)\n", |
| 4552 | zfcp_get_busid_by_adapter(adapter), |
| 4553 | header->fsf_status_qual.word[0]); |
| 4554 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4555 | retval = -EIO; |
| 4556 | break; |
| 4557 | |
| 4558 | case FSF_UNKNOWN_OP_SUBTYPE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, " |
| 4560 | "op_subtype=0x%x)\n", |
| 4561 | zfcp_get_busid_by_adapter(adapter), |
| 4562 | bottom->operation_subtype); |
| 4563 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4564 | retval = -EINVAL; |
| 4565 | break; |
| 4566 | |
| 4567 | case FSF_INVALID_COMMAND_OPTION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | ZFCP_LOG_NORMAL( |
| 4569 | "Invalid option 0x%x has been specified " |
| 4570 | "in QTCB bottom sent to the adapter %s\n", |
| 4571 | bottom->option, |
| 4572 | zfcp_get_busid_by_adapter(adapter)); |
| 4573 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4574 | retval = -EINVAL; |
| 4575 | break; |
| 4576 | |
| 4577 | default: |
| 4578 | ZFCP_LOG_NORMAL( |
| 4579 | "bug: An unknown/unexpected FSF status 0x%08x " |
| 4580 | "was presented on the adapter %s\n", |
| 4581 | header->fsf_status, |
| 4582 | zfcp_get_busid_by_adapter(adapter)); |
| 4583 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval"); |
| 4584 | debug_exception(fsf_req->adapter->erp_dbf, 0, |
| 4585 | &header->fsf_status_qual.word[0], sizeof(u32)); |
| 4586 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 4587 | retval = -EINVAL; |
| 4588 | break; |
| 4589 | } |
| 4590 | |
| 4591 | skip_fsfstatus: |
| 4592 | return retval; |
| 4593 | } |
| 4594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | static inline int |
| 4596 | zfcp_fsf_req_sbal_check(unsigned long *flags, |
| 4597 | struct zfcp_qdio_queue *queue, int needed) |
| 4598 | { |
| 4599 | write_lock_irqsave(&queue->queue_lock, *flags); |
| 4600 | if (likely(atomic_read(&queue->free_count) >= needed)) |
| 4601 | return 1; |
| 4602 | write_unlock_irqrestore(&queue->queue_lock, *flags); |
| 4603 | return 0; |
| 4604 | } |
| 4605 | |
| 4606 | /* |
| 4607 | * set qtcb pointer in fsf_req and initialize QTCB |
| 4608 | */ |
| 4609 | static inline void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4610 | zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | { |
| 4612 | if (likely(fsf_req->qtcb != NULL)) { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4613 | 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] | 4614 | fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req; |
| 4615 | fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4616 | 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] | 4617 | fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION; |
| 4618 | fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4619 | fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue |
| 4625 | * @adapter: adapter for which request queue is examined |
| 4626 | * @req_flags: flags indicating whether to wait for needed SBAL or not |
| 4627 | * @lock_flags: lock_flags if queue_lock is taken |
| 4628 | * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS |
| 4629 | * Locks: lock adapter->request_queue->queue_lock on success |
| 4630 | */ |
| 4631 | static int |
| 4632 | zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags, |
| 4633 | unsigned long *lock_flags) |
| 4634 | { |
| 4635 | long ret; |
| 4636 | struct zfcp_qdio_queue *req_queue = &adapter->request_queue; |
| 4637 | |
| 4638 | if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) { |
| 4639 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
| 4640 | zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1), |
| 4641 | ZFCP_SBAL_TIMEOUT); |
| 4642 | if (ret < 0) |
| 4643 | return ret; |
| 4644 | if (!ret) |
| 4645 | return -EIO; |
| 4646 | } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1)) |
| 4647 | return -EIO; |
| 4648 | |
| 4649 | return 0; |
| 4650 | } |
| 4651 | |
| 4652 | /* |
| 4653 | * function: zfcp_fsf_req_create |
| 4654 | * |
| 4655 | * purpose: create an FSF request at the specified adapter and |
| 4656 | * setup common fields |
| 4657 | * |
| 4658 | * returns: -ENOMEM if there was insufficient memory for a request |
| 4659 | * -EIO if no qdio buffers could be allocate to the request |
| 4660 | * -EINVAL/-EPERM on bug conditions in req_dequeue |
| 4661 | * 0 in success |
| 4662 | * |
| 4663 | * note: The created request is returned by reference. |
| 4664 | * |
| 4665 | * locks: lock of concerned request queue must not be held, |
| 4666 | * but is held on completion (write, irqsave) |
| 4667 | */ |
| 4668 | int |
| 4669 | zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags, |
| 4670 | mempool_t *pool, unsigned long *lock_flags, |
| 4671 | struct zfcp_fsf_req **fsf_req_p) |
| 4672 | { |
| 4673 | volatile struct qdio_buffer_element *sbale; |
| 4674 | struct zfcp_fsf_req *fsf_req = NULL; |
| 4675 | int ret = 0; |
| 4676 | struct zfcp_qdio_queue *req_queue = &adapter->request_queue; |
| 4677 | |
| 4678 | /* allocate new FSF request */ |
| 4679 | fsf_req = zfcp_fsf_req_alloc(pool, req_flags); |
| 4680 | if (unlikely(NULL == fsf_req)) { |
| 4681 | ZFCP_LOG_DEBUG("error: Could not put an FSF request into" |
| 4682 | "the outbound (send) queue.\n"); |
| 4683 | ret = -ENOMEM; |
| 4684 | goto failed_fsf_req; |
| 4685 | } |
| 4686 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4687 | fsf_req->adapter = adapter; |
| 4688 | fsf_req->fsf_command = fsf_cmd; |
| 4689 | |
| 4690 | zfcp_fsf_req_qtcb_init(fsf_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | |
| 4692 | /* initialize waitqueue which may be used to wait on |
| 4693 | this request completion */ |
| 4694 | init_waitqueue_head(&fsf_req->completion_wq); |
| 4695 | |
| 4696 | ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); |
| 4697 | if(ret < 0) { |
| 4698 | goto failed_sbals; |
| 4699 | } |
| 4700 | |
| 4701 | /* |
| 4702 | * We hold queue_lock here. Check if QDIOUP is set and let request fail |
| 4703 | * if it is not set (see also *_open_qdio and *_close_qdio). |
| 4704 | */ |
| 4705 | |
| 4706 | if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) { |
| 4707 | write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags); |
| 4708 | ret = -EIO; |
| 4709 | goto failed_sbals; |
| 4710 | } |
| 4711 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4712 | if (fsf_req->qtcb) { |
| 4713 | fsf_req->seq_no = adapter->fsf_req_seq_no; |
| 4714 | fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
| 4715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | fsf_req->sbal_number = 1; |
| 4717 | fsf_req->sbal_first = req_queue->free_index; |
| 4718 | fsf_req->sbal_curr = req_queue->free_index; |
| 4719 | fsf_req->sbale_curr = 1; |
| 4720 | |
| 4721 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) { |
| 4722 | fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
| 4723 | } |
| 4724 | |
| 4725 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); |
| 4726 | |
| 4727 | /* setup common SBALE fields */ |
| 4728 | sbale[0].addr = fsf_req; |
| 4729 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; |
| 4730 | if (likely(fsf_req->qtcb != NULL)) { |
| 4731 | sbale[1].addr = (void *) fsf_req->qtcb; |
| 4732 | sbale[1].length = sizeof(struct fsf_qtcb); |
| 4733 | } |
| 4734 | |
| 4735 | ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n", |
| 4736 | fsf_req->sbal_number, fsf_req->sbal_first); |
| 4737 | |
| 4738 | goto success; |
| 4739 | |
| 4740 | failed_sbals: |
| 4741 | /* dequeue new FSF request previously enqueued */ |
| 4742 | zfcp_fsf_req_free(fsf_req); |
| 4743 | fsf_req = NULL; |
| 4744 | |
| 4745 | failed_fsf_req: |
| 4746 | write_lock_irqsave(&req_queue->queue_lock, *lock_flags); |
| 4747 | success: |
| 4748 | *fsf_req_p = fsf_req; |
| 4749 | return ret; |
| 4750 | } |
| 4751 | |
| 4752 | /* |
| 4753 | * function: zfcp_fsf_req_send |
| 4754 | * |
| 4755 | * purpose: start transfer of FSF request via QDIO |
| 4756 | * |
| 4757 | * returns: 0 - request transfer succesfully started |
| 4758 | * !0 - start of request transfer failed |
| 4759 | */ |
| 4760 | static int |
| 4761 | zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer) |
| 4762 | { |
| 4763 | struct zfcp_adapter *adapter; |
| 4764 | struct zfcp_qdio_queue *req_queue; |
| 4765 | volatile struct qdio_buffer_element *sbale; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4766 | int inc_seq_no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | int new_distance_from_int; |
| 4768 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | int retval = 0; |
| 4770 | |
| 4771 | adapter = fsf_req->adapter; |
| 4772 | req_queue = &adapter->request_queue, |
| 4773 | |
| 4774 | |
| 4775 | /* FIXME(debug): remove it later */ |
| 4776 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0); |
| 4777 | ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags); |
| 4778 | ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n"); |
| 4779 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr, |
| 4780 | sbale[1].length); |
| 4781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | /* put allocated FSF request at list tail */ |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 4783 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 4785 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4787 | inc_seq_no = (fsf_req->qtcb != NULL); |
| 4788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | /* figure out expiration time of timeout and start timeout */ |
| 4790 | if (unlikely(timer)) { |
| 4791 | timer->expires += jiffies; |
| 4792 | add_timer(timer); |
| 4793 | } |
| 4794 | |
| 4795 | ZFCP_LOG_TRACE("request queue of adapter %s: " |
| 4796 | "next free SBAL is %i, %i free SBALs\n", |
| 4797 | zfcp_get_busid_by_adapter(adapter), |
| 4798 | req_queue->free_index, |
| 4799 | atomic_read(&req_queue->free_count)); |
| 4800 | |
| 4801 | ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, " |
| 4802 | "index_in_queue=%i, count=%i, buffers=%p\n", |
| 4803 | zfcp_get_busid_by_adapter(adapter), |
| 4804 | QDIO_FLAG_SYNC_OUTPUT, |
| 4805 | 0, fsf_req->sbal_first, fsf_req->sbal_number, |
| 4806 | &req_queue->buffer[fsf_req->sbal_first]); |
| 4807 | |
| 4808 | /* |
| 4809 | * adjust the number of free SBALs in request queue as well as |
| 4810 | * position of first one |
| 4811 | */ |
| 4812 | atomic_sub(fsf_req->sbal_number, &req_queue->free_count); |
| 4813 | ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count)); |
| 4814 | req_queue->free_index += fsf_req->sbal_number; /* increase */ |
| 4815 | req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */ |
| 4816 | new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req); |
| 4817 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4818 | fsf_req->issued = get_clock(); |
| 4819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | retval = do_QDIO(adapter->ccw_device, |
| 4821 | QDIO_FLAG_SYNC_OUTPUT, |
| 4822 | 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL); |
| 4823 | |
| 4824 | if (unlikely(retval)) { |
| 4825 | /* Queues are down..... */ |
| 4826 | retval = -EIO; |
| 4827 | /* |
| 4828 | * FIXME(potential race): |
| 4829 | * timer might be expired (absolutely unlikely) |
| 4830 | */ |
| 4831 | if (timer) |
| 4832 | del_timer(timer); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 4833 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | list_del(&fsf_req->list); |
Andreas Herrmann | 1db2c9c | 2005-06-13 13:20:35 +0200 | [diff] [blame] | 4835 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | /* |
| 4837 | * adjust the number of free SBALs in request queue as well as |
| 4838 | * position of first one |
| 4839 | */ |
| 4840 | zfcp_qdio_zero_sbals(req_queue->buffer, |
| 4841 | fsf_req->sbal_first, fsf_req->sbal_number); |
| 4842 | atomic_add(fsf_req->sbal_number, &req_queue->free_count); |
| 4843 | req_queue->free_index -= fsf_req->sbal_number; /* increase */ |
| 4844 | req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q; |
| 4845 | req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ |
| 4846 | ZFCP_LOG_DEBUG |
| 4847 | ("error: do_QDIO failed. Buffers could not be enqueued " |
| 4848 | "to request queue.\n"); |
| 4849 | } else { |
| 4850 | req_queue->distance_from_int = new_distance_from_int; |
| 4851 | /* |
| 4852 | * increase FSF sequence counter - |
| 4853 | * this must only be done for request successfully enqueued to |
| 4854 | * QDIO this rejected requests may be cleaned up by calling |
| 4855 | * routines resulting in missing sequence counter values |
| 4856 | * otherwise, |
| 4857 | */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | /* Don't increase for unsolicited status */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4860 | if (inc_seq_no) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | adapter->fsf_req_seq_no++; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | /* count FSF requests pending */ |
| 4864 | atomic_inc(&adapter->fsf_reqs_active); |
| 4865 | } |
| 4866 | return retval; |
| 4867 | } |
| 4868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | #undef ZFCP_LOG_AREA |