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 zfcp_adapter *adapter = req->adapter; |
| 625 | struct fsf_qtcb *qtcb = req->qtcb; |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 626 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 627 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | return; |
| 629 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 630 | switch (qtcb->header.fsf_status) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 631 | case FSF_GOOD: |
| 632 | zfcp_fsf_exchange_port_evaluate(req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 633 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 634 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 635 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 636 | zfcp_fsf_exchange_port_evaluate(req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 637 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 638 | zfcp_fsf_link_down_info_eval(req, 43, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 639 | &qtcb->header.fsf_status_qual.link_down_info); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 640 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 644 | static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue) |
| 645 | { |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 646 | spin_lock_bh(&queue->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 647 | if (atomic_read(&queue->count)) |
| 648 | return 1; |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 649 | spin_unlock_bh(&queue->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 650 | return 0; |
| 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 653 | static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter) |
| 654 | { |
| 655 | unsigned int count = atomic_read(&adapter->req_q.count); |
| 656 | if (!count) |
| 657 | atomic_inc(&adapter->qdio_outb_full); |
| 658 | return count > 0; |
| 659 | } |
| 660 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 661 | static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter) |
| 662 | { |
| 663 | long ret; |
| 664 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 665 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 666 | spin_unlock_bh(&req_q->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 667 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
| 668 | zfcp_fsf_sbal_check(req_q), 5 * HZ); |
| 669 | if (ret > 0) |
| 670 | return 0; |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 671 | if (!ret) |
| 672 | atomic_inc(&adapter->qdio_outb_full); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 673 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 674 | spin_lock_bh(&req_q->lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 675 | return -EIO; |
| 676 | } |
| 677 | |
| 678 | static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool) |
| 679 | { |
| 680 | struct zfcp_fsf_req *req; |
| 681 | req = mempool_alloc(pool, GFP_ATOMIC); |
| 682 | if (!req) |
| 683 | return NULL; |
| 684 | memset(req, 0, sizeof(*req)); |
| 685 | return req; |
| 686 | } |
| 687 | |
| 688 | static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool) |
| 689 | { |
| 690 | struct zfcp_fsf_req_qtcb *qtcb; |
| 691 | |
| 692 | if (likely(pool)) |
| 693 | qtcb = mempool_alloc(pool, GFP_ATOMIC); |
| 694 | else |
| 695 | qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache, |
| 696 | GFP_ATOMIC); |
| 697 | if (unlikely(!qtcb)) |
| 698 | return NULL; |
| 699 | |
| 700 | memset(qtcb, 0, sizeof(*qtcb)); |
| 701 | qtcb->fsf_req.qtcb = &qtcb->qtcb; |
| 702 | qtcb->fsf_req.pool = pool; |
| 703 | |
| 704 | return &qtcb->fsf_req; |
| 705 | } |
| 706 | |
| 707 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter, |
| 708 | u32 fsf_cmd, int req_flags, |
| 709 | mempool_t *pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | volatile struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 713 | struct zfcp_fsf_req *req; |
| 714 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 715 | |
| 716 | if (req_flags & ZFCP_REQ_NO_QTCB) |
| 717 | req = zfcp_fsf_alloc_noqtcb(pool); |
| 718 | else |
| 719 | req = zfcp_fsf_alloc_qtcb(pool); |
| 720 | |
| 721 | if (unlikely(!req)) |
| 722 | return ERR_PTR(-EIO); |
| 723 | |
| 724 | if (adapter->req_no == 0) |
| 725 | adapter->req_no++; |
| 726 | |
| 727 | INIT_LIST_HEAD(&req->list); |
| 728 | init_timer(&req->timer); |
| 729 | init_waitqueue_head(&req->completion_wq); |
| 730 | |
| 731 | req->adapter = adapter; |
| 732 | req->fsf_command = fsf_cmd; |
| 733 | req->req_id = adapter->req_no++; |
| 734 | req->sbal_number = 1; |
| 735 | req->sbal_first = req_q->first; |
| 736 | req->sbal_last = req_q->first; |
| 737 | req->sbale_curr = 1; |
| 738 | |
| 739 | sbale = zfcp_qdio_sbale_req(req); |
| 740 | sbale[0].addr = (void *) req->req_id; |
| 741 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; |
| 742 | |
| 743 | if (likely(req->qtcb)) { |
| 744 | req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no; |
| 745 | req->qtcb->prefix.req_id = req->req_id; |
| 746 | req->qtcb->prefix.ulp_info = 26; |
| 747 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command]; |
| 748 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; |
| 749 | req->qtcb->header.req_handle = req->req_id; |
| 750 | req->qtcb->header.fsf_command = req->fsf_command; |
| 751 | req->seq_no = adapter->fsf_req_seq_no; |
| 752 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
| 753 | sbale[1].addr = (void *) req->qtcb; |
| 754 | sbale[1].length = sizeof(struct fsf_qtcb); |
| 755 | } |
| 756 | |
| 757 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) { |
| 758 | zfcp_fsf_req_free(req); |
| 759 | return ERR_PTR(-EIO); |
| 760 | } |
| 761 | |
| 762 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) |
| 763 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
| 764 | |
| 765 | return req; |
| 766 | } |
| 767 | |
| 768 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
| 769 | { |
| 770 | struct zfcp_adapter *adapter = req->adapter; |
| 771 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
| 772 | int idx; |
| 773 | |
| 774 | /* put allocated FSF request into hash table */ |
| 775 | spin_lock(&adapter->req_list_lock); |
| 776 | idx = zfcp_reqlist_hash(req->req_id); |
| 777 | list_add_tail(&req->list, &adapter->req_list[idx]); |
| 778 | spin_unlock(&adapter->req_list_lock); |
| 779 | |
| 780 | req->issued = get_clock(); |
| 781 | if (zfcp_qdio_send(req)) { |
| 782 | /* Queues are down..... */ |
| 783 | del_timer(&req->timer); |
| 784 | spin_lock(&adapter->req_list_lock); |
| 785 | zfcp_reqlist_remove(adapter, req); |
| 786 | spin_unlock(&adapter->req_list_lock); |
| 787 | /* undo changes in request queue made for this request */ |
| 788 | atomic_add(req->sbal_number, &req_q->count); |
| 789 | req_q->first -= req->sbal_number; |
| 790 | req_q->first += QDIO_MAX_BUFFERS_PER_Q; |
| 791 | req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ |
| 792 | zfcp_erp_adapter_reopen(adapter, 0, 116, req); |
| 793 | return -EIO; |
| 794 | } |
| 795 | |
| 796 | /* Don't increase for unsolicited status */ |
| 797 | if (req->qtcb) |
| 798 | adapter->fsf_req_seq_no++; |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * zfcp_fsf_status_read - send status read request |
| 805 | * @adapter: pointer to struct zfcp_adapter |
| 806 | * @req_flags: request flags |
| 807 | * Returns: 0 on success, ERROR otherwise |
| 808 | */ |
| 809 | int zfcp_fsf_status_read(struct zfcp_adapter *adapter) |
| 810 | { |
| 811 | struct zfcp_fsf_req *req; |
| 812 | struct fsf_status_read_buffer *sr_buf; |
| 813 | volatile struct qdio_buffer_element *sbale; |
| 814 | int retval = -EIO; |
| 815 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 816 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 817 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 820 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, |
| 821 | ZFCP_REQ_NO_QTCB, |
| 822 | adapter->pool.fsf_req_status_read); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 823 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 824 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | goto out; |
| 826 | } |
| 827 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 828 | sbale = zfcp_qdio_sbale_req(req); |
| 829 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; |
| 830 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 831 | req->sbale_curr = 2; |
| 832 | |
| 833 | sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); |
| 834 | if (!sr_buf) { |
| 835 | retval = -ENOMEM; |
| 836 | goto failed_buf; |
| 837 | } |
| 838 | memset(sr_buf, 0, sizeof(*sr_buf)); |
| 839 | req->data = sr_buf; |
| 840 | sbale = zfcp_qdio_sbale_curr(req); |
| 841 | sbale->addr = (void *) sr_buf; |
| 842 | sbale->length = sizeof(*sr_buf); |
| 843 | |
| 844 | retval = zfcp_fsf_req_send(req); |
| 845 | if (retval) |
| 846 | goto failed_req_send; |
| 847 | |
| 848 | goto out; |
| 849 | |
| 850 | failed_req_send: |
| 851 | mempool_free(sr_buf, adapter->pool.data_status_read); |
| 852 | failed_buf: |
| 853 | zfcp_fsf_req_free(req); |
| 854 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); |
| 855 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 856 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | return retval; |
| 858 | } |
| 859 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 860 | 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] | 861 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 862 | struct zfcp_unit *unit = req->data; |
| 863 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; |
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 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 866 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 868 | switch (req->qtcb->header.fsf_status) { |
| 869 | case FSF_PORT_HANDLE_NOT_VALID: |
| 870 | if (fsq->word[0] == fsq->word[1]) { |
| 871 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, |
| 872 | req); |
| 873 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 876 | case FSF_LUN_HANDLE_NOT_VALID: |
| 877 | if (fsq->word[0] == fsq->word[1]) { |
| 878 | zfcp_erp_port_reopen(unit->port, 0, 105, req); |
| 879 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 880 | } |
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_FCP_COMMAND_DOES_NOT_EXIST: |
| 883 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 885 | case FSF_PORT_BOXED: |
| 886 | zfcp_erp_port_boxed(unit->port, 47, req); |
| 887 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 888 | ZFCP_STATUS_FSFREQ_RETRY; |
| 889 | break; |
| 890 | case FSF_LUN_BOXED: |
| 891 | zfcp_erp_unit_boxed(unit, 48, req); |
| 892 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 893 | ZFCP_STATUS_FSFREQ_RETRY; |
| 894 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 896 | switch (fsq->word[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 898 | zfcp_test_link(unit->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 900 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | break; |
| 902 | } |
| 903 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 905 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
| 906 | break; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * zfcp_fsf_abort_fcp_command - abort running SCSI command |
| 912 | * @old_req_id: unsigned long |
| 913 | * @adapter: pointer to struct zfcp_adapter |
| 914 | * @unit: pointer to struct zfcp_unit |
| 915 | * @req_flags: integer specifying the request flags |
| 916 | * Returns: pointer to struct zfcp_fsf_req |
| 917 | * |
| 918 | * FIXME(design): should be watched by a timeout !!! |
| 919 | */ |
| 920 | |
| 921 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id, |
| 922 | struct zfcp_adapter *adapter, |
| 923 | struct zfcp_unit *unit, |
| 924 | int req_flags) |
| 925 | { |
| 926 | volatile struct qdio_buffer_element *sbale; |
| 927 | struct zfcp_fsf_req *req = NULL; |
| 928 | |
| 929 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 930 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 931 | goto out; |
| 932 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, |
| 933 | req_flags, adapter->pool.fsf_req_abort); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 934 | if (IS_ERR(req)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 935 | goto out; |
| 936 | |
| 937 | if (unlikely(!(atomic_read(&unit->status) & |
| 938 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 939 | goto out_error_free; |
| 940 | |
| 941 | sbale = zfcp_qdio_sbale_req(req); |
| 942 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 943 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 944 | |
| 945 | req->data = unit; |
| 946 | req->handler = zfcp_fsf_abort_fcp_command_handler; |
| 947 | req->qtcb->header.lun_handle = unit->handle; |
| 948 | req->qtcb->header.port_handle = unit->port->handle; |
| 949 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
| 950 | |
| 951 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 952 | if (!zfcp_fsf_req_send(req)) |
| 953 | goto out; |
| 954 | |
| 955 | out_error_free: |
| 956 | zfcp_fsf_req_free(req); |
| 957 | req = NULL; |
| 958 | out: |
| 959 | spin_unlock(&adapter->req_q.lock); |
| 960 | return req; |
| 961 | } |
| 962 | |
| 963 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
| 964 | { |
| 965 | struct zfcp_adapter *adapter = req->adapter; |
| 966 | struct zfcp_send_ct *send_ct = req->data; |
| 967 | struct zfcp_port *port = send_ct->port; |
| 968 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 969 | |
| 970 | send_ct->status = -EINVAL; |
| 971 | |
| 972 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 973 | goto skip_fsfstatus; |
| 974 | |
| 975 | switch (header->fsf_status) { |
| 976 | case FSF_GOOD: |
| 977 | zfcp_san_dbf_event_ct_response(req); |
| 978 | send_ct->status = 0; |
| 979 | break; |
| 980 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 981 | zfcp_fsf_class_not_supp(req); |
| 982 | break; |
| 983 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 984 | switch (header->fsf_status_qual.word[0]){ |
| 985 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 986 | zfcp_test_link(port); |
| 987 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 988 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 989 | break; |
| 990 | } |
| 991 | break; |
| 992 | case FSF_ACCESS_DENIED: |
| 993 | zfcp_fsf_access_denied_port(req, port); |
| 994 | break; |
| 995 | case FSF_PORT_BOXED: |
| 996 | zfcp_erp_port_boxed(port, 49, req); |
| 997 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 998 | ZFCP_STATUS_FSFREQ_RETRY; |
| 999 | break; |
| 1000 | case FSF_PORT_HANDLE_NOT_VALID: |
| 1001 | zfcp_erp_adapter_reopen(adapter, 0, 106, req); |
| 1002 | case FSF_GENERIC_COMMAND_REJECTED: |
| 1003 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 1004 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 1005 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 1006 | case FSF_SBAL_MISMATCH: |
| 1007 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1008 | break; |
| 1009 | } |
| 1010 | |
| 1011 | skip_fsfstatus: |
| 1012 | if (send_ct->handler) |
| 1013 | send_ct->handler(send_ct->handler_data); |
| 1014 | } |
| 1015 | |
| 1016 | static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req, |
| 1017 | struct scatterlist *sg_req, |
| 1018 | struct scatterlist *sg_resp, int max_sbals) |
| 1019 | { |
| 1020 | int bytes; |
| 1021 | |
| 1022 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, |
| 1023 | sg_req, max_sbals); |
| 1024 | if (bytes <= 0) |
| 1025 | return -ENOMEM; |
| 1026 | req->qtcb->bottom.support.req_buf_length = bytes; |
| 1027 | req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; |
| 1028 | |
| 1029 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, |
| 1030 | sg_resp, max_sbals); |
| 1031 | if (bytes <= 0) |
| 1032 | return -ENOMEM; |
| 1033 | req->qtcb->bottom.support.resp_buf_length = bytes; |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
| 1040 | * @ct: pointer to struct zfcp_send_ct with data for request |
| 1041 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req |
| 1042 | * @erp_action: if non-null the Generic Service request sent within ERP |
| 1043 | */ |
| 1044 | int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, |
| 1045 | struct zfcp_erp_action *erp_action) |
| 1046 | { |
| 1047 | struct zfcp_port *port = ct->port; |
| 1048 | struct zfcp_adapter *adapter = port->adapter; |
| 1049 | struct zfcp_fsf_req *req; |
| 1050 | int ret = -EIO; |
| 1051 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1052 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1053 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1054 | goto out; |
| 1055 | |
| 1056 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, |
| 1057 | ZFCP_REQ_AUTO_CLEANUP, pool); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1058 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1059 | ret = PTR_ERR(req); |
| 1060 | goto out; |
| 1061 | } |
| 1062 | |
| 1063 | ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp, |
| 1064 | FSF_MAX_SBALS_PER_REQ); |
| 1065 | if (ret) |
| 1066 | goto failed_send; |
| 1067 | |
| 1068 | req->handler = zfcp_fsf_send_ct_handler; |
| 1069 | req->qtcb->header.port_handle = port->handle; |
| 1070 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; |
| 1071 | req->qtcb->bottom.support.timeout = ct->timeout; |
| 1072 | req->data = ct; |
| 1073 | |
| 1074 | zfcp_san_dbf_event_ct_request(req); |
| 1075 | |
| 1076 | if (erp_action) { |
| 1077 | erp_action->fsf_req = req; |
| 1078 | req->erp_action = erp_action; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1079 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1080 | } else |
| 1081 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1082 | |
| 1083 | ret = zfcp_fsf_req_send(req); |
| 1084 | if (ret) |
| 1085 | goto failed_send; |
| 1086 | |
| 1087 | goto out; |
| 1088 | |
| 1089 | failed_send: |
| 1090 | zfcp_fsf_req_free(req); |
| 1091 | if (erp_action) |
| 1092 | erp_action->fsf_req = NULL; |
| 1093 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1094 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1095 | return ret; |
| 1096 | } |
| 1097 | |
| 1098 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
| 1099 | { |
| 1100 | struct zfcp_send_els *send_els = req->data; |
| 1101 | struct zfcp_port *port = send_els->port; |
| 1102 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1103 | |
| 1104 | send_els->status = -EINVAL; |
| 1105 | |
| 1106 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1107 | goto skip_fsfstatus; |
| 1108 | |
| 1109 | switch (header->fsf_status) { |
| 1110 | case FSF_GOOD: |
| 1111 | zfcp_san_dbf_event_els_response(req); |
| 1112 | send_els->status = 0; |
| 1113 | break; |
| 1114 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 1115 | zfcp_fsf_class_not_supp(req); |
| 1116 | break; |
| 1117 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1118 | switch (header->fsf_status_qual.word[0]){ |
| 1119 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1120 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
| 1121 | zfcp_test_link(port); |
| 1122 | /*fall through */ |
| 1123 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1124 | case FSF_SQ_RETRY_IF_POSSIBLE: |
| 1125 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1126 | break; |
| 1127 | } |
| 1128 | break; |
| 1129 | case FSF_ELS_COMMAND_REJECTED: |
| 1130 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 1131 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 1132 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 1133 | break; |
| 1134 | case FSF_ACCESS_DENIED: |
| 1135 | zfcp_fsf_access_denied_port(req, port); |
| 1136 | break; |
| 1137 | case FSF_SBAL_MISMATCH: |
| 1138 | /* should never occure, avoided in zfcp_fsf_send_els */ |
| 1139 | /* fall through */ |
| 1140 | default: |
| 1141 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1142 | break; |
| 1143 | } |
| 1144 | skip_fsfstatus: |
| 1145 | if (send_els->handler) |
| 1146 | send_els->handler(send_els->handler_data); |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) |
| 1151 | * @els: pointer to struct zfcp_send_els with data for the command |
| 1152 | */ |
| 1153 | int zfcp_fsf_send_els(struct zfcp_send_els *els) |
| 1154 | { |
| 1155 | struct zfcp_fsf_req *req; |
| 1156 | struct zfcp_adapter *adapter = els->adapter; |
| 1157 | struct fsf_qtcb_bottom_support *bottom; |
| 1158 | int ret = -EIO; |
| 1159 | |
| 1160 | if (unlikely(!(atomic_read(&els->port->status) & |
| 1161 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 1162 | return -EBUSY; |
| 1163 | |
| 1164 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1165 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1166 | goto out; |
| 1167 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, |
| 1168 | ZFCP_REQ_AUTO_CLEANUP, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1169 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1170 | ret = PTR_ERR(req); |
| 1171 | goto out; |
| 1172 | } |
| 1173 | |
| 1174 | ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, |
| 1175 | FSF_MAX_SBALS_PER_ELS_REQ); |
| 1176 | if (ret) |
| 1177 | goto failed_send; |
| 1178 | |
| 1179 | bottom = &req->qtcb->bottom.support; |
| 1180 | req->handler = zfcp_fsf_send_els_handler; |
| 1181 | bottom->d_id = els->d_id; |
| 1182 | bottom->service_class = FSF_CLASS_3; |
| 1183 | bottom->timeout = 2 * R_A_TOV; |
| 1184 | req->data = els; |
| 1185 | |
| 1186 | zfcp_san_dbf_event_els_request(req); |
| 1187 | |
| 1188 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1189 | ret = zfcp_fsf_req_send(req); |
| 1190 | if (ret) |
| 1191 | goto failed_send; |
| 1192 | |
| 1193 | goto out; |
| 1194 | |
| 1195 | failed_send: |
| 1196 | zfcp_fsf_req_free(req); |
| 1197 | out: |
| 1198 | spin_unlock(&adapter->req_q.lock); |
| 1199 | return ret; |
| 1200 | } |
| 1201 | |
| 1202 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
| 1203 | { |
| 1204 | volatile struct qdio_buffer_element *sbale; |
| 1205 | struct zfcp_fsf_req *req; |
| 1206 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1207 | int retval = -EIO; |
| 1208 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1209 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1210 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1211 | goto out; |
| 1212 | req = zfcp_fsf_req_create(adapter, |
| 1213 | FSF_QTCB_EXCHANGE_CONFIG_DATA, |
| 1214 | ZFCP_REQ_AUTO_CLEANUP, |
| 1215 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1216 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1217 | retval = PTR_ERR(req); |
| 1218 | goto out; |
| 1219 | } |
| 1220 | |
| 1221 | sbale = zfcp_qdio_sbale_req(req); |
| 1222 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1223 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1224 | |
| 1225 | req->qtcb->bottom.config.feature_selection = |
| 1226 | FSF_FEATURE_CFDC | |
| 1227 | FSF_FEATURE_LUN_SHARING | |
| 1228 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1229 | FSF_FEATURE_UPDATE_ALERT; |
| 1230 | req->erp_action = erp_action; |
| 1231 | req->handler = zfcp_fsf_exchange_config_data_handler; |
| 1232 | erp_action->fsf_req = req; |
| 1233 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1234 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1235 | retval = zfcp_fsf_req_send(req); |
| 1236 | if (retval) { |
| 1237 | zfcp_fsf_req_free(req); |
| 1238 | erp_action->fsf_req = NULL; |
| 1239 | } |
| 1240 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1241 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1242 | return retval; |
| 1243 | } |
| 1244 | |
| 1245 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, |
| 1246 | struct fsf_qtcb_bottom_config *data) |
| 1247 | { |
| 1248 | volatile struct qdio_buffer_element *sbale; |
| 1249 | struct zfcp_fsf_req *req = NULL; |
| 1250 | int retval = -EIO; |
| 1251 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1252 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1253 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1254 | goto out; |
| 1255 | |
| 1256 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
| 1257 | 0, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1258 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1259 | retval = PTR_ERR(req); |
| 1260 | goto out; |
| 1261 | } |
| 1262 | |
| 1263 | sbale = zfcp_qdio_sbale_req(req); |
| 1264 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1265 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1266 | req->handler = zfcp_fsf_exchange_config_data_handler; |
| 1267 | |
| 1268 | req->qtcb->bottom.config.feature_selection = |
| 1269 | FSF_FEATURE_CFDC | |
| 1270 | FSF_FEATURE_LUN_SHARING | |
| 1271 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1272 | FSF_FEATURE_UPDATE_ALERT; |
| 1273 | |
| 1274 | if (data) |
| 1275 | req->data = data; |
| 1276 | |
| 1277 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1278 | retval = zfcp_fsf_req_send(req); |
| 1279 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1280 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1281 | if (!retval) |
| 1282 | wait_event(req->completion_wq, |
| 1283 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 1284 | |
| 1285 | zfcp_fsf_req_free(req); |
| 1286 | |
| 1287 | return retval; |
| 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * zfcp_fsf_exchange_port_data - request information about local port |
| 1292 | * @erp_action: ERP action for the adapter for which port data is requested |
| 1293 | * Returns: 0 on success, error otherwise |
| 1294 | */ |
| 1295 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
| 1296 | { |
| 1297 | volatile struct qdio_buffer_element *sbale; |
| 1298 | struct zfcp_fsf_req *req; |
| 1299 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1300 | int retval = -EIO; |
| 1301 | |
| 1302 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
| 1303 | return -EOPNOTSUPP; |
| 1304 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1305 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1306 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1307 | goto out; |
| 1308 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
| 1309 | ZFCP_REQ_AUTO_CLEANUP, |
| 1310 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1311 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1312 | retval = PTR_ERR(req); |
| 1313 | goto out; |
| 1314 | } |
| 1315 | |
| 1316 | sbale = zfcp_qdio_sbale_req(req); |
| 1317 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1318 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1319 | |
| 1320 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1321 | req->erp_action = erp_action; |
| 1322 | erp_action->fsf_req = req; |
| 1323 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1324 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1325 | retval = zfcp_fsf_req_send(req); |
| 1326 | if (retval) { |
| 1327 | zfcp_fsf_req_free(req); |
| 1328 | erp_action->fsf_req = NULL; |
| 1329 | } |
| 1330 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1331 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1332 | return retval; |
| 1333 | } |
| 1334 | |
| 1335 | /** |
| 1336 | * zfcp_fsf_exchange_port_data_sync - request information about local port |
| 1337 | * @adapter: pointer to struct zfcp_adapter |
| 1338 | * @data: pointer to struct fsf_qtcb_bottom_port |
| 1339 | * Returns: 0 on success, error otherwise |
| 1340 | */ |
| 1341 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, |
| 1342 | struct fsf_qtcb_bottom_port *data) |
| 1343 | { |
| 1344 | volatile struct qdio_buffer_element *sbale; |
| 1345 | struct zfcp_fsf_req *req = NULL; |
| 1346 | int retval = -EIO; |
| 1347 | |
| 1348 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
| 1349 | return -EOPNOTSUPP; |
| 1350 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1351 | spin_lock_bh(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 1352 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1353 | goto out; |
| 1354 | |
| 1355 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0, |
| 1356 | NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1357 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1358 | retval = PTR_ERR(req); |
| 1359 | goto out; |
| 1360 | } |
| 1361 | |
| 1362 | if (data) |
| 1363 | req->data = data; |
| 1364 | |
| 1365 | sbale = zfcp_qdio_sbale_req(req); |
| 1366 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1367 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1368 | |
| 1369 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1370 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1371 | retval = zfcp_fsf_req_send(req); |
| 1372 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1373 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1374 | if (!retval) |
| 1375 | wait_event(req->completion_wq, |
| 1376 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 1377 | zfcp_fsf_req_free(req); |
| 1378 | |
| 1379 | return retval; |
| 1380 | } |
| 1381 | |
| 1382 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
| 1383 | { |
| 1384 | struct zfcp_port *port = req->data; |
| 1385 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1386 | struct fsf_plogi *plogi; |
| 1387 | |
| 1388 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1389 | goto skip_fsfstatus; |
| 1390 | |
| 1391 | switch (header->fsf_status) { |
| 1392 | case FSF_PORT_ALREADY_OPEN: |
| 1393 | break; |
| 1394 | case FSF_ACCESS_DENIED: |
| 1395 | zfcp_fsf_access_denied_port(req, port); |
| 1396 | break; |
| 1397 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
| 1398 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1399 | "Not enough FCP adapter resources to open " |
| 1400 | "remote port 0x%016Lx\n", port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1401 | zfcp_erp_port_failed(port, 31, req); |
| 1402 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1403 | break; |
| 1404 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1405 | switch (header->fsf_status_qual.word[0]) { |
| 1406 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1407 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1408 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1409 | break; |
| 1410 | case FSF_SQ_NO_RETRY_POSSIBLE: |
| 1411 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1412 | "Remote port 0x%016Lx could not be opened\n", |
| 1413 | port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1414 | zfcp_erp_port_failed(port, 32, req); |
| 1415 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1416 | break; |
| 1417 | } |
| 1418 | break; |
| 1419 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | port->handle = header->port_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
| 1422 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1423 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1424 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
| 1425 | &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | /* check whether D_ID has changed during open */ |
| 1427 | /* |
| 1428 | * FIXME: This check is not airtight, as the FCP channel does |
| 1429 | * not monitor closures of target port connections caused on |
| 1430 | * the remote side. Thus, they might miss out on invalidating |
| 1431 | * locally cached WWPNs (and other N_Port parameters) of gone |
| 1432 | * target ports. So, our heroic attempt to make things safe |
| 1433 | * could be undermined by 'open port' response data tagged with |
| 1434 | * obsolete WWPNs. Another reason to monitor potential |
| 1435 | * connection closures ourself at least (by interpreting |
| 1436 | * incoming ELS' and unsolicited status). It just crosses my |
| 1437 | * mind that one should be able to cross-check by means of |
| 1438 | * another GID_PN straight after a port has been opened. |
| 1439 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
| 1440 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1441 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) |
| 1442 | break; |
| 1443 | |
| 1444 | plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els; |
| 1445 | if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) { |
| 1446 | if (plogi->serv_param.wwpn != port->wwpn) |
| 1447 | atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID, |
| 1448 | &port->status); |
| 1449 | else { |
| 1450 | port->wwnn = plogi->serv_param.wwnn; |
| 1451 | zfcp_fc_plogi_evaluate(port, plogi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | case FSF_UNKNOWN_OP_SUBTYPE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1456 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | break; |
| 1458 | } |
| 1459 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1460 | skip_fsfstatus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1464 | /** |
| 1465 | * zfcp_fsf_open_port - create and send open port request |
| 1466 | * @erp_action: pointer to struct zfcp_erp_action |
| 1467 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1469 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | { |
| 1471 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1472 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1473 | struct zfcp_fsf_req *req; |
| 1474 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1476 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1477 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1480 | req = zfcp_fsf_req_create(adapter, |
| 1481 | FSF_QTCB_OPEN_PORT_WITH_DID, |
| 1482 | ZFCP_REQ_AUTO_CLEANUP, |
| 1483 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1484 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1485 | retval = PTR_ERR(req); |
| 1486 | goto out; |
| 1487 | } |
| 1488 | |
| 1489 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1491 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1492 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1493 | req->handler = zfcp_fsf_open_port_handler; |
| 1494 | req->qtcb->bottom.support.d_id = erp_action->port->d_id; |
| 1495 | req->data = erp_action->port; |
| 1496 | req->erp_action = erp_action; |
| 1497 | erp_action->fsf_req = req; |
| 1498 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1500 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1501 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1503 | zfcp_fsf_req_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | erp_action->fsf_req = NULL; |
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 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1507 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return retval; |
| 1509 | } |
| 1510 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1511 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1513 | struct zfcp_port *port = req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1515 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1518 | switch (req->qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1520 | zfcp_erp_adapter_reopen(port->adapter, 0, 107, req); |
| 1521 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
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 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1526 | zfcp_erp_modify_port_status(port, 33, req, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | ZFCP_STATUS_COMMON_OPEN, |
| 1528 | ZFCP_CLEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1532 | skip_fsfstatus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1536 | /** |
| 1537 | * zfcp_fsf_close_port - create and send close port request |
| 1538 | * @erp_action: pointer to struct zfcp_erp_action |
| 1539 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1541 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1544 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1545 | struct zfcp_fsf_req *req; |
| 1546 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1548 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1549 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1552 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, |
| 1553 | ZFCP_REQ_AUTO_CLEANUP, |
| 1554 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1555 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1556 | retval = PTR_ERR(req); |
| 1557 | goto out; |
| 1558 | } |
| 1559 | |
| 1560 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1562 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1563 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1564 | req->handler = zfcp_fsf_close_port_handler; |
| 1565 | req->data = erp_action->port; |
| 1566 | req->erp_action = erp_action; |
| 1567 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1568 | erp_action->fsf_req = req; |
| 1569 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1571 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1572 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1574 | zfcp_fsf_req_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | erp_action->fsf_req = NULL; |
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 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1578 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | return retval; |
| 1580 | } |
| 1581 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1582 | 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] | 1583 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1584 | struct zfcp_port *port = req->data; |
| 1585 | struct fsf_qtcb_header *header = &req->qtcb->header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | struct zfcp_unit *unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1588 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | switch (header->fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1593 | zfcp_erp_adapter_reopen(port->adapter, 0, 108, req); |
| 1594 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | case FSF_ACCESS_DENIED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1597 | zfcp_fsf_access_denied_port(req, port); |
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_PORT_BOXED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1600 | zfcp_erp_port_boxed(port, 50, req); |
| 1601 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1602 | ZFCP_STATUS_FSFREQ_RETRY; |
Christof Schmitt | 5c815d1 | 2008-03-10 16:18:54 +0100 | [diff] [blame] | 1603 | /* can't use generic zfcp_erp_modify_port_status because |
| 1604 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ |
| 1605 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 1606 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 1607 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 1608 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | switch (header->fsf_status_qual.word[0]) { |
| 1612 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1613 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1615 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
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 | } |
| 1618 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | /* can't use generic zfcp_erp_modify_port_status because |
| 1621 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
| 1622 | */ |
| 1623 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
| 1624 | list_for_each_entry(unit, &port->unit_list_head, list) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1625 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 1626 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1629 | skip_fsfstatus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1633 | /** |
| 1634 | * zfcp_fsf_close_physical_port - close physical port |
| 1635 | * @erp_action: pointer to struct zfcp_erp_action |
| 1636 | * Returns: 0 on success |
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 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | { |
| 1640 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1641 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1642 | struct zfcp_fsf_req *req; |
| 1643 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1645 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1646 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1649 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
| 1650 | ZFCP_REQ_AUTO_CLEANUP, |
| 1651 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1652 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1653 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | goto out; |
| 1655 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1656 | |
| 1657 | sbale = zfcp_qdio_sbale_req(req); |
| 1658 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1659 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1660 | |
| 1661 | req->data = erp_action->port; |
| 1662 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1663 | req->erp_action = erp_action; |
| 1664 | req->handler = zfcp_fsf_close_physical_port_handler; |
| 1665 | erp_action->fsf_req = req; |
| 1666 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, |
| 1667 | &erp_action->port->status); |
| 1668 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1669 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1670 | retval = zfcp_fsf_req_send(req); |
| 1671 | if (retval) { |
| 1672 | zfcp_fsf_req_free(req); |
| 1673 | erp_action->fsf_req = NULL; |
| 1674 | } |
| 1675 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1676 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | return retval; |
| 1678 | } |
| 1679 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1680 | static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1682 | struct zfcp_adapter *adapter = req->adapter; |
| 1683 | struct zfcp_unit *unit = req->data; |
| 1684 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1685 | struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support; |
| 1686 | struct fsf_queue_designator *queue_designator = |
| 1687 | &header->fsf_status_qual.fsf_queue_designator; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1688 | int exclusive, readwrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1690 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Heiko Carstens | b64ddf9 | 2007-05-08 11:19:57 +0200 | [diff] [blame] | 1694 | ZFCP_STATUS_COMMON_ACCESS_BOXED | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | ZFCP_STATUS_UNIT_SHARED | |
| 1696 | ZFCP_STATUS_UNIT_READONLY, |
| 1697 | &unit->status); |
| 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | switch (header->fsf_status) { |
| 1700 | |
| 1701 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1702 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req); |
| 1703 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | case FSF_LUN_ALREADY_OPEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | case FSF_ACCESS_DENIED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1707 | zfcp_fsf_access_denied_unit(req, unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1709 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | case FSF_PORT_BOXED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1712 | zfcp_erp_port_boxed(unit->port, 51, req); |
| 1713 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1714 | ZFCP_STATUS_FSFREQ_RETRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | case FSF_LUN_SHARING_VIOLATION: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1717 | if (header->fsf_status_qual.word[0]) |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1718 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1719 | "LUN 0x%Lx on port 0x%Lx is already in " |
| 1720 | "use by CSS%d, MIF Image ID %x\n", |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1721 | unit->fcp_lun, |
| 1722 | unit->port->wwpn, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1723 | queue_designator->cssid, |
| 1724 | queue_designator->hla); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1725 | else |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1726 | zfcp_act_eval_err(adapter, |
| 1727 | header->fsf_status_qual.word[2]); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1728 | zfcp_erp_unit_access_denied(unit, 60, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
| 1730 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1731 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1734 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1735 | "No handle is available for LUN " |
| 1736 | "0x%016Lx on port 0x%016Lx\n", |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1737 | unit->fcp_lun, unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1738 | zfcp_erp_unit_failed(unit, 34, req); |
| 1739 | /* fall through */ |
| 1740 | case FSF_INVALID_COMMAND_OPTION: |
| 1741 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | switch (header->fsf_status_qual.word[0]) { |
| 1745 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Andreas Herrmann | 65a8d4e | 2005-06-13 13:16:27 +0200 | [diff] [blame] | 1746 | zfcp_test_link(unit->port); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1747 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1749 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | } |
| 1752 | break; |
| 1753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | unit->handle = header->lun_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1757 | |
| 1758 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && |
| 1759 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && |
| 1760 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { |
| 1761 | exclusive = (bottom->lun_access_info & |
| 1762 | FSF_UNIT_ACCESS_EXCLUSIVE); |
| 1763 | readwrite = (bottom->lun_access_info & |
| 1764 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); |
| 1765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | if (!exclusive) |
| 1767 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, |
| 1768 | &unit->status); |
| 1769 | |
| 1770 | if (!readwrite) { |
| 1771 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, |
| 1772 | &unit->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1773 | dev_info(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1774 | "SCSI device at LUN 0x%016Lx on port " |
| 1775 | "0x%016Lx opened read-only\n", |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1776 | unit->fcp_lun, unit->port->wwpn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | if (exclusive && !readwrite) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1780 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1781 | "Exclusive read-only access not " |
| 1782 | "supported (unit 0x%016Lx, " |
| 1783 | "port 0x%016Lx)\n", |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1784 | unit->fcp_lun, unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1785 | zfcp_erp_unit_failed(unit, 35, req); |
| 1786 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1787 | zfcp_erp_unit_shutdown(unit, 0, 80, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | } else if (!exclusive && readwrite) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1789 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 1790 | "Shared read-write access not " |
| 1791 | "supported (unit 0x%016Lx, port " |
| 1792 | "0x%016Lx\n)", |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1793 | unit->fcp_lun, unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1794 | zfcp_erp_unit_failed(unit, 36, req); |
| 1795 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1796 | zfcp_erp_unit_shutdown(unit, 0, 81, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1802 | skip_fsfstatus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | /** |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1807 | * zfcp_fsf_open_unit - open unit |
| 1808 | * @erp_action: pointer to struct zfcp_erp_action |
| 1809 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1811 | int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1813 | volatile struct qdio_buffer_element *sbale; |
| 1814 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1815 | struct zfcp_fsf_req *req; |
| 1816 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1818 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1819 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 1820 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1822 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN, |
| 1823 | ZFCP_REQ_AUTO_CLEANUP, |
| 1824 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1825 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1826 | retval = PTR_ERR(req); |
| 1827 | goto out; |
Christof Schmitt | ba17242 | 2007-12-20 12:30:26 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1830 | sbale = zfcp_qdio_sbale_req(req); |
| 1831 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
| 1832 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1834 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1835 | req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; |
| 1836 | req->handler = zfcp_fsf_open_unit_handler; |
| 1837 | req->data = erp_action->unit; |
| 1838 | req->erp_action = erp_action; |
| 1839 | erp_action->fsf_req = req; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1840 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1841 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
| 1842 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1844 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1846 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1847 | retval = zfcp_fsf_req_send(req); |
| 1848 | if (retval) { |
| 1849 | zfcp_fsf_req_free(req); |
| 1850 | erp_action->fsf_req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1852 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1853 | spin_unlock_bh(&adapter->req_q.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | return retval; |
| 1855 | } |
| 1856 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1857 | static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1859 | struct zfcp_unit *unit = req->data; |
| 1860 | |
| 1861 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1862 | goto skip_fsfstatus; |
| 1863 | |
| 1864 | switch (req->qtcb->header.fsf_status) { |
| 1865 | case FSF_PORT_HANDLE_NOT_VALID: |
| 1866 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req); |
| 1867 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1868 | break; |
| 1869 | case FSF_LUN_HANDLE_NOT_VALID: |
| 1870 | zfcp_erp_port_reopen(unit->port, 0, 111, req); |
| 1871 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1872 | break; |
| 1873 | case FSF_PORT_BOXED: |
| 1874 | zfcp_erp_port_boxed(unit->port, 52, req); |
| 1875 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 1876 | ZFCP_STATUS_FSFREQ_RETRY; |
| 1877 | break; |
| 1878 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1879 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
| 1880 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 1881 | zfcp_test_link(unit->port); |
| 1882 | /* fall through */ |
| 1883 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1884 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1885 | break; |
| 1886 | } |
| 1887 | break; |
| 1888 | case FSF_GOOD: |
| 1889 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
| 1890 | break; |
| 1891 | } |
| 1892 | skip_fsfstatus: |
| 1893 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); |
| 1894 | } |
| 1895 | |
| 1896 | /** |
| 1897 | * zfcp_fsf_close_unit - close zfcp unit |
| 1898 | * @erp_action: pointer to struct zfcp_unit |
| 1899 | * Returns: 0 on success, error otherwise |
| 1900 | */ |
| 1901 | int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
| 1902 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1904 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1905 | struct zfcp_fsf_req *req; |
| 1906 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1908 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1909 | if (zfcp_fsf_req_sbal_get(adapter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | goto out; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1911 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN, |
| 1912 | ZFCP_REQ_AUTO_CLEANUP, |
| 1913 | adapter->pool.fsf_req_erp); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1914 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1915 | retval = PTR_ERR(req); |
| 1916 | goto out; |
| 1917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1919 | sbale = zfcp_qdio_sbale_req(req); |
| 1920 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 1922 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1923 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1924 | req->qtcb->header.lun_handle = erp_action->unit->handle; |
| 1925 | req->handler = zfcp_fsf_close_unit_handler; |
| 1926 | req->data = erp_action->unit; |
| 1927 | req->erp_action = erp_action; |
| 1928 | erp_action->fsf_req = req; |
| 1929 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1931 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1932 | retval = zfcp_fsf_req_send(req); |
| 1933 | if (retval) { |
| 1934 | zfcp_fsf_req_free(req); |
| 1935 | erp_action->fsf_req = NULL; |
| 1936 | } |
| 1937 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 1938 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1939 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1942 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
| 1943 | { |
| 1944 | lat_rec->sum += lat; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1945 | lat_rec->min = min(lat_rec->min, lat); |
| 1946 | lat_rec->max = max(lat_rec->max, lat); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1949 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req) |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1950 | { |
| 1951 | struct fsf_qual_latency_info *lat_inf; |
| 1952 | struct latency_cont *lat; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1953 | struct zfcp_unit *unit = req->unit; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1954 | unsigned long flags; |
| 1955 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1956 | lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1957 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1958 | switch (req->qtcb->bottom.io.data_direction) { |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 1959 | case FSF_DATADIR_READ: |
| 1960 | lat = &unit->latencies.read; |
| 1961 | break; |
| 1962 | case FSF_DATADIR_WRITE: |
| 1963 | lat = &unit->latencies.write; |
| 1964 | break; |
| 1965 | case FSF_DATADIR_CMND: |
| 1966 | lat = &unit->latencies.cmd; |
| 1967 | break; |
| 1968 | default: |
| 1969 | return; |
| 1970 | } |
| 1971 | |
| 1972 | spin_lock_irqsave(&unit->latencies.lock, flags); |
| 1973 | zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat); |
| 1974 | zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat); |
| 1975 | lat->counter++; |
| 1976 | spin_unlock_irqrestore(&unit->latencies.lock, flags); |
| 1977 | } |
| 1978 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1979 | 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] | 1980 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1981 | struct scsi_cmnd *scpnt = req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1983 | &(req->qtcb->bottom.io.fcp_rsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | u32 sns_len; |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 1985 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1988 | if (unlikely(!scpnt)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1989 | return; |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1990 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1991 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
| 1992 | |
| 1993 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 1994 | set_host_byte(scpnt, DID_SOFT_ERROR); |
| 1995 | set_driver_byte(scpnt, SUGGEST_RETRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | goto skip_fsfstatus; |
| 1997 | } |
| 1998 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1999 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2000 | set_host_byte(scpnt, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | goto skip_fsfstatus; |
| 2002 | } |
| 2003 | |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2004 | set_msg_byte(scpnt, COMMAND_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | scpnt->result |= fcp_rsp_iu->scsi_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2008 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) |
| 2009 | zfcp_fsf_req_latency(req); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2012 | if (fcp_rsp_info[3] == RSP_CODE_GOOD) |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2013 | set_host_byte(scpnt, DID_OK); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2014 | else { |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2015 | set_host_byte(scpnt, DID_ERROR); |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 2016 | goto skip_fsfstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2021 | sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) + |
| 2022 | fcp_rsp_iu->fcp_rsp_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
FUJITA Tomonori | 9d058ec | 2008-01-27 12:41:50 +0900 | [diff] [blame] | 2026 | memcpy(scpnt->sense_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
FUJITA Tomonori | 7936a89 | 2007-07-29 16:46:28 +0900 | [diff] [blame] | 2031 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); |
| 2032 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < |
| 2033 | scpnt->underflow) |
Martin Petermann | feac6a0 | 2008-07-02 10:56:35 +0200 | [diff] [blame] | 2034 | set_host_byte(scpnt, DID_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2036 | skip_fsfstatus: |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2037 | if (scpnt->result != 0) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2038 | zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2039 | else if (scpnt->retries > 0) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2040 | zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 2041 | else |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2042 | zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | scpnt->host_scribble = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | (scpnt->scsi_done) (scpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | /* |
| 2047 | * We must hold this lock until scsi_done has been called. |
| 2048 | * Otherwise we may call scsi_done after abort regarding this |
| 2049 | * command has completed. |
| 2050 | * Note: scsi_done must not block! |
| 2051 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2052 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2055 | 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] | 2056 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2058 | &(req->qtcb->bottom.io.fcp_rsp); |
Martin Petermann | f76af7d7 | 2008-07-02 10:56:36 +0200 | [diff] [blame] | 2059 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2061 | if ((fcp_rsp_info[3] != RSP_CODE_GOOD) || |
| 2062 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 2063 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2067 | static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req) |
| 2068 | { |
| 2069 | struct zfcp_unit *unit; |
| 2070 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 2071 | |
| 2072 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) |
| 2073 | unit = req->data; |
| 2074 | else |
| 2075 | unit = req->unit; |
| 2076 | |
| 2077 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 2078 | goto skip_fsfstatus; |
| 2079 | |
| 2080 | switch (header->fsf_status) { |
| 2081 | case FSF_HANDLE_MISMATCH: |
| 2082 | case FSF_PORT_HANDLE_NOT_VALID: |
| 2083 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req); |
| 2084 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2085 | break; |
| 2086 | case FSF_FCPLUN_NOT_VALID: |
| 2087 | case FSF_LUN_HANDLE_NOT_VALID: |
| 2088 | zfcp_erp_port_reopen(unit->port, 0, 113, req); |
| 2089 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2090 | break; |
| 2091 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 2092 | zfcp_fsf_class_not_supp(req); |
| 2093 | break; |
| 2094 | case FSF_ACCESS_DENIED: |
| 2095 | zfcp_fsf_access_denied_unit(req, unit); |
| 2096 | break; |
| 2097 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
| 2098 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 2099 | "Incorrect direction %d, unit 0x%016Lx on port " |
| 2100 | "0x%016Lx closed\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2101 | req->qtcb->bottom.io.data_direction, |
| 2102 | unit->fcp_lun, unit->port->wwpn); |
| 2103 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req); |
| 2104 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2105 | break; |
| 2106 | case FSF_CMND_LENGTH_NOT_VALID: |
| 2107 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 2108 | "Incorrect CDB length %d, unit 0x%016Lx on " |
| 2109 | "port 0x%016Lx closed\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2110 | req->qtcb->bottom.io.fcp_cmnd_length, |
| 2111 | unit->fcp_lun, unit->port->wwpn); |
| 2112 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req); |
| 2113 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2114 | break; |
| 2115 | case FSF_PORT_BOXED: |
| 2116 | zfcp_erp_port_boxed(unit->port, 53, req); |
| 2117 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2118 | ZFCP_STATUS_FSFREQ_RETRY; |
| 2119 | break; |
| 2120 | case FSF_LUN_BOXED: |
| 2121 | zfcp_erp_unit_boxed(unit, 54, req); |
| 2122 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
| 2123 | ZFCP_STATUS_FSFREQ_RETRY; |
| 2124 | break; |
| 2125 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 2126 | if (header->fsf_status_qual.word[0] == |
| 2127 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) |
| 2128 | zfcp_test_link(unit->port); |
| 2129 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2130 | break; |
| 2131 | } |
| 2132 | skip_fsfstatus: |
| 2133 | if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
| 2134 | zfcp_fsf_send_fcp_ctm_handler(req); |
| 2135 | else { |
| 2136 | zfcp_fsf_send_fcp_command_task_handler(req); |
| 2137 | req->unit = NULL; |
| 2138 | zfcp_unit_put(unit); |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) |
| 2144 | * @adapter: adapter where scsi command is issued |
| 2145 | * @unit: unit where command is sent to |
| 2146 | * @scsi_cmnd: scsi command to be sent |
| 2147 | * @timer: timer to be started when request is initiated |
| 2148 | * @req_flags: flags for fsf_request |
| 2149 | */ |
| 2150 | int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, |
| 2151 | struct zfcp_unit *unit, |
| 2152 | struct scsi_cmnd *scsi_cmnd, |
| 2153 | int use_timer, int req_flags) |
| 2154 | { |
| 2155 | struct zfcp_fsf_req *req; |
| 2156 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 2157 | unsigned int sbtype; |
| 2158 | int real_bytes, retval = -EIO; |
| 2159 | |
| 2160 | if (unlikely(!(atomic_read(&unit->status) & |
| 2161 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2162 | return -EBUSY; |
| 2163 | |
| 2164 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 2165 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2166 | goto out; |
| 2167 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 2168 | adapter->pool.fsf_req_scsi); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2169 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2170 | retval = PTR_ERR(req); |
| 2171 | goto out; |
| 2172 | } |
| 2173 | |
| 2174 | zfcp_unit_get(unit); |
| 2175 | req->unit = unit; |
| 2176 | req->data = scsi_cmnd; |
| 2177 | req->handler = zfcp_fsf_send_fcp_command_handler; |
| 2178 | req->qtcb->header.lun_handle = unit->handle; |
| 2179 | req->qtcb->header.port_handle = unit->port->handle; |
| 2180 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; |
| 2181 | |
| 2182 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; |
| 2183 | |
| 2184 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd); |
| 2185 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 2186 | /* |
| 2187 | * set depending on data direction: |
| 2188 | * data direction bits in SBALE (SB Type) |
| 2189 | * data direction bits in QTCB |
| 2190 | * data direction bits in FCP_CMND IU |
| 2191 | */ |
| 2192 | switch (scsi_cmnd->sc_data_direction) { |
| 2193 | case DMA_NONE: |
| 2194 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 2195 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 2196 | break; |
| 2197 | case DMA_FROM_DEVICE: |
| 2198 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
| 2199 | sbtype = SBAL_FLAGS0_TYPE_READ; |
| 2200 | fcp_cmnd_iu->rddata = 1; |
| 2201 | break; |
| 2202 | case DMA_TO_DEVICE: |
| 2203 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; |
| 2204 | sbtype = SBAL_FLAGS0_TYPE_WRITE; |
| 2205 | fcp_cmnd_iu->wddata = 1; |
| 2206 | break; |
| 2207 | case DMA_BIDIRECTIONAL: |
| 2208 | default: |
| 2209 | retval = -EIO; |
| 2210 | goto failed_scsi_cmnd; |
| 2211 | } |
| 2212 | |
| 2213 | if (likely((scsi_cmnd->device->simple_tags) || |
| 2214 | ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) && |
| 2215 | (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED)))) |
| 2216 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; |
| 2217 | else |
| 2218 | fcp_cmnd_iu->task_attribute = UNTAGGED; |
| 2219 | |
| 2220 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) |
| 2221 | fcp_cmnd_iu->add_fcp_cdb_length = |
| 2222 | (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; |
| 2223 | |
| 2224 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
| 2225 | |
| 2226 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
| 2227 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t); |
| 2228 | |
| 2229 | real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype, |
| 2230 | scsi_sglist(scsi_cmnd), |
| 2231 | FSF_MAX_SBALS_PER_REQ); |
| 2232 | if (unlikely(real_bytes < 0)) { |
| 2233 | if (req->sbal_number < FSF_MAX_SBALS_PER_REQ) |
| 2234 | retval = -EIO; |
| 2235 | else { |
| 2236 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame^] | 2237 | "Oversize data package, unit 0x%016Lx " |
| 2238 | "on port 0x%016Lx closed\n", |
| 2239 | unit->fcp_lun, unit->port->wwpn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2240 | zfcp_erp_unit_shutdown(unit, 0, 131, req); |
| 2241 | retval = -EINVAL; |
| 2242 | } |
| 2243 | goto failed_scsi_cmnd; |
| 2244 | } |
| 2245 | |
| 2246 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
| 2247 | |
| 2248 | if (use_timer) |
| 2249 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 2250 | |
| 2251 | retval = zfcp_fsf_req_send(req); |
| 2252 | if (unlikely(retval)) |
| 2253 | goto failed_scsi_cmnd; |
| 2254 | |
| 2255 | goto out; |
| 2256 | |
| 2257 | failed_scsi_cmnd: |
| 2258 | zfcp_unit_put(unit); |
| 2259 | zfcp_fsf_req_free(req); |
| 2260 | scsi_cmnd->host_scribble = NULL; |
| 2261 | out: |
| 2262 | spin_unlock(&adapter->req_q.lock); |
| 2263 | return retval; |
| 2264 | } |
| 2265 | |
| 2266 | /** |
| 2267 | * zfcp_fsf_send_fcp_ctm - send SCSI task management command |
| 2268 | * @adapter: pointer to struct zfcp-adapter |
| 2269 | * @unit: pointer to struct zfcp_unit |
| 2270 | * @tm_flags: unsigned byte for task management flags |
| 2271 | * @req_flags: int request flags |
| 2272 | * Returns: on success pointer to struct fsf_req, NULL otherwise |
| 2273 | */ |
| 2274 | struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter, |
| 2275 | struct zfcp_unit *unit, |
| 2276 | u8 tm_flags, int req_flags) |
| 2277 | { |
| 2278 | volatile struct qdio_buffer_element *sbale; |
| 2279 | struct zfcp_fsf_req *req = NULL; |
| 2280 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
| 2281 | |
| 2282 | if (unlikely(!(atomic_read(&unit->status) & |
| 2283 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2284 | return NULL; |
| 2285 | |
| 2286 | spin_lock(&adapter->req_q.lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 2287 | if (!zfcp_fsf_sbal_available(adapter)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2288 | goto out; |
| 2289 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, |
| 2290 | adapter->pool.fsf_req_scsi); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2291 | if (IS_ERR(req)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2292 | goto out; |
| 2293 | |
| 2294 | req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
| 2295 | req->data = unit; |
| 2296 | req->handler = zfcp_fsf_send_fcp_command_handler; |
| 2297 | req->qtcb->header.lun_handle = unit->handle; |
| 2298 | req->qtcb->header.port_handle = unit->port->handle; |
| 2299 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 2300 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; |
| 2301 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
| 2302 | sizeof(fcp_dl_t); |
| 2303 | |
| 2304 | sbale = zfcp_qdio_sbale_req(req); |
| 2305 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; |
| 2306 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
| 2307 | |
| 2308 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd; |
| 2309 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
| 2310 | fcp_cmnd_iu->task_management_flags = tm_flags; |
| 2311 | |
| 2312 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 2313 | if (!zfcp_fsf_req_send(req)) |
| 2314 | goto out; |
| 2315 | |
| 2316 | zfcp_fsf_req_free(req); |
| 2317 | req = NULL; |
| 2318 | out: |
| 2319 | spin_unlock(&adapter->req_q.lock); |
| 2320 | return req; |
| 2321 | } |
| 2322 | |
| 2323 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req) |
| 2324 | { |
| 2325 | if (req->qtcb->header.fsf_status != FSF_GOOD) |
| 2326 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2327 | } |
| 2328 | |
| 2329 | /** |
| 2330 | * zfcp_fsf_control_file - control file upload/download |
| 2331 | * @adapter: pointer to struct zfcp_adapter |
| 2332 | * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc |
| 2333 | * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | */ |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2335 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
| 2336 | struct zfcp_fsf_cfdc *fsf_cfdc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | volatile struct qdio_buffer_element *sbale; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2339 | struct zfcp_fsf_req *req = NULL; |
| 2340 | struct fsf_qtcb_bottom_support *bottom; |
| 2341 | int direction, retval = -EIO, bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2343 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) |
| 2344 | return ERR_PTR(-EOPNOTSUPP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2346 | switch (fsf_cfdc->command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 2348 | direction = SBAL_FLAGS0_TYPE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 2351 | direction = SBAL_FLAGS0_TYPE_READ; |
| 2352 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | default: |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2354 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2357 | spin_lock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2358 | if (zfcp_fsf_req_sbal_get(adapter)) |
| 2359 | goto out; |
| 2360 | |
| 2361 | req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2362 | if (IS_ERR(req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | retval = -EPERM; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2364 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2367 | req->handler = zfcp_fsf_control_file_handler; |
| 2368 | |
| 2369 | sbale = zfcp_qdio_sbale_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | sbale[0].flags |= direction; |
| 2371 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2372 | bottom = &req->qtcb->bottom.support; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2374 | bottom->option = fsf_cfdc->option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2376 | bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg, |
| 2377 | FSF_MAX_SBALS_PER_REQ); |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2378 | if (bytes != ZFCP_CFDC_MAX_SIZE) { |
| 2379 | retval = -ENOMEM; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2380 | zfcp_fsf_req_free(req); |
| 2381 | goto out; |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2384 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 2385 | retval = zfcp_fsf_req_send(req); |
| 2386 | out: |
Christof Schmitt | d453881 | 2008-08-21 13:43:32 +0200 | [diff] [blame] | 2387 | spin_unlock_bh(&adapter->req_q.lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2388 | |
| 2389 | if (!retval) { |
| 2390 | wait_event(req->completion_wq, |
| 2391 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
| 2392 | return req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | } |
Christof Schmitt | 45633fd | 2008-06-10 18:20:55 +0200 | [diff] [blame] | 2394 | return ERR_PTR(retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |