blob: bc0c9f54d0d8b06c73e0d9ce7eabbbd3f4f07c37 [file] [log] [blame]
Christof Schmitt24073b42008-06-10 18:20:54 +02001/*
2 * zfcp device driver
3 *
4 * Fibre Channel related functions for the zfcp device driver.
5 *
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2008, 2009
Christof Schmitt24073b42008-06-10 18:20:54 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Christof Schmitt24073b42008-06-10 18:20:54 +020012#include "zfcp_ext.h"
13
Christof Schmitte0d7fcb2008-12-19 16:56:58 +010014enum rscn_address_format {
15 RSCN_PORT_ADDRESS = 0x0,
16 RSCN_AREA_ADDRESS = 0x1,
17 RSCN_DOMAIN_ADDRESS = 0x2,
18 RSCN_FABRIC_ADDRESS = 0x3,
19};
20
21static u32 rscn_range_mask[] = {
22 [RSCN_PORT_ADDRESS] = 0xFFFFFF,
23 [RSCN_AREA_ADDRESS] = 0xFFFF00,
24 [RSCN_DOMAIN_ADDRESS] = 0xFF0000,
25 [RSCN_FABRIC_ADDRESS] = 0x000000,
26};
27
Swen Schilligcc8c2822008-06-10 18:21:00 +020028struct gpn_ft_resp_acc {
29 u8 control;
30 u8 port_id[3];
31 u8 reserved[4];
32 u64 wwpn;
33} __attribute__ ((packed));
34
Christof Schmitt39eb7e92008-12-19 16:57:01 +010035#define ZFCP_CT_SIZE_ONE_PAGE (PAGE_SIZE - sizeof(struct ct_hdr))
36#define ZFCP_GPN_FT_ENTRIES (ZFCP_CT_SIZE_ONE_PAGE \
37 / sizeof(struct gpn_ft_resp_acc))
Swen Schilligcc8c2822008-06-10 18:21:00 +020038#define ZFCP_GPN_FT_BUFFERS 4
Christof Schmitt39eb7e92008-12-19 16:57:01 +010039#define ZFCP_GPN_FT_MAX_SIZE (ZFCP_GPN_FT_BUFFERS * PAGE_SIZE \
40 - sizeof(struct ct_hdr))
Swen Schilligcc8c2822008-06-10 18:21:00 +020041#define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1)
42
43struct ct_iu_gpn_ft_resp {
44 struct ct_hdr header;
45 struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES];
46} __attribute__ ((packed));
47
48struct zfcp_gpn_ft {
49 struct zfcp_send_ct ct;
50 struct scatterlist sg_req;
51 struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS];
52};
53
Swen Schillig5ab944f2008-10-01 12:42:17 +020054struct zfcp_fc_ns_handler_data {
55 struct completion done;
56 void (*handler)(unsigned long);
57 unsigned long handler_data;
58};
59
60static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port)
61{
62 if (mutex_lock_interruptible(&wka_port->mutex))
63 return -ERESTARTSYS;
64
Christof Schmitt1c1cba12008-11-26 18:07:36 +010065 if (wka_port->status == ZFCP_WKA_PORT_OFFLINE ||
66 wka_port->status == ZFCP_WKA_PORT_CLOSING) {
Swen Schillig5ab944f2008-10-01 12:42:17 +020067 wka_port->status = ZFCP_WKA_PORT_OPENING;
68 if (zfcp_fsf_open_wka_port(wka_port))
69 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
70 }
71
72 mutex_unlock(&wka_port->mutex);
73
Swen Schillig27f492c2009-07-13 15:06:13 +020074 wait_event(wka_port->completion_wq,
75 wka_port->status == ZFCP_WKA_PORT_ONLINE ||
76 wka_port->status == ZFCP_WKA_PORT_OFFLINE);
Swen Schillig5ab944f2008-10-01 12:42:17 +020077
78 if (wka_port->status == ZFCP_WKA_PORT_ONLINE) {
79 atomic_inc(&wka_port->refcount);
80 return 0;
81 }
82 return -EIO;
83}
84
85static void zfcp_wka_port_offline(struct work_struct *work)
86{
Jean Delvarebf6aede2009-04-02 16:56:54 -070087 struct delayed_work *dw = to_delayed_work(work);
Swen Schillig5ab944f2008-10-01 12:42:17 +020088 struct zfcp_wka_port *wka_port =
89 container_of(dw, struct zfcp_wka_port, work);
90
Swen Schillig5ab944f2008-10-01 12:42:17 +020091 mutex_lock(&wka_port->mutex);
92 if ((atomic_read(&wka_port->refcount) != 0) ||
93 (wka_port->status != ZFCP_WKA_PORT_ONLINE))
94 goto out;
95
96 wka_port->status = ZFCP_WKA_PORT_CLOSING;
97 if (zfcp_fsf_close_wka_port(wka_port)) {
98 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
99 wake_up(&wka_port->completion_wq);
100 }
101out:
102 mutex_unlock(&wka_port->mutex);
103}
104
105static void zfcp_wka_port_put(struct zfcp_wka_port *wka_port)
106{
107 if (atomic_dec_return(&wka_port->refcount) != 0)
108 return;
Martin Olsson19af5cd2009-04-23 11:37:37 +0200109 /* wait 10 milliseconds, other reqs might pop in */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200110 schedule_delayed_work(&wka_port->work, HZ / 100);
111}
112
Sven Schuetz9d544f22009-04-06 18:31:47 +0200113static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id,
114 struct zfcp_adapter *adapter)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200115{
Swen Schillig5ab944f2008-10-01 12:42:17 +0200116 init_waitqueue_head(&wka_port->completion_wq);
117
118 wka_port->adapter = adapter;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200119 wka_port->d_id = d_id;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200120
121 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
122 atomic_set(&wka_port->refcount, 0);
123 mutex_init(&wka_port->mutex);
124 INIT_DELAYED_WORK(&wka_port->work, zfcp_wka_port_offline);
125}
126
Christof Schmitt55c770f2009-08-18 15:43:12 +0200127static void zfcp_fc_wka_port_force_offline(struct zfcp_wka_port *wka)
Swen Schillig828bc122009-04-17 15:08:05 +0200128{
129 cancel_delayed_work_sync(&wka->work);
130 mutex_lock(&wka->mutex);
131 wka->status = ZFCP_WKA_PORT_OFFLINE;
132 mutex_unlock(&wka->mutex);
133}
134
Christof Schmitt55c770f2009-08-18 15:43:12 +0200135void zfcp_fc_wka_ports_force_offline(struct zfcp_wka_ports *gs)
136{
137 zfcp_fc_wka_port_force_offline(&gs->ms);
138 zfcp_fc_wka_port_force_offline(&gs->ts);
139 zfcp_fc_wka_port_force_offline(&gs->ds);
140 zfcp_fc_wka_port_force_offline(&gs->as);
141 zfcp_fc_wka_port_force_offline(&gs->ks);
142}
143
Sven Schuetz9d544f22009-04-06 18:31:47 +0200144void zfcp_fc_wka_ports_init(struct zfcp_adapter *adapter)
145{
146 struct zfcp_wka_ports *gs = adapter->gs;
147
148 zfcp_fc_wka_port_init(&gs->ms, FC_FID_MGMT_SERV, adapter);
149 zfcp_fc_wka_port_init(&gs->ts, FC_FID_TIME_SERV, adapter);
150 zfcp_fc_wka_port_init(&gs->ds, FC_FID_DIR_SERV, adapter);
151 zfcp_fc_wka_port_init(&gs->as, FC_FID_ALIASES, adapter);
152 zfcp_fc_wka_port_init(&gs->ks, FC_FID_SEC_KEY, adapter);
153}
154
Christof Schmitt24073b42008-06-10 18:20:54 +0200155static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range,
156 struct fcp_rscn_element *elem)
157{
158 unsigned long flags;
159 struct zfcp_port *port;
160
161 read_lock_irqsave(&zfcp_data.config_lock, flags);
Swen Schilligea460a82009-05-15 13:18:20 +0200162 list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) {
Swen Schillig24095492009-03-02 13:09:07 +0100163 if ((port->d_id & range) == (elem->nport_did & range))
Christof Schmitt24073b42008-06-10 18:20:54 +0200164 zfcp_test_link(port);
Swen Schilligea460a82009-05-15 13:18:20 +0200165 if (!port->d_id)
166 zfcp_erp_port_reopen(port,
167 ZFCP_STATUS_COMMON_ERP_FAILED,
168 "fcrscn1", NULL);
169 }
Swen Schillig24095492009-03-02 13:09:07 +0100170
Christof Schmitt24073b42008-06-10 18:20:54 +0200171 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
172}
173
174static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req)
175{
176 struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data;
177 struct fcp_rscn_head *fcp_rscn_head;
178 struct fcp_rscn_element *fcp_rscn_element;
179 u16 i;
180 u16 no_entries;
181 u32 range_mask;
182
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200183 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data;
184 fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head;
Christof Schmitt24073b42008-06-10 18:20:54 +0200185
186 /* see FC-FS */
187 no_entries = fcp_rscn_head->payload_len /
188 sizeof(struct fcp_rscn_element);
189
190 for (i = 1; i < no_entries; i++) {
191 /* skip head and start with 1st element */
192 fcp_rscn_element++;
Christof Schmitte0d7fcb2008-12-19 16:56:58 +0100193 range_mask = rscn_range_mask[fcp_rscn_element->addr_format];
Christof Schmitt24073b42008-06-10 18:20:54 +0200194 _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element);
195 }
Swen Schilligcc8c2822008-06-10 18:21:00 +0200196 schedule_work(&fsf_req->adapter->scan_work);
Christof Schmitt24073b42008-06-10 18:20:54 +0200197}
198
Swen Schillig7ba58c92008-10-01 12:42:18 +0200199static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn)
Christof Schmitt24073b42008-06-10 18:20:54 +0200200{
201 struct zfcp_adapter *adapter = req->adapter;
202 struct zfcp_port *port;
203 unsigned long flags;
204
205 read_lock_irqsave(&zfcp_data.config_lock, flags);
206 list_for_each_entry(port, &adapter->port_list_head, list)
207 if (port->wwpn == wwpn)
208 break;
209 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
210
211 if (port && (port->wwpn == wwpn))
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100212 zfcp_erp_port_forced_reopen(port, 0, "fciwwp1", req);
Christof Schmitt24073b42008-06-10 18:20:54 +0200213}
214
215static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req)
216{
217 struct fsf_status_read_buffer *status_buffer =
218 (struct fsf_status_read_buffer *)req->data;
219 struct fsf_plogi *els_plogi =
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200220 (struct fsf_plogi *) status_buffer->payload.data;
Christof Schmitt24073b42008-06-10 18:20:54 +0200221
222 zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn);
223}
224
225static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req)
226{
227 struct fsf_status_read_buffer *status_buffer =
228 (struct fsf_status_read_buffer *)req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200229 struct fcp_logo *els_logo =
230 (struct fcp_logo *) status_buffer->payload.data;
Christof Schmitt24073b42008-06-10 18:20:54 +0200231
232 zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn);
233}
234
235/**
236 * zfcp_fc_incoming_els - handle incoming ELS
237 * @fsf_req - request which contains incoming ELS
238 */
239void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req)
240{
241 struct fsf_status_read_buffer *status_buffer =
242 (struct fsf_status_read_buffer *) fsf_req->data;
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200243 unsigned int els_type = status_buffer->payload.data[0];
Christof Schmitt24073b42008-06-10 18:20:54 +0200244
245 zfcp_san_dbf_event_incoming_els(fsf_req);
246 if (els_type == LS_PLOGI)
247 zfcp_fc_incoming_plogi(fsf_req);
248 else if (els_type == LS_LOGO)
249 zfcp_fc_incoming_logo(fsf_req);
250 else if (els_type == LS_RSCN)
251 zfcp_fc_incoming_rscn(fsf_req);
252}
253
Swen Schillig5ab944f2008-10-01 12:42:17 +0200254static void zfcp_fc_ns_handler(unsigned long data)
255{
256 struct zfcp_fc_ns_handler_data *compl_rec =
257 (struct zfcp_fc_ns_handler_data *) data;
258
259 if (compl_rec->handler)
260 compl_rec->handler(compl_rec->handler_data);
261
262 complete(&compl_rec->done);
263}
264
265static void zfcp_fc_ns_gid_pn_eval(unsigned long data)
Christof Schmitt24073b42008-06-10 18:20:54 +0200266{
267 struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data;
268 struct zfcp_send_ct *ct = &gid_pn->ct;
269 struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req);
270 struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp);
271 struct zfcp_port *port = gid_pn->port;
272
273 if (ct->status)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200274 return;
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100275 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200276 return;
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100277
Christof Schmitt24073b42008-06-10 18:20:54 +0200278 /* paranoia */
279 if (ct_iu_req->wwpn != port->wwpn)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200280 return;
Christof Schmitt24073b42008-06-10 18:20:54 +0200281 /* looks like a valid d_id */
282 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
Christof Schmitt24073b42008-06-10 18:20:54 +0200283}
284
Christof Schmitt799b76d2009-08-18 15:43:20 +0200285static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port,
Swen Schillig5ab944f2008-10-01 12:42:17 +0200286 struct zfcp_gid_pn_data *gid_pn)
Christof Schmitt24073b42008-06-10 18:20:54 +0200287{
Christof Schmitt799b76d2009-08-18 15:43:20 +0200288 struct zfcp_adapter *adapter = port->adapter;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200289 struct zfcp_fc_ns_handler_data compl_rec;
290 int ret;
Christof Schmitt24073b42008-06-10 18:20:54 +0200291
292 /* setup parameters for send generic command */
Christof Schmitt799b76d2009-08-18 15:43:20 +0200293 gid_pn->port = port;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200294 gid_pn->ct.wka_port = &adapter->gs->ds;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200295 gid_pn->ct.handler = zfcp_fc_ns_handler;
296 gid_pn->ct.handler_data = (unsigned long) &compl_rec;
Christof Schmitt24073b42008-06-10 18:20:54 +0200297 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
298 gid_pn->ct.req = &gid_pn->req;
299 gid_pn->ct.resp = &gid_pn->resp;
Christof Schmitt24073b42008-06-10 18:20:54 +0200300 sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req,
301 sizeof(struct ct_iu_gid_pn_req));
302 sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp,
303 sizeof(struct ct_iu_gid_pn_resp));
304
305 /* setup nameserver request */
306 gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION;
307 gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
308 gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER;
309 gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS;
310 gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN;
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100311 gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_SIZE_ONE_PAGE / 4;
Christof Schmitt799b76d2009-08-18 15:43:20 +0200312 gid_pn->ct_iu_req.wwpn = port->wwpn;
Christof Schmitt24073b42008-06-10 18:20:54 +0200313
Swen Schillig5ab944f2008-10-01 12:42:17 +0200314 init_completion(&compl_rec.done);
315 compl_rec.handler = zfcp_fc_ns_gid_pn_eval;
316 compl_rec.handler_data = (unsigned long) gid_pn;
Christof Schmitt799b76d2009-08-18 15:43:20 +0200317 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.gid_pn_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200318 if (!ret)
319 wait_for_completion(&compl_rec.done);
320 return ret;
321}
322
323/**
324 * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request
Christof Schmitt799b76d2009-08-18 15:43:20 +0200325 * @port: port where GID_PN request is needed
Swen Schillig5ab944f2008-10-01 12:42:17 +0200326 * return: -ENOMEM on error, 0 otherwise
327 */
Christof Schmitt799b76d2009-08-18 15:43:20 +0200328static int zfcp_fc_ns_gid_pn(struct zfcp_port *port)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200329{
330 int ret;
331 struct zfcp_gid_pn_data *gid_pn;
Christof Schmitt799b76d2009-08-18 15:43:20 +0200332 struct zfcp_adapter *adapter = port->adapter;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200333
Swen Schilliga4623c42009-08-18 15:43:15 +0200334 gid_pn = mempool_alloc(adapter->pool.gid_pn_data, GFP_ATOMIC);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200335 if (!gid_pn)
336 return -ENOMEM;
337
338 memset(gid_pn, 0, sizeof(*gid_pn));
339
Sven Schuetz9d544f22009-04-06 18:31:47 +0200340 ret = zfcp_wka_port_get(&adapter->gs->ds);
Christof Schmitt24073b42008-06-10 18:20:54 +0200341 if (ret)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200342 goto out;
343
Christof Schmitt799b76d2009-08-18 15:43:20 +0200344 ret = zfcp_fc_ns_gid_pn_request(port, gid_pn);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200345
Sven Schuetz9d544f22009-04-06 18:31:47 +0200346 zfcp_wka_port_put(&adapter->gs->ds);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200347out:
Swen Schilliga4623c42009-08-18 15:43:15 +0200348 mempool_free(gid_pn, adapter->pool.gid_pn_data);
Christof Schmitt24073b42008-06-10 18:20:54 +0200349 return ret;
350}
351
Christof Schmitt799b76d2009-08-18 15:43:20 +0200352void zfcp_fc_port_did_lookup(struct work_struct *work)
353{
354 int ret;
355 struct zfcp_port *port = container_of(work, struct zfcp_port,
356 gid_pn_work);
357
358 ret = zfcp_fc_ns_gid_pn(port);
359 if (ret) {
360 /* could not issue gid_pn for some reason */
361 zfcp_erp_adapter_reopen(port->adapter, 0, "fcgpn_1", NULL);
362 goto out;
363 }
364
365 if (!port->d_id) {
366 zfcp_erp_port_failed(port, "fcgpn_2", NULL);
367 goto out;
368 }
369
370 zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL);
371out:
372 zfcp_port_put(port);
373}
374
Christof Schmitt24073b42008-06-10 18:20:54 +0200375/**
376 * zfcp_fc_plogi_evaluate - evaluate PLOGI playload
377 * @port: zfcp_port structure
378 * @plogi: plogi payload
379 *
380 * Evaluate PLOGI playload and copy important fields into zfcp_port structure
381 */
382void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi)
383{
384 port->maxframe_size = plogi->serv_param.common_serv_param[7] |
385 ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8);
386 if (plogi->serv_param.class1_serv_param[0] & 0x80)
387 port->supported_classes |= FC_COS_CLASS1;
388 if (plogi->serv_param.class2_serv_param[0] & 0x80)
389 port->supported_classes |= FC_COS_CLASS2;
390 if (plogi->serv_param.class3_serv_param[0] & 0x80)
391 port->supported_classes |= FC_COS_CLASS3;
392 if (plogi->serv_param.class4_serv_param[0] & 0x80)
393 port->supported_classes |= FC_COS_CLASS4;
394}
395
396struct zfcp_els_adisc {
397 struct zfcp_send_els els;
398 struct scatterlist req;
399 struct scatterlist resp;
400 struct zfcp_ls_adisc ls_adisc;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200401 struct zfcp_ls_adisc ls_adisc_acc;
Christof Schmitt24073b42008-06-10 18:20:54 +0200402};
403
404static void zfcp_fc_adisc_handler(unsigned long data)
405{
406 struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data;
407 struct zfcp_port *port = adisc->els.port;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200408 struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc;
Christof Schmitt24073b42008-06-10 18:20:54 +0200409
Christof Schmitt3968ce82008-07-02 10:56:32 +0200410 if (adisc->els.status) {
Christof Schmitt24073b42008-06-10 18:20:54 +0200411 /* request rejected or timed out */
Swen Schillig5b43e712009-04-17 15:08:10 +0200412 zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
413 "fcadh_1", NULL);
Christof Schmitt24073b42008-06-10 18:20:54 +0200414 goto out;
415 }
416
417 if (!port->wwnn)
418 port->wwnn = ls_adisc->wwnn;
419
Swen Schillig24095492009-03-02 13:09:07 +0100420 if ((port->wwpn != ls_adisc->wwpn) ||
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100421 !(atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)) {
Swen Schillig24095492009-03-02 13:09:07 +0100422 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
423 "fcadh_2", NULL);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100424 goto out;
425 }
Christof Schmitt24073b42008-06-10 18:20:54 +0200426
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100427 /* port is good, unblock rport without going through erp */
428 zfcp_scsi_schedule_rport_register(port);
Christof Schmitt24073b42008-06-10 18:20:54 +0200429 out:
Christof Schmitt14e242e2009-08-18 15:43:11 +0200430 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
Christof Schmitt24073b42008-06-10 18:20:54 +0200431 zfcp_port_put(port);
432 kfree(adisc);
433}
434
435static int zfcp_fc_adisc(struct zfcp_port *port)
436{
437 struct zfcp_els_adisc *adisc;
438 struct zfcp_adapter *adapter = port->adapter;
439
440 adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC);
441 if (!adisc)
442 return -ENOMEM;
443
444 adisc->els.req = &adisc->req;
445 adisc->els.resp = &adisc->resp;
446 sg_init_one(adisc->els.req, &adisc->ls_adisc,
447 sizeof(struct zfcp_ls_adisc));
448 sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc,
Swen Schillig44cc76f2008-10-01 12:42:16 +0200449 sizeof(struct zfcp_ls_adisc));
Christof Schmitt24073b42008-06-10 18:20:54 +0200450
Christof Schmitt24073b42008-06-10 18:20:54 +0200451 adisc->els.adapter = adapter;
452 adisc->els.port = port;
453 adisc->els.d_id = port->d_id;
454 adisc->els.handler = zfcp_fc_adisc_handler;
455 adisc->els.handler_data = (unsigned long) adisc;
456 adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC;
457
458 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
459 without FC-AL-2 capability, so we don't set it */
460 adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host);
461 adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host);
462 adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host);
463
464 return zfcp_fsf_send_els(&adisc->els);
465}
466
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100467void zfcp_fc_link_test_work(struct work_struct *work)
468{
469 struct zfcp_port *port =
470 container_of(work, struct zfcp_port, test_link_work);
471 int retval;
472
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100473 zfcp_port_get(port);
474 port->rport_task = RPORT_DEL;
475 zfcp_scsi_rport_work(&port->rport_work);
476
Christof Schmitt14e242e2009-08-18 15:43:11 +0200477 /* only issue one test command at one time per port */
478 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_LINK_TEST)
479 goto out;
480
481 atomic_set_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
482
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100483 retval = zfcp_fc_adisc(port);
484 if (retval == 0)
485 return;
486
487 /* send of ADISC was not possible */
Christof Schmitt14e242e2009-08-18 15:43:11 +0200488 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100489 zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL);
490
Christof Schmitt14e242e2009-08-18 15:43:11 +0200491out:
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100492 zfcp_port_put(port);
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100493}
494
Christof Schmitt24073b42008-06-10 18:20:54 +0200495/**
496 * zfcp_test_link - lightweight link test procedure
497 * @port: port to be tested
498 *
499 * Test status of a link to a remote port using the ELS command ADISC.
500 * If there is a problem with the remote port, error recovery steps
501 * will be triggered.
502 */
503void zfcp_test_link(struct zfcp_port *port)
504{
Christof Schmitt24073b42008-06-10 18:20:54 +0200505 zfcp_port_get(port);
Swen Schillig45446832009-08-18 15:43:17 +0200506 if (!queue_work(port->adapter->work_queue, &port->test_link_work))
Christof Schmitt8fdf30d2009-03-02 13:09:01 +0100507 zfcp_port_put(port);
Christof Schmitt24073b42008-06-10 18:20:54 +0200508}
Swen Schilligcc8c2822008-06-10 18:21:00 +0200509
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100510static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft, int buf_num)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200511{
512 struct scatterlist *sg = &gpn_ft->sg_req;
513
Swen Schilliga4623c42009-08-18 15:43:15 +0200514 kmem_cache_free(zfcp_data.gpn_ft_cache, sg_virt(sg));
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100515 zfcp_sg_free_table(gpn_ft->sg_resp, buf_num);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200516
517 kfree(gpn_ft);
518}
519
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100520static struct zfcp_gpn_ft *zfcp_alloc_sg_env(int buf_num)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200521{
522 struct zfcp_gpn_ft *gpn_ft;
523 struct ct_iu_gpn_ft_req *req;
524
525 gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL);
526 if (!gpn_ft)
527 return NULL;
528
Swen Schilliga4623c42009-08-18 15:43:15 +0200529 req = kmem_cache_alloc(zfcp_data.gpn_ft_cache, GFP_KERNEL);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200530 if (!req) {
531 kfree(gpn_ft);
532 gpn_ft = NULL;
533 goto out;
534 }
535 sg_init_one(&gpn_ft->sg_req, req, sizeof(*req));
536
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100537 if (zfcp_sg_setup_table(gpn_ft->sg_resp, buf_num)) {
538 zfcp_free_sg_env(gpn_ft, buf_num);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200539 gpn_ft = NULL;
540 }
541out:
542 return gpn_ft;
543}
544
545
546static int zfcp_scan_issue_gpn_ft(struct zfcp_gpn_ft *gpn_ft,
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100547 struct zfcp_adapter *adapter,
548 int max_bytes)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200549{
550 struct zfcp_send_ct *ct = &gpn_ft->ct;
551 struct ct_iu_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200552 struct zfcp_fc_ns_handler_data compl_rec;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200553 int ret;
554
555 /* prepare CT IU for GPN_FT */
556 req->header.revision = ZFCP_CT_REVISION;
557 req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
558 req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
559 req->header.options = ZFCP_CT_SYNCHRONOUS;
560 req->header.cmd_rsp_code = ZFCP_CT_GPN_FT;
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100561 req->header.max_res_size = max_bytes / 4;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200562 req->flags = 0;
563 req->domain_id_scope = 0;
564 req->area_id_scope = 0;
565 req->fc4_type = ZFCP_CT_SCSI_FCP;
566
567 /* prepare zfcp_send_ct */
Sven Schuetz9d544f22009-04-06 18:31:47 +0200568 ct->wka_port = &adapter->gs->ds;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200569 ct->handler = zfcp_fc_ns_handler;
570 ct->handler_data = (unsigned long)&compl_rec;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200571 ct->timeout = 10;
572 ct->req = &gpn_ft->sg_req;
573 ct->resp = gpn_ft->sg_resp;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200574
Swen Schillig5ab944f2008-10-01 12:42:17 +0200575 init_completion(&compl_rec.done);
576 compl_rec.handler = NULL;
Christof Schmitt799b76d2009-08-18 15:43:20 +0200577 ret = zfcp_fsf_send_ct(ct, NULL);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200578 if (!ret)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200579 wait_for_completion(&compl_rec.done);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200580 return ret;
581}
582
583static void zfcp_validate_port(struct zfcp_port *port)
584{
585 struct zfcp_adapter *adapter = port->adapter;
586
Martin Petermann6ab35c02009-04-17 15:08:13 +0200587 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC))
588 return;
589
Swen Schilligcc8c2822008-06-10 18:21:00 +0200590 atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status);
591
Christof Schmitt04062892008-10-01 12:42:20 +0200592 if ((port->supported_classes != 0) ||
593 !list_empty(&port->unit_list_head)) {
Swen Schilligcc8c2822008-06-10 18:21:00 +0200594 zfcp_port_put(port);
595 return;
596 }
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100597 zfcp_erp_port_shutdown(port, 0, "fcpval1", NULL);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200598 zfcp_erp_wait(adapter);
599 zfcp_port_put(port);
600 zfcp_port_dequeue(port);
601}
602
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100603static int zfcp_scan_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft, int max_entries)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200604{
605 struct zfcp_send_ct *ct = &gpn_ft->ct;
606 struct scatterlist *sg = gpn_ft->sg_resp;
607 struct ct_hdr *hdr = sg_virt(sg);
608 struct gpn_ft_resp_acc *acc = sg_virt(sg);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200609 struct zfcp_adapter *adapter = ct->wka_port->adapter;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200610 struct zfcp_port *port, *tmp;
611 u32 d_id;
Christof Schmitt47f7bba2008-08-21 13:43:33 +0200612 int ret = 0, x, last = 0;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200613
614 if (ct->status)
615 return -EIO;
616
617 if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) {
618 if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD)
619 return -EAGAIN; /* might be a temporary condition */
620 return -EIO;
621 }
622
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100623 if (hdr->max_res_size) {
624 dev_warn(&adapter->ccw_device->dev,
625 "The name server reported %d words residual data\n",
626 hdr->max_res_size);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200627 return -E2BIG;
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100628 }
Swen Schilligcc8c2822008-06-10 18:21:00 +0200629
630 down(&zfcp_data.config_sema);
631
632 /* first entry is the header */
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100633 for (x = 1; x < max_entries && !last; x++) {
Swen Schilligcc8c2822008-06-10 18:21:00 +0200634 if (x % (ZFCP_GPN_FT_ENTRIES + 1))
635 acc++;
636 else
637 acc = sg_virt(++sg);
638
Christof Schmitt47f7bba2008-08-21 13:43:33 +0200639 last = acc->control & 0x80;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200640 d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 |
641 acc->port_id[2];
642
Swen Schillig5ab944f2008-10-01 12:42:17 +0200643 /* don't attach ports with a well known address */
644 if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA)
645 continue;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200646 /* skip the adapter's port and known remote ports */
Swen Schillig95285392008-08-21 13:43:35 +0200647 if (acc->wwpn == fc_host_port_name(adapter->scsi_host))
Swen Schilligcc8c2822008-06-10 18:21:00 +0200648 continue;
Swen Schillig95285392008-08-21 13:43:35 +0200649 port = zfcp_get_port_by_wwpn(adapter, acc->wwpn);
Martin Petermann6ab35c02009-04-17 15:08:13 +0200650 if (port)
Swen Schillig95285392008-08-21 13:43:35 +0200651 continue;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200652
653 port = zfcp_port_enqueue(adapter, acc->wwpn,
Swen Schilligcc8c2822008-06-10 18:21:00 +0200654 ZFCP_STATUS_COMMON_NOESC, d_id);
Swen Schillig317e6b62008-07-02 10:56:37 +0200655 if (IS_ERR(port))
656 ret = PTR_ERR(port);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200657 else
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100658 zfcp_erp_port_reopen(port, 0, "fcegpf1", NULL);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200659 }
660
661 zfcp_erp_wait(adapter);
662 list_for_each_entry_safe(port, tmp, &adapter->port_list_head, list)
663 zfcp_validate_port(port);
664 up(&zfcp_data.config_sema);
665 return ret;
666}
667
668/**
669 * zfcp_scan_ports - scan remote ports and attach new ports
670 * @adapter: pointer to struct zfcp_adapter
671 */
672int zfcp_scan_ports(struct zfcp_adapter *adapter)
673{
674 int ret, i;
675 struct zfcp_gpn_ft *gpn_ft;
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100676 int chain, max_entries, buf_num, max_bytes;
677
678 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS;
679 buf_num = chain ? ZFCP_GPN_FT_BUFFERS : 1;
680 max_entries = chain ? ZFCP_GPN_FT_MAX_ENTRIES : ZFCP_GPN_FT_ENTRIES;
681 max_bytes = chain ? ZFCP_GPN_FT_MAX_SIZE : ZFCP_CT_SIZE_ONE_PAGE;
Swen Schilligcc8c2822008-06-10 18:21:00 +0200682
Swen Schillig306b6ed2009-04-17 15:08:02 +0200683 if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT &&
684 fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV)
Swen Schilligcc8c2822008-06-10 18:21:00 +0200685 return 0;
686
Sven Schuetz9d544f22009-04-06 18:31:47 +0200687 ret = zfcp_wka_port_get(&adapter->gs->ds);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200688 if (ret)
689 return ret;
690
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100691 gpn_ft = zfcp_alloc_sg_env(buf_num);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200692 if (!gpn_ft) {
693 ret = -ENOMEM;
694 goto out;
695 }
Swen Schilligcc8c2822008-06-10 18:21:00 +0200696
697 for (i = 0; i < 3; i++) {
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100698 ret = zfcp_scan_issue_gpn_ft(gpn_ft, adapter, max_bytes);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200699 if (!ret) {
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100700 ret = zfcp_scan_eval_gpn_ft(gpn_ft, max_entries);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200701 if (ret == -EAGAIN)
702 ssleep(1);
703 else
704 break;
705 }
706 }
Christof Schmitt39eb7e92008-12-19 16:57:01 +0100707 zfcp_free_sg_env(gpn_ft, buf_num);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200708out:
Sven Schuetz9d544f22009-04-06 18:31:47 +0200709 zfcp_wka_port_put(&adapter->gs->ds);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200710 return ret;
711}
712
713
714void _zfcp_scan_ports_later(struct work_struct *work)
715{
716 zfcp_scan_ports(container_of(work, struct zfcp_adapter, scan_work));
717}
Sven Schuetz9d544f22009-04-06 18:31:47 +0200718
719struct zfcp_els_fc_job {
720 struct zfcp_send_els els;
721 struct fc_bsg_job *job;
722};
723
724static void zfcp_fc_generic_els_handler(unsigned long data)
725{
726 struct zfcp_els_fc_job *els_fc_job = (struct zfcp_els_fc_job *) data;
727 struct fc_bsg_job *job = els_fc_job->job;
728 struct fc_bsg_reply *reply = job->reply;
729
730 if (els_fc_job->els.status) {
731 /* request rejected or timed out */
732 reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_REJECT;
733 goto out;
734 }
735
736 reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
Christof Schmittdc577d52009-05-15 13:18:22 +0200737 reply->reply_payload_rcv_len = job->reply_payload.payload_len;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200738
739out:
740 job->state_flags = FC_RQST_STATE_DONE;
741 job->job_done(job);
742 kfree(els_fc_job);
743}
744
745int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *job)
746{
747 struct zfcp_els_fc_job *els_fc_job;
748 struct fc_rport *rport = job->rport;
749 struct Scsi_Host *shost;
750 struct zfcp_adapter *adapter;
751 struct zfcp_port *port;
752 u8 *port_did;
753
754 shost = rport ? rport_to_shost(rport) : job->shost;
755 adapter = (struct zfcp_adapter *)shost->hostdata[0];
756
757 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
758 return -EINVAL;
759
760 els_fc_job = kzalloc(sizeof(struct zfcp_els_fc_job), GFP_KERNEL);
761 if (!els_fc_job)
762 return -ENOMEM;
763
764 els_fc_job->els.adapter = adapter;
765 if (rport) {
766 read_lock_irq(&zfcp_data.config_lock);
767 port = rport->dd_data;
768 if (port)
Christof Schmittdc577d52009-05-15 13:18:22 +0200769 els_fc_job->els.d_id = port->d_id;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200770 read_unlock_irq(&zfcp_data.config_lock);
771 if (!port) {
772 kfree(els_fc_job);
773 return -EINVAL;
774 }
Sven Schuetz9d544f22009-04-06 18:31:47 +0200775 } else {
776 port_did = job->request->rqst_data.h_els.port_id;
777 els_fc_job->els.d_id = (port_did[0] << 16) +
778 (port_did[1] << 8) + port_did[2];
779 }
780
781 els_fc_job->els.req = job->request_payload.sg_list;
782 els_fc_job->els.resp = job->reply_payload.sg_list;
783 els_fc_job->els.handler = zfcp_fc_generic_els_handler;
784 els_fc_job->els.handler_data = (unsigned long) els_fc_job;
785 els_fc_job->job = job;
786
787 return zfcp_fsf_send_els(&els_fc_job->els);
788}
789
790struct zfcp_ct_fc_job {
791 struct zfcp_send_ct ct;
792 struct fc_bsg_job *job;
793};
794
795static void zfcp_fc_generic_ct_handler(unsigned long data)
796{
797 struct zfcp_ct_fc_job *ct_fc_job = (struct zfcp_ct_fc_job *) data;
798 struct fc_bsg_job *job = ct_fc_job->job;
799
800 job->reply->reply_data.ctels_reply.status = ct_fc_job->ct.status ?
801 FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK;
Christof Schmittdc577d52009-05-15 13:18:22 +0200802 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200803 job->state_flags = FC_RQST_STATE_DONE;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200804 job->job_done(job);
805
806 zfcp_wka_port_put(ct_fc_job->ct.wka_port);
807
808 kfree(ct_fc_job);
809}
810
811int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *job)
812{
813 int ret;
814 u8 gs_type;
815 struct fc_rport *rport = job->rport;
816 struct Scsi_Host *shost;
817 struct zfcp_adapter *adapter;
818 struct zfcp_ct_fc_job *ct_fc_job;
819 u32 preamble_word1;
820
821 shost = rport ? rport_to_shost(rport) : job->shost;
822
823 adapter = (struct zfcp_adapter *)shost->hostdata[0];
824 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
825 return -EINVAL;
826
827 ct_fc_job = kzalloc(sizeof(struct zfcp_ct_fc_job), GFP_KERNEL);
828 if (!ct_fc_job)
829 return -ENOMEM;
830
831 preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
832 gs_type = (preamble_word1 & 0xff000000) >> 24;
833
834 switch (gs_type) {
835 case FC_FST_ALIAS:
836 ct_fc_job->ct.wka_port = &adapter->gs->as;
837 break;
838 case FC_FST_MGMT:
839 ct_fc_job->ct.wka_port = &adapter->gs->ms;
840 break;
841 case FC_FST_TIME:
842 ct_fc_job->ct.wka_port = &adapter->gs->ts;
843 break;
844 case FC_FST_DIR:
845 ct_fc_job->ct.wka_port = &adapter->gs->ds;
846 break;
847 default:
848 kfree(ct_fc_job);
849 return -EINVAL; /* no such service */
850 }
851
852 ret = zfcp_wka_port_get(ct_fc_job->ct.wka_port);
853 if (ret) {
854 kfree(ct_fc_job);
855 return ret;
856 }
857
858 ct_fc_job->ct.req = job->request_payload.sg_list;
859 ct_fc_job->ct.resp = job->reply_payload.sg_list;
860 ct_fc_job->ct.timeout = ZFCP_FSF_REQUEST_TIMEOUT;
861 ct_fc_job->ct.handler = zfcp_fc_generic_ct_handler;
862 ct_fc_job->ct.handler_data = (unsigned long) ct_fc_job;
863 ct_fc_job->ct.completion = NULL;
864 ct_fc_job->job = job;
865
Christof Schmitt799b76d2009-08-18 15:43:20 +0200866 ret = zfcp_fsf_send_ct(&ct_fc_job->ct, NULL);
Sven Schuetz9d544f22009-04-06 18:31:47 +0200867 if (ret) {
868 kfree(ct_fc_job);
869 zfcp_wka_port_put(ct_fc_job->ct.wka_port);
870 }
871 return ret;
872}