blob: b9a16e4b48b4859ba8446c7398f5f444b02e227b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Stefan Raspl0997f1c2008-10-16 08:23:39 +020012#include <linux/blktrace_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "zfcp_ext.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020014#include "zfcp_dbf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Christof Schmitt287ac012008-07-02 10:56:40 +020016static void zfcp_fsf_request_timeout_handler(unsigned long data)
17{
18 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010019 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
20 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020021}
22
23static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
24 unsigned long timeout)
25{
26 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
27 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
28 fsf_req->timer.expires = jiffies + timeout;
29 add_timer(&fsf_req->timer);
30}
31
32static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
33{
34 BUG_ON(!fsf_req->erp_action);
35 fsf_req->timer.function = zfcp_erp_timeout_handler;
36 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
37 fsf_req->timer.expires = jiffies + 30 * HZ;
38 add_timer(&fsf_req->timer);
39}
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/* association between FSF command and FSF QTCB type */
42static u32 fsf_qtcb_type[] = {
43 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
44 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
45 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
46 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
53 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
54 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
56};
57
Christof Schmitt553448f2008-06-10 18:20:58 +020058static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
59{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020060 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020061 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020062 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020063
Christof Schmittff3b24f2008-10-01 12:42:15 +020064 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020065 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020066 "Access denied according to ACT rule type %s, "
67 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020068}
69
70static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
71 struct zfcp_port *port)
72{
73 struct fsf_qtcb_header *header = &req->qtcb->header;
74 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020075 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020076 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020077 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
78 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010079 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020080 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
81}
82
83static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
84 struct zfcp_unit *unit)
85{
86 struct fsf_qtcb_header *header = &req->qtcb->header;
87 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020088 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020089 (unsigned long long)unit->fcp_lun,
90 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020091 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
92 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010093 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020094 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
95}
96
97static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
98{
Christof Schmittff3b24f2008-10-01 12:42:15 +020099 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
100 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100101 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200102 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
103}
104
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200105/**
106 * zfcp_fsf_req_free - free memory used by fsf request
107 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200109void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200111 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200112 if (likely(req->qtcb))
113 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200115 return;
116 }
117
Swen Schilliga4623c42009-08-18 15:43:15 +0200118 if (likely(req->qtcb))
119 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
120 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200123static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200125 struct fsf_status_read_buffer *sr_buf = req->data;
126 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 struct zfcp_port *port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200128 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 unsigned long flags;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 read_lock_irqsave(&zfcp_data.config_lock, flags);
132 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200133 if (port->d_id == d_id) {
134 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100135 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200136 return;
137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100141static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200142 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200144 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt70932932009-04-17 15:08:15 +0200145 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200147 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
148 return;
149
150 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200151
152 read_lock_irqsave(&zfcp_data.config_lock, flags);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100153 zfcp_scsi_schedule_rports_block(adapter);
Christof Schmitt70932932009-04-17 15:08:15 +0200154 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200155
156 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200158
159 switch (link_down->error_code) {
160 case FSF_PSQ_LINK_NO_LIGHT:
161 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200162 "There is no light signal from the local "
163 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200164 break;
165 case FSF_PSQ_LINK_WRAP_PLUG:
166 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200167 "There is a wrap plug instead of a fibre "
168 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200169 break;
170 case FSF_PSQ_LINK_NO_FCP:
171 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200172 "The adjacent fibre channel node does not "
173 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200174 break;
175 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
176 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200177 "The FCP device is suspended because of a "
178 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200179 break;
180 case FSF_PSQ_LINK_INVALID_WWPN:
181 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200182 "The FCP device detected a WWPN that is "
183 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200184 break;
185 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
186 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200187 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200188 break;
189 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
190 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200191 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200192 break;
193 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
194 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200195 "The adjacent switch cannot support "
196 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200197 break;
198 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
199 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200200 "The FCP adapter could not log in to the "
201 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200202 break;
203 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
204 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200205 "The WWPN assignment file on the FCP adapter "
206 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200207 break;
208 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
209 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200210 "The mode table on the FCP adapter "
211 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200212 break;
213 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
214 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200215 "All NPIV ports on the FCP adapter have "
216 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200217 break;
218 default:
219 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200220 "The link between the FCP adapter and "
221 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200222 }
223out:
224 zfcp_erp_adapter_failed(adapter, id, req);
225}
226
227static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
228{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200229 struct fsf_status_read_buffer *sr_buf = req->data;
230 struct fsf_link_down_info *ldi =
231 (struct fsf_link_down_info *) &sr_buf->payload;
232
233 switch (sr_buf->status_subtype) {
234 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100235 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200236 break;
237 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100238 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200239 break;
240 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100241 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200242 };
243}
244
245static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
246{
247 struct zfcp_adapter *adapter = req->adapter;
248 struct fsf_status_read_buffer *sr_buf = req->data;
249
250 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
251 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200252 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200253 zfcp_fsf_req_free(req);
254 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200257 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200258
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200261 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200264 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200269 dev_warn(&adapter->ccw_device->dev,
270 "The error threshold for checksum statistics "
271 "has been exceeded\n");
Swen Schillig57069382008-10-01 12:42:21 +0200272 zfcp_hba_dbf_event_berr(adapter, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200275 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200278 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200279 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100281 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 ZFCP_STATUS_COMMON_RUNNING,
283 ZFCP_SET);
284 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200285 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
286 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100287 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100289 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200290 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100291 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
292 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200293 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200294 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100297 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200299 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200300 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200301 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200303
Swen Schilliga4623c42009-08-18 15:43:15 +0200304 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200305 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200306
307 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200308 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200311static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313 switch (req->qtcb->header.fsf_status_qual.word[0]) {
314 case FSF_SQ_FCP_RSP_AVAILABLE:
315 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
316 case FSF_SQ_NO_RETRY_POSSIBLE:
317 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
318 return;
319 case FSF_SQ_COMMAND_ABORTED:
320 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
321 break;
322 case FSF_SQ_NO_RECOM:
323 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200324 "The FCP adapter reported a problem "
325 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100326 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200329 /* all non-return stats set FSFREQ_ERROR*/
330 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
331}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200333static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
334{
335 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
336 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200337
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200338 switch (req->qtcb->header.fsf_status) {
339 case FSF_UNKNOWN_COMMAND:
340 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200341 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100343 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200344 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354 struct zfcp_adapter *adapter = req->adapter;
355 struct fsf_qtcb *qtcb = req->qtcb;
356 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200358 zfcp_hba_dbf_event_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
361 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
362 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
363 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 }
365
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200366 switch (qtcb->prefix.prot_status) {
367 case FSF_PROT_GOOD:
368 case FSF_PROT_FSF_STATUS_PRESENTED:
369 return;
370 case FSF_PROT_QTCB_VERSION_ERROR:
371 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200372 "QTCB version 0x%x not supported by FCP adapter "
373 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
374 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100375 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200377 case FSF_PROT_ERROR_STATE:
378 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100379 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200380 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200382 case FSF_PROT_UNSUPP_QTCB_TYPE:
383 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200384 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100385 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200387 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
388 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
389 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200391 case FSF_PROT_DUPLICATE_REQUEST_ID:
392 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200393 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200394 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100395 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200397 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100398 zfcp_fsf_link_down_info_eval(req, "fspse_5",
399 &psq->link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200400 /* FIXME: reopening adapter now? better wait for link up */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100401 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403 case FSF_PROT_REEST_QUEUE:
404 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100405 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200406 ZFCP_STATUS_COMMON_RUNNING,
407 ZFCP_SET);
408 zfcp_erp_adapter_reopen(adapter,
409 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100410 ZFCP_STATUS_COMMON_ERP_FAILED,
411 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200412 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200414 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200415 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100417 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200419 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200423 * zfcp_fsf_req_complete - process completion of a FSF request
424 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200426 * When a request has been completed either from the FCP adapter,
427 * or it has been dismissed due to a queue shutdown, this function
428 * is called to process the completion status and trigger further
429 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200431static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200432{
433 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
434 zfcp_fsf_status_read_handler(req);
435 return;
436 }
437
438 del_timer(&req->timer);
439 zfcp_fsf_protstatus_eval(req);
440 zfcp_fsf_fsfstatus_eval(req);
441 req->handler(req);
442
443 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200444 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200445
446 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
447 zfcp_fsf_req_free(req);
448 else
Swen Schillig058b8642009-08-18 15:43:14 +0200449 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200450}
451
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200452/**
453 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
454 * @adapter: pointer to struct zfcp_adapter
455 *
456 * Never ever call this without shutting down the adapter first.
457 * Otherwise the adapter would continue using and corrupting s390 storage.
458 * Included BUG_ON() call to ensure this is done.
459 * ERP is supposed to be the only user of this function.
460 */
461void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
462{
463 struct zfcp_fsf_req *req, *tmp;
464 unsigned long flags;
465 LIST_HEAD(remove_queue);
466 unsigned int i;
467
468 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
469 spin_lock_irqsave(&adapter->req_list_lock, flags);
470 for (i = 0; i < REQUEST_LIST_SIZE; i++)
471 list_splice_init(&adapter->req_list[i], &remove_queue);
472 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
473
474 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
475 list_del(&req->list);
476 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_fsf_req_complete(req);
478 }
479}
480
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200481static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
483 struct fsf_qtcb_bottom_config *bottom;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200484 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200485 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200487 bottom = &req->qtcb->bottom.config;
488
489 if (req->data)
490 memcpy(req->data, bottom, sizeof(*bottom));
491
492 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
493 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
494 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
495 fc_host_speed(shost) = bottom->fc_link_speed;
496 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
497
498 adapter->hydra_version = bottom->adapter_type;
499 adapter->timer_ticks = bottom->timer_interval;
500
501 if (fc_host_permanent_port_name(shost) == -1)
502 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
503
504 switch (bottom->fc_topology) {
505 case FSF_TOPO_P2P:
506 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
507 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
508 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
509 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200510 break;
511 case FSF_TOPO_FABRIC:
512 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 break;
514 case FSF_TOPO_AL:
515 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200516 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200518 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200519 "Unknown or unsupported arbitrated loop "
520 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100521 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 return -EIO;
523 }
524
525 return 0;
526}
527
528static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
529{
530 struct zfcp_adapter *adapter = req->adapter;
531 struct fsf_qtcb *qtcb = req->qtcb;
532 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
533 struct Scsi_Host *shost = adapter->scsi_host;
534
535 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
536 return;
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200539 adapter->adapter_features = bottom->adapter_features;
540 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500541 adapter->peer_wwpn = 0;
542 adapter->peer_wwnn = 0;
543 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200545 switch (qtcb->header.fsf_status) {
546 case FSF_GOOD:
547 if (zfcp_fsf_exchange_config_evaluate(req))
548 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200549
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200550 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
551 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200552 "FCP adapter maximum QTCB size (%d bytes) "
553 "is too small\n",
554 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100555 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200556 return;
557 }
558 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
559 &adapter->status);
560 break;
561 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200562 fc_host_node_name(shost) = 0;
563 fc_host_port_name(shost) = 0;
564 fc_host_port_id(shost) = 0;
565 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100566 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200568
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
570 &adapter->status);
571
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100572 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200573 &qtcb->header.fsf_status_qual.link_down_info);
574 break;
575 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100576 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200577 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200580 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200582 memcpy(fc_host_serial_number(shost), bottom->serial_number,
583 min(FC_SERIAL_NUMBER_SIZE, 17));
584 EBCASC(fc_host_serial_number(shost),
585 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200588 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200589 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200590 "The FCP adapter only supports newer "
591 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100592 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200593 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200595 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200596 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200597 "The FCP adapter only supports older "
598 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100599 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200605 struct zfcp_adapter *adapter = req->adapter;
606 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
607 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200609 if (req->data)
610 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100611
Christof Schmitt02829852009-03-02 13:09:06 +0100612 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100613 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100614 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
615 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100616 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
617 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
618 fc_host_supported_speeds(shost) = bottom->supported_speed;
619}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200621static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200623 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100624
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200625 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return;
627
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200628 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200629 case FSF_GOOD:
630 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200632 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100634 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200635 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638}
639
Swen Schillig564e1c82009-08-18 15:43:19 +0200640static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641{
Swen Schillig564e1c82009-08-18 15:43:19 +0200642 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200643
Swen Schillig564e1c82009-08-18 15:43:19 +0200644 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200645 if (atomic_read(&req_q->count))
646 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200647 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200648 return 0;
649}
650
Swen Schillig564e1c82009-08-18 15:43:19 +0200651static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200652{
Swen Schillig564e1c82009-08-18 15:43:19 +0200653 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200654 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200655
Swen Schillig564e1c82009-08-18 15:43:19 +0200656 spin_unlock_bh(&qdio->req_q_lock);
657 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
658 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200659 if (ret > 0)
660 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200661 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200662 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200663 /* assume hanging outbound queue, try queue recovery */
664 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
665 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200666
Swen Schillig564e1c82009-08-18 15:43:19 +0200667 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200668 return -EIO;
669}
670
Swen Schilliga4623c42009-08-18 15:43:15 +0200671static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200672{
673 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200674
675 if (likely(pool))
676 req = mempool_alloc(pool, GFP_ATOMIC);
677 else
678 req = kmalloc(sizeof(*req), GFP_ATOMIC);
679
680 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200681 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200682
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200683 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100684 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200685 return req;
686}
687
Swen Schilliga4623c42009-08-18 15:43:15 +0200688static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200689{
Swen Schilliga4623c42009-08-18 15:43:15 +0200690 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200691
692 if (likely(pool))
693 qtcb = mempool_alloc(pool, GFP_ATOMIC);
694 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200695 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
696
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200697 if (unlikely(!qtcb))
698 return NULL;
699
700 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200701 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200702}
703
Swen Schillig564e1c82009-08-18 15:43:19 +0200704static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Swen Schillig09a46c62009-08-18 15:43:16 +0200705 u32 fsf_cmd, mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200707 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +0200708 struct zfcp_qdio_queue *req_q = &qdio->req_q;
709 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200710 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200711
712 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200713 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200714
715 if (adapter->req_no == 0)
716 adapter->req_no++;
717
718 INIT_LIST_HEAD(&req->list);
719 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200720 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200721
722 req->adapter = adapter;
723 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100724 req->req_id = adapter->req_no;
Swen Schillig42428f72009-08-18 15:43:18 +0200725 req->queue_req.sbal_number = 1;
726 req->queue_req.sbal_first = req_q->first;
727 req->queue_req.sbal_last = req_q->first;
728 req->queue_req.sbale_curr = 1;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200729
Swen Schillig564e1c82009-08-18 15:43:19 +0200730 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200731 sbale[0].addr = (void *) req->req_id;
732 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
733
Swen Schilliga4623c42009-08-18 15:43:15 +0200734 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
735 if (likely(pool))
736 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
737 else
738 req->qtcb = zfcp_qtcb_alloc(NULL);
739
740 if (unlikely(!req->qtcb)) {
741 zfcp_fsf_req_free(req);
742 return ERR_PTR(-ENOMEM);
743 }
744
Swen Schillig564e1c82009-08-18 15:43:19 +0200745 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200746 req->qtcb->prefix.req_id = req->req_id;
747 req->qtcb->prefix.ulp_info = 26;
748 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
749 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
750 req->qtcb->header.req_handle = req->req_id;
751 req->qtcb->header.fsf_command = req->fsf_command;
752 req->seq_no = adapter->fsf_req_seq_no;
753 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
754 sbale[1].addr = (void *) req->qtcb;
755 sbale[1].length = sizeof(struct fsf_qtcb);
756 }
757
758 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
759 zfcp_fsf_req_free(req);
760 return ERR_PTR(-EIO);
761 }
762
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200763 return req;
764}
765
766static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
767{
768 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200769 struct zfcp_qdio *qdio = adapter->qdio;
Martin Petermann135ea132009-04-17 15:08:01 +0200770 unsigned long flags;
771 int idx;
772 int with_qtcb = (req->qtcb != NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200773
774 /* put allocated FSF request into hash table */
Heiko Carstens45316a82008-11-04 16:35:06 +0100775 spin_lock_irqsave(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200776 idx = zfcp_reqlist_hash(req->req_id);
777 list_add_tail(&req->list, &adapter->req_list[idx]);
Heiko Carstens45316a82008-11-04 16:35:06 +0100778 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200779
Swen Schillig564e1c82009-08-18 15:43:19 +0200780 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 req->issued = get_clock();
Swen Schillig564e1c82009-08-18 15:43:19 +0200782 if (zfcp_qdio_send(qdio, &req->queue_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100784 spin_lock_irqsave(&adapter->req_list_lock, flags);
785 /* lookup request again, list might have changed */
786 if (zfcp_reqlist_find_safe(adapter, req))
787 zfcp_reqlist_remove(adapter, req);
788 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100789 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200790 return -EIO;
791 }
792
793 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200794 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200795 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100796 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200797
798 return 0;
799}
800
801/**
802 * zfcp_fsf_status_read - send status read request
803 * @adapter: pointer to struct zfcp_adapter
804 * @req_flags: request flags
805 * Returns: 0 on success, ERROR otherwise
806 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200807int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200808{
Swen Schillig564e1c82009-08-18 15:43:19 +0200809 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200810 struct zfcp_fsf_req *req;
811 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200812 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200813 int retval = -EIO;
814
Swen Schillig564e1c82009-08-18 15:43:19 +0200815 spin_lock_bh(&qdio->req_q_lock);
816 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Swen Schillig564e1c82009-08-18 15:43:19 +0200819 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200820 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200821 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 goto out;
824 }
825
Swen Schillig564e1c82009-08-18 15:43:19 +0200826 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
Swen Schillig42428f72009-08-18 15:43:18 +0200828 req->queue_req.sbale_curr = 2;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829
Swen Schilliga4623c42009-08-18 15:43:15 +0200830 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200831 if (!sr_buf) {
832 retval = -ENOMEM;
833 goto failed_buf;
834 }
835 memset(sr_buf, 0, sizeof(*sr_buf));
836 req->data = sr_buf;
Swen Schillig564e1c82009-08-18 15:43:19 +0200837 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200838 sbale->addr = (void *) sr_buf;
839 sbale->length = sizeof(*sr_buf);
840
841 retval = zfcp_fsf_req_send(req);
842 if (retval)
843 goto failed_req_send;
844
845 goto out;
846
847failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200848 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200849failed_buf:
850 zfcp_fsf_req_free(req);
851 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
852out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200853 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return retval;
855}
856
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200859 struct zfcp_unit *unit = req->data;
860 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
863 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 switch (req->qtcb->header.fsf_status) {
866 case FSF_PORT_HANDLE_NOT_VALID:
867 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100868 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
869 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 case FSF_LUN_HANDLE_NOT_VALID:
874 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100875 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
880 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100883 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
885 ZFCP_STATUS_FSFREQ_RETRY;
886 break;
887 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100888 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
890 ZFCP_STATUS_FSFREQ_RETRY;
891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200893 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200895 zfcp_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200896 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200898 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 break;
900 }
901 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
904 break;
905 }
906}
907
908/**
909 * zfcp_fsf_abort_fcp_command - abort running SCSI command
910 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200912 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913 */
914
915struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100916 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200917{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200918 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200919 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200920 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921
Swen Schillig564e1c82009-08-18 15:43:19 +0200922 spin_lock_bh(&qdio->req_q_lock);
923 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200925 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
926 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100927 if (IS_ERR(req)) {
928 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200929 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100930 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200931
932 if (unlikely(!(atomic_read(&unit->status) &
933 ZFCP_STATUS_COMMON_UNBLOCKED)))
934 goto out_error_free;
935
Swen Schillig564e1c82009-08-18 15:43:19 +0200936 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200937 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
938 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
939
940 req->data = unit;
941 req->handler = zfcp_fsf_abort_fcp_command_handler;
942 req->qtcb->header.lun_handle = unit->handle;
943 req->qtcb->header.port_handle = unit->port->handle;
944 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
945
946 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
947 if (!zfcp_fsf_req_send(req))
948 goto out;
949
950out_error_free:
951 zfcp_fsf_req_free(req);
952 req = NULL;
953out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200954 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200955 return req;
956}
957
958static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
959{
960 struct zfcp_adapter *adapter = req->adapter;
961 struct zfcp_send_ct *send_ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200962 struct fsf_qtcb_header *header = &req->qtcb->header;
963
964 send_ct->status = -EINVAL;
965
966 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
967 goto skip_fsfstatus;
968
969 switch (header->fsf_status) {
970 case FSF_GOOD:
971 zfcp_san_dbf_event_ct_response(req);
972 send_ct->status = 0;
973 break;
974 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
975 zfcp_fsf_class_not_supp(req);
976 break;
977 case FSF_ADAPTER_STATUS_AVAILABLE:
978 switch (header->fsf_status_qual.word[0]){
979 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200980 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
981 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
982 break;
983 }
984 break;
985 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200986 break;
987 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200988 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
989 ZFCP_STATUS_FSFREQ_RETRY;
990 break;
991 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100992 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200993 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994 case FSF_GENERIC_COMMAND_REJECTED:
995 case FSF_PAYLOAD_SIZE_MISMATCH:
996 case FSF_REQUEST_SIZE_TOO_LARGE:
997 case FSF_RESPONSE_SIZE_TOO_LARGE:
998 case FSF_SBAL_MISMATCH:
999 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1000 break;
1001 }
1002
1003skip_fsfstatus:
1004 if (send_ct->handler)
1005 send_ct->handler(send_ct->handler_data);
1006}
1007
Christof Schmitt426f6052009-07-13 15:06:06 +02001008static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1009 struct scatterlist *sg_req,
1010 struct scatterlist *sg_resp)
1011{
1012 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1013 sbale[2].addr = sg_virt(sg_req);
1014 sbale[2].length = sg_req->length;
1015 sbale[3].addr = sg_virt(sg_resp);
1016 sbale[3].length = sg_resp->length;
1017 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1018}
1019
1020static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1021{
1022 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1023}
1024
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001025static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1026 struct scatterlist *sg_req,
1027 struct scatterlist *sg_resp,
1028 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001029{
Swen Schillig42428f72009-08-18 15:43:18 +02001030 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001031 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
Swen Schillig42428f72009-08-18 15:43:18 +02001032 &req->queue_req);
1033 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001034 int bytes;
1035
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001036 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001037 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001038 return -EOPNOTSUPP;
1039
Christof Schmitt426f6052009-07-13 15:06:06 +02001040 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1041 return 0;
1042 }
1043
1044 /* use single, unchained SBAL if it can hold the request */
1045 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1046 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001047 return 0;
1048 }
1049
Swen Schillig564e1c82009-08-18 15:43:19 +02001050 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001051 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001052 sg_req, max_sbals);
1053 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001054 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001055 req->qtcb->bottom.support.req_buf_length = bytes;
Swen Schillig42428f72009-08-18 15:43:18 +02001056 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001057
Swen Schillig564e1c82009-08-18 15:43:19 +02001058 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001059 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001060 sg_resp, max_sbals);
1061 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001062 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063 req->qtcb->bottom.support.resp_buf_length = bytes;
1064
1065 return 0;
1066}
1067
1068/**
1069 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1070 * @ct: pointer to struct zfcp_send_ct with data for request
1071 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1072 * @erp_action: if non-null the Generic Service request sent within ERP
1073 */
1074int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1075 struct zfcp_erp_action *erp_action)
1076{
Swen Schillig5ab944f2008-10-01 12:42:17 +02001077 struct zfcp_wka_port *wka_port = ct->wka_port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001078 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001079 struct zfcp_fsf_req *req;
1080 int ret = -EIO;
1081
Swen Schillig564e1c82009-08-18 15:43:19 +02001082 spin_lock_bh(&qdio->req_q_lock);
1083 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001084 goto out;
1085
Swen Schillig564e1c82009-08-18 15:43:19 +02001086 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001087
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001088 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001089 ret = PTR_ERR(req);
1090 goto out;
1091 }
1092
Swen Schillig09a46c62009-08-18 15:43:16 +02001093 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001094 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1095 FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001096 if (ret)
1097 goto failed_send;
1098
1099 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001100 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001101 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1102 req->qtcb->bottom.support.timeout = ct->timeout;
1103 req->data = ct;
1104
1105 zfcp_san_dbf_event_ct_request(req);
1106
1107 if (erp_action) {
1108 erp_action->fsf_req = req;
1109 req->erp_action = erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +02001110 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001111 } else
1112 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1113
1114 ret = zfcp_fsf_req_send(req);
1115 if (ret)
1116 goto failed_send;
1117
1118 goto out;
1119
1120failed_send:
1121 zfcp_fsf_req_free(req);
1122 if (erp_action)
1123 erp_action->fsf_req = NULL;
1124out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001125 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001126 return ret;
1127}
1128
1129static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1130{
1131 struct zfcp_send_els *send_els = req->data;
1132 struct zfcp_port *port = send_els->port;
1133 struct fsf_qtcb_header *header = &req->qtcb->header;
1134
1135 send_els->status = -EINVAL;
1136
1137 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1138 goto skip_fsfstatus;
1139
1140 switch (header->fsf_status) {
1141 case FSF_GOOD:
1142 zfcp_san_dbf_event_els_response(req);
1143 send_els->status = 0;
1144 break;
1145 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1146 zfcp_fsf_class_not_supp(req);
1147 break;
1148 case FSF_ADAPTER_STATUS_AVAILABLE:
1149 switch (header->fsf_status_qual.word[0]){
1150 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1151 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1152 zfcp_test_link(port);
1153 /*fall through */
1154 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1155 case FSF_SQ_RETRY_IF_POSSIBLE:
1156 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1157 break;
1158 }
1159 break;
1160 case FSF_ELS_COMMAND_REJECTED:
1161 case FSF_PAYLOAD_SIZE_MISMATCH:
1162 case FSF_REQUEST_SIZE_TOO_LARGE:
1163 case FSF_RESPONSE_SIZE_TOO_LARGE:
1164 break;
1165 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001166 if (port)
1167 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001168 break;
1169 case FSF_SBAL_MISMATCH:
1170 /* should never occure, avoided in zfcp_fsf_send_els */
1171 /* fall through */
1172 default:
1173 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1174 break;
1175 }
1176skip_fsfstatus:
1177 if (send_els->handler)
1178 send_els->handler(send_els->handler_data);
1179}
1180
1181/**
1182 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1183 * @els: pointer to struct zfcp_send_els with data for the command
1184 */
1185int zfcp_fsf_send_els(struct zfcp_send_els *els)
1186{
1187 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001188 struct zfcp_qdio *qdio = els->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 struct fsf_qtcb_bottom_support *bottom;
1190 int ret = -EIO;
1191
Swen Schillig564e1c82009-08-18 15:43:19 +02001192 spin_lock_bh(&qdio->req_q_lock);
1193 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001194 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001195
Swen Schillig564e1c82009-08-18 15:43:19 +02001196 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001197
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001198 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001199 ret = PTR_ERR(req);
1200 goto out;
1201 }
1202
Swen Schillig09a46c62009-08-18 15:43:16 +02001203 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001204 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001205
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 if (ret)
1207 goto failed_send;
1208
1209 bottom = &req->qtcb->bottom.support;
1210 req->handler = zfcp_fsf_send_els_handler;
1211 bottom->d_id = els->d_id;
1212 bottom->service_class = FSF_CLASS_3;
1213 bottom->timeout = 2 * R_A_TOV;
1214 req->data = els;
1215
1216 zfcp_san_dbf_event_els_request(req);
1217
1218 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1219 ret = zfcp_fsf_req_send(req);
1220 if (ret)
1221 goto failed_send;
1222
1223 goto out;
1224
1225failed_send:
1226 zfcp_fsf_req_free(req);
1227out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001228 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001229 return ret;
1230}
1231
1232int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1233{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001234 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001235 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001236 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001237 int retval = -EIO;
1238
Swen Schillig564e1c82009-08-18 15:43:19 +02001239 spin_lock_bh(&qdio->req_q_lock);
1240 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001242
Swen Schillig564e1c82009-08-18 15:43:19 +02001243 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1244 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001245
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001246 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001247 retval = PTR_ERR(req);
1248 goto out;
1249 }
1250
Swen Schillig09a46c62009-08-18 15:43:16 +02001251 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001252 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001253 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1254 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1255
1256 req->qtcb->bottom.config.feature_selection =
1257 FSF_FEATURE_CFDC |
1258 FSF_FEATURE_LUN_SHARING |
1259 FSF_FEATURE_NOTIFICATION_LOST |
1260 FSF_FEATURE_UPDATE_ALERT;
1261 req->erp_action = erp_action;
1262 req->handler = zfcp_fsf_exchange_config_data_handler;
1263 erp_action->fsf_req = req;
1264
Christof Schmitt287ac012008-07-02 10:56:40 +02001265 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001266 retval = zfcp_fsf_req_send(req);
1267 if (retval) {
1268 zfcp_fsf_req_free(req);
1269 erp_action->fsf_req = NULL;
1270 }
1271out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001272 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001273 return retval;
1274}
1275
Swen Schillig564e1c82009-08-18 15:43:19 +02001276int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001277 struct fsf_qtcb_bottom_config *data)
1278{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001279 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001280 struct zfcp_fsf_req *req = NULL;
1281 int retval = -EIO;
1282
Swen Schillig564e1c82009-08-18 15:43:19 +02001283 spin_lock_bh(&qdio->req_q_lock);
1284 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001285 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001286
Swen Schillig564e1c82009-08-18 15:43:19 +02001287 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001288
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001289 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001290 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001291 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001292 }
1293
Swen Schillig564e1c82009-08-18 15:43:19 +02001294 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1296 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1297 req->handler = zfcp_fsf_exchange_config_data_handler;
1298
1299 req->qtcb->bottom.config.feature_selection =
1300 FSF_FEATURE_CFDC |
1301 FSF_FEATURE_LUN_SHARING |
1302 FSF_FEATURE_NOTIFICATION_LOST |
1303 FSF_FEATURE_UPDATE_ALERT;
1304
1305 if (data)
1306 req->data = data;
1307
1308 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1309 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001310 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001311 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001312 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001313
1314 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001315 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001316
Christof Schmittada81b72009-04-17 15:08:03 +02001317out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001318 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319 return retval;
1320}
1321
1322/**
1323 * zfcp_fsf_exchange_port_data - request information about local port
1324 * @erp_action: ERP action for the adapter for which port data is requested
1325 * Returns: 0 on success, error otherwise
1326 */
1327int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1328{
Swen Schillig564e1c82009-08-18 15:43:19 +02001329 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schillig44cc76f2008-10-01 12:42:16 +02001330 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001332 int retval = -EIO;
1333
Swen Schillig564e1c82009-08-18 15:43:19 +02001334 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001335 return -EOPNOTSUPP;
1336
Swen Schillig564e1c82009-08-18 15:43:19 +02001337 spin_lock_bh(&qdio->req_q_lock);
1338 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001339 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001340
Swen Schillig564e1c82009-08-18 15:43:19 +02001341 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1342 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001343
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001344 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 retval = PTR_ERR(req);
1346 goto out;
1347 }
1348
Swen Schillig09a46c62009-08-18 15:43:16 +02001349 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001350 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1352 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1353
1354 req->handler = zfcp_fsf_exchange_port_data_handler;
1355 req->erp_action = erp_action;
1356 erp_action->fsf_req = req;
1357
Christof Schmitt287ac012008-07-02 10:56:40 +02001358 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001359 retval = zfcp_fsf_req_send(req);
1360 if (retval) {
1361 zfcp_fsf_req_free(req);
1362 erp_action->fsf_req = NULL;
1363 }
1364out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001365 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001366 return retval;
1367}
1368
1369/**
1370 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001371 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001372 * @data: pointer to struct fsf_qtcb_bottom_port
1373 * Returns: 0 on success, error otherwise
1374 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001375int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001376 struct fsf_qtcb_bottom_port *data)
1377{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001378 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001379 struct zfcp_fsf_req *req = NULL;
1380 int retval = -EIO;
1381
Swen Schillig564e1c82009-08-18 15:43:19 +02001382 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001383 return -EOPNOTSUPP;
1384
Swen Schillig564e1c82009-08-18 15:43:19 +02001385 spin_lock_bh(&qdio->req_q_lock);
1386 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001387 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001388
Swen Schillig564e1c82009-08-18 15:43:19 +02001389 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001390
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001391 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001393 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001394 }
1395
1396 if (data)
1397 req->data = data;
1398
Swen Schillig564e1c82009-08-18 15:43:19 +02001399 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001400 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1401 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1402
1403 req->handler = zfcp_fsf_exchange_port_data_handler;
1404 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1405 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001406 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001407
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001408 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001409 wait_for_completion(&req->completion);
1410
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001411 zfcp_fsf_req_free(req);
1412
1413 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001414
1415out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001416 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001417 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001418}
1419
1420static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1421{
1422 struct zfcp_port *port = req->data;
1423 struct fsf_qtcb_header *header = &req->qtcb->header;
1424 struct fsf_plogi *plogi;
1425
1426 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001427 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001428
1429 switch (header->fsf_status) {
1430 case FSF_PORT_ALREADY_OPEN:
1431 break;
1432 case FSF_ACCESS_DENIED:
1433 zfcp_fsf_access_denied_port(req, port);
1434 break;
1435 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1436 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001437 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001438 "remote port 0x%016Lx\n",
1439 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001440 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001441 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1442 break;
1443 case FSF_ADAPTER_STATUS_AVAILABLE:
1444 switch (header->fsf_status_qual.word[0]) {
1445 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1446 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001447 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001448 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1449 break;
1450 }
1451 break;
1452 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1455 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001456 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1457 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1458 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 /* check whether D_ID has changed during open */
1460 /*
1461 * FIXME: This check is not airtight, as the FCP channel does
1462 * not monitor closures of target port connections caused on
1463 * the remote side. Thus, they might miss out on invalidating
1464 * locally cached WWPNs (and other N_Port parameters) of gone
1465 * target ports. So, our heroic attempt to make things safe
1466 * could be undermined by 'open port' response data tagged with
1467 * obsolete WWPNs. Another reason to monitor potential
1468 * connection closures ourself at least (by interpreting
1469 * incoming ELS' and unsolicited status). It just crosses my
1470 * mind that one should be able to cross-check by means of
1471 * another GID_PN straight after a port has been opened.
1472 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1473 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001474 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001475 if (req->qtcb->bottom.support.els1_length >=
1476 FSF_PLOGI_MIN_LEN) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001477 if (plogi->serv_param.wwpn != port->wwpn)
Christof Schmittb98478d2008-12-19 16:56:59 +01001478 port->d_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 else {
1480 port->wwnn = plogi->serv_param.wwnn;
1481 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483 }
1484 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001486 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 break;
1488 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001489
1490out:
1491 zfcp_port_put(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494/**
1495 * zfcp_fsf_open_port - create and send open port request
1496 * @erp_action: pointer to struct zfcp_erp_action
1497 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001501 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001502 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001503 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001504 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001505 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Swen Schillig564e1c82009-08-18 15:43:19 +02001507 spin_lock_bh(&qdio->req_q_lock);
1508 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Swen Schillig564e1c82009-08-18 15:43:19 +02001511 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1512 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001513
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001514 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001515 retval = PTR_ERR(req);
1516 goto out;
1517 }
1518
Swen Schillig09a46c62009-08-18 15:43:16 +02001519 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001520 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1522 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1523
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 req->handler = zfcp_fsf_open_port_handler;
Martin Petermanna17c5852009-05-15 13:18:19 +02001525 req->qtcb->bottom.support.d_id = port->d_id;
1526 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001527 req->erp_action = erp_action;
1528 erp_action->fsf_req = req;
Martin Petermanna17c5852009-05-15 13:18:19 +02001529 zfcp_port_get(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Christof Schmitt287ac012008-07-02 10:56:40 +02001531 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001532 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001534 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 erp_action->fsf_req = NULL;
Martin Petermanna17c5852009-05-15 13:18:19 +02001536 zfcp_port_put(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001538out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001539 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return retval;
1541}
1542
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001543static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001545 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001547 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001548 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001550 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001552 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001553 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001558 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 ZFCP_STATUS_COMMON_OPEN,
1560 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001565/**
1566 * zfcp_fsf_close_port - create and send close port request
1567 * @erp_action: pointer to struct zfcp_erp_action
1568 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001570int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001572 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001573 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001574 struct zfcp_fsf_req *req;
1575 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Swen Schillig564e1c82009-08-18 15:43:19 +02001577 spin_lock_bh(&qdio->req_q_lock);
1578 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Swen Schillig564e1c82009-08-18 15:43:19 +02001581 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1582 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001583
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001584 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001585 retval = PTR_ERR(req);
1586 goto out;
1587 }
1588
Swen Schillig09a46c62009-08-18 15:43:16 +02001589 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001590 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1592 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1593
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001594 req->handler = zfcp_fsf_close_port_handler;
1595 req->data = erp_action->port;
1596 req->erp_action = erp_action;
1597 req->qtcb->header.port_handle = erp_action->port->handle;
1598 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Christof Schmitt287ac012008-07-02 10:56:40 +02001600 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001601 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001603 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001606out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001607 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 return retval;
1609}
1610
Swen Schillig5ab944f2008-10-01 12:42:17 +02001611static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1612{
1613 struct zfcp_wka_port *wka_port = req->data;
1614 struct fsf_qtcb_header *header = &req->qtcb->header;
1615
1616 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1617 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1618 goto out;
1619 }
1620
1621 switch (header->fsf_status) {
1622 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1623 dev_warn(&req->adapter->ccw_device->dev,
1624 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001625 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001626 case FSF_ADAPTER_STATUS_AVAILABLE:
1627 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001628 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001629 case FSF_ACCESS_DENIED:
1630 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1631 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001632 case FSF_GOOD:
1633 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001634 /* fall through */
1635 case FSF_PORT_ALREADY_OPEN:
Swen Schillig5ab944f2008-10-01 12:42:17 +02001636 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1637 }
1638out:
1639 wake_up(&wka_port->completion_wq);
1640}
1641
1642/**
1643 * zfcp_fsf_open_wka_port - create and send open wka-port request
1644 * @wka_port: pointer to struct zfcp_wka_port
1645 * Returns: 0 on success, error otherwise
1646 */
1647int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1648{
1649 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001650 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001651 struct zfcp_fsf_req *req;
1652 int retval = -EIO;
1653
Swen Schillig564e1c82009-08-18 15:43:19 +02001654 spin_lock_bh(&qdio->req_q_lock);
1655 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001656 goto out;
1657
Swen Schillig564e1c82009-08-18 15:43:19 +02001658 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1659 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001660
Swen Schillig5ab944f2008-10-01 12:42:17 +02001661 if (unlikely(IS_ERR(req))) {
1662 retval = PTR_ERR(req);
1663 goto out;
1664 }
1665
Swen Schillig09a46c62009-08-18 15:43:16 +02001666 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001667 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001668 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1669 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1670
1671 req->handler = zfcp_fsf_open_wka_port_handler;
1672 req->qtcb->bottom.support.d_id = wka_port->d_id;
1673 req->data = wka_port;
1674
1675 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1676 retval = zfcp_fsf_req_send(req);
1677 if (retval)
1678 zfcp_fsf_req_free(req);
1679out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001680 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001681 return retval;
1682}
1683
1684static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1685{
1686 struct zfcp_wka_port *wka_port = req->data;
1687
1688 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1689 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001690 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001691 }
1692
1693 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1694 wake_up(&wka_port->completion_wq);
1695}
1696
1697/**
1698 * zfcp_fsf_close_wka_port - create and send close wka port request
1699 * @erp_action: pointer to struct zfcp_erp_action
1700 * Returns: 0 on success, error otherwise
1701 */
1702int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1703{
1704 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001705 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001706 struct zfcp_fsf_req *req;
1707 int retval = -EIO;
1708
Swen Schillig564e1c82009-08-18 15:43:19 +02001709 spin_lock_bh(&qdio->req_q_lock);
1710 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001711 goto out;
1712
Swen Schillig564e1c82009-08-18 15:43:19 +02001713 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1714 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001715
Swen Schillig5ab944f2008-10-01 12:42:17 +02001716 if (unlikely(IS_ERR(req))) {
1717 retval = PTR_ERR(req);
1718 goto out;
1719 }
1720
Swen Schillig09a46c62009-08-18 15:43:16 +02001721 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001722 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001723 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1724 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1725
1726 req->handler = zfcp_fsf_close_wka_port_handler;
1727 req->data = wka_port;
1728 req->qtcb->header.port_handle = wka_port->handle;
1729
1730 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1731 retval = zfcp_fsf_req_send(req);
1732 if (retval)
1733 zfcp_fsf_req_free(req);
1734out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001735 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001736 return retval;
1737}
1738
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001739static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001741 struct zfcp_port *port = req->data;
1742 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001745 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001746 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001750 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001751 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001754 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001757 /* can't use generic zfcp_erp_modify_port_status because
1758 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1759 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1760 list_for_each_entry(unit, &port->unit_list_head, list)
1761 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1762 &unit->status);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001763 zfcp_erp_port_boxed(port, "fscpph2", req);
1764 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1765 ZFCP_STATUS_FSFREQ_RETRY;
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 switch (header->fsf_status_qual.word[0]) {
1770 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001771 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 }
1776 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 /* can't use generic zfcp_erp_modify_port_status because
1779 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1780 */
1781 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1782 list_for_each_entry(unit, &port->unit_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001783 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1784 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001789/**
1790 * zfcp_fsf_close_physical_port - close physical port
1791 * @erp_action: pointer to struct zfcp_erp_action
1792 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001794int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001796 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001797 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001798 struct zfcp_fsf_req *req;
1799 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Swen Schillig564e1c82009-08-18 15:43:19 +02001801 spin_lock_bh(&qdio->req_q_lock);
1802 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Swen Schillig564e1c82009-08-18 15:43:19 +02001805 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1806 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001807
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001808 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 goto out;
1811 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812
Swen Schillig09a46c62009-08-18 15:43:16 +02001813 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001814 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001815 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1816 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1817
1818 req->data = erp_action->port;
1819 req->qtcb->header.port_handle = erp_action->port->handle;
1820 req->erp_action = erp_action;
1821 req->handler = zfcp_fsf_close_physical_port_handler;
1822 erp_action->fsf_req = req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823
Christof Schmitt287ac012008-07-02 10:56:40 +02001824 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001825 retval = zfcp_fsf_req_send(req);
1826 if (retval) {
1827 zfcp_fsf_req_free(req);
1828 erp_action->fsf_req = NULL;
1829 }
1830out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001831 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 return retval;
1833}
1834
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001835static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001837 struct zfcp_adapter *adapter = req->adapter;
1838 struct zfcp_unit *unit = req->data;
1839 struct fsf_qtcb_header *header = &req->qtcb->header;
1840 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1841 struct fsf_queue_designator *queue_designator =
1842 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001843 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001845 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001846 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001849 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 ZFCP_STATUS_UNIT_SHARED |
1851 ZFCP_STATUS_UNIT_READONLY,
1852 &unit->status);
1853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 switch (header->fsf_status) {
1855
1856 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001857 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001858 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001864 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001867 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001868 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1869 ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001873 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001874 "LUN 0x%Lx on port 0x%Lx is already in "
1875 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001876 (unsigned long long)unit->fcp_lun,
1877 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001878 queue_designator->cssid,
1879 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001880 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001881 zfcp_act_eval_err(adapter,
1882 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001883 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1885 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001890 "No handle is available for LUN "
1891 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001892 (unsigned long long)unit->fcp_lun,
1893 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001894 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001895 /* fall through */
1896 case FSF_INVALID_COMMAND_OPTION:
1897 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 switch (header->fsf_status_qual.word[0]) {
1901 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001902 zfcp_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001903 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001905 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 }
1908 break;
1909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001913
1914 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1915 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001916 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001917 exclusive = (bottom->lun_access_info &
1918 FSF_UNIT_ACCESS_EXCLUSIVE);
1919 readwrite = (bottom->lun_access_info &
1920 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 if (!exclusive)
1923 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1924 &unit->status);
1925
1926 if (!readwrite) {
1927 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1928 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001930 "SCSI device at LUN 0x%016Lx on port "
1931 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001932 (unsigned long long)unit->fcp_lun,
1933 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 }
1935
1936 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001937 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001938 "Exclusive read-only access not "
1939 "supported (unit 0x%016Lx, "
1940 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001941 (unsigned long long)unit->fcp_lun,
1942 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001943 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001945 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001947 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001948 "Shared read-write access not "
1949 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001950 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001951 (unsigned long long)unit->fcp_lun,
1952 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001953 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001955 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 }
1957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001963 * zfcp_fsf_open_unit - open unit
1964 * @erp_action: pointer to struct zfcp_erp_action
1965 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001967int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001969 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001971 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001972 struct zfcp_fsf_req *req;
1973 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Swen Schillig564e1c82009-08-18 15:43:19 +02001975 spin_lock_bh(&qdio->req_q_lock);
1976 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001977 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Swen Schillig564e1c82009-08-18 15:43:19 +02001979 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Swen Schilliga4623c42009-08-18 15:43:15 +02001980 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001981
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001982 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001983 retval = PTR_ERR(req);
1984 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001985 }
1986
Swen Schillig09a46c62009-08-18 15:43:16 +02001987 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001988 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1990 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001992 req->qtcb->header.port_handle = erp_action->port->handle;
1993 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1994 req->handler = zfcp_fsf_open_unit_handler;
1995 req->data = erp_action->unit;
1996 req->erp_action = erp_action;
1997 erp_action->fsf_req = req;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001998
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001999 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2000 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Christof Schmitt287ac012008-07-02 10:56:40 +02002002 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002003 retval = zfcp_fsf_req_send(req);
2004 if (retval) {
2005 zfcp_fsf_req_free(req);
2006 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002008out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002009 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 return retval;
2011}
2012
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002013static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002015 struct zfcp_unit *unit = req->data;
2016
2017 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02002018 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002019
2020 switch (req->qtcb->header.fsf_status) {
2021 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002022 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2024 break;
2025 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002026 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002027 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2028 break;
2029 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002030 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002031 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2032 ZFCP_STATUS_FSFREQ_RETRY;
2033 break;
2034 case FSF_ADAPTER_STATUS_AVAILABLE:
2035 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2036 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2037 zfcp_test_link(unit->port);
2038 /* fall through */
2039 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2040 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2041 break;
2042 }
2043 break;
2044 case FSF_GOOD:
2045 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2046 break;
2047 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002048}
2049
2050/**
2051 * zfcp_fsf_close_unit - close zfcp unit
2052 * @erp_action: pointer to struct zfcp_unit
2053 * Returns: 0 on success, error otherwise
2054 */
2055int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2056{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002057 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002058 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002059 struct zfcp_fsf_req *req;
2060 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Swen Schillig564e1c82009-08-18 15:43:19 +02002062 spin_lock_bh(&qdio->req_q_lock);
2063 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002065
Swen Schillig564e1c82009-08-18 15:43:19 +02002066 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2067 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002068
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002069 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002070 retval = PTR_ERR(req);
2071 goto out;
2072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
Swen Schillig09a46c62009-08-18 15:43:16 +02002074 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02002075 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002076 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2078
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 req->qtcb->header.port_handle = erp_action->port->handle;
2080 req->qtcb->header.lun_handle = erp_action->unit->handle;
2081 req->handler = zfcp_fsf_close_unit_handler;
2082 req->data = erp_action->unit;
2083 req->erp_action = erp_action;
2084 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Christof Schmitt287ac012008-07-02 10:56:40 +02002086 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087 retval = zfcp_fsf_req_send(req);
2088 if (retval) {
2089 zfcp_fsf_req_free(req);
2090 erp_action->fsf_req = NULL;
2091 }
2092out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002093 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002094 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
Christof Schmittc9615852008-05-06 11:00:05 +02002097static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2098{
2099 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002100 lat_rec->min = min(lat_rec->min, lat);
2101 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002102}
2103
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002104static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
Christof Schmittc9615852008-05-06 11:00:05 +02002105{
2106 struct fsf_qual_latency_info *lat_inf;
2107 struct latency_cont *lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002108 struct zfcp_unit *unit = req->unit;
Christof Schmittc9615852008-05-06 11:00:05 +02002109
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002110 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002111
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002112 switch (req->qtcb->bottom.io.data_direction) {
Christof Schmittc9615852008-05-06 11:00:05 +02002113 case FSF_DATADIR_READ:
2114 lat = &unit->latencies.read;
2115 break;
2116 case FSF_DATADIR_WRITE:
2117 lat = &unit->latencies.write;
2118 break;
2119 case FSF_DATADIR_CMND:
2120 lat = &unit->latencies.cmd;
2121 break;
2122 default:
2123 return;
2124 }
2125
Christof Schmitt49f0f012009-03-02 13:08:57 +01002126 spin_lock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002127 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2128 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2129 lat->counter++;
Christof Schmitt49f0f012009-03-02 13:08:57 +01002130 spin_unlock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002131}
2132
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002133#ifdef CONFIG_BLK_DEV_IO_TRACE
2134static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2135{
2136 struct fsf_qual_latency_info *lat_inf;
2137 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2138 struct request *req = scsi_cmnd->request;
2139 struct zfcp_blk_drv_data trace;
2140 int ticks = fsf_req->adapter->timer_ticks;
2141
2142 trace.flags = 0;
2143 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2144 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2145 trace.flags |= ZFCP_BLK_LAT_VALID;
2146 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2147 trace.channel_lat = lat_inf->channel_lat * ticks;
2148 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2149 }
2150 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2151 trace.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig42428f72009-08-18 15:43:18 +02002152 trace.inb_usage = fsf_req->queue_req.qdio_inb_usage;
2153 trace.outb_usage = fsf_req->queue_req.qdio_outb_usage;
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002154
2155 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2156}
2157#else
2158static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2159{
2160}
2161#endif
2162
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002163static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002165 struct scsi_cmnd *scpnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002167 &(req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 u32 sns_len;
Martin Petermannf76af7d2008-07-02 10:56:36 +02002169 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002172 read_lock_irqsave(&req->adapter->abort_lock, flags);
2173
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002174 scpnt = req->data;
2175 if (unlikely(!scpnt)) {
2176 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2177 return;
2178 }
2179
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002180 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002181 set_host_byte(scpnt, DID_SOFT_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 goto skip_fsfstatus;
2183 }
2184
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002185 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002186 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 goto skip_fsfstatus;
2188 }
2189
Martin Petermannfeac6a02008-07-02 10:56:35 +02002190 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002194 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2195 zfcp_fsf_req_latency(req);
Christof Schmittc9615852008-05-06 11:00:05 +02002196
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002197 zfcp_fsf_trace_latency(req);
2198
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002200 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002201 set_host_byte(scpnt, DID_OK);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002202 else {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002203 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05002204 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 }
2206 }
2207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002209 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2210 fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09002214 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 }
2217
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09002219 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2220 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2221 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002222 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002224skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002225 if (scpnt->result != 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002227 else if (scpnt->retries > 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002229 else
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002230 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 /*
2235 * We must hold this lock until scsi_done has been called.
2236 * Otherwise we may call scsi_done after abort regarding this
2237 * command has completed.
2238 * Note: scsi_done must not block!
2239 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002240 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002243static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002246 &(req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d2008-07-02 10:56:36 +02002247 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002249 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2250 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2251 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
2254
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002255static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2256{
2257 struct zfcp_unit *unit;
2258 struct fsf_qtcb_header *header = &req->qtcb->header;
2259
2260 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2261 unit = req->data;
2262 else
2263 unit = req->unit;
2264
2265 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2266 goto skip_fsfstatus;
2267
2268 switch (header->fsf_status) {
2269 case FSF_HANDLE_MISMATCH:
2270 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002271 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002272 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2273 break;
2274 case FSF_FCPLUN_NOT_VALID:
2275 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002276 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002277 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2278 break;
2279 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2280 zfcp_fsf_class_not_supp(req);
2281 break;
2282 case FSF_ACCESS_DENIED:
2283 zfcp_fsf_access_denied_unit(req, unit);
2284 break;
2285 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2286 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002287 "Incorrect direction %d, unit 0x%016Lx on port "
2288 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002289 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002290 (unsigned long long)unit->fcp_lun,
2291 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002292 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2293 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002294 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2295 break;
2296 case FSF_CMND_LENGTH_NOT_VALID:
2297 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002298 "Incorrect CDB length %d, unit 0x%016Lx on "
2299 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002300 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002301 (unsigned long long)unit->fcp_lun,
2302 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002303 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2304 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002305 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2306 break;
2307 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002308 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002309 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2310 ZFCP_STATUS_FSFREQ_RETRY;
2311 break;
2312 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002313 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002314 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2315 ZFCP_STATUS_FSFREQ_RETRY;
2316 break;
2317 case FSF_ADAPTER_STATUS_AVAILABLE:
2318 if (header->fsf_status_qual.word[0] ==
2319 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2320 zfcp_test_link(unit->port);
2321 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2322 break;
2323 }
2324skip_fsfstatus:
2325 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2326 zfcp_fsf_send_fcp_ctm_handler(req);
2327 else {
2328 zfcp_fsf_send_fcp_command_task_handler(req);
2329 req->unit = NULL;
2330 zfcp_unit_put(unit);
2331 }
2332}
2333
Swen Schillig7ba58c92008-10-01 12:42:18 +02002334static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2335{
2336 u32 *fcp_dl_ptr;
2337
2338 /*
2339 * fcp_dl_addr = start address of fcp_cmnd structure +
2340 * size of fixed part + size of dynamically sized add_dcp_cdb field
2341 * SEE FCP-2 documentation
2342 */
2343 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2344 (fcp_cmd->add_fcp_cdb_length << 2));
2345 *fcp_dl_ptr = fcp_dl;
2346}
2347
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348/**
2349 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002350 * @unit: unit where command is sent to
2351 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002353int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2354 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002355{
2356 struct zfcp_fsf_req *req;
2357 struct fcp_cmnd_iu *fcp_cmnd_iu;
Christof Schmittbc90c862009-05-15 13:18:17 +02002358 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002359 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002360 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002361 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002362
2363 if (unlikely(!(atomic_read(&unit->status) &
2364 ZFCP_STATUS_COMMON_UNBLOCKED)))
2365 return -EBUSY;
2366
Swen Schillig564e1c82009-08-18 15:43:19 +02002367 spin_lock(&qdio->req_q_lock);
2368 if (atomic_read(&qdio->req_q.count) <= 0) {
2369 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002370 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002371 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002372
Swen Schillig564e1c82009-08-18 15:43:19 +02002373 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Swen Schilliga4623c42009-08-18 15:43:15 +02002374 adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002375
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002376 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377 retval = PTR_ERR(req);
2378 goto out;
2379 }
2380
Swen Schillig09a46c62009-08-18 15:43:16 +02002381 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002382 zfcp_unit_get(unit);
2383 req->unit = unit;
2384 req->data = scsi_cmnd;
2385 req->handler = zfcp_fsf_send_fcp_command_handler;
2386 req->qtcb->header.lun_handle = unit->handle;
2387 req->qtcb->header.port_handle = unit->port->handle;
2388 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2389
2390 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2391
2392 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2393 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2394 /*
2395 * set depending on data direction:
2396 * data direction bits in SBALE (SB Type)
2397 * data direction bits in QTCB
2398 * data direction bits in FCP_CMND IU
2399 */
2400 switch (scsi_cmnd->sc_data_direction) {
2401 case DMA_NONE:
2402 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002403 break;
2404 case DMA_FROM_DEVICE:
2405 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002406 fcp_cmnd_iu->rddata = 1;
2407 break;
2408 case DMA_TO_DEVICE:
2409 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2410 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2411 fcp_cmnd_iu->wddata = 1;
2412 break;
2413 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002414 goto failed_scsi_cmnd;
2415 }
2416
2417 if (likely((scsi_cmnd->device->simple_tags) ||
2418 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2419 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2420 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2421 else
2422 fcp_cmnd_iu->task_attribute = UNTAGGED;
2423
2424 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2425 fcp_cmnd_iu->add_fcp_cdb_length =
2426 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2427
2428 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2429
2430 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002431 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002432
Swen Schillig564e1c82009-08-18 15:43:19 +02002433 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002434 scsi_sglist(scsi_cmnd),
2435 FSF_MAX_SBALS_PER_REQ);
2436 if (unlikely(real_bytes < 0)) {
Swen Schillig42428f72009-08-18 15:43:18 +02002437 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002438 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002439 "Oversize data package, unit 0x%016Lx "
2440 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002441 (unsigned long long)unit->fcp_lun,
2442 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002443 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002444 retval = -EINVAL;
2445 }
2446 goto failed_scsi_cmnd;
2447 }
2448
2449 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2450
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002451 retval = zfcp_fsf_req_send(req);
2452 if (unlikely(retval))
2453 goto failed_scsi_cmnd;
2454
2455 goto out;
2456
2457failed_scsi_cmnd:
2458 zfcp_unit_put(unit);
2459 zfcp_fsf_req_free(req);
2460 scsi_cmnd->host_scribble = NULL;
2461out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002462 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002463 return retval;
2464}
2465
2466/**
2467 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002468 * @unit: pointer to struct zfcp_unit
2469 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002470 * Returns: on success pointer to struct fsf_req, NULL otherwise
2471 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002472struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002473{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002474 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002475 struct zfcp_fsf_req *req = NULL;
2476 struct fcp_cmnd_iu *fcp_cmnd_iu;
Swen Schillig564e1c82009-08-18 15:43:19 +02002477 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002478
2479 if (unlikely(!(atomic_read(&unit->status) &
2480 ZFCP_STATUS_COMMON_UNBLOCKED)))
2481 return NULL;
2482
Swen Schillig564e1c82009-08-18 15:43:19 +02002483 spin_lock_bh(&qdio->req_q_lock);
2484 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002485 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002486
Swen Schillig564e1c82009-08-18 15:43:19 +02002487 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2488 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002489
Swen Schillig633528c2008-11-26 18:07:37 +01002490 if (IS_ERR(req)) {
2491 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002492 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002493 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002494
2495 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2496 req->data = unit;
2497 req->handler = zfcp_fsf_send_fcp_command_handler;
2498 req->qtcb->header.lun_handle = unit->handle;
2499 req->qtcb->header.port_handle = unit->port->handle;
2500 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2501 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2502 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002503 sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002504
Swen Schillig564e1c82009-08-18 15:43:19 +02002505 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002506 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2507 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2508
2509 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2510 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2511 fcp_cmnd_iu->task_management_flags = tm_flags;
2512
2513 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2514 if (!zfcp_fsf_req_send(req))
2515 goto out;
2516
2517 zfcp_fsf_req_free(req);
2518 req = NULL;
2519out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002520 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002521 return req;
2522}
2523
2524static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2525{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002526}
2527
2528/**
2529 * zfcp_fsf_control_file - control file upload/download
2530 * @adapter: pointer to struct zfcp_adapter
2531 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2532 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002534struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2535 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002537 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002538 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002539 struct zfcp_fsf_req *req = NULL;
2540 struct fsf_qtcb_bottom_support *bottom;
2541 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Christof Schmitt45633fd2008-06-10 18:20:55 +02002543 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2544 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Christof Schmitt45633fd2008-06-10 18:20:55 +02002546 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2548 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2551 direction = SBAL_FLAGS0_TYPE_READ;
2552 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002554 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 }
2556
Swen Schillig564e1c82009-08-18 15:43:19 +02002557 spin_lock_bh(&qdio->req_q_lock);
2558 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002559 goto out;
2560
Swen Schillig564e1c82009-08-18 15:43:19 +02002561 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002562 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002564 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 }
2566
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002567 req->handler = zfcp_fsf_control_file_handler;
2568
Swen Schillig564e1c82009-08-18 15:43:19 +02002569 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 sbale[0].flags |= direction;
2571
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002572 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002574 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Swen Schillig564e1c82009-08-18 15:43:19 +02002576 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2577 direction, fsf_cfdc->sg,
2578 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002579 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002580 zfcp_fsf_req_free(req);
2581 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002584 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2585 retval = zfcp_fsf_req_send(req);
2586out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002587 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002588
2589 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002590 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002591 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002593 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002595
2596/**
2597 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2598 * @adapter: pointer to struct zfcp_adapter
2599 * @sbal_idx: response queue index of SBAL to be processed
2600 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002601void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002602{
Swen Schillig564e1c82009-08-18 15:43:19 +02002603 struct zfcp_adapter *adapter = qdio->adapter;
2604 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002605 struct qdio_buffer_element *sbale;
2606 struct zfcp_fsf_req *fsf_req;
2607 unsigned long flags, req_id;
2608 int idx;
2609
2610 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2611
2612 sbale = &sbal->element[idx];
2613 req_id = (unsigned long) sbale->addr;
2614 spin_lock_irqsave(&adapter->req_list_lock, flags);
2615 fsf_req = zfcp_reqlist_find(adapter, req_id);
2616
2617 if (!fsf_req)
2618 /*
2619 * Unknown request means that we have potentially memory
2620 * corruption and must stop the machine immediately.
2621 */
2622 panic("error: unknown req_id (%lx) on adapter %s.\n",
2623 req_id, dev_name(&adapter->ccw_device->dev));
2624
2625 list_del(&fsf_req->list);
2626 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2627
Swen Schillig42428f72009-08-18 15:43:18 +02002628 fsf_req->queue_req.sbal_response = sbal_idx;
2629 fsf_req->queue_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002630 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002631 zfcp_fsf_req_complete(fsf_req);
2632
2633 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2634 break;
2635 }
2636}