blob: ed06a1d17b734957e2ff1656984694cc8d91f903 [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 Schmitt63caf362009-03-02 13:09:00 +010016#define ZFCP_REQ_AUTO_CLEANUP 0x00000002
17#define ZFCP_REQ_NO_QTCB 0x00000008
18
Christof Schmitt287ac012008-07-02 10:56:40 +020019static void zfcp_fsf_request_timeout_handler(unsigned long data)
20{
21 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010022 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
23 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020024}
25
26static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
27 unsigned long timeout)
28{
29 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
30 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
31 fsf_req->timer.expires = jiffies + timeout;
32 add_timer(&fsf_req->timer);
33}
34
35static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
36{
37 BUG_ON(!fsf_req->erp_action);
38 fsf_req->timer.function = zfcp_erp_timeout_handler;
39 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
40 fsf_req->timer.expires = jiffies + 30 * HZ;
41 add_timer(&fsf_req->timer);
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/* association between FSF command and FSF QTCB type */
45static u32 fsf_qtcb_type[] = {
46 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
47 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
56 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
57 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
59};
60
Christof Schmitt553448f2008-06-10 18:20:58 +020061static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
62{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020063 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020064 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020065 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020066
Christof Schmittff3b24f2008-10-01 12:42:15 +020067 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020068 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020069 "Access denied according to ACT rule type %s, "
70 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020071}
72
73static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
74 struct zfcp_port *port)
75{
76 struct fsf_qtcb_header *header = &req->qtcb->header;
77 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020078 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020079 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020080 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010082 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020083 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
84}
85
86static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
87 struct zfcp_unit *unit)
88{
89 struct fsf_qtcb_header *header = &req->qtcb->header;
90 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020091 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020092 (unsigned long long)unit->fcp_lun,
93 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020094 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010096 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020097 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
98}
99
100static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
101{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200102 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
103 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100104 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200105 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
106}
107
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200108/**
109 * zfcp_fsf_req_free - free memory used by fsf request
110 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200112void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114 if (likely(req->pool)) {
115 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200116 return;
117 }
118
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200119 if (req->qtcb) {
120 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200121 return;
122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200125static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200127 struct fsf_status_read_buffer *sr_buf = req->data;
128 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 struct zfcp_port *port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200130 int d_id = sr_buf->d_id & ZFCP_DID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 unsigned long flags;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 read_lock_irqsave(&zfcp_data.config_lock, flags);
134 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200135 if (port->d_id == d_id) {
136 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100137 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 return;
139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100143static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200144 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200146 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt70932932009-04-17 15:08:15 +0200147 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
150 return;
151
152 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200153
154 read_lock_irqsave(&zfcp_data.config_lock, flags);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100155 zfcp_scsi_schedule_rports_block(adapter);
Christof Schmitt70932932009-04-17 15:08:15 +0200156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200157
158 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200160
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200164 "There is no light signal from the local "
165 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200166 break;
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200169 "There is a wrap plug instead of a fibre "
170 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200171 break;
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200174 "The adjacent fibre channel node does not "
175 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200176 break;
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200179 "The FCP device is suspended because of a "
180 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200181 break;
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200186 break;
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200189 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200190 break;
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200193 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200194 break;
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200199 break;
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200204 break;
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200209 break;
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200212 "The mode table on the FCP adapter "
213 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200214 break;
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200217 "All NPIV ports on the FCP adapter have "
218 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200219 break;
220 default:
221 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200224 }
225out:
226 zfcp_erp_adapter_failed(adapter, id, req);
227}
228
229static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
230{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
234
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100237 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200238 break;
239 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100240 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200241 break;
242 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100243 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200244 };
245}
246
247static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
248{
249 struct zfcp_adapter *adapter = req->adapter;
250 struct fsf_status_read_buffer *sr_buf = req->data;
251
252 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
253 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
254 mempool_free(sr_buf, adapter->pool.data_status_read);
255 zfcp_fsf_req_free(req);
256 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200260
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200261 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200263 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200266 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200271 dev_warn(&adapter->ccw_device->dev,
272 "The error threshold for checksum statistics "
273 "has been exceeded\n");
Swen Schillig57069382008-10-01 12:42:21 +0200274 zfcp_hba_dbf_event_berr(adapter, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200277 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200280 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200281 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100283 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 ZFCP_STATUS_COMMON_RUNNING,
285 ZFCP_SET);
286 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200287 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
288 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100289 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100291 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200292 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100293 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
294 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200295 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200296 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100297 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100299 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200301 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200302 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200303 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200305
306 mempool_free(sr_buf, adapter->pool.data_status_read);
307 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200308
309 atomic_inc(&adapter->stat_miss);
Swen Schilligb7f15f32008-10-01 12:42:22 +0200310 queue_work(zfcp_data.work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200315 switch (req->qtcb->header.fsf_status_qual.word[0]) {
316 case FSF_SQ_FCP_RSP_AVAILABLE:
317 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
318 case FSF_SQ_NO_RETRY_POSSIBLE:
319 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
320 return;
321 case FSF_SQ_COMMAND_ABORTED:
322 req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
323 break;
324 case FSF_SQ_NO_RECOM:
325 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200326 "The FCP adapter reported a problem "
327 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100328 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200329 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200331 /* all non-return stats set FSFREQ_ERROR*/
332 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
333}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200335static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
336{
337 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
338 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200339
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200340 switch (req->qtcb->header.fsf_status) {
341 case FSF_UNKNOWN_COMMAND:
342 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200343 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200344 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100345 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200346 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200349 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200356 struct zfcp_adapter *adapter = req->adapter;
357 struct fsf_qtcb *qtcb = req->qtcb;
358 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 zfcp_hba_dbf_event_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
363 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
364 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
365 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200368 switch (qtcb->prefix.prot_status) {
369 case FSF_PROT_GOOD:
370 case FSF_PROT_FSF_STATUS_PRESENTED:
371 return;
372 case FSF_PROT_QTCB_VERSION_ERROR:
373 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200374 "QTCB version 0x%x not supported by FCP adapter "
375 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
376 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100377 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200379 case FSF_PROT_ERROR_STATE:
380 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100381 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200382 req->status |= ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200384 case FSF_PROT_UNSUPP_QTCB_TYPE:
385 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200386 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100387 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200389 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
390 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
391 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 case FSF_PROT_DUPLICATE_REQUEST_ID:
394 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200395 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100397 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200399 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100400 zfcp_fsf_link_down_info_eval(req, "fspse_5",
401 &psq->link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200402 /* FIXME: reopening adapter now? better wait for link up */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100403 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200405 case FSF_PROT_REEST_QUEUE:
406 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100407 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200408 ZFCP_STATUS_COMMON_RUNNING,
409 ZFCP_SET);
410 zfcp_erp_adapter_reopen(adapter,
411 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100412 ZFCP_STATUS_COMMON_ERP_FAILED,
413 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200417 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100419 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200421 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200425 * zfcp_fsf_req_complete - process completion of a FSF request
426 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200428 * When a request has been completed either from the FCP adapter,
429 * or it has been dismissed due to a queue shutdown, this function
430 * is called to process the completion status and trigger further
431 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200433static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200434{
435 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
436 zfcp_fsf_status_read_handler(req);
437 return;
438 }
439
440 del_timer(&req->timer);
441 zfcp_fsf_protstatus_eval(req);
442 zfcp_fsf_fsfstatus_eval(req);
443 req->handler(req);
444
445 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200446 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200447
448 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
449 zfcp_fsf_req_free(req);
450 else
Swen Schillig058b8642009-08-18 15:43:14 +0200451 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200452}
453
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200454/**
455 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
456 * @adapter: pointer to struct zfcp_adapter
457 *
458 * Never ever call this without shutting down the adapter first.
459 * Otherwise the adapter would continue using and corrupting s390 storage.
460 * Included BUG_ON() call to ensure this is done.
461 * ERP is supposed to be the only user of this function.
462 */
463void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
464{
465 struct zfcp_fsf_req *req, *tmp;
466 unsigned long flags;
467 LIST_HEAD(remove_queue);
468 unsigned int i;
469
470 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
471 spin_lock_irqsave(&adapter->req_list_lock, flags);
472 for (i = 0; i < REQUEST_LIST_SIZE; i++)
473 list_splice_init(&adapter->req_list[i], &remove_queue);
474 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
475
476 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
477 list_del(&req->list);
478 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
479 zfcp_fsf_req_complete(req);
480 }
481}
482
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200483static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
485 struct fsf_qtcb_bottom_config *bottom;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200486 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200487 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200489 bottom = &req->qtcb->bottom.config;
490
491 if (req->data)
492 memcpy(req->data, bottom, sizeof(*bottom));
493
494 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
495 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
496 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
497 fc_host_speed(shost) = bottom->fc_link_speed;
498 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
499
500 adapter->hydra_version = bottom->adapter_type;
501 adapter->timer_ticks = bottom->timer_interval;
502
503 if (fc_host_permanent_port_name(shost) == -1)
504 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
505
506 switch (bottom->fc_topology) {
507 case FSF_TOPO_P2P:
508 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
509 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
510 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
511 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 break;
513 case FSF_TOPO_FABRIC:
514 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200515 break;
516 case FSF_TOPO_AL:
517 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200518 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200520 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200521 "Unknown or unsupported arbitrated loop "
522 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100523 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200524 return -EIO;
525 }
526
527 return 0;
528}
529
530static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
531{
532 struct zfcp_adapter *adapter = req->adapter;
533 struct fsf_qtcb *qtcb = req->qtcb;
534 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
535 struct Scsi_Host *shost = adapter->scsi_host;
536
537 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
538 return;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200541 adapter->adapter_features = bottom->adapter_features;
542 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500543 adapter->peer_wwpn = 0;
544 adapter->peer_wwnn = 0;
545 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200547 switch (qtcb->header.fsf_status) {
548 case FSF_GOOD:
549 if (zfcp_fsf_exchange_config_evaluate(req))
550 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200551
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200552 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
553 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200554 "FCP adapter maximum QTCB size (%d bytes) "
555 "is too small\n",
556 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100557 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200558 return;
559 }
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
561 &adapter->status);
562 break;
563 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200564 fc_host_node_name(shost) = 0;
565 fc_host_port_name(shost) = 0;
566 fc_host_port_id(shost) = 0;
567 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100568 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200570
571 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
572 &adapter->status);
573
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100574 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200575 &qtcb->header.fsf_status_qual.link_down_info);
576 break;
577 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100578 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200579 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200582 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200584 memcpy(fc_host_serial_number(shost), bottom->serial_number,
585 min(FC_SERIAL_NUMBER_SIZE, 17));
586 EBCASC(fc_host_serial_number(shost),
587 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200590 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200591 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200592 "The FCP adapter only supports newer "
593 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100594 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200598 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200599 "The FCP adapter only supports older "
600 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100601 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200605static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607 struct zfcp_adapter *adapter = req->adapter;
608 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
609 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200611 if (req->data)
612 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100613
Christof Schmitt02829852009-03-02 13:09:06 +0100614 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100615 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100616 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
617 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100618 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
619 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
620 fc_host_supported_speeds(shost) = bottom->supported_speed;
621}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200623static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200625 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100626
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200627 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return;
629
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200630 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 case FSF_GOOD:
632 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100636 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200637 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200638 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640}
641
Martin Petermann7001f0c2009-04-17 15:08:12 +0200642static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200643{
Christof Schmittdedbc2b2008-12-19 16:56:54 +0100644 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200645
646 spin_lock_bh(&adapter->req_q_lock);
647 if (atomic_read(&req_q->count))
648 return 1;
649 spin_unlock_bh(&adapter->req_q_lock);
650 return 0;
651}
652
653static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
654{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200655 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656
Christof Schmitt04062892008-10-01 12:42:20 +0200657 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658 ret = wait_event_interruptible_timeout(adapter->request_wq,
Martin Petermann7001f0c2009-04-17 15:08:12 +0200659 zfcp_fsf_sbal_check(adapter), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200660 if (ret > 0)
661 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200662 if (!ret) {
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200663 atomic_inc(&adapter->qdio_outb_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200664 /* assume hanging outbound queue, try queue recovery */
665 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
666 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200667
668 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200669 return -EIO;
670}
671
672static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
673{
674 struct zfcp_fsf_req *req;
675 req = mempool_alloc(pool, GFP_ATOMIC);
676 if (!req)
677 return NULL;
678 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100679 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200680 return req;
681}
682
683static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
684{
685 struct zfcp_fsf_req_qtcb *qtcb;
686
687 if (likely(pool))
688 qtcb = mempool_alloc(pool, GFP_ATOMIC);
689 else
690 qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
691 GFP_ATOMIC);
692 if (unlikely(!qtcb))
693 return NULL;
694
695 memset(qtcb, 0, sizeof(*qtcb));
696 qtcb->fsf_req.qtcb = &qtcb->qtcb;
697 qtcb->fsf_req.pool = pool;
698
699 return &qtcb->fsf_req;
700}
701
702static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
703 u32 fsf_cmd, int req_flags,
704 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200706 struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200708 struct zfcp_fsf_req *req;
709 struct zfcp_qdio_queue *req_q = &adapter->req_q;
710
711 if (req_flags & ZFCP_REQ_NO_QTCB)
712 req = zfcp_fsf_alloc_noqtcb(pool);
713 else
714 req = zfcp_fsf_alloc_qtcb(pool);
715
716 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200717 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200718
719 if (adapter->req_no == 0)
720 adapter->req_no++;
721
722 INIT_LIST_HEAD(&req->list);
723 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200724 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200725
726 req->adapter = adapter;
727 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100728 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200729 req->sbal_number = 1;
730 req->sbal_first = req_q->first;
731 req->sbal_last = req_q->first;
732 req->sbale_curr = 1;
733
734 sbale = zfcp_qdio_sbale_req(req);
735 sbale[0].addr = (void *) req->req_id;
736 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
737
738 if (likely(req->qtcb)) {
739 req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
740 req->qtcb->prefix.req_id = req->req_id;
741 req->qtcb->prefix.ulp_info = 26;
742 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
743 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
744 req->qtcb->header.req_handle = req->req_id;
745 req->qtcb->header.fsf_command = req->fsf_command;
746 req->seq_no = adapter->fsf_req_seq_no;
747 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
748 sbale[1].addr = (void *) req->qtcb;
749 sbale[1].length = sizeof(struct fsf_qtcb);
750 }
751
752 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
753 zfcp_fsf_req_free(req);
754 return ERR_PTR(-EIO);
755 }
756
757 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
758 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
759
760 return req;
761}
762
763static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
764{
765 struct zfcp_adapter *adapter = req->adapter;
Martin Petermann135ea132009-04-17 15:08:01 +0200766 unsigned long flags;
767 int idx;
768 int with_qtcb = (req->qtcb != NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200769
770 /* put allocated FSF request into hash table */
Heiko Carstens45316a82008-11-04 16:35:06 +0100771 spin_lock_irqsave(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 idx = zfcp_reqlist_hash(req->req_id);
773 list_add_tail(&req->list, &adapter->req_list[idx]);
Heiko Carstens45316a82008-11-04 16:35:06 +0100774 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200775
Christof Schmitt37651382008-11-04 16:35:08 +0100776 req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777 req->issued = get_clock();
778 if (zfcp_qdio_send(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200779 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100780 spin_lock_irqsave(&adapter->req_list_lock, flags);
781 /* lookup request again, list might have changed */
782 if (zfcp_reqlist_find_safe(adapter, req))
783 zfcp_reqlist_remove(adapter, req);
784 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100785 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200786 return -EIO;
787 }
788
789 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200790 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200791 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100792 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200793
794 return 0;
795}
796
797/**
798 * zfcp_fsf_status_read - send status read request
799 * @adapter: pointer to struct zfcp_adapter
800 * @req_flags: request flags
801 * Returns: 0 on success, ERROR otherwise
802 */
803int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
804{
805 struct zfcp_fsf_req *req;
806 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200807 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200808 int retval = -EIO;
809
Christof Schmitt04062892008-10-01 12:42:20 +0200810 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814 req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
815 ZFCP_REQ_NO_QTCB,
816 adapter->pool.fsf_req_status_read);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200817 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 goto out;
820 }
821
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 sbale = zfcp_qdio_sbale_req(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
824 req->sbale_curr = 2;
825
826 sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
827 if (!sr_buf) {
828 retval = -ENOMEM;
829 goto failed_buf;
830 }
831 memset(sr_buf, 0, sizeof(*sr_buf));
832 req->data = sr_buf;
833 sbale = zfcp_qdio_sbale_curr(req);
834 sbale->addr = (void *) sr_buf;
835 sbale->length = sizeof(*sr_buf);
836
837 retval = zfcp_fsf_req_send(req);
838 if (retval)
839 goto failed_req_send;
840
841 goto out;
842
843failed_req_send:
844 mempool_free(sr_buf, adapter->pool.data_status_read);
845failed_buf:
846 zfcp_fsf_req_free(req);
847 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
848out:
Christof Schmitt04062892008-10-01 12:42:20 +0200849 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return retval;
851}
852
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200853static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200855 struct zfcp_unit *unit = req->data;
856 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200858 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
859 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 switch (req->qtcb->header.fsf_status) {
862 case FSF_PORT_HANDLE_NOT_VALID:
863 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100864 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
865 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869 case FSF_LUN_HANDLE_NOT_VALID:
870 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100871 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
876 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100879 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200880 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
881 ZFCP_STATUS_FSFREQ_RETRY;
882 break;
883 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100884 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200885 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
886 ZFCP_STATUS_FSFREQ_RETRY;
887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200891 zfcp_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200892 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200894 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 break;
896 }
897 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200899 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
900 break;
901 }
902}
903
904/**
905 * zfcp_fsf_abort_fcp_command - abort running SCSI command
906 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200907 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200909 */
910
911struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100912 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200914 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200915 struct zfcp_fsf_req *req = NULL;
Christof Schmitt63caf362009-03-02 13:09:00 +0100916 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200917
Christof Schmitt92cab0d2009-03-02 13:08:59 +0100918 spin_lock_bh(&adapter->req_q_lock);
919 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920 goto out;
921 req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt63caf362009-03-02 13:09:00 +0100922 0, adapter->pool.fsf_req_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100923 if (IS_ERR(req)) {
924 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200925 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100926 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927
928 if (unlikely(!(atomic_read(&unit->status) &
929 ZFCP_STATUS_COMMON_UNBLOCKED)))
930 goto out_error_free;
931
932 sbale = zfcp_qdio_sbale_req(req);
933 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
934 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
935
936 req->data = unit;
937 req->handler = zfcp_fsf_abort_fcp_command_handler;
938 req->qtcb->header.lun_handle = unit->handle;
939 req->qtcb->header.port_handle = unit->port->handle;
940 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
941
942 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
943 if (!zfcp_fsf_req_send(req))
944 goto out;
945
946out_error_free:
947 zfcp_fsf_req_free(req);
948 req = NULL;
949out:
Christof Schmitt92cab0d2009-03-02 13:08:59 +0100950 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200951 return req;
952}
953
954static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
955{
956 struct zfcp_adapter *adapter = req->adapter;
957 struct zfcp_send_ct *send_ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200958 struct fsf_qtcb_header *header = &req->qtcb->header;
959
960 send_ct->status = -EINVAL;
961
962 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
963 goto skip_fsfstatus;
964
965 switch (header->fsf_status) {
966 case FSF_GOOD:
967 zfcp_san_dbf_event_ct_response(req);
968 send_ct->status = 0;
969 break;
970 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
971 zfcp_fsf_class_not_supp(req);
972 break;
973 case FSF_ADAPTER_STATUS_AVAILABLE:
974 switch (header->fsf_status_qual.word[0]){
975 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200976 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
977 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
978 break;
979 }
980 break;
981 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200982 break;
983 case FSF_PORT_BOXED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200984 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
985 ZFCP_STATUS_FSFREQ_RETRY;
986 break;
987 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100988 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200989 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200990 case FSF_GENERIC_COMMAND_REJECTED:
991 case FSF_PAYLOAD_SIZE_MISMATCH:
992 case FSF_REQUEST_SIZE_TOO_LARGE:
993 case FSF_RESPONSE_SIZE_TOO_LARGE:
994 case FSF_SBAL_MISMATCH:
995 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
996 break;
997 }
998
999skip_fsfstatus:
1000 if (send_ct->handler)
1001 send_ct->handler(send_ct->handler_data);
1002}
1003
Christof Schmitt426f6052009-07-13 15:06:06 +02001004static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1005 struct scatterlist *sg_req,
1006 struct scatterlist *sg_resp)
1007{
1008 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1009 sbale[2].addr = sg_virt(sg_req);
1010 sbale[2].length = sg_req->length;
1011 sbale[3].addr = sg_virt(sg_resp);
1012 sbale[3].length = sg_resp->length;
1013 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1014}
1015
1016static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1017{
1018 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1019}
1020
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001021static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1022 struct scatterlist *sg_req,
1023 struct scatterlist *sg_resp,
1024 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001025{
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001026 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
1027 u32 feat = req->adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001028 int bytes;
1029
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001030 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001031 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001032 return -EOPNOTSUPP;
1033
Christof Schmitt426f6052009-07-13 15:06:06 +02001034 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1035 return 0;
1036 }
1037
1038 /* use single, unchained SBAL if it can hold the request */
1039 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1040 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001041 return 0;
1042 }
1043
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1045 sg_req, max_sbals);
1046 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001047 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001048 req->qtcb->bottom.support.req_buf_length = bytes;
1049 req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1050
1051 bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
1052 sg_resp, max_sbals);
1053 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001054 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001055 req->qtcb->bottom.support.resp_buf_length = bytes;
1056
1057 return 0;
1058}
1059
1060/**
1061 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1062 * @ct: pointer to struct zfcp_send_ct with data for request
1063 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1064 * @erp_action: if non-null the Generic Service request sent within ERP
1065 */
1066int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1067 struct zfcp_erp_action *erp_action)
1068{
Swen Schillig5ab944f2008-10-01 12:42:17 +02001069 struct zfcp_wka_port *wka_port = ct->wka_port;
1070 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001071 struct zfcp_fsf_req *req;
1072 int ret = -EIO;
1073
Christof Schmitt04062892008-10-01 12:42:20 +02001074 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001075 if (zfcp_fsf_req_sbal_get(adapter))
1076 goto out;
1077
1078 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1079 ZFCP_REQ_AUTO_CLEANUP, pool);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001080 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001081 ret = PTR_ERR(req);
1082 goto out;
1083 }
1084
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001085 ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
1086 FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 if (ret)
1088 goto failed_send;
1089
1090 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001091 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001092 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1093 req->qtcb->bottom.support.timeout = ct->timeout;
1094 req->data = ct;
1095
1096 zfcp_san_dbf_event_ct_request(req);
1097
1098 if (erp_action) {
1099 erp_action->fsf_req = req;
1100 req->erp_action = erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +02001101 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001102 } else
1103 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1104
1105 ret = zfcp_fsf_req_send(req);
1106 if (ret)
1107 goto failed_send;
1108
1109 goto out;
1110
1111failed_send:
1112 zfcp_fsf_req_free(req);
1113 if (erp_action)
1114 erp_action->fsf_req = NULL;
1115out:
Christof Schmitt04062892008-10-01 12:42:20 +02001116 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001117 return ret;
1118}
1119
1120static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1121{
1122 struct zfcp_send_els *send_els = req->data;
1123 struct zfcp_port *port = send_els->port;
1124 struct fsf_qtcb_header *header = &req->qtcb->header;
1125
1126 send_els->status = -EINVAL;
1127
1128 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1129 goto skip_fsfstatus;
1130
1131 switch (header->fsf_status) {
1132 case FSF_GOOD:
1133 zfcp_san_dbf_event_els_response(req);
1134 send_els->status = 0;
1135 break;
1136 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1137 zfcp_fsf_class_not_supp(req);
1138 break;
1139 case FSF_ADAPTER_STATUS_AVAILABLE:
1140 switch (header->fsf_status_qual.word[0]){
1141 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1142 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1143 zfcp_test_link(port);
1144 /*fall through */
1145 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1146 case FSF_SQ_RETRY_IF_POSSIBLE:
1147 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1148 break;
1149 }
1150 break;
1151 case FSF_ELS_COMMAND_REJECTED:
1152 case FSF_PAYLOAD_SIZE_MISMATCH:
1153 case FSF_REQUEST_SIZE_TOO_LARGE:
1154 case FSF_RESPONSE_SIZE_TOO_LARGE:
1155 break;
1156 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001157 if (port)
1158 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001159 break;
1160 case FSF_SBAL_MISMATCH:
1161 /* should never occure, avoided in zfcp_fsf_send_els */
1162 /* fall through */
1163 default:
1164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1165 break;
1166 }
1167skip_fsfstatus:
1168 if (send_els->handler)
1169 send_els->handler(send_els->handler_data);
1170}
1171
1172/**
1173 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1174 * @els: pointer to struct zfcp_send_els with data for the command
1175 */
1176int zfcp_fsf_send_els(struct zfcp_send_els *els)
1177{
1178 struct zfcp_fsf_req *req;
1179 struct zfcp_adapter *adapter = els->adapter;
1180 struct fsf_qtcb_bottom_support *bottom;
1181 int ret = -EIO;
1182
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01001183 spin_lock_bh(&adapter->req_q_lock);
1184 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001185 goto out;
1186 req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1187 ZFCP_REQ_AUTO_CLEANUP, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001188 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 ret = PTR_ERR(req);
1190 goto out;
1191 }
1192
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001193 ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001194
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195 if (ret)
1196 goto failed_send;
1197
1198 bottom = &req->qtcb->bottom.support;
1199 req->handler = zfcp_fsf_send_els_handler;
1200 bottom->d_id = els->d_id;
1201 bottom->service_class = FSF_CLASS_3;
1202 bottom->timeout = 2 * R_A_TOV;
1203 req->data = els;
1204
1205 zfcp_san_dbf_event_els_request(req);
1206
1207 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1208 ret = zfcp_fsf_req_send(req);
1209 if (ret)
1210 goto failed_send;
1211
1212 goto out;
1213
1214failed_send:
1215 zfcp_fsf_req_free(req);
1216out:
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01001217 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001218 return ret;
1219}
1220
1221int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1222{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001223 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001224 struct zfcp_fsf_req *req;
1225 struct zfcp_adapter *adapter = erp_action->adapter;
1226 int retval = -EIO;
1227
Christof Schmitt04062892008-10-01 12:42:20 +02001228 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001229 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001230 goto out;
1231 req = zfcp_fsf_req_create(adapter,
1232 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1233 ZFCP_REQ_AUTO_CLEANUP,
1234 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001235 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236 retval = PTR_ERR(req);
1237 goto out;
1238 }
1239
1240 sbale = zfcp_qdio_sbale_req(req);
1241 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1242 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1243
1244 req->qtcb->bottom.config.feature_selection =
1245 FSF_FEATURE_CFDC |
1246 FSF_FEATURE_LUN_SHARING |
1247 FSF_FEATURE_NOTIFICATION_LOST |
1248 FSF_FEATURE_UPDATE_ALERT;
1249 req->erp_action = erp_action;
1250 req->handler = zfcp_fsf_exchange_config_data_handler;
1251 erp_action->fsf_req = req;
1252
Christof Schmitt287ac012008-07-02 10:56:40 +02001253 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254 retval = zfcp_fsf_req_send(req);
1255 if (retval) {
1256 zfcp_fsf_req_free(req);
1257 erp_action->fsf_req = NULL;
1258 }
1259out:
Christof Schmitt04062892008-10-01 12:42:20 +02001260 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001261 return retval;
1262}
1263
1264int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1265 struct fsf_qtcb_bottom_config *data)
1266{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001267 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 struct zfcp_fsf_req *req = NULL;
1269 int retval = -EIO;
1270
Christof Schmitt04062892008-10-01 12:42:20 +02001271 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 if (zfcp_fsf_req_sbal_get(adapter))
Christof Schmittada81b72009-04-17 15:08:03 +02001273 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001274
1275 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1276 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001277 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001278 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001279 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001280 }
1281
1282 sbale = zfcp_qdio_sbale_req(req);
1283 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1284 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1285 req->handler = zfcp_fsf_exchange_config_data_handler;
1286
1287 req->qtcb->bottom.config.feature_selection =
1288 FSF_FEATURE_CFDC |
1289 FSF_FEATURE_LUN_SHARING |
1290 FSF_FEATURE_NOTIFICATION_LOST |
1291 FSF_FEATURE_UPDATE_ALERT;
1292
1293 if (data)
1294 req->data = data;
1295
1296 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1297 retval = zfcp_fsf_req_send(req);
Christof Schmitt04062892008-10-01 12:42:20 +02001298 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001299 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001300 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001301
1302 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001303 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304
Christof Schmittada81b72009-04-17 15:08:03 +02001305out_unlock:
1306 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001307 return retval;
1308}
1309
1310/**
1311 * zfcp_fsf_exchange_port_data - request information about local port
1312 * @erp_action: ERP action for the adapter for which port data is requested
1313 * Returns: 0 on success, error otherwise
1314 */
1315int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1316{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001317 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001318 struct zfcp_fsf_req *req;
1319 struct zfcp_adapter *adapter = erp_action->adapter;
1320 int retval = -EIO;
1321
1322 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1323 return -EOPNOTSUPP;
1324
Christof Schmitt04062892008-10-01 12:42:20 +02001325 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001326 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 goto out;
1328 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1329 ZFCP_REQ_AUTO_CLEANUP,
1330 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001331 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001332 retval = PTR_ERR(req);
1333 goto out;
1334 }
1335
1336 sbale = zfcp_qdio_sbale_req(req);
1337 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1338 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1339
1340 req->handler = zfcp_fsf_exchange_port_data_handler;
1341 req->erp_action = erp_action;
1342 erp_action->fsf_req = req;
1343
Christof Schmitt287ac012008-07-02 10:56:40 +02001344 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 retval = zfcp_fsf_req_send(req);
1346 if (retval) {
1347 zfcp_fsf_req_free(req);
1348 erp_action->fsf_req = NULL;
1349 }
1350out:
Christof Schmitt04062892008-10-01 12:42:20 +02001351 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001352 return retval;
1353}
1354
1355/**
1356 * zfcp_fsf_exchange_port_data_sync - request information about local port
1357 * @adapter: pointer to struct zfcp_adapter
1358 * @data: pointer to struct fsf_qtcb_bottom_port
1359 * Returns: 0 on success, error otherwise
1360 */
1361int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1362 struct fsf_qtcb_bottom_port *data)
1363{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001364 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001365 struct zfcp_fsf_req *req = NULL;
1366 int retval = -EIO;
1367
1368 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1369 return -EOPNOTSUPP;
1370
Christof Schmitt04062892008-10-01 12:42:20 +02001371 spin_lock_bh(&adapter->req_q_lock);
Christof Schmitt92cab0d2009-03-02 13:08:59 +01001372 if (zfcp_fsf_req_sbal_get(adapter))
Christof Schmittada81b72009-04-17 15:08:03 +02001373 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374
1375 req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
1376 NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001377 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001378 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001379 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380 }
1381
1382 if (data)
1383 req->data = data;
1384
1385 sbale = zfcp_qdio_sbale_req(req);
1386 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1387 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1388
1389 req->handler = zfcp_fsf_exchange_port_data_handler;
1390 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1391 retval = zfcp_fsf_req_send(req);
Christof Schmitt04062892008-10-01 12:42:20 +02001392 spin_unlock_bh(&adapter->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001393
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001394 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001395 wait_for_completion(&req->completion);
1396
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001397 zfcp_fsf_req_free(req);
1398
1399 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001400
1401out_unlock:
1402 spin_unlock_bh(&adapter->req_q_lock);
1403 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001404}
1405
1406static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1407{
1408 struct zfcp_port *port = req->data;
1409 struct fsf_qtcb_header *header = &req->qtcb->header;
1410 struct fsf_plogi *plogi;
1411
1412 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001413 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001414
1415 switch (header->fsf_status) {
1416 case FSF_PORT_ALREADY_OPEN:
1417 break;
1418 case FSF_ACCESS_DENIED:
1419 zfcp_fsf_access_denied_port(req, port);
1420 break;
1421 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1422 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001423 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001424 "remote port 0x%016Lx\n",
1425 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001426 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001427 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1428 break;
1429 case FSF_ADAPTER_STATUS_AVAILABLE:
1430 switch (header->fsf_status_qual.word[0]) {
1431 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1432 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001433 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001434 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1435 break;
1436 }
1437 break;
1438 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1441 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001442 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1443 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1444 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 /* check whether D_ID has changed during open */
1446 /*
1447 * FIXME: This check is not airtight, as the FCP channel does
1448 * not monitor closures of target port connections caused on
1449 * the remote side. Thus, they might miss out on invalidating
1450 * locally cached WWPNs (and other N_Port parameters) of gone
1451 * target ports. So, our heroic attempt to make things safe
1452 * could be undermined by 'open port' response data tagged with
1453 * obsolete WWPNs. Another reason to monitor potential
1454 * connection closures ourself at least (by interpreting
1455 * incoming ELS' and unsolicited status). It just crosses my
1456 * mind that one should be able to cross-check by means of
1457 * another GID_PN straight after a port has been opened.
1458 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1459 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001460 plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001461 if (req->qtcb->bottom.support.els1_length >=
1462 FSF_PLOGI_MIN_LEN) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001463 if (plogi->serv_param.wwpn != port->wwpn)
Christof Schmittb98478d2008-12-19 16:56:59 +01001464 port->d_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001465 else {
1466 port->wwnn = plogi->serv_param.wwnn;
1467 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469 }
1470 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 break;
1474 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001475
1476out:
1477 zfcp_port_put(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480/**
1481 * zfcp_fsf_open_port - create and send open port request
1482 * @erp_action: pointer to struct zfcp_erp_action
1483 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001485int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001487 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001488 struct zfcp_adapter *adapter = erp_action->adapter;
1489 struct zfcp_fsf_req *req;
Martin Petermanna17c5852009-05-15 13:18:19 +02001490 struct zfcp_port *port = erp_action->port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001491 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Christof Schmitt04062892008-10-01 12:42:20 +02001493 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001497 req = zfcp_fsf_req_create(adapter,
1498 FSF_QTCB_OPEN_PORT_WITH_DID,
1499 ZFCP_REQ_AUTO_CLEANUP,
1500 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001501 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001502 retval = PTR_ERR(req);
1503 goto out;
1504 }
1505
1506 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1508 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1509
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510 req->handler = zfcp_fsf_open_port_handler;
Martin Petermanna17c5852009-05-15 13:18:19 +02001511 req->qtcb->bottom.support.d_id = port->d_id;
1512 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001513 req->erp_action = erp_action;
1514 erp_action->fsf_req = req;
Martin Petermanna17c5852009-05-15 13:18:19 +02001515 zfcp_port_get(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Christof Schmitt287ac012008-07-02 10:56:40 +02001517 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001520 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 erp_action->fsf_req = NULL;
Martin Petermanna17c5852009-05-15 13:18:19 +02001522 zfcp_port_put(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524out:
Christof Schmitt04062892008-10-01 12:42:20 +02001525 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return retval;
1527}
1528
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001534 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001536 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001538 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001539 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001544 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 ZFCP_STATUS_COMMON_OPEN,
1546 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001551/**
1552 * zfcp_fsf_close_port - create and send close port request
1553 * @erp_action: pointer to struct zfcp_erp_action
1554 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001556int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001558 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001559 struct zfcp_adapter *adapter = erp_action->adapter;
1560 struct zfcp_fsf_req *req;
1561 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Christof Schmitt04062892008-10-01 12:42:20 +02001563 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001564 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001567 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1568 ZFCP_REQ_AUTO_CLEANUP,
1569 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001570 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001571 retval = PTR_ERR(req);
1572 goto out;
1573 }
1574
1575 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1577 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1578
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001579 req->handler = zfcp_fsf_close_port_handler;
1580 req->data = erp_action->port;
1581 req->erp_action = erp_action;
1582 req->qtcb->header.port_handle = erp_action->port->handle;
1583 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Christof Schmitt287ac012008-07-02 10:56:40 +02001585 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001586 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001588 zfcp_fsf_req_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001591out:
Christof Schmitt04062892008-10-01 12:42:20 +02001592 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return retval;
1594}
1595
Swen Schillig5ab944f2008-10-01 12:42:17 +02001596static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1597{
1598 struct zfcp_wka_port *wka_port = req->data;
1599 struct fsf_qtcb_header *header = &req->qtcb->header;
1600
1601 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1602 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1603 goto out;
1604 }
1605
1606 switch (header->fsf_status) {
1607 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1608 dev_warn(&req->adapter->ccw_device->dev,
1609 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001610 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001611 case FSF_ADAPTER_STATUS_AVAILABLE:
1612 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001613 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 case FSF_ACCESS_DENIED:
1615 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1616 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 case FSF_GOOD:
1618 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001619 /* fall through */
1620 case FSF_PORT_ALREADY_OPEN:
Swen Schillig5ab944f2008-10-01 12:42:17 +02001621 wka_port->status = ZFCP_WKA_PORT_ONLINE;
1622 }
1623out:
1624 wake_up(&wka_port->completion_wq);
1625}
1626
1627/**
1628 * zfcp_fsf_open_wka_port - create and send open wka-port request
1629 * @wka_port: pointer to struct zfcp_wka_port
1630 * Returns: 0 on success, error otherwise
1631 */
1632int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
1633{
1634 struct qdio_buffer_element *sbale;
1635 struct zfcp_adapter *adapter = wka_port->adapter;
1636 struct zfcp_fsf_req *req;
1637 int retval = -EIO;
1638
Christof Schmitt04062892008-10-01 12:42:20 +02001639 spin_lock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001640 if (zfcp_fsf_req_sbal_get(adapter))
1641 goto out;
1642
1643 req = zfcp_fsf_req_create(adapter,
1644 FSF_QTCB_OPEN_PORT_WITH_DID,
1645 ZFCP_REQ_AUTO_CLEANUP,
1646 adapter->pool.fsf_req_erp);
1647 if (unlikely(IS_ERR(req))) {
1648 retval = PTR_ERR(req);
1649 goto out;
1650 }
1651
1652 sbale = zfcp_qdio_sbale_req(req);
1653 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1654 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1655
1656 req->handler = zfcp_fsf_open_wka_port_handler;
1657 req->qtcb->bottom.support.d_id = wka_port->d_id;
1658 req->data = wka_port;
1659
1660 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1661 retval = zfcp_fsf_req_send(req);
1662 if (retval)
1663 zfcp_fsf_req_free(req);
1664out:
Christof Schmitt04062892008-10-01 12:42:20 +02001665 spin_unlock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001666 return retval;
1667}
1668
1669static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1670{
1671 struct zfcp_wka_port *wka_port = req->data;
1672
1673 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1674 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001675 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001676 }
1677
1678 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
1679 wake_up(&wka_port->completion_wq);
1680}
1681
1682/**
1683 * zfcp_fsf_close_wka_port - create and send close wka port request
1684 * @erp_action: pointer to struct zfcp_erp_action
1685 * Returns: 0 on success, error otherwise
1686 */
1687int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
1688{
1689 struct qdio_buffer_element *sbale;
1690 struct zfcp_adapter *adapter = wka_port->adapter;
1691 struct zfcp_fsf_req *req;
1692 int retval = -EIO;
1693
Christof Schmitt04062892008-10-01 12:42:20 +02001694 spin_lock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001695 if (zfcp_fsf_req_sbal_get(adapter))
1696 goto out;
1697
1698 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
1699 ZFCP_REQ_AUTO_CLEANUP,
1700 adapter->pool.fsf_req_erp);
1701 if (unlikely(IS_ERR(req))) {
1702 retval = PTR_ERR(req);
1703 goto out;
1704 }
1705
1706 sbale = zfcp_qdio_sbale_req(req);
1707 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1708 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1709
1710 req->handler = zfcp_fsf_close_wka_port_handler;
1711 req->data = wka_port;
1712 req->qtcb->header.port_handle = wka_port->handle;
1713
1714 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1715 retval = zfcp_fsf_req_send(req);
1716 if (retval)
1717 zfcp_fsf_req_free(req);
1718out:
Christof Schmitt04062892008-10-01 12:42:20 +02001719 spin_unlock_bh(&adapter->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001720 return retval;
1721}
1722
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001723static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001725 struct zfcp_port *port = req->data;
1726 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001729 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001730 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001734 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001735 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001738 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001741 /* can't use generic zfcp_erp_modify_port_status because
1742 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1743 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1744 list_for_each_entry(unit, &port->unit_list_head, list)
1745 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1746 &unit->status);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001747 zfcp_erp_port_boxed(port, "fscpph2", req);
1748 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1749 ZFCP_STATUS_FSFREQ_RETRY;
1750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 switch (header->fsf_status_qual.word[0]) {
1754 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001755 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001757 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
1760 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 /* can't use generic zfcp_erp_modify_port_status because
1763 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1764 */
1765 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1766 list_for_each_entry(unit, &port->unit_list_head, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001767 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1768 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001773/**
1774 * zfcp_fsf_close_physical_port - close physical port
1775 * @erp_action: pointer to struct zfcp_erp_action
1776 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001778int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001780 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001781 struct zfcp_adapter *adapter = erp_action->adapter;
1782 struct zfcp_fsf_req *req;
1783 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Christof Schmitt04062892008-10-01 12:42:20 +02001785 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001786 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001789 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1790 ZFCP_REQ_AUTO_CLEANUP,
1791 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001792 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001793 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 goto out;
1795 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001796
1797 sbale = zfcp_qdio_sbale_req(req);
1798 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1799 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1800
1801 req->data = erp_action->port;
1802 req->qtcb->header.port_handle = erp_action->port->handle;
1803 req->erp_action = erp_action;
1804 req->handler = zfcp_fsf_close_physical_port_handler;
1805 erp_action->fsf_req = req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001806
Christof Schmitt287ac012008-07-02 10:56:40 +02001807 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 retval = zfcp_fsf_req_send(req);
1809 if (retval) {
1810 zfcp_fsf_req_free(req);
1811 erp_action->fsf_req = NULL;
1812 }
1813out:
Christof Schmitt04062892008-10-01 12:42:20 +02001814 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 return retval;
1816}
1817
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001818static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001820 struct zfcp_adapter *adapter = req->adapter;
1821 struct zfcp_unit *unit = req->data;
1822 struct fsf_qtcb_header *header = &req->qtcb->header;
1823 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1824 struct fsf_queue_designator *queue_designator =
1825 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001826 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001828 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001829 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001832 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 ZFCP_STATUS_UNIT_SHARED |
1834 ZFCP_STATUS_UNIT_READONLY,
1835 &unit->status);
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 switch (header->fsf_status) {
1838
1839 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001840 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001841 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001845 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001847 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001850 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001851 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1852 ZFCP_STATUS_FSFREQ_RETRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001855 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001856 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001857 "LUN 0x%Lx on port 0x%Lx is already in "
1858 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001859 (unsigned long long)unit->fcp_lun,
1860 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001861 queue_designator->cssid,
1862 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001863 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001864 zfcp_act_eval_err(adapter,
1865 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001866 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1868 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001873 "No handle is available for LUN "
1874 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001875 (unsigned long long)unit->fcp_lun,
1876 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001877 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001878 /* fall through */
1879 case FSF_INVALID_COMMAND_OPTION:
1880 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 switch (header->fsf_status_qual.word[0]) {
1884 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001885 zfcp_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 }
1891 break;
1892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001896
1897 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1898 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001899 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001900 exclusive = (bottom->lun_access_info &
1901 FSF_UNIT_ACCESS_EXCLUSIVE);
1902 readwrite = (bottom->lun_access_info &
1903 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 if (!exclusive)
1906 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1907 &unit->status);
1908
1909 if (!readwrite) {
1910 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1911 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001912 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001913 "SCSI device at LUN 0x%016Lx on port "
1914 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001915 (unsigned long long)unit->fcp_lun,
1916 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 }
1918
1919 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001921 "Exclusive read-only access not "
1922 "supported (unit 0x%016Lx, "
1923 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001924 (unsigned long long)unit->fcp_lun,
1925 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001926 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001927 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001928 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001931 "Shared read-write access not "
1932 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001933 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001934 (unsigned long long)unit->fcp_lun,
1935 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001936 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001937 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001938 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944
1945/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001946 * zfcp_fsf_open_unit - open unit
1947 * @erp_action: pointer to struct zfcp_erp_action
1948 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001950int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001952 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001953 struct zfcp_adapter *adapter = erp_action->adapter;
1954 struct zfcp_fsf_req *req;
1955 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Christof Schmitt04062892008-10-01 12:42:20 +02001957 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001958 if (zfcp_fsf_req_sbal_get(adapter))
1959 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001961 req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
1962 ZFCP_REQ_AUTO_CLEANUP,
1963 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001964 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001965 retval = PTR_ERR(req);
1966 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001967 }
1968
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001969 sbale = zfcp_qdio_sbale_req(req);
1970 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1971 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001973 req->qtcb->header.port_handle = erp_action->port->handle;
1974 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1975 req->handler = zfcp_fsf_open_unit_handler;
1976 req->data = erp_action->unit;
1977 req->erp_action = erp_action;
1978 erp_action->fsf_req = req;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001979
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001980 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1981 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Christof Schmitt287ac012008-07-02 10:56:40 +02001983 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001984 retval = zfcp_fsf_req_send(req);
1985 if (retval) {
1986 zfcp_fsf_req_free(req);
1987 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989out:
Christof Schmitt04062892008-10-01 12:42:20 +02001990 spin_unlock_bh(&adapter->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return retval;
1992}
1993
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001994static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001996 struct zfcp_unit *unit = req->data;
1997
1998 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001999 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002000
2001 switch (req->qtcb->header.fsf_status) {
2002 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002003 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2005 break;
2006 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002007 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002008 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2009 break;
2010 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002011 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002012 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2013 ZFCP_STATUS_FSFREQ_RETRY;
2014 break;
2015 case FSF_ADAPTER_STATUS_AVAILABLE:
2016 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2017 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2018 zfcp_test_link(unit->port);
2019 /* fall through */
2020 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2021 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2022 break;
2023 }
2024 break;
2025 case FSF_GOOD:
2026 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2027 break;
2028 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002029}
2030
2031/**
2032 * zfcp_fsf_close_unit - close zfcp unit
2033 * @erp_action: pointer to struct zfcp_unit
2034 * Returns: 0 on success, error otherwise
2035 */
2036int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2037{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002038 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002039 struct zfcp_adapter *adapter = erp_action->adapter;
2040 struct zfcp_fsf_req *req;
2041 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Christof Schmitt04062892008-10-01 12:42:20 +02002043 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002044 if (zfcp_fsf_req_sbal_get(adapter))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002046 req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
2047 ZFCP_REQ_AUTO_CLEANUP,
2048 adapter->pool.fsf_req_erp);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002049 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002050 retval = PTR_ERR(req);
2051 goto out;
2052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002054 sbale = zfcp_qdio_sbale_req(req);
2055 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2057
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002058 req->qtcb->header.port_handle = erp_action->port->handle;
2059 req->qtcb->header.lun_handle = erp_action->unit->handle;
2060 req->handler = zfcp_fsf_close_unit_handler;
2061 req->data = erp_action->unit;
2062 req->erp_action = erp_action;
2063 erp_action->fsf_req = req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Christof Schmitt287ac012008-07-02 10:56:40 +02002065 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002066 retval = zfcp_fsf_req_send(req);
2067 if (retval) {
2068 zfcp_fsf_req_free(req);
2069 erp_action->fsf_req = NULL;
2070 }
2071out:
Christof Schmitt04062892008-10-01 12:42:20 +02002072 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002073 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
Christof Schmittc9615852008-05-06 11:00:05 +02002076static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2077{
2078 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 lat_rec->min = min(lat_rec->min, lat);
2080 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002081}
2082
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002083static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
Christof Schmittc9615852008-05-06 11:00:05 +02002084{
2085 struct fsf_qual_latency_info *lat_inf;
2086 struct latency_cont *lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087 struct zfcp_unit *unit = req->unit;
Christof Schmittc9615852008-05-06 11:00:05 +02002088
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002089 lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002090
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002091 switch (req->qtcb->bottom.io.data_direction) {
Christof Schmittc9615852008-05-06 11:00:05 +02002092 case FSF_DATADIR_READ:
2093 lat = &unit->latencies.read;
2094 break;
2095 case FSF_DATADIR_WRITE:
2096 lat = &unit->latencies.write;
2097 break;
2098 case FSF_DATADIR_CMND:
2099 lat = &unit->latencies.cmd;
2100 break;
2101 default:
2102 return;
2103 }
2104
Christof Schmitt49f0f012009-03-02 13:08:57 +01002105 spin_lock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002106 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2107 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2108 lat->counter++;
Christof Schmitt49f0f012009-03-02 13:08:57 +01002109 spin_unlock(&unit->latencies.lock);
Christof Schmittc9615852008-05-06 11:00:05 +02002110}
2111
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002112#ifdef CONFIG_BLK_DEV_IO_TRACE
2113static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2114{
2115 struct fsf_qual_latency_info *lat_inf;
2116 struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
2117 struct request *req = scsi_cmnd->request;
2118 struct zfcp_blk_drv_data trace;
2119 int ticks = fsf_req->adapter->timer_ticks;
2120
2121 trace.flags = 0;
2122 trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2123 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2124 trace.flags |= ZFCP_BLK_LAT_VALID;
2125 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2126 trace.channel_lat = lat_inf->channel_lat * ticks;
2127 trace.fabric_lat = lat_inf->fabric_lat * ticks;
2128 }
2129 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2130 trace.flags |= ZFCP_BLK_REQ_ERROR;
2131 trace.inb_usage = fsf_req->qdio_inb_usage;
2132 trace.outb_usage = fsf_req->qdio_outb_usage;
2133
2134 blk_add_driver_data(req->q, req, &trace, sizeof(trace));
2135}
2136#else
2137static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
2138{
2139}
2140#endif
2141
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002142static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002144 struct scsi_cmnd *scpnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002146 &(req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 u32 sns_len;
Martin Petermannf76af7d72008-07-02 10:56:36 +02002148 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002151 read_lock_irqsave(&req->adapter->abort_lock, flags);
2152
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002153 scpnt = req->data;
2154 if (unlikely(!scpnt)) {
2155 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2156 return;
2157 }
2158
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002159 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002160 set_host_byte(scpnt, DID_SOFT_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 goto skip_fsfstatus;
2162 }
2163
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002165 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 goto skip_fsfstatus;
2167 }
2168
Martin Petermannfeac6a02008-07-02 10:56:35 +02002169 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002173 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
2174 zfcp_fsf_req_latency(req);
Christof Schmittc9615852008-05-06 11:00:05 +02002175
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002176 zfcp_fsf_trace_latency(req);
2177
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002179 if (fcp_rsp_info[3] == RSP_CODE_GOOD)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002180 set_host_byte(scpnt, DID_OK);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002181 else {
Martin Petermannfeac6a02008-07-02 10:56:35 +02002182 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05002183 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 }
2185 }
2186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002188 sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
2189 fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09002193 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 }
2196
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09002198 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
2199 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
2200 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02002201 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002203skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002204 if (scpnt->result != 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002205 zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002206 else if (scpnt->retries > 0)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002207 zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002208 else
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002209 zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 /*
2214 * We must hold this lock until scsi_done has been called.
2215 * Otherwise we may call scsi_done after abort regarding this
2216 * command has completed.
2217 * Note: scsi_done must not block!
2218 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002219 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002225 &(req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +02002226 char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
2229 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2230 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002234static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2235{
2236 struct zfcp_unit *unit;
2237 struct fsf_qtcb_header *header = &req->qtcb->header;
2238
2239 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2240 unit = req->data;
2241 else
2242 unit = req->unit;
2243
2244 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2245 goto skip_fsfstatus;
2246
2247 switch (header->fsf_status) {
2248 case FSF_HANDLE_MISMATCH:
2249 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002250 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2252 break;
2253 case FSF_FCPLUN_NOT_VALID:
2254 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002255 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2257 break;
2258 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2259 zfcp_fsf_class_not_supp(req);
2260 break;
2261 case FSF_ACCESS_DENIED:
2262 zfcp_fsf_access_denied_unit(req, unit);
2263 break;
2264 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2265 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002266 "Incorrect direction %d, unit 0x%016Lx on port "
2267 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002268 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002269 (unsigned long long)unit->fcp_lun,
2270 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002271 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2272 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002273 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2274 break;
2275 case FSF_CMND_LENGTH_NOT_VALID:
2276 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002277 "Incorrect CDB length %d, unit 0x%016Lx on "
2278 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002279 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002280 (unsigned long long)unit->fcp_lun,
2281 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002282 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2283 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002284 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2285 break;
2286 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002287 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002288 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2289 ZFCP_STATUS_FSFREQ_RETRY;
2290 break;
2291 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002292 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002293 req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2294 ZFCP_STATUS_FSFREQ_RETRY;
2295 break;
2296 case FSF_ADAPTER_STATUS_AVAILABLE:
2297 if (header->fsf_status_qual.word[0] ==
2298 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2299 zfcp_test_link(unit->port);
2300 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2301 break;
2302 }
2303skip_fsfstatus:
2304 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2305 zfcp_fsf_send_fcp_ctm_handler(req);
2306 else {
2307 zfcp_fsf_send_fcp_command_task_handler(req);
2308 req->unit = NULL;
2309 zfcp_unit_put(unit);
2310 }
2311}
2312
Swen Schillig7ba58c92008-10-01 12:42:18 +02002313static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
2314{
2315 u32 *fcp_dl_ptr;
2316
2317 /*
2318 * fcp_dl_addr = start address of fcp_cmnd structure +
2319 * size of fixed part + size of dynamically sized add_dcp_cdb field
2320 * SEE FCP-2 documentation
2321 */
2322 fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
2323 (fcp_cmd->add_fcp_cdb_length << 2));
2324 *fcp_dl_ptr = fcp_dl;
2325}
2326
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002327/**
2328 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002329 * @unit: unit where command is sent to
2330 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002331 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002332int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2333 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334{
2335 struct zfcp_fsf_req *req;
2336 struct fcp_cmnd_iu *fcp_cmnd_iu;
Christof Schmittbc90c862009-05-15 13:18:17 +02002337 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002338 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002339 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002340
2341 if (unlikely(!(atomic_read(&unit->status) &
2342 ZFCP_STATUS_COMMON_UNBLOCKED)))
2343 return -EBUSY;
2344
Christof Schmitt04062892008-10-01 12:42:20 +02002345 spin_lock(&adapter->req_q_lock);
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002346 if (atomic_read(&adapter->req_q.count) <= 0) {
2347 atomic_inc(&adapter->qdio_outb_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002349 }
Christof Schmitt63caf362009-03-02 13:09:00 +01002350 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
2351 ZFCP_REQ_AUTO_CLEANUP,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 adapter->pool.fsf_req_scsi);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002353 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002354 retval = PTR_ERR(req);
2355 goto out;
2356 }
2357
2358 zfcp_unit_get(unit);
2359 req->unit = unit;
2360 req->data = scsi_cmnd;
2361 req->handler = zfcp_fsf_send_fcp_command_handler;
2362 req->qtcb->header.lun_handle = unit->handle;
2363 req->qtcb->header.port_handle = unit->port->handle;
2364 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2365
2366 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2367
2368 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
2369 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2370 /*
2371 * set depending on data direction:
2372 * data direction bits in SBALE (SB Type)
2373 * data direction bits in QTCB
2374 * data direction bits in FCP_CMND IU
2375 */
2376 switch (scsi_cmnd->sc_data_direction) {
2377 case DMA_NONE:
2378 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002379 break;
2380 case DMA_FROM_DEVICE:
2381 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002382 fcp_cmnd_iu->rddata = 1;
2383 break;
2384 case DMA_TO_DEVICE:
2385 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2386 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2387 fcp_cmnd_iu->wddata = 1;
2388 break;
2389 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002390 goto failed_scsi_cmnd;
2391 }
2392
2393 if (likely((scsi_cmnd->device->simple_tags) ||
2394 ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
2395 (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
2396 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2397 else
2398 fcp_cmnd_iu->task_attribute = UNTAGGED;
2399
2400 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
2401 fcp_cmnd_iu->add_fcp_cdb_length =
2402 (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
2403
2404 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2405
2406 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002407 fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002408
2409 real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
2410 scsi_sglist(scsi_cmnd),
2411 FSF_MAX_SBALS_PER_REQ);
2412 if (unlikely(real_bytes < 0)) {
Christof Schmittbc90c862009-05-15 13:18:17 +02002413 if (req->sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002414 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002415 "Oversize data package, unit 0x%016Lx "
2416 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002417 (unsigned long long)unit->fcp_lun,
2418 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002419 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002420 retval = -EINVAL;
2421 }
2422 goto failed_scsi_cmnd;
2423 }
2424
2425 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2426
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002427 retval = zfcp_fsf_req_send(req);
2428 if (unlikely(retval))
2429 goto failed_scsi_cmnd;
2430
2431 goto out;
2432
2433failed_scsi_cmnd:
2434 zfcp_unit_put(unit);
2435 zfcp_fsf_req_free(req);
2436 scsi_cmnd->host_scribble = NULL;
2437out:
Christof Schmitt04062892008-10-01 12:42:20 +02002438 spin_unlock(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002439 return retval;
2440}
2441
2442/**
2443 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002444 * @unit: pointer to struct zfcp_unit
2445 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002446 * Returns: on success pointer to struct fsf_req, NULL otherwise
2447 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002448struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002449{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002450 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002451 struct zfcp_fsf_req *req = NULL;
2452 struct fcp_cmnd_iu *fcp_cmnd_iu;
Christof Schmitt63caf362009-03-02 13:09:00 +01002453 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002454
2455 if (unlikely(!(atomic_read(&unit->status) &
2456 ZFCP_STATUS_COMMON_UNBLOCKED)))
2457 return NULL;
2458
Christof Schmitt92cab0d2009-03-02 13:08:59 +01002459 spin_lock_bh(&adapter->req_q_lock);
2460 if (zfcp_fsf_req_sbal_get(adapter))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002461 goto out;
Christof Schmitt63caf362009-03-02 13:09:00 +01002462 req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002463 adapter->pool.fsf_req_scsi);
Swen Schillig633528c2008-11-26 18:07:37 +01002464 if (IS_ERR(req)) {
2465 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002466 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002467 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002468
2469 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2470 req->data = unit;
2471 req->handler = zfcp_fsf_send_fcp_command_handler;
2472 req->qtcb->header.lun_handle = unit->handle;
2473 req->qtcb->header.port_handle = unit->port->handle;
2474 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2475 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2476 req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
Swen Schillig7ba58c92008-10-01 12:42:18 +02002477 sizeof(u32);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002478
2479 sbale = zfcp_qdio_sbale_req(req);
2480 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2481 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2482
2483 fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
2484 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2485 fcp_cmnd_iu->task_management_flags = tm_flags;
2486
2487 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2488 if (!zfcp_fsf_req_send(req))
2489 goto out;
2490
2491 zfcp_fsf_req_free(req);
2492 req = NULL;
2493out:
Christof Schmitt92cab0d2009-03-02 13:08:59 +01002494 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002495 return req;
2496}
2497
2498static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2499{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002500}
2501
2502/**
2503 * zfcp_fsf_control_file - control file upload/download
2504 * @adapter: pointer to struct zfcp_adapter
2505 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2506 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002508struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2509 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002511 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002512 struct zfcp_fsf_req *req = NULL;
2513 struct fsf_qtcb_bottom_support *bottom;
2514 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Christof Schmitt45633fd2008-06-10 18:20:55 +02002516 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2517 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Christof Schmitt45633fd2008-06-10 18:20:55 +02002519 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2521 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2524 direction = SBAL_FLAGS0_TYPE_READ;
2525 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002527 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 }
2529
Christof Schmitt04062892008-10-01 12:42:20 +02002530 spin_lock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002531 if (zfcp_fsf_req_sbal_get(adapter))
2532 goto out;
2533
2534 req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002535 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002537 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 }
2539
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002540 req->handler = zfcp_fsf_control_file_handler;
2541
2542 sbale = zfcp_qdio_sbale_req(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 sbale[0].flags |= direction;
2544
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002545 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002547 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002549 bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
2550 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002551 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002552 zfcp_fsf_req_free(req);
2553 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002556 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2557 retval = zfcp_fsf_req_send(req);
2558out:
Christof Schmitt04062892008-10-01 12:42:20 +02002559 spin_unlock_bh(&adapter->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002560
2561 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002562 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002563 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002565 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002567
2568/**
2569 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2570 * @adapter: pointer to struct zfcp_adapter
2571 * @sbal_idx: response queue index of SBAL to be processed
2572 */
2573void zfcp_fsf_reqid_check(struct zfcp_adapter *adapter, int sbal_idx)
2574{
2575 struct qdio_buffer *sbal = adapter->resp_q.sbal[sbal_idx];
2576 struct qdio_buffer_element *sbale;
2577 struct zfcp_fsf_req *fsf_req;
2578 unsigned long flags, req_id;
2579 int idx;
2580
2581 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2582
2583 sbale = &sbal->element[idx];
2584 req_id = (unsigned long) sbale->addr;
2585 spin_lock_irqsave(&adapter->req_list_lock, flags);
2586 fsf_req = zfcp_reqlist_find(adapter, req_id);
2587
2588 if (!fsf_req)
2589 /*
2590 * Unknown request means that we have potentially memory
2591 * corruption and must stop the machine immediately.
2592 */
2593 panic("error: unknown req_id (%lx) on adapter %s.\n",
2594 req_id, dev_name(&adapter->ccw_device->dev));
2595
2596 list_del(&fsf_req->list);
2597 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2598
2599 fsf_req->sbal_response = sbal_idx;
2600 fsf_req->qdio_inb_usage = atomic_read(&adapter->resp_q.count);
2601 zfcp_fsf_req_complete(fsf_req);
2602
2603 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2604 break;
2605 }
2606}