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