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