blob: 4e15361a83b98e98cf8fb27411fb9e697a7048c2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Christof Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2002, 2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Stefan Raspl0997f1c2008-10-16 08:23:39 +020012#include <linux/blktrace_api.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010014#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010016#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020017#include "zfcp_dbf.h"
Christof Schmitt34c2b712010-02-17 11:18:59 +010018#include "zfcp_qdio.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010019#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Christof Schmitt287ac012008-07-02 10:56:40 +020021static void zfcp_fsf_request_timeout_handler(unsigned long data)
22{
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010024 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
25 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020026}
27
28static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
29 unsigned long timeout)
30{
31 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
32 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
33 fsf_req->timer.expires = jiffies + timeout;
34 add_timer(&fsf_req->timer);
35}
36
37static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
38{
39 BUG_ON(!fsf_req->erp_action);
40 fsf_req->timer.function = zfcp_erp_timeout_handler;
41 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
42 fsf_req->timer.expires = jiffies + 30 * HZ;
43 add_timer(&fsf_req->timer);
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/* association between FSF command and FSF QTCB type */
47static u32 fsf_qtcb_type[] = {
48 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
49 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
58 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
59 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61};
62
Christof Schmitt553448f2008-06-10 18:20:58 +020063static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
64{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020065 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020066 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020067 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020068
Christof Schmittff3b24f2008-10-01 12:42:15 +020069 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020070 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020071 "Access denied according to ACT rule type %s, "
72 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020073}
74
75static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
76 struct zfcp_port *port)
77{
78 struct fsf_qtcb_header *header = &req->qtcb->header;
79 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020080 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020081 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020082 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010084 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020085 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86}
87
88static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
89 struct zfcp_unit *unit)
90{
91 struct fsf_qtcb_header *header = &req->qtcb->header;
92 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020093 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020094 (unsigned long long)unit->fcp_lun,
95 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020096 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
97 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010098 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020099 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100}
101
102static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
103{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200104 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
105 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100106 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200107 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
108}
109
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200110/**
111 * zfcp_fsf_req_free - free memory used by fsf request
112 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200114void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200116 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200117 if (likely(req->qtcb))
118 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200119 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200120 return;
121 }
122
Swen Schilliga4623c42009-08-18 15:43:15 +0200123 if (likely(req->qtcb))
124 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
125 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200128static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Swen Schilligecf0c772009-11-24 16:53:58 +0100130 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200131 struct fsf_status_read_buffer *sr_buf = req->data;
132 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100134 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Swen Schilligecf0c772009-11-24 16:53:58 +0100136 read_lock_irqsave(&adapter->port_list_lock, flags);
137 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100139 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100140 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200141 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100142 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100145static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200146 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200148 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200150 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
151 return;
152
153 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200154
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100155 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200156
157 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200159
160 switch (link_down->error_code) {
161 case FSF_PSQ_LINK_NO_LIGHT:
162 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200163 "There is no light signal from the local "
164 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200165 break;
166 case FSF_PSQ_LINK_WRAP_PLUG:
167 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200168 "There is a wrap plug instead of a fibre "
169 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200170 break;
171 case FSF_PSQ_LINK_NO_FCP:
172 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200173 "The adjacent fibre channel node does not "
174 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200175 break;
176 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
177 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200178 "The FCP device is suspended because of a "
179 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200180 break;
181 case FSF_PSQ_LINK_INVALID_WWPN:
182 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200183 "The FCP device detected a WWPN that is "
184 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200185 break;
186 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
187 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200188 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200189 break;
190 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
191 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200192 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200193 break;
194 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
195 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200196 "The adjacent switch cannot support "
197 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200198 break;
199 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
200 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200201 "The FCP adapter could not log in to the "
202 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200203 break;
204 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
205 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200206 "The WWPN assignment file on the FCP adapter "
207 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200208 break;
209 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
210 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200211 "The mode table on the FCP adapter "
212 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200213 break;
214 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
215 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200216 "All NPIV ports on the FCP adapter have "
217 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200218 break;
219 default:
220 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200221 "The link between the FCP adapter and "
222 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200223 }
224out:
225 zfcp_erp_adapter_failed(adapter, id, req);
226}
227
228static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
229{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200230 struct fsf_status_read_buffer *sr_buf = req->data;
231 struct fsf_link_down_info *ldi =
232 (struct fsf_link_down_info *) &sr_buf->payload;
233
234 switch (sr_buf->status_subtype) {
235 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100236 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200237 break;
238 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100239 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 break;
241 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100242 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 };
244}
245
246static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
247{
248 struct zfcp_adapter *adapter = req->adapter;
249 struct fsf_status_read_buffer *sr_buf = req->data;
250
251 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200252 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200253 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200254 zfcp_fsf_req_free(req);
255 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Swen Schillig57717102009-08-18 15:43:21 +0200258 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200259
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200260 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200265 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200270 dev_warn(&adapter->ccw_device->dev,
271 "The error threshold for checksum statistics "
272 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200273 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200276 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200279 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200280 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100282 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 ZFCP_STATUS_COMMON_RUNNING,
284 ZFCP_SET);
285 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200286 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
287 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100288 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100290 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200291 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100292 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
293 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200294 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100295 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100296 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100298 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200300 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200301 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200304
Swen Schilliga4623c42009-08-18 15:43:15 +0200305 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200306 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200307
308 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200309 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200312static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200314 switch (req->qtcb->header.fsf_status_qual.word[0]) {
315 case FSF_SQ_FCP_RSP_AVAILABLE:
316 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
317 case FSF_SQ_NO_RETRY_POSSIBLE:
318 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
319 return;
320 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200321 break;
322 case FSF_SQ_NO_RECOM:
323 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200324 "The FCP adapter reported a problem "
325 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100326 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200329 /* all non-return stats set FSFREQ_ERROR*/
330 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
331}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200333static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
334{
335 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
336 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200337
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200338 switch (req->qtcb->header.fsf_status) {
339 case FSF_UNKNOWN_COMMAND:
340 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200341 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200342 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100343 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200344 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200347 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200352static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200354 struct zfcp_adapter *adapter = req->adapter;
355 struct fsf_qtcb *qtcb = req->qtcb;
356 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Swen Schillig57717102009-08-18 15:43:21 +0200358 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200360 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100361 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200365 switch (qtcb->prefix.prot_status) {
366 case FSF_PROT_GOOD:
367 case FSF_PROT_FSF_STATUS_PRESENTED:
368 return;
369 case FSF_PROT_QTCB_VERSION_ERROR:
370 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200371 "QTCB version 0x%x not supported by FCP adapter "
372 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
373 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100374 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200376 case FSF_PROT_ERROR_STATE:
377 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100378 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100379 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200381 case FSF_PROT_UNSUPP_QTCB_TYPE:
382 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200383 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100384 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200386 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
387 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
388 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200390 case FSF_PROT_DUPLICATE_REQUEST_ID:
391 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200392 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100394 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100397 zfcp_fsf_link_down_info_eval(req, "fspse_5",
398 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100399 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100400 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200402 case FSF_PROT_REEST_QUEUE:
403 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100404 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200405 ZFCP_STATUS_COMMON_RUNNING,
406 ZFCP_SET);
407 zfcp_erp_adapter_reopen(adapter,
408 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100409 ZFCP_STATUS_COMMON_ERP_FAILED,
410 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200413 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200414 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200415 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100416 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200418 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200422 * zfcp_fsf_req_complete - process completion of a FSF request
423 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200425 * When a request has been completed either from the FCP adapter,
426 * or it has been dismissed due to a queue shutdown, this function
427 * is called to process the completion status and trigger further
428 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200430static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200431{
432 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
433 zfcp_fsf_status_read_handler(req);
434 return;
435 }
436
437 del_timer(&req->timer);
438 zfcp_fsf_protstatus_eval(req);
439 zfcp_fsf_fsfstatus_eval(req);
440 req->handler(req);
441
442 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200443 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200444
445 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
446 zfcp_fsf_req_free(req);
447 else
Swen Schillig058b8642009-08-18 15:43:14 +0200448 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200449}
450
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200451/**
452 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
453 * @adapter: pointer to struct zfcp_adapter
454 *
455 * Never ever call this without shutting down the adapter first.
456 * Otherwise the adapter would continue using and corrupting s390 storage.
457 * Included BUG_ON() call to ensure this is done.
458 * ERP is supposed to be the only user of this function.
459 */
460void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
461{
462 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200463 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200464
465 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100466 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200467
468 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
469 list_del(&req->list);
470 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
471 zfcp_fsf_req_complete(req);
472 }
473}
474
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200475static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100477 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200478 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200479 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100480 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100482 /* adjust pointers for missing command code */
483 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
484 - sizeof(u32));
485 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
486 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200487
488 if (req->data)
489 memcpy(req->data, bottom, sizeof(*bottom));
490
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100491 fc_host_port_name(shost) = nsp->fl_wwpn;
492 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100493 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200494 fc_host_speed(shost) = bottom->fc_link_speed;
495 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
496
497 adapter->hydra_version = bottom->adapter_type;
498 adapter->timer_ticks = bottom->timer_interval;
Christof Schmitt64deb6e2010-04-30 18:09:36 +0200499 adapter->stat_read_buf_num = max(bottom->status_read_buf_num, (u16)16);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200500
501 if (fc_host_permanent_port_name(shost) == -1)
502 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
503
504 switch (bottom->fc_topology) {
505 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100506 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100507 adapter->peer_wwpn = plogi->fl_wwpn;
508 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200509 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200510 break;
511 case FSF_TOPO_FABRIC:
512 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 break;
514 case FSF_TOPO_AL:
515 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200516 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200517 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200518 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200519 "Unknown or unsupported arbitrated loop "
520 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100521 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200522 return -EIO;
523 }
524
525 return 0;
526}
527
528static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
529{
530 struct zfcp_adapter *adapter = req->adapter;
531 struct fsf_qtcb *qtcb = req->qtcb;
532 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
533 struct Scsi_Host *shost = adapter->scsi_host;
534
535 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
536 return;
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200539 adapter->adapter_features = bottom->adapter_features;
540 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500541 adapter->peer_wwpn = 0;
542 adapter->peer_wwnn = 0;
543 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200545 switch (qtcb->header.fsf_status) {
546 case FSF_GOOD:
547 if (zfcp_fsf_exchange_config_evaluate(req))
548 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200549
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200550 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
551 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200552 "FCP adapter maximum QTCB size (%d bytes) "
553 "is too small\n",
554 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100555 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200556 return;
557 }
558 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
559 &adapter->status);
560 break;
561 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200562 fc_host_node_name(shost) = 0;
563 fc_host_port_name(shost) = 0;
564 fc_host_port_id(shost) = 0;
565 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100566 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200568
569 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
570 &adapter->status);
571
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100572 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200573 &qtcb->header.fsf_status_qual.link_down_info);
574 break;
575 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100576 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200577 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200580 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200582 memcpy(fc_host_serial_number(shost), bottom->serial_number,
583 min(FC_SERIAL_NUMBER_SIZE, 17));
584 EBCASC(fc_host_serial_number(shost),
585 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200588 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200589 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200590 "The FCP adapter only supports newer "
591 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100592 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200593 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200595 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200596 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200597 "The FCP adapter only supports older "
598 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100599 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200605 struct zfcp_adapter *adapter = req->adapter;
606 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
607 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200609 if (req->data)
610 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100611
Christof Schmitt02829852009-03-02 13:09:06 +0100612 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100613 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100614 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
615 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100616 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
617 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
618 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100619 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
620 FC_FC4_LIST_SIZE);
621 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
622 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100623}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200625static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200627 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100628
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200629 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return;
631
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200632 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200633 case FSF_GOOD:
634 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200635 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200637 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100638 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200639 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200640 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642}
643
Swen Schilliga4623c42009-08-18 15:43:15 +0200644static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200645{
646 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200647
648 if (likely(pool))
649 req = mempool_alloc(pool, GFP_ATOMIC);
650 else
651 req = kmalloc(sizeof(*req), GFP_ATOMIC);
652
653 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200654 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200655
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100657 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658 return req;
659}
660
Swen Schilliga4623c42009-08-18 15:43:15 +0200661static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662{
Swen Schilliga4623c42009-08-18 15:43:15 +0200663 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200664
665 if (likely(pool))
666 qtcb = mempool_alloc(pool, GFP_ATOMIC);
667 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200668 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
669
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670 if (unlikely(!qtcb))
671 return NULL;
672
673 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200674 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200675}
676
Swen Schillig564e1c82009-08-18 15:43:19 +0200677static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200678 u32 fsf_cmd, u32 sbtype,
679 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Swen Schillig564e1c82009-08-18 15:43:19 +0200681 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200682 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200683
684 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200685 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200686
687 if (adapter->req_no == 0)
688 adapter->req_no++;
689
690 INIT_LIST_HEAD(&req->list);
691 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200692 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200693
694 req->adapter = adapter;
695 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100696 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200697
Swen Schilliga4623c42009-08-18 15:43:15 +0200698 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
699 if (likely(pool))
700 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
701 else
702 req->qtcb = zfcp_qtcb_alloc(NULL);
703
704 if (unlikely(!req->qtcb)) {
705 zfcp_fsf_req_free(req);
706 return ERR_PTR(-ENOMEM);
707 }
708
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100709 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200710 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200711 req->qtcb->prefix.req_id = req->req_id;
712 req->qtcb->prefix.ulp_info = 26;
713 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
714 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
715 req->qtcb->header.req_handle = req->req_id;
716 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200717 }
718
Christof Schmitt1674b402010-04-30 18:09:34 +0200719 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
720 req->qtcb, sizeof(struct fsf_qtcb));
721
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200722 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
723 zfcp_fsf_req_free(req);
724 return ERR_PTR(-EIO);
725 }
726
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200727 return req;
728}
729
730static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
731{
732 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200733 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100734 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100735 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200736
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100737 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200738
Christof Schmitt34c2b712010-02-17 11:18:59 +0100739 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200740 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100741 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100743 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100744 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100745 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200746 return -EIO;
747 }
748
749 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200750 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200751 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100752 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200753
754 return 0;
755}
756
757/**
758 * zfcp_fsf_status_read - send status read request
759 * @adapter: pointer to struct zfcp_adapter
760 * @req_flags: request flags
761 * Returns: 0 on success, ERROR otherwise
762 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200763int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200764{
Swen Schillig564e1c82009-08-18 15:43:19 +0200765 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200766 struct zfcp_fsf_req *req;
767 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200768 int retval = -EIO;
769
Swen Schillig564e1c82009-08-18 15:43:19 +0200770 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200771 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Christof Schmitt1674b402010-04-30 18:09:34 +0200774 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200775 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200776 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 goto out;
779 }
780
Swen Schilliga4623c42009-08-18 15:43:15 +0200781 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200782 if (!sr_buf) {
783 retval = -ENOMEM;
784 goto failed_buf;
785 }
786 memset(sr_buf, 0, sizeof(*sr_buf));
787 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200788
789 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
790 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200791
792 retval = zfcp_fsf_req_send(req);
793 if (retval)
794 goto failed_req_send;
795
796 goto out;
797
798failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200799 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200800failed_buf:
801 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200802 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200803out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200804 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 return retval;
806}
807
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200808static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200810 struct zfcp_unit *unit = req->data;
811 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200813 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
814 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200816 switch (req->qtcb->header.fsf_status) {
817 case FSF_PORT_HANDLE_NOT_VALID:
818 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100819 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
820 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200821 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200824 case FSF_LUN_HANDLE_NOT_VALID:
825 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100826 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200830 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
831 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200833 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100834 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100835 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200836 break;
837 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100838 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100839 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200840 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200842 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200844 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200845 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200847 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 break;
849 }
850 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200852 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
853 break;
854 }
855}
856
857/**
858 * zfcp_fsf_abort_fcp_command - abort running SCSI command
859 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200860 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200861 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862 */
863
864struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100865 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200867 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200868 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869
Swen Schillig564e1c82009-08-18 15:43:19 +0200870 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200871 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200873 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200874 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200875 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100876 if (IS_ERR(req)) {
877 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100879 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200880
881 if (unlikely(!(atomic_read(&unit->status) &
882 ZFCP_STATUS_COMMON_UNBLOCKED)))
883 goto out_error_free;
884
Christof Schmitt1674b402010-04-30 18:09:34 +0200885 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200886
887 req->data = unit;
888 req->handler = zfcp_fsf_abort_fcp_command_handler;
889 req->qtcb->header.lun_handle = unit->handle;
890 req->qtcb->header.port_handle = unit->port->handle;
891 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
892
893 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
894 if (!zfcp_fsf_req_send(req))
895 goto out;
896
897out_error_free:
898 zfcp_fsf_req_free(req);
899 req = NULL;
900out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200901 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 return req;
903}
904
905static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
906{
907 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100908 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200909 struct fsf_qtcb_header *header = &req->qtcb->header;
910
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100911 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200912
913 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
914 goto skip_fsfstatus;
915
916 switch (header->fsf_status) {
917 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200918 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100919 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920 break;
921 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
922 zfcp_fsf_class_not_supp(req);
923 break;
924 case FSF_ADAPTER_STATUS_AVAILABLE:
925 switch (header->fsf_status_qual.word[0]){
926 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
928 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
929 break;
930 }
931 break;
932 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200933 break;
934 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100935 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200936 break;
937 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100938 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200939 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200940 case FSF_GENERIC_COMMAND_REJECTED:
941 case FSF_PAYLOAD_SIZE_MISMATCH:
942 case FSF_REQUEST_SIZE_TOO_LARGE:
943 case FSF_RESPONSE_SIZE_TOO_LARGE:
944 case FSF_SBAL_MISMATCH:
945 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
946 break;
947 }
948
949skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100950 if (ct->handler)
951 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200952}
953
Christof Schmitt1674b402010-04-30 18:09:34 +0200954static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
955 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200956 struct scatterlist *sg_req,
957 struct scatterlist *sg_resp)
958{
Christof Schmitt1674b402010-04-30 18:09:34 +0200959 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
960 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
961 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200962}
963
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100964static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
965 struct scatterlist *sg_req,
966 struct scatterlist *sg_resp,
967 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200968{
Swen Schillig42428f72009-08-18 15:43:18 +0200969 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200970 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200971 int bytes;
972
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100973 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200974 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
975 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100976 return -EOPNOTSUPP;
977
Christof Schmitt1674b402010-04-30 18:09:34 +0200978 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
979 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200980 return 0;
981 }
982
983 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200984 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200985 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
986 sg_req, sg_resp);
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100987 return 0;
988 }
989
Christof Schmitt34c2b712010-02-17 11:18:59 +0100990 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200991 sg_req, max_sbals);
992 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200993 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +0200995 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200996
Christof Schmitt34c2b712010-02-17 11:18:59 +0100997 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200998 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +0200999 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001000 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001001 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001002
Christof Schmittb1a58982009-09-24 10:23:21 +02001003 return 0;
1004}
1005
1006static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1007 struct scatterlist *sg_req,
1008 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001009 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001010{
1011 int ret;
1012
1013 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1014 if (ret)
1015 return ret;
1016
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001017 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001018 if (timeout > 255)
1019 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001020 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001021 req->qtcb->bottom.support.timeout = timeout;
1022 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001023
1024 return 0;
1025}
1026
1027/**
1028 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1029 * @ct: pointer to struct zfcp_send_ct with data for request
1030 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001031 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001032int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001033 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1034 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001035{
Swen Schillig564e1c82009-08-18 15:43:19 +02001036 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001037 struct zfcp_fsf_req *req;
1038 int ret = -EIO;
1039
Swen Schillig564e1c82009-08-18 15:43:19 +02001040 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001041 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001042 goto out;
1043
Christof Schmitt1674b402010-04-30 18:09:34 +02001044 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1045 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001046
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001047 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001048 ret = PTR_ERR(req);
1049 goto out;
1050 }
1051
Swen Schillig09a46c62009-08-18 15:43:16 +02001052 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001053 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Christof Schmitt1674b402010-04-30 18:09:34 +02001054 ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001055 if (ret)
1056 goto failed_send;
1057
1058 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001059 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001060 req->data = ct;
1061
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001062 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001063
1064 ret = zfcp_fsf_req_send(req);
1065 if (ret)
1066 goto failed_send;
1067
1068 goto out;
1069
1070failed_send:
1071 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001072out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001073 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001074 return ret;
1075}
1076
1077static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1078{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001079 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001080 struct zfcp_port *port = send_els->port;
1081 struct fsf_qtcb_header *header = &req->qtcb->header;
1082
1083 send_els->status = -EINVAL;
1084
1085 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1086 goto skip_fsfstatus;
1087
1088 switch (header->fsf_status) {
1089 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001090 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001091 send_els->status = 0;
1092 break;
1093 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1094 zfcp_fsf_class_not_supp(req);
1095 break;
1096 case FSF_ADAPTER_STATUS_AVAILABLE:
1097 switch (header->fsf_status_qual.word[0]){
1098 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001099 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1100 case FSF_SQ_RETRY_IF_POSSIBLE:
1101 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1102 break;
1103 }
1104 break;
1105 case FSF_ELS_COMMAND_REJECTED:
1106 case FSF_PAYLOAD_SIZE_MISMATCH:
1107 case FSF_REQUEST_SIZE_TOO_LARGE:
1108 case FSF_RESPONSE_SIZE_TOO_LARGE:
1109 break;
1110 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001111 if (port)
1112 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001113 break;
1114 case FSF_SBAL_MISMATCH:
1115 /* should never occure, avoided in zfcp_fsf_send_els */
1116 /* fall through */
1117 default:
1118 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1119 break;
1120 }
1121skip_fsfstatus:
1122 if (send_els->handler)
1123 send_els->handler(send_els->handler_data);
1124}
1125
1126/**
1127 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1128 * @els: pointer to struct zfcp_send_els with data for the command
1129 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001130int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001131 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001132{
1133 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001134 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135 int ret = -EIO;
1136
Swen Schillig564e1c82009-08-18 15:43:19 +02001137 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001138 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001139 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001140
Christof Schmitt1674b402010-04-30 18:09:34 +02001141 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1142 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001143
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001144 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001145 ret = PTR_ERR(req);
1146 goto out;
1147 }
1148
Swen Schillig09a46c62009-08-18 15:43:16 +02001149 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001150 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001151
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001152 if (ret)
1153 goto failed_send;
1154
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001155 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001156 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001157 req->data = els;
1158
Swen Schillig57717102009-08-18 15:43:21 +02001159 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001160
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001161 ret = zfcp_fsf_req_send(req);
1162 if (ret)
1163 goto failed_send;
1164
1165 goto out;
1166
1167failed_send:
1168 zfcp_fsf_req_free(req);
1169out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001170 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001171 return ret;
1172}
1173
1174int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1175{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001177 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001178 int retval = -EIO;
1179
Swen Schillig564e1c82009-08-18 15:43:19 +02001180 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001181 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001182 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001183
Swen Schillig564e1c82009-08-18 15:43:19 +02001184 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001185 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001186 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001187
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001188 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001189 retval = PTR_ERR(req);
1190 goto out;
1191 }
1192
Swen Schillig09a46c62009-08-18 15:43:16 +02001193 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001194 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195
1196 req->qtcb->bottom.config.feature_selection =
1197 FSF_FEATURE_CFDC |
1198 FSF_FEATURE_LUN_SHARING |
1199 FSF_FEATURE_NOTIFICATION_LOST |
1200 FSF_FEATURE_UPDATE_ALERT;
1201 req->erp_action = erp_action;
1202 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001203 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001204
Christof Schmitt287ac012008-07-02 10:56:40 +02001205 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 retval = zfcp_fsf_req_send(req);
1207 if (retval) {
1208 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001209 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210 }
1211out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001212 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001213 return retval;
1214}
1215
Swen Schillig564e1c82009-08-18 15:43:19 +02001216int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001217 struct fsf_qtcb_bottom_config *data)
1218{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 struct zfcp_fsf_req *req = NULL;
1220 int retval = -EIO;
1221
Swen Schillig564e1c82009-08-18 15:43:19 +02001222 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001223 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001224 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001225
Christof Schmitt1674b402010-04-30 18:09:34 +02001226 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1227 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001228
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001229 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001230 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001231 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001232 }
1233
Christof Schmitt1674b402010-04-30 18:09:34 +02001234 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001235 req->handler = zfcp_fsf_exchange_config_data_handler;
1236
1237 req->qtcb->bottom.config.feature_selection =
1238 FSF_FEATURE_CFDC |
1239 FSF_FEATURE_LUN_SHARING |
1240 FSF_FEATURE_NOTIFICATION_LOST |
1241 FSF_FEATURE_UPDATE_ALERT;
1242
1243 if (data)
1244 req->data = data;
1245
1246 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1247 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001248 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001249 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001250 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001251
1252 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001253 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001254
Christof Schmittada81b72009-04-17 15:08:03 +02001255out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001256 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257 return retval;
1258}
1259
1260/**
1261 * zfcp_fsf_exchange_port_data - request information about local port
1262 * @erp_action: ERP action for the adapter for which port data is requested
1263 * Returns: 0 on success, error otherwise
1264 */
1265int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1266{
Swen Schillig564e1c82009-08-18 15:43:19 +02001267 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001269 int retval = -EIO;
1270
Swen Schillig564e1c82009-08-18 15:43:19 +02001271 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 return -EOPNOTSUPP;
1273
Swen Schillig564e1c82009-08-18 15:43:19 +02001274 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001275 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001276 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001277
Swen Schillig564e1c82009-08-18 15:43:19 +02001278 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001279 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001280 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001281
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001282 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001283 retval = PTR_ERR(req);
1284 goto out;
1285 }
1286
Swen Schillig09a46c62009-08-18 15:43:16 +02001287 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001288 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289
1290 req->handler = zfcp_fsf_exchange_port_data_handler;
1291 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001292 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001293
Christof Schmitt287ac012008-07-02 10:56:40 +02001294 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295 retval = zfcp_fsf_req_send(req);
1296 if (retval) {
1297 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001298 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001299 }
1300out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001301 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001302 return retval;
1303}
1304
1305/**
1306 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001307 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308 * @data: pointer to struct fsf_qtcb_bottom_port
1309 * Returns: 0 on success, error otherwise
1310 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001311int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001312 struct fsf_qtcb_bottom_port *data)
1313{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001314 struct zfcp_fsf_req *req = NULL;
1315 int retval = -EIO;
1316
Swen Schillig564e1c82009-08-18 15:43:19 +02001317 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001318 return -EOPNOTSUPP;
1319
Swen Schillig564e1c82009-08-18 15:43:19 +02001320 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001321 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001322 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323
Christof Schmitt1674b402010-04-30 18:09:34 +02001324 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1325 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001326
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001327 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001328 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001329 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001330 }
1331
1332 if (data)
1333 req->data = data;
1334
Christof Schmitt1674b402010-04-30 18:09:34 +02001335 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336
1337 req->handler = zfcp_fsf_exchange_port_data_handler;
1338 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1339 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001340 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001341
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001342 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001343 wait_for_completion(&req->completion);
1344
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001345 zfcp_fsf_req_free(req);
1346
1347 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001348
1349out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001350 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001351 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001352}
1353
1354static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1355{
1356 struct zfcp_port *port = req->data;
1357 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001358 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001359
1360 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001361 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001362
1363 switch (header->fsf_status) {
1364 case FSF_PORT_ALREADY_OPEN:
1365 break;
1366 case FSF_ACCESS_DENIED:
1367 zfcp_fsf_access_denied_port(req, port);
1368 break;
1369 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1370 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001371 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001372 "remote port 0x%016Lx\n",
1373 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001374 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001375 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1376 break;
1377 case FSF_ADAPTER_STATUS_AVAILABLE:
1378 switch (header->fsf_status_qual.word[0]) {
1379 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1380 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001381 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001382 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1383 break;
1384 }
1385 break;
1386 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1389 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001390 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1391 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1392 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 /* check whether D_ID has changed during open */
1394 /*
1395 * FIXME: This check is not airtight, as the FCP channel does
1396 * not monitor closures of target port connections caused on
1397 * the remote side. Thus, they might miss out on invalidating
1398 * locally cached WWPNs (and other N_Port parameters) of gone
1399 * target ports. So, our heroic attempt to make things safe
1400 * could be undermined by 'open port' response data tagged with
1401 * obsolete WWPNs. Another reason to monitor potential
1402 * connection closures ourself at least (by interpreting
1403 * incoming ELS' and unsolicited status). It just crosses my
1404 * mind that one should be able to cross-check by means of
1405 * another GID_PN straight after a port has been opened.
1406 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1407 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001408 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001409 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001410 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001411 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001414 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 break;
1416 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001417
1418out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001419 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001422/**
1423 * zfcp_fsf_open_port - create and send open port request
1424 * @erp_action: pointer to struct zfcp_erp_action
1425 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001427int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Swen Schillig564e1c82009-08-18 15:43:19 +02001429 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001430 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001431 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001432 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Swen Schillig564e1c82009-08-18 15:43:19 +02001434 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001435 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Swen Schillig564e1c82009-08-18 15:43:19 +02001438 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001439 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001440 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001441
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001442 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001443 retval = PTR_ERR(req);
1444 goto out;
1445 }
1446
Swen Schillig09a46c62009-08-18 15:43:16 +02001447 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001448 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001450 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001451 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001452 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001453 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001454 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001455 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Christof Schmitt287ac012008-07-02 10:56:40 +02001457 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001458 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001460 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001461 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001462 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001464out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001465 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 return retval;
1467}
1468
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001469static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001471 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001473 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001474 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001476 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001478 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001479 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001484 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 ZFCP_STATUS_COMMON_OPEN,
1486 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001491/**
1492 * zfcp_fsf_close_port - create and send close port request
1493 * @erp_action: pointer to struct zfcp_erp_action
1494 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001496int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Swen Schillig564e1c82009-08-18 15:43:19 +02001498 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001499 struct zfcp_fsf_req *req;
1500 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Swen Schillig564e1c82009-08-18 15:43:19 +02001502 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001503 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Swen Schillig564e1c82009-08-18 15:43:19 +02001506 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001507 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001508 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001509
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001510 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001511 retval = PTR_ERR(req);
1512 goto out;
1513 }
1514
Swen Schillig09a46c62009-08-18 15:43:16 +02001515 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001516 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 req->handler = zfcp_fsf_close_port_handler;
1519 req->data = erp_action->port;
1520 req->erp_action = erp_action;
1521 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001522 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Christof Schmitt287ac012008-07-02 10:56:40 +02001524 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001525 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001527 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001528 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001531 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 return retval;
1533}
1534
Swen Schillig5ab944f2008-10-01 12:42:17 +02001535static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1536{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001537 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001538 struct fsf_qtcb_header *header = &req->qtcb->header;
1539
1540 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001541 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001542 goto out;
1543 }
1544
1545 switch (header->fsf_status) {
1546 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1547 dev_warn(&req->adapter->ccw_device->dev,
1548 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001549 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001550 case FSF_ADAPTER_STATUS_AVAILABLE:
1551 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001552 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001553 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001554 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001555 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001556 case FSF_GOOD:
1557 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001558 /* fall through */
1559 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001560 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001561 }
1562out:
1563 wake_up(&wka_port->completion_wq);
1564}
1565
1566/**
1567 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001568 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001569 * Returns: 0 on success, error otherwise
1570 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001571int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001572{
Swen Schillig564e1c82009-08-18 15:43:19 +02001573 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001574 struct zfcp_fsf_req *req;
1575 int retval = -EIO;
1576
Swen Schillig564e1c82009-08-18 15:43:19 +02001577 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001578 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001579 goto out;
1580
Swen Schillig564e1c82009-08-18 15:43:19 +02001581 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001582 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001583 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001584
Swen Schillig5ab944f2008-10-01 12:42:17 +02001585 if (unlikely(IS_ERR(req))) {
1586 retval = PTR_ERR(req);
1587 goto out;
1588 }
1589
Swen Schillig09a46c62009-08-18 15:43:16 +02001590 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001591 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001592
1593 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001594 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001595 req->data = wka_port;
1596
1597 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1598 retval = zfcp_fsf_req_send(req);
1599 if (retval)
1600 zfcp_fsf_req_free(req);
1601out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001602 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001603 return retval;
1604}
1605
1606static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1607{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001608 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001609
1610 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1611 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001612 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001613 }
1614
Christof Schmittbd0072e2009-11-24 16:54:11 +01001615 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 wake_up(&wka_port->completion_wq);
1617}
1618
1619/**
1620 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001621 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001622 * Returns: 0 on success, error otherwise
1623 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001624int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001625{
Swen Schillig564e1c82009-08-18 15:43:19 +02001626 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001627 struct zfcp_fsf_req *req;
1628 int retval = -EIO;
1629
Swen Schillig564e1c82009-08-18 15:43:19 +02001630 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001631 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001632 goto out;
1633
Swen Schillig564e1c82009-08-18 15:43:19 +02001634 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001635 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001636 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001637
Swen Schillig5ab944f2008-10-01 12:42:17 +02001638 if (unlikely(IS_ERR(req))) {
1639 retval = PTR_ERR(req);
1640 goto out;
1641 }
1642
Swen Schillig09a46c62009-08-18 15:43:16 +02001643 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001644 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001645
1646 req->handler = zfcp_fsf_close_wka_port_handler;
1647 req->data = wka_port;
1648 req->qtcb->header.port_handle = wka_port->handle;
1649
1650 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1651 retval = zfcp_fsf_req_send(req);
1652 if (retval)
1653 zfcp_fsf_req_free(req);
1654out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001655 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001656 return retval;
1657}
1658
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001659static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001661 struct zfcp_port *port = req->data;
1662 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001665 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001666 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001670 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001671 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001674 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001677 /* can't use generic zfcp_erp_modify_port_status because
1678 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1679 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001680 read_lock(&port->unit_list_lock);
1681 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001682 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1683 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001684 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001685 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001686 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 switch (header->fsf_status_qual.word[0]) {
1690 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001691 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001693 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 }
1696 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 /* can't use generic zfcp_erp_modify_port_status because
1699 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1700 */
1701 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001702 read_lock(&port->unit_list_lock);
1703 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001704 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1705 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001706 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
1710
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001711/**
1712 * zfcp_fsf_close_physical_port - close physical port
1713 * @erp_action: pointer to struct zfcp_erp_action
1714 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001716int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Swen Schillig564e1c82009-08-18 15:43:19 +02001718 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001719 struct zfcp_fsf_req *req;
1720 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Swen Schillig564e1c82009-08-18 15:43:19 +02001722 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001723 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Swen Schillig564e1c82009-08-18 15:43:19 +02001726 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001727 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001728 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001729
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001730 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001731 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 goto out;
1733 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001734
Swen Schillig09a46c62009-08-18 15:43:16 +02001735 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001736 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737
1738 req->data = erp_action->port;
1739 req->qtcb->header.port_handle = erp_action->port->handle;
1740 req->erp_action = erp_action;
1741 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001742 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001743
Christof Schmitt287ac012008-07-02 10:56:40 +02001744 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001745 retval = zfcp_fsf_req_send(req);
1746 if (retval) {
1747 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001748 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749 }
1750out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001751 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 return retval;
1753}
1754
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001755static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001757 struct zfcp_adapter *adapter = req->adapter;
1758 struct zfcp_unit *unit = req->data;
1759 struct fsf_qtcb_header *header = &req->qtcb->header;
1760 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1761 struct fsf_queue_designator *queue_designator =
1762 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001763 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001765 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001766 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001769 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 ZFCP_STATUS_UNIT_SHARED |
1771 ZFCP_STATUS_UNIT_READONLY,
1772 &unit->status);
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 switch (header->fsf_status) {
1775
1776 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001777 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001778 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001782 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001784 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001787 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001788 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001791 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001792 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001793 "LUN 0x%Lx on port 0x%Lx is already in "
1794 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001795 (unsigned long long)unit->fcp_lun,
1796 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001797 queue_designator->cssid,
1798 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001799 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001800 zfcp_act_eval_err(adapter,
1801 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001802 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1804 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001805 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001808 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001809 "No handle is available for LUN "
1810 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001811 (unsigned long long)unit->fcp_lun,
1812 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001813 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001814 /* fall through */
1815 case FSF_INVALID_COMMAND_OPTION:
1816 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 switch (header->fsf_status_qual.word[0]) {
1820 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001821 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001822 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001824 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 }
1827 break;
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001832
1833 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1834 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001835 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001836 exclusive = (bottom->lun_access_info &
1837 FSF_UNIT_ACCESS_EXCLUSIVE);
1838 readwrite = (bottom->lun_access_info &
1839 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 if (!exclusive)
1842 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1843 &unit->status);
1844
1845 if (!readwrite) {
1846 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1847 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001848 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001849 "SCSI device at LUN 0x%016Lx on port "
1850 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001851 (unsigned long long)unit->fcp_lun,
1852 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 }
1854
1855 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001856 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001857 "Exclusive read-only access not "
1858 "supported (unit 0x%016Lx, "
1859 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001860 (unsigned long long)unit->fcp_lun,
1861 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001862 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001863 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001864 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001866 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001867 "Shared read-write access not "
1868 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001869 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001870 (unsigned long long)unit->fcp_lun,
1871 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001872 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001874 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
1881/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001882 * zfcp_fsf_open_unit - open unit
1883 * @erp_action: pointer to struct zfcp_erp_action
1884 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001889 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001890 struct zfcp_fsf_req *req;
1891 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Swen Schillig564e1c82009-08-18 15:43:19 +02001893 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001894 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001895 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Swen Schillig564e1c82009-08-18 15:43:19 +02001897 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001898 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001899 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001900
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001901 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001902 retval = PTR_ERR(req);
1903 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001904 }
1905
Swen Schillig09a46c62009-08-18 15:43:16 +02001906 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001907 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001909 req->qtcb->header.port_handle = erp_action->port->handle;
1910 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1911 req->handler = zfcp_fsf_open_unit_handler;
1912 req->data = erp_action->unit;
1913 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001914 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001915
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1917 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
Christof Schmitt287ac012008-07-02 10:56:40 +02001919 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001920 retval = zfcp_fsf_req_send(req);
1921 if (retval) {
1922 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001923 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001925out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001926 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 return retval;
1928}
1929
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001930static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932 struct zfcp_unit *unit = req->data;
1933
1934 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001935 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001936
1937 switch (req->qtcb->header.fsf_status) {
1938 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001939 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1941 break;
1942 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001943 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1945 break;
1946 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001947 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001948 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001949 break;
1950 case FSF_ADAPTER_STATUS_AVAILABLE:
1951 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1952 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001953 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954 /* fall through */
1955 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1956 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1957 break;
1958 }
1959 break;
1960 case FSF_GOOD:
1961 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1962 break;
1963 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001964}
1965
1966/**
1967 * zfcp_fsf_close_unit - close zfcp unit
1968 * @erp_action: pointer to struct zfcp_unit
1969 * Returns: 0 on success, error otherwise
1970 */
1971int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1972{
Swen Schillig564e1c82009-08-18 15:43:19 +02001973 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001974 struct zfcp_fsf_req *req;
1975 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
Swen Schillig564e1c82009-08-18 15:43:19 +02001977 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001978 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001980
Swen Schillig564e1c82009-08-18 15:43:19 +02001981 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001982 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001983 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001984
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001985 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001986 retval = PTR_ERR(req);
1987 goto out;
1988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Swen Schillig09a46c62009-08-18 15:43:16 +02001990 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001991 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001993 req->qtcb->header.port_handle = erp_action->port->handle;
1994 req->qtcb->header.lun_handle = erp_action->unit->handle;
1995 req->handler = zfcp_fsf_close_unit_handler;
1996 req->data = erp_action->unit;
1997 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001998 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Christof Schmitt287ac012008-07-02 10:56:40 +02002000 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002001 retval = zfcp_fsf_req_send(req);
2002 if (retval) {
2003 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002004 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002005 }
2006out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002007 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002008 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009}
2010
Christof Schmittc9615852008-05-06 11:00:05 +02002011static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2012{
2013 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002014 lat_rec->min = min(lat_rec->min, lat);
2015 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002016}
2017
Christof Schmittd9742b42009-11-24 16:54:03 +01002018static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002019{
Christof Schmittd9742b42009-11-24 16:54:03 +01002020 struct fsf_qual_latency_info *lat_in;
2021 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002022 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002023 struct zfcp_blk_drv_data blktrc;
2024 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002025
Christof Schmittd9742b42009-11-24 16:54:03 +01002026 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002027
Christof Schmittd9742b42009-11-24 16:54:03 +01002028 blktrc.flags = 0;
2029 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2030 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2031 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002032 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2033 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002034
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002035 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2036 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002037 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2038 blktrc.channel_lat = lat_in->channel_lat * ticks;
2039 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2040
2041 switch (req->qtcb->bottom.io.data_direction) {
2042 case FSF_DATADIR_READ:
2043 lat = &unit->latencies.read;
2044 break;
2045 case FSF_DATADIR_WRITE:
2046 lat = &unit->latencies.write;
2047 break;
2048 case FSF_DATADIR_CMND:
2049 lat = &unit->latencies.cmd;
2050 break;
2051 }
2052
2053 if (lat) {
2054 spin_lock(&unit->latencies.lock);
2055 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2056 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2057 lat->counter++;
2058 spin_unlock(&unit->latencies.lock);
2059 }
Christof Schmittc9615852008-05-06 11:00:05 +02002060 }
2061
Christof Schmittd9742b42009-11-24 16:54:03 +01002062 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2063 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002064}
2065
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002066static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002068 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002069 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002072 read_lock_irqsave(&req->adapter->abort_lock, flags);
2073
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002074 scpnt = req->data;
2075 if (unlikely(!scpnt)) {
2076 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2077 return;
2078 }
2079
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002080 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002081 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 goto skip_fsfstatus;
2083 }
2084
Christof Schmitt4318e082009-11-24 16:54:08 +01002085 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2086 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002088skip_fsfstatus:
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002089 zfcp_fsf_req_trace(req, scpnt);
Christof Schmittab725282010-02-17 11:18:57 +01002090 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /*
2095 * We must hold this lock until scsi_done has been called.
2096 * Otherwise we may call scsi_done after abort regarding this
2097 * command has completed.
2098 * Note: scsi_done must not block!
2099 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002100 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002103static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Christof Schmitt4318e082009-11-24 16:54:08 +01002105 struct fcp_resp_with_ext *fcp_rsp;
2106 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Christof Schmitt4318e082009-11-24 16:54:08 +01002108 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2109 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2110
2111 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002112 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2113 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
2116
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002117static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2118{
2119 struct zfcp_unit *unit;
2120 struct fsf_qtcb_header *header = &req->qtcb->header;
2121
2122 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2123 unit = req->data;
2124 else
2125 unit = req->unit;
2126
2127 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2128 goto skip_fsfstatus;
2129
2130 switch (header->fsf_status) {
2131 case FSF_HANDLE_MISMATCH:
2132 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002133 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002134 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2135 break;
2136 case FSF_FCPLUN_NOT_VALID:
2137 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002138 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002139 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2140 break;
2141 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2142 zfcp_fsf_class_not_supp(req);
2143 break;
2144 case FSF_ACCESS_DENIED:
2145 zfcp_fsf_access_denied_unit(req, unit);
2146 break;
2147 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2148 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002149 "Incorrect direction %d, unit 0x%016Lx on port "
2150 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002151 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002152 (unsigned long long)unit->fcp_lun,
2153 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002154 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2155 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002156 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2157 break;
2158 case FSF_CMND_LENGTH_NOT_VALID:
2159 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002160 "Incorrect CDB length %d, unit 0x%016Lx on "
2161 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002162 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002163 (unsigned long long)unit->fcp_lun,
2164 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002165 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2166 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002167 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2168 break;
2169 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002170 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002171 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002172 break;
2173 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002174 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002175 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002176 break;
2177 case FSF_ADAPTER_STATUS_AVAILABLE:
2178 if (header->fsf_status_qual.word[0] ==
2179 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002180 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002181 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2182 break;
2183 }
2184skip_fsfstatus:
2185 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2186 zfcp_fsf_send_fcp_ctm_handler(req);
2187 else {
2188 zfcp_fsf_send_fcp_command_task_handler(req);
2189 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002190 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002191 }
2192}
2193
2194/**
2195 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002196 * @unit: unit where command is sent to
2197 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002198 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002199int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2200 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002201{
2202 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002203 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002204 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002205 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002206 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002207 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002208
2209 if (unlikely(!(atomic_read(&unit->status) &
2210 ZFCP_STATUS_COMMON_UNBLOCKED)))
2211 return -EBUSY;
2212
Swen Schillig564e1c82009-08-18 15:43:19 +02002213 spin_lock(&qdio->req_q_lock);
2214 if (atomic_read(&qdio->req_q.count) <= 0) {
2215 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002216 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002217 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002218
Christof Schmitt1674b402010-04-30 18:09:34 +02002219 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2220 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2221
Swen Schillig564e1c82009-08-18 15:43:19 +02002222 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002223 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002224
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002225 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002226 retval = PTR_ERR(req);
2227 goto out;
2228 }
2229
Swen Schillig09a46c62009-08-18 15:43:16 +02002230 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002231 req->unit = unit;
2232 req->data = scsi_cmnd;
2233 req->handler = zfcp_fsf_send_fcp_command_handler;
2234 req->qtcb->header.lun_handle = unit->handle;
2235 req->qtcb->header.port_handle = unit->port->handle;
2236 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002237 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002238
2239 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2240
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002241 /*
2242 * set depending on data direction:
2243 * data direction bits in SBALE (SB Type)
2244 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002245 */
2246 switch (scsi_cmnd->sc_data_direction) {
2247 case DMA_NONE:
2248 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002249 break;
2250 case DMA_FROM_DEVICE:
2251 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002252 break;
2253 case DMA_TO_DEVICE:
2254 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002255 break;
2256 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002257 goto failed_scsi_cmnd;
2258 }
2259
Christof Schmitt1674b402010-04-30 18:09:34 +02002260 get_device(&unit->dev);
2261
Christof Schmitt4318e082009-11-24 16:54:08 +01002262 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2263 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002264
Christof Schmitt1674b402010-04-30 18:09:34 +02002265 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002266 scsi_sglist(scsi_cmnd),
Christof Schmitt1674b402010-04-30 18:09:34 +02002267 ZFCP_FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002268 if (unlikely(real_bytes < 0)) {
Christof Schmitt1674b402010-04-30 18:09:34 +02002269 if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002270 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002271 "Oversize data package, unit 0x%016Lx "
2272 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002273 (unsigned long long)unit->fcp_lun,
2274 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002275 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002276 retval = -EINVAL;
2277 }
2278 goto failed_scsi_cmnd;
2279 }
2280
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002281 retval = zfcp_fsf_req_send(req);
2282 if (unlikely(retval))
2283 goto failed_scsi_cmnd;
2284
2285 goto out;
2286
2287failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002288 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002289 zfcp_fsf_req_free(req);
2290 scsi_cmnd->host_scribble = NULL;
2291out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002292 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002293 return retval;
2294}
2295
2296/**
2297 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002298 * @unit: pointer to struct zfcp_unit
2299 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002300 * Returns: on success pointer to struct fsf_req, NULL otherwise
2301 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002302struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002303{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002304 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002305 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002306 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002307
2308 if (unlikely(!(atomic_read(&unit->status) &
2309 ZFCP_STATUS_COMMON_UNBLOCKED)))
2310 return NULL;
2311
Swen Schillig564e1c82009-08-18 15:43:19 +02002312 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002313 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002314 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002315
Swen Schillig564e1c82009-08-18 15:43:19 +02002316 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002317 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002318 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002319
Swen Schillig633528c2008-11-26 18:07:37 +01002320 if (IS_ERR(req)) {
2321 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002322 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002323 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002324
2325 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2326 req->data = unit;
2327 req->handler = zfcp_fsf_send_fcp_command_handler;
2328 req->qtcb->header.lun_handle = unit->handle;
2329 req->qtcb->header.port_handle = unit->port->handle;
2330 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2331 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002332 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002333
Christof Schmitt1674b402010-04-30 18:09:34 +02002334 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002335
Christof Schmitt4318e082009-11-24 16:54:08 +01002336 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2337 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002338
2339 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2340 if (!zfcp_fsf_req_send(req))
2341 goto out;
2342
2343 zfcp_fsf_req_free(req);
2344 req = NULL;
2345out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002346 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002347 return req;
2348}
2349
2350static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2351{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352}
2353
2354/**
2355 * zfcp_fsf_control_file - control file upload/download
2356 * @adapter: pointer to struct zfcp_adapter
2357 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2358 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002360struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2361 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
Swen Schillig564e1c82009-08-18 15:43:19 +02002363 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002364 struct zfcp_fsf_req *req = NULL;
2365 struct fsf_qtcb_bottom_support *bottom;
2366 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Christof Schmitt45633fd2008-06-10 18:20:55 +02002368 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2369 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Christof Schmitt45633fd2008-06-10 18:20:55 +02002371 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2373 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2376 direction = SBAL_FLAGS0_TYPE_READ;
2377 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002379 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 }
2381
Swen Schillig564e1c82009-08-18 15:43:19 +02002382 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002383 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002384 goto out;
2385
Christof Schmitt1674b402010-04-30 18:09:34 +02002386 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002387 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002389 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 }
2391
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002392 req->handler = zfcp_fsf_control_file_handler;
2393
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002394 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002396 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Christof Schmitt34c2b712010-02-17 11:18:59 +01002398 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +02002399 fsf_cfdc->sg,
2400 ZFCP_FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002401 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402 zfcp_fsf_req_free(req);
2403 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002406 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2407 retval = zfcp_fsf_req_send(req);
2408out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002409 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002410
2411 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002412 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002413 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002415 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002417
2418/**
2419 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2420 * @adapter: pointer to struct zfcp_adapter
2421 * @sbal_idx: response queue index of SBAL to be processed
2422 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002423void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002424{
Swen Schillig564e1c82009-08-18 15:43:19 +02002425 struct zfcp_adapter *adapter = qdio->adapter;
2426 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002427 struct qdio_buffer_element *sbale;
2428 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002429 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002430 int idx;
2431
2432 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2433
2434 sbale = &sbal->element[idx];
2435 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002436 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002437
2438 if (!fsf_req)
2439 /*
2440 * Unknown request means that we have potentially memory
2441 * corruption and must stop the machine immediately.
2442 */
2443 panic("error: unknown req_id (%lx) on adapter %s.\n",
2444 req_id, dev_name(&adapter->ccw_device->dev));
2445
Christof Schmitt34c2b712010-02-17 11:18:59 +01002446 fsf_req->qdio_req.sbal_response = sbal_idx;
2447 fsf_req->qdio_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002448 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002449 zfcp_fsf_req_complete(fsf_req);
2450
2451 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2452 break;
2453 }
2454}