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