blob: fd2371b69489ba3eece231b10db4e79f4ab80723 [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 Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2002, 2009
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>
Christof Schmitt9d05ce22009-11-24 16:54:09 +010013#include <scsi/fc/fc_els.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "zfcp_ext.h"
Christof Schmitt4318e082009-11-24 16:54:08 +010015#include "zfcp_fc.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020016#include "zfcp_dbf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Christof Schmitt287ac012008-07-02 10:56:40 +020018static void zfcp_fsf_request_timeout_handler(unsigned long data)
19{
20 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010021 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
22 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020023}
24
25static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
26 unsigned long timeout)
27{
28 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
29 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
30 fsf_req->timer.expires = jiffies + timeout;
31 add_timer(&fsf_req->timer);
32}
33
34static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
35{
36 BUG_ON(!fsf_req->erp_action);
37 fsf_req->timer.function = zfcp_erp_timeout_handler;
38 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
39 fsf_req->timer.expires = jiffies + 30 * HZ;
40 add_timer(&fsf_req->timer);
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/* association between FSF command and FSF QTCB type */
44static u32 fsf_qtcb_type[] = {
45 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
46 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
55 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
56 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
58};
59
Christof Schmitt553448f2008-06-10 18:20:58 +020060static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
61{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020062 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020063 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020064 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020065
Christof Schmittff3b24f2008-10-01 12:42:15 +020066 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020067 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 "Access denied according to ACT rule type %s, "
69 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020070}
71
72static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
73 struct zfcp_port *port)
74{
75 struct fsf_qtcb_header *header = &req->qtcb->header;
76 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020077 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020078 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020079 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010081 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020082 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
83}
84
85static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
86 struct zfcp_unit *unit)
87{
88 struct fsf_qtcb_header *header = &req->qtcb->header;
89 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020090 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020091 (unsigned long long)unit->fcp_lun,
92 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020093 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010095 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020096 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
97}
98
99static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
100{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200101 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
102 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100103 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
105}
106
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200107/**
108 * zfcp_fsf_req_free - free memory used by fsf request
109 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200111void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200113 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200114 if (likely(req->qtcb))
115 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200116 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200117 return;
118 }
119
Swen Schilliga4623c42009-08-18 15:43:15 +0200120 if (likely(req->qtcb))
121 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
122 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200125static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Swen Schilligecf0c772009-11-24 16:53:58 +0100127 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200128 struct fsf_status_read_buffer *sr_buf = req->data;
129 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100131 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Swen Schilligecf0c772009-11-24 16:53:58 +0100133 read_lock_irqsave(&adapter->port_list_lock, flags);
134 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200135 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100136 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100137 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200138 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100139 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100142static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200143 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200145 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200147 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
148 return;
149
150 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200151
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100152 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200153
154 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200156
157 switch (link_down->error_code) {
158 case FSF_PSQ_LINK_NO_LIGHT:
159 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200160 "There is no light signal from the local "
161 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200162 break;
163 case FSF_PSQ_LINK_WRAP_PLUG:
164 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200165 "There is a wrap plug instead of a fibre "
166 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200167 break;
168 case FSF_PSQ_LINK_NO_FCP:
169 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200170 "The adjacent fibre channel node does not "
171 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200172 break;
173 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
174 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200175 "The FCP device is suspended because of a "
176 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200177 break;
178 case FSF_PSQ_LINK_INVALID_WWPN:
179 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200180 "The FCP device detected a WWPN that is "
181 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200182 break;
183 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
184 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200185 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200186 break;
187 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
188 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200189 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200190 break;
191 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200193 "The adjacent switch cannot support "
194 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200195 break;
196 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
197 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200198 "The FCP adapter could not log in to the "
199 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200200 break;
201 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
202 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200203 "The WWPN assignment file on the FCP adapter "
204 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200205 break;
206 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
207 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200208 "The mode table on the FCP adapter "
209 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200210 break;
211 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
212 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200213 "All NPIV ports on the FCP adapter have "
214 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200215 break;
216 default:
217 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200218 "The link between the FCP adapter and "
219 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200220 }
221out:
222 zfcp_erp_adapter_failed(adapter, id, req);
223}
224
225static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
226{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200227 struct fsf_status_read_buffer *sr_buf = req->data;
228 struct fsf_link_down_info *ldi =
229 (struct fsf_link_down_info *) &sr_buf->payload;
230
231 switch (sr_buf->status_subtype) {
232 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100233 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200234 break;
235 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100236 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200237 break;
238 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100239 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200240 };
241}
242
243static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
244{
245 struct zfcp_adapter *adapter = req->adapter;
246 struct fsf_status_read_buffer *sr_buf = req->data;
247
248 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200249 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200250 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200251 zfcp_fsf_req_free(req);
252 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
Swen Schillig57717102009-08-18 15:43:21 +0200255 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200256
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200257 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200262 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200267 dev_warn(&adapter->ccw_device->dev,
268 "The error threshold for checksum statistics "
269 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200270 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200273 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200276 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200277 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100279 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 ZFCP_STATUS_COMMON_RUNNING,
281 ZFCP_SET);
282 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200283 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
284 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100285 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100287 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200288 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100289 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
290 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200291 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100292 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100293 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100295 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200297 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200298 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200301
Swen Schilliga4623c42009-08-18 15:43:15 +0200302 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200303 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200304
305 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200306 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200309static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200311 switch (req->qtcb->header.fsf_status_qual.word[0]) {
312 case FSF_SQ_FCP_RSP_AVAILABLE:
313 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
314 case FSF_SQ_NO_RETRY_POSSIBLE:
315 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
316 return;
317 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200318 break;
319 case FSF_SQ_NO_RECOM:
320 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200321 "The FCP adapter reported a problem "
322 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100323 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200324 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 /* all non-return stats set FSFREQ_ERROR*/
327 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
328}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200330static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
331{
332 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
333 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200334
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200335 switch (req->qtcb->header.fsf_status) {
336 case FSF_UNKNOWN_COMMAND:
337 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200338 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200339 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100340 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200341 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200344 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200349static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351 struct zfcp_adapter *adapter = req->adapter;
352 struct fsf_qtcb *qtcb = req->qtcb;
353 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Swen Schillig57717102009-08-18 15:43:21 +0200355 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200357 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100358 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200362 switch (qtcb->prefix.prot_status) {
363 case FSF_PROT_GOOD:
364 case FSF_PROT_FSF_STATUS_PRESENTED:
365 return;
366 case FSF_PROT_QTCB_VERSION_ERROR:
367 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200368 "QTCB version 0x%x not supported by FCP adapter "
369 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
370 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100371 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200373 case FSF_PROT_ERROR_STATE:
374 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100375 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100376 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200378 case FSF_PROT_UNSUPP_QTCB_TYPE:
379 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200380 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100381 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200383 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
384 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
385 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200387 case FSF_PROT_DUPLICATE_REQUEST_ID:
388 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200389 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200390 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100391 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200393 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100394 zfcp_fsf_link_down_info_eval(req, "fspse_5",
395 &psq->link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200396 /* FIXME: reopening adapter now? better wait for link up */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100397 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200399 case FSF_PROT_REEST_QUEUE:
400 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100401 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200402 ZFCP_STATUS_COMMON_RUNNING,
403 ZFCP_SET);
404 zfcp_erp_adapter_reopen(adapter,
405 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100406 ZFCP_STATUS_COMMON_ERP_FAILED,
407 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200408 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200410 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200411 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200412 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100413 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200415 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
418/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200419 * zfcp_fsf_req_complete - process completion of a FSF request
420 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200422 * When a request has been completed either from the FCP adapter,
423 * or it has been dismissed due to a queue shutdown, this function
424 * is called to process the completion status and trigger further
425 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200427static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200428{
429 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
430 zfcp_fsf_status_read_handler(req);
431 return;
432 }
433
434 del_timer(&req->timer);
435 zfcp_fsf_protstatus_eval(req);
436 zfcp_fsf_fsfstatus_eval(req);
437 req->handler(req);
438
439 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200440 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200441
442 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
443 zfcp_fsf_req_free(req);
444 else
Swen Schillig058b8642009-08-18 15:43:14 +0200445 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200446}
447
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200448/**
449 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
450 * @adapter: pointer to struct zfcp_adapter
451 *
452 * Never ever call this without shutting down the adapter first.
453 * Otherwise the adapter would continue using and corrupting s390 storage.
454 * Included BUG_ON() call to ensure this is done.
455 * ERP is supposed to be the only user of this function.
456 */
457void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
458{
459 struct zfcp_fsf_req *req, *tmp;
460 unsigned long flags;
461 LIST_HEAD(remove_queue);
462 unsigned int i;
463
464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
465 spin_lock_irqsave(&adapter->req_list_lock, flags);
466 for (i = 0; i < REQUEST_LIST_SIZE; i++)
467 list_splice_init(&adapter->req_list[i], &remove_queue);
468 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
469
470 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
471 list_del(&req->list);
472 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
473 zfcp_fsf_req_complete(req);
474 }
475}
476
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200477static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100479 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200480 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200481 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100482 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100484 /* adjust pointers for missing command code */
485 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
486 - sizeof(u32));
487 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
488 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200489
490 if (req->data)
491 memcpy(req->data, bottom, sizeof(*bottom));
492
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100493 fc_host_port_name(shost) = nsp->fl_wwpn;
494 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100495 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200496 fc_host_speed(shost) = bottom->fc_link_speed;
497 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
Christof Schmitt0fdd2132009-11-24 16:54:17 +0100498 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
499 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200500
501 adapter->hydra_version = bottom->adapter_type;
502 adapter->timer_ticks = bottom->timer_interval;
503
504 if (fc_host_permanent_port_name(shost) == -1)
505 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
506
507 switch (bottom->fc_topology) {
508 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100509 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100510 adapter->peer_wwpn = plogi->fl_wwpn;
511 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200512 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200513 break;
514 case FSF_TOPO_FABRIC:
515 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 break;
517 case FSF_TOPO_AL:
518 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200519 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200520 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200521 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200522 "Unknown or unsupported arbitrated loop "
523 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100524 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200525 return -EIO;
526 }
527
528 return 0;
529}
530
531static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
532{
533 struct zfcp_adapter *adapter = req->adapter;
534 struct fsf_qtcb *qtcb = req->qtcb;
535 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
536 struct Scsi_Host *shost = adapter->scsi_host;
537
538 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
539 return;
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200542 adapter->adapter_features = bottom->adapter_features;
543 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500544 adapter->peer_wwpn = 0;
545 adapter->peer_wwnn = 0;
546 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200548 switch (qtcb->header.fsf_status) {
549 case FSF_GOOD:
550 if (zfcp_fsf_exchange_config_evaluate(req))
551 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200552
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200553 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
554 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200555 "FCP adapter maximum QTCB size (%d bytes) "
556 "is too small\n",
557 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100558 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200559 return;
560 }
561 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
562 &adapter->status);
563 break;
564 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200565 fc_host_node_name(shost) = 0;
566 fc_host_port_name(shost) = 0;
567 fc_host_port_id(shost) = 0;
568 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100569 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200571
572 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
573 &adapter->status);
574
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100575 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200576 &qtcb->header.fsf_status_qual.link_down_info);
577 break;
578 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100579 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200580 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200583 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200585 memcpy(fc_host_serial_number(shost), bottom->serial_number,
586 min(FC_SERIAL_NUMBER_SIZE, 17));
587 EBCASC(fc_host_serial_number(shost),
588 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200591 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200592 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200593 "The FCP adapter only supports newer "
594 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100595 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200596 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200598 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200599 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200600 "The FCP adapter only supports older "
601 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100602 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200606static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200608 struct zfcp_adapter *adapter = req->adapter;
609 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
610 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200612 if (req->data)
613 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100614
Christof Schmitt02829852009-03-02 13:09:06 +0100615 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100616 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100617 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
618 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100619 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
620 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
621 fc_host_supported_speeds(shost) = bottom->supported_speed;
622}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200624static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200626 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100627
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200628 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return;
630
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200631 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200632 case FSF_GOOD:
633 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200635 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200636 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100637 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200638 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641}
642
Swen Schillig564e1c82009-08-18 15:43:19 +0200643static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200644{
Swen Schillig564e1c82009-08-18 15:43:19 +0200645 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200646
Swen Schillig564e1c82009-08-18 15:43:19 +0200647 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200648 if (atomic_read(&req_q->count))
649 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200650 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200651 return 0;
652}
653
Swen Schillig564e1c82009-08-18 15:43:19 +0200654static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200655{
Swen Schillig564e1c82009-08-18 15:43:19 +0200656 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200658
Swen Schillig564e1c82009-08-18 15:43:19 +0200659 spin_unlock_bh(&qdio->req_q_lock);
660 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
661 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200662 if (ret > 0)
663 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200664 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200665 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200666 /* assume hanging outbound queue, try queue recovery */
667 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
668 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200669
Swen Schillig564e1c82009-08-18 15:43:19 +0200670 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200671 return -EIO;
672}
673
Swen Schilliga4623c42009-08-18 15:43:15 +0200674static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200675{
676 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200677
678 if (likely(pool))
679 req = mempool_alloc(pool, GFP_ATOMIC);
680 else
681 req = kmalloc(sizeof(*req), GFP_ATOMIC);
682
683 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200684 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200685
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200686 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100687 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200688 return req;
689}
690
Swen Schilliga4623c42009-08-18 15:43:15 +0200691static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200692{
Swen Schilliga4623c42009-08-18 15:43:15 +0200693 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200694
695 if (likely(pool))
696 qtcb = mempool_alloc(pool, GFP_ATOMIC);
697 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200698 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
699
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200700 if (unlikely(!qtcb))
701 return NULL;
702
703 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200704 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200705}
706
Swen Schillig564e1c82009-08-18 15:43:19 +0200707static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Swen Schillig09a46c62009-08-18 15:43:16 +0200708 u32 fsf_cmd, mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200710 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +0200711 struct zfcp_qdio_queue *req_q = &qdio->req_q;
712 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200713 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200714
715 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200716 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200717
718 if (adapter->req_no == 0)
719 adapter->req_no++;
720
721 INIT_LIST_HEAD(&req->list);
722 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200723 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200724
725 req->adapter = adapter;
726 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100727 req->req_id = adapter->req_no;
Swen Schillig42428f72009-08-18 15:43:18 +0200728 req->queue_req.sbal_number = 1;
729 req->queue_req.sbal_first = req_q->first;
730 req->queue_req.sbal_last = req_q->first;
731 req->queue_req.sbale_curr = 1;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200732
Swen Schillig564e1c82009-08-18 15:43:19 +0200733 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200734 sbale[0].addr = (void *) req->req_id;
735 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
736
Swen Schilliga4623c42009-08-18 15:43:15 +0200737 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
738 if (likely(pool))
739 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
740 else
741 req->qtcb = zfcp_qtcb_alloc(NULL);
742
743 if (unlikely(!req->qtcb)) {
744 zfcp_fsf_req_free(req);
745 return ERR_PTR(-ENOMEM);
746 }
747
Swen Schillig564e1c82009-08-18 15:43:19 +0200748 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200749 req->qtcb->prefix.req_id = req->req_id;
750 req->qtcb->prefix.ulp_info = 26;
751 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
752 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
753 req->qtcb->header.req_handle = req->req_id;
754 req->qtcb->header.fsf_command = req->fsf_command;
755 req->seq_no = adapter->fsf_req_seq_no;
756 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
757 sbale[1].addr = (void *) req->qtcb;
758 sbale[1].length = sizeof(struct fsf_qtcb);
759 }
760
761 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
762 zfcp_fsf_req_free(req);
763 return ERR_PTR(-EIO);
764 }
765
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200766 return req;
767}
768
769static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
770{
771 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200772 struct zfcp_qdio *qdio = adapter->qdio;
Martin Petermann135ea132009-04-17 15:08:01 +0200773 unsigned long flags;
774 int idx;
775 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100776 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777
778 /* put allocated FSF request into hash table */
Heiko Carstens45316a82008-11-04 16:35:06 +0100779 spin_lock_irqsave(&adapter->req_list_lock, flags);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100780 idx = zfcp_reqlist_hash(req_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200781 list_add_tail(&req->list, &adapter->req_list[idx]);
Heiko Carstens45316a82008-11-04 16:35:06 +0100782 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783
Swen Schillig564e1c82009-08-18 15:43:19 +0200784 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200785 req->issued = get_clock();
Swen Schillig564e1c82009-08-18 15:43:19 +0200786 if (zfcp_qdio_send(qdio, &req->queue_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200787 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100788 spin_lock_irqsave(&adapter->req_list_lock, flags);
789 /* lookup request again, list might have changed */
Christof Schmitte60a6d62010-02-17 11:18:49 +0100790 req = zfcp_reqlist_find(adapter, req_id);
791 if (req)
Christof Schmitt37651382008-11-04 16:35:08 +0100792 zfcp_reqlist_remove(adapter, req);
793 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100794 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200795 return -EIO;
796 }
797
798 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200799 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200800 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100801 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200802
803 return 0;
804}
805
806/**
807 * zfcp_fsf_status_read - send status read request
808 * @adapter: pointer to struct zfcp_adapter
809 * @req_flags: request flags
810 * Returns: 0 on success, ERROR otherwise
811 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200812int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200813{
Swen Schillig564e1c82009-08-18 15:43:19 +0200814 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200815 struct zfcp_fsf_req *req;
816 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200817 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200818 int retval = -EIO;
819
Swen Schillig564e1c82009-08-18 15:43:19 +0200820 spin_lock_bh(&qdio->req_q_lock);
821 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Swen Schillig564e1c82009-08-18 15:43:19 +0200824 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200825 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200826 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200827 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 goto out;
829 }
830
Swen Schillig564e1c82009-08-18 15:43:19 +0200831 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200832 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
Swen Schillig42428f72009-08-18 15:43:18 +0200833 req->queue_req.sbale_curr = 2;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200834
Swen Schilliga4623c42009-08-18 15:43:15 +0200835 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200836 if (!sr_buf) {
837 retval = -ENOMEM;
838 goto failed_buf;
839 }
840 memset(sr_buf, 0, sizeof(*sr_buf));
841 req->data = sr_buf;
Swen Schillig564e1c82009-08-18 15:43:19 +0200842 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200843 sbale->addr = (void *) sr_buf;
844 sbale->length = sizeof(*sr_buf);
845
846 retval = zfcp_fsf_req_send(req);
847 if (retval)
848 goto failed_req_send;
849
850 goto out;
851
852failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200853 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200854failed_buf:
855 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200856 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200857out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200858 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 return retval;
860}
861
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200862static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200864 struct zfcp_unit *unit = req->data;
865 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200867 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
868 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200870 switch (req->qtcb->header.fsf_status) {
871 case FSF_PORT_HANDLE_NOT_VALID:
872 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100873 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
874 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 case FSF_LUN_HANDLE_NOT_VALID:
879 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100880 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200881 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
885 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200887 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100888 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100889 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200890 break;
891 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100892 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100893 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200896 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200898 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200899 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200901 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 break;
903 }
904 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200906 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
907 break;
908 }
909}
910
911/**
912 * zfcp_fsf_abort_fcp_command - abort running SCSI command
913 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200914 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200915 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200916 */
917
918struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100919 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200921 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200922 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200923 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200924
Swen Schillig564e1c82009-08-18 15:43:19 +0200925 spin_lock_bh(&qdio->req_q_lock);
926 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200927 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200928 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
929 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100930 if (IS_ERR(req)) {
931 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200932 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100933 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200934
935 if (unlikely(!(atomic_read(&unit->status) &
936 ZFCP_STATUS_COMMON_UNBLOCKED)))
937 goto out_error_free;
938
Swen Schillig564e1c82009-08-18 15:43:19 +0200939 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200940 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
941 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
942
943 req->data = unit;
944 req->handler = zfcp_fsf_abort_fcp_command_handler;
945 req->qtcb->header.lun_handle = unit->handle;
946 req->qtcb->header.port_handle = unit->port->handle;
947 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
948
949 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
950 if (!zfcp_fsf_req_send(req))
951 goto out;
952
953out_error_free:
954 zfcp_fsf_req_free(req);
955 req = NULL;
956out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200957 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200958 return req;
959}
960
961static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
962{
963 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100964 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200965 struct fsf_qtcb_header *header = &req->qtcb->header;
966
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100967 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200968
969 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
970 goto skip_fsfstatus;
971
972 switch (header->fsf_status) {
973 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200974 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100975 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200976 break;
977 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
978 zfcp_fsf_class_not_supp(req);
979 break;
980 case FSF_ADAPTER_STATUS_AVAILABLE:
981 switch (header->fsf_status_qual.word[0]){
982 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200983 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
984 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
985 break;
986 }
987 break;
988 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200989 break;
990 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100991 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200992 break;
993 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100994 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200995 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200996 case FSF_GENERIC_COMMAND_REJECTED:
997 case FSF_PAYLOAD_SIZE_MISMATCH:
998 case FSF_REQUEST_SIZE_TOO_LARGE:
999 case FSF_RESPONSE_SIZE_TOO_LARGE:
1000 case FSF_SBAL_MISMATCH:
1001 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1002 break;
1003 }
1004
1005skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001006 if (ct->handler)
1007 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001008}
1009
Christof Schmitt426f6052009-07-13 15:06:06 +02001010static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
1011 struct scatterlist *sg_req,
1012 struct scatterlist *sg_resp)
1013{
1014 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1015 sbale[2].addr = sg_virt(sg_req);
1016 sbale[2].length = sg_req->length;
1017 sbale[3].addr = sg_virt(sg_resp);
1018 sbale[3].length = sg_resp->length;
1019 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1020}
1021
1022static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1023{
1024 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1025}
1026
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001027static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1028 struct scatterlist *sg_req,
1029 struct scatterlist *sg_resp,
1030 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001031{
Swen Schillig42428f72009-08-18 15:43:18 +02001032 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001033 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
Swen Schillig42428f72009-08-18 15:43:18 +02001034 &req->queue_req);
1035 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001036 int bytes;
1037
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001038 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001039 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001040 return -EOPNOTSUPP;
1041
Christof Schmitt426f6052009-07-13 15:06:06 +02001042 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1043 return 0;
1044 }
1045
1046 /* use single, unchained SBAL if it can hold the request */
1047 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1048 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001049 return 0;
1050 }
1051
Swen Schillig564e1c82009-08-18 15:43:19 +02001052 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001053 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001054 sg_req, max_sbals);
1055 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001056 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001057 req->qtcb->bottom.support.req_buf_length = bytes;
Swen Schillig42428f72009-08-18 15:43:18 +02001058 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001059
Swen Schillig564e1c82009-08-18 15:43:19 +02001060 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001061 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001062 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +02001063 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001064 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001065 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001066
Christof Schmittb1a58982009-09-24 10:23:21 +02001067 return 0;
1068}
1069
1070static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1071 struct scatterlist *sg_req,
1072 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001073 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001074{
1075 int ret;
1076
1077 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1078 if (ret)
1079 return ret;
1080
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001081 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001082 if (timeout > 255)
1083 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001084 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001085 req->qtcb->bottom.support.timeout = timeout;
1086 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087
1088 return 0;
1089}
1090
1091/**
1092 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1093 * @ct: pointer to struct zfcp_send_ct with data for request
1094 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001095 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001096int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001097 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1098 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001099{
Swen Schillig564e1c82009-08-18 15:43:19 +02001100 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001101 struct zfcp_fsf_req *req;
1102 int ret = -EIO;
1103
Swen Schillig564e1c82009-08-18 15:43:19 +02001104 spin_lock_bh(&qdio->req_q_lock);
1105 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001106 goto out;
1107
Swen Schillig564e1c82009-08-18 15:43:19 +02001108 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001109
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001110 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001111 ret = PTR_ERR(req);
1112 goto out;
1113 }
1114
Swen Schillig09a46c62009-08-18 15:43:16 +02001115 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001116 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001117 FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001118 if (ret)
1119 goto failed_send;
1120
1121 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001122 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001123 req->data = ct;
1124
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001125 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001126
1127 ret = zfcp_fsf_req_send(req);
1128 if (ret)
1129 goto failed_send;
1130
1131 goto out;
1132
1133failed_send:
1134 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001135out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001136 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001137 return ret;
1138}
1139
1140static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1141{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001142 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001143 struct zfcp_port *port = send_els->port;
1144 struct fsf_qtcb_header *header = &req->qtcb->header;
1145
1146 send_els->status = -EINVAL;
1147
1148 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1149 goto skip_fsfstatus;
1150
1151 switch (header->fsf_status) {
1152 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001153 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001154 send_els->status = 0;
1155 break;
1156 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1157 zfcp_fsf_class_not_supp(req);
1158 break;
1159 case FSF_ADAPTER_STATUS_AVAILABLE:
1160 switch (header->fsf_status_qual.word[0]){
1161 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001162 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1163 case FSF_SQ_RETRY_IF_POSSIBLE:
1164 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1165 break;
1166 }
1167 break;
1168 case FSF_ELS_COMMAND_REJECTED:
1169 case FSF_PAYLOAD_SIZE_MISMATCH:
1170 case FSF_REQUEST_SIZE_TOO_LARGE:
1171 case FSF_RESPONSE_SIZE_TOO_LARGE:
1172 break;
1173 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001174 if (port)
1175 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001176 break;
1177 case FSF_SBAL_MISMATCH:
1178 /* should never occure, avoided in zfcp_fsf_send_els */
1179 /* fall through */
1180 default:
1181 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1182 break;
1183 }
1184skip_fsfstatus:
1185 if (send_els->handler)
1186 send_els->handler(send_els->handler_data);
1187}
1188
1189/**
1190 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1191 * @els: pointer to struct zfcp_send_els with data for the command
1192 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001193int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001194 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195{
1196 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001197 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001198 int ret = -EIO;
1199
Swen Schillig564e1c82009-08-18 15:43:19 +02001200 spin_lock_bh(&qdio->req_q_lock);
1201 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001203
Swen Schillig564e1c82009-08-18 15:43:19 +02001204 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001205
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001206 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001207 ret = PTR_ERR(req);
1208 goto out;
1209 }
1210
Swen Schillig09a46c62009-08-18 15:43:16 +02001211 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001212 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001213
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001214 if (ret)
1215 goto failed_send;
1216
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001217 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001218 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001219 req->data = els;
1220
Swen Schillig57717102009-08-18 15:43:21 +02001221 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001222
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001223 ret = zfcp_fsf_req_send(req);
1224 if (ret)
1225 goto failed_send;
1226
1227 goto out;
1228
1229failed_send:
1230 zfcp_fsf_req_free(req);
1231out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001232 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001233 return ret;
1234}
1235
1236int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1237{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001238 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001239 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001240 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001241 int retval = -EIO;
1242
Swen Schillig564e1c82009-08-18 15:43:19 +02001243 spin_lock_bh(&qdio->req_q_lock);
1244 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001246
Swen Schillig564e1c82009-08-18 15:43:19 +02001247 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1248 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001249
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001250 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001251 retval = PTR_ERR(req);
1252 goto out;
1253 }
1254
Swen Schillig09a46c62009-08-18 15:43:16 +02001255 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001256 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001257 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1258 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1259
1260 req->qtcb->bottom.config.feature_selection =
1261 FSF_FEATURE_CFDC |
1262 FSF_FEATURE_LUN_SHARING |
1263 FSF_FEATURE_NOTIFICATION_LOST |
1264 FSF_FEATURE_UPDATE_ALERT;
1265 req->erp_action = erp_action;
1266 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001267 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001268
Christof Schmitt287ac012008-07-02 10:56:40 +02001269 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001270 retval = zfcp_fsf_req_send(req);
1271 if (retval) {
1272 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001273 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001274 }
1275out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001276 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001277 return retval;
1278}
1279
Swen Schillig564e1c82009-08-18 15:43:19 +02001280int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001281 struct fsf_qtcb_bottom_config *data)
1282{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001283 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284 struct zfcp_fsf_req *req = NULL;
1285 int retval = -EIO;
1286
Swen Schillig564e1c82009-08-18 15:43:19 +02001287 spin_lock_bh(&qdio->req_q_lock);
1288 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001289 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001290
Swen Schillig564e1c82009-08-18 15:43:19 +02001291 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001292
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001293 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001294 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001295 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001296 }
1297
Swen Schillig564e1c82009-08-18 15:43:19 +02001298 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001299 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1300 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1301 req->handler = zfcp_fsf_exchange_config_data_handler;
1302
1303 req->qtcb->bottom.config.feature_selection =
1304 FSF_FEATURE_CFDC |
1305 FSF_FEATURE_LUN_SHARING |
1306 FSF_FEATURE_NOTIFICATION_LOST |
1307 FSF_FEATURE_UPDATE_ALERT;
1308
1309 if (data)
1310 req->data = data;
1311
1312 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1313 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001314 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001315 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001316 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001317
1318 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001319 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001320
Christof Schmittada81b72009-04-17 15:08:03 +02001321out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001322 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 return retval;
1324}
1325
1326/**
1327 * zfcp_fsf_exchange_port_data - request information about local port
1328 * @erp_action: ERP action for the adapter for which port data is requested
1329 * Returns: 0 on success, error otherwise
1330 */
1331int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1332{
Swen Schillig564e1c82009-08-18 15:43:19 +02001333 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schillig44cc76f2008-10-01 12:42:16 +02001334 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001335 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001336 int retval = -EIO;
1337
Swen Schillig564e1c82009-08-18 15:43:19 +02001338 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001339 return -EOPNOTSUPP;
1340
Swen Schillig564e1c82009-08-18 15:43:19 +02001341 spin_lock_bh(&qdio->req_q_lock);
1342 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001343 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001344
Swen Schillig564e1c82009-08-18 15:43:19 +02001345 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1346 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001347
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001348 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001349 retval = PTR_ERR(req);
1350 goto out;
1351 }
1352
Swen Schillig09a46c62009-08-18 15:43:16 +02001353 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001354 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1356 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1357
1358 req->handler = zfcp_fsf_exchange_port_data_handler;
1359 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001360 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001361
Christof Schmitt287ac012008-07-02 10:56:40 +02001362 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001363 retval = zfcp_fsf_req_send(req);
1364 if (retval) {
1365 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001366 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001367 }
1368out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001369 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001370 return retval;
1371}
1372
1373/**
1374 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001375 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001376 * @data: pointer to struct fsf_qtcb_bottom_port
1377 * Returns: 0 on success, error otherwise
1378 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001379int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380 struct fsf_qtcb_bottom_port *data)
1381{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001382 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001383 struct zfcp_fsf_req *req = NULL;
1384 int retval = -EIO;
1385
Swen Schillig564e1c82009-08-18 15:43:19 +02001386 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001387 return -EOPNOTSUPP;
1388
Swen Schillig564e1c82009-08-18 15:43:19 +02001389 spin_lock_bh(&qdio->req_q_lock);
1390 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001391 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392
Swen Schillig564e1c82009-08-18 15:43:19 +02001393 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001394
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001395 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001396 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001397 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001398 }
1399
1400 if (data)
1401 req->data = data;
1402
Swen Schillig564e1c82009-08-18 15:43:19 +02001403 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001404 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1405 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1406
1407 req->handler = zfcp_fsf_exchange_port_data_handler;
1408 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1409 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001410 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001411
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001412 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001413 wait_for_completion(&req->completion);
1414
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001415 zfcp_fsf_req_free(req);
1416
1417 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001418
1419out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001420 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001421 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001422}
1423
1424static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1425{
1426 struct zfcp_port *port = req->data;
1427 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001428 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001429
1430 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001431 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001432
1433 switch (header->fsf_status) {
1434 case FSF_PORT_ALREADY_OPEN:
1435 break;
1436 case FSF_ACCESS_DENIED:
1437 zfcp_fsf_access_denied_port(req, port);
1438 break;
1439 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1440 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001441 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001442 "remote port 0x%016Lx\n",
1443 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001444 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001445 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1446 break;
1447 case FSF_ADAPTER_STATUS_AVAILABLE:
1448 switch (header->fsf_status_qual.word[0]) {
1449 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1450 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001451 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001452 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 break;
1454 }
1455 break;
1456 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1459 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001460 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1461 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1462 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* check whether D_ID has changed during open */
1464 /*
1465 * FIXME: This check is not airtight, as the FCP channel does
1466 * not monitor closures of target port connections caused on
1467 * the remote side. Thus, they might miss out on invalidating
1468 * locally cached WWPNs (and other N_Port parameters) of gone
1469 * target ports. So, our heroic attempt to make things safe
1470 * could be undermined by 'open port' response data tagged with
1471 * obsolete WWPNs. Another reason to monitor potential
1472 * connection closures ourself at least (by interpreting
1473 * incoming ELS' and unsolicited status). It just crosses my
1474 * mind that one should be able to cross-check by means of
1475 * another GID_PN straight after a port has been opened.
1476 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1477 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001478 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +01001479 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001480 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001481 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001484 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 break;
1486 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001487
1488out:
Swen Schilligf3450c72009-11-24 16:53:59 +01001489 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001492/**
1493 * zfcp_fsf_open_port - create and send open port request
1494 * @erp_action: pointer to struct zfcp_erp_action
1495 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001497int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001499 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001500 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001501 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001502 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001503 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Swen Schillig564e1c82009-08-18 15:43:19 +02001505 spin_lock_bh(&qdio->req_q_lock);
1506 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Swen Schillig564e1c82009-08-18 15:43:19 +02001509 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1510 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001511
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001512 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001513 retval = PTR_ERR(req);
1514 goto out;
1515 }
1516
Swen Schillig09a46c62009-08-18 15:43:16 +02001517 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001518 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1520 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1521
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001522 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001523 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001524 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001525 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001526 erp_action->fsf_req_id = req->req_id;
Swen Schilligf3450c72009-11-24 16:53:59 +01001527 get_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Christof Schmitt287ac012008-07-02 10:56:40 +02001529 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001530 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001532 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001533 erp_action->fsf_req_id = 0;
Swen Schilligf3450c72009-11-24 16:53:59 +01001534 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001536out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001537 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 return retval;
1539}
1540
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001541static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001543 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001545 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001546 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001548 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001550 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001551 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001556 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 ZFCP_STATUS_COMMON_OPEN,
1558 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001563/**
1564 * zfcp_fsf_close_port - create and send close port request
1565 * @erp_action: pointer to struct zfcp_erp_action
1566 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001568int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001570 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001571 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001572 struct zfcp_fsf_req *req;
1573 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Swen Schillig564e1c82009-08-18 15:43:19 +02001575 spin_lock_bh(&qdio->req_q_lock);
1576 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Swen Schillig564e1c82009-08-18 15:43:19 +02001579 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1580 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001581
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001582 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001583 retval = PTR_ERR(req);
1584 goto out;
1585 }
1586
Swen Schillig09a46c62009-08-18 15:43:16 +02001587 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001588 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1590 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1591
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001592 req->handler = zfcp_fsf_close_port_handler;
1593 req->data = erp_action->port;
1594 req->erp_action = erp_action;
1595 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001596 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Christof Schmitt287ac012008-07-02 10:56:40 +02001598 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001599 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001601 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001602 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001604out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001605 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 return retval;
1607}
1608
Swen Schillig5ab944f2008-10-01 12:42:17 +02001609static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1610{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001611 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001612 struct fsf_qtcb_header *header = &req->qtcb->header;
1613
1614 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001615 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 goto out;
1617 }
1618
1619 switch (header->fsf_status) {
1620 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1621 dev_warn(&req->adapter->ccw_device->dev,
1622 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001623 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001624 case FSF_ADAPTER_STATUS_AVAILABLE:
1625 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001626 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001627 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001628 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001629 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001630 case FSF_GOOD:
1631 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001632 /* fall through */
1633 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001634 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001635 }
1636out:
1637 wake_up(&wka_port->completion_wq);
1638}
1639
1640/**
1641 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001642 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001643 * Returns: 0 on success, error otherwise
1644 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001645int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001646{
1647 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001648 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001649 struct zfcp_fsf_req *req;
1650 int retval = -EIO;
1651
Swen Schillig564e1c82009-08-18 15:43:19 +02001652 spin_lock_bh(&qdio->req_q_lock);
1653 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001654 goto out;
1655
Swen Schillig564e1c82009-08-18 15:43:19 +02001656 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1657 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001658
Swen Schillig5ab944f2008-10-01 12:42:17 +02001659 if (unlikely(IS_ERR(req))) {
1660 retval = PTR_ERR(req);
1661 goto out;
1662 }
1663
Swen Schillig09a46c62009-08-18 15:43:16 +02001664 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001665 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001666 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1667 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1668
1669 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001670 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001671 req->data = wka_port;
1672
1673 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1674 retval = zfcp_fsf_req_send(req);
1675 if (retval)
1676 zfcp_fsf_req_free(req);
1677out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001678 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001679 return retval;
1680}
1681
1682static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1683{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001684 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001685
1686 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1687 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001688 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001689 }
1690
Christof Schmittbd0072e2009-11-24 16:54:11 +01001691 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001692 wake_up(&wka_port->completion_wq);
1693}
1694
1695/**
1696 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001697 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001698 * Returns: 0 on success, error otherwise
1699 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001700int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001701{
1702 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001703 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001704 struct zfcp_fsf_req *req;
1705 int retval = -EIO;
1706
Swen Schillig564e1c82009-08-18 15:43:19 +02001707 spin_lock_bh(&qdio->req_q_lock);
1708 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001709 goto out;
1710
Swen Schillig564e1c82009-08-18 15:43:19 +02001711 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1712 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001713
Swen Schillig5ab944f2008-10-01 12:42:17 +02001714 if (unlikely(IS_ERR(req))) {
1715 retval = PTR_ERR(req);
1716 goto out;
1717 }
1718
Swen Schillig09a46c62009-08-18 15:43:16 +02001719 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001720 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001721 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1722 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1723
1724 req->handler = zfcp_fsf_close_wka_port_handler;
1725 req->data = wka_port;
1726 req->qtcb->header.port_handle = wka_port->handle;
1727
1728 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1729 retval = zfcp_fsf_req_send(req);
1730 if (retval)
1731 zfcp_fsf_req_free(req);
1732out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001733 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001734 return retval;
1735}
1736
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001739 struct zfcp_port *port = req->data;
1740 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001743 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001744 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001748 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001749 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001752 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001755 /* can't use generic zfcp_erp_modify_port_status because
1756 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1757 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001758 read_lock(&port->unit_list_lock);
1759 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001760 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1761 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001762 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001763 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001764 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 switch (header->fsf_status_qual.word[0]) {
1768 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001769 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001771 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
1774 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 /* can't use generic zfcp_erp_modify_port_status because
1777 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1778 */
1779 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001780 read_lock(&port->unit_list_lock);
1781 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001782 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1783 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001784 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001789/**
1790 * zfcp_fsf_close_physical_port - close physical port
1791 * @erp_action: pointer to struct zfcp_erp_action
1792 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001794int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001796 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001797 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001798 struct zfcp_fsf_req *req;
1799 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Swen Schillig564e1c82009-08-18 15:43:19 +02001801 spin_lock_bh(&qdio->req_q_lock);
1802 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Swen Schillig564e1c82009-08-18 15:43:19 +02001805 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1806 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001807
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001808 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001809 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 goto out;
1811 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001812
Swen Schillig09a46c62009-08-18 15:43:16 +02001813 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001814 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001815 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1816 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1817
1818 req->data = erp_action->port;
1819 req->qtcb->header.port_handle = erp_action->port->handle;
1820 req->erp_action = erp_action;
1821 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001822 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823
Christof Schmitt287ac012008-07-02 10:56:40 +02001824 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001825 retval = zfcp_fsf_req_send(req);
1826 if (retval) {
1827 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001828 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001829 }
1830out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001831 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 return retval;
1833}
1834
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001835static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001837 struct zfcp_adapter *adapter = req->adapter;
1838 struct zfcp_unit *unit = req->data;
1839 struct fsf_qtcb_header *header = &req->qtcb->header;
1840 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1841 struct fsf_queue_designator *queue_designator =
1842 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001843 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001845 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001846 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001849 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 ZFCP_STATUS_UNIT_SHARED |
1851 ZFCP_STATUS_UNIT_READONLY,
1852 &unit->status);
1853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 switch (header->fsf_status) {
1855
1856 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001857 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001858 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001862 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001864 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001867 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001868 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001871 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001872 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001873 "LUN 0x%Lx on port 0x%Lx is already in "
1874 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001875 (unsigned long long)unit->fcp_lun,
1876 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001877 queue_designator->cssid,
1878 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001879 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001880 zfcp_act_eval_err(adapter,
1881 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001882 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1884 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001885 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001888 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001889 "No handle is available for LUN "
1890 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001891 (unsigned long long)unit->fcp_lun,
1892 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001893 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001894 /* fall through */
1895 case FSF_INVALID_COMMAND_OPTION:
1896 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 switch (header->fsf_status_qual.word[0]) {
1900 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001901 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001902 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001904 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 }
1907 break;
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001912
1913 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1914 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001915 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001916 exclusive = (bottom->lun_access_info &
1917 FSF_UNIT_ACCESS_EXCLUSIVE);
1918 readwrite = (bottom->lun_access_info &
1919 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1920
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 if (!exclusive)
1922 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1923 &unit->status);
1924
1925 if (!readwrite) {
1926 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1927 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001928 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001929 "SCSI device at LUN 0x%016Lx on port "
1930 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001931 (unsigned long long)unit->fcp_lun,
1932 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
1934
1935 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001936 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001937 "Exclusive read-only access not "
1938 "supported (unit 0x%016Lx, "
1939 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001940 (unsigned long long)unit->fcp_lun,
1941 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001942 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001943 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001944 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001946 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001947 "Shared read-write access not "
1948 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001949 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001950 (unsigned long long)unit->fcp_lun,
1951 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001952 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001953 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001954 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 }
1956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959}
1960
1961/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001962 * zfcp_fsf_open_unit - open unit
1963 * @erp_action: pointer to struct zfcp_erp_action
1964 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001966int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001968 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001969 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001970 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001971 struct zfcp_fsf_req *req;
1972 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Swen Schillig564e1c82009-08-18 15:43:19 +02001974 spin_lock_bh(&qdio->req_q_lock);
1975 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Swen Schillig564e1c82009-08-18 15:43:19 +02001978 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Swen Schilliga4623c42009-08-18 15:43:15 +02001979 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;
Christof Schmittba172422007-12-20 12:30:26 +01001984 }
1985
Swen Schillig09a46c62009-08-18 15:43:16 +02001986 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02001987 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001988 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1989 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001991 req->qtcb->header.port_handle = erp_action->port->handle;
1992 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1993 req->handler = zfcp_fsf_open_unit_handler;
1994 req->data = erp_action->unit;
1995 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001996 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001997
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001998 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1999 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Christof Schmitt287ac012008-07-02 10:56:40 +02002001 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002002 retval = zfcp_fsf_req_send(req);
2003 if (retval) {
2004 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002005 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002007out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002008 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 return retval;
2010}
2011
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002012static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002014 struct zfcp_unit *unit = req->data;
2015
2016 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02002017 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002018
2019 switch (req->qtcb->header.fsf_status) {
2020 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002021 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002022 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2023 break;
2024 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002025 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002026 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2027 break;
2028 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002029 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002030 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002031 break;
2032 case FSF_ADAPTER_STATUS_AVAILABLE:
2033 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2034 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002035 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002036 /* fall through */
2037 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2038 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2039 break;
2040 }
2041 break;
2042 case FSF_GOOD:
2043 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2044 break;
2045 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002046}
2047
2048/**
2049 * zfcp_fsf_close_unit - close zfcp unit
2050 * @erp_action: pointer to struct zfcp_unit
2051 * Returns: 0 on success, error otherwise
2052 */
2053int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2054{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002055 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002056 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002057 struct zfcp_fsf_req *req;
2058 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Swen Schillig564e1c82009-08-18 15:43:19 +02002060 spin_lock_bh(&qdio->req_q_lock);
2061 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002063
Swen Schillig564e1c82009-08-18 15:43:19 +02002064 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2065 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002066
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002067 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002068 retval = PTR_ERR(req);
2069 goto out;
2070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Swen Schillig09a46c62009-08-18 15:43:16 +02002072 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig564e1c82009-08-18 15:43:19 +02002073 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002074 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2076
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002077 req->qtcb->header.port_handle = erp_action->port->handle;
2078 req->qtcb->header.lun_handle = erp_action->unit->handle;
2079 req->handler = zfcp_fsf_close_unit_handler;
2080 req->data = erp_action->unit;
2081 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002082 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Christof Schmitt287ac012008-07-02 10:56:40 +02002084 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002085 retval = zfcp_fsf_req_send(req);
2086 if (retval) {
2087 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002088 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002089 }
2090out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002091 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002092 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093}
2094
Christof Schmittc9615852008-05-06 11:00:05 +02002095static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2096{
2097 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002098 lat_rec->min = min(lat_rec->min, lat);
2099 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002100}
2101
Christof Schmittd9742b42009-11-24 16:54:03 +01002102static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002103{
Christof Schmittd9742b42009-11-24 16:54:03 +01002104 struct fsf_qual_latency_info *lat_in;
2105 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002106 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002107 struct zfcp_blk_drv_data blktrc;
2108 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002109
Christof Schmittd9742b42009-11-24 16:54:03 +01002110 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002111
Christof Schmittd9742b42009-11-24 16:54:03 +01002112 blktrc.flags = 0;
2113 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2114 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2115 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2116 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2117 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2118
2119 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2120 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2121 blktrc.channel_lat = lat_in->channel_lat * ticks;
2122 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2123
2124 switch (req->qtcb->bottom.io.data_direction) {
2125 case FSF_DATADIR_READ:
2126 lat = &unit->latencies.read;
2127 break;
2128 case FSF_DATADIR_WRITE:
2129 lat = &unit->latencies.write;
2130 break;
2131 case FSF_DATADIR_CMND:
2132 lat = &unit->latencies.cmd;
2133 break;
2134 }
2135
2136 if (lat) {
2137 spin_lock(&unit->latencies.lock);
2138 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2139 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2140 lat->counter++;
2141 spin_unlock(&unit->latencies.lock);
2142 }
Christof Schmittc9615852008-05-06 11:00:05 +02002143 }
2144
Christof Schmittd9742b42009-11-24 16:54:03 +01002145 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2146 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002147}
2148
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002149static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002151 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002152 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002155 read_lock_irqsave(&req->adapter->abort_lock, flags);
2156
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002157 scpnt = req->data;
2158 if (unlikely(!scpnt)) {
2159 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2160 return;
2161 }
2162
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002163 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002164 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 goto skip_fsfstatus;
2166 }
2167
Christof Schmitt4318e082009-11-24 16:54:08 +01002168 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2169 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Christof Schmittd9742b42009-11-24 16:54:03 +01002171 zfcp_fsf_req_trace(req, scpnt);
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002172
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002173skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002174 if (scpnt->result != 0)
Swen Schillig57717102009-08-18 15:43:21 +02002175 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002176 else if (scpnt->retries > 0)
Swen Schillig57717102009-08-18 15:43:21 +02002177 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02002178 else
Swen Schillig57717102009-08-18 15:43:21 +02002179 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 /*
2184 * We must hold this lock until scsi_done has been called.
2185 * Otherwise we may call scsi_done after abort regarding this
2186 * command has completed.
2187 * Note: scsi_done must not block!
2188 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002189 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002192static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Christof Schmitt4318e082009-11-24 16:54:08 +01002194 struct fcp_resp_with_ext *fcp_rsp;
2195 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Christof Schmitt4318e082009-11-24 16:54:08 +01002197 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2198 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2199
2200 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002201 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2202 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203}
2204
2205
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002206static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2207{
2208 struct zfcp_unit *unit;
2209 struct fsf_qtcb_header *header = &req->qtcb->header;
2210
2211 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2212 unit = req->data;
2213 else
2214 unit = req->unit;
2215
2216 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2217 goto skip_fsfstatus;
2218
2219 switch (header->fsf_status) {
2220 case FSF_HANDLE_MISMATCH:
2221 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002222 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002223 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2224 break;
2225 case FSF_FCPLUN_NOT_VALID:
2226 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002227 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2229 break;
2230 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2231 zfcp_fsf_class_not_supp(req);
2232 break;
2233 case FSF_ACCESS_DENIED:
2234 zfcp_fsf_access_denied_unit(req, unit);
2235 break;
2236 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2237 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002238 "Incorrect direction %d, unit 0x%016Lx on port "
2239 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002240 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002241 (unsigned long long)unit->fcp_lun,
2242 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002243 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2244 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002245 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2246 break;
2247 case FSF_CMND_LENGTH_NOT_VALID:
2248 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002249 "Incorrect CDB length %d, unit 0x%016Lx on "
2250 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002251 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002252 (unsigned long long)unit->fcp_lun,
2253 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002254 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2255 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002256 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2257 break;
2258 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002259 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002260 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002261 break;
2262 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002263 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002264 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002265 break;
2266 case FSF_ADAPTER_STATUS_AVAILABLE:
2267 if (header->fsf_status_qual.word[0] ==
2268 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002269 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002270 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2271 break;
2272 }
2273skip_fsfstatus:
2274 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2275 zfcp_fsf_send_fcp_ctm_handler(req);
2276 else {
2277 zfcp_fsf_send_fcp_command_task_handler(req);
2278 req->unit = NULL;
Swen Schilligf3450c72009-11-24 16:53:59 +01002279 put_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002280 }
2281}
2282
2283/**
2284 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002285 * @unit: unit where command is sent to
2286 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002287 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002288int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2289 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002290{
2291 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002292 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002293 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002294 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002295 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002296 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002297
2298 if (unlikely(!(atomic_read(&unit->status) &
2299 ZFCP_STATUS_COMMON_UNBLOCKED)))
2300 return -EBUSY;
2301
Swen Schillig564e1c82009-08-18 15:43:19 +02002302 spin_lock(&qdio->req_q_lock);
2303 if (atomic_read(&qdio->req_q.count) <= 0) {
2304 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002305 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002306 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002307
Swen Schillig564e1c82009-08-18 15:43:19 +02002308 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Swen Schilliga4623c42009-08-18 15:43:15 +02002309 adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002310
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002311 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002312 retval = PTR_ERR(req);
2313 goto out;
2314 }
2315
Swen Schillig09a46c62009-08-18 15:43:16 +02002316 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schilligf3450c72009-11-24 16:53:59 +01002317 get_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002318 req->unit = unit;
2319 req->data = scsi_cmnd;
2320 req->handler = zfcp_fsf_send_fcp_command_handler;
2321 req->qtcb->header.lun_handle = unit->handle;
2322 req->qtcb->header.port_handle = unit->port->handle;
2323 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002324 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002325
2326 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2327
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 /*
2329 * set depending on data direction:
2330 * data direction bits in SBALE (SB Type)
2331 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002332 */
2333 switch (scsi_cmnd->sc_data_direction) {
2334 case DMA_NONE:
2335 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002336 break;
2337 case DMA_FROM_DEVICE:
2338 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339 break;
2340 case DMA_TO_DEVICE:
2341 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2342 sbtype = SBAL_FLAGS0_TYPE_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002343 break;
2344 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002345 goto failed_scsi_cmnd;
2346 }
2347
Christof Schmitt4318e082009-11-24 16:54:08 +01002348 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2349 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002350
Swen Schillig564e1c82009-08-18 15:43:19 +02002351 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002352 scsi_sglist(scsi_cmnd),
2353 FSF_MAX_SBALS_PER_REQ);
2354 if (unlikely(real_bytes < 0)) {
Swen Schillig42428f72009-08-18 15:43:18 +02002355 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002356 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002357 "Oversize data package, unit 0x%016Lx "
2358 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002359 (unsigned long long)unit->fcp_lun,
2360 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002361 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002362 retval = -EINVAL;
2363 }
2364 goto failed_scsi_cmnd;
2365 }
2366
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002367 retval = zfcp_fsf_req_send(req);
2368 if (unlikely(retval))
2369 goto failed_scsi_cmnd;
2370
2371 goto out;
2372
2373failed_scsi_cmnd:
Swen Schilligf3450c72009-11-24 16:53:59 +01002374 put_device(&unit->sysfs_device);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002375 zfcp_fsf_req_free(req);
2376 scsi_cmnd->host_scribble = NULL;
2377out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002378 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002379 return retval;
2380}
2381
2382/**
2383 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002384 * @unit: pointer to struct zfcp_unit
2385 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002386 * Returns: on success pointer to struct fsf_req, NULL otherwise
2387 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002388struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002389{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002390 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002391 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002392 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002393 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002394
2395 if (unlikely(!(atomic_read(&unit->status) &
2396 ZFCP_STATUS_COMMON_UNBLOCKED)))
2397 return NULL;
2398
Swen Schillig564e1c82009-08-18 15:43:19 +02002399 spin_lock_bh(&qdio->req_q_lock);
2400 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002401 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002402
Swen Schillig564e1c82009-08-18 15:43:19 +02002403 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2404 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002405
Swen Schillig633528c2008-11-26 18:07:37 +01002406 if (IS_ERR(req)) {
2407 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002408 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002409 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002410
2411 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2412 req->data = unit;
2413 req->handler = zfcp_fsf_send_fcp_command_handler;
2414 req->qtcb->header.lun_handle = unit->handle;
2415 req->qtcb->header.port_handle = unit->port->handle;
2416 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2417 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002418 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002419
Swen Schillig564e1c82009-08-18 15:43:19 +02002420 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002421 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2422 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2423
Christof Schmitt4318e082009-11-24 16:54:08 +01002424 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2425 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002426
2427 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2428 if (!zfcp_fsf_req_send(req))
2429 goto out;
2430
2431 zfcp_fsf_req_free(req);
2432 req = NULL;
2433out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002434 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002435 return req;
2436}
2437
2438static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2439{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002440}
2441
2442/**
2443 * zfcp_fsf_control_file - control file upload/download
2444 * @adapter: pointer to struct zfcp_adapter
2445 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2446 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002448struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2449 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002451 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002452 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002453 struct zfcp_fsf_req *req = NULL;
2454 struct fsf_qtcb_bottom_support *bottom;
2455 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Christof Schmitt45633fd2008-06-10 18:20:55 +02002457 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2458 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Christof Schmitt45633fd2008-06-10 18:20:55 +02002460 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2462 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2465 direction = SBAL_FLAGS0_TYPE_READ;
2466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002468 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 }
2470
Swen Schillig564e1c82009-08-18 15:43:19 +02002471 spin_lock_bh(&qdio->req_q_lock);
2472 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002473 goto out;
2474
Swen Schillig564e1c82009-08-18 15:43:19 +02002475 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002476 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002478 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 }
2480
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002481 req->handler = zfcp_fsf_control_file_handler;
2482
Swen Schillig564e1c82009-08-18 15:43:19 +02002483 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 sbale[0].flags |= direction;
2485
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002486 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002488 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Swen Schillig564e1c82009-08-18 15:43:19 +02002490 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2491 direction, fsf_cfdc->sg,
2492 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002493 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002494 zfcp_fsf_req_free(req);
2495 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002498 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2499 retval = zfcp_fsf_req_send(req);
2500out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002501 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002502
2503 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002504 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002505 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002507 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002509
2510/**
2511 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2512 * @adapter: pointer to struct zfcp_adapter
2513 * @sbal_idx: response queue index of SBAL to be processed
2514 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002515void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002516{
Swen Schillig564e1c82009-08-18 15:43:19 +02002517 struct zfcp_adapter *adapter = qdio->adapter;
2518 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002519 struct qdio_buffer_element *sbale;
2520 struct zfcp_fsf_req *fsf_req;
2521 unsigned long flags, req_id;
2522 int idx;
2523
2524 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2525
2526 sbale = &sbal->element[idx];
2527 req_id = (unsigned long) sbale->addr;
2528 spin_lock_irqsave(&adapter->req_list_lock, flags);
2529 fsf_req = zfcp_reqlist_find(adapter, req_id);
2530
2531 if (!fsf_req)
2532 /*
2533 * Unknown request means that we have potentially memory
2534 * corruption and must stop the machine immediately.
2535 */
2536 panic("error: unknown req_id (%lx) on adapter %s.\n",
2537 req_id, dev_name(&adapter->ccw_device->dev));
2538
2539 list_del(&fsf_req->list);
2540 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
2541
Swen Schillig42428f72009-08-18 15:43:18 +02002542 fsf_req->queue_req.sbal_response = sbal_idx;
2543 fsf_req->queue_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002544 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002545 zfcp_fsf_req_complete(fsf_req);
2546
2547 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2548 break;
2549 }
2550}