Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 3 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 5 | * Implementation of FSF commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Jens Remus | 6e2e490 | 2018-05-17 19:15:06 +0200 | [diff] [blame] | 7 | * Copyright IBM Corp. 2002, 2018 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 10 | #define KMSG_COMPONENT "zfcp" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Stefan Raspl | 0997f1c | 2008-10-16 08:23:39 +0200 | [diff] [blame] | 13 | #include <linux/blktrace_api.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 15 | #include <scsi/fc/fc_els.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "zfcp_ext.h" |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 17 | #include "zfcp_fc.h" |
Christof Schmitt | dcd20e2 | 2009-08-18 15:43:08 +0200 | [diff] [blame] | 18 | #include "zfcp_dbf.h" |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 19 | #include "zfcp_qdio.h" |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 20 | #include "zfcp_reqlist.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Christof Schmitt | 259afe2 | 2011-02-22 19:54:44 +0100 | [diff] [blame] | 22 | struct kmem_cache *zfcp_fsf_qtcb_cache; |
| 23 | |
Steffen Maier | 3638ccd | 2019-10-01 12:49:49 +0200 | [diff] [blame] | 24 | static bool ber_stop = true; |
| 25 | module_param(ber_stop, bool, 0600); |
| 26 | MODULE_PARM_DESC(ber_stop, |
| 27 | "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)"); |
| 28 | |
Kees Cook | 75492a5 | 2017-10-16 16:44:34 -0700 | [diff] [blame] | 29 | static void zfcp_fsf_request_timeout_handler(struct timer_list *t) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 30 | { |
Kees Cook | 75492a5 | 2017-10-16 16:44:34 -0700 | [diff] [blame] | 31 | struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer); |
| 32 | struct zfcp_adapter *adapter = fsf_req->adapter; |
Steffen Maier | 5c13db9 | 2017-10-17 18:40:51 +0200 | [diff] [blame] | 33 | |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 34 | zfcp_qdio_siosl(adapter); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 35 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 36 | "fsrth_1"); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, |
| 40 | unsigned long timeout) |
| 41 | { |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 42 | fsf_req->timer.function = zfcp_fsf_request_timeout_handler; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 43 | fsf_req->timer.expires = jiffies + timeout; |
| 44 | add_timer(&fsf_req->timer); |
| 45 | } |
| 46 | |
| 47 | static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req) |
| 48 | { |
| 49 | BUG_ON(!fsf_req->erp_action); |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 50 | fsf_req->timer.function = zfcp_erp_timeout_handler; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 51 | fsf_req->timer.expires = jiffies + 30 * HZ; |
| 52 | add_timer(&fsf_req->timer); |
| 53 | } |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* association between FSF command and FSF QTCB type */ |
| 56 | static u32 fsf_qtcb_type[] = { |
| 57 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, |
| 58 | [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND, |
| 59 | [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND, |
| 60 | [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND, |
| 61 | [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND, |
| 62 | [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND, |
| 63 | [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND, |
| 64 | [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND, |
| 65 | [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND, |
| 66 | [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND, |
| 67 | [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND, |
| 68 | [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND, |
| 69 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND |
| 70 | }; |
| 71 | |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 72 | static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req) |
| 73 | { |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 74 | dev_err(&req->adapter->ccw_device->dev, "FCP device not " |
| 75 | "operational because of an unsupported FC class\n"); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 76 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1"); |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 77 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 78 | } |
| 79 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 80 | /** |
| 81 | * zfcp_fsf_req_free - free memory used by fsf request |
| 82 | * @fsf_req: pointer to struct zfcp_fsf_req |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 84 | void zfcp_fsf_req_free(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 86 | if (likely(req->pool)) { |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 87 | if (likely(req->qtcb)) |
| 88 | mempool_free(req->qtcb, req->adapter->pool.qtcb_pool); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 89 | mempool_free(req, req->pool); |
Heiko Carstens | dd52e0e | 2006-09-18 22:28:49 +0200 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 93 | if (likely(req->qtcb)) |
Christof Schmitt | 259afe2 | 2011-02-22 19:54:44 +0100 | [diff] [blame] | 94 | kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 95 | kfree(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 98 | 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] | 99 | { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 100 | unsigned long flags; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 101 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 102 | struct zfcp_adapter *adapter = req->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | struct zfcp_port *port; |
Christof Schmitt | 800c0ca | 2009-11-24 16:54:12 +0100 | [diff] [blame] | 104 | int d_id = ntoh24(sr_buf->d_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 106 | read_lock_irqsave(&adapter->port_list_lock, flags); |
| 107 | list_for_each_entry(port, &adapter->port_list, list) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 108 | if (port->d_id == d_id) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 109 | zfcp_erp_port_reopen(port, 0, "fssrpc1"); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 110 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 111 | } |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 112 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 115 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 116 | struct fsf_link_down_info *link_down) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 118 | struct zfcp_adapter *adapter = req->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 120 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) |
| 121 | return; |
| 122 | |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 123 | atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
Christof Schmitt | 7093293 | 2009-04-17 15:08:15 +0200 | [diff] [blame] | 124 | |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 125 | zfcp_scsi_schedule_rports_block(adapter); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 126 | |
| 127 | if (!link_down) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | goto out; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 129 | |
| 130 | switch (link_down->error_code) { |
| 131 | case FSF_PSQ_LINK_NO_LIGHT: |
| 132 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 133 | "There is no light signal from the local " |
| 134 | "fibre channel cable\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 135 | break; |
| 136 | case FSF_PSQ_LINK_WRAP_PLUG: |
| 137 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 138 | "There is a wrap plug instead of a fibre " |
| 139 | "channel cable\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 140 | break; |
| 141 | case FSF_PSQ_LINK_NO_FCP: |
| 142 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 143 | "The adjacent fibre channel node does not " |
| 144 | "support FCP\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 145 | break; |
| 146 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: |
| 147 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 148 | "The FCP device is suspended because of a " |
| 149 | "firmware update\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 150 | break; |
| 151 | case FSF_PSQ_LINK_INVALID_WWPN: |
| 152 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 153 | "The FCP device detected a WWPN that is " |
| 154 | "duplicate or not valid\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 155 | break; |
| 156 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: |
| 157 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 158 | "The fibre channel fabric does not support NPIV\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 159 | break; |
| 160 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: |
| 161 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 162 | "The FCP adapter cannot support more NPIV ports\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 163 | break; |
| 164 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: |
| 165 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 166 | "The adjacent switch cannot support " |
| 167 | "more NPIV ports\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 168 | break; |
| 169 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: |
| 170 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 171 | "The FCP adapter could not log in to the " |
| 172 | "fibre channel fabric\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 173 | break; |
| 174 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: |
| 175 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 176 | "The WWPN assignment file on the FCP adapter " |
| 177 | "has been damaged\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 178 | break; |
| 179 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: |
| 180 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 181 | "The mode table on the FCP adapter " |
| 182 | "has been damaged\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 183 | break; |
| 184 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: |
| 185 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 186 | "All NPIV ports on the FCP adapter have " |
| 187 | "been assigned\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 188 | break; |
| 189 | default: |
| 190 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 191 | "The link between the FCP adapter and " |
| 192 | "the FC fabric is down\n"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 193 | } |
| 194 | out: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 195 | zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req) |
| 199 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 200 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 201 | struct fsf_link_down_info *ldi = |
| 202 | (struct fsf_link_down_info *) &sr_buf->payload; |
| 203 | |
| 204 | switch (sr_buf->status_subtype) { |
| 205 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 206 | case FSF_STATUS_READ_SUB_FDISC_FAILED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 207 | zfcp_fsf_link_down_info_eval(req, ldi); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 208 | break; |
| 209 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 210 | zfcp_fsf_link_down_info_eval(req, NULL); |
Peter Senna Tschudin | 3b97487 | 2015-08-04 17:11:15 +0200 | [diff] [blame] | 211 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req) |
| 215 | { |
| 216 | struct zfcp_adapter *adapter = req->adapter; |
| 217 | struct fsf_status_read_buffer *sr_buf = req->data; |
| 218 | |
| 219 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 220 | zfcp_dbf_hba_fsf_uss("fssrh_1", req); |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 221 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 222 | zfcp_fsf_req_free(req); |
| 223 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Steffen Maier | 0100998 | 2012-09-04 15:23:30 +0200 | [diff] [blame] | 226 | zfcp_dbf_hba_fsf_uss("fssrh_4", req); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 227 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 228 | switch (sr_buf->status_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | case FSF_STATUS_READ_PORT_CLOSED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 230 | zfcp_fsf_status_read_port_closed(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | case FSF_STATUS_READ_INCOMING_ELS: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 233 | zfcp_fc_incoming_els(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 238 | zfcp_dbf_hba_bit_err("fssrh_3", req); |
Steffen Maier | 3638ccd | 2019-10-01 12:49:49 +0200 | [diff] [blame] | 239 | if (ber_stop) { |
| 240 | dev_warn(&adapter->ccw_device->dev, |
| 241 | "All paths over this FCP device are disused because of excessive bit errors\n"); |
| 242 | zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b"); |
| 243 | } else { |
| 244 | dev_warn(&adapter->ccw_device->dev, |
| 245 | "The error threshold for checksum statistics has been exceeded\n"); |
| 246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | case FSF_STATUS_READ_LINK_DOWN: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 249 | zfcp_fsf_status_read_link_down(req); |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 250 | zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | case FSF_STATUS_READ_LINK_UP: |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 253 | dev_info(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 254 | "The local link has been restored\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* All ports should be marked as ready to run again */ |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 256 | zfcp_erp_set_adapter_status(adapter, |
| 257 | ZFCP_STATUS_COMMON_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | zfcp_erp_adapter_reopen(adapter, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 259 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
| 260 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 261 | "fssrh_2"); |
Sven Schuetz | 2d1e547 | 2010-07-16 15:37:39 +0200 | [diff] [blame] | 262 | zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0); |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | break; |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 265 | case FSF_STATUS_READ_NOTIFICATION_LOST: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 266 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS) |
Steffen Maier | 43f60cb | 2012-09-04 15:23:35 +0200 | [diff] [blame] | 267 | zfcp_fc_conditional_port_scan(adapter); |
Maxim Shchetynin | 9eb69af | 2006-01-05 09:56:47 +0100 | [diff] [blame] | 268 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 269 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 270 | adapter->adapter_features = sr_buf->payload.word[0]; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 273 | |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 274 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 275 | zfcp_fsf_req_free(req); |
Swen Schillig | d26ab06 | 2008-05-19 12:17:37 +0200 | [diff] [blame] | 276 | |
| 277 | atomic_inc(&adapter->stat_miss); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 278 | queue_work(adapter->work_queue, &adapter->stat_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 281 | static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 283 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
| 284 | case FSF_SQ_FCP_RSP_AVAILABLE: |
| 285 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
| 286 | case FSF_SQ_NO_RETRY_POSSIBLE: |
| 287 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 288 | return; |
| 289 | case FSF_SQ_COMMAND_ABORTED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 290 | break; |
| 291 | case FSF_SQ_NO_RECOM: |
| 292 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 293 | "The FCP adapter reported a problem " |
| 294 | "that cannot be recovered\n"); |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 295 | zfcp_qdio_siosl(req->adapter); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 296 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 297 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 299 | /* all non-return stats set FSFREQ_ERROR*/ |
| 300 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 303 | static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req) |
| 304 | { |
| 305 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 306 | return; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 307 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 308 | switch (req->qtcb->header.fsf_status) { |
| 309 | case FSF_UNKNOWN_COMMAND: |
| 310 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 311 | "The FCP adapter does not recognize the command 0x%x\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 312 | req->qtcb->header.fsf_command); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 313 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 314 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 317 | zfcp_fsf_fsfstatus_qual_eval(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 322 | static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 324 | struct zfcp_adapter *adapter = req->adapter; |
| 325 | struct fsf_qtcb *qtcb = req->qtcb; |
| 326 | union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 328 | zfcp_dbf_hba_fsf_response(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 330 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 331 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 332 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 335 | switch (qtcb->prefix.prot_status) { |
| 336 | case FSF_PROT_GOOD: |
| 337 | case FSF_PROT_FSF_STATUS_PRESENTED: |
| 338 | return; |
| 339 | case FSF_PROT_QTCB_VERSION_ERROR: |
| 340 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 341 | "QTCB version 0x%x not supported by FCP adapter " |
| 342 | "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION, |
| 343 | psq->word[0], psq->word[1]); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 344 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 346 | case FSF_PROT_ERROR_STATE: |
| 347 | case FSF_PROT_SEQ_NUMB_ERROR: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 348 | zfcp_erp_adapter_reopen(adapter, 0, "fspse_2"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 349 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 351 | case FSF_PROT_UNSUPP_QTCB_TYPE: |
| 352 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 353 | "The QTCB type is not supported by the FCP adapter\n"); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 354 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 356 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 357 | atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 358 | &adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 360 | case FSF_PROT_DUPLICATE_REQUEST_ID: |
| 361 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 362 | "0x%Lx is an ambiguous request identifier\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 363 | (unsigned long long)qtcb->bottom.support.req_handle); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 364 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 366 | case FSF_PROT_LINK_DOWN: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 367 | zfcp_fsf_link_down_info_eval(req, &psq->link_down_info); |
Christof Schmitt | 452b505 | 2010-02-17 11:18:51 +0100 | [diff] [blame] | 368 | /* go through reopen to flush pending requests */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 369 | zfcp_erp_adapter_reopen(adapter, 0, "fspse_6"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 371 | case FSF_PROT_REEST_QUEUE: |
| 372 | /* All ports should be marked as ready to run again */ |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 373 | zfcp_erp_set_adapter_status(adapter, |
| 374 | ZFCP_STATUS_COMMON_RUNNING); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 375 | zfcp_erp_adapter_reopen(adapter, |
| 376 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 377 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 378 | "fspse_8"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 379 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | default: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 381 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 382 | "0x%x is not a valid transfer protocol status\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 383 | qtcb->prefix.prot_status); |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 384 | zfcp_qdio_siosl(adapter); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 385 | zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 387 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /** |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 391 | * zfcp_fsf_req_complete - process completion of a FSF request |
| 392 | * @fsf_req: The FSF request that has been completed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | * |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 394 | * When a request has been completed either from the FCP adapter, |
| 395 | * or it has been dismissed due to a queue shutdown, this function |
| 396 | * is called to process the completion status and trigger further |
| 397 | * events related to the FSF request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | */ |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 399 | static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 400 | { |
| 401 | if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { |
| 402 | zfcp_fsf_status_read_handler(req); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | del_timer(&req->timer); |
| 407 | zfcp_fsf_protstatus_eval(req); |
| 408 | zfcp_fsf_fsfstatus_eval(req); |
| 409 | req->handler(req); |
| 410 | |
| 411 | if (req->erp_action) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 412 | zfcp_erp_notify(req->erp_action, 0); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 413 | |
| 414 | if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) |
| 415 | zfcp_fsf_req_free(req); |
| 416 | else |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 417 | complete(&req->completion); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 420 | /** |
| 421 | * zfcp_fsf_req_dismiss_all - dismiss all fsf requests |
| 422 | * @adapter: pointer to struct zfcp_adapter |
| 423 | * |
| 424 | * Never ever call this without shutting down the adapter first. |
| 425 | * Otherwise the adapter would continue using and corrupting s390 storage. |
| 426 | * Included BUG_ON() call to ensure this is done. |
| 427 | * ERP is supposed to be the only user of this function. |
| 428 | */ |
| 429 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) |
| 430 | { |
| 431 | struct zfcp_fsf_req *req, *tmp; |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 432 | LIST_HEAD(remove_queue); |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 433 | |
| 434 | BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP); |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 435 | zfcp_reqlist_move(adapter->req_list, &remove_queue); |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 436 | |
| 437 | list_for_each_entry_safe(req, tmp, &remove_queue, list) { |
| 438 | list_del(&req->list); |
| 439 | req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
| 440 | zfcp_fsf_req_complete(req); |
| 441 | } |
| 442 | } |
| 443 | |
Steffen Maier | d220197 | 2012-09-04 15:23:29 +0200 | [diff] [blame] | 444 | #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0) |
| 445 | #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1) |
| 446 | #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2) |
| 447 | #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3) |
| 448 | #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4) |
| 449 | #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5) |
Jens Remus | 6e2e490 | 2018-05-17 19:15:06 +0200 | [diff] [blame] | 450 | #define ZFCP_FSF_PORTSPEED_32GBIT (1 << 6) |
| 451 | #define ZFCP_FSF_PORTSPEED_64GBIT (1 << 7) |
| 452 | #define ZFCP_FSF_PORTSPEED_128GBIT (1 << 8) |
Steffen Maier | d220197 | 2012-09-04 15:23:29 +0200 | [diff] [blame] | 453 | #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15) |
| 454 | |
| 455 | static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed) |
| 456 | { |
| 457 | u32 fdmi_speed = 0; |
| 458 | if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT) |
| 459 | fdmi_speed |= FC_PORTSPEED_1GBIT; |
| 460 | if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT) |
| 461 | fdmi_speed |= FC_PORTSPEED_2GBIT; |
| 462 | if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT) |
| 463 | fdmi_speed |= FC_PORTSPEED_4GBIT; |
| 464 | if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT) |
| 465 | fdmi_speed |= FC_PORTSPEED_10GBIT; |
| 466 | if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT) |
| 467 | fdmi_speed |= FC_PORTSPEED_8GBIT; |
| 468 | if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT) |
| 469 | fdmi_speed |= FC_PORTSPEED_16GBIT; |
Jens Remus | 6e2e490 | 2018-05-17 19:15:06 +0200 | [diff] [blame] | 470 | if (fsf_speed & ZFCP_FSF_PORTSPEED_32GBIT) |
| 471 | fdmi_speed |= FC_PORTSPEED_32GBIT; |
| 472 | if (fsf_speed & ZFCP_FSF_PORTSPEED_64GBIT) |
| 473 | fdmi_speed |= FC_PORTSPEED_64GBIT; |
| 474 | if (fsf_speed & ZFCP_FSF_PORTSPEED_128GBIT) |
| 475 | fdmi_speed |= FC_PORTSPEED_128GBIT; |
Steffen Maier | d220197 | 2012-09-04 15:23:29 +0200 | [diff] [blame] | 476 | if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED) |
| 477 | fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED; |
| 478 | return fdmi_speed; |
| 479 | } |
| 480 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 481 | static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 483 | struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 484 | struct zfcp_adapter *adapter = req->adapter; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 485 | struct Scsi_Host *shost = adapter->scsi_host; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 486 | struct fc_els_flogi *nsp, *plogi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 488 | /* adjust pointers for missing command code */ |
| 489 | nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param |
| 490 | - sizeof(u32)); |
| 491 | plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload |
| 492 | - sizeof(u32)); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 493 | |
| 494 | if (req->data) |
| 495 | memcpy(req->data, bottom, sizeof(*bottom)); |
| 496 | |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 497 | fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn); |
| 498 | fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 499 | fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; |
| 500 | |
Christof Schmitt | faf4cd8 | 2010-07-16 15:37:36 +0200 | [diff] [blame] | 501 | adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK; |
Christof Schmitt | 8d88cf3 | 2010-06-21 10:11:33 +0200 | [diff] [blame] | 502 | adapter->stat_read_buf_num = max(bottom->status_read_buf_num, |
| 503 | (u16)FSF_STATUS_READS_RECOM); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 504 | |
| 505 | if (fc_host_permanent_port_name(shost) == -1) |
| 506 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
| 507 | |
Steffen Maier | 9edf7d7 | 2013-04-26 17:34:54 +0200 | [diff] [blame] | 508 | zfcp_scsi_set_prot(adapter); |
| 509 | |
| 510 | /* no error return above here, otherwise must fix call chains */ |
| 511 | /* do not evaluate invalid fields */ |
| 512 | if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE) |
| 513 | return 0; |
| 514 | |
| 515 | fc_host_port_id(shost) = ntoh24(bottom->s_id); |
| 516 | fc_host_speed(shost) = |
| 517 | zfcp_fsf_convert_portspeed(bottom->fc_link_speed); |
| 518 | |
| 519 | adapter->hydra_version = bottom->adapter_type; |
| 520 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 521 | switch (bottom->fc_topology) { |
| 522 | case FSF_TOPO_P2P: |
Christof Schmitt | 800c0ca | 2009-11-24 16:54:12 +0100 | [diff] [blame] | 523 | adapter->peer_d_id = ntoh24(bottom->peer_d_id); |
Steffen Maier | 9d464fc | 2017-07-28 12:31:02 +0200 | [diff] [blame] | 524 | adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn); |
| 525 | adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 526 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 527 | break; |
| 528 | case FSF_TOPO_FABRIC: |
Steffen Maier | bd77bef | 2016-08-10 18:30:44 +0200 | [diff] [blame] | 529 | if (bottom->connection_features & FSF_FEATURE_NPIV_MODE) |
| 530 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; |
| 531 | else |
| 532 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 533 | break; |
| 534 | case FSF_TOPO_AL: |
| 535 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
Christof Schmitt | dceab65 | 2009-05-15 13:18:18 +0200 | [diff] [blame] | 536 | /* fall through */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 537 | default: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 538 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 539 | "Unknown or unsupported arbitrated loop " |
| 540 | "fibre channel topology detected\n"); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 541 | zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 542 | return -EIO; |
| 543 | } |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req) |
| 549 | { |
| 550 | struct zfcp_adapter *adapter = req->adapter; |
| 551 | struct fsf_qtcb *qtcb = req->qtcb; |
| 552 | struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config; |
| 553 | struct Scsi_Host *shost = adapter->scsi_host; |
| 554 | |
| 555 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 556 | return; |
| 557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | adapter->fsf_lic_version = bottom->lic_version; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 559 | adapter->adapter_features = bottom->adapter_features; |
| 560 | adapter->connection_features = bottom->connection_features; |
| 6f71d9b | 2005-04-10 23:04:28 -0500 | [diff] [blame] | 561 | adapter->peer_wwpn = 0; |
| 562 | adapter->peer_wwnn = 0; |
| 563 | adapter->peer_d_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 565 | switch (qtcb->header.fsf_status) { |
| 566 | case FSF_GOOD: |
| 567 | if (zfcp_fsf_exchange_config_evaluate(req)) |
| 568 | return; |
Swen Schillig | 52ef11a | 2007-08-28 09:31:09 +0200 | [diff] [blame] | 569 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 570 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
| 571 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 572 | "FCP adapter maximum QTCB size (%d bytes) " |
| 573 | "is too small\n", |
| 574 | bottom->max_qtcb_size); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 575 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 576 | return; |
| 577 | } |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 578 | atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 579 | &adapter->status); |
| 580 | break; |
| 581 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 582 | fc_host_node_name(shost) = 0; |
| 583 | fc_host_port_name(shost) = 0; |
| 584 | fc_host_port_id(shost) = 0; |
| 585 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
Andreas Herrmann | ad757cd | 2006-01-13 02:26:11 +0100 | [diff] [blame] | 586 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | adapter->hydra_version = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 588 | |
Daniel Hansel | f76ccaa | 2013-04-26 17:32:14 +0200 | [diff] [blame] | 589 | /* avoids adapter shutdown to be able to recognize |
| 590 | * events such as LINK UP */ |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 591 | atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
Daniel Hansel | f76ccaa | 2013-04-26 17:32:14 +0200 | [diff] [blame] | 592 | &adapter->status); |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 593 | zfcp_fsf_link_down_info_eval(req, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 594 | &qtcb->header.fsf_status_qual.link_down_info); |
Steffen Maier | 9edf7d7 | 2013-04-26 17:34:54 +0200 | [diff] [blame] | 595 | if (zfcp_fsf_exchange_config_evaluate(req)) |
| 596 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 597 | break; |
| 598 | default: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 599 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 600 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 603 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | adapter->hardware_version = bottom->hardware_version; |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 605 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
| 606 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
| 607 | EBCASC(fc_host_serial_number(shost), |
| 608 | min(FC_SERIAL_NUMBER_SIZE, 17)); |
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 | if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 612 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 613 | "The FCP adapter only supports newer " |
| 614 | "control block versions\n"); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 615 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 616 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 618 | if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 619 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 620 | "The FCP adapter only supports older " |
| 621 | "control block versions\n"); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 622 | zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 626 | static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 628 | struct zfcp_adapter *adapter = req->adapter; |
| 629 | struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port; |
| 630 | struct Scsi_Host *shost = adapter->scsi_host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 632 | if (req->data) |
| 633 | memcpy(req->data, bottom, sizeof(*bottom)); |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 634 | |
Christof Schmitt | 0282985 | 2009-03-02 13:09:06 +0100 | [diff] [blame] | 635 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) { |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 636 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
Christof Schmitt | 0282985 | 2009-03-02 13:09:06 +0100 | [diff] [blame] | 637 | } else |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 638 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
| 639 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; |
Steffen Maier | d220197 | 2012-09-04 15:23:29 +0200 | [diff] [blame] | 640 | fc_host_supported_speeds(shost) = |
| 641 | zfcp_fsf_convert_portspeed(bottom->supported_speed); |
Christof Schmitt | 2d8e62b | 2010-02-17 11:18:58 +0100 | [diff] [blame] | 642 | memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types, |
| 643 | FC_FC4_LIST_SIZE); |
| 644 | memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types, |
| 645 | FC_FC4_LIST_SIZE); |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 648 | 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] | 649 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 650 | struct fsf_qtcb *qtcb = req->qtcb; |
Andreas Herrmann | 2f8f3ed | 2006-02-11 01:41:50 +0100 | [diff] [blame] | 651 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 652 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return; |
| 654 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 655 | switch (qtcb->header.fsf_status) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 656 | case FSF_GOOD: |
| 657 | zfcp_fsf_exchange_port_evaluate(req); |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 658 | break; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 659 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 660 | zfcp_fsf_exchange_port_evaluate(req); |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 661 | zfcp_fsf_link_down_info_eval(req, |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 662 | &qtcb->header.fsf_status_qual.link_down_info); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 663 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 667 | static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 668 | { |
| 669 | struct zfcp_fsf_req *req; |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 670 | |
| 671 | if (likely(pool)) |
| 672 | req = mempool_alloc(pool, GFP_ATOMIC); |
| 673 | else |
| 674 | req = kmalloc(sizeof(*req), GFP_ATOMIC); |
| 675 | |
| 676 | if (unlikely(!req)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 677 | return NULL; |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 678 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 679 | memset(req, 0, sizeof(*req)); |
Christof Schmitt | 88f2a97 | 2008-11-04 16:35:07 +0100 | [diff] [blame] | 680 | req->pool = pool; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 681 | return req; |
| 682 | } |
| 683 | |
Steffen Maier | d39eda5 | 2018-05-17 19:14:58 +0200 | [diff] [blame] | 684 | static struct fsf_qtcb *zfcp_fsf_qtcb_alloc(mempool_t *pool) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 685 | { |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 686 | struct fsf_qtcb *qtcb; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 687 | |
| 688 | if (likely(pool)) |
| 689 | qtcb = mempool_alloc(pool, GFP_ATOMIC); |
| 690 | else |
Christof Schmitt | 259afe2 | 2011-02-22 19:54:44 +0100 | [diff] [blame] | 691 | qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 692 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 693 | if (unlikely(!qtcb)) |
| 694 | return NULL; |
| 695 | |
| 696 | memset(qtcb, 0, sizeof(*qtcb)); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 697 | return qtcb; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 698 | } |
| 699 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 700 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 701 | u32 fsf_cmd, u8 sbtype, |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 702 | mempool_t *pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 704 | struct zfcp_adapter *adapter = qdio->adapter; |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 705 | struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 706 | |
| 707 | if (unlikely(!req)) |
Christof Schmitt | 1e9b164 | 2009-07-13 15:06:04 +0200 | [diff] [blame] | 708 | return ERR_PTR(-ENOMEM); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 709 | |
| 710 | if (adapter->req_no == 0) |
| 711 | adapter->req_no++; |
| 712 | |
| 713 | INIT_LIST_HEAD(&req->list); |
Kees Cook | 75492a5 | 2017-10-16 16:44:34 -0700 | [diff] [blame] | 714 | timer_setup(&req->timer, NULL, 0); |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 715 | init_completion(&req->completion); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 716 | |
| 717 | req->adapter = adapter; |
| 718 | req->fsf_command = fsf_cmd; |
Christof Schmitt | 52bfb55 | 2009-03-02 13:08:58 +0100 | [diff] [blame] | 719 | req->req_id = adapter->req_no; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 720 | |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 721 | if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) { |
| 722 | if (likely(pool)) |
Steffen Maier | d39eda5 | 2018-05-17 19:14:58 +0200 | [diff] [blame] | 723 | req->qtcb = zfcp_fsf_qtcb_alloc( |
| 724 | adapter->pool.qtcb_pool); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 725 | else |
Steffen Maier | d39eda5 | 2018-05-17 19:14:58 +0200 | [diff] [blame] | 726 | req->qtcb = zfcp_fsf_qtcb_alloc(NULL); |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 727 | |
| 728 | if (unlikely(!req->qtcb)) { |
| 729 | zfcp_fsf_req_free(req); |
| 730 | return ERR_PTR(-ENOMEM); |
| 731 | } |
| 732 | |
Christof Schmitt | 5bdecd2 | 2010-02-17 11:18:55 +0100 | [diff] [blame] | 733 | req->seq_no = adapter->fsf_req_seq_no; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 734 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 735 | req->qtcb->prefix.req_id = req->req_id; |
| 736 | req->qtcb->prefix.ulp_info = 26; |
| 737 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command]; |
| 738 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; |
| 739 | req->qtcb->header.req_handle = req->req_id; |
| 740 | req->qtcb->header.fsf_command = req->fsf_command; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 741 | } |
| 742 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 743 | zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype, |
| 744 | req->qtcb, sizeof(struct fsf_qtcb)); |
| 745 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 746 | return req; |
| 747 | } |
| 748 | |
| 749 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
| 750 | { |
| 751 | struct zfcp_adapter *adapter = req->adapter; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 752 | struct zfcp_qdio *qdio = adapter->qdio; |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 753 | int with_qtcb = (req->qtcb != NULL); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 754 | int req_id = req->req_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 755 | |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 756 | zfcp_reqlist_add(adapter->req_list, req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 757 | |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 758 | req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free); |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 759 | req->issued = get_tod_clock(); |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 760 | if (zfcp_qdio_send(qdio, &req->qdio_req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 761 | del_timer(&req->timer); |
Christof Schmitt | 3765138 | 2008-11-04 16:35:08 +0100 | [diff] [blame] | 762 | /* lookup request again, list might have changed */ |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 763 | zfcp_reqlist_find_rm(adapter->req_list, req_id); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 764 | zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 765 | return -EIO; |
| 766 | } |
| 767 | |
| 768 | /* Don't increase for unsolicited status */ |
Martin Petermann | 135ea13 | 2009-04-17 15:08:01 +0200 | [diff] [blame] | 769 | if (with_qtcb) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 770 | adapter->fsf_req_seq_no++; |
Christof Schmitt | 52bfb55 | 2009-03-02 13:08:58 +0100 | [diff] [blame] | 771 | adapter->req_no++; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * zfcp_fsf_status_read - send status read request |
| 778 | * @adapter: pointer to struct zfcp_adapter |
| 779 | * @req_flags: request flags |
| 780 | * Returns: 0 on success, ERROR otherwise |
| 781 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 782 | int zfcp_fsf_status_read(struct zfcp_qdio *qdio) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 783 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 784 | struct zfcp_adapter *adapter = qdio->adapter; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 785 | struct zfcp_fsf_req *req; |
| 786 | struct fsf_status_read_buffer *sr_buf; |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 787 | struct page *page; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 788 | int retval = -EIO; |
| 789 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 790 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 791 | if (zfcp_qdio_sbal_get(qdio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Martin Peschke | 75a1408 | 2013-08-22 17:49:31 +0200 | [diff] [blame] | 794 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, |
| 795 | SBAL_SFLAGS0_TYPE_STATUS, |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 796 | adapter->pool.status_read_req); |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 797 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 798 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | goto out; |
| 800 | } |
| 801 | |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 802 | page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC); |
| 803 | if (!page) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 804 | retval = -ENOMEM; |
| 805 | goto failed_buf; |
| 806 | } |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 807 | sr_buf = page_address(page); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 808 | memset(sr_buf, 0, sizeof(*sr_buf)); |
| 809 | req->data = sr_buf; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 810 | |
| 811 | zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf)); |
| 812 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 813 | |
| 814 | retval = zfcp_fsf_req_send(req); |
| 815 | if (retval) |
| 816 | goto failed_req_send; |
| 817 | |
| 818 | goto out; |
| 819 | |
| 820 | failed_req_send: |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 821 | req->data = NULL; |
Christof Schmitt | c7b279a | 2011-02-22 19:54:40 +0100 | [diff] [blame] | 822 | mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 823 | failed_buf: |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 824 | zfcp_dbf_hba_fsf_uss("fssr__1", req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 825 | zfcp_fsf_req_free(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 826 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 827 | spin_unlock_irq(&qdio->req_q_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | return retval; |
| 829 | } |
| 830 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 831 | 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] | 832 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 833 | struct scsi_device *sdev = req->data; |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 834 | struct zfcp_scsi_dev *zfcp_sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 835 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 837 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 838 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 840 | zfcp_sdev = sdev_to_zfcp(sdev); |
| 841 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 842 | switch (req->qtcb->header.fsf_status) { |
| 843 | case FSF_PORT_HANDLE_NOT_VALID: |
| 844 | if (fsq->word[0] == fsq->word[1]) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 845 | zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 846 | "fsafch1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 847 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 848 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 850 | case FSF_LUN_HANDLE_NOT_VALID: |
| 851 | if (fsq->word[0] == fsq->word[1]) { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 852 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 853 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 856 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
| 857 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 859 | case FSF_PORT_BOXED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 860 | zfcp_erp_set_port_status(zfcp_sdev->port, |
| 861 | ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 862 | zfcp_erp_port_reopen(zfcp_sdev->port, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 863 | ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 864 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 865 | break; |
| 866 | case FSF_LUN_BOXED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 867 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 868 | zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 869 | "fsafch4"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 870 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 871 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 873 | switch (fsq->word[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 875 | zfcp_fc_test_link(zfcp_sdev->port); |
Christof Schmitt | dceab65 | 2009-05-15 13:18:18 +0200 | [diff] [blame] | 876 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 878 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | break; |
| 880 | } |
| 881 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 883 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
| 884 | break; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /** |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 889 | * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command |
| 890 | * @scmnd: The SCSI command to abort |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 891 | * Returns: pointer to struct zfcp_fsf_req |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 892 | */ |
| 893 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 894 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 895 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 896 | struct zfcp_fsf_req *req = NULL; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 897 | struct scsi_device *sdev = scmnd->device; |
| 898 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
| 899 | struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio; |
| 900 | unsigned long old_req_id = (unsigned long) scmnd->host_scribble; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 901 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 902 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 903 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 904 | goto out; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 905 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 906 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 907 | qdio->adapter->pool.scsi_abort); |
Swen Schillig | 633528c | 2008-11-26 18:07:37 +0100 | [diff] [blame] | 908 | if (IS_ERR(req)) { |
| 909 | req = NULL; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 910 | goto out; |
Swen Schillig | 633528c | 2008-11-26 18:07:37 +0100 | [diff] [blame] | 911 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 912 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 913 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 914 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 915 | goto out_error_free; |
| 916 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 917 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 918 | |
Swen Schillig | 6fbf25e | 2010-11-17 14:23:41 +0100 | [diff] [blame] | 919 | req->data = sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 920 | req->handler = zfcp_fsf_abort_fcp_command_handler; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 921 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
| 922 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 923 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
| 924 | |
| 925 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 926 | if (!zfcp_fsf_req_send(req)) |
| 927 | goto out; |
| 928 | |
| 929 | out_error_free: |
| 930 | zfcp_fsf_req_free(req); |
| 931 | req = NULL; |
| 932 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 933 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 934 | return req; |
| 935 | } |
| 936 | |
| 937 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
| 938 | { |
| 939 | struct zfcp_adapter *adapter = req->adapter; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 940 | struct zfcp_fsf_ct_els *ct = req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 941 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 942 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 943 | ct->status = -EINVAL; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 944 | |
| 945 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 946 | goto skip_fsfstatus; |
| 947 | |
| 948 | switch (header->fsf_status) { |
| 949 | case FSF_GOOD: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 950 | ct->status = 0; |
Steffen Maier | 975171b | 2017-07-28 12:30:53 +0200 | [diff] [blame] | 951 | zfcp_dbf_san_res("fsscth2", req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 952 | break; |
| 953 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 954 | zfcp_fsf_class_not_supp(req); |
| 955 | break; |
| 956 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 957 | switch (header->fsf_status_qual.word[0]){ |
| 958 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 959 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 960 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 961 | break; |
| 962 | } |
| 963 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 964 | case FSF_PORT_BOXED: |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 965 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 966 | break; |
| 967 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 968 | zfcp_erp_adapter_reopen(adapter, 0, "fsscth1"); |
Christof Schmitt | dceab65 | 2009-05-15 13:18:18 +0200 | [diff] [blame] | 969 | /* fall through */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 970 | case FSF_GENERIC_COMMAND_REJECTED: |
| 971 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 972 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 973 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 974 | case FSF_SBAL_MISMATCH: |
| 975 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 976 | break; |
| 977 | } |
| 978 | |
| 979 | skip_fsfstatus: |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 980 | if (ct->handler) |
| 981 | ct->handler(ct->handler_data); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 982 | } |
| 983 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 984 | static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio, |
| 985 | struct zfcp_qdio_req *q_req, |
Christof Schmitt | 426f605 | 2009-07-13 15:06:06 +0200 | [diff] [blame] | 986 | struct scatterlist *sg_req, |
| 987 | struct scatterlist *sg_resp) |
| 988 | { |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 989 | zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length); |
| 990 | zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length); |
| 991 | zfcp_qdio_set_sbale_last(qdio, q_req); |
Christof Schmitt | 426f605 | 2009-07-13 15:06:06 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 994 | static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req, |
| 995 | struct scatterlist *sg_req, |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 996 | struct scatterlist *sg_resp) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 997 | { |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 998 | struct zfcp_adapter *adapter = req->adapter; |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 999 | struct zfcp_qdio *qdio = adapter->qdio; |
| 1000 | struct fsf_qtcb *qtcb = req->qtcb; |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 1001 | u32 feat = adapter->adapter_features; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1002 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1003 | if (zfcp_adapter_multi_buffer_active(adapter)) { |
| 1004 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req)) |
| 1005 | return -EIO; |
Steffen Maier | 70369f8 | 2016-08-10 18:30:45 +0200 | [diff] [blame] | 1006 | qtcb->bottom.support.req_buf_length = |
| 1007 | zfcp_qdio_real_bytes(sg_req); |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1008 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp)) |
| 1009 | return -EIO; |
Steffen Maier | 70369f8 | 2016-08-10 18:30:45 +0200 | [diff] [blame] | 1010 | qtcb->bottom.support.resp_buf_length = |
| 1011 | zfcp_qdio_real_bytes(sg_resp); |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 1012 | |
LABBE Corentin | 7d91869 | 2017-07-28 12:30:47 +0200 | [diff] [blame] | 1013 | zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req)); |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1014 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
| 1015 | zfcp_qdio_set_scount(qdio, &req->qdio_req); |
Christof Schmitt | 426f605 | 2009-07-13 15:06:06 +0200 | [diff] [blame] | 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | /* use single, unchained SBAL if it can hold the request */ |
Swen Schillig | 30b6777 | 2010-06-21 10:11:31 +0200 | [diff] [blame] | 1020 | if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) { |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1021 | zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req, |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1022 | sg_req, sg_resp); |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1026 | if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) |
| 1027 | return -EOPNOTSUPP; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1028 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1029 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req)) |
Christof Schmitt | 9072df4 | 2009-07-13 15:06:07 +0200 | [diff] [blame] | 1030 | return -EIO; |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1031 | |
| 1032 | qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req); |
| 1033 | |
| 1034 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
| 1035 | zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req); |
| 1036 | |
| 1037 | if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp)) |
| 1038 | return -EIO; |
| 1039 | |
| 1040 | qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp); |
| 1041 | |
| 1042 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Christof Schmitt | 98fc4d5 | 2009-08-18 15:43:26 +0200 | [diff] [blame] | 1043 | |
Christof Schmitt | b1a5898 | 2009-09-24 10:23:21 +0200 | [diff] [blame] | 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req, |
| 1048 | struct scatterlist *sg_req, |
| 1049 | struct scatterlist *sg_resp, |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 1050 | unsigned int timeout) |
Christof Schmitt | b1a5898 | 2009-09-24 10:23:21 +0200 | [diff] [blame] | 1051 | { |
| 1052 | int ret; |
| 1053 | |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 1054 | ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp); |
Christof Schmitt | b1a5898 | 2009-09-24 10:23:21 +0200 | [diff] [blame] | 1055 | if (ret) |
| 1056 | return ret; |
| 1057 | |
Christof Schmitt | 98fc4d5 | 2009-08-18 15:43:26 +0200 | [diff] [blame] | 1058 | /* common settings for ct/gs and els requests */ |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 1059 | if (timeout > 255) |
| 1060 | timeout = 255; /* max value accepted by hardware */ |
Christof Schmitt | 98fc4d5 | 2009-08-18 15:43:26 +0200 | [diff] [blame] | 1061 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 1062 | req->qtcb->bottom.support.timeout = timeout; |
| 1063 | zfcp_fsf_start_timer(req, (timeout + 10) * HZ); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1064 | |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
| 1070 | * @ct: pointer to struct zfcp_send_ct with data for request |
| 1071 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1072 | */ |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1073 | int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 1074 | struct zfcp_fsf_ct_els *ct, mempool_t *pool, |
| 1075 | unsigned int timeout) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1076 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1077 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1078 | struct zfcp_fsf_req *req; |
| 1079 | int ret = -EIO; |
| 1080 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1081 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1082 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1083 | goto out; |
| 1084 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1085 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1086 | SBAL_SFLAGS0_TYPE_WRITE_READ, pool); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1087 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1088 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1089 | ret = PTR_ERR(req); |
| 1090 | goto out; |
| 1091 | } |
| 1092 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1093 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 1094 | ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1095 | if (ret) |
| 1096 | goto failed_send; |
| 1097 | |
| 1098 | req->handler = zfcp_fsf_send_ct_handler; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1099 | req->qtcb->header.port_handle = wka_port->handle; |
Steffen Maier | 771bf03 | 2016-08-10 18:30:51 +0200 | [diff] [blame] | 1100 | ct->d_id = wka_port->d_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1101 | req->data = ct; |
| 1102 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 1103 | zfcp_dbf_san_req("fssct_1", req, wka_port->d_id); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1104 | |
| 1105 | ret = zfcp_fsf_req_send(req); |
| 1106 | if (ret) |
| 1107 | goto failed_send; |
| 1108 | |
| 1109 | goto out; |
| 1110 | |
| 1111 | failed_send: |
| 1112 | zfcp_fsf_req_free(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1113 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1114 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1115 | return ret; |
| 1116 | } |
| 1117 | |
| 1118 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
| 1119 | { |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1120 | struct zfcp_fsf_ct_els *send_els = req->data; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1121 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1122 | |
| 1123 | send_els->status = -EINVAL; |
| 1124 | |
| 1125 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 1126 | goto skip_fsfstatus; |
| 1127 | |
| 1128 | switch (header->fsf_status) { |
| 1129 | case FSF_GOOD: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1130 | send_els->status = 0; |
Steffen Maier | 975171b | 2017-07-28 12:30:53 +0200 | [diff] [blame] | 1131 | zfcp_dbf_san_res("fsselh1", req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1132 | break; |
| 1133 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 1134 | zfcp_fsf_class_not_supp(req); |
| 1135 | break; |
| 1136 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1137 | switch (header->fsf_status_qual.word[0]){ |
| 1138 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1139 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1140 | case FSF_SQ_RETRY_IF_POSSIBLE: |
| 1141 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1142 | break; |
| 1143 | } |
| 1144 | break; |
| 1145 | case FSF_ELS_COMMAND_REJECTED: |
| 1146 | case FSF_PAYLOAD_SIZE_MISMATCH: |
| 1147 | case FSF_REQUEST_SIZE_TOO_LARGE: |
| 1148 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
| 1149 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1150 | case FSF_SBAL_MISMATCH: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1151 | /* should never occur, avoided in zfcp_fsf_send_els */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1152 | /* fall through */ |
| 1153 | default: |
| 1154 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1155 | break; |
| 1156 | } |
| 1157 | skip_fsfstatus: |
| 1158 | if (send_els->handler) |
| 1159 | send_els->handler(send_els->handler_data); |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) |
| 1164 | * @els: pointer to struct zfcp_send_els with data for the command |
| 1165 | */ |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1166 | int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id, |
Swen Schillig | 51375ee | 2010-01-14 17:19:02 +0100 | [diff] [blame] | 1167 | struct zfcp_fsf_ct_els *els, unsigned int timeout) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1168 | { |
| 1169 | struct zfcp_fsf_req *req; |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1170 | struct zfcp_qdio *qdio = adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1171 | int ret = -EIO; |
| 1172 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1173 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1174 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1175 | goto out; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1176 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1177 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1178 | SBAL_SFLAGS0_TYPE_WRITE_READ, NULL); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1179 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1180 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1181 | ret = PTR_ERR(req); |
| 1182 | goto out; |
| 1183 | } |
| 1184 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1185 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 1186 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 1187 | if (!zfcp_adapter_multi_buffer_active(adapter)) |
| 1188 | zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2); |
Swen Schillig | 01b0475 | 2010-07-16 15:37:37 +0200 | [diff] [blame] | 1189 | |
| 1190 | ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout); |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1191 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1192 | if (ret) |
| 1193 | goto failed_send; |
| 1194 | |
Christof Schmitt | 7c7dc19 | 2009-11-24 16:54:13 +0100 | [diff] [blame] | 1195 | hton24(req->qtcb->bottom.support.d_id, d_id); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1196 | req->handler = zfcp_fsf_send_els_handler; |
Steffen Maier | 771bf03 | 2016-08-10 18:30:51 +0200 | [diff] [blame] | 1197 | els->d_id = d_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1198 | req->data = els; |
| 1199 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 1200 | zfcp_dbf_san_req("fssels1", req, d_id); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1201 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1202 | ret = zfcp_fsf_req_send(req); |
| 1203 | if (ret) |
| 1204 | goto failed_send; |
| 1205 | |
| 1206 | goto out; |
| 1207 | |
| 1208 | failed_send: |
| 1209 | zfcp_fsf_req_free(req); |
| 1210 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1211 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
| 1216 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1217 | struct zfcp_fsf_req *req; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1218 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1219 | int retval = -EIO; |
| 1220 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1221 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1222 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1223 | goto out; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1224 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1225 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1226 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1227 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1228 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1229 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1230 | retval = PTR_ERR(req); |
| 1231 | goto out; |
| 1232 | } |
| 1233 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1234 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1235 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1236 | |
| 1237 | req->qtcb->bottom.config.feature_selection = |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1238 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1239 | FSF_FEATURE_UPDATE_ALERT; |
| 1240 | req->erp_action = erp_action; |
| 1241 | req->handler = zfcp_fsf_exchange_config_data_handler; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1242 | erp_action->fsf_req_id = req->req_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1243 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1244 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1245 | retval = zfcp_fsf_req_send(req); |
| 1246 | if (retval) { |
| 1247 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1248 | erp_action->fsf_req_id = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1249 | } |
| 1250 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1251 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1252 | return retval; |
| 1253 | } |
| 1254 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1255 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1256 | struct fsf_qtcb_bottom_config *data) |
| 1257 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1258 | struct zfcp_fsf_req *req = NULL; |
| 1259 | int retval = -EIO; |
| 1260 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1261 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1262 | if (zfcp_qdio_sbal_get(qdio)) |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1263 | goto out_unlock; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1264 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1265 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1266 | SBAL_SFLAGS0_TYPE_READ, NULL); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1267 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1268 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1269 | retval = PTR_ERR(req); |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1270 | goto out_unlock; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1271 | } |
| 1272 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1273 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1274 | req->handler = zfcp_fsf_exchange_config_data_handler; |
| 1275 | |
| 1276 | req->qtcb->bottom.config.feature_selection = |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1277 | FSF_FEATURE_NOTIFICATION_LOST | |
| 1278 | FSF_FEATURE_UPDATE_ALERT; |
| 1279 | |
| 1280 | if (data) |
| 1281 | req->data = data; |
| 1282 | |
| 1283 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1284 | retval = zfcp_fsf_req_send(req); |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1285 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1286 | if (!retval) |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 1287 | wait_for_completion(&req->completion); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1288 | |
| 1289 | zfcp_fsf_req_free(req); |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1290 | return retval; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1291 | |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1292 | out_unlock: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1293 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1294 | return retval; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * zfcp_fsf_exchange_port_data - request information about local port |
| 1299 | * @erp_action: ERP action for the adapter for which port data is requested |
| 1300 | * Returns: 0 on success, error otherwise |
| 1301 | */ |
| 1302 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
| 1303 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1304 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1305 | struct zfcp_fsf_req *req; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1306 | int retval = -EIO; |
| 1307 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1308 | if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1309 | return -EOPNOTSUPP; |
| 1310 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1311 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1312 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1313 | goto out; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1314 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1315 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1316 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1317 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1318 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1319 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1320 | retval = PTR_ERR(req); |
| 1321 | goto out; |
| 1322 | } |
| 1323 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1324 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1325 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1326 | |
| 1327 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1328 | req->erp_action = erp_action; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1329 | erp_action->fsf_req_id = req->req_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1330 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1331 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1332 | retval = zfcp_fsf_req_send(req); |
| 1333 | if (retval) { |
| 1334 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1335 | erp_action->fsf_req_id = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1336 | } |
| 1337 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1338 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1339 | return retval; |
| 1340 | } |
| 1341 | |
| 1342 | /** |
| 1343 | * zfcp_fsf_exchange_port_data_sync - request information about local port |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1344 | * @qdio: pointer to struct zfcp_qdio |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1345 | * @data: pointer to struct fsf_qtcb_bottom_port |
| 1346 | * Returns: 0 on success, error otherwise |
| 1347 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1348 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio, |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1349 | struct fsf_qtcb_bottom_port *data) |
| 1350 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1351 | struct zfcp_fsf_req *req = NULL; |
| 1352 | int retval = -EIO; |
| 1353 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1354 | if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1355 | return -EOPNOTSUPP; |
| 1356 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1357 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1358 | if (zfcp_qdio_sbal_get(qdio)) |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1359 | goto out_unlock; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1360 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1361 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1362 | SBAL_SFLAGS0_TYPE_READ, NULL); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1363 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1364 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1365 | retval = PTR_ERR(req); |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1366 | goto out_unlock; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | if (data) |
| 1370 | req->data = data; |
| 1371 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1372 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1373 | |
| 1374 | req->handler = zfcp_fsf_exchange_port_data_handler; |
| 1375 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1376 | retval = zfcp_fsf_req_send(req); |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1377 | spin_unlock_irq(&qdio->req_q_lock); |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1378 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1379 | if (!retval) |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 1380 | wait_for_completion(&req->completion); |
| 1381 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1382 | zfcp_fsf_req_free(req); |
| 1383 | |
| 1384 | return retval; |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1385 | |
| 1386 | out_unlock: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1387 | spin_unlock_irq(&qdio->req_q_lock); |
Christof Schmitt | ada81b7 | 2009-04-17 15:08:03 +0200 | [diff] [blame] | 1388 | return retval; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
| 1392 | { |
| 1393 | struct zfcp_port *port = req->data; |
| 1394 | struct fsf_qtcb_header *header = &req->qtcb->header; |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 1395 | struct fc_els_flogi *plogi; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1396 | |
| 1397 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Martin Petermann | a17c585 | 2009-05-15 13:18:19 +0200 | [diff] [blame] | 1398 | goto out; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1399 | |
| 1400 | switch (header->fsf_status) { |
| 1401 | case FSF_PORT_ALREADY_OPEN: |
| 1402 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1403 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
| 1404 | dev_warn(&req->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1405 | "Not enough FCP adapter resources to open " |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 1406 | "remote port 0x%016Lx\n", |
| 1407 | (unsigned long long)port->wwpn); |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1408 | zfcp_erp_set_port_status(port, |
| 1409 | ZFCP_STATUS_COMMON_ERP_FAILED); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1410 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1411 | break; |
| 1412 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1413 | switch (header->fsf_status_qual.word[0]) { |
| 1414 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Steffen Maier | 394134f | 2017-07-28 12:31:00 +0200 | [diff] [blame] | 1415 | /* no zfcp_fc_test_link() with failed open port */ |
| 1416 | /* fall through */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1417 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1418 | case FSF_SQ_NO_RETRY_POSSIBLE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1419 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1420 | break; |
| 1421 | } |
| 1422 | break; |
| 1423 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | port->handle = header->port_handle; |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1425 | atomic_or(ZFCP_STATUS_COMMON_OPEN | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1427 | atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED, |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1428 | &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | /* check whether D_ID has changed during open */ |
| 1430 | /* |
| 1431 | * FIXME: This check is not airtight, as the FCP channel does |
| 1432 | * not monitor closures of target port connections caused on |
| 1433 | * the remote side. Thus, they might miss out on invalidating |
| 1434 | * locally cached WWPNs (and other N_Port parameters) of gone |
| 1435 | * target ports. So, our heroic attempt to make things safe |
| 1436 | * could be undermined by 'open port' response data tagged with |
| 1437 | * obsolete WWPNs. Another reason to monitor potential |
| 1438 | * connection closures ourself at least (by interpreting |
| 1439 | * incoming ELS' and unsolicited status). It just crosses my |
| 1440 | * mind that one should be able to cross-check by means of |
| 1441 | * another GID_PN straight after a port has been opened. |
| 1442 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
| 1443 | */ |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 1444 | plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els; |
Christof Schmitt | 39eb7e9a | 2008-12-19 16:57:01 +0100 | [diff] [blame] | 1445 | if (req->qtcb->bottom.support.els1_length >= |
Christof Schmitt | 9d05ce2 | 2009-11-24 16:54:09 +0100 | [diff] [blame] | 1446 | FSF_PLOGI_MIN_LEN) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1447 | zfcp_fc_plogi_evaluate(port, plogi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Martin Petermann | a17c585 | 2009-05-15 13:18:19 +0200 | [diff] [blame] | 1453 | |
| 1454 | out: |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 1455 | put_device(&port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1458 | /** |
| 1459 | * zfcp_fsf_open_port - create and send open port request |
| 1460 | * @erp_action: pointer to struct zfcp_erp_action |
| 1461 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1463 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1465 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Martin Petermann | a17c585 | 2009-05-15 13:18:19 +0200 | [diff] [blame] | 1466 | struct zfcp_port *port = erp_action->port; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1467 | struct zfcp_fsf_req *req; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1468 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1470 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1471 | if (zfcp_qdio_sbal_get(qdio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1474 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1475 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1476 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1477 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1478 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1479 | retval = PTR_ERR(req); |
| 1480 | goto out; |
| 1481 | } |
| 1482 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1483 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1484 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1486 | req->handler = zfcp_fsf_open_port_handler; |
Christof Schmitt | 800c0ca | 2009-11-24 16:54:12 +0100 | [diff] [blame] | 1487 | hton24(req->qtcb->bottom.support.d_id, port->d_id); |
Martin Petermann | a17c585 | 2009-05-15 13:18:19 +0200 | [diff] [blame] | 1488 | req->data = port; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1489 | req->erp_action = erp_action; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1490 | erp_action->fsf_req_id = req->req_id; |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 1491 | get_device(&port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1493 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1494 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1496 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1497 | erp_action->fsf_req_id = 0; |
Christof Schmitt | 615f59e | 2010-02-17 11:18:56 +0100 | [diff] [blame] | 1498 | put_device(&port->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1500 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1501 | spin_unlock_irq(&qdio->req_q_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | return retval; |
| 1503 | } |
| 1504 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1505 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1507 | struct zfcp_port *port = req->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1509 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1510 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1512 | switch (req->qtcb->header.fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1514 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1515 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | case FSF_GOOD: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1520 | zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1525 | /** |
| 1526 | * zfcp_fsf_close_port - create and send close port request |
| 1527 | * @erp_action: pointer to struct zfcp_erp_action |
| 1528 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1530 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1532 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1533 | struct zfcp_fsf_req *req; |
| 1534 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1536 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1537 | if (zfcp_qdio_sbal_get(qdio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1540 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1541 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1542 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1543 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1544 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1545 | retval = PTR_ERR(req); |
| 1546 | goto out; |
| 1547 | } |
| 1548 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1549 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1550 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1552 | req->handler = zfcp_fsf_close_port_handler; |
| 1553 | req->data = erp_action->port; |
| 1554 | req->erp_action = erp_action; |
| 1555 | req->qtcb->header.port_handle = erp_action->port->handle; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1556 | erp_action->fsf_req_id = req->req_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1558 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1559 | retval = zfcp_fsf_req_send(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | if (retval) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1561 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1562 | erp_action->fsf_req_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1564 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1565 | spin_unlock_irq(&qdio->req_q_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | return retval; |
| 1567 | } |
| 1568 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1569 | static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req) |
| 1570 | { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1571 | struct zfcp_fc_wka_port *wka_port = req->data; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1572 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 1573 | |
| 1574 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1575 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1576 | goto out; |
| 1577 | } |
| 1578 | |
| 1579 | switch (header->fsf_status) { |
| 1580 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
| 1581 | dev_warn(&req->adapter->ccw_device->dev, |
| 1582 | "Opening WKA port 0x%x failed\n", wka_port->d_id); |
Christof Schmitt | dceab65 | 2009-05-15 13:18:18 +0200 | [diff] [blame] | 1583 | /* fall through */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1584 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1585 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1586 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1587 | break; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1588 | case FSF_GOOD: |
| 1589 | wka_port->handle = header->port_handle; |
Swen Schillig | 27f492c | 2009-07-13 15:06:13 +0200 | [diff] [blame] | 1590 | /* fall through */ |
| 1591 | case FSF_PORT_ALREADY_OPEN: |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1592 | wka_port->status = ZFCP_FC_WKA_PORT_ONLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1593 | } |
| 1594 | out: |
| 1595 | wake_up(&wka_port->completion_wq); |
| 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * zfcp_fsf_open_wka_port - create and send open wka-port request |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1600 | * @wka_port: pointer to struct zfcp_fc_wka_port |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1601 | * Returns: 0 on success, error otherwise |
| 1602 | */ |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1603 | int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1604 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1605 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
Steffen Maier | 2dfa668 | 2017-02-08 15:34:22 +0100 | [diff] [blame] | 1606 | struct zfcp_fsf_req *req; |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1607 | unsigned long req_id = 0; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1608 | int retval = -EIO; |
| 1609 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1610 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1611 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1612 | goto out; |
| 1613 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1614 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1615 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1616 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1617 | |
Tobias Klauser | 4e7d7af | 2011-02-22 19:54:38 +0100 | [diff] [blame] | 1618 | if (IS_ERR(req)) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1619 | retval = PTR_ERR(req); |
| 1620 | goto out; |
| 1621 | } |
| 1622 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1623 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1624 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1625 | |
| 1626 | req->handler = zfcp_fsf_open_wka_port_handler; |
Christof Schmitt | 800c0ca | 2009-11-24 16:54:12 +0100 | [diff] [blame] | 1627 | hton24(req->qtcb->bottom.support.d_id, wka_port->d_id); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1628 | req->data = wka_port; |
| 1629 | |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1630 | req_id = req->req_id; |
| 1631 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1632 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1633 | retval = zfcp_fsf_req_send(req); |
| 1634 | if (retval) |
| 1635 | zfcp_fsf_req_free(req); |
| 1636 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1637 | spin_unlock_irq(&qdio->req_q_lock); |
Steffen Maier | 2dfa668 | 2017-02-08 15:34:22 +0100 | [diff] [blame] | 1638 | if (!retval) |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1639 | zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1640 | return retval; |
| 1641 | } |
| 1642 | |
| 1643 | static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req) |
| 1644 | { |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1645 | struct zfcp_fc_wka_port *wka_port = req->data; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1646 | |
| 1647 | if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) { |
| 1648 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1649 | zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1"); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1650 | } |
| 1651 | |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1652 | wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1653 | wake_up(&wka_port->completion_wq); |
| 1654 | } |
| 1655 | |
| 1656 | /** |
| 1657 | * zfcp_fsf_close_wka_port - create and send close wka port request |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1658 | * @wka_port: WKA port to open |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1659 | * Returns: 0 on success, error otherwise |
| 1660 | */ |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 1661 | int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1662 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1663 | struct zfcp_qdio *qdio = wka_port->adapter->qdio; |
Steffen Maier | 2dfa668 | 2017-02-08 15:34:22 +0100 | [diff] [blame] | 1664 | struct zfcp_fsf_req *req; |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1665 | unsigned long req_id = 0; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1666 | int retval = -EIO; |
| 1667 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1668 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1669 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1670 | goto out; |
| 1671 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1672 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1673 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1674 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1675 | |
Tobias Klauser | 4e7d7af | 2011-02-22 19:54:38 +0100 | [diff] [blame] | 1676 | if (IS_ERR(req)) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1677 | retval = PTR_ERR(req); |
| 1678 | goto out; |
| 1679 | } |
| 1680 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1681 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1682 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1683 | |
| 1684 | req->handler = zfcp_fsf_close_wka_port_handler; |
| 1685 | req->data = wka_port; |
| 1686 | req->qtcb->header.port_handle = wka_port->handle; |
| 1687 | |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1688 | req_id = req->req_id; |
| 1689 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1690 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
| 1691 | retval = zfcp_fsf_req_send(req); |
| 1692 | if (retval) |
| 1693 | zfcp_fsf_req_free(req); |
| 1694 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1695 | spin_unlock_irq(&qdio->req_q_lock); |
Steffen Maier | 2dfa668 | 2017-02-08 15:34:22 +0100 | [diff] [blame] | 1696 | if (!retval) |
Benjamin Block | d85e830 | 2019-07-02 23:02:01 +0200 | [diff] [blame] | 1697 | zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req_id); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1698 | return retval; |
| 1699 | } |
| 1700 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1701 | 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] | 1702 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1703 | struct zfcp_port *port = req->data; |
| 1704 | struct fsf_qtcb_header *header = &req->qtcb->header; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1705 | struct scsi_device *sdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1707 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Christof Schmitt | a5b11dd | 2009-03-02 13:08:54 +0100 | [diff] [blame] | 1708 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | switch (header->fsf_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1712 | zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1713 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | case FSF_PORT_BOXED: |
Christof Schmitt | 5c815d1 | 2008-03-10 16:18:54 +0100 | [diff] [blame] | 1716 | /* can't use generic zfcp_erp_modify_port_status because |
| 1717 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1718 | atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1719 | shost_for_each_device(sdev, port->adapter->scsi_host) |
| 1720 | if (sdev_to_zfcp(sdev)->port == port) |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1721 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1722 | &sdev_to_zfcp(sdev)->status); |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1723 | zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 1724 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1725 | "fscpph2"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [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 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | switch (header->fsf_status_qual.word[0]) { |
| 1730 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1731 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1733 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | } |
| 1736 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | case FSF_GOOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | /* can't use generic zfcp_erp_modify_port_status because |
| 1739 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
| 1740 | */ |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1741 | atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1742 | shost_for_each_device(sdev, port->adapter->scsi_host) |
| 1743 | if (sdev_to_zfcp(sdev)->port == port) |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1744 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1745 | &sdev_to_zfcp(sdev)->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1750 | /** |
| 1751 | * zfcp_fsf_close_physical_port - close physical port |
| 1752 | * @erp_action: pointer to struct zfcp_erp_action |
| 1753 | * Returns: 0 on success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | */ |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1755 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1757 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1758 | struct zfcp_fsf_req *req; |
| 1759 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1761 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1762 | if (zfcp_qdio_sbal_get(qdio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1765 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1766 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1767 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1768 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1769 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1770 | retval = PTR_ERR(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | goto out; |
| 1772 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1773 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1774 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1775 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1776 | |
| 1777 | req->data = erp_action->port; |
| 1778 | req->qtcb->header.port_handle = erp_action->port->handle; |
| 1779 | req->erp_action = erp_action; |
| 1780 | req->handler = zfcp_fsf_close_physical_port_handler; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1781 | erp_action->fsf_req_id = req->req_id; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1782 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1783 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1784 | retval = zfcp_fsf_req_send(req); |
| 1785 | if (retval) { |
| 1786 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1787 | erp_action->fsf_req_id = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1788 | } |
| 1789 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1790 | spin_unlock_irq(&qdio->req_q_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | return retval; |
| 1792 | } |
| 1793 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1794 | static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1796 | struct zfcp_adapter *adapter = req->adapter; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1797 | struct scsi_device *sdev = req->data; |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 1798 | struct zfcp_scsi_dev *zfcp_sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1799 | struct fsf_qtcb_header *header = &req->qtcb->header; |
Martin Peschke | 663e089 | 2013-04-26 16:13:54 +0200 | [diff] [blame] | 1800 | union fsf_status_qual *qual = &header->fsf_status_qual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1802 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1803 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 1805 | zfcp_sdev = sdev_to_zfcp(sdev); |
| 1806 | |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1807 | atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Martin Peschke | 663e089 | 2013-04-26 16:13:54 +0200 | [diff] [blame] | 1808 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1809 | &zfcp_sdev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | switch (header->fsf_status) { |
| 1812 | |
| 1813 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1814 | zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1815 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | case FSF_LUN_ALREADY_OPEN: |
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 | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1819 | zfcp_erp_set_port_status(zfcp_sdev->port, |
| 1820 | ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 1821 | zfcp_erp_port_reopen(zfcp_sdev->port, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1822 | ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 1823 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | case FSF_LUN_SHARING_VIOLATION: |
Martin Peschke | 663e089 | 2013-04-26 16:13:54 +0200 | [diff] [blame] | 1826 | if (qual->word[0]) |
| 1827 | dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev, |
| 1828 | "LUN 0x%Lx on port 0x%Lx is already in " |
| 1829 | "use by CSS%d, MIF Image ID %x\n", |
| 1830 | zfcp_scsi_dev_lun(sdev), |
| 1831 | (unsigned long long)zfcp_sdev->port->wwpn, |
| 1832 | qual->fsf_queue_designator.cssid, |
| 1833 | qual->fsf_queue_designator.hla); |
| 1834 | zfcp_erp_set_lun_status(sdev, |
| 1835 | ZFCP_STATUS_COMMON_ERP_FAILED | |
| 1836 | ZFCP_STATUS_COMMON_ACCESS_DENIED); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1837 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1840 | dev_warn(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1841 | "No handle is available for LUN " |
| 1842 | "0x%016Lx on port 0x%016Lx\n", |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1843 | (unsigned long long)zfcp_scsi_dev_lun(sdev), |
| 1844 | (unsigned long long)zfcp_sdev->port->wwpn); |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1845 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1846 | /* fall through */ |
| 1847 | case FSF_INVALID_COMMAND_OPTION: |
| 1848 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | case FSF_ADAPTER_STATUS_AVAILABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | switch (header->fsf_status_qual.word[0]) { |
| 1852 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1853 | zfcp_fc_test_link(zfcp_sdev->port); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1854 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1856 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | break; |
| 1860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | case FSF_GOOD: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1862 | zfcp_sdev->lun_handle = header->lun_handle; |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1863 | atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /** |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1869 | * zfcp_fsf_open_lun - open LUN |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1870 | * @erp_action: pointer to struct zfcp_erp_action |
| 1871 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | */ |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1873 | int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1875 | struct zfcp_adapter *adapter = erp_action->adapter; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1876 | struct zfcp_qdio *qdio = adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1877 | struct zfcp_fsf_req *req; |
| 1878 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1880 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1881 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1882 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1884 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1885 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | a4623c4 | 2009-08-18 15:43:15 +0200 | [diff] [blame] | 1886 | adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1887 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1888 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1889 | retval = PTR_ERR(req); |
| 1890 | goto out; |
Christof Schmitt | ba17242 | 2007-12-20 12:30:26 +0100 | [diff] [blame] | 1891 | } |
| 1892 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1893 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1894 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1896 | req->qtcb->header.port_handle = erp_action->port->handle; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1897 | req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev); |
| 1898 | req->handler = zfcp_fsf_open_lun_handler; |
| 1899 | req->data = erp_action->sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1900 | req->erp_action = erp_action; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1901 | erp_action->fsf_req_id = req->req_id; |
Andreas Herrmann | 059c97d | 2005-09-13 21:47:52 +0200 | [diff] [blame] | 1902 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1903 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
| 1904 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1906 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1907 | retval = zfcp_fsf_req_send(req); |
| 1908 | if (retval) { |
| 1909 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1910 | erp_action->fsf_req_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1912 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1913 | spin_unlock_irq(&qdio->req_q_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | return retval; |
| 1915 | } |
| 1916 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1917 | static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1919 | struct scsi_device *sdev = req->data; |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 1920 | struct zfcp_scsi_dev *zfcp_sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1921 | |
| 1922 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 1923 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1924 | |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 1925 | zfcp_sdev = sdev_to_zfcp(sdev); |
| 1926 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1927 | switch (req->qtcb->header.fsf_status) { |
| 1928 | case FSF_PORT_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1929 | zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1930 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1931 | break; |
| 1932 | case FSF_LUN_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1933 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1934 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1935 | break; |
| 1936 | case FSF_PORT_BOXED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 1937 | zfcp_erp_set_port_status(zfcp_sdev->port, |
| 1938 | ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 1939 | zfcp_erp_port_reopen(zfcp_sdev->port, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 1940 | ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 1941 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1942 | break; |
| 1943 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 1944 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
| 1945 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1946 | zfcp_fc_test_link(zfcp_sdev->port); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1947 | /* fall through */ |
| 1948 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
| 1949 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 1950 | break; |
| 1951 | } |
| 1952 | break; |
| 1953 | case FSF_GOOD: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1954 | atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1955 | break; |
| 1956 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /** |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1960 | * zfcp_fsf_close_LUN - close LUN |
| 1961 | * @erp_action: pointer to erp_action triggering the "close LUN" |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1962 | * Returns: 0 on success, error otherwise |
| 1963 | */ |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1964 | int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1965 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1966 | struct zfcp_qdio *qdio = erp_action->adapter->qdio; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1967 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1968 | struct zfcp_fsf_req *req; |
| 1969 | int retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 1971 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 1972 | if (zfcp_qdio_sbal_get(qdio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | goto out; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1974 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1975 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 1976 | SBAL_SFLAGS0_TYPE_READ, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 1977 | qdio->adapter->pool.erp_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1978 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 1979 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1980 | retval = PTR_ERR(req); |
| 1981 | goto out; |
| 1982 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 1984 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 1985 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1987 | req->qtcb->header.port_handle = erp_action->port->handle; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 1988 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
| 1989 | req->handler = zfcp_fsf_close_lun_handler; |
| 1990 | req->data = erp_action->sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1991 | req->erp_action = erp_action; |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1992 | erp_action->fsf_req_id = req->req_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1994 | zfcp_fsf_start_erp_timer(req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1995 | retval = zfcp_fsf_req_send(req); |
| 1996 | if (retval) { |
| 1997 | zfcp_fsf_req_free(req); |
Christof Schmitt | e60a6d6 | 2010-02-17 11:18:49 +0100 | [diff] [blame] | 1998 | erp_action->fsf_req_id = 0; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 1999 | } |
| 2000 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 2001 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2002 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2005 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
| 2006 | { |
| 2007 | lat_rec->sum += lat; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2008 | lat_rec->min = min(lat_rec->min, lat); |
| 2009 | lat_rec->max = max(lat_rec->max, lat); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2012 | static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi) |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2013 | { |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2014 | struct fsf_qual_latency_info *lat_in; |
| 2015 | struct latency_cont *lat = NULL; |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 2016 | struct zfcp_scsi_dev *zfcp_sdev; |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2017 | struct zfcp_blk_drv_data blktrc; |
| 2018 | int ticks = req->adapter->timer_ticks; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2019 | |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2020 | lat_in = &req->qtcb->prefix.prot_status_qual.latency_info; |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2021 | |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2022 | blktrc.flags = 0; |
| 2023 | blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC; |
| 2024 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
| 2025 | blktrc.flags |= ZFCP_BLK_REQ_ERROR; |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 2026 | blktrc.inb_usage = 0; |
Christof Schmitt | 34c2b71 | 2010-02-17 11:18:59 +0100 | [diff] [blame] | 2027 | blktrc.outb_usage = req->qdio_req.qdio_outb_usage; |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2028 | |
Christof Schmitt | 5bbf297 | 2010-04-01 13:04:08 +0200 | [diff] [blame] | 2029 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA && |
| 2030 | !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 2031 | zfcp_sdev = sdev_to_zfcp(scsi->device); |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2032 | blktrc.flags |= ZFCP_BLK_LAT_VALID; |
| 2033 | blktrc.channel_lat = lat_in->channel_lat * ticks; |
| 2034 | blktrc.fabric_lat = lat_in->fabric_lat * ticks; |
| 2035 | |
| 2036 | switch (req->qtcb->bottom.io.data_direction) { |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2037 | case FSF_DATADIR_DIF_READ_STRIP: |
| 2038 | case FSF_DATADIR_DIF_READ_CONVERT: |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2039 | case FSF_DATADIR_READ: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2040 | lat = &zfcp_sdev->latencies.read; |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2041 | break; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2042 | case FSF_DATADIR_DIF_WRITE_INSERT: |
| 2043 | case FSF_DATADIR_DIF_WRITE_CONVERT: |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2044 | case FSF_DATADIR_WRITE: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2045 | lat = &zfcp_sdev->latencies.write; |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2046 | break; |
| 2047 | case FSF_DATADIR_CMND: |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2048 | lat = &zfcp_sdev->latencies.cmd; |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | if (lat) { |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2053 | spin_lock(&zfcp_sdev->latencies.lock); |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2054 | zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat); |
| 2055 | zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat); |
| 2056 | lat->counter++; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2057 | spin_unlock(&zfcp_sdev->latencies.lock); |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2058 | } |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
Christof Schmitt | d9742b4 | 2009-11-24 16:54:03 +0100 | [diff] [blame] | 2061 | blk_add_driver_data(scsi->request->q, scsi->request, &blktrc, |
| 2062 | sizeof(blktrc)); |
Christof Schmitt | c961585 | 2008-05-06 11:00:05 +0200 | [diff] [blame] | 2063 | } |
| 2064 | |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2065 | /** |
| 2066 | * zfcp_fsf_fcp_handler_common() - FCP response handler common to I/O and TMF. |
| 2067 | * @req: Pointer to FSF request. |
| 2068 | * @sdev: Pointer to SCSI device as request context. |
| 2069 | */ |
| 2070 | static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req, |
| 2071 | struct scsi_device *sdev) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2072 | { |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 2073 | struct zfcp_scsi_dev *zfcp_sdev; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2074 | struct fsf_qtcb_header *header = &req->qtcb->header; |
| 2075 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2076 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2077 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2078 | |
Martin Peschke | d436de8 | 2012-09-04 15:23:36 +0200 | [diff] [blame] | 2079 | zfcp_sdev = sdev_to_zfcp(sdev); |
| 2080 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2081 | switch (header->fsf_status) { |
| 2082 | case FSF_HANDLE_MISMATCH: |
| 2083 | case FSF_PORT_HANDLE_NOT_VALID: |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2084 | zfcp_erp_adapter_reopen(req->adapter, 0, "fssfch1"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2085 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2086 | break; |
| 2087 | case FSF_FCPLUN_NOT_VALID: |
| 2088 | case FSF_LUN_HANDLE_NOT_VALID: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 2089 | zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2090 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2091 | break; |
| 2092 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
| 2093 | zfcp_fsf_class_not_supp(req); |
| 2094 | break; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2095 | case FSF_DIRECTION_INDICATOR_NOT_VALID: |
| 2096 | dev_err(&req->adapter->ccw_device->dev, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2097 | "Incorrect direction %d, LUN 0x%016Lx on port " |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 2098 | "0x%016Lx closed\n", |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2099 | req->qtcb->bottom.io.data_direction, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2100 | (unsigned long long)zfcp_scsi_dev_lun(sdev), |
| 2101 | (unsigned long long)zfcp_sdev->port->wwpn); |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2102 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch3"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2103 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2104 | break; |
| 2105 | case FSF_CMND_LENGTH_NOT_VALID: |
| 2106 | dev_err(&req->adapter->ccw_device->dev, |
Steffen Maier | 96f4a86 | 2018-11-08 15:44:47 +0100 | [diff] [blame] | 2107 | "Incorrect FCP_CMND length %d, FCP device closed\n", |
| 2108 | req->qtcb->bottom.io.fcp_cmnd_length); |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2109 | zfcp_erp_adapter_shutdown(req->adapter, 0, "fssfch4"); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2110 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2111 | break; |
| 2112 | case FSF_PORT_BOXED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 2113 | zfcp_erp_set_port_status(zfcp_sdev->port, |
| 2114 | ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 2115 | zfcp_erp_port_reopen(zfcp_sdev->port, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 2116 | ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 2117 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2118 | break; |
| 2119 | case FSF_LUN_BOXED: |
Swen Schillig | edaed85 | 2010-09-08 14:40:01 +0200 | [diff] [blame] | 2120 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED); |
| 2121 | zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 2122 | "fssfch6"); |
Christof Schmitt | 4c571c6 | 2009-11-24 16:54:15 +0100 | [diff] [blame] | 2123 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2124 | break; |
| 2125 | case FSF_ADAPTER_STATUS_AVAILABLE: |
| 2126 | if (header->fsf_status_qual.word[0] == |
| 2127 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2128 | zfcp_fc_test_link(zfcp_sdev->port); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2129 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
| 2130 | break; |
| 2131 | } |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req) |
| 2135 | { |
| 2136 | struct scsi_cmnd *scpnt; |
| 2137 | struct fcp_resp_with_ext *fcp_rsp; |
| 2138 | unsigned long flags; |
| 2139 | |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2140 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
| 2141 | |
| 2142 | scpnt = req->data; |
| 2143 | if (unlikely(!scpnt)) { |
| 2144 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
| 2145 | return; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2146 | } |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2147 | |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2148 | zfcp_fsf_fcp_handler_common(req, scpnt->device); |
Swen Schillig | 5bfb2c3 | 2010-11-17 14:23:40 +0100 | [diff] [blame] | 2149 | |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2150 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
| 2151 | set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED); |
| 2152 | goto skip_fsfstatus; |
| 2153 | } |
| 2154 | |
| 2155 | switch (req->qtcb->header.fsf_status) { |
| 2156 | case FSF_INCONSISTENT_PROT_DATA: |
| 2157 | case FSF_INVALID_PROT_PARM: |
| 2158 | set_host_byte(scpnt, DID_ERROR); |
| 2159 | goto skip_fsfstatus; |
| 2160 | case FSF_BLOCK_GUARD_CHECK_FAILURE: |
| 2161 | zfcp_scsi_dif_sense_error(scpnt, 0x1); |
| 2162 | goto skip_fsfstatus; |
| 2163 | case FSF_APP_TAG_CHECK_FAILURE: |
| 2164 | zfcp_scsi_dif_sense_error(scpnt, 0x2); |
| 2165 | goto skip_fsfstatus; |
| 2166 | case FSF_REF_TAG_CHECK_FAILURE: |
| 2167 | zfcp_scsi_dif_sense_error(scpnt, 0x3); |
| 2168 | goto skip_fsfstatus; |
| 2169 | } |
Steffen Maier | df00d7b | 2017-07-28 12:31:01 +0200 | [diff] [blame] | 2170 | BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE); |
| 2171 | fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu; |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2172 | zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt); |
| 2173 | |
| 2174 | skip_fsfstatus: |
| 2175 | zfcp_fsf_req_trace(req, scpnt); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 2176 | zfcp_dbf_scsi_result(scpnt, req); |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2177 | |
| 2178 | scpnt->host_scribble = NULL; |
| 2179 | (scpnt->scsi_done) (scpnt); |
| 2180 | /* |
| 2181 | * We must hold this lock until scsi_done has been called. |
| 2182 | * Otherwise we may call scsi_done after abort regarding this |
| 2183 | * command has completed. |
| 2184 | * Note: scsi_done must not block! |
| 2185 | */ |
| 2186 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2187 | } |
| 2188 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2189 | static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir) |
| 2190 | { |
| 2191 | switch (scsi_get_prot_op(scsi_cmnd)) { |
| 2192 | case SCSI_PROT_NORMAL: |
| 2193 | switch (scsi_cmnd->sc_data_direction) { |
| 2194 | case DMA_NONE: |
| 2195 | *data_dir = FSF_DATADIR_CMND; |
| 2196 | break; |
| 2197 | case DMA_FROM_DEVICE: |
| 2198 | *data_dir = FSF_DATADIR_READ; |
| 2199 | break; |
| 2200 | case DMA_TO_DEVICE: |
| 2201 | *data_dir = FSF_DATADIR_WRITE; |
| 2202 | break; |
| 2203 | case DMA_BIDIRECTIONAL: |
| 2204 | return -EINVAL; |
| 2205 | } |
| 2206 | break; |
| 2207 | |
| 2208 | case SCSI_PROT_READ_STRIP: |
| 2209 | *data_dir = FSF_DATADIR_DIF_READ_STRIP; |
| 2210 | break; |
| 2211 | case SCSI_PROT_WRITE_INSERT: |
| 2212 | *data_dir = FSF_DATADIR_DIF_WRITE_INSERT; |
| 2213 | break; |
| 2214 | case SCSI_PROT_READ_PASS: |
| 2215 | *data_dir = FSF_DATADIR_DIF_READ_CONVERT; |
| 2216 | break; |
| 2217 | case SCSI_PROT_WRITE_PASS: |
| 2218 | *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT; |
| 2219 | break; |
| 2220 | default: |
| 2221 | return -EINVAL; |
| 2222 | } |
| 2223 | |
| 2224 | return 0; |
| 2225 | } |
| 2226 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2227 | /** |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2228 | * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2229 | * @scsi_cmnd: scsi command to be sent |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2230 | */ |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2231 | int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2232 | { |
| 2233 | struct zfcp_fsf_req *req; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 2234 | struct fcp_cmnd *fcp_cmnd; |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 2235 | u8 sbtype = SBAL_SFLAGS0_TYPE_READ; |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 2236 | int retval = -EIO; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2237 | struct scsi_device *sdev = scsi_cmnd->device; |
| 2238 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
| 2239 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2240 | struct zfcp_qdio *qdio = adapter->qdio; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2241 | struct fsf_qtcb_bottom_io *io; |
Christof Schmitt | e55f875 | 2010-11-18 14:53:18 +0100 | [diff] [blame] | 2242 | unsigned long flags; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2243 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2244 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2245 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2246 | return -EBUSY; |
| 2247 | |
Christof Schmitt | e55f875 | 2010-11-18 14:53:18 +0100 | [diff] [blame] | 2248 | spin_lock_irqsave(&qdio->req_q_lock, flags); |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 2249 | if (atomic_read(&qdio->req_q_free) <= 0) { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2250 | atomic_inc(&qdio->req_q_full); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2251 | goto out; |
Christof Schmitt | 8fdf30d | 2009-03-02 13:09:01 +0100 | [diff] [blame] | 2252 | } |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 2253 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 2254 | if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE) |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 2255 | sbtype = SBAL_SFLAGS0_TYPE_WRITE; |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 2256 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2257 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND, |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 2258 | sbtype, adapter->pool.scsi_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 2259 | |
Hirofumi Nakagawa | 025270f | 2008-08-21 13:43:37 +0200 | [diff] [blame] | 2260 | if (IS_ERR(req)) { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2261 | retval = PTR_ERR(req); |
| 2262 | goto out; |
| 2263 | } |
| 2264 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2265 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; |
| 2266 | |
| 2267 | io = &req->qtcb->bottom.io; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 2268 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2269 | req->data = scsi_cmnd; |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2270 | req->handler = zfcp_fsf_fcp_cmnd_handler; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2271 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
| 2272 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2273 | io->service_class = FSF_CLASS_3; |
| 2274 | io->fcp_cmnd_length = FCP_CMND_LEN; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2275 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2276 | if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) { |
| 2277 | io->data_block_length = scsi_cmnd->device->sector_size; |
| 2278 | io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2279 | } |
| 2280 | |
Steffen Maier | cc405ac | 2011-08-15 14:40:30 +0200 | [diff] [blame] | 2281 | if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction)) |
| 2282 | goto failed_scsi_cmnd; |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2283 | |
Steffen Maier | df00d7b | 2017-07-28 12:31:01 +0200 | [diff] [blame] | 2284 | BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE); |
| 2285 | fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu; |
Steffen Maier | e0116c9 | 2018-05-17 19:14:52 +0200 | [diff] [blame] | 2286 | zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2287 | |
Steffen Maier | 71b8e45 | 2017-07-28 12:30:51 +0200 | [diff] [blame] | 2288 | if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) && |
| 2289 | scsi_prot_sg_count(scsi_cmnd)) { |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2290 | zfcp_qdio_set_data_div(qdio, &req->qdio_req, |
| 2291 | scsi_prot_sg_count(scsi_cmnd)); |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 2292 | retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, |
| 2293 | scsi_prot_sglist(scsi_cmnd)); |
| 2294 | if (retval) |
| 2295 | goto failed_scsi_cmnd; |
| 2296 | io->prot_data_length = zfcp_qdio_real_bytes( |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2297 | scsi_prot_sglist(scsi_cmnd)); |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 2300 | retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, |
| 2301 | scsi_sglist(scsi_cmnd)); |
| 2302 | if (unlikely(retval)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2303 | goto failed_scsi_cmnd; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2304 | |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2305 | zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req); |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 2306 | if (zfcp_adapter_multi_buffer_active(adapter)) |
| 2307 | zfcp_qdio_set_scount(qdio, &req->qdio_req); |
Felix Beck | ef3eb71 | 2010-07-16 15:37:42 +0200 | [diff] [blame] | 2308 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2309 | retval = zfcp_fsf_req_send(req); |
| 2310 | if (unlikely(retval)) |
| 2311 | goto failed_scsi_cmnd; |
| 2312 | |
| 2313 | goto out; |
| 2314 | |
| 2315 | failed_scsi_cmnd: |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2316 | zfcp_fsf_req_free(req); |
| 2317 | scsi_cmnd->host_scribble = NULL; |
| 2318 | out: |
Christof Schmitt | e55f875 | 2010-11-18 14:53:18 +0100 | [diff] [blame] | 2319 | spin_unlock_irqrestore(&qdio->req_q_lock, flags); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2320 | return retval; |
| 2321 | } |
| 2322 | |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2323 | static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req) |
| 2324 | { |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2325 | struct scsi_device *sdev = req->data; |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2326 | struct fcp_resp_with_ext *fcp_rsp; |
| 2327 | struct fcp_resp_rsp_info *rsp_info; |
| 2328 | |
Steffen Maier | 266883f | 2018-05-17 19:14:51 +0200 | [diff] [blame] | 2329 | zfcp_fsf_fcp_handler_common(req, sdev); |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2330 | |
Steffen Maier | df00d7b | 2017-07-28 12:31:01 +0200 | [diff] [blame] | 2331 | fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu; |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2332 | rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; |
| 2333 | |
| 2334 | if ((rsp_info->rsp_code != FCP_TMF_CMPL) || |
| 2335 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
| 2336 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
| 2337 | } |
| 2338 | |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2339 | /** |
Steffen Maier | 26f5fa9 | 2018-05-17 19:14:54 +0200 | [diff] [blame] | 2340 | * zfcp_fsf_fcp_task_mgmt() - Send SCSI task management command (TMF). |
| 2341 | * @sdev: Pointer to SCSI device to send the task management command to. |
| 2342 | * @tm_flags: Unsigned byte for task management flags. |
| 2343 | * |
| 2344 | * Return: On success pointer to struct zfcp_fsf_req, %NULL otherwise. |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2345 | */ |
Steffen Maier | 26f5fa9 | 2018-05-17 19:14:54 +0200 | [diff] [blame] | 2346 | struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_device *sdev, |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2347 | u8 tm_flags) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2348 | { |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2349 | struct zfcp_fsf_req *req = NULL; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 2350 | struct fcp_cmnd *fcp_cmnd; |
Steffen Maier | 39abb11 | 2018-05-17 19:14:53 +0200 | [diff] [blame] | 2351 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2352 | struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2353 | |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2354 | if (unlikely(!(atomic_read(&zfcp_sdev->status) & |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2355 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
| 2356 | return NULL; |
| 2357 | |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 2358 | spin_lock_irq(&qdio->req_q_lock); |
Christof Schmitt | 6b9e152 | 2010-04-30 18:09:35 +0200 | [diff] [blame] | 2359 | if (zfcp_qdio_sbal_get(qdio)) |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2360 | goto out; |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 2361 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2362 | req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND, |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 2363 | SBAL_SFLAGS0_TYPE_WRITE, |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2364 | qdio->adapter->pool.scsi_req); |
Swen Schillig | 09a46c6 | 2009-08-18 15:43:16 +0200 | [diff] [blame] | 2365 | |
Swen Schillig | 633528c | 2008-11-26 18:07:37 +0100 | [diff] [blame] | 2366 | if (IS_ERR(req)) { |
| 2367 | req = NULL; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2368 | goto out; |
Swen Schillig | 633528c | 2008-11-26 18:07:37 +0100 | [diff] [blame] | 2369 | } |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2370 | |
Steffen Maier | 39abb11 | 2018-05-17 19:14:53 +0200 | [diff] [blame] | 2371 | req->data = sdev; |
| 2372 | |
Christof Schmitt | c61b536 | 2010-09-08 14:39:58 +0200 | [diff] [blame] | 2373 | req->handler = zfcp_fsf_fcp_task_mgmt_handler; |
Christof Schmitt | b62a8d9 | 2010-09-08 14:39:55 +0200 | [diff] [blame] | 2374 | req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; |
| 2375 | req->qtcb->header.port_handle = zfcp_sdev->port->handle; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2376 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
| 2377 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 2378 | req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN; |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2379 | |
Christof Schmitt | 1674b40 | 2010-04-30 18:09:34 +0200 | [diff] [blame] | 2380 | zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2381 | |
Steffen Maier | df00d7b | 2017-07-28 12:31:01 +0200 | [diff] [blame] | 2382 | fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu; |
Steffen Maier | 39abb11 | 2018-05-17 19:14:53 +0200 | [diff] [blame] | 2383 | zfcp_fc_fcp_tm(fcp_cmnd, sdev, tm_flags); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2384 | |
| 2385 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
| 2386 | if (!zfcp_fsf_req_send(req)) |
| 2387 | goto out; |
| 2388 | |
| 2389 | zfcp_fsf_req_free(req); |
| 2390 | req = NULL; |
| 2391 | out: |
Christof Schmitt | 44a24cb | 2010-09-08 14:39:57 +0200 | [diff] [blame] | 2392 | spin_unlock_irq(&qdio->req_q_lock); |
Swen Schillig | c41f8cb | 2008-07-02 10:56:39 +0200 | [diff] [blame] | 2393 | return req; |
| 2394 | } |
| 2395 | |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2396 | /** |
| 2397 | * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO |
| 2398 | * @adapter: pointer to struct zfcp_adapter |
| 2399 | * @sbal_idx: response queue index of SBAL to be processed |
| 2400 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2401 | void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx) |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2402 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 2403 | struct zfcp_adapter *adapter = qdio->adapter; |
Swen Schillig | 706eca4 | 2010-07-16 15:37:38 +0200 | [diff] [blame] | 2404 | struct qdio_buffer *sbal = qdio->res_q[sbal_idx]; |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2405 | struct qdio_buffer_element *sbale; |
| 2406 | struct zfcp_fsf_req *fsf_req; |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 2407 | unsigned long req_id; |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2408 | int idx; |
| 2409 | |
| 2410 | for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) { |
| 2411 | |
| 2412 | sbale = &sbal->element[idx]; |
| 2413 | req_id = (unsigned long) sbale->addr; |
Christof Schmitt | b6bd2fb | 2010-02-17 11:18:50 +0100 | [diff] [blame] | 2414 | fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id); |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2415 | |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 2416 | if (!fsf_req) { |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2417 | /* |
| 2418 | * Unknown request means that we have potentially memory |
| 2419 | * corruption and must stop the machine immediately. |
| 2420 | */ |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 2421 | zfcp_qdio_siosl(adapter); |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2422 | panic("error: unknown req_id (%lx) on adapter %s.\n", |
| 2423 | req_id, dev_name(&adapter->ccw_device->dev)); |
Christof Schmitt | 339f4f4 | 2010-07-16 15:37:43 +0200 | [diff] [blame] | 2424 | } |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2425 | |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2426 | zfcp_fsf_req_complete(fsf_req); |
| 2427 | |
Jan Glauber | 3ec90878 | 2011-06-06 14:14:40 +0200 | [diff] [blame] | 2428 | if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY)) |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 2429 | break; |
| 2430 | } |
| 2431 | } |