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