blob: f9be5d60d92a1b7310cb4463e1f59403c2e96ac4 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010014#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010016#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020017#include "zfcp_dbf.h"
Christof Schmitt34c2b712010-02-17 11:18:59 +010018#include "zfcp_qdio.h"
Christof Schmittb6bd2fb92010-02-17 11:18:50 +010019#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Christof Schmitt287ac012008-07-02 10:56:40 +020021static void zfcp_fsf_request_timeout_handler(unsigned long data)
22{
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010024 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
25 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020026}
27
28static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
29 unsigned long timeout)
30{
31 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
32 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
33 fsf_req->timer.expires = jiffies + timeout;
34 add_timer(&fsf_req->timer);
35}
36
37static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
38{
39 BUG_ON(!fsf_req->erp_action);
40 fsf_req->timer.function = zfcp_erp_timeout_handler;
41 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
42 fsf_req->timer.expires = jiffies + 30 * HZ;
43 add_timer(&fsf_req->timer);
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/* association between FSF command and FSF QTCB type */
47static u32 fsf_qtcb_type[] = {
48 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
49 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
58 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
59 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61};
62
Christof Schmitt553448f2008-06-10 18:20:58 +020063static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
64{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020065 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020066 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020067 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020068
Christof Schmittff3b24f2008-10-01 12:42:15 +020069 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020070 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020071 "Access denied according to ACT rule type %s, "
72 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020073}
74
75static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
76 struct zfcp_port *port)
77{
78 struct fsf_qtcb_header *header = &req->qtcb->header;
79 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020080 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020081 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020082 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010084 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020085 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86}
87
88static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
89 struct zfcp_unit *unit)
90{
91 struct fsf_qtcb_header *header = &req->qtcb->header;
92 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020093 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020094 (unsigned long long)unit->fcp_lun,
95 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020096 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
97 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010098 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020099 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100}
101
102static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
103{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200104 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
105 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100106 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200107 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
108}
109
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200110/**
111 * zfcp_fsf_req_free - free memory used by fsf request
112 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200116 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200117 if (likely(req->qtcb))
118 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200119 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200120 return;
121 }
122
Swen Schilliga4623c42009-08-18 15:43:15 +0200123 if (likely(req->qtcb))
124 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
125 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200128static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Swen Schilligecf0c772009-11-24 16:53:58 +0100130 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200131 struct fsf_status_read_buffer *sr_buf = req->data;
132 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100134 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Swen Schilligecf0c772009-11-24 16:53:58 +0100136 read_lock_irqsave(&adapter->port_list_lock, flags);
137 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100139 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100140 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200141 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100142 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100145static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200146 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200148 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200150 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
151 return;
152
153 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200154
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100155 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200156
157 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200159
160 switch (link_down->error_code) {
161 case FSF_PSQ_LINK_NO_LIGHT:
162 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200163 "There is no light signal from the local "
164 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200165 break;
166 case FSF_PSQ_LINK_WRAP_PLUG:
167 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200168 "There is a wrap plug instead of a fibre "
169 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200170 break;
171 case FSF_PSQ_LINK_NO_FCP:
172 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200173 "The adjacent fibre channel node does not "
174 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200175 break;
176 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
177 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200178 "The FCP device is suspended because of a "
179 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200180 break;
181 case FSF_PSQ_LINK_INVALID_WWPN:
182 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200183 "The FCP device detected a WWPN that is "
184 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200185 break;
186 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
187 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200188 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200189 break;
190 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
191 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200192 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200193 break;
194 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
195 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200196 "The adjacent switch cannot support "
197 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200198 break;
199 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
200 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200201 "The FCP adapter could not log in to the "
202 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200203 break;
204 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
205 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200206 "The WWPN assignment file on the FCP adapter "
207 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200208 break;
209 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
210 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200211 "The mode table on the FCP adapter "
212 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200213 break;
214 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
215 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200216 "All NPIV ports on the FCP adapter have "
217 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200218 break;
219 default:
220 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200221 "The link between the FCP adapter and "
222 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200223 }
224out:
225 zfcp_erp_adapter_failed(adapter, id, req);
226}
227
228static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
229{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200230 struct fsf_status_read_buffer *sr_buf = req->data;
231 struct fsf_link_down_info *ldi =
232 (struct fsf_link_down_info *) &sr_buf->payload;
233
234 switch (sr_buf->status_subtype) {
235 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100236 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200237 break;
238 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100239 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 break;
241 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100242 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 };
244}
245
246static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
247{
248 struct zfcp_adapter *adapter = req->adapter;
249 struct fsf_status_read_buffer *sr_buf = req->data;
250
251 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200252 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200253 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200254 zfcp_fsf_req_free(req);
255 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Swen Schillig57717102009-08-18 15:43:21 +0200258 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200259
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200260 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200270 dev_warn(&adapter->ccw_device->dev,
271 "The error threshold for checksum statistics "
272 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200273 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200276 zfcp_fsf_status_read_link_down(req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200277 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200280 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200281 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100283 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 ZFCP_STATUS_COMMON_RUNNING,
285 ZFCP_SET);
286 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200287 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
288 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100289 "fssrh_2", req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200290 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100293 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200294 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100295 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
296 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200297 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100298 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100301 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200303 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200305 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200307
Swen Schilliga4623c42009-08-18 15:43:15 +0200308 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200309 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200310
311 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200312 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200315static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200317 switch (req->qtcb->header.fsf_status_qual.word[0]) {
318 case FSF_SQ_FCP_RSP_AVAILABLE:
319 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
320 case FSF_SQ_NO_RETRY_POSSIBLE:
321 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
322 return;
323 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200324 break;
325 case FSF_SQ_NO_RECOM:
326 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200327 "The FCP adapter reported a problem "
328 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100329 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200330 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200332 /* all non-return stats set FSFREQ_ERROR*/
333 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
334}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200336static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
337{
338 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
339 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200340
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200341 switch (req->qtcb->header.fsf_status) {
342 case FSF_UNKNOWN_COMMAND:
343 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200344 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200345 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100346 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200350 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200355static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200357 struct zfcp_adapter *adapter = req->adapter;
358 struct fsf_qtcb *qtcb = req->qtcb;
359 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Swen Schillig57717102009-08-18 15:43:21 +0200361 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200363 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100364 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200368 switch (qtcb->prefix.prot_status) {
369 case FSF_PROT_GOOD:
370 case FSF_PROT_FSF_STATUS_PRESENTED:
371 return;
372 case FSF_PROT_QTCB_VERSION_ERROR:
373 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200374 "QTCB version 0x%x not supported by FCP adapter "
375 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
376 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100377 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200379 case FSF_PROT_ERROR_STATE:
380 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100381 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100382 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200384 case FSF_PROT_UNSUPP_QTCB_TYPE:
385 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200386 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100387 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200389 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
390 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
391 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 case FSF_PROT_DUPLICATE_REQUEST_ID:
394 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200395 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100397 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200399 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100400 zfcp_fsf_link_down_info_eval(req, "fspse_5",
401 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100402 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100403 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200405 case FSF_PROT_REEST_QUEUE:
406 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100407 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200408 ZFCP_STATUS_COMMON_RUNNING,
409 ZFCP_SET);
410 zfcp_erp_adapter_reopen(adapter,
411 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100412 ZFCP_STATUS_COMMON_ERP_FAILED,
413 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200417 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100419 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200421 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200425 * zfcp_fsf_req_complete - process completion of a FSF request
426 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200428 * When a request has been completed either from the FCP adapter,
429 * or it has been dismissed due to a queue shutdown, this function
430 * is called to process the completion status and trigger further
431 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200433static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200434{
435 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
436 zfcp_fsf_status_read_handler(req);
437 return;
438 }
439
440 del_timer(&req->timer);
441 zfcp_fsf_protstatus_eval(req);
442 zfcp_fsf_fsfstatus_eval(req);
443 req->handler(req);
444
445 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200446 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200447
448 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
449 zfcp_fsf_req_free(req);
450 else
Swen Schillig058b8642009-08-18 15:43:14 +0200451 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200452}
453
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200454/**
455 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
456 * @adapter: pointer to struct zfcp_adapter
457 *
458 * Never ever call this without shutting down the adapter first.
459 * Otherwise the adapter would continue using and corrupting s390 storage.
460 * Included BUG_ON() call to ensure this is done.
461 * ERP is supposed to be the only user of this function.
462 */
463void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
464{
465 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200466 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200467
468 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100469 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200470
471 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
472 list_del(&req->list);
473 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
474 zfcp_fsf_req_complete(req);
475 }
476}
477
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200478static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100480 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200481 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200482 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100483 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100485 /* adjust pointers for missing command code */
486 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
487 - sizeof(u32));
488 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
489 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200490
491 if (req->data)
492 memcpy(req->data, bottom, sizeof(*bottom));
493
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100494 fc_host_port_name(shost) = nsp->fl_wwpn;
495 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100496 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200497 fc_host_speed(shost) = bottom->fc_link_speed;
498 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
499
500 adapter->hydra_version = bottom->adapter_type;
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200501 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200502 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
503 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200504
505 if (fc_host_permanent_port_name(shost) == -1)
506 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
507
508 switch (bottom->fc_topology) {
509 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100510 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100511 adapter->peer_wwpn = plogi->fl_wwpn;
512 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 break;
515 case FSF_TOPO_FABRIC:
516 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 break;
518 case FSF_TOPO_AL:
519 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200520 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200521 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200523 "Unknown or unsupported arbitrated loop "
524 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100525 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200526 return -EIO;
527 }
528
Felix Beckef3eb712010-07-16 15:37:42 +0200529 zfcp_scsi_set_prot(adapter);
530
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200531 return 0;
532}
533
534static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
535{
536 struct zfcp_adapter *adapter = req->adapter;
537 struct fsf_qtcb *qtcb = req->qtcb;
538 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
539 struct Scsi_Host *shost = adapter->scsi_host;
540
541 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
542 return;
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200545 adapter->adapter_features = bottom->adapter_features;
546 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500547 adapter->peer_wwpn = 0;
548 adapter->peer_wwnn = 0;
549 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200551 switch (qtcb->header.fsf_status) {
552 case FSF_GOOD:
553 if (zfcp_fsf_exchange_config_evaluate(req))
554 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200555
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200556 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
557 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200558 "FCP adapter maximum QTCB size (%d bytes) "
559 "is too small\n",
560 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100561 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200562 return;
563 }
564 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
565 &adapter->status);
566 break;
567 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200568 fc_host_node_name(shost) = 0;
569 fc_host_port_name(shost) = 0;
570 fc_host_port_id(shost) = 0;
571 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100572 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200574
575 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
576 &adapter->status);
577
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100578 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200579 &qtcb->header.fsf_status_qual.link_down_info);
580 break;
581 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100582 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200583 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200586 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200588 memcpy(fc_host_serial_number(shost), bottom->serial_number,
589 min(FC_SERIAL_NUMBER_SIZE, 17));
590 EBCASC(fc_host_serial_number(shost),
591 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200594 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200595 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200596 "The FCP adapter only supports newer "
597 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100598 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200599 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200601 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200602 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200603 "The FCP adapter only supports older "
604 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100605 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200609static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200611 struct zfcp_adapter *adapter = req->adapter;
612 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
613 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200615 if (req->data)
616 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100617
Christof Schmitt02829852009-03-02 13:09:06 +0100618 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100619 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100620 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
621 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
623 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
624 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100625 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
626 FC_FC4_LIST_SIZE);
627 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
628 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100629}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100634
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return;
637
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200638 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200639 case FSF_GOOD:
640 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200641 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200642 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200643 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100644 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200645 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200646 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648}
649
Swen Schilliga4623c42009-08-18 15:43:15 +0200650static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200651{
652 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200653
654 if (likely(pool))
655 req = mempool_alloc(pool, GFP_ATOMIC);
656 else
657 req = kmalloc(sizeof(*req), GFP_ATOMIC);
658
659 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200660 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200661
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100663 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664 return req;
665}
666
Swen Schilliga4623c42009-08-18 15:43:15 +0200667static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200668{
Swen Schilliga4623c42009-08-18 15:43:15 +0200669 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670
671 if (likely(pool))
672 qtcb = mempool_alloc(pool, GFP_ATOMIC);
673 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200674 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
675
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200676 if (unlikely(!qtcb))
677 return NULL;
678
679 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200680 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200681}
682
Swen Schillig564e1c82009-08-18 15:43:19 +0200683static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200684 u32 fsf_cmd, u32 sbtype,
685 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Swen Schillig564e1c82009-08-18 15:43:19 +0200687 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200688 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200689
690 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200691 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692
693 if (adapter->req_no == 0)
694 adapter->req_no++;
695
696 INIT_LIST_HEAD(&req->list);
697 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200698 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200699
700 req->adapter = adapter;
701 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100702 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200703
Swen Schilliga4623c42009-08-18 15:43:15 +0200704 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
705 if (likely(pool))
706 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
707 else
708 req->qtcb = zfcp_qtcb_alloc(NULL);
709
710 if (unlikely(!req->qtcb)) {
711 zfcp_fsf_req_free(req);
712 return ERR_PTR(-ENOMEM);
713 }
714
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100715 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200716 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200717 req->qtcb->prefix.req_id = req->req_id;
718 req->qtcb->prefix.ulp_info = 26;
719 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
720 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
721 req->qtcb->header.req_handle = req->req_id;
722 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200723 }
724
Christof Schmitt1674b402010-04-30 18:09:34 +0200725 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
726 req->qtcb, sizeof(struct fsf_qtcb));
727
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200728 return req;
729}
730
731static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
732{
733 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200734 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100735 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100736 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200737
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100738 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200739
Swen Schillig706eca42010-07-16 15:37:38 +0200740 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100742 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200743 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100744 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb92010-02-17 11:18:50 +0100745 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100746 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200747 return -EIO;
748 }
749
750 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200751 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200752 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100753 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200754
755 return 0;
756}
757
758/**
759 * zfcp_fsf_status_read - send status read request
760 * @adapter: pointer to struct zfcp_adapter
761 * @req_flags: request flags
762 * Returns: 0 on success, ERROR otherwise
763 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200764int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200765{
Swen Schillig564e1c82009-08-18 15:43:19 +0200766 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200767 struct zfcp_fsf_req *req;
768 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200769 int retval = -EIO;
770
Swen Schillig564e1c82009-08-18 15:43:19 +0200771 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200772 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Christof Schmitt1674b402010-04-30 18:09:34 +0200775 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200776 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200777 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 goto out;
780 }
781
Swen Schilliga4623c42009-08-18 15:43:15 +0200782 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783 if (!sr_buf) {
784 retval = -ENOMEM;
785 goto failed_buf;
786 }
787 memset(sr_buf, 0, sizeof(*sr_buf));
788 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200789
790 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
791 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200792
793 retval = zfcp_fsf_req_send(req);
794 if (retval)
795 goto failed_req_send;
796
797 goto out;
798
799failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200800 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200801failed_buf:
802 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200803 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200804out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200805 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 return retval;
807}
808
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200811 struct zfcp_unit *unit = req->data;
812 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
815 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 switch (req->qtcb->header.fsf_status) {
818 case FSF_PORT_HANDLE_NOT_VALID:
819 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100820 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
821 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200825 case FSF_LUN_HANDLE_NOT_VALID:
826 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100827 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200828 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200831 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
832 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200834 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100835 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100836 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200837 break;
838 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100839 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100840 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200845 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200846 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 break;
850 }
851 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200853 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
854 break;
855 }
856}
857
858/**
859 * zfcp_fsf_abort_fcp_command - abort running SCSI command
860 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863 */
864
865struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100866 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200867{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200868 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200869 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870
Swen Schillig564e1c82009-08-18 15:43:19 +0200871 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200872 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200874 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200875 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200876 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100877 if (IS_ERR(req)) {
878 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100880 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881
882 if (unlikely(!(atomic_read(&unit->status) &
883 ZFCP_STATUS_COMMON_UNBLOCKED)))
884 goto out_error_free;
885
Christof Schmitt1674b402010-04-30 18:09:34 +0200886 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887
888 req->data = unit;
889 req->handler = zfcp_fsf_abort_fcp_command_handler;
890 req->qtcb->header.lun_handle = unit->handle;
891 req->qtcb->header.port_handle = unit->port->handle;
892 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
893
894 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
895 if (!zfcp_fsf_req_send(req))
896 goto out;
897
898out_error_free:
899 zfcp_fsf_req_free(req);
900 req = NULL;
901out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200902 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 return req;
904}
905
906static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
907{
908 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100909 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910 struct fsf_qtcb_header *header = &req->qtcb->header;
911
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100912 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913
914 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
915 goto skip_fsfstatus;
916
917 switch (header->fsf_status) {
918 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200919 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100920 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200921 break;
922 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
923 zfcp_fsf_class_not_supp(req);
924 break;
925 case FSF_ADAPTER_STATUS_AVAILABLE:
926 switch (header->fsf_status_qual.word[0]){
927 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200928 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
929 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
930 break;
931 }
932 break;
933 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200934 break;
935 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100936 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200937 break;
938 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100939 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200940 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200941 case FSF_GENERIC_COMMAND_REJECTED:
942 case FSF_PAYLOAD_SIZE_MISMATCH:
943 case FSF_REQUEST_SIZE_TOO_LARGE:
944 case FSF_RESPONSE_SIZE_TOO_LARGE:
945 case FSF_SBAL_MISMATCH:
946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
947 break;
948 }
949
950skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100951 if (ct->handler)
952 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200953}
954
Christof Schmitt1674b402010-04-30 18:09:34 +0200955static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
956 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200957 struct scatterlist *sg_req,
958 struct scatterlist *sg_resp)
959{
Christof Schmitt1674b402010-04-30 18:09:34 +0200960 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
961 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
962 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200963}
964
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100965static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
966 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200967 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200968{
Swen Schillig42428f72009-08-18 15:43:18 +0200969 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200970 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200971 int bytes;
972
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100973 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200974 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
975 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100976 return -EOPNOTSUPP;
977
Christof Schmitt1674b402010-04-30 18:09:34 +0200978 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
979 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200980 return 0;
981 }
982
983 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200984 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200985 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
986 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100987 return 0;
988 }
989
Swen Schillig01b04752010-07-16 15:37:37 +0200990 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200991 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200992 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +0200993 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +0200995 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200996
Christof Schmitt34c2b712010-02-17 11:18:59 +0100997 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200998 sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +0200999 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001000 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001001 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +02001002 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001003
Christof Schmittb1a58982009-09-24 10:23:21 +02001004 return 0;
1005}
1006
1007static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1008 struct scatterlist *sg_req,
1009 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001010 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001011{
1012 int ret;
1013
Swen Schillig01b04752010-07-16 15:37:37 +02001014 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001015 if (ret)
1016 return ret;
1017
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001018 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001019 if (timeout > 255)
1020 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001021 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001022 req->qtcb->bottom.support.timeout = timeout;
1023 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001024
1025 return 0;
1026}
1027
1028/**
1029 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1030 * @ct: pointer to struct zfcp_send_ct with data for request
1031 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001032 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001033int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001034 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1035 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001036{
Swen Schillig564e1c82009-08-18 15:43:19 +02001037 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001038 struct zfcp_fsf_req *req;
1039 int ret = -EIO;
1040
Swen Schillig564e1c82009-08-18 15:43:19 +02001041 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001042 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001043 goto out;
1044
Christof Schmitt1674b402010-04-30 18:09:34 +02001045 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1046 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001047
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001048 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001049 ret = PTR_ERR(req);
1050 goto out;
1051 }
1052
Swen Schillig09a46c62009-08-18 15:43:16 +02001053 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001054 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001055 if (ret)
1056 goto failed_send;
1057
1058 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001059 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001060 req->data = ct;
1061
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001062 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063
1064 ret = zfcp_fsf_req_send(req);
1065 if (ret)
1066 goto failed_send;
1067
1068 goto out;
1069
1070failed_send:
1071 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001072out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001073 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001074 return ret;
1075}
1076
1077static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1078{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001079 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001080 struct zfcp_port *port = send_els->port;
1081 struct fsf_qtcb_header *header = &req->qtcb->header;
1082
1083 send_els->status = -EINVAL;
1084
1085 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1086 goto skip_fsfstatus;
1087
1088 switch (header->fsf_status) {
1089 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001090 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001091 send_els->status = 0;
1092 break;
1093 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1094 zfcp_fsf_class_not_supp(req);
1095 break;
1096 case FSF_ADAPTER_STATUS_AVAILABLE:
1097 switch (header->fsf_status_qual.word[0]){
1098 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001099 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1100 case FSF_SQ_RETRY_IF_POSSIBLE:
1101 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1102 break;
1103 }
1104 break;
1105 case FSF_ELS_COMMAND_REJECTED:
1106 case FSF_PAYLOAD_SIZE_MISMATCH:
1107 case FSF_REQUEST_SIZE_TOO_LARGE:
1108 case FSF_RESPONSE_SIZE_TOO_LARGE:
1109 break;
1110 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001111 if (port)
1112 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001113 break;
1114 case FSF_SBAL_MISMATCH:
1115 /* should never occure, avoided in zfcp_fsf_send_els */
1116 /* fall through */
1117 default:
1118 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1119 break;
1120 }
1121skip_fsfstatus:
1122 if (send_els->handler)
1123 send_els->handler(send_els->handler_data);
1124}
1125
1126/**
1127 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1128 * @els: pointer to struct zfcp_send_els with data for the command
1129 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001130int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001131 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001132{
1133 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001134 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135 int ret = -EIO;
1136
Swen Schillig564e1c82009-08-18 15:43:19 +02001137 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001138 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001139 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001140
Christof Schmitt1674b402010-04-30 18:09:34 +02001141 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1142 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001143
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001144 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001145 ret = PTR_ERR(req);
1146 goto out;
1147 }
1148
Swen Schillig09a46c62009-08-18 15:43:16 +02001149 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001150
1151 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1152
1153 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001154
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001155 if (ret)
1156 goto failed_send;
1157
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001158 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001159 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001160 req->data = els;
1161
Swen Schillig57717102009-08-18 15:43:21 +02001162 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001164 ret = zfcp_fsf_req_send(req);
1165 if (ret)
1166 goto failed_send;
1167
1168 goto out;
1169
1170failed_send:
1171 zfcp_fsf_req_free(req);
1172out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001173 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001174 return ret;
1175}
1176
1177int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1178{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001179 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001180 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001181 int retval = -EIO;
1182
Swen Schillig564e1c82009-08-18 15:43:19 +02001183 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001184 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001185 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001186
Swen Schillig564e1c82009-08-18 15:43:19 +02001187 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001188 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001189 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001190
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001191 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001192 retval = PTR_ERR(req);
1193 goto out;
1194 }
1195
Swen Schillig09a46c62009-08-18 15:43:16 +02001196 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001197 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001198
1199 req->qtcb->bottom.config.feature_selection =
1200 FSF_FEATURE_CFDC |
1201 FSF_FEATURE_LUN_SHARING |
1202 FSF_FEATURE_NOTIFICATION_LOST |
1203 FSF_FEATURE_UPDATE_ALERT;
1204 req->erp_action = erp_action;
1205 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001206 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001207
Christof Schmitt287ac012008-07-02 10:56:40 +02001208 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209 retval = zfcp_fsf_req_send(req);
1210 if (retval) {
1211 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001212 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001213 }
1214out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001215 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001216 return retval;
1217}
1218
Swen Schillig564e1c82009-08-18 15:43:19 +02001219int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001220 struct fsf_qtcb_bottom_config *data)
1221{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001222 struct zfcp_fsf_req *req = NULL;
1223 int retval = -EIO;
1224
Swen Schillig564e1c82009-08-18 15:43:19 +02001225 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001226 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001227 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228
Christof Schmitt1674b402010-04-30 18:09:34 +02001229 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1230 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001231
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001232 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001233 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001234 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001235 }
1236
Christof Schmitt1674b402010-04-30 18:09:34 +02001237 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 req->handler = zfcp_fsf_exchange_config_data_handler;
1239
1240 req->qtcb->bottom.config.feature_selection =
1241 FSF_FEATURE_CFDC |
1242 FSF_FEATURE_LUN_SHARING |
1243 FSF_FEATURE_NOTIFICATION_LOST |
1244 FSF_FEATURE_UPDATE_ALERT;
1245
1246 if (data)
1247 req->data = data;
1248
1249 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1250 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001251 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001252 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001253 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254
1255 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001256 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257
Christof Schmittada81b72009-04-17 15:08:03 +02001258out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001259 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260 return retval;
1261}
1262
1263/**
1264 * zfcp_fsf_exchange_port_data - request information about local port
1265 * @erp_action: ERP action for the adapter for which port data is requested
1266 * Returns: 0 on success, error otherwise
1267 */
1268int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1269{
Swen Schillig564e1c82009-08-18 15:43:19 +02001270 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001271 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 int retval = -EIO;
1273
Swen Schillig564e1c82009-08-18 15:43:19 +02001274 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001275 return -EOPNOTSUPP;
1276
Swen Schillig564e1c82009-08-18 15:43:19 +02001277 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001278 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001279 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001280
Swen Schillig564e1c82009-08-18 15:43:19 +02001281 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001282 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001283 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001284
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001285 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001286 retval = PTR_ERR(req);
1287 goto out;
1288 }
1289
Swen Schillig09a46c62009-08-18 15:43:16 +02001290 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001291 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001292
1293 req->handler = zfcp_fsf_exchange_port_data_handler;
1294 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001295 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001296
Christof Schmitt287ac012008-07-02 10:56:40 +02001297 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001298 retval = zfcp_fsf_req_send(req);
1299 if (retval) {
1300 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001301 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 }
1303out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001304 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001305 return retval;
1306}
1307
1308/**
1309 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001310 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001311 * @data: pointer to struct fsf_qtcb_bottom_port
1312 * Returns: 0 on success, error otherwise
1313 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001314int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001315 struct fsf_qtcb_bottom_port *data)
1316{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317 struct zfcp_fsf_req *req = NULL;
1318 int retval = -EIO;
1319
Swen Schillig564e1c82009-08-18 15:43:19 +02001320 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001321 return -EOPNOTSUPP;
1322
Swen Schillig564e1c82009-08-18 15:43:19 +02001323 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001324 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001325 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001326
Christof Schmitt1674b402010-04-30 18:09:34 +02001327 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1328 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001329
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001330 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001332 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001333 }
1334
1335 if (data)
1336 req->data = data;
1337
Christof Schmitt1674b402010-04-30 18:09:34 +02001338 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001339
1340 req->handler = zfcp_fsf_exchange_port_data_handler;
1341 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1342 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001343 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001344
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001346 wait_for_completion(&req->completion);
1347
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348 zfcp_fsf_req_free(req);
1349
1350 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001351
1352out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001353 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001354 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355}
1356
1357static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1358{
1359 struct zfcp_port *port = req->data;
1360 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001361 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001362
1363 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001364 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001365
1366 switch (header->fsf_status) {
1367 case FSF_PORT_ALREADY_OPEN:
1368 break;
1369 case FSF_ACCESS_DENIED:
1370 zfcp_fsf_access_denied_port(req, port);
1371 break;
1372 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1373 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001374 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001375 "remote port 0x%016Lx\n",
1376 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001377 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001378 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1379 break;
1380 case FSF_ADAPTER_STATUS_AVAILABLE:
1381 switch (header->fsf_status_qual.word[0]) {
1382 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1383 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001384 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001385 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1386 break;
1387 }
1388 break;
1389 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1392 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001393 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1394 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1395 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 /* check whether D_ID has changed during open */
1397 /*
1398 * FIXME: This check is not airtight, as the FCP channel does
1399 * not monitor closures of target port connections caused on
1400 * the remote side. Thus, they might miss out on invalidating
1401 * locally cached WWPNs (and other N_Port parameters) of gone
1402 * target ports. So, our heroic attempt to make things safe
1403 * could be undermined by 'open port' response data tagged with
1404 * obsolete WWPNs. Another reason to monitor potential
1405 * connection closures ourself at least (by interpreting
1406 * incoming ELS' and unsolicited status). It just crosses my
1407 * mind that one should be able to cross-check by means of
1408 * another GID_PN straight after a port has been opened.
1409 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1410 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001411 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001412 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001413 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001414 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001417 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 break;
1419 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001420
1421out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001422 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423}
1424
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001425/**
1426 * zfcp_fsf_open_port - create and send open port request
1427 * @erp_action: pointer to struct zfcp_erp_action
1428 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001430int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Swen Schillig564e1c82009-08-18 15:43:19 +02001432 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001433 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001434 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001435 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Swen Schillig564e1c82009-08-18 15:43:19 +02001437 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001438 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Swen Schillig564e1c82009-08-18 15:43:19 +02001441 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001442 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001443 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001444
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001445 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001446 retval = PTR_ERR(req);
1447 goto out;
1448 }
1449
Swen Schillig09a46c62009-08-18 15:43:16 +02001450 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001451 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001453 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001454 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001455 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001456 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001457 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001458 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Christof Schmitt287ac012008-07-02 10:56:40 +02001460 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001461 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001463 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001464 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001465 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001467out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001468 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 return retval;
1470}
1471
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001474 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001476 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001477 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001481 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001482 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001487 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 ZFCP_STATUS_COMMON_OPEN,
1489 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001494/**
1495 * zfcp_fsf_close_port - create and send close port request
1496 * @erp_action: pointer to struct zfcp_erp_action
1497 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Swen Schillig564e1c82009-08-18 15:43:19 +02001501 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001502 struct zfcp_fsf_req *req;
1503 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Swen Schillig564e1c82009-08-18 15:43:19 +02001505 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001506 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Swen Schillig564e1c82009-08-18 15:43:19 +02001509 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001510 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001511 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001512
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001513 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001514 retval = PTR_ERR(req);
1515 goto out;
1516 }
1517
Swen Schillig09a46c62009-08-18 15:43:16 +02001518 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001519 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001521 req->handler = zfcp_fsf_close_port_handler;
1522 req->data = erp_action->port;
1523 req->erp_action = erp_action;
1524 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001525 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Christof Schmitt287ac012008-07-02 10:56:40 +02001527 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001528 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001531 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001533out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001534 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 return retval;
1536}
1537
Swen Schillig5ab944f2008-10-01 12:42:17 +02001538static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1539{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001540 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001541 struct fsf_qtcb_header *header = &req->qtcb->header;
1542
1543 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001544 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001545 goto out;
1546 }
1547
1548 switch (header->fsf_status) {
1549 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1550 dev_warn(&req->adapter->ccw_device->dev,
1551 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001552 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001553 case FSF_ADAPTER_STATUS_AVAILABLE:
1554 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001555 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001556 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001557 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001558 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001559 case FSF_GOOD:
1560 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001561 /* fall through */
1562 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001563 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001564 }
1565out:
1566 wake_up(&wka_port->completion_wq);
1567}
1568
1569/**
1570 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001571 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001572 * Returns: 0 on success, error otherwise
1573 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001574int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001575{
Swen Schillig564e1c82009-08-18 15:43:19 +02001576 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001577 struct zfcp_fsf_req *req;
1578 int retval = -EIO;
1579
Swen Schillig564e1c82009-08-18 15:43:19 +02001580 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001581 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001582 goto out;
1583
Swen Schillig564e1c82009-08-18 15:43:19 +02001584 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001585 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001586 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001587
Swen Schillig5ab944f2008-10-01 12:42:17 +02001588 if (unlikely(IS_ERR(req))) {
1589 retval = PTR_ERR(req);
1590 goto out;
1591 }
1592
Swen Schillig09a46c62009-08-18 15:43:16 +02001593 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001594 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001595
1596 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001597 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598 req->data = wka_port;
1599
1600 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1601 retval = zfcp_fsf_req_send(req);
1602 if (retval)
1603 zfcp_fsf_req_free(req);
1604out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001605 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001606 return retval;
1607}
1608
1609static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1610{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001611 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001612
1613 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1614 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001615 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 }
1617
Christof Schmittbd0072e2009-11-24 16:54:11 +01001618 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001619 wake_up(&wka_port->completion_wq);
1620}
1621
1622/**
1623 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001624 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001625 * Returns: 0 on success, error otherwise
1626 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001627int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001628{
Swen Schillig564e1c82009-08-18 15:43:19 +02001629 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001630 struct zfcp_fsf_req *req;
1631 int retval = -EIO;
1632
Swen Schillig564e1c82009-08-18 15:43:19 +02001633 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001634 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001635 goto out;
1636
Swen Schillig564e1c82009-08-18 15:43:19 +02001637 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001638 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001639 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001640
Swen Schillig5ab944f2008-10-01 12:42:17 +02001641 if (unlikely(IS_ERR(req))) {
1642 retval = PTR_ERR(req);
1643 goto out;
1644 }
1645
Swen Schillig09a46c62009-08-18 15:43:16 +02001646 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001647 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001648
1649 req->handler = zfcp_fsf_close_wka_port_handler;
1650 req->data = wka_port;
1651 req->qtcb->header.port_handle = wka_port->handle;
1652
1653 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1654 retval = zfcp_fsf_req_send(req);
1655 if (retval)
1656 zfcp_fsf_req_free(req);
1657out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001658 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001659 return retval;
1660}
1661
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001662static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001664 struct zfcp_port *port = req->data;
1665 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001668 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001669 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001673 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001674 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001677 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001680 /* can't use generic zfcp_erp_modify_port_status because
1681 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1682 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001683 read_lock(&port->unit_list_lock);
1684 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001685 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1686 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001687 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001688 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001689 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 switch (header->fsf_status_qual.word[0]) {
1693 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001694 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001696 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 }
1699 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 /* can't use generic zfcp_erp_modify_port_status because
1702 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1703 */
1704 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001705 read_lock(&port->unit_list_lock);
1706 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001707 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1708 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001709 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
1713
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001714/**
1715 * zfcp_fsf_close_physical_port - close physical port
1716 * @erp_action: pointer to struct zfcp_erp_action
1717 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001719int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Swen Schillig564e1c82009-08-18 15:43:19 +02001721 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001722 struct zfcp_fsf_req *req;
1723 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Swen Schillig564e1c82009-08-18 15:43:19 +02001725 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001726 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Swen Schillig564e1c82009-08-18 15:43:19 +02001729 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001730 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001731 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001732
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001733 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001734 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 goto out;
1736 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737
Swen Schillig09a46c62009-08-18 15:43:16 +02001738 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001739 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001740
1741 req->data = erp_action->port;
1742 req->qtcb->header.port_handle = erp_action->port->handle;
1743 req->erp_action = erp_action;
1744 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001745 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001746
Christof Schmitt287ac012008-07-02 10:56:40 +02001747 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001748 retval = zfcp_fsf_req_send(req);
1749 if (retval) {
1750 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001751 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001752 }
1753out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001754 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 return retval;
1756}
1757
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001758static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001760 struct zfcp_adapter *adapter = req->adapter;
1761 struct zfcp_unit *unit = req->data;
1762 struct fsf_qtcb_header *header = &req->qtcb->header;
1763 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1764 struct fsf_queue_designator *queue_designator =
1765 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001766 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001768 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001769 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001772 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 ZFCP_STATUS_UNIT_SHARED |
1774 ZFCP_STATUS_UNIT_READONLY,
1775 &unit->status);
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 switch (header->fsf_status) {
1778
1779 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001780 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001781 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001785 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001787 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001790 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001791 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001794 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001795 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001796 "LUN 0x%Lx on port 0x%Lx is already in "
1797 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001798 (unsigned long long)unit->fcp_lun,
1799 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001800 queue_designator->cssid,
1801 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001802 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001803 zfcp_act_eval_err(adapter,
1804 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001805 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1807 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001811 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001812 "No handle is available for LUN "
1813 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001814 (unsigned long long)unit->fcp_lun,
1815 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001816 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001817 /* fall through */
1818 case FSF_INVALID_COMMAND_OPTION:
1819 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 switch (header->fsf_status_qual.word[0]) {
1823 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001824 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001825 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001827 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 }
1830 break;
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001835
1836 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1837 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001838 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001839 exclusive = (bottom->lun_access_info &
1840 FSF_UNIT_ACCESS_EXCLUSIVE);
1841 readwrite = (bottom->lun_access_info &
1842 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1843
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (!exclusive)
1845 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1846 &unit->status);
1847
1848 if (!readwrite) {
1849 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1850 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001851 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001852 "SCSI device at LUN 0x%016Lx on port "
1853 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001854 (unsigned long long)unit->fcp_lun,
1855 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
1857
1858 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001859 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001860 "Exclusive read-only access not "
1861 "supported (unit 0x%016Lx, "
1862 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001863 (unsigned long long)unit->fcp_lun,
1864 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001865 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001866 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001867 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001870 "Shared read-write access not "
1871 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001872 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001873 (unsigned long long)unit->fcp_lun,
1874 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001875 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001877 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 }
1879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
1884/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001885 * zfcp_fsf_open_unit - open unit
1886 * @erp_action: pointer to struct zfcp_erp_action
1887 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001891 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001892 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001893 struct zfcp_fsf_req *req;
1894 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Swen Schillig564e1c82009-08-18 15:43:19 +02001896 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001897 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Swen Schillig564e1c82009-08-18 15:43:19 +02001900 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001901 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001902 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001903
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001904 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001905 retval = PTR_ERR(req);
1906 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001907 }
1908
Swen Schillig09a46c62009-08-18 15:43:16 +02001909 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001910 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001912 req->qtcb->header.port_handle = erp_action->port->handle;
1913 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1914 req->handler = zfcp_fsf_open_unit_handler;
1915 req->data = erp_action->unit;
1916 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001917 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001918
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001919 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1920 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Christof Schmitt287ac012008-07-02 10:56:40 +02001922 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001923 retval = zfcp_fsf_req_send(req);
1924 if (retval) {
1925 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001926 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001928out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001929 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 return retval;
1931}
1932
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001933static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001935 struct zfcp_unit *unit = req->data;
1936
1937 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001938 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939
1940 switch (req->qtcb->header.fsf_status) {
1941 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001942 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001943 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1944 break;
1945 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001946 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001947 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1948 break;
1949 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001950 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001951 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001952 break;
1953 case FSF_ADAPTER_STATUS_AVAILABLE:
1954 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1955 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001956 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001957 /* fall through */
1958 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1959 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1960 break;
1961 }
1962 break;
1963 case FSF_GOOD:
1964 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1965 break;
1966 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001967}
1968
1969/**
1970 * zfcp_fsf_close_unit - close zfcp unit
1971 * @erp_action: pointer to struct zfcp_unit
1972 * Returns: 0 on success, error otherwise
1973 */
1974int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1975{
Swen Schillig564e1c82009-08-18 15:43:19 +02001976 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001977 struct zfcp_fsf_req *req;
1978 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Swen Schillig564e1c82009-08-18 15:43:19 +02001980 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001981 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001983
Swen Schillig564e1c82009-08-18 15:43:19 +02001984 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001985 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001986 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001987
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001988 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 retval = PTR_ERR(req);
1990 goto out;
1991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Swen Schillig09a46c62009-08-18 15:43:16 +02001993 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001994 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001996 req->qtcb->header.port_handle = erp_action->port->handle;
1997 req->qtcb->header.lun_handle = erp_action->unit->handle;
1998 req->handler = zfcp_fsf_close_unit_handler;
1999 req->data = erp_action->unit;
2000 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002001 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
Christof Schmitt287ac012008-07-02 10:56:40 +02002003 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004 retval = zfcp_fsf_req_send(req);
2005 if (retval) {
2006 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002007 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002008 }
2009out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002010 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002011 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
Christof Schmittc9615852008-05-06 11:00:05 +02002014static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2015{
2016 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002017 lat_rec->min = min(lat_rec->min, lat);
2018 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002019}
2020
Christof Schmittd9742b42009-11-24 16:54:03 +01002021static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002022{
Christof Schmittd9742b42009-11-24 16:54:03 +01002023 struct fsf_qual_latency_info *lat_in;
2024 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002025 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002026 struct zfcp_blk_drv_data blktrc;
2027 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002028
Christof Schmittd9742b42009-11-24 16:54:03 +01002029 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002030
Christof Schmittd9742b42009-11-24 16:54:03 +01002031 blktrc.flags = 0;
2032 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2033 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2034 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002035 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002036 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002037
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002038 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2039 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002040 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2041 blktrc.channel_lat = lat_in->channel_lat * ticks;
2042 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2043
2044 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002045 case FSF_DATADIR_DIF_READ_STRIP:
2046 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002047 case FSF_DATADIR_READ:
2048 lat = &unit->latencies.read;
2049 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002050 case FSF_DATADIR_DIF_WRITE_INSERT:
2051 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002052 case FSF_DATADIR_WRITE:
2053 lat = &unit->latencies.write;
2054 break;
2055 case FSF_DATADIR_CMND:
2056 lat = &unit->latencies.cmd;
2057 break;
2058 }
2059
2060 if (lat) {
2061 spin_lock(&unit->latencies.lock);
2062 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2063 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2064 lat->counter++;
2065 spin_unlock(&unit->latencies.lock);
2066 }
Christof Schmittc9615852008-05-06 11:00:05 +02002067 }
2068
Christof Schmittd9742b42009-11-24 16:54:03 +01002069 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2070 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002071}
2072
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002073static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002075 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002076 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 read_lock_irqsave(&req->adapter->abort_lock, flags);
2080
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002081 scpnt = req->data;
2082 if (unlikely(!scpnt)) {
2083 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2084 return;
2085 }
2086
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002088 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 goto skip_fsfstatus;
2090 }
2091
Felix Beckef3eb712010-07-16 15:37:42 +02002092 switch (req->qtcb->header.fsf_status) {
2093 case FSF_INCONSISTENT_PROT_DATA:
2094 case FSF_INVALID_PROT_PARM:
2095 set_host_byte(scpnt, DID_ERROR);
2096 goto skip_fsfstatus;
2097 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2098 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2099 goto skip_fsfstatus;
2100 case FSF_APP_TAG_CHECK_FAILURE:
2101 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2102 goto skip_fsfstatus;
2103 case FSF_REF_TAG_CHECK_FAILURE:
2104 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2105 goto skip_fsfstatus;
2106 }
Christof Schmitt4318e082009-11-24 16:54:08 +01002107 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2108 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002110skip_fsfstatus:
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002111 zfcp_fsf_req_trace(req, scpnt);
Christof Schmittab725282010-02-17 11:18:57 +01002112 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 /*
2117 * We must hold this lock until scsi_done has been called.
2118 * Otherwise we may call scsi_done after abort regarding this
2119 * command has completed.
2120 * Note: scsi_done must not block!
2121 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002122 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002125static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Christof Schmitt4318e082009-11-24 16:54:08 +01002127 struct fcp_resp_with_ext *fcp_rsp;
2128 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Christof Schmitt4318e082009-11-24 16:54:08 +01002130 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2131 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2132
2133 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002134 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2135 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002139static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2140{
2141 struct zfcp_unit *unit;
2142 struct fsf_qtcb_header *header = &req->qtcb->header;
2143
2144 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2145 unit = req->data;
2146 else
2147 unit = req->unit;
2148
2149 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2150 goto skip_fsfstatus;
2151
2152 switch (header->fsf_status) {
2153 case FSF_HANDLE_MISMATCH:
2154 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002155 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002156 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2157 break;
2158 case FSF_FCPLUN_NOT_VALID:
2159 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002160 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002161 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2162 break;
2163 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2164 zfcp_fsf_class_not_supp(req);
2165 break;
2166 case FSF_ACCESS_DENIED:
2167 zfcp_fsf_access_denied_unit(req, unit);
2168 break;
2169 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2170 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002171 "Incorrect direction %d, unit 0x%016Lx on port "
2172 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002173 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002174 (unsigned long long)unit->fcp_lun,
2175 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002176 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2177 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002178 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2179 break;
2180 case FSF_CMND_LENGTH_NOT_VALID:
2181 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002182 "Incorrect CDB length %d, unit 0x%016Lx on "
2183 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002184 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002185 (unsigned long long)unit->fcp_lun,
2186 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002187 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2188 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002189 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2190 break;
2191 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002192 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002193 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002194 break;
2195 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002196 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002197 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002198 break;
2199 case FSF_ADAPTER_STATUS_AVAILABLE:
2200 if (header->fsf_status_qual.word[0] ==
2201 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002202 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002203 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2204 break;
2205 }
2206skip_fsfstatus:
2207 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2208 zfcp_fsf_send_fcp_ctm_handler(req);
2209 else {
2210 zfcp_fsf_send_fcp_command_task_handler(req);
2211 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002212 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002213 }
2214}
2215
Felix Beckef3eb712010-07-16 15:37:42 +02002216static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2217{
2218 switch (scsi_get_prot_op(scsi_cmnd)) {
2219 case SCSI_PROT_NORMAL:
2220 switch (scsi_cmnd->sc_data_direction) {
2221 case DMA_NONE:
2222 *data_dir = FSF_DATADIR_CMND;
2223 break;
2224 case DMA_FROM_DEVICE:
2225 *data_dir = FSF_DATADIR_READ;
2226 break;
2227 case DMA_TO_DEVICE:
2228 *data_dir = FSF_DATADIR_WRITE;
2229 break;
2230 case DMA_BIDIRECTIONAL:
2231 return -EINVAL;
2232 }
2233 break;
2234
2235 case SCSI_PROT_READ_STRIP:
2236 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2237 break;
2238 case SCSI_PROT_WRITE_INSERT:
2239 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2240 break;
2241 case SCSI_PROT_READ_PASS:
2242 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2243 break;
2244 case SCSI_PROT_WRITE_PASS:
2245 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2246 break;
2247 default:
2248 return -EINVAL;
2249 }
2250
2251 return 0;
2252}
2253
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002254/**
2255 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 * @unit: unit where command is sent to
2257 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002258 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002259int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2260 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002261{
2262 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002263 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002264 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Felix Beckef3eb712010-07-16 15:37:42 +02002265 int real_bytes, retval = -EIO, dix_bytes = 0;
Christof Schmitt63caf362009-03-02 13:09:00 +01002266 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002267 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002268 struct fsf_qtcb_bottom_io *io;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269
2270 if (unlikely(!(atomic_read(&unit->status) &
2271 ZFCP_STATUS_COMMON_UNBLOCKED)))
2272 return -EBUSY;
2273
Swen Schillig564e1c82009-08-18 15:43:19 +02002274 spin_lock(&qdio->req_q_lock);
Swen Schillig706eca42010-07-16 15:37:38 +02002275 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002276 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002277 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002278 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002279
Christof Schmitt1674b402010-04-30 18:09:34 +02002280 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2281 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2282
Swen Schillig564e1c82009-08-18 15:43:19 +02002283 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002284 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002285
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002286 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002287 retval = PTR_ERR(req);
2288 goto out;
2289 }
2290
Felix Beckef3eb712010-07-16 15:37:42 +02002291 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2292
2293 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002294 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295 req->unit = unit;
2296 req->data = scsi_cmnd;
2297 req->handler = zfcp_fsf_send_fcp_command_handler;
2298 req->qtcb->header.lun_handle = unit->handle;
2299 req->qtcb->header.port_handle = unit->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002300 io->service_class = FSF_CLASS_3;
2301 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002302
Felix Beckef3eb712010-07-16 15:37:42 +02002303 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2304 io->data_block_length = scsi_cmnd->device->sector_size;
2305 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002306 }
2307
Felix Beckef3eb712010-07-16 15:37:42 +02002308 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2309
Christof Schmitt1674b402010-04-30 18:09:34 +02002310 get_device(&unit->dev);
2311
Christof Schmitt4318e082009-11-24 16:54:08 +01002312 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2313 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002314
Felix Beckef3eb712010-07-16 15:37:42 +02002315 if (scsi_prot_sg_count(scsi_cmnd)) {
2316 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2317 scsi_prot_sg_count(scsi_cmnd));
2318 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2319 scsi_prot_sglist(scsi_cmnd));
2320 io->prot_data_length = dix_bytes;
2321 }
2322
Christof Schmitt1674b402010-04-30 18:09:34 +02002323 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02002324 scsi_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002325
2326 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002327 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328
Felix Beckef3eb712010-07-16 15:37:42 +02002329 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2330
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002331 retval = zfcp_fsf_req_send(req);
2332 if (unlikely(retval))
2333 goto failed_scsi_cmnd;
2334
2335 goto out;
2336
2337failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002338 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339 zfcp_fsf_req_free(req);
2340 scsi_cmnd->host_scribble = NULL;
2341out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002342 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002343 return retval;
2344}
2345
2346/**
2347 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348 * @unit: pointer to struct zfcp_unit
2349 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002350 * Returns: on success pointer to struct fsf_req, NULL otherwise
2351 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002352struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002354 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002355 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002356 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002357
2358 if (unlikely(!(atomic_read(&unit->status) &
2359 ZFCP_STATUS_COMMON_UNBLOCKED)))
2360 return NULL;
2361
Swen Schillig564e1c82009-08-18 15:43:19 +02002362 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002363 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002364 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002365
Swen Schillig564e1c82009-08-18 15:43:19 +02002366 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002367 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002368 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002369
Swen Schillig633528c2008-11-26 18:07:37 +01002370 if (IS_ERR(req)) {
2371 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002372 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002373 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002374
2375 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2376 req->data = unit;
2377 req->handler = zfcp_fsf_send_fcp_command_handler;
2378 req->qtcb->header.lun_handle = unit->handle;
2379 req->qtcb->header.port_handle = unit->port->handle;
2380 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2381 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002382 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002383
Christof Schmitt1674b402010-04-30 18:09:34 +02002384 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002385
Christof Schmitt4318e082009-11-24 16:54:08 +01002386 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2387 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002388
2389 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2390 if (!zfcp_fsf_req_send(req))
2391 goto out;
2392
2393 zfcp_fsf_req_free(req);
2394 req = NULL;
2395out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002396 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002397 return req;
2398}
2399
2400static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2401{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402}
2403
2404/**
2405 * zfcp_fsf_control_file - control file upload/download
2406 * @adapter: pointer to struct zfcp_adapter
2407 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2408 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002410struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2411 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
Swen Schillig564e1c82009-08-18 15:43:19 +02002413 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002414 struct zfcp_fsf_req *req = NULL;
2415 struct fsf_qtcb_bottom_support *bottom;
2416 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Christof Schmitt45633fd2008-06-10 18:20:55 +02002418 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2419 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Christof Schmitt45633fd2008-06-10 18:20:55 +02002421 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2423 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2426 direction = SBAL_FLAGS0_TYPE_READ;
2427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002429 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 }
2431
Swen Schillig564e1c82009-08-18 15:43:19 +02002432 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002433 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002434 goto out;
2435
Christof Schmitt1674b402010-04-30 18:09:34 +02002436 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002437 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002439 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 }
2441
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002442 req->handler = zfcp_fsf_control_file_handler;
2443
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002444 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002446 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Swen Schillig01b04752010-07-16 15:37:37 +02002448 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2449
Christof Schmitt45633fd2008-06-10 18:20:55 +02002450 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002451 zfcp_fsf_req_free(req);
2452 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002453 }
Felix Beckef3eb712010-07-16 15:37:42 +02002454 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002456 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2457 retval = zfcp_fsf_req_send(req);
2458out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002459 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002460
2461 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002462 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002463 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002465 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002467
2468/**
2469 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2470 * @adapter: pointer to struct zfcp_adapter
2471 * @sbal_idx: response queue index of SBAL to be processed
2472 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002473void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002474{
Swen Schillig564e1c82009-08-18 15:43:19 +02002475 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002476 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002477 struct qdio_buffer_element *sbale;
2478 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +01002479 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002480 int idx;
2481
2482 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2483
2484 sbale = &sbal->element[idx];
2485 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb92010-02-17 11:18:50 +01002486 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002487
2488 if (!fsf_req)
2489 /*
2490 * Unknown request means that we have potentially memory
2491 * corruption and must stop the machine immediately.
2492 */
2493 panic("error: unknown req_id (%lx) on adapter %s.\n",
2494 req_id, dev_name(&adapter->ccw_device->dev));
2495
Christof Schmitt34c2b712010-02-17 11:18:59 +01002496 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002497 zfcp_fsf_req_complete(fsf_req);
2498
2499 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2500 break;
2501 }
2502}