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