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