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