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