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