1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2025 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
8 * www.broadcom.com *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
10 * *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
29
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <uapi/scsi/fc/fc_fs.h>
35 #include <uapi/scsi/fc/fc_els.h>
36
37 #include "lpfc_hw4.h"
38 #include "lpfc_hw.h"
39 #include "lpfc_sli.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_nl.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_debugfs.h"
49
50 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
51 struct lpfc_iocbq *);
52 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
53 struct lpfc_iocbq *);
54 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
55 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
56 struct lpfc_nodelist *ndlp, uint8_t retry);
57 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
58 struct lpfc_iocbq *iocb);
59 static void lpfc_cmpl_els_edc(struct lpfc_hba *phba,
60 struct lpfc_iocbq *cmdiocb,
61 struct lpfc_iocbq *rspiocb);
62 static void lpfc_cmpl_els_uvem(struct lpfc_hba *, struct lpfc_iocbq *,
63 struct lpfc_iocbq *);
64
65 static int lpfc_max_els_tries = 3;
66
67 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport);
68 static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max);
69 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid);
70
71 /**
72 * lpfc_els_chk_latt - Check host link attention event for a vport
73 * @vport: pointer to a host virtual N_Port data structure.
74 *
75 * This routine checks whether there is an outstanding host link
76 * attention event during the discovery process with the @vport. It is done
77 * by reading the HBA's Host Attention (HA) register. If there is any host
78 * link attention events during this @vport's discovery process, the @vport
79 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
80 * be issued if the link state is not already in host link cleared state,
81 * and a return code shall indicate whether the host link attention event
82 * had happened.
83 *
84 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
85 * state in LPFC_VPORT_READY, the request for checking host link attention
86 * event will be ignored and a return code shall indicate no host link
87 * attention event had happened.
88 *
89 * Return codes
90 * 0 - no host link attention event happened
91 * 1 - host link attention event happened
92 **/
93 int
lpfc_els_chk_latt(struct lpfc_vport * vport)94 lpfc_els_chk_latt(struct lpfc_vport *vport)
95 {
96 struct lpfc_hba *phba = vport->phba;
97 uint32_t ha_copy;
98
99 if (vport->port_state >= LPFC_VPORT_READY ||
100 phba->link_state == LPFC_LINK_DOWN ||
101 phba->sli_rev > LPFC_SLI_REV3)
102 return 0;
103
104 /* Read the HBA Host Attention Register */
105 if (lpfc_readl(phba->HAregaddr, &ha_copy))
106 return 1;
107
108 if (!(ha_copy & HA_LATT))
109 return 0;
110
111 /* Pending Link Event during Discovery */
112 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
113 "0237 Pending Link Event during "
114 "Discovery: State x%x\n",
115 phba->pport->port_state);
116
117 /* CLEAR_LA should re-enable link attention events and
118 * we should then immediately take a LATT event. The
119 * LATT processing should call lpfc_linkdown() which
120 * will cleanup any left over in-progress discovery
121 * events.
122 */
123 set_bit(FC_ABORT_DISCOVERY, &vport->fc_flag);
124
125 if (phba->link_state != LPFC_CLEAR_LA)
126 lpfc_issue_clear_la(phba, vport);
127
128 return 1;
129 }
130
lpfc_is_els_acc_rsp(struct lpfc_dmabuf * buf)131 static bool lpfc_is_els_acc_rsp(struct lpfc_dmabuf *buf)
132 {
133 struct fc_els_ls_acc *rsp = buf->virt;
134
135 if (rsp && rsp->la_cmd == ELS_LS_ACC)
136 return true;
137 return false;
138 }
139
140 /**
141 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
142 * @vport: pointer to a host virtual N_Port data structure.
143 * @expect_rsp: flag indicating whether response is expected.
144 * @cmd_size: size of the ELS command.
145 * @retry: number of retries to the command when it fails.
146 * @ndlp: pointer to a node-list data structure.
147 * @did: destination identifier.
148 * @elscmd: the ELS command code.
149 *
150 * This routine is used for allocating a lpfc-IOCB data structure from
151 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
152 * passed into the routine for discovery state machine to issue an Extended
153 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
154 * and preparation routine that is used by all the discovery state machine
155 * routines and the ELS command-specific fields will be later set up by
156 * the individual discovery machine routines after calling this routine
157 * allocating and preparing a generic IOCB data structure. It fills in the
158 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
159 * payload and response payload (if expected). The reference count on the
160 * ndlp is incremented by 1 and the reference to the ndlp is put into
161 * ndlp of the IOCB data structure for this IOCB to hold the ndlp
162 * reference for the command's callback function to access later.
163 *
164 * Return code
165 * Pointer to the newly allocated/prepared els iocb data structure
166 * NULL - when els iocb data structure allocation/preparation failed
167 **/
168 struct lpfc_iocbq *
lpfc_prep_els_iocb(struct lpfc_vport * vport,u8 expect_rsp,u16 cmd_size,u8 retry,struct lpfc_nodelist * ndlp,u32 did,u32 elscmd)169 lpfc_prep_els_iocb(struct lpfc_vport *vport, u8 expect_rsp,
170 u16 cmd_size, u8 retry,
171 struct lpfc_nodelist *ndlp, u32 did,
172 u32 elscmd)
173 {
174 struct lpfc_hba *phba = vport->phba;
175 struct lpfc_iocbq *elsiocb;
176 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist, *bmp;
177 struct ulp_bde64_le *bpl;
178 u32 timeout = 0;
179
180 if (!lpfc_is_link_up(phba))
181 return NULL;
182
183 /* Allocate buffer for command iocb */
184 elsiocb = lpfc_sli_get_iocbq(phba);
185 if (!elsiocb)
186 return NULL;
187
188 /*
189 * If this command is for fabric controller and HBA running
190 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
191 */
192 if (did == Fabric_DID &&
193 test_bit(HBA_FIP_SUPPORT, &phba->hba_flag) &&
194 (elscmd == ELS_CMD_FLOGI ||
195 elscmd == ELS_CMD_FDISC ||
196 elscmd == ELS_CMD_LOGO))
197 switch (elscmd) {
198 case ELS_CMD_FLOGI:
199 elsiocb->cmd_flag |=
200 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
201 & LPFC_FIP_ELS_ID_MASK);
202 break;
203 case ELS_CMD_FDISC:
204 elsiocb->cmd_flag |=
205 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
206 & LPFC_FIP_ELS_ID_MASK);
207 break;
208 case ELS_CMD_LOGO:
209 elsiocb->cmd_flag |=
210 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
211 & LPFC_FIP_ELS_ID_MASK);
212 break;
213 }
214 else
215 elsiocb->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
216
217 /* fill in BDEs for command */
218 /* Allocate buffer for command payload */
219 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
220 if (pcmd)
221 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
222 if (!pcmd || !pcmd->virt)
223 goto els_iocb_free_pcmb_exit;
224
225 INIT_LIST_HEAD(&pcmd->list);
226
227 /* Allocate buffer for response payload */
228 if (expect_rsp) {
229 prsp = kmalloc(sizeof(*prsp), GFP_KERNEL);
230 if (prsp)
231 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
232 &prsp->phys);
233 if (!prsp || !prsp->virt)
234 goto els_iocb_free_prsp_exit;
235 INIT_LIST_HEAD(&prsp->list);
236 } else {
237 prsp = NULL;
238 }
239
240 /* Allocate buffer for Buffer ptr list */
241 pbuflist = kmalloc(sizeof(*pbuflist), GFP_KERNEL);
242 if (pbuflist)
243 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
244 &pbuflist->phys);
245 if (!pbuflist || !pbuflist->virt)
246 goto els_iocb_free_pbuf_exit;
247
248 INIT_LIST_HEAD(&pbuflist->list);
249
250 if (expect_rsp) {
251 switch (elscmd) {
252 case ELS_CMD_FLOGI:
253 timeout = FF_DEF_RATOV * 2;
254 break;
255 case ELS_CMD_LOGO:
256 timeout = phba->fc_ratov;
257 break;
258 default:
259 timeout = phba->fc_ratov * 2;
260 }
261
262 /* Fill SGE for the num bde count */
263 elsiocb->num_bdes = 2;
264 }
265
266 if (phba->sli_rev == LPFC_SLI_REV4)
267 bmp = pcmd;
268 else
269 bmp = pbuflist;
270
271 lpfc_sli_prep_els_req_rsp(phba, elsiocb, vport, bmp, cmd_size, did,
272 elscmd, timeout, expect_rsp);
273
274 bpl = (struct ulp_bde64_le *)pbuflist->virt;
275 bpl->addr_low = cpu_to_le32(putPaddrLow(pcmd->phys));
276 bpl->addr_high = cpu_to_le32(putPaddrHigh(pcmd->phys));
277 bpl->type_size = cpu_to_le32(cmd_size);
278 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
279
280 if (expect_rsp) {
281 bpl++;
282 bpl->addr_low = cpu_to_le32(putPaddrLow(prsp->phys));
283 bpl->addr_high = cpu_to_le32(putPaddrHigh(prsp->phys));
284 bpl->type_size = cpu_to_le32(FCELSSIZE);
285 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
286 }
287
288 elsiocb->cmd_dmabuf = pcmd;
289 elsiocb->bpl_dmabuf = pbuflist;
290 elsiocb->retry = retry;
291 elsiocb->vport = vport;
292 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
293
294 if (prsp)
295 list_add(&prsp->list, &pcmd->list);
296 if (expect_rsp) {
297 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
298 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
299 "0116 Xmit ELS command x%x to remote "
300 "NPORT x%x I/O tag: x%x, port state:x%x "
301 "rpi x%x fc_flag:x%lx\n",
302 elscmd, did, elsiocb->iotag,
303 vport->port_state, ndlp->nlp_rpi,
304 vport->fc_flag);
305 } else {
306 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
308 "0117 Xmit ELS response x%x to remote "
309 "NPORT x%x I/O tag: x%x, size: x%x "
310 "port_state x%x rpi x%x fc_flag x%lx\n",
311 elscmd, ndlp->nlp_DID, elsiocb->iotag,
312 cmd_size, vport->port_state,
313 ndlp->nlp_rpi, vport->fc_flag);
314 }
315
316 return elsiocb;
317
318 els_iocb_free_pbuf_exit:
319 if (expect_rsp)
320 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
321 kfree(pbuflist);
322
323 els_iocb_free_prsp_exit:
324 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
325 kfree(prsp);
326
327 els_iocb_free_pcmb_exit:
328 kfree(pcmd);
329 lpfc_sli_release_iocbq(phba, elsiocb);
330 return NULL;
331 }
332
333 /**
334 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
335 * @vport: pointer to a host virtual N_Port data structure.
336 *
337 * This routine issues a fabric registration login for a @vport. An
338 * active ndlp node with Fabric_DID must already exist for this @vport.
339 * The routine invokes two mailbox commands to carry out fabric registration
340 * login through the HBA firmware: the first mailbox command requests the
341 * HBA to perform link configuration for the @vport; and the second mailbox
342 * command requests the HBA to perform the actual fabric registration login
343 * with the @vport.
344 *
345 * Return code
346 * 0 - successfully issued fabric registration login for @vport
347 * -ENXIO -- failed to issue fabric registration login for @vport
348 **/
349 int
lpfc_issue_fabric_reglogin(struct lpfc_vport * vport)350 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
351 {
352 struct lpfc_hba *phba = vport->phba;
353 LPFC_MBOXQ_t *mbox;
354 struct lpfc_nodelist *ndlp;
355 struct serv_parm *sp;
356 int rc;
357 int err = 0;
358
359 sp = &phba->fc_fabparam;
360 ndlp = lpfc_findnode_did(vport, Fabric_DID);
361 if (!ndlp) {
362 err = 1;
363 goto fail;
364 }
365
366 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
367 if (!mbox) {
368 err = 2;
369 goto fail;
370 }
371
372 vport->port_state = LPFC_FABRIC_CFG_LINK;
373 lpfc_config_link(phba, mbox);
374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
375 mbox->vport = vport;
376
377 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
378 if (rc == MBX_NOT_FINISHED) {
379 err = 3;
380 goto fail_free_mbox;
381 }
382
383 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
384 if (!mbox) {
385 err = 4;
386 goto fail;
387 }
388 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
389 ndlp->nlp_rpi);
390 if (rc) {
391 err = 5;
392 goto fail_free_mbox;
393 }
394
395 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
396 mbox->vport = vport;
397 /* increment the reference count on ndlp to hold reference
398 * for the callback routine.
399 */
400 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
401 if (!mbox->ctx_ndlp) {
402 err = 6;
403 goto fail_free_mbox;
404 }
405
406 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
407 if (rc == MBX_NOT_FINISHED) {
408 err = 7;
409 goto fail_issue_reg_login;
410 }
411
412 return 0;
413
414 fail_issue_reg_login:
415 /* decrement the reference count on ndlp just incremented
416 * for the failed mbox command.
417 */
418 lpfc_nlp_put(ndlp);
419 fail_free_mbox:
420 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
421 fail:
422 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
423 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
424 "0249 Cannot issue Register Fabric login: Err %d\n",
425 err);
426 return -ENXIO;
427 }
428
429 /**
430 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
431 * @vport: pointer to a host virtual N_Port data structure.
432 *
433 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
434 * the @vport. This mailbox command is necessary for SLI4 port only.
435 *
436 * Return code
437 * 0 - successfully issued REG_VFI for @vport
438 * A failure code otherwise.
439 **/
440 int
lpfc_issue_reg_vfi(struct lpfc_vport * vport)441 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
442 {
443 struct lpfc_hba *phba = vport->phba;
444 LPFC_MBOXQ_t *mboxq = NULL;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_dmabuf *dmabuf = NULL;
447 int rc = 0;
448
449 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
450 if ((phba->sli_rev == LPFC_SLI_REV4) &&
451 !(phba->link_flag & LS_LOOPBACK_MODE) &&
452 !test_bit(FC_PT2PT, &vport->fc_flag)) {
453 ndlp = lpfc_findnode_did(vport, Fabric_DID);
454 if (!ndlp) {
455 rc = -ENODEV;
456 goto fail;
457 }
458 }
459
460 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
461 if (!mboxq) {
462 rc = -ENOMEM;
463 goto fail;
464 }
465
466 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
467 if (test_bit(FC_FABRIC, &vport->fc_flag) ||
468 test_bit(FC_PT2PT, &vport->fc_flag)) {
469 rc = lpfc_mbox_rsrc_prep(phba, mboxq);
470 if (rc) {
471 rc = -ENOMEM;
472 goto fail_mbox;
473 }
474 dmabuf = mboxq->ctx_buf;
475 memcpy(dmabuf->virt, &phba->fc_fabparam,
476 sizeof(struct serv_parm));
477 }
478
479 vport->port_state = LPFC_FABRIC_CFG_LINK;
480 if (dmabuf) {
481 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
482 /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */
483 mboxq->ctx_buf = dmabuf;
484 } else {
485 lpfc_reg_vfi(mboxq, vport, 0);
486 }
487
488 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
489 mboxq->vport = vport;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
492 rc = -ENXIO;
493 goto fail_mbox;
494 }
495 return 0;
496
497 fail_mbox:
498 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
499 fail:
500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
501 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
502 "0289 Issue Register VFI failed: Err %d\n", rc);
503 return rc;
504 }
505
506 /**
507 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
508 * @vport: pointer to a host virtual N_Port data structure.
509 *
510 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
511 * the @vport. This mailbox command is necessary for SLI4 port only.
512 *
513 * Return code
514 * 0 - successfully issued REG_VFI for @vport
515 * A failure code otherwise.
516 **/
517 int
lpfc_issue_unreg_vfi(struct lpfc_vport * vport)518 lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
519 {
520 struct lpfc_hba *phba = vport->phba;
521 LPFC_MBOXQ_t *mboxq;
522 int rc;
523
524 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
525 if (!mboxq) {
526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
527 "2556 UNREG_VFI mbox allocation failed"
528 "HBA state x%x\n", phba->pport->port_state);
529 return -ENOMEM;
530 }
531
532 lpfc_unreg_vfi(mboxq, vport);
533 mboxq->vport = vport;
534 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
535
536 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
537 if (rc == MBX_NOT_FINISHED) {
538 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
539 "2557 UNREG_VFI issue mbox failed rc x%x "
540 "HBA state x%x\n",
541 rc, phba->pport->port_state);
542 mempool_free(mboxq, phba->mbox_mem_pool);
543 return -EIO;
544 }
545
546 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag);
547 return 0;
548 }
549
550 /**
551 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
552 * @vport: pointer to a host virtual N_Port data structure.
553 * @sp: pointer to service parameter data structure.
554 *
555 * This routine is called from FLOGI/FDISC completion handler functions.
556 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
557 * node nodename is changed in the completion service parameter else return
558 * 0. This function also set flag in the vport data structure to delay
559 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
560 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
561 * node nodename is changed in the completion service parameter.
562 *
563 * Return code
564 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
565 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
566 *
567 **/
568 static uint8_t
lpfc_check_clean_addr_bit(struct lpfc_vport * vport,struct serv_parm * sp)569 lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
570 struct serv_parm *sp)
571 {
572 struct lpfc_hba *phba = vport->phba;
573 uint8_t fabric_param_changed = 0;
574
575 if ((vport->fc_prevDID != vport->fc_myDID) ||
576 memcmp(&vport->fabric_portname, &sp->portName,
577 sizeof(struct lpfc_name)) ||
578 memcmp(&vport->fabric_nodename, &sp->nodeName,
579 sizeof(struct lpfc_name)) ||
580 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
581 fabric_param_changed = 1;
582 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
583 }
584 /*
585 * Word 1 Bit 31 in common service parameter is overloaded.
586 * Word 1 Bit 31 in FLOGI request is multiple NPort request
587 * Word 1 Bit 31 in FLOGI response is clean address bit
588 *
589 * If fabric parameter is changed and clean address bit is
590 * cleared delay nport discovery if
591 * - vport->fc_prevDID != 0 (not initial discovery) OR
592 * - lpfc_delay_discovery module parameter is set.
593 */
594 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
595 (vport->fc_prevDID || phba->cfg_delay_discovery))
596 set_bit(FC_DISC_DELAYED, &vport->fc_flag);
597
598 return fabric_param_changed;
599 }
600
601
602 /**
603 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
604 * @vport: pointer to a host virtual N_Port data structure.
605 * @ndlp: pointer to a node-list data structure.
606 * @sp: pointer to service parameter data structure.
607 * @ulp_word4: command response value
608 *
609 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
610 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
611 * port in a fabric topology. It properly sets up the parameters to the @ndlp
612 * from the IOCB response. It also check the newly assigned N_Port ID to the
613 * @vport against the previously assigned N_Port ID. If it is different from
614 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
615 * is invoked on all the remaining nodes with the @vport to unregister the
616 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
617 * is invoked to register login to the fabric.
618 *
619 * Return code
620 * 0 - Success (currently, always return 0)
621 **/
622 static int
lpfc_cmpl_els_flogi_fabric(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct serv_parm * sp,uint32_t ulp_word4)623 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
624 struct serv_parm *sp, uint32_t ulp_word4)
625 {
626 struct lpfc_hba *phba = vport->phba;
627 struct lpfc_nodelist *np;
628 struct lpfc_nodelist *next_np;
629 uint8_t fabric_param_changed;
630
631 set_bit(FC_FABRIC, &vport->fc_flag);
632
633 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
634 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
635 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
636
637 phba->fc_edtovResol = sp->cmn.edtovResolution;
638 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
639
640 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
641 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
642
643 vport->fc_myDID = ulp_word4 & Mask_DID;
644 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
645 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
646 ndlp->nlp_class_sup = 0;
647 if (sp->cls1.classValid)
648 ndlp->nlp_class_sup |= FC_COS_CLASS1;
649 if (sp->cls2.classValid)
650 ndlp->nlp_class_sup |= FC_COS_CLASS2;
651 if (sp->cls3.classValid)
652 ndlp->nlp_class_sup |= FC_COS_CLASS3;
653 if (sp->cls4.classValid)
654 ndlp->nlp_class_sup |= FC_COS_CLASS4;
655 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
656 sp->cmn.bbRcvSizeLsb;
657
658 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
659 if (fabric_param_changed) {
660 /* Reset FDMI attribute masks based on config parameter */
661 if (phba->cfg_enable_SmartSAN ||
662 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
663 /* Setup appropriate attribute masks */
664 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
665 if (phba->cfg_enable_SmartSAN)
666 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
667 else
668 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
669 } else {
670 vport->fdmi_hba_mask = 0;
671 vport->fdmi_port_mask = 0;
672 }
673
674 }
675 memcpy(&vport->fabric_portname, &sp->portName,
676 sizeof(struct lpfc_name));
677 memcpy(&vport->fabric_nodename, &sp->nodeName,
678 sizeof(struct lpfc_name));
679 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
680
681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
682 if (sp->cmn.response_multiple_NPort) {
683 lpfc_printf_vlog(vport, KERN_WARNING,
684 LOG_ELS | LOG_VPORT,
685 "1816 FLOGI NPIV supported, "
686 "response data 0x%x\n",
687 sp->cmn.response_multiple_NPort);
688 spin_lock_irq(&phba->hbalock);
689 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
690 spin_unlock_irq(&phba->hbalock);
691 } else {
692 /* Because we asked f/w for NPIV it still expects us
693 to call reg_vnpid at least for the physical host */
694 lpfc_printf_vlog(vport, KERN_WARNING,
695 LOG_ELS | LOG_VPORT,
696 "1817 Fabric does not support NPIV "
697 "- configuring single port mode.\n");
698 spin_lock_irq(&phba->hbalock);
699 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
700 spin_unlock_irq(&phba->hbalock);
701 }
702 }
703
704 /*
705 * For FC we need to do some special processing because of the SLI
706 * Port's default settings of the Common Service Parameters.
707 */
708 if ((phba->sli_rev == LPFC_SLI_REV4) &&
709 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
710 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
711 if (fabric_param_changed)
712 lpfc_unregister_fcf_prep(phba);
713
714 /* This should just update the VFI CSPs*/
715 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag))
716 lpfc_issue_reg_vfi(vport);
717 }
718
719 if (fabric_param_changed &&
720 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
721
722 /* If our NportID changed, we need to ensure all
723 * remaining NPORTs get unreg_login'ed.
724 */
725 list_for_each_entry_safe(np, next_np,
726 &vport->fc_nodes, nlp_listp) {
727 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
728 !test_bit(NLP_NPR_ADISC, &np->nlp_flag))
729 continue;
730 clear_bit(NLP_NPR_ADISC, &np->nlp_flag);
731 lpfc_unreg_rpi(vport, np);
732 }
733 lpfc_cleanup_pending_mbox(vport);
734
735 if (phba->sli_rev == LPFC_SLI_REV4) {
736 lpfc_sli4_unreg_all_rpis(vport);
737 lpfc_mbx_unreg_vpi(vport);
738 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
739 }
740
741 /*
742 * For SLI3 and SLI4, the VPI needs to be reregistered in
743 * response to this fabric parameter change event.
744 */
745 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
746 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
747 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
748 /*
749 * Driver needs to re-reg VPI in order for f/w
750 * to update the MAC address.
751 */
752 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
753 lpfc_register_new_vport(phba, vport, ndlp);
754 return 0;
755 }
756
757 if (phba->sli_rev < LPFC_SLI_REV4) {
758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
759 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
760 test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag))
761 lpfc_register_new_vport(phba, vport, ndlp);
762 else
763 lpfc_issue_fabric_reglogin(vport);
764 } else {
765 ndlp->nlp_type |= NLP_FABRIC;
766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
767 if ((!test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) &&
768 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
769 lpfc_start_fdiscs(phba);
770 lpfc_do_scr_ns_plogi(phba, vport);
771 } else if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag))
772 lpfc_issue_init_vpi(vport);
773 else {
774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
775 "3135 Need register VFI: (x%x/%x)\n",
776 vport->fc_prevDID, vport->fc_myDID);
777 lpfc_issue_reg_vfi(vport);
778 }
779 }
780 return 0;
781 }
782
783 /**
784 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
785 * @vport: pointer to a host virtual N_Port data structure.
786 * @ndlp: pointer to a node-list data structure.
787 * @sp: pointer to service parameter data structure.
788 *
789 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
790 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
791 * in a point-to-point topology. First, the @vport's N_Port Name is compared
792 * with the received N_Port Name: if the @vport's N_Port Name is greater than
793 * the received N_Port Name lexicographically, this node shall assign local
794 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
795 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
796 * this node shall just wait for the remote node to issue PLOGI and assign
797 * N_Port IDs.
798 *
799 * Return code
800 * 0 - Success
801 * -ENXIO - Fail
802 **/
803 static int
lpfc_cmpl_els_flogi_nport(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct serv_parm * sp)804 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
805 struct serv_parm *sp)
806 {
807 struct lpfc_hba *phba = vport->phba;
808 LPFC_MBOXQ_t *mbox;
809 int rc;
810
811 clear_bit(FC_FABRIC, &vport->fc_flag);
812 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
813 set_bit(FC_PT2PT, &vport->fc_flag);
814
815 /* If we are pt2pt with another NPort, force NPIV off! */
816 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
817
818 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
819 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
820 lpfc_unregister_fcf_prep(phba);
821 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag);
822 phba->fc_topology_changed = 0;
823 }
824
825 rc = memcmp(&vport->fc_portname, &sp->portName,
826 sizeof(vport->fc_portname));
827
828 if (rc >= 0) {
829 /* This side will initiate the PLOGI */
830 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag);
831
832 /*
833 * N_Port ID cannot be 0, set our Id to LocalID
834 * the other side will be RemoteID.
835 */
836
837 /* not equal */
838 if (rc)
839 vport->fc_myDID = PT2PT_LocalID;
840
841 /* If not registered with a transport, decrement ndlp reference
842 * count indicating that ndlp can be safely released when other
843 * references are removed.
844 */
845 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
846 lpfc_nlp_put(ndlp);
847
848 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
849 if (!ndlp) {
850 /*
851 * Cannot find existing Fabric ndlp, so allocate a
852 * new one
853 */
854 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
855 if (!ndlp)
856 goto fail;
857 }
858
859 memcpy(&ndlp->nlp_portname, &sp->portName,
860 sizeof(struct lpfc_name));
861 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
862 sizeof(struct lpfc_name));
863 /* Set state will put ndlp onto node list if not already done */
864 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
865 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
866
867 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
868 if (!mbox)
869 goto fail;
870
871 lpfc_config_link(phba, mbox);
872
873 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
874 mbox->vport = vport;
875 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
876 if (rc == MBX_NOT_FINISHED) {
877 mempool_free(mbox, phba->mbox_mem_pool);
878 goto fail;
879 }
880 } else {
881 /* This side will wait for the PLOGI. If not registered with
882 * a transport, decrement node reference count indicating that
883 * ndlp can be released when other references are removed.
884 */
885 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
886 lpfc_nlp_put(ndlp);
887
888 /* Start discovery - this should just do CLEAR_LA */
889 lpfc_disc_start(vport);
890 }
891
892 return 0;
893 fail:
894 return -ENXIO;
895 }
896
897 /**
898 * lpfc_cmpl_els_flogi - Completion callback function for flogi
899 * @phba: pointer to lpfc hba data structure.
900 * @cmdiocb: pointer to lpfc command iocb data structure.
901 * @rspiocb: pointer to lpfc response iocb data structure.
902 *
903 * This routine is the top-level completion callback function for issuing
904 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
905 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
906 * retry has been made (either immediately or delayed with lpfc_els_retry()
907 * returning 1), the command IOCB will be released and function returned.
908 * If the retry attempt has been given up (possibly reach the maximum
909 * number of retries), one additional decrement of ndlp reference shall be
910 * invoked before going out after releasing the command IOCB. This will
911 * actually release the remote node (Note, lpfc_els_free_iocb() will also
912 * invoke one decrement of ndlp reference count). If no error reported in
913 * the IOCB status, the command Port ID field is used to determine whether
914 * this is a point-to-point topology or a fabric topology: if the Port ID
915 * field is assigned, it is a fabric topology; otherwise, it is a
916 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
917 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
918 * specific topology completion conditions.
919 **/
920 static void
lpfc_cmpl_els_flogi(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)921 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
922 struct lpfc_iocbq *rspiocb)
923 {
924 struct lpfc_vport *vport = cmdiocb->vport;
925 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
926 IOCB_t *irsp;
927 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
928 struct serv_parm *sp;
929 uint16_t fcf_index;
930 int rc;
931 u32 ulp_status, ulp_word4, tmo;
932 bool flogi_in_retry = false;
933
934 /* Check to see if link went down during discovery */
935 if (lpfc_els_chk_latt(vport)) {
936 /* One additional decrement on node reference count to
937 * trigger the release of the node
938 */
939 if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
940 lpfc_nlp_put(ndlp);
941 goto out;
942 }
943
944 ulp_status = get_job_ulpstatus(phba, rspiocb);
945 ulp_word4 = get_job_word4(phba, rspiocb);
946
947 if (phba->sli_rev == LPFC_SLI_REV4) {
948 tmo = get_wqe_tmo(cmdiocb);
949 } else {
950 irsp = &rspiocb->iocb;
951 tmo = irsp->ulpTimeout;
952 }
953
954 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
955 "FLOGI cmpl: status:x%x/x%x state:x%x",
956 ulp_status, ulp_word4,
957 vport->port_state);
958
959 if (ulp_status) {
960 /*
961 * In case of FIP mode, perform roundrobin FCF failover
962 * due to new FCF discovery
963 */
964 if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag) &&
965 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
966 if (phba->link_state < LPFC_LINK_UP)
967 goto stop_rr_fcf_flogi;
968 if ((phba->fcoe_cvl_eventtag_attn ==
969 phba->fcoe_cvl_eventtag) &&
970 (ulp_status == IOSTAT_LOCAL_REJECT) &&
971 ((ulp_word4 & IOERR_PARAM_MASK) ==
972 IOERR_SLI_ABORTED))
973 goto stop_rr_fcf_flogi;
974 else
975 phba->fcoe_cvl_eventtag_attn =
976 phba->fcoe_cvl_eventtag;
977 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
978 "2611 FLOGI FCF (x%x), "
979 "status:x%x/x%x, tmo:x%x, perform "
980 "roundrobin FCF failover\n",
981 phba->fcf.current_rec.fcf_indx,
982 ulp_status, ulp_word4, tmo);
983 lpfc_sli4_set_fcf_flogi_fail(phba,
984 phba->fcf.current_rec.fcf_indx);
985 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
986 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
987 if (rc)
988 goto out;
989 }
990
991 stop_rr_fcf_flogi:
992 /* FLOGI failure */
993 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
994 ((ulp_word4 & IOERR_PARAM_MASK) ==
995 IOERR_LOOP_OPEN_FAILURE)))
996 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
997 "2858 FLOGI Status:x%x/x%x TMO"
998 ":x%x Data x%lx x%x\n",
999 ulp_status, ulp_word4, tmo,
1000 phba->hba_flag, phba->fcf.fcf_flag);
1001
1002 /* Check for retry */
1003 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1004 /* Address a timing race with dev_loss. If dev_loss
1005 * is active on this FPort node, put the initial ref
1006 * count back to stop premature node release actions.
1007 */
1008 lpfc_check_nlp_post_devloss(vport, ndlp);
1009 flogi_in_retry = true;
1010 goto out;
1011 }
1012
1013 /* The FLOGI will not be retried. If the FPort node is not
1014 * registered with the SCSI transport, remove the initial
1015 * reference to trigger node release.
1016 */
1017 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) &&
1018 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
1019 lpfc_nlp_put(ndlp);
1020
1021 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1022 "0150 FLOGI Status:x%x/x%x "
1023 "xri x%x TMO:x%x refcnt %d\n",
1024 ulp_status, ulp_word4, cmdiocb->sli4_xritag,
1025 tmo, kref_read(&ndlp->kref));
1026
1027 /* If this is not a loop open failure, bail out */
1028 if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
1029 ((ulp_word4 & IOERR_PARAM_MASK) ==
1030 IOERR_LOOP_OPEN_FAILURE))) {
1031 /* Warn FLOGI status */
1032 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
1033 "0100 FLOGI Status:x%x/x%x "
1034 "TMO:x%x\n",
1035 ulp_status, ulp_word4, tmo);
1036 goto flogifail;
1037 }
1038
1039 /* FLOGI failed, so there is no fabric */
1040 clear_bit(FC_FABRIC, &vport->fc_flag);
1041 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
1042 clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
1043
1044 /* If private loop, then allow max outstanding els to be
1045 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1046 * alpa map would take too long otherwise.
1047 */
1048 if (phba->alpa_map[0] == 0)
1049 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1050 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1051 (!test_bit(FC_VFI_REGISTERED, &vport->fc_flag) ||
1052 (vport->fc_prevDID != vport->fc_myDID) ||
1053 phba->fc_topology_changed)) {
1054 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag)) {
1055 if (phba->fc_topology_changed) {
1056 lpfc_unregister_fcf_prep(phba);
1057 clear_bit(FC_VFI_REGISTERED,
1058 &vport->fc_flag);
1059 phba->fc_topology_changed = 0;
1060 } else {
1061 lpfc_sli4_unreg_all_rpis(vport);
1062 }
1063 }
1064
1065 /* Do not register VFI if the driver aborted FLOGI */
1066 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
1067 lpfc_issue_reg_vfi(vport);
1068
1069 goto out;
1070 }
1071 goto flogifail;
1072 }
1073 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag);
1074 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag);
1075
1076 /*
1077 * The FLOGI succeeded. Sync the data for the CPU before
1078 * accessing it.
1079 */
1080 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1081 if (!prsp)
1082 goto out;
1083 if (!lpfc_is_els_acc_rsp(prsp))
1084 goto out;
1085 sp = prsp->virt + sizeof(uint32_t);
1086
1087 /* FLOGI completes successfully */
1088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1089 "0101 FLOGI completes successfully, I/O tag:x%x "
1090 "xri x%x Data: x%x x%x x%x x%x x%x x%lx x%x %d\n",
1091 cmdiocb->iotag, cmdiocb->sli4_xritag,
1092 ulp_word4, sp->cmn.e_d_tov,
1093 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1094 vport->port_state, vport->fc_flag,
1095 sp->cmn.priority_tagging, kref_read(&ndlp->kref));
1096
1097 /* reinitialize the VMID datastructure before returning */
1098 if (lpfc_is_vmid_enabled(phba)) {
1099 lpfc_reinit_vmid(vport);
1100 vport->vmid_flag = 0;
1101 }
1102 if (sp->cmn.priority_tagging)
1103 vport->phba->pport->vmid_flag |= (LPFC_VMID_ISSUE_QFPA |
1104 LPFC_VMID_TYPE_PRIO);
1105
1106 /*
1107 * Address a timing race with dev_loss. If dev_loss is active on
1108 * this FPort node, put the initial ref count back to stop premature
1109 * node release actions.
1110 */
1111 lpfc_check_nlp_post_devloss(vport, ndlp);
1112 if (vport->port_state == LPFC_FLOGI) {
1113 /*
1114 * If Common Service Parameters indicate Nport
1115 * we are point to point, if Fport we are Fabric.
1116 */
1117 if (sp->cmn.fPort)
1118 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp,
1119 ulp_word4);
1120 else if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag))
1121 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1122 else {
1123 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1124 "2831 FLOGI response with cleared Fabric "
1125 "bit fcf_index 0x%x "
1126 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1127 "Fabric Name "
1128 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1129 phba->fcf.current_rec.fcf_indx,
1130 phba->fcf.current_rec.switch_name[0],
1131 phba->fcf.current_rec.switch_name[1],
1132 phba->fcf.current_rec.switch_name[2],
1133 phba->fcf.current_rec.switch_name[3],
1134 phba->fcf.current_rec.switch_name[4],
1135 phba->fcf.current_rec.switch_name[5],
1136 phba->fcf.current_rec.switch_name[6],
1137 phba->fcf.current_rec.switch_name[7],
1138 phba->fcf.current_rec.fabric_name[0],
1139 phba->fcf.current_rec.fabric_name[1],
1140 phba->fcf.current_rec.fabric_name[2],
1141 phba->fcf.current_rec.fabric_name[3],
1142 phba->fcf.current_rec.fabric_name[4],
1143 phba->fcf.current_rec.fabric_name[5],
1144 phba->fcf.current_rec.fabric_name[6],
1145 phba->fcf.current_rec.fabric_name[7]);
1146
1147 lpfc_nlp_put(ndlp);
1148 spin_lock_irq(&phba->hbalock);
1149 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1150 spin_unlock_irq(&phba->hbalock);
1151 clear_bit(FCF_RR_INPROG, &phba->hba_flag);
1152 clear_bit(HBA_DEVLOSS_TMO, &phba->hba_flag);
1153 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1154 goto out;
1155 }
1156 if (!rc) {
1157 /* Mark the FCF discovery process done */
1158 if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag))
1159 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1160 LOG_ELS,
1161 "2769 FLOGI to FCF (x%x) "
1162 "completed successfully\n",
1163 phba->fcf.current_rec.fcf_indx);
1164 spin_lock_irq(&phba->hbalock);
1165 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1166 spin_unlock_irq(&phba->hbalock);
1167 clear_bit(FCF_RR_INPROG, &phba->hba_flag);
1168 clear_bit(HBA_DEVLOSS_TMO, &phba->hba_flag);
1169 phba->fcf.fcf_redisc_attempted = 0; /* reset */
1170 goto out;
1171 }
1172 } else if (vport->port_state > LPFC_FLOGI &&
1173 test_bit(FC_PT2PT, &vport->fc_flag)) {
1174 /*
1175 * In a p2p topology, it is possible that discovery has
1176 * already progressed, and this completion can be ignored.
1177 * Recheck the indicated topology.
1178 */
1179 if (!sp->cmn.fPort)
1180 goto out;
1181 }
1182
1183 flogifail:
1184 spin_lock_irq(&phba->hbalock);
1185 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1186 spin_unlock_irq(&phba->hbalock);
1187
1188 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
1189 /* FLOGI failed, so just use loop map to make discovery list */
1190 lpfc_disc_list_loopmap(vport);
1191
1192 /* Start discovery */
1193 lpfc_disc_start(vport);
1194 } else if (((ulp_status != IOSTAT_LOCAL_REJECT) ||
1195 (((ulp_word4 & IOERR_PARAM_MASK) !=
1196 IOERR_SLI_ABORTED) &&
1197 ((ulp_word4 & IOERR_PARAM_MASK) !=
1198 IOERR_SLI_DOWN))) &&
1199 (phba->link_state != LPFC_CLEAR_LA)) {
1200 /* If FLOGI failed enable link interrupt. */
1201 lpfc_issue_clear_la(phba, vport);
1202 }
1203 out:
1204 if (!flogi_in_retry)
1205 clear_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag);
1206
1207 lpfc_els_free_iocb(phba, cmdiocb);
1208 lpfc_nlp_put(ndlp);
1209 }
1210
1211 /**
1212 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1213 * aborted during a link down
1214 * @phba: pointer to lpfc hba data structure.
1215 * @cmdiocb: pointer to lpfc command iocb data structure.
1216 * @rspiocb: pointer to lpfc response iocb data structure.
1217 *
1218 */
1219 static void
lpfc_cmpl_els_link_down(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)1220 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1221 struct lpfc_iocbq *rspiocb)
1222 {
1223 uint32_t *pcmd;
1224 uint32_t cmd;
1225 u32 ulp_status, ulp_word4;
1226
1227 pcmd = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
1228 cmd = *pcmd;
1229
1230 ulp_status = get_job_ulpstatus(phba, rspiocb);
1231 ulp_word4 = get_job_word4(phba, rspiocb);
1232
1233 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1234 "6445 ELS completes after LINK_DOWN: "
1235 " Status %x/%x cmd x%x flg x%x iotag x%x\n",
1236 ulp_status, ulp_word4, cmd,
1237 cmdiocb->cmd_flag, cmdiocb->iotag);
1238
1239 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) {
1240 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
1241 atomic_dec(&phba->fabric_iocb_count);
1242 }
1243 lpfc_els_free_iocb(phba, cmdiocb);
1244 }
1245
1246 /**
1247 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1248 * @vport: pointer to a host virtual N_Port data structure.
1249 * @ndlp: pointer to a node-list data structure.
1250 * @retry: number of retries to the command IOCB.
1251 *
1252 * This routine issues a Fabric Login (FLOGI) Request ELS command
1253 * for a @vport. The initiator service parameters are put into the payload
1254 * of the FLOGI Request IOCB and the top-level callback function pointer
1255 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1256 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1257 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1258 *
1259 * Note that the ndlp reference count will be incremented by 1 for holding the
1260 * ndlp and the reference to ndlp will be stored into the ndlp field of
1261 * the IOCB for the completion callback function to the FLOGI ELS command.
1262 *
1263 * Return code
1264 * 0 - successfully issued flogi iocb for @vport
1265 * 1 - failed to issue flogi iocb for @vport
1266 **/
1267 static int
lpfc_issue_els_flogi(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)1268 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1269 uint8_t retry)
1270 {
1271 struct lpfc_hba *phba = vport->phba;
1272 struct serv_parm *sp;
1273 union lpfc_wqe128 *wqe = NULL;
1274 IOCB_t *icmd = NULL;
1275 struct lpfc_iocbq *elsiocb;
1276 struct lpfc_iocbq defer_flogi_acc;
1277 u8 *pcmd, ct;
1278 uint16_t cmdsize;
1279 uint32_t tmo, did;
1280 int rc;
1281
1282 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1283 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1284 ndlp->nlp_DID, ELS_CMD_FLOGI);
1285
1286 if (!elsiocb)
1287 return 1;
1288
1289 wqe = &elsiocb->wqe;
1290 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
1291 icmd = &elsiocb->iocb;
1292
1293 /* For FLOGI request, remainder of payload is service parameters */
1294 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1295 pcmd += sizeof(uint32_t);
1296 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1297 sp = (struct serv_parm *) pcmd;
1298
1299 /* Setup CSPs accordingly for Fabric */
1300 sp->cmn.e_d_tov = 0;
1301 sp->cmn.w2.r_a_tov = 0;
1302 sp->cmn.virtual_fabric_support = 0;
1303 sp->cls1.classValid = 0;
1304 if (sp->cmn.fcphLow < FC_PH3)
1305 sp->cmn.fcphLow = FC_PH3;
1306 if (sp->cmn.fcphHigh < FC_PH3)
1307 sp->cmn.fcphHigh = FC_PH3;
1308
1309 /* Determine if switch supports priority tagging */
1310 if (phba->cfg_vmid_priority_tagging) {
1311 sp->cmn.priority_tagging = 1;
1312 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1313 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0,
1314 sizeof(vport->lpfc_vmid_host_uuid))) {
1315 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
1316 sizeof(phba->wwpn));
1317 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
1318 sizeof(phba->wwnn));
1319 }
1320 }
1321
1322 if (phba->sli_rev == LPFC_SLI_REV4) {
1323 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1324 LPFC_SLI_INTF_IF_TYPE_0) {
1325 /* FLOGI needs to be 3 for WQE FCFI */
1326 ct = SLI4_CT_FCFI;
1327 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
1328
1329 /* Set the fcfi to the fcfi we registered with */
1330 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
1331 phba->fcf.fcfi);
1332 }
1333
1334 /* Can't do SLI4 class2 without support sequence coalescing */
1335 sp->cls2.classValid = 0;
1336 sp->cls2.seqDelivery = 0;
1337 } else {
1338 /* Historical, setting sequential-delivery bit for SLI3 */
1339 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1340 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1341 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1342 sp->cmn.request_multiple_Nport = 1;
1343 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1344 icmd->ulpCt_h = 1;
1345 icmd->ulpCt_l = 0;
1346 } else {
1347 sp->cmn.request_multiple_Nport = 0;
1348 }
1349
1350 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1351 icmd->un.elsreq64.myID = 0;
1352 icmd->un.elsreq64.fl = 1;
1353 }
1354 }
1355
1356 tmo = phba->fc_ratov;
1357 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1358 lpfc_set_disctmo(vport);
1359 phba->fc_ratov = tmo;
1360
1361 phba->fc_stat.elsXmitFLOGI++;
1362 elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi;
1363
1364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1365 "Issue FLOGI: opt:x%x",
1366 phba->sli3_options, 0, 0);
1367
1368 elsiocb->ndlp = lpfc_nlp_get(ndlp);
1369 if (!elsiocb->ndlp) {
1370 lpfc_els_free_iocb(phba, elsiocb);
1371 return 1;
1372 }
1373
1374 /* Avoid race with FLOGI completion and hba_flags. */
1375 set_bit(HBA_FLOGI_ISSUED, &phba->hba_flag);
1376 set_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag);
1377
1378 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1379 if (rc == IOCB_ERROR) {
1380 clear_bit(HBA_FLOGI_ISSUED, &phba->hba_flag);
1381 clear_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag);
1382 lpfc_els_free_iocb(phba, elsiocb);
1383 lpfc_nlp_put(ndlp);
1384 return 1;
1385 }
1386
1387 /* Clear external loopback plug detected flag */
1388 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1389
1390 /* Check for a deferred FLOGI ACC condition */
1391 if (phba->defer_flogi_acc.flag) {
1392 /* lookup ndlp for received FLOGI */
1393 ndlp = lpfc_findnode_did(vport, 0);
1394 if (!ndlp)
1395 return 0;
1396
1397 did = vport->fc_myDID;
1398 vport->fc_myDID = Fabric_DID;
1399
1400 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1401
1402 if (phba->sli_rev == LPFC_SLI_REV4) {
1403 bf_set(wqe_ctxt_tag,
1404 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1405 phba->defer_flogi_acc.rx_id);
1406 bf_set(wqe_rcvoxid,
1407 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
1408 phba->defer_flogi_acc.ox_id);
1409 } else {
1410 icmd = &defer_flogi_acc.iocb;
1411 icmd->ulpContext = phba->defer_flogi_acc.rx_id;
1412 icmd->unsli3.rcvsli3.ox_id =
1413 phba->defer_flogi_acc.ox_id;
1414 }
1415
1416 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1417 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1418 " ox_id: x%x, hba_flag x%lx\n",
1419 phba->defer_flogi_acc.rx_id,
1420 phba->defer_flogi_acc.ox_id, phba->hba_flag);
1421
1422 /* Send deferred FLOGI ACC */
1423 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1424 ndlp, NULL);
1425
1426 phba->defer_flogi_acc.flag = false;
1427
1428 /* Decrement the held ndlp that was incremented when the
1429 * deferred flogi acc flag was set.
1430 */
1431 if (phba->defer_flogi_acc.ndlp) {
1432 lpfc_nlp_put(phba->defer_flogi_acc.ndlp);
1433 phba->defer_flogi_acc.ndlp = NULL;
1434 }
1435
1436 vport->fc_myDID = did;
1437 }
1438
1439 return 0;
1440 }
1441
1442 /**
1443 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1444 * @phba: pointer to lpfc hba data structure.
1445 *
1446 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1447 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1448 * list and issues an abort IOCB commond on each outstanding IOCB that
1449 * contains a active Fabric_DID ndlp. Note that this function is to issue
1450 * the abort IOCB command on all the outstanding IOCBs, thus when this
1451 * function returns, it does not guarantee all the IOCBs are actually aborted.
1452 *
1453 * Return code
1454 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1455 **/
1456 int
lpfc_els_abort_flogi(struct lpfc_hba * phba)1457 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1458 {
1459 struct lpfc_sli_ring *pring;
1460 struct lpfc_iocbq *iocb, *next_iocb;
1461 struct lpfc_nodelist *ndlp;
1462 u32 ulp_command;
1463
1464 /* Abort outstanding I/O on NPort <nlp_DID> */
1465 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1466 "0201 Abort outstanding I/O on NPort x%x\n",
1467 Fabric_DID);
1468
1469 pring = lpfc_phba_elsring(phba);
1470 if (unlikely(!pring))
1471 return -EIO;
1472
1473 /*
1474 * Check the txcmplq for an iocb that matches the nport the driver is
1475 * searching for.
1476 */
1477 spin_lock_irq(&phba->hbalock);
1478 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1479 ulp_command = get_job_cmnd(phba, iocb);
1480 if (ulp_command == CMD_ELS_REQUEST64_CR) {
1481 ndlp = iocb->ndlp;
1482 if (ndlp && ndlp->nlp_DID == Fabric_DID) {
1483 if (test_bit(FC_PT2PT, &phba->pport->fc_flag) &&
1484 !test_bit(FC_PT2PT_PLOGI,
1485 &phba->pport->fc_flag))
1486 iocb->fabric_cmd_cmpl =
1487 lpfc_ignore_els_cmpl;
1488 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
1489 NULL);
1490 }
1491 }
1492 }
1493 /* Make sure HBA is alive */
1494 lpfc_issue_hb_tmo(phba);
1495
1496 spin_unlock_irq(&phba->hbalock);
1497
1498 return 0;
1499 }
1500
1501 /**
1502 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1503 * @vport: pointer to a host virtual N_Port data structure.
1504 *
1505 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1506 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1507 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1508 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1509 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1510 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1511 * @vport.
1512 *
1513 * Return code
1514 * 0 - failed to issue initial flogi for @vport
1515 * 1 - successfully issued initial flogi for @vport
1516 **/
1517 int
lpfc_initial_flogi(struct lpfc_vport * vport)1518 lpfc_initial_flogi(struct lpfc_vport *vport)
1519 {
1520 struct lpfc_nodelist *ndlp;
1521
1522 vport->port_state = LPFC_FLOGI;
1523 lpfc_set_disctmo(vport);
1524
1525 /* First look for the Fabric ndlp */
1526 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1527 if (!ndlp) {
1528 /* Cannot find existing Fabric ndlp, so allocate a new one */
1529 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1530 if (!ndlp)
1531 return 0;
1532 /* Set the node type */
1533 ndlp->nlp_type |= NLP_FABRIC;
1534
1535 /* Put ndlp onto node list */
1536 lpfc_enqueue_node(vport, ndlp);
1537 }
1538
1539 /* Reset the Fabric flag, topology change may have happened */
1540 clear_bit(FC_FABRIC, &vport->fc_flag);
1541 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1542 /* A node reference should be retained while registered with a
1543 * transport or dev-loss-evt work is pending.
1544 * Otherwise, decrement node reference to trigger release.
1545 */
1546 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1547 !test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag))
1548 lpfc_nlp_put(ndlp);
1549 return 0;
1550 }
1551 return 1;
1552 }
1553
1554 /**
1555 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1556 * @vport: pointer to a host virtual N_Port data structure.
1557 *
1558 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1559 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1560 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1561 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1562 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1563 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1564 * @vport.
1565 *
1566 * Return code
1567 * 0 - failed to issue initial fdisc for @vport
1568 * 1 - successfully issued initial fdisc for @vport
1569 **/
1570 int
lpfc_initial_fdisc(struct lpfc_vport * vport)1571 lpfc_initial_fdisc(struct lpfc_vport *vport)
1572 {
1573 struct lpfc_nodelist *ndlp;
1574
1575 /* First look for the Fabric ndlp */
1576 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1577 if (!ndlp) {
1578 /* Cannot find existing Fabric ndlp, so allocate a new one */
1579 ndlp = lpfc_nlp_init(vport, Fabric_DID);
1580 if (!ndlp)
1581 return 0;
1582
1583 /* NPIV is only supported in Fabrics. */
1584 ndlp->nlp_type |= NLP_FABRIC;
1585
1586 /* Put ndlp onto node list */
1587 lpfc_enqueue_node(vport, ndlp);
1588 }
1589
1590 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1591 /* A node reference should be retained while registered with a
1592 * transport or dev-loss-evt work is pending.
1593 * Otherwise, decrement node reference to trigger release.
1594 */
1595 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
1596 !test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag))
1597 lpfc_nlp_put(ndlp);
1598 return 0;
1599 }
1600 return 1;
1601 }
1602
1603 /**
1604 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1605 * @vport: pointer to a host virtual N_Port data structure.
1606 *
1607 * This routine checks whether there are more remaining Port Logins
1608 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1609 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1610 * to issue ELS PLOGIs up to the configured discover threads with the
1611 * @vport (@vport->cfg_discovery_threads). The function also decrement
1612 * the @vport's num_disc_node by 1 if it is not already 0.
1613 **/
1614 void
lpfc_more_plogi(struct lpfc_vport * vport)1615 lpfc_more_plogi(struct lpfc_vport *vport)
1616 {
1617 if (vport->num_disc_nodes)
1618 vport->num_disc_nodes--;
1619
1620 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1622 "0232 Continue discovery with %d PLOGIs to go "
1623 "Data: x%x x%lx x%x\n",
1624 vport->num_disc_nodes,
1625 atomic_read(&vport->fc_plogi_cnt),
1626 vport->fc_flag, vport->port_state);
1627 /* Check to see if there are more PLOGIs to be sent */
1628 if (test_bit(FC_NLP_MORE, &vport->fc_flag))
1629 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1630 lpfc_els_disc_plogi(vport);
1631
1632 return;
1633 }
1634
1635 /**
1636 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1637 * @phba: pointer to lpfc hba data structure.
1638 * @prsp: pointer to response IOCB payload.
1639 * @ndlp: pointer to a node-list data structure.
1640 *
1641 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1642 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1643 * The following cases are considered N_Port confirmed:
1644 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1645 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1646 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1647 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1648 * 1) if there is a node on vport list other than the @ndlp with the same
1649 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1650 * on that node to release the RPI associated with the node; 2) if there is
1651 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1652 * into, a new node shall be allocated (or activated). In either case, the
1653 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1654 * be released and the new_ndlp shall be put on to the vport node list and
1655 * its pointer returned as the confirmed node.
1656 *
1657 * Note that before the @ndlp got "released", the keepDID from not-matching
1658 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1659 * of the @ndlp. This is because the release of @ndlp is actually to put it
1660 * into an inactive state on the vport node list and the vport node list
1661 * management algorithm does not allow two node with a same DID.
1662 *
1663 * Return code
1664 * pointer to the PLOGI N_Port @ndlp
1665 **/
1666 static struct lpfc_nodelist *
lpfc_plogi_confirm_nport(struct lpfc_hba * phba,uint32_t * prsp,struct lpfc_nodelist * ndlp)1667 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1668 struct lpfc_nodelist *ndlp)
1669 {
1670 struct lpfc_vport *vport = ndlp->vport;
1671 struct lpfc_nodelist *new_ndlp;
1672 struct serv_parm *sp;
1673 uint8_t name[sizeof(struct lpfc_name)];
1674 uint32_t keepDID = 0;
1675 int rc;
1676 unsigned long keep_nlp_flag = 0, keep_new_nlp_flag = 0;
1677 uint16_t keep_nlp_state;
1678 u32 keep_nlp_fc4_type = 0;
1679 struct lpfc_nvme_rport *keep_nrport = NULL;
1680 unsigned long *active_rrqs_xri_bitmap = NULL;
1681
1682 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1683 memset(name, 0, sizeof(struct lpfc_name));
1684
1685 /* Now we find out if the NPort we are logging into, matches the WWPN
1686 * we have for that ndlp. If not, we have some work to do.
1687 */
1688 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1689
1690 /* return immediately if the WWPN matches ndlp */
1691 if (new_ndlp == ndlp)
1692 return ndlp;
1693
1694 if (phba->sli_rev == LPFC_SLI_REV4) {
1695 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1696 GFP_KERNEL);
1697 if (active_rrqs_xri_bitmap)
1698 memset(active_rrqs_xri_bitmap, 0,
1699 phba->cfg_rrq_xri_bitmap_sz);
1700 }
1701
1702 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1703 "3178 PLOGI confirm: ndlp x%x x%lx x%x: "
1704 "new_ndlp x%x x%lx x%x\n",
1705 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1706 (new_ndlp ? new_ndlp->nlp_DID : 0),
1707 (new_ndlp ? new_ndlp->nlp_flag : 0),
1708 (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1709
1710 if (!new_ndlp) {
1711 rc = memcmp(&ndlp->nlp_portname, name,
1712 sizeof(struct lpfc_name));
1713 if (!rc) {
1714 if (active_rrqs_xri_bitmap)
1715 mempool_free(active_rrqs_xri_bitmap,
1716 phba->active_rrq_pool);
1717 return ndlp;
1718 }
1719 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1720 if (!new_ndlp) {
1721 if (active_rrqs_xri_bitmap)
1722 mempool_free(active_rrqs_xri_bitmap,
1723 phba->active_rrq_pool);
1724 return ndlp;
1725 }
1726 } else {
1727 if (phba->sli_rev == LPFC_SLI_REV4 &&
1728 active_rrqs_xri_bitmap)
1729 memcpy(active_rrqs_xri_bitmap,
1730 new_ndlp->active_rrqs_xri_bitmap,
1731 phba->cfg_rrq_xri_bitmap_sz);
1732
1733 /*
1734 * Unregister from backend if not done yet. Could have been
1735 * skipped due to ADISC
1736 */
1737 lpfc_nlp_unreg_node(vport, new_ndlp);
1738 }
1739
1740 keepDID = new_ndlp->nlp_DID;
1741
1742 /* At this point in this routine, we know new_ndlp will be
1743 * returned. however, any previous GID_FTs that were done
1744 * would have updated nlp_fc4_type in ndlp, so we must ensure
1745 * new_ndlp has the right value.
1746 */
1747 if (test_bit(FC_FABRIC, &vport->fc_flag)) {
1748 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1749 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1750 }
1751
1752 lpfc_unreg_rpi(vport, new_ndlp);
1753 new_ndlp->nlp_DID = ndlp->nlp_DID;
1754 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1755 if (phba->sli_rev == LPFC_SLI_REV4)
1756 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1757 ndlp->active_rrqs_xri_bitmap,
1758 phba->cfg_rrq_xri_bitmap_sz);
1759
1760 /* Lock both ndlps */
1761 spin_lock_irq(&ndlp->lock);
1762 spin_lock_irq(&new_ndlp->lock);
1763 keep_new_nlp_flag = new_ndlp->nlp_flag;
1764 keep_nlp_flag = ndlp->nlp_flag;
1765 new_ndlp->nlp_flag = ndlp->nlp_flag;
1766
1767 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1768 if (test_bit(NLP_UNREG_INP, &keep_new_nlp_flag))
1769 set_bit(NLP_UNREG_INP, &new_ndlp->nlp_flag);
1770 else
1771 clear_bit(NLP_UNREG_INP, &new_ndlp->nlp_flag);
1772
1773 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1774 if (test_bit(NLP_RPI_REGISTERED, &keep_new_nlp_flag))
1775 set_bit(NLP_RPI_REGISTERED, &new_ndlp->nlp_flag);
1776 else
1777 clear_bit(NLP_RPI_REGISTERED, &new_ndlp->nlp_flag);
1778
1779 /*
1780 * Retain the DROPPED flag. This will take care of the init
1781 * refcount when affecting the state change
1782 */
1783 if (test_bit(NLP_DROPPED, &keep_new_nlp_flag))
1784 set_bit(NLP_DROPPED, &new_ndlp->nlp_flag);
1785 else
1786 clear_bit(NLP_DROPPED, &new_ndlp->nlp_flag);
1787
1788 ndlp->nlp_flag = keep_new_nlp_flag;
1789
1790 /* if ndlp had NLP_UNREG_INP set, keep it */
1791 if (test_bit(NLP_UNREG_INP, &keep_nlp_flag))
1792 set_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
1793 else
1794 clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
1795
1796 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1797 if (test_bit(NLP_RPI_REGISTERED, &keep_nlp_flag))
1798 set_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag);
1799 else
1800 clear_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag);
1801
1802 /*
1803 * Retain the DROPPED flag. This will take care of the init
1804 * refcount when affecting the state change
1805 */
1806 if (test_bit(NLP_DROPPED, &keep_nlp_flag))
1807 set_bit(NLP_DROPPED, &ndlp->nlp_flag);
1808 else
1809 clear_bit(NLP_DROPPED, &ndlp->nlp_flag);
1810
1811 spin_unlock_irq(&new_ndlp->lock);
1812 spin_unlock_irq(&ndlp->lock);
1813
1814 /* Set nlp_states accordingly */
1815 keep_nlp_state = new_ndlp->nlp_state;
1816 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1817
1818 /* interchange the nvme remoteport structs */
1819 keep_nrport = new_ndlp->nrport;
1820 new_ndlp->nrport = ndlp->nrport;
1821
1822 /* Move this back to NPR state */
1823 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1824 /* The ndlp doesn't have a portname yet, but does have an
1825 * NPort ID. The new_ndlp portname matches the Rport's
1826 * portname. Reinstantiate the new_ndlp and reset the ndlp.
1827 */
1828 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1829 "3179 PLOGI confirm NEW: %x %x\n",
1830 new_ndlp->nlp_DID, keepDID);
1831
1832 /* Two ndlps cannot have the same did on the nodelist.
1833 * The KeepDID and keep_nlp_fc4_type need to be swapped
1834 * because ndlp is inflight with no WWPN.
1835 */
1836 ndlp->nlp_DID = keepDID;
1837 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1838 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1839 if (phba->sli_rev == LPFC_SLI_REV4 &&
1840 active_rrqs_xri_bitmap)
1841 memcpy(ndlp->active_rrqs_xri_bitmap,
1842 active_rrqs_xri_bitmap,
1843 phba->cfg_rrq_xri_bitmap_sz);
1844
1845 } else {
1846 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1847 "3180 PLOGI confirm SWAP: %x %x\n",
1848 new_ndlp->nlp_DID, keepDID);
1849
1850 lpfc_unreg_rpi(vport, ndlp);
1851
1852 /* The ndlp and new_ndlp both have WWPNs but are swapping
1853 * NPort Ids and attributes.
1854 */
1855 ndlp->nlp_DID = keepDID;
1856 ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1857
1858 if (phba->sli_rev == LPFC_SLI_REV4 &&
1859 active_rrqs_xri_bitmap)
1860 memcpy(ndlp->active_rrqs_xri_bitmap,
1861 active_rrqs_xri_bitmap,
1862 phba->cfg_rrq_xri_bitmap_sz);
1863
1864 /* Since we are switching over to the new_ndlp,
1865 * reset the old ndlp state
1866 */
1867 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1868 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1869 keep_nlp_state = NLP_STE_NPR_NODE;
1870 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1871 ndlp->nrport = keep_nrport;
1872 }
1873
1874 /*
1875 * If ndlp is not associated with any rport we can drop it here else
1876 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1877 */
1878 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
1879 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
1880
1881 if (phba->sli_rev == LPFC_SLI_REV4 &&
1882 active_rrqs_xri_bitmap)
1883 mempool_free(active_rrqs_xri_bitmap,
1884 phba->active_rrq_pool);
1885
1886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1887 "3173 PLOGI confirm exit: new_ndlp x%x x%lx x%x\n",
1888 new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1889 new_ndlp->nlp_fc4_type);
1890
1891 return new_ndlp;
1892 }
1893
1894 /**
1895 * lpfc_end_rscn - Check and handle more rscn for a vport
1896 * @vport: pointer to a host virtual N_Port data structure.
1897 *
1898 * This routine checks whether more Registration State Change
1899 * Notifications (RSCNs) came in while the discovery state machine was in
1900 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1901 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1902 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1903 * handling the RSCNs.
1904 **/
1905 void
lpfc_end_rscn(struct lpfc_vport * vport)1906 lpfc_end_rscn(struct lpfc_vport *vport)
1907 {
1908
1909 if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
1910 /*
1911 * Check to see if more RSCNs came in while we were
1912 * processing this one.
1913 */
1914 if (vport->fc_rscn_id_cnt ||
1915 test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag))
1916 lpfc_els_handle_rscn(vport);
1917 else
1918 clear_bit(FC_RSCN_MODE, &vport->fc_flag);
1919 }
1920 }
1921
1922 /**
1923 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1924 * @phba: pointer to lpfc hba data structure.
1925 * @cmdiocb: pointer to lpfc command iocb data structure.
1926 * @rspiocb: pointer to lpfc response iocb data structure.
1927 *
1928 * This routine will call the clear rrq function to free the rrq and
1929 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1930 * exist then the clear_rrq is still called because the rrq needs to
1931 * be freed.
1932 **/
1933
1934 static void
lpfc_cmpl_els_rrq(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)1935 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1936 struct lpfc_iocbq *rspiocb)
1937 {
1938 struct lpfc_vport *vport = cmdiocb->vport;
1939 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
1940 struct lpfc_node_rrq *rrq;
1941 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
1942 u32 ulp_word4 = get_job_word4(phba, rspiocb);
1943
1944 /* we pass cmdiocb to state machine which needs rspiocb as well */
1945 rrq = cmdiocb->context_un.rrq;
1946 cmdiocb->rsp_iocb = rspiocb;
1947
1948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1949 "RRQ cmpl: status:x%x/x%x did:x%x",
1950 ulp_status, ulp_word4,
1951 get_job_els_rsp64_did(phba, cmdiocb));
1952
1953
1954 /* rrq completes to NPort <nlp_DID> */
1955 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1956 "2880 RRQ completes to DID x%x "
1957 "Data: x%x x%x x%x x%x x%x\n",
1958 ndlp->nlp_DID, ulp_status, ulp_word4,
1959 get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid);
1960
1961 if (ulp_status) {
1962 /* Check for retry */
1963 /* Warn RRQ status Don't print the vport to vport rjts */
1964 if (ulp_status != IOSTAT_LS_RJT ||
1965 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
1966 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
1967 (phba)->pport->cfg_log_verbose & LOG_ELS)
1968 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
1969 "2881 RRQ DID:%06X Status:"
1970 "x%x/x%x\n",
1971 ndlp->nlp_DID, ulp_status,
1972 ulp_word4);
1973 }
1974
1975 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1976 lpfc_els_free_iocb(phba, cmdiocb);
1977 lpfc_nlp_put(ndlp);
1978 return;
1979 }
1980 /**
1981 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1982 * @phba: pointer to lpfc hba data structure.
1983 * @cmdiocb: pointer to lpfc command iocb data structure.
1984 * @rspiocb: pointer to lpfc response iocb data structure.
1985 *
1986 * This routine is the completion callback function for issuing the Port
1987 * Login (PLOGI) command. For PLOGI completion, there must be an active
1988 * ndlp on the vport node list that matches the remote node ID from the
1989 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1990 * ignored and command IOCB released. The PLOGI response IOCB status is
1991 * checked for error conditions. If there is error status reported, PLOGI
1992 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1993 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1994 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1995 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1996 * there are additional N_Port nodes with the vport that need to perform
1997 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1998 * PLOGIs.
1999 **/
2000 static void
lpfc_cmpl_els_plogi(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2001 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2002 struct lpfc_iocbq *rspiocb)
2003 {
2004 struct lpfc_vport *vport = cmdiocb->vport;
2005 IOCB_t *irsp;
2006 struct lpfc_nodelist *ndlp, *free_ndlp;
2007 struct lpfc_dmabuf *prsp;
2008 bool disc;
2009 struct serv_parm *sp = NULL;
2010 u32 ulp_status, ulp_word4, did, iotag;
2011 bool release_node = false;
2012
2013 /* we pass cmdiocb to state machine which needs rspiocb as well */
2014 cmdiocb->rsp_iocb = rspiocb;
2015
2016 ulp_status = get_job_ulpstatus(phba, rspiocb);
2017 ulp_word4 = get_job_word4(phba, rspiocb);
2018 did = get_job_els_rsp64_did(phba, cmdiocb);
2019
2020 if (phba->sli_rev == LPFC_SLI_REV4) {
2021 iotag = get_wqe_reqtag(cmdiocb);
2022 } else {
2023 irsp = &rspiocb->iocb;
2024 iotag = irsp->ulpIoTag;
2025 }
2026
2027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2028 "PLOGI cmpl: status:x%x/x%x did:x%x",
2029 ulp_status, ulp_word4, did);
2030
2031 ndlp = lpfc_findnode_did(vport, did);
2032 if (!ndlp) {
2033 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2034 "0136 PLOGI completes to NPort x%x "
2035 "with no ndlp. Data: x%x x%x x%x\n",
2036 did, ulp_status, ulp_word4, iotag);
2037 goto out_freeiocb;
2038 }
2039
2040 /* Since ndlp can be freed in the disc state machine, note if this node
2041 * is being used during discovery.
2042 */
2043 disc = test_and_clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2044
2045 /* PLOGI completes to NPort <nlp_DID> */
2046 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2047 "0102 PLOGI completes to NPort x%06x "
2048 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2049 ndlp->nlp_DID, iotag,
2050 ndlp->nlp_fc4_type,
2051 ulp_status, ulp_word4,
2052 disc, vport->num_disc_nodes);
2053
2054 /* Check to see if link went down during discovery */
2055 if (lpfc_els_chk_latt(vport)) {
2056 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2057 goto out;
2058 }
2059
2060 if (ulp_status) {
2061 /* Check for retry */
2062 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2063 /* ELS command is being retried */
2064 if (disc)
2065 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2066 goto out;
2067 }
2068 /* Warn PLOGI status Don't print the vport to vport rjts */
2069 if (ulp_status != IOSTAT_LS_RJT ||
2070 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
2071 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
2072 (phba)->pport->cfg_log_verbose & LOG_ELS)
2073 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
2074 "2753 PLOGI DID:%06X "
2075 "Status:x%x/x%x\n",
2076 ndlp->nlp_DID, ulp_status,
2077 ulp_word4);
2078
2079 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2080 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
2081 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2082 NLP_EVT_CMPL_PLOGI);
2083
2084 /* If a PLOGI collision occurred, the node needs to continue
2085 * with the reglogin process.
2086 */
2087 spin_lock_irq(&ndlp->lock);
2088 if ((test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag) ||
2089 test_bit(NLP_RCV_PLOGI, &ndlp->nlp_flag)) &&
2090 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
2091 spin_unlock_irq(&ndlp->lock);
2092 goto out;
2093 }
2094
2095 /* No PLOGI collision and the node is not registered with the
2096 * scsi or nvme transport. It is no longer an active node. Just
2097 * start the device remove process.
2098 */
2099 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2100 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2101 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag))
2102 release_node = true;
2103 }
2104 spin_unlock_irq(&ndlp->lock);
2105
2106 if (release_node)
2107 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2108 NLP_EVT_DEVICE_RM);
2109 } else {
2110 /* Good status, call state machine */
2111 prsp = list_get_first(&cmdiocb->cmd_dmabuf->list,
2112 struct lpfc_dmabuf, list);
2113 if (!prsp)
2114 goto out;
2115 if (!lpfc_is_els_acc_rsp(prsp))
2116 goto out;
2117 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2118
2119 sp = (struct serv_parm *)((u8 *)prsp->virt +
2120 sizeof(u32));
2121
2122 ndlp->vmid_support = 0;
2123 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
2124 (phba->cfg_vmid_priority_tagging &&
2125 sp->cmn.priority_tagging)) {
2126 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
2127 "4018 app_hdr_support %d tagging %d DID x%x\n",
2128 sp->cmn.app_hdr_support,
2129 sp->cmn.priority_tagging,
2130 ndlp->nlp_DID);
2131 /* if the dest port supports VMID, mark it in ndlp */
2132 ndlp->vmid_support = 1;
2133 }
2134
2135 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2136 NLP_EVT_CMPL_PLOGI);
2137 }
2138
2139 if (disc && vport->num_disc_nodes) {
2140 /* Check to see if there are more PLOGIs to be sent */
2141 lpfc_more_plogi(vport);
2142
2143 if (vport->num_disc_nodes == 0) {
2144 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
2145
2146 lpfc_can_disctmo(vport);
2147 lpfc_end_rscn(vport);
2148 }
2149 }
2150
2151 out:
2152 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2153 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2154 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2155
2156 out_freeiocb:
2157 /* Release the reference on the original I/O request. */
2158 free_ndlp = cmdiocb->ndlp;
2159
2160 lpfc_els_free_iocb(phba, cmdiocb);
2161 lpfc_nlp_put(free_ndlp);
2162 return;
2163 }
2164
2165 /**
2166 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2167 * @vport: pointer to a host virtual N_Port data structure.
2168 * @did: destination port identifier.
2169 * @retry: number of retries to the command IOCB.
2170 *
2171 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2172 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2173 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2174 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2175 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2176 *
2177 * Note that the ndlp reference count will be incremented by 1 for holding
2178 * the ndlp and the reference to ndlp will be stored into the ndlp field
2179 * of the IOCB for the completion callback function to the PLOGI ELS command.
2180 *
2181 * Return code
2182 * 0 - Successfully issued a plogi for @vport
2183 * 1 - failed to issue a plogi for @vport
2184 **/
2185 int
lpfc_issue_els_plogi(struct lpfc_vport * vport,uint32_t did,uint8_t retry)2186 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2187 {
2188 struct lpfc_hba *phba = vport->phba;
2189 struct serv_parm *sp;
2190 struct lpfc_nodelist *ndlp;
2191 struct lpfc_iocbq *elsiocb;
2192 uint8_t *pcmd;
2193 uint16_t cmdsize;
2194 int ret;
2195
2196 ndlp = lpfc_findnode_did(vport, did);
2197 if (!ndlp)
2198 return 1;
2199
2200 /* Defer the processing of the issue PLOGI until after the
2201 * outstanding UNREG_RPI mbox command completes, unless we
2202 * are going offline. This logic does not apply for Fabric DIDs
2203 */
2204 if ((test_bit(NLP_IGNR_REG_CMPL, &ndlp->nlp_flag) ||
2205 test_bit(NLP_UNREG_INP, &ndlp->nlp_flag)) &&
2206 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2207 !test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
2208 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2209 "4110 Issue PLOGI x%x deferred "
2210 "on NPort x%x rpi x%x flg x%lx Data:"
2211 " x%px\n",
2212 ndlp->nlp_defer_did, ndlp->nlp_DID,
2213 ndlp->nlp_rpi, ndlp->nlp_flag, ndlp);
2214
2215 /* We can only defer 1st PLOGI */
2216 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2217 ndlp->nlp_defer_did = did;
2218 return 0;
2219 }
2220
2221 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2222 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2223 ELS_CMD_PLOGI);
2224 if (!elsiocb)
2225 return 1;
2226
2227 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2228
2229 /* For PLOGI request, remainder of payload is service parameters */
2230 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2231 pcmd += sizeof(uint32_t);
2232 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2233 sp = (struct serv_parm *) pcmd;
2234
2235 /*
2236 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2237 * to device on remote loops work.
2238 */
2239 if (test_bit(FC_FABRIC, &vport->fc_flag) &&
2240 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
2241 sp->cmn.altBbCredit = 1;
2242
2243 if (sp->cmn.fcphLow < FC_PH_4_3)
2244 sp->cmn.fcphLow = FC_PH_4_3;
2245
2246 if (sp->cmn.fcphHigh < FC_PH3)
2247 sp->cmn.fcphHigh = FC_PH3;
2248
2249 sp->cmn.valid_vendor_ver_level = 0;
2250 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2251 sp->cmn.bbRcvSizeMsb &= 0xF;
2252
2253 /* Check if the destination port supports VMID */
2254 ndlp->vmid_support = 0;
2255 if (vport->vmid_priority_tagging)
2256 sp->cmn.priority_tagging = 1;
2257 else if (phba->cfg_vmid_app_header &&
2258 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
2259 sp->cmn.app_hdr_support = 1;
2260
2261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2262 "Issue PLOGI: did:x%x",
2263 did, 0, 0);
2264
2265 /* If our firmware supports this feature, convey that
2266 * information to the target using the vendor specific field.
2267 */
2268 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2269 sp->cmn.valid_vendor_ver_level = 1;
2270 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2271 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2272 }
2273
2274 phba->fc_stat.elsXmitPLOGI++;
2275 elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi;
2276
2277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2278 "Issue PLOGI: did:x%x refcnt %d",
2279 did, kref_read(&ndlp->kref), 0);
2280 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2281 if (!elsiocb->ndlp) {
2282 lpfc_els_free_iocb(phba, elsiocb);
2283 return 1;
2284 }
2285
2286 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2287 if (ret) {
2288 lpfc_els_free_iocb(phba, elsiocb);
2289 lpfc_nlp_put(ndlp);
2290 return 1;
2291 }
2292
2293 return 0;
2294 }
2295
2296 /**
2297 * lpfc_cmpl_els_prli - Completion callback function for prli
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 callback function for a Process Login
2303 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2304 * status. If there is error status reported, PRLI retry shall be attempted
2305 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2306 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2307 * ndlp to mark the PRLI completion.
2308 **/
2309 static void
lpfc_cmpl_els_prli(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2310 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2311 struct lpfc_iocbq *rspiocb)
2312 {
2313 struct lpfc_vport *vport = cmdiocb->vport;
2314 struct lpfc_nodelist *ndlp;
2315 char *mode;
2316 u32 ulp_status;
2317 u32 ulp_word4;
2318 bool release_node = false;
2319
2320 /* we pass cmdiocb to state machine which needs rspiocb as well */
2321 cmdiocb->rsp_iocb = rspiocb;
2322
2323 ndlp = cmdiocb->ndlp;
2324
2325 ulp_status = get_job_ulpstatus(phba, rspiocb);
2326 ulp_word4 = get_job_word4(phba, rspiocb);
2327
2328 clear_bit(NLP_PRLI_SND, &ndlp->nlp_flag);
2329
2330 /* Driver supports multiple FC4 types. Counters matter. */
2331 spin_lock_irq(&ndlp->lock);
2332 vport->fc_prli_sent--;
2333 ndlp->fc4_prli_sent--;
2334 spin_unlock_irq(&ndlp->lock);
2335
2336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2337 "PRLI cmpl: status:x%x/x%x did:x%x",
2338 ulp_status, ulp_word4,
2339 ndlp->nlp_DID);
2340
2341 /* PRLI completes to NPort <nlp_DID> */
2342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2343 "0103 PRLI completes to NPort x%06x "
2344 "Data: x%x x%x x%x x%x x%x\n",
2345 ndlp->nlp_DID, ulp_status, ulp_word4,
2346 vport->num_disc_nodes, ndlp->fc4_prli_sent,
2347 ndlp->fc4_xpt_flags);
2348
2349 /* Check to see if link went down during discovery */
2350 if (lpfc_els_chk_latt(vport))
2351 goto out;
2352
2353 if (ulp_status) {
2354 /* Check for retry */
2355 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2356 /* ELS command is being retried */
2357 goto out;
2358 }
2359
2360 /* If we don't send GFT_ID to Fabric, a PRLI error
2361 * could be expected.
2362 */
2363 if (test_bit(FC_FABRIC, &vport->fc_flag) ||
2364 vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)
2365 mode = KERN_WARNING;
2366 else
2367 mode = KERN_INFO;
2368
2369 /* Warn PRLI status */
2370 lpfc_printf_vlog(vport, mode, LOG_ELS,
2371 "2754 PRLI DID:%06X Status:x%x/x%x, "
2372 "data: x%x x%x x%lx\n",
2373 ndlp->nlp_DID, ulp_status,
2374 ulp_word4, ndlp->nlp_state,
2375 ndlp->fc4_prli_sent, ndlp->nlp_flag);
2376
2377 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2378 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4))
2379 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2380 NLP_EVT_CMPL_PRLI);
2381
2382 /* The following condition catches an inflight transition
2383 * mismatch typically caused by an RSCN. Skip any
2384 * processing to allow recovery.
2385 */
2386 if ((ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
2387 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE) ||
2388 (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2389 test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag))) {
2390 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
2391 "2784 PRLI cmpl: Allow Node recovery "
2392 "DID x%06x nstate x%x nflag x%lx\n",
2393 ndlp->nlp_DID, ndlp->nlp_state,
2394 ndlp->nlp_flag);
2395 goto out;
2396 }
2397
2398 /*
2399 * For P2P topology, retain the node so that PLOGI can be
2400 * attempted on it again.
2401 */
2402 if (test_bit(FC_PT2PT, &vport->fc_flag))
2403 goto out;
2404
2405 /* As long as this node is not registered with the SCSI
2406 * or NVMe transport and no other PRLIs are outstanding,
2407 * it is no longer an active node. Otherwise devloss
2408 * handles the final cleanup.
2409 */
2410 spin_lock_irq(&ndlp->lock);
2411 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
2412 !ndlp->fc4_prli_sent) {
2413 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2414 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag))
2415 release_node = true;
2416 }
2417 spin_unlock_irq(&ndlp->lock);
2418
2419 if (release_node)
2420 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2421 NLP_EVT_DEVICE_RM);
2422 } else {
2423 /* Good status, call state machine. However, if another
2424 * PRLI is outstanding, don't call the state machine
2425 * because final disposition to Mapped or Unmapped is
2426 * completed there.
2427 */
2428 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2429 NLP_EVT_CMPL_PRLI);
2430 }
2431
2432 out:
2433 lpfc_els_free_iocb(phba, cmdiocb);
2434 lpfc_nlp_put(ndlp);
2435 return;
2436 }
2437
2438 /**
2439 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2440 * @vport: pointer to a host virtual N_Port data structure.
2441 * @ndlp: pointer to a node-list data structure.
2442 * @retry: number of retries to the command IOCB.
2443 *
2444 * This routine issues a Process Login (PRLI) ELS command for the
2445 * @vport. The PRLI service parameters are set up in the payload of the
2446 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2447 * is put to the IOCB completion callback func field before invoking the
2448 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2449 *
2450 * Note that the ndlp reference count will be incremented by 1 for holding the
2451 * ndlp and the reference to ndlp will be stored into the ndlp field of
2452 * the IOCB for the completion callback function to the PRLI ELS command.
2453 *
2454 * Return code
2455 * 0 - successfully issued prli iocb command for @vport
2456 * 1 - failed to issue prli iocb command for @vport
2457 **/
2458 int
lpfc_issue_els_prli(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)2459 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2460 uint8_t retry)
2461 {
2462 int rc = 0;
2463 struct lpfc_hba *phba = vport->phba;
2464 PRLI *npr;
2465 struct lpfc_nvme_prli *npr_nvme;
2466 struct lpfc_iocbq *elsiocb;
2467 uint8_t *pcmd;
2468 uint16_t cmdsize;
2469 u32 local_nlp_type, elscmd;
2470
2471 /*
2472 * If we are in RSCN mode, the FC4 types supported from a
2473 * previous GFT_ID command may not be accurate. So, if we
2474 * are a NVME Initiator, always look for the possibility of
2475 * the remote NPort beng a NVME Target.
2476 */
2477 if (phba->sli_rev == LPFC_SLI_REV4 &&
2478 test_bit(FC_RSCN_MODE, &vport->fc_flag) &&
2479 vport->nvmei_support)
2480 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2481 local_nlp_type = ndlp->nlp_fc4_type;
2482
2483 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2484 * fields here before any of them can complete.
2485 */
2486 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2487 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2488 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2489 clear_bit(NLP_FIRSTBURST, &ndlp->nlp_flag);
2490 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2491 ndlp->nvme_fb_size = 0;
2492
2493 send_next_prli:
2494 if (local_nlp_type & NLP_FC4_FCP) {
2495 /* Payload is 4 + 16 = 20 x14 bytes. */
2496 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2497 elscmd = ELS_CMD_PRLI;
2498 } else if (local_nlp_type & NLP_FC4_NVME) {
2499 /* Payload is 4 + 20 = 24 x18 bytes. */
2500 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2501 elscmd = ELS_CMD_NVMEPRLI;
2502 } else {
2503 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2504 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2505 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2506 return 1;
2507 }
2508
2509 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2510 * FC4 type, implicitly LOGO.
2511 */
2512 if (phba->sli_rev == LPFC_SLI_REV3 &&
2513 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2514 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2515 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2516 ndlp->nlp_type);
2517 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2518 return 1;
2519 }
2520
2521 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2522 ndlp->nlp_DID, elscmd);
2523 if (!elsiocb)
2524 return 1;
2525
2526 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2527
2528 /* For PRLI request, remainder of payload is service parameters */
2529 memset(pcmd, 0, cmdsize);
2530
2531 if (local_nlp_type & NLP_FC4_FCP) {
2532 /* Remainder of payload is FCP PRLI parameter page.
2533 * Note: this data structure is defined as
2534 * BE/LE in the structure definition so no
2535 * byte swap call is made.
2536 */
2537 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2538 pcmd += sizeof(uint32_t);
2539 npr = (PRLI *)pcmd;
2540
2541 /*
2542 * If our firmware version is 3.20 or later,
2543 * set the following bits for FC-TAPE support.
2544 */
2545 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2546 npr->ConfmComplAllowed = 1;
2547 npr->Retry = 1;
2548 npr->TaskRetryIdReq = 1;
2549 }
2550 npr->estabImagePair = 1;
2551 npr->readXferRdyDis = 1;
2552 if (vport->cfg_first_burst_size)
2553 npr->writeXferRdyDis = 1;
2554
2555 /* For FCP support */
2556 npr->prliType = PRLI_FCP_TYPE;
2557 npr->initiatorFunc = 1;
2558 elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ;
2559
2560 /* Remove FCP type - processed. */
2561 local_nlp_type &= ~NLP_FC4_FCP;
2562 } else if (local_nlp_type & NLP_FC4_NVME) {
2563 /* Remainder of payload is NVME PRLI parameter page.
2564 * This data structure is the newer definition that
2565 * uses bf macros so a byte swap is required.
2566 */
2567 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2568 pcmd += sizeof(uint32_t);
2569 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2570 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2571 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2572 if (phba->nsler) {
2573 bf_set(prli_nsler, npr_nvme, 1);
2574 bf_set(prli_conf, npr_nvme, 1);
2575 }
2576
2577 /* Only initiators request first burst. */
2578 if ((phba->cfg_nvme_enable_fb) &&
2579 !phba->nvmet_support)
2580 bf_set(prli_fba, npr_nvme, 1);
2581
2582 if (phba->nvmet_support) {
2583 bf_set(prli_tgt, npr_nvme, 1);
2584 bf_set(prli_disc, npr_nvme, 1);
2585 } else {
2586 bf_set(prli_init, npr_nvme, 1);
2587 bf_set(prli_conf, npr_nvme, 1);
2588 }
2589
2590 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2591 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2592 elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ;
2593
2594 /* Remove NVME type - processed. */
2595 local_nlp_type &= ~NLP_FC4_NVME;
2596 }
2597
2598 phba->fc_stat.elsXmitPRLI++;
2599 elsiocb->cmd_cmpl = lpfc_cmpl_els_prli;
2600
2601 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2602 "Issue PRLI: did:x%x refcnt %d",
2603 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2604 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2605 if (!elsiocb->ndlp) {
2606 lpfc_els_free_iocb(phba, elsiocb);
2607 return 1;
2608 }
2609
2610 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2611 if (rc == IOCB_ERROR) {
2612 lpfc_els_free_iocb(phba, elsiocb);
2613 lpfc_nlp_put(ndlp);
2614 return 1;
2615 }
2616
2617 /* The vport counters are used for lpfc_scan_finished, but
2618 * the ndlp is used to track outstanding PRLIs for different
2619 * FC4 types.
2620 */
2621 set_bit(NLP_PRLI_SND, &ndlp->nlp_flag);
2622 spin_lock_irq(&ndlp->lock);
2623 vport->fc_prli_sent++;
2624 ndlp->fc4_prli_sent++;
2625 spin_unlock_irq(&ndlp->lock);
2626
2627 /* The driver supports 2 FC4 types. Make sure
2628 * a PRLI is issued for all types before exiting.
2629 */
2630 if (phba->sli_rev == LPFC_SLI_REV4 &&
2631 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2632 goto send_next_prli;
2633 else
2634 return 0;
2635 }
2636
2637 /**
2638 * lpfc_rscn_disc - Perform rscn discovery for a vport
2639 * @vport: pointer to a host virtual N_Port data structure.
2640 *
2641 * This routine performs Registration State Change Notification (RSCN)
2642 * discovery for a @vport. If the @vport's node port recovery count is not
2643 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2644 * the nodes that need recovery. If none of the PLOGI were needed through
2645 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2646 * invoked to check and handle possible more RSCN came in during the period
2647 * of processing the current ones.
2648 **/
2649 static void
lpfc_rscn_disc(struct lpfc_vport * vport)2650 lpfc_rscn_disc(struct lpfc_vport *vport)
2651 {
2652 lpfc_can_disctmo(vport);
2653
2654 /* RSCN discovery */
2655 /* go thru NPR nodes and issue ELS PLOGIs */
2656 if (atomic_read(&vport->fc_npr_cnt))
2657 if (lpfc_els_disc_plogi(vport))
2658 return;
2659
2660 lpfc_end_rscn(vport);
2661 }
2662
2663 /**
2664 * lpfc_adisc_done - Complete the adisc phase of discovery
2665 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2666 *
2667 * This function is called when the final ADISC is completed during discovery.
2668 * This function handles clearing link attention or issuing reg_vpi depending
2669 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2670 * discovery.
2671 * This function is called with no locks held.
2672 **/
2673 static void
lpfc_adisc_done(struct lpfc_vport * vport)2674 lpfc_adisc_done(struct lpfc_vport *vport)
2675 {
2676 struct lpfc_hba *phba = vport->phba;
2677
2678 /*
2679 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2680 * and continue discovery.
2681 */
2682 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2683 !test_bit(FC_RSCN_MODE, &vport->fc_flag) &&
2684 (phba->sli_rev < LPFC_SLI_REV4)) {
2685
2686 /*
2687 * If link is down, clear_la and reg_vpi will be done after
2688 * flogi following a link up event
2689 */
2690 if (!lpfc_is_link_up(phba))
2691 return;
2692
2693 /* The ADISCs are complete. Doesn't matter if they
2694 * succeeded or failed because the ADISC completion
2695 * routine guarantees to call the state machine and
2696 * the RPI is either unregistered (failed ADISC response)
2697 * or the RPI is still valid and the node is marked
2698 * mapped for a target. The exchanges should be in the
2699 * correct state. This code is specific to SLI3.
2700 */
2701 lpfc_issue_clear_la(phba, vport);
2702 lpfc_issue_reg_vpi(phba, vport);
2703 return;
2704 }
2705 /*
2706 * For SLI2, we need to set port_state to READY
2707 * and continue discovery.
2708 */
2709 if (vport->port_state < LPFC_VPORT_READY) {
2710 /* If we get here, there is nothing to ADISC */
2711 lpfc_issue_clear_la(phba, vport);
2712 if (!test_bit(FC_ABORT_DISCOVERY, &vport->fc_flag)) {
2713 vport->num_disc_nodes = 0;
2714 /* go thru NPR list, issue ELS PLOGIs */
2715 if (atomic_read(&vport->fc_npr_cnt))
2716 lpfc_els_disc_plogi(vport);
2717 if (!vport->num_disc_nodes) {
2718 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
2719 lpfc_can_disctmo(vport);
2720 lpfc_end_rscn(vport);
2721 }
2722 }
2723 vport->port_state = LPFC_VPORT_READY;
2724 } else
2725 lpfc_rscn_disc(vport);
2726 }
2727
2728 /**
2729 * lpfc_more_adisc - Issue more adisc as needed
2730 * @vport: pointer to a host virtual N_Port data structure.
2731 *
2732 * This routine determines whether there are more ndlps on a @vport
2733 * node list need to have Address Discover (ADISC) issued. If so, it will
2734 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2735 * remaining nodes which need to have ADISC sent.
2736 **/
2737 void
lpfc_more_adisc(struct lpfc_vport * vport)2738 lpfc_more_adisc(struct lpfc_vport *vport)
2739 {
2740 if (vport->num_disc_nodes)
2741 vport->num_disc_nodes--;
2742 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2744 "0210 Continue discovery with %d ADISCs to go "
2745 "Data: x%x x%lx x%x\n",
2746 vport->num_disc_nodes,
2747 atomic_read(&vport->fc_adisc_cnt),
2748 vport->fc_flag, vport->port_state);
2749 /* Check to see if there are more ADISCs to be sent */
2750 if (test_bit(FC_NLP_MORE, &vport->fc_flag)) {
2751 lpfc_set_disctmo(vport);
2752 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2753 lpfc_els_disc_adisc(vport);
2754 }
2755 if (!vport->num_disc_nodes)
2756 lpfc_adisc_done(vport);
2757 return;
2758 }
2759
2760 /**
2761 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2762 * @phba: pointer to lpfc hba data structure.
2763 * @cmdiocb: pointer to lpfc command iocb data structure.
2764 * @rspiocb: pointer to lpfc response iocb data structure.
2765 *
2766 * This routine is the completion function for issuing the Address Discover
2767 * (ADISC) command. It first checks to see whether link went down during
2768 * the discovery process. If so, the node will be marked as node port
2769 * recovery for issuing discover IOCB by the link attention handler and
2770 * exit. Otherwise, the response status is checked. If error was reported
2771 * in the response status, the ADISC command shall be retried by invoking
2772 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2773 * the response status, the state machine is invoked to set transition
2774 * with respect to NLP_EVT_CMPL_ADISC event.
2775 **/
2776 static void
lpfc_cmpl_els_adisc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2777 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2778 struct lpfc_iocbq *rspiocb)
2779 {
2780 struct lpfc_vport *vport = cmdiocb->vport;
2781 IOCB_t *irsp;
2782 struct lpfc_nodelist *ndlp;
2783 bool disc;
2784 u32 ulp_status, ulp_word4, tmo, iotag;
2785 bool release_node = false;
2786
2787 /* we pass cmdiocb to state machine which needs rspiocb as well */
2788 cmdiocb->rsp_iocb = rspiocb;
2789
2790 ndlp = cmdiocb->ndlp;
2791
2792 ulp_status = get_job_ulpstatus(phba, rspiocb);
2793 ulp_word4 = get_job_word4(phba, rspiocb);
2794
2795 if (phba->sli_rev == LPFC_SLI_REV4) {
2796 tmo = get_wqe_tmo(cmdiocb);
2797 iotag = get_wqe_reqtag(cmdiocb);
2798 } else {
2799 irsp = &rspiocb->iocb;
2800 tmo = irsp->ulpTimeout;
2801 iotag = irsp->ulpIoTag;
2802 }
2803
2804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2805 "ADISC cmpl: status:x%x/x%x did:x%x",
2806 ulp_status, ulp_word4,
2807 ndlp->nlp_DID);
2808
2809 /* Since ndlp can be freed in the disc state machine, note if this node
2810 * is being used during discovery.
2811 */
2812 disc = test_and_clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2813 clear_bit(NLP_ADISC_SND, &ndlp->nlp_flag);
2814 /* ADISC completes to NPort <nlp_DID> */
2815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2816 "0104 ADISC completes to NPort x%x "
2817 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2818 ndlp->nlp_DID, iotag,
2819 ulp_status, ulp_word4,
2820 tmo, disc, vport->num_disc_nodes);
2821
2822 /* Check to see if link went down during discovery */
2823 if (lpfc_els_chk_latt(vport)) {
2824 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2825 goto out;
2826 }
2827
2828 if (ulp_status) {
2829 /* Check for retry */
2830 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2831 /* ELS command is being retried */
2832 if (disc) {
2833 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2834 lpfc_set_disctmo(vport);
2835 }
2836 goto out;
2837 }
2838 /* Warn ADISC status */
2839 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
2840 "2755 ADISC DID:%06X Status:x%x/x%x\n",
2841 ndlp->nlp_DID, ulp_status,
2842 ulp_word4);
2843 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2844 NLP_EVT_CMPL_ADISC);
2845
2846 /* As long as this node is not registered with the SCSI or NVMe
2847 * transport, it is no longer an active node. Otherwise
2848 * devloss handles the final cleanup.
2849 */
2850 spin_lock_irq(&ndlp->lock);
2851 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
2852 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
2853 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag))
2854 release_node = true;
2855 }
2856 spin_unlock_irq(&ndlp->lock);
2857
2858 if (release_node)
2859 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2860 NLP_EVT_DEVICE_RM);
2861 } else
2862 /* Good status, call state machine */
2863 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2864 NLP_EVT_CMPL_ADISC);
2865
2866 /* Check to see if there are more ADISCs to be sent */
2867 if (disc && vport->num_disc_nodes)
2868 lpfc_more_adisc(vport);
2869 out:
2870 lpfc_els_free_iocb(phba, cmdiocb);
2871 lpfc_nlp_put(ndlp);
2872 return;
2873 }
2874
2875 /**
2876 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2877 * @vport: pointer to a virtual N_Port data structure.
2878 * @ndlp: pointer to a node-list data structure.
2879 * @retry: number of retries to the command IOCB.
2880 *
2881 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2882 * @vport. It prepares the payload of the ADISC ELS command, updates the
2883 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2884 * to issue the ADISC ELS command.
2885 *
2886 * Note that the ndlp reference count will be incremented by 1 for holding the
2887 * ndlp and the reference to ndlp will be stored into the ndlp field of
2888 * the IOCB for the completion callback function to the ADISC ELS command.
2889 *
2890 * Return code
2891 * 0 - successfully issued adisc
2892 * 1 - failed to issue adisc
2893 **/
2894 int
lpfc_issue_els_adisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)2895 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2896 uint8_t retry)
2897 {
2898 int rc = 0;
2899 struct lpfc_hba *phba = vport->phba;
2900 ADISC *ap;
2901 struct lpfc_iocbq *elsiocb;
2902 uint8_t *pcmd;
2903 uint16_t cmdsize;
2904
2905 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2906 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2907 ndlp->nlp_DID, ELS_CMD_ADISC);
2908 if (!elsiocb)
2909 return 1;
2910
2911 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
2912
2913 /* For ADISC request, remainder of payload is service parameters */
2914 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2915 pcmd += sizeof(uint32_t);
2916
2917 /* Fill in ADISC payload */
2918 ap = (ADISC *) pcmd;
2919 ap->hardAL_PA = phba->fc_pref_ALPA;
2920 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2921 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2922 ap->DID = be32_to_cpu(vport->fc_myDID);
2923
2924 phba->fc_stat.elsXmitADISC++;
2925 elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc;
2926 set_bit(NLP_ADISC_SND, &ndlp->nlp_flag);
2927 elsiocb->ndlp = lpfc_nlp_get(ndlp);
2928 if (!elsiocb->ndlp) {
2929 lpfc_els_free_iocb(phba, elsiocb);
2930 goto err;
2931 }
2932
2933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2934 "Issue ADISC: did:x%x refcnt %d",
2935 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
2936
2937 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2938 if (rc == IOCB_ERROR) {
2939 lpfc_els_free_iocb(phba, elsiocb);
2940 lpfc_nlp_put(ndlp);
2941 goto err;
2942 }
2943
2944 return 0;
2945
2946 err:
2947 clear_bit(NLP_ADISC_SND, &ndlp->nlp_flag);
2948 return 1;
2949 }
2950
2951 /**
2952 * lpfc_cmpl_els_logo - Completion callback function for logo
2953 * @phba: pointer to lpfc hba data structure.
2954 * @cmdiocb: pointer to lpfc command iocb data structure.
2955 * @rspiocb: pointer to lpfc response iocb data structure.
2956 *
2957 * This routine is the completion function for issuing the ELS Logout (LOGO)
2958 * command. If no error status was reported from the LOGO response, the
2959 * state machine of the associated ndlp shall be invoked for transition with
2960 * respect to NLP_EVT_CMPL_LOGO event.
2961 **/
2962 static void
lpfc_cmpl_els_logo(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2963 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2964 struct lpfc_iocbq *rspiocb)
2965 {
2966 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
2967 struct lpfc_vport *vport = ndlp->vport;
2968 IOCB_t *irsp;
2969 uint32_t skip_recovery = 0;
2970 int wake_up_waiter = 0;
2971 u32 ulp_status;
2972 u32 ulp_word4;
2973 u32 tmo, iotag;
2974
2975 /* we pass cmdiocb to state machine which needs rspiocb as well */
2976 cmdiocb->rsp_iocb = rspiocb;
2977
2978 ulp_status = get_job_ulpstatus(phba, rspiocb);
2979 ulp_word4 = get_job_word4(phba, rspiocb);
2980
2981 if (phba->sli_rev == LPFC_SLI_REV4) {
2982 tmo = get_wqe_tmo(cmdiocb);
2983 iotag = get_wqe_reqtag(cmdiocb);
2984 } else {
2985 irsp = &rspiocb->iocb;
2986 tmo = irsp->ulpTimeout;
2987 iotag = irsp->ulpIoTag;
2988 }
2989
2990 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
2991 if (test_and_clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags))
2992 wake_up_waiter = 1;
2993
2994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2995 "LOGO cmpl: status:x%x/x%x did:x%x",
2996 ulp_status, ulp_word4,
2997 ndlp->nlp_DID);
2998
2999 /* LOGO completes to NPort <nlp_DID> */
3000 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3001 "0105 LOGO completes to NPort x%x "
3002 "IoTag x%x refcnt %d nflags x%lx xflags x%x "
3003 "Data: x%x x%x x%x x%x\n",
3004 ndlp->nlp_DID, iotag,
3005 kref_read(&ndlp->kref), ndlp->nlp_flag,
3006 ndlp->fc4_xpt_flags, ulp_status, ulp_word4,
3007 tmo, vport->num_disc_nodes);
3008
3009 if (lpfc_els_chk_latt(vport)) {
3010 skip_recovery = 1;
3011 goto out;
3012 }
3013
3014 /* The LOGO will not be retried on failure. A LOGO was
3015 * issued to the remote rport and a ACC or RJT or no Answer are
3016 * all acceptable. Note the failure and move forward with
3017 * discovery. The PLOGI will retry.
3018 */
3019 if (ulp_status) {
3020 /* Warn LOGO status */
3021 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
3022 "2756 LOGO, No Retry DID:%06X "
3023 "Status:x%x/x%x\n",
3024 ndlp->nlp_DID, ulp_status,
3025 ulp_word4);
3026
3027 if (lpfc_error_lost_link(vport, ulp_status, ulp_word4))
3028 skip_recovery = 1;
3029 }
3030
3031 /* Call state machine. This will unregister the rpi if needed. */
3032 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
3033
3034 out:
3035 /* At this point, the LOGO processing is complete. NOTE: For a
3036 * pt2pt topology, we are assuming the NPortID will only change
3037 * on link up processing. For a LOGO / PLOGI initiated by the
3038 * Initiator, we are assuming the NPortID is not going to change.
3039 */
3040
3041 if (wake_up_waiter && ndlp->logo_waitq)
3042 wake_up(ndlp->logo_waitq);
3043 /*
3044 * If the node is a target, the handling attempts to recover the port.
3045 * For any other port type, the rpi is unregistered as an implicit
3046 * LOGO.
3047 */
3048 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
3049 skip_recovery == 0) {
3050 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3051 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
3052
3053 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3054 "3187 LOGO completes to NPort x%x: Start "
3055 "Recovery Data: x%x x%x x%x x%x\n",
3056 ndlp->nlp_DID, ulp_status,
3057 ulp_word4, tmo,
3058 vport->num_disc_nodes);
3059
3060 lpfc_els_free_iocb(phba, cmdiocb);
3061 lpfc_nlp_put(ndlp);
3062
3063 lpfc_disc_start(vport);
3064 return;
3065 }
3066
3067 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3068 * driver sends a LOGO to the rport to cleanup. For fabric and
3069 * initiator ports cleanup the node as long as it the node is not
3070 * register with the transport.
3071 */
3072 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
3073 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
3074 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3075 NLP_EVT_DEVICE_RM);
3076 }
3077
3078 /* Driver is done with the I/O. */
3079 lpfc_els_free_iocb(phba, cmdiocb);
3080 lpfc_nlp_put(ndlp);
3081 }
3082
3083 /**
3084 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3085 * @vport: pointer to a virtual N_Port data structure.
3086 * @ndlp: pointer to a node-list data structure.
3087 * @retry: number of retries to the command IOCB.
3088 *
3089 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3090 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3091 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3092 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3093 *
3094 * Note that the ndlp reference count will be incremented by 1 for holding the
3095 * ndlp and the reference to ndlp will be stored into the ndlp field of
3096 * the IOCB for the completion callback function to the LOGO ELS command.
3097 *
3098 * Callers of this routine are expected to unregister the RPI first
3099 *
3100 * Return code
3101 * 0 - successfully issued logo
3102 * 1 - failed to issue logo
3103 **/
3104 int
lpfc_issue_els_logo(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)3105 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3106 uint8_t retry)
3107 {
3108 struct lpfc_hba *phba = vport->phba;
3109 struct lpfc_iocbq *elsiocb;
3110 uint8_t *pcmd;
3111 uint16_t cmdsize;
3112 int rc;
3113
3114 if (test_bit(NLP_LOGO_SND, &ndlp->nlp_flag))
3115 return 0;
3116
3117 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
3118 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3119 ndlp->nlp_DID, ELS_CMD_LOGO);
3120 if (!elsiocb)
3121 return 1;
3122
3123 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3124 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
3125 pcmd += sizeof(uint32_t);
3126
3127 /* Fill in LOGO payload */
3128 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
3129 pcmd += sizeof(uint32_t);
3130 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
3131
3132 phba->fc_stat.elsXmitLOGO++;
3133 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo;
3134 set_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
3135 clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
3136 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3137 if (!elsiocb->ndlp) {
3138 lpfc_els_free_iocb(phba, elsiocb);
3139 goto err;
3140 }
3141
3142 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3143 "Issue LOGO: did:x%x refcnt %d",
3144 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3145
3146 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3147 if (rc == IOCB_ERROR) {
3148 lpfc_els_free_iocb(phba, elsiocb);
3149 lpfc_nlp_put(ndlp);
3150 goto err;
3151 }
3152
3153 spin_lock_irq(&ndlp->lock);
3154 ndlp->nlp_prev_state = ndlp->nlp_state;
3155 spin_unlock_irq(&ndlp->lock);
3156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3157 return 0;
3158
3159 err:
3160 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
3161 return 1;
3162 }
3163
3164 /**
3165 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3166 * @phba: pointer to lpfc hba data structure.
3167 * @cmdiocb: pointer to lpfc command iocb data structure.
3168 * @rspiocb: pointer to lpfc response iocb data structure.
3169 *
3170 * This routine is a generic completion callback function for ELS commands.
3171 * Specifically, it is the callback function which does not need to perform
3172 * any command specific operations. It is currently used by the ELS command
3173 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3174 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3175 * Other than certain debug loggings, this callback function simply invokes the
3176 * lpfc_els_chk_latt() routine to check whether link went down during the
3177 * discovery process.
3178 **/
3179 static void
lpfc_cmpl_els_cmd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3180 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3181 struct lpfc_iocbq *rspiocb)
3182 {
3183 struct lpfc_vport *vport = cmdiocb->vport;
3184 struct lpfc_nodelist *free_ndlp;
3185 IOCB_t *irsp;
3186 u32 ulp_status, ulp_word4, tmo, did, iotag;
3187
3188 ulp_status = get_job_ulpstatus(phba, rspiocb);
3189 ulp_word4 = get_job_word4(phba, rspiocb);
3190 did = get_job_els_rsp64_did(phba, cmdiocb);
3191
3192 if (phba->sli_rev == LPFC_SLI_REV4) {
3193 tmo = get_wqe_tmo(cmdiocb);
3194 iotag = get_wqe_reqtag(cmdiocb);
3195 } else {
3196 irsp = &rspiocb->iocb;
3197 tmo = irsp->ulpTimeout;
3198 iotag = irsp->ulpIoTag;
3199 }
3200
3201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3202 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3203 ulp_status, ulp_word4, did);
3204
3205 /* ELS cmd tag <ulpIoTag> completes */
3206 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3207 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3208 iotag, ulp_status, ulp_word4, tmo);
3209
3210 /* Check to see if link went down during discovery */
3211 lpfc_els_chk_latt(vport);
3212
3213 free_ndlp = cmdiocb->ndlp;
3214
3215 lpfc_els_free_iocb(phba, cmdiocb);
3216 lpfc_nlp_put(free_ndlp);
3217 }
3218
3219 /**
3220 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3221 * @vport: pointer to lpfc_vport data structure.
3222 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3223 *
3224 * This routine registers the rpi assigned to the fabric controller
3225 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3226 * state triggering a registration with the SCSI transport.
3227 *
3228 * This routine is single out because the fabric controller node
3229 * does not receive a PLOGI. This routine is consumed by the
3230 * SCR and RDF ELS commands. Callers are expected to qualify
3231 * with SLI4 first.
3232 **/
3233 static int
lpfc_reg_fab_ctrl_node(struct lpfc_vport * vport,struct lpfc_nodelist * fc_ndlp)3234 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
3235 {
3236 int rc;
3237 struct lpfc_hba *phba = vport->phba;
3238 struct lpfc_nodelist *ns_ndlp;
3239 LPFC_MBOXQ_t *mbox;
3240
3241 if (test_bit(NLP_RPI_REGISTERED, &fc_ndlp->nlp_flag))
3242 return 0;
3243
3244 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
3245 if (!ns_ndlp)
3246 return -ENODEV;
3247
3248 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3249 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3250 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
3251 ns_ndlp->nlp_state);
3252 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3253 return -ENODEV;
3254
3255 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3256 if (!mbox) {
3257 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3258 "0936 %s: no memory for reg_login "
3259 "Data: x%x x%x x%lx x%x\n", __func__,
3260 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3261 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3262 return -ENOMEM;
3263 }
3264 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
3265 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
3266 if (rc) {
3267 rc = -EACCES;
3268 goto out;
3269 }
3270
3271 set_bit(NLP_REG_LOGIN_SEND, &fc_ndlp->nlp_flag);
3272 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
3273 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
3274 if (!mbox->ctx_ndlp) {
3275 rc = -ENOMEM;
3276 goto out;
3277 }
3278
3279 mbox->vport = vport;
3280 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3281 if (rc == MBX_NOT_FINISHED) {
3282 rc = -ENODEV;
3283 lpfc_nlp_put(fc_ndlp);
3284 goto out;
3285 }
3286 /* Success path. Exit. */
3287 lpfc_nlp_set_state(vport, fc_ndlp,
3288 NLP_STE_REG_LOGIN_ISSUE);
3289 return 0;
3290
3291 out:
3292 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
3293 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3294 "0938 %s: failed to format reg_login "
3295 "Data: x%x x%x x%lx x%x\n", __func__,
3296 fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
3297 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
3298 return rc;
3299 }
3300
3301 /**
3302 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3303 * @phba: pointer to lpfc hba data structure.
3304 * @cmdiocb: pointer to lpfc command iocb data structure.
3305 * @rspiocb: pointer to lpfc response iocb data structure.
3306 *
3307 * This routine is a generic completion callback function for Discovery ELS cmd.
3308 * Currently used by the ELS command issuing routines for the ELS State Change
3309 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3310 * These commands will be retried once only for ELS timeout errors.
3311 **/
3312 static void
lpfc_cmpl_els_disc_cmd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3313 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3314 struct lpfc_iocbq *rspiocb)
3315 {
3316 struct lpfc_vport *vport = cmdiocb->vport;
3317 IOCB_t *irsp;
3318 struct lpfc_els_rdf_rsp *prdf;
3319 struct lpfc_dmabuf *pcmd, *prsp;
3320 u32 *pdata;
3321 u32 cmd;
3322 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
3323 u32 ulp_status, ulp_word4, tmo, did, iotag;
3324
3325 ulp_status = get_job_ulpstatus(phba, rspiocb);
3326 ulp_word4 = get_job_word4(phba, rspiocb);
3327 did = get_job_els_rsp64_did(phba, cmdiocb);
3328
3329 if (phba->sli_rev == LPFC_SLI_REV4) {
3330 tmo = get_wqe_tmo(cmdiocb);
3331 iotag = get_wqe_reqtag(cmdiocb);
3332 } else {
3333 irsp = &rspiocb->iocb;
3334 tmo = irsp->ulpTimeout;
3335 iotag = irsp->ulpIoTag;
3336 }
3337
3338 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3339 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3340 ulp_status, ulp_word4, did);
3341
3342 /* ELS cmd tag <ulpIoTag> completes */
3343 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3344 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
3345 iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry);
3346
3347 pcmd = cmdiocb->cmd_dmabuf;
3348 if (!pcmd)
3349 goto out;
3350
3351 pdata = (u32 *)pcmd->virt;
3352 if (!pdata)
3353 goto out;
3354 cmd = *pdata;
3355
3356 /* Only 1 retry for ELS Timeout only */
3357 if (ulp_status == IOSTAT_LOCAL_REJECT &&
3358 ((ulp_word4 & IOERR_PARAM_MASK) ==
3359 IOERR_SEQUENCE_TIMEOUT)) {
3360 cmdiocb->retry++;
3361 if (cmdiocb->retry <= 1) {
3362 switch (cmd) {
3363 case ELS_CMD_SCR:
3364 lpfc_issue_els_scr(vport, cmdiocb->retry);
3365 break;
3366 case ELS_CMD_EDC:
3367 lpfc_issue_els_edc(vport, cmdiocb->retry);
3368 break;
3369 case ELS_CMD_RDF:
3370 lpfc_issue_els_rdf(vport, cmdiocb->retry);
3371 break;
3372 }
3373 goto out;
3374 }
3375 phba->fc_stat.elsRetryExceeded++;
3376 }
3377 if (cmd == ELS_CMD_EDC) {
3378 /* must be called before checking uplStatus and returning */
3379 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb);
3380 return;
3381 }
3382 if (ulp_status) {
3383 /* ELS discovery cmd completes with error */
3384 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
3385 "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3386 ulp_status, ulp_word4);
3387 goto out;
3388 }
3389
3390 /* The RDF response doesn't have any impact on the running driver
3391 * but the notification descriptors are dumped here for support.
3392 */
3393 if (cmd == ELS_CMD_RDF) {
3394 int i;
3395
3396 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3397 if (!prsp)
3398 goto out;
3399
3400 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3401 if (!prdf)
3402 goto out;
3403 if (!lpfc_is_els_acc_rsp(prsp))
3404 goto out;
3405
3406 for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3407 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3408 lpfc_printf_vlog(vport, KERN_INFO,
3409 LOG_ELS | LOG_CGN_MGMT,
3410 "4677 Fabric RDF Notification Grant "
3411 "Data: 0x%08x Reg: %x %x\n",
3412 be32_to_cpu(
3413 prdf->reg_d1.desc_tags[i]),
3414 phba->cgn_reg_signal,
3415 phba->cgn_reg_fpin);
3416 }
3417
3418 out:
3419 /* Check to see if link went down during discovery */
3420 lpfc_els_chk_latt(vport);
3421 lpfc_els_free_iocb(phba, cmdiocb);
3422 lpfc_nlp_put(ndlp);
3423 return;
3424 }
3425
3426 /**
3427 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3428 * @vport: pointer to a host virtual N_Port data structure.
3429 * @retry: retry counter for the command IOCB.
3430 *
3431 * This routine issues a State Change Request (SCR) to a fabric node
3432 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3433 * first search the @vport node list to find the matching ndlp. If no such
3434 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3435 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3436 * routine is invoked to send the SCR IOCB.
3437 *
3438 * Note that the ndlp reference count will be incremented by 1 for holding the
3439 * ndlp and the reference to ndlp will be stored into the ndlp field of
3440 * the IOCB for the completion callback function to the SCR ELS command.
3441 *
3442 * Return code
3443 * 0 - Successfully issued scr command
3444 * 1 - Failed to issue scr command
3445 **/
3446 int
lpfc_issue_els_scr(struct lpfc_vport * vport,uint8_t retry)3447 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3448 {
3449 int rc = 0;
3450 struct lpfc_hba *phba = vport->phba;
3451 struct lpfc_iocbq *elsiocb;
3452 uint8_t *pcmd;
3453 uint16_t cmdsize;
3454 struct lpfc_nodelist *ndlp;
3455
3456 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3457
3458 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3459 if (!ndlp) {
3460 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3461 if (!ndlp)
3462 return 1;
3463 lpfc_enqueue_node(vport, ndlp);
3464 }
3465
3466 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3467 ndlp->nlp_DID, ELS_CMD_SCR);
3468 if (!elsiocb)
3469 return 1;
3470
3471 if (phba->sli_rev == LPFC_SLI_REV4) {
3472 rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
3473 if (rc) {
3474 lpfc_els_free_iocb(phba, elsiocb);
3475 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3476 "0937 %s: Failed to reg fc node, rc %d\n",
3477 __func__, rc);
3478 return 1;
3479 }
3480 }
3481 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3482
3483 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3484 pcmd += sizeof(uint32_t);
3485
3486 /* For SCR, remainder of payload is SCR parameter page */
3487 memset(pcmd, 0, sizeof(SCR));
3488 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3489
3490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3491 "Issue SCR: did:x%x",
3492 ndlp->nlp_DID, 0, 0);
3493
3494 phba->fc_stat.elsXmitSCR++;
3495 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3496 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3497 if (!elsiocb->ndlp) {
3498 lpfc_els_free_iocb(phba, elsiocb);
3499 return 1;
3500 }
3501
3502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3503 "Issue SCR: did:x%x refcnt %d",
3504 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3505
3506 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3507 if (rc == IOCB_ERROR) {
3508 lpfc_els_free_iocb(phba, elsiocb);
3509 lpfc_nlp_put(ndlp);
3510 return 1;
3511 }
3512
3513 return 0;
3514 }
3515
3516 /**
3517 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3518 * or the other nport (pt2pt).
3519 * @vport: pointer to a host virtual N_Port data structure.
3520 * @retry: number of retries to the command IOCB.
3521 *
3522 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3523 * when connected to a fabric, or to the remote port when connected
3524 * in point-to-point mode. When sent to the Fabric Controller, it will
3525 * replay the RSCN to registered recipients.
3526 *
3527 * Note that the ndlp reference count will be incremented by 1 for holding the
3528 * ndlp and the reference to ndlp will be stored into the ndlp field of
3529 * the IOCB for the completion callback function to the RSCN ELS command.
3530 *
3531 * Return code
3532 * 0 - Successfully issued RSCN command
3533 * 1 - Failed to issue RSCN command
3534 **/
3535 int
lpfc_issue_els_rscn(struct lpfc_vport * vport,uint8_t retry)3536 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3537 {
3538 int rc = 0;
3539 struct lpfc_hba *phba = vport->phba;
3540 struct lpfc_iocbq *elsiocb;
3541 struct lpfc_nodelist *ndlp;
3542 struct {
3543 struct fc_els_rscn rscn;
3544 struct fc_els_rscn_page portid;
3545 } *event;
3546 uint32_t nportid;
3547 uint16_t cmdsize = sizeof(*event);
3548
3549 /* Not supported for private loop */
3550 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3551 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
3552 return 1;
3553
3554 if (test_bit(FC_PT2PT, &vport->fc_flag)) {
3555 /* find any mapped nport - that would be the other nport */
3556 ndlp = lpfc_findnode_mapped(vport);
3557 if (!ndlp)
3558 return 1;
3559 } else {
3560 nportid = FC_FID_FCTRL;
3561 /* find the fabric controller node */
3562 ndlp = lpfc_findnode_did(vport, nportid);
3563 if (!ndlp) {
3564 /* if one didn't exist, make one */
3565 ndlp = lpfc_nlp_init(vport, nportid);
3566 if (!ndlp)
3567 return 1;
3568 lpfc_enqueue_node(vport, ndlp);
3569 }
3570 }
3571
3572 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3573 ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3574
3575 if (!elsiocb)
3576 return 1;
3577
3578 event = elsiocb->cmd_dmabuf->virt;
3579
3580 event->rscn.rscn_cmd = ELS_RSCN;
3581 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3582 event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3583
3584 nportid = vport->fc_myDID;
3585 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3586 event->portid.rscn_page_flags = 0;
3587 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3588 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3589 event->portid.rscn_fid[2] = nportid & 0x000000FF;
3590
3591 phba->fc_stat.elsXmitRSCN++;
3592 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3593 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3594 if (!elsiocb->ndlp) {
3595 lpfc_els_free_iocb(phba, elsiocb);
3596 return 1;
3597 }
3598
3599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3600 "Issue RSCN: did:x%x",
3601 ndlp->nlp_DID, 0, 0);
3602
3603 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3604 if (rc == IOCB_ERROR) {
3605 lpfc_els_free_iocb(phba, elsiocb);
3606 lpfc_nlp_put(ndlp);
3607 return 1;
3608 }
3609
3610 return 0;
3611 }
3612
3613 /**
3614 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3615 * @vport: pointer to a host virtual N_Port data structure.
3616 * @nportid: N_Port identifier to the remote node.
3617 * @retry: number of retries to the command IOCB.
3618 *
3619 * This routine issues a Fibre Channel Address Resolution Response
3620 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3621 * is passed into the function. It first search the @vport node list to find
3622 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3623 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3624 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3625 *
3626 * Note that the ndlp reference count will be incremented by 1 for holding the
3627 * ndlp and the reference to ndlp will be stored into the ndlp field of
3628 * the IOCB for the completion callback function to the FARPR ELS command.
3629 *
3630 * Return code
3631 * 0 - Successfully issued farpr command
3632 * 1 - Failed to issue farpr command
3633 **/
3634 static int
lpfc_issue_els_farpr(struct lpfc_vport * vport,uint32_t nportid,uint8_t retry)3635 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3636 {
3637 int rc = 0;
3638 struct lpfc_hba *phba = vport->phba;
3639 struct lpfc_iocbq *elsiocb;
3640 FARP *fp;
3641 uint8_t *pcmd;
3642 uint32_t *lp;
3643 uint16_t cmdsize;
3644 struct lpfc_nodelist *ondlp;
3645 struct lpfc_nodelist *ndlp;
3646
3647 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3648
3649 ndlp = lpfc_findnode_did(vport, nportid);
3650 if (!ndlp) {
3651 ndlp = lpfc_nlp_init(vport, nportid);
3652 if (!ndlp)
3653 return 1;
3654 lpfc_enqueue_node(vport, ndlp);
3655 }
3656
3657 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3658 ndlp->nlp_DID, ELS_CMD_FARPR);
3659 if (!elsiocb)
3660 return 1;
3661
3662 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
3663
3664 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3665 pcmd += sizeof(uint32_t);
3666
3667 /* Fill in FARPR payload */
3668 fp = (FARP *) (pcmd);
3669 memset(fp, 0, sizeof(FARP));
3670 lp = (uint32_t *) pcmd;
3671 *lp++ = be32_to_cpu(nportid);
3672 *lp++ = be32_to_cpu(vport->fc_myDID);
3673 fp->Rflags = 0;
3674 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3675
3676 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3677 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3678 ondlp = lpfc_findnode_did(vport, nportid);
3679 if (ondlp) {
3680 memcpy(&fp->OportName, &ondlp->nlp_portname,
3681 sizeof(struct lpfc_name));
3682 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3683 sizeof(struct lpfc_name));
3684 }
3685
3686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3687 "Issue FARPR: did:x%x",
3688 ndlp->nlp_DID, 0, 0);
3689
3690 phba->fc_stat.elsXmitFARPR++;
3691 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
3692 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3693 if (!elsiocb->ndlp) {
3694 lpfc_els_free_iocb(phba, elsiocb);
3695 return 1;
3696 }
3697
3698 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3699 if (rc == IOCB_ERROR) {
3700 /* The additional lpfc_nlp_put will cause the following
3701 * lpfc_els_free_iocb routine to trigger the release of
3702 * the node.
3703 */
3704 lpfc_els_free_iocb(phba, elsiocb);
3705 lpfc_nlp_put(ndlp);
3706 return 1;
3707 }
3708 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3709 * trigger the release of the node.
3710 */
3711 /* Don't release reference count as RDF is likely outstanding */
3712 return 0;
3713 }
3714
3715 /**
3716 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3717 * @vport: pointer to a host virtual N_Port data structure.
3718 * @retry: retry counter for the command IOCB.
3719 *
3720 * This routine issues an ELS RDF to the Fabric Controller to register
3721 * for diagnostic functions.
3722 *
3723 * Note that the ndlp reference count will be incremented by 1 for holding the
3724 * ndlp and the reference to ndlp will be stored into the ndlp field of
3725 * the IOCB for the completion callback function to the RDF ELS command.
3726 *
3727 * Return code
3728 * 0 - Successfully issued rdf command
3729 * 1 - Failed to issue rdf command
3730 **/
3731 int
lpfc_issue_els_rdf(struct lpfc_vport * vport,uint8_t retry)3732 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3733 {
3734 struct lpfc_hba *phba = vport->phba;
3735 struct lpfc_iocbq *elsiocb;
3736 struct lpfc_els_rdf_req *prdf;
3737 struct lpfc_nodelist *ndlp;
3738 uint16_t cmdsize;
3739 int rc;
3740
3741 cmdsize = sizeof(*prdf);
3742
3743 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3744 if (!ndlp) {
3745 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3746 if (!ndlp)
3747 return -ENODEV;
3748 lpfc_enqueue_node(vport, ndlp);
3749 }
3750
3751 /* RDF ELS is not required on an NPIV VN_Port. */
3752 if (vport->port_type == LPFC_NPIV_PORT)
3753 return -EACCES;
3754
3755 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3756 ndlp->nlp_DID, ELS_CMD_RDF);
3757 if (!elsiocb)
3758 return -ENOMEM;
3759
3760 /* Configure the payload for the supported FPIN events. */
3761 prdf = (struct lpfc_els_rdf_req *)elsiocb->cmd_dmabuf->virt;
3762 memset(prdf, 0, cmdsize);
3763 prdf->rdf.fpin_cmd = ELS_RDF;
3764 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3765 sizeof(struct fc_els_rdf));
3766 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3767 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3768 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3769 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3770 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3771 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3772 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3773 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3774
3775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3776 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3777 ndlp->nlp_DID, phba->cgn_reg_signal,
3778 phba->cgn_reg_fpin);
3779
3780 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
3781 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
3782 elsiocb->ndlp = lpfc_nlp_get(ndlp);
3783 if (!elsiocb->ndlp) {
3784 lpfc_els_free_iocb(phba, elsiocb);
3785 return -EIO;
3786 }
3787
3788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3789 "Issue RDF: did:x%x refcnt %d",
3790 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
3791
3792 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3793 if (rc == IOCB_ERROR) {
3794 lpfc_els_free_iocb(phba, elsiocb);
3795 lpfc_nlp_put(ndlp);
3796 return -EIO;
3797 }
3798 return 0;
3799 }
3800
3801 /**
3802 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3803 * @vport: pointer to a host virtual N_Port data structure.
3804 * @cmdiocb: pointer to lpfc command iocb data structure.
3805 * @ndlp: pointer to a node-list data structure.
3806 *
3807 * A received RDF implies a possible change to fabric supported diagnostic
3808 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3809 * RDF request to reregister for supported diagnostic functions.
3810 *
3811 * Return code
3812 * 0 - Success
3813 * -EIO - Failed to process received RDF
3814 **/
3815 static int
lpfc_els_rcv_rdf(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)3816 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3817 struct lpfc_nodelist *ndlp)
3818 {
3819 /* Send LS_ACC */
3820 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
3821 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3822 "1623 Failed to RDF_ACC from x%x for x%x\n",
3823 ndlp->nlp_DID, vport->fc_myDID);
3824 return -EIO;
3825 }
3826
3827 /* Issue new RDF for reregistering */
3828 if (lpfc_issue_els_rdf(vport, 0)) {
3829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3830 "2623 Failed to re register RDF for x%x\n",
3831 vport->fc_myDID);
3832 return -EIO;
3833 }
3834
3835 return 0;
3836 }
3837
3838 /**
3839 * lpfc_least_capable_settings - helper function for EDC rsp processing
3840 * @phba: pointer to lpfc hba data structure.
3841 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3842 *
3843 * This helper routine determines the least capable setting for
3844 * congestion signals, signal freq, including scale, from the
3845 * congestion detection descriptor in the EDC rsp. The routine
3846 * sets @phba values in preparation for a set_featues mailbox.
3847 **/
3848 static void
lpfc_least_capable_settings(struct lpfc_hba * phba,struct fc_diag_cg_sig_desc * pcgd)3849 lpfc_least_capable_settings(struct lpfc_hba *phba,
3850 struct fc_diag_cg_sig_desc *pcgd)
3851 {
3852 u32 rsp_sig_cap = 0, drv_sig_cap = 0;
3853 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
3854
3855 /* Get rsp signal and frequency capabilities. */
3856 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
3857 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
3858 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
3859
3860 /* If the Fport does not support signals. Set FPIN only */
3861 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
3862 goto out_no_support;
3863
3864 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3865 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3866 * to milliSeconds.
3867 */
3868 switch (rsp_sig_freq_scale) {
3869 case EDC_CG_SIGFREQ_SEC:
3870 rsp_sig_freq_cyc *= MSEC_PER_SEC;
3871 break;
3872 case EDC_CG_SIGFREQ_MSEC:
3873 rsp_sig_freq_cyc = 1;
3874 break;
3875 default:
3876 goto out_no_support;
3877 }
3878
3879 /* Convenient shorthand. */
3880 drv_sig_cap = phba->cgn_reg_signal;
3881
3882 /* Choose the least capable frequency. */
3883 if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
3884 phba->cgn_sig_freq = rsp_sig_freq_cyc;
3885
3886 /* Should be some common signals support. Settle on least capable
3887 * signal and adjust FPIN values. Initialize defaults to ease the
3888 * decision.
3889 */
3890 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
3891 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3892 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
3893 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
3894 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
3895 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3896 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3897 }
3898 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3899 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
3900 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
3901 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
3902 }
3903 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
3904 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
3905 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
3906 }
3907 }
3908
3909 /* We are NOT recording signal frequency in congestion info buffer */
3910 return;
3911
3912 out_no_support:
3913 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
3914 phba->cgn_sig_freq = 0;
3915 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
3916 }
3917
3918 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
3919 FC_LS_TLV_DTAG_INIT);
3920
3921 /**
3922 * lpfc_cmpl_els_edc - Completion callback function for EDC
3923 * @phba: pointer to lpfc hba data structure.
3924 * @cmdiocb: pointer to lpfc command iocb data structure.
3925 * @rspiocb: pointer to lpfc response iocb data structure.
3926 *
3927 * This routine is the completion callback function for issuing the Exchange
3928 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3929 * notify the FPort of its Congestion and Link Fault capabilities. This
3930 * routine parses the FPort's response and decides on the least common
3931 * values applicable to both FPort and NPort for Warnings and Alarms that
3932 * are communicated via hardware signals.
3933 **/
3934 static void
lpfc_cmpl_els_edc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3935 lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3936 struct lpfc_iocbq *rspiocb)
3937 {
3938 IOCB_t *irsp_iocb;
3939 struct fc_els_edc_resp *edc_rsp;
3940 struct fc_tlv_desc *tlv;
3941 struct fc_diag_cg_sig_desc *pcgd;
3942 struct fc_diag_lnkflt_desc *plnkflt;
3943 struct lpfc_dmabuf *pcmd, *prsp;
3944 const char *dtag_nm;
3945 u32 *pdata, dtag;
3946 int desc_cnt = 0, bytes_remain;
3947 bool rcv_cap_desc = false;
3948 struct lpfc_nodelist *ndlp;
3949 u32 ulp_status, ulp_word4, tmo, did, iotag;
3950
3951 ndlp = cmdiocb->ndlp;
3952
3953 ulp_status = get_job_ulpstatus(phba, rspiocb);
3954 ulp_word4 = get_job_word4(phba, rspiocb);
3955 did = get_job_els_rsp64_did(phba, rspiocb);
3956
3957 if (phba->sli_rev == LPFC_SLI_REV4) {
3958 tmo = get_wqe_tmo(rspiocb);
3959 iotag = get_wqe_reqtag(rspiocb);
3960 } else {
3961 irsp_iocb = &rspiocb->iocb;
3962 tmo = irsp_iocb->ulpTimeout;
3963 iotag = irsp_iocb->ulpIoTag;
3964 }
3965
3966 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
3967 "EDC cmpl: status:x%x/x%x did:x%x",
3968 ulp_status, ulp_word4, did);
3969
3970 /* ELS cmd tag <ulpIoTag> completes */
3971 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
3972 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
3973 iotag, ulp_status, ulp_word4, tmo);
3974
3975 pcmd = cmdiocb->cmd_dmabuf;
3976 if (!pcmd)
3977 goto out;
3978
3979 pdata = (u32 *)pcmd->virt;
3980 if (!pdata)
3981 goto out;
3982
3983 /* Need to clear signal values, send features MB and RDF with FPIN. */
3984 if (ulp_status)
3985 goto out;
3986
3987 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3988 if (!prsp)
3989 goto out;
3990
3991 edc_rsp = prsp->virt;
3992 if (!edc_rsp)
3993 goto out;
3994
3995 /* ELS cmd tag <ulpIoTag> completes */
3996 lpfc_printf_log(phba, KERN_INFO,
3997 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
3998 "4676 Fabric EDC Rsp: "
3999 "0x%02x, 0x%08x\n",
4000 edc_rsp->acc_hdr.la_cmd,
4001 be32_to_cpu(edc_rsp->desc_list_len));
4002
4003 if (!lpfc_is_els_acc_rsp(prsp))
4004 goto out;
4005
4006 /*
4007 * Payload length in bytes is the response descriptor list
4008 * length minus the 12 bytes of Link Service Request
4009 * Information descriptor in the reply.
4010 */
4011 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
4012 sizeof(struct fc_els_lsri_desc);
4013 if (bytes_remain <= 0)
4014 goto out;
4015
4016 tlv = edc_rsp->desc;
4017
4018 /*
4019 * cycle through EDC diagnostic descriptors to find the
4020 * congestion signaling capability descriptor
4021 */
4022 while (bytes_remain) {
4023 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
4024 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4025 "6461 Truncated TLV hdr on "
4026 "Diagnostic descriptor[%d]\n",
4027 desc_cnt);
4028 goto out;
4029 }
4030
4031 dtag = be32_to_cpu(tlv->desc_tag);
4032 switch (dtag) {
4033 case ELS_DTAG_LNK_FAULT_CAP:
4034 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4035 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4036 sizeof(struct fc_diag_lnkflt_desc)) {
4037 lpfc_printf_log(phba, KERN_WARNING,
4038 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
4039 "6462 Truncated Link Fault Diagnostic "
4040 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4041 desc_cnt, bytes_remain,
4042 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4043 sizeof(struct fc_diag_lnkflt_desc));
4044 goto out;
4045 }
4046 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
4047 lpfc_printf_log(phba, KERN_INFO,
4048 LOG_ELS | LOG_LDS_EVENT,
4049 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
4050 "0x%08x 0x%08x 0x%08x\n",
4051 be32_to_cpu(plnkflt->desc_tag),
4052 be32_to_cpu(plnkflt->desc_len),
4053 be32_to_cpu(
4054 plnkflt->degrade_activate_threshold),
4055 be32_to_cpu(
4056 plnkflt->degrade_deactivate_threshold),
4057 be32_to_cpu(plnkflt->fec_degrade_interval));
4058 break;
4059 case ELS_DTAG_CG_SIGNAL_CAP:
4060 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
4061 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
4062 sizeof(struct fc_diag_cg_sig_desc)) {
4063 lpfc_printf_log(
4064 phba, KERN_WARNING, LOG_CGN_MGMT,
4065 "6463 Truncated Cgn Signal Diagnostic "
4066 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4067 desc_cnt, bytes_remain,
4068 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
4069 sizeof(struct fc_diag_cg_sig_desc));
4070 goto out;
4071 }
4072
4073 pcgd = (struct fc_diag_cg_sig_desc *)tlv;
4074 lpfc_printf_log(
4075 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4076 "4616 CGN Desc Data: 0x%08x 0x%08x "
4077 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4078 be32_to_cpu(pcgd->desc_tag),
4079 be32_to_cpu(pcgd->desc_len),
4080 be32_to_cpu(pcgd->xmt_signal_capability),
4081 be16_to_cpu(pcgd->xmt_signal_frequency.count),
4082 be16_to_cpu(pcgd->xmt_signal_frequency.units),
4083 be32_to_cpu(pcgd->rcv_signal_capability),
4084 be16_to_cpu(pcgd->rcv_signal_frequency.count),
4085 be16_to_cpu(pcgd->rcv_signal_frequency.units));
4086
4087 /* Compare driver and Fport capabilities and choose
4088 * least common.
4089 */
4090 lpfc_least_capable_settings(phba, pcgd);
4091 rcv_cap_desc = true;
4092 break;
4093 default:
4094 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
4095 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
4096 "4919 unknown Diagnostic "
4097 "Descriptor[%d]: tag x%x (%s)\n",
4098 desc_cnt, dtag, dtag_nm);
4099 }
4100
4101 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
4102 tlv = fc_tlv_next_desc(tlv);
4103 desc_cnt++;
4104 }
4105
4106 out:
4107 if (!rcv_cap_desc) {
4108 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
4109 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4110 phba->cgn_sig_freq = 0;
4111 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
4112 "4202 EDC rsp error - sending RDF "
4113 "for FPIN only.\n");
4114 }
4115
4116 lpfc_config_cgn_signal(phba);
4117
4118 /* Check to see if link went down during discovery */
4119 lpfc_els_chk_latt(phba->pport);
4120 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
4121 "EDC Cmpl: did:x%x refcnt %d",
4122 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4123 lpfc_els_free_iocb(phba, cmdiocb);
4124 lpfc_nlp_put(ndlp);
4125 }
4126
4127 static void
lpfc_format_edc_lft_desc(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)4128 lpfc_format_edc_lft_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
4129 {
4130 struct fc_diag_lnkflt_desc *lft = (struct fc_diag_lnkflt_desc *)tlv;
4131
4132 lft->desc_tag = cpu_to_be32(ELS_DTAG_LNK_FAULT_CAP);
4133 lft->desc_len = cpu_to_be32(
4134 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_lnkflt_desc));
4135
4136 lft->degrade_activate_threshold =
4137 cpu_to_be32(phba->degrade_activate_threshold);
4138 lft->degrade_deactivate_threshold =
4139 cpu_to_be32(phba->degrade_deactivate_threshold);
4140 lft->fec_degrade_interval = cpu_to_be32(phba->fec_degrade_interval);
4141 }
4142
4143 static void
lpfc_format_edc_cgn_desc(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)4144 lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
4145 {
4146 struct fc_diag_cg_sig_desc *cgd = (struct fc_diag_cg_sig_desc *)tlv;
4147
4148 /* We are assuming cgd was zero'ed before calling this routine */
4149
4150 /* Configure the congestion detection capability */
4151 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
4152
4153 /* Descriptor len doesn't include the tag or len fields. */
4154 cgd->desc_len = cpu_to_be32(
4155 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
4156
4157 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4158 * xmt_signal_frequency.count already set to 0.
4159 * xmt_signal_frequency.units already set to 0.
4160 */
4161
4162 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
4163 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4164 * rcv_signal_frequency.count already set to 0.
4165 * rcv_signal_frequency.units already set to 0.
4166 */
4167 phba->cgn_sig_freq = 0;
4168 return;
4169 }
4170 switch (phba->cgn_reg_signal) {
4171 case EDC_CG_SIG_WARN_ONLY:
4172 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
4173 break;
4174 case EDC_CG_SIG_WARN_ALARM:
4175 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
4176 break;
4177 default:
4178 /* rcv_signal_capability left 0 thus no support */
4179 break;
4180 }
4181
4182 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4183 * the completion we settle on the higher frequency.
4184 */
4185 cgd->rcv_signal_frequency.count =
4186 cpu_to_be16(lpfc_fabric_cgn_frequency);
4187 cgd->rcv_signal_frequency.units =
4188 cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
4189 }
4190
4191 static bool
lpfc_link_is_lds_capable(struct lpfc_hba * phba)4192 lpfc_link_is_lds_capable(struct lpfc_hba *phba)
4193 {
4194 if (!(phba->lmt & LMT_64Gb))
4195 return false;
4196 if (phba->sli_rev != LPFC_SLI_REV4)
4197 return false;
4198
4199 if (phba->sli4_hba.conf_trunk) {
4200 if (phba->trunk_link.phy_lnk_speed == LPFC_USER_LINK_SPEED_64G)
4201 return true;
4202 } else if (phba->fc_linkspeed == LPFC_LINK_SPEED_64GHZ) {
4203 return true;
4204 }
4205 return false;
4206 }
4207
4208 /**
4209 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4210 * @vport: pointer to a host virtual N_Port data structure.
4211 * @retry: retry counter for the command iocb.
4212 *
4213 * This routine issues an ELS EDC to the F-Port Controller to communicate
4214 * this N_Port's support of hardware signals in its Congestion
4215 * Capabilities Descriptor.
4216 *
4217 * Note: This routine does not check if one or more signals are
4218 * set in the cgn_reg_signal parameter. The caller makes the
4219 * decision to enforce cgn_reg_signal as nonzero or zero depending
4220 * on the conditions. During Fabric requests, the driver
4221 * requires cgn_reg_signals to be nonzero. But a dynamic request
4222 * to set the congestion mode to OFF from Monitor or Manage
4223 * would correctly issue an EDC with no signals enabled to
4224 * turn off switch functionality and then update the FW.
4225 *
4226 * Return code
4227 * 0 - Successfully issued edc command
4228 * 1 - Failed to issue edc command
4229 **/
4230 int
lpfc_issue_els_edc(struct lpfc_vport * vport,uint8_t retry)4231 lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
4232 {
4233 struct lpfc_hba *phba = vport->phba;
4234 struct lpfc_iocbq *elsiocb;
4235 struct fc_els_edc *edc_req;
4236 struct fc_tlv_desc *tlv;
4237 u16 cmdsize;
4238 struct lpfc_nodelist *ndlp;
4239 u8 *pcmd = NULL;
4240 u32 cgn_desc_size, lft_desc_size;
4241 int rc;
4242
4243 if (vport->port_type == LPFC_NPIV_PORT)
4244 return -EACCES;
4245
4246 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4247 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
4248 return -ENODEV;
4249
4250 cgn_desc_size = (phba->cgn_init_reg_signal) ?
4251 sizeof(struct fc_diag_cg_sig_desc) : 0;
4252 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
4253 sizeof(struct fc_diag_lnkflt_desc) : 0;
4254 cmdsize = cgn_desc_size + lft_desc_size;
4255
4256 /* Skip EDC if no applicable descriptors */
4257 if (!cmdsize)
4258 goto try_rdf;
4259
4260 cmdsize += sizeof(struct fc_els_edc);
4261 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
4262 ndlp->nlp_DID, ELS_CMD_EDC);
4263 if (!elsiocb)
4264 goto try_rdf;
4265
4266 /* Configure the payload for the supported Diagnostics capabilities. */
4267 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
4268 memset(pcmd, 0, cmdsize);
4269 edc_req = (struct fc_els_edc *)pcmd;
4270 edc_req->desc_len = cpu_to_be32(cgn_desc_size + lft_desc_size);
4271 edc_req->edc_cmd = ELS_EDC;
4272 tlv = edc_req->desc;
4273
4274 if (cgn_desc_size) {
4275 lpfc_format_edc_cgn_desc(phba, tlv);
4276 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
4277 tlv = fc_tlv_next_desc(tlv);
4278 }
4279
4280 if (lft_desc_size)
4281 lpfc_format_edc_lft_desc(phba, tlv);
4282
4283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
4284 "4623 Xmit EDC to remote "
4285 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4286 ndlp->nlp_DID, phba->cgn_reg_signal,
4287 phba->cgn_reg_fpin);
4288
4289 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
4290 elsiocb->ndlp = lpfc_nlp_get(ndlp);
4291 if (!elsiocb->ndlp) {
4292 lpfc_els_free_iocb(phba, elsiocb);
4293 return -EIO;
4294 }
4295
4296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4297 "Issue EDC: did:x%x refcnt %d",
4298 ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
4299 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4300 if (rc == IOCB_ERROR) {
4301 /* The additional lpfc_nlp_put will cause the following
4302 * lpfc_els_free_iocb routine to trigger the rlease of
4303 * the node.
4304 */
4305 lpfc_els_free_iocb(phba, elsiocb);
4306 lpfc_nlp_put(ndlp);
4307 goto try_rdf;
4308 }
4309 return 0;
4310 try_rdf:
4311 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
4312 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
4313 rc = lpfc_issue_els_rdf(vport, 0);
4314 return rc;
4315 }
4316
4317 /**
4318 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
4319 * @vport: pointer to a host virtual N_Port data structure.
4320 * @nlp: pointer to a node-list data structure.
4321 *
4322 * This routine cancels the timer with a delayed IOCB-command retry for
4323 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4324 * removes the ELS retry event if it presents. In addition, if the
4325 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4326 * commands are sent for the @vport's nodes that require issuing discovery
4327 * ADISC.
4328 **/
4329 void
lpfc_cancel_retry_delay_tmo(struct lpfc_vport * vport,struct lpfc_nodelist * nlp)4330 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
4331 {
4332 struct lpfc_work_evt *evtp;
4333
4334 if (!test_and_clear_bit(NLP_DELAY_TMO, &nlp->nlp_flag))
4335 return;
4336 timer_delete_sync(&nlp->nlp_delayfunc);
4337 nlp->nlp_last_elscmd = 0;
4338 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
4339 list_del_init(&nlp->els_retry_evt.evt_listp);
4340 /* Decrement nlp reference count held for the delayed retry */
4341 evtp = &nlp->els_retry_evt;
4342 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
4343 }
4344 if (test_and_clear_bit(NLP_NPR_2B_DISC, &nlp->nlp_flag)) {
4345 if (vport->num_disc_nodes) {
4346 if (vport->port_state < LPFC_VPORT_READY) {
4347 /* Check if there are more ADISCs to be sent */
4348 lpfc_more_adisc(vport);
4349 } else {
4350 /* Check if there are more PLOGIs to be sent */
4351 lpfc_more_plogi(vport);
4352 if (vport->num_disc_nodes == 0) {
4353 clear_bit(FC_NDISC_ACTIVE,
4354 &vport->fc_flag);
4355 lpfc_can_disctmo(vport);
4356 lpfc_end_rscn(vport);
4357 }
4358 }
4359 }
4360 }
4361 return;
4362 }
4363
4364 /**
4365 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
4366 * @t: pointer to the timer function associated data (ndlp).
4367 *
4368 * This routine is invoked by the ndlp delayed-function timer to check
4369 * whether there is any pending ELS retry event(s) with the node. If not, it
4370 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4371 * adds the delayed events to the HBA work list and invokes the
4372 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4373 * event. Note that lpfc_nlp_get() is called before posting the event to
4374 * the work list to hold reference count of ndlp so that it guarantees the
4375 * reference to ndlp will still be available when the worker thread gets
4376 * to the event associated with the ndlp.
4377 **/
4378 void
lpfc_els_retry_delay(struct timer_list * t)4379 lpfc_els_retry_delay(struct timer_list *t)
4380 {
4381 struct lpfc_nodelist *ndlp = timer_container_of(ndlp, t,
4382 nlp_delayfunc);
4383 struct lpfc_vport *vport = ndlp->vport;
4384 struct lpfc_hba *phba = vport->phba;
4385 unsigned long flags;
4386 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
4387
4388 /* Hold a node reference for outstanding queued work */
4389 if (!lpfc_nlp_get(ndlp))
4390 return;
4391
4392 spin_lock_irqsave(&phba->hbalock, flags);
4393 if (!list_empty(&evtp->evt_listp)) {
4394 spin_unlock_irqrestore(&phba->hbalock, flags);
4395 lpfc_nlp_put(ndlp);
4396 return;
4397 }
4398
4399 evtp->evt_arg1 = ndlp;
4400 evtp->evt = LPFC_EVT_ELS_RETRY;
4401 list_add_tail(&evtp->evt_listp, &phba->work_list);
4402 spin_unlock_irqrestore(&phba->hbalock, flags);
4403
4404 lpfc_worker_wake_up(phba);
4405 }
4406
4407 /**
4408 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
4409 * @ndlp: pointer to a node-list data structure.
4410 *
4411 * This routine is the worker-thread handler for processing the @ndlp delayed
4412 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4413 * the last ELS command from the associated ndlp and invokes the proper ELS
4414 * function according to the delayed ELS command to retry the command.
4415 **/
4416 void
lpfc_els_retry_delay_handler(struct lpfc_nodelist * ndlp)4417 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
4418 {
4419 struct lpfc_vport *vport = ndlp->vport;
4420 uint32_t cmd, retry;
4421
4422 spin_lock_irq(&ndlp->lock);
4423 cmd = ndlp->nlp_last_elscmd;
4424 ndlp->nlp_last_elscmd = 0;
4425 spin_unlock_irq(&ndlp->lock);
4426
4427 if (!test_and_clear_bit(NLP_DELAY_TMO, &ndlp->nlp_flag))
4428 return;
4429
4430 /*
4431 * If a discovery event readded nlp_delayfunc after timer
4432 * firing and before processing the timer, cancel the
4433 * nlp_delayfunc.
4434 */
4435 timer_delete_sync(&ndlp->nlp_delayfunc);
4436 retry = ndlp->nlp_retry;
4437 ndlp->nlp_retry = 0;
4438
4439 switch (cmd) {
4440 case ELS_CMD_FLOGI:
4441 lpfc_issue_els_flogi(vport, ndlp, retry);
4442 break;
4443 case ELS_CMD_PLOGI:
4444 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
4445 ndlp->nlp_prev_state = ndlp->nlp_state;
4446 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4447 }
4448 break;
4449 case ELS_CMD_ADISC:
4450 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
4451 ndlp->nlp_prev_state = ndlp->nlp_state;
4452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4453 }
4454 break;
4455 case ELS_CMD_PRLI:
4456 case ELS_CMD_NVMEPRLI:
4457 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
4458 ndlp->nlp_prev_state = ndlp->nlp_state;
4459 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4460 }
4461 break;
4462 case ELS_CMD_LOGO:
4463 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
4464 ndlp->nlp_prev_state = ndlp->nlp_state;
4465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4466 }
4467 break;
4468 case ELS_CMD_FDISC:
4469 if (!test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag))
4470 lpfc_issue_els_fdisc(vport, ndlp, retry);
4471 break;
4472 }
4473 return;
4474 }
4475
4476 /**
4477 * lpfc_link_reset - Issue link reset
4478 * @vport: pointer to a virtual N_Port data structure.
4479 *
4480 * This routine performs link reset by sending INIT_LINK mailbox command.
4481 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4482 * INIT_LINK mailbox command.
4483 *
4484 * Return code
4485 * 0 - Link reset initiated successfully
4486 * 1 - Failed to initiate link reset
4487 **/
4488 int
lpfc_link_reset(struct lpfc_vport * vport)4489 lpfc_link_reset(struct lpfc_vport *vport)
4490 {
4491 struct lpfc_hba *phba = vport->phba;
4492 LPFC_MBOXQ_t *mbox;
4493 uint32_t control;
4494 int rc;
4495
4496 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4497 "2851 Attempt link reset\n");
4498 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4499 if (!mbox) {
4500 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4501 "2852 Failed to allocate mbox memory");
4502 return 1;
4503 }
4504
4505 /* Enable Link attention interrupts */
4506 if (phba->sli_rev <= LPFC_SLI_REV3) {
4507 spin_lock_irq(&phba->hbalock);
4508 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4509 control = readl(phba->HCregaddr);
4510 control |= HC_LAINT_ENA;
4511 writel(control, phba->HCregaddr);
4512 readl(phba->HCregaddr); /* flush */
4513 spin_unlock_irq(&phba->hbalock);
4514 }
4515
4516 lpfc_init_link(phba, mbox, phba->cfg_topology,
4517 phba->cfg_link_speed);
4518 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4519 mbox->vport = vport;
4520 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4521 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
4522 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4523 "2853 Failed to issue INIT_LINK "
4524 "mbox command, rc:x%x\n", rc);
4525 mempool_free(mbox, phba->mbox_mem_pool);
4526 return 1;
4527 }
4528
4529 return 0;
4530 }
4531
4532 /**
4533 * lpfc_els_retry - Make retry decision on an els command iocb
4534 * @phba: pointer to lpfc hba data structure.
4535 * @cmdiocb: pointer to lpfc command iocb data structure.
4536 * @rspiocb: pointer to lpfc response iocb data structure.
4537 *
4538 * This routine makes a retry decision on an ELS command IOCB, which has
4539 * failed. The following ELS IOCBs use this function for retrying the command
4540 * when previously issued command responsed with error status: FLOGI, PLOGI,
4541 * PRLI, ADISC and FDISC. Based on the ELS command type and the
4542 * returned error status, it makes the decision whether a retry shall be
4543 * issued for the command, and whether a retry shall be made immediately or
4544 * delayed. In the former case, the corresponding ELS command issuing-function
4545 * is called to retry the command. In the later case, the ELS command shall
4546 * be posted to the ndlp delayed event and delayed function timer set to the
4547 * ndlp for the delayed command issusing.
4548 *
4549 * Return code
4550 * 0 - No retry of els command is made
4551 * 1 - Immediate or delayed retry of els command is made
4552 **/
4553 static int
lpfc_els_retry(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)4554 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4555 struct lpfc_iocbq *rspiocb)
4556 {
4557 struct lpfc_vport *vport = cmdiocb->vport;
4558 union lpfc_wqe128 *irsp = &rspiocb->wqe;
4559 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
4560 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
4561 uint32_t *elscmd;
4562 struct ls_rjt stat;
4563 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
4564 int logerr = 0;
4565 uint32_t cmd = 0;
4566 uint32_t did;
4567 int link_reset = 0, rc;
4568 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
4569 u32 ulp_word4 = get_job_word4(phba, rspiocb);
4570 u8 rsn_code_exp = 0;
4571
4572
4573 /* Note: cmd_dmabuf may be 0 for internal driver abort
4574 * of delays ELS command.
4575 */
4576
4577 if (pcmd && pcmd->virt) {
4578 elscmd = (uint32_t *) (pcmd->virt);
4579 cmd = *elscmd++;
4580 }
4581
4582 if (ndlp)
4583 did = ndlp->nlp_DID;
4584 else {
4585 /* We should only hit this case for retrying PLOGI */
4586 did = get_job_els_rsp64_did(phba, rspiocb);
4587 ndlp = lpfc_findnode_did(vport, did);
4588 if (!ndlp && (cmd != ELS_CMD_PLOGI))
4589 return 0;
4590 }
4591
4592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4593 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4594 *(((uint32_t *)irsp) + 7), ulp_word4, did);
4595
4596 switch (ulp_status) {
4597 case IOSTAT_FCP_RSP_ERROR:
4598 break;
4599 case IOSTAT_REMOTE_STOP:
4600 if (phba->sli_rev == LPFC_SLI_REV4) {
4601 /* This IO was aborted by the target, we don't
4602 * know the rxid and because we did not send the
4603 * ABTS we cannot generate and RRQ.
4604 */
4605 lpfc_set_rrq_active(phba, ndlp,
4606 cmdiocb->sli4_lxritag, 0, 0);
4607 }
4608 break;
4609 case IOSTAT_LOCAL_REJECT:
4610 switch ((ulp_word4 & IOERR_PARAM_MASK)) {
4611 case IOERR_LOOP_OPEN_FAILURE:
4612 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
4613 delay = 1000;
4614 retry = 1;
4615 break;
4616
4617 case IOERR_ILLEGAL_COMMAND:
4618 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4619 "0124 Retry illegal cmd x%x "
4620 "retry:x%x delay:x%x\n",
4621 cmd, cmdiocb->retry, delay);
4622 retry = 1;
4623 /* All command's retry policy */
4624 maxretry = 8;
4625 if (cmdiocb->retry > 2)
4626 delay = 1000;
4627 break;
4628
4629 case IOERR_NO_RESOURCES:
4630 logerr = 1; /* HBA out of resources */
4631 retry = 1;
4632 if (cmdiocb->retry > 100)
4633 delay = 100;
4634 maxretry = 250;
4635 break;
4636
4637 case IOERR_ILLEGAL_FRAME:
4638 delay = 100;
4639 retry = 1;
4640 break;
4641
4642 case IOERR_INVALID_RPI:
4643 if (cmd == ELS_CMD_PLOGI &&
4644 did == NameServer_DID) {
4645 /* Continue forever if plogi to */
4646 /* the nameserver fails */
4647 maxretry = 0;
4648 delay = 100;
4649 } else if (cmd == ELS_CMD_PRLI &&
4650 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) {
4651 /* State-command disagreement. The PRLI was
4652 * failed with an invalid rpi meaning there
4653 * some unexpected state change. Don't retry.
4654 */
4655 maxretry = 0;
4656 retry = 0;
4657 break;
4658 }
4659 retry = 1;
4660 break;
4661
4662 case IOERR_SEQUENCE_TIMEOUT:
4663 if (cmd == ELS_CMD_PLOGI &&
4664 did == NameServer_DID &&
4665 (cmdiocb->retry + 1) == maxretry) {
4666 /* Reset the Link */
4667 link_reset = 1;
4668 break;
4669 }
4670 retry = 1;
4671 delay = 100;
4672 break;
4673 case IOERR_SLI_ABORTED:
4674 /* Retry ELS PLOGI command?
4675 * Possibly the rport just wasn't ready.
4676 */
4677 if (cmd == ELS_CMD_PLOGI) {
4678 /* No retry if state change */
4679 if (ndlp &&
4680 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
4681 goto out_retry;
4682 retry = 1;
4683 maxretry = 2;
4684 }
4685 break;
4686 }
4687 break;
4688
4689 case IOSTAT_NPORT_RJT:
4690 case IOSTAT_FABRIC_RJT:
4691 if (ulp_word4 & RJT_UNAVAIL_TEMP) {
4692 retry = 1;
4693 break;
4694 }
4695 break;
4696
4697 case IOSTAT_NPORT_BSY:
4698 case IOSTAT_FABRIC_BSY:
4699 logerr = 1; /* Fabric / Remote NPort out of resources */
4700 retry = 1;
4701 break;
4702
4703 case IOSTAT_LS_RJT:
4704 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
4705 /* Added for Vendor specifc support
4706 * Just keep retrying for these Rsn / Exp codes
4707 */
4708 if (test_bit(FC_PT2PT, &vport->fc_flag) &&
4709 cmd == ELS_CMD_NVMEPRLI) {
4710 switch (stat.un.b.lsRjtRsnCode) {
4711 case LSRJT_UNABLE_TPC:
4712 case LSRJT_INVALID_CMD:
4713 case LSRJT_LOGICAL_ERR:
4714 case LSRJT_CMD_UNSUPPORTED:
4715 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
4716 "0168 NVME PRLI LS_RJT "
4717 "reason %x port doesn't "
4718 "support NVME, disabling NVME\n",
4719 stat.un.b.lsRjtRsnCode);
4720 retry = 0;
4721 set_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
4722 goto out_retry;
4723 }
4724 }
4725 switch (stat.un.b.lsRjtRsnCode) {
4726 case LSRJT_UNABLE_TPC:
4727 /* Special case for PRLI LS_RJTs. Recall that lpfc
4728 * uses a single routine to issue both PRLI FC4 types.
4729 * If the PRLI is rejected because that FC4 type
4730 * isn't really supported, don't retry and cause
4731 * multiple transport registrations. Otherwise, parse
4732 * the reason code/reason code explanation and take the
4733 * appropriate action.
4734 */
4735 lpfc_printf_vlog(vport, KERN_INFO,
4736 LOG_DISCOVERY | LOG_ELS | LOG_NODE,
4737 "0153 ELS cmd x%x LS_RJT by x%x. "
4738 "RsnCode x%x RsnCodeExp x%x\n",
4739 cmd, did, stat.un.b.lsRjtRsnCode,
4740 stat.un.b.lsRjtRsnCodeExp);
4741
4742 switch (stat.un.b.lsRjtRsnCodeExp) {
4743 case LSEXP_CANT_GIVE_DATA:
4744 case LSEXP_CMD_IN_PROGRESS:
4745 if (cmd == ELS_CMD_PLOGI) {
4746 delay = 1000;
4747 maxretry = 48;
4748 }
4749 retry = 1;
4750 break;
4751 case LSEXP_REQ_UNSUPPORTED:
4752 case LSEXP_NO_RSRC_ASSIGN:
4753 /* These explanation codes get no retry. */
4754 if (cmd == ELS_CMD_PRLI ||
4755 cmd == ELS_CMD_NVMEPRLI)
4756 break;
4757 fallthrough;
4758 default:
4759 /* Limit the delay and retry action to a limited
4760 * cmd set. There are other ELS commands where
4761 * a retry is not expected.
4762 */
4763 if (cmd == ELS_CMD_PLOGI ||
4764 cmd == ELS_CMD_PRLI ||
4765 cmd == ELS_CMD_NVMEPRLI) {
4766 delay = 1000;
4767 maxretry = lpfc_max_els_tries + 1;
4768 retry = 1;
4769 }
4770 break;
4771 }
4772
4773 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4774 (cmd == ELS_CMD_FDISC) &&
4775 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4776 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
4777 "0125 FDISC (x%x). "
4778 "Fabric out of resources\n",
4779 stat.un.lsRjtError);
4780 lpfc_vport_set_state(vport,
4781 FC_VPORT_NO_FABRIC_RSCS);
4782 }
4783 break;
4784
4785 case LSRJT_LOGICAL_BSY:
4786 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp;
4787 if ((cmd == ELS_CMD_PLOGI) ||
4788 (cmd == ELS_CMD_PRLI) ||
4789 (cmd == ELS_CMD_NVMEPRLI)) {
4790 delay = 1000;
4791 maxretry = 48;
4792
4793 /* An authentication LS_RJT reason code
4794 * explanation means some error in the
4795 * security settings end-to-end. Reduce
4796 * the retry count to allow lpfc to clear
4797 * RSCN mode and not race with dev_loss.
4798 */
4799 if (cmd == ELS_CMD_PLOGI &&
4800 rsn_code_exp == LSEXP_AUTH_REQ)
4801 maxretry = 8;
4802 } else if (cmd == ELS_CMD_FDISC) {
4803 /* FDISC retry policy */
4804 maxretry = 48;
4805 if (cmdiocb->retry >= 32)
4806 delay = 1000;
4807 }
4808 retry = 1;
4809 break;
4810
4811 case LSRJT_LOGICAL_ERR:
4812 /* There are some cases where switches return this
4813 * error when they are not ready and should be returning
4814 * Logical Busy. We should delay every time.
4815 */
4816 if (cmd == ELS_CMD_FDISC &&
4817 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4818 maxretry = 3;
4819 delay = 1000;
4820 retry = 1;
4821 } else if (cmd == ELS_CMD_FLOGI &&
4822 stat.un.b.lsRjtRsnCodeExp ==
4823 LSEXP_NOTHING_MORE) {
4824 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4825 retry = 1;
4826 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
4827 "0820 FLOGI (x%x). "
4828 "BBCredit Not Supported\n",
4829 stat.un.lsRjtError);
4830 } else if (cmd == ELS_CMD_PLOGI) {
4831 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp;
4832
4833 /* An authentication LS_RJT reason code
4834 * explanation means some error in the
4835 * security settings end-to-end. Reduce
4836 * the retry count to allow lpfc to clear
4837 * RSCN mode and not race with dev_loss.
4838 */
4839 if (rsn_code_exp == LSEXP_AUTH_REQ) {
4840 delay = 1000;
4841 retry = 1;
4842 maxretry = 8;
4843 }
4844 }
4845 break;
4846
4847 case LSRJT_PROTOCOL_ERR:
4848 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4849 (cmd == ELS_CMD_FDISC) &&
4850 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4851 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4852 ) {
4853 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
4854 "0122 FDISC (x%x). "
4855 "Fabric Detected Bad WWN\n",
4856 stat.un.lsRjtError);
4857 lpfc_vport_set_state(vport,
4858 FC_VPORT_FABRIC_REJ_WWN);
4859 }
4860 break;
4861 case LSRJT_VENDOR_UNIQUE:
4862 if ((stat.un.b.vendorUnique == 0x45) &&
4863 (cmd == ELS_CMD_FLOGI)) {
4864 goto out_retry;
4865 }
4866 break;
4867 case LSRJT_CMD_UNSUPPORTED:
4868 /* lpfc nvmet returns this type of LS_RJT when it
4869 * receives an FCP PRLI because lpfc nvmet only
4870 * support NVME. ELS request is terminated for FCP4
4871 * on this rport.
4872 */
4873 if (stat.un.b.lsRjtRsnCodeExp ==
4874 LSEXP_REQ_UNSUPPORTED) {
4875 if (cmd == ELS_CMD_PRLI)
4876 goto out_retry;
4877 }
4878 break;
4879 }
4880 break;
4881
4882 case IOSTAT_INTERMED_RSP:
4883 case IOSTAT_BA_RJT:
4884 break;
4885
4886 default:
4887 break;
4888 }
4889
4890 if (link_reset) {
4891 rc = lpfc_link_reset(vport);
4892 if (rc) {
4893 /* Do not give up. Retry PLOGI one more time and attempt
4894 * link reset if PLOGI fails again.
4895 */
4896 retry = 1;
4897 delay = 100;
4898 goto out_retry;
4899 }
4900 return 1;
4901 }
4902
4903 if (did == FDMI_DID)
4904 retry = 1;
4905
4906 if ((cmd == ELS_CMD_FLOGI) &&
4907 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4908 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
4909 /* FLOGI retry policy */
4910 retry = 1;
4911 /* retry FLOGI forever */
4912 if (phba->link_flag != LS_LOOPBACK_MODE)
4913 maxretry = 0;
4914 else
4915 maxretry = 2;
4916
4917 if (cmdiocb->retry >= 100)
4918 delay = 5000;
4919 else if (cmdiocb->retry >= 32)
4920 delay = 1000;
4921 } else if ((cmd == ELS_CMD_FDISC) &&
4922 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
4923 /* retry FDISCs every second up to devloss */
4924 retry = 1;
4925 maxretry = vport->cfg_devloss_tmo;
4926 delay = 1000;
4927 }
4928
4929 cmdiocb->retry++;
4930 if (maxretry && (cmdiocb->retry >= maxretry)) {
4931 phba->fc_stat.elsRetryExceeded++;
4932 retry = 0;
4933 }
4934
4935 if (test_bit(FC_UNLOADING, &vport->load_flag))
4936 retry = 0;
4937
4938 out_retry:
4939 if (retry) {
4940 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4941 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4942 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4943 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4944 "2849 Stop retry ELS command "
4945 "x%x to remote NPORT x%x, "
4946 "Data: x%x x%x\n", cmd, did,
4947 cmdiocb->retry, delay);
4948 return 0;
4949 }
4950 }
4951
4952 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4954 "0107 Retry ELS command x%x to remote "
4955 "NPORT x%x Data: x%x x%x\n",
4956 cmd, did, cmdiocb->retry, delay);
4957
4958 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4959 ((ulp_status != IOSTAT_LOCAL_REJECT) ||
4960 ((ulp_word4 & IOERR_PARAM_MASK) !=
4961 IOERR_NO_RESOURCES))) {
4962 /* Don't reset timer for no resources */
4963
4964 /* If discovery / RSCN timer is running, reset it */
4965 if (timer_pending(&vport->fc_disctmo) ||
4966 test_bit(FC_RSCN_MODE, &vport->fc_flag))
4967 lpfc_set_disctmo(vport);
4968 }
4969
4970 phba->fc_stat.elsXmitRetry++;
4971 if (ndlp && delay) {
4972 phba->fc_stat.elsDelayRetry++;
4973 ndlp->nlp_retry = cmdiocb->retry;
4974
4975 /* delay is specified in milliseconds */
4976 mod_timer(&ndlp->nlp_delayfunc,
4977 jiffies + msecs_to_jiffies(delay));
4978 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
4979
4980 ndlp->nlp_prev_state = ndlp->nlp_state;
4981 if ((cmd == ELS_CMD_PRLI) ||
4982 (cmd == ELS_CMD_NVMEPRLI))
4983 lpfc_nlp_set_state(vport, ndlp,
4984 NLP_STE_PRLI_ISSUE);
4985 else if (cmd != ELS_CMD_ADISC)
4986 lpfc_nlp_set_state(vport, ndlp,
4987 NLP_STE_NPR_NODE);
4988 ndlp->nlp_last_elscmd = cmd;
4989
4990 return 1;
4991 }
4992 switch (cmd) {
4993 case ELS_CMD_FLOGI:
4994 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4995 return 1;
4996 case ELS_CMD_FDISC:
4997 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4998 return 1;
4999 case ELS_CMD_PLOGI:
5000 if (ndlp) {
5001 ndlp->nlp_prev_state = ndlp->nlp_state;
5002 lpfc_nlp_set_state(vport, ndlp,
5003 NLP_STE_PLOGI_ISSUE);
5004 }
5005 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
5006 return 1;
5007 case ELS_CMD_ADISC:
5008 ndlp->nlp_prev_state = ndlp->nlp_state;
5009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5010 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
5011 return 1;
5012 case ELS_CMD_PRLI:
5013 case ELS_CMD_NVMEPRLI:
5014 ndlp->nlp_prev_state = ndlp->nlp_state;
5015 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
5016 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
5017 return 1;
5018 case ELS_CMD_LOGO:
5019 ndlp->nlp_prev_state = ndlp->nlp_state;
5020 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
5021 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
5022 return 1;
5023 }
5024 }
5025 /* No retry ELS command <elsCmd> to remote NPORT <did> */
5026 if (logerr) {
5027 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5028 "0137 No retry ELS command x%x to remote "
5029 "NPORT x%x: Out of Resources: Error:x%x/%x "
5030 "IoTag x%x\n",
5031 cmd, did, ulp_status, ulp_word4,
5032 cmdiocb->iotag);
5033 }
5034 else {
5035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5036 "0108 No retry ELS command x%x to remote "
5037 "NPORT x%x Retried:%d Error:x%x/%x "
5038 "IoTag x%x nflags x%lx\n",
5039 cmd, did, cmdiocb->retry, ulp_status,
5040 ulp_word4, cmdiocb->iotag,
5041 (ndlp ? ndlp->nlp_flag : 0));
5042 }
5043 return 0;
5044 }
5045
5046 /**
5047 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
5048 * @phba: pointer to lpfc hba data structure.
5049 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
5050 *
5051 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
5052 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
5053 * checks to see whether there is a lpfc DMA buffer associated with the
5054 * response of the command IOCB. If so, it will be released before releasing
5055 * the lpfc DMA buffer associated with the IOCB itself.
5056 *
5057 * Return code
5058 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5059 **/
5060 static int
lpfc_els_free_data(struct lpfc_hba * phba,struct lpfc_dmabuf * buf_ptr1)5061 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
5062 {
5063 struct lpfc_dmabuf *buf_ptr;
5064
5065 /* Free the response before processing the command. */
5066 if (!list_empty(&buf_ptr1->list)) {
5067 list_remove_head(&buf_ptr1->list, buf_ptr,
5068 struct lpfc_dmabuf,
5069 list);
5070 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5071 kfree(buf_ptr);
5072 }
5073 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
5074 kfree(buf_ptr1);
5075 return 0;
5076 }
5077
5078 /**
5079 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
5080 * @phba: pointer to lpfc hba data structure.
5081 * @buf_ptr: pointer to the lpfc dma buffer data structure.
5082 *
5083 * This routine releases the lpfc Direct Memory Access (DMA) buffer
5084 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
5085 * pool.
5086 *
5087 * Return code
5088 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5089 **/
5090 static int
lpfc_els_free_bpl(struct lpfc_hba * phba,struct lpfc_dmabuf * buf_ptr)5091 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
5092 {
5093 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
5094 kfree(buf_ptr);
5095 return 0;
5096 }
5097
5098 /**
5099 * lpfc_els_free_iocb - Free a command iocb and its associated resources
5100 * @phba: pointer to lpfc hba data structure.
5101 * @elsiocb: pointer to lpfc els command iocb data structure.
5102 *
5103 * This routine frees a command IOCB and its associated resources. The
5104 * command IOCB data structure contains the reference to various associated
5105 * resources, these fields must be set to NULL if the associated reference
5106 * not present:
5107 * cmd_dmabuf - reference to cmd.
5108 * cmd_dmabuf->next - reference to rsp
5109 * rsp_dmabuf - unused
5110 * bpl_dmabuf - reference to bpl
5111 *
5112 * It first properly decrements the reference count held on ndlp for the
5113 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
5114 * set, it invokes the lpfc_els_free_data() routine to release the Direct
5115 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
5116 * adds the DMA buffer the @phba data structure for the delayed release.
5117 * If reference to the Buffer Pointer List (BPL) is present, the
5118 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
5119 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
5120 * invoked to release the IOCB data structure back to @phba IOCBQ list.
5121 *
5122 * Return code
5123 * 0 - Success (currently, always return 0)
5124 **/
5125 int
lpfc_els_free_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * elsiocb)5126 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
5127 {
5128 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
5129
5130 /* The I/O iocb is complete. Clear the node and first dmbuf */
5131 elsiocb->ndlp = NULL;
5132
5133 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */
5134 if (elsiocb->cmd_dmabuf) {
5135 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) {
5136 /* Firmware could still be in progress of DMAing
5137 * payload, so don't free data buffer till after
5138 * a hbeat.
5139 */
5140 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE;
5141 buf_ptr = elsiocb->cmd_dmabuf;
5142 elsiocb->cmd_dmabuf = NULL;
5143 if (buf_ptr) {
5144 buf_ptr1 = NULL;
5145 spin_lock_irq(&phba->hbalock);
5146 if (!list_empty(&buf_ptr->list)) {
5147 list_remove_head(&buf_ptr->list,
5148 buf_ptr1, struct lpfc_dmabuf,
5149 list);
5150 INIT_LIST_HEAD(&buf_ptr1->list);
5151 list_add_tail(&buf_ptr1->list,
5152 &phba->elsbuf);
5153 phba->elsbuf_cnt++;
5154 }
5155 INIT_LIST_HEAD(&buf_ptr->list);
5156 list_add_tail(&buf_ptr->list, &phba->elsbuf);
5157 phba->elsbuf_cnt++;
5158 spin_unlock_irq(&phba->hbalock);
5159 }
5160 } else {
5161 buf_ptr1 = elsiocb->cmd_dmabuf;
5162 lpfc_els_free_data(phba, buf_ptr1);
5163 elsiocb->cmd_dmabuf = NULL;
5164 }
5165 }
5166
5167 if (elsiocb->bpl_dmabuf) {
5168 buf_ptr = elsiocb->bpl_dmabuf;
5169 lpfc_els_free_bpl(phba, buf_ptr);
5170 elsiocb->bpl_dmabuf = NULL;
5171 }
5172 lpfc_sli_release_iocbq(phba, elsiocb);
5173 return 0;
5174 }
5175
5176 /**
5177 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
5178 * @phba: pointer to lpfc hba data structure.
5179 * @cmdiocb: pointer to lpfc command iocb data structure.
5180 * @rspiocb: pointer to lpfc response iocb data structure.
5181 *
5182 * This routine is the completion callback function to the Logout (LOGO)
5183 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5184 * the completion of the LOGO process. If the node has transitioned to NPR,
5185 * this routine unregisters the RPI if it is still registered. The
5186 * lpfc_els_free_iocb() is invoked to release the IOCB data structure.
5187 **/
5188 static void
lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)5189 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5190 struct lpfc_iocbq *rspiocb)
5191 {
5192 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5193 struct lpfc_vport *vport = cmdiocb->vport;
5194 u32 ulp_status, ulp_word4;
5195
5196 ulp_status = get_job_ulpstatus(phba, rspiocb);
5197 ulp_word4 = get_job_word4(phba, rspiocb);
5198
5199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5200 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5201 ulp_status, ulp_word4, ndlp->nlp_DID);
5202 /* ACC to LOGO completes to NPort <nlp_DID> */
5203 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5204 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
5205 "last els x%x Data: x%lx x%x x%x\n",
5206 ndlp->nlp_DID, kref_read(&ndlp->kref),
5207 ndlp->nlp_last_elscmd, ndlp->nlp_flag, ndlp->nlp_state,
5208 ndlp->nlp_rpi);
5209
5210 /* This clause allows the LOGO ACC to complete and free resources
5211 * for the Fabric Domain Controller. It does deliberately skip
5212 * the unreg_rpi and release rpi because some fabrics send RDP
5213 * requests after logging out from the initiator.
5214 */
5215 if (ndlp->nlp_type & NLP_FABRIC &&
5216 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
5217 goto out;
5218
5219 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
5220 if (test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag))
5221 lpfc_unreg_rpi(vport, ndlp);
5222
5223 /* If came from PRLO, then PRLO_ACC is done.
5224 * Start rediscovery now.
5225 */
5226 if (ndlp->nlp_last_elscmd == ELS_CMD_PRLO) {
5227 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag);
5228 ndlp->nlp_prev_state = ndlp->nlp_state;
5229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5230 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5231 }
5232 }
5233
5234 out:
5235 /*
5236 * The driver received a LOGO from the rport and has ACK'd it.
5237 * At this point, the driver is done so release the IOCB
5238 */
5239 lpfc_els_free_iocb(phba, cmdiocb);
5240 lpfc_nlp_put(ndlp);
5241 }
5242
5243 /**
5244 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
5245 * @phba: pointer to lpfc hba data structure.
5246 * @pmb: pointer to the driver internal queue element for mailbox command.
5247 *
5248 * This routine is the completion callback function for unregister default
5249 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5250 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5251 * decrements the ndlp reference count held for this completion callback
5252 * function. After that, it invokes the lpfc_drop_node to check
5253 * whether it is appropriate to release the node.
5254 **/
5255 void
lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)5256 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5257 {
5258 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
5259 u32 mbx_flag = pmb->mbox_flag;
5260 u32 mbx_cmd = pmb->u.mb.mbxCommand;
5261
5262 if (ndlp) {
5263 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5264 "0006 rpi x%x DID:%x flg:%lx %d x%px "
5265 "mbx_cmd x%x mbx_flag x%x x%px\n",
5266 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5267 kref_read(&ndlp->kref), ndlp, mbx_cmd,
5268 mbx_flag, pmb);
5269
5270 /* This ends the default/temporary RPI cleanup logic for this
5271 * ndlp and the node and rpi needs to be released. Free the rpi
5272 * first on an UNREG_LOGIN and then release the final
5273 * references.
5274 */
5275 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
5276 if (mbx_cmd == MBX_UNREG_LOGIN)
5277 clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag);
5278 lpfc_nlp_put(ndlp);
5279 lpfc_drop_node(ndlp->vport, ndlp);
5280 }
5281
5282 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
5283 }
5284
5285 /**
5286 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
5287 * @phba: pointer to lpfc hba data structure.
5288 * @cmdiocb: pointer to lpfc command iocb data structure.
5289 * @rspiocb: pointer to lpfc response iocb data structure.
5290 *
5291 * This routine is the completion callback function for ELS Response IOCB
5292 * command. In normal case, this callback function just properly sets the
5293 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5294 * field in the command IOCB is not NULL, the referred mailbox command will
5295 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
5296 * the IOCB.
5297 **/
5298 static void
lpfc_cmpl_els_rsp(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)5299 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5300 struct lpfc_iocbq *rspiocb)
5301 {
5302 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
5303 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
5304 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
5305 IOCB_t *irsp;
5306 LPFC_MBOXQ_t *mbox = NULL;
5307 u32 ulp_status, ulp_word4, tmo, did, iotag;
5308
5309 if (!vport) {
5310 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
5311 "3177 null vport in ELS rsp\n");
5312 goto out;
5313 }
5314 if (cmdiocb->context_un.mbox)
5315 mbox = cmdiocb->context_un.mbox;
5316
5317 ulp_status = get_job_ulpstatus(phba, rspiocb);
5318 ulp_word4 = get_job_word4(phba, rspiocb);
5319 did = get_job_els_rsp64_did(phba, cmdiocb);
5320
5321 if (phba->sli_rev == LPFC_SLI_REV4) {
5322 tmo = get_wqe_tmo(cmdiocb);
5323 iotag = get_wqe_reqtag(cmdiocb);
5324 } else {
5325 irsp = &rspiocb->iocb;
5326 tmo = irsp->ulpTimeout;
5327 iotag = irsp->ulpIoTag;
5328 }
5329
5330 /* Check to see if link went down during discovery */
5331 if (!ndlp || lpfc_els_chk_latt(vport)) {
5332 if (mbox)
5333 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5334 goto out;
5335 }
5336
5337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5338 "ELS rsp cmpl: status:x%x/x%x did:x%x",
5339 ulp_status, ulp_word4, did);
5340 /* ELS response tag <ulpIoTag> completes */
5341 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5342 "0110 ELS response tag x%x completes "
5343 "Data: x%x x%x x%x x%x x%lx x%x x%x x%x %p %p\n",
5344 iotag, ulp_status, ulp_word4, tmo,
5345 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5346 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp);
5347 if (mbox) {
5348 if (ulp_status == 0 &&
5349 test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag)) {
5350 if (!lpfc_unreg_rpi(vport, ndlp) &&
5351 !test_bit(FC_PT2PT, &vport->fc_flag)) {
5352 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5353 ndlp->nlp_state ==
5354 NLP_STE_REG_LOGIN_ISSUE) {
5355 lpfc_printf_vlog(vport, KERN_INFO,
5356 LOG_DISCOVERY,
5357 "0314 PLOGI recov "
5358 "DID x%x "
5359 "Data: x%x x%x x%lx\n",
5360 ndlp->nlp_DID,
5361 ndlp->nlp_state,
5362 ndlp->nlp_rpi,
5363 ndlp->nlp_flag);
5364 goto out_free_mbox;
5365 }
5366 }
5367
5368 /* Increment reference count to ndlp to hold the
5369 * reference to ndlp for the callback function.
5370 */
5371 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5372 if (!mbox->ctx_ndlp)
5373 goto out_free_mbox;
5374
5375 mbox->vport = vport;
5376 if (test_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag)) {
5377 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5378 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5379 } else {
5380 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
5381 ndlp->nlp_prev_state = ndlp->nlp_state;
5382 lpfc_nlp_set_state(vport, ndlp,
5383 NLP_STE_REG_LOGIN_ISSUE);
5384 }
5385
5386 set_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
5387 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5388 != MBX_NOT_FINISHED)
5389 goto out;
5390
5391 /* Decrement the ndlp reference count we
5392 * set for this failed mailbox command.
5393 */
5394 lpfc_nlp_put(ndlp);
5395 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag);
5396
5397 /* ELS rsp: Cannot issue reg_login for <NPortid> */
5398 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5399 "0138 ELS rsp: Cannot issue reg_login for x%x "
5400 "Data: x%lx x%x x%x\n",
5401 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5402 ndlp->nlp_rpi);
5403 }
5404 out_free_mbox:
5405 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
5406 }
5407 out:
5408 if (ndlp && shost) {
5409 if (mbox)
5410 clear_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag);
5411 clear_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag);
5412 }
5413
5414 /* An SLI4 NPIV instance wants to drop the node at this point under
5415 * these conditions because it doesn't need the login.
5416 */
5417 if (phba->sli_rev == LPFC_SLI_REV4 &&
5418 vport && vport->port_type == LPFC_NPIV_PORT &&
5419 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
5420 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
5421 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE &&
5422 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) {
5423 /* Drop ndlp if there is no planned or outstanding
5424 * issued PRLI.
5425 *
5426 * In cases when the ndlp is acting as both an initiator
5427 * and target function, let our issued PRLI determine
5428 * the final ndlp kref drop.
5429 */
5430 lpfc_drop_node(vport, ndlp);
5431 }
5432 }
5433
5434 /* Release the originating I/O reference. */
5435 lpfc_els_free_iocb(phba, cmdiocb);
5436 lpfc_nlp_put(ndlp);
5437 return;
5438 }
5439
5440 /**
5441 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
5442 * @vport: pointer to a host virtual N_Port data structure.
5443 * @flag: the els command code to be accepted.
5444 * @oldiocb: pointer to the original lpfc command iocb data structure.
5445 * @ndlp: pointer to a node-list data structure.
5446 * @mbox: pointer to the driver internal queue element for mailbox command.
5447 *
5448 * This routine prepares and issues an Accept (ACC) response IOCB
5449 * command. It uses the @flag to properly set up the IOCB field for the
5450 * specific ACC response command to be issued and invokes the
5451 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5452 * @mbox pointer is passed in, it will be put into the context_un.mbox
5453 * field of the IOCB for the completion callback function to issue the
5454 * mailbox command to the HBA later when callback is invoked.
5455 *
5456 * Note that the ndlp reference count will be incremented by 1 for holding the
5457 * ndlp and the reference to ndlp will be stored into the ndlp field of
5458 * the IOCB for the completion callback function to the corresponding
5459 * response ELS IOCB command.
5460 *
5461 * Return code
5462 * 0 - Successfully issued acc response
5463 * 1 - Failed to issue acc response
5464 **/
5465 int
lpfc_els_rsp_acc(struct lpfc_vport * vport,uint32_t flag,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp,LPFC_MBOXQ_t * mbox)5466 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
5467 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5468 LPFC_MBOXQ_t *mbox)
5469 {
5470 struct lpfc_hba *phba = vport->phba;
5471 IOCB_t *icmd;
5472 IOCB_t *oldcmd;
5473 union lpfc_wqe128 *wqe;
5474 union lpfc_wqe128 *oldwqe = &oldiocb->wqe;
5475 struct lpfc_iocbq *elsiocb;
5476 uint8_t *pcmd;
5477 struct serv_parm *sp;
5478 uint16_t cmdsize;
5479 int rc;
5480 ELS_PKT *els_pkt_ptr;
5481 struct fc_els_rdf_resp *rdf_resp;
5482
5483 switch (flag) {
5484 case ELS_CMD_ACC:
5485 cmdsize = sizeof(uint32_t);
5486 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5487 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5488 if (!elsiocb) {
5489 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
5490 return 1;
5491 }
5492
5493 if (phba->sli_rev == LPFC_SLI_REV4) {
5494 wqe = &elsiocb->wqe;
5495 /* XRI / rx_id */
5496 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5497 bf_get(wqe_ctxt_tag,
5498 &oldwqe->xmit_els_rsp.wqe_com));
5499
5500 /* oxid */
5501 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5502 bf_get(wqe_rcvoxid,
5503 &oldwqe->xmit_els_rsp.wqe_com));
5504 } else {
5505 icmd = &elsiocb->iocb;
5506 oldcmd = &oldiocb->iocb;
5507 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5508 icmd->unsli3.rcvsli3.ox_id =
5509 oldcmd->unsli3.rcvsli3.ox_id;
5510 }
5511
5512 pcmd = elsiocb->cmd_dmabuf->virt;
5513 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5514 pcmd += sizeof(uint32_t);
5515
5516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5517 "Issue ACC: did:x%x flg:x%lx",
5518 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5519 break;
5520 case ELS_CMD_FLOGI:
5521 case ELS_CMD_PLOGI:
5522 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
5523 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5524 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5525 if (!elsiocb)
5526 return 1;
5527
5528 if (phba->sli_rev == LPFC_SLI_REV4) {
5529 wqe = &elsiocb->wqe;
5530 /* XRI / rx_id */
5531 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5532 bf_get(wqe_ctxt_tag,
5533 &oldwqe->xmit_els_rsp.wqe_com));
5534
5535 /* oxid */
5536 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5537 bf_get(wqe_rcvoxid,
5538 &oldwqe->xmit_els_rsp.wqe_com));
5539 } else {
5540 icmd = &elsiocb->iocb;
5541 oldcmd = &oldiocb->iocb;
5542 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5543 icmd->unsli3.rcvsli3.ox_id =
5544 oldcmd->unsli3.rcvsli3.ox_id;
5545 }
5546
5547 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5548
5549 if (mbox)
5550 elsiocb->context_un.mbox = mbox;
5551
5552 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5553 pcmd += sizeof(uint32_t);
5554 sp = (struct serv_parm *)pcmd;
5555
5556 if (flag == ELS_CMD_FLOGI) {
5557 /* Copy the received service parameters back */
5558 memcpy(sp, &phba->fc_fabparam,
5559 sizeof(struct serv_parm));
5560
5561 /* Clear the F_Port bit */
5562 sp->cmn.fPort = 0;
5563
5564 /* Mark all class service parameters as invalid */
5565 sp->cls1.classValid = 0;
5566 sp->cls2.classValid = 0;
5567 sp->cls3.classValid = 0;
5568 sp->cls4.classValid = 0;
5569
5570 /* Copy our worldwide names */
5571 memcpy(&sp->portName, &vport->fc_sparam.portName,
5572 sizeof(struct lpfc_name));
5573 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
5574 sizeof(struct lpfc_name));
5575 } else {
5576 memcpy(pcmd, &vport->fc_sparam,
5577 sizeof(struct serv_parm));
5578
5579 sp->cmn.valid_vendor_ver_level = 0;
5580 memset(sp->un.vendorVersion, 0,
5581 sizeof(sp->un.vendorVersion));
5582 sp->cmn.bbRcvSizeMsb &= 0xF;
5583
5584 /* If our firmware supports this feature, convey that
5585 * info to the target using the vendor specific field.
5586 */
5587 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
5588 sp->cmn.valid_vendor_ver_level = 1;
5589 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
5590 sp->un.vv.flags =
5591 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
5592 }
5593 }
5594
5595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5596 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%lx",
5597 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5598 break;
5599 case ELS_CMD_PRLO:
5600 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
5601 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5602 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
5603 if (!elsiocb)
5604 return 1;
5605
5606 if (phba->sli_rev == LPFC_SLI_REV4) {
5607 wqe = &elsiocb->wqe;
5608 /* XRI / rx_id */
5609 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5610 bf_get(wqe_ctxt_tag,
5611 &oldwqe->xmit_els_rsp.wqe_com));
5612
5613 /* oxid */
5614 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5615 bf_get(wqe_rcvoxid,
5616 &oldwqe->xmit_els_rsp.wqe_com));
5617 } else {
5618 icmd = &elsiocb->iocb;
5619 oldcmd = &oldiocb->iocb;
5620 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5621 icmd->unsli3.rcvsli3.ox_id =
5622 oldcmd->unsli3.rcvsli3.ox_id;
5623 }
5624
5625 pcmd = (u8 *) elsiocb->cmd_dmabuf->virt;
5626
5627 memcpy(pcmd, oldiocb->cmd_dmabuf->virt,
5628 sizeof(uint32_t) + sizeof(PRLO));
5629 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
5630 els_pkt_ptr = (ELS_PKT *) pcmd;
5631 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
5632
5633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5634 "Issue ACC PRLO: did:x%x flg:x%lx",
5635 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5636 break;
5637 case ELS_CMD_RDF:
5638 cmdsize = sizeof(*rdf_resp);
5639 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
5640 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5641 if (!elsiocb)
5642 return 1;
5643
5644 if (phba->sli_rev == LPFC_SLI_REV4) {
5645 wqe = &elsiocb->wqe;
5646 /* XRI / rx_id */
5647 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
5648 bf_get(wqe_ctxt_tag,
5649 &oldwqe->xmit_els_rsp.wqe_com));
5650
5651 /* oxid */
5652 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5653 bf_get(wqe_rcvoxid,
5654 &oldwqe->xmit_els_rsp.wqe_com));
5655 } else {
5656 icmd = &elsiocb->iocb;
5657 oldcmd = &oldiocb->iocb;
5658 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5659 icmd->unsli3.rcvsli3.ox_id =
5660 oldcmd->unsli3.rcvsli3.ox_id;
5661 }
5662
5663 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
5664 rdf_resp = (struct fc_els_rdf_resp *)pcmd;
5665 memset(rdf_resp, 0, sizeof(*rdf_resp));
5666 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
5667
5668 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5669 rdf_resp->desc_list_len = cpu_to_be32(12);
5670
5671 /* FC-LS-5 specifies LS REQ Information descriptor */
5672 rdf_resp->lsri.desc_tag = cpu_to_be32(1);
5673 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
5674 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
5675 break;
5676 default:
5677 return 1;
5678 }
5679 if (test_bit(NLP_LOGO_ACC, &ndlp->nlp_flag)) {
5680 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag) &&
5681 !test_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag))
5682 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag);
5683 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc;
5684 } else {
5685 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5686 }
5687
5688 phba->fc_stat.elsXmitACC++;
5689 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5690 if (!elsiocb->ndlp) {
5691 lpfc_els_free_iocb(phba, elsiocb);
5692 return 1;
5693 }
5694
5695 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5696 if (rc == IOCB_ERROR) {
5697 lpfc_els_free_iocb(phba, elsiocb);
5698 lpfc_nlp_put(ndlp);
5699 return 1;
5700 }
5701
5702 /* Xmit ELS ACC response tag <ulpIoTag> */
5703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5704 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5705 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x "
5706 "RPI: x%x, fc_flag x%lx refcnt %d\n",
5707 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5708 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5709 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
5710 return 0;
5711 }
5712
5713 /**
5714 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5715 * @vport: pointer to a virtual N_Port data structure.
5716 * @rejectError: reject response to issue
5717 * @oldiocb: pointer to the original lpfc command iocb data structure.
5718 * @ndlp: pointer to a node-list data structure.
5719 * @mbox: pointer to the driver internal queue element for mailbox command.
5720 *
5721 * This routine prepares and issue an Reject (RJT) response IOCB
5722 * command. If a @mbox pointer is passed in, it will be put into the
5723 * context_un.mbox field of the IOCB for the completion callback function
5724 * to issue to the HBA later.
5725 *
5726 * Note that the ndlp reference count will be incremented by 1 for holding the
5727 * ndlp and the reference to ndlp will be stored into the ndlp field of
5728 * the IOCB for the completion callback function to the reject response
5729 * ELS IOCB command.
5730 *
5731 * Return code
5732 * 0 - Successfully issued reject response
5733 * 1 - Failed to issue reject response
5734 **/
5735 int
lpfc_els_rsp_reject(struct lpfc_vport * vport,uint32_t rejectError,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp,LPFC_MBOXQ_t * mbox)5736 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
5737 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
5738 LPFC_MBOXQ_t *mbox)
5739 {
5740 int rc;
5741 struct lpfc_hba *phba = vport->phba;
5742 IOCB_t *icmd;
5743 IOCB_t *oldcmd;
5744 union lpfc_wqe128 *wqe;
5745 struct lpfc_iocbq *elsiocb;
5746 uint8_t *pcmd;
5747 uint16_t cmdsize;
5748
5749 cmdsize = 2 * sizeof(uint32_t);
5750 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5751 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5752 if (!elsiocb)
5753 return 1;
5754
5755 if (phba->sli_rev == LPFC_SLI_REV4) {
5756 wqe = &elsiocb->wqe;
5757 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5758 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
5759 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5760 get_job_rcvoxid(phba, oldiocb));
5761 } else {
5762 icmd = &elsiocb->iocb;
5763 oldcmd = &oldiocb->iocb;
5764 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5765 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5766 }
5767
5768 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
5769
5770 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5771 pcmd += sizeof(uint32_t);
5772 *((uint32_t *) (pcmd)) = rejectError;
5773
5774 if (mbox)
5775 elsiocb->context_un.mbox = mbox;
5776
5777 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5779 "0129 Xmit ELS RJT x%x response tag x%x "
5780 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, "
5781 "rpi x%x\n",
5782 rejectError, elsiocb->iotag,
5783 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID,
5784 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
5785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5786 "Issue LS_RJT: did:x%x flg:x%lx err:x%x",
5787 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
5788
5789 phba->fc_stat.elsXmitLSRJT++;
5790 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5791 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5792 if (!elsiocb->ndlp) {
5793 lpfc_els_free_iocb(phba, elsiocb);
5794 return 1;
5795 }
5796
5797 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5798 if (rc == IOCB_ERROR) {
5799 lpfc_els_free_iocb(phba, elsiocb);
5800 lpfc_nlp_put(ndlp);
5801 return 1;
5802 }
5803
5804 return 0;
5805 }
5806
5807 /**
5808 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5809 * @vport: pointer to a host virtual N_Port data structure.
5810 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5811 * @ndlp: NPort to where rsp is directed
5812 *
5813 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5814 * this N_Port's support of hardware signals in its Congestion
5815 * Capabilities Descriptor.
5816 *
5817 * Return code
5818 * 0 - Successfully issued edc rsp command
5819 * 1 - Failed to issue edc rsp command
5820 **/
5821 static int
lpfc_issue_els_edc_rsp(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)5822 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5823 struct lpfc_nodelist *ndlp)
5824 {
5825 struct lpfc_hba *phba = vport->phba;
5826 struct fc_els_edc_resp *edc_rsp;
5827 struct fc_tlv_desc *tlv;
5828 struct lpfc_iocbq *elsiocb;
5829 IOCB_t *icmd, *cmd;
5830 union lpfc_wqe128 *wqe;
5831 u32 cgn_desc_size, lft_desc_size;
5832 u16 cmdsize;
5833 uint8_t *pcmd;
5834 int rc;
5835
5836 cmdsize = sizeof(struct fc_els_edc_resp);
5837 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
5838 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
5839 sizeof(struct fc_diag_lnkflt_desc) : 0;
5840 cmdsize += cgn_desc_size + lft_desc_size;
5841 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
5842 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
5843 if (!elsiocb)
5844 return 1;
5845
5846 if (phba->sli_rev == LPFC_SLI_REV4) {
5847 wqe = &elsiocb->wqe;
5848 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5849 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */
5850 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5851 get_job_rcvoxid(phba, cmdiocb));
5852 } else {
5853 icmd = &elsiocb->iocb;
5854 cmd = &cmdiocb->iocb;
5855 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
5856 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
5857 }
5858
5859 pcmd = elsiocb->cmd_dmabuf->virt;
5860 memset(pcmd, 0, cmdsize);
5861
5862 edc_rsp = (struct fc_els_edc_resp *)pcmd;
5863 edc_rsp->acc_hdr.la_cmd = ELS_LS_ACC;
5864 edc_rsp->desc_list_len = cpu_to_be32(sizeof(struct fc_els_lsri_desc) +
5865 cgn_desc_size + lft_desc_size);
5866 edc_rsp->lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
5867 edc_rsp->lsri.desc_len = cpu_to_be32(
5868 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
5869 edc_rsp->lsri.rqst_w0.cmd = ELS_EDC;
5870 tlv = edc_rsp->desc;
5871 lpfc_format_edc_cgn_desc(phba, tlv);
5872 tlv = fc_tlv_next_desc(tlv);
5873 if (lft_desc_size)
5874 lpfc_format_edc_lft_desc(phba, tlv);
5875
5876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5877 "Issue EDC ACC: did:x%x flg:x%lx refcnt %d",
5878 ndlp->nlp_DID, ndlp->nlp_flag,
5879 kref_read(&ndlp->kref));
5880 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5881
5882 phba->fc_stat.elsXmitACC++;
5883 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5884 if (!elsiocb->ndlp) {
5885 lpfc_els_free_iocb(phba, elsiocb);
5886 return 1;
5887 }
5888
5889 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5890 if (rc == IOCB_ERROR) {
5891 lpfc_els_free_iocb(phba, elsiocb);
5892 lpfc_nlp_put(ndlp);
5893 return 1;
5894 }
5895
5896 /* Xmit ELS ACC response tag <ulpIoTag> */
5897 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5898 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5899 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x "
5900 "RPI: x%x, fc_flag x%lx\n",
5901 rc, elsiocb->iotag, elsiocb->sli4_xritag,
5902 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5903 ndlp->nlp_rpi, vport->fc_flag);
5904
5905 return 0;
5906 }
5907
5908 /**
5909 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5910 * @vport: pointer to a virtual N_Port data structure.
5911 * @oldiocb: pointer to the original lpfc command iocb data structure.
5912 * @ndlp: pointer to a node-list data structure.
5913 *
5914 * This routine prepares and issues an Accept (ACC) response to Address
5915 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5916 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5917 *
5918 * Note that the ndlp reference count will be incremented by 1 for holding the
5919 * ndlp and the reference to ndlp will be stored into the ndlp field of
5920 * the IOCB for the completion callback function to the ADISC Accept response
5921 * ELS IOCB command.
5922 *
5923 * Return code
5924 * 0 - Successfully issued acc adisc response
5925 * 1 - Failed to issue adisc acc response
5926 **/
5927 int
lpfc_els_rsp_adisc_acc(struct lpfc_vport * vport,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)5928 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5929 struct lpfc_nodelist *ndlp)
5930 {
5931 struct lpfc_hba *phba = vport->phba;
5932 ADISC *ap;
5933 IOCB_t *icmd, *oldcmd;
5934 union lpfc_wqe128 *wqe;
5935 struct lpfc_iocbq *elsiocb;
5936 uint8_t *pcmd;
5937 uint16_t cmdsize;
5938 int rc;
5939 u32 ulp_context;
5940
5941 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
5942 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5943 ndlp->nlp_DID, ELS_CMD_ACC);
5944 if (!elsiocb)
5945 return 1;
5946
5947 if (phba->sli_rev == LPFC_SLI_REV4) {
5948 wqe = &elsiocb->wqe;
5949 /* XRI / rx_id */
5950 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
5951 get_job_ulpcontext(phba, oldiocb));
5952 ulp_context = get_job_ulpcontext(phba, elsiocb);
5953 /* oxid */
5954 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
5955 get_job_rcvoxid(phba, oldiocb));
5956 } else {
5957 icmd = &elsiocb->iocb;
5958 oldcmd = &oldiocb->iocb;
5959 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5960 ulp_context = elsiocb->iocb.ulpContext;
5961 icmd->unsli3.rcvsli3.ox_id =
5962 oldcmd->unsli3.rcvsli3.ox_id;
5963 }
5964
5965 /* Xmit ADISC ACC response tag <ulpIoTag> */
5966 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5967 "0130 Xmit ADISC ACC response iotag x%x xri: "
5968 "x%x, did x%x, nlp_flag x%lx, nlp_state x%x rpi x%x\n",
5969 elsiocb->iotag, ulp_context,
5970 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5971 ndlp->nlp_rpi);
5972 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
5973
5974 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5975 pcmd += sizeof(uint32_t);
5976
5977 ap = (ADISC *) (pcmd);
5978 ap->hardAL_PA = phba->fc_pref_ALPA;
5979 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5980 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5981 ap->DID = be32_to_cpu(vport->fc_myDID);
5982
5983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5984 "Issue ACC ADISC: did:x%x flg:x%lx refcnt %d",
5985 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
5986
5987 phba->fc_stat.elsXmitACC++;
5988 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
5989 elsiocb->ndlp = lpfc_nlp_get(ndlp);
5990 if (!elsiocb->ndlp) {
5991 lpfc_els_free_iocb(phba, elsiocb);
5992 return 1;
5993 }
5994
5995 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5996 if (rc == IOCB_ERROR) {
5997 lpfc_els_free_iocb(phba, elsiocb);
5998 lpfc_nlp_put(ndlp);
5999 return 1;
6000 }
6001
6002 return 0;
6003 }
6004
6005 /**
6006 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
6007 * @vport: pointer to a virtual N_Port data structure.
6008 * @oldiocb: pointer to the original lpfc command iocb data structure.
6009 * @ndlp: pointer to a node-list data structure.
6010 *
6011 * This routine prepares and issues an Accept (ACC) response to Process
6012 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
6013 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
6014 *
6015 * Note that the ndlp reference count will be incremented by 1 for holding the
6016 * ndlp and the reference to ndlp will be stored into the ndlp field of
6017 * the IOCB for the completion callback function to the PRLI Accept response
6018 * ELS IOCB command.
6019 *
6020 * Return code
6021 * 0 - Successfully issued acc prli response
6022 * 1 - Failed to issue acc prli response
6023 **/
6024 int
lpfc_els_rsp_prli_acc(struct lpfc_vport * vport,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)6025 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
6026 struct lpfc_nodelist *ndlp)
6027 {
6028 struct lpfc_hba *phba = vport->phba;
6029 PRLI *npr;
6030 struct lpfc_nvme_prli *npr_nvme;
6031 lpfc_vpd_t *vpd;
6032 IOCB_t *icmd;
6033 IOCB_t *oldcmd;
6034 union lpfc_wqe128 *wqe;
6035 struct lpfc_iocbq *elsiocb;
6036 uint8_t *pcmd;
6037 uint16_t cmdsize;
6038 uint32_t prli_fc4_req, *req_payload;
6039 struct lpfc_dmabuf *req_buf;
6040 int rc;
6041 u32 elsrspcmd, ulp_context;
6042
6043 /* Need the incoming PRLI payload to determine if the ACC is for an
6044 * FC4 or NVME PRLI type. The PRLI type is at word 1.
6045 */
6046 req_buf = oldiocb->cmd_dmabuf;
6047 req_payload = (((uint32_t *)req_buf->virt) + 1);
6048
6049 /* PRLI type payload is at byte 3 for FCP or NVME. */
6050 prli_fc4_req = be32_to_cpu(*req_payload);
6051 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
6052 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6053 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
6054 prli_fc4_req, *((uint32_t *)req_payload));
6055
6056 if (prli_fc4_req == PRLI_FCP_TYPE) {
6057 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
6058 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
6059 } else if (prli_fc4_req == PRLI_NVME_TYPE) {
6060 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
6061 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
6062 } else {
6063 return 1;
6064 }
6065
6066 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6067 ndlp->nlp_DID, elsrspcmd);
6068 if (!elsiocb)
6069 return 1;
6070
6071 if (phba->sli_rev == LPFC_SLI_REV4) {
6072 wqe = &elsiocb->wqe;
6073 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6074 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6075 ulp_context = get_job_ulpcontext(phba, elsiocb);
6076 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6077 get_job_rcvoxid(phba, oldiocb));
6078 } else {
6079 icmd = &elsiocb->iocb;
6080 oldcmd = &oldiocb->iocb;
6081 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6082 ulp_context = elsiocb->iocb.ulpContext;
6083 icmd->unsli3.rcvsli3.ox_id =
6084 oldcmd->unsli3.rcvsli3.ox_id;
6085 }
6086
6087 /* Xmit PRLI ACC response tag <ulpIoTag> */
6088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6089 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
6090 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n",
6091 elsiocb->iotag, ulp_context,
6092 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6093 ndlp->nlp_rpi);
6094 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6095 memset(pcmd, 0, cmdsize);
6096
6097 *((uint32_t *)(pcmd)) = elsrspcmd;
6098 pcmd += sizeof(uint32_t);
6099
6100 /* For PRLI, remainder of payload is PRLI parameter page */
6101 vpd = &phba->vpd;
6102
6103 if (prli_fc4_req == PRLI_FCP_TYPE) {
6104 /*
6105 * If the remote port is a target and our firmware version
6106 * is 3.20 or later, set the following bits for FC-TAPE
6107 * support.
6108 */
6109 npr = (PRLI *) pcmd;
6110 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
6111 (vpd->rev.feaLevelHigh >= 0x02)) {
6112 npr->ConfmComplAllowed = 1;
6113 npr->Retry = 1;
6114 npr->TaskRetryIdReq = 1;
6115 }
6116 npr->acceptRspCode = PRLI_REQ_EXECUTED;
6117
6118 /* Set image pair for complementary pairs only. */
6119 if (ndlp->nlp_type & NLP_FCP_TARGET)
6120 npr->estabImagePair = 1;
6121 else
6122 npr->estabImagePair = 0;
6123 npr->readXferRdyDis = 1;
6124 npr->ConfmComplAllowed = 1;
6125 npr->prliType = PRLI_FCP_TYPE;
6126 npr->initiatorFunc = 1;
6127
6128 /* Xmit PRLI ACC response tag <ulpIoTag> */
6129 lpfc_printf_vlog(vport, KERN_INFO,
6130 LOG_ELS | LOG_NODE | LOG_DISCOVERY,
6131 "6014 FCP issue PRLI ACC imgpair %d "
6132 "retry %d task %d\n",
6133 npr->estabImagePair,
6134 npr->Retry, npr->TaskRetryIdReq);
6135
6136 } else if (prli_fc4_req == PRLI_NVME_TYPE) {
6137 /* Respond with an NVME PRLI Type */
6138 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
6139 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
6140 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
6141 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
6142 if (phba->nvmet_support) {
6143 bf_set(prli_tgt, npr_nvme, 1);
6144 bf_set(prli_disc, npr_nvme, 1);
6145 if (phba->cfg_nvme_enable_fb) {
6146 bf_set(prli_fba, npr_nvme, 1);
6147
6148 /* TBD. Target mode needs to post buffers
6149 * that support the configured first burst
6150 * byte size.
6151 */
6152 bf_set(prli_fb_sz, npr_nvme,
6153 phba->cfg_nvmet_fb_size);
6154 }
6155 } else {
6156 bf_set(prli_init, npr_nvme, 1);
6157 }
6158
6159 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
6160 "6015 NVME issue PRLI ACC word1 x%08x "
6161 "word4 x%08x word5 x%08x flag x%lx, "
6162 "fcp_info x%x nlp_type x%x\n",
6163 npr_nvme->word1, npr_nvme->word4,
6164 npr_nvme->word5, ndlp->nlp_flag,
6165 ndlp->nlp_fcp_info, ndlp->nlp_type);
6166 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
6167 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
6168 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
6169 } else
6170 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6171 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
6172 prli_fc4_req, ndlp->nlp_fc4_type,
6173 ndlp->nlp_DID);
6174
6175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6176 "Issue ACC PRLI: did:x%x flg:x%lx",
6177 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6178
6179 phba->fc_stat.elsXmitACC++;
6180 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6181 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6182 if (!elsiocb->ndlp) {
6183 lpfc_els_free_iocb(phba, elsiocb);
6184 return 1;
6185 }
6186
6187 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6188 if (rc == IOCB_ERROR) {
6189 lpfc_els_free_iocb(phba, elsiocb);
6190 lpfc_nlp_put(ndlp);
6191 return 1;
6192 }
6193
6194 return 0;
6195 }
6196
6197 /**
6198 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
6199 * @vport: pointer to a virtual N_Port data structure.
6200 * @format: rnid command format.
6201 * @oldiocb: pointer to the original lpfc command iocb data structure.
6202 * @ndlp: pointer to a node-list data structure.
6203 *
6204 * This routine issues a Request Node Identification Data (RNID) Accept
6205 * (ACC) response. It constructs the RNID ACC response command according to
6206 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
6207 * issue the response.
6208 *
6209 * Note that the ndlp reference count will be incremented by 1 for holding the
6210 * ndlp and the reference to ndlp will be stored into the ndlp field of
6211 * the IOCB for the completion callback function.
6212 *
6213 * Return code
6214 * 0 - Successfully issued acc rnid response
6215 * 1 - Failed to issue acc rnid response
6216 **/
6217 static int
lpfc_els_rsp_rnid_acc(struct lpfc_vport * vport,uint8_t format,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)6218 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
6219 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6220 {
6221 struct lpfc_hba *phba = vport->phba;
6222 RNID *rn;
6223 IOCB_t *icmd, *oldcmd;
6224 union lpfc_wqe128 *wqe;
6225 struct lpfc_iocbq *elsiocb;
6226 uint8_t *pcmd;
6227 uint16_t cmdsize;
6228 int rc;
6229 u32 ulp_context;
6230
6231 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
6232 + (2 * sizeof(struct lpfc_name));
6233 if (format)
6234 cmdsize += sizeof(RNID_TOP_DISC);
6235
6236 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6237 ndlp->nlp_DID, ELS_CMD_ACC);
6238 if (!elsiocb)
6239 return 1;
6240
6241 if (phba->sli_rev == LPFC_SLI_REV4) {
6242 wqe = &elsiocb->wqe;
6243 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6244 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6245 ulp_context = get_job_ulpcontext(phba, elsiocb);
6246 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6247 get_job_rcvoxid(phba, oldiocb));
6248 } else {
6249 icmd = &elsiocb->iocb;
6250 oldcmd = &oldiocb->iocb;
6251 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6252 ulp_context = elsiocb->iocb.ulpContext;
6253 icmd->unsli3.rcvsli3.ox_id =
6254 oldcmd->unsli3.rcvsli3.ox_id;
6255 }
6256
6257 /* Xmit RNID ACC response tag <ulpIoTag> */
6258 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6259 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6260 elsiocb->iotag, ulp_context);
6261 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6262 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6263 pcmd += sizeof(uint32_t);
6264
6265 memset(pcmd, 0, sizeof(RNID));
6266 rn = (RNID *) (pcmd);
6267 rn->Format = format;
6268 rn->CommonLen = (2 * sizeof(struct lpfc_name));
6269 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
6270 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
6271 switch (format) {
6272 case 0:
6273 rn->SpecificLen = 0;
6274 break;
6275 case RNID_TOPOLOGY_DISC:
6276 rn->SpecificLen = sizeof(RNID_TOP_DISC);
6277 memcpy(&rn->un.topologyDisc.portName,
6278 &vport->fc_portname, sizeof(struct lpfc_name));
6279 rn->un.topologyDisc.unitType = RNID_HBA;
6280 rn->un.topologyDisc.physPort = 0;
6281 rn->un.topologyDisc.attachedNodes = 0;
6282 break;
6283 default:
6284 rn->CommonLen = 0;
6285 rn->SpecificLen = 0;
6286 break;
6287 }
6288
6289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6290 "Issue ACC RNID: did:x%x flg:x%lx refcnt %d",
6291 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6292
6293 phba->fc_stat.elsXmitACC++;
6294 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6295 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6296 if (!elsiocb->ndlp) {
6297 lpfc_els_free_iocb(phba, elsiocb);
6298 return 1;
6299 }
6300
6301 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6302 if (rc == IOCB_ERROR) {
6303 lpfc_els_free_iocb(phba, elsiocb);
6304 lpfc_nlp_put(ndlp);
6305 return 1;
6306 }
6307
6308 return 0;
6309 }
6310
6311 /**
6312 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6313 * @vport: pointer to a virtual N_Port data structure.
6314 * @iocb: pointer to the lpfc command iocb data structure.
6315 * @ndlp: pointer to a node-list data structure.
6316 *
6317 * Return
6318 **/
6319 static void
lpfc_els_clear_rrq(struct lpfc_vport * vport,struct lpfc_iocbq * iocb,struct lpfc_nodelist * ndlp)6320 lpfc_els_clear_rrq(struct lpfc_vport *vport,
6321 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
6322 {
6323 struct lpfc_hba *phba = vport->phba;
6324 uint8_t *pcmd;
6325 struct RRQ *rrq;
6326 uint16_t rxid;
6327 uint16_t xri;
6328 struct lpfc_node_rrq *prrq;
6329
6330
6331 pcmd = (uint8_t *)iocb->cmd_dmabuf->virt;
6332 pcmd += sizeof(uint32_t);
6333 rrq = (struct RRQ *)pcmd;
6334 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
6335 rxid = bf_get(rrq_rxid, rrq);
6336
6337 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6338 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6339 " x%x x%x\n",
6340 be32_to_cpu(bf_get(rrq_did, rrq)),
6341 bf_get(rrq_oxid, rrq),
6342 rxid,
6343 get_wqe_reqtag(iocb),
6344 get_job_ulpcontext(phba, iocb));
6345
6346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6347 "Clear RRQ: did:x%x flg:x%lx exchg:x%.08x",
6348 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
6349 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
6350 xri = bf_get(rrq_oxid, rrq);
6351 else
6352 xri = rxid;
6353 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
6354 if (prrq)
6355 lpfc_clr_rrq_active(phba, xri, prrq);
6356 return;
6357 }
6358
6359 /**
6360 * lpfc_els_rsp_echo_acc - Issue echo acc response
6361 * @vport: pointer to a virtual N_Port data structure.
6362 * @data: pointer to echo data to return in the accept.
6363 * @oldiocb: pointer to the original lpfc command iocb data structure.
6364 * @ndlp: pointer to a node-list data structure.
6365 *
6366 * Return code
6367 * 0 - Successfully issued acc echo response
6368 * 1 - Failed to issue acc echo response
6369 **/
6370 static int
lpfc_els_rsp_echo_acc(struct lpfc_vport * vport,uint8_t * data,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)6371 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
6372 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
6373 {
6374 struct lpfc_hba *phba = vport->phba;
6375 IOCB_t *icmd, *oldcmd;
6376 union lpfc_wqe128 *wqe;
6377 struct lpfc_iocbq *elsiocb;
6378 uint8_t *pcmd;
6379 uint16_t cmdsize;
6380 int rc;
6381 u32 ulp_context;
6382
6383 if (phba->sli_rev == LPFC_SLI_REV4)
6384 cmdsize = oldiocb->wcqe_cmpl.total_data_placed;
6385 else
6386 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
6387
6388 /* The accumulated length can exceed the BPL_SIZE. For
6389 * now, use this as the limit
6390 */
6391 if (cmdsize > LPFC_BPL_SIZE)
6392 cmdsize = LPFC_BPL_SIZE;
6393 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6394 ndlp->nlp_DID, ELS_CMD_ACC);
6395 if (!elsiocb)
6396 return 1;
6397
6398 if (phba->sli_rev == LPFC_SLI_REV4) {
6399 wqe = &elsiocb->wqe;
6400 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
6401 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
6402 ulp_context = get_job_ulpcontext(phba, elsiocb);
6403 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
6404 get_job_rcvoxid(phba, oldiocb));
6405 } else {
6406 icmd = &elsiocb->iocb;
6407 oldcmd = &oldiocb->iocb;
6408 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6409 ulp_context = elsiocb->iocb.ulpContext;
6410 icmd->unsli3.rcvsli3.ox_id =
6411 oldcmd->unsli3.rcvsli3.ox_id;
6412 }
6413
6414 /* Xmit ECHO ACC response tag <ulpIoTag> */
6415 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6416 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6417 elsiocb->iotag, ulp_context);
6418 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
6419 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6420 pcmd += sizeof(uint32_t);
6421 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
6422
6423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
6424 "Issue ACC ECHO: did:x%x flg:x%lx refcnt %d",
6425 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
6426
6427 phba->fc_stat.elsXmitACC++;
6428 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
6429 elsiocb->ndlp = lpfc_nlp_get(ndlp);
6430 if (!elsiocb->ndlp) {
6431 lpfc_els_free_iocb(phba, elsiocb);
6432 return 1;
6433 }
6434
6435 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6436 if (rc == IOCB_ERROR) {
6437 lpfc_els_free_iocb(phba, elsiocb);
6438 lpfc_nlp_put(ndlp);
6439 return 1;
6440 }
6441
6442 return 0;
6443 }
6444
6445 /**
6446 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
6447 * @vport: pointer to a host virtual N_Port data structure.
6448 *
6449 * This routine issues Address Discover (ADISC) ELS commands to those
6450 * N_Ports which are in node port recovery state and ADISC has not been issued
6451 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6452 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6453 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6454 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6455 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6456 * IOCBs quit for later pick up. On the other hand, after walking through
6457 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6458 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6459 * no more ADISC need to be sent.
6460 *
6461 * Return code
6462 * The number of N_Ports with adisc issued.
6463 **/
6464 int
lpfc_els_disc_adisc(struct lpfc_vport * vport)6465 lpfc_els_disc_adisc(struct lpfc_vport *vport)
6466 {
6467 struct lpfc_nodelist *ndlp, *next_ndlp;
6468 int sentadisc = 0;
6469
6470 /* go thru NPR nodes and issue any remaining ELS ADISCs */
6471 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6472
6473 if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
6474 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag))
6475 continue;
6476
6477 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag);
6478
6479 if (!test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) {
6480 /* This node was marked for ADISC but was not picked
6481 * for discovery. This is possible if the node was
6482 * missing in gidft response.
6483 *
6484 * At time of marking node for ADISC, we skipped unreg
6485 * from backend
6486 */
6487 lpfc_nlp_unreg_node(vport, ndlp);
6488 lpfc_unreg_rpi(vport, ndlp);
6489 continue;
6490 }
6491
6492 ndlp->nlp_prev_state = ndlp->nlp_state;
6493 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
6494 lpfc_issue_els_adisc(vport, ndlp, 0);
6495 sentadisc++;
6496 vport->num_disc_nodes++;
6497 if (vport->num_disc_nodes >=
6498 vport->cfg_discovery_threads) {
6499 set_bit(FC_NLP_MORE, &vport->fc_flag);
6500 break;
6501 }
6502
6503 }
6504 if (sentadisc == 0)
6505 clear_bit(FC_NLP_MORE, &vport->fc_flag);
6506 return sentadisc;
6507 }
6508
6509 /**
6510 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
6511 * @vport: pointer to a host virtual N_Port data structure.
6512 *
6513 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6514 * which are in node port recovery state, with a @vport. Each time an ELS
6515 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6516 * the per @vport number of discover count (num_disc_nodes) shall be
6517 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6518 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6519 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6520 * later pick up. On the other hand, after walking through all the ndlps with
6521 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6522 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6523 * PLOGI need to be sent.
6524 *
6525 * Return code
6526 * The number of N_Ports with plogi issued.
6527 **/
6528 int
lpfc_els_disc_plogi(struct lpfc_vport * vport)6529 lpfc_els_disc_plogi(struct lpfc_vport *vport)
6530 {
6531 struct lpfc_nodelist *ndlp, *next_ndlp;
6532 int sentplogi = 0;
6533
6534 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6535 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
6536 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
6537 test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag) &&
6538 !test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) &&
6539 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) {
6540 ndlp->nlp_prev_state = ndlp->nlp_state;
6541 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6542 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
6543 sentplogi++;
6544 vport->num_disc_nodes++;
6545 if (vport->num_disc_nodes >=
6546 vport->cfg_discovery_threads) {
6547 set_bit(FC_NLP_MORE, &vport->fc_flag);
6548 break;
6549 }
6550 }
6551 }
6552
6553 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6554 "6452 Discover PLOGI %d flag x%lx\n",
6555 sentplogi, vport->fc_flag);
6556
6557 if (sentplogi)
6558 lpfc_set_disctmo(vport);
6559 else
6560 clear_bit(FC_NLP_MORE, &vport->fc_flag);
6561 return sentplogi;
6562 }
6563
6564 static uint32_t
lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc * desc,uint32_t word0)6565 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
6566 uint32_t word0)
6567 {
6568
6569 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
6570 desc->payload.els_req = word0;
6571 desc->length = cpu_to_be32(sizeof(desc->payload));
6572
6573 return sizeof(struct fc_rdp_link_service_desc);
6574 }
6575
6576 static uint32_t
lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc * desc,uint8_t * page_a0,uint8_t * page_a2)6577 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
6578 uint8_t *page_a0, uint8_t *page_a2)
6579 {
6580 uint16_t wavelength;
6581 uint16_t temperature;
6582 uint16_t rx_power;
6583 uint16_t tx_bias;
6584 uint16_t tx_power;
6585 uint16_t vcc;
6586 uint16_t flag = 0;
6587 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
6588 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
6589
6590 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
6591
6592 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
6593 &page_a0[SSF_TRANSCEIVER_CODE_B4];
6594 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
6595 &page_a0[SSF_TRANSCEIVER_CODE_B5];
6596
6597 if ((trasn_code_byte4->fc_sw_laser) ||
6598 (trasn_code_byte5->fc_sw_laser_sl) ||
6599 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
6600 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
6601 } else if (trasn_code_byte4->fc_lw_laser) {
6602 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
6603 page_a0[SSF_WAVELENGTH_B0];
6604 if (wavelength == SFP_WAVELENGTH_LC1310)
6605 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
6606 if (wavelength == SFP_WAVELENGTH_LL1550)
6607 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
6608 }
6609 /* check if its SFP+ */
6610 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
6611 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
6612 << SFP_FLAG_CT_SHIFT;
6613
6614 /* check if its OPTICAL */
6615 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
6616 SFP_FLAG_IS_OPTICAL_PORT : 0)
6617 << SFP_FLAG_IS_OPTICAL_SHIFT;
6618
6619 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
6620 page_a2[SFF_TEMPERATURE_B0]);
6621 vcc = (page_a2[SFF_VCC_B1] << 8 |
6622 page_a2[SFF_VCC_B0]);
6623 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
6624 page_a2[SFF_TXPOWER_B0]);
6625 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
6626 page_a2[SFF_TX_BIAS_CURRENT_B0]);
6627 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
6628 page_a2[SFF_RXPOWER_B0]);
6629 desc->sfp_info.temperature = cpu_to_be16(temperature);
6630 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
6631 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
6632 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
6633 desc->sfp_info.vcc = cpu_to_be16(vcc);
6634
6635 desc->sfp_info.flags = cpu_to_be16(flag);
6636 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
6637
6638 return sizeof(struct fc_rdp_sfp_desc);
6639 }
6640
6641 static uint32_t
lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc * desc,READ_LNK_VAR * stat)6642 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
6643 READ_LNK_VAR *stat)
6644 {
6645 uint32_t type;
6646
6647 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
6648
6649 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
6650
6651 desc->info.port_type = cpu_to_be32(type);
6652
6653 desc->info.link_status.link_failure_cnt =
6654 cpu_to_be32(stat->linkFailureCnt);
6655 desc->info.link_status.loss_of_synch_cnt =
6656 cpu_to_be32(stat->lossSyncCnt);
6657 desc->info.link_status.loss_of_signal_cnt =
6658 cpu_to_be32(stat->lossSignalCnt);
6659 desc->info.link_status.primitive_seq_proto_err =
6660 cpu_to_be32(stat->primSeqErrCnt);
6661 desc->info.link_status.invalid_trans_word =
6662 cpu_to_be32(stat->invalidXmitWord);
6663 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
6664
6665 desc->length = cpu_to_be32(sizeof(desc->info));
6666
6667 return sizeof(struct fc_rdp_link_error_status_desc);
6668 }
6669
6670 static uint32_t
lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc * desc,READ_LNK_VAR * stat,struct lpfc_vport * vport)6671 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
6672 struct lpfc_vport *vport)
6673 {
6674 uint32_t bbCredit;
6675
6676 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
6677
6678 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
6679 (vport->fc_sparam.cmn.bbCreditMsb << 8);
6680 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
6681 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
6682 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
6683 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
6684 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
6685 } else {
6686 desc->bbc_info.attached_port_bbc = 0;
6687 }
6688
6689 desc->bbc_info.rtt = 0;
6690 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
6691
6692 return sizeof(struct fc_rdp_bbc_desc);
6693 }
6694
6695 static uint32_t
lpfc_rdp_res_oed_temp_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)6696 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
6697 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
6698 {
6699 uint32_t flags = 0;
6700
6701 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6702
6703 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
6704 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
6705 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
6706 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
6707
6708 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6709 flags |= RDP_OET_HIGH_ALARM;
6710 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6711 flags |= RDP_OET_LOW_ALARM;
6712 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
6713 flags |= RDP_OET_HIGH_WARNING;
6714 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
6715 flags |= RDP_OET_LOW_WARNING;
6716
6717 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
6718 desc->oed_info.function_flags = cpu_to_be32(flags);
6719 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6720 return sizeof(struct fc_rdp_oed_sfp_desc);
6721 }
6722
6723 static uint32_t
lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)6724 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
6725 struct fc_rdp_oed_sfp_desc *desc,
6726 uint8_t *page_a2)
6727 {
6728 uint32_t flags = 0;
6729
6730 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6731
6732 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
6733 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
6734 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
6735 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
6736
6737 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6738 flags |= RDP_OET_HIGH_ALARM;
6739 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6740 flags |= RDP_OET_LOW_ALARM;
6741 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
6742 flags |= RDP_OET_HIGH_WARNING;
6743 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
6744 flags |= RDP_OET_LOW_WARNING;
6745
6746 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
6747 desc->oed_info.function_flags = cpu_to_be32(flags);
6748 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6749 return sizeof(struct fc_rdp_oed_sfp_desc);
6750 }
6751
6752 static uint32_t
lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)6753 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
6754 struct fc_rdp_oed_sfp_desc *desc,
6755 uint8_t *page_a2)
6756 {
6757 uint32_t flags = 0;
6758
6759 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6760
6761 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
6762 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
6763 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
6764 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
6765
6766 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6767 flags |= RDP_OET_HIGH_ALARM;
6768 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
6769 flags |= RDP_OET_LOW_ALARM;
6770 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
6771 flags |= RDP_OET_HIGH_WARNING;
6772 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
6773 flags |= RDP_OET_LOW_WARNING;
6774
6775 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
6776 desc->oed_info.function_flags = cpu_to_be32(flags);
6777 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6778 return sizeof(struct fc_rdp_oed_sfp_desc);
6779 }
6780
6781 static uint32_t
lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)6782 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
6783 struct fc_rdp_oed_sfp_desc *desc,
6784 uint8_t *page_a2)
6785 {
6786 uint32_t flags = 0;
6787
6788 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6789
6790 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
6791 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
6792 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
6793 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
6794
6795 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6796 flags |= RDP_OET_HIGH_ALARM;
6797 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
6798 flags |= RDP_OET_LOW_ALARM;
6799 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
6800 flags |= RDP_OET_HIGH_WARNING;
6801 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
6802 flags |= RDP_OET_LOW_WARNING;
6803
6804 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
6805 desc->oed_info.function_flags = cpu_to_be32(flags);
6806 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6807 return sizeof(struct fc_rdp_oed_sfp_desc);
6808 }
6809
6810
6811 static uint32_t
lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)6812 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
6813 struct fc_rdp_oed_sfp_desc *desc,
6814 uint8_t *page_a2)
6815 {
6816 uint32_t flags = 0;
6817
6818 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
6819
6820 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
6821 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
6822 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
6823 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
6824
6825 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6826 flags |= RDP_OET_HIGH_ALARM;
6827 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
6828 flags |= RDP_OET_LOW_ALARM;
6829 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
6830 flags |= RDP_OET_HIGH_WARNING;
6831 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
6832 flags |= RDP_OET_LOW_WARNING;
6833
6834 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
6835 desc->oed_info.function_flags = cpu_to_be32(flags);
6836 desc->length = cpu_to_be32(sizeof(desc->oed_info));
6837 return sizeof(struct fc_rdp_oed_sfp_desc);
6838 }
6839
6840 static uint32_t
lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc * desc,uint8_t * page_a0,struct lpfc_vport * vport)6841 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
6842 uint8_t *page_a0, struct lpfc_vport *vport)
6843 {
6844 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
6845 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
6846 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
6847 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
6848 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
6849 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
6850 desc->length = cpu_to_be32(sizeof(desc->opd_info));
6851 return sizeof(struct fc_rdp_opd_sfp_desc);
6852 }
6853
6854 static uint32_t
lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc * desc,READ_LNK_VAR * stat)6855 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
6856 {
6857 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
6858 return 0;
6859 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
6860
6861 desc->info.CorrectedBlocks =
6862 cpu_to_be32(stat->fecCorrBlkCount);
6863 desc->info.UncorrectableBlocks =
6864 cpu_to_be32(stat->fecUncorrBlkCount);
6865
6866 desc->length = cpu_to_be32(sizeof(desc->info));
6867
6868 return sizeof(struct fc_fec_rdp_desc);
6869 }
6870
6871 static uint32_t
lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc * desc,struct lpfc_hba * phba)6872 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
6873 {
6874 uint16_t rdp_cap = 0;
6875 uint16_t rdp_speed;
6876
6877 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
6878
6879 switch (phba->fc_linkspeed) {
6880 case LPFC_LINK_SPEED_1GHZ:
6881 rdp_speed = RDP_PS_1GB;
6882 break;
6883 case LPFC_LINK_SPEED_2GHZ:
6884 rdp_speed = RDP_PS_2GB;
6885 break;
6886 case LPFC_LINK_SPEED_4GHZ:
6887 rdp_speed = RDP_PS_4GB;
6888 break;
6889 case LPFC_LINK_SPEED_8GHZ:
6890 rdp_speed = RDP_PS_8GB;
6891 break;
6892 case LPFC_LINK_SPEED_10GHZ:
6893 rdp_speed = RDP_PS_10GB;
6894 break;
6895 case LPFC_LINK_SPEED_16GHZ:
6896 rdp_speed = RDP_PS_16GB;
6897 break;
6898 case LPFC_LINK_SPEED_32GHZ:
6899 rdp_speed = RDP_PS_32GB;
6900 break;
6901 case LPFC_LINK_SPEED_64GHZ:
6902 rdp_speed = RDP_PS_64GB;
6903 break;
6904 case LPFC_LINK_SPEED_128GHZ:
6905 rdp_speed = RDP_PS_128GB;
6906 break;
6907 case LPFC_LINK_SPEED_256GHZ:
6908 rdp_speed = RDP_PS_256GB;
6909 break;
6910 default:
6911 rdp_speed = RDP_PS_UNKNOWN;
6912 break;
6913 }
6914
6915 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
6916
6917 if (phba->lmt & LMT_256Gb)
6918 rdp_cap |= RDP_PS_256GB;
6919 if (phba->lmt & LMT_128Gb)
6920 rdp_cap |= RDP_PS_128GB;
6921 if (phba->lmt & LMT_64Gb)
6922 rdp_cap |= RDP_PS_64GB;
6923 if (phba->lmt & LMT_32Gb)
6924 rdp_cap |= RDP_PS_32GB;
6925 if (phba->lmt & LMT_16Gb)
6926 rdp_cap |= RDP_PS_16GB;
6927 if (phba->lmt & LMT_10Gb)
6928 rdp_cap |= RDP_PS_10GB;
6929 if (phba->lmt & LMT_8Gb)
6930 rdp_cap |= RDP_PS_8GB;
6931 if (phba->lmt & LMT_4Gb)
6932 rdp_cap |= RDP_PS_4GB;
6933 if (phba->lmt & LMT_2Gb)
6934 rdp_cap |= RDP_PS_2GB;
6935 if (phba->lmt & LMT_1Gb)
6936 rdp_cap |= RDP_PS_1GB;
6937
6938 if (rdp_cap == 0)
6939 rdp_cap = RDP_CAP_UNKNOWN;
6940 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
6941 rdp_cap |= RDP_CAP_USER_CONFIGURED;
6942
6943 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
6944 desc->length = cpu_to_be32(sizeof(desc->info));
6945 return sizeof(struct fc_rdp_port_speed_desc);
6946 }
6947
6948 static uint32_t
lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc * desc,struct lpfc_vport * vport)6949 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
6950 struct lpfc_vport *vport)
6951 {
6952
6953 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6954
6955 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
6956 sizeof(desc->port_names.wwnn));
6957
6958 memcpy(desc->port_names.wwpn, &vport->fc_portname,
6959 sizeof(desc->port_names.wwpn));
6960
6961 desc->length = cpu_to_be32(sizeof(desc->port_names));
6962 return sizeof(struct fc_rdp_port_name_desc);
6963 }
6964
6965 static uint32_t
lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc * desc,struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)6966 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
6967 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6968 {
6969
6970 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
6971 if (test_bit(FC_FABRIC, &vport->fc_flag)) {
6972 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
6973 sizeof(desc->port_names.wwnn));
6974
6975 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
6976 sizeof(desc->port_names.wwpn));
6977 } else { /* Point to Point */
6978 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
6979 sizeof(desc->port_names.wwnn));
6980
6981 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
6982 sizeof(desc->port_names.wwpn));
6983 }
6984
6985 desc->length = cpu_to_be32(sizeof(desc->port_names));
6986 return sizeof(struct fc_rdp_port_name_desc);
6987 }
6988
6989 static void
lpfc_els_rdp_cmpl(struct lpfc_hba * phba,struct lpfc_rdp_context * rdp_context,int status)6990 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
6991 int status)
6992 {
6993 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
6994 struct lpfc_vport *vport = ndlp->vport;
6995 struct lpfc_iocbq *elsiocb;
6996 struct ulp_bde64 *bpl;
6997 IOCB_t *icmd;
6998 union lpfc_wqe128 *wqe;
6999 uint8_t *pcmd;
7000 struct ls_rjt *stat;
7001 struct fc_rdp_res_frame *rdp_res;
7002 uint32_t cmdsize, len;
7003 uint16_t *flag_ptr;
7004 int rc;
7005 u32 ulp_context;
7006
7007 if (status != SUCCESS)
7008 goto error;
7009
7010 /* This will change once we know the true size of the RDP payload */
7011 cmdsize = sizeof(struct fc_rdp_res_frame);
7012
7013 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
7014 lpfc_max_els_tries, rdp_context->ndlp,
7015 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
7016 if (!elsiocb)
7017 goto free_rdp_context;
7018
7019 ulp_context = get_job_ulpcontext(phba, elsiocb);
7020 if (phba->sli_rev == LPFC_SLI_REV4) {
7021 wqe = &elsiocb->wqe;
7022 /* ox-id of the frame */
7023 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7024 rdp_context->ox_id);
7025 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
7026 rdp_context->rx_id);
7027 } else {
7028 icmd = &elsiocb->iocb;
7029 icmd->ulpContext = rdp_context->rx_id;
7030 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7031 }
7032
7033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7034 "2171 Xmit RDP response tag x%x xri x%x, "
7035 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x",
7036 elsiocb->iotag, ulp_context,
7037 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7038 ndlp->nlp_rpi);
7039 rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt;
7040 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7041 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
7042 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7043
7044 /* Update Alarm and Warning */
7045 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
7046 phba->sfp_alarm |= *flag_ptr;
7047 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
7048 phba->sfp_warning |= *flag_ptr;
7049
7050 /* For RDP payload */
7051 len = 8;
7052 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
7053 (len + pcmd), ELS_CMD_RDP);
7054
7055 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
7056 rdp_context->page_a0, rdp_context->page_a2);
7057 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
7058 phba);
7059 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
7060 (len + pcmd), &rdp_context->link_stat);
7061 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
7062 (len + pcmd), vport);
7063 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
7064 (len + pcmd), vport, ndlp);
7065 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
7066 &rdp_context->link_stat);
7067 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
7068 &rdp_context->link_stat, vport);
7069 len += lpfc_rdp_res_oed_temp_desc(phba,
7070 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7071 rdp_context->page_a2);
7072 len += lpfc_rdp_res_oed_voltage_desc(phba,
7073 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7074 rdp_context->page_a2);
7075 len += lpfc_rdp_res_oed_txbias_desc(phba,
7076 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7077 rdp_context->page_a2);
7078 len += lpfc_rdp_res_oed_txpower_desc(phba,
7079 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7080 rdp_context->page_a2);
7081 len += lpfc_rdp_res_oed_rxpower_desc(phba,
7082 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
7083 rdp_context->page_a2);
7084 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
7085 rdp_context->page_a0, vport);
7086
7087 rdp_res->length = cpu_to_be32(len - 8);
7088 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7089
7090 /* Now that we know the true size of the payload, update the BPL */
7091 bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt;
7092 bpl->tus.f.bdeSize = len;
7093 bpl->tus.f.bdeFlags = 0;
7094 bpl->tus.w = le32_to_cpu(bpl->tus.w);
7095
7096 phba->fc_stat.elsXmitACC++;
7097 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7098 if (!elsiocb->ndlp) {
7099 lpfc_els_free_iocb(phba, elsiocb);
7100 goto free_rdp_context;
7101 }
7102
7103 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7104 if (rc == IOCB_ERROR) {
7105 lpfc_els_free_iocb(phba, elsiocb);
7106 lpfc_nlp_put(ndlp);
7107 }
7108
7109 goto free_rdp_context;
7110
7111 error:
7112 cmdsize = 2 * sizeof(uint32_t);
7113 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
7114 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
7115 if (!elsiocb)
7116 goto free_rdp_context;
7117
7118 if (phba->sli_rev == LPFC_SLI_REV4) {
7119 wqe = &elsiocb->wqe;
7120 /* ox-id of the frame */
7121 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7122 rdp_context->ox_id);
7123 bf_set(wqe_ctxt_tag,
7124 &wqe->xmit_els_rsp.wqe_com,
7125 rdp_context->rx_id);
7126 } else {
7127 icmd = &elsiocb->iocb;
7128 icmd->ulpContext = rdp_context->rx_id;
7129 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
7130 }
7131
7132 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7133
7134 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
7135 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7136 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7137
7138 phba->fc_stat.elsXmitLSRJT++;
7139 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7140 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7141 if (!elsiocb->ndlp) {
7142 lpfc_els_free_iocb(phba, elsiocb);
7143 goto free_rdp_context;
7144 }
7145
7146 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7147 if (rc == IOCB_ERROR) {
7148 lpfc_els_free_iocb(phba, elsiocb);
7149 lpfc_nlp_put(ndlp);
7150 }
7151
7152 free_rdp_context:
7153 /* This reference put is for the original unsolicited RDP. If the
7154 * prep failed, there is no reference to remove.
7155 */
7156 lpfc_nlp_put(ndlp);
7157 kfree(rdp_context);
7158 }
7159
7160 static int
lpfc_get_rdp_info(struct lpfc_hba * phba,struct lpfc_rdp_context * rdp_context)7161 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
7162 {
7163 LPFC_MBOXQ_t *mbox = NULL;
7164 int rc;
7165
7166 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7167 if (!mbox) {
7168 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7169 "7105 failed to allocate mailbox memory");
7170 return 1;
7171 }
7172
7173 if (lpfc_sli4_dump_page_a0(phba, mbox))
7174 goto rdp_fail;
7175 mbox->vport = rdp_context->ndlp->vport;
7176 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
7177 mbox->ctx_u.rdp = rdp_context;
7178 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7179 if (rc == MBX_NOT_FINISHED) {
7180 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
7181 return 1;
7182 }
7183
7184 return 0;
7185
7186 rdp_fail:
7187 mempool_free(mbox, phba->mbox_mem_pool);
7188 return 1;
7189 }
7190
lpfc_get_sfp_info_wait(struct lpfc_hba * phba,struct lpfc_rdp_context * rdp_context)7191 int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
7192 struct lpfc_rdp_context *rdp_context)
7193 {
7194 LPFC_MBOXQ_t *mbox = NULL;
7195 int rc;
7196 struct lpfc_dmabuf *mp;
7197 struct lpfc_dmabuf *mpsave;
7198 void *virt;
7199 MAILBOX_t *mb;
7200
7201 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7202 if (!mbox) {
7203 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
7204 "7205 failed to allocate mailbox memory");
7205 return 1;
7206 }
7207
7208 if (lpfc_sli4_dump_page_a0(phba, mbox))
7209 goto sfp_fail;
7210 mp = mbox->ctx_buf;
7211 mpsave = mp;
7212 virt = mp->virt;
7213 if (phba->sli_rev < LPFC_SLI_REV4) {
7214 mb = &mbox->u.mb;
7215 mb->un.varDmp.cv = 1;
7216 mb->un.varDmp.co = 1;
7217 mb->un.varWords[2] = 0;
7218 mb->un.varWords[3] = DMP_SFF_PAGE_A0_SIZE / 4;
7219 mb->un.varWords[4] = 0;
7220 mb->un.varWords[5] = 0;
7221 mb->un.varWords[6] = 0;
7222 mb->un.varWords[7] = 0;
7223 mb->un.varWords[8] = 0;
7224 mb->un.varWords[9] = 0;
7225 mb->un.varWords[10] = 0;
7226 mbox->in_ext_byte_len = DMP_SFF_PAGE_A0_SIZE;
7227 mbox->out_ext_byte_len = DMP_SFF_PAGE_A0_SIZE;
7228 mbox->mbox_offset_word = 5;
7229 mbox->ext_buf = virt;
7230 } else {
7231 bf_set(lpfc_mbx_memory_dump_type3_length,
7232 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
7233 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
7234 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
7235 }
7236 mbox->vport = phba->pport;
7237 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO);
7238 if (rc == MBX_NOT_FINISHED) {
7239 rc = 1;
7240 goto error;
7241 }
7242 if (rc == MBX_TIMEOUT)
7243 goto error;
7244 if (phba->sli_rev == LPFC_SLI_REV4)
7245 mp = mbox->ctx_buf;
7246 else
7247 mp = mpsave;
7248
7249 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
7250 rc = 1;
7251 goto error;
7252 }
7253
7254 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
7255 DMP_SFF_PAGE_A0_SIZE);
7256
7257 memset(mbox, 0, sizeof(*mbox));
7258 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
7259 INIT_LIST_HEAD(&mp->list);
7260
7261 /* save address for completion */
7262 mbox->ctx_buf = mp;
7263 mbox->vport = phba->pport;
7264
7265 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
7266 bf_set(lpfc_mbx_memory_dump_type3_type,
7267 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
7268 bf_set(lpfc_mbx_memory_dump_type3_link,
7269 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
7270 bf_set(lpfc_mbx_memory_dump_type3_page_no,
7271 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
7272 if (phba->sli_rev < LPFC_SLI_REV4) {
7273 mb = &mbox->u.mb;
7274 mb->un.varDmp.cv = 1;
7275 mb->un.varDmp.co = 1;
7276 mb->un.varWords[2] = 0;
7277 mb->un.varWords[3] = DMP_SFF_PAGE_A2_SIZE / 4;
7278 mb->un.varWords[4] = 0;
7279 mb->un.varWords[5] = 0;
7280 mb->un.varWords[6] = 0;
7281 mb->un.varWords[7] = 0;
7282 mb->un.varWords[8] = 0;
7283 mb->un.varWords[9] = 0;
7284 mb->un.varWords[10] = 0;
7285 mbox->in_ext_byte_len = DMP_SFF_PAGE_A2_SIZE;
7286 mbox->out_ext_byte_len = DMP_SFF_PAGE_A2_SIZE;
7287 mbox->mbox_offset_word = 5;
7288 mbox->ext_buf = virt;
7289 } else {
7290 bf_set(lpfc_mbx_memory_dump_type3_length,
7291 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
7292 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
7293 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
7294 }
7295
7296 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO);
7297
7298 if (rc == MBX_TIMEOUT)
7299 goto error;
7300 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
7301 rc = 1;
7302 goto error;
7303 }
7304 rc = 0;
7305
7306 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
7307 DMP_SFF_PAGE_A2_SIZE);
7308
7309 error:
7310 if (mbox->mbox_flag & LPFC_MBX_WAKE) {
7311 mbox->ctx_buf = mpsave;
7312 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
7313 }
7314
7315 return rc;
7316
7317 sfp_fail:
7318 mempool_free(mbox, phba->mbox_mem_pool);
7319 return 1;
7320 }
7321
7322 /*
7323 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
7324 * @vport: pointer to a host virtual N_Port data structure.
7325 * @cmdiocb: pointer to lpfc command iocb data structure.
7326 * @ndlp: pointer to a node-list data structure.
7327 *
7328 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
7329 * IOCB. First, the payload of the unsolicited RDP is checked.
7330 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
7331 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
7332 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
7333 * gather all data and send RDP response.
7334 *
7335 * Return code
7336 * 0 - Sent the acc response
7337 * 1 - Sent the reject response.
7338 */
7339 static int
lpfc_els_rcv_rdp(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7340 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7341 struct lpfc_nodelist *ndlp)
7342 {
7343 struct lpfc_hba *phba = vport->phba;
7344 struct lpfc_dmabuf *pcmd;
7345 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
7346 struct fc_rdp_req_frame *rdp_req;
7347 struct lpfc_rdp_context *rdp_context;
7348 union lpfc_wqe128 *cmd = NULL;
7349 struct ls_rjt stat;
7350
7351 if (phba->sli_rev < LPFC_SLI_REV4 ||
7352 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7353 LPFC_SLI_INTF_IF_TYPE_2) {
7354 rjt_err = LSRJT_UNABLE_TPC;
7355 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7356 goto error;
7357 }
7358
7359 if (phba->sli_rev < LPFC_SLI_REV4 ||
7360 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
7361 rjt_err = LSRJT_UNABLE_TPC;
7362 rjt_expl = LSEXP_REQ_UNSUPPORTED;
7363 goto error;
7364 }
7365
7366 pcmd = cmdiocb->cmd_dmabuf;
7367 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
7368
7369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7370 "2422 ELS RDP Request "
7371 "dec len %d tag x%x port_id %d len %d\n",
7372 be32_to_cpu(rdp_req->rdp_des_length),
7373 be32_to_cpu(rdp_req->nport_id_desc.tag),
7374 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
7375 be32_to_cpu(rdp_req->nport_id_desc.length));
7376
7377 if (sizeof(struct fc_rdp_nport_desc) !=
7378 be32_to_cpu(rdp_req->rdp_des_length))
7379 goto rjt_logerr;
7380 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
7381 goto rjt_logerr;
7382 if (RDP_NPORT_ID_SIZE !=
7383 be32_to_cpu(rdp_req->nport_id_desc.length))
7384 goto rjt_logerr;
7385 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
7386 if (!rdp_context) {
7387 rjt_err = LSRJT_UNABLE_TPC;
7388 goto error;
7389 }
7390
7391 cmd = &cmdiocb->wqe;
7392 rdp_context->ndlp = lpfc_nlp_get(ndlp);
7393 if (!rdp_context->ndlp) {
7394 kfree(rdp_context);
7395 rjt_err = LSRJT_UNABLE_TPC;
7396 goto error;
7397 }
7398 rdp_context->ox_id = bf_get(wqe_rcvoxid,
7399 &cmd->xmit_els_rsp.wqe_com);
7400 rdp_context->rx_id = bf_get(wqe_ctxt_tag,
7401 &cmd->xmit_els_rsp.wqe_com);
7402 rdp_context->cmpl = lpfc_els_rdp_cmpl;
7403 if (lpfc_get_rdp_info(phba, rdp_context)) {
7404 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
7405 "2423 Unable to send mailbox");
7406 kfree(rdp_context);
7407 rjt_err = LSRJT_UNABLE_TPC;
7408 lpfc_nlp_put(ndlp);
7409 goto error;
7410 }
7411
7412 return 0;
7413
7414 rjt_logerr:
7415 rjt_err = LSRJT_LOGICAL_ERR;
7416
7417 error:
7418 memset(&stat, 0, sizeof(stat));
7419 stat.un.b.lsRjtRsnCode = rjt_err;
7420 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
7421 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7422 return 1;
7423 }
7424
7425
7426 static void
lpfc_els_lcb_rsp(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)7427 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7428 {
7429 MAILBOX_t *mb;
7430 IOCB_t *icmd;
7431 union lpfc_wqe128 *wqe;
7432 uint8_t *pcmd;
7433 struct lpfc_iocbq *elsiocb;
7434 struct lpfc_nodelist *ndlp;
7435 struct ls_rjt *stat;
7436 union lpfc_sli4_cfg_shdr *shdr;
7437 struct lpfc_lcb_context *lcb_context;
7438 struct fc_lcb_res_frame *lcb_res;
7439 uint32_t cmdsize, shdr_status, shdr_add_status;
7440 int rc;
7441
7442 mb = &pmb->u.mb;
7443 lcb_context = pmb->ctx_u.lcb;
7444 ndlp = lcb_context->ndlp;
7445 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u));
7446 pmb->ctx_buf = NULL;
7447
7448 shdr = (union lpfc_sli4_cfg_shdr *)
7449 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
7450 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7451 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7452
7453 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
7454 "0194 SET_BEACON_CONFIG mailbox "
7455 "completed with status x%x add_status x%x,"
7456 " mbx status x%x\n",
7457 shdr_status, shdr_add_status, mb->mbxStatus);
7458
7459 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
7460 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
7461 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
7462 mempool_free(pmb, phba->mbox_mem_pool);
7463 goto error;
7464 }
7465
7466 mempool_free(pmb, phba->mbox_mem_pool);
7467 cmdsize = sizeof(struct fc_lcb_res_frame);
7468 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7469 lpfc_max_els_tries, ndlp,
7470 ndlp->nlp_DID, ELS_CMD_ACC);
7471
7472 /* Decrement the ndlp reference count from previous mbox command */
7473 lpfc_nlp_put(ndlp);
7474
7475 if (!elsiocb)
7476 goto free_lcb_context;
7477
7478 lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt;
7479
7480 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
7481
7482 if (phba->sli_rev == LPFC_SLI_REV4) {
7483 wqe = &elsiocb->wqe;
7484 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7485 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7486 lcb_context->ox_id);
7487 } else {
7488 icmd = &elsiocb->iocb;
7489 icmd->ulpContext = lcb_context->rx_id;
7490 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7491 }
7492
7493 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7494 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
7495 lcb_res->lcb_sub_command = lcb_context->sub_command;
7496 lcb_res->lcb_type = lcb_context->type;
7497 lcb_res->capability = lcb_context->capability;
7498 lcb_res->lcb_frequency = lcb_context->frequency;
7499 lcb_res->lcb_duration = lcb_context->duration;
7500 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7501 phba->fc_stat.elsXmitACC++;
7502
7503 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7504 if (!elsiocb->ndlp) {
7505 lpfc_els_free_iocb(phba, elsiocb);
7506 goto out;
7507 }
7508
7509 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7510 if (rc == IOCB_ERROR) {
7511 lpfc_els_free_iocb(phba, elsiocb);
7512 lpfc_nlp_put(ndlp);
7513 }
7514 out:
7515 kfree(lcb_context);
7516 return;
7517
7518 error:
7519 cmdsize = sizeof(struct fc_lcb_res_frame);
7520 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7521 lpfc_max_els_tries, ndlp,
7522 ndlp->nlp_DID, ELS_CMD_LS_RJT);
7523 lpfc_nlp_put(ndlp);
7524 if (!elsiocb)
7525 goto free_lcb_context;
7526
7527 if (phba->sli_rev == LPFC_SLI_REV4) {
7528 wqe = &elsiocb->wqe;
7529 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
7530 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
7531 lcb_context->ox_id);
7532 } else {
7533 icmd = &elsiocb->iocb;
7534 icmd->ulpContext = lcb_context->rx_id;
7535 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
7536 }
7537
7538 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
7539
7540 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
7541 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
7542 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7543
7544 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
7545 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
7546
7547 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
7548 phba->fc_stat.elsXmitLSRJT++;
7549 elsiocb->ndlp = lpfc_nlp_get(ndlp);
7550 if (!elsiocb->ndlp) {
7551 lpfc_els_free_iocb(phba, elsiocb);
7552 goto free_lcb_context;
7553 }
7554
7555 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7556 if (rc == IOCB_ERROR) {
7557 lpfc_els_free_iocb(phba, elsiocb);
7558 lpfc_nlp_put(ndlp);
7559 }
7560 free_lcb_context:
7561 kfree(lcb_context);
7562 }
7563
7564 static int
lpfc_sli4_set_beacon(struct lpfc_vport * vport,struct lpfc_lcb_context * lcb_context,uint32_t beacon_state)7565 lpfc_sli4_set_beacon(struct lpfc_vport *vport,
7566 struct lpfc_lcb_context *lcb_context,
7567 uint32_t beacon_state)
7568 {
7569 struct lpfc_hba *phba = vport->phba;
7570 union lpfc_sli4_cfg_shdr *cfg_shdr;
7571 LPFC_MBOXQ_t *mbox = NULL;
7572 uint32_t len;
7573 int rc;
7574
7575 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7576 if (!mbox)
7577 return 1;
7578
7579 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
7580 len = sizeof(struct lpfc_mbx_set_beacon_config) -
7581 sizeof(struct lpfc_sli4_cfg_mhdr);
7582 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7583 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
7584 LPFC_SLI4_MBX_EMBED);
7585 mbox->ctx_u.lcb = lcb_context;
7586 mbox->vport = phba->pport;
7587 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
7588 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
7589 phba->sli4_hba.physical_port);
7590 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
7591 beacon_state);
7592 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
7593
7594 /*
7595 * Check bv1s bit before issuing the mailbox
7596 * if bv1s == 1, LCB V1 supported
7597 * else, LCB V0 supported
7598 */
7599
7600 if (phba->sli4_hba.pc_sli4_params.bv1s) {
7601 /* COMMON_SET_BEACON_CONFIG_V1 */
7602 cfg_shdr->request.word9 = BEACON_VERSION_V1;
7603 lcb_context->capability |= LCB_CAPABILITY_DURATION;
7604 bf_set(lpfc_mbx_set_beacon_port_type,
7605 &mbox->u.mqe.un.beacon_config, 0);
7606 bf_set(lpfc_mbx_set_beacon_duration_v1,
7607 &mbox->u.mqe.un.beacon_config,
7608 be16_to_cpu(lcb_context->duration));
7609 } else {
7610 /* COMMON_SET_BEACON_CONFIG_V0 */
7611 if (be16_to_cpu(lcb_context->duration) != 0) {
7612 mempool_free(mbox, phba->mbox_mem_pool);
7613 return 1;
7614 }
7615 cfg_shdr->request.word9 = BEACON_VERSION_V0;
7616 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
7617 bf_set(lpfc_mbx_set_beacon_state,
7618 &mbox->u.mqe.un.beacon_config, beacon_state);
7619 bf_set(lpfc_mbx_set_beacon_port_type,
7620 &mbox->u.mqe.un.beacon_config, 1);
7621 bf_set(lpfc_mbx_set_beacon_duration,
7622 &mbox->u.mqe.un.beacon_config,
7623 be16_to_cpu(lcb_context->duration));
7624 }
7625
7626 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7627 if (rc == MBX_NOT_FINISHED) {
7628 mempool_free(mbox, phba->mbox_mem_pool);
7629 return 1;
7630 }
7631
7632 return 0;
7633 }
7634
7635
7636 /**
7637 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7638 * @vport: pointer to a host virtual N_Port data structure.
7639 * @cmdiocb: pointer to lpfc command iocb data structure.
7640 * @ndlp: pointer to a node-list data structure.
7641 *
7642 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7643 * First, the payload of the unsolicited LCB is checked.
7644 * Then based on Subcommand beacon will either turn on or off.
7645 *
7646 * Return code
7647 * 0 - Sent the acc response
7648 * 1 - Sent the reject response.
7649 **/
7650 static int
lpfc_els_rcv_lcb(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7651 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7652 struct lpfc_nodelist *ndlp)
7653 {
7654 struct lpfc_hba *phba = vport->phba;
7655 struct lpfc_dmabuf *pcmd;
7656 uint8_t *lp;
7657 struct fc_lcb_request_frame *beacon;
7658 struct lpfc_lcb_context *lcb_context;
7659 u8 state, rjt_err = 0;
7660 struct ls_rjt stat;
7661
7662 pcmd = cmdiocb->cmd_dmabuf;
7663 lp = (uint8_t *)pcmd->virt;
7664 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
7665
7666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7667 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7668 "type x%x frequency %x duration x%x\n",
7669 lp[0], lp[1], lp[2],
7670 beacon->lcb_command,
7671 beacon->lcb_sub_command,
7672 beacon->lcb_type,
7673 beacon->lcb_frequency,
7674 be16_to_cpu(beacon->lcb_duration));
7675
7676 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
7677 beacon->lcb_sub_command != LPFC_LCB_OFF) {
7678 rjt_err = LSRJT_CMD_UNSUPPORTED;
7679 goto rjt;
7680 }
7681
7682 if (phba->sli_rev < LPFC_SLI_REV4 ||
7683 test_bit(HBA_FCOE_MODE, &phba->hba_flag) ||
7684 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
7685 LPFC_SLI_INTF_IF_TYPE_2)) {
7686 rjt_err = LSRJT_CMD_UNSUPPORTED;
7687 goto rjt;
7688 }
7689
7690 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
7691 if (!lcb_context) {
7692 rjt_err = LSRJT_UNABLE_TPC;
7693 goto rjt;
7694 }
7695
7696 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
7697 lcb_context->sub_command = beacon->lcb_sub_command;
7698 lcb_context->capability = 0;
7699 lcb_context->type = beacon->lcb_type;
7700 lcb_context->frequency = beacon->lcb_frequency;
7701 lcb_context->duration = beacon->lcb_duration;
7702 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb);
7703 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb);
7704 lcb_context->ndlp = lpfc_nlp_get(ndlp);
7705 if (!lcb_context->ndlp) {
7706 rjt_err = LSRJT_UNABLE_TPC;
7707 goto rjt_free;
7708 }
7709
7710 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
7711 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
7712 "0193 failed to send mail box");
7713 lpfc_nlp_put(ndlp);
7714 rjt_err = LSRJT_UNABLE_TPC;
7715 goto rjt_free;
7716 }
7717 return 0;
7718
7719 rjt_free:
7720 kfree(lcb_context);
7721 rjt:
7722 memset(&stat, 0, sizeof(stat));
7723 stat.un.b.lsRjtRsnCode = rjt_err;
7724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7725 return 1;
7726 }
7727
7728
7729 /**
7730 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
7731 * @vport: pointer to a host virtual N_Port data structure.
7732 *
7733 * This routine cleans up any Registration State Change Notification
7734 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7735 * @vport together with the host_lock is used to prevent multiple thread
7736 * trying to access the RSCN array on a same @vport at the same time.
7737 **/
7738 void
lpfc_els_flush_rscn(struct lpfc_vport * vport)7739 lpfc_els_flush_rscn(struct lpfc_vport *vport)
7740 {
7741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7742 struct lpfc_hba *phba = vport->phba;
7743 int i;
7744
7745 spin_lock_irq(shost->host_lock);
7746 if (vport->fc_rscn_flush) {
7747 /* Another thread is walking fc_rscn_id_list on this vport */
7748 spin_unlock_irq(shost->host_lock);
7749 return;
7750 }
7751 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7752 vport->fc_rscn_flush = 1;
7753 spin_unlock_irq(shost->host_lock);
7754
7755 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7756 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
7757 vport->fc_rscn_id_list[i] = NULL;
7758 }
7759 clear_bit(FC_RSCN_MODE, &vport->fc_flag);
7760 clear_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
7761 spin_lock_irq(shost->host_lock);
7762 vport->fc_rscn_id_cnt = 0;
7763 spin_unlock_irq(shost->host_lock);
7764 lpfc_can_disctmo(vport);
7765 /* Indicate we are done walking this fc_rscn_id_list */
7766 vport->fc_rscn_flush = 0;
7767 }
7768
7769 /**
7770 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
7771 * @vport: pointer to a host virtual N_Port data structure.
7772 * @did: remote destination port identifier.
7773 *
7774 * This routine checks whether there is any pending Registration State
7775 * Configuration Notification (RSCN) to a @did on @vport.
7776 *
7777 * Return code
7778 * None zero - The @did matched with a pending rscn
7779 * 0 - not able to match @did with a pending rscn
7780 **/
7781 int
lpfc_rscn_payload_check(struct lpfc_vport * vport,uint32_t did)7782 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
7783 {
7784 D_ID ns_did;
7785 D_ID rscn_did;
7786 uint32_t *lp;
7787 uint32_t payload_len, i;
7788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7789
7790 ns_did.un.word = did;
7791
7792 /* Never match fabric nodes for RSCNs */
7793 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7794 return 0;
7795
7796 /* If we are doing a FULL RSCN rediscovery, match everything */
7797 if (test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag))
7798 return did;
7799
7800 spin_lock_irq(shost->host_lock);
7801 if (vport->fc_rscn_flush) {
7802 /* Another thread is walking fc_rscn_id_list on this vport */
7803 spin_unlock_irq(shost->host_lock);
7804 return 0;
7805 }
7806 /* Indicate we are walking fc_rscn_id_list on this vport */
7807 vport->fc_rscn_flush = 1;
7808 spin_unlock_irq(shost->host_lock);
7809 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
7810 lp = vport->fc_rscn_id_list[i]->virt;
7811 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7812 payload_len -= sizeof(uint32_t); /* take off word 0 */
7813 while (payload_len) {
7814 rscn_did.un.word = be32_to_cpu(*lp++);
7815 payload_len -= sizeof(uint32_t);
7816 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
7817 case RSCN_ADDRESS_FORMAT_PORT:
7818 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7819 && (ns_did.un.b.area == rscn_did.un.b.area)
7820 && (ns_did.un.b.id == rscn_did.un.b.id))
7821 goto return_did_out;
7822 break;
7823 case RSCN_ADDRESS_FORMAT_AREA:
7824 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
7825 && (ns_did.un.b.area == rscn_did.un.b.area))
7826 goto return_did_out;
7827 break;
7828 case RSCN_ADDRESS_FORMAT_DOMAIN:
7829 if (ns_did.un.b.domain == rscn_did.un.b.domain)
7830 goto return_did_out;
7831 break;
7832 case RSCN_ADDRESS_FORMAT_FABRIC:
7833 goto return_did_out;
7834 }
7835 }
7836 }
7837 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7838 vport->fc_rscn_flush = 0;
7839 return 0;
7840 return_did_out:
7841 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7842 vport->fc_rscn_flush = 0;
7843 return did;
7844 }
7845
7846 /**
7847 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
7848 * @vport: pointer to a host virtual N_Port data structure.
7849 *
7850 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7851 * state machine for a @vport's nodes that are with pending RSCN (Registration
7852 * State Change Notification).
7853 *
7854 * Return code
7855 * 0 - Successful (currently alway return 0)
7856 **/
7857 static int
lpfc_rscn_recovery_check(struct lpfc_vport * vport)7858 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
7859 {
7860 struct lpfc_nodelist *ndlp = NULL, *n;
7861
7862 /* Move all affected nodes by pending RSCNs to NPR state. */
7863 list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) {
7864 if (test_bit(FC_UNLOADING, &vport->load_flag)) {
7865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7866 "1000 %s Unloading set\n",
7867 __func__);
7868 return 0;
7869 }
7870
7871 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
7872 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
7873 continue;
7874
7875 /* NVME Target mode does not do RSCN Recovery. */
7876 if (vport->phba->nvmet_support)
7877 continue;
7878
7879 /* If we are in the process of doing discovery on this
7880 * NPort, let it continue on its own.
7881 */
7882 switch (ndlp->nlp_state) {
7883 case NLP_STE_PLOGI_ISSUE:
7884 case NLP_STE_ADISC_ISSUE:
7885 case NLP_STE_REG_LOGIN_ISSUE:
7886 case NLP_STE_PRLI_ISSUE:
7887 case NLP_STE_LOGO_ISSUE:
7888 continue;
7889 }
7890
7891 lpfc_disc_state_machine(vport, ndlp, NULL,
7892 NLP_EVT_DEVICE_RECOVERY);
7893 lpfc_cancel_retry_delay_tmo(vport, ndlp);
7894 }
7895 return 0;
7896 }
7897
7898 /**
7899 * lpfc_send_rscn_event - Send an RSCN event to management application
7900 * @vport: pointer to a host virtual N_Port data structure.
7901 * @cmdiocb: pointer to lpfc command iocb data structure.
7902 *
7903 * lpfc_send_rscn_event sends an RSCN netlink event to management
7904 * applications.
7905 */
7906 static void
lpfc_send_rscn_event(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb)7907 lpfc_send_rscn_event(struct lpfc_vport *vport,
7908 struct lpfc_iocbq *cmdiocb)
7909 {
7910 struct lpfc_dmabuf *pcmd;
7911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7912 uint32_t *payload_ptr;
7913 uint32_t payload_len;
7914 struct lpfc_rscn_event_header *rscn_event_data;
7915
7916 pcmd = cmdiocb->cmd_dmabuf;
7917 payload_ptr = (uint32_t *) pcmd->virt;
7918 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
7919
7920 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
7921 payload_len, GFP_KERNEL);
7922 if (!rscn_event_data) {
7923 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7924 "0147 Failed to allocate memory for RSCN event\n");
7925 return;
7926 }
7927 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
7928 rscn_event_data->payload_length = payload_len;
7929 memcpy(rscn_event_data->rscn_payload, payload_ptr,
7930 payload_len);
7931
7932 fc_host_post_vendor_event(shost,
7933 fc_get_event_number(),
7934 sizeof(struct lpfc_rscn_event_header) + payload_len,
7935 (char *)rscn_event_data,
7936 LPFC_NL_VENDOR_ID);
7937
7938 kfree(rscn_event_data);
7939 }
7940
7941 /**
7942 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
7943 * @vport: pointer to a host virtual N_Port data structure.
7944 * @cmdiocb: pointer to lpfc command iocb data structure.
7945 * @ndlp: pointer to a node-list data structure.
7946 *
7947 * This routine processes an unsolicited RSCN (Registration State Change
7948 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
7949 * to invoke fc_host_post_event() routine to the FC transport layer. If the
7950 * discover state machine is about to begin discovery, it just accepts the
7951 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
7952 * contains N_Port IDs for other vports on this HBA, it just accepts the
7953 * RSCN and ignore processing it. If the state machine is in the recovery
7954 * state, the fc_rscn_id_list of this @vport is walked and the
7955 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
7956 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
7957 * routine is invoked to handle the RSCN event.
7958 *
7959 * Return code
7960 * 0 - Just sent the acc response
7961 * 1 - Sent the acc response and waited for name server completion
7962 **/
7963 static int
lpfc_els_rcv_rscn(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7964 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7965 struct lpfc_nodelist *ndlp)
7966 {
7967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7968 struct lpfc_hba *phba = vport->phba;
7969 struct lpfc_dmabuf *pcmd;
7970 uint32_t *lp, *datap;
7971 uint32_t payload_len, length, nportid, *cmd;
7972 int rscn_cnt;
7973 int rscn_id = 0, hba_id = 0;
7974 int i, tmo;
7975
7976 pcmd = cmdiocb->cmd_dmabuf;
7977 lp = (uint32_t *) pcmd->virt;
7978
7979 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
7980 payload_len -= sizeof(uint32_t); /* take off word 0 */
7981 /* RSCN received */
7982 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
7983 "0214 RSCN received Data: x%lx x%x x%x x%x\n",
7984 vport->fc_flag, payload_len, *lp,
7985 vport->fc_rscn_id_cnt);
7986
7987 /* Send an RSCN event to the management application */
7988 lpfc_send_rscn_event(vport, cmdiocb);
7989
7990 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
7991 fc_host_post_event(shost, fc_get_event_number(),
7992 FCH_EVT_RSCN, lp[i]);
7993
7994 /* Check if RSCN is coming from a direct-connected remote NPort */
7995 if (test_bit(FC_PT2PT, &vport->fc_flag)) {
7996 /* If so, just ACC it, no other action needed for now */
7997 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7998 "2024 pt2pt RSCN %08x Data: x%lx x%x\n",
7999 *lp, vport->fc_flag, payload_len);
8000 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8001
8002 /* Check to see if we need to NVME rescan this target
8003 * remoteport.
8004 */
8005 if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
8006 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
8007 lpfc_nvme_rescan_port(vport, ndlp);
8008 return 0;
8009 }
8010
8011 /* If we are about to begin discovery, just ACC the RSCN.
8012 * Discovery processing will satisfy it.
8013 */
8014 if (vport->port_state <= LPFC_NS_QRY) {
8015 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8016 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%lx",
8017 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8018
8019 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8020 return 0;
8021 }
8022
8023 /* If this RSCN just contains NPortIDs for other vports on this HBA,
8024 * just ACC and ignore it.
8025 */
8026 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8027 !(vport->cfg_peer_port_login)) {
8028 i = payload_len;
8029 datap = lp;
8030 while (i > 0) {
8031 nportid = *datap++;
8032 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
8033 i -= sizeof(uint32_t);
8034 rscn_id++;
8035 if (lpfc_find_vport_by_did(phba, nportid))
8036 hba_id++;
8037 }
8038 if (rscn_id == hba_id) {
8039 /* ALL NPortIDs in RSCN are on HBA */
8040 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8041 "0219 Ignore RSCN "
8042 "Data: x%lx x%x x%x x%x\n",
8043 vport->fc_flag, payload_len,
8044 *lp, vport->fc_rscn_id_cnt);
8045 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8046 "RCV RSCN vport: did:x%x/ste:x%x flg:x%lx",
8047 ndlp->nlp_DID, vport->port_state,
8048 ndlp->nlp_flag);
8049
8050 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
8051 ndlp, NULL);
8052 /* Restart disctmo if its already running */
8053 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) {
8054 tmo = ((phba->fc_ratov * 3) + 3);
8055 mod_timer(&vport->fc_disctmo,
8056 jiffies + secs_to_jiffies(tmo));
8057 }
8058 return 0;
8059 }
8060 }
8061
8062 spin_lock_irq(shost->host_lock);
8063 if (vport->fc_rscn_flush) {
8064 /* Another thread is walking fc_rscn_id_list on this vport */
8065 spin_unlock_irq(shost->host_lock);
8066 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
8067 /* Send back ACC */
8068 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8069 return 0;
8070 }
8071 /* Indicate we are walking fc_rscn_id_list on this vport */
8072 vport->fc_rscn_flush = 1;
8073 spin_unlock_irq(shost->host_lock);
8074 /* Get the array count after successfully have the token */
8075 rscn_cnt = vport->fc_rscn_id_cnt;
8076 /* If we are already processing an RSCN, save the received
8077 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later.
8078 */
8079 if (test_bit(FC_RSCN_MODE, &vport->fc_flag) ||
8080 test_bit(FC_NDISC_ACTIVE, &vport->fc_flag)) {
8081 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8082 "RCV RSCN defer: did:x%x/ste:x%x flg:x%lx",
8083 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8084
8085 set_bit(FC_RSCN_DEFERRED, &vport->fc_flag);
8086
8087 /* Restart disctmo if its already running */
8088 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) {
8089 tmo = ((phba->fc_ratov * 3) + 3);
8090 mod_timer(&vport->fc_disctmo,
8091 jiffies + secs_to_jiffies(tmo));
8092 }
8093 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
8094 !test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) {
8095 set_bit(FC_RSCN_MODE, &vport->fc_flag);
8096 if (rscn_cnt) {
8097 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
8098 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
8099 }
8100 if ((rscn_cnt) &&
8101 (payload_len + length <= LPFC_BPL_SIZE)) {
8102 *cmd &= ELS_CMD_MASK;
8103 *cmd |= cpu_to_be32(payload_len + length);
8104 memcpy(((uint8_t *)cmd) + length, lp,
8105 payload_len);
8106 } else {
8107 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
8108 vport->fc_rscn_id_cnt++;
8109 /* If we zero, cmdiocb->cmd_dmabuf, the calling
8110 * routine will not try to free it.
8111 */
8112 cmdiocb->cmd_dmabuf = NULL;
8113 }
8114 /* Deferred RSCN */
8115 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8116 "0235 Deferred RSCN "
8117 "Data: x%x x%lx x%x\n",
8118 vport->fc_rscn_id_cnt, vport->fc_flag,
8119 vport->port_state);
8120 } else {
8121 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag);
8122 /* ReDiscovery RSCN */
8123 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8124 "0234 ReDiscovery RSCN "
8125 "Data: x%x x%lx x%x\n",
8126 vport->fc_rscn_id_cnt, vport->fc_flag,
8127 vport->port_state);
8128 }
8129 /* Indicate we are done walking fc_rscn_id_list on this vport */
8130 vport->fc_rscn_flush = 0;
8131 /* Send back ACC */
8132 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8133 /* send RECOVERY event for ALL nodes that match RSCN payload */
8134 lpfc_rscn_recovery_check(vport);
8135 return 0;
8136 }
8137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8138 "RCV RSCN: did:x%x/ste:x%x flg:x%lx",
8139 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
8140
8141 set_bit(FC_RSCN_MODE, &vport->fc_flag);
8142 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
8143 /* Indicate we are done walking fc_rscn_id_list on this vport */
8144 vport->fc_rscn_flush = 0;
8145 /*
8146 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will
8147 * not try to free it.
8148 */
8149 cmdiocb->cmd_dmabuf = NULL;
8150 lpfc_set_disctmo(vport);
8151 /* Send back ACC */
8152 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8153 /* send RECOVERY event for ALL nodes that match RSCN payload */
8154 lpfc_rscn_recovery_check(vport);
8155 return lpfc_els_handle_rscn(vport);
8156 }
8157
8158 /**
8159 * lpfc_els_handle_rscn - Handle rscn for a vport
8160 * @vport: pointer to a host virtual N_Port data structure.
8161 *
8162 * This routine handles the Registration State Configuration Notification
8163 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
8164 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
8165 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
8166 * NameServer shall be issued. If CT command to the NameServer fails to be
8167 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
8168 * RSCN activities with the @vport.
8169 *
8170 * Return code
8171 * 0 - Cleaned up rscn on the @vport
8172 * 1 - Wait for plogi to name server before proceed
8173 **/
8174 int
lpfc_els_handle_rscn(struct lpfc_vport * vport)8175 lpfc_els_handle_rscn(struct lpfc_vport *vport)
8176 {
8177 struct lpfc_nodelist *ndlp;
8178 struct lpfc_hba *phba = vport->phba;
8179
8180 /* Ignore RSCN if the port is being torn down. */
8181 if (test_bit(FC_UNLOADING, &vport->load_flag)) {
8182 lpfc_els_flush_rscn(vport);
8183 return 0;
8184 }
8185
8186 /* Start timer for RSCN processing */
8187 lpfc_set_disctmo(vport);
8188
8189 /* RSCN processed */
8190 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
8191 "0215 RSCN processed Data: x%lx x%x x%x x%x x%x x%x\n",
8192 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
8193 vport->port_state, vport->num_disc_nodes,
8194 vport->gidft_inp);
8195
8196 /* To process RSCN, first compare RSCN data with NameServer */
8197 vport->fc_ns_retry = 0;
8198 vport->num_disc_nodes = 0;
8199
8200 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8201 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
8202 /* Good ndlp, issue CT Request to NameServer. Need to
8203 * know how many gidfts were issued. If none, then just
8204 * flush the RSCN. Otherwise, the outstanding requests
8205 * need to complete.
8206 */
8207 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
8208 if (lpfc_issue_gidft(vport) > 0)
8209 return 1;
8210 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
8211 if (lpfc_issue_gidpt(vport) > 0)
8212 return 1;
8213 } else {
8214 return 1;
8215 }
8216 } else {
8217 /* Nameserver login in question. Revalidate. */
8218 if (ndlp) {
8219 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
8220 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8221 } else {
8222 ndlp = lpfc_nlp_init(vport, NameServer_DID);
8223 if (!ndlp) {
8224 lpfc_els_flush_rscn(vport);
8225 return 0;
8226 }
8227 ndlp->nlp_prev_state = ndlp->nlp_state;
8228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8229 }
8230 ndlp->nlp_type |= NLP_FABRIC;
8231 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
8232 /* Wait for NameServer login cmpl before we can
8233 * continue
8234 */
8235 return 1;
8236 }
8237
8238 lpfc_els_flush_rscn(vport);
8239 return 0;
8240 }
8241
8242 /**
8243 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
8244 * @vport: pointer to a host virtual N_Port data structure.
8245 * @cmdiocb: pointer to lpfc command iocb data structure.
8246 * @ndlp: pointer to a node-list data structure.
8247 *
8248 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
8249 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
8250 * point topology. As an unsolicited FLOGI should not be received in a loop
8251 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
8252 * lpfc_check_sparm() routine is invoked to check the parameters in the
8253 * unsolicited FLOGI. If parameters validation failed, the routine
8254 * lpfc_els_rsp_reject() shall be called with reject reason code set to
8255 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
8256 * FLOGI shall be compared with the Port WWN of the @vport to determine who
8257 * will initiate PLOGI. The higher lexicographical value party shall has
8258 * higher priority (as the winning port) and will initiate PLOGI and
8259 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
8260 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
8261 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
8262 *
8263 * Return code
8264 * 0 - Successfully processed the unsolicited flogi
8265 * 1 - Failed to process the unsolicited flogi
8266 **/
8267 static int
lpfc_els_rcv_flogi(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8268 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8269 struct lpfc_nodelist *ndlp)
8270 {
8271 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8272 struct lpfc_hba *phba = vport->phba;
8273 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
8274 uint32_t *lp = (uint32_t *) pcmd->virt;
8275 union lpfc_wqe128 *wqe = &cmdiocb->wqe;
8276 struct serv_parm *sp;
8277 LPFC_MBOXQ_t *mbox;
8278 uint32_t cmd, did;
8279 int rc;
8280 unsigned long fc_flag = 0;
8281 uint32_t port_state = 0;
8282
8283 /* Clear external loopback plug detected flag */
8284 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
8285
8286 cmd = *lp++;
8287 sp = (struct serv_parm *) lp;
8288
8289 /* FLOGI received */
8290
8291 lpfc_set_disctmo(vport);
8292
8293 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8294 /* We should never receive a FLOGI in loop mode, ignore it */
8295 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
8296
8297 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
8298 Loop Mode */
8299 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8300 "0113 An FLOGI ELS command x%x was "
8301 "received from DID x%x in Loop Mode\n",
8302 cmd, did);
8303 return 1;
8304 }
8305
8306 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
8307
8308 /*
8309 * If our portname is greater than the remote portname,
8310 * then we initiate Nport login.
8311 */
8312
8313 rc = memcmp(&vport->fc_portname, &sp->portName,
8314 sizeof(struct lpfc_name));
8315
8316 if (!rc) {
8317 if (phba->sli_rev < LPFC_SLI_REV4) {
8318 mbox = mempool_alloc(phba->mbox_mem_pool,
8319 GFP_KERNEL);
8320 if (!mbox)
8321 return 1;
8322 lpfc_linkdown(phba);
8323 lpfc_init_link(phba, mbox,
8324 phba->cfg_topology,
8325 phba->cfg_link_speed);
8326 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8327 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8328 mbox->vport = vport;
8329 rc = lpfc_sli_issue_mbox(phba, mbox,
8330 MBX_NOWAIT);
8331 lpfc_set_loopback_flag(phba);
8332 if (rc == MBX_NOT_FINISHED)
8333 mempool_free(mbox, phba->mbox_mem_pool);
8334 return 1;
8335 }
8336
8337 /* External loopback plug insertion detected */
8338 phba->link_flag |= LS_EXTERNAL_LOOPBACK;
8339
8340 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC,
8341 "1119 External Loopback plug detected\n");
8342
8343 /* abort the flogi coming back to ourselves
8344 * due to external loopback on the port.
8345 */
8346 lpfc_els_abort_flogi(phba);
8347 return 0;
8348
8349 } else if (rc > 0) { /* greater than */
8350 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag);
8351
8352 /* If we have the high WWPN we can assign our own
8353 * myDID; otherwise, we have to WAIT for a PLOGI
8354 * from the remote NPort to find out what it
8355 * will be.
8356 */
8357 vport->fc_myDID = PT2PT_LocalID;
8358 } else {
8359 vport->fc_myDID = PT2PT_RemoteID;
8360 }
8361
8362 /*
8363 * The vport state should go to LPFC_FLOGI only
8364 * AFTER we issue a FLOGI, not receive one.
8365 */
8366 spin_lock_irq(shost->host_lock);
8367 fc_flag = vport->fc_flag;
8368 port_state = vport->port_state;
8369 /* Acking an unsol FLOGI. Count 1 for link bounce
8370 * work-around.
8371 */
8372 vport->rcv_flogi_cnt++;
8373 spin_unlock_irq(shost->host_lock);
8374 set_bit(FC_PT2PT, &vport->fc_flag);
8375 clear_bit(FC_FABRIC, &vport->fc_flag);
8376 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
8377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8378 "3311 Rcv Flogi PS x%x new PS x%x "
8379 "fc_flag x%lx new fc_flag x%lx, hba_flag x%lx\n",
8380 port_state, vport->port_state,
8381 fc_flag, vport->fc_flag, phba->hba_flag);
8382
8383 /*
8384 * We temporarily set fc_myDID to make it look like we are
8385 * a Fabric. This is done just so we end up with the right
8386 * did / sid on the FLOGI ACC rsp.
8387 */
8388 did = vport->fc_myDID;
8389 vport->fc_myDID = Fabric_DID;
8390
8391 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
8392
8393 /* Defer ACC response until AFTER we issue a FLOGI */
8394 if (!test_bit(HBA_FLOGI_ISSUED, &phba->hba_flag)) {
8395 phba->defer_flogi_acc.rx_id = bf_get(wqe_ctxt_tag,
8396 &wqe->xmit_els_rsp.wqe_com);
8397 phba->defer_flogi_acc.ox_id = bf_get(wqe_rcvoxid,
8398 &wqe->xmit_els_rsp.wqe_com);
8399
8400 vport->fc_myDID = did;
8401
8402 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8403 "3344 Deferring FLOGI ACC: rx_id: x%x,"
8404 " ox_id: x%x, hba_flag x%lx\n",
8405 phba->defer_flogi_acc.rx_id,
8406 phba->defer_flogi_acc.ox_id, phba->hba_flag);
8407
8408 phba->defer_flogi_acc.flag = true;
8409
8410 /* This nlp_get is paired with nlp_puts that reset the
8411 * defer_flogi_acc.flag back to false. We need to retain
8412 * a kref on the ndlp until the deferred FLOGI ACC is
8413 * processed or cancelled.
8414 */
8415 phba->defer_flogi_acc.ndlp = lpfc_nlp_get(ndlp);
8416 return 0;
8417 }
8418
8419 /* Send back ACC */
8420 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
8421
8422 /* Now lets put fc_myDID back to what its supposed to be */
8423 vport->fc_myDID = did;
8424
8425 return 0;
8426 }
8427
8428 /**
8429 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
8430 * @vport: pointer to a host virtual N_Port data structure.
8431 * @cmdiocb: pointer to lpfc command iocb data structure.
8432 * @ndlp: pointer to a node-list data structure.
8433 *
8434 * This routine processes Request Node Identification Data (RNID) IOCB
8435 * received as an ELS unsolicited event. Only when the RNID specified format
8436 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8437 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8438 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8439 * rejected by invoking the lpfc_els_rsp_reject() routine.
8440 *
8441 * Return code
8442 * 0 - Successfully processed rnid iocb (currently always return 0)
8443 **/
8444 static int
lpfc_els_rcv_rnid(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8445 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8446 struct lpfc_nodelist *ndlp)
8447 {
8448 struct lpfc_dmabuf *pcmd;
8449 uint32_t *lp;
8450 RNID *rn;
8451 struct ls_rjt stat;
8452
8453 pcmd = cmdiocb->cmd_dmabuf;
8454 lp = (uint32_t *) pcmd->virt;
8455
8456 lp++;
8457 rn = (RNID *) lp;
8458
8459 /* RNID received */
8460
8461 switch (rn->Format) {
8462 case 0:
8463 case RNID_TOPOLOGY_DISC:
8464 /* Send back ACC */
8465 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
8466 break;
8467 default:
8468 /* Reject this request because format not supported */
8469 stat.un.b.lsRjtRsvd0 = 0;
8470 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8471 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8472 stat.un.b.vendorUnique = 0;
8473 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
8474 NULL);
8475 }
8476 return 0;
8477 }
8478
8479 /**
8480 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8481 * @vport: pointer to a host virtual N_Port data structure.
8482 * @cmdiocb: pointer to lpfc command iocb data structure.
8483 * @ndlp: pointer to a node-list data structure.
8484 *
8485 * Return code
8486 * 0 - Successfully processed echo iocb (currently always return 0)
8487 **/
8488 static int
lpfc_els_rcv_echo(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8489 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8490 struct lpfc_nodelist *ndlp)
8491 {
8492 uint8_t *pcmd;
8493
8494 pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt;
8495
8496 /* skip over first word of echo command to find echo data */
8497 pcmd += sizeof(uint32_t);
8498
8499 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
8500 return 0;
8501 }
8502
8503 /**
8504 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
8505 * @vport: pointer to a host virtual N_Port data structure.
8506 * @cmdiocb: pointer to lpfc command iocb data structure.
8507 * @ndlp: pointer to a node-list data structure.
8508 *
8509 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8510 * received as an ELS unsolicited event. Currently, this function just invokes
8511 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8512 *
8513 * Return code
8514 * 0 - Successfully processed lirr iocb (currently always return 0)
8515 **/
8516 static int
lpfc_els_rcv_lirr(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8517 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8518 struct lpfc_nodelist *ndlp)
8519 {
8520 struct ls_rjt stat;
8521
8522 /* For now, unconditionally reject this command */
8523 stat.un.b.lsRjtRsvd0 = 0;
8524 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8525 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8526 stat.un.b.vendorUnique = 0;
8527 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8528 return 0;
8529 }
8530
8531 /**
8532 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8533 * @vport: pointer to a host virtual N_Port data structure.
8534 * @cmdiocb: pointer to lpfc command iocb data structure.
8535 * @ndlp: pointer to a node-list data structure.
8536 *
8537 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8538 * received as an ELS unsolicited event. A request to RRQ shall only
8539 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8540 * Nx_Port N_Port_ID of the target Exchange is the same as the
8541 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8542 * not accepted, an LS_RJT with reason code "Unable to perform
8543 * command request" and reason code explanation "Invalid Originator
8544 * S_ID" shall be returned. For now, we just unconditionally accept
8545 * RRQ from the target.
8546 **/
8547 static void
lpfc_els_rcv_rrq(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8548 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8549 struct lpfc_nodelist *ndlp)
8550 {
8551 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
8552 if (vport->phba->sli_rev == LPFC_SLI_REV4)
8553 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
8554 }
8555
8556 /**
8557 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8558 * @phba: pointer to lpfc hba data structure.
8559 * @pmb: pointer to the driver internal queue element for mailbox command.
8560 *
8561 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8562 * mailbox command. This callback function is to actually send the Accept
8563 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
8564 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
8565 * mailbox command, constructs the RLS response with the link statistics
8566 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
8567 * response to the RLS.
8568 *
8569 * Note that the ndlp reference count will be incremented by 1 for holding the
8570 * ndlp and the reference to ndlp will be stored into the ndlp field of
8571 * the IOCB for the completion callback function to the RLS Accept Response
8572 * ELS IOCB command.
8573 *
8574 **/
8575 static void
lpfc_els_rsp_rls_acc(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)8576 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8577 {
8578 int rc = 0;
8579 MAILBOX_t *mb;
8580 IOCB_t *icmd;
8581 union lpfc_wqe128 *wqe;
8582 struct RLS_RSP *rls_rsp;
8583 uint8_t *pcmd;
8584 struct lpfc_iocbq *elsiocb;
8585 struct lpfc_nodelist *ndlp;
8586 uint16_t oxid;
8587 uint16_t rxid;
8588 uint32_t cmdsize;
8589 u32 ulp_context;
8590
8591 mb = &pmb->u.mb;
8592
8593 ndlp = pmb->ctx_ndlp;
8594 rxid = (uint16_t)(pmb->ctx_u.ox_rx_id & 0xffff);
8595 oxid = (uint16_t)((pmb->ctx_u.ox_rx_id >> 16) & 0xffff);
8596 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u));
8597 pmb->ctx_ndlp = NULL;
8598
8599 if (mb->mbxStatus) {
8600 mempool_free(pmb, phba->mbox_mem_pool);
8601 return;
8602 }
8603
8604 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
8605 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8606 lpfc_max_els_tries, ndlp,
8607 ndlp->nlp_DID, ELS_CMD_ACC);
8608
8609 /* Decrement the ndlp reference count from previous mbox command */
8610 lpfc_nlp_put(ndlp);
8611
8612 if (!elsiocb) {
8613 mempool_free(pmb, phba->mbox_mem_pool);
8614 return;
8615 }
8616
8617 ulp_context = get_job_ulpcontext(phba, elsiocb);
8618 if (phba->sli_rev == LPFC_SLI_REV4) {
8619 wqe = &elsiocb->wqe;
8620 /* Xri / rx_id */
8621 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid);
8622 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid);
8623 } else {
8624 icmd = &elsiocb->iocb;
8625 icmd->ulpContext = rxid;
8626 icmd->unsli3.rcvsli3.ox_id = oxid;
8627 }
8628
8629 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8630 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8631 pcmd += sizeof(uint32_t); /* Skip past command */
8632 rls_rsp = (struct RLS_RSP *)pcmd;
8633
8634 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
8635 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
8636 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
8637 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
8638 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
8639 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
8640 mempool_free(pmb, phba->mbox_mem_pool);
8641 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8642 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8643 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8644 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n",
8645 elsiocb->iotag, ulp_context,
8646 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8647 ndlp->nlp_rpi);
8648 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8649 phba->fc_stat.elsXmitACC++;
8650 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8651 if (!elsiocb->ndlp) {
8652 lpfc_els_free_iocb(phba, elsiocb);
8653 return;
8654 }
8655
8656 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8657 if (rc == IOCB_ERROR) {
8658 lpfc_els_free_iocb(phba, elsiocb);
8659 lpfc_nlp_put(ndlp);
8660 }
8661 return;
8662 }
8663
8664 /**
8665 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8666 * @vport: pointer to a host virtual N_Port data structure.
8667 * @cmdiocb: pointer to lpfc command iocb data structure.
8668 * @ndlp: pointer to a node-list data structure.
8669 *
8670 * This routine processes Read Link Status (RLS) IOCB received as an
8671 * ELS unsolicited event. It first checks the remote port state. If the
8672 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8673 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8674 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8675 * for reading the HBA link statistics. It is for the callback function,
8676 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8677 * to actually sending out RPL Accept (ACC) response.
8678 *
8679 * Return codes
8680 * 0 - Successfully processed rls iocb (currently always return 0)
8681 **/
8682 static int
lpfc_els_rcv_rls(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8683 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8684 struct lpfc_nodelist *ndlp)
8685 {
8686 struct lpfc_hba *phba = vport->phba;
8687 LPFC_MBOXQ_t *mbox;
8688 struct ls_rjt stat;
8689 u32 ctx = get_job_ulpcontext(phba, cmdiocb);
8690 u32 ox_id = get_job_rcvoxid(phba, cmdiocb);
8691
8692 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8693 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8694 /* reject the unsolicited RLS request and done with it */
8695 goto reject_out;
8696
8697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
8698 if (mbox) {
8699 lpfc_read_lnk_stat(phba, mbox);
8700 mbox->ctx_u.ox_rx_id = ox_id << 16 | ctx;
8701 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
8702 if (!mbox->ctx_ndlp)
8703 goto node_err;
8704 mbox->vport = vport;
8705 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
8706 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
8707 != MBX_NOT_FINISHED)
8708 /* Mbox completion will send ELS Response */
8709 return 0;
8710 /* Decrement reference count used for the failed mbox
8711 * command.
8712 */
8713 lpfc_nlp_put(ndlp);
8714 node_err:
8715 mempool_free(mbox, phba->mbox_mem_pool);
8716 }
8717 reject_out:
8718 /* issue rejection response */
8719 stat.un.b.lsRjtRsvd0 = 0;
8720 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8721 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8722 stat.un.b.vendorUnique = 0;
8723 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8724 return 0;
8725 }
8726
8727 /**
8728 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8729 * @vport: pointer to a host virtual N_Port data structure.
8730 * @cmdiocb: pointer to lpfc command iocb data structure.
8731 * @ndlp: pointer to a node-list data structure.
8732 *
8733 * This routine processes Read Timout Value (RTV) IOCB received as an
8734 * ELS unsolicited event. It first checks the remote port state. If the
8735 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8736 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8737 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8738 * Value (RTV) unsolicited IOCB event.
8739 *
8740 * Note that the ndlp reference count will be incremented by 1 for holding the
8741 * ndlp and the reference to ndlp will be stored into the ndlp field of
8742 * the IOCB for the completion callback function to the RTV Accept Response
8743 * ELS IOCB command.
8744 *
8745 * Return codes
8746 * 0 - Successfully processed rtv iocb (currently always return 0)
8747 **/
8748 static int
lpfc_els_rcv_rtv(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)8749 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
8750 struct lpfc_nodelist *ndlp)
8751 {
8752 int rc = 0;
8753 IOCB_t *icmd;
8754 union lpfc_wqe128 *wqe;
8755 struct lpfc_hba *phba = vport->phba;
8756 struct ls_rjt stat;
8757 struct RTV_RSP *rtv_rsp;
8758 uint8_t *pcmd;
8759 struct lpfc_iocbq *elsiocb;
8760 uint32_t cmdsize;
8761 u32 ulp_context;
8762
8763 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
8764 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
8765 /* reject the unsolicited RTV request and done with it */
8766 goto reject_out;
8767
8768 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
8769 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
8770 lpfc_max_els_tries, ndlp,
8771 ndlp->nlp_DID, ELS_CMD_ACC);
8772
8773 if (!elsiocb)
8774 return 1;
8775
8776 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8777 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8778 pcmd += sizeof(uint32_t); /* Skip past command */
8779
8780 ulp_context = get_job_ulpcontext(phba, elsiocb);
8781 /* use the command's xri in the response */
8782 if (phba->sli_rev == LPFC_SLI_REV4) {
8783 wqe = &elsiocb->wqe;
8784 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8785 get_job_ulpcontext(phba, cmdiocb));
8786 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8787 get_job_rcvoxid(phba, cmdiocb));
8788 } else {
8789 icmd = &elsiocb->iocb;
8790 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb);
8791 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb);
8792 }
8793
8794 rtv_rsp = (struct RTV_RSP *)pcmd;
8795
8796 /* populate RTV payload */
8797 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
8798 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
8799 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
8800 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
8801 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
8802
8803 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8804 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
8805 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8806 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x, "
8807 "Data: x%x x%x x%x\n",
8808 elsiocb->iotag, ulp_context,
8809 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
8810 ndlp->nlp_rpi,
8811 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
8812 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
8813 phba->fc_stat.elsXmitACC++;
8814 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8815 if (!elsiocb->ndlp) {
8816 lpfc_els_free_iocb(phba, elsiocb);
8817 return 0;
8818 }
8819
8820 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8821 if (rc == IOCB_ERROR) {
8822 lpfc_els_free_iocb(phba, elsiocb);
8823 lpfc_nlp_put(ndlp);
8824 }
8825 return 0;
8826
8827 reject_out:
8828 /* issue rejection response */
8829 stat.un.b.lsRjtRsvd0 = 0;
8830 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
8831 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
8832 stat.un.b.vendorUnique = 0;
8833 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
8834 return 0;
8835 }
8836
8837 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
8838 * @vport: pointer to a host virtual N_Port data structure.
8839 * @ndlp: pointer to a node-list data structure.
8840 * @did: DID of the target.
8841 * @rrq: Pointer to the rrq struct.
8842 *
8843 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8844 * successful, the completion handler will clear the RRQ.
8845 *
8846 * Return codes
8847 * 0 - Successfully sent rrq els iocb.
8848 * 1 - Failed to send rrq els iocb.
8849 **/
8850 static int
lpfc_issue_els_rrq(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint32_t did,struct lpfc_node_rrq * rrq)8851 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8852 uint32_t did, struct lpfc_node_rrq *rrq)
8853 {
8854 struct lpfc_hba *phba = vport->phba;
8855 struct RRQ *els_rrq;
8856 struct lpfc_iocbq *elsiocb;
8857 uint8_t *pcmd;
8858 uint16_t cmdsize;
8859 int ret;
8860
8861 if (!ndlp)
8862 return 1;
8863
8864 /* If ndlp is not NULL, we will bump the reference count on it */
8865 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
8866 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
8867 ELS_CMD_RRQ);
8868 if (!elsiocb)
8869 return 1;
8870
8871 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
8872
8873 /* For RRQ request, remainder of payload is Exchange IDs */
8874 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
8875 pcmd += sizeof(uint32_t);
8876 els_rrq = (struct RRQ *) pcmd;
8877
8878 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
8879 bf_set(rrq_rxid, els_rrq, rrq->rxid);
8880 bf_set(rrq_did, els_rrq, vport->fc_myDID);
8881 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
8882 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
8883
8884
8885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8886 "Issue RRQ: did:x%x",
8887 did, rrq->xritag, rrq->rxid);
8888 elsiocb->context_un.rrq = rrq;
8889 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq;
8890
8891 elsiocb->ndlp = lpfc_nlp_get(ndlp);
8892 if (!elsiocb->ndlp)
8893 goto io_err;
8894
8895 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
8896 if (ret == IOCB_ERROR) {
8897 lpfc_nlp_put(ndlp);
8898 goto io_err;
8899 }
8900 return 0;
8901
8902 io_err:
8903 lpfc_els_free_iocb(phba, elsiocb);
8904 return 1;
8905 }
8906
8907 /**
8908 * lpfc_send_rrq - Sends ELS RRQ if needed.
8909 * @phba: pointer to lpfc hba data structure.
8910 * @rrq: pointer to the active rrq.
8911 *
8912 * This routine will call the lpfc_issue_els_rrq if the rrq is
8913 * still active for the xri. If this function returns a failure then
8914 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8915 *
8916 * Returns 0 Success.
8917 * 1 Failure.
8918 **/
8919 int
lpfc_send_rrq(struct lpfc_hba * phba,struct lpfc_node_rrq * rrq)8920 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
8921 {
8922 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
8923 rrq->nlp_DID);
8924 if (!ndlp)
8925 return 1;
8926
8927 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
8928 return lpfc_issue_els_rrq(rrq->vport, ndlp,
8929 rrq->nlp_DID, rrq);
8930 else
8931 return 1;
8932 }
8933
8934 /**
8935 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
8936 * @vport: pointer to a host virtual N_Port data structure.
8937 * @cmdsize: size of the ELS command.
8938 * @oldiocb: pointer to the original lpfc command iocb data structure.
8939 * @ndlp: pointer to a node-list data structure.
8940 *
8941 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
8942 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
8943 *
8944 * Note that the ndlp reference count will be incremented by 1 for holding the
8945 * ndlp and the reference to ndlp will be stored into the ndlp field of
8946 * the IOCB for the completion callback function to the RPL Accept Response
8947 * ELS command.
8948 *
8949 * Return code
8950 * 0 - Successfully issued ACC RPL ELS command
8951 * 1 - Failed to issue ACC RPL ELS command
8952 **/
8953 static int
lpfc_els_rsp_rpl_acc(struct lpfc_vport * vport,uint16_t cmdsize,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)8954 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
8955 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
8956 {
8957 int rc = 0;
8958 struct lpfc_hba *phba = vport->phba;
8959 IOCB_t *icmd;
8960 union lpfc_wqe128 *wqe;
8961 RPL_RSP rpl_rsp;
8962 struct lpfc_iocbq *elsiocb;
8963 uint8_t *pcmd;
8964 u32 ulp_context;
8965
8966 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
8967 ndlp->nlp_DID, ELS_CMD_ACC);
8968
8969 if (!elsiocb)
8970 return 1;
8971
8972 ulp_context = get_job_ulpcontext(phba, elsiocb);
8973 if (phba->sli_rev == LPFC_SLI_REV4) {
8974 wqe = &elsiocb->wqe;
8975 /* Xri / rx_id */
8976 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
8977 get_job_ulpcontext(phba, oldiocb));
8978 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8979 get_job_rcvoxid(phba, oldiocb));
8980 } else {
8981 icmd = &elsiocb->iocb;
8982 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb);
8983 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb);
8984 }
8985
8986 pcmd = elsiocb->cmd_dmabuf->virt;
8987 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
8988 pcmd += sizeof(uint16_t);
8989 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
8990 pcmd += sizeof(uint16_t);
8991
8992 /* Setup the RPL ACC payload */
8993 rpl_rsp.listLen = be32_to_cpu(1);
8994 rpl_rsp.index = 0;
8995 rpl_rsp.port_num_blk.portNum = 0;
8996 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
8997 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
8998 sizeof(struct lpfc_name));
8999 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
9000 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
9001 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9002 "0120 Xmit ELS RPL ACC response tag x%x "
9003 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, "
9004 "rpi x%x\n",
9005 elsiocb->iotag, ulp_context,
9006 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
9007 ndlp->nlp_rpi);
9008 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
9009 phba->fc_stat.elsXmitACC++;
9010 elsiocb->ndlp = lpfc_nlp_get(ndlp);
9011 if (!elsiocb->ndlp) {
9012 lpfc_els_free_iocb(phba, elsiocb);
9013 return 1;
9014 }
9015
9016 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
9017 if (rc == IOCB_ERROR) {
9018 lpfc_els_free_iocb(phba, elsiocb);
9019 lpfc_nlp_put(ndlp);
9020 return 1;
9021 }
9022
9023 return 0;
9024 }
9025
9026 /**
9027 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
9028 * @vport: pointer to a host virtual N_Port data structure.
9029 * @cmdiocb: pointer to lpfc command iocb data structure.
9030 * @ndlp: pointer to a node-list data structure.
9031 *
9032 * This routine processes Read Port List (RPL) IOCB received as an ELS
9033 * unsolicited event. It first checks the remote port state. If the remote
9034 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
9035 * invokes the lpfc_els_rsp_reject() routine to send reject response.
9036 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
9037 * to accept the RPL.
9038 *
9039 * Return code
9040 * 0 - Successfully processed rpl iocb (currently always return 0)
9041 **/
9042 static int
lpfc_els_rcv_rpl(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)9043 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9044 struct lpfc_nodelist *ndlp)
9045 {
9046 struct lpfc_dmabuf *pcmd;
9047 uint32_t *lp;
9048 uint32_t maxsize;
9049 uint16_t cmdsize;
9050 RPL *rpl;
9051 struct ls_rjt stat;
9052
9053 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
9054 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
9055 /* issue rejection response */
9056 stat.un.b.lsRjtRsvd0 = 0;
9057 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
9058 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
9059 stat.un.b.vendorUnique = 0;
9060 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
9061 NULL);
9062 /* rejected the unsolicited RPL request and done with it */
9063 return 0;
9064 }
9065
9066 pcmd = cmdiocb->cmd_dmabuf;
9067 lp = (uint32_t *) pcmd->virt;
9068 rpl = (RPL *) (lp + 1);
9069 maxsize = be32_to_cpu(rpl->maxsize);
9070
9071 /* We support only one port */
9072 if ((rpl->index == 0) &&
9073 ((maxsize == 0) ||
9074 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
9075 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
9076 } else {
9077 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
9078 }
9079 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
9080
9081 return 0;
9082 }
9083
9084 /**
9085 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
9086 * @vport: pointer to a virtual N_Port data structure.
9087 * @cmdiocb: pointer to lpfc command iocb data structure.
9088 * @ndlp: pointer to a node-list data structure.
9089 *
9090 * This routine processes Fibre Channel Address Resolution Protocol
9091 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
9092 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
9093 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
9094 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
9095 * remote PortName is compared against the FC PortName stored in the @vport
9096 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
9097 * compared against the FC NodeName stored in the @vport data structure.
9098 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
9099 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
9100 * invoked to send out FARP Response to the remote node. Before sending the
9101 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
9102 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
9103 * routine is invoked to log into the remote port first.
9104 *
9105 * Return code
9106 * 0 - Either the FARP Match Mode not supported or successfully processed
9107 **/
9108 static int
lpfc_els_rcv_farp(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)9109 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9110 struct lpfc_nodelist *ndlp)
9111 {
9112 struct lpfc_dmabuf *pcmd;
9113 uint32_t *lp;
9114 FARP *fp;
9115 uint32_t cnt, did;
9116
9117 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9118 pcmd = cmdiocb->cmd_dmabuf;
9119 lp = (uint32_t *) pcmd->virt;
9120
9121 lp++;
9122 fp = (FARP *) lp;
9123 /* FARP-REQ received from DID <did> */
9124 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9125 "0601 FARP-REQ received from DID x%x\n", did);
9126 /* We will only support match on WWPN or WWNN */
9127 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
9128 return 0;
9129 }
9130
9131 cnt = 0;
9132 /* If this FARP command is searching for my portname */
9133 if (fp->Mflags & FARP_MATCH_PORT) {
9134 if (memcmp(&fp->RportName, &vport->fc_portname,
9135 sizeof(struct lpfc_name)) == 0)
9136 cnt = 1;
9137 }
9138
9139 /* If this FARP command is searching for my nodename */
9140 if (fp->Mflags & FARP_MATCH_NODE) {
9141 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
9142 sizeof(struct lpfc_name)) == 0)
9143 cnt = 1;
9144 }
9145
9146 if (cnt) {
9147 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
9148 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
9149 /* Log back into the node before sending the FARP. */
9150 if (fp->Rflags & FARP_REQUEST_PLOGI) {
9151 ndlp->nlp_prev_state = ndlp->nlp_state;
9152 lpfc_nlp_set_state(vport, ndlp,
9153 NLP_STE_PLOGI_ISSUE);
9154 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9155 }
9156
9157 /* Send a FARP response to that node */
9158 if (fp->Rflags & FARP_REQUEST_FARPR)
9159 lpfc_issue_els_farpr(vport, did, 0);
9160 }
9161 }
9162 return 0;
9163 }
9164
9165 /**
9166 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
9167 * @vport: pointer to a host virtual N_Port data structure.
9168 * @cmdiocb: pointer to lpfc command iocb data structure.
9169 * @ndlp: pointer to a node-list data structure.
9170 *
9171 * This routine processes Fibre Channel Address Resolution Protocol
9172 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
9173 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
9174 * the FARP response request.
9175 *
9176 * Return code
9177 * 0 - Successfully processed FARPR IOCB (currently always return 0)
9178 **/
9179 static int
lpfc_els_rcv_farpr(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)9180 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9181 struct lpfc_nodelist *ndlp)
9182 {
9183 uint32_t did;
9184
9185 did = get_job_els_rsp64_did(vport->phba, cmdiocb);
9186
9187 /* FARP-RSP received from DID <did> */
9188 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9189 "0600 FARP-RSP received from DID x%x\n", did);
9190 /* ACCEPT the Farp resp request */
9191 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
9192
9193 return 0;
9194 }
9195
9196 /**
9197 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
9198 * @vport: pointer to a host virtual N_Port data structure.
9199 * @cmdiocb: pointer to lpfc command iocb data structure.
9200 * @fan_ndlp: pointer to a node-list data structure.
9201 *
9202 * This routine processes a Fabric Address Notification (FAN) IOCB
9203 * command received as an ELS unsolicited event. The FAN ELS command will
9204 * only be processed on a physical port (i.e., the @vport represents the
9205 * physical port). The fabric NodeName and PortName from the FAN IOCB are
9206 * compared against those in the phba data structure. If any of those is
9207 * different, the lpfc_initial_flogi() routine is invoked to initialize
9208 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
9209 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
9210 * is invoked to register login to the fabric.
9211 *
9212 * Return code
9213 * 0 - Successfully processed fan iocb (currently always return 0).
9214 **/
9215 static int
lpfc_els_rcv_fan(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * fan_ndlp)9216 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9217 struct lpfc_nodelist *fan_ndlp)
9218 {
9219 struct lpfc_hba *phba = vport->phba;
9220 uint32_t *lp;
9221 FAN *fp;
9222
9223 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
9224 lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
9225 fp = (FAN *) ++lp;
9226 /* FAN received; Fan does not have a reply sequence */
9227 if ((vport == phba->pport) &&
9228 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
9229 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
9230 sizeof(struct lpfc_name))) ||
9231 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
9232 sizeof(struct lpfc_name)))) {
9233 /* This port has switched fabrics. FLOGI is required */
9234 lpfc_issue_init_vfi(vport);
9235 } else {
9236 /* FAN verified - skip FLOGI */
9237 vport->fc_myDID = vport->fc_prevDID;
9238 if (phba->sli_rev < LPFC_SLI_REV4)
9239 lpfc_issue_fabric_reglogin(vport);
9240 else {
9241 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9242 "3138 Need register VFI: (x%x/%x)\n",
9243 vport->fc_prevDID, vport->fc_myDID);
9244 lpfc_issue_reg_vfi(vport);
9245 }
9246 }
9247 }
9248 return 0;
9249 }
9250
9251 /**
9252 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
9253 * @vport: pointer to a host virtual N_Port data structure.
9254 * @cmdiocb: pointer to lpfc command iocb data structure.
9255 * @ndlp: pointer to a node-list data structure.
9256 *
9257 * Return code
9258 * 0 - Successfully processed echo iocb (currently always return 0)
9259 **/
9260 static int
lpfc_els_rcv_edc(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)9261 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
9262 struct lpfc_nodelist *ndlp)
9263 {
9264 struct lpfc_hba *phba = vport->phba;
9265 struct fc_els_edc *edc_req;
9266 struct fc_tlv_desc *tlv;
9267 uint8_t *payload;
9268 uint32_t *ptr, dtag;
9269 const char *dtag_nm;
9270 int desc_cnt = 0, bytes_remain;
9271 struct fc_diag_lnkflt_desc *plnkflt;
9272
9273 payload = cmdiocb->cmd_dmabuf->virt;
9274
9275 edc_req = (struct fc_els_edc *)payload;
9276 bytes_remain = be32_to_cpu(edc_req->desc_len);
9277
9278 ptr = (uint32_t *)payload;
9279 lpfc_printf_vlog(vport, KERN_INFO,
9280 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9281 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
9282 bytes_remain, be32_to_cpu(*ptr),
9283 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
9284
9285 /* No signal support unless there is a congestion descriptor */
9286 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
9287 phba->cgn_sig_freq = 0;
9288 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
9289
9290 if (bytes_remain <= 0)
9291 goto out;
9292
9293 tlv = edc_req->desc;
9294
9295 /*
9296 * cycle through EDC diagnostic descriptors to find the
9297 * congestion signaling capability descriptor
9298 */
9299 while (bytes_remain) {
9300 if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
9301 lpfc_printf_log(phba, KERN_WARNING,
9302 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9303 "6464 Truncated TLV hdr on "
9304 "Diagnostic descriptor[%d]\n",
9305 desc_cnt);
9306 goto out;
9307 }
9308
9309 dtag = be32_to_cpu(tlv->desc_tag);
9310 switch (dtag) {
9311 case ELS_DTAG_LNK_FAULT_CAP:
9312 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9313 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9314 sizeof(struct fc_diag_lnkflt_desc)) {
9315 lpfc_printf_log(phba, KERN_WARNING,
9316 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9317 "6465 Truncated Link Fault Diagnostic "
9318 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9319 desc_cnt, bytes_remain,
9320 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9321 sizeof(struct fc_diag_lnkflt_desc));
9322 goto out;
9323 }
9324 plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
9325 lpfc_printf_log(phba, KERN_INFO,
9326 LOG_ELS | LOG_LDS_EVENT,
9327 "4626 Link Fault Desc Data: x%08x len x%x "
9328 "da x%x dd x%x interval x%x\n",
9329 be32_to_cpu(plnkflt->desc_tag),
9330 be32_to_cpu(plnkflt->desc_len),
9331 be32_to_cpu(
9332 plnkflt->degrade_activate_threshold),
9333 be32_to_cpu(
9334 plnkflt->degrade_deactivate_threshold),
9335 be32_to_cpu(plnkflt->fec_degrade_interval));
9336 break;
9337 case ELS_DTAG_CG_SIGNAL_CAP:
9338 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
9339 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
9340 sizeof(struct fc_diag_cg_sig_desc)) {
9341 lpfc_printf_log(
9342 phba, KERN_WARNING, LOG_CGN_MGMT,
9343 "6466 Truncated cgn signal Diagnostic "
9344 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9345 desc_cnt, bytes_remain,
9346 FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
9347 sizeof(struct fc_diag_cg_sig_desc));
9348 goto out;
9349 }
9350
9351 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
9352 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
9353
9354 /* We start negotiation with lpfc_fabric_cgn_frequency.
9355 * When we process the EDC, we will settle on the
9356 * higher frequency.
9357 */
9358 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
9359
9360 lpfc_least_capable_settings(
9361 phba, (struct fc_diag_cg_sig_desc *)tlv);
9362 break;
9363 default:
9364 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
9365 lpfc_printf_log(phba, KERN_WARNING,
9366 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
9367 "6467 unknown Diagnostic "
9368 "Descriptor[%d]: tag x%x (%s)\n",
9369 desc_cnt, dtag, dtag_nm);
9370 }
9371 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
9372 tlv = fc_tlv_next_desc(tlv);
9373 desc_cnt++;
9374 }
9375 out:
9376 /* Need to send back an ACC */
9377 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
9378
9379 lpfc_config_cgn_signal(phba);
9380 return 0;
9381 }
9382
9383 /**
9384 * lpfc_els_timeout - Handler funciton to the els timer
9385 * @t: timer context used to obtain the vport.
9386 *
9387 * This routine is invoked by the ELS timer after timeout. It posts the ELS
9388 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
9389 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
9390 * up the worker thread. It is for the worker thread to invoke the routine
9391 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
9392 **/
9393 void
lpfc_els_timeout(struct timer_list * t)9394 lpfc_els_timeout(struct timer_list *t)
9395 {
9396 struct lpfc_vport *vport = timer_container_of(vport, t, els_tmofunc);
9397 struct lpfc_hba *phba = vport->phba;
9398 uint32_t tmo_posted;
9399 unsigned long iflag;
9400
9401 spin_lock_irqsave(&vport->work_port_lock, iflag);
9402 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
9403 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
9404 vport->work_port_events |= WORKER_ELS_TMO;
9405 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
9406
9407 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
9408 lpfc_worker_wake_up(phba);
9409 return;
9410 }
9411
9412
9413 /**
9414 * lpfc_els_timeout_handler - Process an els timeout event
9415 * @vport: pointer to a virtual N_Port data structure.
9416 *
9417 * This routine is the actual handler function that processes an ELS timeout
9418 * event. It walks the ELS ring to get and abort all the IOCBs (except the
9419 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
9420 * invoking the lpfc_sli_issue_abort_iotag() routine.
9421 **/
9422 void
lpfc_els_timeout_handler(struct lpfc_vport * vport)9423 lpfc_els_timeout_handler(struct lpfc_vport *vport)
9424 {
9425 struct lpfc_hba *phba = vport->phba;
9426 struct lpfc_sli_ring *pring;
9427 struct lpfc_iocbq *tmp_iocb, *piocb;
9428 IOCB_t *cmd = NULL;
9429 struct lpfc_dmabuf *pcmd;
9430 uint32_t els_command = 0;
9431 uint32_t timeout;
9432 uint32_t remote_ID = 0xffffffff;
9433 LIST_HEAD(abort_list);
9434 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0;
9435
9436
9437 timeout = (uint32_t)(phba->fc_ratov << 1);
9438
9439 pring = lpfc_phba_elsring(phba);
9440 if (unlikely(!pring))
9441 return;
9442
9443 if (test_bit(FC_UNLOADING, &phba->pport->load_flag))
9444 return;
9445
9446 spin_lock_irq(&phba->hbalock);
9447 if (phba->sli_rev == LPFC_SLI_REV4)
9448 spin_lock(&pring->ring_lock);
9449
9450 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9451 ulp_command = get_job_cmnd(phba, piocb);
9452 ulp_context = get_job_ulpcontext(phba, piocb);
9453 did = get_job_els_rsp64_did(phba, piocb);
9454
9455 if (phba->sli_rev == LPFC_SLI_REV4) {
9456 iotag = get_wqe_reqtag(piocb);
9457 } else {
9458 cmd = &piocb->iocb;
9459 iotag = cmd->ulpIoTag;
9460 }
9461
9462 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 ||
9463 ulp_command == CMD_ABORT_XRI_CX ||
9464 ulp_command == CMD_ABORT_XRI_CN ||
9465 ulp_command == CMD_CLOSE_XRI_CN)
9466 continue;
9467
9468 if (piocb->vport != vport)
9469 continue;
9470
9471 pcmd = piocb->cmd_dmabuf;
9472 if (pcmd)
9473 els_command = *(uint32_t *) (pcmd->virt);
9474
9475 if (els_command == ELS_CMD_FARP ||
9476 els_command == ELS_CMD_FARPR ||
9477 els_command == ELS_CMD_FDISC)
9478 continue;
9479
9480 if (piocb->drvrTimeout > 0) {
9481 if (piocb->drvrTimeout >= timeout)
9482 piocb->drvrTimeout -= timeout;
9483 else
9484 piocb->drvrTimeout = 0;
9485 continue;
9486 }
9487
9488 remote_ID = 0xffffffff;
9489 if (ulp_command != CMD_GEN_REQUEST64_CR) {
9490 remote_ID = did;
9491 } else {
9492 struct lpfc_nodelist *ndlp;
9493 ndlp = __lpfc_findnode_rpi(vport, ulp_context);
9494 if (ndlp)
9495 remote_ID = ndlp->nlp_DID;
9496 }
9497 list_add_tail(&piocb->dlist, &abort_list);
9498 }
9499 if (phba->sli_rev == LPFC_SLI_REV4)
9500 spin_unlock(&pring->ring_lock);
9501 spin_unlock_irq(&phba->hbalock);
9502
9503 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9504 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9505 "0127 ELS timeout Data: x%x x%x x%x "
9506 "x%x\n", els_command,
9507 remote_ID, ulp_command, iotag);
9508
9509 spin_lock_irq(&phba->hbalock);
9510 list_del_init(&piocb->dlist);
9511 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9512 spin_unlock_irq(&phba->hbalock);
9513 }
9514
9515 /* Make sure HBA is alive */
9516 lpfc_issue_hb_tmo(phba);
9517
9518 if (!list_empty(&pring->txcmplq))
9519 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
9520 mod_timer(&vport->els_tmofunc,
9521 jiffies + secs_to_jiffies(timeout));
9522 }
9523
9524 /**
9525 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
9526 * @vport: pointer to a host virtual N_Port data structure.
9527 *
9528 * This routine is used to clean up all the outstanding ELS commands on a
9529 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9530 * routine. After that, it walks the ELS transmit queue to remove all the
9531 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9532 * the IOCBs with a non-NULL completion callback function, the callback
9533 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9534 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9535 * callback function, the IOCB will simply be released. Finally, it walks
9536 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9537 * completion queue IOCB that is associated with the @vport and is not
9538 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9539 * part of the discovery state machine) out to HBA by invoking the
9540 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9541 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9542 * the IOCBs are aborted when this function returns.
9543 **/
9544 void
lpfc_els_flush_cmd(struct lpfc_vport * vport)9545 lpfc_els_flush_cmd(struct lpfc_vport *vport)
9546 {
9547 LIST_HEAD(abort_list);
9548 LIST_HEAD(cancel_list);
9549 struct lpfc_hba *phba = vport->phba;
9550 struct lpfc_sli_ring *pring;
9551 struct lpfc_iocbq *tmp_iocb, *piocb;
9552 u32 ulp_command;
9553 unsigned long iflags = 0;
9554 bool mbx_tmo_err;
9555
9556 lpfc_fabric_abort_vport(vport);
9557
9558 /*
9559 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9560 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9561 * ultimately grabs the ring_lock, the driver must splice the list into
9562 * a working list and release the locks before calling the abort.
9563 */
9564 spin_lock_irqsave(&phba->hbalock, iflags);
9565 pring = lpfc_phba_elsring(phba);
9566
9567 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9568 if (unlikely(!pring)) {
9569 spin_unlock_irqrestore(&phba->hbalock, iflags);
9570 return;
9571 }
9572
9573 if (phba->sli_rev == LPFC_SLI_REV4)
9574 spin_lock(&pring->ring_lock);
9575
9576 mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags);
9577 /* First we need to issue aborts to outstanding cmds on txcmpl */
9578 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
9579 if (piocb->vport != vport)
9580 continue;
9581
9582 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9583 "2243 iotag = 0x%x cmd_flag = 0x%x "
9584 "ulp_command = 0x%x sli_flag = 0x%x\n",
9585 piocb->iotag, piocb->cmd_flag,
9586 get_job_cmnd(phba, piocb),
9587 phba->sli.sli_flag);
9588
9589 if ((phba->sli.sli_flag & LPFC_SLI_ACTIVE) && !mbx_tmo_err) {
9590 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9591 continue;
9592 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED)
9593 continue;
9594 }
9595
9596 /* On the ELS ring we can have ELS_REQUESTs, ELS_RSPs,
9597 * or GEN_REQUESTs waiting for a CQE response.
9598 */
9599 ulp_command = get_job_cmnd(phba, piocb);
9600 if (ulp_command == CMD_ELS_REQUEST64_WQE ||
9601 ulp_command == CMD_XMIT_ELS_RSP64_WQE) {
9602 list_add_tail(&piocb->dlist, &abort_list);
9603
9604 /* If the link is down when flushing ELS commands
9605 * the firmware will not complete them till after
9606 * the link comes back up. This may confuse
9607 * discovery for the new link up, so we need to
9608 * change the compl routine to just clean up the iocb
9609 * and avoid any retry logic.
9610 */
9611 if (phba->link_state == LPFC_LINK_DOWN)
9612 piocb->cmd_cmpl = lpfc_cmpl_els_link_down;
9613 } else if (ulp_command == CMD_GEN_REQUEST64_CR ||
9614 mbx_tmo_err)
9615 list_add_tail(&piocb->dlist, &abort_list);
9616 }
9617
9618 if (phba->sli_rev == LPFC_SLI_REV4)
9619 spin_unlock(&pring->ring_lock);
9620 spin_unlock_irqrestore(&phba->hbalock, iflags);
9621
9622 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
9623 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
9624 spin_lock_irqsave(&phba->hbalock, iflags);
9625 list_del_init(&piocb->dlist);
9626 if (mbx_tmo_err || !(phba->sli.sli_flag & LPFC_SLI_ACTIVE))
9627 list_move_tail(&piocb->list, &cancel_list);
9628 else
9629 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
9630
9631 spin_unlock_irqrestore(&phba->hbalock, iflags);
9632 }
9633 if (!list_empty(&cancel_list))
9634 lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT,
9635 IOERR_SLI_ABORTED);
9636 else
9637 /* Make sure HBA is alive */
9638 lpfc_issue_hb_tmo(phba);
9639
9640 if (!list_empty(&abort_list))
9641 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9642 "3387 abort list for txq not empty\n");
9643 INIT_LIST_HEAD(&abort_list);
9644
9645 spin_lock_irqsave(&phba->hbalock, iflags);
9646 if (phba->sli_rev == LPFC_SLI_REV4)
9647 spin_lock(&pring->ring_lock);
9648
9649 /* No need to abort the txq list,
9650 * just queue them up for lpfc_sli_cancel_iocbs
9651 */
9652 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
9653 ulp_command = get_job_cmnd(phba, piocb);
9654
9655 if (piocb->cmd_flag & LPFC_IO_LIBDFC)
9656 continue;
9657
9658 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
9659 if (ulp_command == CMD_QUE_RING_BUF_CN ||
9660 ulp_command == CMD_QUE_RING_BUF64_CN ||
9661 ulp_command == CMD_CLOSE_XRI_CN ||
9662 ulp_command == CMD_ABORT_XRI_CN ||
9663 ulp_command == CMD_ABORT_XRI_CX)
9664 continue;
9665
9666 if (piocb->vport != vport)
9667 continue;
9668
9669 list_del_init(&piocb->list);
9670 list_add_tail(&piocb->list, &abort_list);
9671 }
9672
9673 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9674 if (vport == phba->pport) {
9675 list_for_each_entry_safe(piocb, tmp_iocb,
9676 &phba->fabric_iocb_list, list) {
9677 list_del_init(&piocb->list);
9678 list_add_tail(&piocb->list, &abort_list);
9679 }
9680 }
9681
9682 if (phba->sli_rev == LPFC_SLI_REV4)
9683 spin_unlock(&pring->ring_lock);
9684 spin_unlock_irqrestore(&phba->hbalock, iflags);
9685
9686 /* Cancel all the IOCBs from the completions list */
9687 lpfc_sli_cancel_iocbs(phba, &abort_list,
9688 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
9689
9690 return;
9691 }
9692
9693 /**
9694 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
9695 * @phba: pointer to lpfc hba data structure.
9696 *
9697 * This routine is used to clean up all the outstanding ELS commands on a
9698 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9699 * routine. After that, it walks the ELS transmit queue to remove all the
9700 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9701 * the IOCBs with the completion callback function associated, the callback
9702 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9703 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9704 * callback function associated, the IOCB will simply be released. Finally,
9705 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9706 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9707 * management plane IOCBs that are not part of the discovery state machine)
9708 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9709 **/
9710 void
lpfc_els_flush_all_cmd(struct lpfc_hba * phba)9711 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
9712 {
9713 struct lpfc_vport *vport;
9714
9715 spin_lock_irq(&phba->port_list_lock);
9716 list_for_each_entry(vport, &phba->port_list, listentry)
9717 lpfc_els_flush_cmd(vport);
9718 spin_unlock_irq(&phba->port_list_lock);
9719
9720 return;
9721 }
9722
9723 /**
9724 * lpfc_send_els_failure_event - Posts an ELS command failure event
9725 * @phba: Pointer to hba context object.
9726 * @cmdiocbp: Pointer to command iocb which reported error.
9727 * @rspiocbp: Pointer to response iocb which reported error.
9728 *
9729 * This function sends an event when there is an ELS command
9730 * failure.
9731 **/
9732 void
lpfc_send_els_failure_event(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocbp,struct lpfc_iocbq * rspiocbp)9733 lpfc_send_els_failure_event(struct lpfc_hba *phba,
9734 struct lpfc_iocbq *cmdiocbp,
9735 struct lpfc_iocbq *rspiocbp)
9736 {
9737 struct lpfc_vport *vport = cmdiocbp->vport;
9738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9739 struct lpfc_lsrjt_event lsrjt_event;
9740 struct lpfc_fabric_event_header fabric_event;
9741 struct ls_rjt stat;
9742 struct lpfc_nodelist *ndlp;
9743 uint32_t *pcmd;
9744 u32 ulp_status, ulp_word4;
9745
9746 ndlp = cmdiocbp->ndlp;
9747 if (!ndlp)
9748 return;
9749
9750 ulp_status = get_job_ulpstatus(phba, rspiocbp);
9751 ulp_word4 = get_job_word4(phba, rspiocbp);
9752
9753 if (ulp_status == IOSTAT_LS_RJT) {
9754 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
9755 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
9756 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
9757 sizeof(struct lpfc_name));
9758 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
9759 sizeof(struct lpfc_name));
9760 pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt;
9761 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
9762 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
9763 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
9764 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
9765 fc_host_post_vendor_event(shost,
9766 fc_get_event_number(),
9767 sizeof(lsrjt_event),
9768 (char *)&lsrjt_event,
9769 LPFC_NL_VENDOR_ID);
9770 return;
9771 }
9772 if (ulp_status == IOSTAT_NPORT_BSY ||
9773 ulp_status == IOSTAT_FABRIC_BSY) {
9774 fabric_event.event_type = FC_REG_FABRIC_EVENT;
9775 if (ulp_status == IOSTAT_NPORT_BSY)
9776 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
9777 else
9778 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
9779 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
9780 sizeof(struct lpfc_name));
9781 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
9782 sizeof(struct lpfc_name));
9783 fc_host_post_vendor_event(shost,
9784 fc_get_event_number(),
9785 sizeof(fabric_event),
9786 (char *)&fabric_event,
9787 LPFC_NL_VENDOR_ID);
9788 return;
9789 }
9790
9791 }
9792
9793 /**
9794 * lpfc_send_els_event - Posts unsolicited els event
9795 * @vport: Pointer to vport object.
9796 * @ndlp: Pointer FC node object.
9797 * @payload: ELS command code type.
9798 *
9799 * This function posts an event when there is an incoming
9800 * unsolicited ELS command.
9801 **/
9802 static void
lpfc_send_els_event(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint32_t * payload)9803 lpfc_send_els_event(struct lpfc_vport *vport,
9804 struct lpfc_nodelist *ndlp,
9805 uint32_t *payload)
9806 {
9807 struct lpfc_els_event_header *els_data = NULL;
9808 struct lpfc_logo_event *logo_data = NULL;
9809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9810
9811 if (*payload == ELS_CMD_LOGO) {
9812 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
9813 if (!logo_data) {
9814 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9815 "0148 Failed to allocate memory "
9816 "for LOGO event\n");
9817 return;
9818 }
9819 els_data = &logo_data->header;
9820 } else {
9821 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
9822 GFP_KERNEL);
9823 if (!els_data) {
9824 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9825 "0149 Failed to allocate memory "
9826 "for ELS event\n");
9827 return;
9828 }
9829 }
9830 els_data->event_type = FC_REG_ELS_EVENT;
9831 switch (*payload) {
9832 case ELS_CMD_PLOGI:
9833 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
9834 break;
9835 case ELS_CMD_PRLO:
9836 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
9837 break;
9838 case ELS_CMD_ADISC:
9839 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
9840 break;
9841 case ELS_CMD_LOGO:
9842 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
9843 /* Copy the WWPN in the LOGO payload */
9844 memcpy(logo_data->logo_wwpn, &payload[2],
9845 sizeof(struct lpfc_name));
9846 break;
9847 default:
9848 kfree(els_data);
9849 return;
9850 }
9851 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
9852 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
9853 if (*payload == ELS_CMD_LOGO) {
9854 fc_host_post_vendor_event(shost,
9855 fc_get_event_number(),
9856 sizeof(struct lpfc_logo_event),
9857 (char *)logo_data,
9858 LPFC_NL_VENDOR_ID);
9859 kfree(logo_data);
9860 } else {
9861 fc_host_post_vendor_event(shost,
9862 fc_get_event_number(),
9863 sizeof(struct lpfc_els_event_header),
9864 (char *)els_data,
9865 LPFC_NL_VENDOR_ID);
9866 kfree(els_data);
9867 }
9868
9869 return;
9870 }
9871
9872
9873 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
9874 FC_FPIN_LI_EVT_TYPES_INIT);
9875
9876 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
9877 FC_FPIN_DELI_EVT_TYPES_INIT);
9878
9879 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
9880 FC_FPIN_CONGN_EVT_TYPES_INIT);
9881
9882 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
9883 fc_fpin_congn_severity_types,
9884 FC_FPIN_CONGN_SEVERITY_INIT);
9885
9886
9887 /**
9888 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9889 * @phba: Pointer to phba object.
9890 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9891 * @cnt: count of WWPNs in FPIN payload
9892 *
9893 * This routine is called by LI and PC descriptors.
9894 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9895 */
9896 static void
lpfc_display_fpin_wwpn(struct lpfc_hba * phba,__be64 * wwnlist,u32 cnt)9897 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
9898 {
9899 char buf[LPFC_FPIN_WWPN_LINE_SZ];
9900 __be64 wwn;
9901 u64 wwpn;
9902 int i, len;
9903 int line = 0;
9904 int wcnt = 0;
9905 bool endit = false;
9906
9907 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
9908 for (i = 0; i < cnt; i++) {
9909 /* Are we on the last WWPN */
9910 if (i == (cnt - 1))
9911 endit = true;
9912
9913 /* Extract the next WWPN from the payload */
9914 wwn = *wwnlist++;
9915 wwpn = be64_to_cpu(wwn);
9916 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
9917 " %016llx", wwpn);
9918
9919 /* Log a message if we are on the last WWPN
9920 * or if we hit the max allowed per message.
9921 */
9922 wcnt++;
9923 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
9924 buf[len] = 0;
9925 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9926 "4686 %s\n", buf);
9927
9928 /* Check if we reached the last WWPN */
9929 if (endit)
9930 return;
9931
9932 /* Limit the number of log message displayed per FPIN */
9933 line++;
9934 if (line == LPFC_FPIN_WWPN_NUM_LINE) {
9935 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9936 "4687 %d WWPNs Truncated\n",
9937 cnt - i - 1);
9938 return;
9939 }
9940
9941 /* Start over with next log message */
9942 wcnt = 0;
9943 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
9944 "Additional WWPNs:");
9945 }
9946 }
9947 }
9948
9949 /**
9950 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
9951 * @phba: Pointer to phba object.
9952 * @tlv: Pointer to the Link Integrity Notification Descriptor.
9953 *
9954 * This function processes a Link Integrity FPIN event by logging a message.
9955 **/
9956 static void
lpfc_els_rcv_fpin_li(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)9957 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9958 {
9959 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
9960 const char *li_evt_str;
9961 u32 li_evt, cnt;
9962
9963 li_evt = be16_to_cpu(li->event_type);
9964 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
9965 cnt = be32_to_cpu(li->pname_count);
9966
9967 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
9968 "4680 FPIN Link Integrity %s (x%x) "
9969 "Detecting PN x%016llx Attached PN x%016llx "
9970 "Duration %d mSecs Count %d Port Cnt %d\n",
9971 li_evt_str, li_evt,
9972 be64_to_cpu(li->detecting_wwpn),
9973 be64_to_cpu(li->attached_wwpn),
9974 be32_to_cpu(li->event_threshold),
9975 be32_to_cpu(li->event_count), cnt);
9976
9977 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
9978 }
9979
9980 /**
9981 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
9982 * @phba: Pointer to hba object.
9983 * @tlv: Pointer to the Delivery Notification Descriptor TLV
9984 *
9985 * This function processes a Delivery FPIN event by logging a message.
9986 **/
9987 static void
lpfc_els_rcv_fpin_del(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)9988 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
9989 {
9990 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
9991 const char *del_rsn_str;
9992 u32 del_rsn;
9993 __be32 *frame;
9994
9995 del_rsn = be16_to_cpu(del->deli_reason_code);
9996 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
9997
9998 /* Skip over desc_tag/desc_len header to payload */
9999 frame = (__be32 *)(del + 1);
10000
10001 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10002 "4681 FPIN Delivery %s (x%x) "
10003 "Detecting PN x%016llx Attached PN x%016llx "
10004 "DiscHdr0 x%08x "
10005 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
10006 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
10007 del_rsn_str, del_rsn,
10008 be64_to_cpu(del->detecting_wwpn),
10009 be64_to_cpu(del->attached_wwpn),
10010 be32_to_cpu(frame[0]),
10011 be32_to_cpu(frame[1]),
10012 be32_to_cpu(frame[2]),
10013 be32_to_cpu(frame[3]),
10014 be32_to_cpu(frame[4]),
10015 be32_to_cpu(frame[5]));
10016 }
10017
10018 /**
10019 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
10020 * @phba: Pointer to hba object.
10021 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
10022 *
10023 * This function processes a Peer Congestion FPIN event by logging a message.
10024 **/
10025 static void
lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)10026 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
10027 {
10028 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
10029 const char *pc_evt_str;
10030 u32 pc_evt, cnt;
10031
10032 pc_evt = be16_to_cpu(pc->event_type);
10033 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
10034 cnt = be32_to_cpu(pc->pname_count);
10035
10036 /* Capture FPIN frequency */
10037 phba->cgn_fpin_frequency = be32_to_cpu(pc->event_period);
10038
10039 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
10040 "4684 FPIN Peer Congestion %s (x%x) "
10041 "Duration %d mSecs "
10042 "Detecting PN x%016llx Attached PN x%016llx "
10043 "Impacted Port Cnt %d\n",
10044 pc_evt_str, pc_evt,
10045 be32_to_cpu(pc->event_period),
10046 be64_to_cpu(pc->detecting_wwpn),
10047 be64_to_cpu(pc->attached_wwpn),
10048 cnt);
10049
10050 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
10051 }
10052
10053 /**
10054 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
10055 * @phba: Pointer to hba object.
10056 * @tlv: Pointer to the Congestion Notification Descriptor TLV
10057 *
10058 * This function processes an FPIN Congestion Notifiction. The notification
10059 * could be an Alarm or Warning. This routine feeds that data into driver's
10060 * running congestion algorithm. It also processes the FPIN by
10061 * logging a message. It returns 1 to indicate deliver this message
10062 * to the upper layer or 0 to indicate don't deliver it.
10063 **/
10064 static int
lpfc_els_rcv_fpin_cgn(struct lpfc_hba * phba,struct fc_tlv_desc * tlv)10065 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
10066 {
10067 struct lpfc_cgn_info *cp;
10068 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
10069 const char *cgn_evt_str;
10070 u32 cgn_evt;
10071 const char *cgn_sev_str;
10072 u32 cgn_sev;
10073 uint16_t value;
10074 u32 crc;
10075 bool nm_log = false;
10076 int rc = 1;
10077
10078 cgn_evt = be16_to_cpu(cgn->event_type);
10079 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
10080 cgn_sev = cgn->severity;
10081 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
10082
10083 /* The driver only takes action on a Credit Stall or Oversubscription
10084 * event type to engage the IO algorithm. The driver prints an
10085 * unmaskable message only for Lost Credit and Credit Stall.
10086 * TODO: Still need to have definition of host action on clear,
10087 * lost credit and device specific event types.
10088 */
10089 switch (cgn_evt) {
10090 case FPIN_CONGN_LOST_CREDIT:
10091 nm_log = true;
10092 break;
10093 case FPIN_CONGN_CREDIT_STALL:
10094 nm_log = true;
10095 fallthrough;
10096 case FPIN_CONGN_OVERSUBSCRIPTION:
10097 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
10098 nm_log = false;
10099 switch (cgn_sev) {
10100 case FPIN_CONGN_SEVERITY_ERROR:
10101 /* Take action here for an Alarm event */
10102 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
10103 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
10104 /* Track of alarm cnt for SYNC_WQE */
10105 atomic_inc(&phba->cgn_sync_alarm_cnt);
10106 }
10107 /* Track alarm cnt for cgn_info regardless
10108 * of whether CMF is configured for Signals
10109 * or FPINs.
10110 */
10111 atomic_inc(&phba->cgn_fabric_alarm_cnt);
10112 goto cleanup;
10113 }
10114 break;
10115 case FPIN_CONGN_SEVERITY_WARNING:
10116 /* Take action here for a Warning event */
10117 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
10118 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
10119 /* Track of warning cnt for SYNC_WQE */
10120 atomic_inc(&phba->cgn_sync_warn_cnt);
10121 }
10122 /* Track warning cnt and freq for cgn_info
10123 * regardless of whether CMF is configured for
10124 * Signals or FPINs.
10125 */
10126 atomic_inc(&phba->cgn_fabric_warn_cnt);
10127 cleanup:
10128 /* Save frequency in ms */
10129 phba->cgn_fpin_frequency =
10130 be32_to_cpu(cgn->event_period);
10131 value = phba->cgn_fpin_frequency;
10132 if (phba->cgn_i) {
10133 cp = (struct lpfc_cgn_info *)
10134 phba->cgn_i->virt;
10135 cp->cgn_alarm_freq =
10136 cpu_to_le16(value);
10137 cp->cgn_warn_freq =
10138 cpu_to_le16(value);
10139 crc = lpfc_cgn_calc_crc32
10140 (cp,
10141 LPFC_CGN_INFO_SZ,
10142 LPFC_CGN_CRC32_SEED);
10143 cp->cgn_info_crc = cpu_to_le32(crc);
10144 }
10145
10146 /* Don't deliver to upper layer since
10147 * driver took action on this tlv.
10148 */
10149 rc = 0;
10150 }
10151 break;
10152 }
10153 break;
10154 }
10155
10156 /* Change the log level to unmaskable for the following event types. */
10157 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
10158 LOG_CGN_MGMT | LOG_ELS,
10159 "4683 FPIN CONGESTION %s type %s (x%x) Event "
10160 "Duration %d mSecs\n",
10161 cgn_sev_str, cgn_evt_str, cgn_evt,
10162 be32_to_cpu(cgn->event_period));
10163 return rc;
10164 }
10165
10166 void
lpfc_els_rcv_fpin(struct lpfc_vport * vport,void * p,u32 fpin_length)10167 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
10168 {
10169 struct lpfc_hba *phba = vport->phba;
10170 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
10171 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
10172 const char *dtag_nm;
10173 int desc_cnt = 0, bytes_remain, cnt;
10174 u32 dtag, deliver = 0;
10175 int len;
10176
10177 /* FPINs handled only if we are in the right discovery state */
10178 if (vport->port_state < LPFC_DISC_AUTH)
10179 return;
10180
10181 /* make sure there is the full fpin header */
10182 if (fpin_length < sizeof(struct fc_els_fpin))
10183 return;
10184
10185 /* Sanity check descriptor length. The desc_len value does not
10186 * include space for the ELS command and the desc_len fields.
10187 */
10188 len = be32_to_cpu(fpin->desc_len);
10189 if (fpin_length < len + sizeof(struct fc_els_fpin)) {
10190 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10191 "4671 Bad ELS FPIN length %d: %d\n",
10192 len, fpin_length);
10193 return;
10194 }
10195
10196 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
10197 first_tlv = tlv;
10198 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
10199 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
10200
10201 /* process each descriptor separately */
10202 while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
10203 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
10204 dtag = be32_to_cpu(tlv->desc_tag);
10205 switch (dtag) {
10206 case ELS_DTAG_LNK_INTEGRITY:
10207 lpfc_els_rcv_fpin_li(phba, tlv);
10208 deliver = 1;
10209 break;
10210 case ELS_DTAG_DELIVERY:
10211 lpfc_els_rcv_fpin_del(phba, tlv);
10212 deliver = 1;
10213 break;
10214 case ELS_DTAG_PEER_CONGEST:
10215 lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
10216 deliver = 1;
10217 break;
10218 case ELS_DTAG_CONGESTION:
10219 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
10220 break;
10221 default:
10222 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10223 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10224 "4678 unknown FPIN descriptor[%d]: "
10225 "tag x%x (%s)\n",
10226 desc_cnt, dtag, dtag_nm);
10227
10228 /* If descriptor is bad, drop the rest of the data */
10229 return;
10230 }
10231 lpfc_cgn_update_stat(phba, dtag);
10232 cnt = be32_to_cpu(tlv->desc_len);
10233
10234 /* Sanity check descriptor length. The desc_len value does not
10235 * include space for the desc_tag and the desc_len fields.
10236 */
10237 len -= (cnt + sizeof(struct fc_tlv_desc));
10238 if (len < 0) {
10239 dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
10240 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
10241 "4672 Bad FPIN descriptor TLV length "
10242 "%d: %d %d %s\n",
10243 cnt, len, fpin_length, dtag_nm);
10244 return;
10245 }
10246
10247 current_tlv = tlv;
10248 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
10249 tlv = fc_tlv_next_desc(tlv);
10250
10251 /* Format payload such that the FPIN delivered to the
10252 * upper layer is a single descriptor FPIN.
10253 */
10254 if (desc_cnt)
10255 memcpy(first_tlv, current_tlv,
10256 (cnt + sizeof(struct fc_els_fpin)));
10257
10258 /* Adjust the length so that it only reflects a
10259 * single descriptor FPIN.
10260 */
10261 fpin_length = cnt + sizeof(struct fc_els_fpin);
10262 fpin->desc_len = cpu_to_be32(fpin_length);
10263 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
10264
10265 /* Send every descriptor individually to the upper layer */
10266 if (deliver)
10267 fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
10268 fpin_length, (char *)fpin, 0);
10269 desc_cnt++;
10270 }
10271 }
10272
10273 /**
10274 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
10275 * @phba: pointer to lpfc hba data structure.
10276 * @pring: pointer to a SLI ring.
10277 * @vport: pointer to a host virtual N_Port data structure.
10278 * @elsiocb: pointer to lpfc els command iocb data structure.
10279 *
10280 * This routine is used for processing the IOCB associated with a unsolicited
10281 * event. It first determines whether there is an existing ndlp that matches
10282 * the DID from the unsolicited IOCB. If not, it will create a new one with
10283 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
10284 * IOCB is then used to invoke the proper routine and to set up proper state
10285 * of the discovery state machine.
10286 **/
10287 static void
lpfc_els_unsol_buffer(struct lpfc_hba * phba,struct lpfc_sli_ring * pring,struct lpfc_vport * vport,struct lpfc_iocbq * elsiocb)10288 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10289 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
10290 {
10291 struct lpfc_nodelist *ndlp;
10292 struct ls_rjt stat;
10293 u32 *payload, payload_len;
10294 u32 cmd = 0, did = 0, newnode, status = 0;
10295 uint8_t rjt_exp, rjt_err = 0, init_link = 0;
10296 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10297 LPFC_MBOXQ_t *mbox;
10298
10299 if (!vport || !elsiocb->cmd_dmabuf)
10300 goto dropit;
10301
10302 newnode = 0;
10303 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10304 payload = elsiocb->cmd_dmabuf->virt;
10305 if (phba->sli_rev == LPFC_SLI_REV4)
10306 payload_len = wcqe_cmpl->total_data_placed;
10307 else
10308 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
10309 status = get_job_ulpstatus(phba, elsiocb);
10310 cmd = *payload;
10311 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
10312 lpfc_sli3_post_buffer(phba, pring, 1);
10313
10314 did = get_job_els_rsp64_did(phba, elsiocb);
10315 if (status) {
10316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10317 "RCV Unsol ELS: status:x%x/x%x did:x%x",
10318 status, get_job_word4(phba, elsiocb), did);
10319 goto dropit;
10320 }
10321
10322 /* Check to see if link went down during discovery */
10323 if (lpfc_els_chk_latt(vport))
10324 goto dropit;
10325
10326 /* Ignore traffic received during vport shutdown. */
10327 if (test_bit(FC_UNLOADING, &vport->load_flag))
10328 goto dropit;
10329
10330 /* If NPort discovery is delayed drop incoming ELS */
10331 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag) &&
10332 cmd != ELS_CMD_PLOGI)
10333 goto dropit;
10334
10335 ndlp = lpfc_findnode_did(vport, did);
10336 if (!ndlp) {
10337 /* Cannot find existing Fabric ndlp, so allocate a new one */
10338 ndlp = lpfc_nlp_init(vport, did);
10339 if (!ndlp)
10340 goto dropit;
10341 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10342 newnode = 1;
10343 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
10344 ndlp->nlp_type |= NLP_FABRIC;
10345 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
10346 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
10347 newnode = 1;
10348 }
10349
10350 phba->fc_stat.elsRcvFrame++;
10351
10352 /*
10353 * Do not process any unsolicited ELS commands
10354 * if the ndlp is in DEV_LOSS
10355 */
10356 if (test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) {
10357 if (newnode)
10358 lpfc_nlp_put(ndlp);
10359 goto dropit;
10360 }
10361
10362 elsiocb->ndlp = lpfc_nlp_get(ndlp);
10363 if (!elsiocb->ndlp)
10364 goto dropit;
10365 elsiocb->vport = vport;
10366
10367 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
10368 cmd &= ELS_CMD_MASK;
10369 }
10370 /* ELS command <elsCmd> received from NPORT <did> */
10371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10372 "0112 ELS command x%x received from NPORT x%x "
10373 "refcnt %d Data: x%x x%lx x%x x%x\n",
10374 cmd, did, kref_read(&ndlp->kref), vport->port_state,
10375 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
10376
10377 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
10378 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
10379 (cmd != ELS_CMD_FLOGI) &&
10380 !((cmd == ELS_CMD_PLOGI) && test_bit(FC_PT2PT, &vport->fc_flag))) {
10381 rjt_err = LSRJT_LOGICAL_BSY;
10382 rjt_exp = LSEXP_NOTHING_MORE;
10383 goto lsrjt;
10384 }
10385
10386 switch (cmd) {
10387 case ELS_CMD_PLOGI:
10388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10389 "RCV PLOGI: did:x%x/ste:x%x flg:x%lx",
10390 did, vport->port_state, ndlp->nlp_flag);
10391
10392 phba->fc_stat.elsRcvPLOGI++;
10393 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
10394 if (phba->sli_rev == LPFC_SLI_REV4 &&
10395 test_bit(FC_PT2PT, &phba->pport->fc_flag)) {
10396 vport->fc_prevDID = vport->fc_myDID;
10397 /* Our DID needs to be updated before registering
10398 * the vfi. This is done in lpfc_rcv_plogi but
10399 * that is called after the reg_vfi.
10400 */
10401 vport->fc_myDID =
10402 bf_get(els_rsp64_sid,
10403 &elsiocb->wqe.xmit_els_rsp);
10404 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
10405 "3312 Remote port assigned DID x%x "
10406 "%x\n", vport->fc_myDID,
10407 vport->fc_prevDID);
10408 }
10409
10410 lpfc_send_els_event(vport, ndlp, payload);
10411
10412 /* If Nport discovery is delayed, reject PLOGIs */
10413 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) {
10414 rjt_err = LSRJT_UNABLE_TPC;
10415 rjt_exp = LSEXP_NOTHING_MORE;
10416 break;
10417 }
10418
10419 if (vport->port_state < LPFC_DISC_AUTH) {
10420 if (!test_bit(FC_PT2PT, &phba->pport->fc_flag) ||
10421 test_bit(FC_PT2PT_PLOGI, &phba->pport->fc_flag)) {
10422 rjt_err = LSRJT_UNABLE_TPC;
10423 rjt_exp = LSEXP_NOTHING_MORE;
10424 break;
10425 }
10426 }
10427
10428 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10429 NLP_EVT_RCV_PLOGI);
10430
10431 break;
10432 case ELS_CMD_FLOGI:
10433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10434 "RCV FLOGI: did:x%x/ste:x%x flg:x%lx",
10435 did, vport->port_state, ndlp->nlp_flag);
10436
10437 phba->fc_stat.elsRcvFLOGI++;
10438
10439 /* If the driver believes fabric discovery is done and is ready,
10440 * bounce the link. There is some descrepancy.
10441 */
10442 if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
10443 test_bit(FC_PT2PT, &vport->fc_flag) &&
10444 vport->rcv_flogi_cnt >= 1) {
10445 rjt_err = LSRJT_LOGICAL_BSY;
10446 rjt_exp = LSEXP_NOTHING_MORE;
10447 init_link++;
10448 goto lsrjt;
10449 }
10450
10451 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
10452 /* retain node if our response is deferred */
10453 if (phba->defer_flogi_acc.flag)
10454 break;
10455 if (newnode)
10456 lpfc_disc_state_machine(vport, ndlp, NULL,
10457 NLP_EVT_DEVICE_RM);
10458 break;
10459 case ELS_CMD_LOGO:
10460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10461 "RCV LOGO: did:x%x/ste:x%x flg:x%lx",
10462 did, vport->port_state, ndlp->nlp_flag);
10463
10464 phba->fc_stat.elsRcvLOGO++;
10465 lpfc_send_els_event(vport, ndlp, payload);
10466 if (vport->port_state < LPFC_DISC_AUTH) {
10467 rjt_err = LSRJT_UNABLE_TPC;
10468 rjt_exp = LSEXP_NOTHING_MORE;
10469 break;
10470 }
10471 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
10472 if (newnode)
10473 lpfc_disc_state_machine(vport, ndlp, NULL,
10474 NLP_EVT_DEVICE_RM);
10475 break;
10476 case ELS_CMD_PRLO:
10477 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10478 "RCV PRLO: did:x%x/ste:x%x flg:x%lx",
10479 did, vport->port_state, ndlp->nlp_flag);
10480
10481 phba->fc_stat.elsRcvPRLO++;
10482 lpfc_send_els_event(vport, ndlp, payload);
10483 if (vport->port_state < LPFC_DISC_AUTH) {
10484 rjt_err = LSRJT_UNABLE_TPC;
10485 rjt_exp = LSEXP_NOTHING_MORE;
10486 break;
10487 }
10488 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
10489 break;
10490 case ELS_CMD_LCB:
10491 phba->fc_stat.elsRcvLCB++;
10492 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
10493 break;
10494 case ELS_CMD_RDP:
10495 phba->fc_stat.elsRcvRDP++;
10496 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
10497 break;
10498 case ELS_CMD_RSCN:
10499 phba->fc_stat.elsRcvRSCN++;
10500 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
10501 if (newnode)
10502 lpfc_disc_state_machine(vport, ndlp, NULL,
10503 NLP_EVT_DEVICE_RM);
10504 break;
10505 case ELS_CMD_ADISC:
10506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10507 "RCV ADISC: did:x%x/ste:x%x flg:x%lx",
10508 did, vport->port_state, ndlp->nlp_flag);
10509
10510 lpfc_send_els_event(vport, ndlp, payload);
10511 phba->fc_stat.elsRcvADISC++;
10512 if (vport->port_state < LPFC_DISC_AUTH) {
10513 rjt_err = LSRJT_UNABLE_TPC;
10514 rjt_exp = LSEXP_NOTHING_MORE;
10515 break;
10516 }
10517 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10518 NLP_EVT_RCV_ADISC);
10519 break;
10520 case ELS_CMD_PDISC:
10521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10522 "RCV PDISC: did:x%x/ste:x%x flg:x%lx",
10523 did, vport->port_state, ndlp->nlp_flag);
10524
10525 phba->fc_stat.elsRcvPDISC++;
10526 if (vport->port_state < LPFC_DISC_AUTH) {
10527 rjt_err = LSRJT_UNABLE_TPC;
10528 rjt_exp = LSEXP_NOTHING_MORE;
10529 break;
10530 }
10531 lpfc_disc_state_machine(vport, ndlp, elsiocb,
10532 NLP_EVT_RCV_PDISC);
10533 break;
10534 case ELS_CMD_FARPR:
10535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10536 "RCV FARPR: did:x%x/ste:x%x flg:x%lx",
10537 did, vport->port_state, ndlp->nlp_flag);
10538
10539 phba->fc_stat.elsRcvFARPR++;
10540 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
10541 break;
10542 case ELS_CMD_FARP:
10543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10544 "RCV FARP: did:x%x/ste:x%x flg:x%lx",
10545 did, vport->port_state, ndlp->nlp_flag);
10546
10547 phba->fc_stat.elsRcvFARP++;
10548 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
10549 break;
10550 case ELS_CMD_FAN:
10551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10552 "RCV FAN: did:x%x/ste:x%x flg:x%lx",
10553 did, vport->port_state, ndlp->nlp_flag);
10554
10555 phba->fc_stat.elsRcvFAN++;
10556 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
10557 break;
10558 case ELS_CMD_PRLI:
10559 case ELS_CMD_NVMEPRLI:
10560 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10561 "RCV PRLI: did:x%x/ste:x%x flg:x%lx",
10562 did, vport->port_state, ndlp->nlp_flag);
10563
10564 phba->fc_stat.elsRcvPRLI++;
10565 if ((vport->port_state < LPFC_DISC_AUTH) &&
10566 test_bit(FC_FABRIC, &vport->fc_flag)) {
10567 rjt_err = LSRJT_UNABLE_TPC;
10568 rjt_exp = LSEXP_NOTHING_MORE;
10569 break;
10570 }
10571 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
10572 break;
10573 case ELS_CMD_LIRR:
10574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10575 "RCV LIRR: did:x%x/ste:x%x flg:x%lx",
10576 did, vport->port_state, ndlp->nlp_flag);
10577
10578 phba->fc_stat.elsRcvLIRR++;
10579 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
10580 if (newnode)
10581 lpfc_disc_state_machine(vport, ndlp, NULL,
10582 NLP_EVT_DEVICE_RM);
10583 break;
10584 case ELS_CMD_RLS:
10585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10586 "RCV RLS: did:x%x/ste:x%x flg:x%lx",
10587 did, vport->port_state, ndlp->nlp_flag);
10588
10589 phba->fc_stat.elsRcvRLS++;
10590 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
10591 if (newnode)
10592 lpfc_disc_state_machine(vport, ndlp, NULL,
10593 NLP_EVT_DEVICE_RM);
10594 break;
10595 case ELS_CMD_RPL:
10596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10597 "RCV RPL: did:x%x/ste:x%x flg:x%lx",
10598 did, vport->port_state, ndlp->nlp_flag);
10599
10600 phba->fc_stat.elsRcvRPL++;
10601 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
10602 if (newnode)
10603 lpfc_disc_state_machine(vport, ndlp, NULL,
10604 NLP_EVT_DEVICE_RM);
10605 break;
10606 case ELS_CMD_RNID:
10607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10608 "RCV RNID: did:x%x/ste:x%x flg:x%lx",
10609 did, vport->port_state, ndlp->nlp_flag);
10610
10611 phba->fc_stat.elsRcvRNID++;
10612 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
10613 if (newnode)
10614 lpfc_disc_state_machine(vport, ndlp, NULL,
10615 NLP_EVT_DEVICE_RM);
10616 break;
10617 case ELS_CMD_RTV:
10618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10619 "RCV RTV: did:x%x/ste:x%x flg:x%lx",
10620 did, vport->port_state, ndlp->nlp_flag);
10621 phba->fc_stat.elsRcvRTV++;
10622 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
10623 if (newnode)
10624 lpfc_disc_state_machine(vport, ndlp, NULL,
10625 NLP_EVT_DEVICE_RM);
10626 break;
10627 case ELS_CMD_RRQ:
10628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10629 "RCV RRQ: did:x%x/ste:x%x flg:x%lx",
10630 did, vport->port_state, ndlp->nlp_flag);
10631
10632 phba->fc_stat.elsRcvRRQ++;
10633 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
10634 if (newnode)
10635 lpfc_disc_state_machine(vport, ndlp, NULL,
10636 NLP_EVT_DEVICE_RM);
10637 break;
10638 case ELS_CMD_ECHO:
10639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10640 "RCV ECHO: did:x%x/ste:x%x flg:x%lx",
10641 did, vport->port_state, ndlp->nlp_flag);
10642
10643 phba->fc_stat.elsRcvECHO++;
10644 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
10645 if (newnode)
10646 lpfc_disc_state_machine(vport, ndlp, NULL,
10647 NLP_EVT_DEVICE_RM);
10648 break;
10649 case ELS_CMD_REC:
10650 /* receive this due to exchange closed */
10651 rjt_err = LSRJT_UNABLE_TPC;
10652 rjt_exp = LSEXP_INVALID_OX_RX;
10653 break;
10654 case ELS_CMD_FPIN:
10655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10656 "RCV FPIN: did:x%x/ste:x%x "
10657 "flg:x%lx",
10658 did, vport->port_state, ndlp->nlp_flag);
10659
10660 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
10661 payload_len);
10662
10663 /* There are no replies, so no rjt codes */
10664 break;
10665 case ELS_CMD_EDC:
10666 lpfc_els_rcv_edc(vport, elsiocb, ndlp);
10667 break;
10668 case ELS_CMD_RDF:
10669 phba->fc_stat.elsRcvRDF++;
10670 /* Accept RDF only from fabric controller */
10671 if (did != Fabric_Cntl_DID) {
10672 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
10673 "1115 Received RDF from invalid DID "
10674 "x%x\n", did);
10675 rjt_err = LSRJT_PROTOCOL_ERR;
10676 rjt_exp = LSEXP_NOTHING_MORE;
10677 goto lsrjt;
10678 }
10679
10680 lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
10681 break;
10682 default:
10683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
10684 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10685 cmd, did, vport->port_state);
10686
10687 /* Unsupported ELS command, reject */
10688 rjt_err = LSRJT_CMD_UNSUPPORTED;
10689 rjt_exp = LSEXP_NOTHING_MORE;
10690
10691 /* Unknown ELS command <elsCmd> received from NPORT <did> */
10692 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
10693 "0115 Unknown ELS command x%x "
10694 "received from NPORT x%x\n", cmd, did);
10695 if (newnode)
10696 lpfc_disc_state_machine(vport, ndlp, NULL,
10697 NLP_EVT_DEVICE_RM);
10698 break;
10699 }
10700
10701 lsrjt:
10702 /* check if need to LS_RJT received ELS cmd */
10703 if (rjt_err) {
10704 memset(&stat, 0, sizeof(stat));
10705 stat.un.b.lsRjtRsnCode = rjt_err;
10706 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
10707 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
10708 NULL);
10709 /* Remove the reference from above for new nodes. */
10710 if (newnode)
10711 lpfc_disc_state_machine(vport, ndlp, NULL,
10712 NLP_EVT_DEVICE_RM);
10713 }
10714
10715 /* Release the reference on this elsiocb, not the ndlp. */
10716 lpfc_nlp_put(elsiocb->ndlp);
10717 elsiocb->ndlp = NULL;
10718
10719 /* Special case. Driver received an unsolicited command that
10720 * unsupportable given the driver's current state. Reset the
10721 * link and start over.
10722 */
10723 if (init_link) {
10724 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10725 if (!mbox)
10726 return;
10727 lpfc_linkdown(phba);
10728 lpfc_init_link(phba, mbox,
10729 phba->cfg_topology,
10730 phba->cfg_link_speed);
10731 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
10732 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
10733 mbox->vport = vport;
10734 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
10735 MBX_NOT_FINISHED)
10736 mempool_free(mbox, phba->mbox_mem_pool);
10737 }
10738
10739 return;
10740
10741 dropit:
10742 if (vport && !test_bit(FC_UNLOADING, &vport->load_flag))
10743 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10744 "0111 Dropping received ELS cmd "
10745 "Data: x%x x%x x%x x%x\n",
10746 cmd, status, get_job_word4(phba, elsiocb), did);
10747
10748 phba->fc_stat.elsRcvDrop++;
10749 }
10750
10751 /**
10752 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
10753 * @phba: pointer to lpfc hba data structure.
10754 * @pring: pointer to a SLI ring.
10755 * @elsiocb: pointer to lpfc els iocb data structure.
10756 *
10757 * This routine is used to process an unsolicited event received from a SLI
10758 * (Service Level Interface) ring. The actual processing of the data buffer
10759 * associated with the unsolicited event is done by invoking the routine
10760 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10761 * SLI ring on which the unsolicited event was received.
10762 **/
10763 void
lpfc_els_unsol_event(struct lpfc_hba * phba,struct lpfc_sli_ring * pring,struct lpfc_iocbq * elsiocb)10764 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10765 struct lpfc_iocbq *elsiocb)
10766 {
10767 struct lpfc_vport *vport = elsiocb->vport;
10768 u32 ulp_command, status, parameter, bde_count = 0;
10769 IOCB_t *icmd;
10770 struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
10771 struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf;
10772 struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf;
10773 dma_addr_t paddr;
10774
10775 elsiocb->cmd_dmabuf = NULL;
10776 elsiocb->rsp_dmabuf = NULL;
10777 elsiocb->bpl_dmabuf = NULL;
10778
10779 wcqe_cmpl = &elsiocb->wcqe_cmpl;
10780 ulp_command = get_job_cmnd(phba, elsiocb);
10781 status = get_job_ulpstatus(phba, elsiocb);
10782 parameter = get_job_word4(phba, elsiocb);
10783 if (phba->sli_rev == LPFC_SLI_REV4)
10784 bde_count = wcqe_cmpl->word3;
10785 else
10786 bde_count = elsiocb->iocb.ulpBdeCount;
10787
10788 if (status == IOSTAT_NEED_BUFFER) {
10789 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
10790 } else if (status == IOSTAT_LOCAL_REJECT &&
10791 (parameter & IOERR_PARAM_MASK) ==
10792 IOERR_RCV_BUFFER_WAITING) {
10793 phba->fc_stat.NoRcvBuf++;
10794 /* Not enough posted buffers; Try posting more buffers */
10795 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
10796 lpfc_sli3_post_buffer(phba, pring, 0);
10797 return;
10798 }
10799
10800 if (phba->sli_rev == LPFC_SLI_REV3) {
10801 icmd = &elsiocb->iocb;
10802 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
10803 (ulp_command == CMD_IOCB_RCV_ELS64_CX ||
10804 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) {
10805 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
10806 vport = phba->pport;
10807 else
10808 vport = lpfc_find_vport_by_vpid(phba,
10809 icmd->unsli3.rcvsli3.vpi);
10810 }
10811 }
10812
10813 /* If there are no BDEs associated
10814 * with this IOCB, there is nothing to do.
10815 */
10816 if (bde_count == 0)
10817 return;
10818
10819 /* Account for SLI2 or SLI3 and later unsolicited buffering */
10820 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
10821 elsiocb->cmd_dmabuf = bdeBuf1;
10822 if (bde_count == 2)
10823 elsiocb->bpl_dmabuf = bdeBuf2;
10824 } else {
10825 icmd = &elsiocb->iocb;
10826 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
10827 icmd->un.cont64[0].addrLow);
10828 elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
10829 paddr);
10830 if (bde_count == 2) {
10831 paddr = getPaddr(icmd->un.cont64[1].addrHigh,
10832 icmd->un.cont64[1].addrLow);
10833 elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
10834 pring,
10835 paddr);
10836 }
10837 }
10838
10839 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
10840 /*
10841 * The different unsolicited event handlers would tell us
10842 * if they are done with "mp" by setting cmd_dmabuf to NULL.
10843 */
10844 if (elsiocb->cmd_dmabuf) {
10845 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf);
10846 elsiocb->cmd_dmabuf = NULL;
10847 }
10848
10849 if (elsiocb->bpl_dmabuf) {
10850 lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf);
10851 elsiocb->bpl_dmabuf = NULL;
10852 }
10853
10854 }
10855
10856 static void
lpfc_start_fdmi(struct lpfc_vport * vport)10857 lpfc_start_fdmi(struct lpfc_vport *vport)
10858 {
10859 struct lpfc_nodelist *ndlp;
10860
10861 /* If this is the first time, allocate an ndlp and initialize
10862 * it. Otherwise, make sure the node is enabled and then do the
10863 * login.
10864 */
10865 ndlp = lpfc_findnode_did(vport, FDMI_DID);
10866 if (!ndlp) {
10867 ndlp = lpfc_nlp_init(vport, FDMI_DID);
10868 if (ndlp) {
10869 ndlp->nlp_type |= NLP_FABRIC;
10870 } else {
10871 return;
10872 }
10873 }
10874
10875 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10876 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
10877 }
10878
10879 /**
10880 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
10881 * @phba: pointer to lpfc hba data structure.
10882 * @vport: pointer to a virtual N_Port data structure.
10883 *
10884 * This routine issues a Port Login (PLOGI) to the Name Server with
10885 * State Change Request (SCR) for a @vport. This routine will create an
10886 * ndlp for the Name Server associated to the @vport if such node does
10887 * not already exist. The PLOGI to Name Server is issued by invoking the
10888 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10889 * (FDMI) is configured to the @vport, a FDMI node will be created and
10890 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10891 **/
10892 void
lpfc_do_scr_ns_plogi(struct lpfc_hba * phba,struct lpfc_vport * vport)10893 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
10894 {
10895 struct lpfc_nodelist *ndlp;
10896
10897 /*
10898 * If lpfc_delay_discovery parameter is set and the clean address
10899 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10900 * discovery.
10901 */
10902 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) {
10903 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10904 "3334 Delay fc port discovery for %d secs\n",
10905 phba->fc_ratov);
10906 mod_timer(&vport->delayed_disc_tmo,
10907 jiffies + secs_to_jiffies(phba->fc_ratov));
10908 return;
10909 }
10910
10911 ndlp = lpfc_findnode_did(vport, NameServer_DID);
10912 if (!ndlp) {
10913 ndlp = lpfc_nlp_init(vport, NameServer_DID);
10914 if (!ndlp) {
10915 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10916 lpfc_disc_start(vport);
10917 return;
10918 }
10919 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10920 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10921 "0251 NameServer login: no memory\n");
10922 return;
10923 }
10924 }
10925
10926 ndlp->nlp_type |= NLP_FABRIC;
10927
10928 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
10929
10930 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
10931 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10932 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10933 "0252 Cannot issue NameServer login\n");
10934 return;
10935 }
10936
10937 if ((phba->cfg_enable_SmartSAN ||
10938 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) &&
10939 test_bit(FC_ALLOW_FDMI, &vport->load_flag))
10940 lpfc_start_fdmi(vport);
10941 }
10942
10943 /**
10944 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
10945 * @phba: pointer to lpfc hba data structure.
10946 * @pmb: pointer to the driver internal queue element for mailbox command.
10947 *
10948 * This routine is the completion callback function to register new vport
10949 * mailbox command. If the new vport mailbox command completes successfully,
10950 * the fabric registration login shall be performed on physical port (the
10951 * new vport created is actually a physical port, with VPI 0) or the port
10952 * login to Name Server for State Change Request (SCR) will be performed
10953 * on virtual port (real virtual port, with VPI greater than 0).
10954 **/
10955 static void
lpfc_cmpl_reg_new_vport(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)10956 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
10957 {
10958 struct lpfc_vport *vport = pmb->vport;
10959 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10960 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
10961 MAILBOX_t *mb = &pmb->u.mb;
10962 int rc;
10963
10964 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
10965
10966 if (mb->mbxStatus) {
10967 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
10968 "0915 Register VPI failed : Status: x%x"
10969 " upd bit: x%x \n", mb->mbxStatus,
10970 mb->un.varRegVpi.upd);
10971 if (phba->sli_rev == LPFC_SLI_REV4 &&
10972 mb->un.varRegVpi.upd)
10973 goto mbox_err_exit ;
10974
10975 switch (mb->mbxStatus) {
10976 case 0x11: /* unsupported feature */
10977 case 0x9603: /* max_vpi exceeded */
10978 case 0x9602: /* Link event since CLEAR_LA */
10979 /* giving up on vport registration */
10980 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
10981 clear_bit(FC_FABRIC, &vport->fc_flag);
10982 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
10983 lpfc_can_disctmo(vport);
10984 break;
10985 /* If reg_vpi fail with invalid VPI status, re-init VPI */
10986 case 0x20:
10987 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
10988 lpfc_init_vpi(phba, pmb, vport->vpi);
10989 pmb->vport = vport;
10990 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
10991 rc = lpfc_sli_issue_mbox(phba, pmb,
10992 MBX_NOWAIT);
10993 if (rc == MBX_NOT_FINISHED) {
10994 lpfc_printf_vlog(vport, KERN_ERR,
10995 LOG_TRACE_EVENT,
10996 "2732 Failed to issue INIT_VPI"
10997 " mailbox command\n");
10998 } else {
10999 lpfc_nlp_put(ndlp);
11000 return;
11001 }
11002 fallthrough;
11003 default:
11004 /* Try to recover from this error */
11005 if (phba->sli_rev == LPFC_SLI_REV4)
11006 lpfc_sli4_unreg_all_rpis(vport);
11007 lpfc_mbx_unreg_vpi(vport);
11008 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11009 if (mb->mbxStatus == MBX_NOT_FINISHED)
11010 break;
11011 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
11012 !test_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag)) {
11013 if (phba->sli_rev == LPFC_SLI_REV4)
11014 lpfc_issue_init_vfi(vport);
11015 else
11016 lpfc_initial_flogi(vport);
11017 } else {
11018 lpfc_initial_fdisc(vport);
11019 }
11020 break;
11021 }
11022 } else {
11023 spin_lock_irq(shost->host_lock);
11024 vport->vpi_state |= LPFC_VPI_REGISTERED;
11025 spin_unlock_irq(shost->host_lock);
11026 if (vport == phba->pport) {
11027 if (phba->sli_rev < LPFC_SLI_REV4)
11028 lpfc_issue_fabric_reglogin(vport);
11029 else {
11030 /*
11031 * If the physical port is instantiated using
11032 * FDISC, do not start vport discovery.
11033 */
11034 if (vport->port_state != LPFC_FDISC)
11035 lpfc_start_fdiscs(phba);
11036 lpfc_do_scr_ns_plogi(phba, vport);
11037 }
11038 } else {
11039 lpfc_do_scr_ns_plogi(phba, vport);
11040 }
11041 }
11042 mbox_err_exit:
11043 /* Now, we decrement the ndlp reference count held for this
11044 * callback function
11045 */
11046 lpfc_nlp_put(ndlp);
11047
11048 mempool_free(pmb, phba->mbox_mem_pool);
11049
11050 /* reinitialize the VMID datastructure before returning.
11051 * this is specifically for vport
11052 */
11053 if (lpfc_is_vmid_enabled(phba))
11054 lpfc_reinit_vmid(vport);
11055 vport->vmid_flag = vport->phba->pport->vmid_flag;
11056
11057 return;
11058 }
11059
11060 /**
11061 * lpfc_register_new_vport - Register a new vport with a HBA
11062 * @phba: pointer to lpfc hba data structure.
11063 * @vport: pointer to a host virtual N_Port data structure.
11064 * @ndlp: pointer to a node-list data structure.
11065 *
11066 * This routine registers the @vport as a new virtual port with a HBA.
11067 * It is done through a registering vpi mailbox command.
11068 **/
11069 void
lpfc_register_new_vport(struct lpfc_hba * phba,struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)11070 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
11071 struct lpfc_nodelist *ndlp)
11072 {
11073 LPFC_MBOXQ_t *mbox;
11074
11075 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
11076 if (mbox) {
11077 lpfc_reg_vpi(vport, mbox);
11078 mbox->vport = vport;
11079 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
11080 if (!mbox->ctx_ndlp) {
11081 mempool_free(mbox, phba->mbox_mem_pool);
11082 goto mbox_err_exit;
11083 }
11084
11085 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
11086 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
11087 == MBX_NOT_FINISHED) {
11088 /* mailbox command not success, decrement ndlp
11089 * reference count for this command
11090 */
11091 lpfc_nlp_put(ndlp);
11092 mempool_free(mbox, phba->mbox_mem_pool);
11093
11094 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11095 "0253 Register VPI: Can't send mbox\n");
11096 goto mbox_err_exit;
11097 }
11098 } else {
11099 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11100 "0254 Register VPI: no memory\n");
11101 goto mbox_err_exit;
11102 }
11103 return;
11104
11105 mbox_err_exit:
11106 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11107 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11108 return;
11109 }
11110
11111 /**
11112 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
11113 * @phba: pointer to lpfc hba data structure.
11114 *
11115 * This routine cancels the retry delay timers to all the vports.
11116 **/
11117 void
lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba * phba)11118 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
11119 {
11120 struct lpfc_vport **vports;
11121 struct lpfc_nodelist *ndlp;
11122 uint32_t link_state;
11123 int i;
11124
11125 /* Treat this failure as linkdown for all vports */
11126 link_state = phba->link_state;
11127 lpfc_linkdown(phba);
11128 phba->link_state = link_state;
11129
11130 vports = lpfc_create_vport_work_array(phba);
11131
11132 if (vports) {
11133 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11134 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
11135 if (ndlp)
11136 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
11137 lpfc_els_flush_cmd(vports[i]);
11138 }
11139 lpfc_destroy_vport_work_array(phba, vports);
11140 }
11141 }
11142
11143 /**
11144 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
11145 * @phba: pointer to lpfc hba data structure.
11146 *
11147 * This routine abort all pending discovery commands and
11148 * start a timer to retry FLOGI for the physical port
11149 * discovery.
11150 **/
11151 void
lpfc_retry_pport_discovery(struct lpfc_hba * phba)11152 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
11153 {
11154 struct lpfc_nodelist *ndlp;
11155
11156 /* Cancel the all vports retry delay retry timers */
11157 lpfc_cancel_all_vport_retry_delay_timer(phba);
11158
11159 /* If fabric require FLOGI, then re-instantiate physical login */
11160 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
11161 if (!ndlp)
11162 return;
11163
11164 mod_timer(&ndlp->nlp_delayfunc, jiffies + secs_to_jiffies(1));
11165 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag);
11166 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
11167 phba->pport->port_state = LPFC_FLOGI;
11168 return;
11169 }
11170
11171 /**
11172 * lpfc_fabric_login_reqd - Check if FLOGI required.
11173 * @phba: pointer to lpfc hba data structure.
11174 * @cmdiocb: pointer to FDISC command iocb.
11175 * @rspiocb: pointer to FDISC response iocb.
11176 *
11177 * This routine checks if a FLOGI is reguired for FDISC
11178 * to succeed.
11179 **/
11180 static int
lpfc_fabric_login_reqd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)11181 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
11182 struct lpfc_iocbq *cmdiocb,
11183 struct lpfc_iocbq *rspiocb)
11184 {
11185 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11186 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11187
11188 if (ulp_status != IOSTAT_FABRIC_RJT ||
11189 ulp_word4 != RJT_LOGIN_REQUIRED)
11190 return 0;
11191 else
11192 return 1;
11193 }
11194
11195 /**
11196 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
11197 * @phba: pointer to lpfc hba data structure.
11198 * @cmdiocb: pointer to lpfc command iocb data structure.
11199 * @rspiocb: pointer to lpfc response iocb data structure.
11200 *
11201 * This routine is the completion callback function to a Fabric Discover
11202 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
11203 * single threaded, each FDISC completion callback function will reset
11204 * the discovery timer for all vports such that the timers will not get
11205 * unnecessary timeout. The function checks the FDISC IOCB status. If error
11206 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
11207 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
11208 * assigned to the vport has been changed with the completion of the FDISC
11209 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
11210 * are unregistered from the HBA, and then the lpfc_register_new_vport()
11211 * routine is invoked to register new vport with the HBA. Otherwise, the
11212 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
11213 * Server for State Change Request (SCR).
11214 **/
11215 static void
lpfc_cmpl_els_fdisc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)11216 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11217 struct lpfc_iocbq *rspiocb)
11218 {
11219 struct lpfc_vport *vport = cmdiocb->vport;
11220 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
11221 struct lpfc_nodelist *np;
11222 struct lpfc_nodelist *next_np;
11223 struct lpfc_iocbq *piocb;
11224 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
11225 struct serv_parm *sp;
11226 uint8_t fabric_param_changed;
11227 u32 ulp_status, ulp_word4;
11228
11229 ulp_status = get_job_ulpstatus(phba, rspiocb);
11230 ulp_word4 = get_job_word4(phba, rspiocb);
11231
11232 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11233 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
11234 ulp_status, ulp_word4,
11235 vport->fc_prevDID);
11236 /* Since all FDISCs are being single threaded, we
11237 * must reset the discovery timer for ALL vports
11238 * waiting to send FDISC when one completes.
11239 */
11240 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
11241 lpfc_set_disctmo(piocb->vport);
11242 }
11243
11244 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11245 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
11246 ulp_status, ulp_word4, vport->fc_prevDID);
11247
11248 if (ulp_status) {
11249
11250 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
11251 lpfc_retry_pport_discovery(phba);
11252 goto out;
11253 }
11254
11255 /* Check for retry */
11256 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
11257 goto out;
11258 /* Warn FDISC status */
11259 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
11260 "0126 FDISC cmpl status: x%x/x%x)\n",
11261 ulp_status, ulp_word4);
11262 goto fdisc_failed;
11263 }
11264
11265 lpfc_check_nlp_post_devloss(vport, ndlp);
11266
11267 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag);
11268 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag);
11269 set_bit(FC_FABRIC, &vport->fc_flag);
11270 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
11271 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag);
11272
11273 vport->fc_myDID = ulp_word4 & Mask_DID;
11274 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
11275 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
11276 if (!prsp)
11277 goto out;
11278 if (!lpfc_is_els_acc_rsp(prsp))
11279 goto out;
11280
11281 sp = prsp->virt + sizeof(uint32_t);
11282 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
11283 memcpy(&vport->fabric_portname, &sp->portName,
11284 sizeof(struct lpfc_name));
11285 memcpy(&vport->fabric_nodename, &sp->nodeName,
11286 sizeof(struct lpfc_name));
11287 if (fabric_param_changed &&
11288 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
11289 /* If our NportID changed, we need to ensure all
11290 * remaining NPORTs get unreg_login'ed so we can
11291 * issue unreg_vpi.
11292 */
11293 list_for_each_entry_safe(np, next_np,
11294 &vport->fc_nodes, nlp_listp) {
11295 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
11296 !test_bit(NLP_NPR_ADISC, &np->nlp_flag))
11297 continue;
11298 clear_bit(NLP_NPR_ADISC, &np->nlp_flag);
11299 lpfc_unreg_rpi(vport, np);
11300 }
11301 lpfc_cleanup_pending_mbox(vport);
11302
11303 if (phba->sli_rev == LPFC_SLI_REV4)
11304 lpfc_sli4_unreg_all_rpis(vport);
11305
11306 lpfc_mbx_unreg_vpi(vport);
11307 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
11308 if (phba->sli_rev == LPFC_SLI_REV4)
11309 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
11310 else
11311 set_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag);
11312 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
11313 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) {
11314 /*
11315 * Driver needs to re-reg VPI in order for f/w
11316 * to update the MAC address.
11317 */
11318 lpfc_register_new_vport(phba, vport, ndlp);
11319 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11320 goto out;
11321 }
11322
11323 if (test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag))
11324 lpfc_issue_init_vpi(vport);
11325 else if (test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag))
11326 lpfc_register_new_vport(phba, vport, ndlp);
11327 else
11328 lpfc_do_scr_ns_plogi(phba, vport);
11329
11330 /* The FDISC completed successfully. Move the fabric ndlp to
11331 * UNMAPPED state and register with the transport.
11332 */
11333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
11334 goto out;
11335
11336 fdisc_failed:
11337 if (vport->fc_vport &&
11338 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
11339 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11340 /* Cancel discovery timer */
11341 lpfc_can_disctmo(vport);
11342 out:
11343 lpfc_els_free_iocb(phba, cmdiocb);
11344 lpfc_nlp_put(ndlp);
11345 }
11346
11347 /**
11348 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
11349 * @vport: pointer to a virtual N_Port data structure.
11350 * @ndlp: pointer to a node-list data structure.
11351 * @retry: number of retries to the command IOCB.
11352 *
11353 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
11354 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
11355 * routine to issue the IOCB, which makes sure only one outstanding fabric
11356 * IOCB will be sent off HBA at any given time.
11357 *
11358 * Note that the ndlp reference count will be incremented by 1 for holding the
11359 * ndlp and the reference to ndlp will be stored into the ndlp field of
11360 * the IOCB for the completion callback function to the FDISC ELS command.
11361 *
11362 * Return code
11363 * 0 - Successfully issued fdisc iocb command
11364 * 1 - Failed to issue fdisc iocb command
11365 **/
11366 static int
lpfc_issue_els_fdisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)11367 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
11368 uint8_t retry)
11369 {
11370 struct lpfc_hba *phba = vport->phba;
11371 IOCB_t *icmd;
11372 union lpfc_wqe128 *wqe = NULL;
11373 struct lpfc_iocbq *elsiocb;
11374 struct serv_parm *sp;
11375 uint8_t *pcmd;
11376 uint16_t cmdsize;
11377 int did = ndlp->nlp_DID;
11378 int rc;
11379
11380 vport->port_state = LPFC_FDISC;
11381 vport->fc_myDID = 0;
11382 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
11383 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
11384 ELS_CMD_FDISC);
11385 if (!elsiocb) {
11386 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11387 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11388 "0255 Issue FDISC: no IOCB\n");
11389 return 1;
11390 }
11391
11392 if (phba->sli_rev == LPFC_SLI_REV4) {
11393 wqe = &elsiocb->wqe;
11394 bf_set(els_req64_sid, &wqe->els_req, 0);
11395 bf_set(els_req64_sp, &wqe->els_req, 1);
11396 } else {
11397 icmd = &elsiocb->iocb;
11398 icmd->un.elsreq64.myID = 0;
11399 icmd->un.elsreq64.fl = 1;
11400 icmd->ulpCt_h = 1;
11401 icmd->ulpCt_l = 0;
11402 }
11403
11404 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11405 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
11406 pcmd += sizeof(uint32_t); /* CSP Word 1 */
11407 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
11408 sp = (struct serv_parm *) pcmd;
11409 /* Setup CSPs accordingly for Fabric */
11410 sp->cmn.e_d_tov = 0;
11411 sp->cmn.w2.r_a_tov = 0;
11412 sp->cmn.virtual_fabric_support = 0;
11413 sp->cls1.classValid = 0;
11414 sp->cls2.seqDelivery = 1;
11415 sp->cls3.seqDelivery = 1;
11416
11417 pcmd += sizeof(uint32_t); /* CSP Word 2 */
11418 pcmd += sizeof(uint32_t); /* CSP Word 3 */
11419 pcmd += sizeof(uint32_t); /* CSP Word 4 */
11420 pcmd += sizeof(uint32_t); /* Port Name */
11421 memcpy(pcmd, &vport->fc_portname, 8);
11422 pcmd += sizeof(uint32_t); /* Node Name */
11423 pcmd += sizeof(uint32_t); /* Node Name */
11424 memcpy(pcmd, &vport->fc_nodename, 8);
11425 sp->cmn.valid_vendor_ver_level = 0;
11426 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
11427 lpfc_set_disctmo(vport);
11428
11429 phba->fc_stat.elsXmitFDISC++;
11430 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc;
11431
11432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11433 "Issue FDISC: did:x%x",
11434 did, 0, 0);
11435
11436 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11437 if (!elsiocb->ndlp)
11438 goto err_out;
11439
11440 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
11441 if (rc == IOCB_ERROR) {
11442 lpfc_nlp_put(ndlp);
11443 goto err_out;
11444 }
11445
11446 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
11447 return 0;
11448
11449 err_out:
11450 lpfc_els_free_iocb(phba, elsiocb);
11451 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
11452 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
11453 "0256 Issue FDISC: Cannot send IOCB\n");
11454 return 1;
11455 }
11456
11457 /**
11458 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
11459 * @phba: pointer to lpfc hba data structure.
11460 * @cmdiocb: pointer to lpfc command iocb data structure.
11461 * @rspiocb: pointer to lpfc response iocb data structure.
11462 *
11463 * This routine is the completion callback function to the issuing of a LOGO
11464 * ELS command off a vport. It frees the command IOCB and then decrement the
11465 * reference count held on ndlp for this completion function, indicating that
11466 * the reference to the ndlp is no long needed. Note that the
11467 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
11468 * callback function and an additional explicit ndlp reference decrementation
11469 * will trigger the actual release of the ndlp.
11470 **/
11471 static void
lpfc_cmpl_els_npiv_logo(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)11472 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11473 struct lpfc_iocbq *rspiocb)
11474 {
11475 struct lpfc_vport *vport = cmdiocb->vport;
11476 IOCB_t *irsp;
11477 struct lpfc_nodelist *ndlp;
11478 u32 ulp_status, ulp_word4, did, tmo;
11479
11480 ndlp = cmdiocb->ndlp;
11481
11482 ulp_status = get_job_ulpstatus(phba, rspiocb);
11483 ulp_word4 = get_job_word4(phba, rspiocb);
11484
11485 if (phba->sli_rev == LPFC_SLI_REV4) {
11486 did = get_job_els_rsp64_did(phba, cmdiocb);
11487 tmo = get_wqe_tmo(cmdiocb);
11488 } else {
11489 irsp = &rspiocb->iocb;
11490 did = get_job_els_rsp64_did(phba, rspiocb);
11491 tmo = irsp->ulpTimeout;
11492 }
11493
11494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11495 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
11496 ulp_status, ulp_word4, did);
11497
11498 /* NPIV LOGO completes to NPort <nlp_DID> */
11499 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
11500 "2928 NPIV LOGO completes to NPort x%x "
11501 "Data: x%x x%x x%x x%x x%x x%lx x%x\n",
11502 ndlp->nlp_DID, ulp_status, ulp_word4,
11503 tmo, vport->num_disc_nodes,
11504 kref_read(&ndlp->kref), ndlp->nlp_flag,
11505 ndlp->fc4_xpt_flags);
11506
11507 if (ulp_status == IOSTAT_SUCCESS) {
11508 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag);
11509 clear_bit(FC_FABRIC, &vport->fc_flag);
11510 lpfc_can_disctmo(vport);
11511 }
11512
11513 if (test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags)) {
11514 /* Wake up lpfc_vport_delete if waiting...*/
11515 if (ndlp->logo_waitq)
11516 wake_up(ndlp->logo_waitq);
11517 clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
11518 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
11519 clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags);
11520 }
11521
11522 /* Safe to release resources now. */
11523 lpfc_els_free_iocb(phba, cmdiocb);
11524 lpfc_nlp_put(ndlp);
11525 }
11526
11527 /**
11528 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
11529 * @vport: pointer to a virtual N_Port data structure.
11530 * @ndlp: pointer to a node-list data structure.
11531 *
11532 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
11533 *
11534 * Note that the ndlp reference count will be incremented by 1 for holding the
11535 * ndlp and the reference to ndlp will be stored into the ndlp field of
11536 * the IOCB for the completion callback function to the LOGO ELS command.
11537 *
11538 * Return codes
11539 * 0 - Successfully issued logo off the @vport
11540 * 1 - Failed to issue logo off the @vport
11541 **/
11542 int
lpfc_issue_els_npiv_logo(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)11543 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
11544 {
11545 int rc = 0;
11546 struct lpfc_hba *phba = vport->phba;
11547 struct lpfc_iocbq *elsiocb;
11548 uint8_t *pcmd;
11549 uint16_t cmdsize;
11550
11551 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
11552 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
11553 ELS_CMD_LOGO);
11554 if (!elsiocb)
11555 return 1;
11556
11557 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
11558 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
11559 pcmd += sizeof(uint32_t);
11560
11561 /* Fill in LOGO payload */
11562 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
11563 pcmd += sizeof(uint32_t);
11564 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
11565
11566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
11567 "Issue LOGO npiv did:x%x flg:x%lx",
11568 ndlp->nlp_DID, ndlp->nlp_flag, 0);
11569
11570 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo;
11571 set_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
11572 elsiocb->ndlp = lpfc_nlp_get(ndlp);
11573 if (!elsiocb->ndlp) {
11574 lpfc_els_free_iocb(phba, elsiocb);
11575 goto err;
11576 }
11577
11578 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
11579 if (rc == IOCB_ERROR) {
11580 lpfc_els_free_iocb(phba, elsiocb);
11581 lpfc_nlp_put(ndlp);
11582 goto err;
11583 }
11584 return 0;
11585
11586 err:
11587 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
11588 return 1;
11589 }
11590
11591 /**
11592 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
11593 * @t: timer context used to obtain the lpfc hba.
11594 *
11595 * This routine is invoked by the fabric iocb block timer after
11596 * timeout. It posts the fabric iocb block timeout event by setting the
11597 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11598 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11599 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11600 * posted event WORKER_FABRIC_BLOCK_TMO.
11601 **/
11602 void
lpfc_fabric_block_timeout(struct timer_list * t)11603 lpfc_fabric_block_timeout(struct timer_list *t)
11604 {
11605 struct lpfc_hba *phba = timer_container_of(phba, t,
11606 fabric_block_timer);
11607 unsigned long iflags;
11608 uint32_t tmo_posted;
11609
11610 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
11611 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
11612 if (!tmo_posted)
11613 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
11614 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
11615
11616 if (!tmo_posted)
11617 lpfc_worker_wake_up(phba);
11618 return;
11619 }
11620
11621 /**
11622 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
11623 * @phba: pointer to lpfc hba data structure.
11624 *
11625 * This routine issues one fabric iocb from the driver internal list to
11626 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11627 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11628 * remove one pending fabric iocb from the driver internal list and invokes
11629 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11630 **/
11631 static void
lpfc_resume_fabric_iocbs(struct lpfc_hba * phba)11632 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
11633 {
11634 struct lpfc_iocbq *iocb;
11635 unsigned long iflags;
11636 int ret;
11637
11638 repeat:
11639 iocb = NULL;
11640 spin_lock_irqsave(&phba->hbalock, iflags);
11641 /* Post any pending iocb to the SLI layer */
11642 if (atomic_read(&phba->fabric_iocb_count) == 0) {
11643 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
11644 list);
11645 if (iocb)
11646 /* Increment fabric iocb count to hold the position */
11647 atomic_inc(&phba->fabric_iocb_count);
11648 }
11649 spin_unlock_irqrestore(&phba->hbalock, iflags);
11650 if (iocb) {
11651 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11652 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11653 iocb->cmd_flag |= LPFC_IO_FABRIC;
11654
11655 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11656 "Fabric sched1: ste:x%x",
11657 iocb->vport->port_state, 0, 0);
11658
11659 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11660
11661 if (ret == IOCB_ERROR) {
11662 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11663 iocb->fabric_cmd_cmpl = NULL;
11664 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11665 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT);
11666 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
11667 iocb->cmd_cmpl(phba, iocb, iocb);
11668
11669 atomic_dec(&phba->fabric_iocb_count);
11670 goto repeat;
11671 }
11672 }
11673 }
11674
11675 /**
11676 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
11677 * @phba: pointer to lpfc hba data structure.
11678 *
11679 * This routine unblocks the issuing fabric iocb command. The function
11680 * will clear the fabric iocb block bit and then invoke the routine
11681 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11682 * from the driver internal fabric iocb list.
11683 **/
11684 void
lpfc_unblock_fabric_iocbs(struct lpfc_hba * phba)11685 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
11686 {
11687 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11688
11689 lpfc_resume_fabric_iocbs(phba);
11690 return;
11691 }
11692
11693 /**
11694 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
11695 * @phba: pointer to lpfc hba data structure.
11696 *
11697 * This routine blocks the issuing fabric iocb for a specified amount of
11698 * time (currently 100 ms). This is done by set the fabric iocb block bit
11699 * and set up a timeout timer for 100ms. When the block bit is set, no more
11700 * fabric iocb will be issued out of the HBA.
11701 **/
11702 static void
lpfc_block_fabric_iocbs(struct lpfc_hba * phba)11703 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
11704 {
11705 int blocked;
11706
11707 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11708 /* Start a timer to unblock fabric iocbs after 100ms */
11709 if (!blocked)
11710 mod_timer(&phba->fabric_block_timer,
11711 jiffies + msecs_to_jiffies(100));
11712
11713 return;
11714 }
11715
11716 /**
11717 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
11718 * @phba: pointer to lpfc hba data structure.
11719 * @cmdiocb: pointer to lpfc command iocb data structure.
11720 * @rspiocb: pointer to lpfc response iocb data structure.
11721 *
11722 * This routine is the callback function that is put to the fabric iocb's
11723 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
11724 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
11725 * function first restores and invokes the original iocb's callback function
11726 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11727 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11728 **/
11729 static void
lpfc_cmpl_fabric_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)11730 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11731 struct lpfc_iocbq *rspiocb)
11732 {
11733 struct ls_rjt stat;
11734 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
11735 u32 ulp_word4 = get_job_word4(phba, rspiocb);
11736
11737 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
11738
11739 switch (ulp_status) {
11740 case IOSTAT_NPORT_RJT:
11741 case IOSTAT_FABRIC_RJT:
11742 if (ulp_word4 & RJT_UNAVAIL_TEMP)
11743 lpfc_block_fabric_iocbs(phba);
11744 break;
11745
11746 case IOSTAT_NPORT_BSY:
11747 case IOSTAT_FABRIC_BSY:
11748 lpfc_block_fabric_iocbs(phba);
11749 break;
11750
11751 case IOSTAT_LS_RJT:
11752 stat.un.ls_rjt_error_be =
11753 cpu_to_be32(ulp_word4);
11754 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
11755 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
11756 lpfc_block_fabric_iocbs(phba);
11757 break;
11758 }
11759
11760 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
11761
11762 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl;
11763 cmdiocb->fabric_cmd_cmpl = NULL;
11764 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
11765 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb);
11766
11767 atomic_dec(&phba->fabric_iocb_count);
11768 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
11769 /* Post any pending iocbs to HBA */
11770 lpfc_resume_fabric_iocbs(phba);
11771 }
11772 }
11773
11774 /**
11775 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
11776 * @phba: pointer to lpfc hba data structure.
11777 * @iocb: pointer to lpfc command iocb data structure.
11778 *
11779 * This routine is used as the top-level API for issuing a fabric iocb command
11780 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11781 * function makes sure that only one fabric bound iocb will be outstanding at
11782 * any given time. As such, this function will first check to see whether there
11783 * is already an outstanding fabric iocb on the wire. If so, it will put the
11784 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11785 * issued later. Otherwise, it will issue the iocb on the wire and update the
11786 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11787 *
11788 * Note, this implementation has a potential sending out fabric IOCBs out of
11789 * order. The problem is caused by the construction of the "ready" boolen does
11790 * not include the condition that the internal fabric IOCB list is empty. As
11791 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11792 * ahead of the fabric IOCBs in the internal list.
11793 *
11794 * Return code
11795 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11796 * IOCB_ERROR - failed to issue fabric iocb
11797 **/
11798 static int
lpfc_issue_fabric_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * iocb)11799 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
11800 {
11801 unsigned long iflags;
11802 int ready;
11803 int ret;
11804
11805 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
11806
11807 spin_lock_irqsave(&phba->hbalock, iflags);
11808 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
11809 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
11810
11811 if (ready)
11812 /* Increment fabric iocb count to hold the position */
11813 atomic_inc(&phba->fabric_iocb_count);
11814 spin_unlock_irqrestore(&phba->hbalock, iflags);
11815 if (ready) {
11816 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
11817 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
11818 iocb->cmd_flag |= LPFC_IO_FABRIC;
11819
11820 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
11821 "Fabric sched2: ste:x%x",
11822 iocb->vport->port_state, 0, 0);
11823
11824 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
11825
11826 if (ret == IOCB_ERROR) {
11827 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
11828 iocb->fabric_cmd_cmpl = NULL;
11829 iocb->cmd_flag &= ~LPFC_IO_FABRIC;
11830 atomic_dec(&phba->fabric_iocb_count);
11831 }
11832 } else {
11833 spin_lock_irqsave(&phba->hbalock, iflags);
11834 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
11835 spin_unlock_irqrestore(&phba->hbalock, iflags);
11836 ret = IOCB_SUCCESS;
11837 }
11838 return ret;
11839 }
11840
11841 /**
11842 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
11843 * @vport: pointer to a virtual N_Port data structure.
11844 *
11845 * This routine aborts all the IOCBs associated with a @vport from the
11846 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11847 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11848 * list, removes each IOCB associated with the @vport off the list, set the
11849 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11850 * associated with the IOCB.
11851 **/
lpfc_fabric_abort_vport(struct lpfc_vport * vport)11852 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
11853 {
11854 LIST_HEAD(completions);
11855 struct lpfc_hba *phba = vport->phba;
11856 struct lpfc_iocbq *tmp_iocb, *piocb;
11857
11858 spin_lock_irq(&phba->hbalock);
11859 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11860 list) {
11861
11862 if (piocb->vport != vport)
11863 continue;
11864
11865 list_move_tail(&piocb->list, &completions);
11866 }
11867 spin_unlock_irq(&phba->hbalock);
11868
11869 /* Cancel all the IOCBs from the completions list */
11870 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11871 IOERR_SLI_ABORTED);
11872 }
11873
11874 /**
11875 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
11876 * @ndlp: pointer to a node-list data structure.
11877 *
11878 * This routine aborts all the IOCBs associated with an @ndlp from the
11879 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11880 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11881 * list, removes each IOCB associated with the @ndlp off the list, set the
11882 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11883 * associated with the IOCB.
11884 **/
lpfc_fabric_abort_nport(struct lpfc_nodelist * ndlp)11885 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
11886 {
11887 LIST_HEAD(completions);
11888 struct lpfc_hba *phba = ndlp->phba;
11889 struct lpfc_iocbq *tmp_iocb, *piocb;
11890 struct lpfc_sli_ring *pring;
11891
11892 pring = lpfc_phba_elsring(phba);
11893
11894 if (unlikely(!pring))
11895 return;
11896
11897 spin_lock_irq(&phba->hbalock);
11898 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
11899 list) {
11900 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
11901
11902 list_move_tail(&piocb->list, &completions);
11903 }
11904 }
11905 spin_unlock_irq(&phba->hbalock);
11906
11907 /* Cancel all the IOCBs from the completions list */
11908 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11909 IOERR_SLI_ABORTED);
11910 }
11911
11912 /**
11913 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
11914 * @phba: pointer to lpfc hba data structure.
11915 *
11916 * This routine aborts all the IOCBs currently on the driver internal
11917 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11918 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
11919 * list, removes IOCBs off the list, set the status field to
11920 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11921 * the IOCB.
11922 **/
lpfc_fabric_abort_hba(struct lpfc_hba * phba)11923 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
11924 {
11925 LIST_HEAD(completions);
11926
11927 spin_lock_irq(&phba->hbalock);
11928 list_splice_init(&phba->fabric_iocb_list, &completions);
11929 spin_unlock_irq(&phba->hbalock);
11930
11931 /* Cancel all the IOCBs from the completions list */
11932 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11933 IOERR_SLI_ABORTED);
11934 }
11935
11936 /**
11937 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
11938 * @vport: pointer to lpfc vport data structure.
11939 *
11940 * This routine is invoked by the vport cleanup for deletions and the cleanup
11941 * for an ndlp on removal.
11942 **/
11943 void
lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport * vport)11944 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
11945 {
11946 struct lpfc_hba *phba = vport->phba;
11947 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11948 struct lpfc_nodelist *ndlp = NULL;
11949 unsigned long iflag = 0;
11950
11951 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
11952 list_for_each_entry_safe(sglq_entry, sglq_next,
11953 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
11954 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
11955 lpfc_nlp_put(sglq_entry->ndlp);
11956 ndlp = sglq_entry->ndlp;
11957 sglq_entry->ndlp = NULL;
11958
11959 /* If the xri on the abts_els_sgl list is for the Fport
11960 * node and the vport is unloading, the xri aborted wcqe
11961 * likely isn't coming back. Just release the sgl.
11962 */
11963 if (test_bit(FC_UNLOADING, &vport->load_flag) &&
11964 ndlp->nlp_DID == Fabric_DID) {
11965 list_del(&sglq_entry->list);
11966 sglq_entry->state = SGL_FREED;
11967 list_add_tail(&sglq_entry->list,
11968 &phba->sli4_hba.lpfc_els_sgl_list);
11969 }
11970 }
11971 }
11972 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
11973 return;
11974 }
11975
11976 /**
11977 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
11978 * @phba: pointer to lpfc hba data structure.
11979 * @axri: pointer to the els xri abort wcqe structure.
11980 *
11981 * This routine is invoked by the worker thread to process a SLI4 slow-path
11982 * ELS aborted xri.
11983 **/
11984 void
lpfc_sli4_els_xri_aborted(struct lpfc_hba * phba,struct sli4_wcqe_xri_aborted * axri)11985 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
11986 struct sli4_wcqe_xri_aborted *axri)
11987 {
11988 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
11989 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
11990 uint16_t lxri = 0;
11991
11992 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
11993 unsigned long iflag = 0;
11994 struct lpfc_nodelist *ndlp;
11995 struct lpfc_sli_ring *pring;
11996
11997 pring = lpfc_phba_elsring(phba);
11998
11999 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
12000 list_for_each_entry_safe(sglq_entry, sglq_next,
12001 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
12002 if (sglq_entry->sli4_xritag == xri) {
12003 list_del(&sglq_entry->list);
12004 ndlp = sglq_entry->ndlp;
12005 sglq_entry->ndlp = NULL;
12006 list_add_tail(&sglq_entry->list,
12007 &phba->sli4_hba.lpfc_els_sgl_list);
12008 sglq_entry->state = SGL_FREED;
12009 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
12010 iflag);
12011
12012 if (ndlp) {
12013 lpfc_set_rrq_active(phba, ndlp,
12014 sglq_entry->sli4_lxritag,
12015 rxid, 1);
12016 lpfc_nlp_put(ndlp);
12017 }
12018
12019 /* Check if TXQ queue needs to be serviced */
12020 if (pring && !list_empty(&pring->txq))
12021 lpfc_worker_wake_up(phba);
12022 return;
12023 }
12024 }
12025 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
12026 lxri = lpfc_sli4_xri_inrange(phba, xri);
12027 if (lxri == NO_XRI)
12028 return;
12029
12030 spin_lock_irqsave(&phba->hbalock, iflag);
12031 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
12032 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
12033 spin_unlock_irqrestore(&phba->hbalock, iflag);
12034 return;
12035 }
12036 sglq_entry->state = SGL_XRI_ABORTED;
12037 spin_unlock_irqrestore(&phba->hbalock, iflag);
12038 return;
12039 }
12040
12041 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
12042 * @vport: pointer to virtual port object.
12043 * @ndlp: nodelist pointer for the impacted node.
12044 *
12045 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
12046 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
12047 * the driver is required to send a LOGO to the remote node before it
12048 * attempts to recover its login to the remote node.
12049 */
12050 void
lpfc_sli_abts_recover_port(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)12051 lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
12052 struct lpfc_nodelist *ndlp)
12053 {
12054 struct Scsi_Host *shost;
12055 struct lpfc_hba *phba;
12056 unsigned long flags = 0;
12057
12058 shost = lpfc_shost_from_vport(vport);
12059 phba = vport->phba;
12060 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
12061 lpfc_printf_log(phba, KERN_INFO,
12062 LOG_SLI, "3093 No rport recovery needed. "
12063 "rport in state 0x%x\n", ndlp->nlp_state);
12064 return;
12065 }
12066 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12067 "3094 Start rport recovery on shost id 0x%x "
12068 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
12069 "flag 0x%lx\n",
12070 shost->host_no, ndlp->nlp_DID,
12071 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
12072 ndlp->nlp_flag);
12073 /*
12074 * The rport is not responding. Remove the FCP-2 flag to prevent
12075 * an ADISC in the follow-up recovery code.
12076 */
12077 spin_lock_irqsave(&ndlp->lock, flags);
12078 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
12079 spin_unlock_irqrestore(&ndlp->lock, flags);
12080 set_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
12081 lpfc_unreg_rpi(vport, ndlp);
12082 }
12083
lpfc_init_cs_ctl_bitmap(struct lpfc_vport * vport)12084 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
12085 {
12086 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
12087 }
12088
12089 static void
lpfc_vmid_set_cs_ctl_range(struct lpfc_vport * vport,u32 min,u32 max)12090 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
12091 {
12092 u32 i;
12093
12094 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
12095 return;
12096
12097 for (i = min; i <= max; i++)
12098 set_bit(i, vport->vmid_priority_range);
12099 }
12100
lpfc_vmid_put_cs_ctl(struct lpfc_vport * vport,u32 ctcl_vmid)12101 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
12102 {
12103 set_bit(ctcl_vmid, vport->vmid_priority_range);
12104 }
12105
lpfc_vmid_get_cs_ctl(struct lpfc_vport * vport)12106 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
12107 {
12108 u32 i;
12109
12110 i = find_first_bit(vport->vmid_priority_range,
12111 LPFC_VMID_MAX_PRIORITY_RANGE);
12112
12113 if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
12114 return 0;
12115
12116 clear_bit(i, vport->vmid_priority_range);
12117 return i;
12118 }
12119
12120 #define MAX_PRIORITY_DESC 255
12121
12122 static void
lpfc_cmpl_els_qfpa(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)12123 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12124 struct lpfc_iocbq *rspiocb)
12125 {
12126 struct lpfc_vport *vport = cmdiocb->vport;
12127 struct priority_range_desc *desc;
12128 struct lpfc_dmabuf *prsp = NULL;
12129 struct lpfc_vmid_priority_range *vmid_range = NULL;
12130 u32 *data;
12131 struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf;
12132 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12133 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12134 u8 *pcmd, max_desc;
12135 u32 len, i;
12136 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
12137
12138 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12139 if (!prsp)
12140 goto out;
12141
12142 pcmd = prsp->virt;
12143 data = (u32 *)pcmd;
12144 if (data[0] == ELS_CMD_LS_RJT) {
12145 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12146 "3277 QFPA LS_RJT x%x x%x\n",
12147 data[0], data[1]);
12148 goto out;
12149 }
12150 if (ulp_status) {
12151 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
12152 "6529 QFPA failed with status x%x x%x\n",
12153 ulp_status, ulp_word4);
12154 goto out;
12155 }
12156
12157 if (!vport->qfpa_res) {
12158 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
12159 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
12160 GFP_KERNEL);
12161 if (!vport->qfpa_res)
12162 goto out;
12163 }
12164
12165 len = *((u32 *)(pcmd + 4));
12166 len = be32_to_cpu(len);
12167 memcpy(vport->qfpa_res, pcmd, len + 8);
12168 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
12169
12170 desc = (struct priority_range_desc *)(pcmd + 8);
12171 vmid_range = vport->vmid_priority.vmid_range;
12172 if (!vmid_range) {
12173 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
12174 GFP_KERNEL);
12175 if (!vmid_range) {
12176 kfree(vport->qfpa_res);
12177 goto out;
12178 }
12179 vport->vmid_priority.vmid_range = vmid_range;
12180 }
12181 vport->vmid_priority.num_descriptors = len;
12182
12183 for (i = 0; i < len; i++, vmid_range++, desc++) {
12184 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12185 "6539 vmid values low=%d, high=%d, qos=%d, "
12186 "local ve id=%d\n", desc->lo_range,
12187 desc->hi_range, desc->qos_priority,
12188 desc->local_ve_id);
12189
12190 vmid_range->low = desc->lo_range << 1;
12191 if (desc->local_ve_id == QFPA_ODD_ONLY)
12192 vmid_range->low++;
12193 if (desc->qos_priority)
12194 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
12195 vmid_range->qos = desc->qos_priority;
12196
12197 vmid_range->high = desc->hi_range << 1;
12198 if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
12199 (desc->local_ve_id == QFPA_EVEN_ODD))
12200 vmid_range->high++;
12201 }
12202 lpfc_init_cs_ctl_bitmap(vport);
12203 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
12204 lpfc_vmid_set_cs_ctl_range(vport,
12205 vport->vmid_priority.vmid_range[i].low,
12206 vport->vmid_priority.vmid_range[i].high);
12207 }
12208
12209 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
12210 out:
12211 lpfc_els_free_iocb(phba, cmdiocb);
12212 lpfc_nlp_put(ndlp);
12213 }
12214
lpfc_issue_els_qfpa(struct lpfc_vport * vport)12215 int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
12216 {
12217 struct lpfc_hba *phba = vport->phba;
12218 struct lpfc_nodelist *ndlp;
12219 struct lpfc_iocbq *elsiocb;
12220 u8 *pcmd;
12221 int ret;
12222
12223 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
12224 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12225 return -ENXIO;
12226
12227 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
12228 ndlp->nlp_DID, ELS_CMD_QFPA);
12229 if (!elsiocb)
12230 return -ENOMEM;
12231
12232 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12233
12234 *((u32 *)(pcmd)) = ELS_CMD_QFPA;
12235 pcmd += 4;
12236
12237 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa;
12238
12239 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12240 if (!elsiocb->ndlp) {
12241 lpfc_els_free_iocb(vport->phba, elsiocb);
12242 return -ENXIO;
12243 }
12244
12245 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
12246 if (ret != IOCB_SUCCESS) {
12247 lpfc_els_free_iocb(phba, elsiocb);
12248 lpfc_nlp_put(ndlp);
12249 return -EIO;
12250 }
12251 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
12252 return 0;
12253 }
12254
12255 int
lpfc_vmid_uvem(struct lpfc_vport * vport,struct lpfc_vmid * vmid,bool instantiated)12256 lpfc_vmid_uvem(struct lpfc_vport *vport,
12257 struct lpfc_vmid *vmid, bool instantiated)
12258 {
12259 struct lpfc_vem_id_desc *vem_id_desc;
12260 struct lpfc_nodelist *ndlp;
12261 struct lpfc_iocbq *elsiocb;
12262 struct instantiated_ve_desc *inst_desc;
12263 struct lpfc_vmid_context *vmid_context;
12264 u8 *pcmd;
12265 u32 *len;
12266 int ret = 0;
12267
12268 ndlp = lpfc_findnode_did(vport, Fabric_DID);
12269 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12270 return -ENXIO;
12271
12272 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
12273 if (!vmid_context)
12274 return -ENOMEM;
12275 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
12276 ndlp, Fabric_DID, ELS_CMD_UVEM);
12277 if (!elsiocb)
12278 goto out;
12279
12280 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
12281 "3427 Host vmid %s %d\n",
12282 vmid->host_vmid, instantiated);
12283 vmid_context->vmp = vmid;
12284 vmid_context->nlp = ndlp;
12285 vmid_context->instantiated = instantiated;
12286 elsiocb->vmid_tag.vmid_context = vmid_context;
12287 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
12288
12289 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0,
12290 sizeof(vport->lpfc_vmid_host_uuid)))
12291 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
12292 sizeof(vport->lpfc_vmid_host_uuid));
12293
12294 *((u32 *)(pcmd)) = ELS_CMD_UVEM;
12295 len = (u32 *)(pcmd + 4);
12296 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
12297
12298 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
12299 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
12300 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
12301 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
12302 sizeof(vem_id_desc->vem_id));
12303
12304 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
12305 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12306 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
12307 memcpy(inst_desc->global_vem_id, vmid->host_vmid,
12308 sizeof(inst_desc->global_vem_id));
12309
12310 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
12311 bf_set(lpfc_instantiated_local_id, inst_desc,
12312 vmid->un.cs_ctl_vmid);
12313 if (instantiated) {
12314 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
12315 } else {
12316 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
12317 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
12318 }
12319 inst_desc->word6 = cpu_to_be32(inst_desc->word6);
12320
12321 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem;
12322
12323 elsiocb->ndlp = lpfc_nlp_get(ndlp);
12324 if (!elsiocb->ndlp) {
12325 lpfc_els_free_iocb(vport->phba, elsiocb);
12326 goto out;
12327 }
12328
12329 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
12330 if (ret != IOCB_SUCCESS) {
12331 lpfc_els_free_iocb(vport->phba, elsiocb);
12332 lpfc_nlp_put(ndlp);
12333 goto out;
12334 }
12335
12336 return 0;
12337 out:
12338 kfree(vmid_context);
12339 return -EIO;
12340 }
12341
12342 static void
lpfc_cmpl_els_uvem(struct lpfc_hba * phba,struct lpfc_iocbq * icmdiocb,struct lpfc_iocbq * rspiocb)12343 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
12344 struct lpfc_iocbq *rspiocb)
12345 {
12346 struct lpfc_vport *vport = icmdiocb->vport;
12347 struct lpfc_dmabuf *prsp = NULL;
12348 struct lpfc_vmid_context *vmid_context =
12349 icmdiocb->vmid_tag.vmid_context;
12350 struct lpfc_nodelist *ndlp = icmdiocb->ndlp;
12351 u8 *pcmd;
12352 u32 *data;
12353 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12354 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12355 struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf;
12356 struct lpfc_vmid *vmid;
12357
12358 vmid = vmid_context->vmp;
12359 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
12360 ndlp = NULL;
12361
12362 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
12363 if (!prsp)
12364 goto out;
12365 pcmd = prsp->virt;
12366 data = (u32 *)pcmd;
12367 if (data[0] == ELS_CMD_LS_RJT) {
12368 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12369 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
12370 goto out;
12371 }
12372 if (ulp_status) {
12373 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
12374 "4533 UVEM error status %x: %x\n",
12375 ulp_status, ulp_word4);
12376 goto out;
12377 }
12378 spin_lock(&phba->hbalock);
12379 /* Set IN USE flag */
12380 vport->vmid_flag |= LPFC_VMID_IN_USE;
12381 phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
12382 spin_unlock(&phba->hbalock);
12383
12384 if (vmid_context->instantiated) {
12385 write_lock(&vport->vmid_lock);
12386 vmid->flag |= LPFC_VMID_REGISTERED;
12387 vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
12388 write_unlock(&vport->vmid_lock);
12389 }
12390
12391 out:
12392 kfree(vmid_context);
12393 lpfc_els_free_iocb(phba, icmdiocb);
12394 lpfc_nlp_put(ndlp);
12395 }
12396