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