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