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