blob: 6538742b421a1737ae84d766a34990ebfa484277 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Christof Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2002, 2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Stefan Raspl0997f1c2008-10-16 08:23:39 +020012#include <linux/blktrace_api.h>
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"
Christof Schmitt34c2b712010-02-17 11:18:59 +010017#include "zfcp_qdio.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010018#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Christof Schmitt287ac012008-07-02 10:56:40 +020020static void zfcp_fsf_request_timeout_handler(unsigned long data)
21{
22 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010023 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
24 "fsrth_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +020025}
26
27static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
28 unsigned long timeout)
29{
30 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
31 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
32 fsf_req->timer.expires = jiffies + timeout;
33 add_timer(&fsf_req->timer);
34}
35
36static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
37{
38 BUG_ON(!fsf_req->erp_action);
39 fsf_req->timer.function = zfcp_erp_timeout_handler;
40 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
41 fsf_req->timer.expires = jiffies + 30 * HZ;
42 add_timer(&fsf_req->timer);
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* association between FSF command and FSF QTCB type */
46static u32 fsf_qtcb_type[] = {
47 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
48 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
57 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
58 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
60};
61
Christof Schmitt553448f2008-06-10 18:20:58 +020062static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
63{
Swen Schilligc41f8cb2008-07-02 10:56:39 +020064 u16 subtable = table >> 16;
Christof Schmitt553448f2008-06-10 18:20:58 +020065 u16 rule = table & 0xffff;
Christof Schmittff3b24f2008-10-01 12:42:15 +020066 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
Christof Schmitt553448f2008-06-10 18:20:58 +020067
Christof Schmittff3b24f2008-10-01 12:42:15 +020068 if (subtable && subtable < ARRAY_SIZE(act_type))
Christof Schmitt553448f2008-06-10 18:20:58 +020069 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020070 "Access denied according to ACT rule type %s, "
71 "rule %d\n", act_type[subtable], rule);
Christof Schmitt553448f2008-06-10 18:20:58 +020072}
73
74static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
75 struct zfcp_port *port)
76{
77 struct fsf_qtcb_header *header = &req->qtcb->header;
78 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020079 "Access denied to port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020080 (unsigned long long)port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020081 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
82 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010083 zfcp_erp_port_access_denied(port, "fspad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020084 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
85}
86
87static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
88 struct zfcp_unit *unit)
89{
90 struct fsf_qtcb_header *header = &req->qtcb->header;
91 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +020092 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +020093 (unsigned long long)unit->fcp_lun,
94 (unsigned long long)unit->port->wwpn);
Christof Schmitt553448f2008-06-10 18:20:58 +020095 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
96 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010097 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +020098 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
99}
100
101static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
102{
Christof Schmittff3b24f2008-10-01 12:42:15 +0200103 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
104 "operational because of an unsupported FC class\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100105 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200106 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
107}
108
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200109/**
110 * zfcp_fsf_req_free - free memory used by fsf request
111 * @fsf_req: pointer to struct zfcp_fsf_req
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200113void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200115 if (likely(req->pool)) {
Swen Schilliga4623c42009-08-18 15:43:15 +0200116 if (likely(req->qtcb))
117 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200118 mempool_free(req, req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200119 return;
120 }
121
Swen Schilliga4623c42009-08-18 15:43:15 +0200122 if (likely(req->qtcb))
123 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
124 kfree(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200127static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Swen Schilligecf0c772009-11-24 16:53:58 +0100129 unsigned long flags;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200130 struct fsf_status_read_buffer *sr_buf = req->data;
131 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 struct zfcp_port *port;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100133 int d_id = ntoh24(sr_buf->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Swen Schilligecf0c772009-11-24 16:53:58 +0100135 read_lock_irqsave(&adapter->port_list_lock, flags);
136 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200137 if (port->d_id == d_id) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100138 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
Swen Schilligecf0c772009-11-24 16:53:58 +0100139 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200140 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100141 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100144static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200145 struct fsf_link_down_info *link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200147 struct zfcp_adapter *adapter = req->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200149 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
150 return;
151
152 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
Christof Schmitt70932932009-04-17 15:08:15 +0200153
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100154 zfcp_scsi_schedule_rports_block(adapter);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200155
156 if (!link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200158
159 switch (link_down->error_code) {
160 case FSF_PSQ_LINK_NO_LIGHT:
161 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200162 "There is no light signal from the local "
163 "fibre channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200164 break;
165 case FSF_PSQ_LINK_WRAP_PLUG:
166 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200167 "There is a wrap plug instead of a fibre "
168 "channel cable\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200169 break;
170 case FSF_PSQ_LINK_NO_FCP:
171 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200172 "The adjacent fibre channel node does not "
173 "support FCP\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200174 break;
175 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
176 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200177 "The FCP device is suspended because of a "
178 "firmware update\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200179 break;
180 case FSF_PSQ_LINK_INVALID_WWPN:
181 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200182 "The FCP device detected a WWPN that is "
183 "duplicate or not valid\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200184 break;
185 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
186 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200187 "The fibre channel fabric does not support NPIV\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200188 break;
189 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
190 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200191 "The FCP adapter cannot support more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200192 break;
193 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
194 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200195 "The adjacent switch cannot support "
196 "more NPIV ports\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200197 break;
198 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
199 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200200 "The FCP adapter could not log in to the "
201 "fibre channel fabric\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200202 break;
203 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
204 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200205 "The WWPN assignment file on the FCP adapter "
206 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200207 break;
208 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
209 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200210 "The mode table on the FCP adapter "
211 "has been damaged\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200212 break;
213 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
214 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200215 "All NPIV ports on the FCP adapter have "
216 "been assigned\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200217 break;
218 default:
219 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200220 "The link between the FCP adapter and "
221 "the FC fabric is down\n");
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200222 }
223out:
224 zfcp_erp_adapter_failed(adapter, id, req);
225}
226
227static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
228{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200229 struct fsf_status_read_buffer *sr_buf = req->data;
230 struct fsf_link_down_info *ldi =
231 (struct fsf_link_down_info *) &sr_buf->payload;
232
233 switch (sr_buf->status_subtype) {
234 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100235 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200236 break;
237 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100238 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200239 break;
240 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100241 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200242 };
243}
244
245static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
246{
247 struct zfcp_adapter *adapter = req->adapter;
248 struct fsf_status_read_buffer *sr_buf = req->data;
249
250 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Swen Schillig57717102009-08-18 15:43:21 +0200251 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
Swen Schilliga4623c42009-08-18 15:43:15 +0200252 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200253 zfcp_fsf_req_free(req);
254 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
Swen Schillig57717102009-08-18 15:43:21 +0200257 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200258
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200259 switch (sr_buf->status_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 case FSF_STATUS_READ_PORT_CLOSED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200261 zfcp_fsf_status_read_port_closed(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 case FSF_STATUS_READ_INCOMING_ELS:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200264 zfcp_fc_incoming_els(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmittff3b24f2008-10-01 12:42:15 +0200269 dev_warn(&adapter->ccw_device->dev,
270 "The error threshold for checksum statistics "
271 "has been exceeded\n");
Swen Schillig57717102009-08-18 15:43:21 +0200272 zfcp_dbf_hba_berr(adapter->dbf, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 case FSF_STATUS_READ_LINK_DOWN:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200275 zfcp_fsf_status_read_link_down(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200278 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200279 "The local link has been restored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100281 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 ZFCP_STATUS_COMMON_RUNNING,
283 ZFCP_SET);
284 zfcp_erp_adapter_reopen(adapter,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200285 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
286 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100287 "fssrh_2", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 break;
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100289 case FSF_STATUS_READ_NOTIFICATION_LOST:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200290 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100291 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
292 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200293 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
Swen Schillig9eae07e2009-11-24 16:54:06 +0100294 queue_work(adapter->work_queue, &adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 case FSF_STATUS_READ_CFDC_UPDATED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100297 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200299 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200300 adapter->adapter_features = sr_buf->payload.word[0];
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200301 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200303
Swen Schilliga4623c42009-08-18 15:43:15 +0200304 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200305 zfcp_fsf_req_free(req);
Swen Schilligd26ab062008-05-19 12:17:37 +0200306
307 atomic_inc(&adapter->stat_miss);
Swen Schillig45446832009-08-18 15:43:17 +0200308 queue_work(adapter->work_queue, &adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200311static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200313 switch (req->qtcb->header.fsf_status_qual.word[0]) {
314 case FSF_SQ_FCP_RSP_AVAILABLE:
315 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
316 case FSF_SQ_NO_RETRY_POSSIBLE:
317 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
318 return;
319 case FSF_SQ_COMMAND_ABORTED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200320 break;
321 case FSF_SQ_NO_RECOM:
322 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200323 "The FCP adapter reported a problem "
324 "that cannot be recovered\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100325 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200326 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200328 /* all non-return stats set FSFREQ_ERROR*/
329 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
330}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200332static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
333{
334 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
335 return;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200336
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200337 switch (req->qtcb->header.fsf_status) {
338 case FSF_UNKNOWN_COMMAND:
339 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200340 "The FCP adapter does not recognize the command 0x%x\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200341 req->qtcb->header.fsf_command);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100342 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200343 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200346 zfcp_fsf_fsfstatus_qual_eval(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200351static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200353 struct zfcp_adapter *adapter = req->adapter;
354 struct fsf_qtcb *qtcb = req->qtcb;
355 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Swen Schillig57717102009-08-18 15:43:21 +0200357 zfcp_dbf_hba_fsf_response(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200359 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Christof Schmitt4c571c62009-11-24 16:54:15 +0100360 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200361 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200364 switch (qtcb->prefix.prot_status) {
365 case FSF_PROT_GOOD:
366 case FSF_PROT_FSF_STATUS_PRESENTED:
367 return;
368 case FSF_PROT_QTCB_VERSION_ERROR:
369 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200370 "QTCB version 0x%x not supported by FCP adapter "
371 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
372 psq->word[0], psq->word[1]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100373 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200375 case FSF_PROT_ERROR_STATE:
376 case FSF_PROT_SEQ_NUMB_ERROR:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100377 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100378 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200380 case FSF_PROT_UNSUPP_QTCB_TYPE:
381 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200382 "The QTCB type is not supported by the FCP adapter\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100383 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200385 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
386 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
387 &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200389 case FSF_PROT_DUPLICATE_REQUEST_ID:
390 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200391 "0x%Lx is an ambiguous request identifier\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200392 (unsigned long long)qtcb->bottom.support.req_handle);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100393 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200395 case FSF_PROT_LINK_DOWN:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100396 zfcp_fsf_link_down_info_eval(req, "fspse_5",
397 &psq->link_down_info);
Christof Schmitt452b5052010-02-17 11:18:51 +0100398 /* go through reopen to flush pending requests */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100399 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200401 case FSF_PROT_REEST_QUEUE:
402 /* All ports should be marked as ready to run again */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100403 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200404 ZFCP_STATUS_COMMON_RUNNING,
405 ZFCP_SET);
406 zfcp_erp_adapter_reopen(adapter,
407 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100408 ZFCP_STATUS_COMMON_ERP_FAILED,
409 "fspse_8", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200410 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200412 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200413 "0x%x is not a valid transfer protocol status\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200414 qtcb->prefix.prot_status);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100415 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200417 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
420/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200421 * zfcp_fsf_req_complete - process completion of a FSF request
422 * @fsf_req: The FSF request that has been completed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 *
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200424 * When a request has been completed either from the FCP adapter,
425 * or it has been dismissed due to a queue shutdown, this function
426 * is called to process the completion status and trigger further
427 * events related to the FSF request.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 */
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200429static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200430{
431 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
432 zfcp_fsf_status_read_handler(req);
433 return;
434 }
435
436 del_timer(&req->timer);
437 zfcp_fsf_protstatus_eval(req);
438 zfcp_fsf_fsfstatus_eval(req);
439 req->handler(req);
440
441 if (req->erp_action)
Christof Schmitt287ac012008-07-02 10:56:40 +0200442 zfcp_erp_notify(req->erp_action, 0);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200443
444 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
445 zfcp_fsf_req_free(req);
446 else
Swen Schillig058b8642009-08-18 15:43:14 +0200447 complete(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200448}
449
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200450/**
451 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
452 * @adapter: pointer to struct zfcp_adapter
453 *
454 * Never ever call this without shutting down the adapter first.
455 * Otherwise the adapter would continue using and corrupting s390 storage.
456 * Included BUG_ON() call to ensure this is done.
457 * ERP is supposed to be the only user of this function.
458 */
459void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
460{
461 struct zfcp_fsf_req *req, *tmp;
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200462 LIST_HEAD(remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200463
464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100465 zfcp_reqlist_move(adapter->req_list, &remove_queue);
Swen Schilligbd63eaf2009-08-18 15:43:13 +0200466
467 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
468 list_del(&req->list);
469 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
470 zfcp_fsf_req_complete(req);
471 }
472}
473
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200474static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100476 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200477 struct zfcp_adapter *adapter = req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200478 struct Scsi_Host *shost = adapter->scsi_host;
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100479 struct fc_els_flogi *nsp, *plogi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100481 /* adjust pointers for missing command code */
482 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
483 - sizeof(u32));
484 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
485 - sizeof(u32));
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200486
487 if (req->data)
488 memcpy(req->data, bottom, sizeof(*bottom));
489
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100490 fc_host_port_name(shost) = nsp->fl_wwpn;
491 fc_host_node_name(shost) = nsp->fl_wwnn;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100492 fc_host_port_id(shost) = ntoh24(bottom->s_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200493 fc_host_speed(shost) = bottom->fc_link_speed;
494 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
495
496 adapter->hydra_version = bottom->adapter_type;
497 adapter->timer_ticks = bottom->timer_interval;
498
499 if (fc_host_permanent_port_name(shost) == -1)
500 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
501
502 switch (bottom->fc_topology) {
503 case FSF_TOPO_P2P:
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100504 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
Christof Schmitt9d05ce22009-11-24 16:54:09 +0100505 adapter->peer_wwpn = plogi->fl_wwpn;
506 adapter->peer_wwnn = plogi->fl_wwnn;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200507 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200508 break;
509 case FSF_TOPO_FABRIC:
510 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200511 break;
512 case FSF_TOPO_AL:
513 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
Christof Schmittdceab652009-05-15 13:18:18 +0200514 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200515 default:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200516 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200517 "Unknown or unsupported arbitrated loop "
518 "fibre channel topology detected\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100519 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200520 return -EIO;
521 }
522
523 return 0;
524}
525
526static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
527{
528 struct zfcp_adapter *adapter = req->adapter;
529 struct fsf_qtcb *qtcb = req->qtcb;
530 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
531 struct Scsi_Host *shost = adapter->scsi_host;
532
533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
534 return;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200537 adapter->adapter_features = bottom->adapter_features;
538 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -0500539 adapter->peer_wwpn = 0;
540 adapter->peer_wwnn = 0;
541 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200543 switch (qtcb->header.fsf_status) {
544 case FSF_GOOD:
545 if (zfcp_fsf_exchange_config_evaluate(req))
546 return;
Swen Schillig52ef11a2007-08-28 09:31:09 +0200547
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200548 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
549 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200550 "FCP adapter maximum QTCB size (%d bytes) "
551 "is too small\n",
552 bottom->max_qtcb_size);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100553 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200554 return;
555 }
556 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
557 &adapter->status);
558 break;
559 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200560 fc_host_node_name(shost) = 0;
561 fc_host_port_name(shost) = 0;
562 fc_host_port_id(shost) = 0;
563 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100564 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 adapter->hydra_version = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200566
567 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
568 &adapter->status);
569
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100570 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200571 &qtcb->header.fsf_status_qual.link_down_info);
572 break;
573 default:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100574 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200578 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200580 memcpy(fc_host_serial_number(shost), bottom->serial_number,
581 min(FC_SERIAL_NUMBER_SIZE, 17));
582 EBCASC(fc_host_serial_number(shost),
583 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200586 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200587 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200588 "The FCP adapter only supports newer "
589 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100590 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200591 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200593 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200594 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200595 "The FCP adapter only supports older "
596 "control block versions\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100597 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200601static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200603 struct zfcp_adapter *adapter = req->adapter;
604 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
605 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200607 if (req->data)
608 memcpy(req->data, bottom, sizeof(*bottom));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100609
Christof Schmitt02829852009-03-02 13:09:06 +0100610 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100611 fc_host_permanent_port_name(shost) = bottom->wwpn;
Christof Schmitt02829852009-03-02 13:09:06 +0100612 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
613 } else
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100614 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
615 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
616 fc_host_supported_speeds(shost) = bottom->supported_speed;
Christof Schmitt2d8e62b2010-02-17 11:18:58 +0100617 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
618 FC_FC4_LIST_SIZE);
619 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
620 FC_FC4_LIST_SIZE);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100621}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200623static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200625 struct fsf_qtcb *qtcb = req->qtcb;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100626
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200627 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return;
629
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200630 switch (qtcb->header.fsf_status) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200631 case FSF_GOOD:
632 zfcp_fsf_exchange_port_evaluate(req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200633 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200635 zfcp_fsf_exchange_port_evaluate(req);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100636 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200637 &qtcb->header.fsf_status_qual.link_down_info);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200638 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640}
641
Swen Schillig564e1c82009-08-18 15:43:19 +0200642static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200643{
Swen Schillig564e1c82009-08-18 15:43:19 +0200644 struct zfcp_qdio_queue *req_q = &qdio->req_q;
Martin Petermann7001f0c2009-04-17 15:08:12 +0200645
Swen Schillig564e1c82009-08-18 15:43:19 +0200646 spin_lock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200647 if (atomic_read(&req_q->count))
648 return 1;
Swen Schillig564e1c82009-08-18 15:43:19 +0200649 spin_unlock_bh(&qdio->req_q_lock);
Martin Petermann7001f0c2009-04-17 15:08:12 +0200650 return 0;
651}
652
Swen Schillig564e1c82009-08-18 15:43:19 +0200653static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
Martin Petermann7001f0c2009-04-17 15:08:12 +0200654{
Swen Schillig564e1c82009-08-18 15:43:19 +0200655 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200656 long ret;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200657
Swen Schillig564e1c82009-08-18 15:43:19 +0200658 spin_unlock_bh(&qdio->req_q_lock);
659 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
660 zfcp_fsf_sbal_check(qdio), 5 * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200661 if (ret > 0)
662 return 0;
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200663 if (!ret) {
Swen Schillig564e1c82009-08-18 15:43:19 +0200664 atomic_inc(&qdio->req_q_full);
Christof Schmittcbf1ed02009-07-13 15:06:10 +0200665 /* assume hanging outbound queue, try queue recovery */
666 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
667 }
Martin Petermann7001f0c2009-04-17 15:08:12 +0200668
Swen Schillig564e1c82009-08-18 15:43:19 +0200669 spin_lock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200670 return -EIO;
671}
672
Swen Schilliga4623c42009-08-18 15:43:15 +0200673static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200674{
675 struct zfcp_fsf_req *req;
Swen Schilliga4623c42009-08-18 15:43:15 +0200676
677 if (likely(pool))
678 req = mempool_alloc(pool, GFP_ATOMIC);
679 else
680 req = kmalloc(sizeof(*req), GFP_ATOMIC);
681
682 if (unlikely(!req))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200683 return NULL;
Swen Schilliga4623c42009-08-18 15:43:15 +0200684
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200685 memset(req, 0, sizeof(*req));
Christof Schmitt88f2a972008-11-04 16:35:07 +0100686 req->pool = pool;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200687 return req;
688}
689
Swen Schilliga4623c42009-08-18 15:43:15 +0200690static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200691{
Swen Schilliga4623c42009-08-18 15:43:15 +0200692 struct fsf_qtcb *qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200693
694 if (likely(pool))
695 qtcb = mempool_alloc(pool, GFP_ATOMIC);
696 else
Swen Schilliga4623c42009-08-18 15:43:15 +0200697 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
698
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200699 if (unlikely(!qtcb))
700 return NULL;
701
702 memset(qtcb, 0, sizeof(*qtcb));
Swen Schilliga4623c42009-08-18 15:43:15 +0200703 return qtcb;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200704}
705
Swen Schillig564e1c82009-08-18 15:43:19 +0200706static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
Swen Schillig09a46c62009-08-18 15:43:16 +0200707 u32 fsf_cmd, mempool_t *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200709 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +0200710 struct zfcp_qdio_queue *req_q = &qdio->req_q;
711 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilliga4623c42009-08-18 15:43:15 +0200712 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200713
714 if (unlikely(!req))
Christof Schmitt1e9b1642009-07-13 15:06:04 +0200715 return ERR_PTR(-ENOMEM);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200716
717 if (adapter->req_no == 0)
718 adapter->req_no++;
719
720 INIT_LIST_HEAD(&req->list);
721 init_timer(&req->timer);
Swen Schillig058b8642009-08-18 15:43:14 +0200722 init_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200723
724 req->adapter = adapter;
725 req->fsf_command = fsf_cmd;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100726 req->req_id = adapter->req_no;
Christof Schmitt34c2b712010-02-17 11:18:59 +0100727 req->qdio_req.sbal_number = 1;
728 req->qdio_req.sbal_first = req_q->first;
729 req->qdio_req.sbal_last = req_q->first;
730 req->qdio_req.sbale_curr = 1;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200731
Christof Schmitt34c2b712010-02-17 11:18:59 +0100732 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200733 sbale[0].addr = (void *) req->req_id;
734 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
735
Swen Schilliga4623c42009-08-18 15:43:15 +0200736 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
737 if (likely(pool))
738 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
739 else
740 req->qtcb = zfcp_qtcb_alloc(NULL);
741
742 if (unlikely(!req->qtcb)) {
743 zfcp_fsf_req_free(req);
744 return ERR_PTR(-ENOMEM);
745 }
746
Christof Schmitt5bdecd22010-02-17 11:18:55 +0100747 req->seq_no = adapter->fsf_req_seq_no;
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;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200755 sbale[1].addr = (void *) req->qtcb;
756 sbale[1].length = sizeof(struct fsf_qtcb);
757 }
758
759 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
760 zfcp_fsf_req_free(req);
761 return ERR_PTR(-EIO);
762 }
763
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200764 return req;
765}
766
767static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
768{
769 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200770 struct zfcp_qdio *qdio = adapter->qdio;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100771 int with_qtcb = (req->qtcb != NULL);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100772 int req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200773
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100774 zfcp_reqlist_add(adapter->req_list, req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200775
Christof Schmitt34c2b712010-02-17 11:18:59 +0100776 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200777 req->issued = get_clock();
Christof Schmitt34c2b712010-02-17 11:18:59 +0100778 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200779 del_timer(&req->timer);
Christof Schmitt37651382008-11-04 16:35:08 +0100780 /* lookup request again, list might have changed */
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100781 zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100782 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200783 return -EIO;
784 }
785
786 /* Don't increase for unsolicited status */
Martin Petermann135ea132009-04-17 15:08:01 +0200787 if (with_qtcb)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200788 adapter->fsf_req_seq_no++;
Christof Schmitt52bfb552009-03-02 13:08:58 +0100789 adapter->req_no++;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200790
791 return 0;
792}
793
794/**
795 * zfcp_fsf_status_read - send status read request
796 * @adapter: pointer to struct zfcp_adapter
797 * @req_flags: request flags
798 * Returns: 0 on success, ERROR otherwise
799 */
Swen Schillig564e1c82009-08-18 15:43:19 +0200800int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200801{
Swen Schillig564e1c82009-08-18 15:43:19 +0200802 struct zfcp_adapter *adapter = qdio->adapter;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200803 struct zfcp_fsf_req *req;
804 struct fsf_status_read_buffer *sr_buf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200805 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200806 int retval = -EIO;
807
Swen Schillig564e1c82009-08-18 15:43:19 +0200808 spin_lock_bh(&qdio->req_q_lock);
809 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Swen Schillig564e1c82009-08-18 15:43:19 +0200812 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
Swen Schilliga4623c42009-08-18 15:43:15 +0200813 adapter->pool.status_read_req);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +0200814 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200815 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 goto out;
817 }
818
Christof Schmitt34c2b712010-02-17 11:18:59 +0100819 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200820 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
Christof Schmitt34c2b712010-02-17 11:18:59 +0100821 req->qdio_req.sbale_curr = 2;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200822
Swen Schilliga4623c42009-08-18 15:43:15 +0200823 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200824 if (!sr_buf) {
825 retval = -ENOMEM;
826 goto failed_buf;
827 }
828 memset(sr_buf, 0, sizeof(*sr_buf));
829 req->data = sr_buf;
Christof Schmitt34c2b712010-02-17 11:18:59 +0100830 sbale = zfcp_qdio_sbale_curr(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200831 sbale->addr = (void *) sr_buf;
832 sbale->length = sizeof(*sr_buf);
833
834 retval = zfcp_fsf_req_send(req);
835 if (retval)
836 goto failed_req_send;
837
838 goto out;
839
840failed_req_send:
Swen Schilliga4623c42009-08-18 15:43:15 +0200841 mempool_free(sr_buf, adapter->pool.status_read_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200842failed_buf:
843 zfcp_fsf_req_free(req);
Swen Schillig57717102009-08-18 15:43:21 +0200844 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200845out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200846 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 return retval;
848}
849
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200850static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200852 struct zfcp_unit *unit = req->data;
853 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200855 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
856 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200858 switch (req->qtcb->header.fsf_status) {
859 case FSF_PORT_HANDLE_NOT_VALID:
860 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100861 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
862 "fsafch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200863 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200866 case FSF_LUN_HANDLE_NOT_VALID:
867 if (fsq->word[0] == fsq->word[1]) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100868 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200869 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200872 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
873 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 break;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200875 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100876 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100877 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200878 break;
879 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100880 zfcp_erp_unit_boxed(unit, "fsafch4", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +0100881 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200882 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 case FSF_ADAPTER_STATUS_AVAILABLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200884 switch (fsq->word[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +0200886 zfcp_fc_test_link(unit->port);
Christof Schmittdceab652009-05-15 13:18:18 +0200887 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200889 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 break;
891 }
892 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 case FSF_GOOD:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200894 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
895 break;
896 }
897}
898
899/**
900 * zfcp_fsf_abort_fcp_command - abort running SCSI command
901 * @old_req_id: unsigned long
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200902 * @unit: pointer to struct zfcp_unit
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200903 * Returns: pointer to struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200904 */
905
906struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
Christof Schmitt63caf362009-03-02 13:09:00 +0100907 struct zfcp_unit *unit)
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200908{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200909 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200910 struct zfcp_fsf_req *req = NULL;
Swen Schillig564e1c82009-08-18 15:43:19 +0200911 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200912
Swen Schillig564e1c82009-08-18 15:43:19 +0200913 spin_lock_bh(&qdio->req_q_lock);
914 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200915 goto out;
Swen Schillig564e1c82009-08-18 15:43:19 +0200916 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
917 qdio->adapter->pool.scsi_abort);
Swen Schillig633528c2008-11-26 18:07:37 +0100918 if (IS_ERR(req)) {
919 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200920 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +0100921 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200922
923 if (unlikely(!(atomic_read(&unit->status) &
924 ZFCP_STATUS_COMMON_UNBLOCKED)))
925 goto out_error_free;
926
Christof Schmitt34c2b712010-02-17 11:18:59 +0100927 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200928 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
929 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
930
931 req->data = unit;
932 req->handler = zfcp_fsf_abort_fcp_command_handler;
933 req->qtcb->header.lun_handle = unit->handle;
934 req->qtcb->header.port_handle = unit->port->handle;
935 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
936
937 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
938 if (!zfcp_fsf_req_send(req))
939 goto out;
940
941out_error_free:
942 zfcp_fsf_req_free(req);
943 req = NULL;
944out:
Swen Schillig564e1c82009-08-18 15:43:19 +0200945 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200946 return req;
947}
948
949static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
950{
951 struct zfcp_adapter *adapter = req->adapter;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100952 struct zfcp_fsf_ct_els *ct = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200953 struct fsf_qtcb_header *header = &req->qtcb->header;
954
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100955 ct->status = -EINVAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200956
957 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
958 goto skip_fsfstatus;
959
960 switch (header->fsf_status) {
961 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +0200962 zfcp_dbf_san_ct_response(req);
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100963 ct->status = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200964 break;
965 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
966 zfcp_fsf_class_not_supp(req);
967 break;
968 case FSF_ADAPTER_STATUS_AVAILABLE:
969 switch (header->fsf_status_qual.word[0]){
970 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200971 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
972 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
973 break;
974 }
975 break;
976 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200977 break;
978 case FSF_PORT_BOXED:
Christof Schmitt4c571c62009-11-24 16:54:15 +0100979 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200980 break;
981 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100982 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
Christof Schmittdceab652009-05-15 13:18:18 +0200983 /* fall through */
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200984 case FSF_GENERIC_COMMAND_REJECTED:
985 case FSF_PAYLOAD_SIZE_MISMATCH:
986 case FSF_REQUEST_SIZE_TOO_LARGE:
987 case FSF_RESPONSE_SIZE_TOO_LARGE:
988 case FSF_SBAL_MISMATCH:
989 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
990 break;
991 }
992
993skip_fsfstatus:
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100994 if (ct->handler)
995 ct->handler(ct->handler_data);
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200996}
997
Christof Schmitt426f6052009-07-13 15:06:06 +0200998static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
999 struct scatterlist *sg_req,
1000 struct scatterlist *sg_resp)
1001{
1002 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1003 sbale[2].addr = sg_virt(sg_req);
1004 sbale[2].length = sg_req->length;
1005 sbale[3].addr = sg_virt(sg_resp);
1006 sbale[3].length = sg_resp->length;
1007 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1008}
1009
1010static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1011{
1012 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1013}
1014
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001015static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1016 struct scatterlist *sg_req,
1017 struct scatterlist *sg_resp,
1018 int max_sbals)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001019{
Swen Schillig42428f72009-08-18 15:43:18 +02001020 struct zfcp_adapter *adapter = req->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001021 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
Christof Schmitt34c2b712010-02-17 11:18:59 +01001022 &req->qdio_req);
Swen Schillig42428f72009-08-18 15:43:18 +02001023 u32 feat = adapter->adapter_features;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001024 int bytes;
1025
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001026 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
Christof Schmitt426f6052009-07-13 15:06:06 +02001027 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001028 return -EOPNOTSUPP;
1029
Christof Schmitt426f6052009-07-13 15:06:06 +02001030 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1031 return 0;
1032 }
1033
1034 /* use single, unchained SBAL if it can hold the request */
1035 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1036 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001037 return 0;
1038 }
1039
Christof Schmitt34c2b712010-02-17 11:18:59 +01001040 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001041 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001042 sg_req, max_sbals);
1043 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001044 return -EIO;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001045 req->qtcb->bottom.support.req_buf_length = bytes;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001046 req->qdio_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001047
Christof Schmitt34c2b712010-02-17 11:18:59 +01001048 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
Swen Schillig42428f72009-08-18 15:43:18 +02001049 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001050 sg_resp, max_sbals);
Christof Schmittb1a58982009-09-24 10:23:21 +02001051 req->qtcb->bottom.support.resp_buf_length = bytes;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001052 if (bytes <= 0)
Christof Schmitt9072df42009-07-13 15:06:07 +02001053 return -EIO;
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001054
Christof Schmittb1a58982009-09-24 10:23:21 +02001055 return 0;
1056}
1057
1058static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1059 struct scatterlist *sg_req,
1060 struct scatterlist *sg_resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001061 int max_sbals, unsigned int timeout)
Christof Schmittb1a58982009-09-24 10:23:21 +02001062{
1063 int ret;
1064
1065 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1066 if (ret)
1067 return ret;
1068
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001069 /* common settings for ct/gs and els requests */
Swen Schillig51375ee2010-01-14 17:19:02 +01001070 if (timeout > 255)
1071 timeout = 255; /* max value accepted by hardware */
Christof Schmitt98fc4d52009-08-18 15:43:26 +02001072 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
Swen Schillig51375ee2010-01-14 17:19:02 +01001073 req->qtcb->bottom.support.timeout = timeout;
1074 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001075
1076 return 0;
1077}
1078
1079/**
1080 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1081 * @ct: pointer to struct zfcp_send_ct with data for request
1082 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001083 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001084int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
Swen Schillig51375ee2010-01-14 17:19:02 +01001085 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1086 unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001087{
Swen Schillig564e1c82009-08-18 15:43:19 +02001088 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001089 struct zfcp_fsf_req *req;
1090 int ret = -EIO;
1091
Swen Schillig564e1c82009-08-18 15:43:19 +02001092 spin_lock_bh(&qdio->req_q_lock);
1093 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001094 goto out;
1095
Swen Schillig564e1c82009-08-18 15:43:19 +02001096 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
Swen Schillig09a46c62009-08-18 15:43:16 +02001097
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001098 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001099 ret = PTR_ERR(req);
1100 goto out;
1101 }
1102
Swen Schillig09a46c62009-08-18 15:43:16 +02001103 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmittb1a58982009-09-24 10:23:21 +02001104 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
Swen Schillig51375ee2010-01-14 17:19:02 +01001105 FSF_MAX_SBALS_PER_REQ, timeout);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001106 if (ret)
1107 goto failed_send;
1108
1109 req->handler = zfcp_fsf_send_ct_handler;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001110 req->qtcb->header.port_handle = wka_port->handle;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001111 req->data = ct;
1112
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001113 zfcp_dbf_san_ct_request(req, wka_port->d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001114
1115 ret = zfcp_fsf_req_send(req);
1116 if (ret)
1117 goto failed_send;
1118
1119 goto out;
1120
1121failed_send:
1122 zfcp_fsf_req_free(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001123out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001124 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001125 return ret;
1126}
1127
1128static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1129{
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001130 struct zfcp_fsf_ct_els *send_els = req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001131 struct zfcp_port *port = send_els->port;
1132 struct fsf_qtcb_header *header = &req->qtcb->header;
1133
1134 send_els->status = -EINVAL;
1135
1136 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1137 goto skip_fsfstatus;
1138
1139 switch (header->fsf_status) {
1140 case FSF_GOOD:
Swen Schillig57717102009-08-18 15:43:21 +02001141 zfcp_dbf_san_els_response(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001142 send_els->status = 0;
1143 break;
1144 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1145 zfcp_fsf_class_not_supp(req);
1146 break;
1147 case FSF_ADAPTER_STATUS_AVAILABLE:
1148 switch (header->fsf_status_qual.word[0]){
1149 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001150 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1151 case FSF_SQ_RETRY_IF_POSSIBLE:
1152 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1153 break;
1154 }
1155 break;
1156 case FSF_ELS_COMMAND_REJECTED:
1157 case FSF_PAYLOAD_SIZE_MISMATCH:
1158 case FSF_REQUEST_SIZE_TOO_LARGE:
1159 case FSF_RESPONSE_SIZE_TOO_LARGE:
1160 break;
1161 case FSF_ACCESS_DENIED:
Christof Schmittdc577d52009-05-15 13:18:22 +02001162 if (port)
1163 zfcp_fsf_access_denied_port(req, port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001164 break;
1165 case FSF_SBAL_MISMATCH:
1166 /* should never occure, avoided in zfcp_fsf_send_els */
1167 /* fall through */
1168 default:
1169 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1170 break;
1171 }
1172skip_fsfstatus:
1173 if (send_els->handler)
1174 send_els->handler(send_els->handler_data);
1175}
1176
1177/**
1178 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1179 * @els: pointer to struct zfcp_send_els with data for the command
1180 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001181int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
Swen Schillig51375ee2010-01-14 17:19:02 +01001182 struct zfcp_fsf_ct_els *els, unsigned int timeout)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001183{
1184 struct zfcp_fsf_req *req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001185 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001186 int ret = -EIO;
1187
Swen Schillig564e1c82009-08-18 15:43:19 +02001188 spin_lock_bh(&qdio->req_q_lock);
1189 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001190 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001191
Swen Schillig564e1c82009-08-18 15:43:19 +02001192 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001193
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001194 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001195 ret = PTR_ERR(req);
1196 goto out;
1197 }
1198
Swen Schillig09a46c62009-08-18 15:43:16 +02001199 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Swen Schillig51375ee2010-01-14 17:19:02 +01001200 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
Swen Schillig44cc76f2008-10-01 12:42:16 +02001201
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001202 if (ret)
1203 goto failed_send;
1204
Christof Schmitt7c7dc192009-11-24 16:54:13 +01001205 hton24(req->qtcb->bottom.support.d_id, d_id);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001206 req->handler = zfcp_fsf_send_els_handler;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001207 req->data = els;
1208
Swen Schillig57717102009-08-18 15:43:21 +02001209 zfcp_dbf_san_els_request(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001210
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001211 ret = zfcp_fsf_req_send(req);
1212 if (ret)
1213 goto failed_send;
1214
1215 goto out;
1216
1217failed_send:
1218 zfcp_fsf_req_free(req);
1219out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001220 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001221 return ret;
1222}
1223
1224int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1225{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001226 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001227 struct zfcp_fsf_req *req;
Swen Schillig564e1c82009-08-18 15:43:19 +02001228 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001229 int retval = -EIO;
1230
Swen Schillig564e1c82009-08-18 15:43:19 +02001231 spin_lock_bh(&qdio->req_q_lock);
1232 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001233 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001234
Swen Schillig564e1c82009-08-18 15:43:19 +02001235 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1236 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001237
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001238 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001239 retval = PTR_ERR(req);
1240 goto out;
1241 }
1242
Swen Schillig09a46c62009-08-18 15:43:16 +02001243 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001244 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001245 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1246 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1247
1248 req->qtcb->bottom.config.feature_selection =
1249 FSF_FEATURE_CFDC |
1250 FSF_FEATURE_LUN_SHARING |
1251 FSF_FEATURE_NOTIFICATION_LOST |
1252 FSF_FEATURE_UPDATE_ALERT;
1253 req->erp_action = erp_action;
1254 req->handler = zfcp_fsf_exchange_config_data_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001255 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001256
Christof Schmitt287ac012008-07-02 10:56:40 +02001257 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001258 retval = zfcp_fsf_req_send(req);
1259 if (retval) {
1260 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001261 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001262 }
1263out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001264 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001265 return retval;
1266}
1267
Swen Schillig564e1c82009-08-18 15:43:19 +02001268int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001269 struct fsf_qtcb_bottom_config *data)
1270{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001271 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001272 struct zfcp_fsf_req *req = NULL;
1273 int retval = -EIO;
1274
Swen Schillig564e1c82009-08-18 15:43:19 +02001275 spin_lock_bh(&qdio->req_q_lock);
1276 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001277 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001278
Swen Schillig564e1c82009-08-18 15:43:19 +02001279 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001280
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001281 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001282 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001283 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001284 }
1285
Christof Schmitt34c2b712010-02-17 11:18:59 +01001286 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001287 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1288 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1289 req->handler = zfcp_fsf_exchange_config_data_handler;
1290
1291 req->qtcb->bottom.config.feature_selection =
1292 FSF_FEATURE_CFDC |
1293 FSF_FEATURE_LUN_SHARING |
1294 FSF_FEATURE_NOTIFICATION_LOST |
1295 FSF_FEATURE_UPDATE_ALERT;
1296
1297 if (data)
1298 req->data = data;
1299
1300 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1301 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001302 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001303 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001304 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001305
1306 zfcp_fsf_req_free(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001307 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001308
Christof Schmittada81b72009-04-17 15:08:03 +02001309out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001310 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001311 return retval;
1312}
1313
1314/**
1315 * zfcp_fsf_exchange_port_data - request information about local port
1316 * @erp_action: ERP action for the adapter for which port data is requested
1317 * Returns: 0 on success, error otherwise
1318 */
1319int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1320{
Swen Schillig564e1c82009-08-18 15:43:19 +02001321 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schillig44cc76f2008-10-01 12:42:16 +02001322 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001323 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001324 int retval = -EIO;
1325
Swen Schillig564e1c82009-08-18 15:43:19 +02001326 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001327 return -EOPNOTSUPP;
1328
Swen Schillig564e1c82009-08-18 15:43:19 +02001329 spin_lock_bh(&qdio->req_q_lock);
1330 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001331 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02001332
Swen Schillig564e1c82009-08-18 15:43:19 +02001333 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1334 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001335
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001336 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001337 retval = PTR_ERR(req);
1338 goto out;
1339 }
1340
Swen Schillig09a46c62009-08-18 15:43:16 +02001341 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001342 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001343 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1344 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1345
1346 req->handler = zfcp_fsf_exchange_port_data_handler;
1347 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001348 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001349
Christof Schmitt287ac012008-07-02 10:56:40 +02001350 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001351 retval = zfcp_fsf_req_send(req);
1352 if (retval) {
1353 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001354 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001355 }
1356out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001357 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001358 return retval;
1359}
1360
1361/**
1362 * zfcp_fsf_exchange_port_data_sync - request information about local port
Swen Schillig564e1c82009-08-18 15:43:19 +02001363 * @qdio: pointer to struct zfcp_qdio
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001364 * @data: pointer to struct fsf_qtcb_bottom_port
1365 * Returns: 0 on success, error otherwise
1366 */
Swen Schillig564e1c82009-08-18 15:43:19 +02001367int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001368 struct fsf_qtcb_bottom_port *data)
1369{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001370 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001371 struct zfcp_fsf_req *req = NULL;
1372 int retval = -EIO;
1373
Swen Schillig564e1c82009-08-18 15:43:19 +02001374 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001375 return -EOPNOTSUPP;
1376
Swen Schillig564e1c82009-08-18 15:43:19 +02001377 spin_lock_bh(&qdio->req_q_lock);
1378 if (zfcp_fsf_req_sbal_get(qdio))
Christof Schmittada81b72009-04-17 15:08:03 +02001379 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001380
Swen Schillig564e1c82009-08-18 15:43:19 +02001381 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
Swen Schillig09a46c62009-08-18 15:43:16 +02001382
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001383 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001384 retval = PTR_ERR(req);
Christof Schmittada81b72009-04-17 15:08:03 +02001385 goto out_unlock;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001386 }
1387
1388 if (data)
1389 req->data = data;
1390
Christof Schmitt34c2b712010-02-17 11:18:59 +01001391 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001392 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1393 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1394
1395 req->handler = zfcp_fsf_exchange_port_data_handler;
1396 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1397 retval = zfcp_fsf_req_send(req);
Swen Schillig564e1c82009-08-18 15:43:19 +02001398 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001399
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001400 if (!retval)
Swen Schillig058b8642009-08-18 15:43:14 +02001401 wait_for_completion(&req->completion);
1402
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001403 zfcp_fsf_req_free(req);
1404
1405 return retval;
Christof Schmittada81b72009-04-17 15:08:03 +02001406
1407out_unlock:
Swen Schillig564e1c82009-08-18 15:43:19 +02001408 spin_unlock_bh(&qdio->req_q_lock);
Christof Schmittada81b72009-04-17 15:08:03 +02001409 return retval;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001410}
1411
1412static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1413{
1414 struct zfcp_port *port = req->data;
1415 struct fsf_qtcb_header *header = &req->qtcb->header;
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001416 struct fc_els_flogi *plogi;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001417
1418 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Martin Petermanna17c5852009-05-15 13:18:19 +02001419 goto out;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001420
1421 switch (header->fsf_status) {
1422 case FSF_PORT_ALREADY_OPEN:
1423 break;
1424 case FSF_ACCESS_DENIED:
1425 zfcp_fsf_access_denied_port(req, port);
1426 break;
1427 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1428 dev_warn(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001429 "Not enough FCP adapter resources to open "
Swen Schillig7ba58c92008-10-01 12:42:18 +02001430 "remote port 0x%016Lx\n",
1431 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001432 zfcp_erp_port_failed(port, "fsoph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001433 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1434 break;
1435 case FSF_ADAPTER_STATUS_AVAILABLE:
1436 switch (header->fsf_status_qual.word[0]) {
1437 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1438 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001439 case FSF_SQ_NO_RETRY_POSSIBLE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001440 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1441 break;
1442 }
1443 break;
1444 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1447 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001448 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1449 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1450 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 /* check whether D_ID has changed during open */
1452 /*
1453 * FIXME: This check is not airtight, as the FCP channel does
1454 * not monitor closures of target port connections caused on
1455 * the remote side. Thus, they might miss out on invalidating
1456 * locally cached WWPNs (and other N_Port parameters) of gone
1457 * target ports. So, our heroic attempt to make things safe
1458 * could be undermined by 'open port' response data tagged with
1459 * obsolete WWPNs. Another reason to monitor potential
1460 * connection closures ourself at least (by interpreting
1461 * incoming ELS' and unsolicited status). It just crosses my
1462 * mind that one should be able to cross-check by means of
1463 * another GID_PN straight after a port has been opened.
1464 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1465 */
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001466 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
Christof Schmitt39eb7e92008-12-19 16:57:01 +01001467 if (req->qtcb->bottom.support.els1_length >=
Christof Schmitt9d05ce22009-11-24 16:54:09 +01001468 FSF_PLOGI_MIN_LEN)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001469 zfcp_fc_plogi_evaluate(port, plogi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 case FSF_UNKNOWN_OP_SUBTYPE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001472 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 break;
1474 }
Martin Petermanna17c5852009-05-15 13:18:19 +02001475
1476out:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001477 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001480/**
1481 * zfcp_fsf_open_port - create and send open port request
1482 * @erp_action: pointer to struct zfcp_erp_action
1483 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001485int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001487 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001488 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Martin Petermanna17c5852009-05-15 13:18:19 +02001489 struct zfcp_port *port = erp_action->port;
Swen Schillig564e1c82009-08-18 15:43:19 +02001490 struct zfcp_fsf_req *req;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001491 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Swen Schillig564e1c82009-08-18 15:43:19 +02001493 spin_lock_bh(&qdio->req_q_lock);
1494 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Swen Schillig564e1c82009-08-18 15:43:19 +02001497 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1498 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001499
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001500 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001501 retval = PTR_ERR(req);
1502 goto out;
1503 }
1504
Swen Schillig09a46c62009-08-18 15:43:16 +02001505 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001506 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1508 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1509
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001510 req->handler = zfcp_fsf_open_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001511 hton24(req->qtcb->bottom.support.d_id, port->d_id);
Martin Petermanna17c5852009-05-15 13:18:19 +02001512 req->data = port;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001513 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001514 erp_action->fsf_req_id = req->req_id;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001515 get_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Christof Schmitt287ac012008-07-02 10:56:40 +02001517 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001518 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001520 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001521 erp_action->fsf_req_id = 0;
Christof Schmitt615f59e2010-02-17 11:18:56 +01001522 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001524out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001525 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return retval;
1527}
1528
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001529static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001531 struct zfcp_port *port = req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001533 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001534 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001536 switch (req->qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001538 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001539 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 case FSF_GOOD:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001544 zfcp_erp_modify_port_status(port, "fscph_2", req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 ZFCP_STATUS_COMMON_OPEN,
1546 ZFCP_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001551/**
1552 * zfcp_fsf_close_port - create and send close port request
1553 * @erp_action: pointer to struct zfcp_erp_action
1554 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001556int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001558 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001559 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001560 struct zfcp_fsf_req *req;
1561 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Swen Schillig564e1c82009-08-18 15:43:19 +02001563 spin_lock_bh(&qdio->req_q_lock);
1564 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Swen Schillig564e1c82009-08-18 15:43:19 +02001567 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1568 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001569
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001570 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001571 retval = PTR_ERR(req);
1572 goto out;
1573 }
1574
Swen Schillig09a46c62009-08-18 15:43:16 +02001575 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001576 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1578 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1579
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001580 req->handler = zfcp_fsf_close_port_handler;
1581 req->data = erp_action->port;
1582 req->erp_action = erp_action;
1583 req->qtcb->header.port_handle = erp_action->port->handle;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001584 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Christof Schmitt287ac012008-07-02 10:56:40 +02001586 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001587 retval = zfcp_fsf_req_send(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (retval) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001589 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001590 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001592out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001593 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return retval;
1595}
1596
Swen Schillig5ab944f2008-10-01 12:42:17 +02001597static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1598{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001599 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001600 struct fsf_qtcb_header *header = &req->qtcb->header;
1601
1602 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
Christof Schmittbd0072e2009-11-24 16:54:11 +01001603 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001604 goto out;
1605 }
1606
1607 switch (header->fsf_status) {
1608 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1609 dev_warn(&req->adapter->ccw_device->dev,
1610 "Opening WKA port 0x%x failed\n", wka_port->d_id);
Christof Schmittdceab652009-05-15 13:18:18 +02001611 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001612 case FSF_ADAPTER_STATUS_AVAILABLE:
1613 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Christof Schmittdceab652009-05-15 13:18:18 +02001614 /* fall through */
Swen Schillig5ab944f2008-10-01 12:42:17 +02001615 case FSF_ACCESS_DENIED:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001616 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001617 break;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001618 case FSF_GOOD:
1619 wka_port->handle = header->port_handle;
Swen Schillig27f492c2009-07-13 15:06:13 +02001620 /* fall through */
1621 case FSF_PORT_ALREADY_OPEN:
Christof Schmittbd0072e2009-11-24 16:54:11 +01001622 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001623 }
1624out:
1625 wake_up(&wka_port->completion_wq);
1626}
1627
1628/**
1629 * zfcp_fsf_open_wka_port - create and send open wka-port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001630 * @wka_port: pointer to struct zfcp_fc_wka_port
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631 * Returns: 0 on success, error otherwise
1632 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001633int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001634{
1635 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001636 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001637 struct zfcp_fsf_req *req;
1638 int retval = -EIO;
1639
Swen Schillig564e1c82009-08-18 15:43:19 +02001640 spin_lock_bh(&qdio->req_q_lock);
1641 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001642 goto out;
1643
Swen Schillig564e1c82009-08-18 15:43:19 +02001644 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1645 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001646
Swen Schillig5ab944f2008-10-01 12:42:17 +02001647 if (unlikely(IS_ERR(req))) {
1648 retval = PTR_ERR(req);
1649 goto out;
1650 }
1651
Swen Schillig09a46c62009-08-18 15:43:16 +02001652 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001653 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001654 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1655 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1656
1657 req->handler = zfcp_fsf_open_wka_port_handler;
Christof Schmitt800c0ca2009-11-24 16:54:12 +01001658 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001659 req->data = wka_port;
1660
1661 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1662 retval = zfcp_fsf_req_send(req);
1663 if (retval)
1664 zfcp_fsf_req_free(req);
1665out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001666 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001667 return retval;
1668}
1669
1670static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1671{
Christof Schmittbd0072e2009-11-24 16:54:11 +01001672 struct zfcp_fc_wka_port *wka_port = req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001673
1674 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1675 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001676 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001677 }
1678
Christof Schmittbd0072e2009-11-24 16:54:11 +01001679 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001680 wake_up(&wka_port->completion_wq);
1681}
1682
1683/**
1684 * zfcp_fsf_close_wka_port - create and send close wka port request
Christof Schmittbd0072e2009-11-24 16:54:11 +01001685 * @wka_port: WKA port to open
Swen Schillig5ab944f2008-10-01 12:42:17 +02001686 * Returns: 0 on success, error otherwise
1687 */
Christof Schmittbd0072e2009-11-24 16:54:11 +01001688int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001689{
1690 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001691 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
Swen Schillig5ab944f2008-10-01 12:42:17 +02001692 struct zfcp_fsf_req *req;
1693 int retval = -EIO;
1694
Swen Schillig564e1c82009-08-18 15:43:19 +02001695 spin_lock_bh(&qdio->req_q_lock);
1696 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schillig5ab944f2008-10-01 12:42:17 +02001697 goto out;
1698
Swen Schillig564e1c82009-08-18 15:43:19 +02001699 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1700 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001701
Swen Schillig5ab944f2008-10-01 12:42:17 +02001702 if (unlikely(IS_ERR(req))) {
1703 retval = PTR_ERR(req);
1704 goto out;
1705 }
1706
Swen Schillig09a46c62009-08-18 15:43:16 +02001707 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001708 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001709 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1710 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1711
1712 req->handler = zfcp_fsf_close_wka_port_handler;
1713 req->data = wka_port;
1714 req->qtcb->header.port_handle = wka_port->handle;
1715
1716 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1717 retval = zfcp_fsf_req_send(req);
1718 if (retval)
1719 zfcp_fsf_req_free(req);
1720out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001721 spin_unlock_bh(&qdio->req_q_lock);
Swen Schillig5ab944f2008-10-01 12:42:17 +02001722 return retval;
1723}
1724
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001725static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001727 struct zfcp_port *port = req->data;
1728 struct fsf_qtcb_header *header = &req->qtcb->header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001731 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Christof Schmitta5b11dd2009-03-02 13:08:54 +01001732 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 switch (header->fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001736 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001737 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001740 zfcp_fsf_access_denied_port(req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 case FSF_PORT_BOXED:
Christof Schmitt5c815d12008-03-10 16:18:54 +01001743 /* can't use generic zfcp_erp_modify_port_status because
1744 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1745 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001746 read_lock(&port->unit_list_lock);
1747 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt5c815d12008-03-10 16:18:54 +01001748 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1749 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001750 read_unlock(&port->unit_list_lock);
Swen Schilligdfb3cf02009-07-13 15:06:02 +02001751 zfcp_erp_port_boxed(port, "fscpph2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001752 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 switch (header->fsf_status_qual.word[0]) {
1756 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001757 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001759 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 }
1762 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* can't use generic zfcp_erp_modify_port_status because
1765 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1766 */
1767 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001768 read_lock(&port->unit_list_lock);
1769 list_for_each_entry(unit, &port->unit_list, list)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001770 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1771 &unit->status);
Swen Schilligecf0c772009-11-24 16:53:58 +01001772 read_unlock(&port->unit_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001777/**
1778 * zfcp_fsf_close_physical_port - close physical port
1779 * @erp_action: pointer to struct zfcp_erp_action
1780 * Returns: 0 on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001782int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001784 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02001785 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001786 struct zfcp_fsf_req *req;
1787 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Swen Schillig564e1c82009-08-18 15:43:19 +02001789 spin_lock_bh(&qdio->req_q_lock);
1790 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Swen Schillig564e1c82009-08-18 15:43:19 +02001793 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1794 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001795
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001796 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001797 retval = PTR_ERR(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 goto out;
1799 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001800
Swen Schillig09a46c62009-08-18 15:43:16 +02001801 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001802 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001803 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1804 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1805
1806 req->data = erp_action->port;
1807 req->qtcb->header.port_handle = erp_action->port->handle;
1808 req->erp_action = erp_action;
1809 req->handler = zfcp_fsf_close_physical_port_handler;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001810 erp_action->fsf_req_id = req->req_id;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001811
Christof Schmitt287ac012008-07-02 10:56:40 +02001812 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001813 retval = zfcp_fsf_req_send(req);
1814 if (retval) {
1815 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001816 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001817 }
1818out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001819 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 return retval;
1821}
1822
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001823static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001825 struct zfcp_adapter *adapter = req->adapter;
1826 struct zfcp_unit *unit = req->data;
1827 struct fsf_qtcb_header *header = &req->qtcb->header;
1828 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1829 struct fsf_queue_designator *queue_designator =
1830 &header->fsf_status_qual.fsf_queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001831 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001833 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02001834 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02001837 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 ZFCP_STATUS_UNIT_SHARED |
1839 ZFCP_STATUS_UNIT_READONLY,
1840 &unit->status);
1841
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 switch (header->fsf_status) {
1843
1844 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001845 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001846 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 case FSF_ACCESS_DENIED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001850 zfcp_fsf_access_denied_unit(req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02001852 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001855 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01001856 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 case FSF_LUN_SHARING_VIOLATION:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001859 if (header->fsf_status_qual.word[0])
Christof Schmitt553448f2008-06-10 18:20:58 +02001860 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001861 "LUN 0x%Lx on port 0x%Lx is already in "
1862 "use by CSS%d, MIF Image ID %x\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001863 (unsigned long long)unit->fcp_lun,
1864 (unsigned long long)unit->port->wwpn,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001865 queue_designator->cssid,
1866 queue_designator->hla);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001867 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001868 zfcp_act_eval_err(adapter,
1869 header->fsf_status_qual.word[2]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001870 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1872 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001873 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001876 dev_warn(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001877 "No handle is available for LUN "
1878 "0x%016Lx on port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001879 (unsigned long long)unit->fcp_lun,
1880 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001881 zfcp_erp_unit_failed(unit, "fsouh_4", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001882 /* fall through */
1883 case FSF_INVALID_COMMAND_OPTION:
1884 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 switch (header->fsf_status_qual.word[0]) {
1888 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02001889 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001890 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001892 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 }
1895 break;
1896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001900
1901 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1902 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
Christof Schmitt6fcf41d2009-05-15 13:18:21 +02001903 !zfcp_ccw_priv_sch(adapter)) {
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001904 exclusive = (bottom->lun_access_info &
1905 FSF_UNIT_ACCESS_EXCLUSIVE);
1906 readwrite = (bottom->lun_access_info &
1907 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 if (!exclusive)
1910 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1911 &unit->status);
1912
1913 if (!readwrite) {
1914 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1915 &unit->status);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001916 dev_info(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001917 "SCSI device at LUN 0x%016Lx on port "
1918 "0x%016Lx opened read-only\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001919 (unsigned long long)unit->fcp_lun,
1920 (unsigned long long)unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 }
1922
1923 if (exclusive && !readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001924 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001925 "Exclusive read-only access not "
1926 "supported (unit 0x%016Lx, "
1927 "port 0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001928 (unsigned long long)unit->fcp_lun,
1929 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001930 zfcp_erp_unit_failed(unit, "fsouh_5", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001931 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001932 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 } else if (!exclusive && readwrite) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001934 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001935 "Shared read-write access not "
1936 "supported (unit 0x%016Lx, port "
Christof Schmitt27c3f0a2008-12-19 16:56:52 +01001937 "0x%016Lx)\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001938 (unsigned long long)unit->fcp_lun,
1939 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001940 zfcp_erp_unit_failed(unit, "fsouh_7", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001941 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001942 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 }
1944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947}
1948
1949/**
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001950 * zfcp_fsf_open_unit - open unit
1951 * @erp_action: pointer to struct zfcp_erp_action
1952 * Returns: 0 on success, error otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001954int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955{
Swen Schillig44cc76f2008-10-01 12:42:16 +02001956 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001957 struct zfcp_adapter *adapter = erp_action->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02001958 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001959 struct zfcp_fsf_req *req;
1960 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Swen Schillig564e1c82009-08-18 15:43:19 +02001962 spin_lock_bh(&qdio->req_q_lock);
1963 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001964 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Swen Schillig564e1c82009-08-18 15:43:19 +02001966 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
Swen Schilliga4623c42009-08-18 15:43:15 +02001967 adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02001968
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02001969 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001970 retval = PTR_ERR(req);
1971 goto out;
Christof Schmittba172422007-12-20 12:30:26 +01001972 }
1973
Swen Schillig09a46c62009-08-18 15:43:16 +02001974 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01001975 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001976 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1977 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001979 req->qtcb->header.port_handle = erp_action->port->handle;
1980 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1981 req->handler = zfcp_fsf_open_unit_handler;
1982 req->data = erp_action->unit;
1983 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01001984 erp_action->fsf_req_id = req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001985
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001986 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1987 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Christof Schmitt287ac012008-07-02 10:56:40 +02001989 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001990 retval = zfcp_fsf_req_send(req);
1991 if (retval) {
1992 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01001993 erp_action->fsf_req_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001995out:
Swen Schillig564e1c82009-08-18 15:43:19 +02001996 spin_unlock_bh(&qdio->req_q_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 return retval;
1998}
1999
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002000static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002002 struct zfcp_unit *unit = req->data;
2003
2004 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
Swen Schillig44cc76f2008-10-01 12:42:16 +02002005 return;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002006
2007 switch (req->qtcb->header.fsf_status) {
2008 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002009 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002010 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2011 break;
2012 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002013 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002014 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2015 break;
2016 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002017 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002018 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002019 break;
2020 case FSF_ADAPTER_STATUS_AVAILABLE:
2021 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2022 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002023 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002024 /* fall through */
2025 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2026 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2027 break;
2028 }
2029 break;
2030 case FSF_GOOD:
2031 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2032 break;
2033 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002034}
2035
2036/**
2037 * zfcp_fsf_close_unit - close zfcp unit
2038 * @erp_action: pointer to struct zfcp_unit
2039 * Returns: 0 on success, error otherwise
2040 */
2041int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2042{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002043 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002044 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002045 struct zfcp_fsf_req *req;
2046 int retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Swen Schillig564e1c82009-08-18 15:43:19 +02002048 spin_lock_bh(&qdio->req_q_lock);
2049 if (zfcp_fsf_req_sbal_get(qdio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002051
Swen Schillig564e1c82009-08-18 15:43:19 +02002052 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2053 qdio->adapter->pool.erp_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002054
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002055 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002056 retval = PTR_ERR(req);
2057 goto out;
2058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Swen Schillig09a46c62009-08-18 15:43:16 +02002060 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002061 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002062 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2064
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002065 req->qtcb->header.port_handle = erp_action->port->handle;
2066 req->qtcb->header.lun_handle = erp_action->unit->handle;
2067 req->handler = zfcp_fsf_close_unit_handler;
2068 req->data = erp_action->unit;
2069 req->erp_action = erp_action;
Christof Schmitte60a6d62010-02-17 11:18:49 +01002070 erp_action->fsf_req_id = req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Christof Schmitt287ac012008-07-02 10:56:40 +02002072 zfcp_fsf_start_erp_timer(req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002073 retval = zfcp_fsf_req_send(req);
2074 if (retval) {
2075 zfcp_fsf_req_free(req);
Christof Schmitte60a6d62010-02-17 11:18:49 +01002076 erp_action->fsf_req_id = 0;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002077 }
2078out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002079 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002080 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
Christof Schmittc9615852008-05-06 11:00:05 +02002083static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2084{
2085 lat_rec->sum += lat;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002086 lat_rec->min = min(lat_rec->min, lat);
2087 lat_rec->max = max(lat_rec->max, lat);
Christof Schmittc9615852008-05-06 11:00:05 +02002088}
2089
Christof Schmittd9742b42009-11-24 16:54:03 +01002090static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
Christof Schmittc9615852008-05-06 11:00:05 +02002091{
Christof Schmittd9742b42009-11-24 16:54:03 +01002092 struct fsf_qual_latency_info *lat_in;
2093 struct latency_cont *lat = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002094 struct zfcp_unit *unit = req->unit;
Christof Schmittd9742b42009-11-24 16:54:03 +01002095 struct zfcp_blk_drv_data blktrc;
2096 int ticks = req->adapter->timer_ticks;
Christof Schmittc9615852008-05-06 11:00:05 +02002097
Christof Schmittd9742b42009-11-24 16:54:03 +01002098 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
Christof Schmittc9615852008-05-06 11:00:05 +02002099
Christof Schmittd9742b42009-11-24 16:54:03 +01002100 blktrc.flags = 0;
2101 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2102 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2103 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
Christof Schmitt34c2b712010-02-17 11:18:59 +01002104 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2105 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
Christof Schmittd9742b42009-11-24 16:54:03 +01002106
2107 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2108 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2109 blktrc.channel_lat = lat_in->channel_lat * ticks;
2110 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2111
2112 switch (req->qtcb->bottom.io.data_direction) {
2113 case FSF_DATADIR_READ:
2114 lat = &unit->latencies.read;
2115 break;
2116 case FSF_DATADIR_WRITE:
2117 lat = &unit->latencies.write;
2118 break;
2119 case FSF_DATADIR_CMND:
2120 lat = &unit->latencies.cmd;
2121 break;
2122 }
2123
2124 if (lat) {
2125 spin_lock(&unit->latencies.lock);
2126 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2127 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2128 lat->counter++;
2129 spin_unlock(&unit->latencies.lock);
2130 }
Christof Schmittc9615852008-05-06 11:00:05 +02002131 }
2132
Christof Schmittd9742b42009-11-24 16:54:03 +01002133 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2134 sizeof(blktrc));
Christof Schmittc9615852008-05-06 11:00:05 +02002135}
2136
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002137static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002139 struct scsi_cmnd *scpnt;
Christof Schmitt4318e082009-11-24 16:54:08 +01002140 struct fcp_resp_with_ext *fcp_rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002143 read_lock_irqsave(&req->adapter->abort_lock, flags);
2144
Swen Schillig0ac55aa2008-11-26 18:07:39 +01002145 scpnt = req->data;
2146 if (unlikely(!scpnt)) {
2147 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2148 return;
2149 }
2150
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002151 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Christof Schmitt4c571c62009-11-24 16:54:15 +01002152 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 goto skip_fsfstatus;
2154 }
2155
Christof Schmitt4318e082009-11-24 16:54:08 +01002156 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2157 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Christof Schmittd9742b42009-11-24 16:54:03 +01002159 zfcp_fsf_req_trace(req, scpnt);
Stefan Raspl0997f1c2008-10-16 08:23:39 +02002160
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002161skip_fsfstatus:
Christof Schmittab725282010-02-17 11:18:57 +01002162 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 (scpnt->scsi_done) (scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 /*
2167 * We must hold this lock until scsi_done has been called.
2168 * Otherwise we may call scsi_done after abort regarding this
2169 * command has completed.
2170 * Note: scsi_done must not block!
2171 */
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002172 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002175static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
Christof Schmitt4318e082009-11-24 16:54:08 +01002177 struct fcp_resp_with_ext *fcp_rsp;
2178 struct fcp_resp_rsp_info *rsp_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Christof Schmitt4318e082009-11-24 16:54:08 +01002180 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2181 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2182
2183 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002184 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2185 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002189static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2190{
2191 struct zfcp_unit *unit;
2192 struct fsf_qtcb_header *header = &req->qtcb->header;
2193
2194 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2195 unit = req->data;
2196 else
2197 unit = req->unit;
2198
2199 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2200 goto skip_fsfstatus;
2201
2202 switch (header->fsf_status) {
2203 case FSF_HANDLE_MISMATCH:
2204 case FSF_PORT_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002205 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002206 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2207 break;
2208 case FSF_FCPLUN_NOT_VALID:
2209 case FSF_LUN_HANDLE_NOT_VALID:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002210 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002211 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2212 break;
2213 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2214 zfcp_fsf_class_not_supp(req);
2215 break;
2216 case FSF_ACCESS_DENIED:
2217 zfcp_fsf_access_denied_unit(req, unit);
2218 break;
2219 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2220 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002221 "Incorrect direction %d, unit 0x%016Lx on port "
2222 "0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002223 req->qtcb->bottom.io.data_direction,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002224 (unsigned long long)unit->fcp_lun,
2225 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002226 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2227 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002228 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2229 break;
2230 case FSF_CMND_LENGTH_NOT_VALID:
2231 dev_err(&req->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002232 "Incorrect CDB length %d, unit 0x%016Lx on "
2233 "port 0x%016Lx closed\n",
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002234 req->qtcb->bottom.io.fcp_cmnd_length,
Swen Schillig7ba58c92008-10-01 12:42:18 +02002235 (unsigned long long)unit->fcp_lun,
2236 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002237 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2238 req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002239 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2240 break;
2241 case FSF_PORT_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002242 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002243 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002244 break;
2245 case FSF_LUN_BOXED:
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002246 zfcp_erp_unit_boxed(unit, "fssfch6", req);
Christof Schmitt4c571c62009-11-24 16:54:15 +01002247 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002248 break;
2249 case FSF_ADAPTER_STATUS_AVAILABLE:
2250 if (header->fsf_status_qual.word[0] ==
2251 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
Swen Schillig6f53a2d2009-08-18 15:43:23 +02002252 zfcp_fc_test_link(unit->port);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002253 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2254 break;
2255 }
2256skip_fsfstatus:
2257 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2258 zfcp_fsf_send_fcp_ctm_handler(req);
2259 else {
2260 zfcp_fsf_send_fcp_command_task_handler(req);
2261 req->unit = NULL;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002262 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002263 }
2264}
2265
2266/**
2267 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002268 * @unit: unit where command is sent to
2269 * @scsi_cmnd: scsi command to be sent
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002270 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002271int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2272 struct scsi_cmnd *scsi_cmnd)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002273{
2274 struct zfcp_fsf_req *req;
Christof Schmitt4318e082009-11-24 16:54:08 +01002275 struct fcp_cmnd *fcp_cmnd;
Christof Schmittbc90c862009-05-15 13:18:17 +02002276 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002277 int real_bytes, retval = -EIO;
Christof Schmitt63caf362009-03-02 13:09:00 +01002278 struct zfcp_adapter *adapter = unit->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +02002279 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002280
2281 if (unlikely(!(atomic_read(&unit->status) &
2282 ZFCP_STATUS_COMMON_UNBLOCKED)))
2283 return -EBUSY;
2284
Swen Schillig564e1c82009-08-18 15:43:19 +02002285 spin_lock(&qdio->req_q_lock);
2286 if (atomic_read(&qdio->req_q.count) <= 0) {
2287 atomic_inc(&qdio->req_q_full);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002288 goto out;
Christof Schmitt8fdf30d2009-03-02 13:09:01 +01002289 }
Swen Schillig09a46c62009-08-18 15:43:16 +02002290
Swen Schillig564e1c82009-08-18 15:43:19 +02002291 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
Swen Schilliga4623c42009-08-18 15:43:15 +02002292 adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002293
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002294 if (IS_ERR(req)) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002295 retval = PTR_ERR(req);
2296 goto out;
2297 }
2298
Swen Schillig09a46c62009-08-18 15:43:16 +02002299 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
Christof Schmitt615f59e2010-02-17 11:18:56 +01002300 get_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002301 req->unit = unit;
2302 req->data = scsi_cmnd;
2303 req->handler = zfcp_fsf_send_fcp_command_handler;
2304 req->qtcb->header.lun_handle = unit->handle;
2305 req->qtcb->header.port_handle = unit->port->handle;
2306 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002307 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002308
2309 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2310
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002311 /*
2312 * set depending on data direction:
2313 * data direction bits in SBALE (SB Type)
2314 * data direction bits in QTCB
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002315 */
2316 switch (scsi_cmnd->sc_data_direction) {
2317 case DMA_NONE:
2318 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002319 break;
2320 case DMA_FROM_DEVICE:
2321 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002322 break;
2323 case DMA_TO_DEVICE:
2324 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2325 sbtype = SBAL_FLAGS0_TYPE_WRITE;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002326 break;
2327 case DMA_BIDIRECTIONAL:
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002328 goto failed_scsi_cmnd;
2329 }
2330
Christof Schmitt4318e082009-11-24 16:54:08 +01002331 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2332 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002333
Christof Schmitt34c2b712010-02-17 11:18:59 +01002334 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sbtype,
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002335 scsi_sglist(scsi_cmnd),
2336 FSF_MAX_SBALS_PER_REQ);
2337 if (unlikely(real_bytes < 0)) {
Christof Schmitt34c2b712010-02-17 11:18:59 +01002338 if (req->qdio_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002339 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02002340 "Oversize data package, unit 0x%016Lx "
2341 "on port 0x%016Lx closed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02002342 (unsigned long long)unit->fcp_lun,
2343 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01002344 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002345 retval = -EINVAL;
2346 }
2347 goto failed_scsi_cmnd;
2348 }
2349
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002350 retval = zfcp_fsf_req_send(req);
2351 if (unlikely(retval))
2352 goto failed_scsi_cmnd;
2353
2354 goto out;
2355
2356failed_scsi_cmnd:
Christof Schmitt615f59e2010-02-17 11:18:56 +01002357 put_device(&unit->dev);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002358 zfcp_fsf_req_free(req);
2359 scsi_cmnd->host_scribble = NULL;
2360out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002361 spin_unlock(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002362 return retval;
2363}
2364
2365/**
2366 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002367 * @unit: pointer to struct zfcp_unit
2368 * @tm_flags: unsigned byte for task management flags
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002369 * Returns: on success pointer to struct fsf_req, NULL otherwise
2370 */
Christof Schmitt63caf362009-03-02 13:09:00 +01002371struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002372{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002373 struct qdio_buffer_element *sbale;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002374 struct zfcp_fsf_req *req = NULL;
Christof Schmitt4318e082009-11-24 16:54:08 +01002375 struct fcp_cmnd *fcp_cmnd;
Swen Schillig564e1c82009-08-18 15:43:19 +02002376 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002377
2378 if (unlikely(!(atomic_read(&unit->status) &
2379 ZFCP_STATUS_COMMON_UNBLOCKED)))
2380 return NULL;
2381
Swen Schillig564e1c82009-08-18 15:43:19 +02002382 spin_lock_bh(&qdio->req_q_lock);
2383 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002384 goto out;
Swen Schillig09a46c62009-08-18 15:43:16 +02002385
Swen Schillig564e1c82009-08-18 15:43:19 +02002386 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2387 qdio->adapter->pool.scsi_req);
Swen Schillig09a46c62009-08-18 15:43:16 +02002388
Swen Schillig633528c2008-11-26 18:07:37 +01002389 if (IS_ERR(req)) {
2390 req = NULL;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002391 goto out;
Swen Schillig633528c2008-11-26 18:07:37 +01002392 }
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002393
2394 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2395 req->data = unit;
2396 req->handler = zfcp_fsf_send_fcp_command_handler;
2397 req->qtcb->header.lun_handle = unit->handle;
2398 req->qtcb->header.port_handle = unit->port->handle;
2399 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2400 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
Christof Schmitt4318e082009-11-24 16:54:08 +01002401 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002402
Christof Schmitt34c2b712010-02-17 11:18:59 +01002403 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002404 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2405 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2406
Christof Schmitt4318e082009-11-24 16:54:08 +01002407 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2408 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002409
2410 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2411 if (!zfcp_fsf_req_send(req))
2412 goto out;
2413
2414 zfcp_fsf_req_free(req);
2415 req = NULL;
2416out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002417 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002418 return req;
2419}
2420
2421static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2422{
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002423}
2424
2425/**
2426 * zfcp_fsf_control_file - control file upload/download
2427 * @adapter: pointer to struct zfcp_adapter
2428 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2429 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02002431struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2432 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Swen Schillig44cc76f2008-10-01 12:42:16 +02002434 struct qdio_buffer_element *sbale;
Swen Schillig564e1c82009-08-18 15:43:19 +02002435 struct zfcp_qdio *qdio = adapter->qdio;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002436 struct zfcp_fsf_req *req = NULL;
2437 struct fsf_qtcb_bottom_support *bottom;
2438 int direction, retval = -EIO, bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Christof Schmitt45633fd2008-06-10 18:20:55 +02002440 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2441 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Christof Schmitt45633fd2008-06-10 18:20:55 +02002443 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2445 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2448 direction = SBAL_FLAGS0_TYPE_READ;
2449 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02002451 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 }
2453
Swen Schillig564e1c82009-08-18 15:43:19 +02002454 spin_lock_bh(&qdio->req_q_lock);
2455 if (zfcp_fsf_req_sbal_get(qdio))
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002456 goto out;
2457
Swen Schillig564e1c82009-08-18 15:43:19 +02002458 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
Hirofumi Nakagawa025270f2008-08-21 13:43:37 +02002459 if (IS_ERR(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 retval = -EPERM;
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002461 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002464 req->handler = zfcp_fsf_control_file_handler;
2465
Christof Schmitt34c2b712010-02-17 11:18:59 +01002466 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 sbale[0].flags |= direction;
2468
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002469 bottom = &req->qtcb->bottom.support;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002471 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
Christof Schmitt34c2b712010-02-17 11:18:59 +01002473 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
Swen Schillig564e1c82009-08-18 15:43:19 +02002474 direction, fsf_cfdc->sg,
2475 FSF_MAX_SBALS_PER_REQ);
Christof Schmitt45633fd2008-06-10 18:20:55 +02002476 if (bytes != ZFCP_CFDC_MAX_SIZE) {
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002477 zfcp_fsf_req_free(req);
2478 goto out;
Christof Schmitt45633fd2008-06-10 18:20:55 +02002479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002481 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2482 retval = zfcp_fsf_req_send(req);
2483out:
Swen Schillig564e1c82009-08-18 15:43:19 +02002484 spin_unlock_bh(&qdio->req_q_lock);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002485
2486 if (!retval) {
Swen Schillig058b8642009-08-18 15:43:14 +02002487 wait_for_completion(&req->completion);
Swen Schilligc41f8cb2008-07-02 10:56:39 +02002488 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 }
Christof Schmitt45633fd2008-06-10 18:20:55 +02002490 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491}
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002492
2493/**
2494 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2495 * @adapter: pointer to struct zfcp_adapter
2496 * @sbal_idx: response queue index of SBAL to be processed
2497 */
Swen Schillig564e1c82009-08-18 15:43:19 +02002498void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002499{
Swen Schillig564e1c82009-08-18 15:43:19 +02002500 struct zfcp_adapter *adapter = qdio->adapter;
2501 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002502 struct qdio_buffer_element *sbale;
2503 struct zfcp_fsf_req *fsf_req;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002504 unsigned long req_id;
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002505 int idx;
2506
2507 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2508
2509 sbale = &sbal->element[idx];
2510 req_id = (unsigned long) sbale->addr;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +01002511 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002512
2513 if (!fsf_req)
2514 /*
2515 * Unknown request means that we have potentially memory
2516 * corruption and must stop the machine immediately.
2517 */
2518 panic("error: unknown req_id (%lx) on adapter %s.\n",
2519 req_id, dev_name(&adapter->ccw_device->dev));
2520
Christof Schmitt34c2b712010-02-17 11:18:59 +01002521 fsf_req->qdio_req.sbal_response = sbal_idx;
2522 fsf_req->qdio_req.qdio_inb_usage =
Swen Schillig564e1c82009-08-18 15:43:19 +02002523 atomic_read(&qdio->resp_q.count);
Swen Schilligbd63eaf2009-08-18 15:43:13 +02002524 zfcp_fsf_req_complete(fsf_req);
2525
2526 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2527 break;
2528 }
2529}