blob: e5ff45fbb8ae7ac8051226209fba4318ecd1b83e [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>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010013#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010015#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020016#include "zfcp_dbf.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010017#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
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)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200115 if (likely(req->qtcb))
116 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200117 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200118 return;
119 }
120
Swen Schilliga4623c42009-08-18 15:43:15 +0200121 if (likely(req->qtcb))
122 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
123 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200126static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Swen Schilligecf0c772009-11-24 16:53:58 +0100128 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200129 struct fsf_status_read_buffer *sr_buf = req->data;
130 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100132 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Swen Schilligecf0c772009-11-24 16:53:58 +0100134 read_lock_irqsave(&adapter->port_list_lock, flags);
135 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200136 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100137 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100138 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200139 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100140 read_unlock_irqrestore(&adapter->port_list_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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200148 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
149 return;
150
151 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200152
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100153 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200154
155 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200157
158 switch (link_down->error_code) {
159 case FSF_PSQ_LINK_NO_LIGHT:
160 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200161 "There is no light signal from the local "
162 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200163 break;
164 case FSF_PSQ_LINK_WRAP_PLUG:
165 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200166 "There is a wrap plug instead of a fibre "
167 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200168 break;
169 case FSF_PSQ_LINK_NO_FCP:
170 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200171 "The adjacent fibre channel node does not "
172 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200173 break;
174 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
175 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200176 "The FCP device is suspended because of a "
177 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200178 break;
179 case FSF_PSQ_LINK_INVALID_WWPN:
180 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200181 "The FCP device detected a WWPN that is "
182 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200183 break;
184 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
185 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200186 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200187 break;
188 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
189 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200190 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200191 break;
192 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
193 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200194 "The adjacent switch cannot support "
195 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200196 break;
197 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
198 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200199 "The FCP adapter could not log in to the "
200 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200201 break;
202 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
203 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200204 "The WWPN assignment file on the FCP adapter "
205 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200206 break;
207 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
208 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200209 "The mode table on the FCP adapter "
210 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200211 break;
212 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
213 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200214 "All NPIV ports on the FCP adapter have "
215 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200216 break;
217 default:
218 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200219 "The link between the FCP adapter and "
220 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200221 }
222out:
223 zfcp_erp_adapter_failed(adapter, id, req);
224}
225
226static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
227{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200228 struct fsf_status_read_buffer *sr_buf = req->data;
229 struct fsf_link_down_info *ldi =
230 (struct fsf_link_down_info *) &sr_buf->payload;
231
232 switch (sr_buf->status_subtype) {
233 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100234 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200235 break;
236 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100237 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200238 break;
239 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100240 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200241 };
242}
243
244static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
245{
246 struct zfcp_adapter *adapter = req->adapter;
247 struct fsf_status_read_buffer *sr_buf = req->data;
248
249 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200250 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200251 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200252 zfcp_fsf_req_free(req);
253 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Swen Schillig57717102009-08-18 15:43:21 +0200256 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200257
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200258 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200260 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200263 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200268 dev_warn(&adapter->ccw_device->dev,
269 "The error threshold for checksum statistics "
270 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200271 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200274 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200277 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200278 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100280 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 ZFCP_STATUS_COMMON_RUNNING,
282 ZFCP_SET);
283 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200284 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
285 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100286 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100288 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200289 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100290 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
291 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200292 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100293 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100294 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100296 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200298 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200299 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200300 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200302
Swen Schilliga4623c42009-08-18 15:43:15 +0200303 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200305
306 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200307 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200310static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200312 switch (req->qtcb->header.fsf_status_qual.word[0]) {
313 case FSF_SQ_FCP_RSP_AVAILABLE:
314 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
315 case FSF_SQ_NO_RETRY_POSSIBLE:
316 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
317 return;
318 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200319 break;
320 case FSF_SQ_NO_RECOM:
321 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200322 "The FCP adapter reported a problem "
323 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100324 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200325 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200327 /* all non-return stats set FSFREQ_ERROR*/
328 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
329}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200331static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
332{
333 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
334 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200335
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200336 switch (req->qtcb->header.fsf_status) {
337 case FSF_UNKNOWN_COMMAND:
338 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200339 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200340 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100341 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200345 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200350static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352 struct zfcp_adapter *adapter = req->adapter;
353 struct fsf_qtcb *qtcb = req->qtcb;
354 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Swen Schillig57717102009-08-18 15:43:21 +0200356 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200358 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100359 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200363 switch (qtcb->prefix.prot_status) {
364 case FSF_PROT_GOOD:
365 case FSF_PROT_FSF_STATUS_PRESENTED:
366 return;
367 case FSF_PROT_QTCB_VERSION_ERROR:
368 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200369 "QTCB version 0x%x not supported by FCP adapter "
370 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
371 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100372 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200374 case FSF_PROT_ERROR_STATE:
375 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100376 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100377 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200379 case FSF_PROT_UNSUPP_QTCB_TYPE:
380 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200381 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100382 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200384 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
385 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
386 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200388 case FSF_PROT_DUPLICATE_REQUEST_ID:
389 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200390 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200391 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100392 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200394 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100395 zfcp_fsf_link_down_info_eval(req, "fspse_5",
396 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100397 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100398 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200400 case FSF_PROT_REEST_QUEUE:
401 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100402 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200403 ZFCP_STATUS_COMMON_RUNNING,
404 ZFCP_SET);
405 zfcp_erp_adapter_reopen(adapter,
406 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100407 ZFCP_STATUS_COMMON_ERP_FAILED,
408 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200409 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200411 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200412 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100414 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
419/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200420 * zfcp_fsf_req_complete - process completion of a FSF request
421 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200423 * When a request has been completed either from the FCP adapter,
424 * or it has been dismissed due to a queue shutdown, this function
425 * is called to process the completion status and trigger further
426 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200428static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200429{
430 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
431 zfcp_fsf_status_read_handler(req);
432 return;
433 }
434
435 del_timer(&req->timer);
436 zfcp_fsf_protstatus_eval(req);
437 zfcp_fsf_fsfstatus_eval(req);
438 req->handler(req);
439
440 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200441 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200442
443 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
444 zfcp_fsf_req_free(req);
445 else
Swen Schillig058b8642009-08-18 15:43:14 +0200446 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200447}
448
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200449/**
450 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
451 * @adapter: pointer to struct zfcp_adapter
452 *
453 * Never ever call this without shutting down the adapter first.
454 * Otherwise the adapter would continue using and corrupting s390 storage.
455 * Included BUG_ON() call to ensure this is done.
456 * ERP is supposed to be the only user of this function.
457 */
458void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
459{
460 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200461 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200462
463 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100464 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200465
466 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
467 list_del(&req->list);
468 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
469 zfcp_fsf_req_complete(req);
470 }
471}
472
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200473static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100475 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200476 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200477 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100478 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100480 /* adjust pointers for missing command code */
481 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
482 - sizeof(u32));
483 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
484 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200485
486 if (req->data)
487 memcpy(req->data, bottom, sizeof(*bottom));
488
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100489 fc_host_port_name(shost) = nsp->fl_wwpn;
490 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100491 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200492 fc_host_speed(shost) = bottom->fc_link_speed;
493 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
Christof Schmitt0fdd2132009-11-24 16:54:17 +0100494 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
495 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200496
497 adapter->hydra_version = bottom->adapter_type;
498 adapter->timer_ticks = bottom->timer_interval;
499
500 if (fc_host_permanent_port_name(shost) == -1)
501 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
502
503 switch (bottom->fc_topology) {
504 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100505 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100506 adapter->peer_wwpn = plogi->fl_wwpn;
507 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200509 break;
510 case FSF_TOPO_FABRIC:
511 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 break;
513 case FSF_TOPO_AL:
514 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200515 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200518 "Unknown or unsupported arbitrated loop "
519 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100520 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200521 return -EIO;
522 }
523
524 return 0;
525}
526
527static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
528{
529 struct zfcp_adapter *adapter = req->adapter;
530 struct fsf_qtcb *qtcb = req->qtcb;
531 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
532 struct Scsi_Host *shost = adapter->scsi_host;
533
534 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
535 return;
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200538 adapter->adapter_features = bottom->adapter_features;
539 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500540 adapter->peer_wwpn = 0;
541 adapter->peer_wwnn = 0;
542 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200544 switch (qtcb->header.fsf_status) {
545 case FSF_GOOD:
546 if (zfcp_fsf_exchange_config_evaluate(req))
547 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200548
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200549 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
550 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200551 "FCP adapter maximum QTCB size (%d bytes) "
552 "is too small\n",
553 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100554 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200555 return;
556 }
557 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
558 &adapter->status);
559 break;
560 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200561 fc_host_node_name(shost) = 0;
562 fc_host_port_name(shost) = 0;
563 fc_host_port_id(shost) = 0;
564 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100565 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200567
568 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
569 &adapter->status);
570
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100571 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200572 &qtcb->header.fsf_status_qual.link_down_info);
573 break;
574 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100575 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200576 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200579 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200581 memcpy(fc_host_serial_number(shost), bottom->serial_number,
582 min(FC_SERIAL_NUMBER_SIZE, 17));
583 EBCASC(fc_host_serial_number(shost),
584 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200587 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200588 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200589 "The FCP adapter only supports newer "
590 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100591 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200592 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200594 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200595 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200596 "The FCP adapter only supports older "
597 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100598 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604 struct zfcp_adapter *adapter = req->adapter;
605 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
606 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200608 if (req->data)
609 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100610
Christof Schmitt02829852009-03-02 13:09:06 +0100611 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100612 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100613 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
614 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100615 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
616 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
617 fc_host_supported_speeds(shost) = bottom->supported_speed;
618}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200620static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200622 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100623
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return;
626
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200627 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 case FSF_GOOD:
629 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200630 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100633 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637}
638
Swen Schillig564e1c82009-08-18 15:43:19 +0200639static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200640{
Swen Schillig564e1c82009-08-18 15:43:19 +0200641 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200642
Swen Schillig564e1c82009-08-18 15:43:19 +0200643 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200644 if (atomic_read(&req_q->count))
645 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200646 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200647 return 0;
648}
649
Swen Schillig564e1c82009-08-18 15:43:19 +0200650static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200651{
Swen Schillig564e1c82009-08-18 15:43:19 +0200652 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200653 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200654
Swen Schillig564e1c82009-08-18 15:43:19 +0200655 spin_unlock_bh(&qdio->req_q_lock);
656 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
657 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658 if (ret > 0)
659 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200660 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200661 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200662 /* assume hanging outbound queue, try queue recovery */
663 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
664 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200665
Swen Schillig564e1c82009-08-18 15:43:19 +0200666 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200667 return -EIO;
668}
669
Swen Schilliga4623c42009-08-18 15:43:15 +0200670static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200671{
672 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200673
674 if (likely(pool))
675 req = mempool_alloc(pool, GFP_ATOMIC);
676 else
677 req = kmalloc(sizeof(*req), GFP_ATOMIC);
678
679 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200680 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200681
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200682 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100683 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684 return req;
685}
686
Swen Schilliga4623c42009-08-18 15:43:15 +0200687static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200688{
Swen Schilliga4623c42009-08-18 15:43:15 +0200689 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200690
691 if (likely(pool))
692 qtcb = mempool_alloc(pool, GFP_ATOMIC);
693 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200694 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
695
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200696 if (unlikely(!qtcb))
697 return NULL;
698
699 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200700 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200701}
702
Swen Schillig564e1c82009-08-18 15:43:19 +0200703static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Swen Schillig09a46c62009-08-18 15:43:16 +0200704 u32 fsf_cmd, mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200706 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +0200707 struct zfcp_qdio_queue *req_q = &qdio->req_q;
708 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200709 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200710
711 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200712 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200713
714 if (adapter->req_no == 0)
715 adapter->req_no++;
716
717 INIT_LIST_HEAD(&req->list);
718 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200719 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200720
721 req->adapter = adapter;
722 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100723 req->req_id = adapter->req_no;
Swen Schillig42428f72009-08-18 15:43:18 +0200724 req->queue_req.sbal_number = 1;
725 req->queue_req.sbal_first = req_q->first;
726 req->queue_req.sbal_last = req_q->first;
727 req->queue_req.sbale_curr = 1;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200728
Swen Schillig564e1c82009-08-18 15:43:19 +0200729 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200730 sbale[0].addr = (void *) req->req_id;
731 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
732
Swen Schilliga4623c42009-08-18 15:43:15 +0200733 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
734 if (likely(pool))
735 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
736 else
737 req->qtcb = zfcp_qtcb_alloc(NULL);
738
739 if (unlikely(!req->qtcb)) {
740 zfcp_fsf_req_free(req);
741 return ERR_PTR(-ENOMEM);
742 }
743
Swen Schillig564e1c82009-08-18 15:43:19 +0200744 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200745 req->qtcb->prefix.req_id = req->req_id;
746 req->qtcb->prefix.ulp_info = 26;
747 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
748 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
749 req->qtcb->header.req_handle = req->req_id;
750 req->qtcb->header.fsf_command = req->fsf_command;
751 req->seq_no = adapter->fsf_req_seq_no;
752 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
753 sbale[1].addr = (void *) req->qtcb;
754 sbale[1].length = sizeof(struct fsf_qtcb);
755 }
756
757 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
758 zfcp_fsf_req_free(req);
759 return ERR_PTR(-EIO);
760 }
761
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200762 return req;
763}
764
765static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
766{
767 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200768 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100769 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100770 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200771
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100772 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200773
Swen Schillig564e1c82009-08-18 15:43:19 +0200774 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200775 req->issued = get_clock();
Swen Schillig564e1c82009-08-18 15:43:19 +0200776 if (zfcp_qdio_send(qdio, &req->queue_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100778 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100779 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100780 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 return -EIO;
782 }
783
784 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200785 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200786 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100787 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200788
789 return 0;
790}
791
792/**
793 * zfcp_fsf_status_read - send status read request
794 * @adapter: pointer to struct zfcp_adapter
795 * @req_flags: request flags
796 * Returns: 0 on success, ERROR otherwise
797 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200798int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200799{
Swen Schillig564e1c82009-08-18 15:43:19 +0200800 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200801 struct zfcp_fsf_req *req;
802 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200803 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200804 int retval = -EIO;
805
Swen Schillig564e1c82009-08-18 15:43:19 +0200806 spin_lock_bh(&qdio->req_q_lock);
807 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Swen Schillig564e1c82009-08-18 15:43:19 +0200810 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200811 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200812 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200813 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 goto out;
815 }
816
Swen Schillig564e1c82009-08-18 15:43:19 +0200817 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
Swen Schillig42428f72009-08-18 15:43:18 +0200819 req->queue_req.sbale_curr = 2;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820
Swen Schilliga4623c42009-08-18 15:43:15 +0200821 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 if (!sr_buf) {
823 retval = -ENOMEM;
824 goto failed_buf;
825 }
826 memset(sr_buf, 0, sizeof(*sr_buf));
827 req->data = sr_buf;
Swen Schillig564e1c82009-08-18 15:43:19 +0200828 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829 sbale->addr = (void *) sr_buf;
830 sbale->length = sizeof(*sr_buf);
831
832 retval = zfcp_fsf_req_send(req);
833 if (retval)
834 goto failed_req_send;
835
836 goto out;
837
838failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200839 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200840failed_buf:
841 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200842 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200844 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 return retval;
846}
847
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200850 struct zfcp_unit *unit = req->data;
851 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200853 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
854 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200856 switch (req->qtcb->header.fsf_status) {
857 case FSF_PORT_HANDLE_NOT_VALID:
858 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100859 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
860 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200864 case FSF_LUN_HANDLE_NOT_VALID:
865 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100866 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200867 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
871 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100874 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100875 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876 break;
877 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100878 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200880 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200884 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200885 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 break;
889 }
890 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200892 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
893 break;
894 }
895}
896
897/**
898 * zfcp_fsf_abort_fcp_command - abort running SCSI command
899 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200900 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200901 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 */
903
904struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100905 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200906{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200907 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200909 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910
Swen Schillig564e1c82009-08-18 15:43:19 +0200911 spin_lock_bh(&qdio->req_q_lock);
912 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200914 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
915 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100916 if (IS_ERR(req)) {
917 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200918 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100919 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920
921 if (unlikely(!(atomic_read(&unit->status) &
922 ZFCP_STATUS_COMMON_UNBLOCKED)))
923 goto out_error_free;
924
Swen Schillig564e1c82009-08-18 15:43:19 +0200925 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200926 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
927 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
928
929 req->data = unit;
930 req->handler = zfcp_fsf_abort_fcp_command_handler;
931 req->qtcb->header.lun_handle = unit->handle;
932 req->qtcb->header.port_handle = unit->port->handle;
933 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
934
935 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
936 if (!zfcp_fsf_req_send(req))
937 goto out;
938
939out_error_free:
940 zfcp_fsf_req_free(req);
941 req = NULL;
942out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200943 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200944 return req;
945}
946
947static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
948{
949 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100950 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200951 struct fsf_qtcb_header *header = &req->qtcb->header;
952
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100953 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200954
955 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
956 goto skip_fsfstatus;
957
958 switch (header->fsf_status) {
959 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200960 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100961 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200962 break;
963 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
964 zfcp_fsf_class_not_supp(req);
965 break;
966 case FSF_ADAPTER_STATUS_AVAILABLE:
967 switch (header->fsf_status_qual.word[0]){
968 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200969 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
970 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
971 break;
972 }
973 break;
974 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200975 break;
976 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100977 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200978 break;
979 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100980 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200981 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200982 case FSF_GENERIC_COMMAND_REJECTED:
983 case FSF_PAYLOAD_SIZE_MISMATCH:
984 case FSF_REQUEST_SIZE_TOO_LARGE:
985 case FSF_RESPONSE_SIZE_TOO_LARGE:
986 case FSF_SBAL_MISMATCH:
987 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
988 break;
989 }
990
991skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100992 if (ct->handler)
993 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994}
995
Christof Schmitt426f6052009-07-13 15:06:06 +0200996static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
997 struct scatterlist *sg_req,
998 struct scatterlist *sg_resp)
999{
1000 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1001 sbale[2].addr = sg_virt(sg_req);
1002 sbale[2].length = sg_req->length;
1003 sbale[3].addr = sg_virt(sg_resp);
1004 sbale[3].length = sg_resp->length;
1005 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1006}
1007
1008static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1009{
1010 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1011}
1012
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001013static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1014 struct scatterlist *sg_req,
1015 struct scatterlist *sg_resp,
1016 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001017{
Swen Schillig42428f72009-08-18 15:43:18 +02001018 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001019 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
Swen Schillig42428f72009-08-18 15:43:18 +02001020 &req->queue_req);
1021 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001022 int bytes;
1023
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001024 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001025 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001026 return -EOPNOTSUPP;
1027
Christof Schmitt426f6052009-07-13 15:06:06 +02001028 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1029 return 0;
1030 }
1031
1032 /* use single, unchained SBAL if it can hold the request */
1033 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1034 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001035 return 0;
1036 }
1037
Swen Schillig564e1c82009-08-18 15:43:19 +02001038 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001039 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001040 sg_req, max_sbals);
1041 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001042 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001043 req->qtcb->bottom.support.req_buf_length = bytes;
Swen Schillig42428f72009-08-18 15:43:18 +02001044 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045
Swen Schillig564e1c82009-08-18 15:43:19 +02001046 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001047 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001048 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +02001049 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001050 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001051 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001052
Christof Schmittb1a58982009-09-24 10:23:21 +02001053 return 0;
1054}
1055
1056static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1057 struct scatterlist *sg_req,
1058 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001059 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001060{
1061 int ret;
1062
1063 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1064 if (ret)
1065 return ret;
1066
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001067 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001068 if (timeout > 255)
1069 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001070 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001071 req->qtcb->bottom.support.timeout = timeout;
1072 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001073
1074 return 0;
1075}
1076
1077/**
1078 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1079 * @ct: pointer to struct zfcp_send_ct with data for request
1080 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001081 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001082int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001083 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1084 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001085{
Swen Schillig564e1c82009-08-18 15:43:19 +02001086 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 struct zfcp_fsf_req *req;
1088 int ret = -EIO;
1089
Swen Schillig564e1c82009-08-18 15:43:19 +02001090 spin_lock_bh(&qdio->req_q_lock);
1091 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001092 goto out;
1093
Swen Schillig564e1c82009-08-18 15:43:19 +02001094 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001095
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001096 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001097 ret = PTR_ERR(req);
1098 goto out;
1099 }
1100
Swen Schillig09a46c62009-08-18 15:43:16 +02001101 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001102 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001103 FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001104 if (ret)
1105 goto failed_send;
1106
1107 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001108 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001109 req->data = ct;
1110
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001111 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001112
1113 ret = zfcp_fsf_req_send(req);
1114 if (ret)
1115 goto failed_send;
1116
1117 goto out;
1118
1119failed_send:
1120 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001121out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001122 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001123 return ret;
1124}
1125
1126static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1127{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001128 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001129 struct zfcp_port *port = send_els->port;
1130 struct fsf_qtcb_header *header = &req->qtcb->header;
1131
1132 send_els->status = -EINVAL;
1133
1134 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1135 goto skip_fsfstatus;
1136
1137 switch (header->fsf_status) {
1138 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001139 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001140 send_els->status = 0;
1141 break;
1142 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1143 zfcp_fsf_class_not_supp(req);
1144 break;
1145 case FSF_ADAPTER_STATUS_AVAILABLE:
1146 switch (header->fsf_status_qual.word[0]){
1147 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001148 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1149 case FSF_SQ_RETRY_IF_POSSIBLE:
1150 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1151 break;
1152 }
1153 break;
1154 case FSF_ELS_COMMAND_REJECTED:
1155 case FSF_PAYLOAD_SIZE_MISMATCH:
1156 case FSF_REQUEST_SIZE_TOO_LARGE:
1157 case FSF_RESPONSE_SIZE_TOO_LARGE:
1158 break;
1159 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001160 if (port)
1161 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162 break;
1163 case FSF_SBAL_MISMATCH:
1164 /* should never occure, avoided in zfcp_fsf_send_els */
1165 /* fall through */
1166 default:
1167 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1168 break;
1169 }
1170skip_fsfstatus:
1171 if (send_els->handler)
1172 send_els->handler(send_els->handler_data);
1173}
1174
1175/**
1176 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1177 * @els: pointer to struct zfcp_send_els with data for the command
1178 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001179int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001180 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001181{
1182 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001183 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001184 int ret = -EIO;
1185
Swen Schillig564e1c82009-08-18 15:43:19 +02001186 spin_lock_bh(&qdio->req_q_lock);
1187 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001188 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001189
Swen Schillig564e1c82009-08-18 15:43:19 +02001190 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001191
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001192 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001193 ret = PTR_ERR(req);
1194 goto out;
1195 }
1196
Swen Schillig09a46c62009-08-18 15:43:16 +02001197 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001198 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001199
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001200 if (ret)
1201 goto failed_send;
1202
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001203 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001204 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001205 req->data = els;
1206
Swen Schillig57717102009-08-18 15:43:21 +02001207 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001208
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209 ret = zfcp_fsf_req_send(req);
1210 if (ret)
1211 goto failed_send;
1212
1213 goto out;
1214
1215failed_send:
1216 zfcp_fsf_req_free(req);
1217out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001218 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 return ret;
1220}
1221
1222int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1223{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001224 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001226 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001227 int retval = -EIO;
1228
Swen Schillig564e1c82009-08-18 15:43:19 +02001229 spin_lock_bh(&qdio->req_q_lock);
1230 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001231 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001232
Swen Schillig564e1c82009-08-18 15:43:19 +02001233 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1234 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001235
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001236 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001237 retval = PTR_ERR(req);
1238 goto out;
1239 }
1240
Swen Schillig09a46c62009-08-18 15:43:16 +02001241 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001242 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001243 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1244 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1245
1246 req->qtcb->bottom.config.feature_selection =
1247 FSF_FEATURE_CFDC |
1248 FSF_FEATURE_LUN_SHARING |
1249 FSF_FEATURE_NOTIFICATION_LOST |
1250 FSF_FEATURE_UPDATE_ALERT;
1251 req->erp_action = erp_action;
1252 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001253 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254
Christof Schmitt287ac012008-07-02 10:56:40 +02001255 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001256 retval = zfcp_fsf_req_send(req);
1257 if (retval) {
1258 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001259 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260 }
1261out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001262 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001263 return retval;
1264}
1265
Swen Schillig564e1c82009-08-18 15:43:19 +02001266int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001267 struct fsf_qtcb_bottom_config *data)
1268{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001269 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001270 struct zfcp_fsf_req *req = NULL;
1271 int retval = -EIO;
1272
Swen Schillig564e1c82009-08-18 15:43:19 +02001273 spin_lock_bh(&qdio->req_q_lock);
1274 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001275 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001276
Swen Schillig564e1c82009-08-18 15:43:19 +02001277 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001278
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001279 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001280 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001281 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282 }
1283
Swen Schillig564e1c82009-08-18 15:43:19 +02001284 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001285 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1286 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1287 req->handler = zfcp_fsf_exchange_config_data_handler;
1288
1289 req->qtcb->bottom.config.feature_selection =
1290 FSF_FEATURE_CFDC |
1291 FSF_FEATURE_LUN_SHARING |
1292 FSF_FEATURE_NOTIFICATION_LOST |
1293 FSF_FEATURE_UPDATE_ALERT;
1294
1295 if (data)
1296 req->data = data;
1297
1298 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1299 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001300 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001301 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001302 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001303
1304 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001305 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001306
Christof Schmittada81b72009-04-17 15:08:03 +02001307out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001308 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001309 return retval;
1310}
1311
1312/**
1313 * zfcp_fsf_exchange_port_data - request information about local port
1314 * @erp_action: ERP action for the adapter for which port data is requested
1315 * Returns: 0 on success, error otherwise
1316 */
1317int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1318{
Swen Schillig564e1c82009-08-18 15:43:19 +02001319 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schillig44cc76f2008-10-01 12:42:16 +02001320 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001321 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001322 int retval = -EIO;
1323
Swen Schillig564e1c82009-08-18 15:43:19 +02001324 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001325 return -EOPNOTSUPP;
1326
Swen Schillig564e1c82009-08-18 15:43:19 +02001327 spin_lock_bh(&qdio->req_q_lock);
1328 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001330
Swen Schillig564e1c82009-08-18 15:43:19 +02001331 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1332 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001333
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001334 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001335 retval = PTR_ERR(req);
1336 goto out;
1337 }
1338
Swen Schillig09a46c62009-08-18 15:43:16 +02001339 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001340 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001341 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1342 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1343
1344 req->handler = zfcp_fsf_exchange_port_data_handler;
1345 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001346 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001347
Christof Schmitt287ac012008-07-02 10:56:40 +02001348 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001349 retval = zfcp_fsf_req_send(req);
1350 if (retval) {
1351 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001352 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001353 }
1354out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001355 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001356 return retval;
1357}
1358
1359/**
1360 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001361 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001362 * @data: pointer to struct fsf_qtcb_bottom_port
1363 * Returns: 0 on success, error otherwise
1364 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001365int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001366 struct fsf_qtcb_bottom_port *data)
1367{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001368 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001369 struct zfcp_fsf_req *req = NULL;
1370 int retval = -EIO;
1371
Swen Schillig564e1c82009-08-18 15:43:19 +02001372 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001373 return -EOPNOTSUPP;
1374
Swen Schillig564e1c82009-08-18 15:43:19 +02001375 spin_lock_bh(&qdio->req_q_lock);
1376 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001377 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001378
Swen Schillig564e1c82009-08-18 15:43:19 +02001379 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001380
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001381 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001382 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001383 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001384 }
1385
1386 if (data)
1387 req->data = data;
1388
Swen Schillig564e1c82009-08-18 15:43:19 +02001389 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001390 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1391 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1392
1393 req->handler = zfcp_fsf_exchange_port_data_handler;
1394 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1395 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001396 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001397
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001398 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001399 wait_for_completion(&req->completion);
1400
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001401 zfcp_fsf_req_free(req);
1402
1403 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001404
1405out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001406 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001407 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001408}
1409
1410static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1411{
1412 struct zfcp_port *port = req->data;
1413 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001414 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001415
1416 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001417 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001418
1419 switch (header->fsf_status) {
1420 case FSF_PORT_ALREADY_OPEN:
1421 break;
1422 case FSF_ACCESS_DENIED:
1423 zfcp_fsf_access_denied_port(req, port);
1424 break;
1425 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1426 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001427 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001428 "remote port 0x%016Lx\n",
1429 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001430 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001431 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1432 break;
1433 case FSF_ADAPTER_STATUS_AVAILABLE:
1434 switch (header->fsf_status_qual.word[0]) {
1435 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1436 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001437 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1439 break;
1440 }
1441 break;
1442 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1445 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001446 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1447 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1448 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 /* check whether D_ID has changed during open */
1450 /*
1451 * FIXME: This check is not airtight, as the FCP channel does
1452 * not monitor closures of target port connections caused on
1453 * the remote side. Thus, they might miss out on invalidating
1454 * locally cached WWPNs (and other N_Port parameters) of gone
1455 * target ports. So, our heroic attempt to make things safe
1456 * could be undermined by 'open port' response data tagged with
1457 * obsolete WWPNs. Another reason to monitor potential
1458 * connection closures ourself at least (by interpreting
1459 * incoming ELS' and unsolicited status). It just crosses my
1460 * mind that one should be able to cross-check by means of
1461 * another GID_PN straight after a port has been opened.
1462 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1463 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001464 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001465 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001466 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001467 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 break;
1472 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001473
1474out:
Swen Schilligf3450c72009-11-24 16:53:59 +01001475 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001478/**
1479 * zfcp_fsf_open_port - create and send open port request
1480 * @erp_action: pointer to struct zfcp_erp_action
1481 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001483int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001485 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001486 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001487 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001488 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001489 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Swen Schillig564e1c82009-08-18 15:43:19 +02001491 spin_lock_bh(&qdio->req_q_lock);
1492 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Swen Schillig564e1c82009-08-18 15:43:19 +02001495 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1496 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001497
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001498 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499 retval = PTR_ERR(req);
1500 goto out;
1501 }
1502
Swen Schillig09a46c62009-08-18 15:43:16 +02001503 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001504 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1506 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1507
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001508 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001509 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001510 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001511 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001512 erp_action->fsf_req_id = req->req_id;
Swen Schilligf3450c72009-11-24 16:53:59 +01001513 get_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Christof Schmitt287ac012008-07-02 10:56:40 +02001515 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001516 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001519 erp_action->fsf_req_id = 0;
Swen Schilligf3450c72009-11-24 16:53:59 +01001520 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001522out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001523 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 return retval;
1525}
1526
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001527static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001532 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001534 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001536 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001537 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001542 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ZFCP_STATUS_COMMON_OPEN,
1544 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001549/**
1550 * zfcp_fsf_close_port - create and send close port request
1551 * @erp_action: pointer to struct zfcp_erp_action
1552 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001554int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001556 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001557 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001558 struct zfcp_fsf_req *req;
1559 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Swen Schillig564e1c82009-08-18 15:43:19 +02001561 spin_lock_bh(&qdio->req_q_lock);
1562 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Swen Schillig564e1c82009-08-18 15:43:19 +02001565 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1566 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001567
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001568 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001569 retval = PTR_ERR(req);
1570 goto out;
1571 }
1572
Swen Schillig09a46c62009-08-18 15:43:16 +02001573 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001574 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1576 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1577
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001578 req->handler = zfcp_fsf_close_port_handler;
1579 req->data = erp_action->port;
1580 req->erp_action = erp_action;
1581 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001582 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Christof Schmitt287ac012008-07-02 10:56:40 +02001584 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001585 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001587 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001588 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001590out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001591 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return retval;
1593}
1594
Swen Schillig5ab944f2008-10-01 12:42:17 +02001595static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1596{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001597 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598 struct fsf_qtcb_header *header = &req->qtcb->header;
1599
1600 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001601 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001602 goto out;
1603 }
1604
1605 switch (header->fsf_status) {
1606 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1607 dev_warn(&req->adapter->ccw_device->dev,
1608 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001609 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001610 case FSF_ADAPTER_STATUS_AVAILABLE:
1611 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001612 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001613 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001614 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001615 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 case FSF_GOOD:
1617 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001618 /* fall through */
1619 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001620 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001621 }
1622out:
1623 wake_up(&wka_port->completion_wq);
1624}
1625
1626/**
1627 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001628 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001629 * Returns: 0 on success, error otherwise
1630 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001631int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001632{
1633 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001634 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001635 struct zfcp_fsf_req *req;
1636 int retval = -EIO;
1637
Swen Schillig564e1c82009-08-18 15:43:19 +02001638 spin_lock_bh(&qdio->req_q_lock);
1639 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001640 goto out;
1641
Swen Schillig564e1c82009-08-18 15:43:19 +02001642 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1643 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001644
Swen Schillig5ab944f2008-10-01 12:42:17 +02001645 if (unlikely(IS_ERR(req))) {
1646 retval = PTR_ERR(req);
1647 goto out;
1648 }
1649
Swen Schillig09a46c62009-08-18 15:43:16 +02001650 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001651 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001652 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1653 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1654
1655 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001656 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001657 req->data = wka_port;
1658
1659 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1660 retval = zfcp_fsf_req_send(req);
1661 if (retval)
1662 zfcp_fsf_req_free(req);
1663out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001664 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001665 return retval;
1666}
1667
1668static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1669{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001670 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001671
1672 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1673 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001674 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001675 }
1676
Christof Schmittbd0072e2009-11-24 16:54:11 +01001677 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001678 wake_up(&wka_port->completion_wq);
1679}
1680
1681/**
1682 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001683 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001684 * Returns: 0 on success, error otherwise
1685 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001686int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001687{
1688 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001689 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001690 struct zfcp_fsf_req *req;
1691 int retval = -EIO;
1692
Swen Schillig564e1c82009-08-18 15:43:19 +02001693 spin_lock_bh(&qdio->req_q_lock);
1694 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001695 goto out;
1696
Swen Schillig564e1c82009-08-18 15:43:19 +02001697 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1698 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001699
Swen Schillig5ab944f2008-10-01 12:42:17 +02001700 if (unlikely(IS_ERR(req))) {
1701 retval = PTR_ERR(req);
1702 goto out;
1703 }
1704
Swen Schillig09a46c62009-08-18 15:43:16 +02001705 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001706 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001707 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:
Swen Schillig564e1c82009-08-18 15:43:19 +02001719 spin_unlock_bh(&qdio->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);
Swen Schilligecf0c772009-11-24 16:53:58 +01001744 read_lock(&port->unit_list_lock);
1745 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001746 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1747 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001748 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001749 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001750 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
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);
Swen Schilligecf0c772009-11-24 16:53:58 +01001766 read_lock(&port->unit_list_lock);
1767 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001768 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1769 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001770 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773}
1774
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001775/**
1776 * zfcp_fsf_close_physical_port - close physical port
1777 * @erp_action: pointer to struct zfcp_erp_action
1778 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001780int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001782 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001783 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001784 struct zfcp_fsf_req *req;
1785 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Swen Schillig564e1c82009-08-18 15:43:19 +02001787 spin_lock_bh(&qdio->req_q_lock);
1788 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Swen Schillig564e1c82009-08-18 15:43:19 +02001791 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1792 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001793
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001794 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001795 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 goto out;
1797 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001798
Swen Schillig09a46c62009-08-18 15:43:16 +02001799 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001800 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001801 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1802 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1803
1804 req->data = erp_action->port;
1805 req->qtcb->header.port_handle = erp_action->port->handle;
1806 req->erp_action = erp_action;
1807 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001808 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809
Christof Schmitt287ac012008-07-02 10:56:40 +02001810 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001811 retval = zfcp_fsf_req_send(req);
1812 if (retval) {
1813 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001814 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001815 }
1816out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001817 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 return retval;
1819}
1820
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001821static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823 struct zfcp_adapter *adapter = req->adapter;
1824 struct zfcp_unit *unit = req->data;
1825 struct fsf_qtcb_header *header = &req->qtcb->header;
1826 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1827 struct fsf_queue_designator *queue_designator =
1828 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001829 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001831 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001832 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001835 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 ZFCP_STATUS_UNIT_SHARED |
1837 ZFCP_STATUS_UNIT_READONLY,
1838 &unit->status);
1839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 switch (header->fsf_status) {
1841
1842 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001843 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001844 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001848 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001850 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001853 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001854 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001857 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001858 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001859 "LUN 0x%Lx on port 0x%Lx is already in "
1860 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001861 (unsigned long long)unit->fcp_lun,
1862 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001863 queue_designator->cssid,
1864 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001865 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001866 zfcp_act_eval_err(adapter,
1867 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001868 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1870 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001871 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001874 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001875 "No handle is available for LUN "
1876 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001877 (unsigned long long)unit->fcp_lun,
1878 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001879 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001880 /* fall through */
1881 case FSF_INVALID_COMMAND_OPTION:
1882 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 switch (header->fsf_status_qual.word[0]) {
1886 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001887 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001890 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
1893 break;
1894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001898
1899 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1900 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001901 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001902 exclusive = (bottom->lun_access_info &
1903 FSF_UNIT_ACCESS_EXCLUSIVE);
1904 readwrite = (bottom->lun_access_info &
1905 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 if (!exclusive)
1908 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1909 &unit->status);
1910
1911 if (!readwrite) {
1912 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1913 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001914 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001915 "SCSI device at LUN 0x%016Lx on port "
1916 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001917 (unsigned long long)unit->fcp_lun,
1918 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 }
1920
1921 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001922 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001923 "Exclusive read-only access not "
1924 "supported (unit 0x%016Lx, "
1925 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001926 (unsigned long long)unit->fcp_lun,
1927 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001928 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001930 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001933 "Shared read-write access not "
1934 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001935 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001936 (unsigned long long)unit->fcp_lun,
1937 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001938 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001940 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 }
1942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945}
1946
1947/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001948 * zfcp_fsf_open_unit - open unit
1949 * @erp_action: pointer to struct zfcp_erp_action
1950 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001952int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001954 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001955 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001956 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001957 struct zfcp_fsf_req *req;
1958 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Swen Schillig564e1c82009-08-18 15:43:19 +02001960 spin_lock_bh(&qdio->req_q_lock);
1961 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001962 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Swen Schillig564e1c82009-08-18 15:43:19 +02001964 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Swen Schilliga4623c42009-08-18 15:43:15 +02001965 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001966
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001967 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001968 retval = PTR_ERR(req);
1969 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001970 }
1971
Swen Schillig09a46c62009-08-18 15:43:16 +02001972 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001973 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001974 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1975 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001977 req->qtcb->header.port_handle = erp_action->port->handle;
1978 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1979 req->handler = zfcp_fsf_open_unit_handler;
1980 req->data = erp_action->unit;
1981 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001982 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001983
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001984 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1985 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Christof Schmitt287ac012008-07-02 10:56:40 +02001987 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001988 retval = zfcp_fsf_req_send(req);
1989 if (retval) {
1990 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001991 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001993out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001994 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 return retval;
1996}
1997
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001998static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002000 struct zfcp_unit *unit = req->data;
2001
2002 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02002003 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004
2005 switch (req->qtcb->header.fsf_status) {
2006 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002007 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002008 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2009 break;
2010 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002011 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002012 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2013 break;
2014 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002015 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002016 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002017 break;
2018 case FSF_ADAPTER_STATUS_AVAILABLE:
2019 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2020 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002021 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002022 /* fall through */
2023 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2024 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2025 break;
2026 }
2027 break;
2028 case FSF_GOOD:
2029 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2030 break;
2031 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002032}
2033
2034/**
2035 * zfcp_fsf_close_unit - close zfcp unit
2036 * @erp_action: pointer to struct zfcp_unit
2037 * Returns: 0 on success, error otherwise
2038 */
2039int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2040{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002041 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002042 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002043 struct zfcp_fsf_req *req;
2044 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Swen Schillig564e1c82009-08-18 15:43:19 +02002046 spin_lock_bh(&qdio->req_q_lock);
2047 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002049
Swen Schillig564e1c82009-08-18 15:43:19 +02002050 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2051 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002052
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002053 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002054 retval = PTR_ERR(req);
2055 goto out;
2056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Swen Schillig09a46c62009-08-18 15:43:16 +02002058 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02002059 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002060 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2062
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002063 req->qtcb->header.port_handle = erp_action->port->handle;
2064 req->qtcb->header.lun_handle = erp_action->unit->handle;
2065 req->handler = zfcp_fsf_close_unit_handler;
2066 req->data = erp_action->unit;
2067 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002068 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Christof Schmitt287ac012008-07-02 10:56:40 +02002070 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002071 retval = zfcp_fsf_req_send(req);
2072 if (retval) {
2073 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002074 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002075 }
2076out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002077 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002078 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
Christof Schmittc9615852008-05-06 11:00:05 +02002081static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2082{
2083 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002084 lat_rec->min = min(lat_rec->min, lat);
2085 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002086}
2087
Christof Schmittd9742b42009-11-24 16:54:03 +01002088static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002089{
Christof Schmittd9742b42009-11-24 16:54:03 +01002090 struct fsf_qual_latency_info *lat_in;
2091 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002092 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002093 struct zfcp_blk_drv_data blktrc;
2094 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002095
Christof Schmittd9742b42009-11-24 16:54:03 +01002096 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002097
Christof Schmittd9742b42009-11-24 16:54:03 +01002098 blktrc.flags = 0;
2099 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2100 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2101 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2102 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2103 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2104
2105 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2106 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2107 blktrc.channel_lat = lat_in->channel_lat * ticks;
2108 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2109
2110 switch (req->qtcb->bottom.io.data_direction) {
2111 case FSF_DATADIR_READ:
2112 lat = &unit->latencies.read;
2113 break;
2114 case FSF_DATADIR_WRITE:
2115 lat = &unit->latencies.write;
2116 break;
2117 case FSF_DATADIR_CMND:
2118 lat = &unit->latencies.cmd;
2119 break;
2120 }
2121
2122 if (lat) {
2123 spin_lock(&unit->latencies.lock);
2124 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2125 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2126 lat->counter++;
2127 spin_unlock(&unit->latencies.lock);
2128 }
Christof Schmittc9615852008-05-06 11:00:05 +02002129 }
2130
Christof Schmittd9742b42009-11-24 16:54:03 +01002131 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2132 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002133}
2134
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002135static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002137 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002138 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002141 read_lock_irqsave(&req->adapter->abort_lock, flags);
2142
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002143 scpnt = req->data;
2144 if (unlikely(!scpnt)) {
2145 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2146 return;
2147 }
2148
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002149 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002150 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 goto skip_fsfstatus;
2152 }
2153
Christof Schmitt4318e082009-11-24 16:54:08 +01002154 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2155 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Christof Schmittd9742b42009-11-24 16:54:03 +01002157 zfcp_fsf_req_trace(req, scpnt);
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002158
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002159skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002160 if (scpnt->result != 0)
Swen Schillig57717102009-08-18 15:43:21 +02002161 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002162 else if (scpnt->retries > 0)
Swen Schillig57717102009-08-18 15:43:21 +02002163 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002164 else
Swen Schillig57717102009-08-18 15:43:21 +02002165 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 /*
2170 * We must hold this lock until scsi_done has been called.
2171 * Otherwise we may call scsi_done after abort regarding this
2172 * command has completed.
2173 * Note: scsi_done must not block!
2174 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002175 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002178static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
Christof Schmitt4318e082009-11-24 16:54:08 +01002180 struct fcp_resp_with_ext *fcp_rsp;
2181 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Christof Schmitt4318e082009-11-24 16:54:08 +01002183 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2184 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2185
2186 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002187 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2188 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
2191
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002192static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2193{
2194 struct zfcp_unit *unit;
2195 struct fsf_qtcb_header *header = &req->qtcb->header;
2196
2197 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2198 unit = req->data;
2199 else
2200 unit = req->unit;
2201
2202 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2203 goto skip_fsfstatus;
2204
2205 switch (header->fsf_status) {
2206 case FSF_HANDLE_MISMATCH:
2207 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002208 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002209 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2210 break;
2211 case FSF_FCPLUN_NOT_VALID:
2212 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002213 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002214 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2215 break;
2216 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2217 zfcp_fsf_class_not_supp(req);
2218 break;
2219 case FSF_ACCESS_DENIED:
2220 zfcp_fsf_access_denied_unit(req, unit);
2221 break;
2222 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2223 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002224 "Incorrect direction %d, unit 0x%016Lx on port "
2225 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002227 (unsigned long long)unit->fcp_lun,
2228 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002229 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2230 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002231 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2232 break;
2233 case FSF_CMND_LENGTH_NOT_VALID:
2234 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002235 "Incorrect CDB length %d, unit 0x%016Lx on "
2236 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002237 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002238 (unsigned long long)unit->fcp_lun,
2239 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002240 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2241 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002242 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2243 break;
2244 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002245 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002246 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002247 break;
2248 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002249 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002250 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 break;
2252 case FSF_ADAPTER_STATUS_AVAILABLE:
2253 if (header->fsf_status_qual.word[0] ==
2254 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002255 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2257 break;
2258 }
2259skip_fsfstatus:
2260 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2261 zfcp_fsf_send_fcp_ctm_handler(req);
2262 else {
2263 zfcp_fsf_send_fcp_command_task_handler(req);
2264 req->unit = NULL;
Swen Schilligf3450c72009-11-24 16:53:59 +01002265 put_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002266 }
2267}
2268
2269/**
2270 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002271 * @unit: unit where command is sent to
2272 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002273 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002274int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2275 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002276{
2277 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002278 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002279 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002280 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002281 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002282 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002283
2284 if (unlikely(!(atomic_read(&unit->status) &
2285 ZFCP_STATUS_COMMON_UNBLOCKED)))
2286 return -EBUSY;
2287
Swen Schillig564e1c82009-08-18 15:43:19 +02002288 spin_lock(&qdio->req_q_lock);
2289 if (atomic_read(&qdio->req_q.count) <= 0) {
2290 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002291 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002292 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002293
Swen Schillig564e1c82009-08-18 15:43:19 +02002294 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Swen Schilliga4623c42009-08-18 15:43:15 +02002295 adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002296
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002297 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002298 retval = PTR_ERR(req);
2299 goto out;
2300 }
2301
Swen Schillig09a46c62009-08-18 15:43:16 +02002302 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligf3450c72009-11-24 16:53:59 +01002303 get_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002304 req->unit = unit;
2305 req->data = scsi_cmnd;
2306 req->handler = zfcp_fsf_send_fcp_command_handler;
2307 req->qtcb->header.lun_handle = unit->handle;
2308 req->qtcb->header.port_handle = unit->port->handle;
2309 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002310 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002311
2312 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2313
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002314 /*
2315 * set depending on data direction:
2316 * data direction bits in SBALE (SB Type)
2317 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002318 */
2319 switch (scsi_cmnd->sc_data_direction) {
2320 case DMA_NONE:
2321 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002322 break;
2323 case DMA_FROM_DEVICE:
2324 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002325 break;
2326 case DMA_TO_DEVICE:
2327 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2328 sbtype = SBAL_FLAGS0_TYPE_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002329 break;
2330 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002331 goto failed_scsi_cmnd;
2332 }
2333
Christof Schmitt4318e082009-11-24 16:54:08 +01002334 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2335 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002336
Swen Schillig564e1c82009-08-18 15:43:19 +02002337 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002338 scsi_sglist(scsi_cmnd),
2339 FSF_MAX_SBALS_PER_REQ);
2340 if (unlikely(real_bytes < 0)) {
Swen Schillig42428f72009-08-18 15:43:18 +02002341 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002342 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002343 "Oversize data package, unit 0x%016Lx "
2344 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002345 (unsigned long long)unit->fcp_lun,
2346 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002347 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 retval = -EINVAL;
2349 }
2350 goto failed_scsi_cmnd;
2351 }
2352
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353 retval = zfcp_fsf_req_send(req);
2354 if (unlikely(retval))
2355 goto failed_scsi_cmnd;
2356
2357 goto out;
2358
2359failed_scsi_cmnd:
Swen Schilligf3450c72009-11-24 16:53:59 +01002360 put_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361 zfcp_fsf_req_free(req);
2362 scsi_cmnd->host_scribble = NULL;
2363out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002364 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002365 return retval;
2366}
2367
2368/**
2369 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002370 * @unit: pointer to struct zfcp_unit
2371 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002372 * Returns: on success pointer to struct fsf_req, NULL otherwise
2373 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002374struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002375{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002376 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002378 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002379 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002380
2381 if (unlikely(!(atomic_read(&unit->status) &
2382 ZFCP_STATUS_COMMON_UNBLOCKED)))
2383 return NULL;
2384
Swen Schillig564e1c82009-08-18 15:43:19 +02002385 spin_lock_bh(&qdio->req_q_lock);
2386 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002387 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002388
Swen Schillig564e1c82009-08-18 15:43:19 +02002389 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2390 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002391
Swen Schillig633528c2008-11-26 18:07:37 +01002392 if (IS_ERR(req)) {
2393 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002394 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002395 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002396
2397 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2398 req->data = unit;
2399 req->handler = zfcp_fsf_send_fcp_command_handler;
2400 req->qtcb->header.lun_handle = unit->handle;
2401 req->qtcb->header.port_handle = unit->port->handle;
2402 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2403 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002404 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002405
Swen Schillig564e1c82009-08-18 15:43:19 +02002406 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002407 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2408 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2409
Christof Schmitt4318e082009-11-24 16:54:08 +01002410 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2411 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002412
2413 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2414 if (!zfcp_fsf_req_send(req))
2415 goto out;
2416
2417 zfcp_fsf_req_free(req);
2418 req = NULL;
2419out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002420 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002421 return req;
2422}
2423
2424static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2425{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002426}
2427
2428/**
2429 * zfcp_fsf_control_file - control file upload/download
2430 * @adapter: pointer to struct zfcp_adapter
2431 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2432 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002434struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2435 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002437 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002438 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002439 struct zfcp_fsf_req *req = NULL;
2440 struct fsf_qtcb_bottom_support *bottom;
2441 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Christof Schmitt45633fd2008-06-10 18:20:55 +02002443 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2444 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Christof Schmitt45633fd2008-06-10 18:20:55 +02002446 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2448 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2451 direction = SBAL_FLAGS0_TYPE_READ;
2452 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002454 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
2456
Swen Schillig564e1c82009-08-18 15:43:19 +02002457 spin_lock_bh(&qdio->req_q_lock);
2458 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002459 goto out;
2460
Swen Schillig564e1c82009-08-18 15:43:19 +02002461 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002462 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002464 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 }
2466
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002467 req->handler = zfcp_fsf_control_file_handler;
2468
Swen Schillig564e1c82009-08-18 15:43:19 +02002469 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 sbale[0].flags |= direction;
2471
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002472 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002474 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Swen Schillig564e1c82009-08-18 15:43:19 +02002476 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2477 direction, fsf_cfdc->sg,
2478 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002479 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002480 zfcp_fsf_req_free(req);
2481 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002484 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2485 retval = zfcp_fsf_req_send(req);
2486out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002487 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002488
2489 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002490 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002491 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002493 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002495
2496/**
2497 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2498 * @adapter: pointer to struct zfcp_adapter
2499 * @sbal_idx: response queue index of SBAL to be processed
2500 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002501void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002502{
Swen Schillig564e1c82009-08-18 15:43:19 +02002503 struct zfcp_adapter *adapter = qdio->adapter;
2504 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002505 struct qdio_buffer_element *sbale;
2506 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002507 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002508 int idx;
2509
2510 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2511
2512 sbale = &sbal->element[idx];
2513 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002514 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002515
2516 if (!fsf_req)
2517 /*
2518 * Unknown request means that we have potentially memory
2519 * corruption and must stop the machine immediately.
2520 */
2521 panic("error: unknown req_id (%lx) on adapter %s.\n",
2522 req_id, dev_name(&adapter->ccw_device->dev));
2523
Swen Schillig42428f72009-08-18 15:43:18 +02002524 fsf_req->queue_req.sbal_response = sbal_idx;
2525 fsf_req->queue_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002526 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002527 zfcp_fsf_req_complete(fsf_req);
2528
2529 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2530 break;
2531 }
2532}