blob: 71663fb77310b5a51a9331d7210b978a444dd707 [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 Schmitt8d88cf32010-06-21 10:11:33 +0200499 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
500 (u16)FSF_STATUS_READS_RECOM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200501
502 if (fc_host_permanent_port_name(shost) == -1)
503 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
504
505 switch (bottom->fc_topology) {
506 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100507 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100508 adapter->peer_wwpn = plogi->fl_wwpn;
509 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200510 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200511 break;
512 case FSF_TOPO_FABRIC:
513 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200514 break;
515 case FSF_TOPO_AL:
516 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200517 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200518 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200519 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200520 "Unknown or unsupported arbitrated loop "
521 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100522 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200523 return -EIO;
524 }
525
526 return 0;
527}
528
529static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
530{
531 struct zfcp_adapter *adapter = req->adapter;
532 struct fsf_qtcb *qtcb = req->qtcb;
533 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
534 struct Scsi_Host *shost = adapter->scsi_host;
535
536 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
537 return;
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200540 adapter->adapter_features = bottom->adapter_features;
541 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500542 adapter->peer_wwpn = 0;
543 adapter->peer_wwnn = 0;
544 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200546 switch (qtcb->header.fsf_status) {
547 case FSF_GOOD:
548 if (zfcp_fsf_exchange_config_evaluate(req))
549 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200550
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200551 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
552 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200553 "FCP adapter maximum QTCB size (%d bytes) "
554 "is too small\n",
555 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100556 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200557 return;
558 }
559 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
560 &adapter->status);
561 break;
562 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200563 fc_host_node_name(shost) = 0;
564 fc_host_port_name(shost) = 0;
565 fc_host_port_id(shost) = 0;
566 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100567 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200569
570 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
571 &adapter->status);
572
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100573 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200574 &qtcb->header.fsf_status_qual.link_down_info);
575 break;
576 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100577 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200578 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200581 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200583 memcpy(fc_host_serial_number(shost), bottom->serial_number,
584 min(FC_SERIAL_NUMBER_SIZE, 17));
585 EBCASC(fc_host_serial_number(shost),
586 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200589 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200590 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200591 "The FCP adapter only supports newer "
592 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100593 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200594 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200596 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200597 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200598 "The FCP adapter only supports older "
599 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100600 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200604static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200606 struct zfcp_adapter *adapter = req->adapter;
607 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
608 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200610 if (req->data)
611 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100612
Christof Schmitt02829852009-03-02 13:09:06 +0100613 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100614 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100615 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
616 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100617 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
618 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
619 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100620 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
621 FC_FC4_LIST_SIZE);
622 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
623 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100624}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100629
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200630 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return;
632
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200634 case FSF_GOOD:
635 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200637 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200638 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100639 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200640 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200641 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643}
644
Swen Schilliga4623c42009-08-18 15:43:15 +0200645static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200646{
647 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200648
649 if (likely(pool))
650 req = mempool_alloc(pool, GFP_ATOMIC);
651 else
652 req = kmalloc(sizeof(*req), GFP_ATOMIC);
653
654 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200655 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200656
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100658 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200659 return req;
660}
661
Swen Schilliga4623c42009-08-18 15:43:15 +0200662static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200663{
Swen Schilliga4623c42009-08-18 15:43:15 +0200664 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200665
666 if (likely(pool))
667 qtcb = mempool_alloc(pool, GFP_ATOMIC);
668 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200669 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
670
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200671 if (unlikely(!qtcb))
672 return NULL;
673
674 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200675 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200676}
677
Swen Schillig564e1c82009-08-18 15:43:19 +0200678static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Christof Schmitt1674b402010-04-30 18:09:34 +0200679 u32 fsf_cmd, u32 sbtype,
680 mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Swen Schillig564e1c82009-08-18 15:43:19 +0200682 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200683 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684
685 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200686 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200687
688 if (adapter->req_no == 0)
689 adapter->req_no++;
690
691 INIT_LIST_HEAD(&req->list);
692 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200693 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694
695 req->adapter = adapter;
696 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100697 req->req_id = adapter->req_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200698
Swen Schilliga4623c42009-08-18 15:43:15 +0200699 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
700 if (likely(pool))
701 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
702 else
703 req->qtcb = zfcp_qtcb_alloc(NULL);
704
705 if (unlikely(!req->qtcb)) {
706 zfcp_fsf_req_free(req);
707 return ERR_PTR(-ENOMEM);
708 }
709
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100710 req->seq_no = adapter->fsf_req_seq_no;
Swen Schillig564e1c82009-08-18 15:43:19 +0200711 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200712 req->qtcb->prefix.req_id = req->req_id;
713 req->qtcb->prefix.ulp_info = 26;
714 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
715 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
716 req->qtcb->header.req_handle = req->req_id;
717 req->qtcb->header.fsf_command = req->fsf_command;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200718 }
719
Christof Schmitt1674b402010-04-30 18:09:34 +0200720 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
721 req->qtcb, sizeof(struct fsf_qtcb));
722
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200723 return req;
724}
725
726static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
727{
728 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200729 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100730 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100731 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100733 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200734
Christof Schmitt34c2b712010-02-17 11:18:59 +0100735 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200736 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100737 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200738 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100739 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100740 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100741 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200742 return -EIO;
743 }
744
745 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200746 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200747 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100748 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200749
750 return 0;
751}
752
753/**
754 * zfcp_fsf_status_read - send status read request
755 * @adapter: pointer to struct zfcp_adapter
756 * @req_flags: request flags
757 * Returns: 0 on success, ERROR otherwise
758 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200759int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200760{
Swen Schillig564e1c82009-08-18 15:43:19 +0200761 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200762 struct zfcp_fsf_req *req;
763 struct fsf_status_read_buffer *sr_buf;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200764 int retval = -EIO;
765
Swen Schillig564e1c82009-08-18 15:43:19 +0200766 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200767 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Christof Schmitt1674b402010-04-30 18:09:34 +0200770 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
Swen Schilliga4623c42009-08-18 15:43:15 +0200771 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200772 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200773 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 goto out;
775 }
776
Swen Schilliga4623c42009-08-18 15:43:15 +0200777 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200778 if (!sr_buf) {
779 retval = -ENOMEM;
780 goto failed_buf;
781 }
782 memset(sr_buf, 0, sizeof(*sr_buf));
783 req->data = sr_buf;
Christof Schmitt1674b402010-04-30 18:09:34 +0200784
785 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
786 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200787
788 retval = zfcp_fsf_req_send(req);
789 if (retval)
790 goto failed_req_send;
791
792 goto out;
793
794failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200795 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200796failed_buf:
797 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200798 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200799out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200800 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 return retval;
802}
803
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200804static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806 struct zfcp_unit *unit = req->data;
807 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200809 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
810 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200812 switch (req->qtcb->header.fsf_status) {
813 case FSF_PORT_HANDLE_NOT_VALID:
814 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100815 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
816 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 case FSF_LUN_HANDLE_NOT_VALID:
821 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100822 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200823 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200826 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
827 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100830 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100831 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200832 break;
833 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100834 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100835 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200836 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200838 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200840 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200841 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 break;
845 }
846 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200848 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
849 break;
850 }
851}
852
853/**
854 * zfcp_fsf_abort_fcp_command - abort running SCSI command
855 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200856 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200858 */
859
860struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100861 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200864 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200865
Swen Schillig564e1c82009-08-18 15:43:19 +0200866 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +0200867 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200868 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200869 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +0200870 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +0200871 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100872 if (IS_ERR(req)) {
873 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200874 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100875 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200876
877 if (unlikely(!(atomic_read(&unit->status) &
878 ZFCP_STATUS_COMMON_UNBLOCKED)))
879 goto out_error_free;
880
Christof Schmitt1674b402010-04-30 18:09:34 +0200881 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882
883 req->data = unit;
884 req->handler = zfcp_fsf_abort_fcp_command_handler;
885 req->qtcb->header.lun_handle = unit->handle;
886 req->qtcb->header.port_handle = unit->port->handle;
887 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
888
889 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
890 if (!zfcp_fsf_req_send(req))
891 goto out;
892
893out_error_free:
894 zfcp_fsf_req_free(req);
895 req = NULL;
896out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200897 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200898 return req;
899}
900
901static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
902{
903 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100904 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200905 struct fsf_qtcb_header *header = &req->qtcb->header;
906
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100907 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908
909 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
910 goto skip_fsfstatus;
911
912 switch (header->fsf_status) {
913 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200914 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100915 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200916 break;
917 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
918 zfcp_fsf_class_not_supp(req);
919 break;
920 case FSF_ADAPTER_STATUS_AVAILABLE:
921 switch (header->fsf_status_qual.word[0]){
922 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200923 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
924 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
925 break;
926 }
927 break;
928 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200929 break;
930 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100931 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 break;
933 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100934 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200935 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200936 case FSF_GENERIC_COMMAND_REJECTED:
937 case FSF_PAYLOAD_SIZE_MISMATCH:
938 case FSF_REQUEST_SIZE_TOO_LARGE:
939 case FSF_RESPONSE_SIZE_TOO_LARGE:
940 case FSF_SBAL_MISMATCH:
941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
942 break;
943 }
944
945skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100946 if (ct->handler)
947 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200948}
949
Christof Schmitt1674b402010-04-30 18:09:34 +0200950static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
951 struct zfcp_qdio_req *q_req,
Christof Schmitt426f6052009-07-13 15:06:06 +0200952 struct scatterlist *sg_req,
953 struct scatterlist *sg_resp)
954{
Christof Schmitt1674b402010-04-30 18:09:34 +0200955 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
956 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
957 zfcp_qdio_set_sbale_last(qdio, q_req);
Christof Schmitt426f6052009-07-13 15:06:06 +0200958}
959
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100960static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
961 struct scatterlist *sg_req,
962 struct scatterlist *sg_resp,
963 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200964{
Swen Schillig42428f72009-08-18 15:43:18 +0200965 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig42428f72009-08-18 15:43:18 +0200966 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200967 int bytes;
968
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100969 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200970 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
971 !zfcp_qdio_sg_one_sbale(sg_resp))
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100972 return -EOPNOTSUPP;
973
Christof Schmitt1674b402010-04-30 18:09:34 +0200974 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
975 sg_req, sg_resp);
Christof Schmitt426f6052009-07-13 15:06:06 +0200976 return 0;
977 }
978
979 /* use single, unchained SBAL if it can hold the request */
Swen Schillig30b67772010-06-21 10:11:31 +0200980 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
Christof Schmitt1674b402010-04-30 18:09:34 +0200981 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
982 sg_req, sg_resp);
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100983 return 0;
984 }
985
Christof Schmitt34c2b712010-02-17 11:18:59 +0100986 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200987 sg_req, max_sbals);
988 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200989 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200990 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt1674b402010-04-30 18:09:34 +0200991 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200992
Christof Schmitt34c2b712010-02-17 11:18:59 +0100993 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200994 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +0200995 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200996 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +0200997 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +0200998
Christof Schmittb1a58982009-09-24 10:23:21 +0200999 return 0;
1000}
1001
1002static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1003 struct scatterlist *sg_req,
1004 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001005 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001006{
1007 int ret;
1008
1009 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1010 if (ret)
1011 return ret;
1012
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001013 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001014 if (timeout > 255)
1015 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001016 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001017 req->qtcb->bottom.support.timeout = timeout;
1018 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001019
1020 return 0;
1021}
1022
1023/**
1024 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1025 * @ct: pointer to struct zfcp_send_ct with data for request
1026 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001027 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001028int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001029 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1030 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001031{
Swen Schillig564e1c82009-08-18 15:43:19 +02001032 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001033 struct zfcp_fsf_req *req;
1034 int ret = -EIO;
1035
Swen Schillig564e1c82009-08-18 15:43:19 +02001036 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001037 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001038 goto out;
1039
Christof Schmitt1674b402010-04-30 18:09:34 +02001040 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1041 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001042
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001043 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001044 ret = PTR_ERR(req);
1045 goto out;
1046 }
1047
Swen Schillig09a46c62009-08-18 15:43:16 +02001048 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001049 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Christof Schmitt1674b402010-04-30 18:09:34 +02001050 ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001051 if (ret)
1052 goto failed_send;
1053
1054 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001055 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001056 req->data = ct;
1057
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001058 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001059
1060 ret = zfcp_fsf_req_send(req);
1061 if (ret)
1062 goto failed_send;
1063
1064 goto out;
1065
1066failed_send:
1067 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001068out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001069 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001070 return ret;
1071}
1072
1073static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1074{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001075 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001076 struct zfcp_port *port = send_els->port;
1077 struct fsf_qtcb_header *header = &req->qtcb->header;
1078
1079 send_els->status = -EINVAL;
1080
1081 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1082 goto skip_fsfstatus;
1083
1084 switch (header->fsf_status) {
1085 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001086 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087 send_els->status = 0;
1088 break;
1089 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1090 zfcp_fsf_class_not_supp(req);
1091 break;
1092 case FSF_ADAPTER_STATUS_AVAILABLE:
1093 switch (header->fsf_status_qual.word[0]){
1094 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001095 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1096 case FSF_SQ_RETRY_IF_POSSIBLE:
1097 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1098 break;
1099 }
1100 break;
1101 case FSF_ELS_COMMAND_REJECTED:
1102 case FSF_PAYLOAD_SIZE_MISMATCH:
1103 case FSF_REQUEST_SIZE_TOO_LARGE:
1104 case FSF_RESPONSE_SIZE_TOO_LARGE:
1105 break;
1106 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001107 if (port)
1108 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001109 break;
1110 case FSF_SBAL_MISMATCH:
1111 /* should never occure, avoided in zfcp_fsf_send_els */
1112 /* fall through */
1113 default:
1114 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1115 break;
1116 }
1117skip_fsfstatus:
1118 if (send_els->handler)
1119 send_els->handler(send_els->handler_data);
1120}
1121
1122/**
1123 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1124 * @els: pointer to struct zfcp_send_els with data for the command
1125 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001126int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001127 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001128{
1129 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001130 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001131 int ret = -EIO;
1132
Swen Schillig564e1c82009-08-18 15:43:19 +02001133 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001134 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001136
Christof Schmitt1674b402010-04-30 18:09:34 +02001137 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1138 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001139
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001140 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001141 ret = PTR_ERR(req);
1142 goto out;
1143 }
1144
Swen Schillig09a46c62009-08-18 15:43:16 +02001145 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001146 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001147
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001148 if (ret)
1149 goto failed_send;
1150
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001151 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001152 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001153 req->data = els;
1154
Swen Schillig57717102009-08-18 15:43:21 +02001155 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001156
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001157 ret = zfcp_fsf_req_send(req);
1158 if (ret)
1159 goto failed_send;
1160
1161 goto out;
1162
1163failed_send:
1164 zfcp_fsf_req_free(req);
1165out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001166 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001167 return ret;
1168}
1169
1170int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1171{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001172 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001173 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001174 int retval = -EIO;
1175
Swen Schillig564e1c82009-08-18 15:43:19 +02001176 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001177 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001178 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001179
Swen Schillig564e1c82009-08-18 15:43:19 +02001180 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001181 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001182 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001183
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001184 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001185 retval = PTR_ERR(req);
1186 goto out;
1187 }
1188
Swen Schillig09a46c62009-08-18 15:43:16 +02001189 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001190 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001191
1192 req->qtcb->bottom.config.feature_selection =
1193 FSF_FEATURE_CFDC |
1194 FSF_FEATURE_LUN_SHARING |
1195 FSF_FEATURE_NOTIFICATION_LOST |
1196 FSF_FEATURE_UPDATE_ALERT;
1197 req->erp_action = erp_action;
1198 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001199 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001200
Christof Schmitt287ac012008-07-02 10:56:40 +02001201 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 retval = zfcp_fsf_req_send(req);
1203 if (retval) {
1204 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001205 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 }
1207out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001208 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001209 return retval;
1210}
1211
Swen Schillig564e1c82009-08-18 15:43:19 +02001212int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001213 struct fsf_qtcb_bottom_config *data)
1214{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001215 struct zfcp_fsf_req *req = NULL;
1216 int retval = -EIO;
1217
Swen Schillig564e1c82009-08-18 15:43:19 +02001218 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001219 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001220 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001221
Christof Schmitt1674b402010-04-30 18:09:34 +02001222 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1223 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001224
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001225 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001226 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001227 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001228 }
1229
Christof Schmitt1674b402010-04-30 18:09:34 +02001230 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001231 req->handler = zfcp_fsf_exchange_config_data_handler;
1232
1233 req->qtcb->bottom.config.feature_selection =
1234 FSF_FEATURE_CFDC |
1235 FSF_FEATURE_LUN_SHARING |
1236 FSF_FEATURE_NOTIFICATION_LOST |
1237 FSF_FEATURE_UPDATE_ALERT;
1238
1239 if (data)
1240 req->data = data;
1241
1242 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1243 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001244 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001246 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001247
1248 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001249 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001250
Christof Schmittada81b72009-04-17 15:08:03 +02001251out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001252 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001253 return retval;
1254}
1255
1256/**
1257 * zfcp_fsf_exchange_port_data - request information about local port
1258 * @erp_action: ERP action for the adapter for which port data is requested
1259 * Returns: 0 on success, error otherwise
1260 */
1261int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1262{
Swen Schillig564e1c82009-08-18 15:43:19 +02001263 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001264 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001265 int retval = -EIO;
1266
Swen Schillig564e1c82009-08-18 15:43:19 +02001267 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268 return -EOPNOTSUPP;
1269
Swen Schillig564e1c82009-08-18 15:43:19 +02001270 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001271 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001273
Swen Schillig564e1c82009-08-18 15:43:19 +02001274 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
Christof Schmitt1674b402010-04-30 18:09:34 +02001275 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001276 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001277
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001278 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001279 retval = PTR_ERR(req);
1280 goto out;
1281 }
1282
Swen Schillig09a46c62009-08-18 15:43:16 +02001283 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001284 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001285
1286 req->handler = zfcp_fsf_exchange_port_data_handler;
1287 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001288 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001289
Christof Schmitt287ac012008-07-02 10:56:40 +02001290 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001291 retval = zfcp_fsf_req_send(req);
1292 if (retval) {
1293 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001294 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001295 }
1296out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001297 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001298 return retval;
1299}
1300
1301/**
1302 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001303 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001304 * @data: pointer to struct fsf_qtcb_bottom_port
1305 * Returns: 0 on success, error otherwise
1306 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001307int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308 struct fsf_qtcb_bottom_port *data)
1309{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001310 struct zfcp_fsf_req *req = NULL;
1311 int retval = -EIO;
1312
Swen Schillig564e1c82009-08-18 15:43:19 +02001313 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001314 return -EOPNOTSUPP;
1315
Swen Schillig564e1c82009-08-18 15:43:19 +02001316 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001317 if (zfcp_qdio_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001318 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001319
Christof Schmitt1674b402010-04-30 18:09:34 +02001320 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1321 SBAL_FLAGS0_TYPE_READ, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001322
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001323 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001324 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001325 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001326 }
1327
1328 if (data)
1329 req->data = data;
1330
Christof Schmitt1674b402010-04-30 18:09:34 +02001331 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001332
1333 req->handler = zfcp_fsf_exchange_port_data_handler;
1334 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1335 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001336 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001337
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001338 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001339 wait_for_completion(&req->completion);
1340
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001341 zfcp_fsf_req_free(req);
1342
1343 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001344
1345out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001346 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001347 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001348}
1349
1350static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1351{
1352 struct zfcp_port *port = req->data;
1353 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001354 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355
1356 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001357 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358
1359 switch (header->fsf_status) {
1360 case FSF_PORT_ALREADY_OPEN:
1361 break;
1362 case FSF_ACCESS_DENIED:
1363 zfcp_fsf_access_denied_port(req, port);
1364 break;
1365 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1366 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001367 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001368 "remote port 0x%016Lx\n",
1369 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001370 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001371 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1372 break;
1373 case FSF_ADAPTER_STATUS_AVAILABLE:
1374 switch (header->fsf_status_qual.word[0]) {
1375 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1376 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001377 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001378 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1379 break;
1380 }
1381 break;
1382 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1385 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001386 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1387 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1388 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 /* check whether D_ID has changed during open */
1390 /*
1391 * FIXME: This check is not airtight, as the FCP channel does
1392 * not monitor closures of target port connections caused on
1393 * the remote side. Thus, they might miss out on invalidating
1394 * locally cached WWPNs (and other N_Port parameters) of gone
1395 * target ports. So, our heroic attempt to make things safe
1396 * could be undermined by 'open port' response data tagged with
1397 * obsolete WWPNs. Another reason to monitor potential
1398 * connection closures ourself at least (by interpreting
1399 * incoming ELS' and unsolicited status). It just crosses my
1400 * mind that one should be able to cross-check by means of
1401 * another GID_PN straight after a port has been opened.
1402 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1403 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001404 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001405 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001406 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001407 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001410 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 break;
1412 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001413
1414out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001415 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001418/**
1419 * zfcp_fsf_open_port - create and send open port request
1420 * @erp_action: pointer to struct zfcp_erp_action
1421 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001423int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Swen Schillig564e1c82009-08-18 15:43:19 +02001425 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001426 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001427 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001428 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Swen Schillig564e1c82009-08-18 15:43:19 +02001430 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001431 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Swen Schillig564e1c82009-08-18 15:43:19 +02001434 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001435 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001436 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001437
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001438 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001439 retval = PTR_ERR(req);
1440 goto out;
1441 }
1442
Swen Schillig09a46c62009-08-18 15:43:16 +02001443 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001444 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001446 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001447 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001448 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001449 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001450 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001451 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Christof Schmitt287ac012008-07-02 10:56:40 +02001453 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001454 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001456 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001457 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001458 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001460out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001461 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 return retval;
1463}
1464
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001465static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001467 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001469 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001470 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001474 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001475 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001480 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 ZFCP_STATUS_COMMON_OPEN,
1482 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485}
1486
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001487/**
1488 * zfcp_fsf_close_port - create and send close port request
1489 * @erp_action: pointer to struct zfcp_erp_action
1490 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001492int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Swen Schillig564e1c82009-08-18 15:43:19 +02001494 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001495 struct zfcp_fsf_req *req;
1496 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Swen Schillig564e1c82009-08-18 15:43:19 +02001498 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001499 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Swen Schillig564e1c82009-08-18 15:43:19 +02001502 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001503 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001504 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001505
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001506 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001507 retval = PTR_ERR(req);
1508 goto out;
1509 }
1510
Swen Schillig09a46c62009-08-18 15:43:16 +02001511 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001512 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001514 req->handler = zfcp_fsf_close_port_handler;
1515 req->data = erp_action->port;
1516 req->erp_action = erp_action;
1517 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001518 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Christof Schmitt287ac012008-07-02 10:56:40 +02001520 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001521 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001523 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001524 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001526out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001527 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 return retval;
1529}
1530
Swen Schillig5ab944f2008-10-01 12:42:17 +02001531static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1532{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001533 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001534 struct fsf_qtcb_header *header = &req->qtcb->header;
1535
1536 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001537 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001538 goto out;
1539 }
1540
1541 switch (header->fsf_status) {
1542 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1543 dev_warn(&req->adapter->ccw_device->dev,
1544 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001545 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001546 case FSF_ADAPTER_STATUS_AVAILABLE:
1547 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001548 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001549 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001550 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001551 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001552 case FSF_GOOD:
1553 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001554 /* fall through */
1555 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001556 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001557 }
1558out:
1559 wake_up(&wka_port->completion_wq);
1560}
1561
1562/**
1563 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001564 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001565 * Returns: 0 on success, error otherwise
1566 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001567int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001568{
Swen Schillig564e1c82009-08-18 15:43:19 +02001569 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001570 struct zfcp_fsf_req *req;
1571 int retval = -EIO;
1572
Swen Schillig564e1c82009-08-18 15:43:19 +02001573 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001574 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001575 goto out;
1576
Swen Schillig564e1c82009-08-18 15:43:19 +02001577 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
Christof Schmitt1674b402010-04-30 18:09:34 +02001578 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001579 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001580
Swen Schillig5ab944f2008-10-01 12:42:17 +02001581 if (unlikely(IS_ERR(req))) {
1582 retval = PTR_ERR(req);
1583 goto out;
1584 }
1585
Swen Schillig09a46c62009-08-18 15:43:16 +02001586 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001587 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001588
1589 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001590 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591 req->data = wka_port;
1592
1593 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1594 retval = zfcp_fsf_req_send(req);
1595 if (retval)
1596 zfcp_fsf_req_free(req);
1597out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001598 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001599 return retval;
1600}
1601
1602static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1603{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001604 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001605
1606 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1607 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001608 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001609 }
1610
Christof Schmittbd0072e2009-11-24 16:54:11 +01001611 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001612 wake_up(&wka_port->completion_wq);
1613}
1614
1615/**
1616 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001617 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001618 * Returns: 0 on success, error otherwise
1619 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001620int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001621{
Swen Schillig564e1c82009-08-18 15:43:19 +02001622 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001623 struct zfcp_fsf_req *req;
1624 int retval = -EIO;
1625
Swen Schillig564e1c82009-08-18 15:43:19 +02001626 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001627 if (zfcp_qdio_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001628 goto out;
1629
Swen Schillig564e1c82009-08-18 15:43:19 +02001630 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001631 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001632 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001633
Swen Schillig5ab944f2008-10-01 12:42:17 +02001634 if (unlikely(IS_ERR(req))) {
1635 retval = PTR_ERR(req);
1636 goto out;
1637 }
1638
Swen Schillig09a46c62009-08-18 15:43:16 +02001639 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001640 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001641
1642 req->handler = zfcp_fsf_close_wka_port_handler;
1643 req->data = wka_port;
1644 req->qtcb->header.port_handle = wka_port->handle;
1645
1646 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1647 retval = zfcp_fsf_req_send(req);
1648 if (retval)
1649 zfcp_fsf_req_free(req);
1650out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001651 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001652 return retval;
1653}
1654
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001655static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001657 struct zfcp_port *port = req->data;
1658 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001661 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001666 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001667 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001670 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001673 /* can't use generic zfcp_erp_modify_port_status because
1674 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1675 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001676 read_lock(&port->unit_list_lock);
1677 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001678 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1679 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001680 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001681 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001682 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 switch (header->fsf_status_qual.word[0]) {
1686 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001687 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001689 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 /* can't use generic zfcp_erp_modify_port_status because
1695 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1696 */
1697 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001698 read_lock(&port->unit_list_lock);
1699 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001700 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1701 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001702 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001707/**
1708 * zfcp_fsf_close_physical_port - close physical port
1709 * @erp_action: pointer to struct zfcp_erp_action
1710 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001712int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Swen Schillig564e1c82009-08-18 15:43:19 +02001714 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001715 struct zfcp_fsf_req *req;
1716 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Swen Schillig564e1c82009-08-18 15:43:19 +02001718 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001719 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Swen Schillig564e1c82009-08-18 15:43:19 +02001722 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
Christof Schmitt1674b402010-04-30 18:09:34 +02001723 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001724 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001725
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001726 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001727 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 goto out;
1729 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001730
Swen Schillig09a46c62009-08-18 15:43:16 +02001731 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001732 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001733
1734 req->data = erp_action->port;
1735 req->qtcb->header.port_handle = erp_action->port->handle;
1736 req->erp_action = erp_action;
1737 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001738 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001739
Christof Schmitt287ac012008-07-02 10:56:40 +02001740 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001741 retval = zfcp_fsf_req_send(req);
1742 if (retval) {
1743 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001744 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001745 }
1746out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001747 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 return retval;
1749}
1750
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001751static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001753 struct zfcp_adapter *adapter = req->adapter;
1754 struct zfcp_unit *unit = req->data;
1755 struct fsf_qtcb_header *header = &req->qtcb->header;
1756 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1757 struct fsf_queue_designator *queue_designator =
1758 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001759 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001761 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001762 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001765 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 ZFCP_STATUS_UNIT_SHARED |
1767 ZFCP_STATUS_UNIT_READONLY,
1768 &unit->status);
1769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 switch (header->fsf_status) {
1771
1772 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001773 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001774 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001778 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001780 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001783 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001784 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001787 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001788 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001789 "LUN 0x%Lx on port 0x%Lx is already in "
1790 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001791 (unsigned long long)unit->fcp_lun,
1792 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001793 queue_designator->cssid,
1794 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001795 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001796 zfcp_act_eval_err(adapter,
1797 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001798 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1800 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001801 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001804 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001805 "No handle is available for LUN "
1806 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001807 (unsigned long long)unit->fcp_lun,
1808 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001809 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001810 /* fall through */
1811 case FSF_INVALID_COMMAND_OPTION:
1812 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 switch (header->fsf_status_qual.word[0]) {
1816 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001817 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001818 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001820 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 }
1823 break;
1824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001828
1829 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1830 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001831 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001832 exclusive = (bottom->lun_access_info &
1833 FSF_UNIT_ACCESS_EXCLUSIVE);
1834 readwrite = (bottom->lun_access_info &
1835 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if (!exclusive)
1838 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1839 &unit->status);
1840
1841 if (!readwrite) {
1842 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1843 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001844 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001845 "SCSI device at LUN 0x%016Lx on port "
1846 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001847 (unsigned long long)unit->fcp_lun,
1848 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850
1851 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001852 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001853 "Exclusive read-only access not "
1854 "supported (unit 0x%016Lx, "
1855 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001856 (unsigned long long)unit->fcp_lun,
1857 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001858 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001859 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001860 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001863 "Shared read-write access not "
1864 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001865 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001866 (unsigned long long)unit->fcp_lun,
1867 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001868 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001870 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 }
1872 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
1877/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001878 * zfcp_fsf_open_unit - open unit
1879 * @erp_action: pointer to struct zfcp_erp_action
1880 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001882int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001884 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001885 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001886 struct zfcp_fsf_req *req;
1887 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Swen Schillig564e1c82009-08-18 15:43:19 +02001889 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001890 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001891 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Swen Schillig564e1c82009-08-18 15:43:19 +02001893 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001894 SBAL_FLAGS0_TYPE_READ,
Swen Schilliga4623c42009-08-18 15:43:15 +02001895 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001896
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001897 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001898 retval = PTR_ERR(req);
1899 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001900 }
1901
Swen Schillig09a46c62009-08-18 15:43:16 +02001902 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001903 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001905 req->qtcb->header.port_handle = erp_action->port->handle;
1906 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1907 req->handler = zfcp_fsf_open_unit_handler;
1908 req->data = erp_action->unit;
1909 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001910 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001911
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001912 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1913 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Christof Schmitt287ac012008-07-02 10:56:40 +02001915 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916 retval = zfcp_fsf_req_send(req);
1917 if (retval) {
1918 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001919 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001921out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001922 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 return retval;
1924}
1925
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001926static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001928 struct zfcp_unit *unit = req->data;
1929
1930 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001931 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001932
1933 switch (req->qtcb->header.fsf_status) {
1934 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001935 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001936 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1937 break;
1938 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001939 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1941 break;
1942 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001943 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001944 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001945 break;
1946 case FSF_ADAPTER_STATUS_AVAILABLE:
1947 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1948 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001949 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001950 /* fall through */
1951 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1952 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1953 break;
1954 }
1955 break;
1956 case FSF_GOOD:
1957 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1958 break;
1959 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001960}
1961
1962/**
1963 * zfcp_fsf_close_unit - close zfcp unit
1964 * @erp_action: pointer to struct zfcp_unit
1965 * Returns: 0 on success, error otherwise
1966 */
1967int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1968{
Swen Schillig564e1c82009-08-18 15:43:19 +02001969 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970 struct zfcp_fsf_req *req;
1971 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Swen Schillig564e1c82009-08-18 15:43:19 +02001973 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02001974 if (zfcp_qdio_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001976
Swen Schillig564e1c82009-08-18 15:43:19 +02001977 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
Christof Schmitt1674b402010-04-30 18:09:34 +02001978 SBAL_FLAGS0_TYPE_READ,
Swen Schillig564e1c82009-08-18 15:43:19 +02001979 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001980
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001981 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001982 retval = PTR_ERR(req);
1983 goto out;
1984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Swen Schillig09a46c62009-08-18 15:43:16 +02001986 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt1674b402010-04-30 18:09:34 +02001987 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001989 req->qtcb->header.port_handle = erp_action->port->handle;
1990 req->qtcb->header.lun_handle = erp_action->unit->handle;
1991 req->handler = zfcp_fsf_close_unit_handler;
1992 req->data = erp_action->unit;
1993 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001994 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Christof Schmitt287ac012008-07-02 10:56:40 +02001996 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001997 retval = zfcp_fsf_req_send(req);
1998 if (retval) {
1999 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002000 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002001 }
2002out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002003 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002004 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
2006
Christof Schmittc9615852008-05-06 11:00:05 +02002007static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2008{
2009 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002010 lat_rec->min = min(lat_rec->min, lat);
2011 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002012}
2013
Christof Schmittd9742b42009-11-24 16:54:03 +01002014static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002015{
Christof Schmittd9742b42009-11-24 16:54:03 +01002016 struct fsf_qual_latency_info *lat_in;
2017 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002018 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002019 struct zfcp_blk_drv_data blktrc;
2020 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002021
Christof Schmittd9742b42009-11-24 16:54:03 +01002022 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002023
Christof Schmittd9742b42009-11-24 16:54:03 +01002024 blktrc.flags = 0;
2025 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2026 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2027 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002028 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2029 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002030
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002031 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2032 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmittd9742b42009-11-24 16:54:03 +01002033 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2034 blktrc.channel_lat = lat_in->channel_lat * ticks;
2035 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2036
2037 switch (req->qtcb->bottom.io.data_direction) {
2038 case FSF_DATADIR_READ:
2039 lat = &unit->latencies.read;
2040 break;
2041 case FSF_DATADIR_WRITE:
2042 lat = &unit->latencies.write;
2043 break;
2044 case FSF_DATADIR_CMND:
2045 lat = &unit->latencies.cmd;
2046 break;
2047 }
2048
2049 if (lat) {
2050 spin_lock(&unit->latencies.lock);
2051 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2052 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2053 lat->counter++;
2054 spin_unlock(&unit->latencies.lock);
2055 }
Christof Schmittc9615852008-05-06 11:00:05 +02002056 }
2057
Christof Schmittd9742b42009-11-24 16:54:03 +01002058 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2059 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002060}
2061
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002062static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002064 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002065 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002068 read_lock_irqsave(&req->adapter->abort_lock, flags);
2069
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002070 scpnt = req->data;
2071 if (unlikely(!scpnt)) {
2072 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2073 return;
2074 }
2075
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002076 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002077 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 goto skip_fsfstatus;
2079 }
2080
Christof Schmitt4318e082009-11-24 16:54:08 +01002081 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2082 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002084skip_fsfstatus:
Christof Schmitt5bbf2972010-04-01 13:04:08 +02002085 zfcp_fsf_req_trace(req, scpnt);
Christof Schmittab725282010-02-17 11:18:57 +01002086 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 /*
2091 * We must hold this lock until scsi_done has been called.
2092 * Otherwise we may call scsi_done after abort regarding this
2093 * command has completed.
2094 * Note: scsi_done must not block!
2095 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002096 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002099static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
Christof Schmitt4318e082009-11-24 16:54:08 +01002101 struct fcp_resp_with_ext *fcp_rsp;
2102 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Christof Schmitt4318e082009-11-24 16:54:08 +01002104 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2105 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2106
2107 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002108 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2109 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002113static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2114{
2115 struct zfcp_unit *unit;
2116 struct fsf_qtcb_header *header = &req->qtcb->header;
2117
2118 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2119 unit = req->data;
2120 else
2121 unit = req->unit;
2122
2123 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2124 goto skip_fsfstatus;
2125
2126 switch (header->fsf_status) {
2127 case FSF_HANDLE_MISMATCH:
2128 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002129 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002130 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2131 break;
2132 case FSF_FCPLUN_NOT_VALID:
2133 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002134 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002135 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2136 break;
2137 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2138 zfcp_fsf_class_not_supp(req);
2139 break;
2140 case FSF_ACCESS_DENIED:
2141 zfcp_fsf_access_denied_unit(req, unit);
2142 break;
2143 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2144 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002145 "Incorrect direction %d, unit 0x%016Lx on port "
2146 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002147 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002148 (unsigned long long)unit->fcp_lun,
2149 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002150 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2151 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002152 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2153 break;
2154 case FSF_CMND_LENGTH_NOT_VALID:
2155 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002156 "Incorrect CDB length %d, unit 0x%016Lx on "
2157 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002158 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002159 (unsigned long long)unit->fcp_lun,
2160 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002161 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2162 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002163 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2164 break;
2165 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002166 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002167 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002168 break;
2169 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002170 zfcp_erp_unit_boxed(unit, "fssfch6", 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_ADAPTER_STATUS_AVAILABLE:
2174 if (header->fsf_status_qual.word[0] ==
2175 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002176 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002177 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2178 break;
2179 }
2180skip_fsfstatus:
2181 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2182 zfcp_fsf_send_fcp_ctm_handler(req);
2183 else {
2184 zfcp_fsf_send_fcp_command_task_handler(req);
2185 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002186 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002187 }
2188}
2189
2190/**
2191 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002192 * @unit: unit where command is sent to
2193 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002194 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002195int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2196 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002197{
2198 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002199 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002200 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002201 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002202 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002203 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002204
2205 if (unlikely(!(atomic_read(&unit->status) &
2206 ZFCP_STATUS_COMMON_UNBLOCKED)))
2207 return -EBUSY;
2208
Swen Schillig564e1c82009-08-18 15:43:19 +02002209 spin_lock(&qdio->req_q_lock);
2210 if (atomic_read(&qdio->req_q.count) <= 0) {
2211 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002212 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002213 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002214
Christof Schmitt1674b402010-04-30 18:09:34 +02002215 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2216 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2217
Swen Schillig564e1c82009-08-18 15:43:19 +02002218 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002219 sbtype, adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002220
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002221 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002222 retval = PTR_ERR(req);
2223 goto out;
2224 }
2225
Swen Schillig09a46c62009-08-18 15:43:16 +02002226 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002227 req->unit = unit;
2228 req->data = scsi_cmnd;
2229 req->handler = zfcp_fsf_send_fcp_command_handler;
2230 req->qtcb->header.lun_handle = unit->handle;
2231 req->qtcb->header.port_handle = unit->port->handle;
2232 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002233 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002234
2235 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2236
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002237 /*
2238 * set depending on data direction:
2239 * data direction bits in SBALE (SB Type)
2240 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002241 */
2242 switch (scsi_cmnd->sc_data_direction) {
2243 case DMA_NONE:
2244 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002245 break;
2246 case DMA_FROM_DEVICE:
2247 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002248 break;
2249 case DMA_TO_DEVICE:
2250 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 break;
2252 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002253 goto failed_scsi_cmnd;
2254 }
2255
Christof Schmitt1674b402010-04-30 18:09:34 +02002256 get_device(&unit->dev);
2257
Christof Schmitt4318e082009-11-24 16:54:08 +01002258 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2259 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002260
Christof Schmitt1674b402010-04-30 18:09:34 +02002261 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002262 scsi_sglist(scsi_cmnd),
Christof Schmitt1674b402010-04-30 18:09:34 +02002263 ZFCP_FSF_MAX_SBALS_PER_REQ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002264 if (unlikely(real_bytes < 0)) {
Christof Schmitt1674b402010-04-30 18:09:34 +02002265 if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002266 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002267 "Oversize data package, unit 0x%016Lx "
2268 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002269 (unsigned long long)unit->fcp_lun,
2270 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002271 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002272 retval = -EINVAL;
2273 }
2274 goto failed_scsi_cmnd;
2275 }
2276
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002277 retval = zfcp_fsf_req_send(req);
2278 if (unlikely(retval))
2279 goto failed_scsi_cmnd;
2280
2281 goto out;
2282
2283failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002284 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002285 zfcp_fsf_req_free(req);
2286 scsi_cmnd->host_scribble = NULL;
2287out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002288 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002289 return retval;
2290}
2291
2292/**
2293 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002294 * @unit: pointer to struct zfcp_unit
2295 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002296 * Returns: on success pointer to struct fsf_req, NULL otherwise
2297 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002298struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002299{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002300 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002301 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002302 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002303
2304 if (unlikely(!(atomic_read(&unit->status) &
2305 ZFCP_STATUS_COMMON_UNBLOCKED)))
2306 return NULL;
2307
Swen Schillig564e1c82009-08-18 15:43:19 +02002308 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002309 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002310 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002311
Swen Schillig564e1c82009-08-18 15:43:19 +02002312 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Christof Schmitt1674b402010-04-30 18:09:34 +02002313 SBAL_FLAGS0_TYPE_WRITE,
Swen Schillig564e1c82009-08-18 15:43:19 +02002314 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002315
Swen Schillig633528c2008-11-26 18:07:37 +01002316 if (IS_ERR(req)) {
2317 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002318 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002319 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002320
2321 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2322 req->data = unit;
2323 req->handler = zfcp_fsf_send_fcp_command_handler;
2324 req->qtcb->header.lun_handle = unit->handle;
2325 req->qtcb->header.port_handle = unit->port->handle;
2326 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2327 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002328 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002329
Christof Schmitt1674b402010-04-30 18:09:34 +02002330 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002331
Christof Schmitt4318e082009-11-24 16:54:08 +01002332 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2333 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002334
2335 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2336 if (!zfcp_fsf_req_send(req))
2337 goto out;
2338
2339 zfcp_fsf_req_free(req);
2340 req = NULL;
2341out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002342 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002343 return req;
2344}
2345
2346static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2347{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002348}
2349
2350/**
2351 * zfcp_fsf_control_file - control file upload/download
2352 * @adapter: pointer to struct zfcp_adapter
2353 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2354 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002356struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2357 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Swen Schillig564e1c82009-08-18 15:43:19 +02002359 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002360 struct zfcp_fsf_req *req = NULL;
2361 struct fsf_qtcb_bottom_support *bottom;
2362 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Christof Schmitt45633fd2008-06-10 18:20:55 +02002364 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2365 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Christof Schmitt45633fd2008-06-10 18:20:55 +02002367 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2369 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2372 direction = SBAL_FLAGS0_TYPE_READ;
2373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002375 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 }
2377
Swen Schillig564e1c82009-08-18 15:43:19 +02002378 spin_lock_bh(&qdio->req_q_lock);
Christof Schmitt6b9e1522010-04-30 18:09:35 +02002379 if (zfcp_qdio_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002380 goto out;
2381
Christof Schmitt1674b402010-04-30 18:09:34 +02002382 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002383 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002385 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 }
2387
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002388 req->handler = zfcp_fsf_control_file_handler;
2389
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002390 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002392 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Christof Schmitt34c2b712010-02-17 11:18:59 +01002394 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Christof Schmitt1674b402010-04-30 18:09:34 +02002395 fsf_cfdc->sg,
2396 ZFCP_FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002397 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002398 zfcp_fsf_req_free(req);
2399 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2403 retval = zfcp_fsf_req_send(req);
2404out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002405 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002406
2407 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002408 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002409 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002411 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002413
2414/**
2415 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2416 * @adapter: pointer to struct zfcp_adapter
2417 * @sbal_idx: response queue index of SBAL to be processed
2418 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002419void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002420{
Swen Schillig564e1c82009-08-18 15:43:19 +02002421 struct zfcp_adapter *adapter = qdio->adapter;
2422 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002423 struct qdio_buffer_element *sbale;
2424 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002425 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002426 int idx;
2427
2428 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2429
2430 sbale = &sbal->element[idx];
2431 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002432 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002433
2434 if (!fsf_req)
2435 /*
2436 * Unknown request means that we have potentially memory
2437 * corruption and must stop the machine immediately.
2438 */
2439 panic("error: unknown req_id (%lx) on adapter %s.\n",
2440 req_id, dev_name(&adapter->ccw_device->dev));
2441
Christof Schmitt34c2b712010-02-17 11:18:59 +01002442 fsf_req->qdio_req.sbal_response = sbal_idx;
2443 fsf_req->qdio_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002444 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002445 zfcp_fsf_req_complete(fsf_req);
2446
2447 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2448 break;
2449 }
2450}