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