blob: 9d1d7d1842cef7f3d8abd73fc7be931502360110 [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;
Christof Schmitt339f4f42010-07-16 15:37:43 +020024 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010025 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020027}
28
29static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
30 unsigned long timeout)
31{
32 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
33 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
34 fsf_req->timer.expires = jiffies + timeout;
35 add_timer(&fsf_req->timer);
36}
37
38static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
39{
40 BUG_ON(!fsf_req->erp_action);
41 fsf_req->timer.function = zfcp_erp_timeout_handler;
42 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
43 fsf_req->timer.expires = jiffies + 30 * HZ;
44 add_timer(&fsf_req->timer);
45}
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* association between FSF command and FSF QTCB type */
48static u32 fsf_qtcb_type[] = {
49 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
50 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
59 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
60 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
62};
63
Christof Schmitt553448f2008-06-10 18:20:58 +020064static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
65{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020066 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020067 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020069
Christof Schmittff3b24f2008-10-01 12:42:15 +020070 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020071 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020072 "Access denied according to ACT rule type %s, "
73 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020074}
75
76static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
77 struct zfcp_port *port)
78{
79 struct fsf_qtcb_header *header = &req->qtcb->header;
80 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020081 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020082 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020083 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
84 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010085 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020086 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
87}
88
89static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
90 struct zfcp_unit *unit)
91{
92 struct fsf_qtcb_header *header = &req->qtcb->header;
93 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020094 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020095 (unsigned long long)unit->fcp_lun,
96 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020097 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
98 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010099 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200100 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
101}
102
103static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
104{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200105 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
106 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100107 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
109}
110
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200111/**
112 * zfcp_fsf_req_free - free memory used by fsf request
113 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200115void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200117 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200118 if (likely(req->qtcb))
119 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200120 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200121 return;
122 }
123
Swen Schilliga4623c42009-08-18 15:43:15 +0200124 if (likely(req->qtcb))
125 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
126 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200129static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Swen Schilligecf0c772009-11-24 16:53:58 +0100131 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200132 struct fsf_status_read_buffer *sr_buf = req->data;
133 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100135 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Swen Schilligecf0c772009-11-24 16:53:58 +0100137 read_lock_irqsave(&adapter->port_list_lock, flags);
138 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200139 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100140 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100141 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200142 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100143 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100146static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200147 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200151 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
152 return;
153
154 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200155
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100156 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200157
158 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200160
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200164 "There is no light signal from the local "
165 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200166 break;
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200169 "There is a wrap plug instead of a fibre "
170 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200171 break;
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200174 "The adjacent fibre channel node does not "
175 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200176 break;
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200179 "The FCP device is suspended because of a "
180 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200181 break;
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200186 break;
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200189 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200190 break;
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200193 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200194 break;
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200199 break;
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200204 break;
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200209 break;
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200212 "The mode table on the FCP adapter "
213 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200214 break;
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200217 "All NPIV ports on the FCP adapter have "
218 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200219 break;
220 default:
221 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200224 }
225out:
226 zfcp_erp_adapter_failed(adapter, id, req);
227}
228
229static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
230{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
234
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100237 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200238 break;
239 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100240 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200241 break;
242 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100243 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200244 };
245}
246
247static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
248{
249 struct zfcp_adapter *adapter = req->adapter;
250 struct fsf_status_read_buffer *sr_buf = req->data;
251
252 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200253 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200254 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200255 zfcp_fsf_req_free(req);
256 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
Swen Schillig57717102009-08-18 15:43:21 +0200259 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200260
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200261 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200263 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200266 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200271 dev_warn(&adapter->ccw_device->dev,
272 "The error threshold for checksum statistics "
273 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200274 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200277 zfcp_fsf_status_read_link_down(req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200278 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200281 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200282 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100284 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 ZFCP_STATUS_COMMON_RUNNING,
286 ZFCP_SET);
287 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200288 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
289 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100290 "fssrh_2", req);
Sven Schuetz2d1e5472010-07-16 15:37:39 +0200291 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100294 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200295 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100296 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
297 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200298 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100299 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100300 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100302 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200304 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200305 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200306 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200308
Swen Schilliga4623c42009-08-18 15:43:15 +0200309 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200310 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200311
312 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200313 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200316static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200318 switch (req->qtcb->header.fsf_status_qual.word[0]) {
319 case FSF_SQ_FCP_RSP_AVAILABLE:
320 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
321 case FSF_SQ_NO_RETRY_POSSIBLE:
322 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
323 return;
324 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200325 break;
326 case FSF_SQ_NO_RECOM:
327 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200328 "The FCP adapter reported a problem "
329 "that cannot be recovered\n");
Christof Schmitt339f4f42010-07-16 15:37:43 +0200330 zfcp_qdio_siosl(req->adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100331 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200332 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200334 /* all non-return stats set FSFREQ_ERROR*/
335 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
336}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200338static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
339{
340 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
341 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200342
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200343 switch (req->qtcb->header.fsf_status) {
344 case FSF_UNKNOWN_COMMAND:
345 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200346 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100348 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200349 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200357static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359 struct zfcp_adapter *adapter = req->adapter;
360 struct fsf_qtcb *qtcb = req->qtcb;
361 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Swen Schillig57717102009-08-18 15:43:21 +0200363 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100366 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200367 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200370 switch (qtcb->prefix.prot_status) {
371 case FSF_PROT_GOOD:
372 case FSF_PROT_FSF_STATUS_PRESENTED:
373 return;
374 case FSF_PROT_QTCB_VERSION_ERROR:
375 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200376 "QTCB version 0x%x not supported by FCP adapter "
377 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
378 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100379 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200381 case FSF_PROT_ERROR_STATE:
382 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100383 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100384 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200386 case FSF_PROT_UNSUPP_QTCB_TYPE:
387 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200388 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100389 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200391 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
392 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
393 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200395 case FSF_PROT_DUPLICATE_REQUEST_ID:
396 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200397 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200398 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100399 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200401 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100402 zfcp_fsf_link_down_info_eval(req, "fspse_5",
403 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100404 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100405 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200407 case FSF_PROT_REEST_QUEUE:
408 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100409 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200410 ZFCP_STATUS_COMMON_RUNNING,
411 ZFCP_SET);
412 zfcp_erp_adapter_reopen(adapter,
413 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100414 ZFCP_STATUS_COMMON_ERP_FAILED,
415 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200419 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200420 qtcb->prefix.prot_status);
Christof Schmitt339f4f42010-07-16 15:37:43 +0200421 zfcp_qdio_siosl(adapter);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100422 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200424 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200428 * zfcp_fsf_req_complete - process completion of a FSF request
429 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200431 * When a request has been completed either from the FCP adapter,
432 * or it has been dismissed due to a queue shutdown, this function
433 * is called to process the completion status and trigger further
434 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200436static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200437{
438 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
439 zfcp_fsf_status_read_handler(req);
440 return;
441 }
442
443 del_timer(&req->timer);
444 zfcp_fsf_protstatus_eval(req);
445 zfcp_fsf_fsfstatus_eval(req);
446 req->handler(req);
447
448 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200449 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200450
451 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
452 zfcp_fsf_req_free(req);
453 else
Swen Schillig058b8642009-08-18 15:43:14 +0200454 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200455}
456
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200457/**
458 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
459 * @adapter: pointer to struct zfcp_adapter
460 *
461 * Never ever call this without shutting down the adapter first.
462 * Otherwise the adapter would continue using and corrupting s390 storage.
463 * Included BUG_ON() call to ensure this is done.
464 * ERP is supposed to be the only user of this function.
465 */
466void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
467{
468 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200469 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200470
471 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100472 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200473
474 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
475 list_del(&req->list);
476 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_fsf_req_complete(req);
478 }
479}
480
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200481static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100483 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200484 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200485 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100486 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100488 /* adjust pointers for missing command code */
489 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
490 - sizeof(u32));
491 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
492 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200493
494 if (req->data)
495 memcpy(req->data, bottom, sizeof(*bottom));
496
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100497 fc_host_port_name(shost) = nsp->fl_wwpn;
498 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100499 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200500 fc_host_speed(shost) = bottom->fc_link_speed;
501 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
502
503 adapter->hydra_version = bottom->adapter_type;
Christof Schmittfaf4cd82010-07-16 15:37:36 +0200504 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200505 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
506 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200507
508 if (fc_host_permanent_port_name(shost) == -1)
509 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
510
511 switch (bottom->fc_topology) {
512 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100513 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100514 adapter->peer_wwpn = plogi->fl_wwpn;
515 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 break;
518 case FSF_TOPO_FABRIC:
519 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200520 break;
521 case FSF_TOPO_AL:
522 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200523 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200524 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200525 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200526 "Unknown or unsupported arbitrated loop "
527 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100528 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200529 return -EIO;
530 }
531
Felix Beckef3eb712010-07-16 15:37:42 +0200532 zfcp_scsi_set_prot(adapter);
533
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200534 return 0;
535}
536
537static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
538{
539 struct zfcp_adapter *adapter = req->adapter;
540 struct fsf_qtcb *qtcb = req->qtcb;
541 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
542 struct Scsi_Host *shost = adapter->scsi_host;
543
544 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
545 return;
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200548 adapter->adapter_features = bottom->adapter_features;
549 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500550 adapter->peer_wwpn = 0;
551 adapter->peer_wwnn = 0;
552 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200554 switch (qtcb->header.fsf_status) {
555 case FSF_GOOD:
556 if (zfcp_fsf_exchange_config_evaluate(req))
557 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200558
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200559 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
560 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200561 "FCP adapter maximum QTCB size (%d bytes) "
562 "is too small\n",
563 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100564 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200565 return;
566 }
567 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
568 &adapter->status);
569 break;
570 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200571 fc_host_node_name(shost) = 0;
572 fc_host_port_name(shost) = 0;
573 fc_host_port_id(shost) = 0;
574 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100575 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200577
578 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
579 &adapter->status);
580
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100581 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200582 &qtcb->header.fsf_status_qual.link_down_info);
583 break;
584 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100585 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200586 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200589 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200591 memcpy(fc_host_serial_number(shost), bottom->serial_number,
592 min(FC_SERIAL_NUMBER_SIZE, 17));
593 EBCASC(fc_host_serial_number(shost),
594 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200597 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200598 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200599 "The FCP adapter only supports newer "
600 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100601 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200602 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200605 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200606 "The FCP adapter only supports older "
607 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100608 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
611
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200612static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200614 struct zfcp_adapter *adapter = req->adapter;
615 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
616 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200618 if (req->data)
619 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100620
Christof Schmitt02829852009-03-02 13:09:06 +0100621 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100622 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100623 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
624 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100625 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
626 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
627 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100628 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
629 FC_FC4_LIST_SIZE);
630 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
631 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200634static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100637
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200638 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return;
640
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200641 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200642 case FSF_GOOD:
643 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200644 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200645 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200646 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100647 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200648 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651}
652
Swen Schilliga4623c42009-08-18 15:43:15 +0200653static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200654{
655 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200656
657 if (likely(pool))
658 req = mempool_alloc(pool, GFP_ATOMIC);
659 else
660 req = kmalloc(sizeof(*req), GFP_ATOMIC);
661
662 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200663 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200664
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200665 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100666 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200667 return req;
668}
669
Swen Schilliga4623c42009-08-18 15:43:15 +0200670static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200671{
Swen Schilliga4623c42009-08-18 15:43:15 +0200672 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200673
674 if (likely(pool))
675 qtcb = mempool_alloc(pool, GFP_ATOMIC);
676 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200677 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
678
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200679 if (unlikely(!qtcb))
680 return NULL;
681
682 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200683 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684}
685
Swen Schillig564e1c82009-08-18 15:43:19 +0200686static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200687 u32 fsf_cmd, u32 sbtype,
688 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Swen Schillig564e1c82009-08-18 15:43:19 +0200690 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200691 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692
693 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200694 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200695
696 if (adapter->req_no == 0)
697 adapter->req_no++;
698
699 INIT_LIST_HEAD(&req->list);
700 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200701 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200702
703 req->adapter = adapter;
704 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100705 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200706
Swen Schilliga4623c42009-08-18 15:43:15 +0200707 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
708 if (likely(pool))
709 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
710 else
711 req->qtcb = zfcp_qtcb_alloc(NULL);
712
713 if (unlikely(!req->qtcb)) {
714 zfcp_fsf_req_free(req);
715 return ERR_PTR(-ENOMEM);
716 }
717
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100718 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200719 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200720 req->qtcb->prefix.req_id = req->req_id;
721 req->qtcb->prefix.ulp_info = 26;
722 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
723 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
724 req->qtcb->header.req_handle = req->req_id;
725 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200726 }
727
Christof Schmitt1674b402010-04-30 18:09:34 +0200728 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
729 req->qtcb, sizeof(struct fsf_qtcb));
730
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200731 return req;
732}
733
734static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
735{
736 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200737 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100738 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100739 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200740
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100741 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742
Swen Schillig706eca42010-07-16 15:37:38 +0200743 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200744 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100745 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200746 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100747 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100748 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100749 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200750 return -EIO;
751 }
752
753 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200754 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200755 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100756 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200757
758 return 0;
759}
760
761/**
762 * zfcp_fsf_status_read - send status read request
763 * @adapter: pointer to struct zfcp_adapter
764 * @req_flags: request flags
765 * Returns: 0 on success, ERROR otherwise
766 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200767int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200768{
Swen Schillig564e1c82009-08-18 15:43:19 +0200769 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200770 struct zfcp_fsf_req *req;
771 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200772 int retval = -EIO;
773
Swen Schillig564e1c82009-08-18 15:43:19 +0200774 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200775 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Christof Schmitt1674b402010-04-30 18:09:34 +0200778 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200779 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200780 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 goto out;
783 }
784
Swen Schilliga4623c42009-08-18 15:43:15 +0200785 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200786 if (!sr_buf) {
787 retval = -ENOMEM;
788 goto failed_buf;
789 }
790 memset(sr_buf, 0, sizeof(*sr_buf));
791 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200792
793 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
794 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200795
796 retval = zfcp_fsf_req_send(req);
797 if (retval)
798 goto failed_req_send;
799
800 goto out;
801
802failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200803 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200804failed_buf:
805 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200806 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200807out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200808 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return retval;
810}
811
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200812static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200814 struct zfcp_unit *unit = req->data;
815 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
818 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 switch (req->qtcb->header.fsf_status) {
821 case FSF_PORT_HANDLE_NOT_VALID:
822 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100823 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
824 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200825 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200828 case FSF_LUN_HANDLE_NOT_VALID:
829 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100830 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200831 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200834 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
835 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200837 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100838 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100839 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200840 break;
841 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100842 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200844 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200846 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200848 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200849 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200851 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 break;
853 }
854 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200856 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
857 break;
858 }
859}
860
861/**
862 * zfcp_fsf_abort_fcp_command - abort running SCSI command
863 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200864 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 */
867
868struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100869 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200871 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200872 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200873
Swen Schillig564e1c82009-08-18 15:43:19 +0200874 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200875 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200877 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200878 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200879 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100880 if (IS_ERR(req)) {
881 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100883 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884
885 if (unlikely(!(atomic_read(&unit->status) &
886 ZFCP_STATUS_COMMON_UNBLOCKED)))
887 goto out_error_free;
888
Christof Schmitt1674b402010-04-30 18:09:34 +0200889 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200890
891 req->data = unit;
892 req->handler = zfcp_fsf_abort_fcp_command_handler;
893 req->qtcb->header.lun_handle = unit->handle;
894 req->qtcb->header.port_handle = unit->port->handle;
895 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
896
897 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
898 if (!zfcp_fsf_req_send(req))
899 goto out;
900
901out_error_free:
902 zfcp_fsf_req_free(req);
903 req = NULL;
904out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200905 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200906 return req;
907}
908
909static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
910{
911 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100912 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200913 struct fsf_qtcb_header *header = &req->qtcb->header;
914
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100915 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200916
917 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
918 goto skip_fsfstatus;
919
920 switch (header->fsf_status) {
921 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200922 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100923 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924 break;
925 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
926 zfcp_fsf_class_not_supp(req);
927 break;
928 case FSF_ADAPTER_STATUS_AVAILABLE:
929 switch (header->fsf_status_qual.word[0]){
930 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200931 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
932 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
933 break;
934 }
935 break;
936 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200937 break;
938 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200940 break;
941 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100942 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200943 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200944 case FSF_GENERIC_COMMAND_REJECTED:
945 case FSF_PAYLOAD_SIZE_MISMATCH:
946 case FSF_REQUEST_SIZE_TOO_LARGE:
947 case FSF_RESPONSE_SIZE_TOO_LARGE:
948 case FSF_SBAL_MISMATCH:
949 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
950 break;
951 }
952
953skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100954 if (ct->handler)
955 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200956}
957
Christof Schmitt1674b402010-04-30 18:09:34 +0200958static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
959 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200960 struct scatterlist *sg_req,
961 struct scatterlist *sg_resp)
962{
Christof Schmitt1674b402010-04-30 18:09:34 +0200963 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
964 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
965 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200966}
967
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100968static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
969 struct scatterlist *sg_req,
Swen Schillig01b04752010-07-16 15:37:37 +0200970 struct scatterlist *sg_resp)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200971{
Swen Schillig42428f72009-08-18 15:43:18 +0200972 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200973 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200974 int bytes;
975
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100976 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200977 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
978 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100979 return -EOPNOTSUPP;
980
Christof Schmitt1674b402010-04-30 18:09:34 +0200981 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
982 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200983 return 0;
984 }
985
986 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200987 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200988 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
989 sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100990 return 0;
991 }
992
Swen Schillig01b04752010-07-16 15:37:37 +0200993 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200995 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +0200996 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200997 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +0200998 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200999
Christof Schmitt34c2b712010-02-17 11:18:59 +01001000 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02001001 sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001002 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001003 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001004 return -EIO;
Felix Beckef3eb712010-07-16 15:37:42 +02001005 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001006
Christof Schmittb1a58982009-09-24 10:23:21 +02001007 return 0;
1008}
1009
1010static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1011 struct scatterlist *sg_req,
1012 struct scatterlist *sg_resp,
Swen Schillig01b04752010-07-16 15:37:37 +02001013 unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001014{
1015 int ret;
1016
Swen Schillig01b04752010-07-16 15:37:37 +02001017 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
Christof Schmittb1a58982009-09-24 10:23:21 +02001018 if (ret)
1019 return ret;
1020
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001021 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001022 if (timeout > 255)
1023 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001024 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001025 req->qtcb->bottom.support.timeout = timeout;
1026 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001027
1028 return 0;
1029}
1030
1031/**
1032 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1033 * @ct: pointer to struct zfcp_send_ct with data for request
1034 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001035 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001036int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001037 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1038 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001039{
Swen Schillig564e1c82009-08-18 15:43:19 +02001040 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001041 struct zfcp_fsf_req *req;
1042 int ret = -EIO;
1043
Swen Schillig564e1c82009-08-18 15:43:19 +02001044 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001045 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001046 goto out;
1047
Christof Schmitt1674b402010-04-30 18:09:34 +02001048 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1049 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001050
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001051 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001052 ret = PTR_ERR(req);
1053 goto out;
1054 }
1055
Swen Schillig09a46c62009-08-18 15:43:16 +02001056 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001057 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001058 if (ret)
1059 goto failed_send;
1060
1061 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001062 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063 req->data = ct;
1064
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001065 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001066
1067 ret = zfcp_fsf_req_send(req);
1068 if (ret)
1069 goto failed_send;
1070
1071 goto out;
1072
1073failed_send:
1074 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001075out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001076 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001077 return ret;
1078}
1079
1080static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1081{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001082 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001083 struct zfcp_port *port = send_els->port;
1084 struct fsf_qtcb_header *header = &req->qtcb->header;
1085
1086 send_els->status = -EINVAL;
1087
1088 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1089 goto skip_fsfstatus;
1090
1091 switch (header->fsf_status) {
1092 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001093 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001094 send_els->status = 0;
1095 break;
1096 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1097 zfcp_fsf_class_not_supp(req);
1098 break;
1099 case FSF_ADAPTER_STATUS_AVAILABLE:
1100 switch (header->fsf_status_qual.word[0]){
1101 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001102 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1103 case FSF_SQ_RETRY_IF_POSSIBLE:
1104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1105 break;
1106 }
1107 break;
1108 case FSF_ELS_COMMAND_REJECTED:
1109 case FSF_PAYLOAD_SIZE_MISMATCH:
1110 case FSF_REQUEST_SIZE_TOO_LARGE:
1111 case FSF_RESPONSE_SIZE_TOO_LARGE:
1112 break;
1113 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001114 if (port)
1115 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001116 break;
1117 case FSF_SBAL_MISMATCH:
1118 /* should never occure, avoided in zfcp_fsf_send_els */
1119 /* fall through */
1120 default:
1121 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1122 break;
1123 }
1124skip_fsfstatus:
1125 if (send_els->handler)
1126 send_els->handler(send_els->handler_data);
1127}
1128
1129/**
1130 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1131 * @els: pointer to struct zfcp_send_els with data for the command
1132 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001133int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001134 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135{
1136 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001137 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001138 int ret = -EIO;
1139
Swen Schillig564e1c82009-08-18 15:43:19 +02001140 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001141 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001142 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001143
Christof Schmitt1674b402010-04-30 18:09:34 +02001144 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1145 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001146
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001147 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001148 ret = PTR_ERR(req);
1149 goto out;
1150 }
1151
Swen Schillig09a46c62009-08-18 15:43:16 +02001152 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig01b04752010-07-16 15:37:37 +02001153
1154 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1155
1156 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001157
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001158 if (ret)
1159 goto failed_send;
1160
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001161 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001163 req->data = els;
1164
Swen Schillig57717102009-08-18 15:43:21 +02001165 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001166
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001167 ret = zfcp_fsf_req_send(req);
1168 if (ret)
1169 goto failed_send;
1170
1171 goto out;
1172
1173failed_send:
1174 zfcp_fsf_req_free(req);
1175out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001176 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001177 return ret;
1178}
1179
1180int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1181{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001183 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001184 int retval = -EIO;
1185
Swen Schillig564e1c82009-08-18 15:43:19 +02001186 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001187 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001188 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001189
Swen Schillig564e1c82009-08-18 15:43:19 +02001190 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001191 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001192 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001193
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001194 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195 retval = PTR_ERR(req);
1196 goto out;
1197 }
1198
Swen Schillig09a46c62009-08-18 15:43:16 +02001199 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001200 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001201
1202 req->qtcb->bottom.config.feature_selection =
1203 FSF_FEATURE_CFDC |
1204 FSF_FEATURE_LUN_SHARING |
1205 FSF_FEATURE_NOTIFICATION_LOST |
1206 FSF_FEATURE_UPDATE_ALERT;
1207 req->erp_action = erp_action;
1208 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001209 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210
Christof Schmitt287ac012008-07-02 10:56:40 +02001211 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001212 retval = zfcp_fsf_req_send(req);
1213 if (retval) {
1214 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001215 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001216 }
1217out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001218 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 return retval;
1220}
1221
Swen Schillig564e1c82009-08-18 15:43:19 +02001222int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223 struct fsf_qtcb_bottom_config *data)
1224{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225 struct zfcp_fsf_req *req = NULL;
1226 int retval = -EIO;
1227
Swen Schillig564e1c82009-08-18 15:43:19 +02001228 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001229 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001230 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001231
Christof Schmitt1674b402010-04-30 18:09:34 +02001232 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1233 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001234
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001235 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001236 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001237 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001238 }
1239
Christof Schmitt1674b402010-04-30 18:09:34 +02001240 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 req->handler = zfcp_fsf_exchange_config_data_handler;
1242
1243 req->qtcb->bottom.config.feature_selection =
1244 FSF_FEATURE_CFDC |
1245 FSF_FEATURE_LUN_SHARING |
1246 FSF_FEATURE_NOTIFICATION_LOST |
1247 FSF_FEATURE_UPDATE_ALERT;
1248
1249 if (data)
1250 req->data = data;
1251
1252 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1253 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001254 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001255 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001256 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257
1258 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001259 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001260
Christof Schmittada81b72009-04-17 15:08:03 +02001261out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001262 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001263 return retval;
1264}
1265
1266/**
1267 * zfcp_fsf_exchange_port_data - request information about local port
1268 * @erp_action: ERP action for the adapter for which port data is requested
1269 * Returns: 0 on success, error otherwise
1270 */
1271int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1272{
Swen Schillig564e1c82009-08-18 15:43:19 +02001273 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001274 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001275 int retval = -EIO;
1276
Swen Schillig564e1c82009-08-18 15:43:19 +02001277 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001278 return -EOPNOTSUPP;
1279
Swen Schillig564e1c82009-08-18 15:43:19 +02001280 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001281 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001283
Swen Schillig564e1c82009-08-18 15:43:19 +02001284 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001285 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001286 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001287
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001288 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289 retval = PTR_ERR(req);
1290 goto out;
1291 }
1292
Swen Schillig09a46c62009-08-18 15:43:16 +02001293 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001294 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295
1296 req->handler = zfcp_fsf_exchange_port_data_handler;
1297 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001298 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001299
Christof Schmitt287ac012008-07-02 10:56:40 +02001300 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001301 retval = zfcp_fsf_req_send(req);
1302 if (retval) {
1303 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001304 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001305 }
1306out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001307 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308 return retval;
1309}
1310
1311/**
1312 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001313 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001314 * @data: pointer to struct fsf_qtcb_bottom_port
1315 * Returns: 0 on success, error otherwise
1316 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001317int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001318 struct fsf_qtcb_bottom_port *data)
1319{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001320 struct zfcp_fsf_req *req = NULL;
1321 int retval = -EIO;
1322
Swen Schillig564e1c82009-08-18 15:43:19 +02001323 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001324 return -EOPNOTSUPP;
1325
Swen Schillig564e1c82009-08-18 15:43:19 +02001326 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001327 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001328 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001329
Christof Schmitt1674b402010-04-30 18:09:34 +02001330 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1331 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001332
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001333 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001334 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001335 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336 }
1337
1338 if (data)
1339 req->data = data;
1340
Christof Schmitt1674b402010-04-30 18:09:34 +02001341 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342
1343 req->handler = zfcp_fsf_exchange_port_data_handler;
1344 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1345 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001346 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001347
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001349 wait_for_completion(&req->completion);
1350
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351 zfcp_fsf_req_free(req);
1352
1353 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001354
1355out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001356 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001357 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358}
1359
1360static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1361{
1362 struct zfcp_port *port = req->data;
1363 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001364 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001365
1366 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001367 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001368
1369 switch (header->fsf_status) {
1370 case FSF_PORT_ALREADY_OPEN:
1371 break;
1372 case FSF_ACCESS_DENIED:
1373 zfcp_fsf_access_denied_port(req, port);
1374 break;
1375 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1376 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001377 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001378 "remote port 0x%016Lx\n",
1379 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001380 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1382 break;
1383 case FSF_ADAPTER_STATUS_AVAILABLE:
1384 switch (header->fsf_status_qual.word[0]) {
1385 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1386 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001387 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001388 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1389 break;
1390 }
1391 break;
1392 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1395 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001396 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1397 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1398 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 /* check whether D_ID has changed during open */
1400 /*
1401 * FIXME: This check is not airtight, as the FCP channel does
1402 * not monitor closures of target port connections caused on
1403 * the remote side. Thus, they might miss out on invalidating
1404 * locally cached WWPNs (and other N_Port parameters) of gone
1405 * target ports. So, our heroic attempt to make things safe
1406 * could be undermined by 'open port' response data tagged with
1407 * obsolete WWPNs. Another reason to monitor potential
1408 * connection closures ourself at least (by interpreting
1409 * incoming ELS' and unsolicited status). It just crosses my
1410 * mind that one should be able to cross-check by means of
1411 * another GID_PN straight after a port has been opened.
1412 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1413 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001414 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001415 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001416 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001417 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001420 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 break;
1422 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001423
1424out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001425 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001428/**
1429 * zfcp_fsf_open_port - create and send open port request
1430 * @erp_action: pointer to struct zfcp_erp_action
1431 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001433int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
Swen Schillig564e1c82009-08-18 15:43:19 +02001435 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001436 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001437 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001438 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Swen Schillig564e1c82009-08-18 15:43:19 +02001440 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001441 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Swen Schillig564e1c82009-08-18 15:43:19 +02001444 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001445 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001446 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001447
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001448 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001449 retval = PTR_ERR(req);
1450 goto out;
1451 }
1452
Swen Schillig09a46c62009-08-18 15:43:16 +02001453 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001454 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001456 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001457 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001458 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001459 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001460 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001461 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Christof Schmitt287ac012008-07-02 10:56:40 +02001463 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001464 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001466 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001467 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001468 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001470out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001471 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 return retval;
1473}
1474
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001477 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001480 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001482 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001484 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001485 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001490 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 ZFCP_STATUS_COMMON_OPEN,
1492 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001497/**
1498 * zfcp_fsf_close_port - create and send close port request
1499 * @erp_action: pointer to struct zfcp_erp_action
1500 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001502int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
Swen Schillig564e1c82009-08-18 15:43:19 +02001504 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001505 struct zfcp_fsf_req *req;
1506 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Swen Schillig564e1c82009-08-18 15:43:19 +02001508 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001509 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Swen Schillig564e1c82009-08-18 15:43:19 +02001512 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001513 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001514 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001515
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001516 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001517 retval = PTR_ERR(req);
1518 goto out;
1519 }
1520
Swen Schillig09a46c62009-08-18 15:43:16 +02001521 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001522 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524 req->handler = zfcp_fsf_close_port_handler;
1525 req->data = erp_action->port;
1526 req->erp_action = erp_action;
1527 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001528 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Christof Schmitt287ac012008-07-02 10:56:40 +02001530 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001533 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001534 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001536out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001537 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 return retval;
1539}
1540
Swen Schillig5ab944f2008-10-01 12:42:17 +02001541static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1542{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001543 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001544 struct fsf_qtcb_header *header = &req->qtcb->header;
1545
1546 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001547 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001548 goto out;
1549 }
1550
1551 switch (header->fsf_status) {
1552 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1553 dev_warn(&req->adapter->ccw_device->dev,
1554 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001555 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001556 case FSF_ADAPTER_STATUS_AVAILABLE:
1557 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001558 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001559 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001560 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001561 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001562 case FSF_GOOD:
1563 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001564 /* fall through */
1565 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001566 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001567 }
1568out:
1569 wake_up(&wka_port->completion_wq);
1570}
1571
1572/**
1573 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001574 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001575 * Returns: 0 on success, error otherwise
1576 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001577int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001578{
Swen Schillig564e1c82009-08-18 15:43:19 +02001579 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001580 struct zfcp_fsf_req *req;
1581 int retval = -EIO;
1582
Swen Schillig564e1c82009-08-18 15:43:19 +02001583 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001584 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001585 goto out;
1586
Swen Schillig564e1c82009-08-18 15:43:19 +02001587 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001588 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001589 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001590
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591 if (unlikely(IS_ERR(req))) {
1592 retval = PTR_ERR(req);
1593 goto out;
1594 }
1595
Swen Schillig09a46c62009-08-18 15:43:16 +02001596 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001597 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001598
1599 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001600 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001601 req->data = wka_port;
1602
1603 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1604 retval = zfcp_fsf_req_send(req);
1605 if (retval)
1606 zfcp_fsf_req_free(req);
1607out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001608 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001609 return retval;
1610}
1611
1612static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1613{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001614 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001615
1616 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1617 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001618 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001619 }
1620
Christof Schmittbd0072e2009-11-24 16:54:11 +01001621 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622 wake_up(&wka_port->completion_wq);
1623}
1624
1625/**
1626 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001627 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001628 * Returns: 0 on success, error otherwise
1629 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001630int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631{
Swen Schillig564e1c82009-08-18 15:43:19 +02001632 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001633 struct zfcp_fsf_req *req;
1634 int retval = -EIO;
1635
Swen Schillig564e1c82009-08-18 15:43:19 +02001636 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001637 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001638 goto out;
1639
Swen Schillig564e1c82009-08-18 15:43:19 +02001640 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001641 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001642 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001643
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644 if (unlikely(IS_ERR(req))) {
1645 retval = PTR_ERR(req);
1646 goto out;
1647 }
1648
Swen Schillig09a46c62009-08-18 15:43:16 +02001649 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001650 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001651
1652 req->handler = zfcp_fsf_close_wka_port_handler;
1653 req->data = wka_port;
1654 req->qtcb->header.port_handle = wka_port->handle;
1655
1656 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1657 retval = zfcp_fsf_req_send(req);
1658 if (retval)
1659 zfcp_fsf_req_free(req);
1660out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001661 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001662 return retval;
1663}
1664
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001665static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001667 struct zfcp_port *port = req->data;
1668 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001671 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001672 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001676 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001677 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001680 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001683 /* can't use generic zfcp_erp_modify_port_status because
1684 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1685 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001686 read_lock(&port->unit_list_lock);
1687 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001688 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1689 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001690 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001691 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001692 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 switch (header->fsf_status_qual.word[0]) {
1696 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001697 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001699 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 /* can't use generic zfcp_erp_modify_port_status because
1705 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1706 */
1707 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001708 read_lock(&port->unit_list_lock);
1709 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001710 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1711 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001712 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001717/**
1718 * zfcp_fsf_close_physical_port - close physical port
1719 * @erp_action: pointer to struct zfcp_erp_action
1720 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001722int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723{
Swen Schillig564e1c82009-08-18 15:43:19 +02001724 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001725 struct zfcp_fsf_req *req;
1726 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Swen Schillig564e1c82009-08-18 15:43:19 +02001728 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001729 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Swen Schillig564e1c82009-08-18 15:43:19 +02001732 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001733 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001734 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001735
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001736 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 goto out;
1739 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001740
Swen Schillig09a46c62009-08-18 15:43:16 +02001741 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001742 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001743
1744 req->data = erp_action->port;
1745 req->qtcb->header.port_handle = erp_action->port->handle;
1746 req->erp_action = erp_action;
1747 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001748 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749
Christof Schmitt287ac012008-07-02 10:56:40 +02001750 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001751 retval = zfcp_fsf_req_send(req);
1752 if (retval) {
1753 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001754 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001755 }
1756out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001757 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return retval;
1759}
1760
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001761static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001763 struct zfcp_adapter *adapter = req->adapter;
1764 struct zfcp_unit *unit = req->data;
1765 struct fsf_qtcb_header *header = &req->qtcb->header;
1766 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1767 struct fsf_queue_designator *queue_designator =
1768 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001769 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001771 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001772 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001775 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 ZFCP_STATUS_UNIT_SHARED |
1777 ZFCP_STATUS_UNIT_READONLY,
1778 &unit->status);
1779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 switch (header->fsf_status) {
1781
1782 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001783 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001784 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001788 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001790 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001793 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001794 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001797 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001798 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001799 "LUN 0x%Lx on port 0x%Lx is already in "
1800 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001801 (unsigned long long)unit->fcp_lun,
1802 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001803 queue_designator->cssid,
1804 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001805 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001806 zfcp_act_eval_err(adapter,
1807 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001808 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1810 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001811 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001814 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001815 "No handle is available for LUN "
1816 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001817 (unsigned long long)unit->fcp_lun,
1818 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001819 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001820 /* fall through */
1821 case FSF_INVALID_COMMAND_OPTION:
1822 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 switch (header->fsf_status_qual.word[0]) {
1826 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001827 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001828 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001830 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 }
1833 break;
1834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001838
1839 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1840 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001841 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001842 exclusive = (bottom->lun_access_info &
1843 FSF_UNIT_ACCESS_EXCLUSIVE);
1844 readwrite = (bottom->lun_access_info &
1845 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 if (!exclusive)
1848 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1849 &unit->status);
1850
1851 if (!readwrite) {
1852 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1853 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001854 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001855 "SCSI device at LUN 0x%016Lx on port "
1856 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001857 (unsigned long long)unit->fcp_lun,
1858 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 }
1860
1861 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001863 "Exclusive read-only access not "
1864 "supported (unit 0x%016Lx, "
1865 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001866 (unsigned long long)unit->fcp_lun,
1867 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001868 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001870 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001872 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001873 "Shared read-write access not "
1874 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001875 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001876 (unsigned long long)unit->fcp_lun,
1877 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001878 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001880 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 }
1882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885}
1886
1887/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 * zfcp_fsf_open_unit - open unit
1889 * @erp_action: pointer to struct zfcp_erp_action
1890 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001892int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001894 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001895 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001896 struct zfcp_fsf_req *req;
1897 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Swen Schillig564e1c82009-08-18 15:43:19 +02001899 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001900 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001901 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Swen Schillig564e1c82009-08-18 15:43:19 +02001903 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001904 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001905 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001906
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001907 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001908 retval = PTR_ERR(req);
1909 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001910 }
1911
Swen Schillig09a46c62009-08-18 15:43:16 +02001912 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001913 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001915 req->qtcb->header.port_handle = erp_action->port->handle;
1916 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1917 req->handler = zfcp_fsf_open_unit_handler;
1918 req->data = erp_action->unit;
1919 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001920 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001921
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001922 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1923 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Christof Schmitt287ac012008-07-02 10:56:40 +02001925 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001926 retval = zfcp_fsf_req_send(req);
1927 if (retval) {
1928 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001929 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001931out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001932 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 return retval;
1934}
1935
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001936static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001938 struct zfcp_unit *unit = req->data;
1939
1940 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001941 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001942
1943 switch (req->qtcb->header.fsf_status) {
1944 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001945 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001946 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1947 break;
1948 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001949 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001950 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1951 break;
1952 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001953 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001954 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001955 break;
1956 case FSF_ADAPTER_STATUS_AVAILABLE:
1957 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1958 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001959 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960 /* fall through */
1961 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1962 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1963 break;
1964 }
1965 break;
1966 case FSF_GOOD:
1967 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1968 break;
1969 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970}
1971
1972/**
1973 * zfcp_fsf_close_unit - close zfcp unit
1974 * @erp_action: pointer to struct zfcp_unit
1975 * Returns: 0 on success, error otherwise
1976 */
1977int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1978{
Swen Schillig564e1c82009-08-18 15:43:19 +02001979 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001980 struct zfcp_fsf_req *req;
1981 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Swen Schillig564e1c82009-08-18 15:43:19 +02001983 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001984 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001986
Swen Schillig564e1c82009-08-18 15:43:19 +02001987 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001988 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001989 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001990
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001991 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001992 retval = PTR_ERR(req);
1993 goto out;
1994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Swen Schillig09a46c62009-08-18 15:43:16 +02001996 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001997 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001999 req->qtcb->header.port_handle = erp_action->port->handle;
2000 req->qtcb->header.lun_handle = erp_action->unit->handle;
2001 req->handler = zfcp_fsf_close_unit_handler;
2002 req->data = erp_action->unit;
2003 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002004 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Christof Schmitt287ac012008-07-02 10:56:40 +02002006 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002007 retval = zfcp_fsf_req_send(req);
2008 if (retval) {
2009 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002010 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002011 }
2012out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002013 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002014 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
Christof Schmittc9615852008-05-06 11:00:05 +02002017static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2018{
2019 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002020 lat_rec->min = min(lat_rec->min, lat);
2021 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002022}
2023
Christof Schmittd9742b42009-11-24 16:54:03 +01002024static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002025{
Christof Schmittd9742b42009-11-24 16:54:03 +01002026 struct fsf_qual_latency_info *lat_in;
2027 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002028 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002029 struct zfcp_blk_drv_data blktrc;
2030 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002031
Christof Schmittd9742b42009-11-24 16:54:03 +01002032 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002033
Christof Schmittd9742b42009-11-24 16:54:03 +01002034 blktrc.flags = 0;
2035 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2036 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2037 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Swen Schillig706eca42010-07-16 15:37:38 +02002038 blktrc.inb_usage = 0;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002039 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002040
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002041 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2042 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002043 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2044 blktrc.channel_lat = lat_in->channel_lat * ticks;
2045 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2046
2047 switch (req->qtcb->bottom.io.data_direction) {
Felix Beckef3eb712010-07-16 15:37:42 +02002048 case FSF_DATADIR_DIF_READ_STRIP:
2049 case FSF_DATADIR_DIF_READ_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002050 case FSF_DATADIR_READ:
2051 lat = &unit->latencies.read;
2052 break;
Felix Beckef3eb712010-07-16 15:37:42 +02002053 case FSF_DATADIR_DIF_WRITE_INSERT:
2054 case FSF_DATADIR_DIF_WRITE_CONVERT:
Christof Schmittd9742b42009-11-24 16:54:03 +01002055 case FSF_DATADIR_WRITE:
2056 lat = &unit->latencies.write;
2057 break;
2058 case FSF_DATADIR_CMND:
2059 lat = &unit->latencies.cmd;
2060 break;
2061 }
2062
2063 if (lat) {
2064 spin_lock(&unit->latencies.lock);
2065 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2066 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2067 lat->counter++;
2068 spin_unlock(&unit->latencies.lock);
2069 }
Christof Schmittc9615852008-05-06 11:00:05 +02002070 }
2071
Christof Schmittd9742b42009-11-24 16:54:03 +01002072 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2073 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002074}
2075
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002076static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002078 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002079 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002082 read_lock_irqsave(&req->adapter->abort_lock, flags);
2083
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002084 scpnt = req->data;
2085 if (unlikely(!scpnt)) {
2086 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2087 return;
2088 }
2089
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002090 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002091 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 goto skip_fsfstatus;
2093 }
2094
Felix Beckef3eb712010-07-16 15:37:42 +02002095 switch (req->qtcb->header.fsf_status) {
2096 case FSF_INCONSISTENT_PROT_DATA:
2097 case FSF_INVALID_PROT_PARM:
2098 set_host_byte(scpnt, DID_ERROR);
2099 goto skip_fsfstatus;
2100 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2101 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2102 goto skip_fsfstatus;
2103 case FSF_APP_TAG_CHECK_FAILURE:
2104 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2105 goto skip_fsfstatus;
2106 case FSF_REF_TAG_CHECK_FAILURE:
2107 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2108 goto skip_fsfstatus;
2109 }
Christof Schmitt4318e082009-11-24 16:54:08 +01002110 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2111 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002113skip_fsfstatus:
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002114 zfcp_fsf_req_trace(req, scpnt);
Christof Schmittab725282010-02-17 11:18:57 +01002115 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 /*
2120 * We must hold this lock until scsi_done has been called.
2121 * Otherwise we may call scsi_done after abort regarding this
2122 * command has completed.
2123 * Note: scsi_done must not block!
2124 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002125 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002128static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
Christof Schmitt4318e082009-11-24 16:54:08 +01002130 struct fcp_resp_with_ext *fcp_rsp;
2131 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Christof Schmitt4318e082009-11-24 16:54:08 +01002133 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2134 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2135
2136 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002137 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2138 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139}
2140
2141
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002142static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2143{
2144 struct zfcp_unit *unit;
2145 struct fsf_qtcb_header *header = &req->qtcb->header;
2146
2147 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2148 unit = req->data;
2149 else
2150 unit = req->unit;
2151
2152 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2153 goto skip_fsfstatus;
2154
2155 switch (header->fsf_status) {
2156 case FSF_HANDLE_MISMATCH:
2157 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002158 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002159 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2160 break;
2161 case FSF_FCPLUN_NOT_VALID:
2162 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002163 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2165 break;
2166 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2167 zfcp_fsf_class_not_supp(req);
2168 break;
2169 case FSF_ACCESS_DENIED:
2170 zfcp_fsf_access_denied_unit(req, unit);
2171 break;
2172 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2173 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002174 "Incorrect direction %d, unit 0x%016Lx on port "
2175 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002176 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002177 (unsigned long long)unit->fcp_lun,
2178 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002179 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2180 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002181 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2182 break;
2183 case FSF_CMND_LENGTH_NOT_VALID:
2184 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002185 "Incorrect CDB length %d, unit 0x%016Lx on "
2186 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002187 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002188 (unsigned long long)unit->fcp_lun,
2189 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002190 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2191 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002192 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2193 break;
2194 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002195 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002196 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002197 break;
2198 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002199 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002200 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002201 break;
2202 case FSF_ADAPTER_STATUS_AVAILABLE:
2203 if (header->fsf_status_qual.word[0] ==
2204 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002205 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002206 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2207 break;
2208 }
2209skip_fsfstatus:
2210 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2211 zfcp_fsf_send_fcp_ctm_handler(req);
2212 else {
2213 zfcp_fsf_send_fcp_command_task_handler(req);
2214 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002215 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002216 }
2217}
2218
Felix Beckef3eb712010-07-16 15:37:42 +02002219static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2220{
2221 switch (scsi_get_prot_op(scsi_cmnd)) {
2222 case SCSI_PROT_NORMAL:
2223 switch (scsi_cmnd->sc_data_direction) {
2224 case DMA_NONE:
2225 *data_dir = FSF_DATADIR_CMND;
2226 break;
2227 case DMA_FROM_DEVICE:
2228 *data_dir = FSF_DATADIR_READ;
2229 break;
2230 case DMA_TO_DEVICE:
2231 *data_dir = FSF_DATADIR_WRITE;
2232 break;
2233 case DMA_BIDIRECTIONAL:
2234 return -EINVAL;
2235 }
2236 break;
2237
2238 case SCSI_PROT_READ_STRIP:
2239 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2240 break;
2241 case SCSI_PROT_WRITE_INSERT:
2242 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2243 break;
2244 case SCSI_PROT_READ_PASS:
2245 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2246 break;
2247 case SCSI_PROT_WRITE_PASS:
2248 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2249 break;
2250 default:
2251 return -EINVAL;
2252 }
2253
2254 return 0;
2255}
2256
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002257/**
2258 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002259 * @unit: unit where command is sent to
2260 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002261 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002262int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2263 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002264{
2265 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002266 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002267 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Felix Beckef3eb712010-07-16 15:37:42 +02002268 int real_bytes, retval = -EIO, dix_bytes = 0;
Christof Schmitt63caf362009-03-02 13:09:00 +01002269 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002270 struct zfcp_qdio *qdio = adapter->qdio;
Felix Beckef3eb712010-07-16 15:37:42 +02002271 struct fsf_qtcb_bottom_io *io;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002272
2273 if (unlikely(!(atomic_read(&unit->status) &
2274 ZFCP_STATUS_COMMON_UNBLOCKED)))
2275 return -EBUSY;
2276
Swen Schillig564e1c82009-08-18 15:43:19 +02002277 spin_lock(&qdio->req_q_lock);
Swen Schillig706eca42010-07-16 15:37:38 +02002278 if (atomic_read(&qdio->req_q_free) <= 0) {
Swen Schillig564e1c82009-08-18 15:43:19 +02002279 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002280 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002281 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002282
Christof Schmitt1674b402010-04-30 18:09:34 +02002283 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2284 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2285
Swen Schillig564e1c82009-08-18 15:43:19 +02002286 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002287 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002288
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002289 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002290 retval = PTR_ERR(req);
2291 goto out;
2292 }
2293
Felix Beckef3eb712010-07-16 15:37:42 +02002294 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2295
2296 io = &req->qtcb->bottom.io;
Swen Schillig09a46c62009-08-18 15:43:16 +02002297 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002298 req->unit = unit;
2299 req->data = scsi_cmnd;
2300 req->handler = zfcp_fsf_send_fcp_command_handler;
2301 req->qtcb->header.lun_handle = unit->handle;
2302 req->qtcb->header.port_handle = unit->port->handle;
Felix Beckef3eb712010-07-16 15:37:42 +02002303 io->service_class = FSF_CLASS_3;
2304 io->fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002305
Felix Beckef3eb712010-07-16 15:37:42 +02002306 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2307 io->data_block_length = scsi_cmnd->device->sector_size;
2308 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002309 }
2310
Felix Beckef3eb712010-07-16 15:37:42 +02002311 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2312
Christof Schmitt1674b402010-04-30 18:09:34 +02002313 get_device(&unit->dev);
2314
Christof Schmitt4318e082009-11-24 16:54:08 +01002315 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2316 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002317
Felix Beckef3eb712010-07-16 15:37:42 +02002318 if (scsi_prot_sg_count(scsi_cmnd)) {
2319 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2320 scsi_prot_sg_count(scsi_cmnd));
2321 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2322 scsi_prot_sglist(scsi_cmnd));
2323 io->prot_data_length = dix_bytes;
2324 }
2325
Christof Schmitt1674b402010-04-30 18:09:34 +02002326 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schillig01b04752010-07-16 15:37:37 +02002327 scsi_sglist(scsi_cmnd));
Felix Beckef3eb712010-07-16 15:37:42 +02002328
2329 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002330 goto failed_scsi_cmnd;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002331
Felix Beckef3eb712010-07-16 15:37:42 +02002332 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2333
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334 retval = zfcp_fsf_req_send(req);
2335 if (unlikely(retval))
2336 goto failed_scsi_cmnd;
2337
2338 goto out;
2339
2340failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002341 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002342 zfcp_fsf_req_free(req);
2343 scsi_cmnd->host_scribble = NULL;
2344out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002345 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002346 return retval;
2347}
2348
2349/**
2350 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002351 * @unit: pointer to struct zfcp_unit
2352 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002353 * Returns: on success pointer to struct fsf_req, NULL otherwise
2354 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002355struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002357 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002358 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002359 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002360
2361 if (unlikely(!(atomic_read(&unit->status) &
2362 ZFCP_STATUS_COMMON_UNBLOCKED)))
2363 return NULL;
2364
Swen Schillig564e1c82009-08-18 15:43:19 +02002365 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002366 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002367 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002368
Swen Schillig564e1c82009-08-18 15:43:19 +02002369 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002370 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002371 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002372
Swen Schillig633528c2008-11-26 18:07:37 +01002373 if (IS_ERR(req)) {
2374 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002375 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002376 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377
2378 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2379 req->data = unit;
2380 req->handler = zfcp_fsf_send_fcp_command_handler;
2381 req->qtcb->header.lun_handle = unit->handle;
2382 req->qtcb->header.port_handle = unit->port->handle;
2383 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2384 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002385 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002386
Christof Schmitt1674b402010-04-30 18:09:34 +02002387 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002388
Christof Schmitt4318e082009-11-24 16:54:08 +01002389 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2390 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002391
2392 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2393 if (!zfcp_fsf_req_send(req))
2394 goto out;
2395
2396 zfcp_fsf_req_free(req);
2397 req = NULL;
2398out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002399 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002400 return req;
2401}
2402
2403static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2404{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002405}
2406
2407/**
2408 * zfcp_fsf_control_file - control file upload/download
2409 * @adapter: pointer to struct zfcp_adapter
2410 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2411 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002413struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2414 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Swen Schillig564e1c82009-08-18 15:43:19 +02002416 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002417 struct zfcp_fsf_req *req = NULL;
2418 struct fsf_qtcb_bottom_support *bottom;
2419 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Christof Schmitt45633fd2008-06-10 18:20:55 +02002421 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2422 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Christof Schmitt45633fd2008-06-10 18:20:55 +02002424 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2426 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2429 direction = SBAL_FLAGS0_TYPE_READ;
2430 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002432 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 }
2434
Swen Schillig564e1c82009-08-18 15:43:19 +02002435 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002436 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002437 goto out;
2438
Christof Schmitt1674b402010-04-30 18:09:34 +02002439 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002440 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002442 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 }
2444
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002445 req->handler = zfcp_fsf_control_file_handler;
2446
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002447 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002449 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Swen Schillig01b04752010-07-16 15:37:37 +02002451 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2452
Christof Schmitt45633fd2008-06-10 18:20:55 +02002453 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002454 zfcp_fsf_req_free(req);
2455 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002456 }
Felix Beckef3eb712010-07-16 15:37:42 +02002457 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002459 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2460 retval = zfcp_fsf_req_send(req);
2461out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002462 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002463
2464 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002465 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002466 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002468 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002470
2471/**
2472 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2473 * @adapter: pointer to struct zfcp_adapter
2474 * @sbal_idx: response queue index of SBAL to be processed
2475 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002476void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002477{
Swen Schillig564e1c82009-08-18 15:43:19 +02002478 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schillig706eca42010-07-16 15:37:38 +02002479 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002480 struct qdio_buffer_element *sbale;
2481 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002482 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002483 int idx;
2484
2485 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2486
2487 sbale = &sbal->element[idx];
2488 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002489 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002490
Christof Schmitt339f4f42010-07-16 15:37:43 +02002491 if (!fsf_req) {
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002492 /*
2493 * Unknown request means that we have potentially memory
2494 * corruption and must stop the machine immediately.
2495 */
Christof Schmitt339f4f42010-07-16 15:37:43 +02002496 zfcp_qdio_siosl(adapter);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002497 panic("error: unknown req_id (%lx) on adapter %s.\n",
2498 req_id, dev_name(&adapter->ccw_device->dev));
Christof Schmitt339f4f42010-07-16 15:37:43 +02002499 }
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002500
Christof Schmitt34c2b712010-02-17 11:18:59 +01002501 fsf_req->qdio_req.sbal_response = sbal_idx;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002502 zfcp_fsf_req_complete(fsf_req);
2503
2504 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2505 break;
2506 }
2507}