blob: 63402fd5f9aeef77cc88f4a4b7245cc7db10e336 [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 Schmittb6bd2fb2010-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 Schmittb6bd2fb2010-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
529 return 0;
530}
531
532static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
533{
534 struct zfcp_adapter *adapter = req->adapter;
535 struct fsf_qtcb *qtcb = req->qtcb;
536 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
537 struct Scsi_Host *shost = adapter->scsi_host;
538
539 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
540 return;
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200543 adapter->adapter_features = bottom->adapter_features;
544 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500545 adapter->peer_wwpn = 0;
546 adapter->peer_wwnn = 0;
547 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200549 switch (qtcb->header.fsf_status) {
550 case FSF_GOOD:
551 if (zfcp_fsf_exchange_config_evaluate(req))
552 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200553
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200554 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
555 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200556 "FCP adapter maximum QTCB size (%d bytes) "
557 "is too small\n",
558 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100559 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200560 return;
561 }
562 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
563 &adapter->status);
564 break;
565 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200566 fc_host_node_name(shost) = 0;
567 fc_host_port_name(shost) = 0;
568 fc_host_port_id(shost) = 0;
569 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100570 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200572
573 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
574 &adapter->status);
575
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100576 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200577 &qtcb->header.fsf_status_qual.link_down_info);
578 break;
579 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100580 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200581 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200584 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200586 memcpy(fc_host_serial_number(shost), bottom->serial_number,
587 min(FC_SERIAL_NUMBER_SIZE, 17));
588 EBCASC(fc_host_serial_number(shost),
589 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200592 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200593 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200594 "The FCP adapter only supports newer "
595 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100596 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200599 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200600 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200601 "The FCP adapter only supports older "
602 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100603 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200609 struct zfcp_adapter *adapter = req->adapter;
610 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
611 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200613 if (req->data)
614 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100615
Christof Schmitt02829852009-03-02 13:09:06 +0100616 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100617 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100618 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
619 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100620 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
621 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
622 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100623 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
624 FC_FC4_LIST_SIZE);
625 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
626 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200629static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return;
635
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 case FSF_GOOD:
638 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200639 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200640 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100642 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200643 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646}
647
Swen Schilliga4623c42009-08-18 15:43:15 +0200648static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200649{
650 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200651
652 if (likely(pool))
653 req = mempool_alloc(pool, GFP_ATOMIC);
654 else
655 req = kmalloc(sizeof(*req), GFP_ATOMIC);
656
657 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200659
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200660 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100661 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 return req;
663}
664
Swen Schilliga4623c42009-08-18 15:43:15 +0200665static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200666{
Swen Schilliga4623c42009-08-18 15:43:15 +0200667 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200668
669 if (likely(pool))
670 qtcb = mempool_alloc(pool, GFP_ATOMIC);
671 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200672 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
673
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200674 if (unlikely(!qtcb))
675 return NULL;
676
677 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200678 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200679}
680
Swen Schillig564e1c82009-08-18 15:43:19 +0200681static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200682 u32 fsf_cmd, u32 sbtype,
683 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Swen Schillig564e1c82009-08-18 15:43:19 +0200685 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200686 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200687
688 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200689 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200690
691 if (adapter->req_no == 0)
692 adapter->req_no++;
693
694 INIT_LIST_HEAD(&req->list);
695 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200696 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200697
698 req->adapter = adapter;
699 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100700 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200701
Swen Schilliga4623c42009-08-18 15:43:15 +0200702 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
703 if (likely(pool))
704 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
705 else
706 req->qtcb = zfcp_qtcb_alloc(NULL);
707
708 if (unlikely(!req->qtcb)) {
709 zfcp_fsf_req_free(req);
710 return ERR_PTR(-ENOMEM);
711 }
712
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100713 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200714 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200715 req->qtcb->prefix.req_id = req->req_id;
716 req->qtcb->prefix.ulp_info = 26;
717 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
718 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
719 req->qtcb->header.req_handle = req->req_id;
720 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200721 }
722
Christof Schmitt1674b402010-04-30 18:09:34 +0200723 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
724 req->qtcb, sizeof(struct fsf_qtcb));
725
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200726 return req;
727}
728
729static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
730{
731 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200732 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100733 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100734 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200735
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100736 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200737
Swen Schillig706eca42010-07-16 15:37:38 +0200738 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200739 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100740 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200741 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100742 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100743 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100744 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200745 return -EIO;
746 }
747
748 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200749 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200750 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100751 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200752
753 return 0;
754}
755
756/**
757 * zfcp_fsf_status_read - send status read request
758 * @adapter: pointer to struct zfcp_adapter
759 * @req_flags: request flags
760 * Returns: 0 on success, ERROR otherwise
761 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200762int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200763{
Swen Schillig564e1c82009-08-18 15:43:19 +0200764 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200765 struct zfcp_fsf_req *req;
766 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200767 int retval = -EIO;
768
Swen Schillig564e1c82009-08-18 15:43:19 +0200769 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200770 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Christof Schmitt1674b402010-04-30 18:09:34 +0200773 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200774 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200775 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200776 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 goto out;
778 }
779
Swen Schilliga4623c42009-08-18 15:43:15 +0200780 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 if (!sr_buf) {
782 retval = -ENOMEM;
783 goto failed_buf;
784 }
785 memset(sr_buf, 0, sizeof(*sr_buf));
786 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200787
788 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
789 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200790
791 retval = zfcp_fsf_req_send(req);
792 if (retval)
793 goto failed_req_send;
794
795 goto out;
796
797failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200798 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200799failed_buf:
800 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200801 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200802out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200803 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return retval;
805}
806
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200807static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809 struct zfcp_unit *unit = req->data;
810 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200812 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
813 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200815 switch (req->qtcb->header.fsf_status) {
816 case FSF_PORT_HANDLE_NOT_VALID:
817 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100818 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
819 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 case FSF_LUN_HANDLE_NOT_VALID:
824 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100825 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200826 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
830 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200832 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100833 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100834 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200835 break;
836 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100837 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100838 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200839 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200841 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200843 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200844 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200846 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 break;
848 }
849 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
852 break;
853 }
854}
855
856/**
857 * zfcp_fsf_abort_fcp_command - abort running SCSI command
858 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200859 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 */
862
863struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100864 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200867 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200868
Swen Schillig564e1c82009-08-18 15:43:19 +0200869 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200870 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200871 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200872 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200873 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200874 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100875 if (IS_ERR(req)) {
876 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200877 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100878 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200879
880 if (unlikely(!(atomic_read(&unit->status) &
881 ZFCP_STATUS_COMMON_UNBLOCKED)))
882 goto out_error_free;
883
Christof Schmitt1674b402010-04-30 18:09:34 +0200884 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200885
886 req->data = unit;
887 req->handler = zfcp_fsf_abort_fcp_command_handler;
888 req->qtcb->header.lun_handle = unit->handle;
889 req->qtcb->header.port_handle = unit->port->handle;
890 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
891
892 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
893 if (!zfcp_fsf_req_send(req))
894 goto out;
895
896out_error_free:
897 zfcp_fsf_req_free(req);
898 req = NULL;
899out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200900 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200901 return req;
902}
903
904static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
905{
906 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100907 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908 struct fsf_qtcb_header *header = &req->qtcb->header;
909
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100910 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200911
912 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
913 goto skip_fsfstatus;
914
915 switch (header->fsf_status) {
916 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200917 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100918 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200919 break;
920 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
921 zfcp_fsf_class_not_supp(req);
922 break;
923 case FSF_ADAPTER_STATUS_AVAILABLE:
924 switch (header->fsf_status_qual.word[0]){
925 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200926 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
927 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
928 break;
929 }
930 break;
931 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 break;
933 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100934 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200935 break;
936 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100937 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200938 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200939 case FSF_GENERIC_COMMAND_REJECTED:
940 case FSF_PAYLOAD_SIZE_MISMATCH:
941 case FSF_REQUEST_SIZE_TOO_LARGE:
942 case FSF_RESPONSE_SIZE_TOO_LARGE:
943 case FSF_SBAL_MISMATCH:
944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
945 break;
946 }
947
948skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100949 if (ct->handler)
950 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200951}
952
Christof Schmitt1674b402010-04-30 18:09:34 +0200953static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
954 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200955 struct scatterlist *sg_req,
956 struct scatterlist *sg_resp)
957{
Christof Schmitt1674b402010-04-30 18:09:34 +0200958 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
959 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
960 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200961}
962
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100963static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
964 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200965 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200966{
Swen Schillig42428f72009-08-18 15:43:18 +0200967 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200968 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200969 int bytes;
970
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100971 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200972 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
973 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100974 return -EOPNOTSUPP;
975
Christof Schmitt1674b402010-04-30 18:09:34 +0200976 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
977 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200978 return 0;
979 }
980
981 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200982 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200983 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
984 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100985 return 0;
986 }
987
Swen Schillig01b04752010-07-16 15:37:37 +0200988 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200989 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200990 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200991 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +0200992 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200993
Christof Schmitt34c2b712010-02-17 11:18:59 +0100994 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200995 sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +0200996 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200997 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200998 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +0200999
Christof Schmittb1a58982009-09-24 10:23:21 +02001000 return 0;
1001}
1002
1003static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1004 struct scatterlist *sg_req,
1005 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001006 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001007{
1008 int ret;
1009
Swen Schillig01b04752010-07-16 15:37:37 +02001010 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001011 if (ret)
1012 return ret;
1013
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001014 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001015 if (timeout > 255)
1016 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001017 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001018 req->qtcb->bottom.support.timeout = timeout;
1019 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001020
1021 return 0;
1022}
1023
1024/**
1025 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1026 * @ct: pointer to struct zfcp_send_ct with data for request
1027 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001028 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001029int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001030 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1031 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001032{
Swen Schillig564e1c82009-08-18 15:43:19 +02001033 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001034 struct zfcp_fsf_req *req;
1035 int ret = -EIO;
1036
Swen Schillig564e1c82009-08-18 15:43:19 +02001037 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001038 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001039 goto out;
1040
Christof Schmitt1674b402010-04-30 18:09:34 +02001041 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1042 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001043
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001044 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045 ret = PTR_ERR(req);
1046 goto out;
1047 }
1048
Swen Schillig09a46c62009-08-18 15:43:16 +02001049 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001050 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001051 if (ret)
1052 goto failed_send;
1053
1054 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001055 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 req->data = ct;
1057
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001058 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001059
1060 ret = zfcp_fsf_req_send(req);
1061 if (ret)
1062 goto failed_send;
1063
1064 goto out;
1065
1066failed_send:
1067 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001068out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001069 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001070 return ret;
1071}
1072
1073static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1074{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001075 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001076 struct zfcp_port *port = send_els->port;
1077 struct fsf_qtcb_header *header = &req->qtcb->header;
1078
1079 send_els->status = -EINVAL;
1080
1081 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1082 goto skip_fsfstatus;
1083
1084 switch (header->fsf_status) {
1085 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001086 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 send_els->status = 0;
1088 break;
1089 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1090 zfcp_fsf_class_not_supp(req);
1091 break;
1092 case FSF_ADAPTER_STATUS_AVAILABLE:
1093 switch (header->fsf_status_qual.word[0]){
1094 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001095 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1096 case FSF_SQ_RETRY_IF_POSSIBLE:
1097 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1098 break;
1099 }
1100 break;
1101 case FSF_ELS_COMMAND_REJECTED:
1102 case FSF_PAYLOAD_SIZE_MISMATCH:
1103 case FSF_REQUEST_SIZE_TOO_LARGE:
1104 case FSF_RESPONSE_SIZE_TOO_LARGE:
1105 break;
1106 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001107 if (port)
1108 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001109 break;
1110 case FSF_SBAL_MISMATCH:
1111 /* should never occure, avoided in zfcp_fsf_send_els */
1112 /* fall through */
1113 default:
1114 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1115 break;
1116 }
1117skip_fsfstatus:
1118 if (send_els->handler)
1119 send_els->handler(send_els->handler_data);
1120}
1121
1122/**
1123 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1124 * @els: pointer to struct zfcp_send_els with data for the command
1125 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001126int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001127 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001128{
1129 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001130 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001131 int ret = -EIO;
1132
Swen Schillig564e1c82009-08-18 15:43:19 +02001133 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001134 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001136
Christof Schmitt1674b402010-04-30 18:09:34 +02001137 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1138 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001139
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001140 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001141 ret = PTR_ERR(req);
1142 goto out;
1143 }
1144
Swen Schillig09a46c62009-08-18 15:43:16 +02001145 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001146
1147 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1148
1149 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001150
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001151 if (ret)
1152 goto failed_send;
1153
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001154 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001155 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001156 req->data = els;
1157
Swen Schillig57717102009-08-18 15:43:21 +02001158 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001159
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001160 ret = zfcp_fsf_req_send(req);
1161 if (ret)
1162 goto failed_send;
1163
1164 goto out;
1165
1166failed_send:
1167 zfcp_fsf_req_free(req);
1168out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001169 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001170 return ret;
1171}
1172
1173int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1174{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001175 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001176 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001177 int retval = -EIO;
1178
Swen Schillig564e1c82009-08-18 15:43:19 +02001179 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001180 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001181 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001182
Swen Schillig564e1c82009-08-18 15:43:19 +02001183 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001184 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001185 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001186
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001187 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001188 retval = PTR_ERR(req);
1189 goto out;
1190 }
1191
Swen Schillig09a46c62009-08-18 15:43:16 +02001192 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001193 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001194
1195 req->qtcb->bottom.config.feature_selection =
1196 FSF_FEATURE_CFDC |
1197 FSF_FEATURE_LUN_SHARING |
1198 FSF_FEATURE_NOTIFICATION_LOST |
1199 FSF_FEATURE_UPDATE_ALERT;
1200 req->erp_action = erp_action;
1201 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001202 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001203
Christof Schmitt287ac012008-07-02 10:56:40 +02001204 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001205 retval = zfcp_fsf_req_send(req);
1206 if (retval) {
1207 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001208 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209 }
1210out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001211 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001212 return retval;
1213}
1214
Swen Schillig564e1c82009-08-18 15:43:19 +02001215int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001216 struct fsf_qtcb_bottom_config *data)
1217{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001218 struct zfcp_fsf_req *req = NULL;
1219 int retval = -EIO;
1220
Swen Schillig564e1c82009-08-18 15:43:19 +02001221 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001222 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001223 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001224
Christof Schmitt1674b402010-04-30 18:09:34 +02001225 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1226 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001227
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001228 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001229 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001230 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001231 }
1232
Christof Schmitt1674b402010-04-30 18:09:34 +02001233 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001234 req->handler = zfcp_fsf_exchange_config_data_handler;
1235
1236 req->qtcb->bottom.config.feature_selection =
1237 FSF_FEATURE_CFDC |
1238 FSF_FEATURE_LUN_SHARING |
1239 FSF_FEATURE_NOTIFICATION_LOST |
1240 FSF_FEATURE_UPDATE_ALERT;
1241
1242 if (data)
1243 req->data = data;
1244
1245 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1246 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001247 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001248 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001249 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001250
1251 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001252 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001253
Christof Schmittada81b72009-04-17 15:08:03 +02001254out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001255 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001256 return retval;
1257}
1258
1259/**
1260 * zfcp_fsf_exchange_port_data - request information about local port
1261 * @erp_action: ERP action for the adapter for which port data is requested
1262 * Returns: 0 on success, error otherwise
1263 */
1264int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1265{
Swen Schillig564e1c82009-08-18 15:43:19 +02001266 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001267 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 int retval = -EIO;
1269
Swen Schillig564e1c82009-08-18 15:43:19 +02001270 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001271 return -EOPNOTSUPP;
1272
Swen Schillig564e1c82009-08-18 15:43:19 +02001273 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001274 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001275 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001276
Swen Schillig564e1c82009-08-18 15:43:19 +02001277 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001278 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001279 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001280
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001281 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282 retval = PTR_ERR(req);
1283 goto out;
1284 }
1285
Swen Schillig09a46c62009-08-18 15:43:16 +02001286 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001287 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001288
1289 req->handler = zfcp_fsf_exchange_port_data_handler;
1290 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001291 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001292
Christof Schmitt287ac012008-07-02 10:56:40 +02001293 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001294 retval = zfcp_fsf_req_send(req);
1295 if (retval) {
1296 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001297 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001298 }
1299out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001300 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001301 return retval;
1302}
1303
1304/**
1305 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001306 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001307 * @data: pointer to struct fsf_qtcb_bottom_port
1308 * Returns: 0 on success, error otherwise
1309 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001310int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001311 struct fsf_qtcb_bottom_port *data)
1312{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001313 struct zfcp_fsf_req *req = NULL;
1314 int retval = -EIO;
1315
Swen Schillig564e1c82009-08-18 15:43:19 +02001316 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317 return -EOPNOTSUPP;
1318
Swen Schillig564e1c82009-08-18 15:43:19 +02001319 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001320 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001321 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001322
Christof Schmitt1674b402010-04-30 18:09:34 +02001323 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1324 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001325
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001326 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001328 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329 }
1330
1331 if (data)
1332 req->data = data;
1333
Christof Schmitt1674b402010-04-30 18:09:34 +02001334 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001335
1336 req->handler = zfcp_fsf_exchange_port_data_handler;
1337 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1338 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001339 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001340
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001341 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001342 wait_for_completion(&req->completion);
1343
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001344 zfcp_fsf_req_free(req);
1345
1346 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001347
1348out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001349 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001350 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351}
1352
1353static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1354{
1355 struct zfcp_port *port = req->data;
1356 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001357 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358
1359 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001360 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001361
1362 switch (header->fsf_status) {
1363 case FSF_PORT_ALREADY_OPEN:
1364 break;
1365 case FSF_ACCESS_DENIED:
1366 zfcp_fsf_access_denied_port(req, port);
1367 break;
1368 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1369 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001370 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001371 "remote port 0x%016Lx\n",
1372 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001373 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001374 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1375 break;
1376 case FSF_ADAPTER_STATUS_AVAILABLE:
1377 switch (header->fsf_status_qual.word[0]) {
1378 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1379 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1382 break;
1383 }
1384 break;
1385 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1388 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001389 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1390 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1391 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 /* check whether D_ID has changed during open */
1393 /*
1394 * FIXME: This check is not airtight, as the FCP channel does
1395 * not monitor closures of target port connections caused on
1396 * the remote side. Thus, they might miss out on invalidating
1397 * locally cached WWPNs (and other N_Port parameters) of gone
1398 * target ports. So, our heroic attempt to make things safe
1399 * could be undermined by 'open port' response data tagged with
1400 * obsolete WWPNs. Another reason to monitor potential
1401 * connection closures ourself at least (by interpreting
1402 * incoming ELS' and unsolicited status). It just crosses my
1403 * mind that one should be able to cross-check by means of
1404 * another GID_PN straight after a port has been opened.
1405 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1406 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001407 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001408 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001409 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001410 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001413 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 break;
1415 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001416
1417out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001418 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419}
1420
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001421/**
1422 * zfcp_fsf_open_port - create and send open port request
1423 * @erp_action: pointer to struct zfcp_erp_action
1424 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001426int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Swen Schillig564e1c82009-08-18 15:43:19 +02001428 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001429 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001430 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001431 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Swen Schillig564e1c82009-08-18 15:43:19 +02001433 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001434 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Swen Schillig564e1c82009-08-18 15:43:19 +02001437 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001438 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001439 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001440
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001441 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001442 retval = PTR_ERR(req);
1443 goto out;
1444 }
1445
Swen Schillig09a46c62009-08-18 15:43:16 +02001446 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001447 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001449 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001450 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001451 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001452 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001453 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001454 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Christof Schmitt287ac012008-07-02 10:56:40 +02001456 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001457 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001459 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001460 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001461 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001463out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001464 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 return retval;
1466}
1467
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001468static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001473 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001477 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001478 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001483 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 ZFCP_STATUS_COMMON_OPEN,
1485 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001490/**
1491 * zfcp_fsf_close_port - create and send close port request
1492 * @erp_action: pointer to struct zfcp_erp_action
1493 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001495int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Swen Schillig564e1c82009-08-18 15:43:19 +02001497 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001498 struct zfcp_fsf_req *req;
1499 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Swen Schillig564e1c82009-08-18 15:43:19 +02001501 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001502 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Swen Schillig564e1c82009-08-18 15:43:19 +02001505 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001506 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001507 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001508
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001509 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510 retval = PTR_ERR(req);
1511 goto out;
1512 }
1513
Swen Schillig09a46c62009-08-18 15:43:16 +02001514 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001515 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001517 req->handler = zfcp_fsf_close_port_handler;
1518 req->data = erp_action->port;
1519 req->erp_action = erp_action;
1520 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001521 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Christof Schmitt287ac012008-07-02 10:56:40 +02001523 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001526 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001527 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001530 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return retval;
1532}
1533
Swen Schillig5ab944f2008-10-01 12:42:17 +02001534static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1535{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001536 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001537 struct fsf_qtcb_header *header = &req->qtcb->header;
1538
1539 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001540 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001541 goto out;
1542 }
1543
1544 switch (header->fsf_status) {
1545 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1546 dev_warn(&req->adapter->ccw_device->dev,
1547 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001548 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001549 case FSF_ADAPTER_STATUS_AVAILABLE:
1550 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001551 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001552 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001553 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001554 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001555 case FSF_GOOD:
1556 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001557 /* fall through */
1558 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001559 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001560 }
1561out:
1562 wake_up(&wka_port->completion_wq);
1563}
1564
1565/**
1566 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001567 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568 * Returns: 0 on success, error otherwise
1569 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001570int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001571{
Swen Schillig564e1c82009-08-18 15:43:19 +02001572 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001573 struct zfcp_fsf_req *req;
1574 int retval = -EIO;
1575
Swen Schillig564e1c82009-08-18 15:43:19 +02001576 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001577 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001578 goto out;
1579
Swen Schillig564e1c82009-08-18 15:43:19 +02001580 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001581 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001582 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001583
Swen Schillig5ab944f2008-10-01 12:42:17 +02001584 if (unlikely(IS_ERR(req))) {
1585 retval = PTR_ERR(req);
1586 goto out;
1587 }
1588
Swen Schillig09a46c62009-08-18 15:43:16 +02001589 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001590 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591
1592 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001593 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001594 req->data = wka_port;
1595
1596 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1597 retval = zfcp_fsf_req_send(req);
1598 if (retval)
1599 zfcp_fsf_req_free(req);
1600out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001601 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001602 return retval;
1603}
1604
1605static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1606{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001607 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001608
1609 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1610 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001611 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001612 }
1613
Christof Schmittbd0072e2009-11-24 16:54:11 +01001614 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001615 wake_up(&wka_port->completion_wq);
1616}
1617
1618/**
1619 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001620 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001621 * Returns: 0 on success, error otherwise
1622 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001623int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001624{
Swen Schillig564e1c82009-08-18 15:43:19 +02001625 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001626 struct zfcp_fsf_req *req;
1627 int retval = -EIO;
1628
Swen Schillig564e1c82009-08-18 15:43:19 +02001629 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001630 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631 goto out;
1632
Swen Schillig564e1c82009-08-18 15:43:19 +02001633 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001634 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001635 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001636
Swen Schillig5ab944f2008-10-01 12:42:17 +02001637 if (unlikely(IS_ERR(req))) {
1638 retval = PTR_ERR(req);
1639 goto out;
1640 }
1641
Swen Schillig09a46c62009-08-18 15:43:16 +02001642 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001643 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644
1645 req->handler = zfcp_fsf_close_wka_port_handler;
1646 req->data = wka_port;
1647 req->qtcb->header.port_handle = wka_port->handle;
1648
1649 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1650 retval = zfcp_fsf_req_send(req);
1651 if (retval)
1652 zfcp_fsf_req_free(req);
1653out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001654 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001655 return retval;
1656}
1657
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001658static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001660 struct zfcp_port *port = req->data;
1661 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001664 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001665 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001669 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001670 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001673 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001676 /* can't use generic zfcp_erp_modify_port_status because
1677 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1678 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001679 read_lock(&port->unit_list_lock);
1680 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001681 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1682 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001683 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001684 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001685 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 switch (header->fsf_status_qual.word[0]) {
1689 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001690 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001692 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 }
1695 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 /* can't use generic zfcp_erp_modify_port_status because
1698 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1699 */
1700 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001701 read_lock(&port->unit_list_lock);
1702 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001703 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1704 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001705 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001710/**
1711 * zfcp_fsf_close_physical_port - close physical port
1712 * @erp_action: pointer to struct zfcp_erp_action
1713 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001715int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Swen Schillig564e1c82009-08-18 15:43:19 +02001717 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001718 struct zfcp_fsf_req *req;
1719 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Swen Schillig564e1c82009-08-18 15:43:19 +02001721 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001722 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Swen Schillig564e1c82009-08-18 15:43:19 +02001725 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001726 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001727 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001728
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001729 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001730 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 goto out;
1732 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001733
Swen Schillig09a46c62009-08-18 15:43:16 +02001734 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001735 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001736
1737 req->data = erp_action->port;
1738 req->qtcb->header.port_handle = erp_action->port->handle;
1739 req->erp_action = erp_action;
1740 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001741 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001742
Christof Schmitt287ac012008-07-02 10:56:40 +02001743 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001744 retval = zfcp_fsf_req_send(req);
1745 if (retval) {
1746 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001747 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001748 }
1749out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001750 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 return retval;
1752}
1753
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001754static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001756 struct zfcp_adapter *adapter = req->adapter;
1757 struct zfcp_unit *unit = req->data;
1758 struct fsf_qtcb_header *header = &req->qtcb->header;
1759 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1760 struct fsf_queue_designator *queue_designator =
1761 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001762 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001764 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001765 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001768 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 ZFCP_STATUS_UNIT_SHARED |
1770 ZFCP_STATUS_UNIT_READONLY,
1771 &unit->status);
1772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 switch (header->fsf_status) {
1774
1775 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001776 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001777 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001781 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001783 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001786 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001787 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001790 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001791 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001792 "LUN 0x%Lx on port 0x%Lx is already in "
1793 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001794 (unsigned long long)unit->fcp_lun,
1795 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001796 queue_designator->cssid,
1797 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001798 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001799 zfcp_act_eval_err(adapter,
1800 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001801 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1803 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001804 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001807 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001808 "No handle is available for LUN "
1809 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001810 (unsigned long long)unit->fcp_lun,
1811 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001812 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001813 /* fall through */
1814 case FSF_INVALID_COMMAND_OPTION:
1815 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 switch (header->fsf_status_qual.word[0]) {
1819 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001820 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001821 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 }
1826 break;
1827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001831
1832 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1833 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001834 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001835 exclusive = (bottom->lun_access_info &
1836 FSF_UNIT_ACCESS_EXCLUSIVE);
1837 readwrite = (bottom->lun_access_info &
1838 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (!exclusive)
1841 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1842 &unit->status);
1843
1844 if (!readwrite) {
1845 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1846 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001847 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001848 "SCSI device at LUN 0x%016Lx on port "
1849 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001850 (unsigned long long)unit->fcp_lun,
1851 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
1853
1854 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001855 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001856 "Exclusive read-only access not "
1857 "supported (unit 0x%016Lx, "
1858 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001859 (unsigned long long)unit->fcp_lun,
1860 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001861 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001863 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001865 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001866 "Shared read-write access not "
1867 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001868 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001869 (unsigned long long)unit->fcp_lun,
1870 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001871 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001873 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
1875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878}
1879
1880/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001881 * zfcp_fsf_open_unit - open unit
1882 * @erp_action: pointer to struct zfcp_erp_action
1883 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001885int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001887 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001888 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001889 struct zfcp_fsf_req *req;
1890 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Swen Schillig564e1c82009-08-18 15:43:19 +02001892 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001893 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001894 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Swen Schillig564e1c82009-08-18 15:43:19 +02001896 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001897 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001898 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001899
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001900 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901 retval = PTR_ERR(req);
1902 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001903 }
1904
Swen Schillig09a46c62009-08-18 15:43:16 +02001905 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001906 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001908 req->qtcb->header.port_handle = erp_action->port->handle;
1909 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1910 req->handler = zfcp_fsf_open_unit_handler;
1911 req->data = erp_action->unit;
1912 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001913 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001914
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001915 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1916 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Christof Schmitt287ac012008-07-02 10:56:40 +02001918 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001919 retval = zfcp_fsf_req_send(req);
1920 if (retval) {
1921 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001922 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001924out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001925 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 return retval;
1927}
1928
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001929static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001931 struct zfcp_unit *unit = req->data;
1932
1933 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001934 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001935
1936 switch (req->qtcb->header.fsf_status) {
1937 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001938 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1940 break;
1941 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001942 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001943 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1944 break;
1945 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001946 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001947 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001948 break;
1949 case FSF_ADAPTER_STATUS_AVAILABLE:
1950 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1951 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001952 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001953 /* fall through */
1954 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1955 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1956 break;
1957 }
1958 break;
1959 case FSF_GOOD:
1960 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1961 break;
1962 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001963}
1964
1965/**
1966 * zfcp_fsf_close_unit - close zfcp unit
1967 * @erp_action: pointer to struct zfcp_unit
1968 * Returns: 0 on success, error otherwise
1969 */
1970int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1971{
Swen Schillig564e1c82009-08-18 15:43:19 +02001972 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001973 struct zfcp_fsf_req *req;
1974 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Swen Schillig564e1c82009-08-18 15:43:19 +02001976 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001977 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001979
Swen Schillig564e1c82009-08-18 15:43:19 +02001980 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001981 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001982 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001983
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001984 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001985 retval = PTR_ERR(req);
1986 goto out;
1987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Swen Schillig09a46c62009-08-18 15:43:16 +02001989 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001990 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001992 req->qtcb->header.port_handle = erp_action->port->handle;
1993 req->qtcb->header.lun_handle = erp_action->unit->handle;
1994 req->handler = zfcp_fsf_close_unit_handler;
1995 req->data = erp_action->unit;
1996 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001997 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Christof Schmitt287ac012008-07-02 10:56:40 +02001999 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002000 retval = zfcp_fsf_req_send(req);
2001 if (retval) {
2002 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002003 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004 }
2005out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002006 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002007 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008}
2009
Christof Schmittc9615852008-05-06 11:00:05 +02002010static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2011{
2012 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002013 lat_rec->min = min(lat_rec->min, lat);
2014 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002015}
2016
Christof Schmittd9742b42009-11-24 16:54:03 +01002017static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002018{
Christof Schmittd9742b42009-11-24 16:54:03 +01002019 struct fsf_qual_latency_info *lat_in;
2020 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002021 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002022 struct zfcp_blk_drv_data blktrc;
2023 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002024
Christof Schmittd9742b42009-11-24 16:54:03 +01002025 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002026
Christof Schmittd9742b42009-11-24 16:54:03 +01002027 blktrc.flags = 0;
2028 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2029 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2030 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002031 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002032 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002033
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002034 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2035 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002036 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2037 blktrc.channel_lat = lat_in->channel_lat * ticks;
2038 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2039
2040 switch (req->qtcb->bottom.io.data_direction) {
2041 case FSF_DATADIR_READ:
2042 lat = &unit->latencies.read;
2043 break;
2044 case FSF_DATADIR_WRITE:
2045 lat = &unit->latencies.write;
2046 break;
2047 case FSF_DATADIR_CMND:
2048 lat = &unit->latencies.cmd;
2049 break;
2050 }
2051
2052 if (lat) {
2053 spin_lock(&unit->latencies.lock);
2054 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2055 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2056 lat->counter++;
2057 spin_unlock(&unit->latencies.lock);
2058 }
Christof Schmittc9615852008-05-06 11:00:05 +02002059 }
2060
Christof Schmittd9742b42009-11-24 16:54:03 +01002061 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2062 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002063}
2064
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002065static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002067 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002068 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002071 read_lock_irqsave(&req->adapter->abort_lock, flags);
2072
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002073 scpnt = req->data;
2074 if (unlikely(!scpnt)) {
2075 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2076 return;
2077 }
2078
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002079 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002080 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 goto skip_fsfstatus;
2082 }
2083
Christof Schmitt4318e082009-11-24 16:54:08 +01002084 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2085 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002087skip_fsfstatus:
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002088 zfcp_fsf_req_trace(req, scpnt);
Christof Schmittab725282010-02-17 11:18:57 +01002089 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 /*
2094 * We must hold this lock until scsi_done has been called.
2095 * Otherwise we may call scsi_done after abort regarding this
2096 * command has completed.
2097 * Note: scsi_done must not block!
2098 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002099 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002102static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
Christof Schmitt4318e082009-11-24 16:54:08 +01002104 struct fcp_resp_with_ext *fcp_rsp;
2105 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Christof Schmitt4318e082009-11-24 16:54:08 +01002107 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2108 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2109
2110 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002111 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2112 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
2114
2115
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002116static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2117{
2118 struct zfcp_unit *unit;
2119 struct fsf_qtcb_header *header = &req->qtcb->header;
2120
2121 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2122 unit = req->data;
2123 else
2124 unit = req->unit;
2125
2126 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2127 goto skip_fsfstatus;
2128
2129 switch (header->fsf_status) {
2130 case FSF_HANDLE_MISMATCH:
2131 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002132 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002133 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2134 break;
2135 case FSF_FCPLUN_NOT_VALID:
2136 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002137 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002138 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2139 break;
2140 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2141 zfcp_fsf_class_not_supp(req);
2142 break;
2143 case FSF_ACCESS_DENIED:
2144 zfcp_fsf_access_denied_unit(req, unit);
2145 break;
2146 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2147 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002148 "Incorrect direction %d, unit 0x%016Lx on port "
2149 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002150 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002151 (unsigned long long)unit->fcp_lun,
2152 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002153 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2154 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002155 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2156 break;
2157 case FSF_CMND_LENGTH_NOT_VALID:
2158 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002159 "Incorrect CDB length %d, unit 0x%016Lx on "
2160 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002161 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002162 (unsigned long long)unit->fcp_lun,
2163 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002164 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2165 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002166 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2167 break;
2168 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002169 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002170 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002171 break;
2172 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002173 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002174 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002175 break;
2176 case FSF_ADAPTER_STATUS_AVAILABLE:
2177 if (header->fsf_status_qual.word[0] ==
2178 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002179 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002180 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2181 break;
2182 }
2183skip_fsfstatus:
2184 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2185 zfcp_fsf_send_fcp_ctm_handler(req);
2186 else {
2187 zfcp_fsf_send_fcp_command_task_handler(req);
2188 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002189 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002190 }
2191}
2192
2193/**
2194 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002195 * @unit: unit where command is sent to
2196 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002197 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002198int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2199 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002200{
2201 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002202 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002203 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002205 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002206 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002207
2208 if (unlikely(!(atomic_read(&unit->status) &
2209 ZFCP_STATUS_COMMON_UNBLOCKED)))
2210 return -EBUSY;
2211
Swen Schillig564e1c82009-08-18 15:43:19 +02002212 spin_lock(&qdio->req_q_lock);
Swen Schillig706eca42010-07-16 15:37:38 +02002213 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002214 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002215 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002216 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002217
Christof Schmitt1674b402010-04-30 18:09:34 +02002218 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2219 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2220
Swen Schillig564e1c82009-08-18 15:43:19 +02002221 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002222 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002223
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002224 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002225 retval = PTR_ERR(req);
2226 goto out;
2227 }
2228
Swen Schillig09a46c62009-08-18 15:43:16 +02002229 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002230 req->unit = unit;
2231 req->data = scsi_cmnd;
2232 req->handler = zfcp_fsf_send_fcp_command_handler;
2233 req->qtcb->header.lun_handle = unit->handle;
2234 req->qtcb->header.port_handle = unit->port->handle;
2235 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002236 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002237
2238 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2239
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002240 /*
2241 * set depending on data direction:
2242 * data direction bits in SBALE (SB Type)
2243 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002244 */
2245 switch (scsi_cmnd->sc_data_direction) {
2246 case DMA_NONE:
2247 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002248 break;
2249 case DMA_FROM_DEVICE:
2250 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 break;
2252 case DMA_TO_DEVICE:
2253 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002254 break;
2255 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 goto failed_scsi_cmnd;
2257 }
2258
Christof Schmitt1674b402010-04-30 18:09:34 +02002259 get_device(&unit->dev);
2260
Christof Schmitt4318e082009-11-24 16:54:08 +01002261 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2262 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002263
Christof Schmitt1674b402010-04-30 18:09:34 +02002264 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02002265 scsi_sglist(scsi_cmnd));
2266 if (unlikely(real_bytes < 0))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002267 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002268
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002269 retval = zfcp_fsf_req_send(req);
2270 if (unlikely(retval))
2271 goto failed_scsi_cmnd;
2272
2273 goto out;
2274
2275failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002276 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002277 zfcp_fsf_req_free(req);
2278 scsi_cmnd->host_scribble = NULL;
2279out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002280 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002281 return retval;
2282}
2283
2284/**
2285 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002286 * @unit: pointer to struct zfcp_unit
2287 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002288 * Returns: on success pointer to struct fsf_req, NULL otherwise
2289 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002290struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002291{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002292 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002293 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002294 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295
2296 if (unlikely(!(atomic_read(&unit->status) &
2297 ZFCP_STATUS_COMMON_UNBLOCKED)))
2298 return NULL;
2299
Swen Schillig564e1c82009-08-18 15:43:19 +02002300 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002301 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002302 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002303
Swen Schillig564e1c82009-08-18 15:43:19 +02002304 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002305 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002306 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002307
Swen Schillig633528c2008-11-26 18:07:37 +01002308 if (IS_ERR(req)) {
2309 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002310 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002311 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002312
2313 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2314 req->data = unit;
2315 req->handler = zfcp_fsf_send_fcp_command_handler;
2316 req->qtcb->header.lun_handle = unit->handle;
2317 req->qtcb->header.port_handle = unit->port->handle;
2318 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2319 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002320 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002321
Christof Schmitt1674b402010-04-30 18:09:34 +02002322 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002323
Christof Schmitt4318e082009-11-24 16:54:08 +01002324 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2325 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326
2327 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2328 if (!zfcp_fsf_req_send(req))
2329 goto out;
2330
2331 zfcp_fsf_req_free(req);
2332 req = NULL;
2333out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002334 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002335 return req;
2336}
2337
2338static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2339{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002340}
2341
2342/**
2343 * zfcp_fsf_control_file - control file upload/download
2344 * @adapter: pointer to struct zfcp_adapter
2345 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2346 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002348struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2349 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350{
Swen Schillig564e1c82009-08-18 15:43:19 +02002351 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 struct zfcp_fsf_req *req = NULL;
2353 struct fsf_qtcb_bottom_support *bottom;
2354 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Christof Schmitt45633fd2008-06-10 18:20:55 +02002356 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2357 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Christof Schmitt45633fd2008-06-10 18:20:55 +02002359 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2361 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2364 direction = SBAL_FLAGS0_TYPE_READ;
2365 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002367 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 }
2369
Swen Schillig564e1c82009-08-18 15:43:19 +02002370 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002371 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002372 goto out;
2373
Christof Schmitt1674b402010-04-30 18:09:34 +02002374 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002375 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
2379
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002380 req->handler = zfcp_fsf_control_file_handler;
2381
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002382 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002384 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Swen Schillig01b04752010-07-16 15:37:37 +02002386 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2387
Christof Schmitt45633fd2008-06-10 18:20:55 +02002388 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002389 zfcp_fsf_req_free(req);
2390 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002393 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2394 retval = zfcp_fsf_req_send(req);
2395out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002396 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002397
2398 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002399 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002400 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002402 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002404
2405/**
2406 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2407 * @adapter: pointer to struct zfcp_adapter
2408 * @sbal_idx: response queue index of SBAL to be processed
2409 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002410void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002411{
Swen Schillig564e1c82009-08-18 15:43:19 +02002412 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002413 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002414 struct qdio_buffer_element *sbale;
2415 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002416 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002417 int idx;
2418
2419 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2420
2421 sbale = &sbal->element[idx];
2422 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002423 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002424
2425 if (!fsf_req)
2426 /*
2427 * Unknown request means that we have potentially memory
2428 * corruption and must stop the machine immediately.
2429 */
2430 panic("error: unknown req_id (%lx) on adapter %s.\n",
2431 req_id, dev_name(&adapter->ccw_device->dev));
2432
Christof Schmitt34c2b712010-02-17 11:18:59 +01002433 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002434 zfcp_fsf_req_complete(fsf_req);
2435
2436 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2437 break;
2438 }
2439}