Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Implementation of FSF commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "zfcp_ext.h" |
| 10 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 11 | static void zfcp_fsf_request_timeout_handler(unsigned long data) |
| 12 | { |
| 13 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; |
| 14 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62, |
| 15 | NULL); |
| 16 | } |
| 17 | |
| 18 | static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, |
| 19 | unsigned long timeout) |
| 20 | { |
| 21 | fsf_req->timer.function = zfcp_fsf_request_timeout_handler; |
| 22 | fsf_req->timer.data = (unsigned long) fsf_req->adapter; |
| 23 | fsf_req->timer.expires = jiffies + timeout; |
| 24 | add_timer(&fsf_req->timer); |
| 25 | } |
| 26 | |
| 27 | static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req) |
| 28 | { |
| 29 | BUG_ON(!fsf_req->erp_action); |
| 30 | fsf_req->timer.function = zfcp_erp_timeout_handler; |
| 31 | fsf_req->timer.data = (unsigned long) fsf_req->erp_action; |
| 32 | fsf_req->timer.expires = jiffies + 30 * HZ; |
| 33 | add_timer(&fsf_req->timer); |
| 34 | } |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* association between FSF command and FSF QTCB type */ |
| 37 | static u32 fsf_qtcb_type[] = { |
| 38 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, |
| 39 | [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND, |
| 40 | [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND, |
| 41 | [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND, |
| 42 | [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND, |
| 43 | [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND, |
| 44 | [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND, |
| 45 | [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND, |
| 46 | [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND, |
| 47 | [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND, |
| 48 | [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND, |
| 49 | [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND, |
| 50 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND |
| 51 | }; |
| 52 | |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 53 | static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table) |
| 54 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 55 | u16 subtable = table >> 16; |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 56 | u16 rule = table & 0xffff; |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 57 | const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" }; |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 58 | |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 59 | if (subtable && subtable < ARRAY_SIZE(act_type)) |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 60 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 61 | "Access denied according to ACT rule type %s, " |
| 62 | "rule %d\n", act_type[subtable], rule); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req, |
| 66 | struct zfcp_port *port) |
| 67 | { |
| 68 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 69 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 70 | "Access denied to port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 71 | (unsigned long long)port->wwpn); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 72 | zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]); |
| 73 | zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]); |
| 74 | zfcp_erp_port_access_denied(port, 55, req); |
| 75 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 76 | } |
| 77 | |
| 78 | static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req, |
| 79 | struct zfcp_unit *unit) |
| 80 | { |
| 81 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 82 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 83 | "Access denied to unit 0x%016Lx on port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 84 | (unsigned long long)unit->fcp_lun, |
| 85 | (unsigned long long)unit->port->wwpn); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 86 | zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]); |
| 87 | zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]); |
| 88 | zfcp_erp_unit_access_denied(unit, 59, req); |
| 89 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 90 | } |
| 91 | |
| 92 | static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req) |
| 93 | { |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 94 | dev_err(&req->adapter->ccw_device->dev, "FCP device not " |
| 95 | "operational because of an unsupported FC class\n"); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 96 | zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req); |
| 97 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 98 | } |
| 99 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 100 | /** |
| 101 | * zfcp_fsf_req_free - free memory used by fsf request |
| 102 | * @fsf_req: pointer to struct zfcp_fsf_req |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 104 | void zfcp_fsf_req_free(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 106 | if (likely(req->pool)) { |
| 107 | mempool_free(req, req->pool); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 111 | if (req->qtcb) { |
| 112 | kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 113 | return; |
| 114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 117 | /** |
| 118 | * zfcp_fsf_req_dismiss_all - dismiss all fsf requests |
| 119 | * @adapter: pointer to struct zfcp_adapter |
| 120 | * |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 121 | * Never ever call this without shutting down the adapter first. |
| 122 | * Otherwise the adapter would continue using and corrupting s390 storage. |
| 123 | * Included BUG_ON() call to ensure this is done. |
| 124 | * ERP is supposed to be the only user of this function. |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 125 | */ |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 126 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 127 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 128 | struct zfcp_fsf_req *req, *tmp; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 129 | unsigned long flags; |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 130 | LIST_HEAD(remove_queue); |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 131 | unsigned int i; |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 132 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 133 | BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 134 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
Martin Peschke | 869b2b4 | 2007-05-09 11:01:20 +0200 | [diff] [blame] | 135 | for (i = 0; i < REQUEST_LIST_SIZE; i++) |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 136 | list_splice_init(&adapter->req_list[i], &remove_queue); |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 137 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); |
| 138 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 139 | list_for_each_entry_safe(req, tmp, &remove_queue, list) { |
| 140 | list_del(&req->list); |
| 141 | req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
| 142 | zfcp_fsf_req_complete(req); |
Swen Schillig | 6fcc471 | 2007-02-07 13:17:57 +0100 | [diff] [blame] | 143 | } |
Volker Sameske | fea9d6c | 2006-08-02 11:05:16 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 146 | static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 148 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 149 | struct zfcp_adapter *adapter = req->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | struct zfcp_port *port; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 151 | int d_id = sr_buf->d_id & ZFCP_DID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | unsigned long flags; |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 155 | list_for_each_entry(port, &adapter->port_list_head, list) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 156 | if (port->d_id == d_id) { |
| 157 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 158 | switch (sr_buf->status_subtype) { |
| 159 | case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: |
| 160 | zfcp_erp_port_reopen(port, 0, 101, req); |
| 161 | break; |
| 162 | case FSF_STATUS_READ_SUB_ERROR_PORT: |
| 163 | zfcp_erp_port_shutdown(port, 0, 122, req); |
| 164 | break; |
| 165 | } |
| 166 | return; |
| 167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 171 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id, |
| 172 | struct fsf_link_down_info *link_down) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 174 | struct zfcp_adapter *adapter = req->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 176 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) |
| 177 | return; |
| 178 | |
| 179 | atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
| 180 | |
| 181 | if (!link_down) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | goto out; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 183 | |
| 184 | switch (link_down->error_code) { |
| 185 | case FSF_PSQ_LINK_NO_LIGHT: |
| 186 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 187 | "There is no light signal from the local " |
| 188 | "fibre channel cable\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 189 | break; |
| 190 | case FSF_PSQ_LINK_WRAP_PLUG: |
| 191 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 192 | "There is a wrap plug instead of a fibre " |
| 193 | "channel cable\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 194 | break; |
| 195 | case FSF_PSQ_LINK_NO_FCP: |
| 196 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 197 | "The adjacent fibre channel node does not " |
| 198 | "support FCP\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 199 | break; |
| 200 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: |
| 201 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 202 | "The FCP device is suspended because of a " |
| 203 | "firmware update\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 204 | break; |
| 205 | case FSF_PSQ_LINK_INVALID_WWPN: |
| 206 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 207 | "The FCP device detected a WWPN that is " |
| 208 | "duplicate or not valid\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 209 | break; |
| 210 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: |
| 211 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 212 | "The fibre channel fabric does not support NPIV\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 213 | break; |
| 214 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: |
| 215 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 216 | "The FCP adapter cannot support more NPIV ports\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 217 | break; |
| 218 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: |
| 219 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 220 | "The adjacent switch cannot support " |
| 221 | "more NPIV ports\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 222 | break; |
| 223 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: |
| 224 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 225 | "The FCP adapter could not log in to the " |
| 226 | "fibre channel fabric\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 227 | break; |
| 228 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: |
| 229 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 230 | "The WWPN assignment file on the FCP adapter " |
| 231 | "has been damaged\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 232 | break; |
| 233 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: |
| 234 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 235 | "The mode table on the FCP adapter " |
| 236 | "has been damaged\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 237 | break; |
| 238 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: |
| 239 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 240 | "All NPIV ports on the FCP adapter have " |
| 241 | "been assigned\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 242 | break; |
| 243 | default: |
| 244 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 245 | "The link between the FCP adapter and " |
| 246 | "the FC fabric is down\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 247 | } |
| 248 | out: |
| 249 | zfcp_erp_adapter_failed(adapter, id, req); |
| 250 | } |
| 251 | |
| 252 | static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req) |
| 253 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 254 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 255 | struct fsf_link_down_info *ldi = |
| 256 | (struct fsf_link_down_info *) &sr_buf->payload; |
| 257 | |
| 258 | switch (sr_buf->status_subtype) { |
| 259 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 260 | zfcp_fsf_link_down_info_eval(req, 38, ldi); |
| 261 | break; |
| 262 | case FSF_STATUS_READ_SUB_FDISC_FAILED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 263 | zfcp_fsf_link_down_info_eval(req, 39, ldi); |
| 264 | break; |
| 265 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 266 | zfcp_fsf_link_down_info_eval(req, 40, NULL); |
| 267 | }; |
| 268 | } |
| 269 | |
| 270 | static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req) |
| 271 | { |
| 272 | struct zfcp_adapter *adapter = req->adapter; |
| 273 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 274 | |
| 275 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
| 276 | zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf); |
| 277 | mempool_free(sr_buf, adapter->pool.data_status_read); |
| 278 | zfcp_fsf_req_free(req); |
| 279 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 282 | zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 283 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 284 | switch (sr_buf->status_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | case FSF_STATUS_READ_PORT_CLOSED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 286 | zfcp_fsf_status_read_port_closed(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | case FSF_STATUS_READ_INCOMING_ELS: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 289 | zfcp_fc_incoming_els(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 294 | dev_warn(&adapter->ccw_device->dev, |
| 295 | "The error threshold for checksum statistics " |
| 296 | "has been exceeded\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | case FSF_STATUS_READ_LINK_DOWN: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 299 | zfcp_fsf_status_read_link_down(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | case FSF_STATUS_READ_LINK_UP: |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 302 | dev_info(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 303 | "The local link has been restored\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* All ports should be marked as ready to run again */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 305 | zfcp_erp_modify_adapter_status(adapter, 30, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | ZFCP_STATUS_COMMON_RUNNING, |
| 307 | ZFCP_SET); |
| 308 | zfcp_erp_adapter_reopen(adapter, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 309 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
| 310 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 311 | 102, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | break; |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 313 | case FSF_STATUS_READ_NOTIFICATION_LOST: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 314 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED) |
| 315 | zfcp_erp_adapter_access_changed(adapter, 135, req); |
| 316 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS) |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 317 | schedule_work(&adapter->scan_work); |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 318 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | case FSF_STATUS_READ_CFDC_UPDATED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 320 | zfcp_erp_adapter_access_changed(adapter, 136, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 322 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 323 | adapter->adapter_features = sr_buf->payload.word[0]; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 324 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 326 | |
| 327 | mempool_free(sr_buf, adapter->pool.data_status_read); |
| 328 | zfcp_fsf_req_free(req); |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 329 | |
| 330 | atomic_inc(&adapter->stat_miss); |
| 331 | schedule_work(&adapter->stat_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 334 | static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 336 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
| 337 | case FSF_SQ_FCP_RSP_AVAILABLE: |
| 338 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 339 | case FSF_SQ_NO_RETRY_POSSIBLE: |
| 340 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 341 | return; |
| 342 | case FSF_SQ_COMMAND_ABORTED: |
| 343 | req->status |= ZFCP_STATUS_FSFREQ_ABORTED; |
| 344 | break; |
| 345 | case FSF_SQ_NO_RECOM: |
| 346 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 347 | "The FCP adapter reported a problem " |
| 348 | "that cannot be recovered\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 349 | zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req); |
| 350 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 352 | /* all non-return stats set FSFREQ_ERROR*/ |
| 353 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 356 | static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req) |
| 357 | { |
| 358 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 359 | return; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 360 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 361 | switch (req->qtcb->header.fsf_status) { |
| 362 | case FSF_UNKNOWN_COMMAND: |
| 363 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 364 | "The FCP adapter does not recognize the command 0x%x\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 365 | req->qtcb->header.fsf_command); |
| 366 | zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req); |
| 367 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 370 | zfcp_fsf_fsfstatus_qual_eval(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 375 | static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 377 | struct zfcp_adapter *adapter = req->adapter; |
| 378 | struct fsf_qtcb *qtcb = req->qtcb; |
| 379 | union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 381 | zfcp_hba_dbf_event_fsf_response(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 383 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
| 384 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 385 | ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */ |
| 386 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 389 | switch (qtcb->prefix.prot_status) { |
| 390 | case FSF_PROT_GOOD: |
| 391 | case FSF_PROT_FSF_STATUS_PRESENTED: |
| 392 | return; |
| 393 | case FSF_PROT_QTCB_VERSION_ERROR: |
| 394 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 395 | "QTCB version 0x%x not supported by FCP adapter " |
| 396 | "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION, |
| 397 | psq->word[0], psq->word[1]); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 398 | zfcp_erp_adapter_shutdown(adapter, 0, 117, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 400 | case FSF_PROT_ERROR_STATE: |
| 401 | case FSF_PROT_SEQ_NUMB_ERROR: |
| 402 | zfcp_erp_adapter_reopen(adapter, 0, 98, req); |
| 403 | req->status |= ZFCP_STATUS_FSFREQ_RETRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 405 | case FSF_PROT_UNSUPP_QTCB_TYPE: |
| 406 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 407 | "The QTCB type is not supported by the FCP adapter\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 408 | zfcp_erp_adapter_shutdown(adapter, 0, 118, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 410 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: |
| 411 | atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 412 | &adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 414 | case FSF_PROT_DUPLICATE_REQUEST_ID: |
| 415 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 416 | "0x%Lx is an ambiguous request identifier\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 417 | (unsigned long long)qtcb->bottom.support.req_handle); |
| 418 | zfcp_erp_adapter_shutdown(adapter, 0, 78, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 420 | case FSF_PROT_LINK_DOWN: |
| 421 | zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info); |
| 422 | /* FIXME: reopening adapter now? better wait for link up */ |
| 423 | zfcp_erp_adapter_reopen(adapter, 0, 79, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 425 | case FSF_PROT_REEST_QUEUE: |
| 426 | /* All ports should be marked as ready to run again */ |
| 427 | zfcp_erp_modify_adapter_status(adapter, 28, NULL, |
| 428 | ZFCP_STATUS_COMMON_RUNNING, |
| 429 | ZFCP_SET); |
| 430 | zfcp_erp_adapter_reopen(adapter, |
| 431 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
| 432 | ZFCP_STATUS_COMMON_ERP_FAILED, 99, req); |
| 433 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | default: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 435 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 436 | "0x%x is not a valid transfer protocol status\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 437 | qtcb->prefix.prot_status); |
| 438 | zfcp_erp_adapter_shutdown(adapter, 0, 119, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 440 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /** |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 444 | * zfcp_fsf_req_complete - process completion of a FSF request |
| 445 | * @fsf_req: The FSF request that has been completed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | * |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 447 | * When a request has been completed either from the FCP adapter, |
| 448 | * or it has been dismissed due to a queue shutdown, this function |
| 449 | * is called to process the completion status and trigger further |
| 450 | * events related to the FSF request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 452 | void zfcp_fsf_req_complete(struct zfcp_fsf_req *req) |
| 453 | { |
| 454 | if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { |
| 455 | zfcp_fsf_status_read_handler(req); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | del_timer(&req->timer); |
| 460 | zfcp_fsf_protstatus_eval(req); |
| 461 | zfcp_fsf_fsfstatus_eval(req); |
| 462 | req->handler(req); |
| 463 | |
| 464 | if (req->erp_action) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 465 | zfcp_erp_notify(req->erp_action, 0); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 466 | req->status |= ZFCP_STATUS_FSFREQ_COMPLETED; |
| 467 | |
| 468 | if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) |
| 469 | zfcp_fsf_req_free(req); |
| 470 | else |
| 471 | /* notify initiator waiting for the requests completion */ |
| 472 | /* |
| 473 | * FIXME: Race! We must not access fsf_req here as it might have been |
| 474 | * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED |
| 475 | * flag. It's an improbable case. But, we have the same paranoia for |
| 476 | * the cleanup flag already. |
| 477 | * Might better be handled using complete()? |
| 478 | * (setting the flag and doing wakeup ought to be atomic |
| 479 | * with regard to checking the flag as long as waitqueue is |
| 480 | * part of the to be released structure) |
| 481 | */ |
| 482 | wake_up(&req->completion_wq); |
| 483 | } |
| 484 | |
| 485 | static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | struct fsf_qtcb_bottom_config *bottom; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 488 | struct zfcp_adapter *adapter = req->adapter; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 489 | struct Scsi_Host *shost = adapter->scsi_host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 491 | bottom = &req->qtcb->bottom.config; |
| 492 | |
| 493 | if (req->data) |
| 494 | memcpy(req->data, bottom, sizeof(*bottom)); |
| 495 | |
| 496 | fc_host_node_name(shost) = bottom->nport_serv_param.wwnn; |
| 497 | fc_host_port_name(shost) = bottom->nport_serv_param.wwpn; |
| 498 | fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK; |
| 499 | fc_host_speed(shost) = bottom->fc_link_speed; |
| 500 | fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; |
| 501 | |
| 502 | adapter->hydra_version = bottom->adapter_type; |
| 503 | adapter->timer_ticks = bottom->timer_interval; |
| 504 | |
| 505 | if (fc_host_permanent_port_name(shost) == -1) |
| 506 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
| 507 | |
| 508 | switch (bottom->fc_topology) { |
| 509 | case FSF_TOPO_P2P: |
| 510 | adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; |
| 511 | adapter->peer_wwpn = bottom->plogi_payload.wwpn; |
| 512 | adapter->peer_wwnn = bottom->plogi_payload.wwnn; |
| 513 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 514 | break; |
| 515 | case FSF_TOPO_FABRIC: |
| 516 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 517 | break; |
| 518 | case FSF_TOPO_AL: |
| 519 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 520 | default: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 521 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 522 | "Unknown or unsupported arbitrated loop " |
| 523 | "fibre channel topology detected\n"); |
| 524 | zfcp_erp_adapter_shutdown(adapter, 0, 127, req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 525 | return -EIO; |
| 526 | } |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req) |
| 532 | { |
| 533 | struct zfcp_adapter *adapter = req->adapter; |
| 534 | struct fsf_qtcb *qtcb = req->qtcb; |
| 535 | struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config; |
| 536 | struct Scsi_Host *shost = adapter->scsi_host; |
| 537 | |
| 538 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 539 | return; |
| 540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | adapter->fsf_lic_version = bottom->lic_version; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 542 | adapter->adapter_features = bottom->adapter_features; |
| 543 | adapter->connection_features = bottom->connection_features; |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 544 | adapter->peer_wwpn = 0; |
| 545 | adapter->peer_wwnn = 0; |
| 546 | adapter->peer_d_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 548 | switch (qtcb->header.fsf_status) { |
| 549 | case FSF_GOOD: |
| 550 | if (zfcp_fsf_exchange_config_evaluate(req)) |
| 551 | return; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 552 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 553 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
| 554 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 555 | "FCP adapter maximum QTCB size (%d bytes) " |
| 556 | "is too small\n", |
| 557 | bottom->max_qtcb_size); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 558 | zfcp_erp_adapter_shutdown(adapter, 0, 129, req); |
| 559 | return; |
| 560 | } |
| 561 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
| 562 | &adapter->status); |
| 563 | break; |
| 564 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 565 | fc_host_node_name(shost) = 0; |
| 566 | fc_host_port_name(shost) = 0; |
| 567 | fc_host_port_id(shost) = 0; |
| 568 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 569 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | adapter->hydra_version = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 571 | |
| 572 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
| 573 | &adapter->status); |
| 574 | |
| 575 | zfcp_fsf_link_down_info_eval(req, 42, |
| 576 | &qtcb->header.fsf_status_qual.link_down_info); |
| 577 | break; |
| 578 | default: |
| 579 | zfcp_erp_adapter_shutdown(adapter, 0, 130, req); |
| 580 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 583 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | adapter->hardware_version = bottom->hardware_version; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 585 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
| 586 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
| 587 | EBCASC(fc_host_serial_number(shost), |
| 588 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 591 | if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 592 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 593 | "The FCP adapter only supports newer " |
| 594 | "control block versions\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 595 | zfcp_erp_adapter_shutdown(adapter, 0, 125, req); |
| 596 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 598 | if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 599 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 600 | "The FCP adapter only supports older " |
| 601 | "control block versions\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 602 | zfcp_erp_adapter_shutdown(adapter, 0, 126, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 606 | static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 608 | struct zfcp_adapter *adapter = req->adapter; |
| 609 | struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port; |
| 610 | struct Scsi_Host *shost = adapter->scsi_host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 612 | if (req->data) |
| 613 | memcpy(req->data, bottom, sizeof(*bottom)); |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 614 | |
| 615 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 616 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
| 617 | else |
| 618 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
| 619 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; |
| 620 | fc_host_supported_speeds(shost) = bottom->supported_speed; |
| 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 623 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 625 | struct fsf_qtcb *qtcb = req->qtcb; |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 626 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 627 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | return; |
| 629 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 630 | switch (qtcb->header.fsf_status) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 631 | case FSF_GOOD: |
| 632 | zfcp_fsf_exchange_port_evaluate(req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 633 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 634 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 635 | zfcp_fsf_exchange_port_evaluate(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 636 | zfcp_fsf_link_down_info_eval(req, 43, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 637 | &qtcb->header.fsf_status_qual.link_down_info); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 638 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 642 | static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue) |
| 643 | { |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 644 | spin_lock_bh(&queue->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 645 | if (atomic_read(&queue->count)) |
| 646 | return 1; |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 647 | spin_unlock_bh(&queue->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 648 | return 0; |
| 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 651 | static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter) |
| 652 | { |
| 653 | unsigned int count = atomic_read(&adapter->req_q.count); |
| 654 | if (!count) |
| 655 | atomic_inc(&adapter->qdio_outb_full); |
| 656 | return count > 0; |
| 657 | } |
| 658 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 659 | static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter) |
| 660 | { |
| 661 | long ret; |
| 662 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 663 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 664 | spin_unlock_bh(&req_q->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 665 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
| 666 | zfcp_fsf_sbal_check(req_q), 5 * HZ); |
| 667 | if (ret > 0) |
| 668 | return 0; |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 669 | if (!ret) |
| 670 | atomic_inc(&adapter->qdio_outb_full); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 671 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 672 | spin_lock_bh(&req_q->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 673 | return -EIO; |
| 674 | } |
| 675 | |
| 676 | static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool) |
| 677 | { |
| 678 | struct zfcp_fsf_req *req; |
| 679 | req = mempool_alloc(pool, GFP_ATOMIC); |
| 680 | if (!req) |
| 681 | return NULL; |
| 682 | memset(req, 0, sizeof(*req)); |
| 683 | return req; |
| 684 | } |
| 685 | |
| 686 | static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool) |
| 687 | { |
| 688 | struct zfcp_fsf_req_qtcb *qtcb; |
| 689 | |
| 690 | if (likely(pool)) |
| 691 | qtcb = mempool_alloc(pool, GFP_ATOMIC); |
| 692 | else |
| 693 | qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache, |
| 694 | GFP_ATOMIC); |
| 695 | if (unlikely(!qtcb)) |
| 696 | return NULL; |
| 697 | |
| 698 | memset(qtcb, 0, sizeof(*qtcb)); |
| 699 | qtcb->fsf_req.qtcb = &qtcb->qtcb; |
| 700 | qtcb->fsf_req.pool = pool; |
| 701 | |
| 702 | return &qtcb->fsf_req; |
| 703 | } |
| 704 | |
| 705 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter, |
| 706 | u32 fsf_cmd, int req_flags, |
| 707 | mempool_t *pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 709 | struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 711 | struct zfcp_fsf_req *req; |
| 712 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 713 | |
| 714 | if (req_flags & ZFCP_REQ_NO_QTCB) |
| 715 | req = zfcp_fsf_alloc_noqtcb(pool); |
| 716 | else |
| 717 | req = zfcp_fsf_alloc_qtcb(pool); |
| 718 | |
| 719 | if (unlikely(!req)) |
| 720 | return ERR_PTR(-EIO); |
| 721 | |
| 722 | if (adapter->req_no == 0) |
| 723 | adapter->req_no++; |
| 724 | |
| 725 | INIT_LIST_HEAD(&req->list); |
| 726 | init_timer(&req->timer); |
| 727 | init_waitqueue_head(&req->completion_wq); |
| 728 | |
| 729 | req->adapter = adapter; |
| 730 | req->fsf_command = fsf_cmd; |
| 731 | req->req_id = adapter->req_no++; |
| 732 | req->sbal_number = 1; |
| 733 | req->sbal_first = req_q->first; |
| 734 | req->sbal_last = req_q->first; |
| 735 | req->sbale_curr = 1; |
| 736 | |
| 737 | sbale = zfcp_qdio_sbale_req(req); |
| 738 | sbale[0].addr = (void *) req->req_id; |
| 739 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; |
| 740 | |
| 741 | if (likely(req->qtcb)) { |
| 742 | req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no; |
| 743 | req->qtcb->prefix.req_id = req->req_id; |
| 744 | req->qtcb->prefix.ulp_info = 26; |
| 745 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command]; |
| 746 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; |
| 747 | req->qtcb->header.req_handle = req->req_id; |
| 748 | req->qtcb->header.fsf_command = req->fsf_command; |
| 749 | req->seq_no = adapter->fsf_req_seq_no; |
| 750 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
| 751 | sbale[1].addr = (void *) req->qtcb; |
| 752 | sbale[1].length = sizeof(struct fsf_qtcb); |
| 753 | } |
| 754 | |
| 755 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) { |
| 756 | zfcp_fsf_req_free(req); |
| 757 | return ERR_PTR(-EIO); |
| 758 | } |
| 759 | |
| 760 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) |
| 761 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
| 762 | |
| 763 | return req; |
| 764 | } |
| 765 | |
| 766 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
| 767 | { |
| 768 | struct zfcp_adapter *adapter = req->adapter; |
| 769 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 770 | int idx; |
| 771 | |
| 772 | /* put allocated FSF request into hash table */ |
| 773 | spin_lock(&adapter->req_list_lock); |
| 774 | idx = zfcp_reqlist_hash(req->req_id); |
| 775 | list_add_tail(&req->list, &adapter->req_list[idx]); |
| 776 | spin_unlock(&adapter->req_list_lock); |
| 777 | |
| 778 | req->issued = get_clock(); |
| 779 | if (zfcp_qdio_send(req)) { |
| 780 | /* Queues are down..... */ |
| 781 | del_timer(&req->timer); |
| 782 | spin_lock(&adapter->req_list_lock); |
| 783 | zfcp_reqlist_remove(adapter, req); |
| 784 | spin_unlock(&adapter->req_list_lock); |
| 785 | /* undo changes in request queue made for this request */ |
| 786 | atomic_add(req->sbal_number, &req_q->count); |
| 787 | req_q->first -= req->sbal_number; |
| 788 | req_q->first += QDIO_MAX_BUFFERS_PER_Q; |
| 789 | req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ |
| 790 | zfcp_erp_adapter_reopen(adapter, 0, 116, req); |
| 791 | return -EIO; |
| 792 | } |
| 793 | |
| 794 | /* Don't increase for unsolicited status */ |
| 795 | if (req->qtcb) |
| 796 | adapter->fsf_req_seq_no++; |
| 797 | |
| 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * zfcp_fsf_status_read - send status read request |
| 803 | * @adapter: pointer to struct zfcp_adapter |
| 804 | * @req_flags: request flags |
| 805 | * Returns: 0 on success, ERROR otherwise |
| 806 | */ |
| 807 | int zfcp_fsf_status_read(struct zfcp_adapter *adapter) |
| 808 | { |
| 809 | struct zfcp_fsf_req *req; |
| 810 | struct fsf_status_read_buffer *sr_buf; |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 811 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 812 | int retval = -EIO; |
| 813 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 814 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 815 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 818 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, |
| 819 | ZFCP_REQ_NO_QTCB, |
| 820 | adapter->pool.fsf_req_status_read); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 821 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 822 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | goto out; |
| 824 | } |
| 825 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 826 | sbale = zfcp_qdio_sbale_req(req); |
| 827 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; |
| 828 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 829 | req->sbale_curr = 2; |
| 830 | |
| 831 | sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); |
| 832 | if (!sr_buf) { |
| 833 | retval = -ENOMEM; |
| 834 | goto failed_buf; |
| 835 | } |
| 836 | memset(sr_buf, 0, sizeof(*sr_buf)); |
| 837 | req->data = sr_buf; |
| 838 | sbale = zfcp_qdio_sbale_curr(req); |
| 839 | sbale->addr = (void *) sr_buf; |
| 840 | sbale->length = sizeof(*sr_buf); |
| 841 | |
| 842 | retval = zfcp_fsf_req_send(req); |
| 843 | if (retval) |
| 844 | goto failed_req_send; |
| 845 | |
| 846 | goto out; |
| 847 | |
| 848 | failed_req_send: |
| 849 | mempool_free(sr_buf, adapter->pool.data_status_read); |
| 850 | failed_buf: |
| 851 | zfcp_fsf_req_free(req); |
| 852 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); |
| 853 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 854 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | return retval; |
| 856 | } |
| 857 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 858 | static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 860 | struct zfcp_unit *unit = req->data; |
| 861 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 863 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 864 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 866 | switch (req->qtcb->header.fsf_status) { |
| 867 | case FSF_PORT_HANDLE_NOT_VALID: |
| 868 | if (fsq->word[0] == fsq->word[1]) { |
| 869 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, |
| 870 | req); |
| 871 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 872 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 874 | case FSF_LUN_HANDLE_NOT_VALID: |
| 875 | if (fsq->word[0] == fsq->word[1]) { |
| 876 | zfcp_erp_port_reopen(unit->port, 0, 105, req); |
| 877 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 880 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
| 881 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 883 | case FSF_PORT_BOXED: |
| 884 | zfcp_erp_port_boxed(unit->port, 47, req); |
| 885 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 886 | ZFCP_STATUS_FSFREQ_RETRY; |
| 887 | break; |
| 888 | case FSF_LUN_BOXED: |
| 889 | zfcp_erp_unit_boxed(unit, 48, req); |
| 890 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 891 | ZFCP_STATUS_FSFREQ_RETRY; |
| 892 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 894 | switch (fsq->word[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 896 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 898 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | break; |
| 900 | } |
| 901 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 903 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
| 904 | break; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * zfcp_fsf_abort_fcp_command - abort running SCSI command |
| 910 | * @old_req_id: unsigned long |
| 911 | * @adapter: pointer to struct zfcp_adapter |
| 912 | * @unit: pointer to struct zfcp_unit |
| 913 | * @req_flags: integer specifying the request flags |
| 914 | * Returns: pointer to struct zfcp_fsf_req |
| 915 | * |
| 916 | * FIXME(design): should be watched by a timeout !!! |
| 917 | */ |
| 918 | |
| 919 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id, |
| 920 | struct zfcp_adapter *adapter, |
| 921 | struct zfcp_unit *unit, |
| 922 | int req_flags) |
| 923 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 924 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 925 | struct zfcp_fsf_req *req = NULL; |
| 926 | |
| 927 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 928 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 929 | goto out; |
| 930 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, |
| 931 | req_flags, adapter->pool.fsf_req_abort); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 932 | if (IS_ERR(req)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 933 | goto out; |
| 934 | |
| 935 | if (unlikely(!(atomic_read(&unit->status) & |
| 936 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 937 | goto out_error_free; |
| 938 | |
| 939 | sbale = zfcp_qdio_sbale_req(req); |
| 940 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 941 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 942 | |
| 943 | req->data = unit; |
| 944 | req->handler = zfcp_fsf_abort_fcp_command_handler; |
| 945 | req->qtcb->header.lun_handle = unit->handle; |
| 946 | req->qtcb->header.port_handle = unit->port->handle; |
| 947 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
| 948 | |
| 949 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 950 | if (!zfcp_fsf_req_send(req)) |
| 951 | goto out; |
| 952 | |
| 953 | out_error_free: |
| 954 | zfcp_fsf_req_free(req); |
| 955 | req = NULL; |
| 956 | out: |
| 957 | spin_unlock(&adapter->req_q.lock); |
| 958 | return req; |
| 959 | } |
| 960 | |
| 961 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
| 962 | { |
| 963 | struct zfcp_adapter *adapter = req->adapter; |
| 964 | struct zfcp_send_ct *send_ct = req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 965 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 966 | |
| 967 | send_ct->status = -EINVAL; |
| 968 | |
| 969 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 970 | goto skip_fsfstatus; |
| 971 | |
| 972 | switch (header->fsf_status) { |
| 973 | case FSF_GOOD: |
| 974 | zfcp_san_dbf_event_ct_response(req); |
| 975 | send_ct->status = 0; |
| 976 | break; |
| 977 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 978 | zfcp_fsf_class_not_supp(req); |
| 979 | break; |
| 980 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 981 | switch (header->fsf_status_qual.word[0]){ |
| 982 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 983 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 984 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 985 | break; |
| 986 | } |
| 987 | break; |
| 988 | case FSF_ACCESS_DENIED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 989 | break; |
| 990 | case FSF_PORT_BOXED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 991 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 992 | ZFCP_STATUS_FSFREQ_RETRY; |
| 993 | break; |
| 994 | case FSF_PORT_HANDLE_NOT_VALID: |
| 995 | zfcp_erp_adapter_reopen(adapter, 0, 106, req); |
| 996 | case FSF_GENERIC_COMMAND_REJECTED: |
| 997 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 998 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 999 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 1000 | case FSF_SBAL_MISMATCH: |
| 1001 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1002 | break; |
| 1003 | } |
| 1004 | |
| 1005 | skip_fsfstatus: |
| 1006 | if (send_ct->handler) |
| 1007 | send_ct->handler(send_ct->handler_data); |
| 1008 | } |
| 1009 | |
| 1010 | static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req, |
| 1011 | struct scatterlist *sg_req, |
| 1012 | struct scatterlist *sg_resp, int max_sbals) |
| 1013 | { |
| 1014 | int bytes; |
| 1015 | |
| 1016 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, |
| 1017 | sg_req, max_sbals); |
| 1018 | if (bytes <= 0) |
| 1019 | return -ENOMEM; |
| 1020 | req->qtcb->bottom.support.req_buf_length = bytes; |
| 1021 | req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; |
| 1022 | |
| 1023 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, |
| 1024 | sg_resp, max_sbals); |
| 1025 | if (bytes <= 0) |
| 1026 | return -ENOMEM; |
| 1027 | req->qtcb->bottom.support.resp_buf_length = bytes; |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
| 1034 | * @ct: pointer to struct zfcp_send_ct with data for request |
| 1035 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req |
| 1036 | * @erp_action: if non-null the Generic Service request sent within ERP |
| 1037 | */ |
| 1038 | int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, |
| 1039 | struct zfcp_erp_action *erp_action) |
| 1040 | { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1041 | struct zfcp_wka_port *wka_port = ct->wka_port; |
| 1042 | struct zfcp_adapter *adapter = wka_port->adapter; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1043 | struct zfcp_fsf_req *req; |
| 1044 | int ret = -EIO; |
| 1045 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1046 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1047 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1048 | goto out; |
| 1049 | |
| 1050 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, |
| 1051 | ZFCP_REQ_AUTO_CLEANUP, pool); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1052 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1053 | ret = PTR_ERR(req); |
| 1054 | goto out; |
| 1055 | } |
| 1056 | |
| 1057 | ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp, |
| 1058 | FSF_MAX_SBALS_PER_REQ); |
| 1059 | if (ret) |
| 1060 | goto failed_send; |
| 1061 | |
| 1062 | req->handler = zfcp_fsf_send_ct_handler; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1063 | req->qtcb->header.port_handle = wka_port->handle; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1064 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; |
| 1065 | req->qtcb->bottom.support.timeout = ct->timeout; |
| 1066 | req->data = ct; |
| 1067 | |
| 1068 | zfcp_san_dbf_event_ct_request(req); |
| 1069 | |
| 1070 | if (erp_action) { |
| 1071 | erp_action->fsf_req = req; |
| 1072 | req->erp_action = erp_action; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1073 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1074 | } else |
| 1075 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1076 | |
| 1077 | ret = zfcp_fsf_req_send(req); |
| 1078 | if (ret) |
| 1079 | goto failed_send; |
| 1080 | |
| 1081 | goto out; |
| 1082 | |
| 1083 | failed_send: |
| 1084 | zfcp_fsf_req_free(req); |
| 1085 | if (erp_action) |
| 1086 | erp_action->fsf_req = NULL; |
| 1087 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1088 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1089 | return ret; |
| 1090 | } |
| 1091 | |
| 1092 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
| 1093 | { |
| 1094 | struct zfcp_send_els *send_els = req->data; |
| 1095 | struct zfcp_port *port = send_els->port; |
| 1096 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1097 | |
| 1098 | send_els->status = -EINVAL; |
| 1099 | |
| 1100 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1101 | goto skip_fsfstatus; |
| 1102 | |
| 1103 | switch (header->fsf_status) { |
| 1104 | case FSF_GOOD: |
| 1105 | zfcp_san_dbf_event_els_response(req); |
| 1106 | send_els->status = 0; |
| 1107 | break; |
| 1108 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 1109 | zfcp_fsf_class_not_supp(req); |
| 1110 | break; |
| 1111 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1112 | switch (header->fsf_status_qual.word[0]){ |
| 1113 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1114 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
| 1115 | zfcp_test_link(port); |
| 1116 | /*fall through */ |
| 1117 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1118 | case FSF_SQ_RETRY_IF_POSSIBLE: |
| 1119 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1120 | break; |
| 1121 | } |
| 1122 | break; |
| 1123 | case FSF_ELS_COMMAND_REJECTED: |
| 1124 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 1125 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 1126 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 1127 | break; |
| 1128 | case FSF_ACCESS_DENIED: |
| 1129 | zfcp_fsf_access_denied_port(req, port); |
| 1130 | break; |
| 1131 | case FSF_SBAL_MISMATCH: |
| 1132 | /* should never occure, avoided in zfcp_fsf_send_els */ |
| 1133 | /* fall through */ |
| 1134 | default: |
| 1135 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1136 | break; |
| 1137 | } |
| 1138 | skip_fsfstatus: |
| 1139 | if (send_els->handler) |
| 1140 | send_els->handler(send_els->handler_data); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) |
| 1145 | * @els: pointer to struct zfcp_send_els with data for the command |
| 1146 | */ |
| 1147 | int zfcp_fsf_send_els(struct zfcp_send_els *els) |
| 1148 | { |
| 1149 | struct zfcp_fsf_req *req; |
| 1150 | struct zfcp_adapter *adapter = els->adapter; |
| 1151 | struct fsf_qtcb_bottom_support *bottom; |
| 1152 | int ret = -EIO; |
| 1153 | |
| 1154 | if (unlikely(!(atomic_read(&els->port->status) & |
| 1155 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 1156 | return -EBUSY; |
| 1157 | |
| 1158 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1159 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1160 | goto out; |
| 1161 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, |
| 1162 | ZFCP_REQ_AUTO_CLEANUP, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1163 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1164 | ret = PTR_ERR(req); |
| 1165 | goto out; |
| 1166 | } |
| 1167 | |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1168 | ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2); |
| 1169 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1170 | if (ret) |
| 1171 | goto failed_send; |
| 1172 | |
| 1173 | bottom = &req->qtcb->bottom.support; |
| 1174 | req->handler = zfcp_fsf_send_els_handler; |
| 1175 | bottom->d_id = els->d_id; |
| 1176 | bottom->service_class = FSF_CLASS_3; |
| 1177 | bottom->timeout = 2 * R_A_TOV; |
| 1178 | req->data = els; |
| 1179 | |
| 1180 | zfcp_san_dbf_event_els_request(req); |
| 1181 | |
| 1182 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1183 | ret = zfcp_fsf_req_send(req); |
| 1184 | if (ret) |
| 1185 | goto failed_send; |
| 1186 | |
| 1187 | goto out; |
| 1188 | |
| 1189 | failed_send: |
| 1190 | zfcp_fsf_req_free(req); |
| 1191 | out: |
| 1192 | spin_unlock(&adapter->req_q.lock); |
| 1193 | return ret; |
| 1194 | } |
| 1195 | |
| 1196 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
| 1197 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1198 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1199 | struct zfcp_fsf_req *req; |
| 1200 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1201 | int retval = -EIO; |
| 1202 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1203 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1204 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1205 | goto out; |
| 1206 | req = zfcp_fsf_req_create(adapter, |
| 1207 | FSF_QTCB_EXCHANGE_CONFIG_DATA, |
| 1208 | ZFCP_REQ_AUTO_CLEANUP, |
| 1209 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1210 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1211 | retval = PTR_ERR(req); |
| 1212 | goto out; |
| 1213 | } |
| 1214 | |
| 1215 | sbale = zfcp_qdio_sbale_req(req); |
| 1216 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1217 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1218 | |
| 1219 | req->qtcb->bottom.config.feature_selection = |
| 1220 | FSF_FEATURE_CFDC | |
| 1221 | FSF_FEATURE_LUN_SHARING | |
| 1222 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1223 | FSF_FEATURE_UPDATE_ALERT; |
| 1224 | req->erp_action = erp_action; |
| 1225 | req->handler = zfcp_fsf_exchange_config_data_handler; |
| 1226 | erp_action->fsf_req = req; |
| 1227 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1228 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1229 | retval = zfcp_fsf_req_send(req); |
| 1230 | if (retval) { |
| 1231 | zfcp_fsf_req_free(req); |
| 1232 | erp_action->fsf_req = NULL; |
| 1233 | } |
| 1234 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1235 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1236 | return retval; |
| 1237 | } |
| 1238 | |
| 1239 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, |
| 1240 | struct fsf_qtcb_bottom_config *data) |
| 1241 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1242 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1243 | struct zfcp_fsf_req *req = NULL; |
| 1244 | int retval = -EIO; |
| 1245 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1246 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1247 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1248 | goto out; |
| 1249 | |
| 1250 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
| 1251 | 0, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1252 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1253 | retval = PTR_ERR(req); |
| 1254 | goto out; |
| 1255 | } |
| 1256 | |
| 1257 | sbale = zfcp_qdio_sbale_req(req); |
| 1258 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1259 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1260 | req->handler = zfcp_fsf_exchange_config_data_handler; |
| 1261 | |
| 1262 | req->qtcb->bottom.config.feature_selection = |
| 1263 | FSF_FEATURE_CFDC | |
| 1264 | FSF_FEATURE_LUN_SHARING | |
| 1265 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1266 | FSF_FEATURE_UPDATE_ALERT; |
| 1267 | |
| 1268 | if (data) |
| 1269 | req->data = data; |
| 1270 | |
| 1271 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1272 | retval = zfcp_fsf_req_send(req); |
| 1273 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1274 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1275 | if (!retval) |
| 1276 | wait_event(req->completion_wq, |
| 1277 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 1278 | |
| 1279 | zfcp_fsf_req_free(req); |
| 1280 | |
| 1281 | return retval; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * zfcp_fsf_exchange_port_data - request information about local port |
| 1286 | * @erp_action: ERP action for the adapter for which port data is requested |
| 1287 | * Returns: 0 on success, error otherwise |
| 1288 | */ |
| 1289 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
| 1290 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1291 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1292 | struct zfcp_fsf_req *req; |
| 1293 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1294 | int retval = -EIO; |
| 1295 | |
| 1296 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
| 1297 | return -EOPNOTSUPP; |
| 1298 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1299 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1300 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1301 | goto out; |
| 1302 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
| 1303 | ZFCP_REQ_AUTO_CLEANUP, |
| 1304 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1305 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1306 | retval = PTR_ERR(req); |
| 1307 | goto out; |
| 1308 | } |
| 1309 | |
| 1310 | sbale = zfcp_qdio_sbale_req(req); |
| 1311 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1312 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1313 | |
| 1314 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1315 | req->erp_action = erp_action; |
| 1316 | erp_action->fsf_req = req; |
| 1317 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1318 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1319 | retval = zfcp_fsf_req_send(req); |
| 1320 | if (retval) { |
| 1321 | zfcp_fsf_req_free(req); |
| 1322 | erp_action->fsf_req = NULL; |
| 1323 | } |
| 1324 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1325 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1326 | return retval; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * zfcp_fsf_exchange_port_data_sync - request information about local port |
| 1331 | * @adapter: pointer to struct zfcp_adapter |
| 1332 | * @data: pointer to struct fsf_qtcb_bottom_port |
| 1333 | * Returns: 0 on success, error otherwise |
| 1334 | */ |
| 1335 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, |
| 1336 | struct fsf_qtcb_bottom_port *data) |
| 1337 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1338 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1339 | struct zfcp_fsf_req *req = NULL; |
| 1340 | int retval = -EIO; |
| 1341 | |
| 1342 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
| 1343 | return -EOPNOTSUPP; |
| 1344 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1345 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1346 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1347 | goto out; |
| 1348 | |
| 1349 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0, |
| 1350 | NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1351 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1352 | retval = PTR_ERR(req); |
| 1353 | goto out; |
| 1354 | } |
| 1355 | |
| 1356 | if (data) |
| 1357 | req->data = data; |
| 1358 | |
| 1359 | sbale = zfcp_qdio_sbale_req(req); |
| 1360 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1361 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1362 | |
| 1363 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1364 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1365 | retval = zfcp_fsf_req_send(req); |
| 1366 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1367 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1368 | if (!retval) |
| 1369 | wait_event(req->completion_wq, |
| 1370 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 1371 | zfcp_fsf_req_free(req); |
| 1372 | |
| 1373 | return retval; |
| 1374 | } |
| 1375 | |
| 1376 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
| 1377 | { |
| 1378 | struct zfcp_port *port = req->data; |
| 1379 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1380 | struct fsf_plogi *plogi; |
| 1381 | |
| 1382 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1383 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1384 | |
| 1385 | switch (header->fsf_status) { |
| 1386 | case FSF_PORT_ALREADY_OPEN: |
| 1387 | break; |
| 1388 | case FSF_ACCESS_DENIED: |
| 1389 | zfcp_fsf_access_denied_port(req, port); |
| 1390 | break; |
| 1391 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
| 1392 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1393 | "Not enough FCP adapter resources to open " |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1394 | "remote port 0x%016Lx\n", |
| 1395 | (unsigned long long)port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1396 | zfcp_erp_port_failed(port, 31, req); |
| 1397 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1398 | break; |
| 1399 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1400 | switch (header->fsf_status_qual.word[0]) { |
| 1401 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1402 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1403 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1404 | break; |
| 1405 | case FSF_SQ_NO_RETRY_POSSIBLE: |
| 1406 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1407 | "Remote port 0x%016Lx could not be opened\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1408 | (unsigned long long)port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1409 | zfcp_erp_port_failed(port, 32, req); |
| 1410 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1411 | break; |
| 1412 | } |
| 1413 | break; |
| 1414 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | port->handle = header->port_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
| 1417 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1418 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1419 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
| 1420 | &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | /* check whether D_ID has changed during open */ |
| 1422 | /* |
| 1423 | * FIXME: This check is not airtight, as the FCP channel does |
| 1424 | * not monitor closures of target port connections caused on |
| 1425 | * the remote side. Thus, they might miss out on invalidating |
| 1426 | * locally cached WWPNs (and other N_Port parameters) of gone |
| 1427 | * target ports. So, our heroic attempt to make things safe |
| 1428 | * could be undermined by 'open port' response data tagged with |
| 1429 | * obsolete WWPNs. Another reason to monitor potential |
| 1430 | * connection closures ourself at least (by interpreting |
| 1431 | * incoming ELS' and unsolicited status). It just crosses my |
| 1432 | * mind that one should be able to cross-check by means of |
| 1433 | * another GID_PN straight after a port has been opened. |
| 1434 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
| 1435 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1436 | plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els; |
| 1437 | if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) { |
| 1438 | if (plogi->serv_param.wwpn != port->wwpn) |
| 1439 | atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID, |
| 1440 | &port->status); |
| 1441 | else { |
| 1442 | port->wwnn = plogi->serv_param.wwnn; |
| 1443 | zfcp_fc_plogi_evaluate(port, plogi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | case FSF_UNKNOWN_OP_SUBTYPE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1448 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | break; |
| 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1453 | /** |
| 1454 | * zfcp_fsf_open_port - create and send open port request |
| 1455 | * @erp_action: pointer to struct zfcp_erp_action |
| 1456 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1458 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1460 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1461 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1462 | struct zfcp_fsf_req *req; |
| 1463 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1465 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1466 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1469 | req = zfcp_fsf_req_create(adapter, |
| 1470 | FSF_QTCB_OPEN_PORT_WITH_DID, |
| 1471 | ZFCP_REQ_AUTO_CLEANUP, |
| 1472 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1473 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1474 | retval = PTR_ERR(req); |
| 1475 | goto out; |
| 1476 | } |
| 1477 | |
| 1478 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1480 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1481 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1482 | req->handler = zfcp_fsf_open_port_handler; |
| 1483 | req->qtcb->bottom.support.d_id = erp_action->port->d_id; |
| 1484 | req->data = erp_action->port; |
| 1485 | req->erp_action = erp_action; |
| 1486 | erp_action->fsf_req = req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1488 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1489 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1491 | zfcp_fsf_req_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | erp_action->fsf_req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1494 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1495 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | return retval; |
| 1497 | } |
| 1498 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1499 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1501 | struct zfcp_port *port = req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1503 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1504 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1506 | switch (req->qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1508 | zfcp_erp_adapter_reopen(port->adapter, 0, 107, req); |
| 1509 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1514 | zfcp_erp_modify_port_status(port, 33, req, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | ZFCP_STATUS_COMMON_OPEN, |
| 1516 | ZFCP_CLEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1521 | /** |
| 1522 | * zfcp_fsf_close_port - create and send close port request |
| 1523 | * @erp_action: pointer to struct zfcp_erp_action |
| 1524 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1526 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1528 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1529 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1530 | struct zfcp_fsf_req *req; |
| 1531 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1533 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1534 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1537 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, |
| 1538 | ZFCP_REQ_AUTO_CLEANUP, |
| 1539 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1540 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1541 | retval = PTR_ERR(req); |
| 1542 | goto out; |
| 1543 | } |
| 1544 | |
| 1545 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1547 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1548 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1549 | req->handler = zfcp_fsf_close_port_handler; |
| 1550 | req->data = erp_action->port; |
| 1551 | req->erp_action = erp_action; |
| 1552 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1553 | erp_action->fsf_req = req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1555 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1556 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1558 | zfcp_fsf_req_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | erp_action->fsf_req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1561 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1562 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | return retval; |
| 1564 | } |
| 1565 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1566 | static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req) |
| 1567 | { |
| 1568 | struct zfcp_wka_port *wka_port = req->data; |
| 1569 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1570 | |
| 1571 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
| 1572 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 1573 | goto out; |
| 1574 | } |
| 1575 | |
| 1576 | switch (header->fsf_status) { |
| 1577 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
| 1578 | dev_warn(&req->adapter->ccw_device->dev, |
| 1579 | "Opening WKA port 0x%x failed\n", wka_port->d_id); |
| 1580 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1581 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1582 | case FSF_ACCESS_DENIED: |
| 1583 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 1584 | break; |
| 1585 | case FSF_PORT_ALREADY_OPEN: |
| 1586 | case FSF_GOOD: |
| 1587 | wka_port->handle = header->port_handle; |
| 1588 | wka_port->status = ZFCP_WKA_PORT_ONLINE; |
| 1589 | } |
| 1590 | out: |
| 1591 | wake_up(&wka_port->completion_wq); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * zfcp_fsf_open_wka_port - create and send open wka-port request |
| 1596 | * @wka_port: pointer to struct zfcp_wka_port |
| 1597 | * Returns: 0 on success, error otherwise |
| 1598 | */ |
| 1599 | int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port) |
| 1600 | { |
| 1601 | struct qdio_buffer_element *sbale; |
| 1602 | struct zfcp_adapter *adapter = wka_port->adapter; |
| 1603 | struct zfcp_fsf_req *req; |
| 1604 | int retval = -EIO; |
| 1605 | |
| 1606 | spin_lock_bh(&adapter->req_q.lock); |
| 1607 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1608 | goto out; |
| 1609 | |
| 1610 | req = zfcp_fsf_req_create(adapter, |
| 1611 | FSF_QTCB_OPEN_PORT_WITH_DID, |
| 1612 | ZFCP_REQ_AUTO_CLEANUP, |
| 1613 | adapter->pool.fsf_req_erp); |
| 1614 | if (unlikely(IS_ERR(req))) { |
| 1615 | retval = PTR_ERR(req); |
| 1616 | goto out; |
| 1617 | } |
| 1618 | |
| 1619 | sbale = zfcp_qdio_sbale_req(req); |
| 1620 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1621 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1622 | |
| 1623 | req->handler = zfcp_fsf_open_wka_port_handler; |
| 1624 | req->qtcb->bottom.support.d_id = wka_port->d_id; |
| 1625 | req->data = wka_port; |
| 1626 | |
| 1627 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1628 | retval = zfcp_fsf_req_send(req); |
| 1629 | if (retval) |
| 1630 | zfcp_fsf_req_free(req); |
| 1631 | out: |
| 1632 | spin_unlock_bh(&adapter->req_q.lock); |
| 1633 | return retval; |
| 1634 | } |
| 1635 | |
| 1636 | static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req) |
| 1637 | { |
| 1638 | struct zfcp_wka_port *wka_port = req->data; |
| 1639 | |
| 1640 | if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) { |
| 1641 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1642 | zfcp_erp_adapter_reopen(wka_port->adapter, 0, 107, req); |
| 1643 | } |
| 1644 | |
| 1645 | wka_port->status = ZFCP_WKA_PORT_OFFLINE; |
| 1646 | wake_up(&wka_port->completion_wq); |
| 1647 | } |
| 1648 | |
| 1649 | /** |
| 1650 | * zfcp_fsf_close_wka_port - create and send close wka port request |
| 1651 | * @erp_action: pointer to struct zfcp_erp_action |
| 1652 | * Returns: 0 on success, error otherwise |
| 1653 | */ |
| 1654 | int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port) |
| 1655 | { |
| 1656 | struct qdio_buffer_element *sbale; |
| 1657 | struct zfcp_adapter *adapter = wka_port->adapter; |
| 1658 | struct zfcp_fsf_req *req; |
| 1659 | int retval = -EIO; |
| 1660 | |
| 1661 | spin_lock_bh(&adapter->req_q.lock); |
| 1662 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1663 | goto out; |
| 1664 | |
| 1665 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, |
| 1666 | ZFCP_REQ_AUTO_CLEANUP, |
| 1667 | adapter->pool.fsf_req_erp); |
| 1668 | if (unlikely(IS_ERR(req))) { |
| 1669 | retval = PTR_ERR(req); |
| 1670 | goto out; |
| 1671 | } |
| 1672 | |
| 1673 | sbale = zfcp_qdio_sbale_req(req); |
| 1674 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1675 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1676 | |
| 1677 | req->handler = zfcp_fsf_close_wka_port_handler; |
| 1678 | req->data = wka_port; |
| 1679 | req->qtcb->header.port_handle = wka_port->handle; |
| 1680 | |
| 1681 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1682 | retval = zfcp_fsf_req_send(req); |
| 1683 | if (retval) |
| 1684 | zfcp_fsf_req_free(req); |
| 1685 | out: |
| 1686 | spin_unlock_bh(&adapter->req_q.lock); |
| 1687 | return retval; |
| 1688 | } |
| 1689 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1690 | static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1692 | struct zfcp_port *port = req->data; |
| 1693 | struct fsf_qtcb_header *header = &req->qtcb->header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | struct zfcp_unit *unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1696 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | switch (header->fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1701 | zfcp_erp_adapter_reopen(port->adapter, 0, 108, req); |
| 1702 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | case FSF_ACCESS_DENIED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1705 | zfcp_fsf_access_denied_port(req, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | case FSF_PORT_BOXED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1708 | zfcp_erp_port_boxed(port, 50, req); |
| 1709 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1710 | ZFCP_STATUS_FSFREQ_RETRY; |
Christof Schmitt | 5c815d1 | 2008-03-10 16:18:54 +0100 | [diff] [blame] | 1711 | /* can't use generic zfcp_erp_modify_port_status because |
| 1712 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ |
| 1713 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 1714 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 1715 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 1716 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | switch (header->fsf_status_qual.word[0]) { |
| 1720 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1721 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1723 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
| 1726 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | /* can't use generic zfcp_erp_modify_port_status because |
| 1729 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
| 1730 | */ |
| 1731 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 1732 | list_for_each_entry(unit, &port->unit_list_head, list) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1733 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 1734 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1737 | skip_fsfstatus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1741 | /** |
| 1742 | * zfcp_fsf_close_physical_port - close physical port |
| 1743 | * @erp_action: pointer to struct zfcp_erp_action |
| 1744 | * Returns: 0 on success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1746 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1748 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1749 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1750 | struct zfcp_fsf_req *req; |
| 1751 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1753 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1754 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1757 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
| 1758 | ZFCP_REQ_AUTO_CLEANUP, |
| 1759 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1760 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1761 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | goto out; |
| 1763 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1764 | |
| 1765 | sbale = zfcp_qdio_sbale_req(req); |
| 1766 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1767 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1768 | |
| 1769 | req->data = erp_action->port; |
| 1770 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1771 | req->erp_action = erp_action; |
| 1772 | req->handler = zfcp_fsf_close_physical_port_handler; |
| 1773 | erp_action->fsf_req = req; |
| 1774 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, |
| 1775 | &erp_action->port->status); |
| 1776 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1777 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1778 | retval = zfcp_fsf_req_send(req); |
| 1779 | if (retval) { |
| 1780 | zfcp_fsf_req_free(req); |
| 1781 | erp_action->fsf_req = NULL; |
| 1782 | } |
| 1783 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1784 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | return retval; |
| 1786 | } |
| 1787 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1788 | static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1790 | struct zfcp_adapter *adapter = req->adapter; |
| 1791 | struct zfcp_unit *unit = req->data; |
| 1792 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1793 | struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support; |
| 1794 | struct fsf_queue_designator *queue_designator = |
| 1795 | &header->fsf_status_qual.fsf_queue_designator; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1796 | int exclusive, readwrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1798 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1799 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Heiko Carstens | b64ddf9 | 2007-05-08 11:19:57 +0200 | [diff] [blame] | 1802 | ZFCP_STATUS_COMMON_ACCESS_BOXED | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | ZFCP_STATUS_UNIT_SHARED | |
| 1804 | ZFCP_STATUS_UNIT_READONLY, |
| 1805 | &unit->status); |
| 1806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | switch (header->fsf_status) { |
| 1808 | |
| 1809 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1810 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req); |
| 1811 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | case FSF_LUN_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | case FSF_ACCESS_DENIED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1815 | zfcp_fsf_access_denied_unit(req, unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1817 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | case FSF_PORT_BOXED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1820 | zfcp_erp_port_boxed(unit->port, 51, req); |
| 1821 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1822 | ZFCP_STATUS_FSFREQ_RETRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | case FSF_LUN_SHARING_VIOLATION: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1825 | if (header->fsf_status_qual.word[0]) |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1826 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1827 | "LUN 0x%Lx on port 0x%Lx is already in " |
| 1828 | "use by CSS%d, MIF Image ID %x\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1829 | (unsigned long long)unit->fcp_lun, |
| 1830 | (unsigned long long)unit->port->wwpn, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1831 | queue_designator->cssid, |
| 1832 | queue_designator->hla); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1833 | else |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1834 | zfcp_act_eval_err(adapter, |
| 1835 | header->fsf_status_qual.word[2]); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1836 | zfcp_erp_unit_access_denied(unit, 60, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 1838 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1839 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1842 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1843 | "No handle is available for LUN " |
| 1844 | "0x%016Lx on port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1845 | (unsigned long long)unit->fcp_lun, |
| 1846 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1847 | zfcp_erp_unit_failed(unit, 34, req); |
| 1848 | /* fall through */ |
| 1849 | case FSF_INVALID_COMMAND_OPTION: |
| 1850 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | switch (header->fsf_status_qual.word[0]) { |
| 1854 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 1855 | zfcp_test_link(unit->port); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1856 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1858 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | break; |
| 1862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | unit->handle = header->lun_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1866 | |
| 1867 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && |
| 1868 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && |
| 1869 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { |
| 1870 | exclusive = (bottom->lun_access_info & |
| 1871 | FSF_UNIT_ACCESS_EXCLUSIVE); |
| 1872 | readwrite = (bottom->lun_access_info & |
| 1873 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); |
| 1874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | if (!exclusive) |
| 1876 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, |
| 1877 | &unit->status); |
| 1878 | |
| 1879 | if (!readwrite) { |
| 1880 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, |
| 1881 | &unit->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1882 | dev_info(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1883 | "SCSI device at LUN 0x%016Lx on port " |
| 1884 | "0x%016Lx opened read-only\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1885 | (unsigned long long)unit->fcp_lun, |
| 1886 | (unsigned long long)unit->port->wwpn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | if (exclusive && !readwrite) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1890 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1891 | "Exclusive read-only access not " |
| 1892 | "supported (unit 0x%016Lx, " |
| 1893 | "port 0x%016Lx)\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1894 | (unsigned long long)unit->fcp_lun, |
| 1895 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1896 | zfcp_erp_unit_failed(unit, 35, req); |
| 1897 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1898 | zfcp_erp_unit_shutdown(unit, 0, 80, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } else if (!exclusive && readwrite) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1900 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1901 | "Shared read-write access not " |
| 1902 | "supported (unit 0x%016Lx, port " |
| 1903 | "0x%016Lx\n)", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 1904 | (unsigned long long)unit->fcp_lun, |
| 1905 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1906 | zfcp_erp_unit_failed(unit, 36, req); |
| 1907 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1908 | zfcp_erp_unit_shutdown(unit, 0, 81, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | } |
| 1910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | /** |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1916 | * zfcp_fsf_open_unit - open unit |
| 1917 | * @erp_action: pointer to struct zfcp_erp_action |
| 1918 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1920 | int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1922 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1923 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1924 | struct zfcp_fsf_req *req; |
| 1925 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1927 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1928 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1929 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1931 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN, |
| 1932 | ZFCP_REQ_AUTO_CLEANUP, |
| 1933 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1934 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1935 | retval = PTR_ERR(req); |
| 1936 | goto out; |
Christof Schmitt | ba17242 | 2007-12-20 12:30:26 +0100 | [diff] [blame] | 1937 | } |
| 1938 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1939 | sbale = zfcp_qdio_sbale_req(req); |
| 1940 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1941 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1943 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1944 | req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; |
| 1945 | req->handler = zfcp_fsf_open_unit_handler; |
| 1946 | req->data = erp_action->unit; |
| 1947 | req->erp_action = erp_action; |
| 1948 | erp_action->fsf_req = req; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1949 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1950 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
| 1951 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1953 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1954 | retval = zfcp_fsf_req_send(req); |
| 1955 | if (retval) { |
| 1956 | zfcp_fsf_req_free(req); |
| 1957 | erp_action->fsf_req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1959 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1960 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | return retval; |
| 1962 | } |
| 1963 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1964 | static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1966 | struct zfcp_unit *unit = req->data; |
| 1967 | |
| 1968 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1969 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1970 | |
| 1971 | switch (req->qtcb->header.fsf_status) { |
| 1972 | case FSF_PORT_HANDLE_NOT_VALID: |
| 1973 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req); |
| 1974 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1975 | break; |
| 1976 | case FSF_LUN_HANDLE_NOT_VALID: |
| 1977 | zfcp_erp_port_reopen(unit->port, 0, 111, req); |
| 1978 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1979 | break; |
| 1980 | case FSF_PORT_BOXED: |
| 1981 | zfcp_erp_port_boxed(unit->port, 52, req); |
| 1982 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1983 | ZFCP_STATUS_FSFREQ_RETRY; |
| 1984 | break; |
| 1985 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1986 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
| 1987 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1988 | zfcp_test_link(unit->port); |
| 1989 | /* fall through */ |
| 1990 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1991 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1992 | break; |
| 1993 | } |
| 1994 | break; |
| 1995 | case FSF_GOOD: |
| 1996 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 1997 | break; |
| 1998 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
| 2002 | * zfcp_fsf_close_unit - close zfcp unit |
| 2003 | * @erp_action: pointer to struct zfcp_unit |
| 2004 | * Returns: 0 on success, error otherwise |
| 2005 | */ |
| 2006 | int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
| 2007 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 2008 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2009 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 2010 | struct zfcp_fsf_req *req; |
| 2011 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2013 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2014 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | goto out; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2016 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN, |
| 2017 | ZFCP_REQ_AUTO_CLEANUP, |
| 2018 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2019 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2020 | retval = PTR_ERR(req); |
| 2021 | goto out; |
| 2022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2024 | sbale = zfcp_qdio_sbale_req(req); |
| 2025 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2027 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2028 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 2029 | req->qtcb->header.lun_handle = erp_action->unit->handle; |
| 2030 | req->handler = zfcp_fsf_close_unit_handler; |
| 2031 | req->data = erp_action->unit; |
| 2032 | req->erp_action = erp_action; |
| 2033 | erp_action->fsf_req = req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 2035 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2036 | retval = zfcp_fsf_req_send(req); |
| 2037 | if (retval) { |
| 2038 | zfcp_fsf_req_free(req); |
| 2039 | erp_action->fsf_req = NULL; |
| 2040 | } |
| 2041 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2042 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2043 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2046 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
| 2047 | { |
| 2048 | lat_rec->sum += lat; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2049 | lat_rec->min = min(lat_rec->min, lat); |
| 2050 | lat_rec->max = max(lat_rec->max, lat); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2053 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req) |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2054 | { |
| 2055 | struct fsf_qual_latency_info *lat_inf; |
| 2056 | struct latency_cont *lat; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2057 | struct zfcp_unit *unit = req->unit; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2058 | unsigned long flags; |
| 2059 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2060 | lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2061 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2062 | switch (req->qtcb->bottom.io.data_direction) { |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2063 | case FSF_DATADIR_READ: |
| 2064 | lat = &unit->latencies.read; |
| 2065 | break; |
| 2066 | case FSF_DATADIR_WRITE: |
| 2067 | lat = &unit->latencies.write; |
| 2068 | break; |
| 2069 | case FSF_DATADIR_CMND: |
| 2070 | lat = &unit->latencies.cmd; |
| 2071 | break; |
| 2072 | default: |
| 2073 | return; |
| 2074 | } |
| 2075 | |
| 2076 | spin_lock_irqsave(&unit->latencies.lock, flags); |
| 2077 | zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat); |
| 2078 | zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat); |
| 2079 | lat->counter++; |
| 2080 | spin_unlock_irqrestore(&unit->latencies.lock, flags); |
| 2081 | } |
| 2082 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2083 | static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2085 | struct scsi_cmnd *scpnt = req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2087 | &(req->qtcb->bottom.io.fcp_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | u32 sns_len; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 2089 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2092 | if (unlikely(!scpnt)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2093 | return; |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2094 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2095 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
| 2096 | |
| 2097 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2098 | set_host_byte(scpnt, DID_SOFT_ERROR); |
| 2099 | set_driver_byte(scpnt, SUGGEST_RETRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | goto skip_fsfstatus; |
| 2101 | } |
| 2102 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2103 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2104 | set_host_byte(scpnt, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | goto skip_fsfstatus; |
| 2106 | } |
| 2107 | |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2108 | set_msg_byte(scpnt, COMMAND_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | scpnt->result |= fcp_rsp_iu->scsi_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2112 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) |
| 2113 | zfcp_fsf_req_latency(req); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2116 | if (fcp_rsp_info[3] == RSP_CODE_GOOD) |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2117 | set_host_byte(scpnt, DID_OK); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2118 | else { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2119 | set_host_byte(scpnt, DID_ERROR); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2120 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2125 | sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) + |
| 2126 | fcp_rsp_iu->fcp_rsp_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
FUJITA Tomonori | 9d058ec | 2008-01-27 12:41:50 +0900 | [diff] [blame] | 2130 | memcpy(scpnt->sense_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
FUJITA Tomonori | 7936a89 | 2007-07-29 16:46:28 +0900 | [diff] [blame] | 2135 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); |
| 2136 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < |
| 2137 | scpnt->underflow) |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2138 | set_host_byte(scpnt, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2140 | skip_fsfstatus: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2141 | if (scpnt->result != 0) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2142 | zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2143 | else if (scpnt->retries > 0) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2144 | zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2145 | else |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2146 | zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | scpnt->host_scribble = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | (scpnt->scsi_done) (scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | /* |
| 2151 | * We must hold this lock until scsi_done has been called. |
| 2152 | * Otherwise we may call scsi_done after abort regarding this |
| 2153 | * command has completed. |
| 2154 | * Note: scsi_done must not block! |
| 2155 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2156 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2159 | static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2162 | &(req->qtcb->bottom.io.fcp_rsp); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 2163 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2165 | if ((fcp_rsp_info[3] != RSP_CODE_GOOD) || |
| 2166 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 2167 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2171 | static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req) |
| 2172 | { |
| 2173 | struct zfcp_unit *unit; |
| 2174 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 2175 | |
| 2176 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) |
| 2177 | unit = req->data; |
| 2178 | else |
| 2179 | unit = req->unit; |
| 2180 | |
| 2181 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 2182 | goto skip_fsfstatus; |
| 2183 | |
| 2184 | switch (header->fsf_status) { |
| 2185 | case FSF_HANDLE_MISMATCH: |
| 2186 | case FSF_PORT_HANDLE_NOT_VALID: |
| 2187 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req); |
| 2188 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2189 | break; |
| 2190 | case FSF_FCPLUN_NOT_VALID: |
| 2191 | case FSF_LUN_HANDLE_NOT_VALID: |
| 2192 | zfcp_erp_port_reopen(unit->port, 0, 113, req); |
| 2193 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2194 | break; |
| 2195 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 2196 | zfcp_fsf_class_not_supp(req); |
| 2197 | break; |
| 2198 | case FSF_ACCESS_DENIED: |
| 2199 | zfcp_fsf_access_denied_unit(req, unit); |
| 2200 | break; |
| 2201 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
| 2202 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 2203 | "Incorrect direction %d, unit 0x%016Lx on port " |
| 2204 | "0x%016Lx closed\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2205 | req->qtcb->bottom.io.data_direction, |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2206 | (unsigned long long)unit->fcp_lun, |
| 2207 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2208 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req); |
| 2209 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2210 | break; |
| 2211 | case FSF_CMND_LENGTH_NOT_VALID: |
| 2212 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 2213 | "Incorrect CDB length %d, unit 0x%016Lx on " |
| 2214 | "port 0x%016Lx closed\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2215 | req->qtcb->bottom.io.fcp_cmnd_length, |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2216 | (unsigned long long)unit->fcp_lun, |
| 2217 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2218 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req); |
| 2219 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2220 | break; |
| 2221 | case FSF_PORT_BOXED: |
| 2222 | zfcp_erp_port_boxed(unit->port, 53, req); |
| 2223 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2224 | ZFCP_STATUS_FSFREQ_RETRY; |
| 2225 | break; |
| 2226 | case FSF_LUN_BOXED: |
| 2227 | zfcp_erp_unit_boxed(unit, 54, req); |
| 2228 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2229 | ZFCP_STATUS_FSFREQ_RETRY; |
| 2230 | break; |
| 2231 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 2232 | if (header->fsf_status_qual.word[0] == |
| 2233 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) |
| 2234 | zfcp_test_link(unit->port); |
| 2235 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2236 | break; |
| 2237 | } |
| 2238 | skip_fsfstatus: |
| 2239 | if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
| 2240 | zfcp_fsf_send_fcp_ctm_handler(req); |
| 2241 | else { |
| 2242 | zfcp_fsf_send_fcp_command_task_handler(req); |
| 2243 | req->unit = NULL; |
| 2244 | zfcp_unit_put(unit); |
| 2245 | } |
| 2246 | } |
| 2247 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2248 | static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl) |
| 2249 | { |
| 2250 | u32 *fcp_dl_ptr; |
| 2251 | |
| 2252 | /* |
| 2253 | * fcp_dl_addr = start address of fcp_cmnd structure + |
| 2254 | * size of fixed part + size of dynamically sized add_dcp_cdb field |
| 2255 | * SEE FCP-2 documentation |
| 2256 | */ |
| 2257 | fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] + |
| 2258 | (fcp_cmd->add_fcp_cdb_length << 2)); |
| 2259 | *fcp_dl_ptr = fcp_dl; |
| 2260 | } |
| 2261 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2262 | /** |
| 2263 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) |
| 2264 | * @adapter: adapter where scsi command is issued |
| 2265 | * @unit: unit where command is sent to |
| 2266 | * @scsi_cmnd: scsi command to be sent |
| 2267 | * @timer: timer to be started when request is initiated |
| 2268 | * @req_flags: flags for fsf_request |
| 2269 | */ |
| 2270 | int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, |
| 2271 | struct zfcp_unit *unit, |
| 2272 | struct scsi_cmnd *scsi_cmnd, |
| 2273 | int use_timer, int req_flags) |
| 2274 | { |
| 2275 | struct zfcp_fsf_req *req; |
| 2276 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 2277 | unsigned int sbtype; |
| 2278 | int real_bytes, retval = -EIO; |
| 2279 | |
| 2280 | if (unlikely(!(atomic_read(&unit->status) & |
| 2281 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2282 | return -EBUSY; |
| 2283 | |
| 2284 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 2285 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2286 | goto out; |
| 2287 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 2288 | adapter->pool.fsf_req_scsi); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2289 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2290 | retval = PTR_ERR(req); |
| 2291 | goto out; |
| 2292 | } |
| 2293 | |
| 2294 | zfcp_unit_get(unit); |
| 2295 | req->unit = unit; |
| 2296 | req->data = scsi_cmnd; |
| 2297 | req->handler = zfcp_fsf_send_fcp_command_handler; |
| 2298 | req->qtcb->header.lun_handle = unit->handle; |
| 2299 | req->qtcb->header.port_handle = unit->port->handle; |
| 2300 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; |
| 2301 | |
| 2302 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; |
| 2303 | |
| 2304 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd); |
| 2305 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 2306 | /* |
| 2307 | * set depending on data direction: |
| 2308 | * data direction bits in SBALE (SB Type) |
| 2309 | * data direction bits in QTCB |
| 2310 | * data direction bits in FCP_CMND IU |
| 2311 | */ |
| 2312 | switch (scsi_cmnd->sc_data_direction) { |
| 2313 | case DMA_NONE: |
| 2314 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 2315 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 2316 | break; |
| 2317 | case DMA_FROM_DEVICE: |
| 2318 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
| 2319 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 2320 | fcp_cmnd_iu->rddata = 1; |
| 2321 | break; |
| 2322 | case DMA_TO_DEVICE: |
| 2323 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; |
| 2324 | sbtype = SBAL_FLAGS0_TYPE_WRITE; |
| 2325 | fcp_cmnd_iu->wddata = 1; |
| 2326 | break; |
| 2327 | case DMA_BIDIRECTIONAL: |
| 2328 | default: |
| 2329 | retval = -EIO; |
| 2330 | goto failed_scsi_cmnd; |
| 2331 | } |
| 2332 | |
| 2333 | if (likely((scsi_cmnd->device->simple_tags) || |
| 2334 | ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) && |
| 2335 | (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED)))) |
| 2336 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; |
| 2337 | else |
| 2338 | fcp_cmnd_iu->task_attribute = UNTAGGED; |
| 2339 | |
| 2340 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) |
| 2341 | fcp_cmnd_iu->add_fcp_cdb_length = |
| 2342 | (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; |
| 2343 | |
| 2344 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 2345 | |
| 2346 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2347 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2348 | |
| 2349 | real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype, |
| 2350 | scsi_sglist(scsi_cmnd), |
| 2351 | FSF_MAX_SBALS_PER_REQ); |
| 2352 | if (unlikely(real_bytes < 0)) { |
| 2353 | if (req->sbal_number < FSF_MAX_SBALS_PER_REQ) |
| 2354 | retval = -EIO; |
| 2355 | else { |
| 2356 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 2357 | "Oversize data package, unit 0x%016Lx " |
| 2358 | "on port 0x%016Lx closed\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2359 | (unsigned long long)unit->fcp_lun, |
| 2360 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2361 | zfcp_erp_unit_shutdown(unit, 0, 131, req); |
| 2362 | retval = -EINVAL; |
| 2363 | } |
| 2364 | goto failed_scsi_cmnd; |
| 2365 | } |
| 2366 | |
| 2367 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
| 2368 | |
| 2369 | if (use_timer) |
| 2370 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 2371 | |
| 2372 | retval = zfcp_fsf_req_send(req); |
| 2373 | if (unlikely(retval)) |
| 2374 | goto failed_scsi_cmnd; |
| 2375 | |
| 2376 | goto out; |
| 2377 | |
| 2378 | failed_scsi_cmnd: |
| 2379 | zfcp_unit_put(unit); |
| 2380 | zfcp_fsf_req_free(req); |
| 2381 | scsi_cmnd->host_scribble = NULL; |
| 2382 | out: |
| 2383 | spin_unlock(&adapter->req_q.lock); |
| 2384 | return retval; |
| 2385 | } |
| 2386 | |
| 2387 | /** |
| 2388 | * zfcp_fsf_send_fcp_ctm - send SCSI task management command |
| 2389 | * @adapter: pointer to struct zfcp-adapter |
| 2390 | * @unit: pointer to struct zfcp_unit |
| 2391 | * @tm_flags: unsigned byte for task management flags |
| 2392 | * @req_flags: int request flags |
| 2393 | * Returns: on success pointer to struct fsf_req, NULL otherwise |
| 2394 | */ |
| 2395 | struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter, |
| 2396 | struct zfcp_unit *unit, |
| 2397 | u8 tm_flags, int req_flags) |
| 2398 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 2399 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2400 | struct zfcp_fsf_req *req = NULL; |
| 2401 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 2402 | |
| 2403 | if (unlikely(!(atomic_read(&unit->status) & |
| 2404 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2405 | return NULL; |
| 2406 | |
| 2407 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 2408 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2409 | goto out; |
| 2410 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 2411 | adapter->pool.fsf_req_scsi); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2412 | if (IS_ERR(req)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2413 | goto out; |
| 2414 | |
| 2415 | req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
| 2416 | req->data = unit; |
| 2417 | req->handler = zfcp_fsf_send_fcp_command_handler; |
| 2418 | req->qtcb->header.lun_handle = unit->handle; |
| 2419 | req->qtcb->header.port_handle = unit->port->handle; |
| 2420 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 2421 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; |
| 2422 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame^] | 2423 | sizeof(u32); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2424 | |
| 2425 | sbale = zfcp_qdio_sbale_req(req); |
| 2426 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; |
| 2427 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2428 | |
| 2429 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd; |
| 2430 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 2431 | fcp_cmnd_iu->task_management_flags = tm_flags; |
| 2432 | |
| 2433 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 2434 | if (!zfcp_fsf_req_send(req)) |
| 2435 | goto out; |
| 2436 | |
| 2437 | zfcp_fsf_req_free(req); |
| 2438 | req = NULL; |
| 2439 | out: |
| 2440 | spin_unlock(&adapter->req_q.lock); |
| 2441 | return req; |
| 2442 | } |
| 2443 | |
| 2444 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req) |
| 2445 | { |
| 2446 | if (req->qtcb->header.fsf_status != FSF_GOOD) |
| 2447 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2448 | } |
| 2449 | |
| 2450 | /** |
| 2451 | * zfcp_fsf_control_file - control file upload/download |
| 2452 | * @adapter: pointer to struct zfcp_adapter |
| 2453 | * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc |
| 2454 | * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | */ |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2456 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
| 2457 | struct zfcp_fsf_cfdc *fsf_cfdc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 2459 | struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2460 | struct zfcp_fsf_req *req = NULL; |
| 2461 | struct fsf_qtcb_bottom_support *bottom; |
| 2462 | int direction, retval = -EIO, bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2464 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) |
| 2465 | return ERR_PTR(-EOPNOTSUPP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2467 | switch (fsf_cfdc->command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 2469 | direction = SBAL_FLAGS0_TYPE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 2472 | direction = SBAL_FLAGS0_TYPE_READ; |
| 2473 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | default: |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2475 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2478 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2479 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 2480 | goto out; |
| 2481 | |
| 2482 | req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2483 | if (IS_ERR(req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | retval = -EPERM; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2485 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2488 | req->handler = zfcp_fsf_control_file_handler; |
| 2489 | |
| 2490 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | sbale[0].flags |= direction; |
| 2492 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2493 | bottom = &req->qtcb->bottom.support; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2495 | bottom->option = fsf_cfdc->option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2497 | bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg, |
| 2498 | FSF_MAX_SBALS_PER_REQ); |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2499 | if (bytes != ZFCP_CFDC_MAX_SIZE) { |
| 2500 | retval = -ENOMEM; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2501 | zfcp_fsf_req_free(req); |
| 2502 | goto out; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2505 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 2506 | retval = zfcp_fsf_req_send(req); |
| 2507 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2508 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2509 | |
| 2510 | if (!retval) { |
| 2511 | wait_event(req->completion_wq, |
| 2512 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 2513 | return req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | } |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2515 | return ERR_PTR(retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | } |