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