[S390] convert vmlogrdr printks to pr_xxx macros.
[deliverable/linux.git] / drivers / s390 / scsi / zfcp_fc.c
CommitLineData
24073b47
CS
1/*
2 * zfcp device driver
3 *
4 * Fibre Channel related functions for the zfcp device driver.
5 *
6 * Copyright IBM Corporation 2008
7 */
8
9#include "zfcp_ext.h"
10
cc8c2829
SS
11struct ct_iu_gpn_ft_req {
12 struct ct_hdr header;
13 u8 flags;
14 u8 domain_id_scope;
15 u8 area_id_scope;
16 u8 fc4_type;
17} __attribute__ ((packed));
18
19struct gpn_ft_resp_acc {
20 u8 control;
21 u8 port_id[3];
22 u8 reserved[4];
23 u64 wwpn;
24} __attribute__ ((packed));
25
26#define ZFCP_GPN_FT_ENTRIES ((PAGE_SIZE - sizeof(struct ct_hdr)) \
27 / sizeof(struct gpn_ft_resp_acc))
28#define ZFCP_GPN_FT_BUFFERS 4
29#define ZFCP_GPN_FT_MAX_ENTRIES ZFCP_GPN_FT_BUFFERS * (ZFCP_GPN_FT_ENTRIES + 1)
30
31struct ct_iu_gpn_ft_resp {
32 struct ct_hdr header;
33 struct gpn_ft_resp_acc accept[ZFCP_GPN_FT_ENTRIES];
34} __attribute__ ((packed));
35
36struct zfcp_gpn_ft {
37 struct zfcp_send_ct ct;
38 struct scatterlist sg_req;
39 struct scatterlist sg_resp[ZFCP_GPN_FT_BUFFERS];
40};
41
5ab944f9
SS
42struct zfcp_fc_ns_handler_data {
43 struct completion done;
44 void (*handler)(unsigned long);
45 unsigned long handler_data;
46};
47
48static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port)
49{
50 if (mutex_lock_interruptible(&wka_port->mutex))
51 return -ERESTARTSYS;
52
1c1cba17
CS
53 if (wka_port->status == ZFCP_WKA_PORT_OFFLINE ||
54 wka_port->status == ZFCP_WKA_PORT_CLOSING) {
5ab944f9
SS
55 wka_port->status = ZFCP_WKA_PORT_OPENING;
56 if (zfcp_fsf_open_wka_port(wka_port))
57 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
58 }
59
60 mutex_unlock(&wka_port->mutex);
61
62 wait_event_timeout(
63 wka_port->completion_wq,
64 wka_port->status == ZFCP_WKA_PORT_ONLINE ||
65 wka_port->status == ZFCP_WKA_PORT_OFFLINE,
66 HZ >> 1);
67
68 if (wka_port->status == ZFCP_WKA_PORT_ONLINE) {
69 atomic_inc(&wka_port->refcount);
70 return 0;
71 }
72 return -EIO;
73}
74
75static void zfcp_wka_port_offline(struct work_struct *work)
76{
77 struct delayed_work *dw = container_of(work, struct delayed_work, work);
78 struct zfcp_wka_port *wka_port =
79 container_of(dw, struct zfcp_wka_port, work);
80
81 wait_event(wka_port->completion_wq,
82 atomic_read(&wka_port->refcount) == 0);
83
84 mutex_lock(&wka_port->mutex);
85 if ((atomic_read(&wka_port->refcount) != 0) ||
86 (wka_port->status != ZFCP_WKA_PORT_ONLINE))
87 goto out;
88
89 wka_port->status = ZFCP_WKA_PORT_CLOSING;
90 if (zfcp_fsf_close_wka_port(wka_port)) {
91 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
92 wake_up(&wka_port->completion_wq);
93 }
94out:
95 mutex_unlock(&wka_port->mutex);
96}
97
98static void zfcp_wka_port_put(struct zfcp_wka_port *wka_port)
99{
100 if (atomic_dec_return(&wka_port->refcount) != 0)
101 return;
102 /* wait 10 miliseconds, other reqs might pop in */
103 schedule_delayed_work(&wka_port->work, HZ / 100);
104}
105
106void zfcp_fc_nameserver_init(struct zfcp_adapter *adapter)
107{
108 struct zfcp_wka_port *wka_port = &adapter->nsp;
109
110 init_waitqueue_head(&wka_port->completion_wq);
111
112 wka_port->adapter = adapter;
113 wka_port->d_id = ZFCP_DID_DIRECTORY_SERVICE;
114
115 wka_port->status = ZFCP_WKA_PORT_OFFLINE;
116 atomic_set(&wka_port->refcount, 0);
117 mutex_init(&wka_port->mutex);
118 INIT_DELAYED_WORK(&wka_port->work, zfcp_wka_port_offline);
119}
120
24073b47
CS
121static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range,
122 struct fcp_rscn_element *elem)
123{
124 unsigned long flags;
125 struct zfcp_port *port;
126
127 read_lock_irqsave(&zfcp_data.config_lock, flags);
128 list_for_each_entry(port, &fsf_req->adapter->port_list_head, list) {
bce02614 129 if (!(atomic_read(&port->status) & ZFCP_STATUS_PORT_PHYS_OPEN))
24073b47
CS
130 /* Try to connect to unused ports anyway. */
131 zfcp_erp_port_reopen(port,
132 ZFCP_STATUS_COMMON_ERP_FAILED,
133 82, fsf_req);
134 else if ((port->d_id & range) == (elem->nport_did & range))
135 /* Check connection status for connected ports */
136 zfcp_test_link(port);
137 }
138 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
139}
140
141static void zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req)
142{
143 struct fsf_status_read_buffer *status_buffer = (void *)fsf_req->data;
144 struct fcp_rscn_head *fcp_rscn_head;
145 struct fcp_rscn_element *fcp_rscn_element;
146 u16 i;
147 u16 no_entries;
148 u32 range_mask;
149
c41f8cbd
SS
150 fcp_rscn_head = (struct fcp_rscn_head *) status_buffer->payload.data;
151 fcp_rscn_element = (struct fcp_rscn_element *) fcp_rscn_head;
24073b47
CS
152
153 /* see FC-FS */
154 no_entries = fcp_rscn_head->payload_len /
155 sizeof(struct fcp_rscn_element);
156
157 for (i = 1; i < no_entries; i++) {
158 /* skip head and start with 1st element */
159 fcp_rscn_element++;
160 switch (fcp_rscn_element->addr_format) {
161 case ZFCP_PORT_ADDRESS:
162 range_mask = ZFCP_PORTS_RANGE_PORT;
163 break;
164 case ZFCP_AREA_ADDRESS:
165 range_mask = ZFCP_PORTS_RANGE_AREA;
166 break;
167 case ZFCP_DOMAIN_ADDRESS:
168 range_mask = ZFCP_PORTS_RANGE_DOMAIN;
169 break;
170 case ZFCP_FABRIC_ADDRESS:
171 range_mask = ZFCP_PORTS_RANGE_FABRIC;
172 break;
173 default:
174 continue;
175 }
176 _zfcp_fc_incoming_rscn(fsf_req, range_mask, fcp_rscn_element);
177 }
cc8c2829 178 schedule_work(&fsf_req->adapter->scan_work);
24073b47
CS
179}
180
7ba58c9c 181static void zfcp_fc_incoming_wwpn(struct zfcp_fsf_req *req, u64 wwpn)
24073b47
CS
182{
183 struct zfcp_adapter *adapter = req->adapter;
184 struct zfcp_port *port;
185 unsigned long flags;
186
187 read_lock_irqsave(&zfcp_data.config_lock, flags);
188 list_for_each_entry(port, &adapter->port_list_head, list)
189 if (port->wwpn == wwpn)
190 break;
191 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
192
193 if (port && (port->wwpn == wwpn))
194 zfcp_erp_port_forced_reopen(port, 0, 83, req);
195}
196
197static void zfcp_fc_incoming_plogi(struct zfcp_fsf_req *req)
198{
199 struct fsf_status_read_buffer *status_buffer =
200 (struct fsf_status_read_buffer *)req->data;
201 struct fsf_plogi *els_plogi =
c41f8cbd 202 (struct fsf_plogi *) status_buffer->payload.data;
24073b47
CS
203
204 zfcp_fc_incoming_wwpn(req, els_plogi->serv_param.wwpn);
205}
206
207static void zfcp_fc_incoming_logo(struct zfcp_fsf_req *req)
208{
209 struct fsf_status_read_buffer *status_buffer =
210 (struct fsf_status_read_buffer *)req->data;
c41f8cbd
SS
211 struct fcp_logo *els_logo =
212 (struct fcp_logo *) status_buffer->payload.data;
24073b47
CS
213
214 zfcp_fc_incoming_wwpn(req, els_logo->nport_wwpn);
215}
216
217/**
218 * zfcp_fc_incoming_els - handle incoming ELS
219 * @fsf_req - request which contains incoming ELS
220 */
221void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req)
222{
223 struct fsf_status_read_buffer *status_buffer =
224 (struct fsf_status_read_buffer *) fsf_req->data;
c41f8cbd 225 unsigned int els_type = status_buffer->payload.data[0];
24073b47
CS
226
227 zfcp_san_dbf_event_incoming_els(fsf_req);
228 if (els_type == LS_PLOGI)
229 zfcp_fc_incoming_plogi(fsf_req);
230 else if (els_type == LS_LOGO)
231 zfcp_fc_incoming_logo(fsf_req);
232 else if (els_type == LS_RSCN)
233 zfcp_fc_incoming_rscn(fsf_req);
234}
235
5ab944f9
SS
236static void zfcp_fc_ns_handler(unsigned long data)
237{
238 struct zfcp_fc_ns_handler_data *compl_rec =
239 (struct zfcp_fc_ns_handler_data *) data;
240
241 if (compl_rec->handler)
242 compl_rec->handler(compl_rec->handler_data);
243
244 complete(&compl_rec->done);
245}
246
247static void zfcp_fc_ns_gid_pn_eval(unsigned long data)
24073b47
CS
248{
249 struct zfcp_gid_pn_data *gid_pn = (struct zfcp_gid_pn_data *) data;
250 struct zfcp_send_ct *ct = &gid_pn->ct;
251 struct ct_iu_gid_pn_req *ct_iu_req = sg_virt(ct->req);
252 struct ct_iu_gid_pn_resp *ct_iu_resp = sg_virt(ct->resp);
253 struct zfcp_port *port = gid_pn->port;
254
255 if (ct->status)
5ab944f9 256 return;
24073b47
CS
257 if (ct_iu_resp->header.cmd_rsp_code != ZFCP_CT_ACCEPT) {
258 atomic_set_mask(ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
5ab944f9 259 return;
24073b47
CS
260 }
261 /* paranoia */
262 if (ct_iu_req->wwpn != port->wwpn)
5ab944f9 263 return;
24073b47
CS
264 /* looks like a valid d_id */
265 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
266 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
24073b47
CS
267}
268
5ab944f9
SS
269int static zfcp_fc_ns_gid_pn_request(struct zfcp_erp_action *erp_action,
270 struct zfcp_gid_pn_data *gid_pn)
24073b47 271{
24073b47 272 struct zfcp_adapter *adapter = erp_action->adapter;
5ab944f9
SS
273 struct zfcp_fc_ns_handler_data compl_rec;
274 int ret;
24073b47
CS
275
276 /* setup parameters for send generic command */
277 gid_pn->port = erp_action->port;
5ab944f9
SS
278 gid_pn->ct.wka_port = &adapter->nsp;
279 gid_pn->ct.handler = zfcp_fc_ns_handler;
280 gid_pn->ct.handler_data = (unsigned long) &compl_rec;
24073b47
CS
281 gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
282 gid_pn->ct.req = &gid_pn->req;
283 gid_pn->ct.resp = &gid_pn->resp;
284 gid_pn->ct.req_count = 1;
285 gid_pn->ct.resp_count = 1;
286 sg_init_one(&gid_pn->req, &gid_pn->ct_iu_req,
287 sizeof(struct ct_iu_gid_pn_req));
288 sg_init_one(&gid_pn->resp, &gid_pn->ct_iu_resp,
289 sizeof(struct ct_iu_gid_pn_resp));
290
291 /* setup nameserver request */
292 gid_pn->ct_iu_req.header.revision = ZFCP_CT_REVISION;
293 gid_pn->ct_iu_req.header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
294 gid_pn->ct_iu_req.header.gs_subtype = ZFCP_CT_NAME_SERVER;
295 gid_pn->ct_iu_req.header.options = ZFCP_CT_SYNCHRONOUS;
296 gid_pn->ct_iu_req.header.cmd_rsp_code = ZFCP_CT_GID_PN;
297 gid_pn->ct_iu_req.header.max_res_size = ZFCP_CT_MAX_SIZE;
298 gid_pn->ct_iu_req.wwpn = erp_action->port->wwpn;
299
5ab944f9
SS
300 init_completion(&compl_rec.done);
301 compl_rec.handler = zfcp_fc_ns_gid_pn_eval;
302 compl_rec.handler_data = (unsigned long) gid_pn;
24073b47
CS
303 ret = zfcp_fsf_send_ct(&gid_pn->ct, adapter->pool.fsf_req_erp,
304 erp_action);
5ab944f9
SS
305 if (!ret)
306 wait_for_completion(&compl_rec.done);
307 return ret;
308}
309
310/**
311 * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request
312 * @erp_action: pointer to zfcp_erp_action where GID_PN request is needed
313 * return: -ENOMEM on error, 0 otherwise
314 */
315int zfcp_fc_ns_gid_pn(struct zfcp_erp_action *erp_action)
316{
317 int ret;
318 struct zfcp_gid_pn_data *gid_pn;
319 struct zfcp_adapter *adapter = erp_action->adapter;
320
321 gid_pn = mempool_alloc(adapter->pool.data_gid_pn, GFP_ATOMIC);
322 if (!gid_pn)
323 return -ENOMEM;
324
325 memset(gid_pn, 0, sizeof(*gid_pn));
326
327 ret = zfcp_wka_port_get(&adapter->nsp);
24073b47 328 if (ret)
5ab944f9
SS
329 goto out;
330
331 ret = zfcp_fc_ns_gid_pn_request(erp_action, gid_pn);
332
333 zfcp_wka_port_put(&adapter->nsp);
334out:
335 mempool_free(gid_pn, adapter->pool.data_gid_pn);
24073b47
CS
336 return ret;
337}
338
339/**
340 * zfcp_fc_plogi_evaluate - evaluate PLOGI playload
341 * @port: zfcp_port structure
342 * @plogi: plogi payload
343 *
344 * Evaluate PLOGI playload and copy important fields into zfcp_port structure
345 */
346void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fsf_plogi *plogi)
347{
348 port->maxframe_size = plogi->serv_param.common_serv_param[7] |
349 ((plogi->serv_param.common_serv_param[6] & 0x0F) << 8);
350 if (plogi->serv_param.class1_serv_param[0] & 0x80)
351 port->supported_classes |= FC_COS_CLASS1;
352 if (plogi->serv_param.class2_serv_param[0] & 0x80)
353 port->supported_classes |= FC_COS_CLASS2;
354 if (plogi->serv_param.class3_serv_param[0] & 0x80)
355 port->supported_classes |= FC_COS_CLASS3;
356 if (plogi->serv_param.class4_serv_param[0] & 0x80)
357 port->supported_classes |= FC_COS_CLASS4;
358}
359
360struct zfcp_els_adisc {
361 struct zfcp_send_els els;
362 struct scatterlist req;
363 struct scatterlist resp;
364 struct zfcp_ls_adisc ls_adisc;
44cc76f2 365 struct zfcp_ls_adisc ls_adisc_acc;
24073b47
CS
366};
367
368static void zfcp_fc_adisc_handler(unsigned long data)
369{
370 struct zfcp_els_adisc *adisc = (struct zfcp_els_adisc *) data;
371 struct zfcp_port *port = adisc->els.port;
44cc76f2 372 struct zfcp_ls_adisc *ls_adisc = &adisc->ls_adisc_acc;
24073b47 373
3968ce80 374 if (adisc->els.status) {
24073b47
CS
375 /* request rejected or timed out */
376 zfcp_erp_port_forced_reopen(port, 0, 63, NULL);
377 goto out;
378 }
379
380 if (!port->wwnn)
381 port->wwnn = ls_adisc->wwnn;
382
383 if (port->wwpn != ls_adisc->wwpn)
384 zfcp_erp_port_reopen(port, 0, 64, NULL);
385
386 out:
387 zfcp_port_put(port);
388 kfree(adisc);
389}
390
391static int zfcp_fc_adisc(struct zfcp_port *port)
392{
393 struct zfcp_els_adisc *adisc;
394 struct zfcp_adapter *adapter = port->adapter;
395
396 adisc = kzalloc(sizeof(struct zfcp_els_adisc), GFP_ATOMIC);
397 if (!adisc)
398 return -ENOMEM;
399
400 adisc->els.req = &adisc->req;
401 adisc->els.resp = &adisc->resp;
402 sg_init_one(adisc->els.req, &adisc->ls_adisc,
403 sizeof(struct zfcp_ls_adisc));
404 sg_init_one(adisc->els.resp, &adisc->ls_adisc_acc,
44cc76f2 405 sizeof(struct zfcp_ls_adisc));
24073b47
CS
406
407 adisc->els.req_count = 1;
408 adisc->els.resp_count = 1;
409 adisc->els.adapter = adapter;
410 adisc->els.port = port;
411 adisc->els.d_id = port->d_id;
412 adisc->els.handler = zfcp_fc_adisc_handler;
413 adisc->els.handler_data = (unsigned long) adisc;
414 adisc->els.ls_code = adisc->ls_adisc.code = ZFCP_LS_ADISC;
415
416 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
417 without FC-AL-2 capability, so we don't set it */
418 adisc->ls_adisc.wwpn = fc_host_port_name(adapter->scsi_host);
419 adisc->ls_adisc.wwnn = fc_host_node_name(adapter->scsi_host);
420 adisc->ls_adisc.nport_id = fc_host_port_id(adapter->scsi_host);
421
422 return zfcp_fsf_send_els(&adisc->els);
423}
424
425/**
426 * zfcp_test_link - lightweight link test procedure
427 * @port: port to be tested
428 *
429 * Test status of a link to a remote port using the ELS command ADISC.
430 * If there is a problem with the remote port, error recovery steps
431 * will be triggered.
432 */
433void zfcp_test_link(struct zfcp_port *port)
434{
435 int retval;
436
437 zfcp_port_get(port);
438 retval = zfcp_fc_adisc(port);
9528539c 439 if (retval == 0)
24073b47
CS
440 return;
441
442 /* send of ADISC was not possible */
443 zfcp_port_put(port);
9528539c
SS
444 if (retval != -EBUSY)
445 zfcp_erp_port_forced_reopen(port, 0, 65, NULL);
24073b47 446}
cc8c2829 447
cc8c2829
SS
448static void zfcp_free_sg_env(struct zfcp_gpn_ft *gpn_ft)
449{
450 struct scatterlist *sg = &gpn_ft->sg_req;
451
452 kfree(sg_virt(sg)); /* free request buffer */
453 zfcp_sg_free_table(gpn_ft->sg_resp, ZFCP_GPN_FT_BUFFERS);
454
455 kfree(gpn_ft);
456}
457
458static struct zfcp_gpn_ft *zfcp_alloc_sg_env(void)
459{
460 struct zfcp_gpn_ft *gpn_ft;
461 struct ct_iu_gpn_ft_req *req;
462
463 gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL);
464 if (!gpn_ft)
465 return NULL;
466
467 req = kzalloc(sizeof(struct ct_iu_gpn_ft_req), GFP_KERNEL);
468 if (!req) {
469 kfree(gpn_ft);
470 gpn_ft = NULL;
471 goto out;
472 }
473 sg_init_one(&gpn_ft->sg_req, req, sizeof(*req));
474
475 if (zfcp_sg_setup_table(gpn_ft->sg_resp, ZFCP_GPN_FT_BUFFERS)) {
476 zfcp_free_sg_env(gpn_ft);
477 gpn_ft = NULL;
478 }
479out:
480 return gpn_ft;
481}
482
483
484static int zfcp_scan_issue_gpn_ft(struct zfcp_gpn_ft *gpn_ft,
485 struct zfcp_adapter *adapter)
486{
487 struct zfcp_send_ct *ct = &gpn_ft->ct;
488 struct ct_iu_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req);
5ab944f9 489 struct zfcp_fc_ns_handler_data compl_rec;
cc8c2829
SS
490 int ret;
491
492 /* prepare CT IU for GPN_FT */
493 req->header.revision = ZFCP_CT_REVISION;
494 req->header.gs_type = ZFCP_CT_DIRECTORY_SERVICE;
495 req->header.gs_subtype = ZFCP_CT_NAME_SERVER;
496 req->header.options = ZFCP_CT_SYNCHRONOUS;
497 req->header.cmd_rsp_code = ZFCP_CT_GPN_FT;
498 req->header.max_res_size = (sizeof(struct gpn_ft_resp_acc) *
499 (ZFCP_GPN_FT_MAX_ENTRIES - 1)) >> 2;
500 req->flags = 0;
501 req->domain_id_scope = 0;
502 req->area_id_scope = 0;
503 req->fc4_type = ZFCP_CT_SCSI_FCP;
504
505 /* prepare zfcp_send_ct */
5ab944f9
SS
506 ct->wka_port = &adapter->nsp;
507 ct->handler = zfcp_fc_ns_handler;
508 ct->handler_data = (unsigned long)&compl_rec;
cc8c2829
SS
509 ct->timeout = 10;
510 ct->req = &gpn_ft->sg_req;
511 ct->resp = gpn_ft->sg_resp;
512 ct->req_count = 1;
513 ct->resp_count = ZFCP_GPN_FT_BUFFERS;
514
5ab944f9
SS
515 init_completion(&compl_rec.done);
516 compl_rec.handler = NULL;
cc8c2829
SS
517 ret = zfcp_fsf_send_ct(ct, NULL, NULL);
518 if (!ret)
5ab944f9 519 wait_for_completion(&compl_rec.done);
cc8c2829
SS
520 return ret;
521}
522
523static void zfcp_validate_port(struct zfcp_port *port)
524{
525 struct zfcp_adapter *adapter = port->adapter;
526
527 atomic_clear_mask(ZFCP_STATUS_COMMON_NOESC, &port->status);
528
0406289e
CS
529 if ((port->supported_classes != 0) ||
530 !list_empty(&port->unit_list_head)) {
cc8c2829
SS
531 zfcp_port_put(port);
532 return;
533 }
534 zfcp_erp_port_shutdown(port, 0, 151, NULL);
535 zfcp_erp_wait(adapter);
536 zfcp_port_put(port);
537 zfcp_port_dequeue(port);
538}
539
540static int zfcp_scan_eval_gpn_ft(struct zfcp_gpn_ft *gpn_ft)
541{
542 struct zfcp_send_ct *ct = &gpn_ft->ct;
543 struct scatterlist *sg = gpn_ft->sg_resp;
544 struct ct_hdr *hdr = sg_virt(sg);
545 struct gpn_ft_resp_acc *acc = sg_virt(sg);
5ab944f9 546 struct zfcp_adapter *adapter = ct->wka_port->adapter;
cc8c2829
SS
547 struct zfcp_port *port, *tmp;
548 u32 d_id;
47f7bba5 549 int ret = 0, x, last = 0;
cc8c2829
SS
550
551 if (ct->status)
552 return -EIO;
553
554 if (hdr->cmd_rsp_code != ZFCP_CT_ACCEPT) {
555 if (hdr->reason_code == ZFCP_CT_UNABLE_TO_PERFORM_CMD)
556 return -EAGAIN; /* might be a temporary condition */
557 return -EIO;
558 }
559
560 if (hdr->max_res_size)
561 return -E2BIG;
562
563 down(&zfcp_data.config_sema);
564
565 /* first entry is the header */
47f7bba5 566 for (x = 1; x < ZFCP_GPN_FT_MAX_ENTRIES && !last; x++) {
cc8c2829
SS
567 if (x % (ZFCP_GPN_FT_ENTRIES + 1))
568 acc++;
569 else
570 acc = sg_virt(++sg);
571
47f7bba5 572 last = acc->control & 0x80;
cc8c2829
SS
573 d_id = acc->port_id[0] << 16 | acc->port_id[1] << 8 |
574 acc->port_id[2];
575
5ab944f9
SS
576 /* don't attach ports with a well known address */
577 if ((d_id & ZFCP_DID_WKA) == ZFCP_DID_WKA)
578 continue;
cc8c2829 579 /* skip the adapter's port and known remote ports */
9528539c 580 if (acc->wwpn == fc_host_port_name(adapter->scsi_host))
cc8c2829 581 continue;
9528539c
SS
582 port = zfcp_get_port_by_wwpn(adapter, acc->wwpn);
583 if (port) {
584 zfcp_port_get(port);
585 continue;
586 }
cc8c2829
SS
587
588 port = zfcp_port_enqueue(adapter, acc->wwpn,
589 ZFCP_STATUS_PORT_DID_DID |
590 ZFCP_STATUS_COMMON_NOESC, d_id);
317e6b65
SS
591 if (IS_ERR(port))
592 ret = PTR_ERR(port);
cc8c2829 593 else
317e6b65 594 zfcp_erp_port_reopen(port, 0, 149, NULL);
cc8c2829
SS
595 }
596
597 zfcp_erp_wait(adapter);
598 list_for_each_entry_safe(port, tmp, &adapter->port_list_head, list)
599 zfcp_validate_port(port);
600 up(&zfcp_data.config_sema);
601 return ret;
602}
603
604/**
605 * zfcp_scan_ports - scan remote ports and attach new ports
606 * @adapter: pointer to struct zfcp_adapter
607 */
608int zfcp_scan_ports(struct zfcp_adapter *adapter)
609{
610 int ret, i;
611 struct zfcp_gpn_ft *gpn_ft;
612
613 if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT)
614 return 0;
615
5ab944f9 616 ret = zfcp_wka_port_get(&adapter->nsp);
cc8c2829
SS
617 if (ret)
618 return ret;
619
620 gpn_ft = zfcp_alloc_sg_env();
5ab944f9
SS
621 if (!gpn_ft) {
622 ret = -ENOMEM;
623 goto out;
624 }
cc8c2829
SS
625
626 for (i = 0; i < 3; i++) {
627 ret = zfcp_scan_issue_gpn_ft(gpn_ft, adapter);
628 if (!ret) {
629 ret = zfcp_scan_eval_gpn_ft(gpn_ft);
630 if (ret == -EAGAIN)
631 ssleep(1);
632 else
633 break;
634 }
635 }
636 zfcp_free_sg_env(gpn_ft);
5ab944f9
SS
637out:
638 zfcp_wka_port_put(&adapter->nsp);
cc8c2829
SS
639 return ret;
640}
641
642
643void _zfcp_scan_ports_later(struct work_struct *work)
644{
645 zfcp_scan_ports(container_of(work, struct zfcp_adapter, scan_work));
646}
This page took 0.850645 seconds and 5 git commands to generate.