blob: 8a0705ac52a164ccb279da92194003740bb6fa9f [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 Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2002, 2010
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;
494
495 adapter->hydra_version = bottom->adapter_type;
496 adapter->timer_ticks = bottom->timer_interval;
497
498 if (fc_host_permanent_port_name(shost) == -1)
499 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
500
501 switch (bottom->fc_topology) {
502 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100503 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100504 adapter->peer_wwpn = plogi->fl_wwpn;
505 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200506 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200507 break;
508 case FSF_TOPO_FABRIC:
509 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200510 break;
511 case FSF_TOPO_AL:
512 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200513 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200515 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200516 "Unknown or unsupported arbitrated loop "
517 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100518 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 return -EIO;
520 }
521
522 return 0;
523}
524
525static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
526{
527 struct zfcp_adapter *adapter = req->adapter;
528 struct fsf_qtcb *qtcb = req->qtcb;
529 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
530 struct Scsi_Host *shost = adapter->scsi_host;
531
532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
533 return;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200536 adapter->adapter_features = bottom->adapter_features;
537 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500538 adapter->peer_wwpn = 0;
539 adapter->peer_wwnn = 0;
540 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200542 switch (qtcb->header.fsf_status) {
543 case FSF_GOOD:
544 if (zfcp_fsf_exchange_config_evaluate(req))
545 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200546
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200547 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
548 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200549 "FCP adapter maximum QTCB size (%d bytes) "
550 "is too small\n",
551 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100552 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200553 return;
554 }
555 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
556 &adapter->status);
557 break;
558 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200559 fc_host_node_name(shost) = 0;
560 fc_host_port_name(shost) = 0;
561 fc_host_port_id(shost) = 0;
562 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100563 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200565
566 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
567 &adapter->status);
568
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100569 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200570 &qtcb->header.fsf_status_qual.link_down_info);
571 break;
572 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100573 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200574 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
576
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200577 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200579 memcpy(fc_host_serial_number(shost), bottom->serial_number,
580 min(FC_SERIAL_NUMBER_SIZE, 17));
581 EBCASC(fc_host_serial_number(shost),
582 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
584
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200585 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200586 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200587 "The FCP adapter only supports newer "
588 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100589 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200590 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200592 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200593 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200594 "The FCP adapter only supports older "
595 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100596 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200600static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602 struct zfcp_adapter *adapter = req->adapter;
603 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
604 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200606 if (req->data)
607 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100608
Christof Schmitt02829852009-03-02 13:09:06 +0100609 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100610 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100611 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
612 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100613 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
614 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
615 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100616 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
617 FC_FC4_LIST_SIZE);
618 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
619 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100620}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200622static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100625
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return;
628
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200629 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200630 case FSF_GOOD:
631 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200632 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200634 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100635 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639}
640
Swen Schillig564e1c82009-08-18 15:43:19 +0200641static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200642{
Swen Schillig564e1c82009-08-18 15:43:19 +0200643 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200644
Swen Schillig564e1c82009-08-18 15:43:19 +0200645 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200646 if (atomic_read(&req_q->count))
647 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200648 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200649 return 0;
650}
651
Swen Schillig564e1c82009-08-18 15:43:19 +0200652static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200653{
Swen Schillig564e1c82009-08-18 15:43:19 +0200654 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200655 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656
Swen Schillig564e1c82009-08-18 15:43:19 +0200657 spin_unlock_bh(&qdio->req_q_lock);
658 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
659 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200660 if (ret > 0)
661 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200662 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200663 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200664 /* assume hanging outbound queue, try queue recovery */
665 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
666 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200667
Swen Schillig564e1c82009-08-18 15:43:19 +0200668 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200669 return -EIO;
670}
671
Swen Schilliga4623c42009-08-18 15:43:15 +0200672static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200673{
674 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200675
676 if (likely(pool))
677 req = mempool_alloc(pool, GFP_ATOMIC);
678 else
679 req = kmalloc(sizeof(*req), GFP_ATOMIC);
680
681 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200682 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200683
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100685 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200686 return req;
687}
688
Swen Schilliga4623c42009-08-18 15:43:15 +0200689static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200690{
Swen Schilliga4623c42009-08-18 15:43:15 +0200691 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692
693 if (likely(pool))
694 qtcb = mempool_alloc(pool, GFP_ATOMIC);
695 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200696 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
697
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200698 if (unlikely(!qtcb))
699 return NULL;
700
701 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200702 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200703}
704
Swen Schillig564e1c82009-08-18 15:43:19 +0200705static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Swen Schillig09a46c62009-08-18 15:43:16 +0200706 u32 fsf_cmd, mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200708 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +0200709 struct zfcp_qdio_queue *req_q = &qdio->req_q;
710 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200711 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200712
713 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200714 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200715
716 if (adapter->req_no == 0)
717 adapter->req_no++;
718
719 INIT_LIST_HEAD(&req->list);
720 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200721 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200722
723 req->adapter = adapter;
724 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100725 req->req_id = adapter->req_no;
Swen Schillig42428f72009-08-18 15:43:18 +0200726 req->queue_req.sbal_number = 1;
727 req->queue_req.sbal_first = req_q->first;
728 req->queue_req.sbal_last = req_q->first;
729 req->queue_req.sbale_curr = 1;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200730
Swen Schillig564e1c82009-08-18 15:43:19 +0200731 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732 sbale[0].addr = (void *) req->req_id;
733 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
734
Swen Schilliga4623c42009-08-18 15:43:15 +0200735 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
736 if (likely(pool))
737 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
738 else
739 req->qtcb = zfcp_qtcb_alloc(NULL);
740
741 if (unlikely(!req->qtcb)) {
742 zfcp_fsf_req_free(req);
743 return ERR_PTR(-ENOMEM);
744 }
745
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100746 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200747 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200748 req->qtcb->prefix.req_id = req->req_id;
749 req->qtcb->prefix.ulp_info = 26;
750 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
751 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
752 req->qtcb->header.req_handle = req->req_id;
753 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200754 sbale[1].addr = (void *) req->qtcb;
755 sbale[1].length = sizeof(struct fsf_qtcb);
756 }
757
758 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
759 zfcp_fsf_req_free(req);
760 return ERR_PTR(-EIO);
761 }
762
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200763 return req;
764}
765
766static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
767{
768 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200769 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100770 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100771 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100773 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200774
Swen Schillig564e1c82009-08-18 15:43:19 +0200775 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200776 req->issued = get_clock();
Swen Schillig564e1c82009-08-18 15:43:19 +0200777 if (zfcp_qdio_send(qdio, &req->queue_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100779 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100780 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100781 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200782 return -EIO;
783 }
784
785 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200786 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200787 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100788 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200789
790 return 0;
791}
792
793/**
794 * zfcp_fsf_status_read - send status read request
795 * @adapter: pointer to struct zfcp_adapter
796 * @req_flags: request flags
797 * Returns: 0 on success, ERROR otherwise
798 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200799int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200800{
Swen Schillig564e1c82009-08-18 15:43:19 +0200801 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200802 struct zfcp_fsf_req *req;
803 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200804 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200805 int retval = -EIO;
806
Swen Schillig564e1c82009-08-18 15:43:19 +0200807 spin_lock_bh(&qdio->req_q_lock);
808 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Swen Schillig564e1c82009-08-18 15:43:19 +0200811 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200812 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200813 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 goto out;
816 }
817
Swen Schillig564e1c82009-08-18 15:43:19 +0200818 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200819 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
Swen Schillig42428f72009-08-18 15:43:18 +0200820 req->queue_req.sbale_curr = 2;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821
Swen Schilliga4623c42009-08-18 15:43:15 +0200822 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 if (!sr_buf) {
824 retval = -ENOMEM;
825 goto failed_buf;
826 }
827 memset(sr_buf, 0, sizeof(*sr_buf));
828 req->data = sr_buf;
Swen Schillig564e1c82009-08-18 15:43:19 +0200829 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830 sbale->addr = (void *) sr_buf;
831 sbale->length = sizeof(*sr_buf);
832
833 retval = zfcp_fsf_req_send(req);
834 if (retval)
835 goto failed_req_send;
836
837 goto out;
838
839failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200840 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841failed_buf:
842 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200843 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200844out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200845 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return retval;
847}
848
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200849static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 struct zfcp_unit *unit = req->data;
852 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200854 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
855 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857 switch (req->qtcb->header.fsf_status) {
858 case FSF_PORT_HANDLE_NOT_VALID:
859 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100860 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
861 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 case FSF_LUN_HANDLE_NOT_VALID:
866 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100867 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200868 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200871 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
872 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200874 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100875 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200877 break;
878 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100879 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100880 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200883 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200885 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200886 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200888 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 break;
890 }
891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200893 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
894 break;
895 }
896}
897
898/**
899 * zfcp_fsf_abort_fcp_command - abort running SCSI command
900 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200901 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 */
904
905struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100906 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200907{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200908 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200909 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200910 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911
Swen Schillig564e1c82009-08-18 15:43:19 +0200912 spin_lock_bh(&qdio->req_q_lock);
913 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200914 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200915 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
916 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100917 if (IS_ERR(req)) {
918 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200919 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100920 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921
922 if (unlikely(!(atomic_read(&unit->status) &
923 ZFCP_STATUS_COMMON_UNBLOCKED)))
924 goto out_error_free;
925
Swen Schillig564e1c82009-08-18 15:43:19 +0200926 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
928 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
929
930 req->data = unit;
931 req->handler = zfcp_fsf_abort_fcp_command_handler;
932 req->qtcb->header.lun_handle = unit->handle;
933 req->qtcb->header.port_handle = unit->port->handle;
934 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
935
936 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
937 if (!zfcp_fsf_req_send(req))
938 goto out;
939
940out_error_free:
941 zfcp_fsf_req_free(req);
942 req = NULL;
943out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200944 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200945 return req;
946}
947
948static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
949{
950 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100951 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200952 struct fsf_qtcb_header *header = &req->qtcb->header;
953
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100954 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200955
956 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
957 goto skip_fsfstatus;
958
959 switch (header->fsf_status) {
960 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200961 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100962 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200963 break;
964 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
965 zfcp_fsf_class_not_supp(req);
966 break;
967 case FSF_ADAPTER_STATUS_AVAILABLE:
968 switch (header->fsf_status_qual.word[0]){
969 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200970 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
971 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
972 break;
973 }
974 break;
975 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200976 break;
977 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100978 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200979 break;
980 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100981 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200982 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200983 case FSF_GENERIC_COMMAND_REJECTED:
984 case FSF_PAYLOAD_SIZE_MISMATCH:
985 case FSF_REQUEST_SIZE_TOO_LARGE:
986 case FSF_RESPONSE_SIZE_TOO_LARGE:
987 case FSF_SBAL_MISMATCH:
988 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
989 break;
990 }
991
992skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100993 if (ct->handler)
994 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200995}
996
Christof Schmitt426f6052009-07-13 15:06:06 +0200997static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
998 struct scatterlist *sg_req,
999 struct scatterlist *sg_resp)
1000{
1001 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1002 sbale[2].addr = sg_virt(sg_req);
1003 sbale[2].length = sg_req->length;
1004 sbale[3].addr = sg_virt(sg_resp);
1005 sbale[3].length = sg_resp->length;
1006 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1007}
1008
1009static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1010{
1011 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1012}
1013
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001014static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1015 struct scatterlist *sg_req,
1016 struct scatterlist *sg_resp,
1017 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001018{
Swen Schillig42428f72009-08-18 15:43:18 +02001019 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001020 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
Swen Schillig42428f72009-08-18 15:43:18 +02001021 &req->queue_req);
1022 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001023 int bytes;
1024
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001025 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001026 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001027 return -EOPNOTSUPP;
1028
Christof Schmitt426f6052009-07-13 15:06:06 +02001029 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1030 return 0;
1031 }
1032
1033 /* use single, unchained SBAL if it can hold the request */
1034 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1035 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001036 return 0;
1037 }
1038
Swen Schillig564e1c82009-08-18 15:43:19 +02001039 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001040 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001041 sg_req, max_sbals);
1042 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001043 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044 req->qtcb->bottom.support.req_buf_length = bytes;
Swen Schillig42428f72009-08-18 15:43:18 +02001045 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001046
Swen Schillig564e1c82009-08-18 15:43:19 +02001047 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001048 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001049 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +02001050 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001051 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001052 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001053
Christof Schmittb1a58982009-09-24 10:23:21 +02001054 return 0;
1055}
1056
1057static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1058 struct scatterlist *sg_req,
1059 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001060 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001061{
1062 int ret;
1063
1064 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1065 if (ret)
1066 return ret;
1067
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001068 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001069 if (timeout > 255)
1070 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001071 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001072 req->qtcb->bottom.support.timeout = timeout;
1073 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001074
1075 return 0;
1076}
1077
1078/**
1079 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1080 * @ct: pointer to struct zfcp_send_ct with data for request
1081 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001082 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001083int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001084 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1085 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001086{
Swen Schillig564e1c82009-08-18 15:43:19 +02001087 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001088 struct zfcp_fsf_req *req;
1089 int ret = -EIO;
1090
Swen Schillig564e1c82009-08-18 15:43:19 +02001091 spin_lock_bh(&qdio->req_q_lock);
1092 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001093 goto out;
1094
Swen Schillig564e1c82009-08-18 15:43:19 +02001095 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001096
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001097 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001098 ret = PTR_ERR(req);
1099 goto out;
1100 }
1101
Swen Schillig09a46c62009-08-18 15:43:16 +02001102 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001103 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001104 FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001105 if (ret)
1106 goto failed_send;
1107
1108 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001109 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001110 req->data = ct;
1111
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001112 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001113
1114 ret = zfcp_fsf_req_send(req);
1115 if (ret)
1116 goto failed_send;
1117
1118 goto out;
1119
1120failed_send:
1121 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001122out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001123 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001124 return ret;
1125}
1126
1127static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1128{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001129 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001130 struct zfcp_port *port = send_els->port;
1131 struct fsf_qtcb_header *header = &req->qtcb->header;
1132
1133 send_els->status = -EINVAL;
1134
1135 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1136 goto skip_fsfstatus;
1137
1138 switch (header->fsf_status) {
1139 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001140 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001141 send_els->status = 0;
1142 break;
1143 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1144 zfcp_fsf_class_not_supp(req);
1145 break;
1146 case FSF_ADAPTER_STATUS_AVAILABLE:
1147 switch (header->fsf_status_qual.word[0]){
1148 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001149 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1150 case FSF_SQ_RETRY_IF_POSSIBLE:
1151 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1152 break;
1153 }
1154 break;
1155 case FSF_ELS_COMMAND_REJECTED:
1156 case FSF_PAYLOAD_SIZE_MISMATCH:
1157 case FSF_REQUEST_SIZE_TOO_LARGE:
1158 case FSF_RESPONSE_SIZE_TOO_LARGE:
1159 break;
1160 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001161 if (port)
1162 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163 break;
1164 case FSF_SBAL_MISMATCH:
1165 /* should never occure, avoided in zfcp_fsf_send_els */
1166 /* fall through */
1167 default:
1168 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1169 break;
1170 }
1171skip_fsfstatus:
1172 if (send_els->handler)
1173 send_els->handler(send_els->handler_data);
1174}
1175
1176/**
1177 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1178 * @els: pointer to struct zfcp_send_els with data for the command
1179 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001180int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001181 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182{
1183 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001184 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001185 int ret = -EIO;
1186
Swen Schillig564e1c82009-08-18 15:43:19 +02001187 spin_lock_bh(&qdio->req_q_lock);
1188 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001190
Swen Schillig564e1c82009-08-18 15:43:19 +02001191 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001192
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001193 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001194 ret = PTR_ERR(req);
1195 goto out;
1196 }
1197
Swen Schillig09a46c62009-08-18 15:43:16 +02001198 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001199 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001200
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001201 if (ret)
1202 goto failed_send;
1203
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001204 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001205 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 req->data = els;
1207
Swen Schillig57717102009-08-18 15:43:21 +02001208 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210 ret = zfcp_fsf_req_send(req);
1211 if (ret)
1212 goto failed_send;
1213
1214 goto out;
1215
1216failed_send:
1217 zfcp_fsf_req_free(req);
1218out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001219 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001220 return ret;
1221}
1222
1223int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1224{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001225 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001226 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001227 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228 int retval = -EIO;
1229
Swen Schillig564e1c82009-08-18 15:43:19 +02001230 spin_lock_bh(&qdio->req_q_lock);
1231 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001233
Swen Schillig564e1c82009-08-18 15:43:19 +02001234 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1235 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001236
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001237 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 retval = PTR_ERR(req);
1239 goto out;
1240 }
1241
Swen Schillig09a46c62009-08-18 15:43:16 +02001242 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001243 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001244 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1245 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1246
1247 req->qtcb->bottom.config.feature_selection =
1248 FSF_FEATURE_CFDC |
1249 FSF_FEATURE_LUN_SHARING |
1250 FSF_FEATURE_NOTIFICATION_LOST |
1251 FSF_FEATURE_UPDATE_ALERT;
1252 req->erp_action = erp_action;
1253 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001254 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001255
Christof Schmitt287ac012008-07-02 10:56:40 +02001256 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257 retval = zfcp_fsf_req_send(req);
1258 if (retval) {
1259 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001260 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001261 }
1262out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001263 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001264 return retval;
1265}
1266
Swen Schillig564e1c82009-08-18 15:43:19 +02001267int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 struct fsf_qtcb_bottom_config *data)
1269{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001270 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001271 struct zfcp_fsf_req *req = NULL;
1272 int retval = -EIO;
1273
Swen Schillig564e1c82009-08-18 15:43:19 +02001274 spin_lock_bh(&qdio->req_q_lock);
1275 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001276 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001277
Swen Schillig564e1c82009-08-18 15:43:19 +02001278 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001279
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001280 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001281 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001282 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001283 }
1284
Swen Schillig564e1c82009-08-18 15:43:19 +02001285 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001286 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1287 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1288 req->handler = zfcp_fsf_exchange_config_data_handler;
1289
1290 req->qtcb->bottom.config.feature_selection =
1291 FSF_FEATURE_CFDC |
1292 FSF_FEATURE_LUN_SHARING |
1293 FSF_FEATURE_NOTIFICATION_LOST |
1294 FSF_FEATURE_UPDATE_ALERT;
1295
1296 if (data)
1297 req->data = data;
1298
1299 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1300 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001301 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001303 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304
1305 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001306 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001307
Christof Schmittada81b72009-04-17 15:08:03 +02001308out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001309 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001310 return retval;
1311}
1312
1313/**
1314 * zfcp_fsf_exchange_port_data - request information about local port
1315 * @erp_action: ERP action for the adapter for which port data is requested
1316 * Returns: 0 on success, error otherwise
1317 */
1318int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1319{
Swen Schillig564e1c82009-08-18 15:43:19 +02001320 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schillig44cc76f2008-10-01 12:42:16 +02001321 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001322 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 int retval = -EIO;
1324
Swen Schillig564e1c82009-08-18 15:43:19 +02001325 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001326 return -EOPNOTSUPP;
1327
Swen Schillig564e1c82009-08-18 15:43:19 +02001328 spin_lock_bh(&qdio->req_q_lock);
1329 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001330 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001331
Swen Schillig564e1c82009-08-18 15:43:19 +02001332 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1333 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001334
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001335 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336 retval = PTR_ERR(req);
1337 goto out;
1338 }
1339
Swen Schillig09a46c62009-08-18 15:43:16 +02001340 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001341 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1343 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1344
1345 req->handler = zfcp_fsf_exchange_port_data_handler;
1346 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001347 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348
Christof Schmitt287ac012008-07-02 10:56:40 +02001349 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001350 retval = zfcp_fsf_req_send(req);
1351 if (retval) {
1352 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001353 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001354 }
1355out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001356 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001357 return retval;
1358}
1359
1360/**
1361 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001362 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001363 * @data: pointer to struct fsf_qtcb_bottom_port
1364 * Returns: 0 on success, error otherwise
1365 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001366int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001367 struct fsf_qtcb_bottom_port *data)
1368{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001369 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001370 struct zfcp_fsf_req *req = NULL;
1371 int retval = -EIO;
1372
Swen Schillig564e1c82009-08-18 15:43:19 +02001373 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374 return -EOPNOTSUPP;
1375
Swen Schillig564e1c82009-08-18 15:43:19 +02001376 spin_lock_bh(&qdio->req_q_lock);
1377 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001378 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001379
Swen Schillig564e1c82009-08-18 15:43:19 +02001380 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001381
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001382 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001383 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001384 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001385 }
1386
1387 if (data)
1388 req->data = data;
1389
Swen Schillig564e1c82009-08-18 15:43:19 +02001390 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001391 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1392 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1393
1394 req->handler = zfcp_fsf_exchange_port_data_handler;
1395 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1396 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001397 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001398
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001399 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001400 wait_for_completion(&req->completion);
1401
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001402 zfcp_fsf_req_free(req);
1403
1404 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001405
1406out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001407 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001408 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001409}
1410
1411static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1412{
1413 struct zfcp_port *port = req->data;
1414 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001415 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001416
1417 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001418 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001419
1420 switch (header->fsf_status) {
1421 case FSF_PORT_ALREADY_OPEN:
1422 break;
1423 case FSF_ACCESS_DENIED:
1424 zfcp_fsf_access_denied_port(req, port);
1425 break;
1426 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1427 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001428 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001429 "remote port 0x%016Lx\n",
1430 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001431 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001432 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1433 break;
1434 case FSF_ADAPTER_STATUS_AVAILABLE:
1435 switch (header->fsf_status_qual.word[0]) {
1436 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1437 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001439 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1440 break;
1441 }
1442 break;
1443 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1446 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001447 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1448 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1449 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 /* check whether D_ID has changed during open */
1451 /*
1452 * FIXME: This check is not airtight, as the FCP channel does
1453 * not monitor closures of target port connections caused on
1454 * the remote side. Thus, they might miss out on invalidating
1455 * locally cached WWPNs (and other N_Port parameters) of gone
1456 * target ports. So, our heroic attempt to make things safe
1457 * could be undermined by 'open port' response data tagged with
1458 * obsolete WWPNs. Another reason to monitor potential
1459 * connection closures ourself at least (by interpreting
1460 * incoming ELS' and unsolicited status). It just crosses my
1461 * mind that one should be able to cross-check by means of
1462 * another GID_PN straight after a port has been opened.
1463 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1464 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001465 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001466 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001467 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001468 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001471 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 break;
1473 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001474
1475out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001476 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479/**
1480 * zfcp_fsf_open_port - create and send open port request
1481 * @erp_action: pointer to struct zfcp_erp_action
1482 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001484int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001486 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001487 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001488 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001489 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Swen Schillig564e1c82009-08-18 15:43:19 +02001492 spin_lock_bh(&qdio->req_q_lock);
1493 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Swen Schillig564e1c82009-08-18 15:43:19 +02001496 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1497 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001498
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001499 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001500 retval = PTR_ERR(req);
1501 goto out;
1502 }
1503
Swen Schillig09a46c62009-08-18 15:43:16 +02001504 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001505 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1507 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1508
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001509 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001510 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001511 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001512 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001513 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001514 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Christof Schmitt287ac012008-07-02 10:56:40 +02001516 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001517 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001519 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001520 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001521 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001523out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001524 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 return retval;
1526}
1527
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001528static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001533 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001535 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001537 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001538 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001543 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 ZFCP_STATUS_COMMON_OPEN,
1545 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001550/**
1551 * zfcp_fsf_close_port - create and send close port request
1552 * @erp_action: pointer to struct zfcp_erp_action
1553 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001555int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001557 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001558 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001559 struct zfcp_fsf_req *req;
1560 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Swen Schillig564e1c82009-08-18 15:43:19 +02001562 spin_lock_bh(&qdio->req_q_lock);
1563 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Swen Schillig564e1c82009-08-18 15:43:19 +02001566 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1567 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001568
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001569 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001570 retval = PTR_ERR(req);
1571 goto out;
1572 }
1573
Swen Schillig09a46c62009-08-18 15:43:16 +02001574 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001575 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1577 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1578
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001579 req->handler = zfcp_fsf_close_port_handler;
1580 req->data = erp_action->port;
1581 req->erp_action = erp_action;
1582 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001583 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Christof Schmitt287ac012008-07-02 10:56:40 +02001585 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001586 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001588 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001589 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001591out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001592 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return retval;
1594}
1595
Swen Schillig5ab944f2008-10-01 12:42:17 +02001596static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1597{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001598 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001599 struct fsf_qtcb_header *header = &req->qtcb->header;
1600
1601 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001602 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001603 goto out;
1604 }
1605
1606 switch (header->fsf_status) {
1607 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1608 dev_warn(&req->adapter->ccw_device->dev,
1609 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001610 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001611 case FSF_ADAPTER_STATUS_AVAILABLE:
1612 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001613 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001615 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 case FSF_GOOD:
1618 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001619 /* fall through */
1620 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001621 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622 }
1623out:
1624 wake_up(&wka_port->completion_wq);
1625}
1626
1627/**
1628 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001629 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001630 * Returns: 0 on success, error otherwise
1631 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001632int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001633{
1634 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001635 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001636 struct zfcp_fsf_req *req;
1637 int retval = -EIO;
1638
Swen Schillig564e1c82009-08-18 15:43:19 +02001639 spin_lock_bh(&qdio->req_q_lock);
1640 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001641 goto out;
1642
Swen Schillig564e1c82009-08-18 15:43:19 +02001643 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1644 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001645
Swen Schillig5ab944f2008-10-01 12:42:17 +02001646 if (unlikely(IS_ERR(req))) {
1647 retval = PTR_ERR(req);
1648 goto out;
1649 }
1650
Swen Schillig09a46c62009-08-18 15:43:16 +02001651 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001652 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001653 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1654 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1655
1656 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001657 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001658 req->data = wka_port;
1659
1660 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1661 retval = zfcp_fsf_req_send(req);
1662 if (retval)
1663 zfcp_fsf_req_free(req);
1664out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001665 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001666 return retval;
1667}
1668
1669static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1670{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001671 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001672
1673 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1674 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001675 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001676 }
1677
Christof Schmittbd0072e2009-11-24 16:54:11 +01001678 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001679 wake_up(&wka_port->completion_wq);
1680}
1681
1682/**
1683 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001684 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001685 * Returns: 0 on success, error otherwise
1686 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001687int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001688{
1689 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001690 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001691 struct zfcp_fsf_req *req;
1692 int retval = -EIO;
1693
Swen Schillig564e1c82009-08-18 15:43:19 +02001694 spin_lock_bh(&qdio->req_q_lock);
1695 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001696 goto out;
1697
Swen Schillig564e1c82009-08-18 15:43:19 +02001698 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1699 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001700
Swen Schillig5ab944f2008-10-01 12:42:17 +02001701 if (unlikely(IS_ERR(req))) {
1702 retval = PTR_ERR(req);
1703 goto out;
1704 }
1705
Swen Schillig09a46c62009-08-18 15:43:16 +02001706 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001707 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001708 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1709 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1710
1711 req->handler = zfcp_fsf_close_wka_port_handler;
1712 req->data = wka_port;
1713 req->qtcb->header.port_handle = wka_port->handle;
1714
1715 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1716 retval = zfcp_fsf_req_send(req);
1717 if (retval)
1718 zfcp_fsf_req_free(req);
1719out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001720 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001721 return retval;
1722}
1723
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001724static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001726 struct zfcp_port *port = req->data;
1727 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001730 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001731 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001735 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001736 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001739 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001742 /* can't use generic zfcp_erp_modify_port_status because
1743 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1744 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001745 read_lock(&port->unit_list_lock);
1746 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001747 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1748 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001749 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001750 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001751 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 switch (header->fsf_status_qual.word[0]) {
1755 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001756 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 }
1761 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 /* can't use generic zfcp_erp_modify_port_status because
1764 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1765 */
1766 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001767 read_lock(&port->unit_list_lock);
1768 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001769 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1770 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001771 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774}
1775
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001776/**
1777 * zfcp_fsf_close_physical_port - close physical port
1778 * @erp_action: pointer to struct zfcp_erp_action
1779 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001781int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001783 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001784 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001785 struct zfcp_fsf_req *req;
1786 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Swen Schillig564e1c82009-08-18 15:43:19 +02001788 spin_lock_bh(&qdio->req_q_lock);
1789 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Swen Schillig564e1c82009-08-18 15:43:19 +02001792 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1793 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001794
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001795 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001796 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 goto out;
1798 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001799
Swen Schillig09a46c62009-08-18 15:43:16 +02001800 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001801 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001802 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1803 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1804
1805 req->data = erp_action->port;
1806 req->qtcb->header.port_handle = erp_action->port->handle;
1807 req->erp_action = erp_action;
1808 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001809 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001810
Christof Schmitt287ac012008-07-02 10:56:40 +02001811 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812 retval = zfcp_fsf_req_send(req);
1813 if (retval) {
1814 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001815 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001816 }
1817out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001818 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 return retval;
1820}
1821
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001822static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001824 struct zfcp_adapter *adapter = req->adapter;
1825 struct zfcp_unit *unit = req->data;
1826 struct fsf_qtcb_header *header = &req->qtcb->header;
1827 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1828 struct fsf_queue_designator *queue_designator =
1829 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001830 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001832 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001833 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001836 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 ZFCP_STATUS_UNIT_SHARED |
1838 ZFCP_STATUS_UNIT_READONLY,
1839 &unit->status);
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 switch (header->fsf_status) {
1842
1843 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001844 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001845 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001849 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001851 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001854 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001858 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001859 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001860 "LUN 0x%Lx on port 0x%Lx is already in "
1861 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001862 (unsigned long long)unit->fcp_lun,
1863 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001864 queue_designator->cssid,
1865 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001866 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001867 zfcp_act_eval_err(adapter,
1868 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001869 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1871 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001875 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001876 "No handle is available for LUN "
1877 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001878 (unsigned long long)unit->fcp_lun,
1879 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001880 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001881 /* fall through */
1882 case FSF_INVALID_COMMAND_OPTION:
1883 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 switch (header->fsf_status_qual.word[0]) {
1887 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001888 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001891 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 }
1894 break;
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001899
1900 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1901 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001902 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001903 exclusive = (bottom->lun_access_info &
1904 FSF_UNIT_ACCESS_EXCLUSIVE);
1905 readwrite = (bottom->lun_access_info &
1906 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 if (!exclusive)
1909 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1910 &unit->status);
1911
1912 if (!readwrite) {
1913 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1914 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001915 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001916 "SCSI device at LUN 0x%016Lx on port "
1917 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001918 (unsigned long long)unit->fcp_lun,
1919 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 }
1921
1922 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001923 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001924 "Exclusive read-only access not "
1925 "supported (unit 0x%016Lx, "
1926 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001927 (unsigned long long)unit->fcp_lun,
1928 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001929 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001931 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001933 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001934 "Shared read-write access not "
1935 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001936 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001937 (unsigned long long)unit->fcp_lun,
1938 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001939 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001941 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
1943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
1948/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001949 * zfcp_fsf_open_unit - open unit
1950 * @erp_action: pointer to struct zfcp_erp_action
1951 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001953int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001955 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001956 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001957 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001958 struct zfcp_fsf_req *req;
1959 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Swen Schillig564e1c82009-08-18 15:43:19 +02001961 spin_lock_bh(&qdio->req_q_lock);
1962 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001963 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
Swen Schillig564e1c82009-08-18 15:43:19 +02001965 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Swen Schilliga4623c42009-08-18 15:43:15 +02001966 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001967
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001968 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001969 retval = PTR_ERR(req);
1970 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001971 }
1972
Swen Schillig09a46c62009-08-18 15:43:16 +02001973 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001974 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001975 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1976 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001978 req->qtcb->header.port_handle = erp_action->port->handle;
1979 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1980 req->handler = zfcp_fsf_open_unit_handler;
1981 req->data = erp_action->unit;
1982 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001983 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001984
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001985 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1986 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
Christof Schmitt287ac012008-07-02 10:56:40 +02001988 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 retval = zfcp_fsf_req_send(req);
1990 if (retval) {
1991 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001992 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001994out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001995 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 return retval;
1997}
1998
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001999static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002001 struct zfcp_unit *unit = req->data;
2002
2003 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02002004 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002005
2006 switch (req->qtcb->header.fsf_status) {
2007 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002008 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002009 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2010 break;
2011 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002012 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002013 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2014 break;
2015 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002016 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002017 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002018 break;
2019 case FSF_ADAPTER_STATUS_AVAILABLE:
2020 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2021 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002022 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002023 /* fall through */
2024 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2025 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2026 break;
2027 }
2028 break;
2029 case FSF_GOOD:
2030 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2031 break;
2032 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002033}
2034
2035/**
2036 * zfcp_fsf_close_unit - close zfcp unit
2037 * @erp_action: pointer to struct zfcp_unit
2038 * Returns: 0 on success, error otherwise
2039 */
2040int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2041{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002042 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002043 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002044 struct zfcp_fsf_req *req;
2045 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Swen Schillig564e1c82009-08-18 15:43:19 +02002047 spin_lock_bh(&qdio->req_q_lock);
2048 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002050
Swen Schillig564e1c82009-08-18 15:43:19 +02002051 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2052 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002053
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002054 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002055 retval = PTR_ERR(req);
2056 goto out;
2057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Swen Schillig09a46c62009-08-18 15:43:16 +02002059 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02002060 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002061 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2063
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002064 req->qtcb->header.port_handle = erp_action->port->handle;
2065 req->qtcb->header.lun_handle = erp_action->unit->handle;
2066 req->handler = zfcp_fsf_close_unit_handler;
2067 req->data = erp_action->unit;
2068 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002069 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
Christof Schmitt287ac012008-07-02 10:56:40 +02002071 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002072 retval = zfcp_fsf_req_send(req);
2073 if (retval) {
2074 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002075 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002076 }
2077out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002078 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
Christof Schmittc9615852008-05-06 11:00:05 +02002082static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2083{
2084 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002085 lat_rec->min = min(lat_rec->min, lat);
2086 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002087}
2088
Christof Schmittd9742b42009-11-24 16:54:03 +01002089static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002090{
Christof Schmittd9742b42009-11-24 16:54:03 +01002091 struct fsf_qual_latency_info *lat_in;
2092 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002093 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002094 struct zfcp_blk_drv_data blktrc;
2095 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002096
Christof Schmittd9742b42009-11-24 16:54:03 +01002097 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002098
Christof Schmittd9742b42009-11-24 16:54:03 +01002099 blktrc.flags = 0;
2100 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2101 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2102 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2103 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2104 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2105
2106 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2107 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2108 blktrc.channel_lat = lat_in->channel_lat * ticks;
2109 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2110
2111 switch (req->qtcb->bottom.io.data_direction) {
2112 case FSF_DATADIR_READ:
2113 lat = &unit->latencies.read;
2114 break;
2115 case FSF_DATADIR_WRITE:
2116 lat = &unit->latencies.write;
2117 break;
2118 case FSF_DATADIR_CMND:
2119 lat = &unit->latencies.cmd;
2120 break;
2121 }
2122
2123 if (lat) {
2124 spin_lock(&unit->latencies.lock);
2125 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2126 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2127 lat->counter++;
2128 spin_unlock(&unit->latencies.lock);
2129 }
Christof Schmittc9615852008-05-06 11:00:05 +02002130 }
2131
Christof Schmittd9742b42009-11-24 16:54:03 +01002132 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2133 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002134}
2135
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002136static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002138 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002139 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002142 read_lock_irqsave(&req->adapter->abort_lock, flags);
2143
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002144 scpnt = req->data;
2145 if (unlikely(!scpnt)) {
2146 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2147 return;
2148 }
2149
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002150 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002151 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 goto skip_fsfstatus;
2153 }
2154
Christof Schmitt4318e082009-11-24 16:54:08 +01002155 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2156 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Christof Schmittd9742b42009-11-24 16:54:03 +01002158 zfcp_fsf_req_trace(req, scpnt);
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002159
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002160skip_fsfstatus:
Christof Schmittab725282010-02-17 11:18:57 +01002161 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 /*
2166 * We must hold this lock until scsi_done has been called.
2167 * Otherwise we may call scsi_done after abort regarding this
2168 * command has completed.
2169 * Note: scsi_done must not block!
2170 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002171 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172}
2173
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002174static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
Christof Schmitt4318e082009-11-24 16:54:08 +01002176 struct fcp_resp_with_ext *fcp_rsp;
2177 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Christof Schmitt4318e082009-11-24 16:54:08 +01002179 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2180 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2181
2182 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002183 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2184 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185}
2186
2187
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002188static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2189{
2190 struct zfcp_unit *unit;
2191 struct fsf_qtcb_header *header = &req->qtcb->header;
2192
2193 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2194 unit = req->data;
2195 else
2196 unit = req->unit;
2197
2198 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2199 goto skip_fsfstatus;
2200
2201 switch (header->fsf_status) {
2202 case FSF_HANDLE_MISMATCH:
2203 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002204 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002205 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2206 break;
2207 case FSF_FCPLUN_NOT_VALID:
2208 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002209 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002210 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2211 break;
2212 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2213 zfcp_fsf_class_not_supp(req);
2214 break;
2215 case FSF_ACCESS_DENIED:
2216 zfcp_fsf_access_denied_unit(req, unit);
2217 break;
2218 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2219 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002220 "Incorrect direction %d, unit 0x%016Lx on port "
2221 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002223 (unsigned long long)unit->fcp_lun,
2224 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002225 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2226 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002227 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2228 break;
2229 case FSF_CMND_LENGTH_NOT_VALID:
2230 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002231 "Incorrect CDB length %d, unit 0x%016Lx on "
2232 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002233 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002234 (unsigned long long)unit->fcp_lun,
2235 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002236 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2237 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002238 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2239 break;
2240 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002241 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002242 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002243 break;
2244 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002245 zfcp_erp_unit_boxed(unit, "fssfch6", 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_ADAPTER_STATUS_AVAILABLE:
2249 if (header->fsf_status_qual.word[0] ==
2250 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002251 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002252 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2253 break;
2254 }
2255skip_fsfstatus:
2256 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2257 zfcp_fsf_send_fcp_ctm_handler(req);
2258 else {
2259 zfcp_fsf_send_fcp_command_task_handler(req);
2260 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002261 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002262 }
2263}
2264
2265/**
2266 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002267 * @unit: unit where command is sent to
2268 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002270int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2271 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002272{
2273 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002274 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002275 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002276 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002277 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002278 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002279
2280 if (unlikely(!(atomic_read(&unit->status) &
2281 ZFCP_STATUS_COMMON_UNBLOCKED)))
2282 return -EBUSY;
2283
Swen Schillig564e1c82009-08-18 15:43:19 +02002284 spin_lock(&qdio->req_q_lock);
2285 if (atomic_read(&qdio->req_q.count) <= 0) {
2286 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002287 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002288 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002289
Swen Schillig564e1c82009-08-18 15:43:19 +02002290 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Swen Schilliga4623c42009-08-18 15:43:15 +02002291 adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002292
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002293 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002294 retval = PTR_ERR(req);
2295 goto out;
2296 }
2297
Swen Schillig09a46c62009-08-18 15:43:16 +02002298 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002299 get_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002300 req->unit = unit;
2301 req->data = scsi_cmnd;
2302 req->handler = zfcp_fsf_send_fcp_command_handler;
2303 req->qtcb->header.lun_handle = unit->handle;
2304 req->qtcb->header.port_handle = unit->port->handle;
2305 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002306 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002307
2308 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2309
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002310 /*
2311 * set depending on data direction:
2312 * data direction bits in SBALE (SB Type)
2313 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002314 */
2315 switch (scsi_cmnd->sc_data_direction) {
2316 case DMA_NONE:
2317 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002318 break;
2319 case DMA_FROM_DEVICE:
2320 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002321 break;
2322 case DMA_TO_DEVICE:
2323 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2324 sbtype = SBAL_FLAGS0_TYPE_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002325 break;
2326 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002327 goto failed_scsi_cmnd;
2328 }
2329
Christof Schmitt4318e082009-11-24 16:54:08 +01002330 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2331 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002332
Swen Schillig564e1c82009-08-18 15:43:19 +02002333 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334 scsi_sglist(scsi_cmnd),
2335 FSF_MAX_SBALS_PER_REQ);
2336 if (unlikely(real_bytes < 0)) {
Swen Schillig42428f72009-08-18 15:43:18 +02002337 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002338 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002339 "Oversize data package, unit 0x%016Lx "
2340 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002341 (unsigned long long)unit->fcp_lun,
2342 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002343 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002344 retval = -EINVAL;
2345 }
2346 goto failed_scsi_cmnd;
2347 }
2348
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002349 retval = zfcp_fsf_req_send(req);
2350 if (unlikely(retval))
2351 goto failed_scsi_cmnd;
2352
2353 goto out;
2354
2355failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002356 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002357 zfcp_fsf_req_free(req);
2358 scsi_cmnd->host_scribble = NULL;
2359out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002360 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002361 return retval;
2362}
2363
2364/**
2365 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002366 * @unit: pointer to struct zfcp_unit
2367 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002368 * Returns: on success pointer to struct fsf_req, NULL otherwise
2369 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002370struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002371{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002372 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002373 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002374 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002375 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002376
2377 if (unlikely(!(atomic_read(&unit->status) &
2378 ZFCP_STATUS_COMMON_UNBLOCKED)))
2379 return NULL;
2380
Swen Schillig564e1c82009-08-18 15:43:19 +02002381 spin_lock_bh(&qdio->req_q_lock);
2382 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002383 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002384
Swen Schillig564e1c82009-08-18 15:43:19 +02002385 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2386 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002387
Swen Schillig633528c2008-11-26 18:07:37 +01002388 if (IS_ERR(req)) {
2389 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002390 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002391 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002392
2393 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2394 req->data = unit;
2395 req->handler = zfcp_fsf_send_fcp_command_handler;
2396 req->qtcb->header.lun_handle = unit->handle;
2397 req->qtcb->header.port_handle = unit->port->handle;
2398 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2399 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002400 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002401
Swen Schillig564e1c82009-08-18 15:43:19 +02002402 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002403 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2404 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2405
Christof Schmitt4318e082009-11-24 16:54:08 +01002406 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2407 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002408
2409 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2410 if (!zfcp_fsf_req_send(req))
2411 goto out;
2412
2413 zfcp_fsf_req_free(req);
2414 req = NULL;
2415out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002416 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002417 return req;
2418}
2419
2420static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2421{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002422}
2423
2424/**
2425 * zfcp_fsf_control_file - control file upload/download
2426 * @adapter: pointer to struct zfcp_adapter
2427 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2428 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002430struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2431 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002433 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002434 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002435 struct zfcp_fsf_req *req = NULL;
2436 struct fsf_qtcb_bottom_support *bottom;
2437 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Christof Schmitt45633fd2008-06-10 18:20:55 +02002439 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2440 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Christof Schmitt45633fd2008-06-10 18:20:55 +02002442 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2444 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2447 direction = SBAL_FLAGS0_TYPE_READ;
2448 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002450 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 }
2452
Swen Schillig564e1c82009-08-18 15:43:19 +02002453 spin_lock_bh(&qdio->req_q_lock);
2454 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002455 goto out;
2456
Swen Schillig564e1c82009-08-18 15:43:19 +02002457 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002458 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002460 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 }
2462
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002463 req->handler = zfcp_fsf_control_file_handler;
2464
Swen Schillig564e1c82009-08-18 15:43:19 +02002465 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 sbale[0].flags |= direction;
2467
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002468 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002470 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Swen Schillig564e1c82009-08-18 15:43:19 +02002472 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2473 direction, fsf_cfdc->sg,
2474 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002475 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002476 zfcp_fsf_req_free(req);
2477 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002480 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2481 retval = zfcp_fsf_req_send(req);
2482out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002483 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002484
2485 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002486 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002487 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002489 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002491
2492/**
2493 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2494 * @adapter: pointer to struct zfcp_adapter
2495 * @sbal_idx: response queue index of SBAL to be processed
2496 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002497void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002498{
Swen Schillig564e1c82009-08-18 15:43:19 +02002499 struct zfcp_adapter *adapter = qdio->adapter;
2500 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002501 struct qdio_buffer_element *sbale;
2502 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002503 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002504 int idx;
2505
2506 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2507
2508 sbale = &sbal->element[idx];
2509 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002510 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002511
2512 if (!fsf_req)
2513 /*
2514 * Unknown request means that we have potentially memory
2515 * corruption and must stop the machine immediately.
2516 */
2517 panic("error: unknown req_id (%lx) on adapter %s.\n",
2518 req_id, dev_name(&adapter->ccw_device->dev));
2519
Swen Schillig42428f72009-08-18 15:43:18 +02002520 fsf_req->queue_req.sbal_response = sbal_idx;
2521 fsf_req->queue_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002522 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002523 zfcp_fsf_req_complete(fsf_req);
2524
2525 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2526 break;
2527 }
2528}