]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
d080abe0 JS |
4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * | |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
c44ce173 | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
10 | * * |
11 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
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. * | |
dea3101e | 22 | *******************************************************************/ |
09372820 | 23 | /* See Fibre Channel protocol T11 FC-LS for details */ |
dea3101e JB |
24 | #include <linux/blkdev.h> |
25 | #include <linux/pci.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e JB |
27 | #include <linux/interrupt.h> |
28 | ||
91886523 | 29 | #include <scsi/scsi.h> |
dea3101e JB |
30 | #include <scsi/scsi_device.h> |
31 | #include <scsi/scsi_host.h> | |
32 | #include <scsi/scsi_transport_fc.h> | |
33 | ||
da0436e9 | 34 | #include "lpfc_hw4.h" |
dea3101e JB |
35 | #include "lpfc_hw.h" |
36 | #include "lpfc_sli.h" | |
da0436e9 | 37 | #include "lpfc_sli4.h" |
ea2151b4 | 38 | #include "lpfc_nl.h" |
dea3101e JB |
39 | #include "lpfc_disc.h" |
40 | #include "lpfc_scsi.h" | |
41 | #include "lpfc.h" | |
42 | #include "lpfc_logmsg.h" | |
43 | #include "lpfc_crtn.h" | |
92d7f7b0 | 44 | #include "lpfc_vport.h" |
858c9f6c | 45 | #include "lpfc_debugfs.h" |
dea3101e JB |
46 | |
47 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, | |
48 | struct lpfc_iocbq *); | |
92d7f7b0 JS |
49 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
50 | struct lpfc_iocbq *); | |
a6ababd2 AB |
51 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
52 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, | |
53 | struct lpfc_nodelist *ndlp, uint8_t retry); | |
54 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, | |
55 | struct lpfc_iocbq *iocb); | |
92d7f7b0 | 56 | |
dea3101e JB |
57 | static int lpfc_max_els_tries = 3; |
58 | ||
e59058c4 | 59 | /** |
3621a710 | 60 | * lpfc_els_chk_latt - Check host link attention event for a vport |
e59058c4 JS |
61 | * @vport: pointer to a host virtual N_Port data structure. |
62 | * | |
63 | * This routine checks whether there is an outstanding host link | |
64 | * attention event during the discovery process with the @vport. It is done | |
65 | * by reading the HBA's Host Attention (HA) register. If there is any host | |
66 | * link attention events during this @vport's discovery process, the @vport | |
67 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall | |
68 | * be issued if the link state is not already in host link cleared state, | |
69 | * and a return code shall indicate whether the host link attention event | |
70 | * had happened. | |
71 | * | |
72 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport | |
73 | * state in LPFC_VPORT_READY, the request for checking host link attention | |
74 | * event will be ignored and a return code shall indicate no host link | |
75 | * attention event had happened. | |
76 | * | |
77 | * Return codes | |
78 | * 0 - no host link attention event happened | |
79 | * 1 - host link attention event happened | |
80 | **/ | |
858c9f6c | 81 | int |
2e0fef85 | 82 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
dea3101e | 83 | { |
2e0fef85 JS |
84 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
85 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 86 | uint32_t ha_copy; |
dea3101e | 87 | |
2e0fef85 | 88 | if (vport->port_state >= LPFC_VPORT_READY || |
3772a991 JS |
89 | phba->link_state == LPFC_LINK_DOWN || |
90 | phba->sli_rev > LPFC_SLI_REV3) | |
dea3101e JB |
91 | return 0; |
92 | ||
93 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
94 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
95 | return 1; | |
dea3101e JB |
96 | |
97 | if (!(ha_copy & HA_LATT)) | |
98 | return 0; | |
99 | ||
100 | /* Pending Link Event during Discovery */ | |
e8b62011 JS |
101 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
102 | "0237 Pending Link Event during " | |
103 | "Discovery: State x%x\n", | |
104 | phba->pport->port_state); | |
dea3101e JB |
105 | |
106 | /* CLEAR_LA should re-enable link attention events and | |
25985edc | 107 | * we should then immediately take a LATT event. The |
dea3101e JB |
108 | * LATT processing should call lpfc_linkdown() which |
109 | * will cleanup any left over in-progress discovery | |
110 | * events. | |
111 | */ | |
2e0fef85 JS |
112 | spin_lock_irq(shost->host_lock); |
113 | vport->fc_flag |= FC_ABORT_DISCOVERY; | |
114 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 115 | |
92d7f7b0 | 116 | if (phba->link_state != LPFC_CLEAR_LA) |
ed957684 | 117 | lpfc_issue_clear_la(phba, vport); |
dea3101e | 118 | |
c9f8735b | 119 | return 1; |
dea3101e JB |
120 | } |
121 | ||
e59058c4 | 122 | /** |
3621a710 | 123 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
e59058c4 JS |
124 | * @vport: pointer to a host virtual N_Port data structure. |
125 | * @expectRsp: flag indicating whether response is expected. | |
126 | * @cmdSize: size of the ELS command. | |
127 | * @retry: number of retries to the command IOCB when it fails. | |
128 | * @ndlp: pointer to a node-list data structure. | |
129 | * @did: destination identifier. | |
130 | * @elscmd: the ELS command code. | |
131 | * | |
132 | * This routine is used for allocating a lpfc-IOCB data structure from | |
133 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters | |
134 | * passed into the routine for discovery state machine to issue an Extended | |
135 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation | |
136 | * and preparation routine that is used by all the discovery state machine | |
137 | * routines and the ELS command-specific fields will be later set up by | |
138 | * the individual discovery machine routines after calling this routine | |
139 | * allocating and preparing a generic IOCB data structure. It fills in the | |
140 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command | |
141 | * payload and response payload (if expected). The reference count on the | |
142 | * ndlp is incremented by 1 and the reference to the ndlp is put into | |
143 | * context1 of the IOCB data structure for this IOCB to hold the ndlp | |
144 | * reference for the command's callback function to access later. | |
145 | * | |
146 | * Return code | |
147 | * Pointer to the newly allocated/prepared els iocb data structure | |
148 | * NULL - when els iocb data structure allocation/preparation failed | |
149 | **/ | |
f1c3b0fc | 150 | struct lpfc_iocbq * |
2e0fef85 JS |
151 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
152 | uint16_t cmdSize, uint8_t retry, | |
153 | struct lpfc_nodelist *ndlp, uint32_t did, | |
154 | uint32_t elscmd) | |
dea3101e | 155 | { |
2e0fef85 | 156 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 | 157 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
158 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
159 | struct ulp_bde64 *bpl; | |
160 | IOCB_t *icmd; | |
161 | ||
dea3101e | 162 | |
2e0fef85 JS |
163 | if (!lpfc_is_link_up(phba)) |
164 | return NULL; | |
dea3101e | 165 | |
dea3101e | 166 | /* Allocate buffer for command iocb */ |
0bd4ca25 | 167 | elsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
168 | |
169 | if (elsiocb == NULL) | |
170 | return NULL; | |
e47c9093 | 171 | |
0c287589 JS |
172 | /* |
173 | * If this command is for fabric controller and HBA running | |
174 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. | |
175 | */ | |
176 | if ((did == Fabric_DID) && | |
45ed1190 | 177 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
0c287589 JS |
178 | ((elscmd == ELS_CMD_FLOGI) || |
179 | (elscmd == ELS_CMD_FDISC) || | |
180 | (elscmd == ELS_CMD_LOGO))) | |
c868595d JS |
181 | switch (elscmd) { |
182 | case ELS_CMD_FLOGI: | |
f0d9bccc JS |
183 | elsiocb->iocb_flag |= |
184 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
185 | & LPFC_FIP_ELS_ID_MASK); |
186 | break; | |
187 | case ELS_CMD_FDISC: | |
f0d9bccc JS |
188 | elsiocb->iocb_flag |= |
189 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
190 | & LPFC_FIP_ELS_ID_MASK); |
191 | break; | |
192 | case ELS_CMD_LOGO: | |
f0d9bccc JS |
193 | elsiocb->iocb_flag |= |
194 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
195 | & LPFC_FIP_ELS_ID_MASK); |
196 | break; | |
197 | } | |
0c287589 | 198 | else |
c868595d | 199 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
0c287589 | 200 | |
dea3101e JB |
201 | icmd = &elsiocb->iocb; |
202 | ||
203 | /* fill in BDEs for command */ | |
204 | /* Allocate buffer for command payload */ | |
98c9ea5c JS |
205 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
206 | if (pcmd) | |
207 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); | |
fa4066b6 JS |
208 | if (!pcmd || !pcmd->virt) |
209 | goto els_iocb_free_pcmb_exit; | |
dea3101e JB |
210 | |
211 | INIT_LIST_HEAD(&pcmd->list); | |
212 | ||
213 | /* Allocate buffer for response payload */ | |
214 | if (expectRsp) { | |
92d7f7b0 | 215 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e JB |
216 | if (prsp) |
217 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
218 | &prsp->phys); | |
fa4066b6 JS |
219 | if (!prsp || !prsp->virt) |
220 | goto els_iocb_free_prsp_exit; | |
dea3101e | 221 | INIT_LIST_HEAD(&prsp->list); |
e47c9093 | 222 | } else |
dea3101e | 223 | prsp = NULL; |
dea3101e JB |
224 | |
225 | /* Allocate buffer for Buffer ptr list */ | |
92d7f7b0 | 226 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e | 227 | if (pbuflist) |
ed957684 JS |
228 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
229 | &pbuflist->phys); | |
fa4066b6 JS |
230 | if (!pbuflist || !pbuflist->virt) |
231 | goto els_iocb_free_pbuf_exit; | |
dea3101e JB |
232 | |
233 | INIT_LIST_HEAD(&pbuflist->list); | |
234 | ||
dea3101e | 235 | if (expectRsp) { |
939723a4 JS |
236 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
237 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | |
238 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
92d7f7b0 | 239 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
939723a4 JS |
240 | |
241 | icmd->un.elsreq64.remoteID = did; /* DID */ | |
dea3101e | 242 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
88f43a08 JS |
243 | if (elscmd == ELS_CMD_FLOGI) |
244 | icmd->ulpTimeout = FF_DEF_RATOV * 2; | |
245 | else | |
246 | icmd->ulpTimeout = phba->fc_ratov * 2; | |
dea3101e | 247 | } else { |
939723a4 JS |
248 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
249 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | |
250 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
251 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); | |
252 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ | |
dea3101e JB |
253 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
254 | } | |
dea3101e JB |
255 | icmd->ulpBdeCount = 1; |
256 | icmd->ulpLe = 1; | |
257 | icmd->ulpClass = CLASS3; | |
258 | ||
939723a4 JS |
259 | /* |
260 | * If we have NPIV enabled, we want to send ELS traffic by VPI. | |
261 | * For SLI4, since the driver controls VPIs we also want to include | |
262 | * all ELS pt2pt protocol traffic as well. | |
263 | */ | |
264 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || | |
265 | ((phba->sli_rev == LPFC_SLI_REV4) && | |
266 | (vport->fc_flag & FC_PT2PT))) { | |
267 | ||
268 | if (expectRsp) { | |
269 | icmd->un.elsreq64.myID = vport->fc_myDID; | |
270 | ||
271 | /* For ELS_REQUEST64_CR, use the VPI by default */ | |
272 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; | |
273 | } | |
92d7f7b0 | 274 | |
92d7f7b0 | 275 | icmd->ulpCt_h = 0; |
eada272d JS |
276 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
277 | if (elscmd == ELS_CMD_ECHO) | |
278 | icmd->ulpCt_l = 0; /* context = invalid RPI */ | |
279 | else | |
280 | icmd->ulpCt_l = 1; /* context = VPI */ | |
92d7f7b0 JS |
281 | } |
282 | ||
dea3101e JB |
283 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
284 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); | |
285 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); | |
286 | bpl->tus.f.bdeSize = cmdSize; | |
287 | bpl->tus.f.bdeFlags = 0; | |
288 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
289 | ||
290 | if (expectRsp) { | |
291 | bpl++; | |
292 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); | |
293 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); | |
294 | bpl->tus.f.bdeSize = FCELSSIZE; | |
34b02dcd | 295 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
dea3101e JB |
296 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
297 | } | |
298 | ||
fa4066b6 | 299 | /* prevent preparing iocb with NULL ndlp reference */ |
51ef4c26 | 300 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
fa4066b6 JS |
301 | if (!elsiocb->context1) |
302 | goto els_iocb_free_pbuf_exit; | |
329f9bc7 JS |
303 | elsiocb->context2 = pcmd; |
304 | elsiocb->context3 = pbuflist; | |
dea3101e | 305 | elsiocb->retry = retry; |
2e0fef85 | 306 | elsiocb->vport = vport; |
dea3101e JB |
307 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
308 | ||
309 | if (prsp) { | |
310 | list_add(&prsp->list, &pcmd->list); | |
311 | } | |
dea3101e JB |
312 | if (expectRsp) { |
313 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
314 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
315 | "0116 Xmit ELS command x%x to remote " | |
e74c03c8 JS |
316 | "NPORT x%x I/O tag: x%x, port state:x%x" |
317 | " fc_flag:x%x\n", | |
e8b62011 | 318 | elscmd, did, elsiocb->iotag, |
e74c03c8 JS |
319 | vport->port_state, |
320 | vport->fc_flag); | |
dea3101e JB |
321 | } else { |
322 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
323 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
324 | "0117 Xmit ELS response x%x to remote " | |
e74c03c8 JS |
325 | "NPORT x%x I/O tag: x%x, size: x%x " |
326 | "port_state x%x fc_flag x%x\n", | |
e8b62011 | 327 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
e74c03c8 JS |
328 | cmdSize, vport->port_state, |
329 | vport->fc_flag); | |
dea3101e | 330 | } |
c9f8735b | 331 | return elsiocb; |
dea3101e | 332 | |
fa4066b6 | 333 | els_iocb_free_pbuf_exit: |
eaf15d5b JS |
334 | if (expectRsp) |
335 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | |
fa4066b6 JS |
336 | kfree(pbuflist); |
337 | ||
338 | els_iocb_free_prsp_exit: | |
339 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); | |
340 | kfree(prsp); | |
341 | ||
342 | els_iocb_free_pcmb_exit: | |
343 | kfree(pcmd); | |
344 | lpfc_sli_release_iocbq(phba, elsiocb); | |
345 | return NULL; | |
346 | } | |
dea3101e | 347 | |
e59058c4 | 348 | /** |
3621a710 | 349 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
e59058c4 JS |
350 | * @vport: pointer to a host virtual N_Port data structure. |
351 | * | |
352 | * This routine issues a fabric registration login for a @vport. An | |
353 | * active ndlp node with Fabric_DID must already exist for this @vport. | |
354 | * The routine invokes two mailbox commands to carry out fabric registration | |
355 | * login through the HBA firmware: the first mailbox command requests the | |
356 | * HBA to perform link configuration for the @vport; and the second mailbox | |
357 | * command requests the HBA to perform the actual fabric registration login | |
358 | * with the @vport. | |
359 | * | |
360 | * Return code | |
361 | * 0 - successfully issued fabric registration login for @vport | |
362 | * -ENXIO -- failed to issue fabric registration login for @vport | |
363 | **/ | |
3772a991 | 364 | int |
92d7f7b0 | 365 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
dea3101e | 366 | { |
2e0fef85 | 367 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 368 | LPFC_MBOXQ_t *mbox; |
14691150 | 369 | struct lpfc_dmabuf *mp; |
92d7f7b0 JS |
370 | struct lpfc_nodelist *ndlp; |
371 | struct serv_parm *sp; | |
dea3101e | 372 | int rc; |
98c9ea5c | 373 | int err = 0; |
dea3101e | 374 | |
92d7f7b0 JS |
375 | sp = &phba->fc_fabparam; |
376 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
e47c9093 | 377 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
98c9ea5c | 378 | err = 1; |
92d7f7b0 | 379 | goto fail; |
98c9ea5c | 380 | } |
92d7f7b0 JS |
381 | |
382 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
383 | if (!mbox) { |
384 | err = 2; | |
92d7f7b0 | 385 | goto fail; |
98c9ea5c | 386 | } |
92d7f7b0 JS |
387 | |
388 | vport->port_state = LPFC_FABRIC_CFG_LINK; | |
389 | lpfc_config_link(phba, mbox); | |
390 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
391 | mbox->vport = vport; | |
392 | ||
0b727fea | 393 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
394 | if (rc == MBX_NOT_FINISHED) { |
395 | err = 3; | |
92d7f7b0 | 396 | goto fail_free_mbox; |
98c9ea5c | 397 | } |
92d7f7b0 JS |
398 | |
399 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
400 | if (!mbox) { |
401 | err = 4; | |
92d7f7b0 | 402 | goto fail; |
98c9ea5c | 403 | } |
4042629e JS |
404 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
405 | ndlp->nlp_rpi); | |
98c9ea5c JS |
406 | if (rc) { |
407 | err = 5; | |
92d7f7b0 | 408 | goto fail_free_mbox; |
98c9ea5c | 409 | } |
92d7f7b0 JS |
410 | |
411 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; | |
412 | mbox->vport = vport; | |
e47c9093 JS |
413 | /* increment the reference count on ndlp to hold reference |
414 | * for the callback routine. | |
415 | */ | |
92d7f7b0 JS |
416 | mbox->context2 = lpfc_nlp_get(ndlp); |
417 | ||
0b727fea | 418 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
419 | if (rc == MBX_NOT_FINISHED) { |
420 | err = 6; | |
92d7f7b0 | 421 | goto fail_issue_reg_login; |
98c9ea5c | 422 | } |
92d7f7b0 JS |
423 | |
424 | return 0; | |
425 | ||
426 | fail_issue_reg_login: | |
e47c9093 JS |
427 | /* decrement the reference count on ndlp just incremented |
428 | * for the failed mbox command. | |
429 | */ | |
92d7f7b0 JS |
430 | lpfc_nlp_put(ndlp); |
431 | mp = (struct lpfc_dmabuf *) mbox->context1; | |
432 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
433 | kfree(mp); | |
434 | fail_free_mbox: | |
435 | mempool_free(mbox, phba->mbox_mem_pool); | |
436 | ||
437 | fail: | |
438 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 | 439 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
98c9ea5c | 440 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
92d7f7b0 JS |
441 | return -ENXIO; |
442 | } | |
443 | ||
6fb120a7 JS |
444 | /** |
445 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login | |
446 | * @vport: pointer to a host virtual N_Port data structure. | |
447 | * | |
448 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for | |
1b51197d | 449 | * the @vport. This mailbox command is necessary for SLI4 port only. |
6fb120a7 JS |
450 | * |
451 | * Return code | |
452 | * 0 - successfully issued REG_VFI for @vport | |
453 | * A failure code otherwise. | |
454 | **/ | |
1b51197d | 455 | int |
6fb120a7 JS |
456 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
457 | { | |
458 | struct lpfc_hba *phba = vport->phba; | |
d6de08cc | 459 | LPFC_MBOXQ_t *mboxq = NULL; |
6fb120a7 | 460 | struct lpfc_nodelist *ndlp; |
d6de08cc | 461 | struct lpfc_dmabuf *dmabuf = NULL; |
6fb120a7 JS |
462 | int rc = 0; |
463 | ||
939723a4 | 464 | /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ |
1b51197d | 465 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
939723a4 JS |
466 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
467 | !(vport->fc_flag & FC_PT2PT)) { | |
1b51197d JS |
468 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
469 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
470 | rc = -ENODEV; | |
471 | goto fail; | |
472 | } | |
6fb120a7 JS |
473 | } |
474 | ||
d6de08cc JS |
475 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
476 | if (!mboxq) { | |
6fb120a7 JS |
477 | rc = -ENOMEM; |
478 | goto fail; | |
479 | } | |
6d368e53 | 480 | |
d6de08cc JS |
481 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
482 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { | |
483 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
484 | if (!dmabuf) { | |
485 | rc = -ENOMEM; | |
486 | goto fail; | |
487 | } | |
488 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); | |
489 | if (!dmabuf->virt) { | |
490 | rc = -ENOMEM; | |
491 | goto fail; | |
492 | } | |
493 | memcpy(dmabuf->virt, &phba->fc_fabparam, | |
494 | sizeof(struct serv_parm)); | |
6fb120a7 | 495 | } |
d6de08cc | 496 | |
6fb120a7 | 497 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
d6de08cc JS |
498 | if (dmabuf) |
499 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); | |
500 | else | |
501 | lpfc_reg_vfi(mboxq, vport, 0); | |
ae05ebe3 | 502 | |
6fb120a7 JS |
503 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
504 | mboxq->vport = vport; | |
505 | mboxq->context1 = dmabuf; | |
506 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
507 | if (rc == MBX_NOT_FINISHED) { | |
508 | rc = -ENXIO; | |
d6de08cc | 509 | goto fail; |
6fb120a7 JS |
510 | } |
511 | return 0; | |
512 | ||
6fb120a7 | 513 | fail: |
d6de08cc JS |
514 | if (mboxq) |
515 | mempool_free(mboxq, phba->mbox_mem_pool); | |
516 | if (dmabuf) { | |
517 | if (dmabuf->virt) | |
518 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | |
519 | kfree(dmabuf); | |
520 | } | |
521 | ||
6fb120a7 JS |
522 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
523 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
524 | "0289 Issue Register VFI failed: Err %d\n", rc); | |
525 | return rc; | |
526 | } | |
527 | ||
1b51197d JS |
528 | /** |
529 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login | |
530 | * @vport: pointer to a host virtual N_Port data structure. | |
531 | * | |
532 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for | |
533 | * the @vport. This mailbox command is necessary for SLI4 port only. | |
534 | * | |
535 | * Return code | |
536 | * 0 - successfully issued REG_VFI for @vport | |
537 | * A failure code otherwise. | |
538 | **/ | |
539 | int | |
540 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) | |
541 | { | |
542 | struct lpfc_hba *phba = vport->phba; | |
543 | struct Scsi_Host *shost; | |
544 | LPFC_MBOXQ_t *mboxq; | |
545 | int rc; | |
546 | ||
547 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
548 | if (!mboxq) { | |
549 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
550 | "2556 UNREG_VFI mbox allocation failed" | |
551 | "HBA state x%x\n", phba->pport->port_state); | |
552 | return -ENOMEM; | |
553 | } | |
554 | ||
555 | lpfc_unreg_vfi(mboxq, vport); | |
556 | mboxq->vport = vport; | |
557 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; | |
558 | ||
559 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
560 | if (rc == MBX_NOT_FINISHED) { | |
561 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
562 | "2557 UNREG_VFI issue mbox failed rc x%x " | |
563 | "HBA state x%x\n", | |
564 | rc, phba->pport->port_state); | |
565 | mempool_free(mboxq, phba->mbox_mem_pool); | |
566 | return -EIO; | |
567 | } | |
568 | ||
569 | shost = lpfc_shost_from_vport(vport); | |
570 | spin_lock_irq(shost->host_lock); | |
571 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
572 | spin_unlock_irq(shost->host_lock); | |
573 | return 0; | |
574 | } | |
575 | ||
92494144 JS |
576 | /** |
577 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. | |
578 | * @vport: pointer to a host virtual N_Port data structure. | |
579 | * @sp: pointer to service parameter data structure. | |
580 | * | |
581 | * This routine is called from FLOGI/FDISC completion handler functions. | |
582 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric | |
583 | * node nodename is changed in the completion service parameter else return | |
584 | * 0. This function also set flag in the vport data structure to delay | |
585 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit | |
586 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric | |
587 | * node nodename is changed in the completion service parameter. | |
588 | * | |
589 | * Return code | |
590 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. | |
591 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. | |
592 | * | |
593 | **/ | |
594 | static uint8_t | |
595 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, | |
596 | struct serv_parm *sp) | |
597 | { | |
8eb8b960 | 598 | struct lpfc_hba *phba = vport->phba; |
92494144 JS |
599 | uint8_t fabric_param_changed = 0; |
600 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
601 | ||
602 | if ((vport->fc_prevDID != vport->fc_myDID) || | |
603 | memcmp(&vport->fabric_portname, &sp->portName, | |
604 | sizeof(struct lpfc_name)) || | |
605 | memcmp(&vport->fabric_nodename, &sp->nodeName, | |
606 | sizeof(struct lpfc_name))) | |
607 | fabric_param_changed = 1; | |
608 | ||
609 | /* | |
610 | * Word 1 Bit 31 in common service parameter is overloaded. | |
611 | * Word 1 Bit 31 in FLOGI request is multiple NPort request | |
612 | * Word 1 Bit 31 in FLOGI response is clean address bit | |
613 | * | |
614 | * If fabric parameter is changed and clean address bit is | |
615 | * cleared delay nport discovery if | |
616 | * - vport->fc_prevDID != 0 (not initial discovery) OR | |
617 | * - lpfc_delay_discovery module parameter is set. | |
618 | */ | |
619 | if (fabric_param_changed && !sp->cmn.clean_address_bit && | |
8eb8b960 | 620 | (vport->fc_prevDID || phba->cfg_delay_discovery)) { |
92494144 JS |
621 | spin_lock_irq(shost->host_lock); |
622 | vport->fc_flag |= FC_DISC_DELAYED; | |
623 | spin_unlock_irq(shost->host_lock); | |
624 | } | |
625 | ||
626 | return fabric_param_changed; | |
627 | } | |
628 | ||
629 | ||
e59058c4 | 630 | /** |
3621a710 | 631 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
e59058c4 JS |
632 | * @vport: pointer to a host virtual N_Port data structure. |
633 | * @ndlp: pointer to a node-list data structure. | |
634 | * @sp: pointer to service parameter data structure. | |
635 | * @irsp: pointer to the IOCB within the lpfc response IOCB. | |
636 | * | |
637 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | |
638 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric | |
639 | * port in a fabric topology. It properly sets up the parameters to the @ndlp | |
640 | * from the IOCB response. It also check the newly assigned N_Port ID to the | |
641 | * @vport against the previously assigned N_Port ID. If it is different from | |
642 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine | |
643 | * is invoked on all the remaining nodes with the @vport to unregister the | |
644 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() | |
645 | * is invoked to register login to the fabric. | |
646 | * | |
647 | * Return code | |
648 | * 0 - Success (currently, always return 0) | |
649 | **/ | |
92d7f7b0 JS |
650 | static int |
651 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
652 | struct serv_parm *sp, IOCB_t *irsp) | |
653 | { | |
654 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
655 | struct lpfc_hba *phba = vport->phba; | |
656 | struct lpfc_nodelist *np; | |
657 | struct lpfc_nodelist *next_np; | |
92494144 | 658 | uint8_t fabric_param_changed; |
92d7f7b0 | 659 | |
2e0fef85 JS |
660 | spin_lock_irq(shost->host_lock); |
661 | vport->fc_flag |= FC_FABRIC; | |
662 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
663 | |
664 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); | |
665 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ | |
666 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; | |
667 | ||
12265f68 | 668 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
dea3101e JB |
669 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
670 | ||
76a95d75 | 671 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 JS |
672 | spin_lock_irq(shost->host_lock); |
673 | vport->fc_flag |= FC_PUBLIC_LOOP; | |
674 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
675 | } |
676 | ||
2e0fef85 | 677 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
dea3101e | 678 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
92d7f7b0 | 679 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
dea3101e JB |
680 | ndlp->nlp_class_sup = 0; |
681 | if (sp->cls1.classValid) | |
682 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
683 | if (sp->cls2.classValid) | |
684 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
685 | if (sp->cls3.classValid) | |
686 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
687 | if (sp->cls4.classValid) | |
688 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
689 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | | |
690 | sp->cmn.bbRcvSizeLsb; | |
92494144 JS |
691 | |
692 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | |
4258e98e JS |
693 | if (fabric_param_changed) { |
694 | /* Reset FDMI attribute masks based on config parameter */ | |
8663cbbe JS |
695 | if (phba->cfg_enable_SmartSAN || |
696 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { | |
4258e98e JS |
697 | /* Setup appropriate attribute masks */ |
698 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; | |
8663cbbe | 699 | if (phba->cfg_enable_SmartSAN) |
4258e98e JS |
700 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
701 | else | |
702 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; | |
8663cbbe JS |
703 | } else { |
704 | vport->fdmi_hba_mask = 0; | |
705 | vport->fdmi_port_mask = 0; | |
4258e98e JS |
706 | } |
707 | ||
708 | } | |
92494144 JS |
709 | memcpy(&vport->fabric_portname, &sp->portName, |
710 | sizeof(struct lpfc_name)); | |
711 | memcpy(&vport->fabric_nodename, &sp->nodeName, | |
712 | sizeof(struct lpfc_name)); | |
dea3101e JB |
713 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
714 | ||
92d7f7b0 JS |
715 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
716 | if (sp->cmn.response_multiple_NPort) { | |
e8b62011 JS |
717 | lpfc_printf_vlog(vport, KERN_WARNING, |
718 | LOG_ELS | LOG_VPORT, | |
719 | "1816 FLOGI NPIV supported, " | |
720 | "response data 0x%x\n", | |
721 | sp->cmn.response_multiple_NPort); | |
1b51197d | 722 | spin_lock_irq(&phba->hbalock); |
92d7f7b0 | 723 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
1b51197d | 724 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 JS |
725 | } else { |
726 | /* Because we asked f/w for NPIV it still expects us | |
e8b62011 JS |
727 | to call reg_vnpid atleast for the physcial host */ |
728 | lpfc_printf_vlog(vport, KERN_WARNING, | |
729 | LOG_ELS | LOG_VPORT, | |
730 | "1817 Fabric does not support NPIV " | |
731 | "- configuring single port mode.\n"); | |
1b51197d | 732 | spin_lock_irq(&phba->hbalock); |
92d7f7b0 | 733 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
1b51197d | 734 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 JS |
735 | } |
736 | } | |
dea3101e | 737 | |
ae05ebe3 JS |
738 | /* |
739 | * For FC we need to do some special processing because of the SLI | |
740 | * Port's default settings of the Common Service Parameters. | |
741 | */ | |
d6de08cc JS |
742 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
743 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { | |
ae05ebe3 | 744 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
d6de08cc | 745 | if (fabric_param_changed) |
ae05ebe3 JS |
746 | lpfc_unregister_fcf_prep(phba); |
747 | ||
748 | /* This should just update the VFI CSPs*/ | |
749 | if (vport->fc_flag & FC_VFI_REGISTERED) | |
750 | lpfc_issue_reg_vfi(vport); | |
751 | } | |
752 | ||
92494144 | 753 | if (fabric_param_changed && |
92d7f7b0 | 754 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
dea3101e | 755 | |
92d7f7b0 JS |
756 | /* If our NportID changed, we need to ensure all |
757 | * remaining NPORTs get unreg_login'ed. | |
758 | */ | |
759 | list_for_each_entry_safe(np, next_np, | |
760 | &vport->fc_nodes, nlp_listp) { | |
d7c255b2 | 761 | if (!NLP_CHK_NODE_ACT(np)) |
e47c9093 | 762 | continue; |
92d7f7b0 JS |
763 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
764 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
765 | continue; | |
766 | spin_lock_irq(shost->host_lock); | |
767 | np->nlp_flag &= ~NLP_NPR_ADISC; | |
768 | spin_unlock_irq(shost->host_lock); | |
769 | lpfc_unreg_rpi(vport, np); | |
770 | } | |
78730cfe | 771 | lpfc_cleanup_pending_mbox(vport); |
5af5eee7 | 772 | |
5248a749 | 773 | if (phba->sli_rev == LPFC_SLI_REV4) { |
5af5eee7 | 774 | lpfc_sli4_unreg_all_rpis(vport); |
92d7f7b0 | 775 | lpfc_mbx_unreg_vpi(vport); |
09372820 | 776 | spin_lock_irq(shost->host_lock); |
ecfd03c6 JS |
777 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
778 | spin_unlock_irq(shost->host_lock); | |
779 | } | |
27aa1b73 JS |
780 | |
781 | /* | |
782 | * For SLI3 and SLI4, the VPI needs to be reregistered in | |
783 | * response to this fabric parameter change event. | |
784 | */ | |
785 | spin_lock_irq(shost->host_lock); | |
786 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
787 | spin_unlock_irq(shost->host_lock); | |
38b92ef8 JS |
788 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
789 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
790 | /* | |
791 | * Driver needs to re-reg VPI in order for f/w | |
792 | * to update the MAC address. | |
793 | */ | |
9589b062 | 794 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
38b92ef8 JS |
795 | lpfc_register_new_vport(phba, vport, ndlp); |
796 | return 0; | |
92d7f7b0 | 797 | } |
dea3101e | 798 | |
6fb120a7 JS |
799 | if (phba->sli_rev < LPFC_SLI_REV4) { |
800 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); | |
801 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && | |
802 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | |
803 | lpfc_register_new_vport(phba, vport, ndlp); | |
804 | else | |
805 | lpfc_issue_fabric_reglogin(vport); | |
806 | } else { | |
807 | ndlp->nlp_type |= NLP_FABRIC; | |
808 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | |
695a814e JS |
809 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
810 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { | |
6fb120a7 JS |
811 | lpfc_start_fdiscs(phba); |
812 | lpfc_do_scr_ns_plogi(phba, vport); | |
695a814e | 813 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
ecfd03c6 | 814 | lpfc_issue_init_vpi(vport); |
1b51197d JS |
815 | else { |
816 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
817 | "3135 Need register VFI: (x%x/%x)\n", | |
818 | vport->fc_prevDID, vport->fc_myDID); | |
6fb120a7 | 819 | lpfc_issue_reg_vfi(vport); |
1b51197d | 820 | } |
92d7f7b0 | 821 | } |
dea3101e | 822 | return 0; |
dea3101e | 823 | } |
1b51197d | 824 | |
e59058c4 | 825 | /** |
3621a710 | 826 | * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port |
e59058c4 JS |
827 | * @vport: pointer to a host virtual N_Port data structure. |
828 | * @ndlp: pointer to a node-list data structure. | |
829 | * @sp: pointer to service parameter data structure. | |
830 | * | |
831 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | |
832 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port | |
833 | * in a point-to-point topology. First, the @vport's N_Port Name is compared | |
834 | * with the received N_Port Name: if the @vport's N_Port Name is greater than | |
835 | * the received N_Port Name lexicographically, this node shall assign local | |
836 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and | |
837 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, | |
838 | * this node shall just wait for the remote node to issue PLOGI and assign | |
839 | * N_Port IDs. | |
840 | * | |
841 | * Return code | |
842 | * 0 - Success | |
843 | * -ENXIO - Fail | |
844 | **/ | |
dea3101e | 845 | static int |
2e0fef85 JS |
846 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
847 | struct serv_parm *sp) | |
dea3101e | 848 | { |
2e0fef85 JS |
849 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
850 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
851 | LPFC_MBOXQ_t *mbox; |
852 | int rc; | |
853 | ||
2e0fef85 JS |
854 | spin_lock_irq(shost->host_lock); |
855 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
d6de08cc | 856 | vport->fc_flag |= FC_PT2PT; |
2e0fef85 | 857 | spin_unlock_irq(shost->host_lock); |
dea3101e | 858 | |
d6de08cc JS |
859 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
860 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { | |
861 | lpfc_unregister_fcf_prep(phba); | |
862 | ||
863 | spin_lock_irq(shost->host_lock); | |
864 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
865 | spin_unlock_irq(shost->host_lock); | |
866 | phba->fc_topology_changed = 0; | |
867 | } | |
868 | ||
2e0fef85 | 869 | rc = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 870 | sizeof(vport->fc_portname)); |
2eb6862a | 871 | |
dea3101e JB |
872 | if (rc >= 0) { |
873 | /* This side will initiate the PLOGI */ | |
2e0fef85 JS |
874 | spin_lock_irq(shost->host_lock); |
875 | vport->fc_flag |= FC_PT2PT_PLOGI; | |
876 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
877 | |
878 | /* | |
d6de08cc JS |
879 | * N_Port ID cannot be 0, set our Id to LocalID |
880 | * the other side will be RemoteID. | |
dea3101e JB |
881 | */ |
882 | ||
883 | /* not equal */ | |
884 | if (rc) | |
2e0fef85 | 885 | vport->fc_myDID = PT2PT_LocalID; |
dea3101e | 886 | |
e47c9093 JS |
887 | /* Decrement ndlp reference count indicating that ndlp can be |
888 | * safely released when other references to it are done. | |
889 | */ | |
329f9bc7 | 890 | lpfc_nlp_put(ndlp); |
dea3101e | 891 | |
2e0fef85 | 892 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
dea3101e JB |
893 | if (!ndlp) { |
894 | /* | |
895 | * Cannot find existing Fabric ndlp, so allocate a | |
896 | * new one | |
897 | */ | |
898 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
899 | if (!ndlp) | |
900 | goto fail; | |
2e0fef85 | 901 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
e47c9093 JS |
902 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
903 | ndlp = lpfc_enable_node(vport, ndlp, | |
904 | NLP_STE_UNUSED_NODE); | |
905 | if(!ndlp) | |
906 | goto fail; | |
dea3101e JB |
907 | } |
908 | ||
909 | memcpy(&ndlp->nlp_portname, &sp->portName, | |
2e0fef85 | 910 | sizeof(struct lpfc_name)); |
dea3101e | 911 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
2e0fef85 | 912 | sizeof(struct lpfc_name)); |
e47c9093 | 913 | /* Set state will put ndlp onto node list if not already done */ |
2e0fef85 JS |
914 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
915 | spin_lock_irq(shost->host_lock); | |
dea3101e | 916 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 917 | spin_unlock_irq(shost->host_lock); |
e47c9093 JS |
918 | } else |
919 | /* This side will wait for the PLOGI, decrement ndlp reference | |
920 | * count indicating that ndlp can be released when other | |
921 | * references to it are done. | |
922 | */ | |
329f9bc7 | 923 | lpfc_nlp_put(ndlp); |
dea3101e | 924 | |
09372820 JS |
925 | /* If we are pt2pt with another NPort, force NPIV off! */ |
926 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; | |
927 | ||
d6de08cc JS |
928 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
929 | if (!mbox) | |
930 | goto fail; | |
e74c03c8 | 931 | |
d6de08cc JS |
932 | lpfc_config_link(phba, mbox); |
933 | ||
934 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; | |
935 | mbox->vport = vport; | |
936 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
937 | if (rc == MBX_NOT_FINISHED) { | |
938 | mempool_free(mbox, phba->mbox_mem_pool); | |
939 | goto fail; | |
e74c03c8 | 940 | } |
dea3101e | 941 | |
dea3101e | 942 | return 0; |
92d7f7b0 | 943 | fail: |
dea3101e JB |
944 | return -ENXIO; |
945 | } | |
946 | ||
e59058c4 | 947 | /** |
3621a710 | 948 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
e59058c4 JS |
949 | * @phba: pointer to lpfc hba data structure. |
950 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
951 | * @rspiocb: pointer to lpfc response iocb data structure. | |
952 | * | |
953 | * This routine is the top-level completion callback function for issuing | |
954 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, | |
955 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If | |
956 | * retry has been made (either immediately or delayed with lpfc_els_retry() | |
957 | * returning 1), the command IOCB will be released and function returned. | |
958 | * If the retry attempt has been given up (possibly reach the maximum | |
959 | * number of retries), one additional decrement of ndlp reference shall be | |
960 | * invoked before going out after releasing the command IOCB. This will | |
961 | * actually release the remote node (Note, lpfc_els_free_iocb() will also | |
962 | * invoke one decrement of ndlp reference count). If no error reported in | |
963 | * the IOCB status, the command Port ID field is used to determine whether | |
964 | * this is a point-to-point topology or a fabric topology: if the Port ID | |
965 | * field is assigned, it is a fabric topology; otherwise, it is a | |
966 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or | |
967 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the | |
968 | * specific topology completion conditions. | |
969 | **/ | |
dea3101e | 970 | static void |
329f9bc7 JS |
971 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
972 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 973 | { |
2e0fef85 JS |
974 | struct lpfc_vport *vport = cmdiocb->vport; |
975 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e JB |
976 | IOCB_t *irsp = &rspiocb->iocb; |
977 | struct lpfc_nodelist *ndlp = cmdiocb->context1; | |
978 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | |
979 | struct serv_parm *sp; | |
0c9ab6f5 | 980 | uint16_t fcf_index; |
dea3101e JB |
981 | int rc; |
982 | ||
983 | /* Check to see if link went down during discovery */ | |
2e0fef85 | 984 | if (lpfc_els_chk_latt(vport)) { |
fa4066b6 JS |
985 | /* One additional decrement on node reference count to |
986 | * trigger the release of the node | |
987 | */ | |
329f9bc7 | 988 | lpfc_nlp_put(ndlp); |
dea3101e JB |
989 | goto out; |
990 | } | |
991 | ||
858c9f6c JS |
992 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
993 | "FLOGI cmpl: status:x%x/x%x state:x%x", | |
994 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
995 | vport->port_state); | |
996 | ||
dea3101e | 997 | if (irsp->ulpStatus) { |
0c9ab6f5 | 998 | /* |
a93ff37a | 999 | * In case of FIP mode, perform roundrobin FCF failover |
0c9ab6f5 JS |
1000 | * due to new FCF discovery |
1001 | */ | |
1002 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && | |
80c17849 JS |
1003 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
1004 | if (phba->link_state < LPFC_LINK_UP) | |
1005 | goto stop_rr_fcf_flogi; | |
1006 | if ((phba->fcoe_cvl_eventtag_attn == | |
1007 | phba->fcoe_cvl_eventtag) && | |
1008 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
1009 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
1010 | IOERR_SLI_ABORTED)) | |
80c17849 JS |
1011 | goto stop_rr_fcf_flogi; |
1012 | else | |
1013 | phba->fcoe_cvl_eventtag_attn = | |
1014 | phba->fcoe_cvl_eventtag; | |
0c9ab6f5 | 1015 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
a93ff37a JS |
1016 | "2611 FLOGI failed on FCF (x%x), " |
1017 | "status:x%x/x%x, tmo:x%x, perform " | |
1018 | "roundrobin FCF failover\n", | |
38b92ef8 JS |
1019 | phba->fcf.current_rec.fcf_indx, |
1020 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1021 | irsp->ulpTimeout); | |
7d791df7 JS |
1022 | lpfc_sli4_set_fcf_flogi_fail(phba, |
1023 | phba->fcf.current_rec.fcf_indx); | |
0c9ab6f5 | 1024 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
a93ff37a JS |
1025 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
1026 | if (rc) | |
1027 | goto out; | |
0c9ab6f5 JS |
1028 | } |
1029 | ||
80c17849 | 1030 | stop_rr_fcf_flogi: |
38b92ef8 JS |
1031 | /* FLOGI failure */ |
1032 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
8fe5c165 JS |
1033 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
1034 | "Data x%x x%x\n", | |
38b92ef8 | 1035 | irsp->ulpStatus, irsp->un.ulpWord[4], |
8fe5c165 JS |
1036 | irsp->ulpTimeout, phba->hba_flag, |
1037 | phba->fcf.fcf_flag); | |
38b92ef8 | 1038 | |
dea3101e | 1039 | /* Check for retry */ |
2e0fef85 | 1040 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
dea3101e | 1041 | goto out; |
2e0fef85 | 1042 | |
76a95d75 JS |
1043 | /* FLOGI failure */ |
1044 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1045 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", | |
1046 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1047 | irsp->ulpTimeout); | |
1048 | ||
dea3101e | 1049 | /* FLOGI failed, so there is no fabric */ |
2e0fef85 JS |
1050 | spin_lock_irq(shost->host_lock); |
1051 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
1052 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1053 | |
329f9bc7 | 1054 | /* If private loop, then allow max outstanding els to be |
dea3101e JB |
1055 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
1056 | * alpa map would take too long otherwise. | |
1057 | */ | |
1b51197d | 1058 | if (phba->alpa_map[0] == 0) |
3de2a653 | 1059 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
ff78d8f9 JS |
1060 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1061 | (!(vport->fc_flag & FC_VFI_REGISTERED) || | |
e74c03c8 JS |
1062 | (vport->fc_prevDID != vport->fc_myDID) || |
1063 | phba->fc_topology_changed)) { | |
1064 | if (vport->fc_flag & FC_VFI_REGISTERED) { | |
1065 | if (phba->fc_topology_changed) { | |
1066 | lpfc_unregister_fcf_prep(phba); | |
1067 | spin_lock_irq(shost->host_lock); | |
1068 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
1069 | spin_unlock_irq(shost->host_lock); | |
1070 | phba->fc_topology_changed = 0; | |
1071 | } else { | |
1072 | lpfc_sli4_unreg_all_rpis(vport); | |
1073 | } | |
1074 | } | |
342b59ca JS |
1075 | |
1076 | /* Do not register VFI if the driver aborted FLOGI */ | |
1077 | if (!lpfc_error_lost_link(irsp)) | |
1078 | lpfc_issue_reg_vfi(vport); | |
ff78d8f9 JS |
1079 | lpfc_nlp_put(ndlp); |
1080 | goto out; | |
dea3101e | 1081 | } |
dea3101e JB |
1082 | goto flogifail; |
1083 | } | |
695a814e JS |
1084 | spin_lock_irq(shost->host_lock); |
1085 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; | |
4b40c59e | 1086 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
695a814e | 1087 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1088 | |
1089 | /* | |
1090 | * The FLogI succeeded. Sync the data for the CPU before | |
1091 | * accessing it. | |
1092 | */ | |
1093 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | |
a2fc4aef JS |
1094 | if (!prsp) |
1095 | goto out; | |
dea3101e JB |
1096 | sp = prsp->virt + sizeof(uint32_t); |
1097 | ||
1098 | /* FLOGI completes successfully */ | |
e8b62011 | 1099 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
88f43a08 JS |
1100 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
1101 | "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag, | |
e8b62011 | 1102 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
e74c03c8 JS |
1103 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
1104 | vport->port_state, vport->fc_flag); | |
dea3101e | 1105 | |
2e0fef85 | 1106 | if (vport->port_state == LPFC_FLOGI) { |
dea3101e JB |
1107 | /* |
1108 | * If Common Service Parameters indicate Nport | |
1109 | * we are point to point, if Fport we are Fabric. | |
1110 | */ | |
1111 | if (sp->cmn.fPort) | |
2e0fef85 | 1112 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
76a95d75 | 1113 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
2e0fef85 | 1114 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
dbb6b3ab JS |
1115 | else { |
1116 | lpfc_printf_vlog(vport, KERN_ERR, | |
1117 | LOG_FIP | LOG_ELS, | |
1118 | "2831 FLOGI response with cleared Fabric " | |
1119 | "bit fcf_index 0x%x " | |
1120 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " | |
1121 | "Fabric Name " | |
1122 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", | |
1123 | phba->fcf.current_rec.fcf_indx, | |
1124 | phba->fcf.current_rec.switch_name[0], | |
1125 | phba->fcf.current_rec.switch_name[1], | |
1126 | phba->fcf.current_rec.switch_name[2], | |
1127 | phba->fcf.current_rec.switch_name[3], | |
1128 | phba->fcf.current_rec.switch_name[4], | |
1129 | phba->fcf.current_rec.switch_name[5], | |
1130 | phba->fcf.current_rec.switch_name[6], | |
1131 | phba->fcf.current_rec.switch_name[7], | |
1132 | phba->fcf.current_rec.fabric_name[0], | |
1133 | phba->fcf.current_rec.fabric_name[1], | |
1134 | phba->fcf.current_rec.fabric_name[2], | |
1135 | phba->fcf.current_rec.fabric_name[3], | |
1136 | phba->fcf.current_rec.fabric_name[4], | |
1137 | phba->fcf.current_rec.fabric_name[5], | |
1138 | phba->fcf.current_rec.fabric_name[6], | |
1139 | phba->fcf.current_rec.fabric_name[7]); | |
1140 | lpfc_nlp_put(ndlp); | |
1141 | spin_lock_irq(&phba->hbalock); | |
1142 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
a93ff37a | 1143 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
dbb6b3ab JS |
1144 | spin_unlock_irq(&phba->hbalock); |
1145 | goto out; | |
1146 | } | |
0c9ab6f5 JS |
1147 | if (!rc) { |
1148 | /* Mark the FCF discovery process done */ | |
999d813f JS |
1149 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
1150 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | | |
1151 | LOG_ELS, | |
a93ff37a JS |
1152 | "2769 FLOGI to FCF (x%x) " |
1153 | "completed successfully\n", | |
999d813f | 1154 | phba->fcf.current_rec.fcf_indx); |
0c9ab6f5 JS |
1155 | spin_lock_irq(&phba->hbalock); |
1156 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
a93ff37a | 1157 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
0c9ab6f5 | 1158 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1159 | goto out; |
0c9ab6f5 | 1160 | } |
dea3101e JB |
1161 | } |
1162 | ||
1163 | flogifail: | |
8fe5c165 JS |
1164 | spin_lock_irq(&phba->hbalock); |
1165 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
1166 | spin_unlock_irq(&phba->hbalock); | |
d6de08cc | 1167 | |
329f9bc7 | 1168 | lpfc_nlp_put(ndlp); |
dea3101e | 1169 | |
858c9f6c | 1170 | if (!lpfc_error_lost_link(irsp)) { |
dea3101e | 1171 | /* FLOGI failed, so just use loop map to make discovery list */ |
2e0fef85 | 1172 | lpfc_disc_list_loopmap(vport); |
dea3101e JB |
1173 | |
1174 | /* Start discovery */ | |
2e0fef85 | 1175 | lpfc_disc_start(vport); |
87af33fe | 1176 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
e3d2b802 JS |
1177 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
1178 | IOERR_SLI_ABORTED) && | |
1179 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != | |
1180 | IOERR_SLI_DOWN))) && | |
87af33fe JS |
1181 | (phba->link_state != LPFC_CLEAR_LA)) { |
1182 | /* If FLOGI failed enable link interrupt. */ | |
1183 | lpfc_issue_clear_la(phba, vport); | |
dea3101e | 1184 | } |
dea3101e JB |
1185 | out: |
1186 | lpfc_els_free_iocb(phba, cmdiocb); | |
1187 | } | |
1188 | ||
e59058c4 | 1189 | /** |
3621a710 | 1190 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
e59058c4 JS |
1191 | * @vport: pointer to a host virtual N_Port data structure. |
1192 | * @ndlp: pointer to a node-list data structure. | |
1193 | * @retry: number of retries to the command IOCB. | |
1194 | * | |
1195 | * This routine issues a Fabric Login (FLOGI) Request ELS command | |
1196 | * for a @vport. The initiator service parameters are put into the payload | |
1197 | * of the FLOGI Request IOCB and the top-level callback function pointer | |
1198 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback | |
1199 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send | |
1200 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. | |
1201 | * | |
1202 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
1203 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
1204 | * will be stored into the context1 field of the IOCB for the completion | |
1205 | * callback function to the FLOGI ELS command. | |
1206 | * | |
1207 | * Return code | |
1208 | * 0 - successfully issued flogi iocb for @vport | |
1209 | * 1 - failed to issue flogi iocb for @vport | |
1210 | **/ | |
dea3101e | 1211 | static int |
2e0fef85 | 1212 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
1213 | uint8_t retry) |
1214 | { | |
2e0fef85 | 1215 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1216 | struct serv_parm *sp; |
1217 | IOCB_t *icmd; | |
1218 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
1219 | uint8_t *pcmd; |
1220 | uint16_t cmdsize; | |
1221 | uint32_t tmo; | |
1222 | int rc; | |
1223 | ||
92d7f7b0 | 1224 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
2e0fef85 JS |
1225 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
1226 | ndlp->nlp_DID, ELS_CMD_FLOGI); | |
92d7f7b0 | 1227 | |
488d1469 | 1228 | if (!elsiocb) |
c9f8735b | 1229 | return 1; |
dea3101e JB |
1230 | |
1231 | icmd = &elsiocb->iocb; | |
1232 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1233 | ||
1234 | /* For FLOGI request, remainder of payload is service parameters */ | |
1235 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; | |
92d7f7b0 JS |
1236 | pcmd += sizeof(uint32_t); |
1237 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
1238 | sp = (struct serv_parm *) pcmd; |
1239 | ||
1240 | /* Setup CSPs accordingly for Fabric */ | |
1241 | sp->cmn.e_d_tov = 0; | |
1242 | sp->cmn.w2.r_a_tov = 0; | |
df9e1b59 | 1243 | sp->cmn.virtual_fabric_support = 0; |
dea3101e | 1244 | sp->cls1.classValid = 0; |
dea3101e JB |
1245 | if (sp->cmn.fcphLow < FC_PH3) |
1246 | sp->cmn.fcphLow = FC_PH3; | |
1247 | if (sp->cmn.fcphHigh < FC_PH3) | |
1248 | sp->cmn.fcphHigh = FC_PH3; | |
1249 | ||
c31098ce JS |
1250 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1251 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
1252 | LPFC_SLI_INTF_IF_TYPE_0) { | |
1253 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); | |
1254 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); | |
1255 | /* FLOGI needs to be 3 for WQE FCFI */ | |
1256 | /* Set the fcfi to the fcfi we registered with */ | |
1257 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; | |
1258 | } | |
0f37887e JS |
1259 | /* Can't do SLI4 class2 without support sequence coalescing */ |
1260 | sp->cls2.classValid = 0; | |
1261 | sp->cls2.seqDelivery = 0; | |
5248a749 | 1262 | } else { |
0f37887e JS |
1263 | /* Historical, setting sequential-delivery bit for SLI3 */ |
1264 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; | |
1265 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; | |
5248a749 JS |
1266 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
1267 | sp->cmn.request_multiple_Nport = 1; | |
1268 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ | |
1269 | icmd->ulpCt_h = 1; | |
1270 | icmd->ulpCt_l = 0; | |
1271 | } else | |
1272 | sp->cmn.request_multiple_Nport = 0; | |
92d7f7b0 JS |
1273 | } |
1274 | ||
76a95d75 | 1275 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
858c9f6c JS |
1276 | icmd->un.elsreq64.myID = 0; |
1277 | icmd->un.elsreq64.fl = 1; | |
1278 | } | |
1279 | ||
dea3101e JB |
1280 | tmo = phba->fc_ratov; |
1281 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; | |
2e0fef85 | 1282 | lpfc_set_disctmo(vport); |
dea3101e JB |
1283 | phba->fc_ratov = tmo; |
1284 | ||
1285 | phba->fc_stat.elsXmitFLOGI++; | |
1286 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; | |
858c9f6c JS |
1287 | |
1288 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
1289 | "Issue FLOGI: opt:x%x", | |
1290 | phba->sli3_options, 0, 0); | |
1291 | ||
92d7f7b0 | 1292 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
dea3101e JB |
1293 | if (rc == IOCB_ERROR) { |
1294 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 1295 | return 1; |
dea3101e | 1296 | } |
c9f8735b | 1297 | return 0; |
dea3101e JB |
1298 | } |
1299 | ||
e59058c4 | 1300 | /** |
3621a710 | 1301 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
e59058c4 JS |
1302 | * @phba: pointer to lpfc hba data structure. |
1303 | * | |
1304 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs | |
1305 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq | |
1306 | * list and issues an abort IOCB commond on each outstanding IOCB that | |
1307 | * contains a active Fabric_DID ndlp. Note that this function is to issue | |
1308 | * the abort IOCB command on all the outstanding IOCBs, thus when this | |
1309 | * function returns, it does not guarantee all the IOCBs are actually aborted. | |
1310 | * | |
1311 | * Return code | |
3ad2f3fb | 1312 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
e59058c4 | 1313 | **/ |
dea3101e | 1314 | int |
2e0fef85 | 1315 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
dea3101e JB |
1316 | { |
1317 | struct lpfc_sli_ring *pring; | |
1318 | struct lpfc_iocbq *iocb, *next_iocb; | |
1319 | struct lpfc_nodelist *ndlp; | |
1320 | IOCB_t *icmd; | |
1321 | ||
1322 | /* Abort outstanding I/O on NPort <nlp_DID> */ | |
1323 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
e8b62011 JS |
1324 | "0201 Abort outstanding I/O on NPort x%x\n", |
1325 | Fabric_DID); | |
dea3101e | 1326 | |
895427bd | 1327 | pring = lpfc_phba_elsring(phba); |
dea3101e JB |
1328 | |
1329 | /* | |
1330 | * Check the txcmplq for an iocb that matches the nport the driver is | |
1331 | * searching for. | |
1332 | */ | |
2e0fef85 | 1333 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1334 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
1335 | icmd = &iocb->iocb; | |
1b51197d | 1336 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
dea3101e | 1337 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
58da1ffb JS |
1338 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
1339 | (ndlp->nlp_DID == Fabric_DID)) | |
07951076 | 1340 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
dea3101e JB |
1341 | } |
1342 | } | |
2e0fef85 | 1343 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1344 | |
1345 | return 0; | |
1346 | } | |
1347 | ||
e59058c4 | 1348 | /** |
3621a710 | 1349 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
e59058c4 JS |
1350 | * @vport: pointer to a host virtual N_Port data structure. |
1351 | * | |
1352 | * This routine issues an initial Fabric Login (FLOGI) for the @vport | |
1353 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | |
1354 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | |
1355 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | |
1356 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine | |
1357 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the | |
1358 | * @vport. | |
1359 | * | |
1360 | * Return code | |
1361 | * 0 - failed to issue initial flogi for @vport | |
1362 | * 1 - successfully issued initial flogi for @vport | |
1363 | **/ | |
dea3101e | 1364 | int |
2e0fef85 | 1365 | lpfc_initial_flogi(struct lpfc_vport *vport) |
dea3101e | 1366 | { |
2e0fef85 | 1367 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1368 | struct lpfc_nodelist *ndlp; |
1369 | ||
98c9ea5c JS |
1370 | vport->port_state = LPFC_FLOGI; |
1371 | lpfc_set_disctmo(vport); | |
1372 | ||
c9f8735b | 1373 | /* First look for the Fabric ndlp */ |
2e0fef85 | 1374 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
c9f8735b | 1375 | if (!ndlp) { |
dea3101e | 1376 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b JW |
1377 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
1378 | if (!ndlp) | |
1379 | return 0; | |
2e0fef85 | 1380 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
6fb120a7 JS |
1381 | /* Set the node type */ |
1382 | ndlp->nlp_type |= NLP_FABRIC; | |
e47c9093 JS |
1383 | /* Put ndlp onto node list */ |
1384 | lpfc_enqueue_node(vport, ndlp); | |
1385 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1386 | /* re-setup ndlp without removing from node list */ | |
1387 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1388 | if (!ndlp) | |
1389 | return 0; | |
dea3101e | 1390 | } |
87af33fe | 1391 | |
5ac6b303 | 1392 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
fa4066b6 JS |
1393 | /* This decrement of reference count to node shall kick off |
1394 | * the release of the node. | |
1395 | */ | |
329f9bc7 | 1396 | lpfc_nlp_put(ndlp); |
5ac6b303 JS |
1397 | return 0; |
1398 | } | |
c9f8735b | 1399 | return 1; |
dea3101e JB |
1400 | } |
1401 | ||
e59058c4 | 1402 | /** |
3621a710 | 1403 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
e59058c4 JS |
1404 | * @vport: pointer to a host virtual N_Port data structure. |
1405 | * | |
1406 | * This routine issues an initial Fabric Discover (FDISC) for the @vport | |
1407 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | |
1408 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | |
1409 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | |
1410 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine | |
1411 | * is then invoked with the @vport and the ndlp to perform the FDISC for the | |
1412 | * @vport. | |
1413 | * | |
1414 | * Return code | |
1415 | * 0 - failed to issue initial fdisc for @vport | |
1416 | * 1 - successfully issued initial fdisc for @vport | |
1417 | **/ | |
92d7f7b0 JS |
1418 | int |
1419 | lpfc_initial_fdisc(struct lpfc_vport *vport) | |
1420 | { | |
1421 | struct lpfc_hba *phba = vport->phba; | |
1422 | struct lpfc_nodelist *ndlp; | |
1423 | ||
1424 | /* First look for the Fabric ndlp */ | |
1425 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
1426 | if (!ndlp) { | |
1427 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
1428 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
1429 | if (!ndlp) | |
1430 | return 0; | |
1431 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
e47c9093 JS |
1432 | /* Put ndlp onto node list */ |
1433 | lpfc_enqueue_node(vport, ndlp); | |
1434 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1435 | /* re-setup ndlp without removing from node list */ | |
1436 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1437 | if (!ndlp) | |
1438 | return 0; | |
92d7f7b0 | 1439 | } |
e47c9093 | 1440 | |
92d7f7b0 | 1441 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
fa4066b6 JS |
1442 | /* decrement node reference count to trigger the release of |
1443 | * the node. | |
1444 | */ | |
92d7f7b0 | 1445 | lpfc_nlp_put(ndlp); |
fa4066b6 | 1446 | return 0; |
92d7f7b0 JS |
1447 | } |
1448 | return 1; | |
1449 | } | |
87af33fe | 1450 | |
e59058c4 | 1451 | /** |
3621a710 | 1452 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
e59058c4 JS |
1453 | * @vport: pointer to a host virtual N_Port data structure. |
1454 | * | |
1455 | * This routine checks whether there are more remaining Port Logins | |
1456 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine | |
1457 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes | |
1458 | * to issue ELS PLOGIs up to the configured discover threads with the | |
1459 | * @vport (@vport->cfg_discovery_threads). The function also decrement | |
1460 | * the @vport's num_disc_node by 1 if it is not already 0. | |
1461 | **/ | |
87af33fe | 1462 | void |
2e0fef85 | 1463 | lpfc_more_plogi(struct lpfc_vport *vport) |
dea3101e | 1464 | { |
2e0fef85 JS |
1465 | if (vport->num_disc_nodes) |
1466 | vport->num_disc_nodes--; | |
dea3101e JB |
1467 | |
1468 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ | |
e8b62011 JS |
1469 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1470 | "0232 Continue discovery with %d PLOGIs to go " | |
1471 | "Data: x%x x%x x%x\n", | |
1472 | vport->num_disc_nodes, vport->fc_plogi_cnt, | |
1473 | vport->fc_flag, vport->port_state); | |
dea3101e | 1474 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 JS |
1475 | if (vport->fc_flag & FC_NLP_MORE) |
1476 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | |
db6f1c2f | 1477 | lpfc_els_disc_plogi(vport); |
2e0fef85 | 1478 | |
dea3101e JB |
1479 | return; |
1480 | } | |
1481 | ||
e59058c4 | 1482 | /** |
3621a710 | 1483 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
e59058c4 JS |
1484 | * @phba: pointer to lpfc hba data structure. |
1485 | * @prsp: pointer to response IOCB payload. | |
1486 | * @ndlp: pointer to a node-list data structure. | |
1487 | * | |
1488 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved | |
1489 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. | |
1490 | * The following cases are considered N_Port confirmed: | |
1491 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches | |
1492 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but | |
1493 | * it does not have WWPN assigned either. If the WWPN is confirmed, the | |
1494 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: | |
1495 | * 1) if there is a node on vport list other than the @ndlp with the same | |
1496 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked | |
1497 | * on that node to release the RPI associated with the node; 2) if there is | |
1498 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged | |
1499 | * into, a new node shall be allocated (or activated). In either case, the | |
1500 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall | |
1501 | * be released and the new_ndlp shall be put on to the vport node list and | |
1502 | * its pointer returned as the confirmed node. | |
1503 | * | |
1504 | * Note that before the @ndlp got "released", the keepDID from not-matching | |
1505 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID | |
1506 | * of the @ndlp. This is because the release of @ndlp is actually to put it | |
1507 | * into an inactive state on the vport node list and the vport node list | |
1508 | * management algorithm does not allow two node with a same DID. | |
1509 | * | |
1510 | * Return code | |
1511 | * pointer to the PLOGI N_Port @ndlp | |
1512 | **/ | |
488d1469 | 1513 | static struct lpfc_nodelist * |
92d7f7b0 | 1514 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
488d1469 JS |
1515 | struct lpfc_nodelist *ndlp) |
1516 | { | |
a0f2d3ef | 1517 | struct lpfc_vport *vport = ndlp->vport; |
953ceeda | 1518 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
488d1469 | 1519 | struct lpfc_nodelist *new_ndlp; |
0ff10d46 JS |
1520 | struct lpfc_rport_data *rdata; |
1521 | struct fc_rport *rport; | |
488d1469 | 1522 | struct serv_parm *sp; |
92d7f7b0 | 1523 | uint8_t name[sizeof(struct lpfc_name)]; |
e5abba4c | 1524 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
953ceeda | 1525 | uint16_t keep_nlp_state; |
38b92ef8 JS |
1526 | int put_node; |
1527 | int put_rport; | |
cff261f6 | 1528 | unsigned long *active_rrqs_xri_bitmap = NULL; |
488d1469 | 1529 | |
2fb9bd8b JS |
1530 | /* Fabric nodes can have the same WWPN so we don't bother searching |
1531 | * by WWPN. Just return the ndlp that was given to us. | |
1532 | */ | |
1533 | if (ndlp->nlp_type & NLP_FABRIC) | |
1534 | return ndlp; | |
1535 | ||
92d7f7b0 | 1536 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
685f0bf7 | 1537 | memset(name, 0, sizeof(struct lpfc_name)); |
488d1469 | 1538 | |
685f0bf7 | 1539 | /* Now we find out if the NPort we are logging into, matches the WWPN |
488d1469 JS |
1540 | * we have for that ndlp. If not, we have some work to do. |
1541 | */ | |
2e0fef85 | 1542 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
488d1469 | 1543 | |
e47c9093 | 1544 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
488d1469 | 1545 | return ndlp; |
cff261f6 JS |
1546 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1547 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, | |
1548 | GFP_KERNEL); | |
1549 | if (active_rrqs_xri_bitmap) | |
1550 | memset(active_rrqs_xri_bitmap, 0, | |
1551 | phba->cfg_rrq_xri_bitmap_sz); | |
1552 | } | |
488d1469 | 1553 | |
34f5ad8b JS |
1554 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1555 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", | |
1556 | ndlp, ndlp->nlp_DID, new_ndlp); | |
1557 | ||
488d1469 | 1558 | if (!new_ndlp) { |
2e0fef85 JS |
1559 | rc = memcmp(&ndlp->nlp_portname, name, |
1560 | sizeof(struct lpfc_name)); | |
cff261f6 JS |
1561 | if (!rc) { |
1562 | if (active_rrqs_xri_bitmap) | |
1563 | mempool_free(active_rrqs_xri_bitmap, | |
1564 | phba->active_rrq_pool); | |
92795650 | 1565 | return ndlp; |
cff261f6 | 1566 | } |
488d1469 | 1567 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
cff261f6 JS |
1568 | if (!new_ndlp) { |
1569 | if (active_rrqs_xri_bitmap) | |
1570 | mempool_free(active_rrqs_xri_bitmap, | |
1571 | phba->active_rrq_pool); | |
488d1469 | 1572 | return ndlp; |
cff261f6 | 1573 | } |
2e0fef85 | 1574 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
e47c9093 | 1575 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
58da1ffb JS |
1576 | rc = memcmp(&ndlp->nlp_portname, name, |
1577 | sizeof(struct lpfc_name)); | |
cff261f6 JS |
1578 | if (!rc) { |
1579 | if (active_rrqs_xri_bitmap) | |
1580 | mempool_free(active_rrqs_xri_bitmap, | |
1581 | phba->active_rrq_pool); | |
58da1ffb | 1582 | return ndlp; |
cff261f6 | 1583 | } |
e47c9093 JS |
1584 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
1585 | NLP_STE_UNUSED_NODE); | |
cff261f6 JS |
1586 | if (!new_ndlp) { |
1587 | if (active_rrqs_xri_bitmap) | |
1588 | mempool_free(active_rrqs_xri_bitmap, | |
1589 | phba->active_rrq_pool); | |
e47c9093 | 1590 | return ndlp; |
cff261f6 | 1591 | } |
58da1ffb | 1592 | keepDID = new_ndlp->nlp_DID; |
cff261f6 JS |
1593 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
1594 | memcpy(active_rrqs_xri_bitmap, | |
1595 | new_ndlp->active_rrqs_xri_bitmap, | |
1596 | phba->cfg_rrq_xri_bitmap_sz); | |
19ca7609 | 1597 | } else { |
58da1ffb | 1598 | keepDID = new_ndlp->nlp_DID; |
cff261f6 JS |
1599 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1600 | active_rrqs_xri_bitmap) | |
1601 | memcpy(active_rrqs_xri_bitmap, | |
1602 | new_ndlp->active_rrqs_xri_bitmap, | |
1603 | phba->cfg_rrq_xri_bitmap_sz); | |
19ca7609 | 1604 | } |
488d1469 | 1605 | |
2e0fef85 | 1606 | lpfc_unreg_rpi(vport, new_ndlp); |
488d1469 | 1607 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
92795650 | 1608 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
19ca7609 | 1609 | if (phba->sli_rev == LPFC_SLI_REV4) |
cff261f6 JS |
1610 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
1611 | ndlp->active_rrqs_xri_bitmap, | |
1612 | phba->cfg_rrq_xri_bitmap_sz); | |
0ff10d46 | 1613 | |
953ceeda | 1614 | spin_lock_irq(shost->host_lock); |
e5abba4c JS |
1615 | keep_nlp_flag = new_ndlp->nlp_flag; |
1616 | new_ndlp->nlp_flag = ndlp->nlp_flag; | |
1617 | ndlp->nlp_flag = keep_nlp_flag; | |
953ceeda | 1618 | spin_unlock_irq(shost->host_lock); |
0ff10d46 | 1619 | |
953ceeda JS |
1620 | /* Set nlp_states accordingly */ |
1621 | keep_nlp_state = new_ndlp->nlp_state; | |
2e0fef85 | 1622 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
488d1469 | 1623 | |
2e0fef85 | 1624 | /* Move this back to NPR state */ |
87af33fe JS |
1625 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
1626 | /* The new_ndlp is replacing ndlp totally, so we need | |
1627 | * to put ndlp on UNUSED list and try to free it. | |
1628 | */ | |
34f5ad8b JS |
1629 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1630 | "3179 PLOGI confirm NEW: %x %x\n", | |
1631 | new_ndlp->nlp_DID, keepDID); | |
0ff10d46 JS |
1632 | |
1633 | /* Fix up the rport accordingly */ | |
1634 | rport = ndlp->rport; | |
1635 | if (rport) { | |
1636 | rdata = rport->dd_data; | |
1637 | if (rdata->pnode == ndlp) { | |
466e840b | 1638 | /* break the link before dropping the ref */ |
0ff10d46 | 1639 | ndlp->rport = NULL; |
466e840b | 1640 | lpfc_nlp_put(ndlp); |
0ff10d46 JS |
1641 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
1642 | new_ndlp->rport = rport; | |
1643 | } | |
1644 | new_ndlp->nlp_type = ndlp->nlp_type; | |
1645 | } | |
58da1ffb JS |
1646 | /* We shall actually free the ndlp with both nlp_DID and |
1647 | * nlp_portname fields equals 0 to avoid any ndlp on the | |
1648 | * nodelist never to be used. | |
1649 | */ | |
1650 | if (ndlp->nlp_DID == 0) { | |
1651 | spin_lock_irq(&phba->ndlp_lock); | |
1652 | NLP_SET_FREE_REQ(ndlp); | |
1653 | spin_unlock_irq(&phba->ndlp_lock); | |
1654 | } | |
0ff10d46 | 1655 | |
58da1ffb JS |
1656 | /* Two ndlps cannot have the same did on the nodelist */ |
1657 | ndlp->nlp_DID = keepDID; | |
cff261f6 JS |
1658 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1659 | active_rrqs_xri_bitmap) | |
1660 | memcpy(ndlp->active_rrqs_xri_bitmap, | |
1661 | active_rrqs_xri_bitmap, | |
1662 | phba->cfg_rrq_xri_bitmap_sz); | |
e5abba4c JS |
1663 | |
1664 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
1665 | lpfc_drop_node(vport, ndlp); | |
87af33fe | 1666 | } |
92795650 | 1667 | else { |
34f5ad8b JS |
1668 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1669 | "3180 PLOGI confirm SWAP: %x %x\n", | |
1670 | new_ndlp->nlp_DID, keepDID); | |
1671 | ||
2e0fef85 | 1672 | lpfc_unreg_rpi(vport, ndlp); |
34f5ad8b | 1673 | |
58da1ffb JS |
1674 | /* Two ndlps cannot have the same did */ |
1675 | ndlp->nlp_DID = keepDID; | |
cff261f6 JS |
1676 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1677 | active_rrqs_xri_bitmap) | |
1678 | memcpy(ndlp->active_rrqs_xri_bitmap, | |
1679 | active_rrqs_xri_bitmap, | |
1680 | phba->cfg_rrq_xri_bitmap_sz); | |
34f5ad8b | 1681 | |
953ceeda JS |
1682 | /* Since we are switching over to the new_ndlp, |
1683 | * reset the old ndlp state | |
34f5ad8b JS |
1684 | */ |
1685 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | |
1686 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) | |
953ceeda JS |
1687 | keep_nlp_state = NLP_STE_NPR_NODE; |
1688 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); | |
34f5ad8b | 1689 | |
38b92ef8 JS |
1690 | /* Fix up the rport accordingly */ |
1691 | rport = ndlp->rport; | |
1692 | if (rport) { | |
1693 | rdata = rport->dd_data; | |
1694 | put_node = rdata->pnode != NULL; | |
1695 | put_rport = ndlp->rport != NULL; | |
1696 | rdata->pnode = NULL; | |
1697 | ndlp->rport = NULL; | |
1698 | if (put_node) | |
1699 | lpfc_nlp_put(ndlp); | |
1700 | if (put_rport) | |
1701 | put_device(&rport->dev); | |
1702 | } | |
92795650 | 1703 | } |
cff261f6 JS |
1704 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1705 | active_rrqs_xri_bitmap) | |
1706 | mempool_free(active_rrqs_xri_bitmap, | |
1707 | phba->active_rrq_pool); | |
488d1469 JS |
1708 | return new_ndlp; |
1709 | } | |
1710 | ||
e59058c4 | 1711 | /** |
3621a710 | 1712 | * lpfc_end_rscn - Check and handle more rscn for a vport |
e59058c4 JS |
1713 | * @vport: pointer to a host virtual N_Port data structure. |
1714 | * | |
1715 | * This routine checks whether more Registration State Change | |
1716 | * Notifications (RSCNs) came in while the discovery state machine was in | |
1717 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be | |
1718 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the | |
1719 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of | |
1720 | * handling the RSCNs. | |
1721 | **/ | |
87af33fe JS |
1722 | void |
1723 | lpfc_end_rscn(struct lpfc_vport *vport) | |
1724 | { | |
1725 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
1726 | ||
1727 | if (vport->fc_flag & FC_RSCN_MODE) { | |
1728 | /* | |
1729 | * Check to see if more RSCNs came in while we were | |
1730 | * processing this one. | |
1731 | */ | |
1732 | if (vport->fc_rscn_id_cnt || | |
1733 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) | |
1734 | lpfc_els_handle_rscn(vport); | |
1735 | else { | |
1736 | spin_lock_irq(shost->host_lock); | |
1737 | vport->fc_flag &= ~FC_RSCN_MODE; | |
1738 | spin_unlock_irq(shost->host_lock); | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | ||
19ca7609 JS |
1743 | /** |
1744 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. | |
1745 | * @phba: pointer to lpfc hba data structure. | |
1746 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
1747 | * @rspiocb: pointer to lpfc response iocb data structure. | |
1748 | * | |
1749 | * This routine will call the clear rrq function to free the rrq and | |
1750 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not | |
1751 | * exist then the clear_rrq is still called because the rrq needs to | |
1752 | * be freed. | |
1753 | **/ | |
1754 | ||
1755 | static void | |
1756 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1757 | struct lpfc_iocbq *rspiocb) | |
1758 | { | |
1759 | struct lpfc_vport *vport = cmdiocb->vport; | |
1760 | IOCB_t *irsp; | |
1761 | struct lpfc_nodelist *ndlp; | |
1762 | struct lpfc_node_rrq *rrq; | |
1763 | ||
1764 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
1765 | rrq = cmdiocb->context_un.rrq; | |
1766 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1767 | ||
1768 | irsp = &rspiocb->iocb; | |
1769 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
1770 | "RRQ cmpl: status:x%x/x%x did:x%x", | |
1771 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1772 | irsp->un.elsreq64.remoteID); | |
1773 | ||
1774 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); | |
1775 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { | |
1776 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1777 | "2882 RRQ completes to NPort x%x " | |
1778 | "with no ndlp. Data: x%x x%x x%x\n", | |
1779 | irsp->un.elsreq64.remoteID, | |
1780 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1781 | irsp->ulpIoTag); | |
1782 | goto out; | |
1783 | } | |
1784 | ||
1785 | /* rrq completes to NPort <nlp_DID> */ | |
1786 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
1787 | "2880 RRQ completes to NPort x%x " | |
1788 | "Data: x%x x%x x%x x%x x%x\n", | |
1789 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1790 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); | |
1791 | ||
1792 | if (irsp->ulpStatus) { | |
1793 | /* Check for retry */ | |
1794 | /* RRQ failed Don't print the vport to vport rjts */ | |
1795 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | |
1796 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | |
1797 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | |
1798 | (phba)->pport->cfg_log_verbose & LOG_ELS) | |
1799 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1800 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", | |
1801 | ndlp->nlp_DID, irsp->ulpStatus, | |
1802 | irsp->un.ulpWord[4]); | |
1803 | } | |
1804 | out: | |
1805 | if (rrq) | |
1806 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
1807 | lpfc_els_free_iocb(phba, cmdiocb); | |
1808 | return; | |
1809 | } | |
e59058c4 | 1810 | /** |
3621a710 | 1811 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
e59058c4 JS |
1812 | * @phba: pointer to lpfc hba data structure. |
1813 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
1814 | * @rspiocb: pointer to lpfc response iocb data structure. | |
1815 | * | |
1816 | * This routine is the completion callback function for issuing the Port | |
1817 | * Login (PLOGI) command. For PLOGI completion, there must be an active | |
1818 | * ndlp on the vport node list that matches the remote node ID from the | |
25985edc | 1819 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply |
e59058c4 JS |
1820 | * ignored and command IOCB released. The PLOGI response IOCB status is |
1821 | * checked for error conditons. If there is error status reported, PLOGI | |
1822 | * retry shall be attempted by invoking the lpfc_els_retry() routine. | |
1823 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on | |
1824 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine | |
1825 | * (DSM) is set for this PLOGI completion. Finally, it checks whether | |
1826 | * there are additional N_Port nodes with the vport that need to perform | |
1827 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition | |
1828 | * PLOGIs. | |
1829 | **/ | |
dea3101e | 1830 | static void |
2e0fef85 JS |
1831 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1832 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1833 | { |
2e0fef85 JS |
1834 | struct lpfc_vport *vport = cmdiocb->vport; |
1835 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 1836 | IOCB_t *irsp; |
dea3101e | 1837 | struct lpfc_nodelist *ndlp; |
92795650 | 1838 | struct lpfc_dmabuf *prsp; |
eb016566 | 1839 | int disc, rc; |
dea3101e | 1840 | |
dea3101e JB |
1841 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
1842 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1843 | ||
1844 | irsp = &rspiocb->iocb; | |
858c9f6c JS |
1845 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1846 | "PLOGI cmpl: status:x%x/x%x did:x%x", | |
1847 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1848 | irsp->un.elsreq64.remoteID); | |
1849 | ||
2e0fef85 | 1850 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
e47c9093 | 1851 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
e8b62011 JS |
1852 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
1853 | "0136 PLOGI completes to NPort x%x " | |
1854 | "with no ndlp. Data: x%x x%x x%x\n", | |
1855 | irsp->un.elsreq64.remoteID, | |
1856 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1857 | irsp->ulpIoTag); | |
488d1469 | 1858 | goto out; |
ed957684 | 1859 | } |
dea3101e JB |
1860 | |
1861 | /* Since ndlp can be freed in the disc state machine, note if this node | |
1862 | * is being used during discovery. | |
1863 | */ | |
2e0fef85 | 1864 | spin_lock_irq(shost->host_lock); |
dea3101e | 1865 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
488d1469 | 1866 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 | 1867 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1868 | rc = 0; |
1869 | ||
1870 | /* PLOGI completes to NPort <nlp_DID> */ | |
e8b62011 | 1871 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
a0f2d3ef | 1872 | "0102 PLOGI completes to NPort x%06x " |
e8b62011 | 1873 | "Data: x%x x%x x%x x%x x%x\n", |
a0f2d3ef JS |
1874 | ndlp->nlp_DID, ndlp->nlp_fc4_type, |
1875 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1876 | disc, vport->num_disc_nodes); | |
1877 | ||
dea3101e | 1878 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
1879 | if (lpfc_els_chk_latt(vport)) { |
1880 | spin_lock_irq(shost->host_lock); | |
dea3101e | 1881 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1882 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1883 | goto out; |
1884 | } | |
1885 | ||
dea3101e JB |
1886 | if (irsp->ulpStatus) { |
1887 | /* Check for retry */ | |
1888 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
1889 | /* ELS command is being retried */ | |
1890 | if (disc) { | |
2e0fef85 | 1891 | spin_lock_irq(shost->host_lock); |
dea3101e | 1892 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1893 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1894 | } |
1895 | goto out; | |
1896 | } | |
2a9bf3d0 JS |
1897 | /* PLOGI failed Don't print the vport to vport rjts */ |
1898 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | |
1899 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | |
1900 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | |
1901 | (phba)->pport->cfg_log_verbose & LOG_ELS) | |
1902 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
e40a02c1 JS |
1903 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
1904 | ndlp->nlp_DID, irsp->ulpStatus, | |
1905 | irsp->un.ulpWord[4]); | |
dea3101e | 1906 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 1907 | if (lpfc_error_lost_link(irsp)) |
c9f8735b | 1908 | rc = NLP_STE_FREED_NODE; |
e47c9093 | 1909 | else |
2e0fef85 | 1910 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1911 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1912 | } else { |
1913 | /* Good status, call state machine */ | |
92795650 | 1914 | prsp = list_entry(((struct lpfc_dmabuf *) |
92d7f7b0 JS |
1915 | cmdiocb->context2)->list.next, |
1916 | struct lpfc_dmabuf, list); | |
1917 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); | |
2e0fef85 | 1918 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1919 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1920 | } |
1921 | ||
2e0fef85 | 1922 | if (disc && vport->num_disc_nodes) { |
dea3101e | 1923 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 | 1924 | lpfc_more_plogi(vport); |
dea3101e | 1925 | |
2e0fef85 JS |
1926 | if (vport->num_disc_nodes == 0) { |
1927 | spin_lock_irq(shost->host_lock); | |
1928 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
1929 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1930 | |
2e0fef85 | 1931 | lpfc_can_disctmo(vport); |
87af33fe | 1932 | lpfc_end_rscn(vport); |
dea3101e JB |
1933 | } |
1934 | } | |
1935 | ||
1936 | out: | |
1937 | lpfc_els_free_iocb(phba, cmdiocb); | |
1938 | return; | |
1939 | } | |
1940 | ||
e59058c4 | 1941 | /** |
3621a710 | 1942 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
e59058c4 JS |
1943 | * @vport: pointer to a host virtual N_Port data structure. |
1944 | * @did: destination port identifier. | |
1945 | * @retry: number of retries to the command IOCB. | |
1946 | * | |
1947 | * This routine issues a Port Login (PLOGI) command to a remote N_Port | |
1948 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, | |
1949 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. | |
1950 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes | |
1951 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. | |
1952 | * | |
1953 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
1954 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
1955 | * will be stored into the context1 field of the IOCB for the completion | |
1956 | * callback function to the PLOGI ELS command. | |
1957 | * | |
1958 | * Return code | |
1959 | * 0 - Successfully issued a plogi for @vport | |
1960 | * 1 - failed to issue a plogi for @vport | |
1961 | **/ | |
dea3101e | 1962 | int |
2e0fef85 | 1963 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
dea3101e | 1964 | { |
2e0fef85 | 1965 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1966 | struct serv_parm *sp; |
98c9ea5c | 1967 | struct lpfc_nodelist *ndlp; |
dea3101e | 1968 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
1969 | uint8_t *pcmd; |
1970 | uint16_t cmdsize; | |
92d7f7b0 | 1971 | int ret; |
dea3101e | 1972 | |
98c9ea5c | 1973 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
1974 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
1975 | ndlp = NULL; | |
98c9ea5c | 1976 | |
e47c9093 | 1977 | /* If ndlp is not NULL, we will bump the reference count on it */ |
92d7f7b0 | 1978 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
98c9ea5c | 1979 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
2e0fef85 | 1980 | ELS_CMD_PLOGI); |
c9f8735b JW |
1981 | if (!elsiocb) |
1982 | return 1; | |
dea3101e | 1983 | |
dea3101e JB |
1984 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
1985 | ||
1986 | /* For PLOGI request, remainder of payload is service parameters */ | |
1987 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; | |
92d7f7b0 JS |
1988 | pcmd += sizeof(uint32_t); |
1989 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
1990 | sp = (struct serv_parm *) pcmd; |
1991 | ||
5ac6b303 JS |
1992 | /* |
1993 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins | |
1994 | * to device on remote loops work. | |
1995 | */ | |
1996 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) | |
1997 | sp->cmn.altBbCredit = 1; | |
1998 | ||
dea3101e JB |
1999 | if (sp->cmn.fcphLow < FC_PH_4_3) |
2000 | sp->cmn.fcphLow = FC_PH_4_3; | |
2001 | ||
2002 | if (sp->cmn.fcphHigh < FC_PH3) | |
2003 | sp->cmn.fcphHigh = FC_PH3; | |
2004 | ||
e0165f20 | 2005 | sp->cmn.valid_vendor_ver_level = 0; |
8c258641 | 2006 | memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); |
e0165f20 | 2007 | |
858c9f6c JS |
2008 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2009 | "Issue PLOGI: did:x%x", | |
2010 | did, 0, 0); | |
2011 | ||
8c258641 JS |
2012 | /* If our firmware supports this feature, convey that |
2013 | * information to the target using the vendor specific field. | |
2014 | */ | |
2015 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { | |
2016 | sp->cmn.valid_vendor_ver_level = 1; | |
2017 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); | |
2018 | sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); | |
2019 | } | |
2020 | ||
dea3101e JB |
2021 | phba->fc_stat.elsXmitPLOGI++; |
2022 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; | |
3772a991 | 2023 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
92d7f7b0 JS |
2024 | |
2025 | if (ret == IOCB_ERROR) { | |
dea3101e | 2026 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2027 | return 1; |
dea3101e | 2028 | } |
c9f8735b | 2029 | return 0; |
dea3101e JB |
2030 | } |
2031 | ||
e59058c4 | 2032 | /** |
3621a710 | 2033 | * lpfc_cmpl_els_prli - Completion callback function for prli |
e59058c4 JS |
2034 | * @phba: pointer to lpfc hba data structure. |
2035 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2036 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2037 | * | |
2038 | * This routine is the completion callback function for a Process Login | |
2039 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error | |
2040 | * status. If there is error status reported, PRLI retry shall be attempted | |
2041 | * by invoking the lpfc_els_retry() routine. Otherwise, the state | |
2042 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this | |
2043 | * ndlp to mark the PRLI completion. | |
2044 | **/ | |
dea3101e | 2045 | static void |
2e0fef85 JS |
2046 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2047 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2048 | { |
2e0fef85 JS |
2049 | struct lpfc_vport *vport = cmdiocb->vport; |
2050 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2051 | IOCB_t *irsp; |
dea3101e JB |
2052 | struct lpfc_nodelist *ndlp; |
2053 | ||
dea3101e JB |
2054 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
2055 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2056 | ||
2057 | irsp = &(rspiocb->iocb); | |
2058 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
2e0fef85 | 2059 | spin_lock_irq(shost->host_lock); |
dea3101e | 2060 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 2061 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2062 | |
858c9f6c JS |
2063 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2064 | "PRLI cmpl: status:x%x/x%x did:x%x", | |
2065 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2066 | ndlp->nlp_DID); | |
a0f2d3ef JS |
2067 | |
2068 | /* Ddriver supports multiple FC4 types. Counters matter. */ | |
2069 | vport->fc_prli_sent--; | |
2070 | ||
dea3101e | 2071 | /* PRLI completes to NPort <nlp_DID> */ |
e8b62011 | 2072 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
a0f2d3ef | 2073 | "0103 PRLI completes to NPort x%06x " |
e8b62011 JS |
2074 | "Data: x%x x%x x%x x%x\n", |
2075 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
a0f2d3ef | 2076 | vport->num_disc_nodes, ndlp->fc4_prli_sent); |
dea3101e | 2077 | |
dea3101e | 2078 | /* Check to see if link went down during discovery */ |
2e0fef85 | 2079 | if (lpfc_els_chk_latt(vport)) |
dea3101e JB |
2080 | goto out; |
2081 | ||
2082 | if (irsp->ulpStatus) { | |
2083 | /* Check for retry */ | |
2084 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
2085 | /* ELS command is being retried */ | |
a0f2d3ef | 2086 | ndlp->fc4_prli_sent--; |
dea3101e JB |
2087 | goto out; |
2088 | } | |
2089 | /* PRLI failed */ | |
e40a02c1 JS |
2090 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2091 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", | |
2092 | ndlp->nlp_DID, irsp->ulpStatus, | |
2093 | irsp->un.ulpWord[4]); | |
dea3101e | 2094 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 2095 | if (lpfc_error_lost_link(irsp)) |
dea3101e | 2096 | goto out; |
e47c9093 | 2097 | else |
2e0fef85 | 2098 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 2099 | NLP_EVT_CMPL_PRLI); |
e47c9093 | 2100 | } else |
a0f2d3ef JS |
2101 | /* Good status, call state machine. However, if another |
2102 | * PRLI is outstanding, don't call the state machine | |
2103 | * because final disposition to Mapped or Unmapped is | |
2104 | * completed there. | |
2105 | */ | |
2e0fef85 | 2106 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 2107 | NLP_EVT_CMPL_PRLI); |
a0f2d3ef | 2108 | |
dea3101e JB |
2109 | out: |
2110 | lpfc_els_free_iocb(phba, cmdiocb); | |
2111 | return; | |
2112 | } | |
2113 | ||
e59058c4 | 2114 | /** |
3621a710 | 2115 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
e59058c4 JS |
2116 | * @vport: pointer to a host virtual N_Port data structure. |
2117 | * @ndlp: pointer to a node-list data structure. | |
2118 | * @retry: number of retries to the command IOCB. | |
2119 | * | |
2120 | * This routine issues a Process Login (PRLI) ELS command for the | |
2121 | * @vport. The PRLI service parameters are set up in the payload of the | |
2122 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine | |
2123 | * is put to the IOCB completion callback func field before invoking the | |
2124 | * routine lpfc_sli_issue_iocb() to send out PRLI command. | |
2125 | * | |
2126 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2127 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2128 | * will be stored into the context1 field of the IOCB for the completion | |
2129 | * callback function to the PRLI ELS command. | |
2130 | * | |
2131 | * Return code | |
2132 | * 0 - successfully issued prli iocb command for @vport | |
2133 | * 1 - failed to issue prli iocb command for @vport | |
2134 | **/ | |
dea3101e | 2135 | int |
2e0fef85 | 2136 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2137 | uint8_t retry) |
2138 | { | |
2e0fef85 JS |
2139 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2140 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2141 | PRLI *npr; |
a0f2d3ef | 2142 | struct lpfc_nvme_prli *npr_nvme; |
dea3101e | 2143 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2144 | uint8_t *pcmd; |
2145 | uint16_t cmdsize; | |
a0f2d3ef JS |
2146 | u32 local_nlp_type, elscmd; |
2147 | ||
2148 | local_nlp_type = ndlp->nlp_fc4_type; | |
2149 | ||
2150 | send_next_prli: | |
2151 | if (local_nlp_type & NLP_FC4_FCP) { | |
2152 | /* Payload is 4 + 16 = 20 x14 bytes. */ | |
2153 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); | |
2154 | elscmd = ELS_CMD_PRLI; | |
2155 | } else if (local_nlp_type & NLP_FC4_NVME) { | |
2156 | /* Payload is 4 + 20 = 24 x18 bytes. */ | |
2157 | cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); | |
2158 | elscmd = ELS_CMD_NVMEPRLI; | |
2159 | } else { | |
2160 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
2161 | "3083 Unknown FC_TYPE x%x ndlp x%06x\n", | |
2162 | ndlp->nlp_fc4_type, ndlp->nlp_DID); | |
2163 | return 1; | |
2164 | } | |
2e0fef85 | 2165 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
a0f2d3ef | 2166 | ndlp->nlp_DID, elscmd); |
488d1469 | 2167 | if (!elsiocb) |
c9f8735b | 2168 | return 1; |
dea3101e | 2169 | |
dea3101e JB |
2170 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2171 | ||
2172 | /* For PRLI request, remainder of payload is service parameters */ | |
a0f2d3ef | 2173 | memset(pcmd, 0, cmdsize); |
dea3101e | 2174 | |
a0f2d3ef JS |
2175 | if (local_nlp_type & NLP_FC4_FCP) { |
2176 | /* Remainder of payload is FCP PRLI parameter page. | |
2177 | * Note: this data structure is defined as | |
2178 | * BE/LE in the structure definition so no | |
2179 | * byte swap call is made. | |
2180 | */ | |
2181 | *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; | |
2182 | pcmd += sizeof(uint32_t); | |
2183 | npr = (PRLI *)pcmd; | |
dea3101e | 2184 | |
a0f2d3ef JS |
2185 | /* |
2186 | * If our firmware version is 3.20 or later, | |
2187 | * set the following bits for FC-TAPE support. | |
2188 | */ | |
2189 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { | |
2190 | npr->ConfmComplAllowed = 1; | |
2191 | npr->Retry = 1; | |
2192 | npr->TaskRetryIdReq = 1; | |
2193 | } | |
2194 | npr->estabImagePair = 1; | |
2195 | npr->readXferRdyDis = 1; | |
2196 | if (vport->cfg_first_burst_size) | |
2197 | npr->writeXferRdyDis = 1; | |
2198 | ||
2199 | /* For FCP support */ | |
2200 | npr->prliType = PRLI_FCP_TYPE; | |
2201 | npr->initiatorFunc = 1; | |
2202 | elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ; | |
2203 | ||
2204 | /* Remove FCP type - processed. */ | |
2205 | local_nlp_type &= ~NLP_FC4_FCP; | |
2206 | } else if (local_nlp_type & NLP_FC4_NVME) { | |
2207 | /* Remainder of payload is NVME PRLI parameter page. | |
2208 | * This data structure is the newer definition that | |
2209 | * uses bf macros so a byte swap is required. | |
2210 | */ | |
2211 | *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; | |
2212 | pcmd += sizeof(uint32_t); | |
2213 | npr_nvme = (struct lpfc_nvme_prli *)pcmd; | |
2214 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); | |
2215 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ | |
2216 | ||
2217 | /* Only initiators request first burst. */ | |
2218 | if ((phba->cfg_nvme_enable_fb) && | |
2219 | !phba->nvmet_support) | |
2220 | bf_set(prli_fba, npr_nvme, 1); | |
2221 | ||
8c258641 JS |
2222 | if (phba->nvmet_support) { |
2223 | bf_set(prli_tgt, npr_nvme, 1); | |
2224 | bf_set(prli_disc, npr_nvme, 1); | |
2225 | ||
2226 | } else { | |
2227 | bf_set(prli_init, npr_nvme, 1); | |
2228 | } | |
a0f2d3ef JS |
2229 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); |
2230 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); | |
2231 | elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ; | |
2232 | ||
2233 | /* Remove NVME type - processed. */ | |
2234 | local_nlp_type &= ~NLP_FC4_NVME; | |
2235 | } | |
dea3101e | 2236 | |
858c9f6c JS |
2237 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2238 | "Issue PRLI: did:x%x", | |
2239 | ndlp->nlp_DID, 0, 0); | |
2240 | ||
dea3101e JB |
2241 | phba->fc_stat.elsXmitPRLI++; |
2242 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; | |
2e0fef85 | 2243 | spin_lock_irq(shost->host_lock); |
dea3101e | 2244 | ndlp->nlp_flag |= NLP_PRLI_SND; |
2e0fef85 | 2245 | spin_unlock_irq(shost->host_lock); |
3772a991 JS |
2246 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2247 | IOCB_ERROR) { | |
2e0fef85 | 2248 | spin_lock_irq(shost->host_lock); |
dea3101e | 2249 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 2250 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2251 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2252 | return 1; |
dea3101e | 2253 | } |
a0f2d3ef JS |
2254 | |
2255 | /* The vport counters are used for lpfc_scan_finished, but | |
2256 | * the ndlp is used to track outstanding PRLIs for different | |
2257 | * FC4 types. | |
2258 | */ | |
2e0fef85 | 2259 | vport->fc_prli_sent++; |
a0f2d3ef JS |
2260 | ndlp->fc4_prli_sent++; |
2261 | ||
2262 | /* The driver supports 2 FC4 types. Make sure | |
2263 | * a PRLI is issued for all types before exiting. | |
2264 | */ | |
2265 | if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) | |
2266 | goto send_next_prli; | |
2267 | ||
c9f8735b | 2268 | return 0; |
dea3101e JB |
2269 | } |
2270 | ||
90160e01 | 2271 | /** |
3621a710 | 2272 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
90160e01 JS |
2273 | * @vport: pointer to a host virtual N_Port data structure. |
2274 | * | |
2275 | * This routine performs Registration State Change Notification (RSCN) | |
2276 | * discovery for a @vport. If the @vport's node port recovery count is not | |
2277 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all | |
2278 | * the nodes that need recovery. If none of the PLOGI were needed through | |
2279 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be | |
2280 | * invoked to check and handle possible more RSCN came in during the period | |
2281 | * of processing the current ones. | |
2282 | **/ | |
2283 | static void | |
2284 | lpfc_rscn_disc(struct lpfc_vport *vport) | |
2285 | { | |
2286 | lpfc_can_disctmo(vport); | |
2287 | ||
2288 | /* RSCN discovery */ | |
2289 | /* go thru NPR nodes and issue ELS PLOGIs */ | |
2290 | if (vport->fc_npr_cnt) | |
2291 | if (lpfc_els_disc_plogi(vport)) | |
2292 | return; | |
2293 | ||
2294 | lpfc_end_rscn(vport); | |
2295 | } | |
2296 | ||
2297 | /** | |
3621a710 | 2298 | * lpfc_adisc_done - Complete the adisc phase of discovery |
90160e01 JS |
2299 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
2300 | * | |
2301 | * This function is called when the final ADISC is completed during discovery. | |
2302 | * This function handles clearing link attention or issuing reg_vpi depending | |
2303 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of | |
2304 | * discovery. | |
2305 | * This function is called with no locks held. | |
2306 | **/ | |
2307 | static void | |
2308 | lpfc_adisc_done(struct lpfc_vport *vport) | |
2309 | { | |
2310 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
2311 | struct lpfc_hba *phba = vport->phba; | |
2312 | ||
2313 | /* | |
2314 | * For NPIV, cmpl_reg_vpi will set port_state to READY, | |
2315 | * and continue discovery. | |
2316 | */ | |
2317 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
6fb120a7 JS |
2318 | !(vport->fc_flag & FC_RSCN_MODE) && |
2319 | (phba->sli_rev < LPFC_SLI_REV4)) { | |
d454c91f JS |
2320 | /* The ADISCs are complete. Doesn't matter if they |
2321 | * succeeded or failed because the ADISC completion | |
2322 | * routine guarantees to call the state machine and | |
2323 | * the RPI is either unregistered (failed ADISC response) | |
2324 | * or the RPI is still valid and the node is marked | |
2325 | * mapped for a target. The exchanges should be in the | |
2326 | * correct state. This code is specific to SLI3. | |
2327 | */ | |
2328 | lpfc_issue_clear_la(phba, vport); | |
90160e01 JS |
2329 | lpfc_issue_reg_vpi(phba, vport); |
2330 | return; | |
2331 | } | |
2332 | /* | |
2333 | * For SLI2, we need to set port_state to READY | |
2334 | * and continue discovery. | |
2335 | */ | |
2336 | if (vport->port_state < LPFC_VPORT_READY) { | |
2337 | /* If we get here, there is nothing to ADISC */ | |
85c0f177 | 2338 | lpfc_issue_clear_la(phba, vport); |
90160e01 JS |
2339 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
2340 | vport->num_disc_nodes = 0; | |
2341 | /* go thru NPR list, issue ELS PLOGIs */ | |
2342 | if (vport->fc_npr_cnt) | |
2343 | lpfc_els_disc_plogi(vport); | |
2344 | if (!vport->num_disc_nodes) { | |
2345 | spin_lock_irq(shost->host_lock); | |
2346 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
2347 | spin_unlock_irq(shost->host_lock); | |
2348 | lpfc_can_disctmo(vport); | |
2349 | lpfc_end_rscn(vport); | |
2350 | } | |
2351 | } | |
2352 | vport->port_state = LPFC_VPORT_READY; | |
2353 | } else | |
2354 | lpfc_rscn_disc(vport); | |
2355 | } | |
2356 | ||
e59058c4 | 2357 | /** |
3621a710 | 2358 | * lpfc_more_adisc - Issue more adisc as needed |
e59058c4 JS |
2359 | * @vport: pointer to a host virtual N_Port data structure. |
2360 | * | |
2361 | * This routine determines whether there are more ndlps on a @vport | |
2362 | * node list need to have Address Discover (ADISC) issued. If so, it will | |
2363 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's | |
2364 | * remaining nodes which need to have ADISC sent. | |
2365 | **/ | |
0ff10d46 | 2366 | void |
2e0fef85 | 2367 | lpfc_more_adisc(struct lpfc_vport *vport) |
dea3101e | 2368 | { |
2e0fef85 JS |
2369 | if (vport->num_disc_nodes) |
2370 | vport->num_disc_nodes--; | |
dea3101e | 2371 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
e8b62011 JS |
2372 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
2373 | "0210 Continue discovery with %d ADISCs to go " | |
2374 | "Data: x%x x%x x%x\n", | |
2375 | vport->num_disc_nodes, vport->fc_adisc_cnt, | |
2376 | vport->fc_flag, vport->port_state); | |
dea3101e | 2377 | /* Check to see if there are more ADISCs to be sent */ |
2e0fef85 JS |
2378 | if (vport->fc_flag & FC_NLP_MORE) { |
2379 | lpfc_set_disctmo(vport); | |
2380 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | |
eb016566 | 2381 | lpfc_els_disc_adisc(vport); |
dea3101e | 2382 | } |
90160e01 JS |
2383 | if (!vport->num_disc_nodes) |
2384 | lpfc_adisc_done(vport); | |
dea3101e JB |
2385 | return; |
2386 | } | |
2387 | ||
e59058c4 | 2388 | /** |
3621a710 | 2389 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
e59058c4 JS |
2390 | * @phba: pointer to lpfc hba data structure. |
2391 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2392 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2393 | * | |
2394 | * This routine is the completion function for issuing the Address Discover | |
2395 | * (ADISC) command. It first checks to see whether link went down during | |
2396 | * the discovery process. If so, the node will be marked as node port | |
2397 | * recovery for issuing discover IOCB by the link attention handler and | |
2398 | * exit. Otherwise, the response status is checked. If error was reported | |
2399 | * in the response status, the ADISC command shall be retried by invoking | |
2400 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in | |
2401 | * the response status, the state machine is invoked to set transition | |
2402 | * with respect to NLP_EVT_CMPL_ADISC event. | |
2403 | **/ | |
dea3101e | 2404 | static void |
2e0fef85 JS |
2405 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2406 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2407 | { |
2e0fef85 JS |
2408 | struct lpfc_vport *vport = cmdiocb->vport; |
2409 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2410 | IOCB_t *irsp; |
dea3101e | 2411 | struct lpfc_nodelist *ndlp; |
2e0fef85 | 2412 | int disc; |
dea3101e JB |
2413 | |
2414 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
2415 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2416 | ||
2417 | irsp = &(rspiocb->iocb); | |
2418 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
dea3101e | 2419 | |
858c9f6c JS |
2420 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2421 | "ADISC cmpl: status:x%x/x%x did:x%x", | |
2422 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2423 | ndlp->nlp_DID); | |
2424 | ||
dea3101e JB |
2425 | /* Since ndlp can be freed in the disc state machine, note if this node |
2426 | * is being used during discovery. | |
2427 | */ | |
2e0fef85 | 2428 | spin_lock_irq(shost->host_lock); |
dea3101e | 2429 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
c9f8735b | 2430 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
2e0fef85 | 2431 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2432 | /* ADISC completes to NPort <nlp_DID> */ |
e8b62011 JS |
2433 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2434 | "0104 ADISC completes to NPort x%x " | |
2435 | "Data: x%x x%x x%x x%x x%x\n", | |
2436 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
2437 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | |
dea3101e | 2438 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
2439 | if (lpfc_els_chk_latt(vport)) { |
2440 | spin_lock_irq(shost->host_lock); | |
dea3101e | 2441 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 2442 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
2443 | goto out; |
2444 | } | |
2445 | ||
2446 | if (irsp->ulpStatus) { | |
2447 | /* Check for retry */ | |
2448 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
2449 | /* ELS command is being retried */ | |
2450 | if (disc) { | |
2e0fef85 | 2451 | spin_lock_irq(shost->host_lock); |
dea3101e | 2452 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 JS |
2453 | spin_unlock_irq(shost->host_lock); |
2454 | lpfc_set_disctmo(vport); | |
dea3101e JB |
2455 | } |
2456 | goto out; | |
2457 | } | |
2458 | /* ADISC failed */ | |
e40a02c1 JS |
2459 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2460 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", | |
2461 | ndlp->nlp_DID, irsp->ulpStatus, | |
2462 | irsp->un.ulpWord[4]); | |
dea3101e | 2463 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 2464 | if (!lpfc_error_lost_link(irsp)) |
2e0fef85 | 2465 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
858c9f6c | 2466 | NLP_EVT_CMPL_ADISC); |
e47c9093 | 2467 | } else |
dea3101e | 2468 | /* Good status, call state machine */ |
2e0fef85 | 2469 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
dea3101e | 2470 | NLP_EVT_CMPL_ADISC); |
dea3101e | 2471 | |
90160e01 JS |
2472 | /* Check to see if there are more ADISCs to be sent */ |
2473 | if (disc && vport->num_disc_nodes) | |
2e0fef85 | 2474 | lpfc_more_adisc(vport); |
dea3101e JB |
2475 | out: |
2476 | lpfc_els_free_iocb(phba, cmdiocb); | |
2477 | return; | |
2478 | } | |
2479 | ||
e59058c4 | 2480 | /** |
3621a710 | 2481 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport |
e59058c4 JS |
2482 | * @vport: pointer to a virtual N_Port data structure. |
2483 | * @ndlp: pointer to a node-list data structure. | |
2484 | * @retry: number of retries to the command IOCB. | |
2485 | * | |
2486 | * This routine issues an Address Discover (ADISC) for an @ndlp on a | |
2487 | * @vport. It prepares the payload of the ADISC ELS command, updates the | |
2488 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine | |
2489 | * to issue the ADISC ELS command. | |
2490 | * | |
2491 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2492 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2493 | * will be stored into the context1 field of the IOCB for the completion | |
2494 | * callback function to the ADISC ELS command. | |
2495 | * | |
2496 | * Return code | |
2497 | * 0 - successfully issued adisc | |
2498 | * 1 - failed to issue adisc | |
2499 | **/ | |
dea3101e | 2500 | int |
2e0fef85 | 2501 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2502 | uint8_t retry) |
2503 | { | |
2e0fef85 JS |
2504 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2505 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2506 | ADISC *ap; |
dea3101e | 2507 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2508 | uint8_t *pcmd; |
2509 | uint16_t cmdsize; | |
2510 | ||
92d7f7b0 | 2511 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
2e0fef85 JS |
2512 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
2513 | ndlp->nlp_DID, ELS_CMD_ADISC); | |
488d1469 | 2514 | if (!elsiocb) |
c9f8735b | 2515 | return 1; |
dea3101e | 2516 | |
dea3101e JB |
2517 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2518 | ||
2519 | /* For ADISC request, remainder of payload is service parameters */ | |
2520 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; | |
92d7f7b0 | 2521 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2522 | |
2523 | /* Fill in ADISC payload */ | |
2524 | ap = (ADISC *) pcmd; | |
2525 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
2526 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
2527 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 2528 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 2529 | |
858c9f6c JS |
2530 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2531 | "Issue ADISC: did:x%x", | |
2532 | ndlp->nlp_DID, 0, 0); | |
2533 | ||
dea3101e JB |
2534 | phba->fc_stat.elsXmitADISC++; |
2535 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; | |
2e0fef85 | 2536 | spin_lock_irq(shost->host_lock); |
dea3101e | 2537 | ndlp->nlp_flag |= NLP_ADISC_SND; |
2e0fef85 | 2538 | spin_unlock_irq(shost->host_lock); |
3772a991 JS |
2539 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2540 | IOCB_ERROR) { | |
2e0fef85 | 2541 | spin_lock_irq(shost->host_lock); |
dea3101e | 2542 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
2e0fef85 | 2543 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2544 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2545 | return 1; |
dea3101e | 2546 | } |
c9f8735b | 2547 | return 0; |
dea3101e JB |
2548 | } |
2549 | ||
e59058c4 | 2550 | /** |
3621a710 | 2551 | * lpfc_cmpl_els_logo - Completion callback function for logo |
e59058c4 JS |
2552 | * @phba: pointer to lpfc hba data structure. |
2553 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2554 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2555 | * | |
2556 | * This routine is the completion function for issuing the ELS Logout (LOGO) | |
2557 | * command. If no error status was reported from the LOGO response, the | |
2558 | * state machine of the associated ndlp shall be invoked for transition with | |
2559 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, | |
2560 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. | |
2561 | **/ | |
dea3101e | 2562 | static void |
2e0fef85 JS |
2563 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2564 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2565 | { |
2e0fef85 JS |
2566 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
2567 | struct lpfc_vport *vport = ndlp->vport; | |
2568 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2569 | IOCB_t *irsp; |
92494144 | 2570 | struct lpfcMboxq *mbox; |
086a345f JS |
2571 | unsigned long flags; |
2572 | uint32_t skip_recovery = 0; | |
dea3101e | 2573 | |
dea3101e JB |
2574 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
2575 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2576 | ||
2577 | irsp = &(rspiocb->iocb); | |
2e0fef85 | 2578 | spin_lock_irq(shost->host_lock); |
dea3101e | 2579 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 2580 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2581 | |
858c9f6c JS |
2582 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2583 | "LOGO cmpl: status:x%x/x%x did:x%x", | |
2584 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2585 | ndlp->nlp_DID); | |
086a345f | 2586 | |
dea3101e | 2587 | /* LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
2588 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2589 | "0105 LOGO completes to NPort x%x " | |
2590 | "Data: x%x x%x x%x x%x\n", | |
2591 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
2592 | irsp->ulpTimeout, vport->num_disc_nodes); | |
086a345f JS |
2593 | |
2594 | if (lpfc_els_chk_latt(vport)) { | |
2595 | skip_recovery = 1; | |
dea3101e | 2596 | goto out; |
086a345f | 2597 | } |
dea3101e | 2598 | |
086a345f | 2599 | /* Check to see if link went down during discovery */ |
92d7f7b0 JS |
2600 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
2601 | /* NLP_EVT_DEVICE_RM should unregister the RPI | |
2602 | * which should abort all outstanding IOs. | |
2603 | */ | |
2604 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | |
2605 | NLP_EVT_DEVICE_RM); | |
086a345f | 2606 | skip_recovery = 1; |
92d7f7b0 JS |
2607 | goto out; |
2608 | } | |
2609 | ||
dea3101e JB |
2610 | if (irsp->ulpStatus) { |
2611 | /* Check for retry */ | |
086a345f | 2612 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
dea3101e | 2613 | /* ELS command is being retried */ |
086a345f | 2614 | skip_recovery = 1; |
dea3101e | 2615 | goto out; |
086a345f | 2616 | } |
dea3101e | 2617 | /* LOGO failed */ |
e40a02c1 JS |
2618 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2619 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", | |
2620 | ndlp->nlp_DID, irsp->ulpStatus, | |
2621 | irsp->un.ulpWord[4]); | |
dea3101e | 2622 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
086a345f JS |
2623 | if (lpfc_error_lost_link(irsp)) { |
2624 | skip_recovery = 1; | |
dea3101e | 2625 | goto out; |
086a345f JS |
2626 | } |
2627 | } | |
2628 | ||
2629 | /* Call state machine. This will unregister the rpi if needed. */ | |
2630 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); | |
2631 | ||
dea3101e JB |
2632 | out: |
2633 | lpfc_els_free_iocb(phba, cmdiocb); | |
92494144 JS |
2634 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
2635 | if ((vport->fc_flag & FC_PT2PT) && | |
2636 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { | |
2637 | phba->pport->fc_myDID = 0; | |
a0f2d3ef | 2638 | |
01649561 | 2639 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
8c258641 | 2640 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { |
d613b6a7 JS |
2641 | if (phba->nvmet_support) |
2642 | lpfc_nvmet_update_targetport(phba); | |
2643 | else | |
8c258641 | 2644 | lpfc_nvme_update_localport(phba->pport); |
8c258641 | 2645 | } |
a0f2d3ef | 2646 | |
92494144 JS |
2647 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
2648 | if (mbox) { | |
2649 | lpfc_config_link(phba, mbox); | |
2650 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
2651 | mbox->vport = vport; | |
2652 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == | |
2653 | MBX_NOT_FINISHED) { | |
2654 | mempool_free(mbox, phba->mbox_mem_pool); | |
086a345f | 2655 | skip_recovery = 1; |
92494144 JS |
2656 | } |
2657 | } | |
2658 | } | |
086a345f JS |
2659 | |
2660 | /* | |
2661 | * If the node is a target, the handling attempts to recover the port. | |
2662 | * For any other port type, the rpi is unregistered as an implicit | |
2663 | * LOGO. | |
2664 | */ | |
2665 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { | |
2666 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
2667 | spin_lock_irqsave(shost->host_lock, flags); | |
2668 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
2669 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2670 | ||
2671 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
2672 | "3187 LOGO completes to NPort x%x: Start " | |
2673 | "Recovery Data: x%x x%x x%x x%x\n", | |
2674 | ndlp->nlp_DID, irsp->ulpStatus, | |
2675 | irsp->un.ulpWord[4], irsp->ulpTimeout, | |
2676 | vport->num_disc_nodes); | |
2677 | lpfc_disc_start(vport); | |
2678 | } | |
dea3101e JB |
2679 | return; |
2680 | } | |
2681 | ||
e59058c4 | 2682 | /** |
3621a710 | 2683 | * lpfc_issue_els_logo - Issue a logo to an node on a vport |
e59058c4 JS |
2684 | * @vport: pointer to a virtual N_Port data structure. |
2685 | * @ndlp: pointer to a node-list data structure. | |
2686 | * @retry: number of retries to the command IOCB. | |
2687 | * | |
2688 | * This routine constructs and issues an ELS Logout (LOGO) iocb command | |
2689 | * to a remote node, referred by an @ndlp on a @vport. It constructs the | |
2690 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the | |
2691 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. | |
2692 | * | |
2693 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2694 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2695 | * will be stored into the context1 field of the IOCB for the completion | |
2696 | * callback function to the LOGO ELS command. | |
2697 | * | |
2698 | * Return code | |
2699 | * 0 - successfully issued logo | |
2700 | * 1 - failed to issue logo | |
2701 | **/ | |
dea3101e | 2702 | int |
2e0fef85 | 2703 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2704 | uint8_t retry) |
2705 | { | |
2e0fef85 JS |
2706 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2707 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2708 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2709 | uint8_t *pcmd; |
2710 | uint16_t cmdsize; | |
92d7f7b0 | 2711 | int rc; |
dea3101e | 2712 | |
98c9ea5c JS |
2713 | spin_lock_irq(shost->host_lock); |
2714 | if (ndlp->nlp_flag & NLP_LOGO_SND) { | |
2715 | spin_unlock_irq(shost->host_lock); | |
2716 | return 0; | |
2717 | } | |
2718 | spin_unlock_irq(shost->host_lock); | |
2719 | ||
92d7f7b0 | 2720 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
2e0fef85 JS |
2721 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
2722 | ndlp->nlp_DID, ELS_CMD_LOGO); | |
488d1469 | 2723 | if (!elsiocb) |
c9f8735b | 2724 | return 1; |
dea3101e | 2725 | |
dea3101e JB |
2726 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2727 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
92d7f7b0 | 2728 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2729 | |
2730 | /* Fill in LOGO payload */ | |
2e0fef85 | 2731 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
92d7f7b0 JS |
2732 | pcmd += sizeof(uint32_t); |
2733 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
dea3101e | 2734 | |
858c9f6c JS |
2735 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2736 | "Issue LOGO: did:x%x", | |
2737 | ndlp->nlp_DID, 0, 0); | |
2738 | ||
086a345f JS |
2739 | /* |
2740 | * If we are issuing a LOGO, we may try to recover the remote NPort | |
2741 | * by issuing a PLOGI later. Even though we issue ELS cmds by the | |
2742 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while | |
2743 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI | |
2744 | * for that ELS cmd. To avoid this situation, lets get rid of the | |
2745 | * RPI right now, before any ELS cmds are sent. | |
2746 | */ | |
2747 | spin_lock_irq(shost->host_lock); | |
2748 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; | |
2749 | spin_unlock_irq(shost->host_lock); | |
2750 | if (lpfc_unreg_rpi(vport, ndlp)) { | |
2751 | lpfc_els_free_iocb(phba, elsiocb); | |
2752 | return 0; | |
2753 | } | |
2754 | ||
dea3101e JB |
2755 | phba->fc_stat.elsXmitLOGO++; |
2756 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; | |
2e0fef85 | 2757 | spin_lock_irq(shost->host_lock); |
dea3101e | 2758 | ndlp->nlp_flag |= NLP_LOGO_SND; |
086a345f | 2759 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
2e0fef85 | 2760 | spin_unlock_irq(shost->host_lock); |
3772a991 | 2761 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
92d7f7b0 JS |
2762 | |
2763 | if (rc == IOCB_ERROR) { | |
2e0fef85 | 2764 | spin_lock_irq(shost->host_lock); |
dea3101e | 2765 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 2766 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2767 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2768 | return 1; |
dea3101e | 2769 | } |
c9f8735b | 2770 | return 0; |
dea3101e JB |
2771 | } |
2772 | ||
e59058c4 | 2773 | /** |
3621a710 | 2774 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
e59058c4 JS |
2775 | * @phba: pointer to lpfc hba data structure. |
2776 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2777 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2778 | * | |
2779 | * This routine is a generic completion callback function for ELS commands. | |
2780 | * Specifically, it is the callback function which does not need to perform | |
2781 | * any command specific operations. It is currently used by the ELS command | |
2782 | * issuing routines for the ELS State Change Request (SCR), | |
2783 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution | |
2784 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than | |
2785 | * certain debug loggings, this callback function simply invokes the | |
2786 | * lpfc_els_chk_latt() routine to check whether link went down during the | |
2787 | * discovery process. | |
2788 | **/ | |
dea3101e | 2789 | static void |
2e0fef85 JS |
2790 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2791 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2792 | { |
2e0fef85 | 2793 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
2794 | IOCB_t *irsp; |
2795 | ||
2796 | irsp = &rspiocb->iocb; | |
2797 | ||
858c9f6c JS |
2798 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2799 | "ELS cmd cmpl: status:x%x/x%x did:x%x", | |
2800 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2801 | irsp->un.elsreq64.remoteID); | |
dea3101e | 2802 | /* ELS cmd tag <ulpIoTag> completes */ |
e8b62011 JS |
2803 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2804 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", | |
2805 | irsp->ulpIoTag, irsp->ulpStatus, | |
2806 | irsp->un.ulpWord[4], irsp->ulpTimeout); | |
dea3101e | 2807 | /* Check to see if link went down during discovery */ |
2e0fef85 | 2808 | lpfc_els_chk_latt(vport); |
dea3101e JB |
2809 | lpfc_els_free_iocb(phba, cmdiocb); |
2810 | return; | |
2811 | } | |
2812 | ||
e59058c4 | 2813 | /** |
3621a710 | 2814 | * lpfc_issue_els_scr - Issue a scr to an node on a vport |
e59058c4 JS |
2815 | * @vport: pointer to a host virtual N_Port data structure. |
2816 | * @nportid: N_Port identifier to the remote node. | |
2817 | * @retry: number of retries to the command IOCB. | |
2818 | * | |
2819 | * This routine issues a State Change Request (SCR) to a fabric node | |
2820 | * on a @vport. The remote node @nportid is passed into the function. It | |
2821 | * first search the @vport node list to find the matching ndlp. If no such | |
2822 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An | |
2823 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() | |
2824 | * routine is invoked to send the SCR IOCB. | |
2825 | * | |
2826 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2827 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2828 | * will be stored into the context1 field of the IOCB for the completion | |
2829 | * callback function to the SCR ELS command. | |
2830 | * | |
2831 | * Return code | |
2832 | * 0 - Successfully issued scr command | |
2833 | * 1 - Failed to issue scr command | |
2834 | **/ | |
dea3101e | 2835 | int |
2e0fef85 | 2836 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 2837 | { |
2e0fef85 | 2838 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2839 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2840 | uint8_t *pcmd; |
2841 | uint16_t cmdsize; | |
2842 | struct lpfc_nodelist *ndlp; | |
2843 | ||
92d7f7b0 | 2844 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
dea3101e | 2845 | |
e47c9093 JS |
2846 | ndlp = lpfc_findnode_did(vport, nportid); |
2847 | if (!ndlp) { | |
2848 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
2849 | if (!ndlp) | |
2850 | return 1; | |
2851 | lpfc_nlp_init(vport, ndlp, nportid); | |
2852 | lpfc_enqueue_node(vport, ndlp); | |
2853 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
2854 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
2855 | if (!ndlp) | |
2856 | return 1; | |
2857 | } | |
2e0fef85 JS |
2858 | |
2859 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
2860 | ndlp->nlp_DID, ELS_CMD_SCR); | |
dea3101e | 2861 | |
488d1469 | 2862 | if (!elsiocb) { |
fa4066b6 JS |
2863 | /* This will trigger the release of the node just |
2864 | * allocated | |
2865 | */ | |
329f9bc7 | 2866 | lpfc_nlp_put(ndlp); |
c9f8735b | 2867 | return 1; |
dea3101e JB |
2868 | } |
2869 | ||
dea3101e JB |
2870 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2871 | ||
2872 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; | |
92d7f7b0 | 2873 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2874 | |
2875 | /* For SCR, remainder of payload is SCR parameter page */ | |
92d7f7b0 | 2876 | memset(pcmd, 0, sizeof(SCR)); |
dea3101e JB |
2877 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
2878 | ||
858c9f6c JS |
2879 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2880 | "Issue SCR: did:x%x", | |
2881 | ndlp->nlp_DID, 0, 0); | |
2882 | ||
dea3101e JB |
2883 | phba->fc_stat.elsXmitSCR++; |
2884 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
3772a991 JS |
2885 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2886 | IOCB_ERROR) { | |
fa4066b6 JS |
2887 | /* The additional lpfc_nlp_put will cause the following |
2888 | * lpfc_els_free_iocb routine to trigger the rlease of | |
2889 | * the node. | |
2890 | */ | |
329f9bc7 | 2891 | lpfc_nlp_put(ndlp); |
dea3101e | 2892 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2893 | return 1; |
dea3101e | 2894 | } |
fa4066b6 JS |
2895 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
2896 | * trigger the release of node. | |
2897 | */ | |
cff261f6 | 2898 | |
329f9bc7 | 2899 | lpfc_nlp_put(ndlp); |
c9f8735b | 2900 | return 0; |
dea3101e JB |
2901 | } |
2902 | ||
e59058c4 | 2903 | /** |
3621a710 | 2904 | * lpfc_issue_els_farpr - Issue a farp to an node on a vport |
e59058c4 JS |
2905 | * @vport: pointer to a host virtual N_Port data structure. |
2906 | * @nportid: N_Port identifier to the remote node. | |
2907 | * @retry: number of retries to the command IOCB. | |
2908 | * | |
2909 | * This routine issues a Fibre Channel Address Resolution Response | |
2910 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) | |
2911 | * is passed into the function. It first search the @vport node list to find | |
2912 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created | |
2913 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the | |
2914 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. | |
2915 | * | |
2916 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2917 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2918 | * will be stored into the context1 field of the IOCB for the completion | |
2919 | * callback function to the PARPR ELS command. | |
2920 | * | |
2921 | * Return code | |
2922 | * 0 - Successfully issued farpr command | |
2923 | * 1 - Failed to issue farpr command | |
2924 | **/ | |
dea3101e | 2925 | static int |
2e0fef85 | 2926 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 2927 | { |
2e0fef85 | 2928 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2929 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2930 | FARP *fp; |
2931 | uint8_t *pcmd; | |
2932 | uint32_t *lp; | |
2933 | uint16_t cmdsize; | |
2934 | struct lpfc_nodelist *ondlp; | |
2935 | struct lpfc_nodelist *ndlp; | |
2936 | ||
92d7f7b0 | 2937 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
dea3101e | 2938 | |
e47c9093 JS |
2939 | ndlp = lpfc_findnode_did(vport, nportid); |
2940 | if (!ndlp) { | |
2941 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
2942 | if (!ndlp) | |
2943 | return 1; | |
2944 | lpfc_nlp_init(vport, ndlp, nportid); | |
2945 | lpfc_enqueue_node(vport, ndlp); | |
2946 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
2947 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
2948 | if (!ndlp) | |
2949 | return 1; | |
2950 | } | |
2e0fef85 JS |
2951 | |
2952 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
2953 | ndlp->nlp_DID, ELS_CMD_RNID); | |
488d1469 | 2954 | if (!elsiocb) { |
fa4066b6 JS |
2955 | /* This will trigger the release of the node just |
2956 | * allocated | |
2957 | */ | |
329f9bc7 | 2958 | lpfc_nlp_put(ndlp); |
c9f8735b | 2959 | return 1; |
dea3101e JB |
2960 | } |
2961 | ||
dea3101e JB |
2962 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2963 | ||
2964 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; | |
92d7f7b0 | 2965 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2966 | |
2967 | /* Fill in FARPR payload */ | |
2968 | fp = (FARP *) (pcmd); | |
92d7f7b0 | 2969 | memset(fp, 0, sizeof(FARP)); |
dea3101e JB |
2970 | lp = (uint32_t *) pcmd; |
2971 | *lp++ = be32_to_cpu(nportid); | |
2e0fef85 | 2972 | *lp++ = be32_to_cpu(vport->fc_myDID); |
dea3101e JB |
2973 | fp->Rflags = 0; |
2974 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); | |
2975 | ||
92d7f7b0 JS |
2976 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
2977 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 2978 | ondlp = lpfc_findnode_did(vport, nportid); |
e47c9093 | 2979 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
dea3101e | 2980 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
92d7f7b0 | 2981 | sizeof(struct lpfc_name)); |
dea3101e | 2982 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
92d7f7b0 | 2983 | sizeof(struct lpfc_name)); |
dea3101e JB |
2984 | } |
2985 | ||
858c9f6c JS |
2986 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2987 | "Issue FARPR: did:x%x", | |
2988 | ndlp->nlp_DID, 0, 0); | |
2989 | ||
dea3101e JB |
2990 | phba->fc_stat.elsXmitFARPR++; |
2991 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
3772a991 JS |
2992 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2993 | IOCB_ERROR) { | |
fa4066b6 JS |
2994 | /* The additional lpfc_nlp_put will cause the following |
2995 | * lpfc_els_free_iocb routine to trigger the release of | |
2996 | * the node. | |
2997 | */ | |
329f9bc7 | 2998 | lpfc_nlp_put(ndlp); |
dea3101e | 2999 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 3000 | return 1; |
dea3101e | 3001 | } |
fa4066b6 JS |
3002 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
3003 | * trigger the release of the node. | |
3004 | */ | |
329f9bc7 | 3005 | lpfc_nlp_put(ndlp); |
c9f8735b | 3006 | return 0; |
dea3101e JB |
3007 | } |
3008 | ||
e59058c4 | 3009 | /** |
3621a710 | 3010 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
e59058c4 JS |
3011 | * @vport: pointer to a host virtual N_Port data structure. |
3012 | * @nlp: pointer to a node-list data structure. | |
3013 | * | |
3014 | * This routine cancels the timer with a delayed IOCB-command retry for | |
3015 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and | |
3016 | * removes the ELS retry event if it presents. In addition, if the | |
3017 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB | |
3018 | * commands are sent for the @vport's nodes that require issuing discovery | |
3019 | * ADISC. | |
3020 | **/ | |
fdcebe28 | 3021 | void |
2e0fef85 | 3022 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
fdcebe28 | 3023 | { |
2e0fef85 | 3024 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
e47c9093 | 3025 | struct lpfc_work_evt *evtp; |
2e0fef85 | 3026 | |
0d2b6b83 JS |
3027 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
3028 | return; | |
2e0fef85 | 3029 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 3030 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
2e0fef85 | 3031 | spin_unlock_irq(shost->host_lock); |
fdcebe28 JS |
3032 | del_timer_sync(&nlp->nlp_delayfunc); |
3033 | nlp->nlp_last_elscmd = 0; | |
e47c9093 | 3034 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
fdcebe28 | 3035 | list_del_init(&nlp->els_retry_evt.evt_listp); |
e47c9093 JS |
3036 | /* Decrement nlp reference count held for the delayed retry */ |
3037 | evtp = &nlp->els_retry_evt; | |
3038 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | |
3039 | } | |
fdcebe28 | 3040 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
2e0fef85 | 3041 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 3042 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 JS |
3043 | spin_unlock_irq(shost->host_lock); |
3044 | if (vport->num_disc_nodes) { | |
0d2b6b83 JS |
3045 | if (vport->port_state < LPFC_VPORT_READY) { |
3046 | /* Check if there are more ADISCs to be sent */ | |
3047 | lpfc_more_adisc(vport); | |
0d2b6b83 JS |
3048 | } else { |
3049 | /* Check if there are more PLOGIs to be sent */ | |
3050 | lpfc_more_plogi(vport); | |
90160e01 JS |
3051 | if (vport->num_disc_nodes == 0) { |
3052 | spin_lock_irq(shost->host_lock); | |
3053 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
3054 | spin_unlock_irq(shost->host_lock); | |
3055 | lpfc_can_disctmo(vport); | |
3056 | lpfc_end_rscn(vport); | |
3057 | } | |
fdcebe28 JS |
3058 | } |
3059 | } | |
3060 | } | |
3061 | return; | |
3062 | } | |
3063 | ||
e59058c4 | 3064 | /** |
3621a710 | 3065 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
e59058c4 JS |
3066 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
3067 | * | |
3068 | * This routine is invoked by the ndlp delayed-function timer to check | |
3069 | * whether there is any pending ELS retry event(s) with the node. If not, it | |
3070 | * simply returns. Otherwise, if there is at least one ELS delayed event, it | |
3071 | * adds the delayed events to the HBA work list and invokes the | |
3072 | * lpfc_worker_wake_up() routine to wake up worker thread to process the | |
3073 | * event. Note that lpfc_nlp_get() is called before posting the event to | |
3074 | * the work list to hold reference count of ndlp so that it guarantees the | |
3075 | * reference to ndlp will still be available when the worker thread gets | |
3076 | * to the event associated with the ndlp. | |
3077 | **/ | |
dea3101e JB |
3078 | void |
3079 | lpfc_els_retry_delay(unsigned long ptr) | |
3080 | { | |
2e0fef85 JS |
3081 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
3082 | struct lpfc_vport *vport = ndlp->vport; | |
2e0fef85 | 3083 | struct lpfc_hba *phba = vport->phba; |
92d7f7b0 | 3084 | unsigned long flags; |
2e0fef85 | 3085 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
dea3101e | 3086 | |
92d7f7b0 | 3087 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 3088 | if (!list_empty(&evtp->evt_listp)) { |
92d7f7b0 | 3089 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
3090 | return; |
3091 | } | |
3092 | ||
fa4066b6 JS |
3093 | /* We need to hold the node by incrementing the reference |
3094 | * count until the queued work is done | |
3095 | */ | |
3096 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); | |
5e9d9b82 JS |
3097 | if (evtp->evt_arg1) { |
3098 | evtp->evt = LPFC_EVT_ELS_RETRY; | |
3099 | list_add_tail(&evtp->evt_listp, &phba->work_list); | |
92d7f7b0 | 3100 | lpfc_worker_wake_up(phba); |
5e9d9b82 | 3101 | } |
92d7f7b0 | 3102 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
3103 | return; |
3104 | } | |
3105 | ||
e59058c4 | 3106 | /** |
3621a710 | 3107 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
e59058c4 JS |
3108 | * @ndlp: pointer to a node-list data structure. |
3109 | * | |
3110 | * This routine is the worker-thread handler for processing the @ndlp delayed | |
3111 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves | |
3112 | * the last ELS command from the associated ndlp and invokes the proper ELS | |
3113 | * function according to the delayed ELS command to retry the command. | |
3114 | **/ | |
dea3101e JB |
3115 | void |
3116 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) | |
3117 | { | |
2e0fef85 JS |
3118 | struct lpfc_vport *vport = ndlp->vport; |
3119 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
eb016566 | 3120 | uint32_t cmd, retry; |
dea3101e | 3121 | |
2e0fef85 | 3122 | spin_lock_irq(shost->host_lock); |
5024ab17 JW |
3123 | cmd = ndlp->nlp_last_elscmd; |
3124 | ndlp->nlp_last_elscmd = 0; | |
dea3101e JB |
3125 | |
3126 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
2e0fef85 | 3127 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
3128 | return; |
3129 | } | |
3130 | ||
3131 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | |
2e0fef85 | 3132 | spin_unlock_irq(shost->host_lock); |
1a169689 JS |
3133 | /* |
3134 | * If a discovery event readded nlp_delayfunc after timer | |
3135 | * firing and before processing the timer, cancel the | |
3136 | * nlp_delayfunc. | |
3137 | */ | |
3138 | del_timer_sync(&ndlp->nlp_delayfunc); | |
dea3101e | 3139 | retry = ndlp->nlp_retry; |
4d9ab994 | 3140 | ndlp->nlp_retry = 0; |
dea3101e JB |
3141 | |
3142 | switch (cmd) { | |
3143 | case ELS_CMD_FLOGI: | |
2e0fef85 | 3144 | lpfc_issue_els_flogi(vport, ndlp, retry); |
dea3101e JB |
3145 | break; |
3146 | case ELS_CMD_PLOGI: | |
2e0fef85 | 3147 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
5024ab17 | 3148 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3149 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
6ad42535 | 3150 | } |
dea3101e JB |
3151 | break; |
3152 | case ELS_CMD_ADISC: | |
2e0fef85 | 3153 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
5024ab17 | 3154 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3155 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
6ad42535 | 3156 | } |
dea3101e JB |
3157 | break; |
3158 | case ELS_CMD_PRLI: | |
a0f2d3ef | 3159 | case ELS_CMD_NVMEPRLI: |
2e0fef85 | 3160 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
5024ab17 | 3161 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
6ad42535 | 3163 | } |
dea3101e JB |
3164 | break; |
3165 | case ELS_CMD_LOGO: | |
2e0fef85 | 3166 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
5024ab17 | 3167 | ndlp->nlp_prev_state = ndlp->nlp_state; |
086a345f | 3168 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
6ad42535 | 3169 | } |
dea3101e | 3170 | break; |
92d7f7b0 | 3171 | case ELS_CMD_FDISC: |
fedd3b7b JS |
3172 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
3173 | lpfc_issue_els_fdisc(vport, ndlp, retry); | |
92d7f7b0 | 3174 | break; |
dea3101e JB |
3175 | } |
3176 | return; | |
3177 | } | |
3178 | ||
e59058c4 | 3179 | /** |
3621a710 | 3180 | * lpfc_els_retry - Make retry decision on an els command iocb |
e59058c4 JS |
3181 | * @phba: pointer to lpfc hba data structure. |
3182 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3183 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3184 | * | |
3185 | * This routine makes a retry decision on an ELS command IOCB, which has | |
3186 | * failed. The following ELS IOCBs use this function for retrying the command | |
3187 | * when previously issued command responsed with error status: FLOGI, PLOGI, | |
3188 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the | |
3189 | * returned error status, it makes the decision whether a retry shall be | |
3190 | * issued for the command, and whether a retry shall be made immediately or | |
3191 | * delayed. In the former case, the corresponding ELS command issuing-function | |
3192 | * is called to retry the command. In the later case, the ELS command shall | |
3193 | * be posted to the ndlp delayed event and delayed function timer set to the | |
3194 | * ndlp for the delayed command issusing. | |
3195 | * | |
3196 | * Return code | |
3197 | * 0 - No retry of els command is made | |
3198 | * 1 - Immediate or delayed retry of els command is made | |
3199 | **/ | |
dea3101e | 3200 | static int |
2e0fef85 JS |
3201 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
3202 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 3203 | { |
2e0fef85 JS |
3204 | struct lpfc_vport *vport = cmdiocb->vport; |
3205 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
3206 | IOCB_t *irsp = &rspiocb->iocb; | |
3207 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
3208 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
dea3101e JB |
3209 | uint32_t *elscmd; |
3210 | struct ls_rjt stat; | |
2e0fef85 | 3211 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
98c9ea5c | 3212 | int logerr = 0; |
2e0fef85 | 3213 | uint32_t cmd = 0; |
488d1469 | 3214 | uint32_t did; |
dea3101e | 3215 | |
488d1469 | 3216 | |
dea3101e JB |
3217 | /* Note: context2 may be 0 for internal driver abort |
3218 | * of delays ELS command. | |
3219 | */ | |
3220 | ||
3221 | if (pcmd && pcmd->virt) { | |
3222 | elscmd = (uint32_t *) (pcmd->virt); | |
3223 | cmd = *elscmd++; | |
3224 | } | |
3225 | ||
e47c9093 | 3226 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
488d1469 JS |
3227 | did = ndlp->nlp_DID; |
3228 | else { | |
3229 | /* We should only hit this case for retrying PLOGI */ | |
3230 | did = irsp->un.elsreq64.remoteID; | |
2e0fef85 | 3231 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
3232 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
3233 | && (cmd != ELS_CMD_PLOGI)) | |
488d1469 JS |
3234 | return 1; |
3235 | } | |
3236 | ||
858c9f6c JS |
3237 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
3238 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", | |
3239 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); | |
3240 | ||
dea3101e JB |
3241 | switch (irsp->ulpStatus) { |
3242 | case IOSTAT_FCP_RSP_ERROR: | |
1151e3ec | 3243 | break; |
dea3101e | 3244 | case IOSTAT_REMOTE_STOP: |
1151e3ec JS |
3245 | if (phba->sli_rev == LPFC_SLI_REV4) { |
3246 | /* This IO was aborted by the target, we don't | |
3247 | * know the rxid and because we did not send the | |
3248 | * ABTS we cannot generate and RRQ. | |
3249 | */ | |
3250 | lpfc_set_rrq_active(phba, ndlp, | |
ee0f4fe1 | 3251 | cmdiocb->sli4_lxritag, 0, 0); |
1151e3ec | 3252 | } |
dea3101e | 3253 | break; |
dea3101e | 3254 | case IOSTAT_LOCAL_REJECT: |
e3d2b802 | 3255 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
dea3101e | 3256 | case IOERR_LOOP_OPEN_FAILURE: |
eaf15d5b JS |
3257 | if (cmd == ELS_CMD_FLOGI) { |
3258 | if (PCI_DEVICE_ID_HORNET == | |
3259 | phba->pcidev->device) { | |
76a95d75 | 3260 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
eaf15d5b JS |
3261 | phba->pport->fc_myDID = 0; |
3262 | phba->alpa_map[0] = 0; | |
3263 | phba->alpa_map[1] = 0; | |
3264 | } | |
3265 | } | |
2e0fef85 | 3266 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
92d7f7b0 | 3267 | delay = 1000; |
dea3101e JB |
3268 | retry = 1; |
3269 | break; | |
3270 | ||
92d7f7b0 | 3271 | case IOERR_ILLEGAL_COMMAND: |
7f5f3d0d JS |
3272 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3273 | "0124 Retry illegal cmd x%x " | |
3274 | "retry:x%x delay:x%x\n", | |
3275 | cmd, cmdiocb->retry, delay); | |
3276 | retry = 1; | |
3277 | /* All command's retry policy */ | |
3278 | maxretry = 8; | |
3279 | if (cmdiocb->retry > 2) | |
3280 | delay = 1000; | |
92d7f7b0 JS |
3281 | break; |
3282 | ||
dea3101e | 3283 | case IOERR_NO_RESOURCES: |
98c9ea5c | 3284 | logerr = 1; /* HBA out of resources */ |
858c9f6c JS |
3285 | retry = 1; |
3286 | if (cmdiocb->retry > 100) | |
3287 | delay = 100; | |
3288 | maxretry = 250; | |
3289 | break; | |
3290 | ||
3291 | case IOERR_ILLEGAL_FRAME: | |
92d7f7b0 | 3292 | delay = 100; |
dea3101e JB |
3293 | retry = 1; |
3294 | break; | |
3295 | ||
858c9f6c | 3296 | case IOERR_SEQUENCE_TIMEOUT: |
dea3101e | 3297 | case IOERR_INVALID_RPI: |
5b5b36a9 JS |
3298 | if (cmd == ELS_CMD_PLOGI && |
3299 | did == NameServer_DID) { | |
3300 | /* Continue forever if plogi to */ | |
3301 | /* the nameserver fails */ | |
3302 | maxretry = 0; | |
3303 | delay = 100; | |
3304 | } | |
dea3101e JB |
3305 | retry = 1; |
3306 | break; | |
3307 | } | |
3308 | break; | |
3309 | ||
3310 | case IOSTAT_NPORT_RJT: | |
3311 | case IOSTAT_FABRIC_RJT: | |
3312 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
3313 | retry = 1; | |
3314 | break; | |
3315 | } | |
3316 | break; | |
3317 | ||
3318 | case IOSTAT_NPORT_BSY: | |
3319 | case IOSTAT_FABRIC_BSY: | |
98c9ea5c | 3320 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
dea3101e JB |
3321 | retry = 1; |
3322 | break; | |
3323 | ||
3324 | case IOSTAT_LS_RJT: | |
3325 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); | |
3326 | /* Added for Vendor specifc support | |
3327 | * Just keep retrying for these Rsn / Exp codes | |
3328 | */ | |
3329 | switch (stat.un.b.lsRjtRsnCode) { | |
3330 | case LSRJT_UNABLE_TPC: | |
3331 | if (stat.un.b.lsRjtRsnCodeExp == | |
3332 | LSEXP_CMD_IN_PROGRESS) { | |
3333 | if (cmd == ELS_CMD_PLOGI) { | |
92d7f7b0 | 3334 | delay = 1000; |
dea3101e JB |
3335 | maxretry = 48; |
3336 | } | |
3337 | retry = 1; | |
3338 | break; | |
3339 | } | |
ffc95493 JS |
3340 | if (stat.un.b.lsRjtRsnCodeExp == |
3341 | LSEXP_CANT_GIVE_DATA) { | |
3342 | if (cmd == ELS_CMD_PLOGI) { | |
3343 | delay = 1000; | |
3344 | maxretry = 48; | |
3345 | } | |
3346 | retry = 1; | |
3347 | break; | |
3348 | } | |
4c1b64ba | 3349 | if ((cmd == ELS_CMD_PLOGI) || |
a0f2d3ef JS |
3350 | (cmd == ELS_CMD_PRLI) || |
3351 | (cmd == ELS_CMD_NVMEPRLI)) { | |
92d7f7b0 | 3352 | delay = 1000; |
dea3101e JB |
3353 | maxretry = lpfc_max_els_tries + 1; |
3354 | retry = 1; | |
3355 | break; | |
3356 | } | |
92d7f7b0 JS |
3357 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
3358 | (cmd == ELS_CMD_FDISC) && | |
3359 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ | |
e8b62011 JS |
3360 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3361 | "0125 FDISC Failed (x%x). " | |
3362 | "Fabric out of resources\n", | |
3363 | stat.un.lsRjtError); | |
92d7f7b0 JS |
3364 | lpfc_vport_set_state(vport, |
3365 | FC_VPORT_NO_FABRIC_RSCS); | |
3366 | } | |
dea3101e JB |
3367 | break; |
3368 | ||
3369 | case LSRJT_LOGICAL_BSY: | |
858c9f6c | 3370 | if ((cmd == ELS_CMD_PLOGI) || |
a0f2d3ef JS |
3371 | (cmd == ELS_CMD_PRLI) || |
3372 | (cmd == ELS_CMD_NVMEPRLI)) { | |
92d7f7b0 | 3373 | delay = 1000; |
dea3101e | 3374 | maxretry = 48; |
92d7f7b0 | 3375 | } else if (cmd == ELS_CMD_FDISC) { |
51ef4c26 JS |
3376 | /* FDISC retry policy */ |
3377 | maxretry = 48; | |
3378 | if (cmdiocb->retry >= 32) | |
3379 | delay = 1000; | |
dea3101e JB |
3380 | } |
3381 | retry = 1; | |
3382 | break; | |
92d7f7b0 JS |
3383 | |
3384 | case LSRJT_LOGICAL_ERR: | |
7f5f3d0d JS |
3385 | /* There are some cases where switches return this |
3386 | * error when they are not ready and should be returning | |
3387 | * Logical Busy. We should delay every time. | |
3388 | */ | |
3389 | if (cmd == ELS_CMD_FDISC && | |
3390 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { | |
3391 | maxretry = 3; | |
3392 | delay = 1000; | |
3393 | retry = 1; | |
3394 | break; | |
3395 | } | |
92d7f7b0 JS |
3396 | case LSRJT_PROTOCOL_ERR: |
3397 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
3398 | (cmd == ELS_CMD_FDISC) && | |
3399 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || | |
3400 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) | |
3401 | ) { | |
e8b62011 | 3402 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
d7c255b2 | 3403 | "0122 FDISC Failed (x%x). " |
e8b62011 JS |
3404 | "Fabric Detected Bad WWN\n", |
3405 | stat.un.lsRjtError); | |
92d7f7b0 JS |
3406 | lpfc_vport_set_state(vport, |
3407 | FC_VPORT_FABRIC_REJ_WWN); | |
3408 | } | |
3409 | break; | |
7bdedb34 JS |
3410 | case LSRJT_VENDOR_UNIQUE: |
3411 | if ((stat.un.b.vendorUnique == 0x45) && | |
3412 | (cmd == ELS_CMD_FLOGI)) { | |
3413 | goto out_retry; | |
3414 | } | |
3415 | break; | |
dea3101e JB |
3416 | } |
3417 | break; | |
3418 | ||
3419 | case IOSTAT_INTERMED_RSP: | |
3420 | case IOSTAT_BA_RJT: | |
3421 | break; | |
3422 | ||
3423 | default: | |
3424 | break; | |
3425 | } | |
3426 | ||
488d1469 | 3427 | if (did == FDMI_DID) |
dea3101e | 3428 | retry = 1; |
dea3101e | 3429 | |
df9e1b59 | 3430 | if ((cmd == ELS_CMD_FLOGI) && |
76a95d75 | 3431 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
1b32f6aa | 3432 | !lpfc_error_lost_link(irsp)) { |
98c9ea5c JS |
3433 | /* FLOGI retry policy */ |
3434 | retry = 1; | |
df9e1b59 | 3435 | /* retry FLOGI forever */ |
6eae4303 JS |
3436 | if (phba->link_flag != LS_LOOPBACK_MODE) |
3437 | maxretry = 0; | |
3438 | else | |
3439 | maxretry = 2; | |
3440 | ||
6669f9bb JS |
3441 | if (cmdiocb->retry >= 100) |
3442 | delay = 5000; | |
3443 | else if (cmdiocb->retry >= 32) | |
98c9ea5c | 3444 | delay = 1000; |
df9e1b59 JS |
3445 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
3446 | /* retry FDISCs every second up to devloss */ | |
3447 | retry = 1; | |
3448 | maxretry = vport->cfg_devloss_tmo; | |
3449 | delay = 1000; | |
98c9ea5c JS |
3450 | } |
3451 | ||
6669f9bb JS |
3452 | cmdiocb->retry++; |
3453 | if (maxretry && (cmdiocb->retry >= maxretry)) { | |
dea3101e JB |
3454 | phba->fc_stat.elsRetryExceeded++; |
3455 | retry = 0; | |
3456 | } | |
3457 | ||
ed957684 JS |
3458 | if ((vport->load_flag & FC_UNLOADING) != 0) |
3459 | retry = 0; | |
3460 | ||
7bdedb34 | 3461 | out_retry: |
dea3101e | 3462 | if (retry) { |
38b92ef8 JS |
3463 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
3464 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ | |
3465 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { | |
3466 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
3467 | "2849 Stop retry ELS command " | |
3468 | "x%x to remote NPORT x%x, " | |
3469 | "Data: x%x x%x\n", cmd, did, | |
3470 | cmdiocb->retry, delay); | |
3471 | return 0; | |
3472 | } | |
3473 | } | |
dea3101e JB |
3474 | |
3475 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
3476 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3477 | "0107 Retry ELS command x%x to remote " | |
3478 | "NPORT x%x Data: x%x x%x\n", | |
3479 | cmd, did, cmdiocb->retry, delay); | |
dea3101e | 3480 | |
858c9f6c JS |
3481 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
3482 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | |
e3d2b802 JS |
3483 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
3484 | IOERR_NO_RESOURCES))) { | |
858c9f6c JS |
3485 | /* Don't reset timer for no resources */ |
3486 | ||
dea3101e | 3487 | /* If discovery / RSCN timer is running, reset it */ |
2e0fef85 | 3488 | if (timer_pending(&vport->fc_disctmo) || |
92d7f7b0 | 3489 | (vport->fc_flag & FC_RSCN_MODE)) |
2e0fef85 | 3490 | lpfc_set_disctmo(vport); |
dea3101e JB |
3491 | } |
3492 | ||
3493 | phba->fc_stat.elsXmitRetry++; | |
58da1ffb | 3494 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
dea3101e JB |
3495 | phba->fc_stat.elsDelayRetry++; |
3496 | ndlp->nlp_retry = cmdiocb->retry; | |
3497 | ||
92d7f7b0 JS |
3498 | /* delay is specified in milliseconds */ |
3499 | mod_timer(&ndlp->nlp_delayfunc, | |
3500 | jiffies + msecs_to_jiffies(delay)); | |
2e0fef85 | 3501 | spin_lock_irq(shost->host_lock); |
dea3101e | 3502 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 3503 | spin_unlock_irq(shost->host_lock); |
dea3101e | 3504 | |
5024ab17 | 3505 | ndlp->nlp_prev_state = ndlp->nlp_state; |
a0f2d3ef JS |
3506 | if ((cmd == ELS_CMD_PRLI) || |
3507 | (cmd == ELS_CMD_NVMEPRLI)) | |
858c9f6c | 3508 | lpfc_nlp_set_state(vport, ndlp, |
4c1b64ba | 3509 | NLP_STE_PRLI_ISSUE); |
858c9f6c JS |
3510 | else |
3511 | lpfc_nlp_set_state(vport, ndlp, | |
3512 | NLP_STE_NPR_NODE); | |
dea3101e JB |
3513 | ndlp->nlp_last_elscmd = cmd; |
3514 | ||
c9f8735b | 3515 | return 1; |
dea3101e JB |
3516 | } |
3517 | switch (cmd) { | |
3518 | case ELS_CMD_FLOGI: | |
2e0fef85 | 3519 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
c9f8735b | 3520 | return 1; |
92d7f7b0 JS |
3521 | case ELS_CMD_FDISC: |
3522 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); | |
3523 | return 1; | |
dea3101e | 3524 | case ELS_CMD_PLOGI: |
58da1ffb | 3525 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
488d1469 | 3526 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3527 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 3528 | NLP_STE_PLOGI_ISSUE); |
488d1469 | 3529 | } |
2e0fef85 | 3530 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
c9f8735b | 3531 | return 1; |
dea3101e | 3532 | case ELS_CMD_ADISC: |
5024ab17 | 3533 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
3534 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
3535 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 3536 | return 1; |
dea3101e | 3537 | case ELS_CMD_PRLI: |
a0f2d3ef | 3538 | case ELS_CMD_NVMEPRLI: |
5024ab17 | 3539 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
3540 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
3541 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 3542 | return 1; |
dea3101e | 3543 | case ELS_CMD_LOGO: |
5024ab17 | 3544 | ndlp->nlp_prev_state = ndlp->nlp_state; |
086a345f | 3545 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
2e0fef85 | 3546 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
c9f8735b | 3547 | return 1; |
dea3101e JB |
3548 | } |
3549 | } | |
dea3101e | 3550 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
98c9ea5c JS |
3551 | if (logerr) { |
3552 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
3553 | "0137 No retry ELS command x%x to remote " | |
3554 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", | |
3555 | cmd, did, irsp->ulpStatus, | |
3556 | irsp->un.ulpWord[4]); | |
3557 | } | |
3558 | else { | |
3559 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
a58cbd52 JS |
3560 | "0108 No retry ELS command x%x to remote " |
3561 | "NPORT x%x Retried:%d Error:x%x/%x\n", | |
3562 | cmd, did, cmdiocb->retry, irsp->ulpStatus, | |
3563 | irsp->un.ulpWord[4]); | |
98c9ea5c | 3564 | } |
c9f8735b | 3565 | return 0; |
dea3101e JB |
3566 | } |
3567 | ||
e59058c4 | 3568 | /** |
3621a710 | 3569 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb |
e59058c4 JS |
3570 | * @phba: pointer to lpfc hba data structure. |
3571 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. | |
3572 | * | |
3573 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) | |
3574 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first | |
3575 | * checks to see whether there is a lpfc DMA buffer associated with the | |
3576 | * response of the command IOCB. If so, it will be released before releasing | |
3577 | * the lpfc DMA buffer associated with the IOCB itself. | |
3578 | * | |
3579 | * Return code | |
3580 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) | |
3581 | **/ | |
09372820 | 3582 | static int |
87af33fe JS |
3583 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
3584 | { | |
3585 | struct lpfc_dmabuf *buf_ptr; | |
3586 | ||
e59058c4 | 3587 | /* Free the response before processing the command. */ |
87af33fe JS |
3588 | if (!list_empty(&buf_ptr1->list)) { |
3589 | list_remove_head(&buf_ptr1->list, buf_ptr, | |
3590 | struct lpfc_dmabuf, | |
3591 | list); | |
3592 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
3593 | kfree(buf_ptr); | |
3594 | } | |
3595 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); | |
3596 | kfree(buf_ptr1); | |
3597 | return 0; | |
3598 | } | |
3599 | ||
e59058c4 | 3600 | /** |
3621a710 | 3601 | * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl |
e59058c4 JS |
3602 | * @phba: pointer to lpfc hba data structure. |
3603 | * @buf_ptr: pointer to the lpfc dma buffer data structure. | |
3604 | * | |
3605 | * This routine releases the lpfc Direct Memory Access (DMA) buffer | |
3606 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer | |
3607 | * pool. | |
3608 | * | |
3609 | * Return code | |
3610 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) | |
3611 | **/ | |
09372820 | 3612 | static int |
87af33fe JS |
3613 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
3614 | { | |
3615 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
3616 | kfree(buf_ptr); | |
3617 | return 0; | |
3618 | } | |
3619 | ||
e59058c4 | 3620 | /** |
3621a710 | 3621 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
e59058c4 JS |
3622 | * @phba: pointer to lpfc hba data structure. |
3623 | * @elsiocb: pointer to lpfc els command iocb data structure. | |
3624 | * | |
3625 | * This routine frees a command IOCB and its associated resources. The | |
3626 | * command IOCB data structure contains the reference to various associated | |
3627 | * resources, these fields must be set to NULL if the associated reference | |
3628 | * not present: | |
3629 | * context1 - reference to ndlp | |
3630 | * context2 - reference to cmd | |
3631 | * context2->next - reference to rsp | |
3632 | * context3 - reference to bpl | |
3633 | * | |
3634 | * It first properly decrements the reference count held on ndlp for the | |
3635 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not | |
3636 | * set, it invokes the lpfc_els_free_data() routine to release the Direct | |
3637 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it | |
3638 | * adds the DMA buffer the @phba data structure for the delayed release. | |
3639 | * If reference to the Buffer Pointer List (BPL) is present, the | |
3640 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory | |
3641 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is | |
3642 | * invoked to release the IOCB data structure back to @phba IOCBQ list. | |
3643 | * | |
3644 | * Return code | |
3645 | * 0 - Success (currently, always return 0) | |
3646 | **/ | |
dea3101e | 3647 | int |
329f9bc7 | 3648 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
dea3101e JB |
3649 | { |
3650 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; | |
a8adb832 JS |
3651 | struct lpfc_nodelist *ndlp; |
3652 | ||
3653 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; | |
3654 | if (ndlp) { | |
3655 | if (ndlp->nlp_flag & NLP_DEFER_RM) { | |
3656 | lpfc_nlp_put(ndlp); | |
dea3101e | 3657 | |
a8adb832 JS |
3658 | /* If the ndlp is not being used by another discovery |
3659 | * thread, free it. | |
3660 | */ | |
3661 | if (!lpfc_nlp_not_used(ndlp)) { | |
3662 | /* If ndlp is being used by another discovery | |
3663 | * thread, just clear NLP_DEFER_RM | |
3664 | */ | |
3665 | ndlp->nlp_flag &= ~NLP_DEFER_RM; | |
3666 | } | |
3667 | } | |
3668 | else | |
3669 | lpfc_nlp_put(ndlp); | |
329f9bc7 JS |
3670 | elsiocb->context1 = NULL; |
3671 | } | |
dea3101e JB |
3672 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
3673 | if (elsiocb->context2) { | |
0ff10d46 JS |
3674 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
3675 | /* Firmware could still be in progress of DMAing | |
3676 | * payload, so don't free data buffer till after | |
3677 | * a hbeat. | |
3678 | */ | |
3679 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; | |
3680 | buf_ptr = elsiocb->context2; | |
3681 | elsiocb->context2 = NULL; | |
3682 | if (buf_ptr) { | |
3683 | buf_ptr1 = NULL; | |
3684 | spin_lock_irq(&phba->hbalock); | |
3685 | if (!list_empty(&buf_ptr->list)) { | |
3686 | list_remove_head(&buf_ptr->list, | |
3687 | buf_ptr1, struct lpfc_dmabuf, | |
3688 | list); | |
3689 | INIT_LIST_HEAD(&buf_ptr1->list); | |
3690 | list_add_tail(&buf_ptr1->list, | |
3691 | &phba->elsbuf); | |
3692 | phba->elsbuf_cnt++; | |
3693 | } | |
3694 | INIT_LIST_HEAD(&buf_ptr->list); | |
3695 | list_add_tail(&buf_ptr->list, &phba->elsbuf); | |
3696 | phba->elsbuf_cnt++; | |
3697 | spin_unlock_irq(&phba->hbalock); | |
3698 | } | |
3699 | } else { | |
3700 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; | |
3701 | lpfc_els_free_data(phba, buf_ptr1); | |
8667f515 | 3702 | elsiocb->context2 = NULL; |
0ff10d46 | 3703 | } |
dea3101e JB |
3704 | } |
3705 | ||
3706 | if (elsiocb->context3) { | |
3707 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; | |
87af33fe | 3708 | lpfc_els_free_bpl(phba, buf_ptr); |
8667f515 | 3709 | elsiocb->context3 = NULL; |
dea3101e | 3710 | } |
604a3e30 | 3711 | lpfc_sli_release_iocbq(phba, elsiocb); |
dea3101e JB |
3712 | return 0; |
3713 | } | |
3714 | ||
e59058c4 | 3715 | /** |
3621a710 | 3716 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
e59058c4 JS |
3717 | * @phba: pointer to lpfc hba data structure. |
3718 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3719 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3720 | * | |
3721 | * This routine is the completion callback function to the Logout (LOGO) | |
3722 | * Accept (ACC) Response ELS command. This routine is invoked to indicate | |
3723 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to | |
3724 | * release the ndlp if it has the last reference remaining (reference count | |
3725 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 | |
3726 | * field to NULL to inform the following lpfc_els_free_iocb() routine no | |
3727 | * ndlp reference count needs to be decremented. Otherwise, the ndlp | |
3728 | * reference use-count shall be decremented by the lpfc_els_free_iocb() | |
3729 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the | |
3730 | * IOCB data structure. | |
3731 | **/ | |
dea3101e | 3732 | static void |
2e0fef85 JS |
3733 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
3734 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 3735 | { |
2e0fef85 JS |
3736 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
3737 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c JS |
3738 | IOCB_t *irsp; |
3739 | ||
3740 | irsp = &rspiocb->iocb; | |
3741 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
3742 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", | |
3743 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); | |
dea3101e | 3744 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
3745 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3746 | "0109 ACC to LOGO completes to NPort x%x " | |
3747 | "Data: x%x x%x x%x\n", | |
3748 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3749 | ndlp->nlp_rpi); | |
87af33fe JS |
3750 | |
3751 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | |
3752 | /* NPort Recovery mode or node is just allocated */ | |
3753 | if (!lpfc_nlp_not_used(ndlp)) { | |
3754 | /* If the ndlp is being used by another discovery | |
3755 | * thread, just unregister the RPI. | |
3756 | */ | |
3757 | lpfc_unreg_rpi(vport, ndlp); | |
fa4066b6 JS |
3758 | } else { |
3759 | /* Indicate the node has already released, should | |
3760 | * not reference to it from within lpfc_els_free_iocb. | |
3761 | */ | |
3762 | cmdiocb->context1 = NULL; | |
87af33fe | 3763 | } |
dea3101e | 3764 | } |
73d91e50 JS |
3765 | |
3766 | /* | |
3767 | * The driver received a LOGO from the rport and has ACK'd it. | |
df9e1b59 | 3768 | * At this point, the driver is done so release the IOCB |
73d91e50 | 3769 | */ |
dea3101e | 3770 | lpfc_els_free_iocb(phba, cmdiocb); |
dea3101e JB |
3771 | } |
3772 | ||
e59058c4 | 3773 | /** |
3621a710 | 3774 | * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd |
e59058c4 JS |
3775 | * @phba: pointer to lpfc hba data structure. |
3776 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
3777 | * | |
3778 | * This routine is the completion callback function for unregister default | |
3779 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases | |
3780 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and | |
3781 | * decrements the ndlp reference count held for this completion callback | |
3782 | * function. After that, it invokes the lpfc_nlp_not_used() to check | |
3783 | * whether there is only one reference left on the ndlp. If so, it will | |
3784 | * perform one more decrement and trigger the release of the ndlp. | |
3785 | **/ | |
858c9f6c JS |
3786 | void |
3787 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
3788 | { | |
3789 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | |
3790 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
3791 | ||
3792 | pmb->context1 = NULL; | |
d439d286 JS |
3793 | pmb->context2 = NULL; |
3794 | ||
858c9f6c JS |
3795 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3796 | kfree(mp); | |
3797 | mempool_free(pmb, phba->mbox_mem_pool); | |
086a345f | 3798 | if (ndlp) { |
be6bb941 JS |
3799 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
3800 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", | |
3801 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 3802 | kref_read(&ndlp->kref), |
be6bb941 | 3803 | ndlp->nlp_usg_map, ndlp); |
086a345f JS |
3804 | if (NLP_CHK_NODE_ACT(ndlp)) { |
3805 | lpfc_nlp_put(ndlp); | |
3806 | /* This is the end of the default RPI cleanup logic for | |
3807 | * this ndlp. If no other discovery threads are using | |
3808 | * this ndlp, free all resources associated with it. | |
3809 | */ | |
3810 | lpfc_nlp_not_used(ndlp); | |
3811 | } else { | |
3812 | lpfc_drop_node(ndlp->vport, ndlp); | |
3813 | } | |
a8adb832 | 3814 | } |
3772a991 | 3815 | |
858c9f6c JS |
3816 | return; |
3817 | } | |
3818 | ||
e59058c4 | 3819 | /** |
3621a710 | 3820 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
e59058c4 JS |
3821 | * @phba: pointer to lpfc hba data structure. |
3822 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3823 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3824 | * | |
3825 | * This routine is the completion callback function for ELS Response IOCB | |
3826 | * command. In normal case, this callback function just properly sets the | |
3827 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference | |
3828 | * field in the command IOCB is not NULL, the referred mailbox command will | |
3829 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release | |
3830 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a | |
3831 | * link down event occurred during the discovery, the lpfc_nlp_not_used() | |
3832 | * routine shall be invoked trying to release the ndlp if no other threads | |
3833 | * are currently referring it. | |
3834 | **/ | |
dea3101e | 3835 | static void |
858c9f6c | 3836 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
329f9bc7 | 3837 | struct lpfc_iocbq *rspiocb) |
dea3101e | 3838 | { |
2e0fef85 JS |
3839 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
3840 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; | |
3841 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; | |
87af33fe JS |
3842 | IOCB_t *irsp; |
3843 | uint8_t *pcmd; | |
dea3101e | 3844 | LPFC_MBOXQ_t *mbox = NULL; |
2e0fef85 | 3845 | struct lpfc_dmabuf *mp = NULL; |
87af33fe | 3846 | uint32_t ls_rjt = 0; |
dea3101e | 3847 | |
33ccf8d1 JS |
3848 | irsp = &rspiocb->iocb; |
3849 | ||
dea3101e JB |
3850 | if (cmdiocb->context_un.mbox) |
3851 | mbox = cmdiocb->context_un.mbox; | |
3852 | ||
fa4066b6 JS |
3853 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
3854 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. | |
3855 | */ | |
87af33fe | 3856 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
58da1ffb JS |
3857 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
3858 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { | |
fa4066b6 | 3859 | /* A LS_RJT associated with Default RPI cleanup has its own |
3ad2f3fb | 3860 | * separate code path. |
87af33fe JS |
3861 | */ |
3862 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
3863 | ls_rjt = 1; | |
3864 | } | |
3865 | ||
dea3101e | 3866 | /* Check to see if link went down during discovery */ |
58da1ffb | 3867 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
dea3101e | 3868 | if (mbox) { |
14691150 JS |
3869 | mp = (struct lpfc_dmabuf *) mbox->context1; |
3870 | if (mp) { | |
3871 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
3872 | kfree(mp); | |
3873 | } | |
329f9bc7 | 3874 | mempool_free(mbox, phba->mbox_mem_pool); |
dea3101e | 3875 | } |
58da1ffb JS |
3876 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
3877 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
fa4066b6 | 3878 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3879 | ndlp = NULL; |
fa4066b6 JS |
3880 | /* Indicate the node has already released, |
3881 | * should not reference to it from within | |
3882 | * the routine lpfc_els_free_iocb. | |
3883 | */ | |
3884 | cmdiocb->context1 = NULL; | |
3885 | } | |
dea3101e JB |
3886 | goto out; |
3887 | } | |
3888 | ||
858c9f6c | 3889 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
51ef4c26 | 3890 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
858c9f6c | 3891 | irsp->ulpStatus, irsp->un.ulpWord[4], |
51ef4c26 | 3892 | cmdiocb->iocb.un.elsreq64.remoteID); |
dea3101e | 3893 | /* ELS response tag <ulpIoTag> completes */ |
e8b62011 JS |
3894 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3895 | "0110 ELS response tag x%x completes " | |
3896 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", | |
3897 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, | |
3898 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, | |
3899 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3900 | ndlp->nlp_rpi); | |
dea3101e JB |
3901 | if (mbox) { |
3902 | if ((rspiocb->iocb.ulpStatus == 0) | |
3903 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { | |
2e0fef85 | 3904 | lpfc_unreg_rpi(vport, ndlp); |
e47c9093 JS |
3905 | /* Increment reference count to ndlp to hold the |
3906 | * reference to ndlp for the callback function. | |
3907 | */ | |
329f9bc7 | 3908 | mbox->context2 = lpfc_nlp_get(ndlp); |
2e0fef85 | 3909 | mbox->vport = vport; |
858c9f6c JS |
3910 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
3911 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
3912 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
3913 | } | |
3914 | else { | |
3915 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | |
3916 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
3917 | lpfc_nlp_set_state(vport, ndlp, | |
2e0fef85 | 3918 | NLP_STE_REG_LOGIN_ISSUE); |
858c9f6c | 3919 | } |
4b7789b7 JS |
3920 | |
3921 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; | |
0b727fea | 3922 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
e47c9093 | 3923 | != MBX_NOT_FINISHED) |
dea3101e | 3924 | goto out; |
4b7789b7 JS |
3925 | |
3926 | /* Decrement the ndlp reference count we | |
3927 | * set for this failed mailbox command. | |
3928 | */ | |
3929 | lpfc_nlp_put(ndlp); | |
3930 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; | |
98c9ea5c JS |
3931 | |
3932 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ | |
3933 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
3934 | "0138 ELS rsp: Cannot issue reg_login for x%x " | |
3935 | "Data: x%x x%x x%x\n", | |
3936 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3937 | ndlp->nlp_rpi); | |
3938 | ||
fa4066b6 | 3939 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3940 | ndlp = NULL; |
fa4066b6 JS |
3941 | /* Indicate node has already been released, |
3942 | * should not reference to it from within | |
3943 | * the routine lpfc_els_free_iocb. | |
3944 | */ | |
3945 | cmdiocb->context1 = NULL; | |
3946 | } | |
dea3101e | 3947 | } else { |
858c9f6c JS |
3948 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
3949 | if (!lpfc_error_lost_link(irsp) && | |
3950 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | |
fa4066b6 | 3951 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3952 | ndlp = NULL; |
fa4066b6 JS |
3953 | /* Indicate node has already been |
3954 | * released, should not reference | |
3955 | * to it from within the routine | |
3956 | * lpfc_els_free_iocb. | |
3957 | */ | |
3958 | cmdiocb->context1 = NULL; | |
3959 | } | |
dea3101e JB |
3960 | } |
3961 | } | |
14691150 JS |
3962 | mp = (struct lpfc_dmabuf *) mbox->context1; |
3963 | if (mp) { | |
3964 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
3965 | kfree(mp); | |
3966 | } | |
3967 | mempool_free(mbox, phba->mbox_mem_pool); | |
dea3101e JB |
3968 | } |
3969 | out: | |
58da1ffb | 3970 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
2e0fef85 | 3971 | spin_lock_irq(shost->host_lock); |
858c9f6c | 3972 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
2e0fef85 | 3973 | spin_unlock_irq(shost->host_lock); |
87af33fe JS |
3974 | |
3975 | /* If the node is not being used by another discovery thread, | |
3976 | * and we are sending a reject, we are done with it. | |
3977 | * Release driver reference count here and free associated | |
3978 | * resources. | |
3979 | */ | |
3980 | if (ls_rjt) | |
fa4066b6 JS |
3981 | if (lpfc_nlp_not_used(ndlp)) |
3982 | /* Indicate node has already been released, | |
3983 | * should not reference to it from within | |
3984 | * the routine lpfc_els_free_iocb. | |
3985 | */ | |
3986 | cmdiocb->context1 = NULL; | |
4b7789b7 | 3987 | |
dea3101e | 3988 | } |
87af33fe | 3989 | |
dea3101e JB |
3990 | lpfc_els_free_iocb(phba, cmdiocb); |
3991 | return; | |
3992 | } | |
3993 | ||
e59058c4 | 3994 | /** |
3621a710 | 3995 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
e59058c4 JS |
3996 | * @vport: pointer to a host virtual N_Port data structure. |
3997 | * @flag: the els command code to be accepted. | |
3998 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
3999 | * @ndlp: pointer to a node-list data structure. | |
4000 | * @mbox: pointer to the driver internal queue element for mailbox command. | |
4001 | * | |
4002 | * This routine prepares and issues an Accept (ACC) response IOCB | |
4003 | * command. It uses the @flag to properly set up the IOCB field for the | |
4004 | * specific ACC response command to be issued and invokes the | |
4005 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a | |
4006 | * @mbox pointer is passed in, it will be put into the context_un.mbox | |
4007 | * field of the IOCB for the completion callback function to issue the | |
4008 | * mailbox command to the HBA later when callback is invoked. | |
4009 | * | |
4010 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4011 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4012 | * will be stored into the context1 field of the IOCB for the completion | |
4013 | * callback function to the corresponding response ELS IOCB command. | |
4014 | * | |
4015 | * Return code | |
4016 | * 0 - Successfully issued acc response | |
4017 | * 1 - Failed to issue acc response | |
4018 | **/ | |
dea3101e | 4019 | int |
2e0fef85 JS |
4020 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
4021 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | |
51ef4c26 | 4022 | LPFC_MBOXQ_t *mbox) |
dea3101e | 4023 | { |
2e0fef85 JS |
4024 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
4025 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
4026 | IOCB_t *icmd; |
4027 | IOCB_t *oldcmd; | |
4028 | struct lpfc_iocbq *elsiocb; | |
dea3101e | 4029 | uint8_t *pcmd; |
d6de08cc | 4030 | struct serv_parm *sp; |
dea3101e JB |
4031 | uint16_t cmdsize; |
4032 | int rc; | |
82d9a2a2 | 4033 | ELS_PKT *els_pkt_ptr; |
dea3101e | 4034 | |
dea3101e JB |
4035 | oldcmd = &oldiocb->iocb; |
4036 | ||
4037 | switch (flag) { | |
4038 | case ELS_CMD_ACC: | |
92d7f7b0 | 4039 | cmdsize = sizeof(uint32_t); |
2e0fef85 JS |
4040 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
4041 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4042 | if (!elsiocb) { |
2e0fef85 | 4043 | spin_lock_irq(shost->host_lock); |
5024ab17 | 4044 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
2e0fef85 | 4045 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 4046 | return 1; |
dea3101e | 4047 | } |
2e0fef85 | 4048 | |
dea3101e | 4049 | icmd = &elsiocb->iocb; |
7851fe2c JS |
4050 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4051 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
4052 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4053 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 4054 | pcmd += sizeof(uint32_t); |
858c9f6c JS |
4055 | |
4056 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4057 | "Issue ACC: did:x%x flg:x%x", | |
4058 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
dea3101e | 4059 | break; |
d6de08cc | 4060 | case ELS_CMD_FLOGI: |
dea3101e | 4061 | case ELS_CMD_PLOGI: |
92d7f7b0 | 4062 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
2e0fef85 JS |
4063 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
4064 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4065 | if (!elsiocb) |
c9f8735b | 4066 | return 1; |
488d1469 | 4067 | |
dea3101e | 4068 | icmd = &elsiocb->iocb; |
7851fe2c JS |
4069 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4070 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
4071 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4072 | ||
4073 | if (mbox) | |
4074 | elsiocb->context_un.mbox = mbox; | |
4075 | ||
4076 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 4077 | pcmd += sizeof(uint32_t); |
d6de08cc JS |
4078 | sp = (struct serv_parm *)pcmd; |
4079 | ||
4080 | if (flag == ELS_CMD_FLOGI) { | |
4081 | /* Copy the received service parameters back */ | |
4082 | memcpy(sp, &phba->fc_fabparam, | |
4083 | sizeof(struct serv_parm)); | |
4084 | ||
4085 | /* Clear the F_Port bit */ | |
4086 | sp->cmn.fPort = 0; | |
4087 | ||
4088 | /* Mark all class service parameters as invalid */ | |
4089 | sp->cls1.classValid = 0; | |
4090 | sp->cls2.classValid = 0; | |
4091 | sp->cls3.classValid = 0; | |
4092 | sp->cls4.classValid = 0; | |
4093 | ||
4094 | /* Copy our worldwide names */ | |
4095 | memcpy(&sp->portName, &vport->fc_sparam.portName, | |
4096 | sizeof(struct lpfc_name)); | |
4097 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, | |
4098 | sizeof(struct lpfc_name)); | |
8c258641 | 4099 | } else { |
d6de08cc JS |
4100 | memcpy(pcmd, &vport->fc_sparam, |
4101 | sizeof(struct serv_parm)); | |
e0165f20 | 4102 | |
8c258641 JS |
4103 | sp->cmn.valid_vendor_ver_level = 0; |
4104 | memset(sp->un.vendorVersion, 0, | |
4105 | sizeof(sp->un.vendorVersion)); | |
4106 | ||
4107 | /* If our firmware supports this feature, convey that | |
4108 | * info to the target using the vendor specific field. | |
4109 | */ | |
4110 | if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { | |
4111 | sp->cmn.valid_vendor_ver_level = 1; | |
4112 | sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); | |
4113 | sp->un.vv.flags = | |
4114 | cpu_to_be32(LPFC_VV_SUPPRESS_RSP); | |
4115 | } | |
4116 | } | |
4117 | ||
858c9f6c | 4118 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
d6de08cc | 4119 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
858c9f6c | 4120 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
dea3101e | 4121 | break; |
82d9a2a2 | 4122 | case ELS_CMD_PRLO: |
92d7f7b0 | 4123 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
2e0fef85 | 4124 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
82d9a2a2 JS |
4125 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
4126 | if (!elsiocb) | |
4127 | return 1; | |
4128 | ||
4129 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
4130 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4131 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
82d9a2a2 JS |
4132 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4133 | ||
4134 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, | |
92d7f7b0 | 4135 | sizeof(uint32_t) + sizeof(PRLO)); |
82d9a2a2 JS |
4136 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
4137 | els_pkt_ptr = (ELS_PKT *) pcmd; | |
4138 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; | |
858c9f6c JS |
4139 | |
4140 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4141 | "Issue ACC PRLO: did:x%x flg:x%x", | |
4142 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
82d9a2a2 | 4143 | break; |
dea3101e | 4144 | default: |
c9f8735b | 4145 | return 1; |
dea3101e | 4146 | } |
dea3101e | 4147 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4148 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4149 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " | |
e6446439 JS |
4150 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
4151 | "fc_flag x%x\n", | |
e8b62011 JS |
4152 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
4153 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
e6446439 | 4154 | ndlp->nlp_rpi, vport->fc_flag); |
dea3101e | 4155 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
2e0fef85 | 4156 | spin_lock_irq(shost->host_lock); |
7c5e518c JS |
4157 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
4158 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) | |
4159 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | |
2e0fef85 | 4160 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
4161 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
4162 | } else { | |
858c9f6c | 4163 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e JB |
4164 | } |
4165 | ||
4166 | phba->fc_stat.elsXmitACC++; | |
3772a991 | 4167 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4168 | if (rc == IOCB_ERROR) { |
4169 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4170 | return 1; |
dea3101e | 4171 | } |
c9f8735b | 4172 | return 0; |
dea3101e JB |
4173 | } |
4174 | ||
e59058c4 | 4175 | /** |
3621a710 | 4176 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
e59058c4 JS |
4177 | * @vport: pointer to a virtual N_Port data structure. |
4178 | * @rejectError: | |
4179 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4180 | * @ndlp: pointer to a node-list data structure. | |
4181 | * @mbox: pointer to the driver internal queue element for mailbox command. | |
4182 | * | |
4183 | * This routine prepares and issue an Reject (RJT) response IOCB | |
4184 | * command. If a @mbox pointer is passed in, it will be put into the | |
4185 | * context_un.mbox field of the IOCB for the completion callback function | |
4186 | * to issue to the HBA later. | |
4187 | * | |
4188 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4189 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4190 | * will be stored into the context1 field of the IOCB for the completion | |
4191 | * callback function to the reject response ELS IOCB command. | |
4192 | * | |
4193 | * Return code | |
4194 | * 0 - Successfully issued reject response | |
4195 | * 1 - Failed to issue reject response | |
4196 | **/ | |
dea3101e | 4197 | int |
2e0fef85 | 4198 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
858c9f6c JS |
4199 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
4200 | LPFC_MBOXQ_t *mbox) | |
dea3101e | 4201 | { |
2e0fef85 | 4202 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
4203 | IOCB_t *icmd; |
4204 | IOCB_t *oldcmd; | |
4205 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
4206 | uint8_t *pcmd; |
4207 | uint16_t cmdsize; | |
4208 | int rc; | |
4209 | ||
92d7f7b0 | 4210 | cmdsize = 2 * sizeof(uint32_t); |
2e0fef85 JS |
4211 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4212 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
488d1469 | 4213 | if (!elsiocb) |
c9f8735b | 4214 | return 1; |
dea3101e JB |
4215 | |
4216 | icmd = &elsiocb->iocb; | |
4217 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4218 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4219 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
4220 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4221 | ||
4222 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | |
92d7f7b0 | 4223 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4224 | *((uint32_t *) (pcmd)) = rejectError; |
4225 | ||
51ef4c26 | 4226 | if (mbox) |
858c9f6c | 4227 | elsiocb->context_un.mbox = mbox; |
858c9f6c | 4228 | |
dea3101e | 4229 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
e8b62011 JS |
4230 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4231 | "0129 Xmit ELS RJT x%x response tag x%x " | |
4232 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
4233 | "rpi x%x\n", | |
4234 | rejectError, elsiocb->iotag, | |
4235 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, | |
4236 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); | |
858c9f6c JS |
4237 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4238 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", | |
4239 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); | |
4240 | ||
dea3101e | 4241 | phba->fc_stat.elsXmitLSRJT++; |
858c9f6c | 4242 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
3772a991 | 4243 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
51ef4c26 | 4244 | |
dea3101e JB |
4245 | if (rc == IOCB_ERROR) { |
4246 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4247 | return 1; |
dea3101e | 4248 | } |
c9f8735b | 4249 | return 0; |
dea3101e JB |
4250 | } |
4251 | ||
e59058c4 | 4252 | /** |
3621a710 | 4253 | * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd |
e59058c4 JS |
4254 | * @vport: pointer to a virtual N_Port data structure. |
4255 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4256 | * @ndlp: pointer to a node-list data structure. | |
4257 | * | |
4258 | * This routine prepares and issues an Accept (ACC) response to Address | |
4259 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB | |
4260 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | |
4261 | * | |
4262 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4263 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4264 | * will be stored into the context1 field of the IOCB for the completion | |
4265 | * callback function to the ADISC Accept response ELS IOCB command. | |
4266 | * | |
4267 | * Return code | |
4268 | * 0 - Successfully issued acc adisc response | |
4269 | * 1 - Failed to issue adisc acc response | |
4270 | **/ | |
dea3101e | 4271 | int |
2e0fef85 JS |
4272 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
4273 | struct lpfc_nodelist *ndlp) | |
dea3101e | 4274 | { |
2e0fef85 | 4275 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4276 | ADISC *ap; |
2e0fef85 | 4277 | IOCB_t *icmd, *oldcmd; |
dea3101e | 4278 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
4279 | uint8_t *pcmd; |
4280 | uint16_t cmdsize; | |
4281 | int rc; | |
4282 | ||
92d7f7b0 | 4283 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
2e0fef85 JS |
4284 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4285 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4286 | if (!elsiocb) |
c9f8735b | 4287 | return 1; |
dea3101e | 4288 | |
5b8bd0c9 JS |
4289 | icmd = &elsiocb->iocb; |
4290 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4291 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4292 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
5b8bd0c9 | 4293 | |
dea3101e | 4294 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4295 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4296 | "0130 Xmit ADISC ACC response iotag x%x xri: " | |
4297 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", | |
4298 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
4299 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
4300 | ndlp->nlp_rpi); | |
dea3101e JB |
4301 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4302 | ||
4303 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 4304 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4305 | |
4306 | ap = (ADISC *) (pcmd); | |
4307 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
4308 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
4309 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 4310 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 4311 | |
858c9f6c JS |
4312 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4313 | "Issue ACC ADISC: did:x%x flg:x%x", | |
4314 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4315 | ||
dea3101e | 4316 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4317 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
3772a991 | 4318 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4319 | if (rc == IOCB_ERROR) { |
4320 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4321 | return 1; |
dea3101e | 4322 | } |
c9f8735b | 4323 | return 0; |
dea3101e JB |
4324 | } |
4325 | ||
e59058c4 | 4326 | /** |
3621a710 | 4327 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd |
e59058c4 JS |
4328 | * @vport: pointer to a virtual N_Port data structure. |
4329 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4330 | * @ndlp: pointer to a node-list data structure. | |
4331 | * | |
4332 | * This routine prepares and issues an Accept (ACC) response to Process | |
4333 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB | |
4334 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | |
4335 | * | |
4336 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4337 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4338 | * will be stored into the context1 field of the IOCB for the completion | |
4339 | * callback function to the PRLI Accept response ELS IOCB command. | |
4340 | * | |
4341 | * Return code | |
4342 | * 0 - Successfully issued acc prli response | |
4343 | * 1 - Failed to issue acc prli response | |
4344 | **/ | |
dea3101e | 4345 | int |
2e0fef85 | 4346 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
5b8bd0c9 | 4347 | struct lpfc_nodelist *ndlp) |
dea3101e | 4348 | { |
2e0fef85 | 4349 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4350 | PRLI *npr; |
a0f2d3ef | 4351 | struct lpfc_nvme_prli *npr_nvme; |
dea3101e JB |
4352 | lpfc_vpd_t *vpd; |
4353 | IOCB_t *icmd; | |
4354 | IOCB_t *oldcmd; | |
4355 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
4356 | uint8_t *pcmd; |
4357 | uint16_t cmdsize; | |
a0f2d3ef JS |
4358 | uint32_t prli_fc4_req, *req_payload; |
4359 | struct lpfc_dmabuf *req_buf; | |
dea3101e | 4360 | int rc; |
a0f2d3ef JS |
4361 | u32 elsrspcmd; |
4362 | ||
4363 | /* Need the incoming PRLI payload to determine if the ACC is for an | |
4364 | * FC4 or NVME PRLI type. The PRLI type is at word 1. | |
4365 | */ | |
4366 | req_buf = (struct lpfc_dmabuf *)oldiocb->context2; | |
4367 | req_payload = (((uint32_t *)req_buf->virt) + 1); | |
4368 | ||
4369 | /* PRLI type payload is at byte 3 for FCP or NVME. */ | |
4370 | prli_fc4_req = be32_to_cpu(*req_payload); | |
4371 | prli_fc4_req = (prli_fc4_req >> 24) & 0xff; | |
4372 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4373 | "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", | |
4374 | prli_fc4_req, *((uint32_t *)req_payload)); | |
4375 | ||
4376 | if (prli_fc4_req == PRLI_FCP_TYPE) { | |
4377 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); | |
4378 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | |
4379 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { | |
4380 | cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); | |
4381 | elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); | |
4382 | } else { | |
4383 | return 1; | |
4384 | } | |
dea3101e | 4385 | |
2e0fef85 | 4386 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
a0f2d3ef | 4387 | ndlp->nlp_DID, elsrspcmd); |
c9f8735b JW |
4388 | if (!elsiocb) |
4389 | return 1; | |
dea3101e | 4390 | |
5b8bd0c9 JS |
4391 | icmd = &elsiocb->iocb; |
4392 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4393 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4394 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
4395 | ||
dea3101e | 4396 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4397 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4398 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " | |
4399 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
4400 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
4401 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
4402 | ndlp->nlp_rpi); | |
dea3101e | 4403 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
a0f2d3ef | 4404 | memset(pcmd, 0, cmdsize); |
dea3101e JB |
4405 | |
4406 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | |
92d7f7b0 | 4407 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4408 | |
4409 | /* For PRLI, remainder of payload is PRLI parameter page */ | |
dea3101e | 4410 | vpd = &phba->vpd; |
dea3101e | 4411 | |
a0f2d3ef JS |
4412 | if (prli_fc4_req == PRLI_FCP_TYPE) { |
4413 | /* | |
4414 | * If the remote port is a target and our firmware version | |
4415 | * is 3.20 or later, set the following bits for FC-TAPE | |
4416 | * support. | |
4417 | */ | |
4418 | npr = (PRLI *) pcmd; | |
4419 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && | |
4420 | (vpd->rev.feaLevelHigh >= 0x02)) { | |
4421 | npr->ConfmComplAllowed = 1; | |
4422 | npr->Retry = 1; | |
4423 | npr->TaskRetryIdReq = 1; | |
4424 | } | |
4425 | npr->acceptRspCode = PRLI_REQ_EXECUTED; | |
4426 | npr->estabImagePair = 1; | |
4427 | npr->readXferRdyDis = 1; | |
4428 | npr->ConfmComplAllowed = 1; | |
4429 | npr->prliType = PRLI_FCP_TYPE; | |
4430 | npr->initiatorFunc = 1; | |
4431 | } else if (prli_fc4_req & PRLI_NVME_TYPE) { | |
4432 | /* Respond with an NVME PRLI Type */ | |
4433 | npr_nvme = (struct lpfc_nvme_prli *) pcmd; | |
4434 | bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); | |
4435 | bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ | |
4436 | bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); | |
8c258641 JS |
4437 | if (phba->nvmet_support) { |
4438 | bf_set(prli_tgt, npr_nvme, 1); | |
4439 | bf_set(prli_disc, npr_nvme, 1); | |
4440 | if (phba->cfg_nvme_enable_fb) { | |
4441 | bf_set(prli_fba, npr_nvme, 1); | |
4442 | ||
4443 | /* TBD. Target mode needs to post buffers | |
4444 | * that support the configured first burst | |
4445 | * byte size. | |
4446 | */ | |
4447 | bf_set(prli_fb_sz, npr_nvme, | |
4448 | phba->cfg_nvmet_fb_size); | |
4449 | } | |
4450 | } else { | |
4451 | bf_set(prli_init, npr_nvme, 1); | |
4452 | } | |
a0f2d3ef JS |
4453 | |
4454 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, | |
4455 | "6015 NVME issue PRLI ACC word1 x%08x " | |
4456 | "word4 x%08x word5 x%08x flag x%x, " | |
4457 | "fcp_info x%x nlp_type x%x\n", | |
4458 | npr_nvme->word1, npr_nvme->word4, | |
4459 | npr_nvme->word5, ndlp->nlp_flag, | |
4460 | ndlp->nlp_fcp_info, ndlp->nlp_type); | |
4461 | npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); | |
4462 | npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); | |
4463 | npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); | |
4464 | } else | |
4465 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
4466 | "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", | |
4467 | prli_fc4_req, ndlp->nlp_fc4_type, | |
4468 | ndlp->nlp_DID); | |
dea3101e | 4469 | |
858c9f6c JS |
4470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4471 | "Issue ACC PRLI: did:x%x flg:x%x", | |
4472 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4473 | ||
dea3101e | 4474 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4475 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 4476 | |
3772a991 | 4477 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4478 | if (rc == IOCB_ERROR) { |
4479 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4480 | return 1; |
dea3101e | 4481 | } |
c9f8735b | 4482 | return 0; |
dea3101e JB |
4483 | } |
4484 | ||
e59058c4 | 4485 | /** |
3621a710 | 4486 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
e59058c4 JS |
4487 | * @vport: pointer to a virtual N_Port data structure. |
4488 | * @format: rnid command format. | |
4489 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4490 | * @ndlp: pointer to a node-list data structure. | |
4491 | * | |
4492 | * This routine issues a Request Node Identification Data (RNID) Accept | |
4493 | * (ACC) response. It constructs the RNID ACC response command according to | |
4494 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to | |
4495 | * issue the response. Note that this command does not need to hold the ndlp | |
4496 | * reference count for the callback. So, the ndlp reference count taken by | |
4497 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of | |
4498 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that | |
4499 | * there is no ndlp reference available. | |
4500 | * | |
4501 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4502 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4503 | * will be stored into the context1 field of the IOCB for the completion | |
4504 | * callback function. However, for the RNID Accept Response ELS command, | |
4505 | * this is undone later by this routine after the IOCB is allocated. | |
4506 | * | |
4507 | * Return code | |
4508 | * 0 - Successfully issued acc rnid response | |
4509 | * 1 - Failed to issue acc rnid response | |
4510 | **/ | |
dea3101e | 4511 | static int |
2e0fef85 | 4512 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
329f9bc7 | 4513 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
dea3101e | 4514 | { |
2e0fef85 | 4515 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4516 | RNID *rn; |
2e0fef85 | 4517 | IOCB_t *icmd, *oldcmd; |
dea3101e | 4518 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
4519 | uint8_t *pcmd; |
4520 | uint16_t cmdsize; | |
4521 | int rc; | |
4522 | ||
92d7f7b0 JS |
4523 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
4524 | + (2 * sizeof(struct lpfc_name)); | |
dea3101e | 4525 | if (format) |
92d7f7b0 | 4526 | cmdsize += sizeof(RNID_TOP_DISC); |
dea3101e | 4527 | |
2e0fef85 JS |
4528 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4529 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4530 | if (!elsiocb) |
c9f8735b | 4531 | return 1; |
dea3101e | 4532 | |
5b8bd0c9 JS |
4533 | icmd = &elsiocb->iocb; |
4534 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4535 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4536 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
4537 | ||
dea3101e | 4538 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4539 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4540 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", | |
4541 | elsiocb->iotag, elsiocb->iocb.ulpContext); | |
dea3101e | 4542 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
dea3101e | 4543 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
92d7f7b0 | 4544 | pcmd += sizeof(uint32_t); |
dea3101e | 4545 | |
92d7f7b0 | 4546 | memset(pcmd, 0, sizeof(RNID)); |
dea3101e JB |
4547 | rn = (RNID *) (pcmd); |
4548 | rn->Format = format; | |
92d7f7b0 JS |
4549 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
4550 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | |
4551 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
dea3101e JB |
4552 | switch (format) { |
4553 | case 0: | |
4554 | rn->SpecificLen = 0; | |
4555 | break; | |
4556 | case RNID_TOPOLOGY_DISC: | |
92d7f7b0 | 4557 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
dea3101e | 4558 | memcpy(&rn->un.topologyDisc.portName, |
92d7f7b0 | 4559 | &vport->fc_portname, sizeof(struct lpfc_name)); |
dea3101e JB |
4560 | rn->un.topologyDisc.unitType = RNID_HBA; |
4561 | rn->un.topologyDisc.physPort = 0; | |
4562 | rn->un.topologyDisc.attachedNodes = 0; | |
4563 | break; | |
4564 | default: | |
4565 | rn->CommonLen = 0; | |
4566 | rn->SpecificLen = 0; | |
4567 | break; | |
4568 | } | |
4569 | ||
858c9f6c JS |
4570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4571 | "Issue ACC RNID: did:x%x flg:x%x", | |
4572 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4573 | ||
dea3101e | 4574 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4575 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 4576 | |
3772a991 | 4577 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4578 | if (rc == IOCB_ERROR) { |
4579 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4580 | return 1; |
dea3101e | 4581 | } |
c9f8735b | 4582 | return 0; |
dea3101e JB |
4583 | } |
4584 | ||
19ca7609 JS |
4585 | /** |
4586 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. | |
4587 | * @vport: pointer to a virtual N_Port data structure. | |
4588 | * @iocb: pointer to the lpfc command iocb data structure. | |
4589 | * @ndlp: pointer to a node-list data structure. | |
4590 | * | |
4591 | * Return | |
4592 | **/ | |
4593 | static void | |
4594 | lpfc_els_clear_rrq(struct lpfc_vport *vport, | |
a0f2d3ef | 4595 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
4596 | { |
4597 | struct lpfc_hba *phba = vport->phba; | |
4598 | uint8_t *pcmd; | |
4599 | struct RRQ *rrq; | |
4600 | uint16_t rxid; | |
1151e3ec | 4601 | uint16_t xri; |
19ca7609 JS |
4602 | struct lpfc_node_rrq *prrq; |
4603 | ||
4604 | ||
4605 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); | |
4606 | pcmd += sizeof(uint32_t); | |
4607 | rrq = (struct RRQ *)pcmd; | |
1151e3ec | 4608 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
9589b062 | 4609 | rxid = bf_get(rrq_rxid, rrq); |
19ca7609 JS |
4610 | |
4611 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4612 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" | |
4613 | " x%x x%x\n", | |
1151e3ec | 4614 | be32_to_cpu(bf_get(rrq_did, rrq)), |
9589b062 | 4615 | bf_get(rrq_oxid, rrq), |
19ca7609 JS |
4616 | rxid, |
4617 | iocb->iotag, iocb->iocb.ulpContext); | |
4618 | ||
4619 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4620 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", | |
4621 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); | |
1151e3ec | 4622 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
9589b062 | 4623 | xri = bf_get(rrq_oxid, rrq); |
1151e3ec JS |
4624 | else |
4625 | xri = rxid; | |
4626 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); | |
19ca7609 | 4627 | if (prrq) |
1151e3ec | 4628 | lpfc_clr_rrq_active(phba, xri, prrq); |
19ca7609 JS |
4629 | return; |
4630 | } | |
4631 | ||
12265f68 JS |
4632 | /** |
4633 | * lpfc_els_rsp_echo_acc - Issue echo acc response | |
4634 | * @vport: pointer to a virtual N_Port data structure. | |
4635 | * @data: pointer to echo data to return in the accept. | |
4636 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4637 | * @ndlp: pointer to a node-list data structure. | |
4638 | * | |
4639 | * Return code | |
4640 | * 0 - Successfully issued acc echo response | |
4641 | * 1 - Failed to issue acc echo response | |
4642 | **/ | |
4643 | static int | |
4644 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, | |
4645 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | |
4646 | { | |
4647 | struct lpfc_hba *phba = vport->phba; | |
4648 | struct lpfc_iocbq *elsiocb; | |
12265f68 JS |
4649 | uint8_t *pcmd; |
4650 | uint16_t cmdsize; | |
4651 | int rc; | |
4652 | ||
12265f68 JS |
4653 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
4654 | ||
bf08611b JS |
4655 | /* The accumulated length can exceed the BPL_SIZE. For |
4656 | * now, use this as the limit | |
4657 | */ | |
4658 | if (cmdsize > LPFC_BPL_SIZE) | |
4659 | cmdsize = LPFC_BPL_SIZE; | |
12265f68 JS |
4660 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4661 | ndlp->nlp_DID, ELS_CMD_ACC); | |
4662 | if (!elsiocb) | |
4663 | return 1; | |
4664 | ||
7851fe2c JS |
4665 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
4666 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; | |
4667 | ||
12265f68 JS |
4668 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
4669 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4670 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", | |
4671 | elsiocb->iotag, elsiocb->iocb.ulpContext); | |
4672 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4673 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
4674 | pcmd += sizeof(uint32_t); | |
4675 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); | |
4676 | ||
4677 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4678 | "Issue ACC ECHO: did:x%x flg:x%x", | |
4679 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4680 | ||
4681 | phba->fc_stat.elsXmitACC++; | |
4682 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
12265f68 JS |
4683 | |
4684 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
4685 | if (rc == IOCB_ERROR) { | |
4686 | lpfc_els_free_iocb(phba, elsiocb); | |
4687 | return 1; | |
4688 | } | |
4689 | return 0; | |
4690 | } | |
4691 | ||
e59058c4 | 4692 | /** |
3621a710 | 4693 | * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport |
e59058c4 JS |
4694 | * @vport: pointer to a host virtual N_Port data structure. |
4695 | * | |
4696 | * This routine issues Address Discover (ADISC) ELS commands to those | |
4697 | * N_Ports which are in node port recovery state and ADISC has not been issued | |
4698 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the | |
4699 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count | |
4700 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a | |
4701 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will | |
4702 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC | |
4703 | * IOCBs quit for later pick up. On the other hand, after walking through | |
4704 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the | |
4705 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is | |
4706 | * no more ADISC need to be sent. | |
4707 | * | |
4708 | * Return code | |
4709 | * The number of N_Ports with adisc issued. | |
4710 | **/ | |
dea3101e | 4711 | int |
2e0fef85 | 4712 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
dea3101e | 4713 | { |
2e0fef85 | 4714 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 4715 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 4716 | int sentadisc = 0; |
dea3101e | 4717 | |
685f0bf7 | 4718 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
2e0fef85 | 4719 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
4720 | if (!NLP_CHK_NODE_ACT(ndlp)) |
4721 | continue; | |
685f0bf7 JS |
4722 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
4723 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | |
4724 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { | |
2e0fef85 | 4725 | spin_lock_irq(shost->host_lock); |
685f0bf7 | 4726 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 4727 | spin_unlock_irq(shost->host_lock); |
685f0bf7 | 4728 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
4729 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
4730 | lpfc_issue_els_adisc(vport, ndlp, 0); | |
685f0bf7 | 4731 | sentadisc++; |
2e0fef85 JS |
4732 | vport->num_disc_nodes++; |
4733 | if (vport->num_disc_nodes >= | |
3de2a653 | 4734 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
4735 | spin_lock_irq(shost->host_lock); |
4736 | vport->fc_flag |= FC_NLP_MORE; | |
4737 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 4738 | break; |
dea3101e JB |
4739 | } |
4740 | } | |
4741 | } | |
4742 | if (sentadisc == 0) { | |
2e0fef85 JS |
4743 | spin_lock_irq(shost->host_lock); |
4744 | vport->fc_flag &= ~FC_NLP_MORE; | |
4745 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 4746 | } |
2fe165b6 | 4747 | return sentadisc; |
dea3101e JB |
4748 | } |
4749 | ||
e59058c4 | 4750 | /** |
3621a710 | 4751 | * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc |
e59058c4 JS |
4752 | * @vport: pointer to a host virtual N_Port data structure. |
4753 | * | |
4754 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports | |
4755 | * which are in node port recovery state, with a @vport. Each time an ELS | |
4756 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, | |
4757 | * the per @vport number of discover count (num_disc_nodes) shall be | |
4758 | * incremented. If the num_disc_nodes reaches a pre-configured threshold | |
4759 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE | |
4760 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for | |
4761 | * later pick up. On the other hand, after walking through all the ndlps with | |
4762 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag | |
4763 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC | |
4764 | * PLOGI need to be sent. | |
4765 | * | |
4766 | * Return code | |
4767 | * The number of N_Ports with plogi issued. | |
4768 | **/ | |
dea3101e | 4769 | int |
2e0fef85 | 4770 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
dea3101e | 4771 | { |
2e0fef85 | 4772 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 4773 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 4774 | int sentplogi = 0; |
dea3101e | 4775 | |
2e0fef85 JS |
4776 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
4777 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
4778 | if (!NLP_CHK_NODE_ACT(ndlp)) |
4779 | continue; | |
685f0bf7 | 4780 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
8b017a30 JS |
4781 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
4782 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && | |
4783 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { | |
685f0bf7 | 4784 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
4785 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
4786 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
685f0bf7 | 4787 | sentplogi++; |
2e0fef85 JS |
4788 | vport->num_disc_nodes++; |
4789 | if (vport->num_disc_nodes >= | |
8b017a30 | 4790 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
4791 | spin_lock_irq(shost->host_lock); |
4792 | vport->fc_flag |= FC_NLP_MORE; | |
4793 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 4794 | break; |
dea3101e JB |
4795 | } |
4796 | } | |
4797 | } | |
87af33fe JS |
4798 | if (sentplogi) { |
4799 | lpfc_set_disctmo(vport); | |
4800 | } | |
4801 | else { | |
2e0fef85 JS |
4802 | spin_lock_irq(shost->host_lock); |
4803 | vport->fc_flag &= ~FC_NLP_MORE; | |
4804 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 4805 | } |
2fe165b6 | 4806 | return sentplogi; |
dea3101e JB |
4807 | } |
4808 | ||
bd4b3e5c | 4809 | static uint32_t |
86478875 JS |
4810 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, |
4811 | uint32_t word0) | |
4812 | { | |
4813 | ||
4814 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); | |
4815 | desc->payload.els_req = word0; | |
4816 | desc->length = cpu_to_be32(sizeof(desc->payload)); | |
6c92d1d0 JS |
4817 | |
4818 | return sizeof(struct fc_rdp_link_service_desc); | |
86478875 JS |
4819 | } |
4820 | ||
bd4b3e5c | 4821 | static uint32_t |
86478875 JS |
4822 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, |
4823 | uint8_t *page_a0, uint8_t *page_a2) | |
4824 | { | |
4825 | uint16_t wavelength; | |
4826 | uint16_t temperature; | |
4827 | uint16_t rx_power; | |
4828 | uint16_t tx_bias; | |
4829 | uint16_t tx_power; | |
4830 | uint16_t vcc; | |
4831 | uint16_t flag = 0; | |
4832 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; | |
4833 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; | |
4834 | ||
4835 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); | |
4836 | ||
4837 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) | |
4838 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; | |
4839 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) | |
4840 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; | |
4841 | ||
4842 | if ((trasn_code_byte4->fc_sw_laser) || | |
4843 | (trasn_code_byte5->fc_sw_laser_sl) || | |
4844 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ | |
4845 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); | |
4846 | } else if (trasn_code_byte4->fc_lw_laser) { | |
4847 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | | |
4848 | page_a0[SSF_WAVELENGTH_B0]; | |
4849 | if (wavelength == SFP_WAVELENGTH_LC1310) | |
4850 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; | |
4851 | if (wavelength == SFP_WAVELENGTH_LL1550) | |
4852 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; | |
4853 | } | |
4854 | /* check if its SFP+ */ | |
4855 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? | |
4856 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) | |
4857 | << SFP_FLAG_CT_SHIFT; | |
4858 | ||
4859 | /* check if its OPTICAL */ | |
4860 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? | |
4861 | SFP_FLAG_IS_OPTICAL_PORT : 0) | |
4862 | << SFP_FLAG_IS_OPTICAL_SHIFT; | |
4863 | ||
4864 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | | |
4865 | page_a2[SFF_TEMPERATURE_B0]); | |
4866 | vcc = (page_a2[SFF_VCC_B1] << 8 | | |
4867 | page_a2[SFF_VCC_B0]); | |
4868 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | | |
4869 | page_a2[SFF_TXPOWER_B0]); | |
4870 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | | |
4871 | page_a2[SFF_TX_BIAS_CURRENT_B0]); | |
4872 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | | |
4873 | page_a2[SFF_RXPOWER_B0]); | |
4874 | desc->sfp_info.temperature = cpu_to_be16(temperature); | |
4875 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); | |
4876 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); | |
4877 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); | |
4878 | desc->sfp_info.vcc = cpu_to_be16(vcc); | |
4879 | ||
4880 | desc->sfp_info.flags = cpu_to_be16(flag); | |
4881 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); | |
6c92d1d0 JS |
4882 | |
4883 | return sizeof(struct fc_rdp_sfp_desc); | |
86478875 JS |
4884 | } |
4885 | ||
bd4b3e5c | 4886 | static uint32_t |
86478875 JS |
4887 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, |
4888 | READ_LNK_VAR *stat) | |
4889 | { | |
4890 | uint32_t type; | |
4891 | ||
4892 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); | |
4893 | ||
4894 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; | |
4895 | ||
4896 | desc->info.port_type = cpu_to_be32(type); | |
4897 | ||
4898 | desc->info.link_status.link_failure_cnt = | |
4899 | cpu_to_be32(stat->linkFailureCnt); | |
4900 | desc->info.link_status.loss_of_synch_cnt = | |
4901 | cpu_to_be32(stat->lossSyncCnt); | |
4902 | desc->info.link_status.loss_of_signal_cnt = | |
4903 | cpu_to_be32(stat->lossSignalCnt); | |
4904 | desc->info.link_status.primitive_seq_proto_err = | |
4905 | cpu_to_be32(stat->primSeqErrCnt); | |
4906 | desc->info.link_status.invalid_trans_word = | |
4907 | cpu_to_be32(stat->invalidXmitWord); | |
4908 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); | |
4909 | ||
4910 | desc->length = cpu_to_be32(sizeof(desc->info)); | |
6c92d1d0 JS |
4911 | |
4912 | return sizeof(struct fc_rdp_link_error_status_desc); | |
86478875 JS |
4913 | } |
4914 | ||
bd4b3e5c | 4915 | static uint32_t |
56204984 JS |
4916 | lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, |
4917 | struct lpfc_vport *vport) | |
4918 | { | |
3aaaa314 JS |
4919 | uint32_t bbCredit; |
4920 | ||
56204984 JS |
4921 | desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); |
4922 | ||
3aaaa314 JS |
4923 | bbCredit = vport->fc_sparam.cmn.bbCreditLsb | |
4924 | (vport->fc_sparam.cmn.bbCreditMsb << 8); | |
4925 | desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); | |
4926 | if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { | |
4927 | bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | | |
4928 | (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); | |
4929 | desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); | |
4930 | } else { | |
56204984 | 4931 | desc->bbc_info.attached_port_bbc = 0; |
3aaaa314 | 4932 | } |
56204984 JS |
4933 | |
4934 | desc->bbc_info.rtt = 0; | |
4935 | desc->length = cpu_to_be32(sizeof(desc->bbc_info)); | |
6c92d1d0 JS |
4936 | |
4937 | return sizeof(struct fc_rdp_bbc_desc); | |
56204984 JS |
4938 | } |
4939 | ||
bd4b3e5c | 4940 | static uint32_t |
310429ef JS |
4941 | lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, |
4942 | struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) | |
56204984 | 4943 | { |
310429ef | 4944 | uint32_t flags = 0; |
56204984 JS |
4945 | |
4946 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); | |
4947 | ||
3aaaa314 JS |
4948 | desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; |
4949 | desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; | |
4950 | desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; | |
4951 | desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; | |
310429ef JS |
4952 | |
4953 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) | |
4954 | flags |= RDP_OET_HIGH_ALARM; | |
4955 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) | |
4956 | flags |= RDP_OET_LOW_ALARM; | |
4957 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) | |
4958 | flags |= RDP_OET_HIGH_WARNING; | |
4959 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) | |
4960 | flags |= RDP_OET_LOW_WARNING; | |
4961 | ||
56204984 JS |
4962 | flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); |
4963 | desc->oed_info.function_flags = cpu_to_be32(flags); | |
4964 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); | |
6c92d1d0 | 4965 | return sizeof(struct fc_rdp_oed_sfp_desc); |
56204984 JS |
4966 | } |
4967 | ||
bd4b3e5c | 4968 | static uint32_t |
310429ef JS |
4969 | lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, |
4970 | struct fc_rdp_oed_sfp_desc *desc, | |
56204984 JS |
4971 | uint8_t *page_a2) |
4972 | { | |
310429ef | 4973 | uint32_t flags = 0; |
56204984 JS |
4974 | |
4975 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); | |
4976 | ||
3aaaa314 JS |
4977 | desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; |
4978 | desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; | |
4979 | desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; | |
4980 | desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; | |
310429ef JS |
4981 | |
4982 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) | |
4983 | flags |= RDP_OET_HIGH_ALARM; | |
4984 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) | |
4985 | flags |= RDP_OET_LOW_ALARM; | |
4986 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) | |
4987 | flags |= RDP_OET_HIGH_WARNING; | |
4988 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) | |
4989 | flags |= RDP_OET_LOW_WARNING; | |
4990 | ||
56204984 JS |
4991 | flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); |
4992 | desc->oed_info.function_flags = cpu_to_be32(flags); | |
4993 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); | |
6c92d1d0 | 4994 | return sizeof(struct fc_rdp_oed_sfp_desc); |
56204984 JS |
4995 | } |
4996 | ||
bd4b3e5c | 4997 | static uint32_t |
310429ef JS |
4998 | lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, |
4999 | struct fc_rdp_oed_sfp_desc *desc, | |
56204984 JS |
5000 | uint8_t *page_a2) |
5001 | { | |
310429ef | 5002 | uint32_t flags = 0; |
56204984 JS |
5003 | |
5004 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); | |
5005 | ||
3aaaa314 JS |
5006 | desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; |
5007 | desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; | |
5008 | desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; | |
5009 | desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; | |
310429ef JS |
5010 | |
5011 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) | |
5012 | flags |= RDP_OET_HIGH_ALARM; | |
5013 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) | |
5014 | flags |= RDP_OET_LOW_ALARM; | |
5015 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) | |
5016 | flags |= RDP_OET_HIGH_WARNING; | |
5017 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) | |
5018 | flags |= RDP_OET_LOW_WARNING; | |
5019 | ||
56204984 JS |
5020 | flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); |
5021 | desc->oed_info.function_flags = cpu_to_be32(flags); | |
5022 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); | |
6c92d1d0 | 5023 | return sizeof(struct fc_rdp_oed_sfp_desc); |
56204984 JS |
5024 | } |
5025 | ||
bd4b3e5c | 5026 | static uint32_t |
310429ef JS |
5027 | lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, |
5028 | struct fc_rdp_oed_sfp_desc *desc, | |
56204984 JS |
5029 | uint8_t *page_a2) |
5030 | { | |
310429ef | 5031 | uint32_t flags = 0; |
56204984 JS |
5032 | |
5033 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); | |
5034 | ||
3aaaa314 JS |
5035 | desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; |
5036 | desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; | |
5037 | desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; | |
5038 | desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; | |
310429ef JS |
5039 | |
5040 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) | |
5041 | flags |= RDP_OET_HIGH_ALARM; | |
5042 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) | |
5043 | flags |= RDP_OET_LOW_ALARM; | |
5044 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) | |
5045 | flags |= RDP_OET_HIGH_WARNING; | |
5046 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) | |
5047 | flags |= RDP_OET_LOW_WARNING; | |
5048 | ||
56204984 JS |
5049 | flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); |
5050 | desc->oed_info.function_flags = cpu_to_be32(flags); | |
5051 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); | |
6c92d1d0 | 5052 | return sizeof(struct fc_rdp_oed_sfp_desc); |
56204984 JS |
5053 | } |
5054 | ||
5055 | ||
bd4b3e5c | 5056 | static uint32_t |
310429ef JS |
5057 | lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, |
5058 | struct fc_rdp_oed_sfp_desc *desc, | |
56204984 JS |
5059 | uint8_t *page_a2) |
5060 | { | |
310429ef | 5061 | uint32_t flags = 0; |
56204984 JS |
5062 | |
5063 | desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); | |
5064 | ||
3aaaa314 JS |
5065 | desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; |
5066 | desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; | |
5067 | desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; | |
5068 | desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; | |
310429ef JS |
5069 | |
5070 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) | |
5071 | flags |= RDP_OET_HIGH_ALARM; | |
5072 | if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) | |
5073 | flags |= RDP_OET_LOW_ALARM; | |
5074 | if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) | |
5075 | flags |= RDP_OET_HIGH_WARNING; | |
5076 | if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) | |
5077 | flags |= RDP_OET_LOW_WARNING; | |
5078 | ||
56204984 JS |
5079 | flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); |
5080 | desc->oed_info.function_flags = cpu_to_be32(flags); | |
5081 | desc->length = cpu_to_be32(sizeof(desc->oed_info)); | |
6c92d1d0 | 5082 | return sizeof(struct fc_rdp_oed_sfp_desc); |
56204984 JS |
5083 | } |
5084 | ||
bd4b3e5c | 5085 | static uint32_t |
56204984 JS |
5086 | lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, |
5087 | uint8_t *page_a0, struct lpfc_vport *vport) | |
5088 | { | |
5089 | desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); | |
5090 | memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); | |
5091 | memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); | |
5092 | memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); | |
a0f2d3ef | 5093 | memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); |
56204984 JS |
5094 | memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); |
5095 | desc->length = cpu_to_be32(sizeof(desc->opd_info)); | |
6c92d1d0 | 5096 | return sizeof(struct fc_rdp_opd_sfp_desc); |
56204984 JS |
5097 | } |
5098 | ||
bd4b3e5c | 5099 | static uint32_t |
4258e98e JS |
5100 | lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) |
5101 | { | |
5102 | if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) | |
5103 | return 0; | |
5104 | desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); | |
5105 | ||
5106 | desc->info.CorrectedBlocks = | |
5107 | cpu_to_be32(stat->fecCorrBlkCount); | |
5108 | desc->info.UncorrectableBlocks = | |
5109 | cpu_to_be32(stat->fecUncorrBlkCount); | |
5110 | ||
5111 | desc->length = cpu_to_be32(sizeof(desc->info)); | |
5112 | ||
5113 | return sizeof(struct fc_fec_rdp_desc); | |
5114 | } | |
5115 | ||
bd4b3e5c | 5116 | static uint32_t |
86478875 JS |
5117 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) |
5118 | { | |
5119 | uint16_t rdp_cap = 0; | |
5120 | uint16_t rdp_speed; | |
5121 | ||
5122 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); | |
5123 | ||
81e75177 JS |
5124 | switch (phba->fc_linkspeed) { |
5125 | case LPFC_LINK_SPEED_1GHZ: | |
86478875 JS |
5126 | rdp_speed = RDP_PS_1GB; |
5127 | break; | |
81e75177 | 5128 | case LPFC_LINK_SPEED_2GHZ: |
86478875 JS |
5129 | rdp_speed = RDP_PS_2GB; |
5130 | break; | |
81e75177 | 5131 | case LPFC_LINK_SPEED_4GHZ: |
86478875 JS |
5132 | rdp_speed = RDP_PS_4GB; |
5133 | break; | |
81e75177 | 5134 | case LPFC_LINK_SPEED_8GHZ: |
86478875 JS |
5135 | rdp_speed = RDP_PS_8GB; |
5136 | break; | |
81e75177 | 5137 | case LPFC_LINK_SPEED_10GHZ: |
86478875 JS |
5138 | rdp_speed = RDP_PS_10GB; |
5139 | break; | |
81e75177 | 5140 | case LPFC_LINK_SPEED_16GHZ: |
86478875 JS |
5141 | rdp_speed = RDP_PS_16GB; |
5142 | break; | |
a085e87c JS |
5143 | case LPFC_LINK_SPEED_32GHZ: |
5144 | rdp_speed = RDP_PS_32GB; | |
5145 | break; | |
86478875 JS |
5146 | default: |
5147 | rdp_speed = RDP_PS_UNKNOWN; | |
5148 | break; | |
5149 | } | |
5150 | ||
5151 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); | |
5152 | ||
d38dd52c JS |
5153 | if (phba->lmt & LMT_32Gb) |
5154 | rdp_cap |= RDP_PS_32GB; | |
86478875 JS |
5155 | if (phba->lmt & LMT_16Gb) |
5156 | rdp_cap |= RDP_PS_16GB; | |
5157 | if (phba->lmt & LMT_10Gb) | |
5158 | rdp_cap |= RDP_PS_10GB; | |
5159 | if (phba->lmt & LMT_8Gb) | |
5160 | rdp_cap |= RDP_PS_8GB; | |
5161 | if (phba->lmt & LMT_4Gb) | |
5162 | rdp_cap |= RDP_PS_4GB; | |
5163 | if (phba->lmt & LMT_2Gb) | |
5164 | rdp_cap |= RDP_PS_2GB; | |
5165 | if (phba->lmt & LMT_1Gb) | |
5166 | rdp_cap |= RDP_PS_1GB; | |
5167 | ||
5168 | if (rdp_cap == 0) | |
5169 | rdp_cap = RDP_CAP_UNKNOWN; | |
56204984 JS |
5170 | if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) |
5171 | rdp_cap |= RDP_CAP_USER_CONFIGURED; | |
86478875 JS |
5172 | |
5173 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); | |
5174 | desc->length = cpu_to_be32(sizeof(desc->info)); | |
6c92d1d0 | 5175 | return sizeof(struct fc_rdp_port_speed_desc); |
86478875 JS |
5176 | } |
5177 | ||
bd4b3e5c | 5178 | static uint32_t |
86478875 | 5179 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, |
cd46cded | 5180 | struct lpfc_vport *vport) |
86478875 JS |
5181 | { |
5182 | ||
5183 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); | |
5184 | ||
cd46cded | 5185 | memcpy(desc->port_names.wwnn, &vport->fc_nodename, |
86478875 JS |
5186 | sizeof(desc->port_names.wwnn)); |
5187 | ||
cd46cded | 5188 | memcpy(desc->port_names.wwpn, &vport->fc_portname, |
86478875 JS |
5189 | sizeof(desc->port_names.wwpn)); |
5190 | ||
5191 | desc->length = cpu_to_be32(sizeof(desc->port_names)); | |
6c92d1d0 | 5192 | return sizeof(struct fc_rdp_port_name_desc); |
86478875 JS |
5193 | } |
5194 | ||
bd4b3e5c | 5195 | static uint32_t |
86478875 JS |
5196 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, |
5197 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
5198 | { | |
5199 | ||
5200 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); | |
5201 | if (vport->fc_flag & FC_FABRIC) { | |
5202 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, | |
5203 | sizeof(desc->port_names.wwnn)); | |
5204 | ||
5205 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, | |
5206 | sizeof(desc->port_names.wwpn)); | |
5207 | } else { /* Point to Point */ | |
5208 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, | |
5209 | sizeof(desc->port_names.wwnn)); | |
5210 | ||
5211 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, | |
5212 | sizeof(desc->port_names.wwpn)); | |
5213 | } | |
5214 | ||
5215 | desc->length = cpu_to_be32(sizeof(desc->port_names)); | |
6c92d1d0 | 5216 | return sizeof(struct fc_rdp_port_name_desc); |
86478875 JS |
5217 | } |
5218 | ||
bd4b3e5c | 5219 | static void |
86478875 JS |
5220 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, |
5221 | int status) | |
5222 | { | |
5223 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; | |
5224 | struct lpfc_vport *vport = ndlp->vport; | |
5225 | struct lpfc_iocbq *elsiocb; | |
eb8d68c9 | 5226 | struct ulp_bde64 *bpl; |
86478875 JS |
5227 | IOCB_t *icmd; |
5228 | uint8_t *pcmd; | |
5229 | struct ls_rjt *stat; | |
5230 | struct fc_rdp_res_frame *rdp_res; | |
6c92d1d0 | 5231 | uint32_t cmdsize, len; |
310429ef | 5232 | uint16_t *flag_ptr; |
6c92d1d0 | 5233 | int rc; |
86478875 JS |
5234 | |
5235 | if (status != SUCCESS) | |
5236 | goto error; | |
eb8d68c9 JS |
5237 | |
5238 | /* This will change once we know the true size of the RDP payload */ | |
86478875 JS |
5239 | cmdsize = sizeof(struct fc_rdp_res_frame); |
5240 | ||
5241 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, | |
5242 | lpfc_max_els_tries, rdp_context->ndlp, | |
5243 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); | |
5244 | lpfc_nlp_put(ndlp); | |
5245 | if (!elsiocb) | |
5246 | goto free_rdp_context; | |
5247 | ||
5248 | icmd = &elsiocb->iocb; | |
5249 | icmd->ulpContext = rdp_context->rx_id; | |
5250 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; | |
5251 | ||
5252 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
5253 | "2171 Xmit RDP response tag x%x xri x%x, " | |
5254 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", | |
5255 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
5256 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
5257 | ndlp->nlp_rpi); | |
5258 | rdp_res = (struct fc_rdp_res_frame *) | |
5259 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
5260 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
5261 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); | |
5262 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
5263 | ||
310429ef JS |
5264 | /* Update Alarm and Warning */ |
5265 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); | |
5266 | phba->sfp_alarm |= *flag_ptr; | |
5267 | flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); | |
5268 | phba->sfp_warning |= *flag_ptr; | |
5269 | ||
86478875 | 5270 | /* For RDP payload */ |
6c92d1d0 JS |
5271 | len = 8; |
5272 | len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) | |
5273 | (len + pcmd), ELS_CMD_RDP); | |
86478875 | 5274 | |
6c92d1d0 | 5275 | len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd), |
86478875 | 5276 | rdp_context->page_a0, rdp_context->page_a2); |
6c92d1d0 JS |
5277 | len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), |
5278 | phba); | |
5279 | len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) | |
5280 | (len + pcmd), &rdp_context->link_stat); | |
5281 | len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) | |
cd46cded | 5282 | (len + pcmd), vport); |
6c92d1d0 JS |
5283 | len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) |
5284 | (len + pcmd), vport, ndlp); | |
5285 | len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), | |
4258e98e | 5286 | &rdp_context->link_stat); |
6c92d1d0 JS |
5287 | /* Check if nport is logged, BZ190632 */ |
5288 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) | |
5289 | goto lpfc_skip_descriptor; | |
5290 | ||
5291 | len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), | |
5292 | &rdp_context->link_stat, vport); | |
5293 | len += lpfc_rdp_res_oed_temp_desc(phba, | |
5294 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), | |
5295 | rdp_context->page_a2); | |
5296 | len += lpfc_rdp_res_oed_voltage_desc(phba, | |
5297 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), | |
5298 | rdp_context->page_a2); | |
5299 | len += lpfc_rdp_res_oed_txbias_desc(phba, | |
5300 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), | |
5301 | rdp_context->page_a2); | |
5302 | len += lpfc_rdp_res_oed_txpower_desc(phba, | |
5303 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), | |
5304 | rdp_context->page_a2); | |
5305 | len += lpfc_rdp_res_oed_rxpower_desc(phba, | |
5306 | (struct fc_rdp_oed_sfp_desc *)(len + pcmd), | |
5307 | rdp_context->page_a2); | |
5308 | len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), | |
5309 | rdp_context->page_a0, vport); | |
5310 | ||
5311 | lpfc_skip_descriptor: | |
5312 | rdp_res->length = cpu_to_be32(len - 8); | |
86478875 JS |
5313 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
5314 | ||
eb8d68c9 JS |
5315 | /* Now that we know the true size of the payload, update the BPL */ |
5316 | bpl = (struct ulp_bde64 *) | |
5317 | (((struct lpfc_dmabuf *)(elsiocb->context3))->virt); | |
6c92d1d0 | 5318 | bpl->tus.f.bdeSize = len; |
eb8d68c9 JS |
5319 | bpl->tus.f.bdeFlags = 0; |
5320 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
5321 | ||
86478875 JS |
5322 | phba->fc_stat.elsXmitACC++; |
5323 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5324 | if (rc == IOCB_ERROR) | |
5325 | lpfc_els_free_iocb(phba, elsiocb); | |
5326 | ||
5327 | kfree(rdp_context); | |
5328 | ||
5329 | return; | |
5330 | error: | |
5331 | cmdsize = 2 * sizeof(uint32_t); | |
5332 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, | |
5333 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
5334 | lpfc_nlp_put(ndlp); | |
5335 | if (!elsiocb) | |
5336 | goto free_rdp_context; | |
5337 | ||
5338 | icmd = &elsiocb->iocb; | |
5339 | icmd->ulpContext = rdp_context->rx_id; | |
5340 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; | |
5341 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
5342 | ||
5343 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | |
5344 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); | |
5345 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
5346 | ||
5347 | phba->fc_stat.elsXmitLSRJT++; | |
5348 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
5349 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5350 | ||
5351 | if (rc == IOCB_ERROR) | |
5352 | lpfc_els_free_iocb(phba, elsiocb); | |
5353 | free_rdp_context: | |
5354 | kfree(rdp_context); | |
5355 | } | |
5356 | ||
bd4b3e5c | 5357 | static int |
86478875 JS |
5358 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) |
5359 | { | |
5360 | LPFC_MBOXQ_t *mbox = NULL; | |
5361 | int rc; | |
5362 | ||
5363 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5364 | if (!mbox) { | |
5365 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, | |
5366 | "7105 failed to allocate mailbox memory"); | |
5367 | return 1; | |
5368 | } | |
5369 | ||
5370 | if (lpfc_sli4_dump_page_a0(phba, mbox)) | |
5371 | goto prep_mbox_fail; | |
5372 | mbox->vport = rdp_context->ndlp->vport; | |
5373 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; | |
5374 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; | |
5375 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
5376 | if (rc == MBX_NOT_FINISHED) | |
5377 | goto issue_mbox_fail; | |
5378 | ||
5379 | return 0; | |
5380 | ||
5381 | prep_mbox_fail: | |
5382 | issue_mbox_fail: | |
5383 | mempool_free(mbox, phba->mbox_mem_pool); | |
5384 | return 1; | |
5385 | } | |
5386 | ||
5387 | /* | |
5388 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. | |
5389 | * @vport: pointer to a host virtual N_Port data structure. | |
5390 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5391 | * @ndlp: pointer to a node-list data structure. | |
5392 | * | |
5393 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) | |
5394 | * IOCB. First, the payload of the unsolicited RDP is checked. | |
5395 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 | |
5396 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, | |
5397 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl | |
5398 | * gather all data and send RDP response. | |
5399 | * | |
5400 | * Return code | |
5401 | * 0 - Sent the acc response | |
5402 | * 1 - Sent the reject response. | |
5403 | */ | |
5404 | static int | |
5405 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
5406 | struct lpfc_nodelist *ndlp) | |
5407 | { | |
5408 | struct lpfc_hba *phba = vport->phba; | |
5409 | struct lpfc_dmabuf *pcmd; | |
5410 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; | |
5411 | struct fc_rdp_req_frame *rdp_req; | |
5412 | struct lpfc_rdp_context *rdp_context; | |
5413 | IOCB_t *cmd = NULL; | |
5414 | struct ls_rjt stat; | |
5415 | ||
5416 | if (phba->sli_rev < LPFC_SLI_REV4 || | |
a0f2d3ef JS |
5417 | bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
5418 | LPFC_SLI_INTF_IF_TYPE_2) { | |
86478875 JS |
5419 | rjt_err = LSRJT_UNABLE_TPC; |
5420 | rjt_expl = LSEXP_REQ_UNSUPPORTED; | |
5421 | goto error; | |
5422 | } | |
5423 | ||
5424 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { | |
5425 | rjt_err = LSRJT_UNABLE_TPC; | |
5426 | rjt_expl = LSEXP_REQ_UNSUPPORTED; | |
5427 | goto error; | |
5428 | } | |
5429 | ||
5430 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
5431 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; | |
5432 | ||
5433 | ||
5434 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
5435 | "2422 ELS RDP Request " | |
5436 | "dec len %d tag x%x port_id %d len %d\n", | |
5437 | be32_to_cpu(rdp_req->rdp_des_length), | |
5438 | be32_to_cpu(rdp_req->nport_id_desc.tag), | |
5439 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), | |
5440 | be32_to_cpu(rdp_req->nport_id_desc.length)); | |
5441 | ||
7d933313 JS |
5442 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
5443 | !phba->cfg_enable_SmartSAN) { | |
5444 | rjt_err = LSRJT_UNABLE_TPC; | |
5445 | rjt_expl = LSEXP_PORT_LOGIN_REQ; | |
5446 | goto error; | |
5447 | } | |
86478875 JS |
5448 | if (sizeof(struct fc_rdp_nport_desc) != |
5449 | be32_to_cpu(rdp_req->rdp_des_length)) | |
5450 | goto rjt_logerr; | |
5451 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) | |
5452 | goto rjt_logerr; | |
5453 | if (RDP_NPORT_ID_SIZE != | |
5454 | be32_to_cpu(rdp_req->nport_id_desc.length)) | |
5455 | goto rjt_logerr; | |
699acd62 | 5456 | rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); |
86478875 JS |
5457 | if (!rdp_context) { |
5458 | rjt_err = LSRJT_UNABLE_TPC; | |
5459 | goto error; | |
5460 | } | |
5461 | ||
86478875 JS |
5462 | cmd = &cmdiocb->iocb; |
5463 | rdp_context->ndlp = lpfc_nlp_get(ndlp); | |
5464 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; | |
5465 | rdp_context->rx_id = cmd->ulpContext; | |
5466 | rdp_context->cmpl = lpfc_els_rdp_cmpl; | |
5467 | if (lpfc_get_rdp_info(phba, rdp_context)) { | |
5468 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, | |
5469 | "2423 Unable to send mailbox"); | |
5470 | kfree(rdp_context); | |
5471 | rjt_err = LSRJT_UNABLE_TPC; | |
5472 | lpfc_nlp_put(ndlp); | |
5473 | goto error; | |
5474 | } | |
5475 | ||
5476 | return 0; | |
5477 | ||
5478 | rjt_logerr: | |
5479 | rjt_err = LSRJT_LOGICAL_ERR; | |
5480 | ||
5481 | error: | |
5482 | memset(&stat, 0, sizeof(stat)); | |
5483 | stat.un.b.lsRjtRsnCode = rjt_err; | |
5484 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; | |
5485 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
5486 | return 1; | |
5487 | } | |
5488 | ||
5489 | ||
8b017a30 JS |
5490 | static void |
5491 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
5492 | { | |
5493 | MAILBOX_t *mb; | |
5494 | IOCB_t *icmd; | |
5495 | uint8_t *pcmd; | |
5496 | struct lpfc_iocbq *elsiocb; | |
5497 | struct lpfc_nodelist *ndlp; | |
5498 | struct ls_rjt *stat; | |
481ad967 | 5499 | union lpfc_sli4_cfg_shdr *shdr; |
8b017a30 JS |
5500 | struct lpfc_lcb_context *lcb_context; |
5501 | struct fc_lcb_res_frame *lcb_res; | |
481ad967 | 5502 | uint32_t cmdsize, shdr_status, shdr_add_status; |
8b017a30 JS |
5503 | int rc; |
5504 | ||
5505 | mb = &pmb->u.mb; | |
8b017a30 JS |
5506 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
5507 | ndlp = lcb_context->ndlp; | |
5508 | pmb->context1 = NULL; | |
5509 | pmb->context2 = NULL; | |
5510 | ||
481ad967 JS |
5511 | shdr = (union lpfc_sli4_cfg_shdr *) |
5512 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; | |
5513 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5514 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5515 | ||
5516 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, | |
5517 | "0194 SET_BEACON_CONFIG mailbox " | |
5518 | "completed with status x%x add_status x%x," | |
5519 | " mbx status x%x\n", | |
5520 | shdr_status, shdr_add_status, mb->mbxStatus); | |
5521 | ||
5522 | if (mb->mbxStatus && !(shdr_status && | |
5523 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { | |
8b017a30 JS |
5524 | mempool_free(pmb, phba->mbox_mem_pool); |
5525 | goto error; | |
5526 | } | |
5527 | ||
5528 | mempool_free(pmb, phba->mbox_mem_pool); | |
8b017a30 JS |
5529 | cmdsize = sizeof(struct fc_lcb_res_frame); |
5530 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
5531 | lpfc_max_els_tries, ndlp, | |
5532 | ndlp->nlp_DID, ELS_CMD_ACC); | |
5533 | ||
5534 | /* Decrement the ndlp reference count from previous mbox command */ | |
5535 | lpfc_nlp_put(ndlp); | |
5536 | ||
5537 | if (!elsiocb) | |
5538 | goto free_lcb_context; | |
5539 | ||
5540 | lcb_res = (struct fc_lcb_res_frame *) | |
5541 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5542 | ||
5543 | icmd = &elsiocb->iocb; | |
5544 | icmd->ulpContext = lcb_context->rx_id; | |
5545 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; | |
5546 | ||
5547 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5548 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; | |
5549 | lcb_res->lcb_sub_command = lcb_context->sub_command; | |
5550 | lcb_res->lcb_type = lcb_context->type; | |
5551 | lcb_res->lcb_frequency = lcb_context->frequency; | |
5552 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
5553 | phba->fc_stat.elsXmitACC++; | |
5554 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5555 | if (rc == IOCB_ERROR) | |
5556 | lpfc_els_free_iocb(phba, elsiocb); | |
5557 | ||
5558 | kfree(lcb_context); | |
5559 | return; | |
5560 | ||
5561 | error: | |
5562 | cmdsize = sizeof(struct fc_lcb_res_frame); | |
5563 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
5564 | lpfc_max_els_tries, ndlp, | |
5565 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
5566 | lpfc_nlp_put(ndlp); | |
5567 | if (!elsiocb) | |
5568 | goto free_lcb_context; | |
5569 | ||
5570 | icmd = &elsiocb->iocb; | |
5571 | icmd->ulpContext = lcb_context->rx_id; | |
5572 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; | |
5573 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5574 | ||
5575 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; | |
5576 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); | |
5577 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
5578 | ||
5579 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
5580 | phba->fc_stat.elsXmitLSRJT++; | |
5581 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5582 | if (rc == IOCB_ERROR) | |
5583 | lpfc_els_free_iocb(phba, elsiocb); | |
5584 | free_lcb_context: | |
5585 | kfree(lcb_context); | |
5586 | } | |
5587 | ||
5588 | static int | |
5589 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, | |
5590 | struct lpfc_lcb_context *lcb_context, | |
5591 | uint32_t beacon_state) | |
5592 | { | |
5593 | struct lpfc_hba *phba = vport->phba; | |
5594 | LPFC_MBOXQ_t *mbox = NULL; | |
5595 | uint32_t len; | |
5596 | int rc; | |
5597 | ||
5598 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5599 | if (!mbox) | |
5600 | return 1; | |
5601 | ||
5602 | len = sizeof(struct lpfc_mbx_set_beacon_config) - | |
5603 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
5604 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5605 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, | |
5606 | LPFC_SLI4_MBX_EMBED); | |
5607 | mbox->context1 = (void *)lcb_context; | |
5608 | mbox->vport = phba->pport; | |
5609 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; | |
5610 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, | |
5611 | phba->sli4_hba.physical_port); | |
5612 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, | |
5613 | beacon_state); | |
5614 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); | |
5615 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); | |
5616 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
5617 | if (rc == MBX_NOT_FINISHED) { | |
5618 | mempool_free(mbox, phba->mbox_mem_pool); | |
5619 | return 1; | |
5620 | } | |
5621 | ||
5622 | return 0; | |
5623 | } | |
5624 | ||
5625 | ||
5626 | /** | |
5627 | * lpfc_els_rcv_lcb - Process an unsolicited LCB | |
5628 | * @vport: pointer to a host virtual N_Port data structure. | |
5629 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5630 | * @ndlp: pointer to a node-list data structure. | |
5631 | * | |
5632 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. | |
5633 | * First, the payload of the unsolicited LCB is checked. | |
5634 | * Then based on Subcommand beacon will either turn on or off. | |
5635 | * | |
5636 | * Return code | |
5637 | * 0 - Sent the acc response | |
5638 | * 1 - Sent the reject response. | |
5639 | **/ | |
5640 | static int | |
5641 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
5642 | struct lpfc_nodelist *ndlp) | |
5643 | { | |
5644 | struct lpfc_hba *phba = vport->phba; | |
5645 | struct lpfc_dmabuf *pcmd; | |
8b017a30 JS |
5646 | uint8_t *lp; |
5647 | struct fc_lcb_request_frame *beacon; | |
5648 | struct lpfc_lcb_context *lcb_context; | |
5649 | uint8_t state, rjt_err; | |
5650 | struct ls_rjt stat; | |
5651 | ||
8b017a30 JS |
5652 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
5653 | lp = (uint8_t *)pcmd->virt; | |
5654 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; | |
5655 | ||
5656 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
5657 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " | |
5658 | "type x%x frequency %x duration x%x\n", | |
5659 | lp[0], lp[1], lp[2], | |
5660 | beacon->lcb_command, | |
5661 | beacon->lcb_sub_command, | |
5662 | beacon->lcb_type, | |
5663 | beacon->lcb_frequency, | |
5664 | be16_to_cpu(beacon->lcb_duration)); | |
5665 | ||
5666 | if (phba->sli_rev < LPFC_SLI_REV4 || | |
5667 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
5668 | LPFC_SLI_INTF_IF_TYPE_2)) { | |
5669 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5670 | goto rjt; | |
5671 | } | |
8b017a30 JS |
5672 | |
5673 | if (phba->hba_flag & HBA_FCOE_MODE) { | |
5674 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5675 | goto rjt; | |
5676 | } | |
5677 | if (beacon->lcb_frequency == 0) { | |
5678 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5679 | goto rjt; | |
5680 | } | |
5681 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && | |
5682 | (beacon->lcb_type != LPFC_LCB_AMBER)) { | |
5683 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5684 | goto rjt; | |
5685 | } | |
5686 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && | |
5687 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { | |
5688 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5689 | goto rjt; | |
5690 | } | |
5691 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && | |
5692 | (beacon->lcb_type != LPFC_LCB_GREEN) && | |
5693 | (beacon->lcb_type != LPFC_LCB_AMBER)) { | |
5694 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5695 | goto rjt; | |
5696 | } | |
5697 | if (be16_to_cpu(beacon->lcb_duration) != 0) { | |
5698 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5699 | goto rjt; | |
5700 | } | |
5701 | ||
e7950423 SM |
5702 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
5703 | if (!lcb_context) { | |
5704 | rjt_err = LSRJT_UNABLE_TPC; | |
5705 | goto rjt; | |
5706 | } | |
5707 | ||
8b017a30 JS |
5708 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
5709 | lcb_context->sub_command = beacon->lcb_sub_command; | |
5710 | lcb_context->type = beacon->lcb_type; | |
5711 | lcb_context->frequency = beacon->lcb_frequency; | |
5712 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; | |
5713 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; | |
5714 | lcb_context->ndlp = lpfc_nlp_get(ndlp); | |
5715 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { | |
5716 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
5717 | LOG_ELS, "0193 failed to send mail box"); | |
e7950423 | 5718 | kfree(lcb_context); |
8b017a30 JS |
5719 | lpfc_nlp_put(ndlp); |
5720 | rjt_err = LSRJT_UNABLE_TPC; | |
5721 | goto rjt; | |
5722 | } | |
5723 | return 0; | |
5724 | rjt: | |
5725 | memset(&stat, 0, sizeof(stat)); | |
5726 | stat.un.b.lsRjtRsnCode = rjt_err; | |
5727 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
5728 | return 1; | |
5729 | } | |
5730 | ||
5731 | ||
e59058c4 | 5732 | /** |
3621a710 | 5733 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
e59058c4 JS |
5734 | * @vport: pointer to a host virtual N_Port data structure. |
5735 | * | |
5736 | * This routine cleans up any Registration State Change Notification | |
5737 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the | |
5738 | * @vport together with the host_lock is used to prevent multiple thread | |
5739 | * trying to access the RSCN array on a same @vport at the same time. | |
5740 | **/ | |
92d7f7b0 | 5741 | void |
2e0fef85 | 5742 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
dea3101e | 5743 | { |
2e0fef85 JS |
5744 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5745 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5746 | int i; |
5747 | ||
7f5f3d0d JS |
5748 | spin_lock_irq(shost->host_lock); |
5749 | if (vport->fc_rscn_flush) { | |
5750 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
5751 | spin_unlock_irq(shost->host_lock); | |
5752 | return; | |
5753 | } | |
5754 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ | |
5755 | vport->fc_rscn_flush = 1; | |
5756 | spin_unlock_irq(shost->host_lock); | |
5757 | ||
2e0fef85 | 5758 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 | 5759 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
2e0fef85 | 5760 | vport->fc_rscn_id_list[i] = NULL; |
dea3101e | 5761 | } |
2e0fef85 JS |
5762 | spin_lock_irq(shost->host_lock); |
5763 | vport->fc_rscn_id_cnt = 0; | |
5764 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); | |
5765 | spin_unlock_irq(shost->host_lock); | |
5766 | lpfc_can_disctmo(vport); | |
7f5f3d0d JS |
5767 | /* Indicate we are done walking this fc_rscn_id_list */ |
5768 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
5769 | } |
5770 | ||
e59058c4 | 5771 | /** |
3621a710 | 5772 | * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did |
e59058c4 JS |
5773 | * @vport: pointer to a host virtual N_Port data structure. |
5774 | * @did: remote destination port identifier. | |
5775 | * | |
5776 | * This routine checks whether there is any pending Registration State | |
5777 | * Configuration Notification (RSCN) to a @did on @vport. | |
5778 | * | |
5779 | * Return code | |
5780 | * None zero - The @did matched with a pending rscn | |
5781 | * 0 - not able to match @did with a pending rscn | |
5782 | **/ | |
dea3101e | 5783 | int |
2e0fef85 | 5784 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
dea3101e JB |
5785 | { |
5786 | D_ID ns_did; | |
5787 | D_ID rscn_did; | |
dea3101e | 5788 | uint32_t *lp; |
92d7f7b0 | 5789 | uint32_t payload_len, i; |
7f5f3d0d | 5790 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
5791 | |
5792 | ns_did.un.word = did; | |
dea3101e JB |
5793 | |
5794 | /* Never match fabric nodes for RSCNs */ | |
5795 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
2e0fef85 | 5796 | return 0; |
dea3101e JB |
5797 | |
5798 | /* If we are doing a FULL RSCN rediscovery, match everything */ | |
2e0fef85 | 5799 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
c9f8735b | 5800 | return did; |
dea3101e | 5801 | |
7f5f3d0d JS |
5802 | spin_lock_irq(shost->host_lock); |
5803 | if (vport->fc_rscn_flush) { | |
5804 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
5805 | spin_unlock_irq(shost->host_lock); | |
5806 | return 0; | |
5807 | } | |
5808 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
5809 | vport->fc_rscn_flush = 1; | |
5810 | spin_unlock_irq(shost->host_lock); | |
2e0fef85 | 5811 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 JS |
5812 | lp = vport->fc_rscn_id_list[i]->virt; |
5813 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | |
5814 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 5815 | while (payload_len) { |
92d7f7b0 JS |
5816 | rscn_did.un.word = be32_to_cpu(*lp++); |
5817 | payload_len -= sizeof(uint32_t); | |
eaf15d5b JS |
5818 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
5819 | case RSCN_ADDRESS_FORMAT_PORT: | |
6fb120a7 JS |
5820 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
5821 | && (ns_did.un.b.area == rscn_did.un.b.area) | |
5822 | && (ns_did.un.b.id == rscn_did.un.b.id)) | |
7f5f3d0d | 5823 | goto return_did_out; |
dea3101e | 5824 | break; |
eaf15d5b | 5825 | case RSCN_ADDRESS_FORMAT_AREA: |
dea3101e JB |
5826 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
5827 | && (ns_did.un.b.area == rscn_did.un.b.area)) | |
7f5f3d0d | 5828 | goto return_did_out; |
dea3101e | 5829 | break; |
eaf15d5b | 5830 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
dea3101e | 5831 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
7f5f3d0d | 5832 | goto return_did_out; |
dea3101e | 5833 | break; |
eaf15d5b | 5834 | case RSCN_ADDRESS_FORMAT_FABRIC: |
7f5f3d0d | 5835 | goto return_did_out; |
dea3101e JB |
5836 | } |
5837 | } | |
92d7f7b0 | 5838 | } |
7f5f3d0d JS |
5839 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
5840 | vport->fc_rscn_flush = 0; | |
92d7f7b0 | 5841 | return 0; |
7f5f3d0d JS |
5842 | return_did_out: |
5843 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | |
5844 | vport->fc_rscn_flush = 0; | |
5845 | return did; | |
dea3101e JB |
5846 | } |
5847 | ||
e59058c4 | 5848 | /** |
3621a710 | 5849 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
e59058c4 JS |
5850 | * @vport: pointer to a host virtual N_Port data structure. |
5851 | * | |
5852 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the | |
5853 | * state machine for a @vport's nodes that are with pending RSCN (Registration | |
5854 | * State Change Notification). | |
5855 | * | |
5856 | * Return code | |
5857 | * 0 - Successful (currently alway return 0) | |
5858 | **/ | |
dea3101e | 5859 | static int |
2e0fef85 | 5860 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
dea3101e | 5861 | { |
685f0bf7 | 5862 | struct lpfc_nodelist *ndlp = NULL; |
dea3101e | 5863 | |
0d2b6b83 | 5864 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
2e0fef85 | 5865 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 | 5866 | if (!NLP_CHK_NODE_ACT(ndlp) || |
0d2b6b83 JS |
5867 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
5868 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) | |
685f0bf7 | 5869 | continue; |
8c258641 JS |
5870 | if (vport->phba->nvmet_support) |
5871 | continue; | |
2e0fef85 | 5872 | lpfc_disc_state_machine(vport, ndlp, NULL, |
0d2b6b83 JS |
5873 | NLP_EVT_DEVICE_RECOVERY); |
5874 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
dea3101e | 5875 | } |
c9f8735b | 5876 | return 0; |
dea3101e JB |
5877 | } |
5878 | ||
ddcc50f0 | 5879 | /** |
3621a710 | 5880 | * lpfc_send_rscn_event - Send an RSCN event to management application |
ddcc50f0 JS |
5881 | * @vport: pointer to a host virtual N_Port data structure. |
5882 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5883 | * | |
5884 | * lpfc_send_rscn_event sends an RSCN netlink event to management | |
5885 | * applications. | |
5886 | */ | |
5887 | static void | |
5888 | lpfc_send_rscn_event(struct lpfc_vport *vport, | |
5889 | struct lpfc_iocbq *cmdiocb) | |
5890 | { | |
5891 | struct lpfc_dmabuf *pcmd; | |
5892 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
5893 | uint32_t *payload_ptr; | |
5894 | uint32_t payload_len; | |
5895 | struct lpfc_rscn_event_header *rscn_event_data; | |
5896 | ||
5897 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
5898 | payload_ptr = (uint32_t *) pcmd->virt; | |
5899 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); | |
5900 | ||
5901 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + | |
5902 | payload_len, GFP_KERNEL); | |
5903 | if (!rscn_event_data) { | |
5904 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
5905 | "0147 Failed to allocate memory for RSCN event\n"); | |
5906 | return; | |
5907 | } | |
5908 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; | |
5909 | rscn_event_data->payload_length = payload_len; | |
5910 | memcpy(rscn_event_data->rscn_payload, payload_ptr, | |
5911 | payload_len); | |
5912 | ||
5913 | fc_host_post_vendor_event(shost, | |
5914 | fc_get_event_number(), | |
6599eaaa | 5915 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
ddcc50f0 JS |
5916 | (char *)rscn_event_data, |
5917 | LPFC_NL_VENDOR_ID); | |
5918 | ||
5919 | kfree(rscn_event_data); | |
5920 | } | |
5921 | ||
e59058c4 | 5922 | /** |
3621a710 | 5923 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
e59058c4 JS |
5924 | * @vport: pointer to a host virtual N_Port data structure. |
5925 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5926 | * @ndlp: pointer to a node-list data structure. | |
5927 | * | |
5928 | * This routine processes an unsolicited RSCN (Registration State Change | |
5929 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked | |
5930 | * to invoke fc_host_post_event() routine to the FC transport layer. If the | |
5931 | * discover state machine is about to begin discovery, it just accepts the | |
5932 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only | |
5933 | * contains N_Port IDs for other vports on this HBA, it just accepts the | |
5934 | * RSCN and ignore processing it. If the state machine is in the recovery | |
5935 | * state, the fc_rscn_id_list of this @vport is walked and the | |
5936 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for | |
5937 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() | |
5938 | * routine is invoked to handle the RSCN event. | |
5939 | * | |
5940 | * Return code | |
5941 | * 0 - Just sent the acc response | |
5942 | * 1 - Sent the acc response and waited for name server completion | |
5943 | **/ | |
dea3101e | 5944 | static int |
2e0fef85 | 5945 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 5946 | struct lpfc_nodelist *ndlp) |
dea3101e | 5947 | { |
2e0fef85 JS |
5948 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5949 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5950 | struct lpfc_dmabuf *pcmd; |
92d7f7b0 | 5951 | uint32_t *lp, *datap; |
92d7f7b0 | 5952 | uint32_t payload_len, length, nportid, *cmd; |
7f5f3d0d | 5953 | int rscn_cnt; |
92d7f7b0 | 5954 | int rscn_id = 0, hba_id = 0; |
d2873e4c | 5955 | int i; |
dea3101e | 5956 | |
dea3101e JB |
5957 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
5958 | lp = (uint32_t *) pcmd->virt; | |
5959 | ||
92d7f7b0 JS |
5960 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
5961 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 5962 | /* RSCN received */ |
e8b62011 JS |
5963 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5964 | "0214 RSCN received Data: x%x x%x x%x x%x\n", | |
7f5f3d0d JS |
5965 | vport->fc_flag, payload_len, *lp, |
5966 | vport->fc_rscn_id_cnt); | |
ddcc50f0 JS |
5967 | |
5968 | /* Send an RSCN event to the management application */ | |
5969 | lpfc_send_rscn_event(vport, cmdiocb); | |
5970 | ||
d2873e4c | 5971 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
2e0fef85 | 5972 | fc_host_post_event(shost, fc_get_event_number(), |
d2873e4c JS |
5973 | FCH_EVT_RSCN, lp[i]); |
5974 | ||
dea3101e JB |
5975 | /* If we are about to begin discovery, just ACC the RSCN. |
5976 | * Discovery processing will satisfy it. | |
5977 | */ | |
2e0fef85 | 5978 | if (vport->port_state <= LPFC_NS_QRY) { |
858c9f6c JS |
5979 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
5980 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", | |
5981 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
5982 | ||
51ef4c26 | 5983 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
c9f8735b | 5984 | return 0; |
dea3101e JB |
5985 | } |
5986 | ||
92d7f7b0 JS |
5987 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
5988 | * just ACC and ignore it. | |
5989 | */ | |
5990 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
3de2a653 | 5991 | !(vport->cfg_peer_port_login)) { |
92d7f7b0 JS |
5992 | i = payload_len; |
5993 | datap = lp; | |
5994 | while (i > 0) { | |
5995 | nportid = *datap++; | |
5996 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); | |
5997 | i -= sizeof(uint32_t); | |
5998 | rscn_id++; | |
549e55cd JS |
5999 | if (lpfc_find_vport_by_did(phba, nportid)) |
6000 | hba_id++; | |
92d7f7b0 JS |
6001 | } |
6002 | if (rscn_id == hba_id) { | |
6003 | /* ALL NPortIDs in RSCN are on HBA */ | |
e8b62011 | 6004 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
d7c255b2 | 6005 | "0219 Ignore RSCN " |
e8b62011 JS |
6006 | "Data: x%x x%x x%x x%x\n", |
6007 | vport->fc_flag, payload_len, | |
7f5f3d0d | 6008 | *lp, vport->fc_rscn_id_cnt); |
858c9f6c JS |
6009 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
6010 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", | |
6011 | ndlp->nlp_DID, vport->port_state, | |
6012 | ndlp->nlp_flag); | |
6013 | ||
92d7f7b0 | 6014 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
51ef4c26 | 6015 | ndlp, NULL); |
92d7f7b0 JS |
6016 | return 0; |
6017 | } | |
6018 | } | |
6019 | ||
7f5f3d0d JS |
6020 | spin_lock_irq(shost->host_lock); |
6021 | if (vport->fc_rscn_flush) { | |
6022 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
7f5f3d0d | 6023 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
97957244 | 6024 | spin_unlock_irq(shost->host_lock); |
58da1ffb JS |
6025 | /* Send back ACC */ |
6026 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | |
7f5f3d0d JS |
6027 | return 0; |
6028 | } | |
6029 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
6030 | vport->fc_rscn_flush = 1; | |
6031 | spin_unlock_irq(shost->host_lock); | |
af901ca1 | 6032 | /* Get the array count after successfully have the token */ |
7f5f3d0d | 6033 | rscn_cnt = vport->fc_rscn_id_cnt; |
dea3101e JB |
6034 | /* If we are already processing an RSCN, save the received |
6035 | * RSCN payload buffer, cmdiocb->context2 to process later. | |
6036 | */ | |
2e0fef85 | 6037 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
858c9f6c JS |
6038 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
6039 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", | |
6040 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
6041 | ||
09372820 | 6042 | spin_lock_irq(shost->host_lock); |
92d7f7b0 JS |
6043 | vport->fc_flag |= FC_RSCN_DEFERRED; |
6044 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && | |
2e0fef85 | 6045 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
2e0fef85 JS |
6046 | vport->fc_flag |= FC_RSCN_MODE; |
6047 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 JS |
6048 | if (rscn_cnt) { |
6049 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; | |
6050 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); | |
6051 | } | |
6052 | if ((rscn_cnt) && | |
6053 | (payload_len + length <= LPFC_BPL_SIZE)) { | |
6054 | *cmd &= ELS_CMD_MASK; | |
7f5f3d0d | 6055 | *cmd |= cpu_to_be32(payload_len + length); |
92d7f7b0 JS |
6056 | memcpy(((uint8_t *)cmd) + length, lp, |
6057 | payload_len); | |
6058 | } else { | |
6059 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; | |
6060 | vport->fc_rscn_id_cnt++; | |
6061 | /* If we zero, cmdiocb->context2, the calling | |
6062 | * routine will not try to free it. | |
6063 | */ | |
6064 | cmdiocb->context2 = NULL; | |
6065 | } | |
dea3101e | 6066 | /* Deferred RSCN */ |
e8b62011 JS |
6067 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
6068 | "0235 Deferred RSCN " | |
6069 | "Data: x%x x%x x%x\n", | |
6070 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
6071 | vport->port_state); | |
dea3101e | 6072 | } else { |
2e0fef85 JS |
6073 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
6074 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 6075 | /* ReDiscovery RSCN */ |
e8b62011 JS |
6076 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
6077 | "0234 ReDiscovery RSCN " | |
6078 | "Data: x%x x%x x%x\n", | |
6079 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
6080 | vport->port_state); | |
dea3101e | 6081 | } |
7f5f3d0d JS |
6082 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
6083 | vport->fc_rscn_flush = 0; | |
dea3101e | 6084 | /* Send back ACC */ |
51ef4c26 | 6085 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 6086 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 6087 | lpfc_rscn_recovery_check(vport); |
09372820 | 6088 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 6089 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
09372820 | 6090 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 6091 | return 0; |
dea3101e | 6092 | } |
858c9f6c JS |
6093 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
6094 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", | |
6095 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
6096 | ||
2e0fef85 JS |
6097 | spin_lock_irq(shost->host_lock); |
6098 | vport->fc_flag |= FC_RSCN_MODE; | |
6099 | spin_unlock_irq(shost->host_lock); | |
6100 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; | |
7f5f3d0d JS |
6101 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
6102 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
6103 | /* |
6104 | * If we zero, cmdiocb->context2, the calling routine will | |
6105 | * not try to free it. | |
6106 | */ | |
6107 | cmdiocb->context2 = NULL; | |
2e0fef85 | 6108 | lpfc_set_disctmo(vport); |
dea3101e | 6109 | /* Send back ACC */ |
51ef4c26 | 6110 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 6111 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 6112 | lpfc_rscn_recovery_check(vport); |
2e0fef85 | 6113 | return lpfc_els_handle_rscn(vport); |
dea3101e JB |
6114 | } |
6115 | ||
e59058c4 | 6116 | /** |
3621a710 | 6117 | * lpfc_els_handle_rscn - Handle rscn for a vport |
e59058c4 JS |
6118 | * @vport: pointer to a host virtual N_Port data structure. |
6119 | * | |
6120 | * This routine handles the Registration State Configuration Notification | |
6121 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall | |
6122 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, | |
6123 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the | |
6124 | * NameServer shall be issued. If CT command to the NameServer fails to be | |
6125 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any | |
6126 | * RSCN activities with the @vport. | |
6127 | * | |
6128 | * Return code | |
6129 | * 0 - Cleaned up rscn on the @vport | |
6130 | * 1 - Wait for plogi to name server before proceed | |
6131 | **/ | |
dea3101e | 6132 | int |
2e0fef85 | 6133 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
dea3101e JB |
6134 | { |
6135 | struct lpfc_nodelist *ndlp; | |
2e0fef85 | 6136 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 6137 | |
92d7f7b0 JS |
6138 | /* Ignore RSCN if the port is being torn down. */ |
6139 | if (vport->load_flag & FC_UNLOADING) { | |
6140 | lpfc_els_flush_rscn(vport); | |
6141 | return 0; | |
6142 | } | |
6143 | ||
dea3101e | 6144 | /* Start timer for RSCN processing */ |
2e0fef85 | 6145 | lpfc_set_disctmo(vport); |
dea3101e JB |
6146 | |
6147 | /* RSCN processed */ | |
e8b62011 JS |
6148 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
6149 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", | |
6150 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, | |
6151 | vport->port_state); | |
dea3101e JB |
6152 | |
6153 | /* To process RSCN, first compare RSCN data with NameServer */ | |
2e0fef85 | 6154 | vport->fc_ns_retry = 0; |
0ff10d46 JS |
6155 | vport->num_disc_nodes = 0; |
6156 | ||
2e0fef85 | 6157 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 JS |
6158 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
6159 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { | |
dea3101e | 6160 | /* Good ndlp, issue CT Request to NameServer */ |
a0f2d3ef JS |
6161 | vport->gidft_inp = 0; |
6162 | if (lpfc_issue_gidft(vport) == 0) | |
dea3101e | 6163 | /* Wait for NameServer query cmpl before we can |
a0f2d3ef JS |
6164 | * continue |
6165 | */ | |
c9f8735b | 6166 | return 1; |
dea3101e JB |
6167 | } else { |
6168 | /* If login to NameServer does not exist, issue one */ | |
6169 | /* Good status, issue PLOGI to NameServer */ | |
2e0fef85 | 6170 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 | 6171 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
dea3101e JB |
6172 | /* Wait for NameServer login cmpl before we can |
6173 | continue */ | |
c9f8735b | 6174 | return 1; |
2e0fef85 | 6175 | |
e47c9093 JS |
6176 | if (ndlp) { |
6177 | ndlp = lpfc_enable_node(vport, ndlp, | |
6178 | NLP_STE_PLOGI_ISSUE); | |
6179 | if (!ndlp) { | |
6180 | lpfc_els_flush_rscn(vport); | |
6181 | return 0; | |
6182 | } | |
6183 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; | |
dea3101e | 6184 | } else { |
e47c9093 JS |
6185 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
6186 | if (!ndlp) { | |
6187 | lpfc_els_flush_rscn(vport); | |
6188 | return 0; | |
6189 | } | |
2e0fef85 | 6190 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
5024ab17 | 6191 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 6192 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
dea3101e | 6193 | } |
e47c9093 JS |
6194 | ndlp->nlp_type |= NLP_FABRIC; |
6195 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); | |
6196 | /* Wait for NameServer login cmpl before we can | |
6197 | * continue | |
6198 | */ | |
6199 | return 1; | |
dea3101e JB |
6200 | } |
6201 | ||
2e0fef85 | 6202 | lpfc_els_flush_rscn(vport); |
c9f8735b | 6203 | return 0; |
dea3101e JB |
6204 | } |
6205 | ||
e59058c4 | 6206 | /** |
3621a710 | 6207 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
e59058c4 JS |
6208 | * @vport: pointer to a host virtual N_Port data structure. |
6209 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6210 | * @ndlp: pointer to a node-list data structure. | |
6211 | * | |
6212 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS | |
6213 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- | |
6214 | * point topology. As an unsolicited FLOGI should not be received in a loop | |
6215 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The | |
6216 | * lpfc_check_sparm() routine is invoked to check the parameters in the | |
6217 | * unsolicited FLOGI. If parameters validation failed, the routine | |
6218 | * lpfc_els_rsp_reject() shall be called with reject reason code set to | |
6219 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the | |
6220 | * FLOGI shall be compared with the Port WWN of the @vport to determine who | |
6221 | * will initiate PLOGI. The higher lexicographical value party shall has | |
6222 | * higher priority (as the winning port) and will initiate PLOGI and | |
6223 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result | |
6224 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI | |
6225 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. | |
6226 | * | |
6227 | * Return code | |
6228 | * 0 - Successfully processed the unsolicited flogi | |
6229 | * 1 - Failed to process the unsolicited flogi | |
6230 | **/ | |
dea3101e | 6231 | static int |
2e0fef85 | 6232 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 6233 | struct lpfc_nodelist *ndlp) |
dea3101e | 6234 | { |
2e0fef85 JS |
6235 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
6236 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
6237 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
6238 | uint32_t *lp = (uint32_t *) pcmd->virt; | |
6239 | IOCB_t *icmd = &cmdiocb->iocb; | |
6240 | struct serv_parm *sp; | |
6241 | LPFC_MBOXQ_t *mbox; | |
dea3101e JB |
6242 | uint32_t cmd, did; |
6243 | int rc; | |
e74c03c8 JS |
6244 | uint32_t fc_flag = 0; |
6245 | uint32_t port_state = 0; | |
dea3101e JB |
6246 | |
6247 | cmd = *lp++; | |
6248 | sp = (struct serv_parm *) lp; | |
6249 | ||
6250 | /* FLOGI received */ | |
6251 | ||
2e0fef85 | 6252 | lpfc_set_disctmo(vport); |
dea3101e | 6253 | |
76a95d75 | 6254 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
dea3101e JB |
6255 | /* We should never receive a FLOGI in loop mode, ignore it */ |
6256 | did = icmd->un.elsreq64.remoteID; | |
6257 | ||
6258 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in | |
6259 | Loop Mode */ | |
e8b62011 JS |
6260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
6261 | "0113 An FLOGI ELS command x%x was " | |
6262 | "received from DID x%x in Loop Mode\n", | |
6263 | cmd, did); | |
c9f8735b | 6264 | return 1; |
dea3101e JB |
6265 | } |
6266 | ||
d6de08cc | 6267 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
dea3101e | 6268 | |
d6de08cc JS |
6269 | /* |
6270 | * If our portname is greater than the remote portname, | |
6271 | * then we initiate Nport login. | |
6272 | */ | |
939723a4 | 6273 | |
d6de08cc JS |
6274 | rc = memcmp(&vport->fc_portname, &sp->portName, |
6275 | sizeof(struct lpfc_name)); | |
939723a4 | 6276 | |
d6de08cc JS |
6277 | if (!rc) { |
6278 | if (phba->sli_rev < LPFC_SLI_REV4) { | |
6279 | mbox = mempool_alloc(phba->mbox_mem_pool, | |
6280 | GFP_KERNEL); | |
6281 | if (!mbox) | |
6282 | return 1; | |
6283 | lpfc_linkdown(phba); | |
6284 | lpfc_init_link(phba, mbox, | |
6285 | phba->cfg_topology, | |
6286 | phba->cfg_link_speed); | |
6287 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; | |
6288 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6289 | mbox->vport = vport; | |
6290 | rc = lpfc_sli_issue_mbox(phba, mbox, | |
6291 | MBX_NOWAIT); | |
6292 | lpfc_set_loopback_flag(phba); | |
6293 | if (rc == MBX_NOT_FINISHED) | |
6294 | mempool_free(mbox, phba->mbox_mem_pool); | |
6295 | return 1; | |
6296 | } | |
6297 | ||
6298 | /* abort the flogi coming back to ourselves | |
6299 | * due to external loopback on the port. | |
939723a4 | 6300 | */ |
d6de08cc JS |
6301 | lpfc_els_abort_flogi(phba); |
6302 | return 0; | |
6303 | ||
6304 | } else if (rc > 0) { /* greater than */ | |
2e0fef85 | 6305 | spin_lock_irq(shost->host_lock); |
d6de08cc | 6306 | vport->fc_flag |= FC_PT2PT_PLOGI; |
2e0fef85 | 6307 | spin_unlock_irq(shost->host_lock); |
939723a4 | 6308 | |
d6de08cc JS |
6309 | /* If we have the high WWPN we can assign our own |
6310 | * myDID; otherwise, we have to WAIT for a PLOGI | |
6311 | * from the remote NPort to find out what it | |
6312 | * will be. | |
939723a4 | 6313 | */ |
d6de08cc | 6314 | vport->fc_myDID = PT2PT_LocalID; |
dea3101e | 6315 | } else { |
d6de08cc JS |
6316 | vport->fc_myDID = PT2PT_RemoteID; |
6317 | } | |
939723a4 | 6318 | |
d6de08cc JS |
6319 | /* |
6320 | * The vport state should go to LPFC_FLOGI only | |
6321 | * AFTER we issue a FLOGI, not receive one. | |
6322 | */ | |
6323 | spin_lock_irq(shost->host_lock); | |
6324 | fc_flag = vport->fc_flag; | |
6325 | port_state = vport->port_state; | |
6326 | vport->fc_flag |= FC_PT2PT; | |
6327 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
6328 | spin_unlock_irq(shost->host_lock); | |
6329 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
6330 | "3311 Rcv Flogi PS x%x new PS x%x " | |
6331 | "fc_flag x%x new fc_flag x%x\n", | |
6332 | port_state, vport->port_state, | |
6333 | fc_flag, vport->fc_flag); | |
939723a4 | 6334 | |
d6de08cc JS |
6335 | /* |
6336 | * We temporarily set fc_myDID to make it look like we are | |
6337 | * a Fabric. This is done just so we end up with the right | |
6338 | * did / sid on the FLOGI ACC rsp. | |
6339 | */ | |
6340 | did = vport->fc_myDID; | |
6341 | vport->fc_myDID = Fabric_DID; | |
dea3101e | 6342 | |
d6de08cc | 6343 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
eec3d312 | 6344 | |
dea3101e | 6345 | /* Send back ACC */ |
d6de08cc | 6346 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
dea3101e | 6347 | |
939723a4 JS |
6348 | /* Now lets put fc_myDID back to what its supposed to be */ |
6349 | vport->fc_myDID = did; | |
6350 | ||
c9f8735b | 6351 | return 0; |
dea3101e JB |
6352 | } |
6353 | ||
e59058c4 | 6354 | /** |
3621a710 | 6355 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
e59058c4 JS |
6356 | * @vport: pointer to a host virtual N_Port data structure. |
6357 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6358 | * @ndlp: pointer to a node-list data structure. | |
6359 | * | |
6360 | * This routine processes Request Node Identification Data (RNID) IOCB | |
6361 | * received as an ELS unsolicited event. Only when the RNID specified format | |
6362 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) | |
6363 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to | |
6364 | * Accept (ACC) the RNID ELS command. All the other RNID formats are | |
6365 | * rejected by invoking the lpfc_els_rsp_reject() routine. | |
6366 | * | |
6367 | * Return code | |
6368 | * 0 - Successfully processed rnid iocb (currently always return 0) | |
6369 | **/ | |
dea3101e | 6370 | static int |
2e0fef85 JS |
6371 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6372 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
6373 | { |
6374 | struct lpfc_dmabuf *pcmd; | |
6375 | uint32_t *lp; | |
dea3101e JB |
6376 | RNID *rn; |
6377 | struct ls_rjt stat; | |
eb016566 | 6378 | uint32_t cmd; |
dea3101e | 6379 | |
dea3101e JB |
6380 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
6381 | lp = (uint32_t *) pcmd->virt; | |
6382 | ||
6383 | cmd = *lp++; | |
6384 | rn = (RNID *) lp; | |
6385 | ||
6386 | /* RNID received */ | |
6387 | ||
6388 | switch (rn->Format) { | |
6389 | case 0: | |
6390 | case RNID_TOPOLOGY_DISC: | |
6391 | /* Send back ACC */ | |
2e0fef85 | 6392 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
dea3101e JB |
6393 | break; |
6394 | default: | |
6395 | /* Reject this request because format not supported */ | |
6396 | stat.un.b.lsRjtRsvd0 = 0; | |
6397 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6398 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6399 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
6400 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
6401 | NULL); | |
dea3101e | 6402 | } |
c9f8735b | 6403 | return 0; |
dea3101e JB |
6404 | } |
6405 | ||
12265f68 JS |
6406 | /** |
6407 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb | |
6408 | * @vport: pointer to a host virtual N_Port data structure. | |
6409 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6410 | * @ndlp: pointer to a node-list data structure. | |
6411 | * | |
6412 | * Return code | |
6413 | * 0 - Successfully processed echo iocb (currently always return 0) | |
6414 | **/ | |
6415 | static int | |
6416 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6417 | struct lpfc_nodelist *ndlp) | |
6418 | { | |
6419 | uint8_t *pcmd; | |
6420 | ||
6421 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); | |
6422 | ||
6423 | /* skip over first word of echo command to find echo data */ | |
6424 | pcmd += sizeof(uint32_t); | |
6425 | ||
6426 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); | |
6427 | return 0; | |
6428 | } | |
6429 | ||
e59058c4 | 6430 | /** |
3621a710 | 6431 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
e59058c4 JS |
6432 | * @vport: pointer to a host virtual N_Port data structure. |
6433 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6434 | * @ndlp: pointer to a node-list data structure. | |
6435 | * | |
6436 | * This routine processes a Link Incident Report Registration(LIRR) IOCB | |
6437 | * received as an ELS unsolicited event. Currently, this function just invokes | |
6438 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. | |
6439 | * | |
6440 | * Return code | |
6441 | * 0 - Successfully processed lirr iocb (currently always return 0) | |
6442 | **/ | |
dea3101e | 6443 | static int |
2e0fef85 JS |
6444 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6445 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
6446 | { |
6447 | struct ls_rjt stat; | |
6448 | ||
6449 | /* For now, unconditionally reject this command */ | |
6450 | stat.un.b.lsRjtRsvd0 = 0; | |
6451 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6452 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6453 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 6454 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
6455 | return 0; |
6456 | } | |
6457 | ||
5ffc266e JS |
6458 | /** |
6459 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb | |
6460 | * @vport: pointer to a host virtual N_Port data structure. | |
6461 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6462 | * @ndlp: pointer to a node-list data structure. | |
6463 | * | |
6464 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB | |
6465 | * received as an ELS unsolicited event. A request to RRQ shall only | |
6466 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder | |
6467 | * Nx_Port N_Port_ID of the target Exchange is the same as the | |
6468 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is | |
6469 | * not accepted, an LS_RJT with reason code "Unable to perform | |
6470 | * command request" and reason code explanation "Invalid Originator | |
6471 | * S_ID" shall be returned. For now, we just unconditionally accept | |
6472 | * RRQ from the target. | |
6473 | **/ | |
6474 | static void | |
6475 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6476 | struct lpfc_nodelist *ndlp) | |
6477 | { | |
6478 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | |
19ca7609 JS |
6479 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
6480 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); | |
5ffc266e JS |
6481 | } |
6482 | ||
12265f68 JS |
6483 | /** |
6484 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd | |
6485 | * @phba: pointer to lpfc hba data structure. | |
6486 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
6487 | * | |
6488 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | |
6489 | * mailbox command. This callback function is to actually send the Accept | |
6490 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | |
6491 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | |
6492 | * mailbox command, constructs the RPS response with the link statistics | |
6493 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | |
6494 | * response to the RPS. | |
6495 | * | |
6496 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6497 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6498 | * will be stored into the context1 field of the IOCB for the completion | |
6499 | * callback function to the RPS Accept Response ELS IOCB command. | |
6500 | * | |
6501 | **/ | |
6502 | static void | |
6503 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
6504 | { | |
6505 | MAILBOX_t *mb; | |
6506 | IOCB_t *icmd; | |
6507 | struct RLS_RSP *rls_rsp; | |
6508 | uint8_t *pcmd; | |
6509 | struct lpfc_iocbq *elsiocb; | |
6510 | struct lpfc_nodelist *ndlp; | |
7851fe2c JS |
6511 | uint16_t oxid; |
6512 | uint16_t rxid; | |
12265f68 JS |
6513 | uint32_t cmdsize; |
6514 | ||
6515 | mb = &pmb->u.mb; | |
6516 | ||
6517 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
7851fe2c JS |
6518 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
6519 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | |
12265f68 JS |
6520 | pmb->context1 = NULL; |
6521 | pmb->context2 = NULL; | |
6522 | ||
6523 | if (mb->mbxStatus) { | |
6524 | mempool_free(pmb, phba->mbox_mem_pool); | |
6525 | return; | |
6526 | } | |
6527 | ||
6528 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); | |
12265f68 JS |
6529 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
6530 | lpfc_max_els_tries, ndlp, | |
6531 | ndlp->nlp_DID, ELS_CMD_ACC); | |
6532 | ||
6533 | /* Decrement the ndlp reference count from previous mbox command */ | |
6534 | lpfc_nlp_put(ndlp); | |
6535 | ||
37db57e3 JS |
6536 | if (!elsiocb) { |
6537 | mempool_free(pmb, phba->mbox_mem_pool); | |
12265f68 | 6538 | return; |
37db57e3 | 6539 | } |
12265f68 JS |
6540 | |
6541 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
6542 | icmd->ulpContext = rxid; |
6543 | icmd->unsli3.rcvsli3.ox_id = oxid; | |
12265f68 JS |
6544 | |
6545 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6546 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
6547 | pcmd += sizeof(uint32_t); /* Skip past command */ | |
6548 | rls_rsp = (struct RLS_RSP *)pcmd; | |
6549 | ||
6550 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | |
6551 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | |
6552 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | |
6553 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | |
6554 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | |
6555 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | |
37db57e3 | 6556 | mempool_free(pmb, phba->mbox_mem_pool); |
12265f68 JS |
6557 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
6558 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | |
6559 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " | |
6560 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
6561 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6562 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6563 | ndlp->nlp_rpi); | |
6564 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
6565 | phba->fc_stat.elsXmitACC++; | |
6566 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | |
6567 | lpfc_els_free_iocb(phba, elsiocb); | |
6568 | } | |
6569 | ||
e59058c4 | 6570 | /** |
3621a710 | 6571 | * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
e59058c4 JS |
6572 | * @phba: pointer to lpfc hba data structure. |
6573 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
6574 | * | |
6575 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | |
6576 | * mailbox command. This callback function is to actually send the Accept | |
6577 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | |
6578 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | |
6579 | * mailbox command, constructs the RPS response with the link statistics | |
6580 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | |
6581 | * response to the RPS. | |
6582 | * | |
6583 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6584 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6585 | * will be stored into the context1 field of the IOCB for the completion | |
6586 | * callback function to the RPS Accept Response ELS IOCB command. | |
6587 | * | |
6588 | **/ | |
082c0266 | 6589 | static void |
329f9bc7 | 6590 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
7bb3b137 | 6591 | { |
7bb3b137 JW |
6592 | MAILBOX_t *mb; |
6593 | IOCB_t *icmd; | |
6594 | RPS_RSP *rps_rsp; | |
6595 | uint8_t *pcmd; | |
6596 | struct lpfc_iocbq *elsiocb; | |
6597 | struct lpfc_nodelist *ndlp; | |
7851fe2c JS |
6598 | uint16_t status; |
6599 | uint16_t oxid; | |
6600 | uint16_t rxid; | |
7bb3b137 JW |
6601 | uint32_t cmdsize; |
6602 | ||
04c68496 | 6603 | mb = &pmb->u.mb; |
7bb3b137 JW |
6604 | |
6605 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
7851fe2c JS |
6606 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
6607 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | |
041976fb RD |
6608 | pmb->context1 = NULL; |
6609 | pmb->context2 = NULL; | |
7bb3b137 JW |
6610 | |
6611 | if (mb->mbxStatus) { | |
329f9bc7 | 6612 | mempool_free(pmb, phba->mbox_mem_pool); |
7bb3b137 JW |
6613 | return; |
6614 | } | |
6615 | ||
6616 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); | |
329f9bc7 | 6617 | mempool_free(pmb, phba->mbox_mem_pool); |
2e0fef85 JS |
6618 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
6619 | lpfc_max_els_tries, ndlp, | |
6620 | ndlp->nlp_DID, ELS_CMD_ACC); | |
fa4066b6 JS |
6621 | |
6622 | /* Decrement the ndlp reference count from previous mbox command */ | |
329f9bc7 | 6623 | lpfc_nlp_put(ndlp); |
fa4066b6 | 6624 | |
c9f8735b | 6625 | if (!elsiocb) |
7bb3b137 | 6626 | return; |
7bb3b137 JW |
6627 | |
6628 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
6629 | icmd->ulpContext = rxid; |
6630 | icmd->unsli3.rcvsli3.ox_id = oxid; | |
7bb3b137 JW |
6631 | |
6632 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6633 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 6634 | pcmd += sizeof(uint32_t); /* Skip past command */ |
7bb3b137 JW |
6635 | rps_rsp = (RPS_RSP *)pcmd; |
6636 | ||
76a95d75 | 6637 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
7bb3b137 JW |
6638 | status = 0x10; |
6639 | else | |
6640 | status = 0x8; | |
2e0fef85 | 6641 | if (phba->pport->fc_flag & FC_FABRIC) |
7bb3b137 JW |
6642 | status |= 0x4; |
6643 | ||
6644 | rps_rsp->rsvd1 = 0; | |
09372820 JS |
6645 | rps_rsp->portStatus = cpu_to_be16(status); |
6646 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | |
6647 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | |
6648 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | |
6649 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | |
6650 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | |
6651 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | |
7bb3b137 | 6652 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
6653 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
6654 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " | |
6655 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
6656 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6657 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6658 | ndlp->nlp_rpi); | |
858c9f6c | 6659 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 | 6660 | phba->fc_stat.elsXmitACC++; |
3772a991 | 6661 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
7bb3b137 | 6662 | lpfc_els_free_iocb(phba, elsiocb); |
7bb3b137 JW |
6663 | return; |
6664 | } | |
6665 | ||
e59058c4 | 6666 | /** |
12265f68 JS |
6667 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
6668 | * @vport: pointer to a host virtual N_Port data structure. | |
6669 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6670 | * @ndlp: pointer to a node-list data structure. | |
6671 | * | |
6672 | * This routine processes Read Port Status (RPL) IOCB received as an | |
6673 | * ELS unsolicited event. It first checks the remote port state. If the | |
6674 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6675 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | |
6676 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | |
6677 | * for reading the HBA link statistics. It is for the callback function, | |
6678 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command | |
6679 | * to actually sending out RPL Accept (ACC) response. | |
6680 | * | |
6681 | * Return codes | |
6682 | * 0 - Successfully processed rls iocb (currently always return 0) | |
6683 | **/ | |
6684 | static int | |
6685 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6686 | struct lpfc_nodelist *ndlp) | |
6687 | { | |
6688 | struct lpfc_hba *phba = vport->phba; | |
6689 | LPFC_MBOXQ_t *mbox; | |
12265f68 JS |
6690 | struct ls_rjt stat; |
6691 | ||
6692 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | |
6693 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | |
6694 | /* reject the unsolicited RPS request and done with it */ | |
6695 | goto reject_out; | |
6696 | ||
12265f68 JS |
6697 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
6698 | if (mbox) { | |
6699 | lpfc_read_lnk_stat(phba, mbox); | |
7851fe2c JS |
6700 | mbox->context1 = (void *)((unsigned long) |
6701 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | |
6702 | cmdiocb->iocb.ulpContext)); /* rx_id */ | |
12265f68 JS |
6703 | mbox->context2 = lpfc_nlp_get(ndlp); |
6704 | mbox->vport = vport; | |
6705 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; | |
6706 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | |
6707 | != MBX_NOT_FINISHED) | |
6708 | /* Mbox completion will send ELS Response */ | |
6709 | return 0; | |
6710 | /* Decrement reference count used for the failed mbox | |
6711 | * command. | |
6712 | */ | |
6713 | lpfc_nlp_put(ndlp); | |
6714 | mempool_free(mbox, phba->mbox_mem_pool); | |
6715 | } | |
6716 | reject_out: | |
6717 | /* issue rejection response */ | |
6718 | stat.un.b.lsRjtRsvd0 = 0; | |
6719 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6720 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6721 | stat.un.b.vendorUnique = 0; | |
6722 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
6723 | return 0; | |
6724 | } | |
6725 | ||
6726 | /** | |
6727 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb | |
6728 | * @vport: pointer to a host virtual N_Port data structure. | |
6729 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6730 | * @ndlp: pointer to a node-list data structure. | |
6731 | * | |
6732 | * This routine processes Read Timout Value (RTV) IOCB received as an | |
6733 | * ELS unsolicited event. It first checks the remote port state. If the | |
6734 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6735 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | |
6736 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout | |
6737 | * Value (RTV) unsolicited IOCB event. | |
6738 | * | |
6739 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6740 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6741 | * will be stored into the context1 field of the IOCB for the completion | |
6742 | * callback function to the RPS Accept Response ELS IOCB command. | |
6743 | * | |
6744 | * Return codes | |
6745 | * 0 - Successfully processed rtv iocb (currently always return 0) | |
6746 | **/ | |
6747 | static int | |
6748 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6749 | struct lpfc_nodelist *ndlp) | |
6750 | { | |
6751 | struct lpfc_hba *phba = vport->phba; | |
6752 | struct ls_rjt stat; | |
6753 | struct RTV_RSP *rtv_rsp; | |
6754 | uint8_t *pcmd; | |
6755 | struct lpfc_iocbq *elsiocb; | |
6756 | uint32_t cmdsize; | |
6757 | ||
6758 | ||
6759 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | |
6760 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | |
6761 | /* reject the unsolicited RPS request and done with it */ | |
6762 | goto reject_out; | |
6763 | ||
6764 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); | |
6765 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
6766 | lpfc_max_els_tries, ndlp, | |
6767 | ndlp->nlp_DID, ELS_CMD_ACC); | |
6768 | ||
6769 | if (!elsiocb) | |
6770 | return 1; | |
6771 | ||
6772 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6773 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
6774 | pcmd += sizeof(uint32_t); /* Skip past command */ | |
6775 | ||
6776 | /* use the command's xri in the response */ | |
7851fe2c JS |
6777 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
6778 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; | |
12265f68 JS |
6779 | |
6780 | rtv_rsp = (struct RTV_RSP *)pcmd; | |
6781 | ||
6782 | /* populate RTV payload */ | |
6783 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ | |
6784 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); | |
6785 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); | |
6786 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ | |
6787 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); | |
6788 | ||
6789 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ | |
6790 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | |
6791 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " | |
6792 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " | |
6793 | "Data: x%x x%x x%x\n", | |
6794 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6795 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6796 | ndlp->nlp_rpi, | |
6797 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); | |
6798 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
6799 | phba->fc_stat.elsXmitACC++; | |
6800 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | |
6801 | lpfc_els_free_iocb(phba, elsiocb); | |
6802 | return 0; | |
6803 | ||
6804 | reject_out: | |
6805 | /* issue rejection response */ | |
6806 | stat.un.b.lsRjtRsvd0 = 0; | |
6807 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6808 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6809 | stat.un.b.vendorUnique = 0; | |
6810 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
6811 | return 0; | |
6812 | } | |
6813 | ||
6814 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb | |
e59058c4 JS |
6815 | * @vport: pointer to a host virtual N_Port data structure. |
6816 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6817 | * @ndlp: pointer to a node-list data structure. | |
6818 | * | |
6819 | * This routine processes Read Port Status (RPS) IOCB received as an | |
6820 | * ELS unsolicited event. It first checks the remote port state. If the | |
6821 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6822 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject | |
6823 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | |
6824 | * for reading the HBA link statistics. It is for the callback function, | |
6825 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command | |
6826 | * to actually sending out RPS Accept (ACC) response. | |
6827 | * | |
6828 | * Return codes | |
6829 | * 0 - Successfully processed rps iocb (currently always return 0) | |
6830 | **/ | |
7bb3b137 | 6831 | static int |
2e0fef85 JS |
6832 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6833 | struct lpfc_nodelist *ndlp) | |
dea3101e | 6834 | { |
2e0fef85 | 6835 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 6836 | uint32_t *lp; |
7bb3b137 JW |
6837 | uint8_t flag; |
6838 | LPFC_MBOXQ_t *mbox; | |
6839 | struct lpfc_dmabuf *pcmd; | |
6840 | RPS *rps; | |
6841 | struct ls_rjt stat; | |
6842 | ||
2fe165b6 | 6843 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
90160e01 JS |
6844 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
6845 | /* reject the unsolicited RPS request and done with it */ | |
6846 | goto reject_out; | |
7bb3b137 JW |
6847 | |
6848 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
6849 | lp = (uint32_t *) pcmd->virt; | |
6850 | flag = (be32_to_cpu(*lp++) & 0xf); | |
6851 | rps = (RPS *) lp; | |
6852 | ||
6853 | if ((flag == 0) || | |
6854 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || | |
2e0fef85 | 6855 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
92d7f7b0 | 6856 | sizeof(struct lpfc_name)) == 0))) { |
2e0fef85 | 6857 | |
92d7f7b0 JS |
6858 | printk("Fix me....\n"); |
6859 | dump_stack(); | |
2e0fef85 JS |
6860 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
6861 | if (mbox) { | |
7bb3b137 | 6862 | lpfc_read_lnk_stat(phba, mbox); |
7851fe2c JS |
6863 | mbox->context1 = (void *)((unsigned long) |
6864 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | |
6865 | cmdiocb->iocb.ulpContext)); /* rx_id */ | |
329f9bc7 | 6866 | mbox->context2 = lpfc_nlp_get(ndlp); |
92d7f7b0 | 6867 | mbox->vport = vport; |
7bb3b137 | 6868 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
fa4066b6 | 6869 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
0b727fea | 6870 | != MBX_NOT_FINISHED) |
7bb3b137 JW |
6871 | /* Mbox completion will send ELS Response */ |
6872 | return 0; | |
fa4066b6 JS |
6873 | /* Decrement reference count used for the failed mbox |
6874 | * command. | |
6875 | */ | |
329f9bc7 | 6876 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
6877 | mempool_free(mbox, phba->mbox_mem_pool); |
6878 | } | |
6879 | } | |
90160e01 JS |
6880 | |
6881 | reject_out: | |
6882 | /* issue rejection response */ | |
7bb3b137 JW |
6883 | stat.un.b.lsRjtRsvd0 = 0; |
6884 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6885 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6886 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 6887 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
6888 | return 0; |
6889 | } | |
6890 | ||
19ca7609 JS |
6891 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
6892 | * @vport: pointer to a host virtual N_Port data structure. | |
6893 | * @ndlp: pointer to a node-list data structure. | |
6894 | * @did: DID of the target. | |
6895 | * @rrq: Pointer to the rrq struct. | |
6896 | * | |
6897 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is | |
6898 | * Successful the the completion handler will clear the RRQ. | |
6899 | * | |
6900 | * Return codes | |
6901 | * 0 - Successfully sent rrq els iocb. | |
6902 | * 1 - Failed to send rrq els iocb. | |
6903 | **/ | |
6904 | static int | |
6905 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
6906 | uint32_t did, struct lpfc_node_rrq *rrq) | |
6907 | { | |
6908 | struct lpfc_hba *phba = vport->phba; | |
6909 | struct RRQ *els_rrq; | |
19ca7609 JS |
6910 | struct lpfc_iocbq *elsiocb; |
6911 | uint8_t *pcmd; | |
6912 | uint16_t cmdsize; | |
6913 | int ret; | |
6914 | ||
6915 | ||
6916 | if (ndlp != rrq->ndlp) | |
6917 | ndlp = rrq->ndlp; | |
6918 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
6919 | return 1; | |
6920 | ||
6921 | /* If ndlp is not NULL, we will bump the reference count on it */ | |
6922 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); | |
6923 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, | |
6924 | ELS_CMD_RRQ); | |
6925 | if (!elsiocb) | |
6926 | return 1; | |
6927 | ||
19ca7609 JS |
6928 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
6929 | ||
6930 | /* For RRQ request, remainder of payload is Exchange IDs */ | |
6931 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; | |
6932 | pcmd += sizeof(uint32_t); | |
6933 | els_rrq = (struct RRQ *) pcmd; | |
6934 | ||
ee0f4fe1 | 6935 | bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); |
19ca7609 JS |
6936 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
6937 | bf_set(rrq_did, els_rrq, vport->fc_myDID); | |
6938 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); | |
6939 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); | |
6940 | ||
6941 | ||
6942 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
6943 | "Issue RRQ: did:x%x", | |
6944 | did, rrq->xritag, rrq->rxid); | |
6945 | elsiocb->context_un.rrq = rrq; | |
6946 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; | |
6947 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
6948 | ||
6949 | if (ret == IOCB_ERROR) { | |
6950 | lpfc_els_free_iocb(phba, elsiocb); | |
6951 | return 1; | |
6952 | } | |
6953 | return 0; | |
6954 | } | |
6955 | ||
6956 | /** | |
6957 | * lpfc_send_rrq - Sends ELS RRQ if needed. | |
6958 | * @phba: pointer to lpfc hba data structure. | |
6959 | * @rrq: pointer to the active rrq. | |
6960 | * | |
6961 | * This routine will call the lpfc_issue_els_rrq if the rrq is | |
6962 | * still active for the xri. If this function returns a failure then | |
6963 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. | |
6964 | * | |
6965 | * Returns 0 Success. | |
6966 | * 1 Failure. | |
6967 | **/ | |
6968 | int | |
6969 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) | |
6970 | { | |
6971 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, | |
6972 | rrq->nlp_DID); | |
6973 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) | |
6974 | return lpfc_issue_els_rrq(rrq->vport, ndlp, | |
6975 | rrq->nlp_DID, rrq); | |
6976 | else | |
6977 | return 1; | |
6978 | } | |
6979 | ||
e59058c4 | 6980 | /** |
3621a710 | 6981 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
e59058c4 JS |
6982 | * @vport: pointer to a host virtual N_Port data structure. |
6983 | * @cmdsize: size of the ELS command. | |
6984 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
6985 | * @ndlp: pointer to a node-list data structure. | |
6986 | * | |
6987 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. | |
6988 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. | |
6989 | * | |
6990 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6991 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6992 | * will be stored into the context1 field of the IOCB for the completion | |
6993 | * callback function to the RPL Accept Response ELS command. | |
6994 | * | |
6995 | * Return code | |
6996 | * 0 - Successfully issued ACC RPL ELS command | |
6997 | * 1 - Failed to issue ACC RPL ELS command | |
6998 | **/ | |
082c0266 | 6999 | static int |
2e0fef85 JS |
7000 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
7001 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | |
7bb3b137 | 7002 | { |
2e0fef85 JS |
7003 | struct lpfc_hba *phba = vport->phba; |
7004 | IOCB_t *icmd, *oldcmd; | |
7bb3b137 JW |
7005 | RPL_RSP rpl_rsp; |
7006 | struct lpfc_iocbq *elsiocb; | |
7bb3b137 | 7007 | uint8_t *pcmd; |
dea3101e | 7008 | |
2e0fef85 JS |
7009 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
7010 | ndlp->nlp_DID, ELS_CMD_ACC); | |
7bb3b137 | 7011 | |
488d1469 | 7012 | if (!elsiocb) |
7bb3b137 | 7013 | return 1; |
488d1469 | 7014 | |
7bb3b137 JW |
7015 | icmd = &elsiocb->iocb; |
7016 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
7017 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
7018 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
7bb3b137 JW |
7019 | |
7020 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
7021 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 7022 | pcmd += sizeof(uint16_t); |
7bb3b137 JW |
7023 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
7024 | pcmd += sizeof(uint16_t); | |
7025 | ||
7026 | /* Setup the RPL ACC payload */ | |
7027 | rpl_rsp.listLen = be32_to_cpu(1); | |
7028 | rpl_rsp.index = 0; | |
7029 | rpl_rsp.port_num_blk.portNum = 0; | |
2e0fef85 JS |
7030 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
7031 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, | |
7bb3b137 | 7032 | sizeof(struct lpfc_name)); |
7bb3b137 | 7033 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
7bb3b137 | 7034 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
e8b62011 JS |
7035 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
7036 | "0120 Xmit ELS RPL ACC response tag x%x " | |
7037 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
7038 | "rpi x%x\n", | |
7039 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
7040 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
7041 | ndlp->nlp_rpi); | |
858c9f6c | 7042 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 | 7043 | phba->fc_stat.elsXmitACC++; |
3772a991 JS |
7044 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
7045 | IOCB_ERROR) { | |
7bb3b137 JW |
7046 | lpfc_els_free_iocb(phba, elsiocb); |
7047 | return 1; | |
7048 | } | |
7049 | return 0; | |
7050 | } | |
7051 | ||
e59058c4 | 7052 | /** |
3621a710 | 7053 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
e59058c4 JS |
7054 | * @vport: pointer to a host virtual N_Port data structure. |
7055 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
7056 | * @ndlp: pointer to a node-list data structure. | |
7057 | * | |
7058 | * This routine processes Read Port List (RPL) IOCB received as an ELS | |
7059 | * unsolicited event. It first checks the remote port state. If the remote | |
7060 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it | |
7061 | * invokes the lpfc_els_rsp_reject() routine to send reject response. | |
7062 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine | |
7063 | * to accept the RPL. | |
7064 | * | |
7065 | * Return code | |
7066 | * 0 - Successfully processed rpl iocb (currently always return 0) | |
7067 | **/ | |
7bb3b137 | 7068 | static int |
2e0fef85 JS |
7069 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
7070 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
7071 | { |
7072 | struct lpfc_dmabuf *pcmd; | |
7073 | uint32_t *lp; | |
7074 | uint32_t maxsize; | |
7075 | uint16_t cmdsize; | |
7076 | RPL *rpl; | |
7077 | struct ls_rjt stat; | |
7078 | ||
2fe165b6 JW |
7079 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
7080 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | |
90160e01 | 7081 | /* issue rejection response */ |
7bb3b137 JW |
7082 | stat.un.b.lsRjtRsvd0 = 0; |
7083 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
7084 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
7085 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
7086 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
7087 | NULL); | |
90160e01 JS |
7088 | /* rejected the unsolicited RPL request and done with it */ |
7089 | return 0; | |
7bb3b137 JW |
7090 | } |
7091 | ||
dea3101e JB |
7092 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
7093 | lp = (uint32_t *) pcmd->virt; | |
7bb3b137 | 7094 | rpl = (RPL *) (lp + 1); |
7bb3b137 | 7095 | maxsize = be32_to_cpu(rpl->maxsize); |
dea3101e | 7096 | |
7bb3b137 JW |
7097 | /* We support only one port */ |
7098 | if ((rpl->index == 0) && | |
7099 | ((maxsize == 0) || | |
7100 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { | |
7101 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); | |
2fe165b6 | 7102 | } else { |
7bb3b137 JW |
7103 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
7104 | } | |
2e0fef85 | 7105 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
dea3101e JB |
7106 | |
7107 | return 0; | |
7108 | } | |
7109 | ||
e59058c4 | 7110 | /** |
3621a710 | 7111 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
e59058c4 JS |
7112 | * @vport: pointer to a virtual N_Port data structure. |
7113 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
7114 | * @ndlp: pointer to a node-list data structure. | |
7115 | * | |
7116 | * This routine processes Fibre Channel Address Resolution Protocol | |
7117 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, | |
7118 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, | |
7119 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the | |
7120 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the | |
7121 | * remote PortName is compared against the FC PortName stored in the @vport | |
7122 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is | |
7123 | * compared against the FC NodeName stored in the @vport data structure. | |
7124 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the | |
7125 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is | |
7126 | * invoked to send out FARP Response to the remote node. Before sending the | |
7127 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP | |
7128 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() | |
7129 | * routine is invoked to log into the remote port first. | |
7130 | * | |
7131 | * Return code | |
7132 | * 0 - Either the FARP Match Mode not supported or successfully processed | |
7133 | **/ | |
dea3101e | 7134 | static int |
2e0fef85 JS |
7135 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
7136 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
7137 | { |
7138 | struct lpfc_dmabuf *pcmd; | |
7139 | uint32_t *lp; | |
7140 | IOCB_t *icmd; | |
7141 | FARP *fp; | |
7142 | uint32_t cmd, cnt, did; | |
7143 | ||
7144 | icmd = &cmdiocb->iocb; | |
7145 | did = icmd->un.elsreq64.remoteID; | |
7146 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
7147 | lp = (uint32_t *) pcmd->virt; | |
7148 | ||
7149 | cmd = *lp++; | |
7150 | fp = (FARP *) lp; | |
dea3101e | 7151 | /* FARP-REQ received from DID <did> */ |
e8b62011 JS |
7152 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
7153 | "0601 FARP-REQ received from DID x%x\n", did); | |
dea3101e JB |
7154 | /* We will only support match on WWPN or WWNN */ |
7155 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { | |
c9f8735b | 7156 | return 0; |
dea3101e JB |
7157 | } |
7158 | ||
7159 | cnt = 0; | |
7160 | /* If this FARP command is searching for my portname */ | |
7161 | if (fp->Mflags & FARP_MATCH_PORT) { | |
2e0fef85 | 7162 | if (memcmp(&fp->RportName, &vport->fc_portname, |
92d7f7b0 | 7163 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
7164 | cnt = 1; |
7165 | } | |
7166 | ||
7167 | /* If this FARP command is searching for my nodename */ | |
7168 | if (fp->Mflags & FARP_MATCH_NODE) { | |
2e0fef85 | 7169 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
92d7f7b0 | 7170 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
7171 | cnt = 1; |
7172 | } | |
7173 | ||
7174 | if (cnt) { | |
7175 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | |
7176 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { | |
7177 | /* Log back into the node before sending the FARP. */ | |
7178 | if (fp->Rflags & FARP_REQUEST_PLOGI) { | |
5024ab17 | 7179 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 7180 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 7181 | NLP_STE_PLOGI_ISSUE); |
2e0fef85 | 7182 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
dea3101e JB |
7183 | } |
7184 | ||
7185 | /* Send a FARP response to that node */ | |
2e0fef85 JS |
7186 | if (fp->Rflags & FARP_REQUEST_FARPR) |
7187 | lpfc_issue_els_farpr(vport, did, 0); | |
dea3101e JB |
7188 | } |
7189 | } | |
c9f8735b | 7190 | return 0; |
dea3101e JB |
7191 | } |
7192 | ||
e59058c4 | 7193 | /** |
3621a710 | 7194 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
e59058c4 JS |
7195 | * @vport: pointer to a host virtual N_Port data structure. |
7196 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
7197 | * @ndlp: pointer to a node-list data structure. | |
7198 | * | |
7199 | * This routine processes Fibre Channel Address Resolution Protocol | |
7200 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply | |
7201 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept | |
7202 | * the FARP response request. | |
7203 | * | |
7204 | * Return code | |
7205 | * 0 - Successfully processed FARPR IOCB (currently always return 0) | |
7206 | **/ | |
dea3101e | 7207 | static int |
2e0fef85 JS |
7208 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
7209 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
7210 | { |
7211 | struct lpfc_dmabuf *pcmd; | |
7212 | uint32_t *lp; | |
7213 | IOCB_t *icmd; | |
7214 | uint32_t cmd, did; | |
7215 | ||
7216 | icmd = &cmdiocb->iocb; | |
7217 | did = icmd->un.elsreq64.remoteID; | |
7218 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
7219 | lp = (uint32_t *) pcmd->virt; | |
7220 | ||
7221 | cmd = *lp++; | |
7222 | /* FARP-RSP received from DID <did> */ | |
e8b62011 JS |
7223 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
7224 | "0600 FARP-RSP received from DID x%x\n", did); | |
dea3101e | 7225 | /* ACCEPT the Farp resp request */ |
51ef4c26 | 7226 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e JB |
7227 | |
7228 | return 0; | |
7229 | } | |
7230 | ||
e59058c4 | 7231 | /** |
3621a710 | 7232 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
e59058c4 JS |
7233 | * @vport: pointer to a host virtual N_Port data structure. |
7234 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
7235 | * @fan_ndlp: pointer to a node-list data structure. | |
7236 | * | |
7237 | * This routine processes a Fabric Address Notification (FAN) IOCB | |
7238 | * command received as an ELS unsolicited event. The FAN ELS command will | |
7239 | * only be processed on a physical port (i.e., the @vport represents the | |
7240 | * physical port). The fabric NodeName and PortName from the FAN IOCB are | |
7241 | * compared against those in the phba data structure. If any of those is | |
7242 | * different, the lpfc_initial_flogi() routine is invoked to initialize | |
7243 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, | |
7244 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine | |
7245 | * is invoked to register login to the fabric. | |
7246 | * | |
7247 | * Return code | |
7248 | * 0 - Successfully processed fan iocb (currently always return 0). | |
7249 | **/ | |
dea3101e | 7250 | static int |
2e0fef85 JS |
7251 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
7252 | struct lpfc_nodelist *fan_ndlp) | |
dea3101e | 7253 | { |
0d2b6b83 | 7254 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 7255 | uint32_t *lp; |
5024ab17 | 7256 | FAN *fp; |
dea3101e | 7257 | |
0d2b6b83 JS |
7258 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
7259 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; | |
7260 | fp = (FAN *) ++lp; | |
5024ab17 | 7261 | /* FAN received; Fan does not have a reply sequence */ |
0d2b6b83 JS |
7262 | if ((vport == phba->pport) && |
7263 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { | |
5024ab17 | 7264 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
0d2b6b83 | 7265 | sizeof(struct lpfc_name))) || |
5024ab17 | 7266 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
0d2b6b83 JS |
7267 | sizeof(struct lpfc_name)))) { |
7268 | /* This port has switched fabrics. FLOGI is required */ | |
76a95d75 | 7269 | lpfc_issue_init_vfi(vport); |
0d2b6b83 JS |
7270 | } else { |
7271 | /* FAN verified - skip FLOGI */ | |
7272 | vport->fc_myDID = vport->fc_prevDID; | |
6fb120a7 JS |
7273 | if (phba->sli_rev < LPFC_SLI_REV4) |
7274 | lpfc_issue_fabric_reglogin(vport); | |
1b51197d JS |
7275 | else { |
7276 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
7277 | "3138 Need register VFI: (x%x/%x)\n", | |
7278 | vport->fc_prevDID, vport->fc_myDID); | |
6fb120a7 | 7279 | lpfc_issue_reg_vfi(vport); |
1b51197d | 7280 | } |
5024ab17 | 7281 | } |
dea3101e | 7282 | } |
c9f8735b | 7283 | return 0; |
dea3101e JB |
7284 | } |
7285 | ||
e59058c4 | 7286 | /** |
3621a710 | 7287 | * lpfc_els_timeout - Handler funciton to the els timer |
e59058c4 JS |
7288 | * @ptr: holder for the timer function associated data. |
7289 | * | |
7290 | * This routine is invoked by the ELS timer after timeout. It posts the ELS | |
7291 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port | |
7292 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake | |
7293 | * up the worker thread. It is for the worker thread to invoke the routine | |
7294 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. | |
7295 | **/ | |
dea3101e JB |
7296 | void |
7297 | lpfc_els_timeout(unsigned long ptr) | |
7298 | { | |
2e0fef85 JS |
7299 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
7300 | struct lpfc_hba *phba = vport->phba; | |
5e9d9b82 | 7301 | uint32_t tmo_posted; |
dea3101e JB |
7302 | unsigned long iflag; |
7303 | ||
2e0fef85 | 7304 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
5e9d9b82 | 7305 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
06918ac5 | 7306 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
2e0fef85 | 7307 | vport->work_port_events |= WORKER_ELS_TMO; |
5e9d9b82 | 7308 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
92d7f7b0 | 7309 | |
06918ac5 | 7310 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
5e9d9b82 | 7311 | lpfc_worker_wake_up(phba); |
dea3101e JB |
7312 | return; |
7313 | } | |
7314 | ||
2a9bf3d0 | 7315 | |
e59058c4 | 7316 | /** |
3621a710 | 7317 | * lpfc_els_timeout_handler - Process an els timeout event |
e59058c4 JS |
7318 | * @vport: pointer to a virtual N_Port data structure. |
7319 | * | |
7320 | * This routine is the actual handler function that processes an ELS timeout | |
7321 | * event. It walks the ELS ring to get and abort all the IOCBs (except the | |
7322 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by | |
7323 | * invoking the lpfc_sli_issue_abort_iotag() routine. | |
7324 | **/ | |
dea3101e | 7325 | void |
2e0fef85 | 7326 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
dea3101e | 7327 | { |
2e0fef85 | 7328 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
7329 | struct lpfc_sli_ring *pring; |
7330 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
7331 | IOCB_t *cmd = NULL; | |
7332 | struct lpfc_dmabuf *pcmd; | |
2e0fef85 | 7333 | uint32_t els_command = 0; |
dea3101e | 7334 | uint32_t timeout; |
2e0fef85 | 7335 | uint32_t remote_ID = 0xffffffff; |
2a9bf3d0 JS |
7336 | LIST_HEAD(abort_list); |
7337 | ||
dea3101e | 7338 | |
dea3101e JB |
7339 | timeout = (uint32_t)(phba->fc_ratov << 1); |
7340 | ||
895427bd JS |
7341 | pring = lpfc_phba_elsring(phba); |
7342 | ||
06918ac5 JS |
7343 | if ((phba->pport->load_flag & FC_UNLOADING)) |
7344 | return; | |
2a9bf3d0 | 7345 | spin_lock_irq(&phba->hbalock); |
0976e1a6 JS |
7346 | if (phba->sli_rev == LPFC_SLI_REV4) |
7347 | spin_lock(&pring->ring_lock); | |
2a9bf3d0 | 7348 | |
06918ac5 JS |
7349 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
7350 | if (phba->sli_rev == LPFC_SLI_REV4) | |
7351 | spin_unlock(&pring->ring_lock); | |
7352 | spin_unlock_irq(&phba->hbalock); | |
7353 | return; | |
7354 | } | |
7355 | ||
0976e1a6 | 7356 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
dea3101e JB |
7357 | cmd = &piocb->iocb; |
7358 | ||
2e0fef85 JS |
7359 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
7360 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
7361 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | |
dea3101e | 7362 | continue; |
2e0fef85 JS |
7363 | |
7364 | if (piocb->vport != vport) | |
7365 | continue; | |
7366 | ||
dea3101e | 7367 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
2e0fef85 JS |
7368 | if (pcmd) |
7369 | els_command = *(uint32_t *) (pcmd->virt); | |
dea3101e | 7370 | |
92d7f7b0 JS |
7371 | if (els_command == ELS_CMD_FARP || |
7372 | els_command == ELS_CMD_FARPR || | |
7373 | els_command == ELS_CMD_FDISC) | |
7374 | continue; | |
7375 | ||
dea3101e | 7376 | if (piocb->drvrTimeout > 0) { |
92d7f7b0 | 7377 | if (piocb->drvrTimeout >= timeout) |
dea3101e | 7378 | piocb->drvrTimeout -= timeout; |
92d7f7b0 | 7379 | else |
dea3101e | 7380 | piocb->drvrTimeout = 0; |
dea3101e JB |
7381 | continue; |
7382 | } | |
7383 | ||
2e0fef85 JS |
7384 | remote_ID = 0xffffffff; |
7385 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) | |
dea3101e | 7386 | remote_ID = cmd->un.elsreq64.remoteID; |
2e0fef85 JS |
7387 | else { |
7388 | struct lpfc_nodelist *ndlp; | |
7389 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); | |
58da1ffb | 7390 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
2e0fef85 | 7391 | remote_ID = ndlp->nlp_DID; |
dea3101e | 7392 | } |
2a9bf3d0 JS |
7393 | list_add_tail(&piocb->dlist, &abort_list); |
7394 | } | |
0976e1a6 JS |
7395 | if (phba->sli_rev == LPFC_SLI_REV4) |
7396 | spin_unlock(&pring->ring_lock); | |
2a9bf3d0 JS |
7397 | spin_unlock_irq(&phba->hbalock); |
7398 | ||
7399 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { | |
15026c9e | 7400 | cmd = &piocb->iocb; |
e8b62011 | 7401 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2a9bf3d0 JS |
7402 | "0127 ELS timeout Data: x%x x%x x%x " |
7403 | "x%x\n", els_command, | |
7404 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); | |
7405 | spin_lock_irq(&phba->hbalock); | |
7406 | list_del_init(&piocb->dlist); | |
07951076 | 7407 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
2a9bf3d0 | 7408 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7409 | } |
5a0e326d | 7410 | |
895427bd | 7411 | if (!list_empty(&pring->txcmplq)) |
06918ac5 JS |
7412 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
7413 | mod_timer(&vport->els_tmofunc, | |
7414 | jiffies + msecs_to_jiffies(1000 * timeout)); | |
dea3101e JB |
7415 | } |
7416 | ||
e59058c4 | 7417 | /** |
3621a710 | 7418 | * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport |
e59058c4 JS |
7419 | * @vport: pointer to a host virtual N_Port data structure. |
7420 | * | |
7421 | * This routine is used to clean up all the outstanding ELS commands on a | |
7422 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() | |
7423 | * routine. After that, it walks the ELS transmit queue to remove all the | |
7424 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For | |
7425 | * the IOCBs with a non-NULL completion callback function, the callback | |
7426 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | |
7427 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion | |
7428 | * callback function, the IOCB will simply be released. Finally, it walks | |
7429 | * the ELS transmit completion queue to issue an abort IOCB to any transmit | |
7430 | * completion queue IOCB that is associated with the @vport and is not | |
7431 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not | |
7432 | * part of the discovery state machine) out to HBA by invoking the | |
7433 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the | |
7434 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee | |
7435 | * the IOCBs are aborted when this function returns. | |
7436 | **/ | |
dea3101e | 7437 | void |
2e0fef85 | 7438 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
dea3101e | 7439 | { |
0976e1a6 | 7440 | LIST_HEAD(abort_list); |
2e0fef85 | 7441 | struct lpfc_hba *phba = vport->phba; |
895427bd | 7442 | struct lpfc_sli_ring *pring; |
dea3101e JB |
7443 | struct lpfc_iocbq *tmp_iocb, *piocb; |
7444 | IOCB_t *cmd = NULL; | |
92d7f7b0 JS |
7445 | |
7446 | lpfc_fabric_abort_vport(vport); | |
0976e1a6 JS |
7447 | /* |
7448 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate | |
7449 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag | |
7450 | * ultimately grabs the ring_lock, the driver must splice the list into | |
7451 | * a working list and release the locks before calling the abort. | |
7452 | */ | |
7453 | spin_lock_irq(&phba->hbalock); | |
895427bd | 7454 | pring = lpfc_phba_elsring(phba); |
0976e1a6 JS |
7455 | if (phba->sli_rev == LPFC_SLI_REV4) |
7456 | spin_lock(&pring->ring_lock); | |
7457 | ||
7458 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | |
7459 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | |
7460 | continue; | |
7461 | ||
7462 | if (piocb->vport != vport) | |
7463 | continue; | |
7464 | list_add_tail(&piocb->dlist, &abort_list); | |
7465 | } | |
7466 | if (phba->sli_rev == LPFC_SLI_REV4) | |
7467 | spin_unlock(&pring->ring_lock); | |
7468 | spin_unlock_irq(&phba->hbalock); | |
7469 | /* Abort each iocb on the aborted list and remove the dlist links. */ | |
7470 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { | |
7471 | spin_lock_irq(&phba->hbalock); | |
7472 | list_del_init(&piocb->dlist); | |
7473 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | |
7474 | spin_unlock_irq(&phba->hbalock); | |
7475 | } | |
7476 | if (!list_empty(&abort_list)) | |
7477 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7478 | "3387 abort list for txq not empty\n"); | |
7479 | INIT_LIST_HEAD(&abort_list); | |
dea3101e | 7480 | |
2e0fef85 | 7481 | spin_lock_irq(&phba->hbalock); |
0976e1a6 JS |
7482 | if (phba->sli_rev == LPFC_SLI_REV4) |
7483 | spin_lock(&pring->ring_lock); | |
7484 | ||
dea3101e JB |
7485 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
7486 | cmd = &piocb->iocb; | |
7487 | ||
7488 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | |
7489 | continue; | |
7490 | } | |
7491 | ||
7492 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | |
329f9bc7 JS |
7493 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
7494 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | |
7495 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
7496 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | |
dea3101e | 7497 | continue; |
dea3101e | 7498 | |
2e0fef85 JS |
7499 | if (piocb->vport != vport) |
7500 | continue; | |
7501 | ||
0976e1a6 JS |
7502 | list_del_init(&piocb->list); |
7503 | list_add_tail(&piocb->list, &abort_list); | |
dea3101e | 7504 | } |
0976e1a6 JS |
7505 | if (phba->sli_rev == LPFC_SLI_REV4) |
7506 | spin_unlock(&pring->ring_lock); | |
2e0fef85 | 7507 | spin_unlock_irq(&phba->hbalock); |
2534ba75 | 7508 | |
a257bf90 | 7509 | /* Cancell all the IOCBs from the completions list */ |
0976e1a6 JS |
7510 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
7511 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); | |
2534ba75 | 7512 | |
dea3101e JB |
7513 | return; |
7514 | } | |
7515 | ||
e59058c4 | 7516 | /** |
3621a710 | 7517 | * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA |
e59058c4 JS |
7518 | * @phba: pointer to lpfc hba data structure. |
7519 | * | |
7520 | * This routine is used to clean up all the outstanding ELS commands on a | |
7521 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() | |
7522 | * routine. After that, it walks the ELS transmit queue to remove all the | |
7523 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For | |
7524 | * the IOCBs with the completion callback function associated, the callback | |
7525 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | |
7526 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion | |
7527 | * callback function associated, the IOCB will simply be released. Finally, | |
7528 | * it walks the ELS transmit completion queue to issue an abort IOCB to any | |
7529 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the | |
7530 | * management plane IOCBs that are not part of the discovery state machine) | |
7531 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. | |
7532 | **/ | |
549e55cd JS |
7533 | void |
7534 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) | |
7535 | { | |
0976e1a6 JS |
7536 | struct lpfc_vport *vport; |
7537 | list_for_each_entry(vport, &phba->port_list, listentry) | |
7538 | lpfc_els_flush_cmd(vport); | |
a257bf90 | 7539 | |
549e55cd JS |
7540 | return; |
7541 | } | |
7542 | ||
ea2151b4 | 7543 | /** |
3621a710 | 7544 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
ea2151b4 JS |
7545 | * @phba: Pointer to hba context object. |
7546 | * @cmdiocbp: Pointer to command iocb which reported error. | |
7547 | * @rspiocbp: Pointer to response iocb which reported error. | |
7548 | * | |
7549 | * This function sends an event when there is an ELS command | |
7550 | * failure. | |
7551 | **/ | |
7552 | void | |
7553 | lpfc_send_els_failure_event(struct lpfc_hba *phba, | |
7554 | struct lpfc_iocbq *cmdiocbp, | |
7555 | struct lpfc_iocbq *rspiocbp) | |
7556 | { | |
7557 | struct lpfc_vport *vport = cmdiocbp->vport; | |
7558 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7559 | struct lpfc_lsrjt_event lsrjt_event; | |
7560 | struct lpfc_fabric_event_header fabric_event; | |
7561 | struct ls_rjt stat; | |
7562 | struct lpfc_nodelist *ndlp; | |
7563 | uint32_t *pcmd; | |
7564 | ||
7565 | ndlp = cmdiocbp->context1; | |
7566 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
7567 | return; | |
7568 | ||
7569 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { | |
7570 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; | |
7571 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; | |
7572 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, | |
7573 | sizeof(struct lpfc_name)); | |
7574 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, | |
7575 | sizeof(struct lpfc_name)); | |
7576 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) | |
7577 | cmdiocbp->context2)->virt); | |
49198b37 | 7578 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
ea2151b4 JS |
7579 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
7580 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; | |
7581 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; | |
7582 | fc_host_post_vendor_event(shost, | |
7583 | fc_get_event_number(), | |
7584 | sizeof(lsrjt_event), | |
7585 | (char *)&lsrjt_event, | |
ddcc50f0 | 7586 | LPFC_NL_VENDOR_ID); |
ea2151b4 JS |
7587 | return; |
7588 | } | |
7589 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || | |
7590 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { | |
7591 | fabric_event.event_type = FC_REG_FABRIC_EVENT; | |
7592 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) | |
7593 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; | |
7594 | else | |
7595 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; | |
7596 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, | |
7597 | sizeof(struct lpfc_name)); | |
7598 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, | |
7599 | sizeof(struct lpfc_name)); | |
7600 | fc_host_post_vendor_event(shost, | |
7601 | fc_get_event_number(), | |
7602 | sizeof(fabric_event), | |
7603 | (char *)&fabric_event, | |
ddcc50f0 | 7604 | LPFC_NL_VENDOR_ID); |
ea2151b4 JS |
7605 | return; |
7606 | } | |
7607 | ||
7608 | } | |
7609 | ||
7610 | /** | |
3621a710 | 7611 | * lpfc_send_els_event - Posts unsolicited els event |
ea2151b4 JS |
7612 | * @vport: Pointer to vport object. |
7613 | * @ndlp: Pointer FC node object. | |
7614 | * @cmd: ELS command code. | |
7615 | * | |
7616 | * This function posts an event when there is an incoming | |
7617 | * unsolicited ELS command. | |
7618 | **/ | |
7619 | static void | |
7620 | lpfc_send_els_event(struct lpfc_vport *vport, | |
7621 | struct lpfc_nodelist *ndlp, | |
ddcc50f0 | 7622 | uint32_t *payload) |
ea2151b4 | 7623 | { |
ddcc50f0 JS |
7624 | struct lpfc_els_event_header *els_data = NULL; |
7625 | struct lpfc_logo_event *logo_data = NULL; | |
ea2151b4 JS |
7626 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
7627 | ||
ddcc50f0 JS |
7628 | if (*payload == ELS_CMD_LOGO) { |
7629 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); | |
7630 | if (!logo_data) { | |
7631 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7632 | "0148 Failed to allocate memory " | |
7633 | "for LOGO event\n"); | |
7634 | return; | |
7635 | } | |
7636 | els_data = &logo_data->header; | |
7637 | } else { | |
7638 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), | |
7639 | GFP_KERNEL); | |
7640 | if (!els_data) { | |
7641 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7642 | "0149 Failed to allocate memory " | |
7643 | "for ELS event\n"); | |
7644 | return; | |
7645 | } | |
7646 | } | |
7647 | els_data->event_type = FC_REG_ELS_EVENT; | |
7648 | switch (*payload) { | |
ea2151b4 | 7649 | case ELS_CMD_PLOGI: |
ddcc50f0 | 7650 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
ea2151b4 JS |
7651 | break; |
7652 | case ELS_CMD_PRLO: | |
ddcc50f0 | 7653 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
ea2151b4 JS |
7654 | break; |
7655 | case ELS_CMD_ADISC: | |
ddcc50f0 JS |
7656 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
7657 | break; | |
7658 | case ELS_CMD_LOGO: | |
7659 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; | |
7660 | /* Copy the WWPN in the LOGO payload */ | |
7661 | memcpy(logo_data->logo_wwpn, &payload[2], | |
7662 | sizeof(struct lpfc_name)); | |
ea2151b4 JS |
7663 | break; |
7664 | default: | |
e916141c | 7665 | kfree(els_data); |
ea2151b4 JS |
7666 | return; |
7667 | } | |
ddcc50f0 JS |
7668 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
7669 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | |
7670 | if (*payload == ELS_CMD_LOGO) { | |
7671 | fc_host_post_vendor_event(shost, | |
7672 | fc_get_event_number(), | |
7673 | sizeof(struct lpfc_logo_event), | |
7674 | (char *)logo_data, | |
7675 | LPFC_NL_VENDOR_ID); | |
7676 | kfree(logo_data); | |
7677 | } else { | |
7678 | fc_host_post_vendor_event(shost, | |
7679 | fc_get_event_number(), | |
7680 | sizeof(struct lpfc_els_event_header), | |
7681 | (char *)els_data, | |
7682 | LPFC_NL_VENDOR_ID); | |
7683 | kfree(els_data); | |
7684 | } | |
ea2151b4 JS |
7685 | |
7686 | return; | |
7687 | } | |
7688 | ||
7689 | ||
e59058c4 | 7690 | /** |
3621a710 | 7691 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
e59058c4 JS |
7692 | * @phba: pointer to lpfc hba data structure. |
7693 | * @pring: pointer to a SLI ring. | |
7694 | * @vport: pointer to a host virtual N_Port data structure. | |
7695 | * @elsiocb: pointer to lpfc els command iocb data structure. | |
7696 | * | |
7697 | * This routine is used for processing the IOCB associated with a unsolicited | |
7698 | * event. It first determines whether there is an existing ndlp that matches | |
7699 | * the DID from the unsolicited IOCB. If not, it will create a new one with | |
7700 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited | |
7701 | * IOCB is then used to invoke the proper routine and to set up proper state | |
7702 | * of the discovery state machine. | |
7703 | **/ | |
ed957684 JS |
7704 | static void |
7705 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
92d7f7b0 | 7706 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
dea3101e | 7707 | { |
87af33fe | 7708 | struct Scsi_Host *shost; |
dea3101e | 7709 | struct lpfc_nodelist *ndlp; |
dea3101e | 7710 | struct ls_rjt stat; |
92d7f7b0 | 7711 | uint32_t *payload; |
303f2f9c JS |
7712 | uint32_t cmd, did, newnode; |
7713 | uint8_t rjt_exp, rjt_err = 0; | |
ed957684 | 7714 | IOCB_t *icmd = &elsiocb->iocb; |
dea3101e | 7715 | |
e47c9093 | 7716 | if (!vport || !(elsiocb->context2)) |
dea3101e | 7717 | goto dropit; |
2e0fef85 | 7718 | |
dea3101e | 7719 | newnode = 0; |
92d7f7b0 JS |
7720 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
7721 | cmd = *payload; | |
ed957684 | 7722 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
495a714c | 7723 | lpfc_post_buffer(phba, pring, 1); |
dea3101e | 7724 | |
858c9f6c JS |
7725 | did = icmd->un.rcvels.remoteID; |
7726 | if (icmd->ulpStatus) { | |
7727 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7728 | "RCV Unsol ELS: status:x%x/x%x did:x%x", | |
7729 | icmd->ulpStatus, icmd->un.ulpWord[4], did); | |
dea3101e | 7730 | goto dropit; |
858c9f6c | 7731 | } |
dea3101e JB |
7732 | |
7733 | /* Check to see if link went down during discovery */ | |
ed957684 | 7734 | if (lpfc_els_chk_latt(vport)) |
dea3101e | 7735 | goto dropit; |
dea3101e | 7736 | |
c868595d | 7737 | /* Ignore traffic received during vport shutdown. */ |
92d7f7b0 JS |
7738 | if (vport->load_flag & FC_UNLOADING) |
7739 | goto dropit; | |
7740 | ||
92494144 JS |
7741 | /* If NPort discovery is delayed drop incoming ELS */ |
7742 | if ((vport->fc_flag & FC_DISC_DELAYED) && | |
7743 | (cmd != ELS_CMD_PLOGI)) | |
7744 | goto dropit; | |
7745 | ||
2e0fef85 | 7746 | ndlp = lpfc_findnode_did(vport, did); |
c9f8735b | 7747 | if (!ndlp) { |
dea3101e | 7748 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b | 7749 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
ed957684 | 7750 | if (!ndlp) |
dea3101e | 7751 | goto dropit; |
dea3101e | 7752 | |
2e0fef85 | 7753 | lpfc_nlp_init(vport, ndlp, did); |
98c9ea5c | 7754 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
dea3101e | 7755 | newnode = 1; |
e47c9093 | 7756 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
dea3101e | 7757 | ndlp->nlp_type |= NLP_FABRIC; |
58da1ffb JS |
7758 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
7759 | ndlp = lpfc_enable_node(vport, ndlp, | |
7760 | NLP_STE_UNUSED_NODE); | |
7761 | if (!ndlp) | |
7762 | goto dropit; | |
7763 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
7764 | newnode = 1; | |
7765 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
7766 | ndlp->nlp_type |= NLP_FABRIC; | |
7767 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
7768 | /* This is similar to the new node path */ | |
7769 | ndlp = lpfc_nlp_get(ndlp); | |
7770 | if (!ndlp) | |
7771 | goto dropit; | |
7772 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
7773 | newnode = 1; | |
87af33fe | 7774 | } |
dea3101e JB |
7775 | |
7776 | phba->fc_stat.elsRcvFrame++; | |
e47c9093 | 7777 | |
12838e74 JS |
7778 | /* |
7779 | * Do not process any unsolicited ELS commands | |
7780 | * if the ndlp is in DEV_LOSS | |
7781 | */ | |
466e840b JS |
7782 | shost = lpfc_shost_from_vport(vport); |
7783 | spin_lock_irq(shost->host_lock); | |
7784 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { | |
7785 | spin_unlock_irq(shost->host_lock); | |
12838e74 | 7786 | goto dropit; |
466e840b JS |
7787 | } |
7788 | spin_unlock_irq(shost->host_lock); | |
12838e74 | 7789 | |
329f9bc7 | 7790 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
2e0fef85 | 7791 | elsiocb->vport = vport; |
dea3101e JB |
7792 | |
7793 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { | |
7794 | cmd &= ELS_CMD_MASK; | |
7795 | } | |
7796 | /* ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
7797 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
7798 | "0112 ELS command x%x received from NPORT x%x " | |
e74c03c8 JS |
7799 | "Data: x%x x%x x%x x%x\n", |
7800 | cmd, did, vport->port_state, vport->fc_flag, | |
7801 | vport->fc_myDID, vport->fc_prevDID); | |
eec3d312 JS |
7802 | |
7803 | /* reject till our FLOGI completes */ | |
7804 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && | |
d6de08cc | 7805 | (cmd != ELS_CMD_FLOGI)) { |
401304cc | 7806 | rjt_err = LSRJT_LOGICAL_BSY; |
eec3d312 JS |
7807 | rjt_exp = LSEXP_NOTHING_MORE; |
7808 | goto lsrjt; | |
7809 | } | |
7810 | ||
dea3101e JB |
7811 | switch (cmd) { |
7812 | case ELS_CMD_PLOGI: | |
858c9f6c JS |
7813 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7814 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", | |
7815 | did, vport->port_state, ndlp->nlp_flag); | |
7816 | ||
dea3101e | 7817 | phba->fc_stat.elsRcvPLOGI++; |
858c9f6c | 7818 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
e74c03c8 JS |
7819 | if (phba->sli_rev == LPFC_SLI_REV4 && |
7820 | (phba->pport->fc_flag & FC_PT2PT)) { | |
7821 | vport->fc_prevDID = vport->fc_myDID; | |
7822 | /* Our DID needs to be updated before registering | |
7823 | * the vfi. This is done in lpfc_rcv_plogi but | |
7824 | * that is called after the reg_vfi. | |
7825 | */ | |
7826 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; | |
7827 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
7828 | "3312 Remote port assigned DID x%x " | |
7829 | "%x\n", vport->fc_myDID, | |
7830 | vport->fc_prevDID); | |
7831 | } | |
858c9f6c | 7832 | |
ddcc50f0 | 7833 | lpfc_send_els_event(vport, ndlp, payload); |
92494144 JS |
7834 | |
7835 | /* If Nport discovery is delayed, reject PLOGIs */ | |
7836 | if (vport->fc_flag & FC_DISC_DELAYED) { | |
7837 | rjt_err = LSRJT_UNABLE_TPC; | |
303f2f9c | 7838 | rjt_exp = LSEXP_NOTHING_MORE; |
92494144 JS |
7839 | break; |
7840 | } | |
d6de08cc | 7841 | |
858c9f6c | 7842 | if (vport->port_state < LPFC_DISC_AUTH) { |
1b32f6aa JS |
7843 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
7844 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { | |
7845 | rjt_err = LSRJT_UNABLE_TPC; | |
303f2f9c | 7846 | rjt_exp = LSEXP_NOTHING_MORE; |
1b32f6aa JS |
7847 | break; |
7848 | } | |
dea3101e | 7849 | } |
87af33fe | 7850 | |
87af33fe JS |
7851 | spin_lock_irq(shost->host_lock); |
7852 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; | |
7853 | spin_unlock_irq(shost->host_lock); | |
7854 | ||
2e0fef85 JS |
7855 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7856 | NLP_EVT_RCV_PLOGI); | |
858c9f6c | 7857 | |
dea3101e JB |
7858 | break; |
7859 | case ELS_CMD_FLOGI: | |
858c9f6c JS |
7860 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7861 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", | |
7862 | did, vport->port_state, ndlp->nlp_flag); | |
7863 | ||
dea3101e | 7864 | phba->fc_stat.elsRcvFLOGI++; |
51ef4c26 | 7865 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
87af33fe | 7866 | if (newnode) |
98c9ea5c | 7867 | lpfc_nlp_put(ndlp); |
dea3101e JB |
7868 | break; |
7869 | case ELS_CMD_LOGO: | |
858c9f6c JS |
7870 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7871 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", | |
7872 | did, vport->port_state, ndlp->nlp_flag); | |
7873 | ||
dea3101e | 7874 | phba->fc_stat.elsRcvLOGO++; |
ddcc50f0 | 7875 | lpfc_send_els_event(vport, ndlp, payload); |
2e0fef85 | 7876 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7877 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7878 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7879 | break; |
7880 | } | |
2e0fef85 | 7881 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
dea3101e JB |
7882 | break; |
7883 | case ELS_CMD_PRLO: | |
858c9f6c JS |
7884 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7885 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", | |
7886 | did, vport->port_state, ndlp->nlp_flag); | |
7887 | ||
dea3101e | 7888 | phba->fc_stat.elsRcvPRLO++; |
ddcc50f0 | 7889 | lpfc_send_els_event(vport, ndlp, payload); |
2e0fef85 | 7890 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7891 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7892 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7893 | break; |
7894 | } | |
2e0fef85 | 7895 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
dea3101e | 7896 | break; |
8b017a30 JS |
7897 | case ELS_CMD_LCB: |
7898 | phba->fc_stat.elsRcvLCB++; | |
7899 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); | |
7900 | break; | |
86478875 JS |
7901 | case ELS_CMD_RDP: |
7902 | phba->fc_stat.elsRcvRDP++; | |
7903 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); | |
7904 | break; | |
dea3101e JB |
7905 | case ELS_CMD_RSCN: |
7906 | phba->fc_stat.elsRcvRSCN++; | |
51ef4c26 | 7907 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
87af33fe | 7908 | if (newnode) |
98c9ea5c | 7909 | lpfc_nlp_put(ndlp); |
dea3101e JB |
7910 | break; |
7911 | case ELS_CMD_ADISC: | |
858c9f6c JS |
7912 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7913 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", | |
7914 | did, vport->port_state, ndlp->nlp_flag); | |
7915 | ||
ddcc50f0 | 7916 | lpfc_send_els_event(vport, ndlp, payload); |
dea3101e | 7917 | phba->fc_stat.elsRcvADISC++; |
2e0fef85 | 7918 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7919 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7920 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7921 | break; |
7922 | } | |
2e0fef85 JS |
7923 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7924 | NLP_EVT_RCV_ADISC); | |
dea3101e JB |
7925 | break; |
7926 | case ELS_CMD_PDISC: | |
858c9f6c JS |
7927 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7928 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", | |
7929 | did, vport->port_state, ndlp->nlp_flag); | |
7930 | ||
dea3101e | 7931 | phba->fc_stat.elsRcvPDISC++; |
2e0fef85 | 7932 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7933 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7934 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7935 | break; |
7936 | } | |
2e0fef85 JS |
7937 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7938 | NLP_EVT_RCV_PDISC); | |
dea3101e JB |
7939 | break; |
7940 | case ELS_CMD_FARPR: | |
858c9f6c JS |
7941 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7942 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", | |
7943 | did, vport->port_state, ndlp->nlp_flag); | |
7944 | ||
dea3101e | 7945 | phba->fc_stat.elsRcvFARPR++; |
2e0fef85 | 7946 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
dea3101e JB |
7947 | break; |
7948 | case ELS_CMD_FARP: | |
858c9f6c JS |
7949 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7950 | "RCV FARP: did:x%x/ste:x%x flg:x%x", | |
7951 | did, vport->port_state, ndlp->nlp_flag); | |
7952 | ||
dea3101e | 7953 | phba->fc_stat.elsRcvFARP++; |
2e0fef85 | 7954 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
dea3101e JB |
7955 | break; |
7956 | case ELS_CMD_FAN: | |
858c9f6c JS |
7957 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7958 | "RCV FAN: did:x%x/ste:x%x flg:x%x", | |
7959 | did, vport->port_state, ndlp->nlp_flag); | |
7960 | ||
dea3101e | 7961 | phba->fc_stat.elsRcvFAN++; |
2e0fef85 | 7962 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
dea3101e | 7963 | break; |
dea3101e | 7964 | case ELS_CMD_PRLI: |
a0f2d3ef | 7965 | case ELS_CMD_NVMEPRLI: |
858c9f6c JS |
7966 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7967 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", | |
7968 | did, vport->port_state, ndlp->nlp_flag); | |
7969 | ||
dea3101e | 7970 | phba->fc_stat.elsRcvPRLI++; |
a71e3cdc DK |
7971 | if ((vport->port_state < LPFC_DISC_AUTH) && |
7972 | (vport->fc_flag & FC_FABRIC)) { | |
858c9f6c | 7973 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7974 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7975 | break; |
7976 | } | |
2e0fef85 | 7977 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
dea3101e | 7978 | break; |
7bb3b137 | 7979 | case ELS_CMD_LIRR: |
858c9f6c JS |
7980 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7981 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", | |
7982 | did, vport->port_state, ndlp->nlp_flag); | |
7983 | ||
7bb3b137 | 7984 | phba->fc_stat.elsRcvLIRR++; |
2e0fef85 | 7985 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
87af33fe | 7986 | if (newnode) |
98c9ea5c | 7987 | lpfc_nlp_put(ndlp); |
7bb3b137 | 7988 | break; |
12265f68 JS |
7989 | case ELS_CMD_RLS: |
7990 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7991 | "RCV RLS: did:x%x/ste:x%x flg:x%x", | |
7992 | did, vport->port_state, ndlp->nlp_flag); | |
7993 | ||
7994 | phba->fc_stat.elsRcvRLS++; | |
7995 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); | |
7996 | if (newnode) | |
7997 | lpfc_nlp_put(ndlp); | |
7998 | break; | |
7bb3b137 | 7999 | case ELS_CMD_RPS: |
858c9f6c JS |
8000 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
8001 | "RCV RPS: did:x%x/ste:x%x flg:x%x", | |
8002 | did, vport->port_state, ndlp->nlp_flag); | |
8003 | ||
7bb3b137 | 8004 | phba->fc_stat.elsRcvRPS++; |
2e0fef85 | 8005 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
87af33fe | 8006 | if (newnode) |
98c9ea5c | 8007 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
8008 | break; |
8009 | case ELS_CMD_RPL: | |
858c9f6c JS |
8010 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
8011 | "RCV RPL: did:x%x/ste:x%x flg:x%x", | |
8012 | did, vport->port_state, ndlp->nlp_flag); | |
8013 | ||
7bb3b137 | 8014 | phba->fc_stat.elsRcvRPL++; |
2e0fef85 | 8015 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
87af33fe | 8016 | if (newnode) |
98c9ea5c | 8017 | lpfc_nlp_put(ndlp); |
7bb3b137 | 8018 | break; |
dea3101e | 8019 | case ELS_CMD_RNID: |
858c9f6c JS |
8020 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
8021 | "RCV RNID: did:x%x/ste:x%x flg:x%x", | |
8022 | did, vport->port_state, ndlp->nlp_flag); | |
8023 | ||
dea3101e | 8024 | phba->fc_stat.elsRcvRNID++; |
2e0fef85 | 8025 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
87af33fe | 8026 | if (newnode) |
98c9ea5c | 8027 | lpfc_nlp_put(ndlp); |
dea3101e | 8028 | break; |
12265f68 JS |
8029 | case ELS_CMD_RTV: |
8030 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
8031 | "RCV RTV: did:x%x/ste:x%x flg:x%x", | |
8032 | did, vport->port_state, ndlp->nlp_flag); | |
8033 | phba->fc_stat.elsRcvRTV++; | |
8034 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); | |
8035 | if (newnode) | |
8036 | lpfc_nlp_put(ndlp); | |
8037 | break; | |
5ffc266e JS |
8038 | case ELS_CMD_RRQ: |
8039 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
8040 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", | |
8041 | did, vport->port_state, ndlp->nlp_flag); | |
8042 | ||
8043 | phba->fc_stat.elsRcvRRQ++; | |
8044 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); | |
8045 | if (newnode) | |
8046 | lpfc_nlp_put(ndlp); | |
8047 | break; | |
12265f68 JS |
8048 | case ELS_CMD_ECHO: |
8049 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
8050 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", | |
8051 | did, vport->port_state, ndlp->nlp_flag); | |
8052 | ||
8053 | phba->fc_stat.elsRcvECHO++; | |
8054 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); | |
8055 | if (newnode) | |
8056 | lpfc_nlp_put(ndlp); | |
8057 | break; | |
303f2f9c JS |
8058 | case ELS_CMD_REC: |
8059 | /* receive this due to exchange closed */ | |
8060 | rjt_err = LSRJT_UNABLE_TPC; | |
8061 | rjt_exp = LSEXP_INVALID_OX_RX; | |
8062 | break; | |
dea3101e | 8063 | default: |
858c9f6c JS |
8064 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
8065 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", | |
8066 | cmd, did, vport->port_state); | |
8067 | ||
dea3101e | 8068 | /* Unsupported ELS command, reject */ |
63e801ce | 8069 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
303f2f9c | 8070 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
8071 | |
8072 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
8073 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8074 | "0115 Unknown ELS command x%x " | |
8075 | "received from NPORT x%x\n", cmd, did); | |
87af33fe | 8076 | if (newnode) |
98c9ea5c | 8077 | lpfc_nlp_put(ndlp); |
dea3101e JB |
8078 | break; |
8079 | } | |
8080 | ||
eec3d312 | 8081 | lsrjt: |
dea3101e JB |
8082 | /* check if need to LS_RJT received ELS cmd */ |
8083 | if (rjt_err) { | |
92d7f7b0 | 8084 | memset(&stat, 0, sizeof(stat)); |
858c9f6c | 8085 | stat.un.b.lsRjtRsnCode = rjt_err; |
303f2f9c | 8086 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
858c9f6c JS |
8087 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
8088 | NULL); | |
dea3101e JB |
8089 | } |
8090 | ||
d7c255b2 JS |
8091 | lpfc_nlp_put(elsiocb->context1); |
8092 | elsiocb->context1 = NULL; | |
ed957684 JS |
8093 | return; |
8094 | ||
8095 | dropit: | |
98c9ea5c | 8096 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
6fb120a7 JS |
8097 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8098 | "0111 Dropping received ELS cmd " | |
ed957684 | 8099 | "Data: x%x x%x x%x\n", |
6fb120a7 | 8100 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
ed957684 JS |
8101 | phba->fc_stat.elsRcvDrop++; |
8102 | } | |
8103 | ||
e59058c4 | 8104 | /** |
3621a710 | 8105 | * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring |
e59058c4 JS |
8106 | * @phba: pointer to lpfc hba data structure. |
8107 | * @pring: pointer to a SLI ring. | |
8108 | * @elsiocb: pointer to lpfc els iocb data structure. | |
8109 | * | |
8110 | * This routine is used to process an unsolicited event received from a SLI | |
8111 | * (Service Level Interface) ring. The actual processing of the data buffer | |
8112 | * associated with the unsolicited event is done by invoking the routine | |
8113 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the | |
8114 | * SLI ring on which the unsolicited event was received. | |
8115 | **/ | |
ed957684 JS |
8116 | void |
8117 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8118 | struct lpfc_iocbq *elsiocb) | |
8119 | { | |
8120 | struct lpfc_vport *vport = phba->pport; | |
ed957684 | 8121 | IOCB_t *icmd = &elsiocb->iocb; |
ed957684 | 8122 | dma_addr_t paddr; |
92d7f7b0 JS |
8123 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
8124 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; | |
8125 | ||
d7c255b2 | 8126 | elsiocb->context1 = NULL; |
92d7f7b0 JS |
8127 | elsiocb->context2 = NULL; |
8128 | elsiocb->context3 = NULL; | |
ed957684 | 8129 | |
92d7f7b0 JS |
8130 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
8131 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
8132 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && | |
e3d2b802 JS |
8133 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
8134 | IOERR_RCV_BUFFER_WAITING) { | |
ed957684 JS |
8135 | phba->fc_stat.NoRcvBuf++; |
8136 | /* Not enough posted buffers; Try posting more buffers */ | |
92d7f7b0 | 8137 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
495a714c | 8138 | lpfc_post_buffer(phba, pring, 0); |
ed957684 JS |
8139 | return; |
8140 | } | |
8141 | ||
92d7f7b0 JS |
8142 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
8143 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || | |
8144 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
8145 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) | |
8146 | vport = phba->pport; | |
6fb120a7 JS |
8147 | else |
8148 | vport = lpfc_find_vport_by_vpid(phba, | |
6d368e53 | 8149 | icmd->unsli3.rcvsli3.vpi); |
92d7f7b0 | 8150 | } |
6d368e53 | 8151 | |
7f5f3d0d JS |
8152 | /* If there are no BDEs associated |
8153 | * with this IOCB, there is nothing to do. | |
8154 | */ | |
ed957684 JS |
8155 | if (icmd->ulpBdeCount == 0) |
8156 | return; | |
8157 | ||
7f5f3d0d JS |
8158 | /* type of ELS cmd is first 32bit word |
8159 | * in packet | |
8160 | */ | |
ed957684 | 8161 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
92d7f7b0 | 8162 | elsiocb->context2 = bdeBuf1; |
ed957684 JS |
8163 | } else { |
8164 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, | |
8165 | icmd->un.cont64[0].addrLow); | |
92d7f7b0 JS |
8166 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
8167 | paddr); | |
ed957684 JS |
8168 | } |
8169 | ||
92d7f7b0 JS |
8170 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
8171 | /* | |
8172 | * The different unsolicited event handlers would tell us | |
8173 | * if they are done with "mp" by setting context2 to NULL. | |
8174 | */ | |
dea3101e | 8175 | if (elsiocb->context2) { |
92d7f7b0 JS |
8176 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
8177 | elsiocb->context2 = NULL; | |
dea3101e | 8178 | } |
ed957684 JS |
8179 | |
8180 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ | |
92d7f7b0 | 8181 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
ed957684 | 8182 | icmd->ulpBdeCount == 2) { |
92d7f7b0 JS |
8183 | elsiocb->context2 = bdeBuf2; |
8184 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | |
ed957684 JS |
8185 | /* free mp if we are done with it */ |
8186 | if (elsiocb->context2) { | |
92d7f7b0 JS |
8187 | lpfc_in_buf_free(phba, elsiocb->context2); |
8188 | elsiocb->context2 = NULL; | |
8189 | } | |
8190 | } | |
8191 | } | |
8192 | ||
bd4b3e5c | 8193 | static void |
4258e98e JS |
8194 | lpfc_start_fdmi(struct lpfc_vport *vport) |
8195 | { | |
8196 | struct lpfc_hba *phba = vport->phba; | |
8197 | struct lpfc_nodelist *ndlp; | |
8198 | ||
8199 | /* If this is the first time, allocate an ndlp and initialize | |
8200 | * it. Otherwise, make sure the node is enabled and then do the | |
8201 | * login. | |
8202 | */ | |
8203 | ndlp = lpfc_findnode_did(vport, FDMI_DID); | |
8204 | if (!ndlp) { | |
8205 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
8206 | if (ndlp) { | |
8207 | lpfc_nlp_init(vport, ndlp, FDMI_DID); | |
8208 | ndlp->nlp_type |= NLP_FABRIC; | |
8209 | } else { | |
8210 | return; | |
8211 | } | |
8212 | } | |
8213 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
8214 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); | |
8215 | ||
8216 | if (ndlp) { | |
8217 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
8218 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
8219 | } | |
8220 | } | |
8221 | ||
e59058c4 | 8222 | /** |
3621a710 | 8223 | * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr |
e59058c4 JS |
8224 | * @phba: pointer to lpfc hba data structure. |
8225 | * @vport: pointer to a virtual N_Port data structure. | |
8226 | * | |
8227 | * This routine issues a Port Login (PLOGI) to the Name Server with | |
8228 | * State Change Request (SCR) for a @vport. This routine will create an | |
8229 | * ndlp for the Name Server associated to the @vport if such node does | |
8230 | * not already exist. The PLOGI to Name Server is issued by invoking the | |
8231 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface | |
8232 | * (FDMI) is configured to the @vport, a FDMI node will be created and | |
8233 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. | |
8234 | **/ | |
92d7f7b0 JS |
8235 | void |
8236 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) | |
8237 | { | |
4258e98e | 8238 | struct lpfc_nodelist *ndlp; |
92494144 JS |
8239 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
8240 | ||
8241 | /* | |
8242 | * If lpfc_delay_discovery parameter is set and the clean address | |
8243 | * bit is cleared and fc fabric parameters chenged, delay FC NPort | |
8244 | * discovery. | |
8245 | */ | |
8246 | spin_lock_irq(shost->host_lock); | |
8247 | if (vport->fc_flag & FC_DISC_DELAYED) { | |
8248 | spin_unlock_irq(shost->host_lock); | |
18775708 JS |
8249 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
8250 | "3334 Delay fc port discovery for %d seconds\n", | |
8251 | phba->fc_ratov); | |
92494144 | 8252 | mod_timer(&vport->delayed_disc_tmo, |
256ec0d0 | 8253 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
92494144 JS |
8254 | return; |
8255 | } | |
8256 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 JS |
8257 | |
8258 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | |
8259 | if (!ndlp) { | |
8260 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
8261 | if (!ndlp) { | |
76a95d75 | 8262 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
92d7f7b0 JS |
8263 | lpfc_disc_start(vport); |
8264 | return; | |
8265 | } | |
8266 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
8267 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8268 | "0251 NameServer login: no memory\n"); | |
92d7f7b0 JS |
8269 | return; |
8270 | } | |
8271 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | |
e47c9093 JS |
8272 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
8273 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
8274 | if (!ndlp) { | |
76a95d75 | 8275 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
e47c9093 JS |
8276 | lpfc_disc_start(vport); |
8277 | return; | |
8278 | } | |
8279 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
8280 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
8281 | "0348 NameServer login: node freed\n"); | |
8282 | return; | |
8283 | } | |
92d7f7b0 | 8284 | } |
58da1ffb | 8285 | ndlp->nlp_type |= NLP_FABRIC; |
92d7f7b0 JS |
8286 | |
8287 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
8288 | ||
8289 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { | |
8290 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
8291 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8292 | "0252 Cannot issue NameServer login\n"); | |
92d7f7b0 JS |
8293 | return; |
8294 | } | |
8295 | ||
8663cbbe JS |
8296 | if ((phba->cfg_enable_SmartSAN || |
8297 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) && | |
8298 | (vport->load_flag & FC_ALLOW_FDMI)) | |
4258e98e | 8299 | lpfc_start_fdmi(vport); |
92d7f7b0 JS |
8300 | } |
8301 | ||
e59058c4 | 8302 | /** |
3621a710 | 8303 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
e59058c4 JS |
8304 | * @phba: pointer to lpfc hba data structure. |
8305 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
8306 | * | |
8307 | * This routine is the completion callback function to register new vport | |
8308 | * mailbox command. If the new vport mailbox command completes successfully, | |
8309 | * the fabric registration login shall be performed on physical port (the | |
8310 | * new vport created is actually a physical port, with VPI 0) or the port | |
8311 | * login to Name Server for State Change Request (SCR) will be performed | |
8312 | * on virtual port (real virtual port, with VPI greater than 0). | |
8313 | **/ | |
92d7f7b0 JS |
8314 | static void |
8315 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
8316 | { | |
8317 | struct lpfc_vport *vport = pmb->vport; | |
8318 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8319 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
04c68496 | 8320 | MAILBOX_t *mb = &pmb->u.mb; |
695a814e | 8321 | int rc; |
92d7f7b0 | 8322 | |
09372820 | 8323 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 8324 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
09372820 | 8325 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
8326 | |
8327 | if (mb->mbxStatus) { | |
e8b62011 | 8328 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
38b92ef8 JS |
8329 | "0915 Register VPI failed : Status: x%x" |
8330 | " upd bit: x%x \n", mb->mbxStatus, | |
8331 | mb->un.varRegVpi.upd); | |
8332 | if (phba->sli_rev == LPFC_SLI_REV4 && | |
8333 | mb->un.varRegVpi.upd) | |
8334 | goto mbox_err_exit ; | |
92d7f7b0 JS |
8335 | |
8336 | switch (mb->mbxStatus) { | |
8337 | case 0x11: /* unsupported feature */ | |
8338 | case 0x9603: /* max_vpi exceeded */ | |
7f5f3d0d | 8339 | case 0x9602: /* Link event since CLEAR_LA */ |
92d7f7b0 JS |
8340 | /* giving up on vport registration */ |
8341 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
8342 | spin_lock_irq(shost->host_lock); | |
8343 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
8344 | spin_unlock_irq(shost->host_lock); | |
8345 | lpfc_can_disctmo(vport); | |
8346 | break; | |
695a814e JS |
8347 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
8348 | case 0x20: | |
8349 | spin_lock_irq(shost->host_lock); | |
8350 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
8351 | spin_unlock_irq(shost->host_lock); | |
8352 | lpfc_init_vpi(phba, pmb, vport->vpi); | |
8353 | pmb->vport = vport; | |
8354 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; | |
8355 | rc = lpfc_sli_issue_mbox(phba, pmb, | |
8356 | MBX_NOWAIT); | |
8357 | if (rc == MBX_NOT_FINISHED) { | |
8358 | lpfc_printf_vlog(vport, | |
8359 | KERN_ERR, LOG_MBOX, | |
8360 | "2732 Failed to issue INIT_VPI" | |
8361 | " mailbox command\n"); | |
8362 | } else { | |
8363 | lpfc_nlp_put(ndlp); | |
8364 | return; | |
8365 | } | |
8366 | ||
92d7f7b0 JS |
8367 | default: |
8368 | /* Try to recover from this error */ | |
5af5eee7 JS |
8369 | if (phba->sli_rev == LPFC_SLI_REV4) |
8370 | lpfc_sli4_unreg_all_rpis(vport); | |
92d7f7b0 | 8371 | lpfc_mbx_unreg_vpi(vport); |
09372820 | 8372 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 8373 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 8374 | spin_unlock_irq(shost->host_lock); |
5d181531 JS |
8375 | if (mb->mbxStatus == MBX_NOT_FINISHED) |
8376 | break; | |
8377 | if ((vport->port_type == LPFC_PHYSICAL_PORT) && | |
8378 | !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) { | |
8379 | if (phba->sli_rev == LPFC_SLI_REV4) | |
8380 | lpfc_issue_init_vfi(vport); | |
8381 | else | |
8382 | lpfc_initial_flogi(vport); | |
8383 | } else { | |
7f5f3d0d | 8384 | lpfc_initial_fdisc(vport); |
5d181531 | 8385 | } |
92d7f7b0 JS |
8386 | break; |
8387 | } | |
92d7f7b0 | 8388 | } else { |
695a814e | 8389 | spin_lock_irq(shost->host_lock); |
1987807d | 8390 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
695a814e JS |
8391 | spin_unlock_irq(shost->host_lock); |
8392 | if (vport == phba->pport) { | |
6fb120a7 JS |
8393 | if (phba->sli_rev < LPFC_SLI_REV4) |
8394 | lpfc_issue_fabric_reglogin(vport); | |
695a814e | 8395 | else { |
fc2b989b JS |
8396 | /* |
8397 | * If the physical port is instantiated using | |
8398 | * FDISC, do not start vport discovery. | |
8399 | */ | |
8400 | if (vport->port_state != LPFC_FDISC) | |
8401 | lpfc_start_fdiscs(phba); | |
695a814e JS |
8402 | lpfc_do_scr_ns_plogi(phba, vport); |
8403 | } | |
8404 | } else | |
92d7f7b0 JS |
8405 | lpfc_do_scr_ns_plogi(phba, vport); |
8406 | } | |
38b92ef8 | 8407 | mbox_err_exit: |
fa4066b6 JS |
8408 | /* Now, we decrement the ndlp reference count held for this |
8409 | * callback function | |
8410 | */ | |
8411 | lpfc_nlp_put(ndlp); | |
8412 | ||
92d7f7b0 JS |
8413 | mempool_free(pmb, phba->mbox_mem_pool); |
8414 | return; | |
8415 | } | |
8416 | ||
e59058c4 | 8417 | /** |
3621a710 | 8418 | * lpfc_register_new_vport - Register a new vport with a HBA |
e59058c4 JS |
8419 | * @phba: pointer to lpfc hba data structure. |
8420 | * @vport: pointer to a host virtual N_Port data structure. | |
8421 | * @ndlp: pointer to a node-list data structure. | |
8422 | * | |
8423 | * This routine registers the @vport as a new virtual port with a HBA. | |
8424 | * It is done through a registering vpi mailbox command. | |
8425 | **/ | |
695a814e | 8426 | void |
92d7f7b0 JS |
8427 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
8428 | struct lpfc_nodelist *ndlp) | |
8429 | { | |
09372820 | 8430 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
92d7f7b0 JS |
8431 | LPFC_MBOXQ_t *mbox; |
8432 | ||
8433 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
8434 | if (mbox) { | |
6fb120a7 | 8435 | lpfc_reg_vpi(vport, mbox); |
92d7f7b0 JS |
8436 | mbox->vport = vport; |
8437 | mbox->context2 = lpfc_nlp_get(ndlp); | |
8438 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; | |
0b727fea | 8439 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
92d7f7b0 | 8440 | == MBX_NOT_FINISHED) { |
fa4066b6 JS |
8441 | /* mailbox command not success, decrement ndlp |
8442 | * reference count for this command | |
8443 | */ | |
8444 | lpfc_nlp_put(ndlp); | |
92d7f7b0 | 8445 | mempool_free(mbox, phba->mbox_mem_pool); |
92d7f7b0 | 8446 | |
e8b62011 JS |
8447 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
8448 | "0253 Register VPI: Can't send mbox\n"); | |
fa4066b6 | 8449 | goto mbox_err_exit; |
92d7f7b0 JS |
8450 | } |
8451 | } else { | |
e8b62011 JS |
8452 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
8453 | "0254 Register VPI: no memory\n"); | |
fa4066b6 | 8454 | goto mbox_err_exit; |
92d7f7b0 | 8455 | } |
fa4066b6 JS |
8456 | return; |
8457 | ||
8458 | mbox_err_exit: | |
8459 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
8460 | spin_lock_irq(shost->host_lock); | |
8461 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
8462 | spin_unlock_irq(shost->host_lock); | |
8463 | return; | |
92d7f7b0 JS |
8464 | } |
8465 | ||
695a814e | 8466 | /** |
0c9ab6f5 | 8467 | * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer |
695a814e JS |
8468 | * @phba: pointer to lpfc hba data structure. |
8469 | * | |
0c9ab6f5 | 8470 | * This routine cancels the retry delay timers to all the vports. |
695a814e JS |
8471 | **/ |
8472 | void | |
0c9ab6f5 | 8473 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
695a814e JS |
8474 | { |
8475 | struct lpfc_vport **vports; | |
8476 | struct lpfc_nodelist *ndlp; | |
695a814e | 8477 | uint32_t link_state; |
0c9ab6f5 | 8478 | int i; |
695a814e JS |
8479 | |
8480 | /* Treat this failure as linkdown for all vports */ | |
8481 | link_state = phba->link_state; | |
8482 | lpfc_linkdown(phba); | |
8483 | phba->link_state = link_state; | |
8484 | ||
8485 | vports = lpfc_create_vport_work_array(phba); | |
8486 | ||
8487 | if (vports) { | |
8488 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
8489 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); | |
8490 | if (ndlp) | |
8491 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); | |
8492 | lpfc_els_flush_cmd(vports[i]); | |
8493 | } | |
8494 | lpfc_destroy_vport_work_array(phba, vports); | |
8495 | } | |
0c9ab6f5 JS |
8496 | } |
8497 | ||
8498 | /** | |
8499 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. | |
8500 | * @phba: pointer to lpfc hba data structure. | |
8501 | * | |
8502 | * This routine abort all pending discovery commands and | |
8503 | * start a timer to retry FLOGI for the physical port | |
8504 | * discovery. | |
8505 | **/ | |
8506 | void | |
8507 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) | |
8508 | { | |
8509 | struct lpfc_nodelist *ndlp; | |
8510 | struct Scsi_Host *shost; | |
8511 | ||
8512 | /* Cancel the all vports retry delay retry timers */ | |
8513 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
695a814e JS |
8514 | |
8515 | /* If fabric require FLOGI, then re-instantiate physical login */ | |
8516 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); | |
8517 | if (!ndlp) | |
8518 | return; | |
8519 | ||
695a814e | 8520 | shost = lpfc_shost_from_vport(phba->pport); |
256ec0d0 | 8521 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
695a814e JS |
8522 | spin_lock_irq(shost->host_lock); |
8523 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
8524 | spin_unlock_irq(shost->host_lock); | |
8525 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; | |
8526 | phba->pport->port_state = LPFC_FLOGI; | |
8527 | return; | |
8528 | } | |
8529 | ||
8530 | /** | |
8531 | * lpfc_fabric_login_reqd - Check if FLOGI required. | |
8532 | * @phba: pointer to lpfc hba data structure. | |
8533 | * @cmdiocb: pointer to FDISC command iocb. | |
8534 | * @rspiocb: pointer to FDISC response iocb. | |
8535 | * | |
8536 | * This routine checks if a FLOGI is reguired for FDISC | |
8537 | * to succeed. | |
8538 | **/ | |
8539 | static int | |
8540 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, | |
8541 | struct lpfc_iocbq *cmdiocb, | |
8542 | struct lpfc_iocbq *rspiocb) | |
8543 | { | |
8544 | ||
8545 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || | |
8546 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) | |
8547 | return 0; | |
8548 | else | |
8549 | return 1; | |
8550 | } | |
8551 | ||
e59058c4 | 8552 | /** |
3621a710 | 8553 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
e59058c4 JS |
8554 | * @phba: pointer to lpfc hba data structure. |
8555 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
8556 | * @rspiocb: pointer to lpfc response iocb data structure. | |
8557 | * | |
8558 | * This routine is the completion callback function to a Fabric Discover | |
8559 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued | |
8560 | * single threaded, each FDISC completion callback function will reset | |
8561 | * the discovery timer for all vports such that the timers will not get | |
8562 | * unnecessary timeout. The function checks the FDISC IOCB status. If error | |
8563 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the | |
8564 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID | |
8565 | * assigned to the vport has been changed with the completion of the FDISC | |
8566 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) | |
8567 | * are unregistered from the HBA, and then the lpfc_register_new_vport() | |
8568 | * routine is invoked to register new vport with the HBA. Otherwise, the | |
8569 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name | |
8570 | * Server for State Change Request (SCR). | |
8571 | **/ | |
92d7f7b0 JS |
8572 | static void |
8573 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8574 | struct lpfc_iocbq *rspiocb) | |
8575 | { | |
8576 | struct lpfc_vport *vport = cmdiocb->vport; | |
8577 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8578 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
8579 | struct lpfc_nodelist *np; | |
8580 | struct lpfc_nodelist *next_np; | |
8581 | IOCB_t *irsp = &rspiocb->iocb; | |
8582 | struct lpfc_iocbq *piocb; | |
92494144 JS |
8583 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
8584 | struct serv_parm *sp; | |
8585 | uint8_t fabric_param_changed; | |
92d7f7b0 | 8586 | |
e8b62011 JS |
8587 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
8588 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", | |
8589 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
8590 | vport->fc_prevDID); | |
92d7f7b0 JS |
8591 | /* Since all FDISCs are being single threaded, we |
8592 | * must reset the discovery timer for ALL vports | |
8593 | * waiting to send FDISC when one completes. | |
8594 | */ | |
8595 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { | |
8596 | lpfc_set_disctmo(piocb->vport); | |
8597 | } | |
8598 | ||
858c9f6c JS |
8599 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8600 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", | |
8601 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); | |
8602 | ||
92d7f7b0 | 8603 | if (irsp->ulpStatus) { |
695a814e JS |
8604 | |
8605 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { | |
8606 | lpfc_retry_pport_discovery(phba); | |
8607 | goto out; | |
8608 | } | |
8609 | ||
92d7f7b0 JS |
8610 | /* Check for retry */ |
8611 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | |
8612 | goto out; | |
92d7f7b0 | 8613 | /* FDISC failed */ |
e8b62011 | 8614 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
6b5151fd | 8615 | "0126 FDISC failed. (x%x/x%x)\n", |
e8b62011 | 8616 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
d7c255b2 JS |
8617 | goto fdisc_failed; |
8618 | } | |
d7c255b2 | 8619 | spin_lock_irq(shost->host_lock); |
695a814e | 8620 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
4b40c59e | 8621 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
d7c255b2 | 8622 | vport->fc_flag |= FC_FABRIC; |
76a95d75 | 8623 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
d7c255b2 JS |
8624 | vport->fc_flag |= FC_PUBLIC_LOOP; |
8625 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 | 8626 | |
d7c255b2 JS |
8627 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
8628 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); | |
92494144 | 8629 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
a2fc4aef JS |
8630 | if (!prsp) |
8631 | goto out; | |
92494144 JS |
8632 | sp = prsp->virt + sizeof(uint32_t); |
8633 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | |
8634 | memcpy(&vport->fabric_portname, &sp->portName, | |
8635 | sizeof(struct lpfc_name)); | |
8636 | memcpy(&vport->fabric_nodename, &sp->nodeName, | |
8637 | sizeof(struct lpfc_name)); | |
8638 | if (fabric_param_changed && | |
d7c255b2 JS |
8639 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
8640 | /* If our NportID changed, we need to ensure all | |
8641 | * remaining NPORTs get unreg_login'ed so we can | |
8642 | * issue unreg_vpi. | |
8643 | */ | |
8644 | list_for_each_entry_safe(np, next_np, | |
8645 | &vport->fc_nodes, nlp_listp) { | |
8646 | if (!NLP_CHK_NODE_ACT(ndlp) || | |
8647 | (np->nlp_state != NLP_STE_NPR_NODE) || | |
8648 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
8649 | continue; | |
09372820 | 8650 | spin_lock_irq(shost->host_lock); |
d7c255b2 | 8651 | np->nlp_flag &= ~NLP_NPR_ADISC; |
09372820 | 8652 | spin_unlock_irq(shost->host_lock); |
d7c255b2 | 8653 | lpfc_unreg_rpi(vport, np); |
92d7f7b0 | 8654 | } |
78730cfe | 8655 | lpfc_cleanup_pending_mbox(vport); |
5af5eee7 JS |
8656 | |
8657 | if (phba->sli_rev == LPFC_SLI_REV4) | |
8658 | lpfc_sli4_unreg_all_rpis(vport); | |
8659 | ||
d7c255b2 JS |
8660 | lpfc_mbx_unreg_vpi(vport); |
8661 | spin_lock_irq(shost->host_lock); | |
8662 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
0f65ff68 JS |
8663 | if (phba->sli_rev == LPFC_SLI_REV4) |
8664 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
4b40c59e JS |
8665 | else |
8666 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; | |
d7c255b2 | 8667 | spin_unlock_irq(shost->host_lock); |
38b92ef8 JS |
8668 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
8669 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
8670 | /* | |
8671 | * Driver needs to re-reg VPI in order for f/w | |
8672 | * to update the MAC address. | |
8673 | */ | |
8674 | lpfc_register_new_vport(phba, vport, ndlp); | |
5ac6b303 | 8675 | goto out; |
92d7f7b0 JS |
8676 | } |
8677 | ||
ecfd03c6 JS |
8678 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
8679 | lpfc_issue_init_vpi(vport); | |
8680 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | |
d7c255b2 JS |
8681 | lpfc_register_new_vport(phba, vport, ndlp); |
8682 | else | |
8683 | lpfc_do_scr_ns_plogi(phba, vport); | |
8684 | goto out; | |
8685 | fdisc_failed: | |
c84163d1 JS |
8686 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
8687 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
d7c255b2 JS |
8688 | /* Cancel discovery timer */ |
8689 | lpfc_can_disctmo(vport); | |
8690 | lpfc_nlp_put(ndlp); | |
92d7f7b0 JS |
8691 | out: |
8692 | lpfc_els_free_iocb(phba, cmdiocb); | |
8693 | } | |
8694 | ||
e59058c4 | 8695 | /** |
3621a710 | 8696 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
e59058c4 JS |
8697 | * @vport: pointer to a virtual N_Port data structure. |
8698 | * @ndlp: pointer to a node-list data structure. | |
8699 | * @retry: number of retries to the command IOCB. | |
8700 | * | |
8701 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to | |
8702 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() | |
8703 | * routine to issue the IOCB, which makes sure only one outstanding fabric | |
8704 | * IOCB will be sent off HBA at any given time. | |
8705 | * | |
8706 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
8707 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
8708 | * will be stored into the context1 field of the IOCB for the completion | |
8709 | * callback function to the FDISC ELS command. | |
8710 | * | |
8711 | * Return code | |
8712 | * 0 - Successfully issued fdisc iocb command | |
8713 | * 1 - Failed to issue fdisc iocb command | |
8714 | **/ | |
a6ababd2 | 8715 | static int |
92d7f7b0 JS |
8716 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
8717 | uint8_t retry) | |
8718 | { | |
8719 | struct lpfc_hba *phba = vport->phba; | |
8720 | IOCB_t *icmd; | |
8721 | struct lpfc_iocbq *elsiocb; | |
8722 | struct serv_parm *sp; | |
8723 | uint8_t *pcmd; | |
8724 | uint16_t cmdsize; | |
8725 | int did = ndlp->nlp_DID; | |
8726 | int rc; | |
92d7f7b0 | 8727 | |
5ffc266e | 8728 | vport->port_state = LPFC_FDISC; |
6b5151fd | 8729 | vport->fc_myDID = 0; |
92d7f7b0 JS |
8730 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
8731 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | |
8732 | ELS_CMD_FDISC); | |
8733 | if (!elsiocb) { | |
92d7f7b0 | 8734 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
8735 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8736 | "0255 Issue FDISC: no IOCB\n"); | |
92d7f7b0 JS |
8737 | return 1; |
8738 | } | |
8739 | ||
8740 | icmd = &elsiocb->iocb; | |
8741 | icmd->un.elsreq64.myID = 0; | |
8742 | icmd->un.elsreq64.fl = 1; | |
8743 | ||
73d91e50 JS |
8744 | /* |
8745 | * SLI3 ports require a different context type value than SLI4. | |
8746 | * Catch SLI3 ports here and override the prep. | |
8747 | */ | |
8748 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
f1126688 JS |
8749 | icmd->ulpCt_h = 1; |
8750 | icmd->ulpCt_l = 0; | |
8751 | } | |
92d7f7b0 JS |
8752 | |
8753 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
8754 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; | |
8755 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ | |
8756 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); | |
8757 | sp = (struct serv_parm *) pcmd; | |
8758 | /* Setup CSPs accordingly for Fabric */ | |
8759 | sp->cmn.e_d_tov = 0; | |
8760 | sp->cmn.w2.r_a_tov = 0; | |
df9e1b59 | 8761 | sp->cmn.virtual_fabric_support = 0; |
92d7f7b0 JS |
8762 | sp->cls1.classValid = 0; |
8763 | sp->cls2.seqDelivery = 1; | |
8764 | sp->cls3.seqDelivery = 1; | |
8765 | ||
8766 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ | |
8767 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ | |
8768 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ | |
8769 | pcmd += sizeof(uint32_t); /* Port Name */ | |
8770 | memcpy(pcmd, &vport->fc_portname, 8); | |
8771 | pcmd += sizeof(uint32_t); /* Node Name */ | |
8772 | pcmd += sizeof(uint32_t); /* Node Name */ | |
8773 | memcpy(pcmd, &vport->fc_nodename, 8); | |
8774 | ||
8775 | lpfc_set_disctmo(vport); | |
8776 | ||
8777 | phba->fc_stat.elsXmitFDISC++; | |
8778 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; | |
8779 | ||
858c9f6c JS |
8780 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8781 | "Issue FDISC: did:x%x", | |
8782 | did, 0, 0); | |
8783 | ||
92d7f7b0 JS |
8784 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
8785 | if (rc == IOCB_ERROR) { | |
8786 | lpfc_els_free_iocb(phba, elsiocb); | |
92d7f7b0 | 8787 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
8788 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8789 | "0256 Issue FDISC: Cannot send IOCB\n"); | |
92d7f7b0 JS |
8790 | return 1; |
8791 | } | |
8792 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); | |
92d7f7b0 JS |
8793 | return 0; |
8794 | } | |
8795 | ||
e59058c4 | 8796 | /** |
3621a710 | 8797 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
e59058c4 JS |
8798 | * @phba: pointer to lpfc hba data structure. |
8799 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
8800 | * @rspiocb: pointer to lpfc response iocb data structure. | |
8801 | * | |
8802 | * This routine is the completion callback function to the issuing of a LOGO | |
8803 | * ELS command off a vport. It frees the command IOCB and then decrement the | |
8804 | * reference count held on ndlp for this completion function, indicating that | |
8805 | * the reference to the ndlp is no long needed. Note that the | |
8806 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this | |
8807 | * callback function and an additional explicit ndlp reference decrementation | |
8808 | * will trigger the actual release of the ndlp. | |
8809 | **/ | |
92d7f7b0 JS |
8810 | static void |
8811 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8812 | struct lpfc_iocbq *rspiocb) | |
8813 | { | |
8814 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c | 8815 | IOCB_t *irsp; |
e47c9093 | 8816 | struct lpfc_nodelist *ndlp; |
9589b062 | 8817 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
858c9f6c | 8818 | |
9589b062 | 8819 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
858c9f6c JS |
8820 | irsp = &rspiocb->iocb; |
8821 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
8822 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", | |
8823 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); | |
92d7f7b0 JS |
8824 | |
8825 | lpfc_els_free_iocb(phba, cmdiocb); | |
8826 | vport->unreg_vpi_cmpl = VPORT_ERROR; | |
e47c9093 JS |
8827 | |
8828 | /* Trigger the release of the ndlp after logo */ | |
8829 | lpfc_nlp_put(ndlp); | |
9589b062 JS |
8830 | |
8831 | /* NPIV LOGO completes to NPort <nlp_DID> */ | |
8832 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
8833 | "2928 NPIV LOGO completes to NPort x%x " | |
8834 | "Data: x%x x%x x%x x%x\n", | |
8835 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
8836 | irsp->ulpTimeout, vport->num_disc_nodes); | |
8837 | ||
8838 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { | |
8839 | spin_lock_irq(shost->host_lock); | |
73dc0dbe | 8840 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
9589b062 JS |
8841 | vport->fc_flag &= ~FC_FABRIC; |
8842 | spin_unlock_irq(shost->host_lock); | |
73dc0dbe | 8843 | lpfc_can_disctmo(vport); |
9589b062 | 8844 | } |
92d7f7b0 JS |
8845 | } |
8846 | ||
e59058c4 | 8847 | /** |
3621a710 | 8848 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
e59058c4 JS |
8849 | * @vport: pointer to a virtual N_Port data structure. |
8850 | * @ndlp: pointer to a node-list data structure. | |
8851 | * | |
8852 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. | |
8853 | * | |
8854 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
8855 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
8856 | * will be stored into the context1 field of the IOCB for the completion | |
8857 | * callback function to the LOGO ELS command. | |
8858 | * | |
8859 | * Return codes | |
8860 | * 0 - Successfully issued logo off the @vport | |
8861 | * 1 - Failed to issue logo off the @vport | |
8862 | **/ | |
92d7f7b0 JS |
8863 | int |
8864 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
8865 | { | |
8866 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8867 | struct lpfc_hba *phba = vport->phba; | |
92d7f7b0 JS |
8868 | struct lpfc_iocbq *elsiocb; |
8869 | uint8_t *pcmd; | |
8870 | uint16_t cmdsize; | |
8871 | ||
8872 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); | |
8873 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, | |
8874 | ELS_CMD_LOGO); | |
8875 | if (!elsiocb) | |
8876 | return 1; | |
8877 | ||
92d7f7b0 JS |
8878 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
8879 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
8880 | pcmd += sizeof(uint32_t); | |
8881 | ||
8882 | /* Fill in LOGO payload */ | |
8883 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | |
8884 | pcmd += sizeof(uint32_t); | |
8885 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
8886 | ||
858c9f6c JS |
8887 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8888 | "Issue LOGO npiv did:x%x flg:x%x", | |
8889 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
8890 | ||
92d7f7b0 JS |
8891 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
8892 | spin_lock_irq(shost->host_lock); | |
8893 | ndlp->nlp_flag |= NLP_LOGO_SND; | |
8894 | spin_unlock_irq(shost->host_lock); | |
3772a991 JS |
8895 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
8896 | IOCB_ERROR) { | |
92d7f7b0 JS |
8897 | spin_lock_irq(shost->host_lock); |
8898 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | |
8899 | spin_unlock_irq(shost->host_lock); | |
8900 | lpfc_els_free_iocb(phba, elsiocb); | |
8901 | return 1; | |
8902 | } | |
8903 | return 0; | |
8904 | } | |
8905 | ||
e59058c4 | 8906 | /** |
3621a710 | 8907 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
e59058c4 JS |
8908 | * @ptr: holder for the timer function associated data. |
8909 | * | |
8910 | * This routine is invoked by the fabric iocb block timer after | |
8911 | * timeout. It posts the fabric iocb block timeout event by setting the | |
8912 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes | |
8913 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for | |
8914 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the | |
8915 | * posted event WORKER_FABRIC_BLOCK_TMO. | |
8916 | **/ | |
92d7f7b0 JS |
8917 | void |
8918 | lpfc_fabric_block_timeout(unsigned long ptr) | |
8919 | { | |
8920 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
8921 | unsigned long iflags; | |
8922 | uint32_t tmo_posted; | |
5e9d9b82 | 8923 | |
92d7f7b0 JS |
8924 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
8925 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; | |
8926 | if (!tmo_posted) | |
8927 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; | |
8928 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
8929 | ||
5e9d9b82 JS |
8930 | if (!tmo_posted) |
8931 | lpfc_worker_wake_up(phba); | |
8932 | return; | |
92d7f7b0 JS |
8933 | } |
8934 | ||
e59058c4 | 8935 | /** |
3621a710 | 8936 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
e59058c4 JS |
8937 | * @phba: pointer to lpfc hba data structure. |
8938 | * | |
8939 | * This routine issues one fabric iocb from the driver internal list to | |
8940 | * the HBA. It first checks whether it's ready to issue one fabric iocb to | |
8941 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall | |
8942 | * remove one pending fabric iocb from the driver internal list and invokes | |
8943 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. | |
8944 | **/ | |
92d7f7b0 JS |
8945 | static void |
8946 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) | |
8947 | { | |
8948 | struct lpfc_iocbq *iocb; | |
8949 | unsigned long iflags; | |
8950 | int ret; | |
92d7f7b0 JS |
8951 | IOCB_t *cmd; |
8952 | ||
8953 | repeat: | |
8954 | iocb = NULL; | |
8955 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7f5f3d0d | 8956 | /* Post any pending iocb to the SLI layer */ |
92d7f7b0 JS |
8957 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
8958 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), | |
8959 | list); | |
8960 | if (iocb) | |
7f5f3d0d | 8961 | /* Increment fabric iocb count to hold the position */ |
92d7f7b0 JS |
8962 | atomic_inc(&phba->fabric_iocb_count); |
8963 | } | |
8964 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8965 | if (iocb) { | |
8966 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
8967 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
8968 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
8969 | ||
858c9f6c JS |
8970 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
8971 | "Fabric sched1: ste:x%x", | |
8972 | iocb->vport->port_state, 0, 0); | |
8973 | ||
3772a991 | 8974 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
92d7f7b0 JS |
8975 | |
8976 | if (ret == IOCB_ERROR) { | |
8977 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
8978 | iocb->fabric_iocb_cmpl = NULL; | |
8979 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
8980 | cmd = &iocb->iocb; | |
8981 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
8982 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
8983 | iocb->iocb_cmpl(phba, iocb, iocb); | |
8984 | ||
8985 | atomic_dec(&phba->fabric_iocb_count); | |
8986 | goto repeat; | |
8987 | } | |
8988 | } | |
8989 | ||
8990 | return; | |
8991 | } | |
8992 | ||
e59058c4 | 8993 | /** |
3621a710 | 8994 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
e59058c4 JS |
8995 | * @phba: pointer to lpfc hba data structure. |
8996 | * | |
8997 | * This routine unblocks the issuing fabric iocb command. The function | |
8998 | * will clear the fabric iocb block bit and then invoke the routine | |
8999 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb | |
9000 | * from the driver internal fabric iocb list. | |
9001 | **/ | |
92d7f7b0 JS |
9002 | void |
9003 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) | |
9004 | { | |
9005 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
9006 | ||
9007 | lpfc_resume_fabric_iocbs(phba); | |
9008 | return; | |
9009 | } | |
9010 | ||
e59058c4 | 9011 | /** |
3621a710 | 9012 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
e59058c4 JS |
9013 | * @phba: pointer to lpfc hba data structure. |
9014 | * | |
9015 | * This routine blocks the issuing fabric iocb for a specified amount of | |
9016 | * time (currently 100 ms). This is done by set the fabric iocb block bit | |
9017 | * and set up a timeout timer for 100ms. When the block bit is set, no more | |
9018 | * fabric iocb will be issued out of the HBA. | |
9019 | **/ | |
92d7f7b0 JS |
9020 | static void |
9021 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) | |
9022 | { | |
9023 | int blocked; | |
9024 | ||
9025 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
7f5f3d0d | 9026 | /* Start a timer to unblock fabric iocbs after 100ms */ |
92d7f7b0 | 9027 | if (!blocked) |
256ec0d0 JS |
9028 | mod_timer(&phba->fabric_block_timer, |
9029 | jiffies + msecs_to_jiffies(100)); | |
92d7f7b0 JS |
9030 | |
9031 | return; | |
9032 | } | |
9033 | ||
e59058c4 | 9034 | /** |
3621a710 | 9035 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
e59058c4 JS |
9036 | * @phba: pointer to lpfc hba data structure. |
9037 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
9038 | * @rspiocb: pointer to lpfc response iocb data structure. | |
9039 | * | |
9040 | * This routine is the callback function that is put to the fabric iocb's | |
9041 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback | |
9042 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback | |
9043 | * function first restores and invokes the original iocb's callback function | |
9044 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next | |
9045 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. | |
9046 | **/ | |
92d7f7b0 JS |
9047 | static void |
9048 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9049 | struct lpfc_iocbq *rspiocb) | |
9050 | { | |
9051 | struct ls_rjt stat; | |
9052 | ||
e01ea5e2 | 9053 | BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); |
92d7f7b0 JS |
9054 | |
9055 | switch (rspiocb->iocb.ulpStatus) { | |
9056 | case IOSTAT_NPORT_RJT: | |
9057 | case IOSTAT_FABRIC_RJT: | |
9058 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
9059 | lpfc_block_fabric_iocbs(phba); | |
ed957684 | 9060 | } |
92d7f7b0 JS |
9061 | break; |
9062 | ||
9063 | case IOSTAT_NPORT_BSY: | |
9064 | case IOSTAT_FABRIC_BSY: | |
9065 | lpfc_block_fabric_iocbs(phba); | |
9066 | break; | |
9067 | ||
9068 | case IOSTAT_LS_RJT: | |
9069 | stat.un.lsRjtError = | |
9070 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); | |
9071 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || | |
9072 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) | |
9073 | lpfc_block_fabric_iocbs(phba); | |
9074 | break; | |
9075 | } | |
9076 | ||
a0f2d3ef | 9077 | BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); |
92d7f7b0 JS |
9078 | |
9079 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; | |
9080 | cmdiocb->fabric_iocb_cmpl = NULL; | |
9081 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
9082 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); | |
9083 | ||
9084 | atomic_dec(&phba->fabric_iocb_count); | |
9085 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { | |
7f5f3d0d JS |
9086 | /* Post any pending iocbs to HBA */ |
9087 | lpfc_resume_fabric_iocbs(phba); | |
92d7f7b0 JS |
9088 | } |
9089 | } | |
9090 | ||
e59058c4 | 9091 | /** |
3621a710 | 9092 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
e59058c4 JS |
9093 | * @phba: pointer to lpfc hba data structure. |
9094 | * @iocb: pointer to lpfc command iocb data structure. | |
9095 | * | |
9096 | * This routine is used as the top-level API for issuing a fabric iocb command | |
9097 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver | |
9098 | * function makes sure that only one fabric bound iocb will be outstanding at | |
9099 | * any given time. As such, this function will first check to see whether there | |
9100 | * is already an outstanding fabric iocb on the wire. If so, it will put the | |
9101 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be | |
9102 | * issued later. Otherwise, it will issue the iocb on the wire and update the | |
9103 | * fabric iocb count it indicate that there is one fabric iocb on the wire. | |
9104 | * | |
9105 | * Note, this implementation has a potential sending out fabric IOCBs out of | |
9106 | * order. The problem is caused by the construction of the "ready" boolen does | |
9107 | * not include the condition that the internal fabric IOCB list is empty. As | |
9108 | * such, it is possible a fabric IOCB issued by this routine might be "jump" | |
9109 | * ahead of the fabric IOCBs in the internal list. | |
9110 | * | |
9111 | * Return code | |
9112 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully | |
9113 | * IOCB_ERROR - failed to issue fabric iocb | |
9114 | **/ | |
a6ababd2 | 9115 | static int |
92d7f7b0 JS |
9116 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
9117 | { | |
9118 | unsigned long iflags; | |
92d7f7b0 JS |
9119 | int ready; |
9120 | int ret; | |
9121 | ||
a0f2d3ef | 9122 | BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); |
92d7f7b0 JS |
9123 | |
9124 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9125 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && | |
9126 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
9127 | ||
7f5f3d0d JS |
9128 | if (ready) |
9129 | /* Increment fabric iocb count to hold the position */ | |
9130 | atomic_inc(&phba->fabric_iocb_count); | |
92d7f7b0 JS |
9131 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
9132 | if (ready) { | |
9133 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
9134 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
9135 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
9136 | ||
858c9f6c JS |
9137 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
9138 | "Fabric sched2: ste:x%x", | |
9139 | iocb->vport->port_state, 0, 0); | |
9140 | ||
3772a991 | 9141 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
92d7f7b0 JS |
9142 | |
9143 | if (ret == IOCB_ERROR) { | |
9144 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
9145 | iocb->fabric_iocb_cmpl = NULL; | |
9146 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
9147 | atomic_dec(&phba->fabric_iocb_count); | |
9148 | } | |
9149 | } else { | |
9150 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9151 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); | |
9152 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9153 | ret = IOCB_SUCCESS; | |
9154 | } | |
9155 | return ret; | |
9156 | } | |
9157 | ||
e59058c4 | 9158 | /** |
3621a710 | 9159 | * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list |
e59058c4 JS |
9160 | * @vport: pointer to a virtual N_Port data structure. |
9161 | * | |
9162 | * This routine aborts all the IOCBs associated with a @vport from the | |
9163 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | |
9164 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | |
9165 | * list, removes each IOCB associated with the @vport off the list, set the | |
9166 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | |
9167 | * associated with the IOCB. | |
9168 | **/ | |
a6ababd2 | 9169 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
92d7f7b0 JS |
9170 | { |
9171 | LIST_HEAD(completions); | |
9172 | struct lpfc_hba *phba = vport->phba; | |
9173 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
92d7f7b0 JS |
9174 | |
9175 | spin_lock_irq(&phba->hbalock); | |
9176 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
9177 | list) { | |
9178 | ||
9179 | if (piocb->vport != vport) | |
9180 | continue; | |
9181 | ||
9182 | list_move_tail(&piocb->list, &completions); | |
9183 | } | |
9184 | spin_unlock_irq(&phba->hbalock); | |
9185 | ||
a257bf90 JS |
9186 | /* Cancel all the IOCBs from the completions list */ |
9187 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9188 | IOERR_SLI_ABORTED); | |
92d7f7b0 JS |
9189 | } |
9190 | ||
e59058c4 | 9191 | /** |
3621a710 | 9192 | * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list |
e59058c4 JS |
9193 | * @ndlp: pointer to a node-list data structure. |
9194 | * | |
9195 | * This routine aborts all the IOCBs associated with an @ndlp from the | |
9196 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | |
9197 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | |
9198 | * list, removes each IOCB associated with the @ndlp off the list, set the | |
9199 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | |
9200 | * associated with the IOCB. | |
9201 | **/ | |
92d7f7b0 JS |
9202 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
9203 | { | |
9204 | LIST_HEAD(completions); | |
a257bf90 | 9205 | struct lpfc_hba *phba = ndlp->phba; |
92d7f7b0 | 9206 | struct lpfc_iocbq *tmp_iocb, *piocb; |
895427bd JS |
9207 | struct lpfc_sli_ring *pring; |
9208 | ||
9209 | pring = lpfc_phba_elsring(phba); | |
92d7f7b0 JS |
9210 | |
9211 | spin_lock_irq(&phba->hbalock); | |
9212 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
9213 | list) { | |
9214 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { | |
9215 | ||
9216 | list_move_tail(&piocb->list, &completions); | |
ed957684 | 9217 | } |
dea3101e | 9218 | } |
92d7f7b0 JS |
9219 | spin_unlock_irq(&phba->hbalock); |
9220 | ||
a257bf90 JS |
9221 | /* Cancel all the IOCBs from the completions list */ |
9222 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9223 | IOERR_SLI_ABORTED); | |
92d7f7b0 JS |
9224 | } |
9225 | ||
e59058c4 | 9226 | /** |
3621a710 | 9227 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
e59058c4 JS |
9228 | * @phba: pointer to lpfc hba data structure. |
9229 | * | |
9230 | * This routine aborts all the IOCBs currently on the driver internal | |
9231 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS | |
9232 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB | |
9233 | * list, removes IOCBs off the list, set the status feild to | |
9234 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with | |
9235 | * the IOCB. | |
9236 | **/ | |
92d7f7b0 JS |
9237 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
9238 | { | |
9239 | LIST_HEAD(completions); | |
92d7f7b0 JS |
9240 | |
9241 | spin_lock_irq(&phba->hbalock); | |
9242 | list_splice_init(&phba->fabric_iocb_list, &completions); | |
9243 | spin_unlock_irq(&phba->hbalock); | |
9244 | ||
a257bf90 JS |
9245 | /* Cancel all the IOCBs from the completions list */ |
9246 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9247 | IOERR_SLI_ABORTED); | |
dea3101e | 9248 | } |
6fb120a7 | 9249 | |
1151e3ec JS |
9250 | /** |
9251 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport | |
9252 | * @vport: pointer to lpfc vport data structure. | |
9253 | * | |
9254 | * This routine is invoked by the vport cleanup for deletions and the cleanup | |
9255 | * for an ndlp on removal. | |
9256 | **/ | |
9257 | void | |
9258 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) | |
9259 | { | |
9260 | struct lpfc_hba *phba = vport->phba; | |
9261 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | |
9262 | unsigned long iflag = 0; | |
9263 | ||
9264 | spin_lock_irqsave(&phba->hbalock, iflag); | |
895427bd | 9265 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
1151e3ec JS |
9266 | list_for_each_entry_safe(sglq_entry, sglq_next, |
9267 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | |
9268 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) | |
9269 | sglq_entry->ndlp = NULL; | |
9270 | } | |
895427bd | 9271 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
1151e3ec JS |
9272 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9273 | return; | |
9274 | } | |
9275 | ||
6fb120a7 JS |
9276 | /** |
9277 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort | |
9278 | * @phba: pointer to lpfc hba data structure. | |
9279 | * @axri: pointer to the els xri abort wcqe structure. | |
9280 | * | |
9281 | * This routine is invoked by the worker thread to process a SLI4 slow-path | |
9282 | * ELS aborted xri. | |
9283 | **/ | |
9284 | void | |
9285 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, | |
9286 | struct sli4_wcqe_xri_aborted *axri) | |
9287 | { | |
9288 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | |
19ca7609 | 9289 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
7851fe2c | 9290 | uint16_t lxri = 0; |
19ca7609 | 9291 | |
6fb120a7 JS |
9292 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
9293 | unsigned long iflag = 0; | |
19ca7609 | 9294 | struct lpfc_nodelist *ndlp; |
895427bd JS |
9295 | struct lpfc_sli_ring *pring; |
9296 | ||
9297 | pring = lpfc_phba_elsring(phba); | |
6fb120a7 | 9298 | |
0f65ff68 | 9299 | spin_lock_irqsave(&phba->hbalock, iflag); |
895427bd | 9300 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
6fb120a7 JS |
9301 | list_for_each_entry_safe(sglq_entry, sglq_next, |
9302 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | |
9303 | if (sglq_entry->sli4_xritag == xri) { | |
9304 | list_del(&sglq_entry->list); | |
19ca7609 JS |
9305 | ndlp = sglq_entry->ndlp; |
9306 | sglq_entry->ndlp = NULL; | |
6fb120a7 | 9307 | list_add_tail(&sglq_entry->list, |
895427bd | 9308 | &phba->sli4_hba.lpfc_els_sgl_list); |
0f65ff68 | 9309 | sglq_entry->state = SGL_FREED; |
895427bd | 9310 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
6fb120a7 | 9311 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
ee0f4fe1 JS |
9312 | lpfc_set_rrq_active(phba, ndlp, |
9313 | sglq_entry->sli4_lxritag, | |
9314 | rxid, 1); | |
589a52d6 JS |
9315 | |
9316 | /* Check if TXQ queue needs to be serviced */ | |
0e9bb8d7 | 9317 | if (!(list_empty(&pring->txq))) |
589a52d6 | 9318 | lpfc_worker_wake_up(phba); |
6fb120a7 JS |
9319 | return; |
9320 | } | |
9321 | } | |
895427bd | 9322 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
7851fe2c JS |
9323 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
9324 | if (lxri == NO_XRI) { | |
9325 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9326 | return; | |
9327 | } | |
895427bd | 9328 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
7851fe2c | 9329 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
0f65ff68 | 9330 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
895427bd | 9331 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
0f65ff68 JS |
9332 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9333 | return; | |
9334 | } | |
9335 | sglq_entry->state = SGL_XRI_ABORTED; | |
895427bd | 9336 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
0f65ff68 JS |
9337 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9338 | return; | |
6fb120a7 | 9339 | } |
086a345f JS |
9340 | |
9341 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. | |
9342 | * @vport: pointer to virtual port object. | |
9343 | * @ndlp: nodelist pointer for the impacted node. | |
9344 | * | |
9345 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE | |
9346 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, | |
9347 | * the driver is required to send a LOGO to the remote node before it | |
9348 | * attempts to recover its login to the remote node. | |
9349 | */ | |
9350 | void | |
9351 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, | |
9352 | struct lpfc_nodelist *ndlp) | |
9353 | { | |
9354 | struct Scsi_Host *shost; | |
9355 | struct lpfc_hba *phba; | |
9356 | unsigned long flags = 0; | |
9357 | ||
9358 | shost = lpfc_shost_from_vport(vport); | |
9359 | phba = vport->phba; | |
9360 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { | |
9361 | lpfc_printf_log(phba, KERN_INFO, | |
9362 | LOG_SLI, "3093 No rport recovery needed. " | |
9363 | "rport in state 0x%x\n", ndlp->nlp_state); | |
9364 | return; | |
9365 | } | |
9366 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9367 | "3094 Start rport recovery on shost id 0x%x " | |
9368 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " | |
9369 | "flags 0x%x\n", | |
9370 | shost->host_no, ndlp->nlp_DID, | |
9371 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, | |
9372 | ndlp->nlp_flag); | |
9373 | /* | |
9374 | * The rport is not responding. Remove the FCP-2 flag to prevent | |
9375 | * an ADISC in the follow-up recovery code. | |
9376 | */ | |
9377 | spin_lock_irqsave(shost->host_lock, flags); | |
9378 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
9379 | spin_unlock_irqrestore(shost->host_lock, flags); | |
9380 | lpfc_issue_els_logo(vport, ndlp, 0); | |
9381 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); | |
9382 | } | |
9383 |