This source file includes following definitions.
- lpfc_els_chk_latt
- lpfc_prep_els_iocb
- lpfc_issue_fabric_reglogin
- lpfc_issue_reg_vfi
- lpfc_issue_unreg_vfi
- lpfc_check_clean_addr_bit
- lpfc_cmpl_els_flogi_fabric
- lpfc_cmpl_els_flogi_nport
- lpfc_cmpl_els_flogi
- lpfc_cmpl_els_link_down
- lpfc_issue_els_flogi
- lpfc_els_abort_flogi
- lpfc_initial_flogi
- lpfc_initial_fdisc
- lpfc_more_plogi
- lpfc_plogi_confirm_nport
- lpfc_end_rscn
- lpfc_cmpl_els_rrq
- lpfc_cmpl_els_plogi
- lpfc_issue_els_plogi
- lpfc_cmpl_els_prli
- lpfc_issue_els_prli
- lpfc_rscn_disc
- lpfc_adisc_done
- lpfc_more_adisc
- lpfc_cmpl_els_adisc
- lpfc_issue_els_adisc
- lpfc_cmpl_els_logo
- lpfc_issue_els_logo
- lpfc_cmpl_els_cmd
- lpfc_issue_els_scr
- lpfc_issue_els_rscn
- lpfc_issue_els_farpr
- lpfc_cancel_retry_delay_tmo
- lpfc_els_retry_delay
- lpfc_els_retry_delay_handler
- lpfc_link_reset
- lpfc_els_retry
- lpfc_els_free_data
- lpfc_els_free_bpl
- lpfc_els_free_iocb
- lpfc_cmpl_els_logo_acc
- lpfc_mbx_cmpl_dflt_rpi
- lpfc_cmpl_els_rsp
- lpfc_els_rsp_acc
- lpfc_els_rsp_reject
- lpfc_els_rsp_adisc_acc
- lpfc_els_rsp_prli_acc
- lpfc_els_rsp_rnid_acc
- lpfc_els_clear_rrq
- lpfc_els_rsp_echo_acc
- lpfc_els_disc_adisc
- lpfc_els_disc_plogi
- lpfc_rdp_res_link_service
- lpfc_rdp_res_sfp_desc
- lpfc_rdp_res_link_error
- lpfc_rdp_res_bbc_desc
- lpfc_rdp_res_oed_temp_desc
- lpfc_rdp_res_oed_voltage_desc
- lpfc_rdp_res_oed_txbias_desc
- lpfc_rdp_res_oed_txpower_desc
- lpfc_rdp_res_oed_rxpower_desc
- lpfc_rdp_res_opd_desc
- lpfc_rdp_res_fec_desc
- lpfc_rdp_res_speed
- lpfc_rdp_res_diag_port_names
- lpfc_rdp_res_attach_port_names
- lpfc_els_rdp_cmpl
- lpfc_get_rdp_info
- lpfc_els_rcv_rdp
- lpfc_els_lcb_rsp
- lpfc_sli4_set_beacon
- lpfc_els_rcv_lcb
- lpfc_els_flush_rscn
- lpfc_rscn_payload_check
- lpfc_rscn_recovery_check
- lpfc_send_rscn_event
- lpfc_els_rcv_rscn
- lpfc_els_handle_rscn
- lpfc_els_rcv_flogi
- lpfc_els_rcv_rnid
- lpfc_els_rcv_echo
- lpfc_els_rcv_lirr
- lpfc_els_rcv_rrq
- lpfc_els_rsp_rls_acc
- lpfc_els_rsp_rps_acc
- lpfc_els_rcv_rls
- lpfc_els_rcv_rtv
- lpfc_els_rcv_rps
- lpfc_issue_els_rrq
- lpfc_send_rrq
- lpfc_els_rsp_rpl_acc
- lpfc_els_rcv_rpl
- lpfc_els_rcv_farp
- lpfc_els_rcv_farpr
- lpfc_els_rcv_fan
- lpfc_els_timeout
- lpfc_els_timeout_handler
- lpfc_els_flush_cmd
- lpfc_els_flush_all_cmd
- lpfc_send_els_failure_event
- lpfc_send_els_event
- lpfc_els_unsol_buffer
- lpfc_els_unsol_event
- lpfc_start_fdmi
- lpfc_do_scr_ns_plogi
- lpfc_cmpl_reg_new_vport
- lpfc_register_new_vport
- lpfc_cancel_all_vport_retry_delay_timer
- lpfc_retry_pport_discovery
- lpfc_fabric_login_reqd
- lpfc_cmpl_els_fdisc
- lpfc_issue_els_fdisc
- lpfc_cmpl_els_npiv_logo
- lpfc_issue_els_npiv_logo
- lpfc_fabric_block_timeout
- lpfc_resume_fabric_iocbs
- lpfc_unblock_fabric_iocbs
- lpfc_block_fabric_iocbs
- lpfc_cmpl_fabric_iocb
- lpfc_issue_fabric_iocb
- lpfc_fabric_abort_vport
- lpfc_fabric_abort_nport
- lpfc_fabric_abort_hba
- lpfc_sli4_vport_delete_els_xri_aborted
- lpfc_sli4_els_xri_aborted
- lpfc_sli_abts_recover_port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <uapi/scsi/fc/fc_fs.h>
34 #include <uapi/scsi/fc/fc_els.h>
35
36 #include "lpfc_hw4.h"
37 #include "lpfc_hw.h"
38 #include "lpfc_sli.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_nl.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
43 #include "lpfc.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
48
49 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
50 struct lpfc_iocbq *);
51 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
52 struct lpfc_iocbq *);
53 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp, uint8_t retry);
56 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57 struct lpfc_iocbq *iocb);
58
59 static int lpfc_max_els_tries = 3;
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 int
84 lpfc_els_chk_latt(struct lpfc_vport *vport)
85 {
86 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87 struct lpfc_hba *phba = vport->phba;
88 uint32_t ha_copy;
89
90 if (vport->port_state >= LPFC_VPORT_READY ||
91 phba->link_state == LPFC_LINK_DOWN ||
92 phba->sli_rev > LPFC_SLI_REV3)
93 return 0;
94
95
96 if (lpfc_readl(phba->HAregaddr, &ha_copy))
97 return 1;
98
99 if (!(ha_copy & HA_LATT))
100 return 0;
101
102
103 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
104 "0237 Pending Link Event during "
105 "Discovery: State x%x\n",
106 phba->pport->port_state);
107
108
109
110
111
112
113
114 spin_lock_irq(shost->host_lock);
115 vport->fc_flag |= FC_ABORT_DISCOVERY;
116 spin_unlock_irq(shost->host_lock);
117
118 if (phba->link_state != LPFC_CLEAR_LA)
119 lpfc_issue_clear_la(phba, vport);
120
121 return 1;
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 struct lpfc_iocbq *
153 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154 uint16_t cmdSize, uint8_t retry,
155 struct lpfc_nodelist *ndlp, uint32_t did,
156 uint32_t elscmd)
157 {
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_iocbq *elsiocb;
160 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161 struct ulp_bde64 *bpl;
162 IOCB_t *icmd;
163
164
165 if (!lpfc_is_link_up(phba))
166 return NULL;
167
168
169 elsiocb = lpfc_sli_get_iocbq(phba);
170
171 if (elsiocb == NULL)
172 return NULL;
173
174
175
176
177
178 if ((did == Fabric_DID) &&
179 (phba->hba_flag & HBA_FIP_SUPPORT) &&
180 ((elscmd == ELS_CMD_FLOGI) ||
181 (elscmd == ELS_CMD_FDISC) ||
182 (elscmd == ELS_CMD_LOGO)))
183 switch (elscmd) {
184 case ELS_CMD_FLOGI:
185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_FDISC:
190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
192 & LPFC_FIP_ELS_ID_MASK);
193 break;
194 case ELS_CMD_LOGO:
195 elsiocb->iocb_flag |=
196 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
197 & LPFC_FIP_ELS_ID_MASK);
198 break;
199 }
200 else
201 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
202
203 icmd = &elsiocb->iocb;
204
205
206
207 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
208 if (pcmd)
209 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
210 if (!pcmd || !pcmd->virt)
211 goto els_iocb_free_pcmb_exit;
212
213 INIT_LIST_HEAD(&pcmd->list);
214
215
216 if (expectRsp) {
217 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
218 if (prsp)
219 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
220 &prsp->phys);
221 if (!prsp || !prsp->virt)
222 goto els_iocb_free_prsp_exit;
223 INIT_LIST_HEAD(&prsp->list);
224 } else
225 prsp = NULL;
226
227
228 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
229 if (pbuflist)
230 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
231 &pbuflist->phys);
232 if (!pbuflist || !pbuflist->virt)
233 goto els_iocb_free_pbuf_exit;
234
235 INIT_LIST_HEAD(&pbuflist->list);
236
237 if (expectRsp) {
238 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
241 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
242
243 icmd->un.elsreq64.remoteID = did;
244 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
245 if (elscmd == ELS_CMD_FLOGI)
246 icmd->ulpTimeout = FF_DEF_RATOV * 2;
247 else if (elscmd == ELS_CMD_LOGO)
248 icmd->ulpTimeout = phba->fc_ratov;
249 else
250 icmd->ulpTimeout = phba->fc_ratov * 2;
251 } else {
252 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256 icmd->un.xseq64.xmit_els_remoteID = did;
257 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
258 }
259 icmd->ulpBdeCount = 1;
260 icmd->ulpLe = 1;
261 icmd->ulpClass = CLASS3;
262
263
264
265
266
267
268 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269 ((phba->sli_rev == LPFC_SLI_REV4) &&
270 (vport->fc_flag & FC_PT2PT))) {
271
272 if (expectRsp) {
273 icmd->un.elsreq64.myID = vport->fc_myDID;
274
275
276 icmd->ulpContext = phba->vpi_ids[vport->vpi];
277 }
278
279 icmd->ulpCt_h = 0;
280
281 if (elscmd == ELS_CMD_ECHO)
282 icmd->ulpCt_l = 0;
283 else
284 icmd->ulpCt_l = 1;
285 }
286
287 bpl = (struct ulp_bde64 *) pbuflist->virt;
288 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290 bpl->tus.f.bdeSize = cmdSize;
291 bpl->tus.f.bdeFlags = 0;
292 bpl->tus.w = le32_to_cpu(bpl->tus.w);
293
294 if (expectRsp) {
295 bpl++;
296 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298 bpl->tus.f.bdeSize = FCELSSIZE;
299 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
300 bpl->tus.w = le32_to_cpu(bpl->tus.w);
301 }
302
303
304 elsiocb->context1 = lpfc_nlp_get(ndlp);
305 if (!elsiocb->context1)
306 goto els_iocb_free_pbuf_exit;
307 elsiocb->context2 = pcmd;
308 elsiocb->context3 = pbuflist;
309 elsiocb->retry = retry;
310 elsiocb->vport = vport;
311 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312
313 if (prsp) {
314 list_add(&prsp->list, &pcmd->list);
315 }
316 if (expectRsp) {
317
318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
319 "0116 Xmit ELS command x%x to remote "
320 "NPORT x%x I/O tag: x%x, port state:x%x "
321 "rpi x%x fc_flag:x%x\n",
322 elscmd, did, elsiocb->iotag,
323 vport->port_state, ndlp->nlp_rpi,
324 vport->fc_flag);
325 } else {
326
327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328 "0117 Xmit ELS response x%x to remote "
329 "NPORT x%x I/O tag: x%x, size: x%x "
330 "port_state x%x rpi x%x fc_flag x%x\n",
331 elscmd, ndlp->nlp_DID, elsiocb->iotag,
332 cmdSize, vport->port_state,
333 ndlp->nlp_rpi, vport->fc_flag);
334 }
335 return elsiocb;
336
337 els_iocb_free_pbuf_exit:
338 if (expectRsp)
339 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
340 kfree(pbuflist);
341
342 els_iocb_free_prsp_exit:
343 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344 kfree(prsp);
345
346 els_iocb_free_pcmb_exit:
347 kfree(pcmd);
348 lpfc_sli_release_iocbq(phba, elsiocb);
349 return NULL;
350 }
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368 int
369 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
370 {
371 struct lpfc_hba *phba = vport->phba;
372 LPFC_MBOXQ_t *mbox;
373 struct lpfc_dmabuf *mp;
374 struct lpfc_nodelist *ndlp;
375 struct serv_parm *sp;
376 int rc;
377 int err = 0;
378
379 sp = &phba->fc_fabparam;
380 ndlp = lpfc_findnode_did(vport, Fabric_DID);
381 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
382 err = 1;
383 goto fail;
384 }
385
386 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
387 if (!mbox) {
388 err = 2;
389 goto fail;
390 }
391
392 vport->port_state = LPFC_FABRIC_CFG_LINK;
393 lpfc_config_link(phba, mbox);
394 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395 mbox->vport = vport;
396
397 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
398 if (rc == MBX_NOT_FINISHED) {
399 err = 3;
400 goto fail_free_mbox;
401 }
402
403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 if (!mbox) {
405 err = 4;
406 goto fail;
407 }
408 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
409 ndlp->nlp_rpi);
410 if (rc) {
411 err = 5;
412 goto fail_free_mbox;
413 }
414
415 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
416 mbox->vport = vport;
417
418
419
420 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
421
422 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
423 if (rc == MBX_NOT_FINISHED) {
424 err = 6;
425 goto fail_issue_reg_login;
426 }
427
428 return 0;
429
430 fail_issue_reg_login:
431
432
433
434 lpfc_nlp_put(ndlp);
435 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
436 lpfc_mbuf_free(phba, mp->virt, mp->phys);
437 kfree(mp);
438 fail_free_mbox:
439 mempool_free(mbox, phba->mbox_mem_pool);
440
441 fail:
442 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
443 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
444 "0249 Cannot issue Register Fabric login: Err %d\n", err);
445 return -ENXIO;
446 }
447
448
449
450
451
452
453
454
455
456
457
458
459 int
460 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
461 {
462 struct lpfc_hba *phba = vport->phba;
463 LPFC_MBOXQ_t *mboxq = NULL;
464 struct lpfc_nodelist *ndlp;
465 struct lpfc_dmabuf *dmabuf = NULL;
466 int rc = 0;
467
468
469 if ((phba->sli_rev == LPFC_SLI_REV4) &&
470 !(phba->link_flag & LS_LOOPBACK_MODE) &&
471 !(vport->fc_flag & FC_PT2PT)) {
472 ndlp = lpfc_findnode_did(vport, Fabric_DID);
473 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
474 rc = -ENODEV;
475 goto fail;
476 }
477 }
478
479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 if (!mboxq) {
481 rc = -ENOMEM;
482 goto fail;
483 }
484
485
486 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
487 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
488 if (!dmabuf) {
489 rc = -ENOMEM;
490 goto fail;
491 }
492 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
493 if (!dmabuf->virt) {
494 rc = -ENOMEM;
495 goto fail;
496 }
497 memcpy(dmabuf->virt, &phba->fc_fabparam,
498 sizeof(struct serv_parm));
499 }
500
501 vport->port_state = LPFC_FABRIC_CFG_LINK;
502 if (dmabuf)
503 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
504 else
505 lpfc_reg_vfi(mboxq, vport, 0);
506
507 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
508 mboxq->vport = vport;
509 mboxq->ctx_buf = dmabuf;
510 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
511 if (rc == MBX_NOT_FINISHED) {
512 rc = -ENXIO;
513 goto fail;
514 }
515 return 0;
516
517 fail:
518 if (mboxq)
519 mempool_free(mboxq, phba->mbox_mem_pool);
520 if (dmabuf) {
521 if (dmabuf->virt)
522 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
523 kfree(dmabuf);
524 }
525
526 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
527 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
528 "0289 Issue Register VFI failed: Err %d\n", rc);
529 return rc;
530 }
531
532
533
534
535
536
537
538
539
540
541
542
543 int
544 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
545 {
546 struct lpfc_hba *phba = vport->phba;
547 struct Scsi_Host *shost;
548 LPFC_MBOXQ_t *mboxq;
549 int rc;
550
551 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
552 if (!mboxq) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
554 "2556 UNREG_VFI mbox allocation failed"
555 "HBA state x%x\n", phba->pport->port_state);
556 return -ENOMEM;
557 }
558
559 lpfc_unreg_vfi(mboxq, vport);
560 mboxq->vport = vport;
561 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
562
563 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
564 if (rc == MBX_NOT_FINISHED) {
565 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
566 "2557 UNREG_VFI issue mbox failed rc x%x "
567 "HBA state x%x\n",
568 rc, phba->pport->port_state);
569 mempool_free(mboxq, phba->mbox_mem_pool);
570 return -EIO;
571 }
572
573 shost = lpfc_shost_from_vport(vport);
574 spin_lock_irq(shost->host_lock);
575 vport->fc_flag &= ~FC_VFI_REGISTERED;
576 spin_unlock_irq(shost->host_lock);
577 return 0;
578 }
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598 static uint8_t
599 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
600 struct serv_parm *sp)
601 {
602 struct lpfc_hba *phba = vport->phba;
603 uint8_t fabric_param_changed = 0;
604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
605
606 if ((vport->fc_prevDID != vport->fc_myDID) ||
607 memcmp(&vport->fabric_portname, &sp->portName,
608 sizeof(struct lpfc_name)) ||
609 memcmp(&vport->fabric_nodename, &sp->nodeName,
610 sizeof(struct lpfc_name)) ||
611 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
612 fabric_param_changed = 1;
613 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
614 }
615
616
617
618
619
620
621
622
623
624
625 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
626 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
627 spin_lock_irq(shost->host_lock);
628 vport->fc_flag |= FC_DISC_DELAYED;
629 spin_unlock_irq(shost->host_lock);
630 }
631
632 return fabric_param_changed;
633 }
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656 static int
657 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp, IOCB_t *irsp)
659 {
660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
662 struct lpfc_nodelist *np;
663 struct lpfc_nodelist *next_np;
664 uint8_t fabric_param_changed;
665
666 spin_lock_irq(shost->host_lock);
667 vport->fc_flag |= FC_FABRIC;
668 spin_unlock_irq(shost->host_lock);
669
670 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
671 if (sp->cmn.edtovResolution)
672 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
673
674 phba->fc_edtovResol = sp->cmn.edtovResolution;
675 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
676
677 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
678 spin_lock_irq(shost->host_lock);
679 vport->fc_flag |= FC_PUBLIC_LOOP;
680 spin_unlock_irq(shost->host_lock);
681 }
682
683 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
684 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
685 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
686 ndlp->nlp_class_sup = 0;
687 if (sp->cls1.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS1;
689 if (sp->cls2.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS2;
691 if (sp->cls3.classValid)
692 ndlp->nlp_class_sup |= FC_COS_CLASS3;
693 if (sp->cls4.classValid)
694 ndlp->nlp_class_sup |= FC_COS_CLASS4;
695 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
696 sp->cmn.bbRcvSizeLsb;
697
698 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
699 if (fabric_param_changed) {
700
701 if (phba->cfg_enable_SmartSAN ||
702 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
703
704 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
705 if (phba->cfg_enable_SmartSAN)
706 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
707 else
708 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
709 } else {
710 vport->fdmi_hba_mask = 0;
711 vport->fdmi_port_mask = 0;
712 }
713
714 }
715 memcpy(&vport->fabric_portname, &sp->portName,
716 sizeof(struct lpfc_name));
717 memcpy(&vport->fabric_nodename, &sp->nodeName,
718 sizeof(struct lpfc_name));
719 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
720
721 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
722 if (sp->cmn.response_multiple_NPort) {
723 lpfc_printf_vlog(vport, KERN_WARNING,
724 LOG_ELS | LOG_VPORT,
725 "1816 FLOGI NPIV supported, "
726 "response data 0x%x\n",
727 sp->cmn.response_multiple_NPort);
728 spin_lock_irq(&phba->hbalock);
729 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
730 spin_unlock_irq(&phba->hbalock);
731 } else {
732
733
734 lpfc_printf_vlog(vport, KERN_WARNING,
735 LOG_ELS | LOG_VPORT,
736 "1817 Fabric does not support NPIV "
737 "- configuring single port mode.\n");
738 spin_lock_irq(&phba->hbalock);
739 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
740 spin_unlock_irq(&phba->hbalock);
741 }
742 }
743
744
745
746
747
748 if ((phba->sli_rev == LPFC_SLI_REV4) &&
749 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
750
751 if (fabric_param_changed)
752 lpfc_unregister_fcf_prep(phba);
753
754
755 if (vport->fc_flag & FC_VFI_REGISTERED)
756 lpfc_issue_reg_vfi(vport);
757 }
758
759 if (fabric_param_changed &&
760 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
761
762
763
764
765 list_for_each_entry_safe(np, next_np,
766 &vport->fc_nodes, nlp_listp) {
767 if (!NLP_CHK_NODE_ACT(np))
768 continue;
769 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
770 !(np->nlp_flag & NLP_NPR_ADISC))
771 continue;
772 spin_lock_irq(shost->host_lock);
773 np->nlp_flag &= ~NLP_NPR_ADISC;
774 spin_unlock_irq(shost->host_lock);
775 lpfc_unreg_rpi(vport, np);
776 }
777 lpfc_cleanup_pending_mbox(vport);
778
779 if (phba->sli_rev == LPFC_SLI_REV4) {
780 lpfc_sli4_unreg_all_rpis(vport);
781 lpfc_mbx_unreg_vpi(vport);
782 spin_lock_irq(shost->host_lock);
783 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
784 spin_unlock_irq(shost->host_lock);
785 }
786
787
788
789
790
791 spin_lock_irq(shost->host_lock);
792 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
793 spin_unlock_irq(shost->host_lock);
794 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
795 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
796
797
798
799
800 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
801 lpfc_register_new_vport(phba, vport, ndlp);
802 return 0;
803 }
804
805 if (phba->sli_rev < LPFC_SLI_REV4) {
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
808 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
809 lpfc_register_new_vport(phba, vport, ndlp);
810 else
811 lpfc_issue_fabric_reglogin(vport);
812 } else {
813 ndlp->nlp_type |= NLP_FABRIC;
814 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
815 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
816 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
817 lpfc_start_fdiscs(phba);
818 lpfc_do_scr_ns_plogi(phba, vport);
819 } else if (vport->fc_flag & FC_VFI_REGISTERED)
820 lpfc_issue_init_vpi(vport);
821 else {
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
823 "3135 Need register VFI: (x%x/%x)\n",
824 vport->fc_prevDID, vport->fc_myDID);
825 lpfc_issue_reg_vfi(vport);
826 }
827 }
828 return 0;
829 }
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851 static int
852 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
853 struct serv_parm *sp)
854 {
855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 struct lpfc_hba *phba = vport->phba;
857 LPFC_MBOXQ_t *mbox;
858 int rc;
859
860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
862 vport->fc_flag |= FC_PT2PT;
863 spin_unlock_irq(shost->host_lock);
864
865
866 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
867
868
869 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
870 lpfc_unregister_fcf_prep(phba);
871
872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag &= ~FC_VFI_REGISTERED;
874 spin_unlock_irq(shost->host_lock);
875 phba->fc_topology_changed = 0;
876 }
877
878 rc = memcmp(&vport->fc_portname, &sp->portName,
879 sizeof(vport->fc_portname));
880
881 if (rc >= 0) {
882
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag |= FC_PT2PT_PLOGI;
885 spin_unlock_irq(shost->host_lock);
886
887
888
889
890
891
892
893 if (rc)
894 vport->fc_myDID = PT2PT_LocalID;
895
896
897
898
899 lpfc_nlp_put(ndlp);
900
901 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
902 if (!ndlp) {
903
904
905
906
907 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
908 if (!ndlp)
909 goto fail;
910 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
911 ndlp = lpfc_enable_node(vport, ndlp,
912 NLP_STE_UNUSED_NODE);
913 if(!ndlp)
914 goto fail;
915 }
916
917 memcpy(&ndlp->nlp_portname, &sp->portName,
918 sizeof(struct lpfc_name));
919 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
920 sizeof(struct lpfc_name));
921
922 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
923 spin_lock_irq(shost->host_lock);
924 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
925 spin_unlock_irq(shost->host_lock);
926
927 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
928 if (!mbox)
929 goto fail;
930
931 lpfc_config_link(phba, mbox);
932
933 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
934 mbox->vport = vport;
935 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
936 if (rc == MBX_NOT_FINISHED) {
937 mempool_free(mbox, phba->mbox_mem_pool);
938 goto fail;
939 }
940 } else {
941
942
943
944
945 lpfc_nlp_put(ndlp);
946
947
948 lpfc_disc_start(vport);
949 }
950
951 return 0;
952 fail:
953 return -ENXIO;
954 }
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979 static void
980 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
981 struct lpfc_iocbq *rspiocb)
982 {
983 struct lpfc_vport *vport = cmdiocb->vport;
984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
985 IOCB_t *irsp = &rspiocb->iocb;
986 struct lpfc_nodelist *ndlp = cmdiocb->context1;
987 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
988 struct serv_parm *sp;
989 uint16_t fcf_index;
990 int rc;
991
992
993 if (lpfc_els_chk_latt(vport)) {
994
995
996
997 lpfc_nlp_put(ndlp);
998 goto out;
999 }
1000
1001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1002 "FLOGI cmpl: status:x%x/x%x state:x%x",
1003 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 vport->port_state);
1005
1006 if (irsp->ulpStatus) {
1007
1008
1009
1010
1011 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1012 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1013 if (phba->link_state < LPFC_LINK_UP)
1014 goto stop_rr_fcf_flogi;
1015 if ((phba->fcoe_cvl_eventtag_attn ==
1016 phba->fcoe_cvl_eventtag) &&
1017 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1018 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1019 IOERR_SLI_ABORTED))
1020 goto stop_rr_fcf_flogi;
1021 else
1022 phba->fcoe_cvl_eventtag_attn =
1023 phba->fcoe_cvl_eventtag;
1024 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1025 "2611 FLOGI failed on FCF (x%x), "
1026 "status:x%x/x%x, tmo:x%x, perform "
1027 "roundrobin FCF failover\n",
1028 phba->fcf.current_rec.fcf_indx,
1029 irsp->ulpStatus, irsp->un.ulpWord[4],
1030 irsp->ulpTimeout);
1031 lpfc_sli4_set_fcf_flogi_fail(phba,
1032 phba->fcf.current_rec.fcf_indx);
1033 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1034 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1035 if (rc)
1036 goto out;
1037 }
1038
1039 stop_rr_fcf_flogi:
1040
1041 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1042 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1043 IOERR_LOOP_OPEN_FAILURE)))
1044 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1045 "2858 FLOGI failure Status:x%x/x%x "
1046 "TMO:x%x Data x%x x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1048 irsp->ulpTimeout, phba->hba_flag,
1049 phba->fcf.fcf_flag);
1050
1051
1052 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1053 goto out;
1054
1055 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1056 "0150 FLOGI failure Status:x%x/x%x "
1057 "xri x%x TMO:x%x\n",
1058 irsp->ulpStatus, irsp->un.ulpWord[4],
1059 cmdiocb->sli4_xritag, irsp->ulpTimeout);
1060
1061
1062 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1063 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1064 IOERR_LOOP_OPEN_FAILURE)))
1065 goto flogifail;
1066
1067
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1070 spin_unlock_irq(shost->host_lock);
1071
1072
1073
1074
1075
1076 if (phba->alpa_map[0] == 0)
1077 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1078 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1079 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1080 (vport->fc_prevDID != vport->fc_myDID) ||
1081 phba->fc_topology_changed)) {
1082 if (vport->fc_flag & FC_VFI_REGISTERED) {
1083 if (phba->fc_topology_changed) {
1084 lpfc_unregister_fcf_prep(phba);
1085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VFI_REGISTERED;
1087 spin_unlock_irq(shost->host_lock);
1088 phba->fc_topology_changed = 0;
1089 } else {
1090 lpfc_sli4_unreg_all_rpis(vport);
1091 }
1092 }
1093
1094
1095 if (!lpfc_error_lost_link(irsp))
1096 lpfc_issue_reg_vfi(vport);
1097 lpfc_nlp_put(ndlp);
1098 goto out;
1099 }
1100 goto flogifail;
1101 }
1102 spin_lock_irq(shost->host_lock);
1103 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1104 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1105 spin_unlock_irq(shost->host_lock);
1106
1107
1108
1109
1110
1111 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1112 if (!prsp)
1113 goto out;
1114 sp = prsp->virt + sizeof(uint32_t);
1115
1116
1117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1118 "0101 FLOGI completes successfully, I/O tag:x%x, "
1119 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1120 cmdiocb->iotag, cmdiocb->sli4_xritag,
1121 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1122 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1123 vport->port_state, vport->fc_flag);
1124
1125 if (vport->port_state == LPFC_FLOGI) {
1126
1127
1128
1129
1130 if (sp->cmn.fPort)
1131 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1132 else if (!(phba->hba_flag & HBA_FCOE_MODE))
1133 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1134 else {
1135 lpfc_printf_vlog(vport, KERN_ERR,
1136 LOG_FIP | LOG_ELS,
1137 "2831 FLOGI response with cleared Fabric "
1138 "bit fcf_index 0x%x "
1139 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1140 "Fabric Name "
1141 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1142 phba->fcf.current_rec.fcf_indx,
1143 phba->fcf.current_rec.switch_name[0],
1144 phba->fcf.current_rec.switch_name[1],
1145 phba->fcf.current_rec.switch_name[2],
1146 phba->fcf.current_rec.switch_name[3],
1147 phba->fcf.current_rec.switch_name[4],
1148 phba->fcf.current_rec.switch_name[5],
1149 phba->fcf.current_rec.switch_name[6],
1150 phba->fcf.current_rec.switch_name[7],
1151 phba->fcf.current_rec.fabric_name[0],
1152 phba->fcf.current_rec.fabric_name[1],
1153 phba->fcf.current_rec.fabric_name[2],
1154 phba->fcf.current_rec.fabric_name[3],
1155 phba->fcf.current_rec.fabric_name[4],
1156 phba->fcf.current_rec.fabric_name[5],
1157 phba->fcf.current_rec.fabric_name[6],
1158 phba->fcf.current_rec.fabric_name[7]);
1159 lpfc_nlp_put(ndlp);
1160 spin_lock_irq(&phba->hbalock);
1161 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1162 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1163 spin_unlock_irq(&phba->hbalock);
1164 phba->fcf.fcf_redisc_attempted = 0;
1165 goto out;
1166 }
1167 if (!rc) {
1168
1169 if (phba->hba_flag & HBA_FIP_SUPPORT)
1170 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1171 LOG_ELS,
1172 "2769 FLOGI to FCF (x%x) "
1173 "completed successfully\n",
1174 phba->fcf.current_rec.fcf_indx);
1175 spin_lock_irq(&phba->hbalock);
1176 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1177 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1178 spin_unlock_irq(&phba->hbalock);
1179 phba->fcf.fcf_redisc_attempted = 0;
1180 goto out;
1181 }
1182 }
1183
1184 flogifail:
1185 spin_lock_irq(&phba->hbalock);
1186 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1187 spin_unlock_irq(&phba->hbalock);
1188
1189 lpfc_nlp_put(ndlp);
1190
1191 if (!lpfc_error_lost_link(irsp)) {
1192
1193 lpfc_disc_list_loopmap(vport);
1194
1195
1196 lpfc_disc_start(vport);
1197 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1198 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1199 IOERR_SLI_ABORTED) &&
1200 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1201 IOERR_SLI_DOWN))) &&
1202 (phba->link_state != LPFC_CLEAR_LA)) {
1203
1204 lpfc_issue_clear_la(phba, vport);
1205 }
1206 out:
1207 lpfc_els_free_iocb(phba, cmdiocb);
1208 }
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218 static void
1219 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1220 struct lpfc_iocbq *rspiocb)
1221 {
1222 IOCB_t *irsp;
1223 uint32_t *pcmd;
1224 uint32_t cmd;
1225
1226 pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1227 cmd = *pcmd;
1228 irsp = &rspiocb->iocb;
1229
1230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1231 "6445 ELS completes after LINK_DOWN: "
1232 " Status %x/%x cmd x%x flg x%x\n",
1233 irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1234 cmdiocb->iocb_flag);
1235
1236 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1237 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1238 atomic_dec(&phba->fabric_iocb_count);
1239 }
1240 lpfc_els_free_iocb(phba, cmdiocb);
1241 }
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 static int
1266 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1267 uint8_t retry)
1268 {
1269 struct lpfc_hba *phba = vport->phba;
1270 struct serv_parm *sp;
1271 IOCB_t *icmd;
1272 struct lpfc_iocbq *elsiocb;
1273 struct lpfc_iocbq defer_flogi_acc;
1274 uint8_t *pcmd;
1275 uint16_t cmdsize;
1276 uint32_t tmo, did;
1277 int rc;
1278
1279 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1280 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1281 ndlp->nlp_DID, ELS_CMD_FLOGI);
1282
1283 if (!elsiocb)
1284 return 1;
1285
1286 icmd = &elsiocb->iocb;
1287 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1288
1289
1290 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1291 pcmd += sizeof(uint32_t);
1292 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1293 sp = (struct serv_parm *) pcmd;
1294
1295
1296 sp->cmn.e_d_tov = 0;
1297 sp->cmn.w2.r_a_tov = 0;
1298 sp->cmn.virtual_fabric_support = 0;
1299 sp->cls1.classValid = 0;
1300 if (sp->cmn.fcphLow < FC_PH3)
1301 sp->cmn.fcphLow = FC_PH3;
1302 if (sp->cmn.fcphHigh < FC_PH3)
1303 sp->cmn.fcphHigh = FC_PH3;
1304
1305 if (phba->sli_rev == LPFC_SLI_REV4) {
1306 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1307 LPFC_SLI_INTF_IF_TYPE_0) {
1308 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1309 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1310
1311
1312 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1313 }
1314
1315 sp->cls2.classValid = 0;
1316 sp->cls2.seqDelivery = 0;
1317 } else {
1318
1319 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1320 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1321 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1322 sp->cmn.request_multiple_Nport = 1;
1323
1324 icmd->ulpCt_h = 1;
1325 icmd->ulpCt_l = 0;
1326 } else
1327 sp->cmn.request_multiple_Nport = 0;
1328 }
1329
1330 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1331 icmd->un.elsreq64.myID = 0;
1332 icmd->un.elsreq64.fl = 1;
1333 }
1334
1335 tmo = phba->fc_ratov;
1336 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1337 lpfc_set_disctmo(vport);
1338 phba->fc_ratov = tmo;
1339
1340 phba->fc_stat.elsXmitFLOGI++;
1341 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1342
1343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1344 "Issue FLOGI: opt:x%x",
1345 phba->sli3_options, 0, 0);
1346
1347 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1348
1349 phba->hba_flag |= HBA_FLOGI_ISSUED;
1350
1351
1352 if (phba->defer_flogi_acc_flag) {
1353 did = vport->fc_myDID;
1354 vport->fc_myDID = Fabric_DID;
1355
1356 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1357
1358 defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1359 defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1360 phba->defer_flogi_acc_ox_id;
1361
1362 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1363 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1364 " ox_id: x%x, hba_flag x%x\n",
1365 phba->defer_flogi_acc_rx_id,
1366 phba->defer_flogi_acc_ox_id, phba->hba_flag);
1367
1368
1369 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1370 ndlp, NULL);
1371
1372 phba->defer_flogi_acc_flag = false;
1373
1374 vport->fc_myDID = did;
1375 }
1376
1377 if (rc == IOCB_ERROR) {
1378 lpfc_els_free_iocb(phba, elsiocb);
1379 return 1;
1380 }
1381 return 0;
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398 int
1399 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1400 {
1401 struct lpfc_sli_ring *pring;
1402 struct lpfc_iocbq *iocb, *next_iocb;
1403 struct lpfc_nodelist *ndlp;
1404 IOCB_t *icmd;
1405
1406
1407 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1408 "0201 Abort outstanding I/O on NPort x%x\n",
1409 Fabric_DID);
1410
1411 pring = lpfc_phba_elsring(phba);
1412 if (unlikely(!pring))
1413 return -EIO;
1414
1415
1416
1417
1418
1419 spin_lock_irq(&phba->hbalock);
1420 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1421 icmd = &iocb->iocb;
1422 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1423 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1424 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1425 (ndlp->nlp_DID == Fabric_DID))
1426 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1427 }
1428 }
1429 spin_unlock_irq(&phba->hbalock);
1430
1431 return 0;
1432 }
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450 int
1451 lpfc_initial_flogi(struct lpfc_vport *vport)
1452 {
1453 struct lpfc_nodelist *ndlp;
1454
1455 vport->port_state = LPFC_FLOGI;
1456 lpfc_set_disctmo(vport);
1457
1458
1459 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1460 if (!ndlp) {
1461
1462 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1463 if (!ndlp)
1464 return 0;
1465
1466 ndlp->nlp_type |= NLP_FABRIC;
1467
1468 lpfc_enqueue_node(vport, ndlp);
1469 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1470
1471 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1472 if (!ndlp)
1473 return 0;
1474 }
1475
1476 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1477
1478
1479
1480 lpfc_nlp_put(ndlp);
1481 return 0;
1482 }
1483 return 1;
1484 }
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502 int
1503 lpfc_initial_fdisc(struct lpfc_vport *vport)
1504 {
1505 struct lpfc_nodelist *ndlp;
1506
1507
1508 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1509 if (!ndlp) {
1510
1511 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1512 if (!ndlp)
1513 return 0;
1514
1515 lpfc_enqueue_node(vport, ndlp);
1516 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1517
1518 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1519 if (!ndlp)
1520 return 0;
1521 }
1522
1523 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1524
1525
1526
1527 lpfc_nlp_put(ndlp);
1528 return 0;
1529 }
1530 return 1;
1531 }
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 void
1545 lpfc_more_plogi(struct lpfc_vport *vport)
1546 {
1547 if (vport->num_disc_nodes)
1548 vport->num_disc_nodes--;
1549
1550
1551 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1552 "0232 Continue discovery with %d PLOGIs to go "
1553 "Data: x%x x%x x%x\n",
1554 vport->num_disc_nodes, vport->fc_plogi_cnt,
1555 vport->fc_flag, vport->port_state);
1556
1557 if (vport->fc_flag & FC_NLP_MORE)
1558
1559 lpfc_els_disc_plogi(vport);
1560
1561 return;
1562 }
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595 static struct lpfc_nodelist *
1596 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1597 struct lpfc_nodelist *ndlp)
1598 {
1599 struct lpfc_vport *vport = ndlp->vport;
1600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1601 struct lpfc_nodelist *new_ndlp;
1602 struct lpfc_rport_data *rdata;
1603 struct fc_rport *rport;
1604 struct serv_parm *sp;
1605 uint8_t name[sizeof(struct lpfc_name)];
1606 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1607 uint32_t keep_new_nlp_flag = 0;
1608 uint16_t keep_nlp_state;
1609 u32 keep_nlp_fc4_type = 0;
1610 struct lpfc_nvme_rport *keep_nrport = NULL;
1611 int put_node;
1612 int put_rport;
1613 unsigned long *active_rrqs_xri_bitmap = NULL;
1614
1615
1616
1617
1618 if (ndlp->nlp_type & NLP_FABRIC)
1619 return ndlp;
1620
1621 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1622 memset(name, 0, sizeof(struct lpfc_name));
1623
1624
1625
1626
1627 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1628
1629
1630 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1631 return ndlp;
1632
1633 if (phba->sli_rev == LPFC_SLI_REV4) {
1634 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1635 GFP_KERNEL);
1636 if (active_rrqs_xri_bitmap)
1637 memset(active_rrqs_xri_bitmap, 0,
1638 phba->cfg_rrq_xri_bitmap_sz);
1639 }
1640
1641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1642 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1643 "new_ndlp x%x x%x x%x\n",
1644 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1645 (new_ndlp ? new_ndlp->nlp_DID : 0),
1646 (new_ndlp ? new_ndlp->nlp_flag : 0),
1647 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1648
1649 if (!new_ndlp) {
1650 rc = memcmp(&ndlp->nlp_portname, name,
1651 sizeof(struct lpfc_name));
1652 if (!rc) {
1653 if (active_rrqs_xri_bitmap)
1654 mempool_free(active_rrqs_xri_bitmap,
1655 phba->active_rrq_pool);
1656 return ndlp;
1657 }
1658 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1659 if (!new_ndlp) {
1660 if (active_rrqs_xri_bitmap)
1661 mempool_free(active_rrqs_xri_bitmap,
1662 phba->active_rrq_pool);
1663 return ndlp;
1664 }
1665 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1666 rc = memcmp(&ndlp->nlp_portname, name,
1667 sizeof(struct lpfc_name));
1668 if (!rc) {
1669 if (active_rrqs_xri_bitmap)
1670 mempool_free(active_rrqs_xri_bitmap,
1671 phba->active_rrq_pool);
1672 return ndlp;
1673 }
1674 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1675 NLP_STE_UNUSED_NODE);
1676 if (!new_ndlp) {
1677 if (active_rrqs_xri_bitmap)
1678 mempool_free(active_rrqs_xri_bitmap,
1679 phba->active_rrq_pool);
1680 return ndlp;
1681 }
1682 keepDID = new_ndlp->nlp_DID;
1683 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1684 memcpy(active_rrqs_xri_bitmap,
1685 new_ndlp->active_rrqs_xri_bitmap,
1686 phba->cfg_rrq_xri_bitmap_sz);
1687 } else {
1688 keepDID = new_ndlp->nlp_DID;
1689 if (phba->sli_rev == LPFC_SLI_REV4 &&
1690 active_rrqs_xri_bitmap)
1691 memcpy(active_rrqs_xri_bitmap,
1692 new_ndlp->active_rrqs_xri_bitmap,
1693 phba->cfg_rrq_xri_bitmap_sz);
1694 }
1695
1696
1697
1698
1699
1700
1701 if (vport->fc_flag & FC_FABRIC) {
1702 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1703 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1704 }
1705
1706 lpfc_unreg_rpi(vport, new_ndlp);
1707 new_ndlp->nlp_DID = ndlp->nlp_DID;
1708 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1709 if (phba->sli_rev == LPFC_SLI_REV4)
1710 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1711 ndlp->active_rrqs_xri_bitmap,
1712 phba->cfg_rrq_xri_bitmap_sz);
1713
1714 spin_lock_irq(shost->host_lock);
1715 keep_new_nlp_flag = new_ndlp->nlp_flag;
1716 keep_nlp_flag = ndlp->nlp_flag;
1717 new_ndlp->nlp_flag = ndlp->nlp_flag;
1718
1719
1720 if (keep_new_nlp_flag & NLP_UNREG_INP)
1721 new_ndlp->nlp_flag |= NLP_UNREG_INP;
1722 else
1723 new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1724
1725
1726 if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1727 new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1728 else
1729 new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1730
1731 ndlp->nlp_flag = keep_new_nlp_flag;
1732
1733
1734 if (keep_nlp_flag & NLP_UNREG_INP)
1735 ndlp->nlp_flag |= NLP_UNREG_INP;
1736 else
1737 ndlp->nlp_flag &= ~NLP_UNREG_INP;
1738
1739
1740 if (keep_nlp_flag & NLP_RPI_REGISTERED)
1741 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1742 else
1743 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1744
1745 spin_unlock_irq(shost->host_lock);
1746
1747
1748 keep_nlp_state = new_ndlp->nlp_state;
1749 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1750
1751
1752 keep_nrport = new_ndlp->nrport;
1753 new_ndlp->nrport = ndlp->nrport;
1754
1755
1756 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1757
1758
1759
1760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1761 "3179 PLOGI confirm NEW: %x %x\n",
1762 new_ndlp->nlp_DID, keepDID);
1763
1764
1765 rport = ndlp->rport;
1766 if (rport) {
1767 rdata = rport->dd_data;
1768 if (rdata->pnode == ndlp) {
1769
1770 ndlp->rport = NULL;
1771 lpfc_nlp_put(ndlp);
1772 rdata->pnode = lpfc_nlp_get(new_ndlp);
1773 new_ndlp->rport = rport;
1774 }
1775 new_ndlp->nlp_type = ndlp->nlp_type;
1776 }
1777
1778
1779 if (ndlp->nrport) {
1780 ndlp->nrport = NULL;
1781 lpfc_nlp_put(ndlp);
1782 }
1783
1784
1785
1786
1787
1788 if (ndlp->nlp_DID == 0) {
1789 spin_lock_irq(&phba->ndlp_lock);
1790 NLP_SET_FREE_REQ(ndlp);
1791 spin_unlock_irq(&phba->ndlp_lock);
1792 }
1793
1794
1795
1796
1797
1798 ndlp->nlp_DID = keepDID;
1799 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1800 if (phba->sli_rev == LPFC_SLI_REV4 &&
1801 active_rrqs_xri_bitmap)
1802 memcpy(ndlp->active_rrqs_xri_bitmap,
1803 active_rrqs_xri_bitmap,
1804 phba->cfg_rrq_xri_bitmap_sz);
1805
1806 if (!NLP_CHK_NODE_ACT(ndlp))
1807 lpfc_drop_node(vport, ndlp);
1808 }
1809 else {
1810 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1811 "3180 PLOGI confirm SWAP: %x %x\n",
1812 new_ndlp->nlp_DID, keepDID);
1813
1814 lpfc_unreg_rpi(vport, ndlp);
1815
1816
1817
1818
1819
1820 ndlp->nlp_DID = keepDID;
1821 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1822
1823 if (phba->sli_rev == LPFC_SLI_REV4 &&
1824 active_rrqs_xri_bitmap)
1825 memcpy(ndlp->active_rrqs_xri_bitmap,
1826 active_rrqs_xri_bitmap,
1827 phba->cfg_rrq_xri_bitmap_sz);
1828
1829
1830
1831
1832 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1833 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1834 keep_nlp_state = NLP_STE_NPR_NODE;
1835 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1836
1837
1838
1839
1840
1841 if (ndlp->nrport)
1842 lpfc_nlp_put(ndlp);
1843 ndlp->nrport = keep_nrport;
1844
1845
1846 rport = ndlp->rport;
1847 if (rport) {
1848 rdata = rport->dd_data;
1849 put_node = rdata->pnode != NULL;
1850 put_rport = ndlp->rport != NULL;
1851 rdata->pnode = NULL;
1852 ndlp->rport = NULL;
1853 if (put_node)
1854 lpfc_nlp_put(ndlp);
1855 if (put_rport)
1856 put_device(&rport->dev);
1857 }
1858 }
1859 if (phba->sli_rev == LPFC_SLI_REV4 &&
1860 active_rrqs_xri_bitmap)
1861 mempool_free(active_rrqs_xri_bitmap,
1862 phba->active_rrq_pool);
1863
1864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1865 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1866 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1867 new_ndlp->nlp_fc4_type);
1868
1869 return new_ndlp;
1870 }
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883 void
1884 lpfc_end_rscn(struct lpfc_vport *vport)
1885 {
1886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1887
1888 if (vport->fc_flag & FC_RSCN_MODE) {
1889
1890
1891
1892
1893 if (vport->fc_rscn_id_cnt ||
1894 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1895 lpfc_els_handle_rscn(vport);
1896 else {
1897 spin_lock_irq(shost->host_lock);
1898 vport->fc_flag &= ~FC_RSCN_MODE;
1899 spin_unlock_irq(shost->host_lock);
1900 }
1901 }
1902 }
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916 static void
1917 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1918 struct lpfc_iocbq *rspiocb)
1919 {
1920 struct lpfc_vport *vport = cmdiocb->vport;
1921 IOCB_t *irsp;
1922 struct lpfc_nodelist *ndlp;
1923 struct lpfc_node_rrq *rrq;
1924
1925
1926 rrq = cmdiocb->context_un.rrq;
1927 cmdiocb->context_un.rsp_iocb = rspiocb;
1928
1929 irsp = &rspiocb->iocb;
1930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1931 "RRQ cmpl: status:x%x/x%x did:x%x",
1932 irsp->ulpStatus, irsp->un.ulpWord[4],
1933 irsp->un.elsreq64.remoteID);
1934
1935 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1936 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1937 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1938 "2882 RRQ completes to NPort x%x "
1939 "with no ndlp. Data: x%x x%x x%x\n",
1940 irsp->un.elsreq64.remoteID,
1941 irsp->ulpStatus, irsp->un.ulpWord[4],
1942 irsp->ulpIoTag);
1943 goto out;
1944 }
1945
1946
1947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1948 "2880 RRQ completes to NPort x%x "
1949 "Data: x%x x%x x%x x%x x%x\n",
1950 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1951 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1952
1953 if (irsp->ulpStatus) {
1954
1955
1956 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1957 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1958 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1959 (phba)->pport->cfg_log_verbose & LOG_ELS)
1960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1961 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1962 ndlp->nlp_DID, irsp->ulpStatus,
1963 irsp->un.ulpWord[4]);
1964 }
1965 out:
1966 if (rrq)
1967 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1968 lpfc_els_free_iocb(phba, cmdiocb);
1969 return;
1970 }
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991 static void
1992 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1993 struct lpfc_iocbq *rspiocb)
1994 {
1995 struct lpfc_vport *vport = cmdiocb->vport;
1996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1997 IOCB_t *irsp;
1998 struct lpfc_nodelist *ndlp;
1999 struct lpfc_dmabuf *prsp;
2000 int disc;
2001
2002
2003 cmdiocb->context_un.rsp_iocb = rspiocb;
2004
2005 irsp = &rspiocb->iocb;
2006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2007 "PLOGI cmpl: status:x%x/x%x did:x%x",
2008 irsp->ulpStatus, irsp->un.ulpWord[4],
2009 irsp->un.elsreq64.remoteID);
2010
2011 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
2012 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2013 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2014 "0136 PLOGI completes to NPort x%x "
2015 "with no ndlp. Data: x%x x%x x%x\n",
2016 irsp->un.elsreq64.remoteID,
2017 irsp->ulpStatus, irsp->un.ulpWord[4],
2018 irsp->ulpIoTag);
2019 goto out;
2020 }
2021
2022
2023
2024
2025 spin_lock_irq(shost->host_lock);
2026 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2027 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2028 spin_unlock_irq(shost->host_lock);
2029
2030
2031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2032 "0102 PLOGI completes to NPort x%06x "
2033 "Data: x%x x%x x%x x%x x%x\n",
2034 ndlp->nlp_DID, ndlp->nlp_fc4_type,
2035 irsp->ulpStatus, irsp->un.ulpWord[4],
2036 disc, vport->num_disc_nodes);
2037
2038
2039 if (lpfc_els_chk_latt(vport)) {
2040 spin_lock_irq(shost->host_lock);
2041 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2042 spin_unlock_irq(shost->host_lock);
2043 goto out;
2044 }
2045
2046 if (irsp->ulpStatus) {
2047
2048 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2049
2050 if (disc) {
2051 spin_lock_irq(shost->host_lock);
2052 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2053 spin_unlock_irq(shost->host_lock);
2054 }
2055 goto out;
2056 }
2057
2058 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2059 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2060 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2061 (phba)->pport->cfg_log_verbose & LOG_ELS)
2062 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2063 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2064 ndlp->nlp_DID, irsp->ulpStatus,
2065 irsp->un.ulpWord[4]);
2066
2067 if (!lpfc_error_lost_link(irsp))
2068 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2069 NLP_EVT_CMPL_PLOGI);
2070 } else {
2071
2072 prsp = list_entry(((struct lpfc_dmabuf *)
2073 cmdiocb->context2)->list.next,
2074 struct lpfc_dmabuf, list);
2075 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2076 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2077 NLP_EVT_CMPL_PLOGI);
2078 }
2079
2080 if (disc && vport->num_disc_nodes) {
2081
2082 lpfc_more_plogi(vport);
2083
2084 if (vport->num_disc_nodes == 0) {
2085 spin_lock_irq(shost->host_lock);
2086 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2087 spin_unlock_irq(shost->host_lock);
2088
2089 lpfc_can_disctmo(vport);
2090 lpfc_end_rscn(vport);
2091 }
2092 }
2093
2094 out:
2095 lpfc_els_free_iocb(phba, cmdiocb);
2096 return;
2097 }
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120 int
2121 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2122 {
2123 struct lpfc_hba *phba = vport->phba;
2124 struct Scsi_Host *shost;
2125 struct serv_parm *sp;
2126 struct lpfc_nodelist *ndlp;
2127 struct lpfc_iocbq *elsiocb;
2128 uint8_t *pcmd;
2129 uint16_t cmdsize;
2130 int ret;
2131
2132 ndlp = lpfc_findnode_did(vport, did);
2133
2134 if (ndlp) {
2135
2136
2137
2138
2139 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2140 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2141 !(vport->fc_flag & FC_OFFLINE_MODE)) {
2142 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2143 "4110 Issue PLOGI x%x deferred "
2144 "on NPort x%x rpi x%x Data: x%px\n",
2145 ndlp->nlp_defer_did, ndlp->nlp_DID,
2146 ndlp->nlp_rpi, ndlp);
2147
2148
2149 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2150 ndlp->nlp_defer_did = did;
2151 return 0;
2152 }
2153 if (!NLP_CHK_NODE_ACT(ndlp))
2154 ndlp = NULL;
2155 }
2156
2157
2158 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2159 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2160 ELS_CMD_PLOGI);
2161 if (!elsiocb)
2162 return 1;
2163
2164 shost = lpfc_shost_from_vport(vport);
2165 spin_lock_irq(shost->host_lock);
2166 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2167 spin_unlock_irq(shost->host_lock);
2168
2169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2170
2171
2172 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2173 pcmd += sizeof(uint32_t);
2174 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2175 sp = (struct serv_parm *) pcmd;
2176
2177
2178
2179
2180
2181 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2182 sp->cmn.altBbCredit = 1;
2183
2184 if (sp->cmn.fcphLow < FC_PH_4_3)
2185 sp->cmn.fcphLow = FC_PH_4_3;
2186
2187 if (sp->cmn.fcphHigh < FC_PH3)
2188 sp->cmn.fcphHigh = FC_PH3;
2189
2190 sp->cmn.valid_vendor_ver_level = 0;
2191 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2192 sp->cmn.bbRcvSizeMsb &= 0xF;
2193
2194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2195 "Issue PLOGI: did:x%x",
2196 did, 0, 0);
2197
2198
2199
2200
2201 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2202 sp->cmn.valid_vendor_ver_level = 1;
2203 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2204 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2205 }
2206
2207 phba->fc_stat.elsXmitPLOGI++;
2208 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2209 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2210
2211 if (ret == IOCB_ERROR) {
2212 lpfc_els_free_iocb(phba, elsiocb);
2213 return 1;
2214 }
2215 return 0;
2216 }
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231 static void
2232 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2233 struct lpfc_iocbq *rspiocb)
2234 {
2235 struct lpfc_vport *vport = cmdiocb->vport;
2236 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2237 IOCB_t *irsp;
2238 struct lpfc_nodelist *ndlp;
2239 char *mode;
2240
2241
2242 cmdiocb->context_un.rsp_iocb = rspiocb;
2243
2244 irsp = &(rspiocb->iocb);
2245 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2246 spin_lock_irq(shost->host_lock);
2247 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2248
2249
2250 vport->fc_prli_sent--;
2251 ndlp->fc4_prli_sent--;
2252 spin_unlock_irq(shost->host_lock);
2253
2254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2255 "PRLI cmpl: status:x%x/x%x did:x%x",
2256 irsp->ulpStatus, irsp->un.ulpWord[4],
2257 ndlp->nlp_DID);
2258
2259
2260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2261 "0103 PRLI completes to NPort x%06x "
2262 "Data: x%x x%x x%x x%x\n",
2263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2264 vport->num_disc_nodes, ndlp->fc4_prli_sent);
2265
2266
2267 if (lpfc_els_chk_latt(vport))
2268 goto out;
2269
2270 if (irsp->ulpStatus) {
2271
2272 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2273
2274 goto out;
2275 }
2276
2277
2278
2279
2280 if ((vport->fc_flag & FC_FABRIC) ||
2281 (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH))
2282 mode = KERN_ERR;
2283 else
2284 mode = KERN_INFO;
2285
2286
2287 lpfc_printf_vlog(vport, mode, LOG_ELS,
2288 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2289 "data: x%x\n",
2290 ndlp->nlp_DID, irsp->ulpStatus,
2291 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2292
2293
2294 if (lpfc_error_lost_link(irsp))
2295 goto out;
2296 else
2297 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2298 NLP_EVT_CMPL_PRLI);
2299 } else {
2300
2301
2302
2303
2304
2305 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2306 NLP_EVT_CMPL_PRLI);
2307 }
2308
2309 out:
2310 lpfc_els_free_iocb(phba, cmdiocb);
2311 return;
2312 }
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335 int
2336 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2337 uint8_t retry)
2338 {
2339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2340 struct lpfc_hba *phba = vport->phba;
2341 PRLI *npr;
2342 struct lpfc_nvme_prli *npr_nvme;
2343 struct lpfc_iocbq *elsiocb;
2344 uint8_t *pcmd;
2345 uint16_t cmdsize;
2346 u32 local_nlp_type, elscmd;
2347
2348
2349
2350
2351
2352
2353
2354 if (phba->sli_rev == LPFC_SLI_REV4 &&
2355 vport->fc_flag & FC_RSCN_MODE &&
2356 vport->nvmei_support)
2357 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2358 local_nlp_type = ndlp->nlp_fc4_type;
2359
2360
2361
2362
2363 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2364 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2365 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2366 ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2367 ndlp->nvme_fb_size = 0;
2368
2369 send_next_prli:
2370 if (local_nlp_type & NLP_FC4_FCP) {
2371
2372 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2373 elscmd = ELS_CMD_PRLI;
2374 } else if (local_nlp_type & NLP_FC4_NVME) {
2375
2376 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2377 elscmd = ELS_CMD_NVMEPRLI;
2378 } else {
2379 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2380 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2381 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2382 return 1;
2383 }
2384
2385
2386
2387
2388 if (phba->sli_rev == LPFC_SLI_REV3 &&
2389 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2390 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2391 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2392 ndlp->nlp_type);
2393 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2394 return 1;
2395 }
2396
2397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2398 ndlp->nlp_DID, elscmd);
2399 if (!elsiocb)
2400 return 1;
2401
2402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2403
2404
2405 memset(pcmd, 0, cmdsize);
2406
2407 if (local_nlp_type & NLP_FC4_FCP) {
2408
2409
2410
2411
2412
2413 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2414 pcmd += sizeof(uint32_t);
2415 npr = (PRLI *)pcmd;
2416
2417
2418
2419
2420
2421 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2422 npr->ConfmComplAllowed = 1;
2423 npr->Retry = 1;
2424 npr->TaskRetryIdReq = 1;
2425 }
2426 npr->estabImagePair = 1;
2427 npr->readXferRdyDis = 1;
2428 if (vport->cfg_first_burst_size)
2429 npr->writeXferRdyDis = 1;
2430
2431
2432 npr->prliType = PRLI_FCP_TYPE;
2433 npr->initiatorFunc = 1;
2434 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2435
2436
2437 local_nlp_type &= ~NLP_FC4_FCP;
2438 } else if (local_nlp_type & NLP_FC4_NVME) {
2439
2440
2441
2442
2443 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2444 pcmd += sizeof(uint32_t);
2445 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2446 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2447 bf_set(prli_estabImagePair, npr_nvme, 0);
2448 if (phba->nsler) {
2449 bf_set(prli_nsler, npr_nvme, 1);
2450 bf_set(prli_conf, npr_nvme, 1);
2451 }
2452
2453
2454 if ((phba->cfg_nvme_enable_fb) &&
2455 !phba->nvmet_support)
2456 bf_set(prli_fba, npr_nvme, 1);
2457
2458 if (phba->nvmet_support) {
2459 bf_set(prli_tgt, npr_nvme, 1);
2460 bf_set(prli_disc, npr_nvme, 1);
2461 } else {
2462 bf_set(prli_init, npr_nvme, 1);
2463 bf_set(prli_conf, npr_nvme, 1);
2464 }
2465
2466 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2467 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2468 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2469
2470
2471 local_nlp_type &= ~NLP_FC4_NVME;
2472 }
2473
2474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2475 "Issue PRLI: did:x%x",
2476 ndlp->nlp_DID, 0, 0);
2477
2478 phba->fc_stat.elsXmitPRLI++;
2479 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2480 spin_lock_irq(shost->host_lock);
2481 ndlp->nlp_flag |= NLP_PRLI_SND;
2482
2483
2484
2485
2486
2487 vport->fc_prli_sent++;
2488 ndlp->fc4_prli_sent++;
2489 spin_unlock_irq(shost->host_lock);
2490 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2491 IOCB_ERROR) {
2492 spin_lock_irq(shost->host_lock);
2493 ndlp->nlp_flag &= ~NLP_PRLI_SND;
2494 spin_unlock_irq(shost->host_lock);
2495 lpfc_els_free_iocb(phba, elsiocb);
2496 return 1;
2497 }
2498
2499
2500
2501
2502
2503 if (phba->sli_rev == LPFC_SLI_REV4 &&
2504 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2505 goto send_next_prli;
2506
2507 return 0;
2508 }
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522 static void
2523 lpfc_rscn_disc(struct lpfc_vport *vport)
2524 {
2525 lpfc_can_disctmo(vport);
2526
2527
2528
2529 if (vport->fc_npr_cnt)
2530 if (lpfc_els_disc_plogi(vport))
2531 return;
2532
2533 lpfc_end_rscn(vport);
2534 }
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546 static void
2547 lpfc_adisc_done(struct lpfc_vport *vport)
2548 {
2549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2550 struct lpfc_hba *phba = vport->phba;
2551
2552
2553
2554
2555
2556 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2557 !(vport->fc_flag & FC_RSCN_MODE) &&
2558 (phba->sli_rev < LPFC_SLI_REV4)) {
2559
2560
2561
2562
2563
2564
2565
2566
2567 lpfc_issue_clear_la(phba, vport);
2568 lpfc_issue_reg_vpi(phba, vport);
2569 return;
2570 }
2571
2572
2573
2574
2575 if (vport->port_state < LPFC_VPORT_READY) {
2576
2577 lpfc_issue_clear_la(phba, vport);
2578 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2579 vport->num_disc_nodes = 0;
2580
2581 if (vport->fc_npr_cnt)
2582 lpfc_els_disc_plogi(vport);
2583 if (!vport->num_disc_nodes) {
2584 spin_lock_irq(shost->host_lock);
2585 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2586 spin_unlock_irq(shost->host_lock);
2587 lpfc_can_disctmo(vport);
2588 lpfc_end_rscn(vport);
2589 }
2590 }
2591 vport->port_state = LPFC_VPORT_READY;
2592 } else
2593 lpfc_rscn_disc(vport);
2594 }
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605 void
2606 lpfc_more_adisc(struct lpfc_vport *vport)
2607 {
2608 if (vport->num_disc_nodes)
2609 vport->num_disc_nodes--;
2610
2611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2612 "0210 Continue discovery with %d ADISCs to go "
2613 "Data: x%x x%x x%x\n",
2614 vport->num_disc_nodes, vport->fc_adisc_cnt,
2615 vport->fc_flag, vport->port_state);
2616
2617 if (vport->fc_flag & FC_NLP_MORE) {
2618 lpfc_set_disctmo(vport);
2619
2620 lpfc_els_disc_adisc(vport);
2621 }
2622 if (!vport->num_disc_nodes)
2623 lpfc_adisc_done(vport);
2624 return;
2625 }
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643 static void
2644 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2645 struct lpfc_iocbq *rspiocb)
2646 {
2647 struct lpfc_vport *vport = cmdiocb->vport;
2648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2649 IOCB_t *irsp;
2650 struct lpfc_nodelist *ndlp;
2651 int disc;
2652
2653
2654 cmdiocb->context_un.rsp_iocb = rspiocb;
2655
2656 irsp = &(rspiocb->iocb);
2657 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2658
2659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2660 "ADISC cmpl: status:x%x/x%x did:x%x",
2661 irsp->ulpStatus, irsp->un.ulpWord[4],
2662 ndlp->nlp_DID);
2663
2664
2665
2666
2667 spin_lock_irq(shost->host_lock);
2668 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2669 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2670 spin_unlock_irq(shost->host_lock);
2671
2672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2673 "0104 ADISC completes to NPort x%x "
2674 "Data: x%x x%x x%x x%x x%x\n",
2675 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2676 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2677
2678 if (lpfc_els_chk_latt(vport)) {
2679 spin_lock_irq(shost->host_lock);
2680 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2681 spin_unlock_irq(shost->host_lock);
2682 goto out;
2683 }
2684
2685 if (irsp->ulpStatus) {
2686
2687 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2688
2689 if (disc) {
2690 spin_lock_irq(shost->host_lock);
2691 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2692 spin_unlock_irq(shost->host_lock);
2693 lpfc_set_disctmo(vport);
2694 }
2695 goto out;
2696 }
2697
2698 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2699 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2700 ndlp->nlp_DID, irsp->ulpStatus,
2701 irsp->un.ulpWord[4]);
2702
2703 if (!lpfc_error_lost_link(irsp))
2704 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2705 NLP_EVT_CMPL_ADISC);
2706 } else
2707
2708 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2709 NLP_EVT_CMPL_ADISC);
2710
2711
2712 if (disc && vport->num_disc_nodes)
2713 lpfc_more_adisc(vport);
2714 out:
2715 lpfc_els_free_iocb(phba, cmdiocb);
2716 return;
2717 }
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739 int
2740 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2741 uint8_t retry)
2742 {
2743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2744 struct lpfc_hba *phba = vport->phba;
2745 ADISC *ap;
2746 struct lpfc_iocbq *elsiocb;
2747 uint8_t *pcmd;
2748 uint16_t cmdsize;
2749
2750 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2751 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2752 ndlp->nlp_DID, ELS_CMD_ADISC);
2753 if (!elsiocb)
2754 return 1;
2755
2756 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2757
2758
2759 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2760 pcmd += sizeof(uint32_t);
2761
2762
2763 ap = (ADISC *) pcmd;
2764 ap->hardAL_PA = phba->fc_pref_ALPA;
2765 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2766 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2767 ap->DID = be32_to_cpu(vport->fc_myDID);
2768
2769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2770 "Issue ADISC: did:x%x",
2771 ndlp->nlp_DID, 0, 0);
2772
2773 phba->fc_stat.elsXmitADISC++;
2774 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2775 spin_lock_irq(shost->host_lock);
2776 ndlp->nlp_flag |= NLP_ADISC_SND;
2777 spin_unlock_irq(shost->host_lock);
2778 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2779 IOCB_ERROR) {
2780 spin_lock_irq(shost->host_lock);
2781 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2782 spin_unlock_irq(shost->host_lock);
2783 lpfc_els_free_iocb(phba, elsiocb);
2784 return 1;
2785 }
2786 return 0;
2787 }
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801 static void
2802 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2803 struct lpfc_iocbq *rspiocb)
2804 {
2805 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2806 struct lpfc_vport *vport = ndlp->vport;
2807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2808 IOCB_t *irsp;
2809 struct lpfcMboxq *mbox;
2810 unsigned long flags;
2811 uint32_t skip_recovery = 0;
2812
2813
2814 cmdiocb->context_un.rsp_iocb = rspiocb;
2815
2816 irsp = &(rspiocb->iocb);
2817 spin_lock_irq(shost->host_lock);
2818 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2819 spin_unlock_irq(shost->host_lock);
2820
2821 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2822 "LOGO cmpl: status:x%x/x%x did:x%x",
2823 irsp->ulpStatus, irsp->un.ulpWord[4],
2824 ndlp->nlp_DID);
2825
2826
2827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2828 "0105 LOGO completes to NPort x%x "
2829 "Data: x%x x%x x%x x%x\n",
2830 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2831 irsp->ulpTimeout, vport->num_disc_nodes);
2832
2833 if (lpfc_els_chk_latt(vport)) {
2834 skip_recovery = 1;
2835 goto out;
2836 }
2837
2838
2839 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2840
2841
2842
2843 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2844 NLP_EVT_DEVICE_RM);
2845 skip_recovery = 1;
2846 goto out;
2847 }
2848
2849
2850
2851
2852
2853
2854 if (irsp->ulpStatus) {
2855
2856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2857 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2858 ndlp->nlp_DID, irsp->ulpStatus,
2859 irsp->un.ulpWord[4]);
2860
2861 if (lpfc_error_lost_link(irsp)) {
2862 skip_recovery = 1;
2863 goto out;
2864 }
2865 }
2866
2867
2868 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2869
2870 out:
2871 lpfc_els_free_iocb(phba, cmdiocb);
2872
2873 if ((vport->fc_flag & FC_PT2PT) &&
2874 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2875 phba->pport->fc_myDID = 0;
2876
2877 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2878 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2879 if (phba->nvmet_support)
2880 lpfc_nvmet_update_targetport(phba);
2881 else
2882 lpfc_nvme_update_localport(phba->pport);
2883 }
2884
2885 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2886 if (mbox) {
2887 lpfc_config_link(phba, mbox);
2888 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2889 mbox->vport = vport;
2890 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2891 MBX_NOT_FINISHED) {
2892 mempool_free(mbox, phba->mbox_mem_pool);
2893 skip_recovery = 1;
2894 }
2895 }
2896 }
2897
2898
2899
2900
2901
2902
2903 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2904 skip_recovery == 0) {
2905 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2906 spin_lock_irqsave(shost->host_lock, flags);
2907 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2908 spin_unlock_irqrestore(shost->host_lock, flags);
2909
2910 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2911 "3187 LOGO completes to NPort x%x: Start "
2912 "Recovery Data: x%x x%x x%x x%x\n",
2913 ndlp->nlp_DID, irsp->ulpStatus,
2914 irsp->un.ulpWord[4], irsp->ulpTimeout,
2915 vport->num_disc_nodes);
2916 lpfc_disc_start(vport);
2917 }
2918 return;
2919 }
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943 int
2944 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2945 uint8_t retry)
2946 {
2947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2948 struct lpfc_hba *phba = vport->phba;
2949 struct lpfc_iocbq *elsiocb;
2950 uint8_t *pcmd;
2951 uint16_t cmdsize;
2952 int rc;
2953
2954 spin_lock_irq(shost->host_lock);
2955 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2956 spin_unlock_irq(shost->host_lock);
2957 return 0;
2958 }
2959 spin_unlock_irq(shost->host_lock);
2960
2961 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2962 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2963 ndlp->nlp_DID, ELS_CMD_LOGO);
2964 if (!elsiocb)
2965 return 1;
2966
2967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2968 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2969 pcmd += sizeof(uint32_t);
2970
2971
2972 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2973 pcmd += sizeof(uint32_t);
2974 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2975
2976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2977 "Issue LOGO: did:x%x",
2978 ndlp->nlp_DID, 0, 0);
2979
2980 phba->fc_stat.elsXmitLOGO++;
2981 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2982 spin_lock_irq(shost->host_lock);
2983 ndlp->nlp_flag |= NLP_LOGO_SND;
2984 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
2985 spin_unlock_irq(shost->host_lock);
2986 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2987 if (rc == IOCB_ERROR) {
2988 spin_lock_irq(shost->host_lock);
2989 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2990 spin_unlock_irq(shost->host_lock);
2991 lpfc_els_free_iocb(phba, elsiocb);
2992 return 1;
2993 }
2994
2995 spin_lock_irq(shost->host_lock);
2996 ndlp->nlp_prev_state = ndlp->nlp_state;
2997 spin_unlock_irq(shost->host_lock);
2998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
2999 return 0;
3000 }
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018 static void
3019 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3020 struct lpfc_iocbq *rspiocb)
3021 {
3022 struct lpfc_vport *vport = cmdiocb->vport;
3023 IOCB_t *irsp;
3024
3025 irsp = &rspiocb->iocb;
3026
3027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3028 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3029 irsp->ulpStatus, irsp->un.ulpWord[4],
3030 irsp->un.elsreq64.remoteID);
3031
3032 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3033 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3034 irsp->ulpIoTag, irsp->ulpStatus,
3035 irsp->un.ulpWord[4], irsp->ulpTimeout);
3036
3037 lpfc_els_chk_latt(vport);
3038 lpfc_els_free_iocb(phba, cmdiocb);
3039 return;
3040 }
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064 int
3065 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3066 {
3067 struct lpfc_hba *phba = vport->phba;
3068 struct lpfc_iocbq *elsiocb;
3069 uint8_t *pcmd;
3070 uint16_t cmdsize;
3071 struct lpfc_nodelist *ndlp;
3072
3073 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3074
3075 ndlp = lpfc_findnode_did(vport, nportid);
3076 if (!ndlp) {
3077 ndlp = lpfc_nlp_init(vport, nportid);
3078 if (!ndlp)
3079 return 1;
3080 lpfc_enqueue_node(vport, ndlp);
3081 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3082 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3083 if (!ndlp)
3084 return 1;
3085 }
3086
3087 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3088 ndlp->nlp_DID, ELS_CMD_SCR);
3089
3090 if (!elsiocb) {
3091
3092
3093
3094 lpfc_nlp_put(ndlp);
3095 return 1;
3096 }
3097
3098 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3099
3100 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3101 pcmd += sizeof(uint32_t);
3102
3103
3104 memset(pcmd, 0, sizeof(SCR));
3105 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3106
3107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3108 "Issue SCR: did:x%x",
3109 ndlp->nlp_DID, 0, 0);
3110
3111 phba->fc_stat.elsXmitSCR++;
3112 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3113 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3114 IOCB_ERROR) {
3115
3116
3117
3118
3119 lpfc_nlp_put(ndlp);
3120 lpfc_els_free_iocb(phba, elsiocb);
3121 return 1;
3122 }
3123
3124
3125
3126 if (!(vport->fc_flag & FC_PT2PT))
3127 lpfc_nlp_put(ndlp);
3128 return 0;
3129 }
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151 int
3152 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3153 {
3154 struct lpfc_hba *phba = vport->phba;
3155 struct lpfc_iocbq *elsiocb;
3156 struct lpfc_nodelist *ndlp;
3157 struct {
3158 struct fc_els_rscn rscn;
3159 struct fc_els_rscn_page portid;
3160 } *event;
3161 uint32_t nportid;
3162 uint16_t cmdsize = sizeof(*event);
3163
3164
3165 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3166 !(vport->fc_flag & FC_PUBLIC_LOOP))
3167 return 1;
3168
3169 if (vport->fc_flag & FC_PT2PT) {
3170
3171 ndlp = lpfc_findnode_mapped(vport);
3172 if (!ndlp)
3173 return 1;
3174 } else {
3175 nportid = FC_FID_FCTRL;
3176
3177 ndlp = lpfc_findnode_did(vport, nportid);
3178 if (!ndlp) {
3179
3180 ndlp = lpfc_nlp_init(vport, nportid);
3181 if (!ndlp)
3182 return 1;
3183 lpfc_enqueue_node(vport, ndlp);
3184 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3185 ndlp = lpfc_enable_node(vport, ndlp,
3186 NLP_STE_UNUSED_NODE);
3187 if (!ndlp)
3188 return 1;
3189 }
3190 }
3191
3192 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3193 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3194
3195 if (!elsiocb) {
3196
3197
3198
3199 lpfc_nlp_put(ndlp);
3200 return 1;
3201 }
3202
3203 event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3204
3205 event->rscn.rscn_cmd = ELS_RSCN;
3206 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3207 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3208
3209 nportid = vport->fc_myDID;
3210
3211 event->portid.rscn_page_flags = 0;
3212 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3213 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3214 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3215
3216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3217 "Issue RSCN: did:x%x",
3218 ndlp->nlp_DID, 0, 0);
3219
3220 phba->fc_stat.elsXmitRSCN++;
3221 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3222 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3223 IOCB_ERROR) {
3224
3225
3226
3227
3228 lpfc_nlp_put(ndlp);
3229 lpfc_els_free_iocb(phba, elsiocb);
3230 return 1;
3231 }
3232
3233
3234
3235 if (!(vport->fc_flag & FC_PT2PT))
3236 lpfc_nlp_put(ndlp);
3237
3238 return 0;
3239 }
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263 static int
3264 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3265 {
3266 struct lpfc_hba *phba = vport->phba;
3267 struct lpfc_iocbq *elsiocb;
3268 FARP *fp;
3269 uint8_t *pcmd;
3270 uint32_t *lp;
3271 uint16_t cmdsize;
3272 struct lpfc_nodelist *ondlp;
3273 struct lpfc_nodelist *ndlp;
3274
3275 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3276
3277 ndlp = lpfc_findnode_did(vport, nportid);
3278 if (!ndlp) {
3279 ndlp = lpfc_nlp_init(vport, nportid);
3280 if (!ndlp)
3281 return 1;
3282 lpfc_enqueue_node(vport, ndlp);
3283 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3284 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3285 if (!ndlp)
3286 return 1;
3287 }
3288
3289 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3290 ndlp->nlp_DID, ELS_CMD_RNID);
3291 if (!elsiocb) {
3292
3293
3294
3295 lpfc_nlp_put(ndlp);
3296 return 1;
3297 }
3298
3299 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3300
3301 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3302 pcmd += sizeof(uint32_t);
3303
3304
3305 fp = (FARP *) (pcmd);
3306 memset(fp, 0, sizeof(FARP));
3307 lp = (uint32_t *) pcmd;
3308 *lp++ = be32_to_cpu(nportid);
3309 *lp++ = be32_to_cpu(vport->fc_myDID);
3310 fp->Rflags = 0;
3311 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3312
3313 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3314 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3315 ondlp = lpfc_findnode_did(vport, nportid);
3316 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3317 memcpy(&fp->OportName, &ondlp->nlp_portname,
3318 sizeof(struct lpfc_name));
3319 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3320 sizeof(struct lpfc_name));
3321 }
3322
3323 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3324 "Issue FARPR: did:x%x",
3325 ndlp->nlp_DID, 0, 0);
3326
3327 phba->fc_stat.elsXmitFARPR++;
3328 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3329 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3330 IOCB_ERROR) {
3331
3332
3333
3334
3335 lpfc_nlp_put(ndlp);
3336 lpfc_els_free_iocb(phba, elsiocb);
3337 return 1;
3338 }
3339
3340
3341
3342 lpfc_nlp_put(ndlp);
3343 return 0;
3344 }
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358 void
3359 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3360 {
3361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3362 struct lpfc_work_evt *evtp;
3363
3364 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3365 return;
3366 spin_lock_irq(shost->host_lock);
3367 nlp->nlp_flag &= ~NLP_DELAY_TMO;
3368 spin_unlock_irq(shost->host_lock);
3369 del_timer_sync(&nlp->nlp_delayfunc);
3370 nlp->nlp_last_elscmd = 0;
3371 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3372 list_del_init(&nlp->els_retry_evt.evt_listp);
3373
3374 evtp = &nlp->els_retry_evt;
3375 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3376 }
3377 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3378 spin_lock_irq(shost->host_lock);
3379 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3380 spin_unlock_irq(shost->host_lock);
3381 if (vport->num_disc_nodes) {
3382 if (vport->port_state < LPFC_VPORT_READY) {
3383
3384 lpfc_more_adisc(vport);
3385 } else {
3386
3387 lpfc_more_plogi(vport);
3388 if (vport->num_disc_nodes == 0) {
3389 spin_lock_irq(shost->host_lock);
3390 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3391 spin_unlock_irq(shost->host_lock);
3392 lpfc_can_disctmo(vport);
3393 lpfc_end_rscn(vport);
3394 }
3395 }
3396 }
3397 }
3398 return;
3399 }
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415 void
3416 lpfc_els_retry_delay(struct timer_list *t)
3417 {
3418 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3419 struct lpfc_vport *vport = ndlp->vport;
3420 struct lpfc_hba *phba = vport->phba;
3421 unsigned long flags;
3422 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3423
3424 spin_lock_irqsave(&phba->hbalock, flags);
3425 if (!list_empty(&evtp->evt_listp)) {
3426 spin_unlock_irqrestore(&phba->hbalock, flags);
3427 return;
3428 }
3429
3430
3431
3432
3433 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3434 if (evtp->evt_arg1) {
3435 evtp->evt = LPFC_EVT_ELS_RETRY;
3436 list_add_tail(&evtp->evt_listp, &phba->work_list);
3437 lpfc_worker_wake_up(phba);
3438 }
3439 spin_unlock_irqrestore(&phba->hbalock, flags);
3440 return;
3441 }
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452 void
3453 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3454 {
3455 struct lpfc_vport *vport = ndlp->vport;
3456 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3457 uint32_t cmd, retry;
3458
3459 spin_lock_irq(shost->host_lock);
3460 cmd = ndlp->nlp_last_elscmd;
3461 ndlp->nlp_last_elscmd = 0;
3462
3463 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3464 spin_unlock_irq(shost->host_lock);
3465 return;
3466 }
3467
3468 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3469 spin_unlock_irq(shost->host_lock);
3470
3471
3472
3473
3474
3475 del_timer_sync(&ndlp->nlp_delayfunc);
3476 retry = ndlp->nlp_retry;
3477 ndlp->nlp_retry = 0;
3478
3479 switch (cmd) {
3480 case ELS_CMD_FLOGI:
3481 lpfc_issue_els_flogi(vport, ndlp, retry);
3482 break;
3483 case ELS_CMD_PLOGI:
3484 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3485 ndlp->nlp_prev_state = ndlp->nlp_state;
3486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3487 }
3488 break;
3489 case ELS_CMD_ADISC:
3490 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3491 ndlp->nlp_prev_state = ndlp->nlp_state;
3492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3493 }
3494 break;
3495 case ELS_CMD_PRLI:
3496 case ELS_CMD_NVMEPRLI:
3497 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3498 ndlp->nlp_prev_state = ndlp->nlp_state;
3499 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3500 }
3501 break;
3502 case ELS_CMD_LOGO:
3503 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3504 ndlp->nlp_prev_state = ndlp->nlp_state;
3505 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3506 }
3507 break;
3508 case ELS_CMD_FDISC:
3509 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3510 lpfc_issue_els_fdisc(vport, ndlp, retry);
3511 break;
3512 }
3513 return;
3514 }
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528 int
3529 lpfc_link_reset(struct lpfc_vport *vport)
3530 {
3531 struct lpfc_hba *phba = vport->phba;
3532 LPFC_MBOXQ_t *mbox;
3533 uint32_t control;
3534 int rc;
3535
3536 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3537 "2851 Attempt link reset\n");
3538 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3539 if (!mbox) {
3540 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3541 "2852 Failed to allocate mbox memory");
3542 return 1;
3543 }
3544
3545
3546 if (phba->sli_rev <= LPFC_SLI_REV3) {
3547 spin_lock_irq(&phba->hbalock);
3548 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3549 control = readl(phba->HCregaddr);
3550 control |= HC_LAINT_ENA;
3551 writel(control, phba->HCregaddr);
3552 readl(phba->HCregaddr);
3553 spin_unlock_irq(&phba->hbalock);
3554 }
3555
3556 lpfc_init_link(phba, mbox, phba->cfg_topology,
3557 phba->cfg_link_speed);
3558 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3559 mbox->vport = vport;
3560 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3561 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3562 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3563 "2853 Failed to issue INIT_LINK "
3564 "mbox command, rc:x%x\n", rc);
3565 mempool_free(mbox, phba->mbox_mem_pool);
3566 return 1;
3567 }
3568
3569 return 0;
3570 }
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593 static int
3594 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3595 struct lpfc_iocbq *rspiocb)
3596 {
3597 struct lpfc_vport *vport = cmdiocb->vport;
3598 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3599 IOCB_t *irsp = &rspiocb->iocb;
3600 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3601 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3602 uint32_t *elscmd;
3603 struct ls_rjt stat;
3604 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3605 int logerr = 0;
3606 uint32_t cmd = 0;
3607 uint32_t did;
3608 int link_reset = 0, rc;
3609
3610
3611
3612
3613
3614
3615 if (pcmd && pcmd->virt) {
3616 elscmd = (uint32_t *) (pcmd->virt);
3617 cmd = *elscmd++;
3618 }
3619
3620 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3621 did = ndlp->nlp_DID;
3622 else {
3623
3624 did = irsp->un.elsreq64.remoteID;
3625 ndlp = lpfc_findnode_did(vport, did);
3626 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3627 && (cmd != ELS_CMD_PLOGI))
3628 return 1;
3629 }
3630
3631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3632 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3633 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3634
3635 switch (irsp->ulpStatus) {
3636 case IOSTAT_FCP_RSP_ERROR:
3637 break;
3638 case IOSTAT_REMOTE_STOP:
3639 if (phba->sli_rev == LPFC_SLI_REV4) {
3640
3641
3642
3643
3644 lpfc_set_rrq_active(phba, ndlp,
3645 cmdiocb->sli4_lxritag, 0, 0);
3646 }
3647 break;
3648 case IOSTAT_LOCAL_REJECT:
3649 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3650 case IOERR_LOOP_OPEN_FAILURE:
3651 if (cmd == ELS_CMD_FLOGI) {
3652 if (PCI_DEVICE_ID_HORNET ==
3653 phba->pcidev->device) {
3654 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3655 phba->pport->fc_myDID = 0;
3656 phba->alpa_map[0] = 0;
3657 phba->alpa_map[1] = 0;
3658 }
3659 }
3660 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3661 delay = 1000;
3662 retry = 1;
3663 break;
3664
3665 case IOERR_ILLEGAL_COMMAND:
3666 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3667 "0124 Retry illegal cmd x%x "
3668 "retry:x%x delay:x%x\n",
3669 cmd, cmdiocb->retry, delay);
3670 retry = 1;
3671
3672 maxretry = 8;
3673 if (cmdiocb->retry > 2)
3674 delay = 1000;
3675 break;
3676
3677 case IOERR_NO_RESOURCES:
3678 logerr = 1;
3679 retry = 1;
3680 if (cmdiocb->retry > 100)
3681 delay = 100;
3682 maxretry = 250;
3683 break;
3684
3685 case IOERR_ILLEGAL_FRAME:
3686 delay = 100;
3687 retry = 1;
3688 break;
3689
3690 case IOERR_INVALID_RPI:
3691 if (cmd == ELS_CMD_PLOGI &&
3692 did == NameServer_DID) {
3693
3694
3695 maxretry = 0;
3696 delay = 100;
3697 }
3698 retry = 1;
3699 break;
3700
3701 case IOERR_SEQUENCE_TIMEOUT:
3702 if (cmd == ELS_CMD_PLOGI &&
3703 did == NameServer_DID &&
3704 (cmdiocb->retry + 1) == maxretry) {
3705
3706 link_reset = 1;
3707 break;
3708 }
3709 retry = 1;
3710 delay = 100;
3711 break;
3712 }
3713 break;
3714
3715 case IOSTAT_NPORT_RJT:
3716 case IOSTAT_FABRIC_RJT:
3717 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3718 retry = 1;
3719 break;
3720 }
3721 break;
3722
3723 case IOSTAT_NPORT_BSY:
3724 case IOSTAT_FABRIC_BSY:
3725 logerr = 1;
3726 retry = 1;
3727 break;
3728
3729 case IOSTAT_LS_RJT:
3730 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3731
3732
3733
3734 switch (stat.un.b.lsRjtRsnCode) {
3735 case LSRJT_UNABLE_TPC:
3736
3737
3738
3739
3740
3741 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3742 delay = 1000;
3743 maxretry = lpfc_max_els_tries + 1;
3744 retry = 1;
3745 break;
3746 }
3747
3748
3749 if (stat.un.b.lsRjtRsnCodeExp ==
3750 LSEXP_CMD_IN_PROGRESS) {
3751 if (cmd == ELS_CMD_PLOGI) {
3752 delay = 1000;
3753 maxretry = 48;
3754 }
3755 retry = 1;
3756 break;
3757 }
3758 if (stat.un.b.lsRjtRsnCodeExp ==
3759 LSEXP_CANT_GIVE_DATA) {
3760 if (cmd == ELS_CMD_PLOGI) {
3761 delay = 1000;
3762 maxretry = 48;
3763 }
3764 retry = 1;
3765 break;
3766 }
3767 if (cmd == ELS_CMD_PLOGI) {
3768 delay = 1000;
3769 maxretry = lpfc_max_els_tries + 1;
3770 retry = 1;
3771 break;
3772 }
3773 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3774 (cmd == ELS_CMD_FDISC) &&
3775 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
3776 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3777 "0125 FDISC Failed (x%x). "
3778 "Fabric out of resources\n",
3779 stat.un.lsRjtError);
3780 lpfc_vport_set_state(vport,
3781 FC_VPORT_NO_FABRIC_RSCS);
3782 }
3783 break;
3784
3785 case LSRJT_LOGICAL_BSY:
3786 if ((cmd == ELS_CMD_PLOGI) ||
3787 (cmd == ELS_CMD_PRLI) ||
3788 (cmd == ELS_CMD_NVMEPRLI)) {
3789 delay = 1000;
3790 maxretry = 48;
3791 } else if (cmd == ELS_CMD_FDISC) {
3792
3793 maxretry = 48;
3794 if (cmdiocb->retry >= 32)
3795 delay = 1000;
3796 }
3797 retry = 1;
3798 break;
3799
3800 case LSRJT_LOGICAL_ERR:
3801
3802
3803
3804
3805 if (cmd == ELS_CMD_FDISC &&
3806 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3807 maxretry = 3;
3808 delay = 1000;
3809 retry = 1;
3810 } else if (cmd == ELS_CMD_FLOGI &&
3811 stat.un.b.lsRjtRsnCodeExp ==
3812 LSEXP_NOTHING_MORE) {
3813 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3814 retry = 1;
3815 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3816 "0820 FLOGI Failed (x%x). "
3817 "BBCredit Not Supported\n",
3818 stat.un.lsRjtError);
3819 }
3820 break;
3821
3822 case LSRJT_PROTOCOL_ERR:
3823 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3824 (cmd == ELS_CMD_FDISC) &&
3825 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3826 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3827 ) {
3828 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3829 "0122 FDISC Failed (x%x). "
3830 "Fabric Detected Bad WWN\n",
3831 stat.un.lsRjtError);
3832 lpfc_vport_set_state(vport,
3833 FC_VPORT_FABRIC_REJ_WWN);
3834 }
3835 break;
3836 case LSRJT_VENDOR_UNIQUE:
3837 if ((stat.un.b.vendorUnique == 0x45) &&
3838 (cmd == ELS_CMD_FLOGI)) {
3839 goto out_retry;
3840 }
3841 break;
3842 case LSRJT_CMD_UNSUPPORTED:
3843
3844
3845
3846
3847
3848 if (stat.un.b.lsRjtRsnCodeExp ==
3849 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3850 spin_lock_irq(shost->host_lock);
3851 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3852 spin_unlock_irq(shost->host_lock);
3853 retry = 0;
3854 goto out_retry;
3855 }
3856 break;
3857 }
3858 break;
3859
3860 case IOSTAT_INTERMED_RSP:
3861 case IOSTAT_BA_RJT:
3862 break;
3863
3864 default:
3865 break;
3866 }
3867
3868 if (link_reset) {
3869 rc = lpfc_link_reset(vport);
3870 if (rc) {
3871
3872
3873
3874 retry = 1;
3875 delay = 100;
3876 goto out_retry;
3877 }
3878 return 1;
3879 }
3880
3881 if (did == FDMI_DID)
3882 retry = 1;
3883
3884 if ((cmd == ELS_CMD_FLOGI) &&
3885 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
3886 !lpfc_error_lost_link(irsp)) {
3887
3888 retry = 1;
3889
3890 if (phba->link_flag != LS_LOOPBACK_MODE)
3891 maxretry = 0;
3892 else
3893 maxretry = 2;
3894
3895 if (cmdiocb->retry >= 100)
3896 delay = 5000;
3897 else if (cmdiocb->retry >= 32)
3898 delay = 1000;
3899 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3900
3901 retry = 1;
3902 maxretry = vport->cfg_devloss_tmo;
3903 delay = 1000;
3904 }
3905
3906 cmdiocb->retry++;
3907 if (maxretry && (cmdiocb->retry >= maxretry)) {
3908 phba->fc_stat.elsRetryExceeded++;
3909 retry = 0;
3910 }
3911
3912 if ((vport->load_flag & FC_UNLOADING) != 0)
3913 retry = 0;
3914
3915 out_retry:
3916 if (retry) {
3917 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3918
3919 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3921 "2849 Stop retry ELS command "
3922 "x%x to remote NPORT x%x, "
3923 "Data: x%x x%x\n", cmd, did,
3924 cmdiocb->retry, delay);
3925 return 0;
3926 }
3927 }
3928
3929
3930 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3931 "0107 Retry ELS command x%x to remote "
3932 "NPORT x%x Data: x%x x%x\n",
3933 cmd, did, cmdiocb->retry, delay);
3934
3935 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3936 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3937 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3938 IOERR_NO_RESOURCES))) {
3939
3940
3941
3942 if (timer_pending(&vport->fc_disctmo) ||
3943 (vport->fc_flag & FC_RSCN_MODE))
3944 lpfc_set_disctmo(vport);
3945 }
3946
3947 phba->fc_stat.elsXmitRetry++;
3948 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3949 phba->fc_stat.elsDelayRetry++;
3950 ndlp->nlp_retry = cmdiocb->retry;
3951
3952
3953 mod_timer(&ndlp->nlp_delayfunc,
3954 jiffies + msecs_to_jiffies(delay));
3955 spin_lock_irq(shost->host_lock);
3956 ndlp->nlp_flag |= NLP_DELAY_TMO;
3957 spin_unlock_irq(shost->host_lock);
3958
3959 ndlp->nlp_prev_state = ndlp->nlp_state;
3960 if ((cmd == ELS_CMD_PRLI) ||
3961 (cmd == ELS_CMD_NVMEPRLI))
3962 lpfc_nlp_set_state(vport, ndlp,
3963 NLP_STE_PRLI_ISSUE);
3964 else
3965 lpfc_nlp_set_state(vport, ndlp,
3966 NLP_STE_NPR_NODE);
3967 ndlp->nlp_last_elscmd = cmd;
3968
3969 return 1;
3970 }
3971 switch (cmd) {
3972 case ELS_CMD_FLOGI:
3973 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3974 return 1;
3975 case ELS_CMD_FDISC:
3976 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3977 return 1;
3978 case ELS_CMD_PLOGI:
3979 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3980 ndlp->nlp_prev_state = ndlp->nlp_state;
3981 lpfc_nlp_set_state(vport, ndlp,
3982 NLP_STE_PLOGI_ISSUE);
3983 }
3984 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3985 return 1;
3986 case ELS_CMD_ADISC:
3987 ndlp->nlp_prev_state = ndlp->nlp_state;
3988 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3989 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3990 return 1;
3991 case ELS_CMD_PRLI:
3992 case ELS_CMD_NVMEPRLI:
3993 ndlp->nlp_prev_state = ndlp->nlp_state;
3994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3995 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3996 return 1;
3997 case ELS_CMD_LOGO:
3998 ndlp->nlp_prev_state = ndlp->nlp_state;
3999 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4000 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4001 return 1;
4002 }
4003 }
4004
4005 if (logerr) {
4006 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4007 "0137 No retry ELS command x%x to remote "
4008 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4009 cmd, did, irsp->ulpStatus,
4010 irsp->un.ulpWord[4]);
4011 }
4012 else {
4013 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4014 "0108 No retry ELS command x%x to remote "
4015 "NPORT x%x Retried:%d Error:x%x/%x\n",
4016 cmd, did, cmdiocb->retry, irsp->ulpStatus,
4017 irsp->un.ulpWord[4]);
4018 }
4019 return 0;
4020 }
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036 static int
4037 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4038 {
4039 struct lpfc_dmabuf *buf_ptr;
4040
4041
4042 if (!list_empty(&buf_ptr1->list)) {
4043 list_remove_head(&buf_ptr1->list, buf_ptr,
4044 struct lpfc_dmabuf,
4045 list);
4046 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4047 kfree(buf_ptr);
4048 }
4049 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4050 kfree(buf_ptr1);
4051 return 0;
4052 }
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066 static int
4067 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4068 {
4069 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4070 kfree(buf_ptr);
4071 return 0;
4072 }
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101 int
4102 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4103 {
4104 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4105 struct lpfc_nodelist *ndlp;
4106
4107 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4108 if (ndlp) {
4109 if (ndlp->nlp_flag & NLP_DEFER_RM) {
4110 lpfc_nlp_put(ndlp);
4111
4112
4113
4114
4115 if (!lpfc_nlp_not_used(ndlp)) {
4116
4117
4118
4119 ndlp->nlp_flag &= ~NLP_DEFER_RM;
4120 }
4121 }
4122 else
4123 lpfc_nlp_put(ndlp);
4124 elsiocb->context1 = NULL;
4125 }
4126
4127 if (elsiocb->context2) {
4128 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4129
4130
4131
4132
4133 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4134 buf_ptr = elsiocb->context2;
4135 elsiocb->context2 = NULL;
4136 if (buf_ptr) {
4137 buf_ptr1 = NULL;
4138 spin_lock_irq(&phba->hbalock);
4139 if (!list_empty(&buf_ptr->list)) {
4140 list_remove_head(&buf_ptr->list,
4141 buf_ptr1, struct lpfc_dmabuf,
4142 list);
4143 INIT_LIST_HEAD(&buf_ptr1->list);
4144 list_add_tail(&buf_ptr1->list,
4145 &phba->elsbuf);
4146 phba->elsbuf_cnt++;
4147 }
4148 INIT_LIST_HEAD(&buf_ptr->list);
4149 list_add_tail(&buf_ptr->list, &phba->elsbuf);
4150 phba->elsbuf_cnt++;
4151 spin_unlock_irq(&phba->hbalock);
4152 }
4153 } else {
4154 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4155 lpfc_els_free_data(phba, buf_ptr1);
4156 elsiocb->context2 = NULL;
4157 }
4158 }
4159
4160 if (elsiocb->context3) {
4161 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4162 lpfc_els_free_bpl(phba, buf_ptr);
4163 elsiocb->context3 = NULL;
4164 }
4165 lpfc_sli_release_iocbq(phba, elsiocb);
4166 return 0;
4167 }
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186 static void
4187 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4188 struct lpfc_iocbq *rspiocb)
4189 {
4190 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4191 struct lpfc_vport *vport = cmdiocb->vport;
4192 IOCB_t *irsp;
4193
4194 irsp = &rspiocb->iocb;
4195 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4196 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4197 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4198
4199 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4200 "0109 ACC to LOGO completes to NPort x%x "
4201 "Data: x%x x%x x%x\n",
4202 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4203 ndlp->nlp_rpi);
4204
4205 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4206
4207 if (!lpfc_nlp_not_used(ndlp)) {
4208
4209
4210
4211 lpfc_unreg_rpi(vport, ndlp);
4212 } else {
4213
4214
4215
4216 cmdiocb->context1 = NULL;
4217 }
4218 }
4219
4220
4221
4222
4223
4224 lpfc_els_free_iocb(phba, cmdiocb);
4225 }
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240 void
4241 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4242 {
4243 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4244 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4245
4246 pmb->ctx_buf = NULL;
4247 pmb->ctx_ndlp = NULL;
4248
4249 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4250 kfree(mp);
4251 mempool_free(pmb, phba->mbox_mem_pool);
4252 if (ndlp) {
4253 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4254 "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
4255 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4256 kref_read(&ndlp->kref),
4257 ndlp->nlp_usg_map, ndlp);
4258 if (NLP_CHK_NODE_ACT(ndlp)) {
4259 lpfc_nlp_put(ndlp);
4260
4261
4262
4263
4264 lpfc_nlp_not_used(ndlp);
4265 } else {
4266 lpfc_drop_node(ndlp->vport, ndlp);
4267 }
4268 }
4269
4270 return;
4271 }
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289 static void
4290 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4291 struct lpfc_iocbq *rspiocb)
4292 {
4293 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4294 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4295 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4296 IOCB_t *irsp;
4297 uint8_t *pcmd;
4298 LPFC_MBOXQ_t *mbox = NULL;
4299 struct lpfc_dmabuf *mp = NULL;
4300 uint32_t ls_rjt = 0;
4301
4302 irsp = &rspiocb->iocb;
4303
4304 if (cmdiocb->context_un.mbox)
4305 mbox = cmdiocb->context_un.mbox;
4306
4307
4308
4309
4310 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4311 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4312 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4313
4314
4315
4316 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4317 ls_rjt = 1;
4318 }
4319
4320
4321 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4322 if (mbox) {
4323 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4324 if (mp) {
4325 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4326 kfree(mp);
4327 }
4328 mempool_free(mbox, phba->mbox_mem_pool);
4329 }
4330 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4331 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4332 if (lpfc_nlp_not_used(ndlp)) {
4333 ndlp = NULL;
4334
4335
4336
4337
4338 cmdiocb->context1 = NULL;
4339 }
4340 goto out;
4341 }
4342
4343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4344 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4345 irsp->ulpStatus, irsp->un.ulpWord[4],
4346 cmdiocb->iocb.un.elsreq64.remoteID);
4347
4348 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4349 "0110 ELS response tag x%x completes "
4350 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4351 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4352 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4353 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4354 ndlp->nlp_rpi);
4355 if (mbox) {
4356 if ((rspiocb->iocb.ulpStatus == 0)
4357 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4358 if (!lpfc_unreg_rpi(vport, ndlp) &&
4359 (!(vport->fc_flag & FC_PT2PT)) &&
4360 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4361 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4362 lpfc_printf_vlog(vport, KERN_INFO,
4363 LOG_DISCOVERY,
4364 "0314 PLOGI recov DID x%x "
4365 "Data: x%x x%x x%x\n",
4366 ndlp->nlp_DID, ndlp->nlp_state,
4367 ndlp->nlp_rpi, ndlp->nlp_flag);
4368 mp = mbox->ctx_buf;
4369 if (mp) {
4370 lpfc_mbuf_free(phba, mp->virt,
4371 mp->phys);
4372 kfree(mp);
4373 }
4374 mempool_free(mbox, phba->mbox_mem_pool);
4375 goto out;
4376 }
4377
4378
4379
4380
4381 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4382 mbox->vport = vport;
4383 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4384 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4385 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4386 }
4387 else {
4388 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4389 ndlp->nlp_prev_state = ndlp->nlp_state;
4390 lpfc_nlp_set_state(vport, ndlp,
4391 NLP_STE_REG_LOGIN_ISSUE);
4392 }
4393
4394 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4395 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4396 != MBX_NOT_FINISHED)
4397 goto out;
4398
4399
4400
4401
4402 lpfc_nlp_put(ndlp);
4403 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4404
4405
4406 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4407 "0138 ELS rsp: Cannot issue reg_login for x%x "
4408 "Data: x%x x%x x%x\n",
4409 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4410 ndlp->nlp_rpi);
4411
4412 if (lpfc_nlp_not_used(ndlp)) {
4413 ndlp = NULL;
4414
4415
4416
4417
4418 cmdiocb->context1 = NULL;
4419 }
4420 } else {
4421
4422 if (!lpfc_error_lost_link(irsp) &&
4423 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4424 if (lpfc_nlp_not_used(ndlp)) {
4425 ndlp = NULL;
4426
4427
4428
4429
4430
4431 cmdiocb->context1 = NULL;
4432 }
4433 }
4434 }
4435 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4436 if (mp) {
4437 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4438 kfree(mp);
4439 }
4440 mempool_free(mbox, phba->mbox_mem_pool);
4441 }
4442 out:
4443 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4444 spin_lock_irq(shost->host_lock);
4445 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
4446 spin_unlock_irq(shost->host_lock);
4447
4448
4449
4450
4451
4452
4453 if (ls_rjt)
4454 if (lpfc_nlp_not_used(ndlp))
4455
4456
4457
4458
4459 cmdiocb->context1 = NULL;
4460
4461 }
4462
4463 lpfc_els_free_iocb(phba, cmdiocb);
4464 return;
4465 }
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492 int
4493 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4494 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4495 LPFC_MBOXQ_t *mbox)
4496 {
4497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4498 struct lpfc_hba *phba = vport->phba;
4499 IOCB_t *icmd;
4500 IOCB_t *oldcmd;
4501 struct lpfc_iocbq *elsiocb;
4502 uint8_t *pcmd;
4503 struct serv_parm *sp;
4504 uint16_t cmdsize;
4505 int rc;
4506 ELS_PKT *els_pkt_ptr;
4507
4508 oldcmd = &oldiocb->iocb;
4509
4510 switch (flag) {
4511 case ELS_CMD_ACC:
4512 cmdsize = sizeof(uint32_t);
4513 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4514 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4515 if (!elsiocb) {
4516 spin_lock_irq(shost->host_lock);
4517 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4518 spin_unlock_irq(shost->host_lock);
4519 return 1;
4520 }
4521
4522 icmd = &elsiocb->iocb;
4523 icmd->ulpContext = oldcmd->ulpContext;
4524 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4525 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4526 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4527 pcmd += sizeof(uint32_t);
4528
4529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4530 "Issue ACC: did:x%x flg:x%x",
4531 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4532 break;
4533 case ELS_CMD_FLOGI:
4534 case ELS_CMD_PLOGI:
4535 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4536 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4537 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4538 if (!elsiocb)
4539 return 1;
4540
4541 icmd = &elsiocb->iocb;
4542 icmd->ulpContext = oldcmd->ulpContext;
4543 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4544 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4545
4546 if (mbox)
4547 elsiocb->context_un.mbox = mbox;
4548
4549 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4550 pcmd += sizeof(uint32_t);
4551 sp = (struct serv_parm *)pcmd;
4552
4553 if (flag == ELS_CMD_FLOGI) {
4554
4555 memcpy(sp, &phba->fc_fabparam,
4556 sizeof(struct serv_parm));
4557
4558
4559 sp->cmn.fPort = 0;
4560
4561
4562 sp->cls1.classValid = 0;
4563 sp->cls2.classValid = 0;
4564 sp->cls3.classValid = 0;
4565 sp->cls4.classValid = 0;
4566
4567
4568 memcpy(&sp->portName, &vport->fc_sparam.portName,
4569 sizeof(struct lpfc_name));
4570 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4571 sizeof(struct lpfc_name));
4572 } else {
4573 memcpy(pcmd, &vport->fc_sparam,
4574 sizeof(struct serv_parm));
4575
4576 sp->cmn.valid_vendor_ver_level = 0;
4577 memset(sp->un.vendorVersion, 0,
4578 sizeof(sp->un.vendorVersion));
4579 sp->cmn.bbRcvSizeMsb &= 0xF;
4580
4581
4582
4583
4584 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4585 sp->cmn.valid_vendor_ver_level = 1;
4586 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4587 sp->un.vv.flags =
4588 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4589 }
4590 }
4591
4592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4593 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4594 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4595 break;
4596 case ELS_CMD_PRLO:
4597 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4598 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4599 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4600 if (!elsiocb)
4601 return 1;
4602
4603 icmd = &elsiocb->iocb;
4604 icmd->ulpContext = oldcmd->ulpContext;
4605 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4606 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4607
4608 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4609 sizeof(uint32_t) + sizeof(PRLO));
4610 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4611 els_pkt_ptr = (ELS_PKT *) pcmd;
4612 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4613
4614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4615 "Issue ACC PRLO: did:x%x flg:x%x",
4616 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4617 break;
4618 default:
4619 return 1;
4620 }
4621 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4622 spin_lock_irq(shost->host_lock);
4623 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4624 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4625 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4626 spin_unlock_irq(shost->host_lock);
4627 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4628 } else {
4629 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4630 }
4631
4632 phba->fc_stat.elsXmitACC++;
4633 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4634 if (rc == IOCB_ERROR) {
4635 lpfc_els_free_iocb(phba, elsiocb);
4636 return 1;
4637 }
4638 return 0;
4639 }
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663 int
4664 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4665 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4666 LPFC_MBOXQ_t *mbox)
4667 {
4668 struct lpfc_hba *phba = vport->phba;
4669 IOCB_t *icmd;
4670 IOCB_t *oldcmd;
4671 struct lpfc_iocbq *elsiocb;
4672 uint8_t *pcmd;
4673 uint16_t cmdsize;
4674 int rc;
4675
4676 cmdsize = 2 * sizeof(uint32_t);
4677 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4678 ndlp->nlp_DID, ELS_CMD_LS_RJT);
4679 if (!elsiocb)
4680 return 1;
4681
4682 icmd = &elsiocb->iocb;
4683 oldcmd = &oldiocb->iocb;
4684 icmd->ulpContext = oldcmd->ulpContext;
4685 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4686 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4687
4688 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4689 pcmd += sizeof(uint32_t);
4690 *((uint32_t *) (pcmd)) = rejectError;
4691
4692 if (mbox)
4693 elsiocb->context_un.mbox = mbox;
4694
4695
4696 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4697 "0129 Xmit ELS RJT x%x response tag x%x "
4698 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4699 "rpi x%x\n",
4700 rejectError, elsiocb->iotag,
4701 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4702 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4704 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4705 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4706
4707 phba->fc_stat.elsXmitLSRJT++;
4708 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4709 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4710
4711 if (rc == IOCB_ERROR) {
4712 lpfc_els_free_iocb(phba, elsiocb);
4713 return 1;
4714 }
4715 return 0;
4716 }
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737 int
4738 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4739 struct lpfc_nodelist *ndlp)
4740 {
4741 struct lpfc_hba *phba = vport->phba;
4742 ADISC *ap;
4743 IOCB_t *icmd, *oldcmd;
4744 struct lpfc_iocbq *elsiocb;
4745 uint8_t *pcmd;
4746 uint16_t cmdsize;
4747 int rc;
4748
4749 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4750 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4751 ndlp->nlp_DID, ELS_CMD_ACC);
4752 if (!elsiocb)
4753 return 1;
4754
4755 icmd = &elsiocb->iocb;
4756 oldcmd = &oldiocb->iocb;
4757 icmd->ulpContext = oldcmd->ulpContext;
4758 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4759
4760
4761 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4762 "0130 Xmit ADISC ACC response iotag x%x xri: "
4763 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4764 elsiocb->iotag, elsiocb->iocb.ulpContext,
4765 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4766 ndlp->nlp_rpi);
4767 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4768
4769 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4770 pcmd += sizeof(uint32_t);
4771
4772 ap = (ADISC *) (pcmd);
4773 ap->hardAL_PA = phba->fc_pref_ALPA;
4774 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4775 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
4776 ap->DID = be32_to_cpu(vport->fc_myDID);
4777
4778 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4779 "Issue ACC ADISC: did:x%x flg:x%x",
4780 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4781
4782 phba->fc_stat.elsXmitACC++;
4783 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4784 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4785 if (rc == IOCB_ERROR) {
4786 lpfc_els_free_iocb(phba, elsiocb);
4787 return 1;
4788 }
4789
4790
4791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4792 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4793 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4794 "RPI: x%x, fc_flag x%x\n",
4795 rc, elsiocb->iotag, elsiocb->sli4_xritag,
4796 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4797 ndlp->nlp_rpi, vport->fc_flag);
4798 return 0;
4799 }
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820 int
4821 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4822 struct lpfc_nodelist *ndlp)
4823 {
4824 struct lpfc_hba *phba = vport->phba;
4825 PRLI *npr;
4826 struct lpfc_nvme_prli *npr_nvme;
4827 lpfc_vpd_t *vpd;
4828 IOCB_t *icmd;
4829 IOCB_t *oldcmd;
4830 struct lpfc_iocbq *elsiocb;
4831 uint8_t *pcmd;
4832 uint16_t cmdsize;
4833 uint32_t prli_fc4_req, *req_payload;
4834 struct lpfc_dmabuf *req_buf;
4835 int rc;
4836 u32 elsrspcmd;
4837
4838
4839
4840
4841 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4842 req_payload = (((uint32_t *)req_buf->virt) + 1);
4843
4844
4845 prli_fc4_req = be32_to_cpu(*req_payload);
4846 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4847 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4848 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4849 prli_fc4_req, *((uint32_t *)req_payload));
4850
4851 if (prli_fc4_req == PRLI_FCP_TYPE) {
4852 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4853 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4854 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4855 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4856 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4857 } else {
4858 return 1;
4859 }
4860
4861 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4862 ndlp->nlp_DID, elsrspcmd);
4863 if (!elsiocb)
4864 return 1;
4865
4866 icmd = &elsiocb->iocb;
4867 oldcmd = &oldiocb->iocb;
4868 icmd->ulpContext = oldcmd->ulpContext;
4869 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4870
4871
4872 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4873 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4874 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4875 elsiocb->iotag, elsiocb->iocb.ulpContext,
4876 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4877 ndlp->nlp_rpi);
4878 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4879 memset(pcmd, 0, cmdsize);
4880
4881 *((uint32_t *)(pcmd)) = elsrspcmd;
4882 pcmd += sizeof(uint32_t);
4883
4884
4885 vpd = &phba->vpd;
4886
4887 if (prli_fc4_req == PRLI_FCP_TYPE) {
4888
4889
4890
4891
4892
4893 npr = (PRLI *) pcmd;
4894 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4895 (vpd->rev.feaLevelHigh >= 0x02)) {
4896 npr->ConfmComplAllowed = 1;
4897 npr->Retry = 1;
4898 npr->TaskRetryIdReq = 1;
4899 }
4900 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4901 npr->estabImagePair = 1;
4902 npr->readXferRdyDis = 1;
4903 npr->ConfmComplAllowed = 1;
4904 npr->prliType = PRLI_FCP_TYPE;
4905 npr->initiatorFunc = 1;
4906 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4907
4908 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4909 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4910 bf_set(prli_estabImagePair, npr_nvme, 0);
4911 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
4912 if (phba->nvmet_support) {
4913 bf_set(prli_tgt, npr_nvme, 1);
4914 bf_set(prli_disc, npr_nvme, 1);
4915 if (phba->cfg_nvme_enable_fb) {
4916 bf_set(prli_fba, npr_nvme, 1);
4917
4918
4919
4920
4921
4922 bf_set(prli_fb_sz, npr_nvme,
4923 phba->cfg_nvmet_fb_size);
4924 }
4925 } else {
4926 bf_set(prli_init, npr_nvme, 1);
4927 }
4928
4929 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4930 "6015 NVME issue PRLI ACC word1 x%08x "
4931 "word4 x%08x word5 x%08x flag x%x, "
4932 "fcp_info x%x nlp_type x%x\n",
4933 npr_nvme->word1, npr_nvme->word4,
4934 npr_nvme->word5, ndlp->nlp_flag,
4935 ndlp->nlp_fcp_info, ndlp->nlp_type);
4936 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4937 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4938 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4939 } else
4940 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4941 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4942 prli_fc4_req, ndlp->nlp_fc4_type,
4943 ndlp->nlp_DID);
4944
4945 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4946 "Issue ACC PRLI: did:x%x flg:x%x",
4947 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4948
4949 phba->fc_stat.elsXmitACC++;
4950 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4951
4952 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4953 if (rc == IOCB_ERROR) {
4954 lpfc_els_free_iocb(phba, elsiocb);
4955 return 1;
4956 }
4957 return 0;
4958 }
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986 static int
4987 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
4988 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4989 {
4990 struct lpfc_hba *phba = vport->phba;
4991 RNID *rn;
4992 IOCB_t *icmd, *oldcmd;
4993 struct lpfc_iocbq *elsiocb;
4994 uint8_t *pcmd;
4995 uint16_t cmdsize;
4996 int rc;
4997
4998 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4999 + (2 * sizeof(struct lpfc_name));
5000 if (format)
5001 cmdsize += sizeof(RNID_TOP_DISC);
5002
5003 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5004 ndlp->nlp_DID, ELS_CMD_ACC);
5005 if (!elsiocb)
5006 return 1;
5007
5008 icmd = &elsiocb->iocb;
5009 oldcmd = &oldiocb->iocb;
5010 icmd->ulpContext = oldcmd->ulpContext;
5011 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5012
5013
5014 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5015 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5016 elsiocb->iotag, elsiocb->iocb.ulpContext);
5017 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5018 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5019 pcmd += sizeof(uint32_t);
5020
5021 memset(pcmd, 0, sizeof(RNID));
5022 rn = (RNID *) (pcmd);
5023 rn->Format = format;
5024 rn->CommonLen = (2 * sizeof(struct lpfc_name));
5025 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5026 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5027 switch (format) {
5028 case 0:
5029 rn->SpecificLen = 0;
5030 break;
5031 case RNID_TOPOLOGY_DISC:
5032 rn->SpecificLen = sizeof(RNID_TOP_DISC);
5033 memcpy(&rn->un.topologyDisc.portName,
5034 &vport->fc_portname, sizeof(struct lpfc_name));
5035 rn->un.topologyDisc.unitType = RNID_HBA;
5036 rn->un.topologyDisc.physPort = 0;
5037 rn->un.topologyDisc.attachedNodes = 0;
5038 break;
5039 default:
5040 rn->CommonLen = 0;
5041 rn->SpecificLen = 0;
5042 break;
5043 }
5044
5045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5046 "Issue ACC RNID: did:x%x flg:x%x",
5047 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5048
5049 phba->fc_stat.elsXmitACC++;
5050 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5051
5052 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5053 if (rc == IOCB_ERROR) {
5054 lpfc_els_free_iocb(phba, elsiocb);
5055 return 1;
5056 }
5057 return 0;
5058 }
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068 static void
5069 lpfc_els_clear_rrq(struct lpfc_vport *vport,
5070 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5071 {
5072 struct lpfc_hba *phba = vport->phba;
5073 uint8_t *pcmd;
5074 struct RRQ *rrq;
5075 uint16_t rxid;
5076 uint16_t xri;
5077 struct lpfc_node_rrq *prrq;
5078
5079
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5081 pcmd += sizeof(uint32_t);
5082 rrq = (struct RRQ *)pcmd;
5083 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5084 rxid = bf_get(rrq_rxid, rrq);
5085
5086 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5087 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5088 " x%x x%x\n",
5089 be32_to_cpu(bf_get(rrq_did, rrq)),
5090 bf_get(rrq_oxid, rrq),
5091 rxid,
5092 iocb->iotag, iocb->iocb.ulpContext);
5093
5094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5095 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5096 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5097 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5098 xri = bf_get(rrq_oxid, rrq);
5099 else
5100 xri = rxid;
5101 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5102 if (prrq)
5103 lpfc_clr_rrq_active(phba, xri, prrq);
5104 return;
5105 }
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118 static int
5119 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5120 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5121 {
5122 struct lpfc_hba *phba = vport->phba;
5123 struct lpfc_iocbq *elsiocb;
5124 uint8_t *pcmd;
5125 uint16_t cmdsize;
5126 int rc;
5127
5128 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5129
5130
5131
5132
5133 if (cmdsize > LPFC_BPL_SIZE)
5134 cmdsize = LPFC_BPL_SIZE;
5135 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5136 ndlp->nlp_DID, ELS_CMD_ACC);
5137 if (!elsiocb)
5138 return 1;
5139
5140 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext;
5141 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5142
5143
5144 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5145 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5146 elsiocb->iotag, elsiocb->iocb.ulpContext);
5147 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5148 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5149 pcmd += sizeof(uint32_t);
5150 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5151
5152 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5153 "Issue ACC ECHO: did:x%x flg:x%x",
5154 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5155
5156 phba->fc_stat.elsXmitACC++;
5157 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5158
5159 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5160 if (rc == IOCB_ERROR) {
5161 lpfc_els_free_iocb(phba, elsiocb);
5162 return 1;
5163 }
5164 return 0;
5165 }
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186 int
5187 lpfc_els_disc_adisc(struct lpfc_vport *vport)
5188 {
5189 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5190 struct lpfc_nodelist *ndlp, *next_ndlp;
5191 int sentadisc = 0;
5192
5193
5194 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5195 if (!NLP_CHK_NODE_ACT(ndlp))
5196 continue;
5197 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5198 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5199 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5200 spin_lock_irq(shost->host_lock);
5201 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5202 spin_unlock_irq(shost->host_lock);
5203 ndlp->nlp_prev_state = ndlp->nlp_state;
5204 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5205 lpfc_issue_els_adisc(vport, ndlp, 0);
5206 sentadisc++;
5207 vport->num_disc_nodes++;
5208 if (vport->num_disc_nodes >=
5209 vport->cfg_discovery_threads) {
5210 spin_lock_irq(shost->host_lock);
5211 vport->fc_flag |= FC_NLP_MORE;
5212 spin_unlock_irq(shost->host_lock);
5213 break;
5214 }
5215 }
5216 }
5217 if (sentadisc == 0) {
5218 spin_lock_irq(shost->host_lock);
5219 vport->fc_flag &= ~FC_NLP_MORE;
5220 spin_unlock_irq(shost->host_lock);
5221 }
5222 return sentadisc;
5223 }
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244 int
5245 lpfc_els_disc_plogi(struct lpfc_vport *vport)
5246 {
5247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5248 struct lpfc_nodelist *ndlp, *next_ndlp;
5249 int sentplogi = 0;
5250
5251
5252 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5253 if (!NLP_CHK_NODE_ACT(ndlp))
5254 continue;
5255 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5256 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5257 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5258 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5259 ndlp->nlp_prev_state = ndlp->nlp_state;
5260 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5261 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5262 sentplogi++;
5263 vport->num_disc_nodes++;
5264 if (vport->num_disc_nodes >=
5265 vport->cfg_discovery_threads) {
5266 spin_lock_irq(shost->host_lock);
5267 vport->fc_flag |= FC_NLP_MORE;
5268 spin_unlock_irq(shost->host_lock);
5269 break;
5270 }
5271 }
5272 }
5273 if (sentplogi) {
5274 lpfc_set_disctmo(vport);
5275 }
5276 else {
5277 spin_lock_irq(shost->host_lock);
5278 vport->fc_flag &= ~FC_NLP_MORE;
5279 spin_unlock_irq(shost->host_lock);
5280 }
5281 return sentplogi;
5282 }
5283
5284 static uint32_t
5285 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5286 uint32_t word0)
5287 {
5288
5289 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5290 desc->payload.els_req = word0;
5291 desc->length = cpu_to_be32(sizeof(desc->payload));
5292
5293 return sizeof(struct fc_rdp_link_service_desc);
5294 }
5295
5296 static uint32_t
5297 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5298 uint8_t *page_a0, uint8_t *page_a2)
5299 {
5300 uint16_t wavelength;
5301 uint16_t temperature;
5302 uint16_t rx_power;
5303 uint16_t tx_bias;
5304 uint16_t tx_power;
5305 uint16_t vcc;
5306 uint16_t flag = 0;
5307 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5308 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5309
5310 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5311
5312 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5313 &page_a0[SSF_TRANSCEIVER_CODE_B4];
5314 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5315 &page_a0[SSF_TRANSCEIVER_CODE_B5];
5316
5317 if ((trasn_code_byte4->fc_sw_laser) ||
5318 (trasn_code_byte5->fc_sw_laser_sl) ||
5319 (trasn_code_byte5->fc_sw_laser_sn)) {
5320 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5321 } else if (trasn_code_byte4->fc_lw_laser) {
5322 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5323 page_a0[SSF_WAVELENGTH_B0];
5324 if (wavelength == SFP_WAVELENGTH_LC1310)
5325 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5326 if (wavelength == SFP_WAVELENGTH_LL1550)
5327 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5328 }
5329
5330 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5331 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5332 << SFP_FLAG_CT_SHIFT;
5333
5334
5335 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5336 SFP_FLAG_IS_OPTICAL_PORT : 0)
5337 << SFP_FLAG_IS_OPTICAL_SHIFT;
5338
5339 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5340 page_a2[SFF_TEMPERATURE_B0]);
5341 vcc = (page_a2[SFF_VCC_B1] << 8 |
5342 page_a2[SFF_VCC_B0]);
5343 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5344 page_a2[SFF_TXPOWER_B0]);
5345 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5346 page_a2[SFF_TX_BIAS_CURRENT_B0]);
5347 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5348 page_a2[SFF_RXPOWER_B0]);
5349 desc->sfp_info.temperature = cpu_to_be16(temperature);
5350 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5351 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5352 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5353 desc->sfp_info.vcc = cpu_to_be16(vcc);
5354
5355 desc->sfp_info.flags = cpu_to_be16(flag);
5356 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5357
5358 return sizeof(struct fc_rdp_sfp_desc);
5359 }
5360
5361 static uint32_t
5362 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5363 READ_LNK_VAR *stat)
5364 {
5365 uint32_t type;
5366
5367 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5368
5369 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5370
5371 desc->info.port_type = cpu_to_be32(type);
5372
5373 desc->info.link_status.link_failure_cnt =
5374 cpu_to_be32(stat->linkFailureCnt);
5375 desc->info.link_status.loss_of_synch_cnt =
5376 cpu_to_be32(stat->lossSyncCnt);
5377 desc->info.link_status.loss_of_signal_cnt =
5378 cpu_to_be32(stat->lossSignalCnt);
5379 desc->info.link_status.primitive_seq_proto_err =
5380 cpu_to_be32(stat->primSeqErrCnt);
5381 desc->info.link_status.invalid_trans_word =
5382 cpu_to_be32(stat->invalidXmitWord);
5383 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5384
5385 desc->length = cpu_to_be32(sizeof(desc->info));
5386
5387 return sizeof(struct fc_rdp_link_error_status_desc);
5388 }
5389
5390 static uint32_t
5391 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5392 struct lpfc_vport *vport)
5393 {
5394 uint32_t bbCredit;
5395
5396 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5397
5398 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5399 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5400 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5401 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5402 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5403 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5404 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5405 } else {
5406 desc->bbc_info.attached_port_bbc = 0;
5407 }
5408
5409 desc->bbc_info.rtt = 0;
5410 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5411
5412 return sizeof(struct fc_rdp_bbc_desc);
5413 }
5414
5415 static uint32_t
5416 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5417 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5418 {
5419 uint32_t flags = 0;
5420
5421 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5422
5423 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5424 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5425 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5426 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5427
5428 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5429 flags |= RDP_OET_HIGH_ALARM;
5430 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5431 flags |= RDP_OET_LOW_ALARM;
5432 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5433 flags |= RDP_OET_HIGH_WARNING;
5434 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5435 flags |= RDP_OET_LOW_WARNING;
5436
5437 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5438 desc->oed_info.function_flags = cpu_to_be32(flags);
5439 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5440 return sizeof(struct fc_rdp_oed_sfp_desc);
5441 }
5442
5443 static uint32_t
5444 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5445 struct fc_rdp_oed_sfp_desc *desc,
5446 uint8_t *page_a2)
5447 {
5448 uint32_t flags = 0;
5449
5450 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5451
5452 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5453 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5454 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5455 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5456
5457 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5458 flags |= RDP_OET_HIGH_ALARM;
5459 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5460 flags |= RDP_OET_LOW_ALARM;
5461 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5462 flags |= RDP_OET_HIGH_WARNING;
5463 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5464 flags |= RDP_OET_LOW_WARNING;
5465
5466 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5467 desc->oed_info.function_flags = cpu_to_be32(flags);
5468 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5469 return sizeof(struct fc_rdp_oed_sfp_desc);
5470 }
5471
5472 static uint32_t
5473 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5474 struct fc_rdp_oed_sfp_desc *desc,
5475 uint8_t *page_a2)
5476 {
5477 uint32_t flags = 0;
5478
5479 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5480
5481 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5482 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5483 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5484 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5485
5486 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5487 flags |= RDP_OET_HIGH_ALARM;
5488 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5489 flags |= RDP_OET_LOW_ALARM;
5490 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5491 flags |= RDP_OET_HIGH_WARNING;
5492 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5493 flags |= RDP_OET_LOW_WARNING;
5494
5495 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5496 desc->oed_info.function_flags = cpu_to_be32(flags);
5497 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5498 return sizeof(struct fc_rdp_oed_sfp_desc);
5499 }
5500
5501 static uint32_t
5502 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5503 struct fc_rdp_oed_sfp_desc *desc,
5504 uint8_t *page_a2)
5505 {
5506 uint32_t flags = 0;
5507
5508 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5509
5510 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5511 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5512 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5513 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5514
5515 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5516 flags |= RDP_OET_HIGH_ALARM;
5517 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5518 flags |= RDP_OET_LOW_ALARM;
5519 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5520 flags |= RDP_OET_HIGH_WARNING;
5521 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5522 flags |= RDP_OET_LOW_WARNING;
5523
5524 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5525 desc->oed_info.function_flags = cpu_to_be32(flags);
5526 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5527 return sizeof(struct fc_rdp_oed_sfp_desc);
5528 }
5529
5530
5531 static uint32_t
5532 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5533 struct fc_rdp_oed_sfp_desc *desc,
5534 uint8_t *page_a2)
5535 {
5536 uint32_t flags = 0;
5537
5538 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5539
5540 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5541 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5542 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5543 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5544
5545 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5546 flags |= RDP_OET_HIGH_ALARM;
5547 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5548 flags |= RDP_OET_LOW_ALARM;
5549 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5550 flags |= RDP_OET_HIGH_WARNING;
5551 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5552 flags |= RDP_OET_LOW_WARNING;
5553
5554 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5555 desc->oed_info.function_flags = cpu_to_be32(flags);
5556 desc->length = cpu_to_be32(sizeof(desc->oed_info));
5557 return sizeof(struct fc_rdp_oed_sfp_desc);
5558 }
5559
5560 static uint32_t
5561 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5562 uint8_t *page_a0, struct lpfc_vport *vport)
5563 {
5564 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5565 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5566 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5567 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5568 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5569 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5570 desc->length = cpu_to_be32(sizeof(desc->opd_info));
5571 return sizeof(struct fc_rdp_opd_sfp_desc);
5572 }
5573
5574 static uint32_t
5575 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5576 {
5577 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5578 return 0;
5579 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5580
5581 desc->info.CorrectedBlocks =
5582 cpu_to_be32(stat->fecCorrBlkCount);
5583 desc->info.UncorrectableBlocks =
5584 cpu_to_be32(stat->fecUncorrBlkCount);
5585
5586 desc->length = cpu_to_be32(sizeof(desc->info));
5587
5588 return sizeof(struct fc_fec_rdp_desc);
5589 }
5590
5591 static uint32_t
5592 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5593 {
5594 uint16_t rdp_cap = 0;
5595 uint16_t rdp_speed;
5596
5597 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5598
5599 switch (phba->fc_linkspeed) {
5600 case LPFC_LINK_SPEED_1GHZ:
5601 rdp_speed = RDP_PS_1GB;
5602 break;
5603 case LPFC_LINK_SPEED_2GHZ:
5604 rdp_speed = RDP_PS_2GB;
5605 break;
5606 case LPFC_LINK_SPEED_4GHZ:
5607 rdp_speed = RDP_PS_4GB;
5608 break;
5609 case LPFC_LINK_SPEED_8GHZ:
5610 rdp_speed = RDP_PS_8GB;
5611 break;
5612 case LPFC_LINK_SPEED_10GHZ:
5613 rdp_speed = RDP_PS_10GB;
5614 break;
5615 case LPFC_LINK_SPEED_16GHZ:
5616 rdp_speed = RDP_PS_16GB;
5617 break;
5618 case LPFC_LINK_SPEED_32GHZ:
5619 rdp_speed = RDP_PS_32GB;
5620 break;
5621 case LPFC_LINK_SPEED_64GHZ:
5622 rdp_speed = RDP_PS_64GB;
5623 break;
5624 default:
5625 rdp_speed = RDP_PS_UNKNOWN;
5626 break;
5627 }
5628
5629 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5630
5631 if (phba->lmt & LMT_128Gb)
5632 rdp_cap |= RDP_PS_128GB;
5633 if (phba->lmt & LMT_64Gb)
5634 rdp_cap |= RDP_PS_64GB;
5635 if (phba->lmt & LMT_32Gb)
5636 rdp_cap |= RDP_PS_32GB;
5637 if (phba->lmt & LMT_16Gb)
5638 rdp_cap |= RDP_PS_16GB;
5639 if (phba->lmt & LMT_10Gb)
5640 rdp_cap |= RDP_PS_10GB;
5641 if (phba->lmt & LMT_8Gb)
5642 rdp_cap |= RDP_PS_8GB;
5643 if (phba->lmt & LMT_4Gb)
5644 rdp_cap |= RDP_PS_4GB;
5645 if (phba->lmt & LMT_2Gb)
5646 rdp_cap |= RDP_PS_2GB;
5647 if (phba->lmt & LMT_1Gb)
5648 rdp_cap |= RDP_PS_1GB;
5649
5650 if (rdp_cap == 0)
5651 rdp_cap = RDP_CAP_UNKNOWN;
5652 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5653 rdp_cap |= RDP_CAP_USER_CONFIGURED;
5654
5655 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5656 desc->length = cpu_to_be32(sizeof(desc->info));
5657 return sizeof(struct fc_rdp_port_speed_desc);
5658 }
5659
5660 static uint32_t
5661 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5662 struct lpfc_vport *vport)
5663 {
5664
5665 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5666
5667 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5668 sizeof(desc->port_names.wwnn));
5669
5670 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5671 sizeof(desc->port_names.wwpn));
5672
5673 desc->length = cpu_to_be32(sizeof(desc->port_names));
5674 return sizeof(struct fc_rdp_port_name_desc);
5675 }
5676
5677 static uint32_t
5678 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5679 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5680 {
5681
5682 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5683 if (vport->fc_flag & FC_FABRIC) {
5684 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5685 sizeof(desc->port_names.wwnn));
5686
5687 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5688 sizeof(desc->port_names.wwpn));
5689 } else {
5690 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5691 sizeof(desc->port_names.wwnn));
5692
5693 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5694 sizeof(desc->port_names.wwpn));
5695 }
5696
5697 desc->length = cpu_to_be32(sizeof(desc->port_names));
5698 return sizeof(struct fc_rdp_port_name_desc);
5699 }
5700
5701 static void
5702 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5703 int status)
5704 {
5705 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5706 struct lpfc_vport *vport = ndlp->vport;
5707 struct lpfc_iocbq *elsiocb;
5708 struct ulp_bde64 *bpl;
5709 IOCB_t *icmd;
5710 uint8_t *pcmd;
5711 struct ls_rjt *stat;
5712 struct fc_rdp_res_frame *rdp_res;
5713 uint32_t cmdsize, len;
5714 uint16_t *flag_ptr;
5715 int rc;
5716
5717 if (status != SUCCESS)
5718 goto error;
5719
5720
5721 cmdsize = sizeof(struct fc_rdp_res_frame);
5722
5723 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5724 lpfc_max_els_tries, rdp_context->ndlp,
5725 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5726 lpfc_nlp_put(ndlp);
5727 if (!elsiocb)
5728 goto free_rdp_context;
5729
5730 icmd = &elsiocb->iocb;
5731 icmd->ulpContext = rdp_context->rx_id;
5732 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5733
5734 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5735 "2171 Xmit RDP response tag x%x xri x%x, "
5736 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5737 elsiocb->iotag, elsiocb->iocb.ulpContext,
5738 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5739 ndlp->nlp_rpi);
5740 rdp_res = (struct fc_rdp_res_frame *)
5741 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5742 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5743 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5744 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5745
5746
5747 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5748 phba->sfp_alarm |= *flag_ptr;
5749 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5750 phba->sfp_warning |= *flag_ptr;
5751
5752
5753 len = 8;
5754 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5755 (len + pcmd), ELS_CMD_RDP);
5756
5757 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
5758 rdp_context->page_a0, rdp_context->page_a2);
5759 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5760 phba);
5761 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5762 (len + pcmd), &rdp_context->link_stat);
5763 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5764 (len + pcmd), vport);
5765 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5766 (len + pcmd), vport, ndlp);
5767 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
5768 &rdp_context->link_stat);
5769 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5770 &rdp_context->link_stat, vport);
5771 len += lpfc_rdp_res_oed_temp_desc(phba,
5772 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5773 rdp_context->page_a2);
5774 len += lpfc_rdp_res_oed_voltage_desc(phba,
5775 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5776 rdp_context->page_a2);
5777 len += lpfc_rdp_res_oed_txbias_desc(phba,
5778 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5779 rdp_context->page_a2);
5780 len += lpfc_rdp_res_oed_txpower_desc(phba,
5781 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5782 rdp_context->page_a2);
5783 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5784 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5785 rdp_context->page_a2);
5786 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5787 rdp_context->page_a0, vport);
5788
5789 rdp_res->length = cpu_to_be32(len - 8);
5790 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5791
5792
5793 bpl = (struct ulp_bde64 *)
5794 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
5795 bpl->tus.f.bdeSize = len;
5796 bpl->tus.f.bdeFlags = 0;
5797 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5798
5799 phba->fc_stat.elsXmitACC++;
5800 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5801 if (rc == IOCB_ERROR)
5802 lpfc_els_free_iocb(phba, elsiocb);
5803
5804 kfree(rdp_context);
5805
5806 return;
5807 error:
5808 cmdsize = 2 * sizeof(uint32_t);
5809 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5810 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5811 lpfc_nlp_put(ndlp);
5812 if (!elsiocb)
5813 goto free_rdp_context;
5814
5815 icmd = &elsiocb->iocb;
5816 icmd->ulpContext = rdp_context->rx_id;
5817 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5818 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5819
5820 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5821 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5822 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5823
5824 phba->fc_stat.elsXmitLSRJT++;
5825 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5826 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5827
5828 if (rc == IOCB_ERROR)
5829 lpfc_els_free_iocb(phba, elsiocb);
5830 free_rdp_context:
5831 kfree(rdp_context);
5832 }
5833
5834 static int
5835 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5836 {
5837 LPFC_MBOXQ_t *mbox = NULL;
5838 int rc;
5839
5840 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5841 if (!mbox) {
5842 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5843 "7105 failed to allocate mailbox memory");
5844 return 1;
5845 }
5846
5847 if (lpfc_sli4_dump_page_a0(phba, mbox))
5848 goto prep_mbox_fail;
5849 mbox->vport = rdp_context->ndlp->vport;
5850 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5851 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
5852 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5853 if (rc == MBX_NOT_FINISHED)
5854 goto issue_mbox_fail;
5855
5856 return 0;
5857
5858 prep_mbox_fail:
5859 issue_mbox_fail:
5860 mempool_free(mbox, phba->mbox_mem_pool);
5861 return 1;
5862 }
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881 static int
5882 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5883 struct lpfc_nodelist *ndlp)
5884 {
5885 struct lpfc_hba *phba = vport->phba;
5886 struct lpfc_dmabuf *pcmd;
5887 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5888 struct fc_rdp_req_frame *rdp_req;
5889 struct lpfc_rdp_context *rdp_context;
5890 IOCB_t *cmd = NULL;
5891 struct ls_rjt stat;
5892
5893 if (phba->sli_rev < LPFC_SLI_REV4 ||
5894 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
5895 LPFC_SLI_INTF_IF_TYPE_2) {
5896 rjt_err = LSRJT_UNABLE_TPC;
5897 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5898 goto error;
5899 }
5900
5901 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5902 rjt_err = LSRJT_UNABLE_TPC;
5903 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5904 goto error;
5905 }
5906
5907 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5908 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5909
5910 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5911 "2422 ELS RDP Request "
5912 "dec len %d tag x%x port_id %d len %d\n",
5913 be32_to_cpu(rdp_req->rdp_des_length),
5914 be32_to_cpu(rdp_req->nport_id_desc.tag),
5915 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5916 be32_to_cpu(rdp_req->nport_id_desc.length));
5917
5918 if (sizeof(struct fc_rdp_nport_desc) !=
5919 be32_to_cpu(rdp_req->rdp_des_length))
5920 goto rjt_logerr;
5921 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5922 goto rjt_logerr;
5923 if (RDP_NPORT_ID_SIZE !=
5924 be32_to_cpu(rdp_req->nport_id_desc.length))
5925 goto rjt_logerr;
5926 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
5927 if (!rdp_context) {
5928 rjt_err = LSRJT_UNABLE_TPC;
5929 goto error;
5930 }
5931
5932 cmd = &cmdiocb->iocb;
5933 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5934 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5935 rdp_context->rx_id = cmd->ulpContext;
5936 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5937 if (lpfc_get_rdp_info(phba, rdp_context)) {
5938 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5939 "2423 Unable to send mailbox");
5940 kfree(rdp_context);
5941 rjt_err = LSRJT_UNABLE_TPC;
5942 lpfc_nlp_put(ndlp);
5943 goto error;
5944 }
5945
5946 return 0;
5947
5948 rjt_logerr:
5949 rjt_err = LSRJT_LOGICAL_ERR;
5950
5951 error:
5952 memset(&stat, 0, sizeof(stat));
5953 stat.un.b.lsRjtRsnCode = rjt_err;
5954 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5955 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5956 return 1;
5957 }
5958
5959
5960 static void
5961 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5962 {
5963 MAILBOX_t *mb;
5964 IOCB_t *icmd;
5965 uint8_t *pcmd;
5966 struct lpfc_iocbq *elsiocb;
5967 struct lpfc_nodelist *ndlp;
5968 struct ls_rjt *stat;
5969 union lpfc_sli4_cfg_shdr *shdr;
5970 struct lpfc_lcb_context *lcb_context;
5971 struct fc_lcb_res_frame *lcb_res;
5972 uint32_t cmdsize, shdr_status, shdr_add_status;
5973 int rc;
5974
5975 mb = &pmb->u.mb;
5976 lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
5977 ndlp = lcb_context->ndlp;
5978 pmb->ctx_ndlp = NULL;
5979 pmb->ctx_buf = NULL;
5980
5981 shdr = (union lpfc_sli4_cfg_shdr *)
5982 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5983 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5984 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5985
5986 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5987 "0194 SET_BEACON_CONFIG mailbox "
5988 "completed with status x%x add_status x%x,"
5989 " mbx status x%x\n",
5990 shdr_status, shdr_add_status, mb->mbxStatus);
5991
5992 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
5993 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
5994 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
5995 mempool_free(pmb, phba->mbox_mem_pool);
5996 goto error;
5997 }
5998
5999 mempool_free(pmb, phba->mbox_mem_pool);
6000 cmdsize = sizeof(struct fc_lcb_res_frame);
6001 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6002 lpfc_max_els_tries, ndlp,
6003 ndlp->nlp_DID, ELS_CMD_ACC);
6004
6005
6006 lpfc_nlp_put(ndlp);
6007
6008 if (!elsiocb)
6009 goto free_lcb_context;
6010
6011 lcb_res = (struct fc_lcb_res_frame *)
6012 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6013
6014 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6015 icmd = &elsiocb->iocb;
6016 icmd->ulpContext = lcb_context->rx_id;
6017 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6018
6019 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6020 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6021 lcb_res->lcb_sub_command = lcb_context->sub_command;
6022 lcb_res->lcb_type = lcb_context->type;
6023 lcb_res->capability = lcb_context->capability;
6024 lcb_res->lcb_frequency = lcb_context->frequency;
6025 lcb_res->lcb_duration = lcb_context->duration;
6026 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6027 phba->fc_stat.elsXmitACC++;
6028 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6029 if (rc == IOCB_ERROR)
6030 lpfc_els_free_iocb(phba, elsiocb);
6031
6032 kfree(lcb_context);
6033 return;
6034
6035 error:
6036 cmdsize = sizeof(struct fc_lcb_res_frame);
6037 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6038 lpfc_max_els_tries, ndlp,
6039 ndlp->nlp_DID, ELS_CMD_LS_RJT);
6040 lpfc_nlp_put(ndlp);
6041 if (!elsiocb)
6042 goto free_lcb_context;
6043
6044 icmd = &elsiocb->iocb;
6045 icmd->ulpContext = lcb_context->rx_id;
6046 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6047 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6048
6049 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6050 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6051 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6052
6053 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6054 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6055
6056 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6057 phba->fc_stat.elsXmitLSRJT++;
6058 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6059 if (rc == IOCB_ERROR)
6060 lpfc_els_free_iocb(phba, elsiocb);
6061 free_lcb_context:
6062 kfree(lcb_context);
6063 }
6064
6065 static int
6066 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6067 struct lpfc_lcb_context *lcb_context,
6068 uint32_t beacon_state)
6069 {
6070 struct lpfc_hba *phba = vport->phba;
6071 union lpfc_sli4_cfg_shdr *cfg_shdr;
6072 LPFC_MBOXQ_t *mbox = NULL;
6073 uint32_t len;
6074 int rc;
6075
6076 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6077 if (!mbox)
6078 return 1;
6079
6080 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6081 len = sizeof(struct lpfc_mbx_set_beacon_config) -
6082 sizeof(struct lpfc_sli4_cfg_mhdr);
6083 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6084 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6085 LPFC_SLI4_MBX_EMBED);
6086 mbox->ctx_ndlp = (void *)lcb_context;
6087 mbox->vport = phba->pport;
6088 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6089 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6090 phba->sli4_hba.physical_port);
6091 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6092 beacon_state);
6093 mbox->u.mqe.un.beacon_config.word5 = 0;
6094
6095
6096
6097
6098
6099
6100
6101 if (phba->sli4_hba.pc_sli4_params.bv1s) {
6102
6103 cfg_shdr->request.word9 = BEACON_VERSION_V1;
6104 lcb_context->capability |= LCB_CAPABILITY_DURATION;
6105 bf_set(lpfc_mbx_set_beacon_port_type,
6106 &mbox->u.mqe.un.beacon_config, 0);
6107 bf_set(lpfc_mbx_set_beacon_duration_v1,
6108 &mbox->u.mqe.un.beacon_config,
6109 be16_to_cpu(lcb_context->duration));
6110 } else {
6111
6112 if (be16_to_cpu(lcb_context->duration) != 0) {
6113 mempool_free(mbox, phba->mbox_mem_pool);
6114 return 1;
6115 }
6116 cfg_shdr->request.word9 = BEACON_VERSION_V0;
6117 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6118 bf_set(lpfc_mbx_set_beacon_state,
6119 &mbox->u.mqe.un.beacon_config, beacon_state);
6120 bf_set(lpfc_mbx_set_beacon_port_type,
6121 &mbox->u.mqe.un.beacon_config, 1);
6122 bf_set(lpfc_mbx_set_beacon_duration,
6123 &mbox->u.mqe.un.beacon_config,
6124 be16_to_cpu(lcb_context->duration));
6125 }
6126
6127 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6128 if (rc == MBX_NOT_FINISHED) {
6129 mempool_free(mbox, phba->mbox_mem_pool);
6130 return 1;
6131 }
6132
6133 return 0;
6134 }
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151 static int
6152 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6153 struct lpfc_nodelist *ndlp)
6154 {
6155 struct lpfc_hba *phba = vport->phba;
6156 struct lpfc_dmabuf *pcmd;
6157 uint8_t *lp;
6158 struct fc_lcb_request_frame *beacon;
6159 struct lpfc_lcb_context *lcb_context;
6160 uint8_t state, rjt_err;
6161 struct ls_rjt stat;
6162
6163 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6164 lp = (uint8_t *)pcmd->virt;
6165 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6166
6167 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6168 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6169 "type x%x frequency %x duration x%x\n",
6170 lp[0], lp[1], lp[2],
6171 beacon->lcb_command,
6172 beacon->lcb_sub_command,
6173 beacon->lcb_type,
6174 beacon->lcb_frequency,
6175 be16_to_cpu(beacon->lcb_duration));
6176
6177 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6178 beacon->lcb_sub_command != LPFC_LCB_OFF) {
6179 rjt_err = LSRJT_CMD_UNSUPPORTED;
6180 goto rjt;
6181 }
6182
6183 if (phba->sli_rev < LPFC_SLI_REV4 ||
6184 phba->hba_flag & HBA_FCOE_MODE ||
6185 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6186 LPFC_SLI_INTF_IF_TYPE_2)) {
6187 rjt_err = LSRJT_CMD_UNSUPPORTED;
6188 goto rjt;
6189 }
6190
6191 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6192 if (!lcb_context) {
6193 rjt_err = LSRJT_UNABLE_TPC;
6194 goto rjt;
6195 }
6196
6197 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6198 lcb_context->sub_command = beacon->lcb_sub_command;
6199 lcb_context->capability = 0;
6200 lcb_context->type = beacon->lcb_type;
6201 lcb_context->frequency = beacon->lcb_frequency;
6202 lcb_context->duration = beacon->lcb_duration;
6203 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6204 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6205 lcb_context->ndlp = lpfc_nlp_get(ndlp);
6206 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6207 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
6208 LOG_ELS, "0193 failed to send mail box");
6209 kfree(lcb_context);
6210 lpfc_nlp_put(ndlp);
6211 rjt_err = LSRJT_UNABLE_TPC;
6212 goto rjt;
6213 }
6214 return 0;
6215 rjt:
6216 memset(&stat, 0, sizeof(stat));
6217 stat.un.b.lsRjtRsnCode = rjt_err;
6218 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6219 return 1;
6220 }
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232 void
6233 lpfc_els_flush_rscn(struct lpfc_vport *vport)
6234 {
6235 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6236 struct lpfc_hba *phba = vport->phba;
6237 int i;
6238
6239 spin_lock_irq(shost->host_lock);
6240 if (vport->fc_rscn_flush) {
6241
6242 spin_unlock_irq(shost->host_lock);
6243 return;
6244 }
6245
6246 vport->fc_rscn_flush = 1;
6247 spin_unlock_irq(shost->host_lock);
6248
6249 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6250 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6251 vport->fc_rscn_id_list[i] = NULL;
6252 }
6253 spin_lock_irq(shost->host_lock);
6254 vport->fc_rscn_id_cnt = 0;
6255 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6256 spin_unlock_irq(shost->host_lock);
6257 lpfc_can_disctmo(vport);
6258
6259 vport->fc_rscn_flush = 0;
6260 }
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274 int
6275 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6276 {
6277 D_ID ns_did;
6278 D_ID rscn_did;
6279 uint32_t *lp;
6280 uint32_t payload_len, i;
6281 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6282
6283 ns_did.un.word = did;
6284
6285
6286 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6287 return 0;
6288
6289
6290 if (vport->fc_flag & FC_RSCN_DISCOVERY)
6291 return did;
6292
6293 spin_lock_irq(shost->host_lock);
6294 if (vport->fc_rscn_flush) {
6295
6296 spin_unlock_irq(shost->host_lock);
6297 return 0;
6298 }
6299
6300 vport->fc_rscn_flush = 1;
6301 spin_unlock_irq(shost->host_lock);
6302 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6303 lp = vport->fc_rscn_id_list[i]->virt;
6304 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6305 payload_len -= sizeof(uint32_t);
6306 while (payload_len) {
6307 rscn_did.un.word = be32_to_cpu(*lp++);
6308 payload_len -= sizeof(uint32_t);
6309 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6310 case RSCN_ADDRESS_FORMAT_PORT:
6311 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6312 && (ns_did.un.b.area == rscn_did.un.b.area)
6313 && (ns_did.un.b.id == rscn_did.un.b.id))
6314 goto return_did_out;
6315 break;
6316 case RSCN_ADDRESS_FORMAT_AREA:
6317 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6318 && (ns_did.un.b.area == rscn_did.un.b.area))
6319 goto return_did_out;
6320 break;
6321 case RSCN_ADDRESS_FORMAT_DOMAIN:
6322 if (ns_did.un.b.domain == rscn_did.un.b.domain)
6323 goto return_did_out;
6324 break;
6325 case RSCN_ADDRESS_FORMAT_FABRIC:
6326 goto return_did_out;
6327 }
6328 }
6329 }
6330
6331 vport->fc_rscn_flush = 0;
6332 return 0;
6333 return_did_out:
6334
6335 vport->fc_rscn_flush = 0;
6336 return did;
6337 }
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350 static int
6351 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6352 {
6353 struct lpfc_nodelist *ndlp = NULL;
6354
6355
6356 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6357 if (!NLP_CHK_NODE_ACT(ndlp) ||
6358 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6359 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6360 continue;
6361
6362
6363 if (vport->phba->nvmet_support)
6364 continue;
6365
6366
6367
6368
6369 switch (ndlp->nlp_state) {
6370 case NLP_STE_PLOGI_ISSUE:
6371 case NLP_STE_ADISC_ISSUE:
6372 case NLP_STE_REG_LOGIN_ISSUE:
6373 case NLP_STE_PRLI_ISSUE:
6374 case NLP_STE_LOGO_ISSUE:
6375 continue;
6376 }
6377
6378
6379
6380
6381 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6382 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6383 lpfc_nvme_rescan_port(vport, ndlp);
6384
6385 lpfc_disc_state_machine(vport, ndlp, NULL,
6386 NLP_EVT_DEVICE_RECOVERY);
6387 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6388 }
6389 return 0;
6390 }
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400 static void
6401 lpfc_send_rscn_event(struct lpfc_vport *vport,
6402 struct lpfc_iocbq *cmdiocb)
6403 {
6404 struct lpfc_dmabuf *pcmd;
6405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6406 uint32_t *payload_ptr;
6407 uint32_t payload_len;
6408 struct lpfc_rscn_event_header *rscn_event_data;
6409
6410 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6411 payload_ptr = (uint32_t *) pcmd->virt;
6412 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6413
6414 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6415 payload_len, GFP_KERNEL);
6416 if (!rscn_event_data) {
6417 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6418 "0147 Failed to allocate memory for RSCN event\n");
6419 return;
6420 }
6421 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6422 rscn_event_data->payload_length = payload_len;
6423 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6424 payload_len);
6425
6426 fc_host_post_vendor_event(shost,
6427 fc_get_event_number(),
6428 sizeof(struct lpfc_rscn_event_header) + payload_len,
6429 (char *)rscn_event_data,
6430 LPFC_NL_VENDOR_ID);
6431
6432 kfree(rscn_event_data);
6433 }
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457 static int
6458 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6459 struct lpfc_nodelist *ndlp)
6460 {
6461 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6462 struct lpfc_hba *phba = vport->phba;
6463 struct lpfc_dmabuf *pcmd;
6464 uint32_t *lp, *datap;
6465 uint32_t payload_len, length, nportid, *cmd;
6466 int rscn_cnt;
6467 int rscn_id = 0, hba_id = 0;
6468 int i, tmo;
6469
6470 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6471 lp = (uint32_t *) pcmd->virt;
6472
6473 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6474 payload_len -= sizeof(uint32_t);
6475
6476 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6477 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6478 vport->fc_flag, payload_len, *lp,
6479 vport->fc_rscn_id_cnt);
6480
6481
6482 lpfc_send_rscn_event(vport, cmdiocb);
6483
6484 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6485 fc_host_post_event(shost, fc_get_event_number(),
6486 FCH_EVT_RSCN, lp[i]);
6487
6488
6489 if (vport->fc_flag & FC_PT2PT) {
6490
6491 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6492 "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6493 *lp, vport->fc_flag, payload_len);
6494 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6495
6496
6497
6498
6499 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6500 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6501 lpfc_nvme_rescan_port(vport, ndlp);
6502 return 0;
6503 }
6504
6505
6506
6507
6508 if (vport->port_state <= LPFC_NS_QRY) {
6509 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6510 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6511 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6512
6513 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6514 return 0;
6515 }
6516
6517
6518
6519
6520 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6521 !(vport->cfg_peer_port_login)) {
6522 i = payload_len;
6523 datap = lp;
6524 while (i > 0) {
6525 nportid = *datap++;
6526 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6527 i -= sizeof(uint32_t);
6528 rscn_id++;
6529 if (lpfc_find_vport_by_did(phba, nportid))
6530 hba_id++;
6531 }
6532 if (rscn_id == hba_id) {
6533
6534 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6535 "0219 Ignore RSCN "
6536 "Data: x%x x%x x%x x%x\n",
6537 vport->fc_flag, payload_len,
6538 *lp, vport->fc_rscn_id_cnt);
6539 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6540 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6541 ndlp->nlp_DID, vport->port_state,
6542 ndlp->nlp_flag);
6543
6544 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6545 ndlp, NULL);
6546 return 0;
6547 }
6548 }
6549
6550 spin_lock_irq(shost->host_lock);
6551 if (vport->fc_rscn_flush) {
6552
6553 vport->fc_flag |= FC_RSCN_DISCOVERY;
6554 spin_unlock_irq(shost->host_lock);
6555
6556 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6557 return 0;
6558 }
6559
6560 vport->fc_rscn_flush = 1;
6561 spin_unlock_irq(shost->host_lock);
6562
6563 rscn_cnt = vport->fc_rscn_id_cnt;
6564
6565
6566
6567 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6568 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6569 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6570 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6571
6572 spin_lock_irq(shost->host_lock);
6573 vport->fc_flag |= FC_RSCN_DEFERRED;
6574
6575
6576 if (vport->fc_flag & FC_DISC_TMO) {
6577 tmo = ((phba->fc_ratov * 3) + 3);
6578 mod_timer(&vport->fc_disctmo,
6579 jiffies + msecs_to_jiffies(1000 * tmo));
6580 }
6581 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6582 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6583 vport->fc_flag |= FC_RSCN_MODE;
6584 spin_unlock_irq(shost->host_lock);
6585 if (rscn_cnt) {
6586 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6587 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6588 }
6589 if ((rscn_cnt) &&
6590 (payload_len + length <= LPFC_BPL_SIZE)) {
6591 *cmd &= ELS_CMD_MASK;
6592 *cmd |= cpu_to_be32(payload_len + length);
6593 memcpy(((uint8_t *)cmd) + length, lp,
6594 payload_len);
6595 } else {
6596 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6597 vport->fc_rscn_id_cnt++;
6598
6599
6600
6601 cmdiocb->context2 = NULL;
6602 }
6603
6604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6605 "0235 Deferred RSCN "
6606 "Data: x%x x%x x%x\n",
6607 vport->fc_rscn_id_cnt, vport->fc_flag,
6608 vport->port_state);
6609 } else {
6610 vport->fc_flag |= FC_RSCN_DISCOVERY;
6611 spin_unlock_irq(shost->host_lock);
6612
6613 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6614 "0234 ReDiscovery RSCN "
6615 "Data: x%x x%x x%x\n",
6616 vport->fc_rscn_id_cnt, vport->fc_flag,
6617 vport->port_state);
6618 }
6619
6620 vport->fc_rscn_flush = 0;
6621
6622 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6623
6624 lpfc_rscn_recovery_check(vport);
6625 return 0;
6626 }
6627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6628 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6629 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6630
6631 spin_lock_irq(shost->host_lock);
6632 vport->fc_flag |= FC_RSCN_MODE;
6633 spin_unlock_irq(shost->host_lock);
6634 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6635
6636 vport->fc_rscn_flush = 0;
6637
6638
6639
6640
6641 cmdiocb->context2 = NULL;
6642 lpfc_set_disctmo(vport);
6643
6644 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6645
6646 lpfc_rscn_recovery_check(vport);
6647 return lpfc_els_handle_rscn(vport);
6648 }
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666 int
6667 lpfc_els_handle_rscn(struct lpfc_vport *vport)
6668 {
6669 struct lpfc_nodelist *ndlp;
6670 struct lpfc_hba *phba = vport->phba;
6671
6672
6673 if (vport->load_flag & FC_UNLOADING) {
6674 lpfc_els_flush_rscn(vport);
6675 return 0;
6676 }
6677
6678
6679 lpfc_set_disctmo(vport);
6680
6681
6682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6683 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6684 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6685 vport->port_state);
6686
6687
6688 vport->fc_ns_retry = 0;
6689 vport->num_disc_nodes = 0;
6690
6691 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6692 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6693 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6694
6695
6696
6697
6698
6699 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6700 if (lpfc_issue_gidft(vport) > 0)
6701 return 1;
6702 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6703 if (lpfc_issue_gidpt(vport) > 0)
6704 return 1;
6705 } else {
6706 return 1;
6707 }
6708 } else {
6709
6710 if (ndlp) {
6711 ndlp = lpfc_enable_node(vport, ndlp,
6712 NLP_STE_PLOGI_ISSUE);
6713 if (!ndlp) {
6714 lpfc_els_flush_rscn(vport);
6715 return 0;
6716 }
6717 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6718 } else {
6719 ndlp = lpfc_nlp_init(vport, NameServer_DID);
6720 if (!ndlp) {
6721 lpfc_els_flush_rscn(vport);
6722 return 0;
6723 }
6724 ndlp->nlp_prev_state = ndlp->nlp_state;
6725 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6726 }
6727 ndlp->nlp_type |= NLP_FABRIC;
6728 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6729
6730
6731
6732 return 1;
6733 }
6734
6735 lpfc_els_flush_rscn(vport);
6736 return 0;
6737 }
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764 static int
6765 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6766 struct lpfc_nodelist *ndlp)
6767 {
6768 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6769 struct lpfc_hba *phba = vport->phba;
6770 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6771 uint32_t *lp = (uint32_t *) pcmd->virt;
6772 IOCB_t *icmd = &cmdiocb->iocb;
6773 struct serv_parm *sp;
6774 LPFC_MBOXQ_t *mbox;
6775 uint32_t cmd, did;
6776 int rc;
6777 uint32_t fc_flag = 0;
6778 uint32_t port_state = 0;
6779
6780 cmd = *lp++;
6781 sp = (struct serv_parm *) lp;
6782
6783
6784
6785 lpfc_set_disctmo(vport);
6786
6787 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6788
6789 did = icmd->un.elsreq64.remoteID;
6790
6791
6792
6793 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6794 "0113 An FLOGI ELS command x%x was "
6795 "received from DID x%x in Loop Mode\n",
6796 cmd, did);
6797 return 1;
6798 }
6799
6800 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
6801
6802
6803
6804
6805
6806
6807 rc = memcmp(&vport->fc_portname, &sp->portName,
6808 sizeof(struct lpfc_name));
6809
6810 if (!rc) {
6811 if (phba->sli_rev < LPFC_SLI_REV4) {
6812 mbox = mempool_alloc(phba->mbox_mem_pool,
6813 GFP_KERNEL);
6814 if (!mbox)
6815 return 1;
6816 lpfc_linkdown(phba);
6817 lpfc_init_link(phba, mbox,
6818 phba->cfg_topology,
6819 phba->cfg_link_speed);
6820 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6821 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6822 mbox->vport = vport;
6823 rc = lpfc_sli_issue_mbox(phba, mbox,
6824 MBX_NOWAIT);
6825 lpfc_set_loopback_flag(phba);
6826 if (rc == MBX_NOT_FINISHED)
6827 mempool_free(mbox, phba->mbox_mem_pool);
6828 return 1;
6829 }
6830
6831
6832
6833
6834 lpfc_els_abort_flogi(phba);
6835 return 0;
6836
6837 } else if (rc > 0) {
6838 spin_lock_irq(shost->host_lock);
6839 vport->fc_flag |= FC_PT2PT_PLOGI;
6840 spin_unlock_irq(shost->host_lock);
6841
6842
6843
6844
6845
6846
6847 vport->fc_myDID = PT2PT_LocalID;
6848 } else {
6849 vport->fc_myDID = PT2PT_RemoteID;
6850 }
6851
6852
6853
6854
6855
6856 spin_lock_irq(shost->host_lock);
6857 fc_flag = vport->fc_flag;
6858 port_state = vport->port_state;
6859 vport->fc_flag |= FC_PT2PT;
6860 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6861
6862
6863
6864
6865 vport->rcv_flogi_cnt++;
6866 spin_unlock_irq(shost->host_lock);
6867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6868 "3311 Rcv Flogi PS x%x new PS x%x "
6869 "fc_flag x%x new fc_flag x%x\n",
6870 port_state, vport->port_state,
6871 fc_flag, vport->fc_flag);
6872
6873
6874
6875
6876
6877
6878 did = vport->fc_myDID;
6879 vport->fc_myDID = Fabric_DID;
6880
6881 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
6882
6883
6884 if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
6885 phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
6886 phba->defer_flogi_acc_ox_id =
6887 cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6888
6889 vport->fc_myDID = did;
6890
6891 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6892 "3344 Deferring FLOGI ACC: rx_id: x%x,"
6893 " ox_id: x%x, hba_flag x%x\n",
6894 phba->defer_flogi_acc_rx_id,
6895 phba->defer_flogi_acc_ox_id, phba->hba_flag);
6896
6897 phba->defer_flogi_acc_flag = true;
6898
6899 return 0;
6900 }
6901
6902
6903 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
6904
6905
6906 vport->fc_myDID = did;
6907
6908 return 0;
6909 }
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927 static int
6928 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6929 struct lpfc_nodelist *ndlp)
6930 {
6931 struct lpfc_dmabuf *pcmd;
6932 uint32_t *lp;
6933 RNID *rn;
6934 struct ls_rjt stat;
6935
6936 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6937 lp = (uint32_t *) pcmd->virt;
6938
6939 lp++;
6940 rn = (RNID *) lp;
6941
6942
6943
6944 switch (rn->Format) {
6945 case 0:
6946 case RNID_TOPOLOGY_DISC:
6947
6948 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
6949 break;
6950 default:
6951
6952 stat.un.b.lsRjtRsvd0 = 0;
6953 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6954 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6955 stat.un.b.vendorUnique = 0;
6956 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6957 NULL);
6958 }
6959 return 0;
6960 }
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971 static int
6972 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6973 struct lpfc_nodelist *ndlp)
6974 {
6975 uint8_t *pcmd;
6976
6977 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6978
6979
6980 pcmd += sizeof(uint32_t);
6981
6982 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6983 return 0;
6984 }
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999 static int
7000 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7001 struct lpfc_nodelist *ndlp)
7002 {
7003 struct ls_rjt stat;
7004
7005
7006 stat.un.b.lsRjtRsvd0 = 0;
7007 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7008 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7009 stat.un.b.vendorUnique = 0;
7010 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7011 return 0;
7012 }
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030 static void
7031 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7032 struct lpfc_nodelist *ndlp)
7033 {
7034 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7035 if (vport->phba->sli_rev == LPFC_SLI_REV4)
7036 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7037 }
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058 static void
7059 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7060 {
7061 MAILBOX_t *mb;
7062 IOCB_t *icmd;
7063 struct RLS_RSP *rls_rsp;
7064 uint8_t *pcmd;
7065 struct lpfc_iocbq *elsiocb;
7066 struct lpfc_nodelist *ndlp;
7067 uint16_t oxid;
7068 uint16_t rxid;
7069 uint32_t cmdsize;
7070
7071 mb = &pmb->u.mb;
7072
7073 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7074 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7075 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7076 pmb->ctx_buf = NULL;
7077 pmb->ctx_ndlp = NULL;
7078
7079 if (mb->mbxStatus) {
7080 mempool_free(pmb, phba->mbox_mem_pool);
7081 return;
7082 }
7083
7084 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7085 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7086 lpfc_max_els_tries, ndlp,
7087 ndlp->nlp_DID, ELS_CMD_ACC);
7088
7089
7090 lpfc_nlp_put(ndlp);
7091
7092 if (!elsiocb) {
7093 mempool_free(pmb, phba->mbox_mem_pool);
7094 return;
7095 }
7096
7097 icmd = &elsiocb->iocb;
7098 icmd->ulpContext = rxid;
7099 icmd->unsli3.rcvsli3.ox_id = oxid;
7100
7101 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7102 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7103 pcmd += sizeof(uint32_t);
7104 rls_rsp = (struct RLS_RSP *)pcmd;
7105
7106 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7107 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7108 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7109 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7110 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7111 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7112 mempool_free(pmb, phba->mbox_mem_pool);
7113
7114 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7115 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7116 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7117 elsiocb->iotag, elsiocb->iocb.ulpContext,
7118 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7119 ndlp->nlp_rpi);
7120 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7121 phba->fc_stat.elsXmitACC++;
7122 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7123 lpfc_els_free_iocb(phba, elsiocb);
7124 }
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145 static void
7146 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7147 {
7148 MAILBOX_t *mb;
7149 IOCB_t *icmd;
7150 RPS_RSP *rps_rsp;
7151 uint8_t *pcmd;
7152 struct lpfc_iocbq *elsiocb;
7153 struct lpfc_nodelist *ndlp;
7154 uint16_t status;
7155 uint16_t oxid;
7156 uint16_t rxid;
7157 uint32_t cmdsize;
7158
7159 mb = &pmb->u.mb;
7160
7161 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7162 rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7163 oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7164 pmb->ctx_ndlp = NULL;
7165 pmb->ctx_buf = NULL;
7166
7167 if (mb->mbxStatus) {
7168 mempool_free(pmb, phba->mbox_mem_pool);
7169 return;
7170 }
7171
7172 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
7173 mempool_free(pmb, phba->mbox_mem_pool);
7174 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7175 lpfc_max_els_tries, ndlp,
7176 ndlp->nlp_DID, ELS_CMD_ACC);
7177
7178
7179 lpfc_nlp_put(ndlp);
7180
7181 if (!elsiocb)
7182 return;
7183
7184 icmd = &elsiocb->iocb;
7185 icmd->ulpContext = rxid;
7186 icmd->unsli3.rcvsli3.ox_id = oxid;
7187
7188 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7189 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7190 pcmd += sizeof(uint32_t);
7191 rps_rsp = (RPS_RSP *)pcmd;
7192
7193 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
7194 status = 0x10;
7195 else
7196 status = 0x8;
7197 if (phba->pport->fc_flag & FC_FABRIC)
7198 status |= 0x4;
7199
7200 rps_rsp->rsvd1 = 0;
7201 rps_rsp->portStatus = cpu_to_be16(status);
7202 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7203 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7204 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7205 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7206 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7207 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7208
7209 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7210 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
7211 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7212 elsiocb->iotag, elsiocb->iocb.ulpContext,
7213 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7214 ndlp->nlp_rpi);
7215 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7216 phba->fc_stat.elsXmitACC++;
7217 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7218 lpfc_els_free_iocb(phba, elsiocb);
7219 return;
7220 }
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240 static int
7241 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7242 struct lpfc_nodelist *ndlp)
7243 {
7244 struct lpfc_hba *phba = vport->phba;
7245 LPFC_MBOXQ_t *mbox;
7246 struct ls_rjt stat;
7247
7248 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7249 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7250
7251 goto reject_out;
7252
7253 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7254 if (mbox) {
7255 lpfc_read_lnk_stat(phba, mbox);
7256 mbox->ctx_buf = (void *)((unsigned long)
7257 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7258 cmdiocb->iocb.ulpContext));
7259 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7260 mbox->vport = vport;
7261 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7262 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7263 != MBX_NOT_FINISHED)
7264
7265 return 0;
7266
7267
7268
7269 lpfc_nlp_put(ndlp);
7270 mempool_free(mbox, phba->mbox_mem_pool);
7271 }
7272 reject_out:
7273
7274 stat.un.b.lsRjtRsvd0 = 0;
7275 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7276 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7277 stat.un.b.vendorUnique = 0;
7278 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7279 return 0;
7280 }
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303 static int
7304 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7305 struct lpfc_nodelist *ndlp)
7306 {
7307 struct lpfc_hba *phba = vport->phba;
7308 struct ls_rjt stat;
7309 struct RTV_RSP *rtv_rsp;
7310 uint8_t *pcmd;
7311 struct lpfc_iocbq *elsiocb;
7312 uint32_t cmdsize;
7313
7314
7315 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7316 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7317
7318 goto reject_out;
7319
7320 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7321 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7322 lpfc_max_els_tries, ndlp,
7323 ndlp->nlp_DID, ELS_CMD_ACC);
7324
7325 if (!elsiocb)
7326 return 1;
7327
7328 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7329 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7330 pcmd += sizeof(uint32_t);
7331
7332
7333 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
7334 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7335
7336 rtv_rsp = (struct RTV_RSP *)pcmd;
7337
7338
7339 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000);
7340 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7341 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7342 bf_set(qtov_rttov, rtv_rsp, 0);
7343 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7344
7345
7346 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7347 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7348 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7349 "Data: x%x x%x x%x\n",
7350 elsiocb->iotag, elsiocb->iocb.ulpContext,
7351 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7352 ndlp->nlp_rpi,
7353 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7354 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7355 phba->fc_stat.elsXmitACC++;
7356 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7357 lpfc_els_free_iocb(phba, elsiocb);
7358 return 0;
7359
7360 reject_out:
7361
7362 stat.un.b.lsRjtRsvd0 = 0;
7363 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7364 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7365 stat.un.b.vendorUnique = 0;
7366 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7367 return 0;
7368 }
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387 static int
7388 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7389 struct lpfc_nodelist *ndlp)
7390 {
7391 struct lpfc_hba *phba = vport->phba;
7392 uint32_t *lp;
7393 uint8_t flag;
7394 LPFC_MBOXQ_t *mbox;
7395 struct lpfc_dmabuf *pcmd;
7396 RPS *rps;
7397 struct ls_rjt stat;
7398
7399 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7400 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7401
7402 goto reject_out;
7403
7404 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7405 lp = (uint32_t *) pcmd->virt;
7406 flag = (be32_to_cpu(*lp++) & 0xf);
7407 rps = (RPS *) lp;
7408
7409 if ((flag == 0) ||
7410 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
7411 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
7412 sizeof(struct lpfc_name)) == 0))) {
7413
7414 printk("Fix me....\n");
7415 dump_stack();
7416 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7417 if (mbox) {
7418 lpfc_read_lnk_stat(phba, mbox);
7419 mbox->ctx_buf = (void *)((unsigned long)
7420 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7421 cmdiocb->iocb.ulpContext));
7422 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7423 mbox->vport = vport;
7424 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
7425 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7426 != MBX_NOT_FINISHED)
7427
7428 return 0;
7429
7430
7431
7432 lpfc_nlp_put(ndlp);
7433 mempool_free(mbox, phba->mbox_mem_pool);
7434 }
7435 }
7436
7437 reject_out:
7438
7439 stat.un.b.lsRjtRsvd0 = 0;
7440 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7441 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7442 stat.un.b.vendorUnique = 0;
7443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7444 return 0;
7445 }
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460 static int
7461 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7462 uint32_t did, struct lpfc_node_rrq *rrq)
7463 {
7464 struct lpfc_hba *phba = vport->phba;
7465 struct RRQ *els_rrq;
7466 struct lpfc_iocbq *elsiocb;
7467 uint8_t *pcmd;
7468 uint16_t cmdsize;
7469 int ret;
7470
7471
7472 if (ndlp != rrq->ndlp)
7473 ndlp = rrq->ndlp;
7474 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7475 return 1;
7476
7477
7478 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7479 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7480 ELS_CMD_RRQ);
7481 if (!elsiocb)
7482 return 1;
7483
7484 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7485
7486
7487 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7488 pcmd += sizeof(uint32_t);
7489 els_rrq = (struct RRQ *) pcmd;
7490
7491 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7492 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7493 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7494 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7495 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7496
7497
7498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7499 "Issue RRQ: did:x%x",
7500 did, rrq->xritag, rrq->rxid);
7501 elsiocb->context_un.rrq = rrq;
7502 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7503 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7504
7505 if (ret == IOCB_ERROR) {
7506 lpfc_els_free_iocb(phba, elsiocb);
7507 return 1;
7508 }
7509 return 0;
7510 }
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524 int
7525 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7526 {
7527 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7528 rrq->nlp_DID);
7529 if (!ndlp)
7530 return 1;
7531
7532 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7533 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7534 rrq->nlp_DID, rrq);
7535 else
7536 return 1;
7537 }
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558 static int
7559 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7560 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7561 {
7562 struct lpfc_hba *phba = vport->phba;
7563 IOCB_t *icmd, *oldcmd;
7564 RPL_RSP rpl_rsp;
7565 struct lpfc_iocbq *elsiocb;
7566 uint8_t *pcmd;
7567
7568 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7569 ndlp->nlp_DID, ELS_CMD_ACC);
7570
7571 if (!elsiocb)
7572 return 1;
7573
7574 icmd = &elsiocb->iocb;
7575 oldcmd = &oldiocb->iocb;
7576 icmd->ulpContext = oldcmd->ulpContext;
7577 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7578
7579 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7580 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7581 pcmd += sizeof(uint16_t);
7582 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7583 pcmd += sizeof(uint16_t);
7584
7585
7586 rpl_rsp.listLen = be32_to_cpu(1);
7587 rpl_rsp.index = 0;
7588 rpl_rsp.port_num_blk.portNum = 0;
7589 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7590 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7591 sizeof(struct lpfc_name));
7592 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7593
7594 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7595 "0120 Xmit ELS RPL ACC response tag x%x "
7596 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7597 "rpi x%x\n",
7598 elsiocb->iotag, elsiocb->iocb.ulpContext,
7599 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7600 ndlp->nlp_rpi);
7601 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7602 phba->fc_stat.elsXmitACC++;
7603 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7604 IOCB_ERROR) {
7605 lpfc_els_free_iocb(phba, elsiocb);
7606 return 1;
7607 }
7608 return 0;
7609 }
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627 static int
7628 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7629 struct lpfc_nodelist *ndlp)
7630 {
7631 struct lpfc_dmabuf *pcmd;
7632 uint32_t *lp;
7633 uint32_t maxsize;
7634 uint16_t cmdsize;
7635 RPL *rpl;
7636 struct ls_rjt stat;
7637
7638 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7639 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7640
7641 stat.un.b.lsRjtRsvd0 = 0;
7642 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7643 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7644 stat.un.b.vendorUnique = 0;
7645 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7646 NULL);
7647
7648 return 0;
7649 }
7650
7651 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7652 lp = (uint32_t *) pcmd->virt;
7653 rpl = (RPL *) (lp + 1);
7654 maxsize = be32_to_cpu(rpl->maxsize);
7655
7656
7657 if ((rpl->index == 0) &&
7658 ((maxsize == 0) ||
7659 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7660 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7661 } else {
7662 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7663 }
7664 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7665
7666 return 0;
7667 }
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693 static int
7694 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7695 struct lpfc_nodelist *ndlp)
7696 {
7697 struct lpfc_dmabuf *pcmd;
7698 uint32_t *lp;
7699 IOCB_t *icmd;
7700 FARP *fp;
7701 uint32_t cnt, did;
7702
7703 icmd = &cmdiocb->iocb;
7704 did = icmd->un.elsreq64.remoteID;
7705 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7706 lp = (uint32_t *) pcmd->virt;
7707
7708 lp++;
7709 fp = (FARP *) lp;
7710
7711 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7712 "0601 FARP-REQ received from DID x%x\n", did);
7713
7714 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7715 return 0;
7716 }
7717
7718 cnt = 0;
7719
7720 if (fp->Mflags & FARP_MATCH_PORT) {
7721 if (memcmp(&fp->RportName, &vport->fc_portname,
7722 sizeof(struct lpfc_name)) == 0)
7723 cnt = 1;
7724 }
7725
7726
7727 if (fp->Mflags & FARP_MATCH_NODE) {
7728 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7729 sizeof(struct lpfc_name)) == 0)
7730 cnt = 1;
7731 }
7732
7733 if (cnt) {
7734 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7735 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7736
7737 if (fp->Rflags & FARP_REQUEST_PLOGI) {
7738 ndlp->nlp_prev_state = ndlp->nlp_state;
7739 lpfc_nlp_set_state(vport, ndlp,
7740 NLP_STE_PLOGI_ISSUE);
7741 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7742 }
7743
7744
7745 if (fp->Rflags & FARP_REQUEST_FARPR)
7746 lpfc_issue_els_farpr(vport, did, 0);
7747 }
7748 }
7749 return 0;
7750 }
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766 static int
7767 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7768 struct lpfc_nodelist *ndlp)
7769 {
7770 struct lpfc_dmabuf *pcmd;
7771 uint32_t *lp;
7772 IOCB_t *icmd;
7773 uint32_t did;
7774
7775 icmd = &cmdiocb->iocb;
7776 did = icmd->un.elsreq64.remoteID;
7777 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7778 lp = (uint32_t *) pcmd->virt;
7779
7780 lp++;
7781
7782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7783 "0600 FARP-RSP received from DID x%x\n", did);
7784
7785 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7786
7787 return 0;
7788 }
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809 static int
7810 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7811 struct lpfc_nodelist *fan_ndlp)
7812 {
7813 struct lpfc_hba *phba = vport->phba;
7814 uint32_t *lp;
7815 FAN *fp;
7816
7817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7818 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7819 fp = (FAN *) ++lp;
7820
7821 if ((vport == phba->pport) &&
7822 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7823 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7824 sizeof(struct lpfc_name))) ||
7825 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7826 sizeof(struct lpfc_name)))) {
7827
7828 lpfc_issue_init_vfi(vport);
7829 } else {
7830
7831 vport->fc_myDID = vport->fc_prevDID;
7832 if (phba->sli_rev < LPFC_SLI_REV4)
7833 lpfc_issue_fabric_reglogin(vport);
7834 else {
7835 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7836 "3138 Need register VFI: (x%x/%x)\n",
7837 vport->fc_prevDID, vport->fc_myDID);
7838 lpfc_issue_reg_vfi(vport);
7839 }
7840 }
7841 }
7842 return 0;
7843 }
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855 void
7856 lpfc_els_timeout(struct timer_list *t)
7857 {
7858 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7859 struct lpfc_hba *phba = vport->phba;
7860 uint32_t tmo_posted;
7861 unsigned long iflag;
7862
7863 spin_lock_irqsave(&vport->work_port_lock, iflag);
7864 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7865 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7866 vport->work_port_events |= WORKER_ELS_TMO;
7867 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7868
7869 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7870 lpfc_worker_wake_up(phba);
7871 return;
7872 }
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884 void
7885 lpfc_els_timeout_handler(struct lpfc_vport *vport)
7886 {
7887 struct lpfc_hba *phba = vport->phba;
7888 struct lpfc_sli_ring *pring;
7889 struct lpfc_iocbq *tmp_iocb, *piocb;
7890 IOCB_t *cmd = NULL;
7891 struct lpfc_dmabuf *pcmd;
7892 uint32_t els_command = 0;
7893 uint32_t timeout;
7894 uint32_t remote_ID = 0xffffffff;
7895 LIST_HEAD(abort_list);
7896
7897
7898 timeout = (uint32_t)(phba->fc_ratov << 1);
7899
7900 pring = lpfc_phba_elsring(phba);
7901 if (unlikely(!pring))
7902 return;
7903
7904 if ((phba->pport->load_flag & FC_UNLOADING))
7905 return;
7906 spin_lock_irq(&phba->hbalock);
7907 if (phba->sli_rev == LPFC_SLI_REV4)
7908 spin_lock(&pring->ring_lock);
7909
7910 if ((phba->pport->load_flag & FC_UNLOADING)) {
7911 if (phba->sli_rev == LPFC_SLI_REV4)
7912 spin_unlock(&pring->ring_lock);
7913 spin_unlock_irq(&phba->hbalock);
7914 return;
7915 }
7916
7917 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7918 cmd = &piocb->iocb;
7919
7920 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7921 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7922 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7923 continue;
7924
7925 if (piocb->vport != vport)
7926 continue;
7927
7928 pcmd = (struct lpfc_dmabuf *) piocb->context2;
7929 if (pcmd)
7930 els_command = *(uint32_t *) (pcmd->virt);
7931
7932 if (els_command == ELS_CMD_FARP ||
7933 els_command == ELS_CMD_FARPR ||
7934 els_command == ELS_CMD_FDISC)
7935 continue;
7936
7937 if (piocb->drvrTimeout > 0) {
7938 if (piocb->drvrTimeout >= timeout)
7939 piocb->drvrTimeout -= timeout;
7940 else
7941 piocb->drvrTimeout = 0;
7942 continue;
7943 }
7944
7945 remote_ID = 0xffffffff;
7946 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
7947 remote_ID = cmd->un.elsreq64.remoteID;
7948 else {
7949 struct lpfc_nodelist *ndlp;
7950 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
7951 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
7952 remote_ID = ndlp->nlp_DID;
7953 }
7954 list_add_tail(&piocb->dlist, &abort_list);
7955 }
7956 if (phba->sli_rev == LPFC_SLI_REV4)
7957 spin_unlock(&pring->ring_lock);
7958 spin_unlock_irq(&phba->hbalock);
7959
7960 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7961 cmd = &piocb->iocb;
7962 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7963 "0127 ELS timeout Data: x%x x%x x%x "
7964 "x%x\n", els_command,
7965 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7966 spin_lock_irq(&phba->hbalock);
7967 list_del_init(&piocb->dlist);
7968 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7969 spin_unlock_irq(&phba->hbalock);
7970 }
7971
7972 if (!list_empty(&pring->txcmplq))
7973 if (!(phba->pport->load_flag & FC_UNLOADING))
7974 mod_timer(&vport->els_tmofunc,
7975 jiffies + msecs_to_jiffies(1000 * timeout));
7976 }
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998 void
7999 lpfc_els_flush_cmd(struct lpfc_vport *vport)
8000 {
8001 LIST_HEAD(abort_list);
8002 struct lpfc_hba *phba = vport->phba;
8003 struct lpfc_sli_ring *pring;
8004 struct lpfc_iocbq *tmp_iocb, *piocb;
8005 IOCB_t *cmd = NULL;
8006 unsigned long iflags = 0;
8007
8008 lpfc_fabric_abort_vport(vport);
8009
8010
8011
8012
8013
8014
8015
8016 spin_lock_irqsave(&phba->hbalock, iflags);
8017 pring = lpfc_phba_elsring(phba);
8018
8019
8020 if (unlikely(!pring)) {
8021 spin_unlock_irqrestore(&phba->hbalock, iflags);
8022 return;
8023 }
8024
8025 if (phba->sli_rev == LPFC_SLI_REV4)
8026 spin_lock(&pring->ring_lock);
8027
8028
8029 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8030 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8031 continue;
8032
8033 if (piocb->vport != vport)
8034 continue;
8035
8036 if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8037 continue;
8038
8039
8040
8041
8042 cmd = &piocb->iocb;
8043 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8044 list_add_tail(&piocb->dlist, &abort_list);
8045
8046
8047
8048
8049
8050
8051
8052
8053 if (phba->link_state == LPFC_LINK_DOWN)
8054 piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8055 }
8056 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8057 list_add_tail(&piocb->dlist, &abort_list);
8058 }
8059
8060 if (phba->sli_rev == LPFC_SLI_REV4)
8061 spin_unlock(&pring->ring_lock);
8062 spin_unlock_irqrestore(&phba->hbalock, iflags);
8063
8064
8065 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8066 spin_lock_irqsave(&phba->hbalock, iflags);
8067 list_del_init(&piocb->dlist);
8068 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8069 spin_unlock_irqrestore(&phba->hbalock, iflags);
8070 }
8071 if (!list_empty(&abort_list))
8072 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8073 "3387 abort list for txq not empty\n");
8074 INIT_LIST_HEAD(&abort_list);
8075
8076 spin_lock_irqsave(&phba->hbalock, iflags);
8077 if (phba->sli_rev == LPFC_SLI_REV4)
8078 spin_lock(&pring->ring_lock);
8079
8080
8081
8082
8083 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8084 cmd = &piocb->iocb;
8085
8086 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8087 continue;
8088 }
8089
8090
8091 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8092 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8093 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8094 cmd->ulpCommand == CMD_ABORT_XRI_CN)
8095 continue;
8096
8097 if (piocb->vport != vport)
8098 continue;
8099
8100 list_del_init(&piocb->list);
8101 list_add_tail(&piocb->list, &abort_list);
8102 }
8103
8104
8105 if (vport == phba->pport) {
8106 list_for_each_entry_safe(piocb, tmp_iocb,
8107 &phba->fabric_iocb_list, list) {
8108 cmd = &piocb->iocb;
8109 list_del_init(&piocb->list);
8110 list_add_tail(&piocb->list, &abort_list);
8111 }
8112 }
8113
8114 if (phba->sli_rev == LPFC_SLI_REV4)
8115 spin_unlock(&pring->ring_lock);
8116 spin_unlock_irqrestore(&phba->hbalock, iflags);
8117
8118
8119 lpfc_sli_cancel_iocbs(phba, &abort_list,
8120 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8121
8122 return;
8123 }
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142 void
8143 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8144 {
8145 struct lpfc_vport *vport;
8146
8147 spin_lock_irq(&phba->port_list_lock);
8148 list_for_each_entry(vport, &phba->port_list, listentry)
8149 lpfc_els_flush_cmd(vport);
8150 spin_unlock_irq(&phba->port_list_lock);
8151
8152 return;
8153 }
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164 void
8165 lpfc_send_els_failure_event(struct lpfc_hba *phba,
8166 struct lpfc_iocbq *cmdiocbp,
8167 struct lpfc_iocbq *rspiocbp)
8168 {
8169 struct lpfc_vport *vport = cmdiocbp->vport;
8170 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8171 struct lpfc_lsrjt_event lsrjt_event;
8172 struct lpfc_fabric_event_header fabric_event;
8173 struct ls_rjt stat;
8174 struct lpfc_nodelist *ndlp;
8175 uint32_t *pcmd;
8176
8177 ndlp = cmdiocbp->context1;
8178 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8179 return;
8180
8181 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8182 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8183 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8184 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8185 sizeof(struct lpfc_name));
8186 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8187 sizeof(struct lpfc_name));
8188 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8189 cmdiocbp->context2)->virt);
8190 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8191 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8192 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8193 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8194 fc_host_post_vendor_event(shost,
8195 fc_get_event_number(),
8196 sizeof(lsrjt_event),
8197 (char *)&lsrjt_event,
8198 LPFC_NL_VENDOR_ID);
8199 return;
8200 }
8201 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8202 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8203 fabric_event.event_type = FC_REG_FABRIC_EVENT;
8204 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8205 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8206 else
8207 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8208 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8209 sizeof(struct lpfc_name));
8210 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8211 sizeof(struct lpfc_name));
8212 fc_host_post_vendor_event(shost,
8213 fc_get_event_number(),
8214 sizeof(fabric_event),
8215 (char *)&fabric_event,
8216 LPFC_NL_VENDOR_ID);
8217 return;
8218 }
8219
8220 }
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231 static void
8232 lpfc_send_els_event(struct lpfc_vport *vport,
8233 struct lpfc_nodelist *ndlp,
8234 uint32_t *payload)
8235 {
8236 struct lpfc_els_event_header *els_data = NULL;
8237 struct lpfc_logo_event *logo_data = NULL;
8238 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8239
8240 if (*payload == ELS_CMD_LOGO) {
8241 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8242 if (!logo_data) {
8243 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8244 "0148 Failed to allocate memory "
8245 "for LOGO event\n");
8246 return;
8247 }
8248 els_data = &logo_data->header;
8249 } else {
8250 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8251 GFP_KERNEL);
8252 if (!els_data) {
8253 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8254 "0149 Failed to allocate memory "
8255 "for ELS event\n");
8256 return;
8257 }
8258 }
8259 els_data->event_type = FC_REG_ELS_EVENT;
8260 switch (*payload) {
8261 case ELS_CMD_PLOGI:
8262 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8263 break;
8264 case ELS_CMD_PRLO:
8265 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8266 break;
8267 case ELS_CMD_ADISC:
8268 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8269 break;
8270 case ELS_CMD_LOGO:
8271 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8272
8273 memcpy(logo_data->logo_wwpn, &payload[2],
8274 sizeof(struct lpfc_name));
8275 break;
8276 default:
8277 kfree(els_data);
8278 return;
8279 }
8280 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8281 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8282 if (*payload == ELS_CMD_LOGO) {
8283 fc_host_post_vendor_event(shost,
8284 fc_get_event_number(),
8285 sizeof(struct lpfc_logo_event),
8286 (char *)logo_data,
8287 LPFC_NL_VENDOR_ID);
8288 kfree(logo_data);
8289 } else {
8290 fc_host_post_vendor_event(shost,
8291 fc_get_event_number(),
8292 sizeof(struct lpfc_els_event_header),
8293 (char *)els_data,
8294 LPFC_NL_VENDOR_ID);
8295 kfree(els_data);
8296 }
8297
8298 return;
8299 }
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316 static void
8317 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8318 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8319 {
8320 struct Scsi_Host *shost;
8321 struct lpfc_nodelist *ndlp;
8322 struct ls_rjt stat;
8323 uint32_t *payload;
8324 uint32_t cmd, did, newnode;
8325 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8326 IOCB_t *icmd = &elsiocb->iocb;
8327 LPFC_MBOXQ_t *mbox;
8328
8329 if (!vport || !(elsiocb->context2))
8330 goto dropit;
8331
8332 newnode = 0;
8333 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8334 cmd = *payload;
8335 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8336 lpfc_post_buffer(phba, pring, 1);
8337
8338 did = icmd->un.rcvels.remoteID;
8339 if (icmd->ulpStatus) {
8340 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8341 "RCV Unsol ELS: status:x%x/x%x did:x%x",
8342 icmd->ulpStatus, icmd->un.ulpWord[4], did);
8343 goto dropit;
8344 }
8345
8346
8347 if (lpfc_els_chk_latt(vport))
8348 goto dropit;
8349
8350
8351 if (vport->load_flag & FC_UNLOADING)
8352 goto dropit;
8353
8354
8355 if ((vport->fc_flag & FC_DISC_DELAYED) &&
8356 (cmd != ELS_CMD_PLOGI))
8357 goto dropit;
8358
8359 ndlp = lpfc_findnode_did(vport, did);
8360 if (!ndlp) {
8361
8362 ndlp = lpfc_nlp_init(vport, did);
8363 if (!ndlp)
8364 goto dropit;
8365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8366 newnode = 1;
8367 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8368 ndlp->nlp_type |= NLP_FABRIC;
8369 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8370 ndlp = lpfc_enable_node(vport, ndlp,
8371 NLP_STE_UNUSED_NODE);
8372 if (!ndlp)
8373 goto dropit;
8374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8375 newnode = 1;
8376 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8377 ndlp->nlp_type |= NLP_FABRIC;
8378 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8379
8380 ndlp = lpfc_nlp_get(ndlp);
8381 if (!ndlp)
8382 goto dropit;
8383 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8384 newnode = 1;
8385 }
8386
8387 phba->fc_stat.elsRcvFrame++;
8388
8389
8390
8391
8392
8393 shost = lpfc_shost_from_vport(vport);
8394 spin_lock_irq(shost->host_lock);
8395 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8396 spin_unlock_irq(shost->host_lock);
8397 goto dropit;
8398 }
8399 spin_unlock_irq(shost->host_lock);
8400
8401 elsiocb->context1 = lpfc_nlp_get(ndlp);
8402 elsiocb->vport = vport;
8403
8404 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8405 cmd &= ELS_CMD_MASK;
8406 }
8407
8408 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8409 "0112 ELS command x%x received from NPORT x%x "
8410 "Data: x%x x%x x%x x%x\n",
8411 cmd, did, vport->port_state, vport->fc_flag,
8412 vport->fc_myDID, vport->fc_prevDID);
8413
8414
8415 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8416 (cmd != ELS_CMD_FLOGI) &&
8417 !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8418 rjt_err = LSRJT_LOGICAL_BSY;
8419 rjt_exp = LSEXP_NOTHING_MORE;
8420 goto lsrjt;
8421 }
8422
8423 switch (cmd) {
8424 case ELS_CMD_PLOGI:
8425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8426 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8427 did, vport->port_state, ndlp->nlp_flag);
8428
8429 phba->fc_stat.elsRcvPLOGI++;
8430 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8431 if (phba->sli_rev == LPFC_SLI_REV4 &&
8432 (phba->pport->fc_flag & FC_PT2PT)) {
8433 vport->fc_prevDID = vport->fc_myDID;
8434
8435
8436
8437
8438 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8439 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8440 "3312 Remote port assigned DID x%x "
8441 "%x\n", vport->fc_myDID,
8442 vport->fc_prevDID);
8443 }
8444
8445 lpfc_send_els_event(vport, ndlp, payload);
8446
8447
8448 if (vport->fc_flag & FC_DISC_DELAYED) {
8449 rjt_err = LSRJT_UNABLE_TPC;
8450 rjt_exp = LSEXP_NOTHING_MORE;
8451 break;
8452 }
8453
8454 if (vport->port_state < LPFC_DISC_AUTH) {
8455 if (!(phba->pport->fc_flag & FC_PT2PT) ||
8456 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8457 rjt_err = LSRJT_UNABLE_TPC;
8458 rjt_exp = LSEXP_NOTHING_MORE;
8459 break;
8460 }
8461 }
8462
8463 spin_lock_irq(shost->host_lock);
8464 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8465 spin_unlock_irq(shost->host_lock);
8466
8467 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8468 NLP_EVT_RCV_PLOGI);
8469
8470 break;
8471 case ELS_CMD_FLOGI:
8472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8473 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8474 did, vport->port_state, ndlp->nlp_flag);
8475
8476 phba->fc_stat.elsRcvFLOGI++;
8477
8478
8479
8480
8481 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8482 vport->fc_flag & FC_PT2PT &&
8483 vport->rcv_flogi_cnt >= 1) {
8484 rjt_err = LSRJT_LOGICAL_BSY;
8485 rjt_exp = LSEXP_NOTHING_MORE;
8486 init_link++;
8487 goto lsrjt;
8488 }
8489
8490 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8491 if (newnode)
8492 lpfc_nlp_put(ndlp);
8493 break;
8494 case ELS_CMD_LOGO:
8495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8496 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8497 did, vport->port_state, ndlp->nlp_flag);
8498
8499 phba->fc_stat.elsRcvLOGO++;
8500 lpfc_send_els_event(vport, ndlp, payload);
8501 if (vport->port_state < LPFC_DISC_AUTH) {
8502 rjt_err = LSRJT_UNABLE_TPC;
8503 rjt_exp = LSEXP_NOTHING_MORE;
8504 break;
8505 }
8506 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8507 break;
8508 case ELS_CMD_PRLO:
8509 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8510 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8511 did, vport->port_state, ndlp->nlp_flag);
8512
8513 phba->fc_stat.elsRcvPRLO++;
8514 lpfc_send_els_event(vport, ndlp, payload);
8515 if (vport->port_state < LPFC_DISC_AUTH) {
8516 rjt_err = LSRJT_UNABLE_TPC;
8517 rjt_exp = LSEXP_NOTHING_MORE;
8518 break;
8519 }
8520 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8521 break;
8522 case ELS_CMD_LCB:
8523 phba->fc_stat.elsRcvLCB++;
8524 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8525 break;
8526 case ELS_CMD_RDP:
8527 phba->fc_stat.elsRcvRDP++;
8528 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8529 break;
8530 case ELS_CMD_RSCN:
8531 phba->fc_stat.elsRcvRSCN++;
8532 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8533 if (newnode)
8534 lpfc_nlp_put(ndlp);
8535 break;
8536 case ELS_CMD_ADISC:
8537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8538 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8539 did, vport->port_state, ndlp->nlp_flag);
8540
8541 lpfc_send_els_event(vport, ndlp, payload);
8542 phba->fc_stat.elsRcvADISC++;
8543 if (vport->port_state < LPFC_DISC_AUTH) {
8544 rjt_err = LSRJT_UNABLE_TPC;
8545 rjt_exp = LSEXP_NOTHING_MORE;
8546 break;
8547 }
8548 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8549 NLP_EVT_RCV_ADISC);
8550 break;
8551 case ELS_CMD_PDISC:
8552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8553 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8554 did, vport->port_state, ndlp->nlp_flag);
8555
8556 phba->fc_stat.elsRcvPDISC++;
8557 if (vport->port_state < LPFC_DISC_AUTH) {
8558 rjt_err = LSRJT_UNABLE_TPC;
8559 rjt_exp = LSEXP_NOTHING_MORE;
8560 break;
8561 }
8562 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8563 NLP_EVT_RCV_PDISC);
8564 break;
8565 case ELS_CMD_FARPR:
8566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8567 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8568 did, vport->port_state, ndlp->nlp_flag);
8569
8570 phba->fc_stat.elsRcvFARPR++;
8571 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8572 break;
8573 case ELS_CMD_FARP:
8574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8575 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8576 did, vport->port_state, ndlp->nlp_flag);
8577
8578 phba->fc_stat.elsRcvFARP++;
8579 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8580 break;
8581 case ELS_CMD_FAN:
8582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8583 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8584 did, vport->port_state, ndlp->nlp_flag);
8585
8586 phba->fc_stat.elsRcvFAN++;
8587 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8588 break;
8589 case ELS_CMD_PRLI:
8590 case ELS_CMD_NVMEPRLI:
8591 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8592 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8593 did, vport->port_state, ndlp->nlp_flag);
8594
8595 phba->fc_stat.elsRcvPRLI++;
8596 if ((vport->port_state < LPFC_DISC_AUTH) &&
8597 (vport->fc_flag & FC_FABRIC)) {
8598 rjt_err = LSRJT_UNABLE_TPC;
8599 rjt_exp = LSEXP_NOTHING_MORE;
8600 break;
8601 }
8602 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8603 break;
8604 case ELS_CMD_LIRR:
8605 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8606 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8607 did, vport->port_state, ndlp->nlp_flag);
8608
8609 phba->fc_stat.elsRcvLIRR++;
8610 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8611 if (newnode)
8612 lpfc_nlp_put(ndlp);
8613 break;
8614 case ELS_CMD_RLS:
8615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8616 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8617 did, vport->port_state, ndlp->nlp_flag);
8618
8619 phba->fc_stat.elsRcvRLS++;
8620 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8621 if (newnode)
8622 lpfc_nlp_put(ndlp);
8623 break;
8624 case ELS_CMD_RPS:
8625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8626 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8627 did, vport->port_state, ndlp->nlp_flag);
8628
8629 phba->fc_stat.elsRcvRPS++;
8630 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
8631 if (newnode)
8632 lpfc_nlp_put(ndlp);
8633 break;
8634 case ELS_CMD_RPL:
8635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8636 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8637 did, vport->port_state, ndlp->nlp_flag);
8638
8639 phba->fc_stat.elsRcvRPL++;
8640 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8641 if (newnode)
8642 lpfc_nlp_put(ndlp);
8643 break;
8644 case ELS_CMD_RNID:
8645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8646 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8647 did, vport->port_state, ndlp->nlp_flag);
8648
8649 phba->fc_stat.elsRcvRNID++;
8650 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8651 if (newnode)
8652 lpfc_nlp_put(ndlp);
8653 break;
8654 case ELS_CMD_RTV:
8655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8656 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8657 did, vport->port_state, ndlp->nlp_flag);
8658 phba->fc_stat.elsRcvRTV++;
8659 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8660 if (newnode)
8661 lpfc_nlp_put(ndlp);
8662 break;
8663 case ELS_CMD_RRQ:
8664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8665 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8666 did, vport->port_state, ndlp->nlp_flag);
8667
8668 phba->fc_stat.elsRcvRRQ++;
8669 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8670 if (newnode)
8671 lpfc_nlp_put(ndlp);
8672 break;
8673 case ELS_CMD_ECHO:
8674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8675 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8676 did, vport->port_state, ndlp->nlp_flag);
8677
8678 phba->fc_stat.elsRcvECHO++;
8679 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8680 if (newnode)
8681 lpfc_nlp_put(ndlp);
8682 break;
8683 case ELS_CMD_REC:
8684
8685 rjt_err = LSRJT_UNABLE_TPC;
8686 rjt_exp = LSEXP_INVALID_OX_RX;
8687 break;
8688 case ELS_CMD_FPIN:
8689
8690
8691
8692
8693 fc_host_fpin_rcv(shost, elsiocb->iocb.unsli3.rcvsli3.acc_len,
8694 (char *)payload);
8695 break;
8696 default:
8697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8698 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8699 cmd, did, vport->port_state);
8700
8701
8702 rjt_err = LSRJT_CMD_UNSUPPORTED;
8703 rjt_exp = LSEXP_NOTHING_MORE;
8704
8705
8706 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8707 "0115 Unknown ELS command x%x "
8708 "received from NPORT x%x\n", cmd, did);
8709 if (newnode)
8710 lpfc_nlp_put(ndlp);
8711 break;
8712 }
8713
8714 lsrjt:
8715
8716 if (rjt_err) {
8717 memset(&stat, 0, sizeof(stat));
8718 stat.un.b.lsRjtRsnCode = rjt_err;
8719 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8720 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8721 NULL);
8722 }
8723
8724 lpfc_nlp_put(elsiocb->context1);
8725 elsiocb->context1 = NULL;
8726
8727
8728
8729
8730
8731 if (init_link) {
8732 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8733 if (!mbox)
8734 return;
8735 lpfc_linkdown(phba);
8736 lpfc_init_link(phba, mbox,
8737 phba->cfg_topology,
8738 phba->cfg_link_speed);
8739 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8740 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8741 mbox->vport = vport;
8742 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8743 MBX_NOT_FINISHED)
8744 mempool_free(mbox, phba->mbox_mem_pool);
8745 }
8746
8747 return;
8748
8749 dropit:
8750 if (vport && !(vport->load_flag & FC_UNLOADING))
8751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8752 "0111 Dropping received ELS cmd "
8753 "Data: x%x x%x x%x\n",
8754 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8755 phba->fc_stat.elsRcvDrop++;
8756 }
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770 void
8771 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8772 struct lpfc_iocbq *elsiocb)
8773 {
8774 struct lpfc_vport *vport = phba->pport;
8775 IOCB_t *icmd = &elsiocb->iocb;
8776 dma_addr_t paddr;
8777 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8778 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8779
8780 elsiocb->context1 = NULL;
8781 elsiocb->context2 = NULL;
8782 elsiocb->context3 = NULL;
8783
8784 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8785 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8786 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8787 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8788 IOERR_RCV_BUFFER_WAITING) {
8789 phba->fc_stat.NoRcvBuf++;
8790
8791 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8792 lpfc_post_buffer(phba, pring, 0);
8793 return;
8794 }
8795
8796 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8797 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8798 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8799 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8800 vport = phba->pport;
8801 else
8802 vport = lpfc_find_vport_by_vpid(phba,
8803 icmd->unsli3.rcvsli3.vpi);
8804 }
8805
8806
8807
8808
8809 if (icmd->ulpBdeCount == 0)
8810 return;
8811
8812
8813
8814
8815 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8816 elsiocb->context2 = bdeBuf1;
8817 } else {
8818 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8819 icmd->un.cont64[0].addrLow);
8820 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8821 paddr);
8822 }
8823
8824 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8825
8826
8827
8828
8829 if (elsiocb->context2) {
8830 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8831 elsiocb->context2 = NULL;
8832 }
8833
8834
8835 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8836 icmd->ulpBdeCount == 2) {
8837 elsiocb->context2 = bdeBuf2;
8838 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8839
8840 if (elsiocb->context2) {
8841 lpfc_in_buf_free(phba, elsiocb->context2);
8842 elsiocb->context2 = NULL;
8843 }
8844 }
8845 }
8846
8847 static void
8848 lpfc_start_fdmi(struct lpfc_vport *vport)
8849 {
8850 struct lpfc_nodelist *ndlp;
8851
8852
8853
8854
8855
8856 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8857 if (!ndlp) {
8858 ndlp = lpfc_nlp_init(vport, FDMI_DID);
8859 if (ndlp) {
8860 ndlp->nlp_type |= NLP_FABRIC;
8861 } else {
8862 return;
8863 }
8864 }
8865 if (!NLP_CHK_NODE_ACT(ndlp))
8866 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8867
8868 if (ndlp) {
8869 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8870 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8871 }
8872 }
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887 void
8888 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8889 {
8890 struct lpfc_nodelist *ndlp;
8891 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8892
8893
8894
8895
8896
8897
8898 spin_lock_irq(shost->host_lock);
8899 if (vport->fc_flag & FC_DISC_DELAYED) {
8900 spin_unlock_irq(shost->host_lock);
8901 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8902 "3334 Delay fc port discovery for %d seconds\n",
8903 phba->fc_ratov);
8904 mod_timer(&vport->delayed_disc_tmo,
8905 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
8906 return;
8907 }
8908 spin_unlock_irq(shost->host_lock);
8909
8910 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8911 if (!ndlp) {
8912 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8913 if (!ndlp) {
8914 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8915 lpfc_disc_start(vport);
8916 return;
8917 }
8918 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8919 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8920 "0251 NameServer login: no memory\n");
8921 return;
8922 }
8923 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8924 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8925 if (!ndlp) {
8926 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8927 lpfc_disc_start(vport);
8928 return;
8929 }
8930 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8931 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8932 "0348 NameServer login: node freed\n");
8933 return;
8934 }
8935 }
8936 ndlp->nlp_type |= NLP_FABRIC;
8937
8938 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8939
8940 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8941 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8942 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8943 "0252 Cannot issue NameServer login\n");
8944 return;
8945 }
8946
8947 if ((phba->cfg_enable_SmartSAN ||
8948 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8949 (vport->load_flag & FC_ALLOW_FDMI))
8950 lpfc_start_fdmi(vport);
8951 }
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965 static void
8966 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8967 {
8968 struct lpfc_vport *vport = pmb->vport;
8969 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8970 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
8971 MAILBOX_t *mb = &pmb->u.mb;
8972 int rc;
8973
8974 spin_lock_irq(shost->host_lock);
8975 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8976 spin_unlock_irq(shost->host_lock);
8977
8978 if (mb->mbxStatus) {
8979 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8980 "0915 Register VPI failed : Status: x%x"
8981 " upd bit: x%x \n", mb->mbxStatus,
8982 mb->un.varRegVpi.upd);
8983 if (phba->sli_rev == LPFC_SLI_REV4 &&
8984 mb->un.varRegVpi.upd)
8985 goto mbox_err_exit ;
8986
8987 switch (mb->mbxStatus) {
8988 case 0x11:
8989 case 0x9603:
8990 case 0x9602:
8991
8992 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8993 spin_lock_irq(shost->host_lock);
8994 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8995 spin_unlock_irq(shost->host_lock);
8996 lpfc_can_disctmo(vport);
8997 break;
8998
8999 case 0x20:
9000 spin_lock_irq(shost->host_lock);
9001 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9002 spin_unlock_irq(shost->host_lock);
9003 lpfc_init_vpi(phba, pmb, vport->vpi);
9004 pmb->vport = vport;
9005 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9006 rc = lpfc_sli_issue_mbox(phba, pmb,
9007 MBX_NOWAIT);
9008 if (rc == MBX_NOT_FINISHED) {
9009 lpfc_printf_vlog(vport,
9010 KERN_ERR, LOG_MBOX,
9011 "2732 Failed to issue INIT_VPI"
9012 " mailbox command\n");
9013 } else {
9014 lpfc_nlp_put(ndlp);
9015 return;
9016 }
9017
9018 default:
9019
9020 if (phba->sli_rev == LPFC_SLI_REV4)
9021 lpfc_sli4_unreg_all_rpis(vport);
9022 lpfc_mbx_unreg_vpi(vport);
9023 spin_lock_irq(shost->host_lock);
9024 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9025 spin_unlock_irq(shost->host_lock);
9026 if (mb->mbxStatus == MBX_NOT_FINISHED)
9027 break;
9028 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9029 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9030 if (phba->sli_rev == LPFC_SLI_REV4)
9031 lpfc_issue_init_vfi(vport);
9032 else
9033 lpfc_initial_flogi(vport);
9034 } else {
9035 lpfc_initial_fdisc(vport);
9036 }
9037 break;
9038 }
9039 } else {
9040 spin_lock_irq(shost->host_lock);
9041 vport->vpi_state |= LPFC_VPI_REGISTERED;
9042 spin_unlock_irq(shost->host_lock);
9043 if (vport == phba->pport) {
9044 if (phba->sli_rev < LPFC_SLI_REV4)
9045 lpfc_issue_fabric_reglogin(vport);
9046 else {
9047
9048
9049
9050
9051 if (vport->port_state != LPFC_FDISC)
9052 lpfc_start_fdiscs(phba);
9053 lpfc_do_scr_ns_plogi(phba, vport);
9054 }
9055 } else
9056 lpfc_do_scr_ns_plogi(phba, vport);
9057 }
9058 mbox_err_exit:
9059
9060
9061
9062 lpfc_nlp_put(ndlp);
9063
9064 mempool_free(pmb, phba->mbox_mem_pool);
9065 return;
9066 }
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077 void
9078 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9079 struct lpfc_nodelist *ndlp)
9080 {
9081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9082 LPFC_MBOXQ_t *mbox;
9083
9084 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9085 if (mbox) {
9086 lpfc_reg_vpi(vport, mbox);
9087 mbox->vport = vport;
9088 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9089 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9090 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9091 == MBX_NOT_FINISHED) {
9092
9093
9094
9095 lpfc_nlp_put(ndlp);
9096 mempool_free(mbox, phba->mbox_mem_pool);
9097
9098 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9099 "0253 Register VPI: Can't send mbox\n");
9100 goto mbox_err_exit;
9101 }
9102 } else {
9103 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
9104 "0254 Register VPI: no memory\n");
9105 goto mbox_err_exit;
9106 }
9107 return;
9108
9109 mbox_err_exit:
9110 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9111 spin_lock_irq(shost->host_lock);
9112 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9113 spin_unlock_irq(shost->host_lock);
9114 return;
9115 }
9116
9117
9118
9119
9120
9121
9122
9123 void
9124 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9125 {
9126 struct lpfc_vport **vports;
9127 struct lpfc_nodelist *ndlp;
9128 uint32_t link_state;
9129 int i;
9130
9131
9132 link_state = phba->link_state;
9133 lpfc_linkdown(phba);
9134 phba->link_state = link_state;
9135
9136 vports = lpfc_create_vport_work_array(phba);
9137
9138 if (vports) {
9139 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9140 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9141 if (ndlp)
9142 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9143 lpfc_els_flush_cmd(vports[i]);
9144 }
9145 lpfc_destroy_vport_work_array(phba, vports);
9146 }
9147 }
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157 void
9158 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9159 {
9160 struct lpfc_nodelist *ndlp;
9161 struct Scsi_Host *shost;
9162
9163
9164 lpfc_cancel_all_vport_retry_delay_timer(phba);
9165
9166
9167 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9168 if (!ndlp)
9169 return;
9170
9171 shost = lpfc_shost_from_vport(phba->pport);
9172 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9173 spin_lock_irq(shost->host_lock);
9174 ndlp->nlp_flag |= NLP_DELAY_TMO;
9175 spin_unlock_irq(shost->host_lock);
9176 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9177 phba->pport->port_state = LPFC_FLOGI;
9178 return;
9179 }
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190 static int
9191 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9192 struct lpfc_iocbq *cmdiocb,
9193 struct lpfc_iocbq *rspiocb)
9194 {
9195
9196 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9197 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9198 return 0;
9199 else
9200 return 1;
9201 }
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223 static void
9224 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9225 struct lpfc_iocbq *rspiocb)
9226 {
9227 struct lpfc_vport *vport = cmdiocb->vport;
9228 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9229 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9230 struct lpfc_nodelist *np;
9231 struct lpfc_nodelist *next_np;
9232 IOCB_t *irsp = &rspiocb->iocb;
9233 struct lpfc_iocbq *piocb;
9234 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9235 struct serv_parm *sp;
9236 uint8_t fabric_param_changed;
9237
9238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9239 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9240 irsp->ulpStatus, irsp->un.ulpWord[4],
9241 vport->fc_prevDID);
9242
9243
9244
9245
9246 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9247 lpfc_set_disctmo(piocb->vport);
9248 }
9249
9250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9251 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9252 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9253
9254 if (irsp->ulpStatus) {
9255
9256 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9257 lpfc_retry_pport_discovery(phba);
9258 goto out;
9259 }
9260
9261
9262 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9263 goto out;
9264
9265 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9266 "0126 FDISC failed. (x%x/x%x)\n",
9267 irsp->ulpStatus, irsp->un.ulpWord[4]);
9268 goto fdisc_failed;
9269 }
9270 spin_lock_irq(shost->host_lock);
9271 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9272 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9273 vport->fc_flag |= FC_FABRIC;
9274 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9275 vport->fc_flag |= FC_PUBLIC_LOOP;
9276 spin_unlock_irq(shost->host_lock);
9277
9278 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9279 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9280 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9281 if (!prsp)
9282 goto out;
9283 sp = prsp->virt + sizeof(uint32_t);
9284 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9285 memcpy(&vport->fabric_portname, &sp->portName,
9286 sizeof(struct lpfc_name));
9287 memcpy(&vport->fabric_nodename, &sp->nodeName,
9288 sizeof(struct lpfc_name));
9289 if (fabric_param_changed &&
9290 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9291
9292
9293
9294
9295 list_for_each_entry_safe(np, next_np,
9296 &vport->fc_nodes, nlp_listp) {
9297 if (!NLP_CHK_NODE_ACT(ndlp) ||
9298 (np->nlp_state != NLP_STE_NPR_NODE) ||
9299 !(np->nlp_flag & NLP_NPR_ADISC))
9300 continue;
9301 spin_lock_irq(shost->host_lock);
9302 np->nlp_flag &= ~NLP_NPR_ADISC;
9303 spin_unlock_irq(shost->host_lock);
9304 lpfc_unreg_rpi(vport, np);
9305 }
9306 lpfc_cleanup_pending_mbox(vport);
9307
9308 if (phba->sli_rev == LPFC_SLI_REV4)
9309 lpfc_sli4_unreg_all_rpis(vport);
9310
9311 lpfc_mbx_unreg_vpi(vport);
9312 spin_lock_irq(shost->host_lock);
9313 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9314 if (phba->sli_rev == LPFC_SLI_REV4)
9315 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9316 else
9317 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9318 spin_unlock_irq(shost->host_lock);
9319 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9320 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9321
9322
9323
9324
9325 lpfc_register_new_vport(phba, vport, ndlp);
9326 goto out;
9327 }
9328
9329 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9330 lpfc_issue_init_vpi(vport);
9331 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9332 lpfc_register_new_vport(phba, vport, ndlp);
9333 else
9334 lpfc_do_scr_ns_plogi(phba, vport);
9335 goto out;
9336 fdisc_failed:
9337 if (vport->fc_vport &&
9338 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9339 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9340
9341 lpfc_can_disctmo(vport);
9342 lpfc_nlp_put(ndlp);
9343 out:
9344 lpfc_els_free_iocb(phba, cmdiocb);
9345 }
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367 static int
9368 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9369 uint8_t retry)
9370 {
9371 struct lpfc_hba *phba = vport->phba;
9372 IOCB_t *icmd;
9373 struct lpfc_iocbq *elsiocb;
9374 struct serv_parm *sp;
9375 uint8_t *pcmd;
9376 uint16_t cmdsize;
9377 int did = ndlp->nlp_DID;
9378 int rc;
9379
9380 vport->port_state = LPFC_FDISC;
9381 vport->fc_myDID = 0;
9382 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9383 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9384 ELS_CMD_FDISC);
9385 if (!elsiocb) {
9386 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9387 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9388 "0255 Issue FDISC: no IOCB\n");
9389 return 1;
9390 }
9391
9392 icmd = &elsiocb->iocb;
9393 icmd->un.elsreq64.myID = 0;
9394 icmd->un.elsreq64.fl = 1;
9395
9396
9397
9398
9399
9400 if (phba->sli_rev == LPFC_SLI_REV3) {
9401 icmd->ulpCt_h = 1;
9402 icmd->ulpCt_l = 0;
9403 }
9404
9405 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9406 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9407 pcmd += sizeof(uint32_t);
9408 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9409 sp = (struct serv_parm *) pcmd;
9410
9411 sp->cmn.e_d_tov = 0;
9412 sp->cmn.w2.r_a_tov = 0;
9413 sp->cmn.virtual_fabric_support = 0;
9414 sp->cls1.classValid = 0;
9415 sp->cls2.seqDelivery = 1;
9416 sp->cls3.seqDelivery = 1;
9417
9418 pcmd += sizeof(uint32_t);
9419 pcmd += sizeof(uint32_t);
9420 pcmd += sizeof(uint32_t);
9421 pcmd += sizeof(uint32_t);
9422 memcpy(pcmd, &vport->fc_portname, 8);
9423 pcmd += sizeof(uint32_t);
9424 pcmd += sizeof(uint32_t);
9425 memcpy(pcmd, &vport->fc_nodename, 8);
9426 sp->cmn.valid_vendor_ver_level = 0;
9427 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9428 lpfc_set_disctmo(vport);
9429
9430 phba->fc_stat.elsXmitFDISC++;
9431 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9432
9433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9434 "Issue FDISC: did:x%x",
9435 did, 0, 0);
9436
9437 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9438 if (rc == IOCB_ERROR) {
9439 lpfc_els_free_iocb(phba, elsiocb);
9440 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
9442 "0256 Issue FDISC: Cannot send IOCB\n");
9443 return 1;
9444 }
9445 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9446 return 0;
9447 }
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463 static void
9464 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9465 struct lpfc_iocbq *rspiocb)
9466 {
9467 struct lpfc_vport *vport = cmdiocb->vport;
9468 IOCB_t *irsp;
9469 struct lpfc_nodelist *ndlp;
9470 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9471
9472 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9473 irsp = &rspiocb->iocb;
9474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9475 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9476 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9477
9478 lpfc_els_free_iocb(phba, cmdiocb);
9479 vport->unreg_vpi_cmpl = VPORT_ERROR;
9480
9481
9482 lpfc_nlp_put(ndlp);
9483
9484
9485 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9486 "2928 NPIV LOGO completes to NPort x%x "
9487 "Data: x%x x%x x%x x%x\n",
9488 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9489 irsp->ulpTimeout, vport->num_disc_nodes);
9490
9491 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9492 spin_lock_irq(shost->host_lock);
9493 vport->fc_flag &= ~FC_NDISC_ACTIVE;
9494 vport->fc_flag &= ~FC_FABRIC;
9495 spin_unlock_irq(shost->host_lock);
9496 lpfc_can_disctmo(vport);
9497 }
9498 }
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516 int
9517 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9518 {
9519 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9520 struct lpfc_hba *phba = vport->phba;
9521 struct lpfc_iocbq *elsiocb;
9522 uint8_t *pcmd;
9523 uint16_t cmdsize;
9524
9525 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9526 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9527 ELS_CMD_LOGO);
9528 if (!elsiocb)
9529 return 1;
9530
9531 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9532 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9533 pcmd += sizeof(uint32_t);
9534
9535
9536 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9537 pcmd += sizeof(uint32_t);
9538 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9539
9540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9541 "Issue LOGO npiv did:x%x flg:x%x",
9542 ndlp->nlp_DID, ndlp->nlp_flag, 0);
9543
9544 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9545 spin_lock_irq(shost->host_lock);
9546 ndlp->nlp_flag |= NLP_LOGO_SND;
9547 spin_unlock_irq(shost->host_lock);
9548 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9549 IOCB_ERROR) {
9550 spin_lock_irq(shost->host_lock);
9551 ndlp->nlp_flag &= ~NLP_LOGO_SND;
9552 spin_unlock_irq(shost->host_lock);
9553 lpfc_els_free_iocb(phba, elsiocb);
9554 return 1;
9555 }
9556 return 0;
9557 }
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570 void
9571 lpfc_fabric_block_timeout(struct timer_list *t)
9572 {
9573 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9574 unsigned long iflags;
9575 uint32_t tmo_posted;
9576
9577 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9578 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9579 if (!tmo_posted)
9580 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9581 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9582
9583 if (!tmo_posted)
9584 lpfc_worker_wake_up(phba);
9585 return;
9586 }
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598 static void
9599 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9600 {
9601 struct lpfc_iocbq *iocb;
9602 unsigned long iflags;
9603 int ret;
9604 IOCB_t *cmd;
9605
9606 repeat:
9607 iocb = NULL;
9608 spin_lock_irqsave(&phba->hbalock, iflags);
9609
9610 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9611 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9612 list);
9613 if (iocb)
9614
9615 atomic_inc(&phba->fabric_iocb_count);
9616 }
9617 spin_unlock_irqrestore(&phba->hbalock, iflags);
9618 if (iocb) {
9619 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9620 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9621 iocb->iocb_flag |= LPFC_IO_FABRIC;
9622
9623 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9624 "Fabric sched1: ste:x%x",
9625 iocb->vport->port_state, 0, 0);
9626
9627 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9628
9629 if (ret == IOCB_ERROR) {
9630 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9631 iocb->fabric_iocb_cmpl = NULL;
9632 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9633 cmd = &iocb->iocb;
9634 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9635 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9636 iocb->iocb_cmpl(phba, iocb, iocb);
9637
9638 atomic_dec(&phba->fabric_iocb_count);
9639 goto repeat;
9640 }
9641 }
9642
9643 return;
9644 }
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655 void
9656 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9657 {
9658 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9659
9660 lpfc_resume_fabric_iocbs(phba);
9661 return;
9662 }
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673 static void
9674 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9675 {
9676 int blocked;
9677
9678 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9679
9680 if (!blocked)
9681 mod_timer(&phba->fabric_block_timer,
9682 jiffies + msecs_to_jiffies(100));
9683
9684 return;
9685 }
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700 static void
9701 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9702 struct lpfc_iocbq *rspiocb)
9703 {
9704 struct ls_rjt stat;
9705
9706 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9707
9708 switch (rspiocb->iocb.ulpStatus) {
9709 case IOSTAT_NPORT_RJT:
9710 case IOSTAT_FABRIC_RJT:
9711 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9712 lpfc_block_fabric_iocbs(phba);
9713 }
9714 break;
9715
9716 case IOSTAT_NPORT_BSY:
9717 case IOSTAT_FABRIC_BSY:
9718 lpfc_block_fabric_iocbs(phba);
9719 break;
9720
9721 case IOSTAT_LS_RJT:
9722 stat.un.lsRjtError =
9723 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9724 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9725 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9726 lpfc_block_fabric_iocbs(phba);
9727 break;
9728 }
9729
9730 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9731
9732 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9733 cmdiocb->fabric_iocb_cmpl = NULL;
9734 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9735 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9736
9737 atomic_dec(&phba->fabric_iocb_count);
9738 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9739
9740 lpfc_resume_fabric_iocbs(phba);
9741 }
9742 }
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768 static int
9769 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9770 {
9771 unsigned long iflags;
9772 int ready;
9773 int ret;
9774
9775 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9776
9777 spin_lock_irqsave(&phba->hbalock, iflags);
9778 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9779 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9780
9781 if (ready)
9782
9783 atomic_inc(&phba->fabric_iocb_count);
9784 spin_unlock_irqrestore(&phba->hbalock, iflags);
9785 if (ready) {
9786 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9787 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9788 iocb->iocb_flag |= LPFC_IO_FABRIC;
9789
9790 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9791 "Fabric sched2: ste:x%x",
9792 iocb->vport->port_state, 0, 0);
9793
9794 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9795
9796 if (ret == IOCB_ERROR) {
9797 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9798 iocb->fabric_iocb_cmpl = NULL;
9799 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9800 atomic_dec(&phba->fabric_iocb_count);
9801 }
9802 } else {
9803 spin_lock_irqsave(&phba->hbalock, iflags);
9804 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9805 spin_unlock_irqrestore(&phba->hbalock, iflags);
9806 ret = IOCB_SUCCESS;
9807 }
9808 return ret;
9809 }
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9823 {
9824 LIST_HEAD(completions);
9825 struct lpfc_hba *phba = vport->phba;
9826 struct lpfc_iocbq *tmp_iocb, *piocb;
9827
9828 spin_lock_irq(&phba->hbalock);
9829 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9830 list) {
9831
9832 if (piocb->vport != vport)
9833 continue;
9834
9835 list_move_tail(&piocb->list, &completions);
9836 }
9837 spin_unlock_irq(&phba->hbalock);
9838
9839
9840 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9841 IOERR_SLI_ABORTED);
9842 }
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9856 {
9857 LIST_HEAD(completions);
9858 struct lpfc_hba *phba = ndlp->phba;
9859 struct lpfc_iocbq *tmp_iocb, *piocb;
9860 struct lpfc_sli_ring *pring;
9861
9862 pring = lpfc_phba_elsring(phba);
9863
9864 if (unlikely(!pring))
9865 return;
9866
9867 spin_lock_irq(&phba->hbalock);
9868 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9869 list) {
9870 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9871
9872 list_move_tail(&piocb->list, &completions);
9873 }
9874 }
9875 spin_unlock_irq(&phba->hbalock);
9876
9877
9878 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9879 IOERR_SLI_ABORTED);
9880 }
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9894 {
9895 LIST_HEAD(completions);
9896
9897 spin_lock_irq(&phba->hbalock);
9898 list_splice_init(&phba->fabric_iocb_list, &completions);
9899 spin_unlock_irq(&phba->hbalock);
9900
9901
9902 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9903 IOERR_SLI_ABORTED);
9904 }
9905
9906
9907
9908
9909
9910
9911
9912
9913 void
9914 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9915 {
9916 struct lpfc_hba *phba = vport->phba;
9917 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9918 unsigned long iflag = 0;
9919
9920 spin_lock_irqsave(&phba->hbalock, iflag);
9921 spin_lock(&phba->sli4_hba.sgl_list_lock);
9922 list_for_each_entry_safe(sglq_entry, sglq_next,
9923 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9924 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9925 sglq_entry->ndlp = NULL;
9926 }
9927 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9928 spin_unlock_irqrestore(&phba->hbalock, iflag);
9929 return;
9930 }
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940 void
9941 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9942 struct sli4_wcqe_xri_aborted *axri)
9943 {
9944 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
9945 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
9946 uint16_t lxri = 0;
9947
9948 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9949 unsigned long iflag = 0;
9950 struct lpfc_nodelist *ndlp;
9951 struct lpfc_sli_ring *pring;
9952
9953 pring = lpfc_phba_elsring(phba);
9954
9955 spin_lock_irqsave(&phba->hbalock, iflag);
9956 spin_lock(&phba->sli4_hba.sgl_list_lock);
9957 list_for_each_entry_safe(sglq_entry, sglq_next,
9958 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9959 if (sglq_entry->sli4_xritag == xri) {
9960 list_del(&sglq_entry->list);
9961 ndlp = sglq_entry->ndlp;
9962 sglq_entry->ndlp = NULL;
9963 list_add_tail(&sglq_entry->list,
9964 &phba->sli4_hba.lpfc_els_sgl_list);
9965 sglq_entry->state = SGL_FREED;
9966 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9967 spin_unlock_irqrestore(&phba->hbalock, iflag);
9968 lpfc_set_rrq_active(phba, ndlp,
9969 sglq_entry->sli4_lxritag,
9970 rxid, 1);
9971
9972
9973 if (pring && !list_empty(&pring->txq))
9974 lpfc_worker_wake_up(phba);
9975 return;
9976 }
9977 }
9978 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9979 lxri = lpfc_sli4_xri_inrange(phba, xri);
9980 if (lxri == NO_XRI) {
9981 spin_unlock_irqrestore(&phba->hbalock, iflag);
9982 return;
9983 }
9984 spin_lock(&phba->sli4_hba.sgl_list_lock);
9985 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
9986 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
9987 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9988 spin_unlock_irqrestore(&phba->hbalock, iflag);
9989 return;
9990 }
9991 sglq_entry->state = SGL_XRI_ABORTED;
9992 spin_unlock(&phba->sli4_hba.sgl_list_lock);
9993 spin_unlock_irqrestore(&phba->hbalock, iflag);
9994 return;
9995 }
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006 void
10007 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10008 struct lpfc_nodelist *ndlp)
10009 {
10010 struct Scsi_Host *shost;
10011 struct lpfc_hba *phba;
10012 unsigned long flags = 0;
10013
10014 shost = lpfc_shost_from_vport(vport);
10015 phba = vport->phba;
10016 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10017 lpfc_printf_log(phba, KERN_INFO,
10018 LOG_SLI, "3093 No rport recovery needed. "
10019 "rport in state 0x%x\n", ndlp->nlp_state);
10020 return;
10021 }
10022 lpfc_printf_log(phba, KERN_ERR,
10023 LOG_ELS | LOG_FCP_ERROR | LOG_NVME_IOERR,
10024 "3094 Start rport recovery on shost id 0x%x "
10025 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10026 "flags 0x%x\n",
10027 shost->host_no, ndlp->nlp_DID,
10028 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10029 ndlp->nlp_flag);
10030
10031
10032
10033
10034 spin_lock_irqsave(shost->host_lock, flags);
10035 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10036 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10037 spin_unlock_irqrestore(shost->host_lock, flags);
10038 lpfc_unreg_rpi(vport, ndlp);
10039 }
10040