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