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