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