]>
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. * |
f25e8e79 | 4 | * Copyright (C) 2004-2015 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 | ||
e74c03c8 | 32 | |
da0436e9 | 33 | #include "lpfc_hw4.h" |
dea3101e JB |
34 | #include "lpfc_hw.h" |
35 | #include "lpfc_sli.h" | |
da0436e9 | 36 | #include "lpfc_sli4.h" |
ea2151b4 | 37 | #include "lpfc_nl.h" |
dea3101e JB |
38 | #include "lpfc_disc.h" |
39 | #include "lpfc_scsi.h" | |
40 | #include "lpfc.h" | |
41 | #include "lpfc_logmsg.h" | |
42 | #include "lpfc_crtn.h" | |
92d7f7b0 | 43 | #include "lpfc_vport.h" |
858c9f6c | 44 | #include "lpfc_debugfs.h" |
dea3101e JB |
45 | |
46 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, | |
47 | struct lpfc_iocbq *); | |
92d7f7b0 JS |
48 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
49 | struct lpfc_iocbq *); | |
a6ababd2 AB |
50 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
51 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, | |
52 | struct lpfc_nodelist *ndlp, uint8_t retry); | |
53 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, | |
54 | struct lpfc_iocbq *iocb); | |
92d7f7b0 | 55 | |
dea3101e JB |
56 | static int lpfc_max_els_tries = 3; |
57 | ||
e59058c4 | 58 | /** |
3621a710 | 59 | * lpfc_els_chk_latt - Check host link attention event for a vport |
e59058c4 JS |
60 | * @vport: pointer to a host virtual N_Port data structure. |
61 | * | |
62 | * This routine checks whether there is an outstanding host link | |
63 | * attention event during the discovery process with the @vport. It is done | |
64 | * by reading the HBA's Host Attention (HA) register. If there is any host | |
65 | * link attention events during this @vport's discovery process, the @vport | |
66 | * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall | |
67 | * be issued if the link state is not already in host link cleared state, | |
68 | * and a return code shall indicate whether the host link attention event | |
69 | * had happened. | |
70 | * | |
71 | * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport | |
72 | * state in LPFC_VPORT_READY, the request for checking host link attention | |
73 | * event will be ignored and a return code shall indicate no host link | |
74 | * attention event had happened. | |
75 | * | |
76 | * Return codes | |
77 | * 0 - no host link attention event happened | |
78 | * 1 - host link attention event happened | |
79 | **/ | |
858c9f6c | 80 | int |
2e0fef85 | 81 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
dea3101e | 82 | { |
2e0fef85 JS |
83 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
84 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 85 | uint32_t ha_copy; |
dea3101e | 86 | |
2e0fef85 | 87 | if (vport->port_state >= LPFC_VPORT_READY || |
3772a991 JS |
88 | phba->link_state == LPFC_LINK_DOWN || |
89 | phba->sli_rev > LPFC_SLI_REV3) | |
dea3101e JB |
90 | return 0; |
91 | ||
92 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
93 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
94 | return 1; | |
dea3101e JB |
95 | |
96 | if (!(ha_copy & HA_LATT)) | |
97 | return 0; | |
98 | ||
99 | /* Pending Link Event during Discovery */ | |
e8b62011 JS |
100 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
101 | "0237 Pending Link Event during " | |
102 | "Discovery: State x%x\n", | |
103 | phba->pport->port_state); | |
dea3101e JB |
104 | |
105 | /* CLEAR_LA should re-enable link attention events and | |
25985edc | 106 | * we should then immediately take a LATT event. The |
dea3101e JB |
107 | * LATT processing should call lpfc_linkdown() which |
108 | * will cleanup any left over in-progress discovery | |
109 | * events. | |
110 | */ | |
2e0fef85 JS |
111 | spin_lock_irq(shost->host_lock); |
112 | vport->fc_flag |= FC_ABORT_DISCOVERY; | |
113 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 114 | |
92d7f7b0 | 115 | if (phba->link_state != LPFC_CLEAR_LA) |
ed957684 | 116 | lpfc_issue_clear_la(phba, vport); |
dea3101e | 117 | |
c9f8735b | 118 | return 1; |
dea3101e JB |
119 | } |
120 | ||
e59058c4 | 121 | /** |
3621a710 | 122 | * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure |
e59058c4 JS |
123 | * @vport: pointer to a host virtual N_Port data structure. |
124 | * @expectRsp: flag indicating whether response is expected. | |
125 | * @cmdSize: size of the ELS command. | |
126 | * @retry: number of retries to the command IOCB when it fails. | |
127 | * @ndlp: pointer to a node-list data structure. | |
128 | * @did: destination identifier. | |
129 | * @elscmd: the ELS command code. | |
130 | * | |
131 | * This routine is used for allocating a lpfc-IOCB data structure from | |
132 | * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters | |
133 | * passed into the routine for discovery state machine to issue an Extended | |
134 | * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation | |
135 | * and preparation routine that is used by all the discovery state machine | |
136 | * routines and the ELS command-specific fields will be later set up by | |
137 | * the individual discovery machine routines after calling this routine | |
138 | * allocating and preparing a generic IOCB data structure. It fills in the | |
139 | * Buffer Descriptor Entries (BDEs), allocates buffers for both command | |
140 | * payload and response payload (if expected). The reference count on the | |
141 | * ndlp is incremented by 1 and the reference to the ndlp is put into | |
142 | * context1 of the IOCB data structure for this IOCB to hold the ndlp | |
143 | * reference for the command's callback function to access later. | |
144 | * | |
145 | * Return code | |
146 | * Pointer to the newly allocated/prepared els iocb data structure | |
147 | * NULL - when els iocb data structure allocation/preparation failed | |
148 | **/ | |
f1c3b0fc | 149 | struct lpfc_iocbq * |
2e0fef85 JS |
150 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
151 | uint16_t cmdSize, uint8_t retry, | |
152 | struct lpfc_nodelist *ndlp, uint32_t did, | |
153 | uint32_t elscmd) | |
dea3101e | 154 | { |
2e0fef85 | 155 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 | 156 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
157 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
158 | struct ulp_bde64 *bpl; | |
159 | IOCB_t *icmd; | |
160 | ||
dea3101e | 161 | |
2e0fef85 JS |
162 | if (!lpfc_is_link_up(phba)) |
163 | return NULL; | |
dea3101e | 164 | |
dea3101e | 165 | /* Allocate buffer for command iocb */ |
0bd4ca25 | 166 | elsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
167 | |
168 | if (elsiocb == NULL) | |
169 | return NULL; | |
e47c9093 | 170 | |
0c287589 JS |
171 | /* |
172 | * If this command is for fabric controller and HBA running | |
173 | * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. | |
174 | */ | |
175 | if ((did == Fabric_DID) && | |
45ed1190 | 176 | (phba->hba_flag & HBA_FIP_SUPPORT) && |
0c287589 JS |
177 | ((elscmd == ELS_CMD_FLOGI) || |
178 | (elscmd == ELS_CMD_FDISC) || | |
179 | (elscmd == ELS_CMD_LOGO))) | |
c868595d JS |
180 | switch (elscmd) { |
181 | case ELS_CMD_FLOGI: | |
f0d9bccc JS |
182 | elsiocb->iocb_flag |= |
183 | ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
184 | & LPFC_FIP_ELS_ID_MASK); |
185 | break; | |
186 | case ELS_CMD_FDISC: | |
f0d9bccc JS |
187 | elsiocb->iocb_flag |= |
188 | ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
189 | & LPFC_FIP_ELS_ID_MASK); |
190 | break; | |
191 | case ELS_CMD_LOGO: | |
f0d9bccc JS |
192 | elsiocb->iocb_flag |= |
193 | ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) | |
c868595d JS |
194 | & LPFC_FIP_ELS_ID_MASK); |
195 | break; | |
196 | } | |
0c287589 | 197 | else |
c868595d | 198 | elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
0c287589 | 199 | |
dea3101e JB |
200 | icmd = &elsiocb->iocb; |
201 | ||
202 | /* fill in BDEs for command */ | |
203 | /* Allocate buffer for command payload */ | |
98c9ea5c JS |
204 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
205 | if (pcmd) | |
206 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); | |
fa4066b6 JS |
207 | if (!pcmd || !pcmd->virt) |
208 | goto els_iocb_free_pcmb_exit; | |
dea3101e JB |
209 | |
210 | INIT_LIST_HEAD(&pcmd->list); | |
211 | ||
212 | /* Allocate buffer for response payload */ | |
213 | if (expectRsp) { | |
92d7f7b0 | 214 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e JB |
215 | if (prsp) |
216 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
217 | &prsp->phys); | |
fa4066b6 JS |
218 | if (!prsp || !prsp->virt) |
219 | goto els_iocb_free_prsp_exit; | |
dea3101e | 220 | INIT_LIST_HEAD(&prsp->list); |
e47c9093 | 221 | } else |
dea3101e | 222 | prsp = NULL; |
dea3101e JB |
223 | |
224 | /* Allocate buffer for Buffer ptr list */ | |
92d7f7b0 | 225 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e | 226 | if (pbuflist) |
ed957684 JS |
227 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
228 | &pbuflist->phys); | |
fa4066b6 JS |
229 | if (!pbuflist || !pbuflist->virt) |
230 | goto els_iocb_free_pbuf_exit; | |
dea3101e JB |
231 | |
232 | INIT_LIST_HEAD(&pbuflist->list); | |
233 | ||
dea3101e | 234 | if (expectRsp) { |
939723a4 JS |
235 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
236 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | |
237 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
92d7f7b0 | 238 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
939723a4 JS |
239 | |
240 | icmd->un.elsreq64.remoteID = did; /* DID */ | |
dea3101e | 241 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
88f43a08 JS |
242 | if (elscmd == ELS_CMD_FLOGI) |
243 | icmd->ulpTimeout = FF_DEF_RATOV * 2; | |
244 | else | |
245 | icmd->ulpTimeout = phba->fc_ratov * 2; | |
dea3101e | 246 | } else { |
939723a4 JS |
247 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
248 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | |
249 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
250 | icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64); | |
251 | icmd->un.xseq64.xmit_els_remoteID = did; /* DID */ | |
dea3101e JB |
252 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
253 | } | |
dea3101e JB |
254 | icmd->ulpBdeCount = 1; |
255 | icmd->ulpLe = 1; | |
256 | icmd->ulpClass = CLASS3; | |
257 | ||
939723a4 JS |
258 | /* |
259 | * If we have NPIV enabled, we want to send ELS traffic by VPI. | |
260 | * For SLI4, since the driver controls VPIs we also want to include | |
261 | * all ELS pt2pt protocol traffic as well. | |
262 | */ | |
263 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) || | |
264 | ((phba->sli_rev == LPFC_SLI_REV4) && | |
265 | (vport->fc_flag & FC_PT2PT))) { | |
266 | ||
267 | if (expectRsp) { | |
268 | icmd->un.elsreq64.myID = vport->fc_myDID; | |
269 | ||
270 | /* For ELS_REQUEST64_CR, use the VPI by default */ | |
271 | icmd->ulpContext = phba->vpi_ids[vport->vpi]; | |
272 | } | |
92d7f7b0 | 273 | |
92d7f7b0 | 274 | icmd->ulpCt_h = 0; |
eada272d JS |
275 | /* The CT field must be 0=INVALID_RPI for the ECHO cmd */ |
276 | if (elscmd == ELS_CMD_ECHO) | |
277 | icmd->ulpCt_l = 0; /* context = invalid RPI */ | |
278 | else | |
279 | icmd->ulpCt_l = 1; /* context = VPI */ | |
92d7f7b0 JS |
280 | } |
281 | ||
dea3101e JB |
282 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
283 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); | |
284 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); | |
285 | bpl->tus.f.bdeSize = cmdSize; | |
286 | bpl->tus.f.bdeFlags = 0; | |
287 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
288 | ||
289 | if (expectRsp) { | |
290 | bpl++; | |
291 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); | |
292 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); | |
293 | bpl->tus.f.bdeSize = FCELSSIZE; | |
34b02dcd | 294 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
dea3101e JB |
295 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
296 | } | |
297 | ||
fa4066b6 | 298 | /* prevent preparing iocb with NULL ndlp reference */ |
51ef4c26 | 299 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
fa4066b6 JS |
300 | if (!elsiocb->context1) |
301 | goto els_iocb_free_pbuf_exit; | |
329f9bc7 JS |
302 | elsiocb->context2 = pcmd; |
303 | elsiocb->context3 = pbuflist; | |
dea3101e | 304 | elsiocb->retry = retry; |
2e0fef85 | 305 | elsiocb->vport = vport; |
dea3101e JB |
306 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
307 | ||
308 | if (prsp) { | |
309 | list_add(&prsp->list, &pcmd->list); | |
310 | } | |
dea3101e JB |
311 | if (expectRsp) { |
312 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
313 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
314 | "0116 Xmit ELS command x%x to remote " | |
e74c03c8 JS |
315 | "NPORT x%x I/O tag: x%x, port state:x%x" |
316 | " fc_flag:x%x\n", | |
e8b62011 | 317 | elscmd, did, elsiocb->iotag, |
e74c03c8 JS |
318 | vport->port_state, |
319 | vport->fc_flag); | |
dea3101e JB |
320 | } else { |
321 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
322 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
323 | "0117 Xmit ELS response x%x to remote " | |
e74c03c8 JS |
324 | "NPORT x%x I/O tag: x%x, size: x%x " |
325 | "port_state x%x fc_flag x%x\n", | |
e8b62011 | 326 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
e74c03c8 JS |
327 | cmdSize, vport->port_state, |
328 | vport->fc_flag); | |
dea3101e | 329 | } |
c9f8735b | 330 | return elsiocb; |
dea3101e | 331 | |
fa4066b6 | 332 | els_iocb_free_pbuf_exit: |
eaf15d5b JS |
333 | if (expectRsp) |
334 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | |
fa4066b6 JS |
335 | kfree(pbuflist); |
336 | ||
337 | els_iocb_free_prsp_exit: | |
338 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); | |
339 | kfree(prsp); | |
340 | ||
341 | els_iocb_free_pcmb_exit: | |
342 | kfree(pcmd); | |
343 | lpfc_sli_release_iocbq(phba, elsiocb); | |
344 | return NULL; | |
345 | } | |
dea3101e | 346 | |
e59058c4 | 347 | /** |
3621a710 | 348 | * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport |
e59058c4 JS |
349 | * @vport: pointer to a host virtual N_Port data structure. |
350 | * | |
351 | * This routine issues a fabric registration login for a @vport. An | |
352 | * active ndlp node with Fabric_DID must already exist for this @vport. | |
353 | * The routine invokes two mailbox commands to carry out fabric registration | |
354 | * login through the HBA firmware: the first mailbox command requests the | |
355 | * HBA to perform link configuration for the @vport; and the second mailbox | |
356 | * command requests the HBA to perform the actual fabric registration login | |
357 | * with the @vport. | |
358 | * | |
359 | * Return code | |
360 | * 0 - successfully issued fabric registration login for @vport | |
361 | * -ENXIO -- failed to issue fabric registration login for @vport | |
362 | **/ | |
3772a991 | 363 | int |
92d7f7b0 | 364 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
dea3101e | 365 | { |
2e0fef85 | 366 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 367 | LPFC_MBOXQ_t *mbox; |
14691150 | 368 | struct lpfc_dmabuf *mp; |
92d7f7b0 JS |
369 | struct lpfc_nodelist *ndlp; |
370 | struct serv_parm *sp; | |
dea3101e | 371 | int rc; |
98c9ea5c | 372 | int err = 0; |
dea3101e | 373 | |
92d7f7b0 JS |
374 | sp = &phba->fc_fabparam; |
375 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
e47c9093 | 376 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
98c9ea5c | 377 | err = 1; |
92d7f7b0 | 378 | goto fail; |
98c9ea5c | 379 | } |
92d7f7b0 JS |
380 | |
381 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
382 | if (!mbox) { |
383 | err = 2; | |
92d7f7b0 | 384 | goto fail; |
98c9ea5c | 385 | } |
92d7f7b0 JS |
386 | |
387 | vport->port_state = LPFC_FABRIC_CFG_LINK; | |
388 | lpfc_config_link(phba, mbox); | |
389 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
390 | mbox->vport = vport; | |
391 | ||
0b727fea | 392 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
393 | if (rc == MBX_NOT_FINISHED) { |
394 | err = 3; | |
92d7f7b0 | 395 | goto fail_free_mbox; |
98c9ea5c | 396 | } |
92d7f7b0 JS |
397 | |
398 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
399 | if (!mbox) { |
400 | err = 4; | |
92d7f7b0 | 401 | goto fail; |
98c9ea5c | 402 | } |
4042629e JS |
403 | rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
404 | ndlp->nlp_rpi); | |
98c9ea5c JS |
405 | if (rc) { |
406 | err = 5; | |
92d7f7b0 | 407 | goto fail_free_mbox; |
98c9ea5c | 408 | } |
92d7f7b0 JS |
409 | |
410 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; | |
411 | mbox->vport = vport; | |
e47c9093 JS |
412 | /* increment the reference count on ndlp to hold reference |
413 | * for the callback routine. | |
414 | */ | |
92d7f7b0 JS |
415 | mbox->context2 = lpfc_nlp_get(ndlp); |
416 | ||
0b727fea | 417 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
418 | if (rc == MBX_NOT_FINISHED) { |
419 | err = 6; | |
92d7f7b0 | 420 | goto fail_issue_reg_login; |
98c9ea5c | 421 | } |
92d7f7b0 JS |
422 | |
423 | return 0; | |
424 | ||
425 | fail_issue_reg_login: | |
e47c9093 JS |
426 | /* decrement the reference count on ndlp just incremented |
427 | * for the failed mbox command. | |
428 | */ | |
92d7f7b0 JS |
429 | lpfc_nlp_put(ndlp); |
430 | mp = (struct lpfc_dmabuf *) mbox->context1; | |
431 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
432 | kfree(mp); | |
433 | fail_free_mbox: | |
434 | mempool_free(mbox, phba->mbox_mem_pool); | |
435 | ||
436 | fail: | |
437 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 | 438 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
98c9ea5c | 439 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
92d7f7b0 JS |
440 | return -ENXIO; |
441 | } | |
442 | ||
6fb120a7 JS |
443 | /** |
444 | * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login | |
445 | * @vport: pointer to a host virtual N_Port data structure. | |
446 | * | |
447 | * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for | |
1b51197d | 448 | * the @vport. This mailbox command is necessary for SLI4 port only. |
6fb120a7 JS |
449 | * |
450 | * Return code | |
451 | * 0 - successfully issued REG_VFI for @vport | |
452 | * A failure code otherwise. | |
453 | **/ | |
1b51197d | 454 | int |
6fb120a7 JS |
455 | lpfc_issue_reg_vfi(struct lpfc_vport *vport) |
456 | { | |
457 | struct lpfc_hba *phba = vport->phba; | |
d6de08cc | 458 | LPFC_MBOXQ_t *mboxq = NULL; |
6fb120a7 | 459 | struct lpfc_nodelist *ndlp; |
d6de08cc | 460 | struct lpfc_dmabuf *dmabuf = NULL; |
6fb120a7 JS |
461 | int rc = 0; |
462 | ||
939723a4 | 463 | /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ |
1b51197d | 464 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
939723a4 JS |
465 | !(phba->link_flag & LS_LOOPBACK_MODE) && |
466 | !(vport->fc_flag & FC_PT2PT)) { | |
1b51197d JS |
467 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
468 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { | |
469 | rc = -ENODEV; | |
470 | goto fail; | |
471 | } | |
6fb120a7 JS |
472 | } |
473 | ||
d6de08cc JS |
474 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
475 | if (!mboxq) { | |
6fb120a7 JS |
476 | rc = -ENOMEM; |
477 | goto fail; | |
478 | } | |
6d368e53 | 479 | |
d6de08cc JS |
480 | /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ |
481 | if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) { | |
482 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
483 | if (!dmabuf) { | |
484 | rc = -ENOMEM; | |
485 | goto fail; | |
486 | } | |
487 | dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys); | |
488 | if (!dmabuf->virt) { | |
489 | rc = -ENOMEM; | |
490 | goto fail; | |
491 | } | |
492 | memcpy(dmabuf->virt, &phba->fc_fabparam, | |
493 | sizeof(struct serv_parm)); | |
6fb120a7 | 494 | } |
d6de08cc | 495 | |
6fb120a7 | 496 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
d6de08cc JS |
497 | if (dmabuf) |
498 | lpfc_reg_vfi(mboxq, vport, dmabuf->phys); | |
499 | else | |
500 | lpfc_reg_vfi(mboxq, vport, 0); | |
ae05ebe3 | 501 | |
6fb120a7 JS |
502 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; |
503 | mboxq->vport = vport; | |
504 | mboxq->context1 = dmabuf; | |
505 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
506 | if (rc == MBX_NOT_FINISHED) { | |
507 | rc = -ENXIO; | |
d6de08cc | 508 | goto fail; |
6fb120a7 JS |
509 | } |
510 | return 0; | |
511 | ||
6fb120a7 | 512 | fail: |
d6de08cc JS |
513 | if (mboxq) |
514 | mempool_free(mboxq, phba->mbox_mem_pool); | |
515 | if (dmabuf) { | |
516 | if (dmabuf->virt) | |
517 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | |
518 | kfree(dmabuf); | |
519 | } | |
520 | ||
6fb120a7 JS |
521 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
522 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
523 | "0289 Issue Register VFI failed: Err %d\n", rc); | |
524 | return rc; | |
525 | } | |
526 | ||
1b51197d JS |
527 | /** |
528 | * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login | |
529 | * @vport: pointer to a host virtual N_Port data structure. | |
530 | * | |
531 | * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for | |
532 | * the @vport. This mailbox command is necessary for SLI4 port only. | |
533 | * | |
534 | * Return code | |
535 | * 0 - successfully issued REG_VFI for @vport | |
536 | * A failure code otherwise. | |
537 | **/ | |
538 | int | |
539 | lpfc_issue_unreg_vfi(struct lpfc_vport *vport) | |
540 | { | |
541 | struct lpfc_hba *phba = vport->phba; | |
542 | struct Scsi_Host *shost; | |
543 | LPFC_MBOXQ_t *mboxq; | |
544 | int rc; | |
545 | ||
546 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
547 | if (!mboxq) { | |
548 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
549 | "2556 UNREG_VFI mbox allocation failed" | |
550 | "HBA state x%x\n", phba->pport->port_state); | |
551 | return -ENOMEM; | |
552 | } | |
553 | ||
554 | lpfc_unreg_vfi(mboxq, vport); | |
555 | mboxq->vport = vport; | |
556 | mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; | |
557 | ||
558 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
559 | if (rc == MBX_NOT_FINISHED) { | |
560 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
561 | "2557 UNREG_VFI issue mbox failed rc x%x " | |
562 | "HBA state x%x\n", | |
563 | rc, phba->pport->port_state); | |
564 | mempool_free(mboxq, phba->mbox_mem_pool); | |
565 | return -EIO; | |
566 | } | |
567 | ||
568 | shost = lpfc_shost_from_vport(vport); | |
569 | spin_lock_irq(shost->host_lock); | |
570 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
571 | spin_unlock_irq(shost->host_lock); | |
572 | return 0; | |
573 | } | |
574 | ||
92494144 JS |
575 | /** |
576 | * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. | |
577 | * @vport: pointer to a host virtual N_Port data structure. | |
578 | * @sp: pointer to service parameter data structure. | |
579 | * | |
580 | * This routine is called from FLOGI/FDISC completion handler functions. | |
581 | * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric | |
582 | * node nodename is changed in the completion service parameter else return | |
583 | * 0. This function also set flag in the vport data structure to delay | |
584 | * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit | |
585 | * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric | |
586 | * node nodename is changed in the completion service parameter. | |
587 | * | |
588 | * Return code | |
589 | * 0 - FCID and Fabric Nodename and Fabric portname is not changed. | |
590 | * 1 - FCID or Fabric Nodename or Fabric portname is changed. | |
591 | * | |
592 | **/ | |
593 | static uint8_t | |
594 | lpfc_check_clean_addr_bit(struct lpfc_vport *vport, | |
595 | struct serv_parm *sp) | |
596 | { | |
597 | uint8_t fabric_param_changed = 0; | |
598 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
599 | ||
600 | if ((vport->fc_prevDID != vport->fc_myDID) || | |
601 | memcmp(&vport->fabric_portname, &sp->portName, | |
602 | sizeof(struct lpfc_name)) || | |
603 | memcmp(&vport->fabric_nodename, &sp->nodeName, | |
604 | sizeof(struct lpfc_name))) | |
605 | fabric_param_changed = 1; | |
606 | ||
607 | /* | |
608 | * Word 1 Bit 31 in common service parameter is overloaded. | |
609 | * Word 1 Bit 31 in FLOGI request is multiple NPort request | |
610 | * Word 1 Bit 31 in FLOGI response is clean address bit | |
611 | * | |
612 | * If fabric parameter is changed and clean address bit is | |
613 | * cleared delay nport discovery if | |
614 | * - vport->fc_prevDID != 0 (not initial discovery) OR | |
615 | * - lpfc_delay_discovery module parameter is set. | |
616 | */ | |
617 | if (fabric_param_changed && !sp->cmn.clean_address_bit && | |
618 | (vport->fc_prevDID || lpfc_delay_discovery)) { | |
619 | spin_lock_irq(shost->host_lock); | |
620 | vport->fc_flag |= FC_DISC_DELAYED; | |
621 | spin_unlock_irq(shost->host_lock); | |
622 | } | |
623 | ||
624 | return fabric_param_changed; | |
625 | } | |
626 | ||
627 | ||
e59058c4 | 628 | /** |
3621a710 | 629 | * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port |
e59058c4 JS |
630 | * @vport: pointer to a host virtual N_Port data structure. |
631 | * @ndlp: pointer to a node-list data structure. | |
632 | * @sp: pointer to service parameter data structure. | |
633 | * @irsp: pointer to the IOCB within the lpfc response IOCB. | |
634 | * | |
635 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | |
636 | * function to handle the completion of a Fabric Login (FLOGI) into a fabric | |
637 | * port in a fabric topology. It properly sets up the parameters to the @ndlp | |
638 | * from the IOCB response. It also check the newly assigned N_Port ID to the | |
639 | * @vport against the previously assigned N_Port ID. If it is different from | |
640 | * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine | |
641 | * is invoked on all the remaining nodes with the @vport to unregister the | |
642 | * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() | |
643 | * is invoked to register login to the fabric. | |
644 | * | |
645 | * Return code | |
646 | * 0 - Success (currently, always return 0) | |
647 | **/ | |
92d7f7b0 JS |
648 | static int |
649 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
650 | struct serv_parm *sp, IOCB_t *irsp) | |
651 | { | |
652 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
653 | struct lpfc_hba *phba = vport->phba; | |
654 | struct lpfc_nodelist *np; | |
655 | struct lpfc_nodelist *next_np; | |
92494144 | 656 | uint8_t fabric_param_changed; |
92d7f7b0 | 657 | |
2e0fef85 JS |
658 | spin_lock_irq(shost->host_lock); |
659 | vport->fc_flag |= FC_FABRIC; | |
660 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
661 | |
662 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); | |
663 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ | |
664 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; | |
665 | ||
12265f68 | 666 | phba->fc_edtovResol = sp->cmn.edtovResolution; |
dea3101e JB |
667 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
668 | ||
76a95d75 | 669 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 JS |
670 | spin_lock_irq(shost->host_lock); |
671 | vport->fc_flag |= FC_PUBLIC_LOOP; | |
672 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
673 | } |
674 | ||
2e0fef85 | 675 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
dea3101e | 676 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
92d7f7b0 | 677 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
dea3101e JB |
678 | ndlp->nlp_class_sup = 0; |
679 | if (sp->cls1.classValid) | |
680 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
681 | if (sp->cls2.classValid) | |
682 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
683 | if (sp->cls3.classValid) | |
684 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
685 | if (sp->cls4.classValid) | |
686 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
687 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | | |
688 | sp->cmn.bbRcvSizeLsb; | |
92494144 JS |
689 | |
690 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | |
691 | memcpy(&vport->fabric_portname, &sp->portName, | |
692 | sizeof(struct lpfc_name)); | |
693 | memcpy(&vport->fabric_nodename, &sp->nodeName, | |
694 | sizeof(struct lpfc_name)); | |
dea3101e JB |
695 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
696 | ||
92d7f7b0 JS |
697 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
698 | if (sp->cmn.response_multiple_NPort) { | |
e8b62011 JS |
699 | lpfc_printf_vlog(vport, KERN_WARNING, |
700 | LOG_ELS | LOG_VPORT, | |
701 | "1816 FLOGI NPIV supported, " | |
702 | "response data 0x%x\n", | |
703 | sp->cmn.response_multiple_NPort); | |
1b51197d | 704 | spin_lock_irq(&phba->hbalock); |
92d7f7b0 | 705 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
1b51197d | 706 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 JS |
707 | } else { |
708 | /* Because we asked f/w for NPIV it still expects us | |
e8b62011 JS |
709 | to call reg_vnpid atleast for the physcial host */ |
710 | lpfc_printf_vlog(vport, KERN_WARNING, | |
711 | LOG_ELS | LOG_VPORT, | |
712 | "1817 Fabric does not support NPIV " | |
713 | "- configuring single port mode.\n"); | |
1b51197d | 714 | spin_lock_irq(&phba->hbalock); |
92d7f7b0 | 715 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
1b51197d | 716 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 JS |
717 | } |
718 | } | |
dea3101e | 719 | |
ae05ebe3 JS |
720 | /* |
721 | * For FC we need to do some special processing because of the SLI | |
722 | * Port's default settings of the Common Service Parameters. | |
723 | */ | |
d6de08cc JS |
724 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
725 | (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { | |
ae05ebe3 | 726 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
d6de08cc | 727 | if (fabric_param_changed) |
ae05ebe3 JS |
728 | lpfc_unregister_fcf_prep(phba); |
729 | ||
730 | /* This should just update the VFI CSPs*/ | |
731 | if (vport->fc_flag & FC_VFI_REGISTERED) | |
732 | lpfc_issue_reg_vfi(vport); | |
733 | } | |
734 | ||
92494144 | 735 | if (fabric_param_changed && |
92d7f7b0 | 736 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
dea3101e | 737 | |
92d7f7b0 JS |
738 | /* If our NportID changed, we need to ensure all |
739 | * remaining NPORTs get unreg_login'ed. | |
740 | */ | |
741 | list_for_each_entry_safe(np, next_np, | |
742 | &vport->fc_nodes, nlp_listp) { | |
d7c255b2 | 743 | if (!NLP_CHK_NODE_ACT(np)) |
e47c9093 | 744 | continue; |
92d7f7b0 JS |
745 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
746 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
747 | continue; | |
748 | spin_lock_irq(shost->host_lock); | |
749 | np->nlp_flag &= ~NLP_NPR_ADISC; | |
750 | spin_unlock_irq(shost->host_lock); | |
751 | lpfc_unreg_rpi(vport, np); | |
752 | } | |
78730cfe | 753 | lpfc_cleanup_pending_mbox(vport); |
5af5eee7 | 754 | |
5248a749 | 755 | if (phba->sli_rev == LPFC_SLI_REV4) { |
5af5eee7 | 756 | lpfc_sli4_unreg_all_rpis(vport); |
92d7f7b0 | 757 | lpfc_mbx_unreg_vpi(vport); |
09372820 | 758 | spin_lock_irq(shost->host_lock); |
ecfd03c6 JS |
759 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
760 | spin_unlock_irq(shost->host_lock); | |
761 | } | |
27aa1b73 JS |
762 | |
763 | /* | |
764 | * For SLI3 and SLI4, the VPI needs to be reregistered in | |
765 | * response to this fabric parameter change event. | |
766 | */ | |
767 | spin_lock_irq(shost->host_lock); | |
768 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
769 | spin_unlock_irq(shost->host_lock); | |
38b92ef8 JS |
770 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
771 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
772 | /* | |
773 | * Driver needs to re-reg VPI in order for f/w | |
774 | * to update the MAC address. | |
775 | */ | |
9589b062 | 776 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
38b92ef8 JS |
777 | lpfc_register_new_vport(phba, vport, ndlp); |
778 | return 0; | |
92d7f7b0 | 779 | } |
dea3101e | 780 | |
6fb120a7 JS |
781 | if (phba->sli_rev < LPFC_SLI_REV4) { |
782 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); | |
783 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && | |
784 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | |
785 | lpfc_register_new_vport(phba, vport, ndlp); | |
786 | else | |
787 | lpfc_issue_fabric_reglogin(vport); | |
788 | } else { | |
789 | ndlp->nlp_type |= NLP_FABRIC; | |
790 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | |
695a814e JS |
791 | if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) && |
792 | (vport->vpi_state & LPFC_VPI_REGISTERED)) { | |
6fb120a7 JS |
793 | lpfc_start_fdiscs(phba); |
794 | lpfc_do_scr_ns_plogi(phba, vport); | |
695a814e | 795 | } else if (vport->fc_flag & FC_VFI_REGISTERED) |
ecfd03c6 | 796 | lpfc_issue_init_vpi(vport); |
1b51197d JS |
797 | else { |
798 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
799 | "3135 Need register VFI: (x%x/%x)\n", | |
800 | vport->fc_prevDID, vport->fc_myDID); | |
6fb120a7 | 801 | lpfc_issue_reg_vfi(vport); |
1b51197d | 802 | } |
92d7f7b0 | 803 | } |
dea3101e | 804 | return 0; |
dea3101e | 805 | } |
1b51197d | 806 | |
e59058c4 | 807 | /** |
3621a710 | 808 | * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port |
e59058c4 JS |
809 | * @vport: pointer to a host virtual N_Port data structure. |
810 | * @ndlp: pointer to a node-list data structure. | |
811 | * @sp: pointer to service parameter data structure. | |
812 | * | |
813 | * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback | |
814 | * function to handle the completion of a Fabric Login (FLOGI) into an N_Port | |
815 | * in a point-to-point topology. First, the @vport's N_Port Name is compared | |
816 | * with the received N_Port Name: if the @vport's N_Port Name is greater than | |
817 | * the received N_Port Name lexicographically, this node shall assign local | |
818 | * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and | |
819 | * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, | |
820 | * this node shall just wait for the remote node to issue PLOGI and assign | |
821 | * N_Port IDs. | |
822 | * | |
823 | * Return code | |
824 | * 0 - Success | |
825 | * -ENXIO - Fail | |
826 | **/ | |
dea3101e | 827 | static int |
2e0fef85 JS |
828 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
829 | struct serv_parm *sp) | |
dea3101e | 830 | { |
2e0fef85 JS |
831 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
832 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
833 | LPFC_MBOXQ_t *mbox; |
834 | int rc; | |
835 | ||
2e0fef85 JS |
836 | spin_lock_irq(shost->host_lock); |
837 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
d6de08cc | 838 | vport->fc_flag |= FC_PT2PT; |
2e0fef85 | 839 | spin_unlock_irq(shost->host_lock); |
dea3101e | 840 | |
d6de08cc JS |
841 | /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ |
842 | if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { | |
843 | lpfc_unregister_fcf_prep(phba); | |
844 | ||
845 | spin_lock_irq(shost->host_lock); | |
846 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
847 | spin_unlock_irq(shost->host_lock); | |
848 | phba->fc_topology_changed = 0; | |
849 | } | |
850 | ||
2e0fef85 | 851 | rc = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 852 | sizeof(vport->fc_portname)); |
2eb6862a | 853 | |
dea3101e JB |
854 | if (rc >= 0) { |
855 | /* This side will initiate the PLOGI */ | |
2e0fef85 JS |
856 | spin_lock_irq(shost->host_lock); |
857 | vport->fc_flag |= FC_PT2PT_PLOGI; | |
858 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
859 | |
860 | /* | |
d6de08cc JS |
861 | * N_Port ID cannot be 0, set our Id to LocalID |
862 | * the other side will be RemoteID. | |
dea3101e JB |
863 | */ |
864 | ||
865 | /* not equal */ | |
866 | if (rc) | |
2e0fef85 | 867 | vport->fc_myDID = PT2PT_LocalID; |
dea3101e | 868 | |
e47c9093 JS |
869 | /* Decrement ndlp reference count indicating that ndlp can be |
870 | * safely released when other references to it are done. | |
871 | */ | |
329f9bc7 | 872 | lpfc_nlp_put(ndlp); |
dea3101e | 873 | |
2e0fef85 | 874 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
dea3101e JB |
875 | if (!ndlp) { |
876 | /* | |
877 | * Cannot find existing Fabric ndlp, so allocate a | |
878 | * new one | |
879 | */ | |
880 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
881 | if (!ndlp) | |
882 | goto fail; | |
2e0fef85 | 883 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
e47c9093 JS |
884 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
885 | ndlp = lpfc_enable_node(vport, ndlp, | |
886 | NLP_STE_UNUSED_NODE); | |
887 | if(!ndlp) | |
888 | goto fail; | |
dea3101e JB |
889 | } |
890 | ||
891 | memcpy(&ndlp->nlp_portname, &sp->portName, | |
2e0fef85 | 892 | sizeof(struct lpfc_name)); |
dea3101e | 893 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
2e0fef85 | 894 | sizeof(struct lpfc_name)); |
e47c9093 | 895 | /* Set state will put ndlp onto node list if not already done */ |
2e0fef85 JS |
896 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
897 | spin_lock_irq(shost->host_lock); | |
dea3101e | 898 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 899 | spin_unlock_irq(shost->host_lock); |
e47c9093 JS |
900 | } else |
901 | /* This side will wait for the PLOGI, decrement ndlp reference | |
902 | * count indicating that ndlp can be released when other | |
903 | * references to it are done. | |
904 | */ | |
329f9bc7 | 905 | lpfc_nlp_put(ndlp); |
dea3101e | 906 | |
09372820 JS |
907 | /* If we are pt2pt with another NPort, force NPIV off! */ |
908 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; | |
909 | ||
d6de08cc JS |
910 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
911 | if (!mbox) | |
912 | goto fail; | |
e74c03c8 | 913 | |
d6de08cc JS |
914 | lpfc_config_link(phba, mbox); |
915 | ||
916 | mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; | |
917 | mbox->vport = vport; | |
918 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
919 | if (rc == MBX_NOT_FINISHED) { | |
920 | mempool_free(mbox, phba->mbox_mem_pool); | |
921 | goto fail; | |
e74c03c8 | 922 | } |
dea3101e | 923 | |
dea3101e | 924 | return 0; |
92d7f7b0 | 925 | fail: |
dea3101e JB |
926 | return -ENXIO; |
927 | } | |
928 | ||
e59058c4 | 929 | /** |
3621a710 | 930 | * lpfc_cmpl_els_flogi - Completion callback function for flogi |
e59058c4 JS |
931 | * @phba: pointer to lpfc hba data structure. |
932 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
933 | * @rspiocb: pointer to lpfc response iocb data structure. | |
934 | * | |
935 | * This routine is the top-level completion callback function for issuing | |
936 | * a Fabric Login (FLOGI) command. If the response IOCB reported error, | |
937 | * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If | |
938 | * retry has been made (either immediately or delayed with lpfc_els_retry() | |
939 | * returning 1), the command IOCB will be released and function returned. | |
940 | * If the retry attempt has been given up (possibly reach the maximum | |
941 | * number of retries), one additional decrement of ndlp reference shall be | |
942 | * invoked before going out after releasing the command IOCB. This will | |
943 | * actually release the remote node (Note, lpfc_els_free_iocb() will also | |
944 | * invoke one decrement of ndlp reference count). If no error reported in | |
945 | * the IOCB status, the command Port ID field is used to determine whether | |
946 | * this is a point-to-point topology or a fabric topology: if the Port ID | |
947 | * field is assigned, it is a fabric topology; otherwise, it is a | |
948 | * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or | |
949 | * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the | |
950 | * specific topology completion conditions. | |
951 | **/ | |
dea3101e | 952 | static void |
329f9bc7 JS |
953 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
954 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 955 | { |
2e0fef85 JS |
956 | struct lpfc_vport *vport = cmdiocb->vport; |
957 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e JB |
958 | IOCB_t *irsp = &rspiocb->iocb; |
959 | struct lpfc_nodelist *ndlp = cmdiocb->context1; | |
960 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | |
961 | struct serv_parm *sp; | |
0c9ab6f5 | 962 | uint16_t fcf_index; |
dea3101e JB |
963 | int rc; |
964 | ||
965 | /* Check to see if link went down during discovery */ | |
2e0fef85 | 966 | if (lpfc_els_chk_latt(vport)) { |
fa4066b6 JS |
967 | /* One additional decrement on node reference count to |
968 | * trigger the release of the node | |
969 | */ | |
329f9bc7 | 970 | lpfc_nlp_put(ndlp); |
dea3101e JB |
971 | goto out; |
972 | } | |
973 | ||
858c9f6c JS |
974 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
975 | "FLOGI cmpl: status:x%x/x%x state:x%x", | |
976 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
977 | vport->port_state); | |
978 | ||
dea3101e | 979 | if (irsp->ulpStatus) { |
0c9ab6f5 | 980 | /* |
a93ff37a | 981 | * In case of FIP mode, perform roundrobin FCF failover |
0c9ab6f5 JS |
982 | * due to new FCF discovery |
983 | */ | |
984 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && | |
80c17849 JS |
985 | (phba->fcf.fcf_flag & FCF_DISCOVERY)) { |
986 | if (phba->link_state < LPFC_LINK_UP) | |
987 | goto stop_rr_fcf_flogi; | |
988 | if ((phba->fcoe_cvl_eventtag_attn == | |
989 | phba->fcoe_cvl_eventtag) && | |
990 | (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
991 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
992 | IOERR_SLI_ABORTED)) | |
80c17849 JS |
993 | goto stop_rr_fcf_flogi; |
994 | else | |
995 | phba->fcoe_cvl_eventtag_attn = | |
996 | phba->fcoe_cvl_eventtag; | |
0c9ab6f5 | 997 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, |
a93ff37a JS |
998 | "2611 FLOGI failed on FCF (x%x), " |
999 | "status:x%x/x%x, tmo:x%x, perform " | |
1000 | "roundrobin FCF failover\n", | |
38b92ef8 JS |
1001 | phba->fcf.current_rec.fcf_indx, |
1002 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1003 | irsp->ulpTimeout); | |
7d791df7 JS |
1004 | lpfc_sli4_set_fcf_flogi_fail(phba, |
1005 | phba->fcf.current_rec.fcf_indx); | |
0c9ab6f5 | 1006 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); |
a93ff37a JS |
1007 | rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); |
1008 | if (rc) | |
1009 | goto out; | |
0c9ab6f5 JS |
1010 | } |
1011 | ||
80c17849 | 1012 | stop_rr_fcf_flogi: |
38b92ef8 JS |
1013 | /* FLOGI failure */ |
1014 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
8fe5c165 JS |
1015 | "2858 FLOGI failure Status:x%x/x%x TMO:x%x " |
1016 | "Data x%x x%x\n", | |
38b92ef8 | 1017 | irsp->ulpStatus, irsp->un.ulpWord[4], |
8fe5c165 JS |
1018 | irsp->ulpTimeout, phba->hba_flag, |
1019 | phba->fcf.fcf_flag); | |
38b92ef8 | 1020 | |
dea3101e | 1021 | /* Check for retry */ |
2e0fef85 | 1022 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
dea3101e | 1023 | goto out; |
2e0fef85 | 1024 | |
76a95d75 JS |
1025 | /* FLOGI failure */ |
1026 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1027 | "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n", | |
1028 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1029 | irsp->ulpTimeout); | |
1030 | ||
dea3101e | 1031 | /* FLOGI failed, so there is no fabric */ |
2e0fef85 JS |
1032 | spin_lock_irq(shost->host_lock); |
1033 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
1034 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1035 | |
329f9bc7 | 1036 | /* If private loop, then allow max outstanding els to be |
dea3101e JB |
1037 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
1038 | * alpa map would take too long otherwise. | |
1039 | */ | |
1b51197d | 1040 | if (phba->alpa_map[0] == 0) |
3de2a653 | 1041 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
ff78d8f9 JS |
1042 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1043 | (!(vport->fc_flag & FC_VFI_REGISTERED) || | |
e74c03c8 JS |
1044 | (vport->fc_prevDID != vport->fc_myDID) || |
1045 | phba->fc_topology_changed)) { | |
1046 | if (vport->fc_flag & FC_VFI_REGISTERED) { | |
1047 | if (phba->fc_topology_changed) { | |
1048 | lpfc_unregister_fcf_prep(phba); | |
1049 | spin_lock_irq(shost->host_lock); | |
1050 | vport->fc_flag &= ~FC_VFI_REGISTERED; | |
1051 | spin_unlock_irq(shost->host_lock); | |
1052 | phba->fc_topology_changed = 0; | |
1053 | } else { | |
1054 | lpfc_sli4_unreg_all_rpis(vport); | |
1055 | } | |
1056 | } | |
ff78d8f9 JS |
1057 | lpfc_issue_reg_vfi(vport); |
1058 | lpfc_nlp_put(ndlp); | |
1059 | goto out; | |
dea3101e | 1060 | } |
dea3101e JB |
1061 | goto flogifail; |
1062 | } | |
695a814e JS |
1063 | spin_lock_irq(shost->host_lock); |
1064 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; | |
4b40c59e | 1065 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
695a814e | 1066 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1067 | |
1068 | /* | |
1069 | * The FLogI succeeded. Sync the data for the CPU before | |
1070 | * accessing it. | |
1071 | */ | |
1072 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | |
a2fc4aef JS |
1073 | if (!prsp) |
1074 | goto out; | |
dea3101e JB |
1075 | sp = prsp->virt + sizeof(uint32_t); |
1076 | ||
1077 | /* FLOGI completes successfully */ | |
e8b62011 | 1078 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
88f43a08 JS |
1079 | "0101 FLOGI completes successfully, I/O tag:x%x, " |
1080 | "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag, | |
e8b62011 | 1081 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
e74c03c8 JS |
1082 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, |
1083 | vport->port_state, vport->fc_flag); | |
dea3101e | 1084 | |
2e0fef85 | 1085 | if (vport->port_state == LPFC_FLOGI) { |
dea3101e JB |
1086 | /* |
1087 | * If Common Service Parameters indicate Nport | |
1088 | * we are point to point, if Fport we are Fabric. | |
1089 | */ | |
1090 | if (sp->cmn.fPort) | |
2e0fef85 | 1091 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
76a95d75 | 1092 | else if (!(phba->hba_flag & HBA_FCOE_MODE)) |
2e0fef85 | 1093 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
dbb6b3ab JS |
1094 | else { |
1095 | lpfc_printf_vlog(vport, KERN_ERR, | |
1096 | LOG_FIP | LOG_ELS, | |
1097 | "2831 FLOGI response with cleared Fabric " | |
1098 | "bit fcf_index 0x%x " | |
1099 | "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " | |
1100 | "Fabric Name " | |
1101 | "%02x%02x%02x%02x%02x%02x%02x%02x\n", | |
1102 | phba->fcf.current_rec.fcf_indx, | |
1103 | phba->fcf.current_rec.switch_name[0], | |
1104 | phba->fcf.current_rec.switch_name[1], | |
1105 | phba->fcf.current_rec.switch_name[2], | |
1106 | phba->fcf.current_rec.switch_name[3], | |
1107 | phba->fcf.current_rec.switch_name[4], | |
1108 | phba->fcf.current_rec.switch_name[5], | |
1109 | phba->fcf.current_rec.switch_name[6], | |
1110 | phba->fcf.current_rec.switch_name[7], | |
1111 | phba->fcf.current_rec.fabric_name[0], | |
1112 | phba->fcf.current_rec.fabric_name[1], | |
1113 | phba->fcf.current_rec.fabric_name[2], | |
1114 | phba->fcf.current_rec.fabric_name[3], | |
1115 | phba->fcf.current_rec.fabric_name[4], | |
1116 | phba->fcf.current_rec.fabric_name[5], | |
1117 | phba->fcf.current_rec.fabric_name[6], | |
1118 | phba->fcf.current_rec.fabric_name[7]); | |
1119 | lpfc_nlp_put(ndlp); | |
1120 | spin_lock_irq(&phba->hbalock); | |
1121 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
a93ff37a | 1122 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
dbb6b3ab JS |
1123 | spin_unlock_irq(&phba->hbalock); |
1124 | goto out; | |
1125 | } | |
0c9ab6f5 JS |
1126 | if (!rc) { |
1127 | /* Mark the FCF discovery process done */ | |
999d813f JS |
1128 | if (phba->hba_flag & HBA_FIP_SUPPORT) |
1129 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | | |
1130 | LOG_ELS, | |
a93ff37a JS |
1131 | "2769 FLOGI to FCF (x%x) " |
1132 | "completed successfully\n", | |
999d813f | 1133 | phba->fcf.current_rec.fcf_indx); |
0c9ab6f5 JS |
1134 | spin_lock_irq(&phba->hbalock); |
1135 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
a93ff37a | 1136 | phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO); |
0c9ab6f5 | 1137 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1138 | goto out; |
0c9ab6f5 | 1139 | } |
dea3101e JB |
1140 | } |
1141 | ||
1142 | flogifail: | |
8fe5c165 JS |
1143 | spin_lock_irq(&phba->hbalock); |
1144 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
1145 | spin_unlock_irq(&phba->hbalock); | |
d6de08cc | 1146 | |
329f9bc7 | 1147 | lpfc_nlp_put(ndlp); |
dea3101e | 1148 | |
858c9f6c | 1149 | if (!lpfc_error_lost_link(irsp)) { |
dea3101e | 1150 | /* FLOGI failed, so just use loop map to make discovery list */ |
2e0fef85 | 1151 | lpfc_disc_list_loopmap(vport); |
dea3101e JB |
1152 | |
1153 | /* Start discovery */ | |
2e0fef85 | 1154 | lpfc_disc_start(vport); |
87af33fe | 1155 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
e3d2b802 JS |
1156 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
1157 | IOERR_SLI_ABORTED) && | |
1158 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != | |
1159 | IOERR_SLI_DOWN))) && | |
87af33fe JS |
1160 | (phba->link_state != LPFC_CLEAR_LA)) { |
1161 | /* If FLOGI failed enable link interrupt. */ | |
1162 | lpfc_issue_clear_la(phba, vport); | |
dea3101e | 1163 | } |
dea3101e JB |
1164 | out: |
1165 | lpfc_els_free_iocb(phba, cmdiocb); | |
1166 | } | |
1167 | ||
e59058c4 | 1168 | /** |
3621a710 | 1169 | * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport |
e59058c4 JS |
1170 | * @vport: pointer to a host virtual N_Port data structure. |
1171 | * @ndlp: pointer to a node-list data structure. | |
1172 | * @retry: number of retries to the command IOCB. | |
1173 | * | |
1174 | * This routine issues a Fabric Login (FLOGI) Request ELS command | |
1175 | * for a @vport. The initiator service parameters are put into the payload | |
1176 | * of the FLOGI Request IOCB and the top-level callback function pointer | |
1177 | * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback | |
1178 | * function field. The lpfc_issue_fabric_iocb routine is invoked to send | |
1179 | * out FLOGI ELS command with one outstanding fabric IOCB at a time. | |
1180 | * | |
1181 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
1182 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
1183 | * will be stored into the context1 field of the IOCB for the completion | |
1184 | * callback function to the FLOGI ELS command. | |
1185 | * | |
1186 | * Return code | |
1187 | * 0 - successfully issued flogi iocb for @vport | |
1188 | * 1 - failed to issue flogi iocb for @vport | |
1189 | **/ | |
dea3101e | 1190 | static int |
2e0fef85 | 1191 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
1192 | uint8_t retry) |
1193 | { | |
2e0fef85 | 1194 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1195 | struct serv_parm *sp; |
1196 | IOCB_t *icmd; | |
1197 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
1198 | uint8_t *pcmd; |
1199 | uint16_t cmdsize; | |
1200 | uint32_t tmo; | |
1201 | int rc; | |
1202 | ||
92d7f7b0 | 1203 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
2e0fef85 JS |
1204 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
1205 | ndlp->nlp_DID, ELS_CMD_FLOGI); | |
92d7f7b0 | 1206 | |
488d1469 | 1207 | if (!elsiocb) |
c9f8735b | 1208 | return 1; |
dea3101e JB |
1209 | |
1210 | icmd = &elsiocb->iocb; | |
1211 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1212 | ||
1213 | /* For FLOGI request, remainder of payload is service parameters */ | |
1214 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; | |
92d7f7b0 JS |
1215 | pcmd += sizeof(uint32_t); |
1216 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
1217 | sp = (struct serv_parm *) pcmd; |
1218 | ||
1219 | /* Setup CSPs accordingly for Fabric */ | |
1220 | sp->cmn.e_d_tov = 0; | |
1221 | sp->cmn.w2.r_a_tov = 0; | |
df9e1b59 | 1222 | sp->cmn.virtual_fabric_support = 0; |
dea3101e | 1223 | sp->cls1.classValid = 0; |
dea3101e JB |
1224 | if (sp->cmn.fcphLow < FC_PH3) |
1225 | sp->cmn.fcphLow = FC_PH3; | |
1226 | if (sp->cmn.fcphHigh < FC_PH3) | |
1227 | sp->cmn.fcphHigh = FC_PH3; | |
1228 | ||
c31098ce JS |
1229 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1230 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
1231 | LPFC_SLI_INTF_IF_TYPE_0) { | |
1232 | elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1); | |
1233 | elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1); | |
1234 | /* FLOGI needs to be 3 for WQE FCFI */ | |
1235 | /* Set the fcfi to the fcfi we registered with */ | |
1236 | elsiocb->iocb.ulpContext = phba->fcf.fcfi; | |
1237 | } | |
0f37887e JS |
1238 | /* Can't do SLI4 class2 without support sequence coalescing */ |
1239 | sp->cls2.classValid = 0; | |
1240 | sp->cls2.seqDelivery = 0; | |
5248a749 | 1241 | } else { |
0f37887e JS |
1242 | /* Historical, setting sequential-delivery bit for SLI3 */ |
1243 | sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; | |
1244 | sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; | |
5248a749 JS |
1245 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
1246 | sp->cmn.request_multiple_Nport = 1; | |
1247 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ | |
1248 | icmd->ulpCt_h = 1; | |
1249 | icmd->ulpCt_l = 0; | |
1250 | } else | |
1251 | sp->cmn.request_multiple_Nport = 0; | |
92d7f7b0 JS |
1252 | } |
1253 | ||
76a95d75 | 1254 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
858c9f6c JS |
1255 | icmd->un.elsreq64.myID = 0; |
1256 | icmd->un.elsreq64.fl = 1; | |
1257 | } | |
1258 | ||
dea3101e JB |
1259 | tmo = phba->fc_ratov; |
1260 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; | |
2e0fef85 | 1261 | lpfc_set_disctmo(vport); |
dea3101e JB |
1262 | phba->fc_ratov = tmo; |
1263 | ||
1264 | phba->fc_stat.elsXmitFLOGI++; | |
1265 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; | |
858c9f6c JS |
1266 | |
1267 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
1268 | "Issue FLOGI: opt:x%x", | |
1269 | phba->sli3_options, 0, 0); | |
1270 | ||
92d7f7b0 | 1271 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
dea3101e JB |
1272 | if (rc == IOCB_ERROR) { |
1273 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 1274 | return 1; |
dea3101e | 1275 | } |
c9f8735b | 1276 | return 0; |
dea3101e JB |
1277 | } |
1278 | ||
e59058c4 | 1279 | /** |
3621a710 | 1280 | * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs |
e59058c4 JS |
1281 | * @phba: pointer to lpfc hba data structure. |
1282 | * | |
1283 | * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs | |
1284 | * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq | |
1285 | * list and issues an abort IOCB commond on each outstanding IOCB that | |
1286 | * contains a active Fabric_DID ndlp. Note that this function is to issue | |
1287 | * the abort IOCB command on all the outstanding IOCBs, thus when this | |
1288 | * function returns, it does not guarantee all the IOCBs are actually aborted. | |
1289 | * | |
1290 | * Return code | |
3ad2f3fb | 1291 | * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) |
e59058c4 | 1292 | **/ |
dea3101e | 1293 | int |
2e0fef85 | 1294 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
dea3101e JB |
1295 | { |
1296 | struct lpfc_sli_ring *pring; | |
1297 | struct lpfc_iocbq *iocb, *next_iocb; | |
1298 | struct lpfc_nodelist *ndlp; | |
1299 | IOCB_t *icmd; | |
1300 | ||
1301 | /* Abort outstanding I/O on NPort <nlp_DID> */ | |
1302 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
e8b62011 JS |
1303 | "0201 Abort outstanding I/O on NPort x%x\n", |
1304 | Fabric_DID); | |
dea3101e JB |
1305 | |
1306 | pring = &phba->sli.ring[LPFC_ELS_RING]; | |
1307 | ||
1308 | /* | |
1309 | * Check the txcmplq for an iocb that matches the nport the driver is | |
1310 | * searching for. | |
1311 | */ | |
2e0fef85 | 1312 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1313 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
1314 | icmd = &iocb->iocb; | |
1b51197d | 1315 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { |
dea3101e | 1316 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
58da1ffb JS |
1317 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
1318 | (ndlp->nlp_DID == Fabric_DID)) | |
07951076 | 1319 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
dea3101e JB |
1320 | } |
1321 | } | |
2e0fef85 | 1322 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1323 | |
1324 | return 0; | |
1325 | } | |
1326 | ||
e59058c4 | 1327 | /** |
3621a710 | 1328 | * lpfc_initial_flogi - Issue an initial fabric login for a vport |
e59058c4 JS |
1329 | * @vport: pointer to a host virtual N_Port data structure. |
1330 | * | |
1331 | * This routine issues an initial Fabric Login (FLOGI) for the @vport | |
1332 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | |
1333 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | |
1334 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | |
1335 | * it will just be enabled and made active. The lpfc_issue_els_flogi() routine | |
1336 | * is then invoked with the @vport and the ndlp to perform the FLOGI for the | |
1337 | * @vport. | |
1338 | * | |
1339 | * Return code | |
1340 | * 0 - failed to issue initial flogi for @vport | |
1341 | * 1 - successfully issued initial flogi for @vport | |
1342 | **/ | |
dea3101e | 1343 | int |
2e0fef85 | 1344 | lpfc_initial_flogi(struct lpfc_vport *vport) |
dea3101e | 1345 | { |
2e0fef85 | 1346 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1347 | struct lpfc_nodelist *ndlp; |
1348 | ||
98c9ea5c JS |
1349 | vport->port_state = LPFC_FLOGI; |
1350 | lpfc_set_disctmo(vport); | |
1351 | ||
c9f8735b | 1352 | /* First look for the Fabric ndlp */ |
2e0fef85 | 1353 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
c9f8735b | 1354 | if (!ndlp) { |
dea3101e | 1355 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b JW |
1356 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
1357 | if (!ndlp) | |
1358 | return 0; | |
2e0fef85 | 1359 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
6fb120a7 JS |
1360 | /* Set the node type */ |
1361 | ndlp->nlp_type |= NLP_FABRIC; | |
e47c9093 JS |
1362 | /* Put ndlp onto node list */ |
1363 | lpfc_enqueue_node(vport, ndlp); | |
1364 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1365 | /* re-setup ndlp without removing from node list */ | |
1366 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1367 | if (!ndlp) | |
1368 | return 0; | |
dea3101e | 1369 | } |
87af33fe | 1370 | |
5ac6b303 | 1371 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) { |
fa4066b6 JS |
1372 | /* This decrement of reference count to node shall kick off |
1373 | * the release of the node. | |
1374 | */ | |
329f9bc7 | 1375 | lpfc_nlp_put(ndlp); |
5ac6b303 JS |
1376 | return 0; |
1377 | } | |
c9f8735b | 1378 | return 1; |
dea3101e JB |
1379 | } |
1380 | ||
e59058c4 | 1381 | /** |
3621a710 | 1382 | * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport |
e59058c4 JS |
1383 | * @vport: pointer to a host virtual N_Port data structure. |
1384 | * | |
1385 | * This routine issues an initial Fabric Discover (FDISC) for the @vport | |
1386 | * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from | |
1387 | * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and | |
1388 | * put it into the @vport's ndlp list. If an inactive ndlp found on the list, | |
1389 | * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine | |
1390 | * is then invoked with the @vport and the ndlp to perform the FDISC for the | |
1391 | * @vport. | |
1392 | * | |
1393 | * Return code | |
1394 | * 0 - failed to issue initial fdisc for @vport | |
1395 | * 1 - successfully issued initial fdisc for @vport | |
1396 | **/ | |
92d7f7b0 JS |
1397 | int |
1398 | lpfc_initial_fdisc(struct lpfc_vport *vport) | |
1399 | { | |
1400 | struct lpfc_hba *phba = vport->phba; | |
1401 | struct lpfc_nodelist *ndlp; | |
1402 | ||
1403 | /* First look for the Fabric ndlp */ | |
1404 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
1405 | if (!ndlp) { | |
1406 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
1407 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
1408 | if (!ndlp) | |
1409 | return 0; | |
1410 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
e47c9093 JS |
1411 | /* Put ndlp onto node list */ |
1412 | lpfc_enqueue_node(vport, ndlp); | |
1413 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1414 | /* re-setup ndlp without removing from node list */ | |
1415 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1416 | if (!ndlp) | |
1417 | return 0; | |
92d7f7b0 | 1418 | } |
e47c9093 | 1419 | |
92d7f7b0 | 1420 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
fa4066b6 JS |
1421 | /* decrement node reference count to trigger the release of |
1422 | * the node. | |
1423 | */ | |
92d7f7b0 | 1424 | lpfc_nlp_put(ndlp); |
fa4066b6 | 1425 | return 0; |
92d7f7b0 JS |
1426 | } |
1427 | return 1; | |
1428 | } | |
87af33fe | 1429 | |
e59058c4 | 1430 | /** |
3621a710 | 1431 | * lpfc_more_plogi - Check and issue remaining plogis for a vport |
e59058c4 JS |
1432 | * @vport: pointer to a host virtual N_Port data structure. |
1433 | * | |
1434 | * This routine checks whether there are more remaining Port Logins | |
1435 | * (PLOGI) to be issued for the @vport. If so, it will invoke the routine | |
1436 | * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes | |
1437 | * to issue ELS PLOGIs up to the configured discover threads with the | |
1438 | * @vport (@vport->cfg_discovery_threads). The function also decrement | |
1439 | * the @vport's num_disc_node by 1 if it is not already 0. | |
1440 | **/ | |
87af33fe | 1441 | void |
2e0fef85 | 1442 | lpfc_more_plogi(struct lpfc_vport *vport) |
dea3101e | 1443 | { |
2e0fef85 JS |
1444 | if (vport->num_disc_nodes) |
1445 | vport->num_disc_nodes--; | |
dea3101e JB |
1446 | |
1447 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ | |
e8b62011 JS |
1448 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1449 | "0232 Continue discovery with %d PLOGIs to go " | |
1450 | "Data: x%x x%x x%x\n", | |
1451 | vport->num_disc_nodes, vport->fc_plogi_cnt, | |
1452 | vport->fc_flag, vport->port_state); | |
dea3101e | 1453 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 JS |
1454 | if (vport->fc_flag & FC_NLP_MORE) |
1455 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | |
db6f1c2f | 1456 | lpfc_els_disc_plogi(vport); |
2e0fef85 | 1457 | |
dea3101e JB |
1458 | return; |
1459 | } | |
1460 | ||
e59058c4 | 1461 | /** |
3621a710 | 1462 | * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp |
e59058c4 JS |
1463 | * @phba: pointer to lpfc hba data structure. |
1464 | * @prsp: pointer to response IOCB payload. | |
1465 | * @ndlp: pointer to a node-list data structure. | |
1466 | * | |
1467 | * This routine checks and indicates whether the WWPN of an N_Port, retrieved | |
1468 | * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. | |
1469 | * The following cases are considered N_Port confirmed: | |
1470 | * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches | |
1471 | * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but | |
1472 | * it does not have WWPN assigned either. If the WWPN is confirmed, the | |
1473 | * pointer to the @ndlp will be returned. If the WWPN is not confirmed: | |
1474 | * 1) if there is a node on vport list other than the @ndlp with the same | |
1475 | * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked | |
1476 | * on that node to release the RPI associated with the node; 2) if there is | |
1477 | * no node found on vport list with the same WWPN of the N_Port PLOGI logged | |
1478 | * into, a new node shall be allocated (or activated). In either case, the | |
1479 | * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall | |
1480 | * be released and the new_ndlp shall be put on to the vport node list and | |
1481 | * its pointer returned as the confirmed node. | |
1482 | * | |
1483 | * Note that before the @ndlp got "released", the keepDID from not-matching | |
1484 | * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID | |
1485 | * of the @ndlp. This is because the release of @ndlp is actually to put it | |
1486 | * into an inactive state on the vport node list and the vport node list | |
1487 | * management algorithm does not allow two node with a same DID. | |
1488 | * | |
1489 | * Return code | |
1490 | * pointer to the PLOGI N_Port @ndlp | |
1491 | **/ | |
488d1469 | 1492 | static struct lpfc_nodelist * |
92d7f7b0 | 1493 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
488d1469 JS |
1494 | struct lpfc_nodelist *ndlp) |
1495 | { | |
2e0fef85 | 1496 | struct lpfc_vport *vport = ndlp->vport; |
953ceeda | 1497 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
488d1469 | 1498 | struct lpfc_nodelist *new_ndlp; |
0ff10d46 JS |
1499 | struct lpfc_rport_data *rdata; |
1500 | struct fc_rport *rport; | |
488d1469 | 1501 | struct serv_parm *sp; |
92d7f7b0 | 1502 | uint8_t name[sizeof(struct lpfc_name)]; |
e5abba4c | 1503 | uint32_t rc, keepDID = 0, keep_nlp_flag = 0; |
953ceeda | 1504 | uint16_t keep_nlp_state; |
38b92ef8 JS |
1505 | int put_node; |
1506 | int put_rport; | |
cff261f6 | 1507 | unsigned long *active_rrqs_xri_bitmap = NULL; |
488d1469 | 1508 | |
2fb9bd8b JS |
1509 | /* Fabric nodes can have the same WWPN so we don't bother searching |
1510 | * by WWPN. Just return the ndlp that was given to us. | |
1511 | */ | |
1512 | if (ndlp->nlp_type & NLP_FABRIC) | |
1513 | return ndlp; | |
1514 | ||
92d7f7b0 | 1515 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
685f0bf7 | 1516 | memset(name, 0, sizeof(struct lpfc_name)); |
488d1469 | 1517 | |
685f0bf7 | 1518 | /* Now we find out if the NPort we are logging into, matches the WWPN |
488d1469 JS |
1519 | * we have for that ndlp. If not, we have some work to do. |
1520 | */ | |
2e0fef85 | 1521 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
488d1469 | 1522 | |
e47c9093 | 1523 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
488d1469 | 1524 | return ndlp; |
cff261f6 JS |
1525 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1526 | active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, | |
1527 | GFP_KERNEL); | |
1528 | if (active_rrqs_xri_bitmap) | |
1529 | memset(active_rrqs_xri_bitmap, 0, | |
1530 | phba->cfg_rrq_xri_bitmap_sz); | |
1531 | } | |
488d1469 | 1532 | |
34f5ad8b JS |
1533 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1534 | "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n", | |
1535 | ndlp, ndlp->nlp_DID, new_ndlp); | |
1536 | ||
488d1469 | 1537 | if (!new_ndlp) { |
2e0fef85 JS |
1538 | rc = memcmp(&ndlp->nlp_portname, name, |
1539 | sizeof(struct lpfc_name)); | |
cff261f6 JS |
1540 | if (!rc) { |
1541 | if (active_rrqs_xri_bitmap) | |
1542 | mempool_free(active_rrqs_xri_bitmap, | |
1543 | phba->active_rrq_pool); | |
92795650 | 1544 | return ndlp; |
cff261f6 | 1545 | } |
488d1469 | 1546 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
cff261f6 JS |
1547 | if (!new_ndlp) { |
1548 | if (active_rrqs_xri_bitmap) | |
1549 | mempool_free(active_rrqs_xri_bitmap, | |
1550 | phba->active_rrq_pool); | |
488d1469 | 1551 | return ndlp; |
cff261f6 | 1552 | } |
2e0fef85 | 1553 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
e47c9093 | 1554 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
58da1ffb JS |
1555 | rc = memcmp(&ndlp->nlp_portname, name, |
1556 | sizeof(struct lpfc_name)); | |
cff261f6 JS |
1557 | if (!rc) { |
1558 | if (active_rrqs_xri_bitmap) | |
1559 | mempool_free(active_rrqs_xri_bitmap, | |
1560 | phba->active_rrq_pool); | |
58da1ffb | 1561 | return ndlp; |
cff261f6 | 1562 | } |
e47c9093 JS |
1563 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
1564 | NLP_STE_UNUSED_NODE); | |
cff261f6 JS |
1565 | if (!new_ndlp) { |
1566 | if (active_rrqs_xri_bitmap) | |
1567 | mempool_free(active_rrqs_xri_bitmap, | |
1568 | phba->active_rrq_pool); | |
e47c9093 | 1569 | return ndlp; |
cff261f6 | 1570 | } |
58da1ffb | 1571 | keepDID = new_ndlp->nlp_DID; |
cff261f6 JS |
1572 | if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap) |
1573 | memcpy(active_rrqs_xri_bitmap, | |
1574 | new_ndlp->active_rrqs_xri_bitmap, | |
1575 | phba->cfg_rrq_xri_bitmap_sz); | |
19ca7609 | 1576 | } else { |
58da1ffb | 1577 | keepDID = new_ndlp->nlp_DID; |
cff261f6 JS |
1578 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1579 | active_rrqs_xri_bitmap) | |
1580 | memcpy(active_rrqs_xri_bitmap, | |
1581 | new_ndlp->active_rrqs_xri_bitmap, | |
1582 | phba->cfg_rrq_xri_bitmap_sz); | |
19ca7609 | 1583 | } |
488d1469 | 1584 | |
2e0fef85 | 1585 | lpfc_unreg_rpi(vport, new_ndlp); |
488d1469 | 1586 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
92795650 | 1587 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
19ca7609 | 1588 | if (phba->sli_rev == LPFC_SLI_REV4) |
cff261f6 JS |
1589 | memcpy(new_ndlp->active_rrqs_xri_bitmap, |
1590 | ndlp->active_rrqs_xri_bitmap, | |
1591 | phba->cfg_rrq_xri_bitmap_sz); | |
0ff10d46 | 1592 | |
953ceeda | 1593 | spin_lock_irq(shost->host_lock); |
e5abba4c JS |
1594 | keep_nlp_flag = new_ndlp->nlp_flag; |
1595 | new_ndlp->nlp_flag = ndlp->nlp_flag; | |
1596 | ndlp->nlp_flag = keep_nlp_flag; | |
953ceeda | 1597 | spin_unlock_irq(shost->host_lock); |
0ff10d46 | 1598 | |
953ceeda JS |
1599 | /* Set nlp_states accordingly */ |
1600 | keep_nlp_state = new_ndlp->nlp_state; | |
2e0fef85 | 1601 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
488d1469 | 1602 | |
2e0fef85 | 1603 | /* Move this back to NPR state */ |
87af33fe JS |
1604 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
1605 | /* The new_ndlp is replacing ndlp totally, so we need | |
1606 | * to put ndlp on UNUSED list and try to free it. | |
1607 | */ | |
34f5ad8b JS |
1608 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1609 | "3179 PLOGI confirm NEW: %x %x\n", | |
1610 | new_ndlp->nlp_DID, keepDID); | |
0ff10d46 JS |
1611 | |
1612 | /* Fix up the rport accordingly */ | |
1613 | rport = ndlp->rport; | |
1614 | if (rport) { | |
1615 | rdata = rport->dd_data; | |
1616 | if (rdata->pnode == ndlp) { | |
466e840b | 1617 | /* break the link before dropping the ref */ |
0ff10d46 | 1618 | ndlp->rport = NULL; |
466e840b | 1619 | lpfc_nlp_put(ndlp); |
0ff10d46 JS |
1620 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
1621 | new_ndlp->rport = rport; | |
1622 | } | |
1623 | new_ndlp->nlp_type = ndlp->nlp_type; | |
1624 | } | |
58da1ffb JS |
1625 | /* We shall actually free the ndlp with both nlp_DID and |
1626 | * nlp_portname fields equals 0 to avoid any ndlp on the | |
1627 | * nodelist never to be used. | |
1628 | */ | |
1629 | if (ndlp->nlp_DID == 0) { | |
1630 | spin_lock_irq(&phba->ndlp_lock); | |
1631 | NLP_SET_FREE_REQ(ndlp); | |
1632 | spin_unlock_irq(&phba->ndlp_lock); | |
1633 | } | |
0ff10d46 | 1634 | |
58da1ffb JS |
1635 | /* Two ndlps cannot have the same did on the nodelist */ |
1636 | ndlp->nlp_DID = keepDID; | |
cff261f6 JS |
1637 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1638 | active_rrqs_xri_bitmap) | |
1639 | memcpy(ndlp->active_rrqs_xri_bitmap, | |
1640 | active_rrqs_xri_bitmap, | |
1641 | phba->cfg_rrq_xri_bitmap_sz); | |
e5abba4c JS |
1642 | |
1643 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
1644 | lpfc_drop_node(vport, ndlp); | |
87af33fe | 1645 | } |
92795650 | 1646 | else { |
34f5ad8b JS |
1647 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1648 | "3180 PLOGI confirm SWAP: %x %x\n", | |
1649 | new_ndlp->nlp_DID, keepDID); | |
1650 | ||
2e0fef85 | 1651 | lpfc_unreg_rpi(vport, ndlp); |
34f5ad8b | 1652 | |
58da1ffb JS |
1653 | /* Two ndlps cannot have the same did */ |
1654 | ndlp->nlp_DID = keepDID; | |
cff261f6 JS |
1655 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1656 | active_rrqs_xri_bitmap) | |
1657 | memcpy(ndlp->active_rrqs_xri_bitmap, | |
1658 | active_rrqs_xri_bitmap, | |
1659 | phba->cfg_rrq_xri_bitmap_sz); | |
34f5ad8b | 1660 | |
953ceeda JS |
1661 | /* Since we are switching over to the new_ndlp, |
1662 | * reset the old ndlp state | |
34f5ad8b JS |
1663 | */ |
1664 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | |
1665 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) | |
953ceeda JS |
1666 | keep_nlp_state = NLP_STE_NPR_NODE; |
1667 | lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); | |
34f5ad8b | 1668 | |
38b92ef8 JS |
1669 | /* Fix up the rport accordingly */ |
1670 | rport = ndlp->rport; | |
1671 | if (rport) { | |
1672 | rdata = rport->dd_data; | |
1673 | put_node = rdata->pnode != NULL; | |
1674 | put_rport = ndlp->rport != NULL; | |
1675 | rdata->pnode = NULL; | |
1676 | ndlp->rport = NULL; | |
1677 | if (put_node) | |
1678 | lpfc_nlp_put(ndlp); | |
1679 | if (put_rport) | |
1680 | put_device(&rport->dev); | |
1681 | } | |
92795650 | 1682 | } |
cff261f6 JS |
1683 | if (phba->sli_rev == LPFC_SLI_REV4 && |
1684 | active_rrqs_xri_bitmap) | |
1685 | mempool_free(active_rrqs_xri_bitmap, | |
1686 | phba->active_rrq_pool); | |
488d1469 JS |
1687 | return new_ndlp; |
1688 | } | |
1689 | ||
e59058c4 | 1690 | /** |
3621a710 | 1691 | * lpfc_end_rscn - Check and handle more rscn for a vport |
e59058c4 JS |
1692 | * @vport: pointer to a host virtual N_Port data structure. |
1693 | * | |
1694 | * This routine checks whether more Registration State Change | |
1695 | * Notifications (RSCNs) came in while the discovery state machine was in | |
1696 | * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be | |
1697 | * invoked to handle the additional RSCNs for the @vport. Otherwise, the | |
1698 | * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of | |
1699 | * handling the RSCNs. | |
1700 | **/ | |
87af33fe JS |
1701 | void |
1702 | lpfc_end_rscn(struct lpfc_vport *vport) | |
1703 | { | |
1704 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
1705 | ||
1706 | if (vport->fc_flag & FC_RSCN_MODE) { | |
1707 | /* | |
1708 | * Check to see if more RSCNs came in while we were | |
1709 | * processing this one. | |
1710 | */ | |
1711 | if (vport->fc_rscn_id_cnt || | |
1712 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) | |
1713 | lpfc_els_handle_rscn(vport); | |
1714 | else { | |
1715 | spin_lock_irq(shost->host_lock); | |
1716 | vport->fc_flag &= ~FC_RSCN_MODE; | |
1717 | spin_unlock_irq(shost->host_lock); | |
1718 | } | |
1719 | } | |
1720 | } | |
1721 | ||
19ca7609 JS |
1722 | /** |
1723 | * lpfc_cmpl_els_rrq - Completion handled for els RRQs. | |
1724 | * @phba: pointer to lpfc hba data structure. | |
1725 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
1726 | * @rspiocb: pointer to lpfc response iocb data structure. | |
1727 | * | |
1728 | * This routine will call the clear rrq function to free the rrq and | |
1729 | * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not | |
1730 | * exist then the clear_rrq is still called because the rrq needs to | |
1731 | * be freed. | |
1732 | **/ | |
1733 | ||
1734 | static void | |
1735 | lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1736 | struct lpfc_iocbq *rspiocb) | |
1737 | { | |
1738 | struct lpfc_vport *vport = cmdiocb->vport; | |
1739 | IOCB_t *irsp; | |
1740 | struct lpfc_nodelist *ndlp; | |
1741 | struct lpfc_node_rrq *rrq; | |
1742 | ||
1743 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
1744 | rrq = cmdiocb->context_un.rrq; | |
1745 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1746 | ||
1747 | irsp = &rspiocb->iocb; | |
1748 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
1749 | "RRQ cmpl: status:x%x/x%x did:x%x", | |
1750 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1751 | irsp->un.elsreq64.remoteID); | |
1752 | ||
1753 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); | |
1754 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) { | |
1755 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1756 | "2882 RRQ completes to NPort x%x " | |
1757 | "with no ndlp. Data: x%x x%x x%x\n", | |
1758 | irsp->un.elsreq64.remoteID, | |
1759 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1760 | irsp->ulpIoTag); | |
1761 | goto out; | |
1762 | } | |
1763 | ||
1764 | /* rrq completes to NPort <nlp_DID> */ | |
1765 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
1766 | "2880 RRQ completes to NPort x%x " | |
1767 | "Data: x%x x%x x%x x%x x%x\n", | |
1768 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1769 | irsp->ulpTimeout, rrq->xritag, rrq->rxid); | |
1770 | ||
1771 | if (irsp->ulpStatus) { | |
1772 | /* Check for retry */ | |
1773 | /* RRQ failed Don't print the vport to vport rjts */ | |
1774 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | |
1775 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | |
1776 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | |
1777 | (phba)->pport->cfg_log_verbose & LOG_ELS) | |
1778 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
1779 | "2881 RRQ failure DID:%06X Status:x%x/x%x\n", | |
1780 | ndlp->nlp_DID, irsp->ulpStatus, | |
1781 | irsp->un.ulpWord[4]); | |
1782 | } | |
1783 | out: | |
1784 | if (rrq) | |
1785 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
1786 | lpfc_els_free_iocb(phba, cmdiocb); | |
1787 | return; | |
1788 | } | |
e59058c4 | 1789 | /** |
3621a710 | 1790 | * lpfc_cmpl_els_plogi - Completion callback function for plogi |
e59058c4 JS |
1791 | * @phba: pointer to lpfc hba data structure. |
1792 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
1793 | * @rspiocb: pointer to lpfc response iocb data structure. | |
1794 | * | |
1795 | * This routine is the completion callback function for issuing the Port | |
1796 | * Login (PLOGI) command. For PLOGI completion, there must be an active | |
1797 | * ndlp on the vport node list that matches the remote node ID from the | |
25985edc | 1798 | * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply |
e59058c4 JS |
1799 | * ignored and command IOCB released. The PLOGI response IOCB status is |
1800 | * checked for error conditons. If there is error status reported, PLOGI | |
1801 | * retry shall be attempted by invoking the lpfc_els_retry() routine. | |
1802 | * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on | |
1803 | * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine | |
1804 | * (DSM) is set for this PLOGI completion. Finally, it checks whether | |
1805 | * there are additional N_Port nodes with the vport that need to perform | |
1806 | * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition | |
1807 | * PLOGIs. | |
1808 | **/ | |
dea3101e | 1809 | static void |
2e0fef85 JS |
1810 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1811 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1812 | { |
2e0fef85 JS |
1813 | struct lpfc_vport *vport = cmdiocb->vport; |
1814 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 1815 | IOCB_t *irsp; |
dea3101e | 1816 | struct lpfc_nodelist *ndlp; |
92795650 | 1817 | struct lpfc_dmabuf *prsp; |
eb016566 | 1818 | int disc, rc; |
dea3101e | 1819 | |
dea3101e JB |
1820 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
1821 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1822 | ||
1823 | irsp = &rspiocb->iocb; | |
858c9f6c JS |
1824 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1825 | "PLOGI cmpl: status:x%x/x%x did:x%x", | |
1826 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1827 | irsp->un.elsreq64.remoteID); | |
1828 | ||
2e0fef85 | 1829 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
e47c9093 | 1830 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
e8b62011 JS |
1831 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
1832 | "0136 PLOGI completes to NPort x%x " | |
1833 | "with no ndlp. Data: x%x x%x x%x\n", | |
1834 | irsp->un.elsreq64.remoteID, | |
1835 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1836 | irsp->ulpIoTag); | |
488d1469 | 1837 | goto out; |
ed957684 | 1838 | } |
dea3101e JB |
1839 | |
1840 | /* Since ndlp can be freed in the disc state machine, note if this node | |
1841 | * is being used during discovery. | |
1842 | */ | |
2e0fef85 | 1843 | spin_lock_irq(shost->host_lock); |
dea3101e | 1844 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
488d1469 | 1845 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 | 1846 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1847 | rc = 0; |
1848 | ||
1849 | /* PLOGI completes to NPort <nlp_DID> */ | |
e8b62011 JS |
1850 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1851 | "0102 PLOGI completes to NPort x%x " | |
1852 | "Data: x%x x%x x%x x%x x%x\n", | |
1853 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1854 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | |
dea3101e | 1855 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
1856 | if (lpfc_els_chk_latt(vport)) { |
1857 | spin_lock_irq(shost->host_lock); | |
dea3101e | 1858 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1859 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1860 | goto out; |
1861 | } | |
1862 | ||
dea3101e JB |
1863 | if (irsp->ulpStatus) { |
1864 | /* Check for retry */ | |
1865 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
1866 | /* ELS command is being retried */ | |
1867 | if (disc) { | |
2e0fef85 | 1868 | spin_lock_irq(shost->host_lock); |
dea3101e | 1869 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1870 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1871 | } |
1872 | goto out; | |
1873 | } | |
2a9bf3d0 JS |
1874 | /* PLOGI failed Don't print the vport to vport rjts */ |
1875 | if (irsp->ulpStatus != IOSTAT_LS_RJT || | |
1876 | (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) && | |
1877 | ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) || | |
1878 | (phba)->pport->cfg_log_verbose & LOG_ELS) | |
1879 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
e40a02c1 JS |
1880 | "2753 PLOGI failure DID:%06X Status:x%x/x%x\n", |
1881 | ndlp->nlp_DID, irsp->ulpStatus, | |
1882 | irsp->un.ulpWord[4]); | |
dea3101e | 1883 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 1884 | if (lpfc_error_lost_link(irsp)) |
c9f8735b | 1885 | rc = NLP_STE_FREED_NODE; |
e47c9093 | 1886 | else |
2e0fef85 | 1887 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1888 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1889 | } else { |
1890 | /* Good status, call state machine */ | |
92795650 | 1891 | prsp = list_entry(((struct lpfc_dmabuf *) |
92d7f7b0 JS |
1892 | cmdiocb->context2)->list.next, |
1893 | struct lpfc_dmabuf, list); | |
1894 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); | |
2e0fef85 | 1895 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1896 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1897 | } |
1898 | ||
2e0fef85 | 1899 | if (disc && vport->num_disc_nodes) { |
dea3101e | 1900 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 | 1901 | lpfc_more_plogi(vport); |
dea3101e | 1902 | |
2e0fef85 JS |
1903 | if (vport->num_disc_nodes == 0) { |
1904 | spin_lock_irq(shost->host_lock); | |
1905 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
1906 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1907 | |
2e0fef85 | 1908 | lpfc_can_disctmo(vport); |
87af33fe | 1909 | lpfc_end_rscn(vport); |
dea3101e JB |
1910 | } |
1911 | } | |
1912 | ||
1913 | out: | |
1914 | lpfc_els_free_iocb(phba, cmdiocb); | |
1915 | return; | |
1916 | } | |
1917 | ||
e59058c4 | 1918 | /** |
3621a710 | 1919 | * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport |
e59058c4 JS |
1920 | * @vport: pointer to a host virtual N_Port data structure. |
1921 | * @did: destination port identifier. | |
1922 | * @retry: number of retries to the command IOCB. | |
1923 | * | |
1924 | * This routine issues a Port Login (PLOGI) command to a remote N_Port | |
1925 | * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, | |
1926 | * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. | |
1927 | * This routine constructs the proper feilds of the PLOGI IOCB and invokes | |
1928 | * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. | |
1929 | * | |
1930 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
1931 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
1932 | * will be stored into the context1 field of the IOCB for the completion | |
1933 | * callback function to the PLOGI ELS command. | |
1934 | * | |
1935 | * Return code | |
1936 | * 0 - Successfully issued a plogi for @vport | |
1937 | * 1 - failed to issue a plogi for @vport | |
1938 | **/ | |
dea3101e | 1939 | int |
2e0fef85 | 1940 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
dea3101e | 1941 | { |
2e0fef85 | 1942 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1943 | struct serv_parm *sp; |
98c9ea5c | 1944 | struct lpfc_nodelist *ndlp; |
dea3101e | 1945 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
1946 | uint8_t *pcmd; |
1947 | uint16_t cmdsize; | |
92d7f7b0 | 1948 | int ret; |
dea3101e | 1949 | |
98c9ea5c | 1950 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
1951 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
1952 | ndlp = NULL; | |
98c9ea5c | 1953 | |
e47c9093 | 1954 | /* If ndlp is not NULL, we will bump the reference count on it */ |
92d7f7b0 | 1955 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
98c9ea5c | 1956 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
2e0fef85 | 1957 | ELS_CMD_PLOGI); |
c9f8735b JW |
1958 | if (!elsiocb) |
1959 | return 1; | |
dea3101e | 1960 | |
dea3101e JB |
1961 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
1962 | ||
1963 | /* For PLOGI request, remainder of payload is service parameters */ | |
1964 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; | |
92d7f7b0 JS |
1965 | pcmd += sizeof(uint32_t); |
1966 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
1967 | sp = (struct serv_parm *) pcmd; |
1968 | ||
5ac6b303 JS |
1969 | /* |
1970 | * If we are a N-port connected to a Fabric, fix-up paramm's so logins | |
1971 | * to device on remote loops work. | |
1972 | */ | |
1973 | if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP)) | |
1974 | sp->cmn.altBbCredit = 1; | |
1975 | ||
dea3101e JB |
1976 | if (sp->cmn.fcphLow < FC_PH_4_3) |
1977 | sp->cmn.fcphLow = FC_PH_4_3; | |
1978 | ||
1979 | if (sp->cmn.fcphHigh < FC_PH3) | |
1980 | sp->cmn.fcphHigh = FC_PH3; | |
1981 | ||
858c9f6c JS |
1982 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1983 | "Issue PLOGI: did:x%x", | |
1984 | did, 0, 0); | |
1985 | ||
dea3101e JB |
1986 | phba->fc_stat.elsXmitPLOGI++; |
1987 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; | |
3772a991 | 1988 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
92d7f7b0 JS |
1989 | |
1990 | if (ret == IOCB_ERROR) { | |
dea3101e | 1991 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1992 | return 1; |
dea3101e | 1993 | } |
c9f8735b | 1994 | return 0; |
dea3101e JB |
1995 | } |
1996 | ||
e59058c4 | 1997 | /** |
3621a710 | 1998 | * lpfc_cmpl_els_prli - Completion callback function for prli |
e59058c4 JS |
1999 | * @phba: pointer to lpfc hba data structure. |
2000 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2001 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2002 | * | |
2003 | * This routine is the completion callback function for a Process Login | |
2004 | * (PRLI) ELS command. The PRLI response IOCB status is checked for error | |
2005 | * status. If there is error status reported, PRLI retry shall be attempted | |
2006 | * by invoking the lpfc_els_retry() routine. Otherwise, the state | |
2007 | * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this | |
2008 | * ndlp to mark the PRLI completion. | |
2009 | **/ | |
dea3101e | 2010 | static void |
2e0fef85 JS |
2011 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2012 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2013 | { |
2e0fef85 JS |
2014 | struct lpfc_vport *vport = cmdiocb->vport; |
2015 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2016 | IOCB_t *irsp; |
dea3101e JB |
2017 | struct lpfc_nodelist *ndlp; |
2018 | ||
dea3101e JB |
2019 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
2020 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2021 | ||
2022 | irsp = &(rspiocb->iocb); | |
2023 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
2e0fef85 | 2024 | spin_lock_irq(shost->host_lock); |
dea3101e | 2025 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 2026 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2027 | |
858c9f6c JS |
2028 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2029 | "PRLI cmpl: status:x%x/x%x did:x%x", | |
2030 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2031 | ndlp->nlp_DID); | |
dea3101e | 2032 | /* PRLI completes to NPort <nlp_DID> */ |
e8b62011 JS |
2033 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2034 | "0103 PRLI completes to NPort x%x " | |
2035 | "Data: x%x x%x x%x x%x\n", | |
2036 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
2037 | irsp->ulpTimeout, vport->num_disc_nodes); | |
dea3101e | 2038 | |
2e0fef85 | 2039 | vport->fc_prli_sent--; |
dea3101e | 2040 | /* Check to see if link went down during discovery */ |
2e0fef85 | 2041 | if (lpfc_els_chk_latt(vport)) |
dea3101e JB |
2042 | goto out; |
2043 | ||
2044 | if (irsp->ulpStatus) { | |
2045 | /* Check for retry */ | |
2046 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
2047 | /* ELS command is being retried */ | |
2048 | goto out; | |
2049 | } | |
2050 | /* PRLI failed */ | |
e40a02c1 JS |
2051 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2052 | "2754 PRLI failure DID:%06X Status:x%x/x%x\n", | |
2053 | ndlp->nlp_DID, irsp->ulpStatus, | |
2054 | irsp->un.ulpWord[4]); | |
dea3101e | 2055 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 2056 | if (lpfc_error_lost_link(irsp)) |
dea3101e | 2057 | goto out; |
e47c9093 | 2058 | else |
2e0fef85 | 2059 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 2060 | NLP_EVT_CMPL_PRLI); |
e47c9093 | 2061 | } else |
dea3101e | 2062 | /* Good status, call state machine */ |
2e0fef85 | 2063 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 2064 | NLP_EVT_CMPL_PRLI); |
dea3101e JB |
2065 | out: |
2066 | lpfc_els_free_iocb(phba, cmdiocb); | |
2067 | return; | |
2068 | } | |
2069 | ||
e59058c4 | 2070 | /** |
3621a710 | 2071 | * lpfc_issue_els_prli - Issue a prli iocb command for a vport |
e59058c4 JS |
2072 | * @vport: pointer to a host virtual N_Port data structure. |
2073 | * @ndlp: pointer to a node-list data structure. | |
2074 | * @retry: number of retries to the command IOCB. | |
2075 | * | |
2076 | * This routine issues a Process Login (PRLI) ELS command for the | |
2077 | * @vport. The PRLI service parameters are set up in the payload of the | |
2078 | * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine | |
2079 | * is put to the IOCB completion callback func field before invoking the | |
2080 | * routine lpfc_sli_issue_iocb() to send out PRLI command. | |
2081 | * | |
2082 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2083 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2084 | * will be stored into the context1 field of the IOCB for the completion | |
2085 | * callback function to the PRLI ELS command. | |
2086 | * | |
2087 | * Return code | |
2088 | * 0 - successfully issued prli iocb command for @vport | |
2089 | * 1 - failed to issue prli iocb command for @vport | |
2090 | **/ | |
dea3101e | 2091 | int |
2e0fef85 | 2092 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2093 | uint8_t retry) |
2094 | { | |
2e0fef85 JS |
2095 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2096 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2097 | PRLI *npr; |
dea3101e | 2098 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2099 | uint8_t *pcmd; |
2100 | uint16_t cmdsize; | |
2101 | ||
92d7f7b0 | 2102 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
2e0fef85 JS |
2103 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
2104 | ndlp->nlp_DID, ELS_CMD_PRLI); | |
488d1469 | 2105 | if (!elsiocb) |
c9f8735b | 2106 | return 1; |
dea3101e | 2107 | |
dea3101e JB |
2108 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2109 | ||
2110 | /* For PRLI request, remainder of payload is service parameters */ | |
92d7f7b0 | 2111 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
dea3101e | 2112 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
92d7f7b0 | 2113 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2114 | |
2115 | /* For PRLI, remainder of payload is PRLI parameter page */ | |
2116 | npr = (PRLI *) pcmd; | |
2117 | /* | |
2118 | * If our firmware version is 3.20 or later, | |
2119 | * set the following bits for FC-TAPE support. | |
2120 | */ | |
2121 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { | |
2122 | npr->ConfmComplAllowed = 1; | |
2123 | npr->Retry = 1; | |
2124 | npr->TaskRetryIdReq = 1; | |
2125 | } | |
2126 | npr->estabImagePair = 1; | |
2127 | npr->readXferRdyDis = 1; | |
3cb01c57 JS |
2128 | if (vport->cfg_first_burst_size) |
2129 | npr->writeXferRdyDis = 1; | |
dea3101e JB |
2130 | |
2131 | /* For FCP support */ | |
2132 | npr->prliType = PRLI_FCP_TYPE; | |
2133 | npr->initiatorFunc = 1; | |
2134 | ||
858c9f6c JS |
2135 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2136 | "Issue PRLI: did:x%x", | |
2137 | ndlp->nlp_DID, 0, 0); | |
2138 | ||
dea3101e JB |
2139 | phba->fc_stat.elsXmitPRLI++; |
2140 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; | |
2e0fef85 | 2141 | spin_lock_irq(shost->host_lock); |
dea3101e | 2142 | ndlp->nlp_flag |= NLP_PRLI_SND; |
2e0fef85 | 2143 | spin_unlock_irq(shost->host_lock); |
3772a991 JS |
2144 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2145 | IOCB_ERROR) { | |
2e0fef85 | 2146 | spin_lock_irq(shost->host_lock); |
dea3101e | 2147 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 2148 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2149 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2150 | return 1; |
dea3101e | 2151 | } |
2e0fef85 | 2152 | vport->fc_prli_sent++; |
c9f8735b | 2153 | return 0; |
dea3101e JB |
2154 | } |
2155 | ||
90160e01 | 2156 | /** |
3621a710 | 2157 | * lpfc_rscn_disc - Perform rscn discovery for a vport |
90160e01 JS |
2158 | * @vport: pointer to a host virtual N_Port data structure. |
2159 | * | |
2160 | * This routine performs Registration State Change Notification (RSCN) | |
2161 | * discovery for a @vport. If the @vport's node port recovery count is not | |
2162 | * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all | |
2163 | * the nodes that need recovery. If none of the PLOGI were needed through | |
2164 | * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be | |
2165 | * invoked to check and handle possible more RSCN came in during the period | |
2166 | * of processing the current ones. | |
2167 | **/ | |
2168 | static void | |
2169 | lpfc_rscn_disc(struct lpfc_vport *vport) | |
2170 | { | |
2171 | lpfc_can_disctmo(vport); | |
2172 | ||
2173 | /* RSCN discovery */ | |
2174 | /* go thru NPR nodes and issue ELS PLOGIs */ | |
2175 | if (vport->fc_npr_cnt) | |
2176 | if (lpfc_els_disc_plogi(vport)) | |
2177 | return; | |
2178 | ||
2179 | lpfc_end_rscn(vport); | |
2180 | } | |
2181 | ||
2182 | /** | |
3621a710 | 2183 | * lpfc_adisc_done - Complete the adisc phase of discovery |
90160e01 JS |
2184 | * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. |
2185 | * | |
2186 | * This function is called when the final ADISC is completed during discovery. | |
2187 | * This function handles clearing link attention or issuing reg_vpi depending | |
2188 | * on whether npiv is enabled. This function also kicks off the PLOGI phase of | |
2189 | * discovery. | |
2190 | * This function is called with no locks held. | |
2191 | **/ | |
2192 | static void | |
2193 | lpfc_adisc_done(struct lpfc_vport *vport) | |
2194 | { | |
2195 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
2196 | struct lpfc_hba *phba = vport->phba; | |
2197 | ||
2198 | /* | |
2199 | * For NPIV, cmpl_reg_vpi will set port_state to READY, | |
2200 | * and continue discovery. | |
2201 | */ | |
2202 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
6fb120a7 JS |
2203 | !(vport->fc_flag & FC_RSCN_MODE) && |
2204 | (phba->sli_rev < LPFC_SLI_REV4)) { | |
d454c91f JS |
2205 | /* The ADISCs are complete. Doesn't matter if they |
2206 | * succeeded or failed because the ADISC completion | |
2207 | * routine guarantees to call the state machine and | |
2208 | * the RPI is either unregistered (failed ADISC response) | |
2209 | * or the RPI is still valid and the node is marked | |
2210 | * mapped for a target. The exchanges should be in the | |
2211 | * correct state. This code is specific to SLI3. | |
2212 | */ | |
2213 | lpfc_issue_clear_la(phba, vport); | |
90160e01 JS |
2214 | lpfc_issue_reg_vpi(phba, vport); |
2215 | return; | |
2216 | } | |
2217 | /* | |
2218 | * For SLI2, we need to set port_state to READY | |
2219 | * and continue discovery. | |
2220 | */ | |
2221 | if (vport->port_state < LPFC_VPORT_READY) { | |
2222 | /* If we get here, there is nothing to ADISC */ | |
85c0f177 | 2223 | lpfc_issue_clear_la(phba, vport); |
90160e01 JS |
2224 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
2225 | vport->num_disc_nodes = 0; | |
2226 | /* go thru NPR list, issue ELS PLOGIs */ | |
2227 | if (vport->fc_npr_cnt) | |
2228 | lpfc_els_disc_plogi(vport); | |
2229 | if (!vport->num_disc_nodes) { | |
2230 | spin_lock_irq(shost->host_lock); | |
2231 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
2232 | spin_unlock_irq(shost->host_lock); | |
2233 | lpfc_can_disctmo(vport); | |
2234 | lpfc_end_rscn(vport); | |
2235 | } | |
2236 | } | |
2237 | vport->port_state = LPFC_VPORT_READY; | |
2238 | } else | |
2239 | lpfc_rscn_disc(vport); | |
2240 | } | |
2241 | ||
e59058c4 | 2242 | /** |
3621a710 | 2243 | * lpfc_more_adisc - Issue more adisc as needed |
e59058c4 JS |
2244 | * @vport: pointer to a host virtual N_Port data structure. |
2245 | * | |
2246 | * This routine determines whether there are more ndlps on a @vport | |
2247 | * node list need to have Address Discover (ADISC) issued. If so, it will | |
2248 | * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's | |
2249 | * remaining nodes which need to have ADISC sent. | |
2250 | **/ | |
0ff10d46 | 2251 | void |
2e0fef85 | 2252 | lpfc_more_adisc(struct lpfc_vport *vport) |
dea3101e | 2253 | { |
2e0fef85 JS |
2254 | if (vport->num_disc_nodes) |
2255 | vport->num_disc_nodes--; | |
dea3101e | 2256 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
e8b62011 JS |
2257 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
2258 | "0210 Continue discovery with %d ADISCs to go " | |
2259 | "Data: x%x x%x x%x\n", | |
2260 | vport->num_disc_nodes, vport->fc_adisc_cnt, | |
2261 | vport->fc_flag, vport->port_state); | |
dea3101e | 2262 | /* Check to see if there are more ADISCs to be sent */ |
2e0fef85 JS |
2263 | if (vport->fc_flag & FC_NLP_MORE) { |
2264 | lpfc_set_disctmo(vport); | |
2265 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | |
eb016566 | 2266 | lpfc_els_disc_adisc(vport); |
dea3101e | 2267 | } |
90160e01 JS |
2268 | if (!vport->num_disc_nodes) |
2269 | lpfc_adisc_done(vport); | |
dea3101e JB |
2270 | return; |
2271 | } | |
2272 | ||
e59058c4 | 2273 | /** |
3621a710 | 2274 | * lpfc_cmpl_els_adisc - Completion callback function for adisc |
e59058c4 JS |
2275 | * @phba: pointer to lpfc hba data structure. |
2276 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2277 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2278 | * | |
2279 | * This routine is the completion function for issuing the Address Discover | |
2280 | * (ADISC) command. It first checks to see whether link went down during | |
2281 | * the discovery process. If so, the node will be marked as node port | |
2282 | * recovery for issuing discover IOCB by the link attention handler and | |
2283 | * exit. Otherwise, the response status is checked. If error was reported | |
2284 | * in the response status, the ADISC command shall be retried by invoking | |
2285 | * the lpfc_els_retry() routine. Otherwise, if no error was reported in | |
2286 | * the response status, the state machine is invoked to set transition | |
2287 | * with respect to NLP_EVT_CMPL_ADISC event. | |
2288 | **/ | |
dea3101e | 2289 | static void |
2e0fef85 JS |
2290 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2291 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2292 | { |
2e0fef85 JS |
2293 | struct lpfc_vport *vport = cmdiocb->vport; |
2294 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2295 | IOCB_t *irsp; |
dea3101e | 2296 | struct lpfc_nodelist *ndlp; |
2e0fef85 | 2297 | int disc; |
dea3101e JB |
2298 | |
2299 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
2300 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2301 | ||
2302 | irsp = &(rspiocb->iocb); | |
2303 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
dea3101e | 2304 | |
858c9f6c JS |
2305 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2306 | "ADISC cmpl: status:x%x/x%x did:x%x", | |
2307 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2308 | ndlp->nlp_DID); | |
2309 | ||
dea3101e JB |
2310 | /* Since ndlp can be freed in the disc state machine, note if this node |
2311 | * is being used during discovery. | |
2312 | */ | |
2e0fef85 | 2313 | spin_lock_irq(shost->host_lock); |
dea3101e | 2314 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
c9f8735b | 2315 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
2e0fef85 | 2316 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2317 | /* ADISC completes to NPort <nlp_DID> */ |
e8b62011 JS |
2318 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2319 | "0104 ADISC completes to NPort x%x " | |
2320 | "Data: x%x x%x x%x x%x x%x\n", | |
2321 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
2322 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | |
dea3101e | 2323 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
2324 | if (lpfc_els_chk_latt(vport)) { |
2325 | spin_lock_irq(shost->host_lock); | |
dea3101e | 2326 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 2327 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
2328 | goto out; |
2329 | } | |
2330 | ||
2331 | if (irsp->ulpStatus) { | |
2332 | /* Check for retry */ | |
2333 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
2334 | /* ELS command is being retried */ | |
2335 | if (disc) { | |
2e0fef85 | 2336 | spin_lock_irq(shost->host_lock); |
dea3101e | 2337 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 JS |
2338 | spin_unlock_irq(shost->host_lock); |
2339 | lpfc_set_disctmo(vport); | |
dea3101e JB |
2340 | } |
2341 | goto out; | |
2342 | } | |
2343 | /* ADISC failed */ | |
e40a02c1 JS |
2344 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2345 | "2755 ADISC failure DID:%06X Status:x%x/x%x\n", | |
2346 | ndlp->nlp_DID, irsp->ulpStatus, | |
2347 | irsp->un.ulpWord[4]); | |
dea3101e | 2348 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
e47c9093 | 2349 | if (!lpfc_error_lost_link(irsp)) |
2e0fef85 | 2350 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
858c9f6c | 2351 | NLP_EVT_CMPL_ADISC); |
e47c9093 | 2352 | } else |
dea3101e | 2353 | /* Good status, call state machine */ |
2e0fef85 | 2354 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
dea3101e | 2355 | NLP_EVT_CMPL_ADISC); |
dea3101e | 2356 | |
90160e01 JS |
2357 | /* Check to see if there are more ADISCs to be sent */ |
2358 | if (disc && vport->num_disc_nodes) | |
2e0fef85 | 2359 | lpfc_more_adisc(vport); |
dea3101e JB |
2360 | out: |
2361 | lpfc_els_free_iocb(phba, cmdiocb); | |
2362 | return; | |
2363 | } | |
2364 | ||
e59058c4 | 2365 | /** |
3621a710 | 2366 | * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport |
e59058c4 JS |
2367 | * @vport: pointer to a virtual N_Port data structure. |
2368 | * @ndlp: pointer to a node-list data structure. | |
2369 | * @retry: number of retries to the command IOCB. | |
2370 | * | |
2371 | * This routine issues an Address Discover (ADISC) for an @ndlp on a | |
2372 | * @vport. It prepares the payload of the ADISC ELS command, updates the | |
2373 | * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine | |
2374 | * to issue the ADISC ELS command. | |
2375 | * | |
2376 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2377 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2378 | * will be stored into the context1 field of the IOCB for the completion | |
2379 | * callback function to the ADISC ELS command. | |
2380 | * | |
2381 | * Return code | |
2382 | * 0 - successfully issued adisc | |
2383 | * 1 - failed to issue adisc | |
2384 | **/ | |
dea3101e | 2385 | int |
2e0fef85 | 2386 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2387 | uint8_t retry) |
2388 | { | |
2e0fef85 JS |
2389 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2390 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2391 | ADISC *ap; |
dea3101e | 2392 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2393 | uint8_t *pcmd; |
2394 | uint16_t cmdsize; | |
2395 | ||
92d7f7b0 | 2396 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
2e0fef85 JS |
2397 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
2398 | ndlp->nlp_DID, ELS_CMD_ADISC); | |
488d1469 | 2399 | if (!elsiocb) |
c9f8735b | 2400 | return 1; |
dea3101e | 2401 | |
dea3101e JB |
2402 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2403 | ||
2404 | /* For ADISC request, remainder of payload is service parameters */ | |
2405 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; | |
92d7f7b0 | 2406 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2407 | |
2408 | /* Fill in ADISC payload */ | |
2409 | ap = (ADISC *) pcmd; | |
2410 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
2411 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
2412 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 2413 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 2414 | |
858c9f6c JS |
2415 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2416 | "Issue ADISC: did:x%x", | |
2417 | ndlp->nlp_DID, 0, 0); | |
2418 | ||
dea3101e JB |
2419 | phba->fc_stat.elsXmitADISC++; |
2420 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; | |
2e0fef85 | 2421 | spin_lock_irq(shost->host_lock); |
dea3101e | 2422 | ndlp->nlp_flag |= NLP_ADISC_SND; |
2e0fef85 | 2423 | spin_unlock_irq(shost->host_lock); |
3772a991 JS |
2424 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2425 | IOCB_ERROR) { | |
2e0fef85 | 2426 | spin_lock_irq(shost->host_lock); |
dea3101e | 2427 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
2e0fef85 | 2428 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2429 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2430 | return 1; |
dea3101e | 2431 | } |
c9f8735b | 2432 | return 0; |
dea3101e JB |
2433 | } |
2434 | ||
e59058c4 | 2435 | /** |
3621a710 | 2436 | * lpfc_cmpl_els_logo - Completion callback function for logo |
e59058c4 JS |
2437 | * @phba: pointer to lpfc hba data structure. |
2438 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2439 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2440 | * | |
2441 | * This routine is the completion function for issuing the ELS Logout (LOGO) | |
2442 | * command. If no error status was reported from the LOGO response, the | |
2443 | * state machine of the associated ndlp shall be invoked for transition with | |
2444 | * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported, | |
2445 | * the lpfc_els_retry() routine will be invoked to retry the LOGO command. | |
2446 | **/ | |
dea3101e | 2447 | static void |
2e0fef85 JS |
2448 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2449 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2450 | { |
2e0fef85 JS |
2451 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
2452 | struct lpfc_vport *vport = ndlp->vport; | |
2453 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 2454 | IOCB_t *irsp; |
92494144 | 2455 | struct lpfcMboxq *mbox; |
086a345f JS |
2456 | unsigned long flags; |
2457 | uint32_t skip_recovery = 0; | |
dea3101e | 2458 | |
dea3101e JB |
2459 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
2460 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
2461 | ||
2462 | irsp = &(rspiocb->iocb); | |
2e0fef85 | 2463 | spin_lock_irq(shost->host_lock); |
dea3101e | 2464 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 2465 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2466 | |
858c9f6c JS |
2467 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2468 | "LOGO cmpl: status:x%x/x%x did:x%x", | |
2469 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2470 | ndlp->nlp_DID); | |
086a345f | 2471 | |
dea3101e | 2472 | /* LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
2473 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2474 | "0105 LOGO completes to NPort x%x " | |
2475 | "Data: x%x x%x x%x x%x\n", | |
2476 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
2477 | irsp->ulpTimeout, vport->num_disc_nodes); | |
086a345f JS |
2478 | |
2479 | if (lpfc_els_chk_latt(vport)) { | |
2480 | skip_recovery = 1; | |
dea3101e | 2481 | goto out; |
086a345f | 2482 | } |
dea3101e | 2483 | |
086a345f | 2484 | /* Check to see if link went down during discovery */ |
92d7f7b0 JS |
2485 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
2486 | /* NLP_EVT_DEVICE_RM should unregister the RPI | |
2487 | * which should abort all outstanding IOs. | |
2488 | */ | |
2489 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | |
2490 | NLP_EVT_DEVICE_RM); | |
086a345f | 2491 | skip_recovery = 1; |
92d7f7b0 JS |
2492 | goto out; |
2493 | } | |
2494 | ||
dea3101e JB |
2495 | if (irsp->ulpStatus) { |
2496 | /* Check for retry */ | |
086a345f | 2497 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
dea3101e | 2498 | /* ELS command is being retried */ |
086a345f | 2499 | skip_recovery = 1; |
dea3101e | 2500 | goto out; |
086a345f | 2501 | } |
dea3101e | 2502 | /* LOGO failed */ |
e40a02c1 JS |
2503 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2504 | "2756 LOGO failure DID:%06X Status:x%x/x%x\n", | |
2505 | ndlp->nlp_DID, irsp->ulpStatus, | |
2506 | irsp->un.ulpWord[4]); | |
dea3101e | 2507 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
086a345f JS |
2508 | if (lpfc_error_lost_link(irsp)) { |
2509 | skip_recovery = 1; | |
dea3101e | 2510 | goto out; |
086a345f JS |
2511 | } |
2512 | } | |
2513 | ||
2514 | /* Call state machine. This will unregister the rpi if needed. */ | |
2515 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); | |
2516 | ||
dea3101e JB |
2517 | out: |
2518 | lpfc_els_free_iocb(phba, cmdiocb); | |
92494144 JS |
2519 | /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */ |
2520 | if ((vport->fc_flag & FC_PT2PT) && | |
2521 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { | |
2522 | phba->pport->fc_myDID = 0; | |
2523 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2524 | if (mbox) { | |
2525 | lpfc_config_link(phba, mbox); | |
2526 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
2527 | mbox->vport = vport; | |
2528 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == | |
2529 | MBX_NOT_FINISHED) { | |
2530 | mempool_free(mbox, phba->mbox_mem_pool); | |
086a345f | 2531 | skip_recovery = 1; |
92494144 JS |
2532 | } |
2533 | } | |
2534 | } | |
086a345f JS |
2535 | |
2536 | /* | |
2537 | * If the node is a target, the handling attempts to recover the port. | |
2538 | * For any other port type, the rpi is unregistered as an implicit | |
2539 | * LOGO. | |
2540 | */ | |
2541 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) { | |
2542 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
2543 | spin_lock_irqsave(shost->host_lock, flags); | |
2544 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
2545 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2546 | ||
2547 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
2548 | "3187 LOGO completes to NPort x%x: Start " | |
2549 | "Recovery Data: x%x x%x x%x x%x\n", | |
2550 | ndlp->nlp_DID, irsp->ulpStatus, | |
2551 | irsp->un.ulpWord[4], irsp->ulpTimeout, | |
2552 | vport->num_disc_nodes); | |
2553 | lpfc_disc_start(vport); | |
2554 | } | |
dea3101e JB |
2555 | return; |
2556 | } | |
2557 | ||
e59058c4 | 2558 | /** |
3621a710 | 2559 | * lpfc_issue_els_logo - Issue a logo to an node on a vport |
e59058c4 JS |
2560 | * @vport: pointer to a virtual N_Port data structure. |
2561 | * @ndlp: pointer to a node-list data structure. | |
2562 | * @retry: number of retries to the command IOCB. | |
2563 | * | |
2564 | * This routine constructs and issues an ELS Logout (LOGO) iocb command | |
2565 | * to a remote node, referred by an @ndlp on a @vport. It constructs the | |
2566 | * payload of the IOCB, properly sets up the @ndlp state, and invokes the | |
2567 | * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. | |
2568 | * | |
2569 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2570 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2571 | * will be stored into the context1 field of the IOCB for the completion | |
2572 | * callback function to the LOGO ELS command. | |
2573 | * | |
2574 | * Return code | |
2575 | * 0 - successfully issued logo | |
2576 | * 1 - failed to issue logo | |
2577 | **/ | |
dea3101e | 2578 | int |
2e0fef85 | 2579 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
2580 | uint8_t retry) |
2581 | { | |
2e0fef85 JS |
2582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2583 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2584 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2585 | uint8_t *pcmd; |
2586 | uint16_t cmdsize; | |
92d7f7b0 | 2587 | int rc; |
dea3101e | 2588 | |
98c9ea5c JS |
2589 | spin_lock_irq(shost->host_lock); |
2590 | if (ndlp->nlp_flag & NLP_LOGO_SND) { | |
2591 | spin_unlock_irq(shost->host_lock); | |
2592 | return 0; | |
2593 | } | |
2594 | spin_unlock_irq(shost->host_lock); | |
2595 | ||
92d7f7b0 | 2596 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
2e0fef85 JS |
2597 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
2598 | ndlp->nlp_DID, ELS_CMD_LOGO); | |
488d1469 | 2599 | if (!elsiocb) |
c9f8735b | 2600 | return 1; |
dea3101e | 2601 | |
dea3101e JB |
2602 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2603 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
92d7f7b0 | 2604 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2605 | |
2606 | /* Fill in LOGO payload */ | |
2e0fef85 | 2607 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
92d7f7b0 JS |
2608 | pcmd += sizeof(uint32_t); |
2609 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
dea3101e | 2610 | |
858c9f6c JS |
2611 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2612 | "Issue LOGO: did:x%x", | |
2613 | ndlp->nlp_DID, 0, 0); | |
2614 | ||
086a345f JS |
2615 | /* |
2616 | * If we are issuing a LOGO, we may try to recover the remote NPort | |
2617 | * by issuing a PLOGI later. Even though we issue ELS cmds by the | |
2618 | * VPI, if we have a valid RPI, and that RPI gets unreg'ed while | |
2619 | * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI | |
2620 | * for that ELS cmd. To avoid this situation, lets get rid of the | |
2621 | * RPI right now, before any ELS cmds are sent. | |
2622 | */ | |
2623 | spin_lock_irq(shost->host_lock); | |
2624 | ndlp->nlp_flag |= NLP_ISSUE_LOGO; | |
2625 | spin_unlock_irq(shost->host_lock); | |
2626 | if (lpfc_unreg_rpi(vport, ndlp)) { | |
2627 | lpfc_els_free_iocb(phba, elsiocb); | |
2628 | return 0; | |
2629 | } | |
2630 | ||
dea3101e JB |
2631 | phba->fc_stat.elsXmitLOGO++; |
2632 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; | |
2e0fef85 | 2633 | spin_lock_irq(shost->host_lock); |
dea3101e | 2634 | ndlp->nlp_flag |= NLP_LOGO_SND; |
086a345f | 2635 | ndlp->nlp_flag &= ~NLP_ISSUE_LOGO; |
2e0fef85 | 2636 | spin_unlock_irq(shost->host_lock); |
3772a991 | 2637 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
92d7f7b0 JS |
2638 | |
2639 | if (rc == IOCB_ERROR) { | |
2e0fef85 | 2640 | spin_lock_irq(shost->host_lock); |
dea3101e | 2641 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 2642 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2643 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2644 | return 1; |
dea3101e | 2645 | } |
c9f8735b | 2646 | return 0; |
dea3101e JB |
2647 | } |
2648 | ||
e59058c4 | 2649 | /** |
3621a710 | 2650 | * lpfc_cmpl_els_cmd - Completion callback function for generic els command |
e59058c4 JS |
2651 | * @phba: pointer to lpfc hba data structure. |
2652 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
2653 | * @rspiocb: pointer to lpfc response iocb data structure. | |
2654 | * | |
2655 | * This routine is a generic completion callback function for ELS commands. | |
2656 | * Specifically, it is the callback function which does not need to perform | |
2657 | * any command specific operations. It is currently used by the ELS command | |
2658 | * issuing routines for the ELS State Change Request (SCR), | |
2659 | * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution | |
2660 | * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than | |
2661 | * certain debug loggings, this callback function simply invokes the | |
2662 | * lpfc_els_chk_latt() routine to check whether link went down during the | |
2663 | * discovery process. | |
2664 | **/ | |
dea3101e | 2665 | static void |
2e0fef85 JS |
2666 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2667 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2668 | { |
2e0fef85 | 2669 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
2670 | IOCB_t *irsp; |
2671 | ||
2672 | irsp = &rspiocb->iocb; | |
2673 | ||
858c9f6c JS |
2674 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2675 | "ELS cmd cmpl: status:x%x/x%x did:x%x", | |
2676 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
2677 | irsp->un.elsreq64.remoteID); | |
dea3101e | 2678 | /* ELS cmd tag <ulpIoTag> completes */ |
e8b62011 JS |
2679 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2680 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", | |
2681 | irsp->ulpIoTag, irsp->ulpStatus, | |
2682 | irsp->un.ulpWord[4], irsp->ulpTimeout); | |
dea3101e | 2683 | /* Check to see if link went down during discovery */ |
2e0fef85 | 2684 | lpfc_els_chk_latt(vport); |
dea3101e JB |
2685 | lpfc_els_free_iocb(phba, cmdiocb); |
2686 | return; | |
2687 | } | |
2688 | ||
e59058c4 | 2689 | /** |
3621a710 | 2690 | * lpfc_issue_els_scr - Issue a scr to an node on a vport |
e59058c4 JS |
2691 | * @vport: pointer to a host virtual N_Port data structure. |
2692 | * @nportid: N_Port identifier to the remote node. | |
2693 | * @retry: number of retries to the command IOCB. | |
2694 | * | |
2695 | * This routine issues a State Change Request (SCR) to a fabric node | |
2696 | * on a @vport. The remote node @nportid is passed into the function. It | |
2697 | * first search the @vport node list to find the matching ndlp. If no such | |
2698 | * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An | |
2699 | * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() | |
2700 | * routine is invoked to send the SCR IOCB. | |
2701 | * | |
2702 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2703 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2704 | * will be stored into the context1 field of the IOCB for the completion | |
2705 | * callback function to the SCR ELS command. | |
2706 | * | |
2707 | * Return code | |
2708 | * 0 - Successfully issued scr command | |
2709 | * 1 - Failed to issue scr command | |
2710 | **/ | |
dea3101e | 2711 | int |
2e0fef85 | 2712 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 2713 | { |
2e0fef85 | 2714 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2715 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2716 | uint8_t *pcmd; |
2717 | uint16_t cmdsize; | |
2718 | struct lpfc_nodelist *ndlp; | |
2719 | ||
92d7f7b0 | 2720 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
dea3101e | 2721 | |
e47c9093 JS |
2722 | ndlp = lpfc_findnode_did(vport, nportid); |
2723 | if (!ndlp) { | |
2724 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
2725 | if (!ndlp) | |
2726 | return 1; | |
2727 | lpfc_nlp_init(vport, ndlp, nportid); | |
2728 | lpfc_enqueue_node(vport, ndlp); | |
2729 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
2730 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
2731 | if (!ndlp) | |
2732 | return 1; | |
2733 | } | |
2e0fef85 JS |
2734 | |
2735 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
2736 | ndlp->nlp_DID, ELS_CMD_SCR); | |
dea3101e | 2737 | |
488d1469 | 2738 | if (!elsiocb) { |
fa4066b6 JS |
2739 | /* This will trigger the release of the node just |
2740 | * allocated | |
2741 | */ | |
329f9bc7 | 2742 | lpfc_nlp_put(ndlp); |
c9f8735b | 2743 | return 1; |
dea3101e JB |
2744 | } |
2745 | ||
dea3101e JB |
2746 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2747 | ||
2748 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; | |
92d7f7b0 | 2749 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2750 | |
2751 | /* For SCR, remainder of payload is SCR parameter page */ | |
92d7f7b0 | 2752 | memset(pcmd, 0, sizeof(SCR)); |
dea3101e JB |
2753 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
2754 | ||
858c9f6c JS |
2755 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2756 | "Issue SCR: did:x%x", | |
2757 | ndlp->nlp_DID, 0, 0); | |
2758 | ||
dea3101e JB |
2759 | phba->fc_stat.elsXmitSCR++; |
2760 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
3772a991 JS |
2761 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2762 | IOCB_ERROR) { | |
fa4066b6 JS |
2763 | /* The additional lpfc_nlp_put will cause the following |
2764 | * lpfc_els_free_iocb routine to trigger the rlease of | |
2765 | * the node. | |
2766 | */ | |
329f9bc7 | 2767 | lpfc_nlp_put(ndlp); |
dea3101e | 2768 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2769 | return 1; |
dea3101e | 2770 | } |
fa4066b6 JS |
2771 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
2772 | * trigger the release of node. | |
2773 | */ | |
cff261f6 | 2774 | |
329f9bc7 | 2775 | lpfc_nlp_put(ndlp); |
c9f8735b | 2776 | return 0; |
dea3101e JB |
2777 | } |
2778 | ||
e59058c4 | 2779 | /** |
3621a710 | 2780 | * lpfc_issue_els_farpr - Issue a farp to an node on a vport |
e59058c4 JS |
2781 | * @vport: pointer to a host virtual N_Port data structure. |
2782 | * @nportid: N_Port identifier to the remote node. | |
2783 | * @retry: number of retries to the command IOCB. | |
2784 | * | |
2785 | * This routine issues a Fibre Channel Address Resolution Response | |
2786 | * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) | |
2787 | * is passed into the function. It first search the @vport node list to find | |
2788 | * the matching ndlp. If no such ndlp is found, a new ndlp shall be created | |
2789 | * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the | |
2790 | * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. | |
2791 | * | |
2792 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
2793 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
2794 | * will be stored into the context1 field of the IOCB for the completion | |
2795 | * callback function to the PARPR ELS command. | |
2796 | * | |
2797 | * Return code | |
2798 | * 0 - Successfully issued farpr command | |
2799 | * 1 - Failed to issue farpr command | |
2800 | **/ | |
dea3101e | 2801 | static int |
2e0fef85 | 2802 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 2803 | { |
2e0fef85 | 2804 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2805 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2806 | FARP *fp; |
2807 | uint8_t *pcmd; | |
2808 | uint32_t *lp; | |
2809 | uint16_t cmdsize; | |
2810 | struct lpfc_nodelist *ondlp; | |
2811 | struct lpfc_nodelist *ndlp; | |
2812 | ||
92d7f7b0 | 2813 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
dea3101e | 2814 | |
e47c9093 JS |
2815 | ndlp = lpfc_findnode_did(vport, nportid); |
2816 | if (!ndlp) { | |
2817 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
2818 | if (!ndlp) | |
2819 | return 1; | |
2820 | lpfc_nlp_init(vport, ndlp, nportid); | |
2821 | lpfc_enqueue_node(vport, ndlp); | |
2822 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
2823 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
2824 | if (!ndlp) | |
2825 | return 1; | |
2826 | } | |
2e0fef85 JS |
2827 | |
2828 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
2829 | ndlp->nlp_DID, ELS_CMD_RNID); | |
488d1469 | 2830 | if (!elsiocb) { |
fa4066b6 JS |
2831 | /* This will trigger the release of the node just |
2832 | * allocated | |
2833 | */ | |
329f9bc7 | 2834 | lpfc_nlp_put(ndlp); |
c9f8735b | 2835 | return 1; |
dea3101e JB |
2836 | } |
2837 | ||
dea3101e JB |
2838 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2839 | ||
2840 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; | |
92d7f7b0 | 2841 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2842 | |
2843 | /* Fill in FARPR payload */ | |
2844 | fp = (FARP *) (pcmd); | |
92d7f7b0 | 2845 | memset(fp, 0, sizeof(FARP)); |
dea3101e JB |
2846 | lp = (uint32_t *) pcmd; |
2847 | *lp++ = be32_to_cpu(nportid); | |
2e0fef85 | 2848 | *lp++ = be32_to_cpu(vport->fc_myDID); |
dea3101e JB |
2849 | fp->Rflags = 0; |
2850 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); | |
2851 | ||
92d7f7b0 JS |
2852 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
2853 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 2854 | ondlp = lpfc_findnode_did(vport, nportid); |
e47c9093 | 2855 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
dea3101e | 2856 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
92d7f7b0 | 2857 | sizeof(struct lpfc_name)); |
dea3101e | 2858 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
92d7f7b0 | 2859 | sizeof(struct lpfc_name)); |
dea3101e JB |
2860 | } |
2861 | ||
858c9f6c JS |
2862 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
2863 | "Issue FARPR: did:x%x", | |
2864 | ndlp->nlp_DID, 0, 0); | |
2865 | ||
dea3101e JB |
2866 | phba->fc_stat.elsXmitFARPR++; |
2867 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
3772a991 JS |
2868 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
2869 | IOCB_ERROR) { | |
fa4066b6 JS |
2870 | /* The additional lpfc_nlp_put will cause the following |
2871 | * lpfc_els_free_iocb routine to trigger the release of | |
2872 | * the node. | |
2873 | */ | |
329f9bc7 | 2874 | lpfc_nlp_put(ndlp); |
dea3101e | 2875 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 2876 | return 1; |
dea3101e | 2877 | } |
fa4066b6 JS |
2878 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
2879 | * trigger the release of the node. | |
2880 | */ | |
329f9bc7 | 2881 | lpfc_nlp_put(ndlp); |
c9f8735b | 2882 | return 0; |
dea3101e JB |
2883 | } |
2884 | ||
e59058c4 | 2885 | /** |
3621a710 | 2886 | * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry |
e59058c4 JS |
2887 | * @vport: pointer to a host virtual N_Port data structure. |
2888 | * @nlp: pointer to a node-list data structure. | |
2889 | * | |
2890 | * This routine cancels the timer with a delayed IOCB-command retry for | |
2891 | * a @vport's @ndlp. It stops the timer for the delayed function retrial and | |
2892 | * removes the ELS retry event if it presents. In addition, if the | |
2893 | * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB | |
2894 | * commands are sent for the @vport's nodes that require issuing discovery | |
2895 | * ADISC. | |
2896 | **/ | |
fdcebe28 | 2897 | void |
2e0fef85 | 2898 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
fdcebe28 | 2899 | { |
2e0fef85 | 2900 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
e47c9093 | 2901 | struct lpfc_work_evt *evtp; |
2e0fef85 | 2902 | |
0d2b6b83 JS |
2903 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
2904 | return; | |
2e0fef85 | 2905 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 2906 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
2e0fef85 | 2907 | spin_unlock_irq(shost->host_lock); |
fdcebe28 JS |
2908 | del_timer_sync(&nlp->nlp_delayfunc); |
2909 | nlp->nlp_last_elscmd = 0; | |
e47c9093 | 2910 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
fdcebe28 | 2911 | list_del_init(&nlp->els_retry_evt.evt_listp); |
e47c9093 JS |
2912 | /* Decrement nlp reference count held for the delayed retry */ |
2913 | evtp = &nlp->els_retry_evt; | |
2914 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | |
2915 | } | |
fdcebe28 | 2916 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
2e0fef85 | 2917 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 2918 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 JS |
2919 | spin_unlock_irq(shost->host_lock); |
2920 | if (vport->num_disc_nodes) { | |
0d2b6b83 JS |
2921 | if (vport->port_state < LPFC_VPORT_READY) { |
2922 | /* Check if there are more ADISCs to be sent */ | |
2923 | lpfc_more_adisc(vport); | |
0d2b6b83 JS |
2924 | } else { |
2925 | /* Check if there are more PLOGIs to be sent */ | |
2926 | lpfc_more_plogi(vport); | |
90160e01 JS |
2927 | if (vport->num_disc_nodes == 0) { |
2928 | spin_lock_irq(shost->host_lock); | |
2929 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
2930 | spin_unlock_irq(shost->host_lock); | |
2931 | lpfc_can_disctmo(vport); | |
2932 | lpfc_end_rscn(vport); | |
2933 | } | |
fdcebe28 JS |
2934 | } |
2935 | } | |
2936 | } | |
2937 | return; | |
2938 | } | |
2939 | ||
e59058c4 | 2940 | /** |
3621a710 | 2941 | * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer |
e59058c4 JS |
2942 | * @ptr: holder for the pointer to the timer function associated data (ndlp). |
2943 | * | |
2944 | * This routine is invoked by the ndlp delayed-function timer to check | |
2945 | * whether there is any pending ELS retry event(s) with the node. If not, it | |
2946 | * simply returns. Otherwise, if there is at least one ELS delayed event, it | |
2947 | * adds the delayed events to the HBA work list and invokes the | |
2948 | * lpfc_worker_wake_up() routine to wake up worker thread to process the | |
2949 | * event. Note that lpfc_nlp_get() is called before posting the event to | |
2950 | * the work list to hold reference count of ndlp so that it guarantees the | |
2951 | * reference to ndlp will still be available when the worker thread gets | |
2952 | * to the event associated with the ndlp. | |
2953 | **/ | |
dea3101e JB |
2954 | void |
2955 | lpfc_els_retry_delay(unsigned long ptr) | |
2956 | { | |
2e0fef85 JS |
2957 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
2958 | struct lpfc_vport *vport = ndlp->vport; | |
2e0fef85 | 2959 | struct lpfc_hba *phba = vport->phba; |
92d7f7b0 | 2960 | unsigned long flags; |
2e0fef85 | 2961 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
dea3101e | 2962 | |
92d7f7b0 | 2963 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 2964 | if (!list_empty(&evtp->evt_listp)) { |
92d7f7b0 | 2965 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
2966 | return; |
2967 | } | |
2968 | ||
fa4066b6 JS |
2969 | /* We need to hold the node by incrementing the reference |
2970 | * count until the queued work is done | |
2971 | */ | |
2972 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); | |
5e9d9b82 JS |
2973 | if (evtp->evt_arg1) { |
2974 | evtp->evt = LPFC_EVT_ELS_RETRY; | |
2975 | list_add_tail(&evtp->evt_listp, &phba->work_list); | |
92d7f7b0 | 2976 | lpfc_worker_wake_up(phba); |
5e9d9b82 | 2977 | } |
92d7f7b0 | 2978 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
2979 | return; |
2980 | } | |
2981 | ||
e59058c4 | 2982 | /** |
3621a710 | 2983 | * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function |
e59058c4 JS |
2984 | * @ndlp: pointer to a node-list data structure. |
2985 | * | |
2986 | * This routine is the worker-thread handler for processing the @ndlp delayed | |
2987 | * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves | |
2988 | * the last ELS command from the associated ndlp and invokes the proper ELS | |
2989 | * function according to the delayed ELS command to retry the command. | |
2990 | **/ | |
dea3101e JB |
2991 | void |
2992 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) | |
2993 | { | |
2e0fef85 JS |
2994 | struct lpfc_vport *vport = ndlp->vport; |
2995 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
eb016566 | 2996 | uint32_t cmd, retry; |
dea3101e | 2997 | |
2e0fef85 | 2998 | spin_lock_irq(shost->host_lock); |
5024ab17 JW |
2999 | cmd = ndlp->nlp_last_elscmd; |
3000 | ndlp->nlp_last_elscmd = 0; | |
dea3101e JB |
3001 | |
3002 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
2e0fef85 | 3003 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
3004 | return; |
3005 | } | |
3006 | ||
3007 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | |
2e0fef85 | 3008 | spin_unlock_irq(shost->host_lock); |
1a169689 JS |
3009 | /* |
3010 | * If a discovery event readded nlp_delayfunc after timer | |
3011 | * firing and before processing the timer, cancel the | |
3012 | * nlp_delayfunc. | |
3013 | */ | |
3014 | del_timer_sync(&ndlp->nlp_delayfunc); | |
dea3101e | 3015 | retry = ndlp->nlp_retry; |
4d9ab994 | 3016 | ndlp->nlp_retry = 0; |
dea3101e JB |
3017 | |
3018 | switch (cmd) { | |
3019 | case ELS_CMD_FLOGI: | |
2e0fef85 | 3020 | lpfc_issue_els_flogi(vport, ndlp, retry); |
dea3101e JB |
3021 | break; |
3022 | case ELS_CMD_PLOGI: | |
2e0fef85 | 3023 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
5024ab17 | 3024 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3025 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
6ad42535 | 3026 | } |
dea3101e JB |
3027 | break; |
3028 | case ELS_CMD_ADISC: | |
2e0fef85 | 3029 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
5024ab17 | 3030 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3031 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
6ad42535 | 3032 | } |
dea3101e JB |
3033 | break; |
3034 | case ELS_CMD_PRLI: | |
2e0fef85 | 3035 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
5024ab17 | 3036 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3037 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
6ad42535 | 3038 | } |
dea3101e JB |
3039 | break; |
3040 | case ELS_CMD_LOGO: | |
2e0fef85 | 3041 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
5024ab17 | 3042 | ndlp->nlp_prev_state = ndlp->nlp_state; |
086a345f | 3043 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
6ad42535 | 3044 | } |
dea3101e | 3045 | break; |
92d7f7b0 | 3046 | case ELS_CMD_FDISC: |
fedd3b7b JS |
3047 | if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)) |
3048 | lpfc_issue_els_fdisc(vport, ndlp, retry); | |
92d7f7b0 | 3049 | break; |
dea3101e JB |
3050 | } |
3051 | return; | |
3052 | } | |
3053 | ||
e59058c4 | 3054 | /** |
3621a710 | 3055 | * lpfc_els_retry - Make retry decision on an els command iocb |
e59058c4 JS |
3056 | * @phba: pointer to lpfc hba data structure. |
3057 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3058 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3059 | * | |
3060 | * This routine makes a retry decision on an ELS command IOCB, which has | |
3061 | * failed. The following ELS IOCBs use this function for retrying the command | |
3062 | * when previously issued command responsed with error status: FLOGI, PLOGI, | |
3063 | * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the | |
3064 | * returned error status, it makes the decision whether a retry shall be | |
3065 | * issued for the command, and whether a retry shall be made immediately or | |
3066 | * delayed. In the former case, the corresponding ELS command issuing-function | |
3067 | * is called to retry the command. In the later case, the ELS command shall | |
3068 | * be posted to the ndlp delayed event and delayed function timer set to the | |
3069 | * ndlp for the delayed command issusing. | |
3070 | * | |
3071 | * Return code | |
3072 | * 0 - No retry of els command is made | |
3073 | * 1 - Immediate or delayed retry of els command is made | |
3074 | **/ | |
dea3101e | 3075 | static int |
2e0fef85 JS |
3076 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
3077 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 3078 | { |
2e0fef85 JS |
3079 | struct lpfc_vport *vport = cmdiocb->vport; |
3080 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
3081 | IOCB_t *irsp = &rspiocb->iocb; | |
3082 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
3083 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
dea3101e JB |
3084 | uint32_t *elscmd; |
3085 | struct ls_rjt stat; | |
2e0fef85 | 3086 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
98c9ea5c | 3087 | int logerr = 0; |
2e0fef85 | 3088 | uint32_t cmd = 0; |
488d1469 | 3089 | uint32_t did; |
dea3101e | 3090 | |
488d1469 | 3091 | |
dea3101e JB |
3092 | /* Note: context2 may be 0 for internal driver abort |
3093 | * of delays ELS command. | |
3094 | */ | |
3095 | ||
3096 | if (pcmd && pcmd->virt) { | |
3097 | elscmd = (uint32_t *) (pcmd->virt); | |
3098 | cmd = *elscmd++; | |
3099 | } | |
3100 | ||
e47c9093 | 3101 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
488d1469 JS |
3102 | did = ndlp->nlp_DID; |
3103 | else { | |
3104 | /* We should only hit this case for retrying PLOGI */ | |
3105 | did = irsp->un.elsreq64.remoteID; | |
2e0fef85 | 3106 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
3107 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
3108 | && (cmd != ELS_CMD_PLOGI)) | |
488d1469 JS |
3109 | return 1; |
3110 | } | |
3111 | ||
858c9f6c JS |
3112 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
3113 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", | |
3114 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); | |
3115 | ||
dea3101e JB |
3116 | switch (irsp->ulpStatus) { |
3117 | case IOSTAT_FCP_RSP_ERROR: | |
1151e3ec | 3118 | break; |
dea3101e | 3119 | case IOSTAT_REMOTE_STOP: |
1151e3ec JS |
3120 | if (phba->sli_rev == LPFC_SLI_REV4) { |
3121 | /* This IO was aborted by the target, we don't | |
3122 | * know the rxid and because we did not send the | |
3123 | * ABTS we cannot generate and RRQ. | |
3124 | */ | |
3125 | lpfc_set_rrq_active(phba, ndlp, | |
ee0f4fe1 | 3126 | cmdiocb->sli4_lxritag, 0, 0); |
1151e3ec | 3127 | } |
dea3101e | 3128 | break; |
dea3101e | 3129 | case IOSTAT_LOCAL_REJECT: |
e3d2b802 | 3130 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
dea3101e | 3131 | case IOERR_LOOP_OPEN_FAILURE: |
eaf15d5b JS |
3132 | if (cmd == ELS_CMD_FLOGI) { |
3133 | if (PCI_DEVICE_ID_HORNET == | |
3134 | phba->pcidev->device) { | |
76a95d75 | 3135 | phba->fc_topology = LPFC_TOPOLOGY_LOOP; |
eaf15d5b JS |
3136 | phba->pport->fc_myDID = 0; |
3137 | phba->alpa_map[0] = 0; | |
3138 | phba->alpa_map[1] = 0; | |
3139 | } | |
3140 | } | |
2e0fef85 | 3141 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
92d7f7b0 | 3142 | delay = 1000; |
dea3101e JB |
3143 | retry = 1; |
3144 | break; | |
3145 | ||
92d7f7b0 | 3146 | case IOERR_ILLEGAL_COMMAND: |
7f5f3d0d JS |
3147 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3148 | "0124 Retry illegal cmd x%x " | |
3149 | "retry:x%x delay:x%x\n", | |
3150 | cmd, cmdiocb->retry, delay); | |
3151 | retry = 1; | |
3152 | /* All command's retry policy */ | |
3153 | maxretry = 8; | |
3154 | if (cmdiocb->retry > 2) | |
3155 | delay = 1000; | |
92d7f7b0 JS |
3156 | break; |
3157 | ||
dea3101e | 3158 | case IOERR_NO_RESOURCES: |
98c9ea5c | 3159 | logerr = 1; /* HBA out of resources */ |
858c9f6c JS |
3160 | retry = 1; |
3161 | if (cmdiocb->retry > 100) | |
3162 | delay = 100; | |
3163 | maxretry = 250; | |
3164 | break; | |
3165 | ||
3166 | case IOERR_ILLEGAL_FRAME: | |
92d7f7b0 | 3167 | delay = 100; |
dea3101e JB |
3168 | retry = 1; |
3169 | break; | |
3170 | ||
858c9f6c | 3171 | case IOERR_SEQUENCE_TIMEOUT: |
dea3101e | 3172 | case IOERR_INVALID_RPI: |
5b5b36a9 JS |
3173 | if (cmd == ELS_CMD_PLOGI && |
3174 | did == NameServer_DID) { | |
3175 | /* Continue forever if plogi to */ | |
3176 | /* the nameserver fails */ | |
3177 | maxretry = 0; | |
3178 | delay = 100; | |
3179 | } | |
dea3101e JB |
3180 | retry = 1; |
3181 | break; | |
3182 | } | |
3183 | break; | |
3184 | ||
3185 | case IOSTAT_NPORT_RJT: | |
3186 | case IOSTAT_FABRIC_RJT: | |
3187 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
3188 | retry = 1; | |
3189 | break; | |
3190 | } | |
3191 | break; | |
3192 | ||
3193 | case IOSTAT_NPORT_BSY: | |
3194 | case IOSTAT_FABRIC_BSY: | |
98c9ea5c | 3195 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
dea3101e JB |
3196 | retry = 1; |
3197 | break; | |
3198 | ||
3199 | case IOSTAT_LS_RJT: | |
3200 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); | |
3201 | /* Added for Vendor specifc support | |
3202 | * Just keep retrying for these Rsn / Exp codes | |
3203 | */ | |
3204 | switch (stat.un.b.lsRjtRsnCode) { | |
3205 | case LSRJT_UNABLE_TPC: | |
3206 | if (stat.un.b.lsRjtRsnCodeExp == | |
3207 | LSEXP_CMD_IN_PROGRESS) { | |
3208 | if (cmd == ELS_CMD_PLOGI) { | |
92d7f7b0 | 3209 | delay = 1000; |
dea3101e JB |
3210 | maxretry = 48; |
3211 | } | |
3212 | retry = 1; | |
3213 | break; | |
3214 | } | |
ffc95493 JS |
3215 | if (stat.un.b.lsRjtRsnCodeExp == |
3216 | LSEXP_CANT_GIVE_DATA) { | |
3217 | if (cmd == ELS_CMD_PLOGI) { | |
3218 | delay = 1000; | |
3219 | maxretry = 48; | |
3220 | } | |
3221 | retry = 1; | |
3222 | break; | |
3223 | } | |
4c1b64ba JS |
3224 | if ((cmd == ELS_CMD_PLOGI) || |
3225 | (cmd == ELS_CMD_PRLI)) { | |
92d7f7b0 | 3226 | delay = 1000; |
dea3101e JB |
3227 | maxretry = lpfc_max_els_tries + 1; |
3228 | retry = 1; | |
3229 | break; | |
3230 | } | |
92d7f7b0 JS |
3231 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
3232 | (cmd == ELS_CMD_FDISC) && | |
3233 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ | |
e8b62011 JS |
3234 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3235 | "0125 FDISC Failed (x%x). " | |
3236 | "Fabric out of resources\n", | |
3237 | stat.un.lsRjtError); | |
92d7f7b0 JS |
3238 | lpfc_vport_set_state(vport, |
3239 | FC_VPORT_NO_FABRIC_RSCS); | |
3240 | } | |
dea3101e JB |
3241 | break; |
3242 | ||
3243 | case LSRJT_LOGICAL_BSY: | |
858c9f6c JS |
3244 | if ((cmd == ELS_CMD_PLOGI) || |
3245 | (cmd == ELS_CMD_PRLI)) { | |
92d7f7b0 | 3246 | delay = 1000; |
dea3101e | 3247 | maxretry = 48; |
92d7f7b0 | 3248 | } else if (cmd == ELS_CMD_FDISC) { |
51ef4c26 JS |
3249 | /* FDISC retry policy */ |
3250 | maxretry = 48; | |
3251 | if (cmdiocb->retry >= 32) | |
3252 | delay = 1000; | |
dea3101e JB |
3253 | } |
3254 | retry = 1; | |
3255 | break; | |
92d7f7b0 JS |
3256 | |
3257 | case LSRJT_LOGICAL_ERR: | |
7f5f3d0d JS |
3258 | /* There are some cases where switches return this |
3259 | * error when they are not ready and should be returning | |
3260 | * Logical Busy. We should delay every time. | |
3261 | */ | |
3262 | if (cmd == ELS_CMD_FDISC && | |
3263 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { | |
3264 | maxretry = 3; | |
3265 | delay = 1000; | |
3266 | retry = 1; | |
3267 | break; | |
3268 | } | |
92d7f7b0 JS |
3269 | case LSRJT_PROTOCOL_ERR: |
3270 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
3271 | (cmd == ELS_CMD_FDISC) && | |
3272 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || | |
3273 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) | |
3274 | ) { | |
e8b62011 | 3275 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
d7c255b2 | 3276 | "0122 FDISC Failed (x%x). " |
e8b62011 JS |
3277 | "Fabric Detected Bad WWN\n", |
3278 | stat.un.lsRjtError); | |
92d7f7b0 JS |
3279 | lpfc_vport_set_state(vport, |
3280 | FC_VPORT_FABRIC_REJ_WWN); | |
3281 | } | |
3282 | break; | |
dea3101e JB |
3283 | } |
3284 | break; | |
3285 | ||
3286 | case IOSTAT_INTERMED_RSP: | |
3287 | case IOSTAT_BA_RJT: | |
3288 | break; | |
3289 | ||
3290 | default: | |
3291 | break; | |
3292 | } | |
3293 | ||
488d1469 | 3294 | if (did == FDMI_DID) |
dea3101e | 3295 | retry = 1; |
dea3101e | 3296 | |
df9e1b59 | 3297 | if ((cmd == ELS_CMD_FLOGI) && |
76a95d75 | 3298 | (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && |
1b32f6aa | 3299 | !lpfc_error_lost_link(irsp)) { |
98c9ea5c JS |
3300 | /* FLOGI retry policy */ |
3301 | retry = 1; | |
df9e1b59 | 3302 | /* retry FLOGI forever */ |
6eae4303 JS |
3303 | if (phba->link_flag != LS_LOOPBACK_MODE) |
3304 | maxretry = 0; | |
3305 | else | |
3306 | maxretry = 2; | |
3307 | ||
6669f9bb JS |
3308 | if (cmdiocb->retry >= 100) |
3309 | delay = 5000; | |
3310 | else if (cmdiocb->retry >= 32) | |
98c9ea5c | 3311 | delay = 1000; |
df9e1b59 JS |
3312 | } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) { |
3313 | /* retry FDISCs every second up to devloss */ | |
3314 | retry = 1; | |
3315 | maxretry = vport->cfg_devloss_tmo; | |
3316 | delay = 1000; | |
98c9ea5c JS |
3317 | } |
3318 | ||
6669f9bb JS |
3319 | cmdiocb->retry++; |
3320 | if (maxretry && (cmdiocb->retry >= maxretry)) { | |
dea3101e JB |
3321 | phba->fc_stat.elsRetryExceeded++; |
3322 | retry = 0; | |
3323 | } | |
3324 | ||
ed957684 JS |
3325 | if ((vport->load_flag & FC_UNLOADING) != 0) |
3326 | retry = 0; | |
3327 | ||
dea3101e | 3328 | if (retry) { |
38b92ef8 JS |
3329 | if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { |
3330 | /* Stop retrying PLOGI and FDISC if in FCF discovery */ | |
3331 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { | |
3332 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
3333 | "2849 Stop retry ELS command " | |
3334 | "x%x to remote NPORT x%x, " | |
3335 | "Data: x%x x%x\n", cmd, did, | |
3336 | cmdiocb->retry, delay); | |
3337 | return 0; | |
3338 | } | |
3339 | } | |
dea3101e JB |
3340 | |
3341 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
3342 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3343 | "0107 Retry ELS command x%x to remote " | |
3344 | "NPORT x%x Data: x%x x%x\n", | |
3345 | cmd, did, cmdiocb->retry, delay); | |
dea3101e | 3346 | |
858c9f6c JS |
3347 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
3348 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | |
e3d2b802 JS |
3349 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
3350 | IOERR_NO_RESOURCES))) { | |
858c9f6c JS |
3351 | /* Don't reset timer for no resources */ |
3352 | ||
dea3101e | 3353 | /* If discovery / RSCN timer is running, reset it */ |
2e0fef85 | 3354 | if (timer_pending(&vport->fc_disctmo) || |
92d7f7b0 | 3355 | (vport->fc_flag & FC_RSCN_MODE)) |
2e0fef85 | 3356 | lpfc_set_disctmo(vport); |
dea3101e JB |
3357 | } |
3358 | ||
3359 | phba->fc_stat.elsXmitRetry++; | |
58da1ffb | 3360 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
dea3101e JB |
3361 | phba->fc_stat.elsDelayRetry++; |
3362 | ndlp->nlp_retry = cmdiocb->retry; | |
3363 | ||
92d7f7b0 JS |
3364 | /* delay is specified in milliseconds */ |
3365 | mod_timer(&ndlp->nlp_delayfunc, | |
3366 | jiffies + msecs_to_jiffies(delay)); | |
2e0fef85 | 3367 | spin_lock_irq(shost->host_lock); |
dea3101e | 3368 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 3369 | spin_unlock_irq(shost->host_lock); |
dea3101e | 3370 | |
5024ab17 | 3371 | ndlp->nlp_prev_state = ndlp->nlp_state; |
858c9f6c JS |
3372 | if (cmd == ELS_CMD_PRLI) |
3373 | lpfc_nlp_set_state(vport, ndlp, | |
4c1b64ba | 3374 | NLP_STE_PRLI_ISSUE); |
858c9f6c JS |
3375 | else |
3376 | lpfc_nlp_set_state(vport, ndlp, | |
3377 | NLP_STE_NPR_NODE); | |
dea3101e JB |
3378 | ndlp->nlp_last_elscmd = cmd; |
3379 | ||
c9f8735b | 3380 | return 1; |
dea3101e JB |
3381 | } |
3382 | switch (cmd) { | |
3383 | case ELS_CMD_FLOGI: | |
2e0fef85 | 3384 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
c9f8735b | 3385 | return 1; |
92d7f7b0 JS |
3386 | case ELS_CMD_FDISC: |
3387 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); | |
3388 | return 1; | |
dea3101e | 3389 | case ELS_CMD_PLOGI: |
58da1ffb | 3390 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
488d1469 | 3391 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3392 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 3393 | NLP_STE_PLOGI_ISSUE); |
488d1469 | 3394 | } |
2e0fef85 | 3395 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
c9f8735b | 3396 | return 1; |
dea3101e | 3397 | case ELS_CMD_ADISC: |
5024ab17 | 3398 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
3399 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
3400 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 3401 | return 1; |
dea3101e | 3402 | case ELS_CMD_PRLI: |
5024ab17 | 3403 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
3404 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
3405 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 3406 | return 1; |
dea3101e | 3407 | case ELS_CMD_LOGO: |
5024ab17 | 3408 | ndlp->nlp_prev_state = ndlp->nlp_state; |
086a345f | 3409 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); |
2e0fef85 | 3410 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
c9f8735b | 3411 | return 1; |
dea3101e JB |
3412 | } |
3413 | } | |
dea3101e | 3414 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
98c9ea5c JS |
3415 | if (logerr) { |
3416 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
3417 | "0137 No retry ELS command x%x to remote " | |
3418 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", | |
3419 | cmd, did, irsp->ulpStatus, | |
3420 | irsp->un.ulpWord[4]); | |
3421 | } | |
3422 | else { | |
3423 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
a58cbd52 JS |
3424 | "0108 No retry ELS command x%x to remote " |
3425 | "NPORT x%x Retried:%d Error:x%x/%x\n", | |
3426 | cmd, did, cmdiocb->retry, irsp->ulpStatus, | |
3427 | irsp->un.ulpWord[4]); | |
98c9ea5c | 3428 | } |
c9f8735b | 3429 | return 0; |
dea3101e JB |
3430 | } |
3431 | ||
e59058c4 | 3432 | /** |
3621a710 | 3433 | * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb |
e59058c4 JS |
3434 | * @phba: pointer to lpfc hba data structure. |
3435 | * @buf_ptr1: pointer to the lpfc DMA buffer data structure. | |
3436 | * | |
3437 | * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) | |
3438 | * associated with a command IOCB back to the lpfc DMA buffer pool. It first | |
3439 | * checks to see whether there is a lpfc DMA buffer associated with the | |
3440 | * response of the command IOCB. If so, it will be released before releasing | |
3441 | * the lpfc DMA buffer associated with the IOCB itself. | |
3442 | * | |
3443 | * Return code | |
3444 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) | |
3445 | **/ | |
09372820 | 3446 | static int |
87af33fe JS |
3447 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
3448 | { | |
3449 | struct lpfc_dmabuf *buf_ptr; | |
3450 | ||
e59058c4 | 3451 | /* Free the response before processing the command. */ |
87af33fe JS |
3452 | if (!list_empty(&buf_ptr1->list)) { |
3453 | list_remove_head(&buf_ptr1->list, buf_ptr, | |
3454 | struct lpfc_dmabuf, | |
3455 | list); | |
3456 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
3457 | kfree(buf_ptr); | |
3458 | } | |
3459 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); | |
3460 | kfree(buf_ptr1); | |
3461 | return 0; | |
3462 | } | |
3463 | ||
e59058c4 | 3464 | /** |
3621a710 | 3465 | * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl |
e59058c4 JS |
3466 | * @phba: pointer to lpfc hba data structure. |
3467 | * @buf_ptr: pointer to the lpfc dma buffer data structure. | |
3468 | * | |
3469 | * This routine releases the lpfc Direct Memory Access (DMA) buffer | |
3470 | * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer | |
3471 | * pool. | |
3472 | * | |
3473 | * Return code | |
3474 | * 0 - Successfully released lpfc DMA buffer (currently, always return 0) | |
3475 | **/ | |
09372820 | 3476 | static int |
87af33fe JS |
3477 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
3478 | { | |
3479 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
3480 | kfree(buf_ptr); | |
3481 | return 0; | |
3482 | } | |
3483 | ||
e59058c4 | 3484 | /** |
3621a710 | 3485 | * lpfc_els_free_iocb - Free a command iocb and its associated resources |
e59058c4 JS |
3486 | * @phba: pointer to lpfc hba data structure. |
3487 | * @elsiocb: pointer to lpfc els command iocb data structure. | |
3488 | * | |
3489 | * This routine frees a command IOCB and its associated resources. The | |
3490 | * command IOCB data structure contains the reference to various associated | |
3491 | * resources, these fields must be set to NULL if the associated reference | |
3492 | * not present: | |
3493 | * context1 - reference to ndlp | |
3494 | * context2 - reference to cmd | |
3495 | * context2->next - reference to rsp | |
3496 | * context3 - reference to bpl | |
3497 | * | |
3498 | * It first properly decrements the reference count held on ndlp for the | |
3499 | * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not | |
3500 | * set, it invokes the lpfc_els_free_data() routine to release the Direct | |
3501 | * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it | |
3502 | * adds the DMA buffer the @phba data structure for the delayed release. | |
3503 | * If reference to the Buffer Pointer List (BPL) is present, the | |
3504 | * lpfc_els_free_bpl() routine is invoked to release the DMA memory | |
3505 | * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is | |
3506 | * invoked to release the IOCB data structure back to @phba IOCBQ list. | |
3507 | * | |
3508 | * Return code | |
3509 | * 0 - Success (currently, always return 0) | |
3510 | **/ | |
dea3101e | 3511 | int |
329f9bc7 | 3512 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
dea3101e JB |
3513 | { |
3514 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; | |
a8adb832 JS |
3515 | struct lpfc_nodelist *ndlp; |
3516 | ||
3517 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; | |
3518 | if (ndlp) { | |
3519 | if (ndlp->nlp_flag & NLP_DEFER_RM) { | |
3520 | lpfc_nlp_put(ndlp); | |
dea3101e | 3521 | |
a8adb832 JS |
3522 | /* If the ndlp is not being used by another discovery |
3523 | * thread, free it. | |
3524 | */ | |
3525 | if (!lpfc_nlp_not_used(ndlp)) { | |
3526 | /* If ndlp is being used by another discovery | |
3527 | * thread, just clear NLP_DEFER_RM | |
3528 | */ | |
3529 | ndlp->nlp_flag &= ~NLP_DEFER_RM; | |
3530 | } | |
3531 | } | |
3532 | else | |
3533 | lpfc_nlp_put(ndlp); | |
329f9bc7 JS |
3534 | elsiocb->context1 = NULL; |
3535 | } | |
dea3101e JB |
3536 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
3537 | if (elsiocb->context2) { | |
0ff10d46 JS |
3538 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
3539 | /* Firmware could still be in progress of DMAing | |
3540 | * payload, so don't free data buffer till after | |
3541 | * a hbeat. | |
3542 | */ | |
3543 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; | |
3544 | buf_ptr = elsiocb->context2; | |
3545 | elsiocb->context2 = NULL; | |
3546 | if (buf_ptr) { | |
3547 | buf_ptr1 = NULL; | |
3548 | spin_lock_irq(&phba->hbalock); | |
3549 | if (!list_empty(&buf_ptr->list)) { | |
3550 | list_remove_head(&buf_ptr->list, | |
3551 | buf_ptr1, struct lpfc_dmabuf, | |
3552 | list); | |
3553 | INIT_LIST_HEAD(&buf_ptr1->list); | |
3554 | list_add_tail(&buf_ptr1->list, | |
3555 | &phba->elsbuf); | |
3556 | phba->elsbuf_cnt++; | |
3557 | } | |
3558 | INIT_LIST_HEAD(&buf_ptr->list); | |
3559 | list_add_tail(&buf_ptr->list, &phba->elsbuf); | |
3560 | phba->elsbuf_cnt++; | |
3561 | spin_unlock_irq(&phba->hbalock); | |
3562 | } | |
3563 | } else { | |
3564 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; | |
3565 | lpfc_els_free_data(phba, buf_ptr1); | |
3566 | } | |
dea3101e JB |
3567 | } |
3568 | ||
3569 | if (elsiocb->context3) { | |
3570 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; | |
87af33fe | 3571 | lpfc_els_free_bpl(phba, buf_ptr); |
dea3101e | 3572 | } |
604a3e30 | 3573 | lpfc_sli_release_iocbq(phba, elsiocb); |
dea3101e JB |
3574 | return 0; |
3575 | } | |
3576 | ||
e59058c4 | 3577 | /** |
3621a710 | 3578 | * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response |
e59058c4 JS |
3579 | * @phba: pointer to lpfc hba data structure. |
3580 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3581 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3582 | * | |
3583 | * This routine is the completion callback function to the Logout (LOGO) | |
3584 | * Accept (ACC) Response ELS command. This routine is invoked to indicate | |
3585 | * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to | |
3586 | * release the ndlp if it has the last reference remaining (reference count | |
3587 | * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1 | |
3588 | * field to NULL to inform the following lpfc_els_free_iocb() routine no | |
3589 | * ndlp reference count needs to be decremented. Otherwise, the ndlp | |
3590 | * reference use-count shall be decremented by the lpfc_els_free_iocb() | |
3591 | * routine. Finally, the lpfc_els_free_iocb() is invoked to release the | |
3592 | * IOCB data structure. | |
3593 | **/ | |
dea3101e | 3594 | static void |
2e0fef85 JS |
3595 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
3596 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 3597 | { |
2e0fef85 JS |
3598 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
3599 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c JS |
3600 | IOCB_t *irsp; |
3601 | ||
3602 | irsp = &rspiocb->iocb; | |
3603 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
3604 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", | |
3605 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); | |
dea3101e | 3606 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
3607 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3608 | "0109 ACC to LOGO completes to NPort x%x " | |
3609 | "Data: x%x x%x x%x\n", | |
3610 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3611 | ndlp->nlp_rpi); | |
87af33fe JS |
3612 | |
3613 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | |
3614 | /* NPort Recovery mode or node is just allocated */ | |
3615 | if (!lpfc_nlp_not_used(ndlp)) { | |
3616 | /* If the ndlp is being used by another discovery | |
3617 | * thread, just unregister the RPI. | |
3618 | */ | |
3619 | lpfc_unreg_rpi(vport, ndlp); | |
fa4066b6 JS |
3620 | } else { |
3621 | /* Indicate the node has already released, should | |
3622 | * not reference to it from within lpfc_els_free_iocb. | |
3623 | */ | |
3624 | cmdiocb->context1 = NULL; | |
87af33fe | 3625 | } |
dea3101e | 3626 | } |
73d91e50 JS |
3627 | |
3628 | /* | |
3629 | * The driver received a LOGO from the rport and has ACK'd it. | |
df9e1b59 | 3630 | * At this point, the driver is done so release the IOCB |
73d91e50 | 3631 | */ |
dea3101e | 3632 | lpfc_els_free_iocb(phba, cmdiocb); |
dea3101e JB |
3633 | } |
3634 | ||
e59058c4 | 3635 | /** |
3621a710 | 3636 | * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd |
e59058c4 JS |
3637 | * @phba: pointer to lpfc hba data structure. |
3638 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
3639 | * | |
3640 | * This routine is the completion callback function for unregister default | |
3641 | * RPI (Remote Port Index) mailbox command to the @phba. It simply releases | |
3642 | * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and | |
3643 | * decrements the ndlp reference count held for this completion callback | |
3644 | * function. After that, it invokes the lpfc_nlp_not_used() to check | |
3645 | * whether there is only one reference left on the ndlp. If so, it will | |
3646 | * perform one more decrement and trigger the release of the ndlp. | |
3647 | **/ | |
858c9f6c JS |
3648 | void |
3649 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
3650 | { | |
3651 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | |
3652 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
3653 | ||
3654 | pmb->context1 = NULL; | |
d439d286 JS |
3655 | pmb->context2 = NULL; |
3656 | ||
858c9f6c JS |
3657 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3658 | kfree(mp); | |
3659 | mempool_free(pmb, phba->mbox_mem_pool); | |
086a345f | 3660 | if (ndlp) { |
be6bb941 JS |
3661 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
3662 | "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", | |
3663 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
3664 | atomic_read(&ndlp->kref.refcount), | |
3665 | ndlp->nlp_usg_map, ndlp); | |
086a345f JS |
3666 | if (NLP_CHK_NODE_ACT(ndlp)) { |
3667 | lpfc_nlp_put(ndlp); | |
3668 | /* This is the end of the default RPI cleanup logic for | |
3669 | * this ndlp. If no other discovery threads are using | |
3670 | * this ndlp, free all resources associated with it. | |
3671 | */ | |
3672 | lpfc_nlp_not_used(ndlp); | |
3673 | } else { | |
3674 | lpfc_drop_node(ndlp->vport, ndlp); | |
3675 | } | |
a8adb832 | 3676 | } |
3772a991 | 3677 | |
858c9f6c JS |
3678 | return; |
3679 | } | |
3680 | ||
e59058c4 | 3681 | /** |
3621a710 | 3682 | * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd |
e59058c4 JS |
3683 | * @phba: pointer to lpfc hba data structure. |
3684 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
3685 | * @rspiocb: pointer to lpfc response iocb data structure. | |
3686 | * | |
3687 | * This routine is the completion callback function for ELS Response IOCB | |
3688 | * command. In normal case, this callback function just properly sets the | |
3689 | * nlp_flag bitmap in the ndlp data structure, if the mbox command reference | |
3690 | * field in the command IOCB is not NULL, the referred mailbox command will | |
3691 | * be send out, and then invokes the lpfc_els_free_iocb() routine to release | |
3692 | * the IOCB. Under error conditions, such as when a LS_RJT is returned or a | |
3693 | * link down event occurred during the discovery, the lpfc_nlp_not_used() | |
3694 | * routine shall be invoked trying to release the ndlp if no other threads | |
3695 | * are currently referring it. | |
3696 | **/ | |
dea3101e | 3697 | static void |
858c9f6c | 3698 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
329f9bc7 | 3699 | struct lpfc_iocbq *rspiocb) |
dea3101e | 3700 | { |
2e0fef85 JS |
3701 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
3702 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; | |
3703 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; | |
87af33fe JS |
3704 | IOCB_t *irsp; |
3705 | uint8_t *pcmd; | |
dea3101e | 3706 | LPFC_MBOXQ_t *mbox = NULL; |
2e0fef85 | 3707 | struct lpfc_dmabuf *mp = NULL; |
87af33fe | 3708 | uint32_t ls_rjt = 0; |
dea3101e | 3709 | |
33ccf8d1 JS |
3710 | irsp = &rspiocb->iocb; |
3711 | ||
dea3101e JB |
3712 | if (cmdiocb->context_un.mbox) |
3713 | mbox = cmdiocb->context_un.mbox; | |
3714 | ||
fa4066b6 JS |
3715 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
3716 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. | |
3717 | */ | |
87af33fe | 3718 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
58da1ffb JS |
3719 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
3720 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { | |
fa4066b6 | 3721 | /* A LS_RJT associated with Default RPI cleanup has its own |
3ad2f3fb | 3722 | * separate code path. |
87af33fe JS |
3723 | */ |
3724 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
3725 | ls_rjt = 1; | |
3726 | } | |
3727 | ||
dea3101e | 3728 | /* Check to see if link went down during discovery */ |
58da1ffb | 3729 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
dea3101e | 3730 | if (mbox) { |
14691150 JS |
3731 | mp = (struct lpfc_dmabuf *) mbox->context1; |
3732 | if (mp) { | |
3733 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
3734 | kfree(mp); | |
3735 | } | |
329f9bc7 | 3736 | mempool_free(mbox, phba->mbox_mem_pool); |
dea3101e | 3737 | } |
58da1ffb JS |
3738 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
3739 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
fa4066b6 | 3740 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3741 | ndlp = NULL; |
fa4066b6 JS |
3742 | /* Indicate the node has already released, |
3743 | * should not reference to it from within | |
3744 | * the routine lpfc_els_free_iocb. | |
3745 | */ | |
3746 | cmdiocb->context1 = NULL; | |
3747 | } | |
dea3101e JB |
3748 | goto out; |
3749 | } | |
3750 | ||
858c9f6c | 3751 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
51ef4c26 | 3752 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
858c9f6c | 3753 | irsp->ulpStatus, irsp->un.ulpWord[4], |
51ef4c26 | 3754 | cmdiocb->iocb.un.elsreq64.remoteID); |
dea3101e | 3755 | /* ELS response tag <ulpIoTag> completes */ |
e8b62011 JS |
3756 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3757 | "0110 ELS response tag x%x completes " | |
3758 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", | |
3759 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, | |
3760 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, | |
3761 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3762 | ndlp->nlp_rpi); | |
dea3101e JB |
3763 | if (mbox) { |
3764 | if ((rspiocb->iocb.ulpStatus == 0) | |
3765 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { | |
2e0fef85 | 3766 | lpfc_unreg_rpi(vport, ndlp); |
e47c9093 JS |
3767 | /* Increment reference count to ndlp to hold the |
3768 | * reference to ndlp for the callback function. | |
3769 | */ | |
329f9bc7 | 3770 | mbox->context2 = lpfc_nlp_get(ndlp); |
2e0fef85 | 3771 | mbox->vport = vport; |
858c9f6c JS |
3772 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
3773 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
3774 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
3775 | } | |
3776 | else { | |
3777 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | |
3778 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
3779 | lpfc_nlp_set_state(vport, ndlp, | |
2e0fef85 | 3780 | NLP_STE_REG_LOGIN_ISSUE); |
858c9f6c | 3781 | } |
0b727fea | 3782 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
e47c9093 | 3783 | != MBX_NOT_FINISHED) |
dea3101e | 3784 | goto out; |
e47c9093 JS |
3785 | else |
3786 | /* Decrement the ndlp reference count we | |
3787 | * set for this failed mailbox command. | |
3788 | */ | |
3789 | lpfc_nlp_put(ndlp); | |
98c9ea5c JS |
3790 | |
3791 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ | |
3792 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
3793 | "0138 ELS rsp: Cannot issue reg_login for x%x " | |
3794 | "Data: x%x x%x x%x\n", | |
3795 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3796 | ndlp->nlp_rpi); | |
3797 | ||
fa4066b6 | 3798 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3799 | ndlp = NULL; |
fa4066b6 JS |
3800 | /* Indicate node has already been released, |
3801 | * should not reference to it from within | |
3802 | * the routine lpfc_els_free_iocb. | |
3803 | */ | |
3804 | cmdiocb->context1 = NULL; | |
3805 | } | |
dea3101e | 3806 | } else { |
858c9f6c JS |
3807 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
3808 | if (!lpfc_error_lost_link(irsp) && | |
3809 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | |
fa4066b6 | 3810 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 3811 | ndlp = NULL; |
fa4066b6 JS |
3812 | /* Indicate node has already been |
3813 | * released, should not reference | |
3814 | * to it from within the routine | |
3815 | * lpfc_els_free_iocb. | |
3816 | */ | |
3817 | cmdiocb->context1 = NULL; | |
3818 | } | |
dea3101e JB |
3819 | } |
3820 | } | |
14691150 JS |
3821 | mp = (struct lpfc_dmabuf *) mbox->context1; |
3822 | if (mp) { | |
3823 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
3824 | kfree(mp); | |
3825 | } | |
3826 | mempool_free(mbox, phba->mbox_mem_pool); | |
dea3101e JB |
3827 | } |
3828 | out: | |
58da1ffb | 3829 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
2e0fef85 | 3830 | spin_lock_irq(shost->host_lock); |
858c9f6c | 3831 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
2e0fef85 | 3832 | spin_unlock_irq(shost->host_lock); |
87af33fe JS |
3833 | |
3834 | /* If the node is not being used by another discovery thread, | |
3835 | * and we are sending a reject, we are done with it. | |
3836 | * Release driver reference count here and free associated | |
3837 | * resources. | |
3838 | */ | |
3839 | if (ls_rjt) | |
fa4066b6 JS |
3840 | if (lpfc_nlp_not_used(ndlp)) |
3841 | /* Indicate node has already been released, | |
3842 | * should not reference to it from within | |
3843 | * the routine lpfc_els_free_iocb. | |
3844 | */ | |
3845 | cmdiocb->context1 = NULL; | |
dea3101e | 3846 | } |
87af33fe | 3847 | |
dea3101e JB |
3848 | lpfc_els_free_iocb(phba, cmdiocb); |
3849 | return; | |
3850 | } | |
3851 | ||
e59058c4 | 3852 | /** |
3621a710 | 3853 | * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command |
e59058c4 JS |
3854 | * @vport: pointer to a host virtual N_Port data structure. |
3855 | * @flag: the els command code to be accepted. | |
3856 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
3857 | * @ndlp: pointer to a node-list data structure. | |
3858 | * @mbox: pointer to the driver internal queue element for mailbox command. | |
3859 | * | |
3860 | * This routine prepares and issues an Accept (ACC) response IOCB | |
3861 | * command. It uses the @flag to properly set up the IOCB field for the | |
3862 | * specific ACC response command to be issued and invokes the | |
3863 | * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a | |
3864 | * @mbox pointer is passed in, it will be put into the context_un.mbox | |
3865 | * field of the IOCB for the completion callback function to issue the | |
3866 | * mailbox command to the HBA later when callback is invoked. | |
3867 | * | |
3868 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
3869 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
3870 | * will be stored into the context1 field of the IOCB for the completion | |
3871 | * callback function to the corresponding response ELS IOCB command. | |
3872 | * | |
3873 | * Return code | |
3874 | * 0 - Successfully issued acc response | |
3875 | * 1 - Failed to issue acc response | |
3876 | **/ | |
dea3101e | 3877 | int |
2e0fef85 JS |
3878 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
3879 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | |
51ef4c26 | 3880 | LPFC_MBOXQ_t *mbox) |
dea3101e | 3881 | { |
2e0fef85 JS |
3882 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3883 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
3884 | IOCB_t *icmd; |
3885 | IOCB_t *oldcmd; | |
3886 | struct lpfc_iocbq *elsiocb; | |
dea3101e | 3887 | uint8_t *pcmd; |
d6de08cc | 3888 | struct serv_parm *sp; |
dea3101e JB |
3889 | uint16_t cmdsize; |
3890 | int rc; | |
82d9a2a2 | 3891 | ELS_PKT *els_pkt_ptr; |
dea3101e | 3892 | |
dea3101e JB |
3893 | oldcmd = &oldiocb->iocb; |
3894 | ||
3895 | switch (flag) { | |
3896 | case ELS_CMD_ACC: | |
92d7f7b0 | 3897 | cmdsize = sizeof(uint32_t); |
2e0fef85 JS |
3898 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
3899 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 3900 | if (!elsiocb) { |
2e0fef85 | 3901 | spin_lock_irq(shost->host_lock); |
5024ab17 | 3902 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
2e0fef85 | 3903 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 3904 | return 1; |
dea3101e | 3905 | } |
2e0fef85 | 3906 | |
dea3101e | 3907 | icmd = &elsiocb->iocb; |
7851fe2c JS |
3908 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
3909 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
3910 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
3911 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 3912 | pcmd += sizeof(uint32_t); |
858c9f6c JS |
3913 | |
3914 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
3915 | "Issue ACC: did:x%x flg:x%x", | |
3916 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
dea3101e | 3917 | break; |
d6de08cc | 3918 | case ELS_CMD_FLOGI: |
dea3101e | 3919 | case ELS_CMD_PLOGI: |
92d7f7b0 | 3920 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
2e0fef85 JS |
3921 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
3922 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 3923 | if (!elsiocb) |
c9f8735b | 3924 | return 1; |
488d1469 | 3925 | |
dea3101e | 3926 | icmd = &elsiocb->iocb; |
7851fe2c JS |
3927 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
3928 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
3929 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
3930 | ||
3931 | if (mbox) | |
3932 | elsiocb->context_un.mbox = mbox; | |
3933 | ||
3934 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 3935 | pcmd += sizeof(uint32_t); |
d6de08cc JS |
3936 | sp = (struct serv_parm *)pcmd; |
3937 | ||
3938 | if (flag == ELS_CMD_FLOGI) { | |
3939 | /* Copy the received service parameters back */ | |
3940 | memcpy(sp, &phba->fc_fabparam, | |
3941 | sizeof(struct serv_parm)); | |
3942 | ||
3943 | /* Clear the F_Port bit */ | |
3944 | sp->cmn.fPort = 0; | |
3945 | ||
3946 | /* Mark all class service parameters as invalid */ | |
3947 | sp->cls1.classValid = 0; | |
3948 | sp->cls2.classValid = 0; | |
3949 | sp->cls3.classValid = 0; | |
3950 | sp->cls4.classValid = 0; | |
3951 | ||
3952 | /* Copy our worldwide names */ | |
3953 | memcpy(&sp->portName, &vport->fc_sparam.portName, | |
3954 | sizeof(struct lpfc_name)); | |
3955 | memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, | |
3956 | sizeof(struct lpfc_name)); | |
3957 | } else { | |
3958 | memcpy(pcmd, &vport->fc_sparam, | |
3959 | sizeof(struct serv_parm)); | |
3960 | } | |
858c9f6c JS |
3961 | |
3962 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
d6de08cc | 3963 | "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x", |
858c9f6c | 3964 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
dea3101e | 3965 | break; |
82d9a2a2 | 3966 | case ELS_CMD_PRLO: |
92d7f7b0 | 3967 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
2e0fef85 | 3968 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
82d9a2a2 JS |
3969 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
3970 | if (!elsiocb) | |
3971 | return 1; | |
3972 | ||
3973 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
3974 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
3975 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
82d9a2a2 JS |
3976 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
3977 | ||
3978 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, | |
92d7f7b0 | 3979 | sizeof(uint32_t) + sizeof(PRLO)); |
82d9a2a2 JS |
3980 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
3981 | els_pkt_ptr = (ELS_PKT *) pcmd; | |
3982 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; | |
858c9f6c JS |
3983 | |
3984 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
3985 | "Issue ACC PRLO: did:x%x flg:x%x", | |
3986 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
82d9a2a2 | 3987 | break; |
dea3101e | 3988 | default: |
c9f8735b | 3989 | return 1; |
dea3101e | 3990 | } |
dea3101e | 3991 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
3992 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3993 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " | |
e6446439 JS |
3994 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x " |
3995 | "fc_flag x%x\n", | |
e8b62011 JS |
3996 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
3997 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
e6446439 | 3998 | ndlp->nlp_rpi, vport->fc_flag); |
dea3101e | 3999 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
2e0fef85 | 4000 | spin_lock_irq(shost->host_lock); |
7c5e518c JS |
4001 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED || |
4002 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND)) | |
4003 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | |
2e0fef85 | 4004 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
4005 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
4006 | } else { | |
858c9f6c | 4007 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e JB |
4008 | } |
4009 | ||
4010 | phba->fc_stat.elsXmitACC++; | |
3772a991 | 4011 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4012 | if (rc == IOCB_ERROR) { |
4013 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4014 | return 1; |
dea3101e | 4015 | } |
c9f8735b | 4016 | return 0; |
dea3101e JB |
4017 | } |
4018 | ||
e59058c4 | 4019 | /** |
3621a710 | 4020 | * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command |
e59058c4 JS |
4021 | * @vport: pointer to a virtual N_Port data structure. |
4022 | * @rejectError: | |
4023 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4024 | * @ndlp: pointer to a node-list data structure. | |
4025 | * @mbox: pointer to the driver internal queue element for mailbox command. | |
4026 | * | |
4027 | * This routine prepares and issue an Reject (RJT) response IOCB | |
4028 | * command. If a @mbox pointer is passed in, it will be put into the | |
4029 | * context_un.mbox field of the IOCB for the completion callback function | |
4030 | * to issue to the HBA later. | |
4031 | * | |
4032 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4033 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4034 | * will be stored into the context1 field of the IOCB for the completion | |
4035 | * callback function to the reject response ELS IOCB command. | |
4036 | * | |
4037 | * Return code | |
4038 | * 0 - Successfully issued reject response | |
4039 | * 1 - Failed to issue reject response | |
4040 | **/ | |
dea3101e | 4041 | int |
2e0fef85 | 4042 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
858c9f6c JS |
4043 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
4044 | LPFC_MBOXQ_t *mbox) | |
dea3101e | 4045 | { |
2e0fef85 | 4046 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
4047 | IOCB_t *icmd; |
4048 | IOCB_t *oldcmd; | |
4049 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
4050 | uint8_t *pcmd; |
4051 | uint16_t cmdsize; | |
4052 | int rc; | |
4053 | ||
92d7f7b0 | 4054 | cmdsize = 2 * sizeof(uint32_t); |
2e0fef85 JS |
4055 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4056 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
488d1469 | 4057 | if (!elsiocb) |
c9f8735b | 4058 | return 1; |
dea3101e JB |
4059 | |
4060 | icmd = &elsiocb->iocb; | |
4061 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4062 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4063 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
dea3101e JB |
4064 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4065 | ||
4066 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | |
92d7f7b0 | 4067 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4068 | *((uint32_t *) (pcmd)) = rejectError; |
4069 | ||
51ef4c26 | 4070 | if (mbox) |
858c9f6c | 4071 | elsiocb->context_un.mbox = mbox; |
858c9f6c | 4072 | |
dea3101e | 4073 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
e8b62011 JS |
4074 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4075 | "0129 Xmit ELS RJT x%x response tag x%x " | |
4076 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
4077 | "rpi x%x\n", | |
4078 | rejectError, elsiocb->iotag, | |
4079 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, | |
4080 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); | |
858c9f6c JS |
4081 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4082 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", | |
4083 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); | |
4084 | ||
dea3101e | 4085 | phba->fc_stat.elsXmitLSRJT++; |
858c9f6c | 4086 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
3772a991 | 4087 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
51ef4c26 | 4088 | |
dea3101e JB |
4089 | if (rc == IOCB_ERROR) { |
4090 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4091 | return 1; |
dea3101e | 4092 | } |
c9f8735b | 4093 | return 0; |
dea3101e JB |
4094 | } |
4095 | ||
e59058c4 | 4096 | /** |
3621a710 | 4097 | * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd |
e59058c4 JS |
4098 | * @vport: pointer to a virtual N_Port data structure. |
4099 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4100 | * @ndlp: pointer to a node-list data structure. | |
4101 | * | |
4102 | * This routine prepares and issues an Accept (ACC) response to Address | |
4103 | * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB | |
4104 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | |
4105 | * | |
4106 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4107 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4108 | * will be stored into the context1 field of the IOCB for the completion | |
4109 | * callback function to the ADISC Accept response ELS IOCB command. | |
4110 | * | |
4111 | * Return code | |
4112 | * 0 - Successfully issued acc adisc response | |
4113 | * 1 - Failed to issue adisc acc response | |
4114 | **/ | |
dea3101e | 4115 | int |
2e0fef85 JS |
4116 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
4117 | struct lpfc_nodelist *ndlp) | |
dea3101e | 4118 | { |
2e0fef85 | 4119 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4120 | ADISC *ap; |
2e0fef85 | 4121 | IOCB_t *icmd, *oldcmd; |
dea3101e | 4122 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
4123 | uint8_t *pcmd; |
4124 | uint16_t cmdsize; | |
4125 | int rc; | |
4126 | ||
92d7f7b0 | 4127 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
2e0fef85 JS |
4128 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4129 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4130 | if (!elsiocb) |
c9f8735b | 4131 | return 1; |
dea3101e | 4132 | |
5b8bd0c9 JS |
4133 | icmd = &elsiocb->iocb; |
4134 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4135 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4136 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
5b8bd0c9 | 4137 | |
dea3101e | 4138 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4139 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4140 | "0130 Xmit ADISC ACC response iotag x%x xri: " | |
4141 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", | |
4142 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
4143 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
4144 | ndlp->nlp_rpi); | |
dea3101e JB |
4145 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4146 | ||
4147 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 4148 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4149 | |
4150 | ap = (ADISC *) (pcmd); | |
4151 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
4152 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
4153 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 4154 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 4155 | |
858c9f6c JS |
4156 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4157 | "Issue ACC ADISC: did:x%x flg:x%x", | |
4158 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4159 | ||
dea3101e | 4160 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4161 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
3772a991 | 4162 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4163 | if (rc == IOCB_ERROR) { |
4164 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4165 | return 1; |
dea3101e | 4166 | } |
c9f8735b | 4167 | return 0; |
dea3101e JB |
4168 | } |
4169 | ||
e59058c4 | 4170 | /** |
3621a710 | 4171 | * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd |
e59058c4 JS |
4172 | * @vport: pointer to a virtual N_Port data structure. |
4173 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4174 | * @ndlp: pointer to a node-list data structure. | |
4175 | * | |
4176 | * This routine prepares and issues an Accept (ACC) response to Process | |
4177 | * Login (PRLI) ELS command. It simply prepares the payload of the IOCB | |
4178 | * and invokes the lpfc_sli_issue_iocb() routine to send out the command. | |
4179 | * | |
4180 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4181 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4182 | * will be stored into the context1 field of the IOCB for the completion | |
4183 | * callback function to the PRLI Accept response ELS IOCB command. | |
4184 | * | |
4185 | * Return code | |
4186 | * 0 - Successfully issued acc prli response | |
4187 | * 1 - Failed to issue acc prli response | |
4188 | **/ | |
dea3101e | 4189 | int |
2e0fef85 | 4190 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
5b8bd0c9 | 4191 | struct lpfc_nodelist *ndlp) |
dea3101e | 4192 | { |
2e0fef85 | 4193 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
4194 | PRLI *npr; |
4195 | lpfc_vpd_t *vpd; | |
4196 | IOCB_t *icmd; | |
4197 | IOCB_t *oldcmd; | |
4198 | struct lpfc_iocbq *elsiocb; | |
dea3101e JB |
4199 | uint8_t *pcmd; |
4200 | uint16_t cmdsize; | |
4201 | int rc; | |
4202 | ||
92d7f7b0 | 4203 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
2e0fef85 | 4204 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
92d7f7b0 | 4205 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
c9f8735b JW |
4206 | if (!elsiocb) |
4207 | return 1; | |
dea3101e | 4208 | |
5b8bd0c9 JS |
4209 | icmd = &elsiocb->iocb; |
4210 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4211 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4212 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
4213 | ||
dea3101e | 4214 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4215 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4216 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " | |
4217 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
4218 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
4219 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
4220 | ndlp->nlp_rpi); | |
dea3101e JB |
4221 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
4222 | ||
4223 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | |
92d7f7b0 | 4224 | pcmd += sizeof(uint32_t); |
dea3101e JB |
4225 | |
4226 | /* For PRLI, remainder of payload is PRLI parameter page */ | |
92d7f7b0 | 4227 | memset(pcmd, 0, sizeof(PRLI)); |
dea3101e JB |
4228 | |
4229 | npr = (PRLI *) pcmd; | |
4230 | vpd = &phba->vpd; | |
4231 | /* | |
0d2b6b83 JS |
4232 | * If the remote port is a target and our firmware version is 3.20 or |
4233 | * later, set the following bits for FC-TAPE support. | |
dea3101e | 4234 | */ |
0d2b6b83 JS |
4235 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
4236 | (vpd->rev.feaLevelHigh >= 0x02)) { | |
dea3101e JB |
4237 | npr->ConfmComplAllowed = 1; |
4238 | npr->Retry = 1; | |
4239 | npr->TaskRetryIdReq = 1; | |
4240 | } | |
4241 | ||
4242 | npr->acceptRspCode = PRLI_REQ_EXECUTED; | |
4243 | npr->estabImagePair = 1; | |
4244 | npr->readXferRdyDis = 1; | |
4245 | npr->ConfmComplAllowed = 1; | |
4246 | ||
4247 | npr->prliType = PRLI_FCP_TYPE; | |
4248 | npr->initiatorFunc = 1; | |
4249 | ||
858c9f6c JS |
4250 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4251 | "Issue ACC PRLI: did:x%x flg:x%x", | |
4252 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4253 | ||
dea3101e | 4254 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4255 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 4256 | |
3772a991 | 4257 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4258 | if (rc == IOCB_ERROR) { |
4259 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4260 | return 1; |
dea3101e | 4261 | } |
c9f8735b | 4262 | return 0; |
dea3101e JB |
4263 | } |
4264 | ||
e59058c4 | 4265 | /** |
3621a710 | 4266 | * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command |
e59058c4 JS |
4267 | * @vport: pointer to a virtual N_Port data structure. |
4268 | * @format: rnid command format. | |
4269 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4270 | * @ndlp: pointer to a node-list data structure. | |
4271 | * | |
4272 | * This routine issues a Request Node Identification Data (RNID) Accept | |
4273 | * (ACC) response. It constructs the RNID ACC response command according to | |
4274 | * the proper @format and then calls the lpfc_sli_issue_iocb() routine to | |
4275 | * issue the response. Note that this command does not need to hold the ndlp | |
4276 | * reference count for the callback. So, the ndlp reference count taken by | |
4277 | * the lpfc_prep_els_iocb() routine is put back and the context1 field of | |
4278 | * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that | |
4279 | * there is no ndlp reference available. | |
4280 | * | |
4281 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
4282 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
4283 | * will be stored into the context1 field of the IOCB for the completion | |
4284 | * callback function. However, for the RNID Accept Response ELS command, | |
4285 | * this is undone later by this routine after the IOCB is allocated. | |
4286 | * | |
4287 | * Return code | |
4288 | * 0 - Successfully issued acc rnid response | |
4289 | * 1 - Failed to issue acc rnid response | |
4290 | **/ | |
dea3101e | 4291 | static int |
2e0fef85 | 4292 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
329f9bc7 | 4293 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
dea3101e | 4294 | { |
2e0fef85 | 4295 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4296 | RNID *rn; |
2e0fef85 | 4297 | IOCB_t *icmd, *oldcmd; |
dea3101e | 4298 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
4299 | uint8_t *pcmd; |
4300 | uint16_t cmdsize; | |
4301 | int rc; | |
4302 | ||
92d7f7b0 JS |
4303 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
4304 | + (2 * sizeof(struct lpfc_name)); | |
dea3101e | 4305 | if (format) |
92d7f7b0 | 4306 | cmdsize += sizeof(RNID_TOP_DISC); |
dea3101e | 4307 | |
2e0fef85 JS |
4308 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4309 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 4310 | if (!elsiocb) |
c9f8735b | 4311 | return 1; |
dea3101e | 4312 | |
5b8bd0c9 JS |
4313 | icmd = &elsiocb->iocb; |
4314 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
4315 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
4316 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
4317 | ||
dea3101e | 4318 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
e8b62011 JS |
4319 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4320 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", | |
4321 | elsiocb->iotag, elsiocb->iocb.ulpContext); | |
dea3101e | 4322 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
dea3101e | 4323 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
92d7f7b0 | 4324 | pcmd += sizeof(uint32_t); |
dea3101e | 4325 | |
92d7f7b0 | 4326 | memset(pcmd, 0, sizeof(RNID)); |
dea3101e JB |
4327 | rn = (RNID *) (pcmd); |
4328 | rn->Format = format; | |
92d7f7b0 JS |
4329 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
4330 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | |
4331 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
dea3101e JB |
4332 | switch (format) { |
4333 | case 0: | |
4334 | rn->SpecificLen = 0; | |
4335 | break; | |
4336 | case RNID_TOPOLOGY_DISC: | |
92d7f7b0 | 4337 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
dea3101e | 4338 | memcpy(&rn->un.topologyDisc.portName, |
92d7f7b0 | 4339 | &vport->fc_portname, sizeof(struct lpfc_name)); |
dea3101e JB |
4340 | rn->un.topologyDisc.unitType = RNID_HBA; |
4341 | rn->un.topologyDisc.physPort = 0; | |
4342 | rn->un.topologyDisc.attachedNodes = 0; | |
4343 | break; | |
4344 | default: | |
4345 | rn->CommonLen = 0; | |
4346 | rn->SpecificLen = 0; | |
4347 | break; | |
4348 | } | |
4349 | ||
858c9f6c JS |
4350 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
4351 | "Issue ACC RNID: did:x%x flg:x%x", | |
4352 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4353 | ||
dea3101e | 4354 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 4355 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 4356 | |
3772a991 | 4357 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); |
dea3101e JB |
4358 | if (rc == IOCB_ERROR) { |
4359 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 4360 | return 1; |
dea3101e | 4361 | } |
c9f8735b | 4362 | return 0; |
dea3101e JB |
4363 | } |
4364 | ||
19ca7609 JS |
4365 | /** |
4366 | * lpfc_els_clear_rrq - Clear the rq that this rrq describes. | |
4367 | * @vport: pointer to a virtual N_Port data structure. | |
4368 | * @iocb: pointer to the lpfc command iocb data structure. | |
4369 | * @ndlp: pointer to a node-list data structure. | |
4370 | * | |
4371 | * Return | |
4372 | **/ | |
4373 | static void | |
4374 | lpfc_els_clear_rrq(struct lpfc_vport *vport, | |
4375 | struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) | |
4376 | { | |
4377 | struct lpfc_hba *phba = vport->phba; | |
4378 | uint8_t *pcmd; | |
4379 | struct RRQ *rrq; | |
4380 | uint16_t rxid; | |
1151e3ec | 4381 | uint16_t xri; |
19ca7609 JS |
4382 | struct lpfc_node_rrq *prrq; |
4383 | ||
4384 | ||
4385 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); | |
4386 | pcmd += sizeof(uint32_t); | |
4387 | rrq = (struct RRQ *)pcmd; | |
1151e3ec | 4388 | rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); |
9589b062 | 4389 | rxid = bf_get(rrq_rxid, rrq); |
19ca7609 JS |
4390 | |
4391 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4392 | "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" | |
4393 | " x%x x%x\n", | |
1151e3ec | 4394 | be32_to_cpu(bf_get(rrq_did, rrq)), |
9589b062 | 4395 | bf_get(rrq_oxid, rrq), |
19ca7609 JS |
4396 | rxid, |
4397 | iocb->iotag, iocb->iocb.ulpContext); | |
4398 | ||
4399 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4400 | "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", | |
4401 | ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); | |
1151e3ec | 4402 | if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) |
9589b062 | 4403 | xri = bf_get(rrq_oxid, rrq); |
1151e3ec JS |
4404 | else |
4405 | xri = rxid; | |
4406 | prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); | |
19ca7609 | 4407 | if (prrq) |
1151e3ec | 4408 | lpfc_clr_rrq_active(phba, xri, prrq); |
19ca7609 JS |
4409 | return; |
4410 | } | |
4411 | ||
12265f68 JS |
4412 | /** |
4413 | * lpfc_els_rsp_echo_acc - Issue echo acc response | |
4414 | * @vport: pointer to a virtual N_Port data structure. | |
4415 | * @data: pointer to echo data to return in the accept. | |
4416 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
4417 | * @ndlp: pointer to a node-list data structure. | |
4418 | * | |
4419 | * Return code | |
4420 | * 0 - Successfully issued acc echo response | |
4421 | * 1 - Failed to issue acc echo response | |
4422 | **/ | |
4423 | static int | |
4424 | lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, | |
4425 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | |
4426 | { | |
4427 | struct lpfc_hba *phba = vport->phba; | |
4428 | struct lpfc_iocbq *elsiocb; | |
12265f68 JS |
4429 | uint8_t *pcmd; |
4430 | uint16_t cmdsize; | |
4431 | int rc; | |
4432 | ||
12265f68 JS |
4433 | cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; |
4434 | ||
bf08611b JS |
4435 | /* The accumulated length can exceed the BPL_SIZE. For |
4436 | * now, use this as the limit | |
4437 | */ | |
4438 | if (cmdsize > LPFC_BPL_SIZE) | |
4439 | cmdsize = LPFC_BPL_SIZE; | |
12265f68 JS |
4440 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
4441 | ndlp->nlp_DID, ELS_CMD_ACC); | |
4442 | if (!elsiocb) | |
4443 | return 1; | |
4444 | ||
7851fe2c JS |
4445 | elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */ |
4446 | elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id; | |
4447 | ||
12265f68 JS |
4448 | /* Xmit ECHO ACC response tag <ulpIoTag> */ |
4449 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4450 | "2876 Xmit ECHO ACC response tag x%x xri x%x\n", | |
4451 | elsiocb->iotag, elsiocb->iocb.ulpContext); | |
4452 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4453 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
4454 | pcmd += sizeof(uint32_t); | |
4455 | memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); | |
4456 | ||
4457 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
4458 | "Issue ACC ECHO: did:x%x flg:x%x", | |
4459 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4460 | ||
4461 | phba->fc_stat.elsXmitACC++; | |
4462 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
12265f68 JS |
4463 | |
4464 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
4465 | if (rc == IOCB_ERROR) { | |
4466 | lpfc_els_free_iocb(phba, elsiocb); | |
4467 | return 1; | |
4468 | } | |
4469 | return 0; | |
4470 | } | |
4471 | ||
e59058c4 | 4472 | /** |
3621a710 | 4473 | * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport |
e59058c4 JS |
4474 | * @vport: pointer to a host virtual N_Port data structure. |
4475 | * | |
4476 | * This routine issues Address Discover (ADISC) ELS commands to those | |
4477 | * N_Ports which are in node port recovery state and ADISC has not been issued | |
4478 | * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the | |
4479 | * lpfc_issue_els_adisc() routine, the per @vport number of discover count | |
4480 | * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a | |
4481 | * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will | |
4482 | * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC | |
4483 | * IOCBs quit for later pick up. On the other hand, after walking through | |
4484 | * all the ndlps with the @vport and there is none ADISC IOCB issued, the | |
4485 | * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is | |
4486 | * no more ADISC need to be sent. | |
4487 | * | |
4488 | * Return code | |
4489 | * The number of N_Ports with adisc issued. | |
4490 | **/ | |
dea3101e | 4491 | int |
2e0fef85 | 4492 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
dea3101e | 4493 | { |
2e0fef85 | 4494 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 4495 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 4496 | int sentadisc = 0; |
dea3101e | 4497 | |
685f0bf7 | 4498 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
2e0fef85 | 4499 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
4500 | if (!NLP_CHK_NODE_ACT(ndlp)) |
4501 | continue; | |
685f0bf7 JS |
4502 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
4503 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | |
4504 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { | |
2e0fef85 | 4505 | spin_lock_irq(shost->host_lock); |
685f0bf7 | 4506 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 4507 | spin_unlock_irq(shost->host_lock); |
685f0bf7 | 4508 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
4509 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
4510 | lpfc_issue_els_adisc(vport, ndlp, 0); | |
685f0bf7 | 4511 | sentadisc++; |
2e0fef85 JS |
4512 | vport->num_disc_nodes++; |
4513 | if (vport->num_disc_nodes >= | |
3de2a653 | 4514 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
4515 | spin_lock_irq(shost->host_lock); |
4516 | vport->fc_flag |= FC_NLP_MORE; | |
4517 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 4518 | break; |
dea3101e JB |
4519 | } |
4520 | } | |
4521 | } | |
4522 | if (sentadisc == 0) { | |
2e0fef85 JS |
4523 | spin_lock_irq(shost->host_lock); |
4524 | vport->fc_flag &= ~FC_NLP_MORE; | |
4525 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 4526 | } |
2fe165b6 | 4527 | return sentadisc; |
dea3101e JB |
4528 | } |
4529 | ||
e59058c4 | 4530 | /** |
3621a710 | 4531 | * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc |
e59058c4 JS |
4532 | * @vport: pointer to a host virtual N_Port data structure. |
4533 | * | |
4534 | * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports | |
4535 | * which are in node port recovery state, with a @vport. Each time an ELS | |
4536 | * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, | |
4537 | * the per @vport number of discover count (num_disc_nodes) shall be | |
4538 | * incremented. If the num_disc_nodes reaches a pre-configured threshold | |
4539 | * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE | |
4540 | * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for | |
4541 | * later pick up. On the other hand, after walking through all the ndlps with | |
4542 | * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag | |
4543 | * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC | |
4544 | * PLOGI need to be sent. | |
4545 | * | |
4546 | * Return code | |
4547 | * The number of N_Ports with plogi issued. | |
4548 | **/ | |
dea3101e | 4549 | int |
2e0fef85 | 4550 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
dea3101e | 4551 | { |
2e0fef85 | 4552 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 4553 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 4554 | int sentplogi = 0; |
dea3101e | 4555 | |
2e0fef85 JS |
4556 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
4557 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
4558 | if (!NLP_CHK_NODE_ACT(ndlp)) |
4559 | continue; | |
685f0bf7 | 4560 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
8b017a30 JS |
4561 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
4562 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && | |
4563 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { | |
685f0bf7 | 4564 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
4565 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
4566 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
685f0bf7 | 4567 | sentplogi++; |
2e0fef85 JS |
4568 | vport->num_disc_nodes++; |
4569 | if (vport->num_disc_nodes >= | |
8b017a30 | 4570 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
4571 | spin_lock_irq(shost->host_lock); |
4572 | vport->fc_flag |= FC_NLP_MORE; | |
4573 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 4574 | break; |
dea3101e JB |
4575 | } |
4576 | } | |
4577 | } | |
87af33fe JS |
4578 | if (sentplogi) { |
4579 | lpfc_set_disctmo(vport); | |
4580 | } | |
4581 | else { | |
2e0fef85 JS |
4582 | spin_lock_irq(shost->host_lock); |
4583 | vport->fc_flag &= ~FC_NLP_MORE; | |
4584 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 4585 | } |
2fe165b6 | 4586 | return sentplogi; |
dea3101e JB |
4587 | } |
4588 | ||
86478875 JS |
4589 | void |
4590 | lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, | |
4591 | uint32_t word0) | |
4592 | { | |
4593 | ||
4594 | desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); | |
4595 | desc->payload.els_req = word0; | |
4596 | desc->length = cpu_to_be32(sizeof(desc->payload)); | |
4597 | } | |
4598 | ||
4599 | void | |
4600 | lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, | |
4601 | uint8_t *page_a0, uint8_t *page_a2) | |
4602 | { | |
4603 | uint16_t wavelength; | |
4604 | uint16_t temperature; | |
4605 | uint16_t rx_power; | |
4606 | uint16_t tx_bias; | |
4607 | uint16_t tx_power; | |
4608 | uint16_t vcc; | |
4609 | uint16_t flag = 0; | |
4610 | struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; | |
4611 | struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; | |
4612 | ||
4613 | desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); | |
4614 | ||
4615 | trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) | |
4616 | &page_a0[SSF_TRANSCEIVER_CODE_B4]; | |
4617 | trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) | |
4618 | &page_a0[SSF_TRANSCEIVER_CODE_B5]; | |
4619 | ||
4620 | if ((trasn_code_byte4->fc_sw_laser) || | |
4621 | (trasn_code_byte5->fc_sw_laser_sl) || | |
4622 | (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ | |
4623 | flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); | |
4624 | } else if (trasn_code_byte4->fc_lw_laser) { | |
4625 | wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | | |
4626 | page_a0[SSF_WAVELENGTH_B0]; | |
4627 | if (wavelength == SFP_WAVELENGTH_LC1310) | |
4628 | flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; | |
4629 | if (wavelength == SFP_WAVELENGTH_LL1550) | |
4630 | flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; | |
4631 | } | |
4632 | /* check if its SFP+ */ | |
4633 | flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? | |
4634 | SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) | |
4635 | << SFP_FLAG_CT_SHIFT; | |
4636 | ||
4637 | /* check if its OPTICAL */ | |
4638 | flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? | |
4639 | SFP_FLAG_IS_OPTICAL_PORT : 0) | |
4640 | << SFP_FLAG_IS_OPTICAL_SHIFT; | |
4641 | ||
4642 | temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | | |
4643 | page_a2[SFF_TEMPERATURE_B0]); | |
4644 | vcc = (page_a2[SFF_VCC_B1] << 8 | | |
4645 | page_a2[SFF_VCC_B0]); | |
4646 | tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | | |
4647 | page_a2[SFF_TXPOWER_B0]); | |
4648 | tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | | |
4649 | page_a2[SFF_TX_BIAS_CURRENT_B0]); | |
4650 | rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | | |
4651 | page_a2[SFF_RXPOWER_B0]); | |
4652 | desc->sfp_info.temperature = cpu_to_be16(temperature); | |
4653 | desc->sfp_info.rx_power = cpu_to_be16(rx_power); | |
4654 | desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); | |
4655 | desc->sfp_info.tx_power = cpu_to_be16(tx_power); | |
4656 | desc->sfp_info.vcc = cpu_to_be16(vcc); | |
4657 | ||
4658 | desc->sfp_info.flags = cpu_to_be16(flag); | |
4659 | desc->length = cpu_to_be32(sizeof(desc->sfp_info)); | |
4660 | } | |
4661 | ||
4662 | void | |
4663 | lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, | |
4664 | READ_LNK_VAR *stat) | |
4665 | { | |
4666 | uint32_t type; | |
4667 | ||
4668 | desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); | |
4669 | ||
4670 | type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; | |
4671 | ||
4672 | desc->info.port_type = cpu_to_be32(type); | |
4673 | ||
4674 | desc->info.link_status.link_failure_cnt = | |
4675 | cpu_to_be32(stat->linkFailureCnt); | |
4676 | desc->info.link_status.loss_of_synch_cnt = | |
4677 | cpu_to_be32(stat->lossSyncCnt); | |
4678 | desc->info.link_status.loss_of_signal_cnt = | |
4679 | cpu_to_be32(stat->lossSignalCnt); | |
4680 | desc->info.link_status.primitive_seq_proto_err = | |
4681 | cpu_to_be32(stat->primSeqErrCnt); | |
4682 | desc->info.link_status.invalid_trans_word = | |
4683 | cpu_to_be32(stat->invalidXmitWord); | |
4684 | desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); | |
4685 | ||
4686 | desc->length = cpu_to_be32(sizeof(desc->info)); | |
4687 | } | |
4688 | ||
4689 | void | |
4690 | lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) | |
4691 | { | |
4692 | uint16_t rdp_cap = 0; | |
4693 | uint16_t rdp_speed; | |
4694 | ||
4695 | desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); | |
4696 | ||
4697 | switch (phba->sli4_hba.link_state.speed) { | |
4698 | case LPFC_FC_LA_SPEED_1G: | |
4699 | rdp_speed = RDP_PS_1GB; | |
4700 | break; | |
4701 | case LPFC_FC_LA_SPEED_2G: | |
4702 | rdp_speed = RDP_PS_2GB; | |
4703 | break; | |
4704 | case LPFC_FC_LA_SPEED_4G: | |
4705 | rdp_speed = RDP_PS_4GB; | |
4706 | break; | |
4707 | case LPFC_FC_LA_SPEED_8G: | |
4708 | rdp_speed = RDP_PS_8GB; | |
4709 | break; | |
4710 | case LPFC_FC_LA_SPEED_10G: | |
4711 | rdp_speed = RDP_PS_10GB; | |
4712 | break; | |
4713 | case LPFC_FC_LA_SPEED_16G: | |
4714 | rdp_speed = RDP_PS_16GB; | |
4715 | break; | |
4716 | case LPFC_FC_LA_SPEED_32G: | |
4717 | rdp_speed = RDP_PS_32GB; | |
4718 | break; | |
4719 | default: | |
4720 | rdp_speed = RDP_PS_UNKNOWN; | |
4721 | break; | |
4722 | } | |
4723 | ||
4724 | desc->info.port_speed.speed = cpu_to_be16(rdp_speed); | |
4725 | ||
d38dd52c JS |
4726 | if (phba->lmt & LMT_32Gb) |
4727 | rdp_cap |= RDP_PS_32GB; | |
86478875 JS |
4728 | if (phba->lmt & LMT_16Gb) |
4729 | rdp_cap |= RDP_PS_16GB; | |
4730 | if (phba->lmt & LMT_10Gb) | |
4731 | rdp_cap |= RDP_PS_10GB; | |
4732 | if (phba->lmt & LMT_8Gb) | |
4733 | rdp_cap |= RDP_PS_8GB; | |
4734 | if (phba->lmt & LMT_4Gb) | |
4735 | rdp_cap |= RDP_PS_4GB; | |
4736 | if (phba->lmt & LMT_2Gb) | |
4737 | rdp_cap |= RDP_PS_2GB; | |
4738 | if (phba->lmt & LMT_1Gb) | |
4739 | rdp_cap |= RDP_PS_1GB; | |
4740 | ||
4741 | if (rdp_cap == 0) | |
4742 | rdp_cap = RDP_CAP_UNKNOWN; | |
4743 | ||
4744 | desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); | |
4745 | desc->length = cpu_to_be32(sizeof(desc->info)); | |
4746 | } | |
4747 | ||
4748 | void | |
4749 | lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, | |
4750 | struct lpfc_hba *phba) | |
4751 | { | |
4752 | ||
4753 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); | |
4754 | ||
4755 | memcpy(desc->port_names.wwnn, phba->wwnn, | |
4756 | sizeof(desc->port_names.wwnn)); | |
4757 | ||
4758 | memcpy(desc->port_names.wwpn, &phba->wwpn, | |
4759 | sizeof(desc->port_names.wwpn)); | |
4760 | ||
4761 | desc->length = cpu_to_be32(sizeof(desc->port_names)); | |
4762 | } | |
4763 | ||
4764 | void | |
4765 | lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, | |
4766 | struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
4767 | { | |
4768 | ||
4769 | desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); | |
4770 | if (vport->fc_flag & FC_FABRIC) { | |
4771 | memcpy(desc->port_names.wwnn, &vport->fabric_nodename, | |
4772 | sizeof(desc->port_names.wwnn)); | |
4773 | ||
4774 | memcpy(desc->port_names.wwpn, &vport->fabric_portname, | |
4775 | sizeof(desc->port_names.wwpn)); | |
4776 | } else { /* Point to Point */ | |
4777 | memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, | |
4778 | sizeof(desc->port_names.wwnn)); | |
4779 | ||
4780 | memcpy(desc->port_names.wwnn, &ndlp->nlp_portname, | |
4781 | sizeof(desc->port_names.wwpn)); | |
4782 | } | |
4783 | ||
4784 | desc->length = cpu_to_be32(sizeof(desc->port_names)); | |
4785 | } | |
4786 | ||
4787 | void | |
4788 | lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, | |
4789 | int status) | |
4790 | { | |
4791 | struct lpfc_nodelist *ndlp = rdp_context->ndlp; | |
4792 | struct lpfc_vport *vport = ndlp->vport; | |
4793 | struct lpfc_iocbq *elsiocb; | |
4794 | IOCB_t *icmd; | |
4795 | uint8_t *pcmd; | |
4796 | struct ls_rjt *stat; | |
4797 | struct fc_rdp_res_frame *rdp_res; | |
4798 | uint32_t cmdsize; | |
4799 | int rc; | |
4800 | ||
4801 | if (status != SUCCESS) | |
4802 | goto error; | |
4803 | cmdsize = sizeof(struct fc_rdp_res_frame); | |
4804 | ||
4805 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, | |
4806 | lpfc_max_els_tries, rdp_context->ndlp, | |
4807 | rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); | |
4808 | lpfc_nlp_put(ndlp); | |
4809 | if (!elsiocb) | |
4810 | goto free_rdp_context; | |
4811 | ||
4812 | icmd = &elsiocb->iocb; | |
4813 | icmd->ulpContext = rdp_context->rx_id; | |
4814 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; | |
4815 | ||
4816 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4817 | "2171 Xmit RDP response tag x%x xri x%x, " | |
4818 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x", | |
4819 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
4820 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
4821 | ndlp->nlp_rpi); | |
4822 | rdp_res = (struct fc_rdp_res_frame *) | |
4823 | (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4824 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4825 | memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); | |
4826 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
4827 | ||
4828 | /* For RDP payload */ | |
4829 | lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP); | |
4830 | ||
4831 | lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc, | |
4832 | rdp_context->page_a0, rdp_context->page_a2); | |
4833 | lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba); | |
4834 | lpfc_rdp_res_link_error(&rdp_res->link_error_desc, | |
4835 | &rdp_context->link_stat); | |
4836 | lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba); | |
4837 | lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc, | |
4838 | vport, ndlp); | |
4839 | rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE); | |
4840 | ||
4841 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
4842 | ||
4843 | phba->fc_stat.elsXmitACC++; | |
4844 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
4845 | if (rc == IOCB_ERROR) | |
4846 | lpfc_els_free_iocb(phba, elsiocb); | |
4847 | ||
4848 | kfree(rdp_context); | |
4849 | ||
4850 | return; | |
4851 | error: | |
4852 | cmdsize = 2 * sizeof(uint32_t); | |
4853 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, | |
4854 | ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
4855 | lpfc_nlp_put(ndlp); | |
4856 | if (!elsiocb) | |
4857 | goto free_rdp_context; | |
4858 | ||
4859 | icmd = &elsiocb->iocb; | |
4860 | icmd->ulpContext = rdp_context->rx_id; | |
4861 | icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; | |
4862 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4863 | ||
4864 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | |
4865 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); | |
4866 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
4867 | ||
4868 | phba->fc_stat.elsXmitLSRJT++; | |
4869 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
4870 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
4871 | ||
4872 | if (rc == IOCB_ERROR) | |
4873 | lpfc_els_free_iocb(phba, elsiocb); | |
4874 | free_rdp_context: | |
4875 | kfree(rdp_context); | |
4876 | } | |
4877 | ||
4878 | int | |
4879 | lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) | |
4880 | { | |
4881 | LPFC_MBOXQ_t *mbox = NULL; | |
4882 | int rc; | |
4883 | ||
4884 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4885 | if (!mbox) { | |
4886 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, | |
4887 | "7105 failed to allocate mailbox memory"); | |
4888 | return 1; | |
4889 | } | |
4890 | ||
4891 | if (lpfc_sli4_dump_page_a0(phba, mbox)) | |
4892 | goto prep_mbox_fail; | |
4893 | mbox->vport = rdp_context->ndlp->vport; | |
4894 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; | |
4895 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; | |
4896 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
4897 | if (rc == MBX_NOT_FINISHED) | |
4898 | goto issue_mbox_fail; | |
4899 | ||
4900 | return 0; | |
4901 | ||
4902 | prep_mbox_fail: | |
4903 | issue_mbox_fail: | |
4904 | mempool_free(mbox, phba->mbox_mem_pool); | |
4905 | return 1; | |
4906 | } | |
4907 | ||
4908 | /* | |
4909 | * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. | |
4910 | * @vport: pointer to a host virtual N_Port data structure. | |
4911 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
4912 | * @ndlp: pointer to a node-list data structure. | |
4913 | * | |
4914 | * This routine processes an unsolicited RDP(Read Diagnostic Parameters) | |
4915 | * IOCB. First, the payload of the unsolicited RDP is checked. | |
4916 | * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 | |
4917 | * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, | |
4918 | * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl | |
4919 | * gather all data and send RDP response. | |
4920 | * | |
4921 | * Return code | |
4922 | * 0 - Sent the acc response | |
4923 | * 1 - Sent the reject response. | |
4924 | */ | |
4925 | static int | |
4926 | lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
4927 | struct lpfc_nodelist *ndlp) | |
4928 | { | |
4929 | struct lpfc_hba *phba = vport->phba; | |
4930 | struct lpfc_dmabuf *pcmd; | |
4931 | uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; | |
4932 | struct fc_rdp_req_frame *rdp_req; | |
4933 | struct lpfc_rdp_context *rdp_context; | |
4934 | IOCB_t *cmd = NULL; | |
4935 | struct ls_rjt stat; | |
4936 | ||
4937 | if (phba->sli_rev < LPFC_SLI_REV4 || | |
4938 | (bf_get(lpfc_sli_intf_if_type, | |
4939 | &phba->sli4_hba.sli_intf) != | |
4940 | LPFC_SLI_INTF_IF_TYPE_2)) { | |
4941 | rjt_err = LSRJT_UNABLE_TPC; | |
4942 | rjt_expl = LSEXP_REQ_UNSUPPORTED; | |
4943 | goto error; | |
4944 | } | |
4945 | ||
4946 | if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) { | |
4947 | rjt_err = LSRJT_UNABLE_TPC; | |
4948 | rjt_expl = LSEXP_REQ_UNSUPPORTED; | |
4949 | goto error; | |
4950 | } | |
4951 | ||
4952 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
4953 | rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; | |
4954 | ||
4955 | ||
4956 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
4957 | "2422 ELS RDP Request " | |
4958 | "dec len %d tag x%x port_id %d len %d\n", | |
4959 | be32_to_cpu(rdp_req->rdp_des_length), | |
4960 | be32_to_cpu(rdp_req->nport_id_desc.tag), | |
4961 | be32_to_cpu(rdp_req->nport_id_desc.nport_id), | |
4962 | be32_to_cpu(rdp_req->nport_id_desc.length)); | |
4963 | ||
4964 | if (sizeof(struct fc_rdp_nport_desc) != | |
4965 | be32_to_cpu(rdp_req->rdp_des_length)) | |
4966 | goto rjt_logerr; | |
4967 | if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) | |
4968 | goto rjt_logerr; | |
4969 | if (RDP_NPORT_ID_SIZE != | |
4970 | be32_to_cpu(rdp_req->nport_id_desc.length)) | |
4971 | goto rjt_logerr; | |
4972 | rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); | |
4973 | if (!rdp_context) { | |
4974 | rjt_err = LSRJT_UNABLE_TPC; | |
4975 | goto error; | |
4976 | } | |
4977 | ||
4978 | memset(rdp_context, 0, sizeof(struct lpfc_rdp_context)); | |
4979 | cmd = &cmdiocb->iocb; | |
4980 | rdp_context->ndlp = lpfc_nlp_get(ndlp); | |
4981 | rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id; | |
4982 | rdp_context->rx_id = cmd->ulpContext; | |
4983 | rdp_context->cmpl = lpfc_els_rdp_cmpl; | |
4984 | if (lpfc_get_rdp_info(phba, rdp_context)) { | |
4985 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, | |
4986 | "2423 Unable to send mailbox"); | |
4987 | kfree(rdp_context); | |
4988 | rjt_err = LSRJT_UNABLE_TPC; | |
4989 | lpfc_nlp_put(ndlp); | |
4990 | goto error; | |
4991 | } | |
4992 | ||
4993 | return 0; | |
4994 | ||
4995 | rjt_logerr: | |
4996 | rjt_err = LSRJT_LOGICAL_ERR; | |
4997 | ||
4998 | error: | |
4999 | memset(&stat, 0, sizeof(stat)); | |
5000 | stat.un.b.lsRjtRsnCode = rjt_err; | |
5001 | stat.un.b.lsRjtRsnCodeExp = rjt_expl; | |
5002 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
5003 | return 1; | |
5004 | } | |
5005 | ||
5006 | ||
8b017a30 JS |
5007 | static void |
5008 | lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
5009 | { | |
5010 | MAILBOX_t *mb; | |
5011 | IOCB_t *icmd; | |
5012 | uint8_t *pcmd; | |
5013 | struct lpfc_iocbq *elsiocb; | |
5014 | struct lpfc_nodelist *ndlp; | |
5015 | struct ls_rjt *stat; | |
481ad967 | 5016 | union lpfc_sli4_cfg_shdr *shdr; |
8b017a30 JS |
5017 | struct lpfc_lcb_context *lcb_context; |
5018 | struct fc_lcb_res_frame *lcb_res; | |
481ad967 | 5019 | uint32_t cmdsize, shdr_status, shdr_add_status; |
8b017a30 JS |
5020 | int rc; |
5021 | ||
5022 | mb = &pmb->u.mb; | |
8b017a30 JS |
5023 | lcb_context = (struct lpfc_lcb_context *)pmb->context1; |
5024 | ndlp = lcb_context->ndlp; | |
5025 | pmb->context1 = NULL; | |
5026 | pmb->context2 = NULL; | |
5027 | ||
481ad967 JS |
5028 | shdr = (union lpfc_sli4_cfg_shdr *) |
5029 | &pmb->u.mqe.un.beacon_config.header.cfg_shdr; | |
5030 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5031 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5032 | ||
5033 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, | |
5034 | "0194 SET_BEACON_CONFIG mailbox " | |
5035 | "completed with status x%x add_status x%x," | |
5036 | " mbx status x%x\n", | |
5037 | shdr_status, shdr_add_status, mb->mbxStatus); | |
5038 | ||
5039 | if (mb->mbxStatus && !(shdr_status && | |
5040 | shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) { | |
8b017a30 JS |
5041 | mempool_free(pmb, phba->mbox_mem_pool); |
5042 | goto error; | |
5043 | } | |
5044 | ||
5045 | mempool_free(pmb, phba->mbox_mem_pool); | |
8b017a30 JS |
5046 | cmdsize = sizeof(struct fc_lcb_res_frame); |
5047 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
5048 | lpfc_max_els_tries, ndlp, | |
5049 | ndlp->nlp_DID, ELS_CMD_ACC); | |
5050 | ||
5051 | /* Decrement the ndlp reference count from previous mbox command */ | |
5052 | lpfc_nlp_put(ndlp); | |
5053 | ||
5054 | if (!elsiocb) | |
5055 | goto free_lcb_context; | |
5056 | ||
5057 | lcb_res = (struct fc_lcb_res_frame *) | |
5058 | (((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5059 | ||
5060 | icmd = &elsiocb->iocb; | |
5061 | icmd->ulpContext = lcb_context->rx_id; | |
5062 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; | |
5063 | ||
5064 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5065 | *((uint32_t *)(pcmd)) = ELS_CMD_ACC; | |
5066 | lcb_res->lcb_sub_command = lcb_context->sub_command; | |
5067 | lcb_res->lcb_type = lcb_context->type; | |
5068 | lcb_res->lcb_frequency = lcb_context->frequency; | |
5069 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
5070 | phba->fc_stat.elsXmitACC++; | |
5071 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5072 | if (rc == IOCB_ERROR) | |
5073 | lpfc_els_free_iocb(phba, elsiocb); | |
5074 | ||
5075 | kfree(lcb_context); | |
5076 | return; | |
5077 | ||
5078 | error: | |
5079 | cmdsize = sizeof(struct fc_lcb_res_frame); | |
5080 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
5081 | lpfc_max_els_tries, ndlp, | |
5082 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
5083 | lpfc_nlp_put(ndlp); | |
5084 | if (!elsiocb) | |
5085 | goto free_lcb_context; | |
5086 | ||
5087 | icmd = &elsiocb->iocb; | |
5088 | icmd->ulpContext = lcb_context->rx_id; | |
5089 | icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; | |
5090 | pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt); | |
5091 | ||
5092 | *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; | |
5093 | stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); | |
5094 | stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
5095 | ||
5096 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
5097 | phba->fc_stat.elsXmitLSRJT++; | |
5098 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
5099 | if (rc == IOCB_ERROR) | |
5100 | lpfc_els_free_iocb(phba, elsiocb); | |
5101 | free_lcb_context: | |
5102 | kfree(lcb_context); | |
5103 | } | |
5104 | ||
5105 | static int | |
5106 | lpfc_sli4_set_beacon(struct lpfc_vport *vport, | |
5107 | struct lpfc_lcb_context *lcb_context, | |
5108 | uint32_t beacon_state) | |
5109 | { | |
5110 | struct lpfc_hba *phba = vport->phba; | |
5111 | LPFC_MBOXQ_t *mbox = NULL; | |
5112 | uint32_t len; | |
5113 | int rc; | |
5114 | ||
5115 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5116 | if (!mbox) | |
5117 | return 1; | |
5118 | ||
5119 | len = sizeof(struct lpfc_mbx_set_beacon_config) - | |
5120 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
5121 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5122 | LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, | |
5123 | LPFC_SLI4_MBX_EMBED); | |
5124 | mbox->context1 = (void *)lcb_context; | |
5125 | mbox->vport = phba->pport; | |
5126 | mbox->mbox_cmpl = lpfc_els_lcb_rsp; | |
5127 | bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, | |
5128 | phba->sli4_hba.physical_port); | |
5129 | bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, | |
5130 | beacon_state); | |
5131 | bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1); | |
5132 | bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0); | |
5133 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
5134 | if (rc == MBX_NOT_FINISHED) { | |
5135 | mempool_free(mbox, phba->mbox_mem_pool); | |
5136 | return 1; | |
5137 | } | |
5138 | ||
5139 | return 0; | |
5140 | } | |
5141 | ||
5142 | ||
5143 | /** | |
5144 | * lpfc_els_rcv_lcb - Process an unsolicited LCB | |
5145 | * @vport: pointer to a host virtual N_Port data structure. | |
5146 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5147 | * @ndlp: pointer to a node-list data structure. | |
5148 | * | |
5149 | * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. | |
5150 | * First, the payload of the unsolicited LCB is checked. | |
5151 | * Then based on Subcommand beacon will either turn on or off. | |
5152 | * | |
5153 | * Return code | |
5154 | * 0 - Sent the acc response | |
5155 | * 1 - Sent the reject response. | |
5156 | **/ | |
5157 | static int | |
5158 | lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
5159 | struct lpfc_nodelist *ndlp) | |
5160 | { | |
5161 | struct lpfc_hba *phba = vport->phba; | |
5162 | struct lpfc_dmabuf *pcmd; | |
8b017a30 JS |
5163 | uint8_t *lp; |
5164 | struct fc_lcb_request_frame *beacon; | |
5165 | struct lpfc_lcb_context *lcb_context; | |
5166 | uint8_t state, rjt_err; | |
5167 | struct ls_rjt stat; | |
5168 | ||
8b017a30 JS |
5169 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
5170 | lp = (uint8_t *)pcmd->virt; | |
5171 | beacon = (struct fc_lcb_request_frame *)pcmd->virt; | |
5172 | ||
5173 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
5174 | "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " | |
5175 | "type x%x frequency %x duration x%x\n", | |
5176 | lp[0], lp[1], lp[2], | |
5177 | beacon->lcb_command, | |
5178 | beacon->lcb_sub_command, | |
5179 | beacon->lcb_type, | |
5180 | beacon->lcb_frequency, | |
5181 | be16_to_cpu(beacon->lcb_duration)); | |
5182 | ||
5183 | if (phba->sli_rev < LPFC_SLI_REV4 || | |
5184 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
5185 | LPFC_SLI_INTF_IF_TYPE_2)) { | |
5186 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5187 | goto rjt; | |
5188 | } | |
8b017a30 JS |
5189 | |
5190 | if (phba->hba_flag & HBA_FCOE_MODE) { | |
5191 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5192 | goto rjt; | |
5193 | } | |
5194 | if (beacon->lcb_frequency == 0) { | |
5195 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5196 | goto rjt; | |
5197 | } | |
5198 | if ((beacon->lcb_type != LPFC_LCB_GREEN) && | |
5199 | (beacon->lcb_type != LPFC_LCB_AMBER)) { | |
5200 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5201 | goto rjt; | |
5202 | } | |
5203 | if ((beacon->lcb_sub_command != LPFC_LCB_ON) && | |
5204 | (beacon->lcb_sub_command != LPFC_LCB_OFF)) { | |
5205 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5206 | goto rjt; | |
5207 | } | |
5208 | if ((beacon->lcb_sub_command == LPFC_LCB_ON) && | |
5209 | (beacon->lcb_type != LPFC_LCB_GREEN) && | |
5210 | (beacon->lcb_type != LPFC_LCB_AMBER)) { | |
5211 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5212 | goto rjt; | |
5213 | } | |
5214 | if (be16_to_cpu(beacon->lcb_duration) != 0) { | |
5215 | rjt_err = LSRJT_CMD_UNSUPPORTED; | |
5216 | goto rjt; | |
5217 | } | |
5218 | ||
e7950423 SM |
5219 | lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); |
5220 | if (!lcb_context) { | |
5221 | rjt_err = LSRJT_UNABLE_TPC; | |
5222 | goto rjt; | |
5223 | } | |
5224 | ||
8b017a30 JS |
5225 | state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; |
5226 | lcb_context->sub_command = beacon->lcb_sub_command; | |
5227 | lcb_context->type = beacon->lcb_type; | |
5228 | lcb_context->frequency = beacon->lcb_frequency; | |
5229 | lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; | |
5230 | lcb_context->rx_id = cmdiocb->iocb.ulpContext; | |
5231 | lcb_context->ndlp = lpfc_nlp_get(ndlp); | |
5232 | if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { | |
5233 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
5234 | LOG_ELS, "0193 failed to send mail box"); | |
e7950423 | 5235 | kfree(lcb_context); |
8b017a30 JS |
5236 | lpfc_nlp_put(ndlp); |
5237 | rjt_err = LSRJT_UNABLE_TPC; | |
5238 | goto rjt; | |
5239 | } | |
5240 | return 0; | |
5241 | rjt: | |
5242 | memset(&stat, 0, sizeof(stat)); | |
5243 | stat.un.b.lsRjtRsnCode = rjt_err; | |
5244 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
5245 | return 1; | |
5246 | } | |
5247 | ||
5248 | ||
e59058c4 | 5249 | /** |
3621a710 | 5250 | * lpfc_els_flush_rscn - Clean up any rscn activities with a vport |
e59058c4 JS |
5251 | * @vport: pointer to a host virtual N_Port data structure. |
5252 | * | |
5253 | * This routine cleans up any Registration State Change Notification | |
5254 | * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the | |
5255 | * @vport together with the host_lock is used to prevent multiple thread | |
5256 | * trying to access the RSCN array on a same @vport at the same time. | |
5257 | **/ | |
92d7f7b0 | 5258 | void |
2e0fef85 | 5259 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
dea3101e | 5260 | { |
2e0fef85 JS |
5261 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5262 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5263 | int i; |
5264 | ||
7f5f3d0d JS |
5265 | spin_lock_irq(shost->host_lock); |
5266 | if (vport->fc_rscn_flush) { | |
5267 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
5268 | spin_unlock_irq(shost->host_lock); | |
5269 | return; | |
5270 | } | |
5271 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ | |
5272 | vport->fc_rscn_flush = 1; | |
5273 | spin_unlock_irq(shost->host_lock); | |
5274 | ||
2e0fef85 | 5275 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 | 5276 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
2e0fef85 | 5277 | vport->fc_rscn_id_list[i] = NULL; |
dea3101e | 5278 | } |
2e0fef85 JS |
5279 | spin_lock_irq(shost->host_lock); |
5280 | vport->fc_rscn_id_cnt = 0; | |
5281 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); | |
5282 | spin_unlock_irq(shost->host_lock); | |
5283 | lpfc_can_disctmo(vport); | |
7f5f3d0d JS |
5284 | /* Indicate we are done walking this fc_rscn_id_list */ |
5285 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
5286 | } |
5287 | ||
e59058c4 | 5288 | /** |
3621a710 | 5289 | * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did |
e59058c4 JS |
5290 | * @vport: pointer to a host virtual N_Port data structure. |
5291 | * @did: remote destination port identifier. | |
5292 | * | |
5293 | * This routine checks whether there is any pending Registration State | |
5294 | * Configuration Notification (RSCN) to a @did on @vport. | |
5295 | * | |
5296 | * Return code | |
5297 | * None zero - The @did matched with a pending rscn | |
5298 | * 0 - not able to match @did with a pending rscn | |
5299 | **/ | |
dea3101e | 5300 | int |
2e0fef85 | 5301 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
dea3101e JB |
5302 | { |
5303 | D_ID ns_did; | |
5304 | D_ID rscn_did; | |
dea3101e | 5305 | uint32_t *lp; |
92d7f7b0 | 5306 | uint32_t payload_len, i; |
7f5f3d0d | 5307 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
5308 | |
5309 | ns_did.un.word = did; | |
dea3101e JB |
5310 | |
5311 | /* Never match fabric nodes for RSCNs */ | |
5312 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
2e0fef85 | 5313 | return 0; |
dea3101e JB |
5314 | |
5315 | /* If we are doing a FULL RSCN rediscovery, match everything */ | |
2e0fef85 | 5316 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
c9f8735b | 5317 | return did; |
dea3101e | 5318 | |
7f5f3d0d JS |
5319 | spin_lock_irq(shost->host_lock); |
5320 | if (vport->fc_rscn_flush) { | |
5321 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
5322 | spin_unlock_irq(shost->host_lock); | |
5323 | return 0; | |
5324 | } | |
5325 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
5326 | vport->fc_rscn_flush = 1; | |
5327 | spin_unlock_irq(shost->host_lock); | |
2e0fef85 | 5328 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 JS |
5329 | lp = vport->fc_rscn_id_list[i]->virt; |
5330 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | |
5331 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 5332 | while (payload_len) { |
92d7f7b0 JS |
5333 | rscn_did.un.word = be32_to_cpu(*lp++); |
5334 | payload_len -= sizeof(uint32_t); | |
eaf15d5b JS |
5335 | switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { |
5336 | case RSCN_ADDRESS_FORMAT_PORT: | |
6fb120a7 JS |
5337 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
5338 | && (ns_did.un.b.area == rscn_did.un.b.area) | |
5339 | && (ns_did.un.b.id == rscn_did.un.b.id)) | |
7f5f3d0d | 5340 | goto return_did_out; |
dea3101e | 5341 | break; |
eaf15d5b | 5342 | case RSCN_ADDRESS_FORMAT_AREA: |
dea3101e JB |
5343 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
5344 | && (ns_did.un.b.area == rscn_did.un.b.area)) | |
7f5f3d0d | 5345 | goto return_did_out; |
dea3101e | 5346 | break; |
eaf15d5b | 5347 | case RSCN_ADDRESS_FORMAT_DOMAIN: |
dea3101e | 5348 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
7f5f3d0d | 5349 | goto return_did_out; |
dea3101e | 5350 | break; |
eaf15d5b | 5351 | case RSCN_ADDRESS_FORMAT_FABRIC: |
7f5f3d0d | 5352 | goto return_did_out; |
dea3101e JB |
5353 | } |
5354 | } | |
92d7f7b0 | 5355 | } |
7f5f3d0d JS |
5356 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
5357 | vport->fc_rscn_flush = 0; | |
92d7f7b0 | 5358 | return 0; |
7f5f3d0d JS |
5359 | return_did_out: |
5360 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | |
5361 | vport->fc_rscn_flush = 0; | |
5362 | return did; | |
dea3101e JB |
5363 | } |
5364 | ||
e59058c4 | 5365 | /** |
3621a710 | 5366 | * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn |
e59058c4 JS |
5367 | * @vport: pointer to a host virtual N_Port data structure. |
5368 | * | |
5369 | * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the | |
5370 | * state machine for a @vport's nodes that are with pending RSCN (Registration | |
5371 | * State Change Notification). | |
5372 | * | |
5373 | * Return code | |
5374 | * 0 - Successful (currently alway return 0) | |
5375 | **/ | |
dea3101e | 5376 | static int |
2e0fef85 | 5377 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
dea3101e | 5378 | { |
685f0bf7 | 5379 | struct lpfc_nodelist *ndlp = NULL; |
dea3101e | 5380 | |
0d2b6b83 | 5381 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
2e0fef85 | 5382 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 | 5383 | if (!NLP_CHK_NODE_ACT(ndlp) || |
0d2b6b83 JS |
5384 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
5385 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) | |
685f0bf7 | 5386 | continue; |
2e0fef85 | 5387 | lpfc_disc_state_machine(vport, ndlp, NULL, |
0d2b6b83 JS |
5388 | NLP_EVT_DEVICE_RECOVERY); |
5389 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
dea3101e | 5390 | } |
c9f8735b | 5391 | return 0; |
dea3101e JB |
5392 | } |
5393 | ||
ddcc50f0 | 5394 | /** |
3621a710 | 5395 | * lpfc_send_rscn_event - Send an RSCN event to management application |
ddcc50f0 JS |
5396 | * @vport: pointer to a host virtual N_Port data structure. |
5397 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5398 | * | |
5399 | * lpfc_send_rscn_event sends an RSCN netlink event to management | |
5400 | * applications. | |
5401 | */ | |
5402 | static void | |
5403 | lpfc_send_rscn_event(struct lpfc_vport *vport, | |
5404 | struct lpfc_iocbq *cmdiocb) | |
5405 | { | |
5406 | struct lpfc_dmabuf *pcmd; | |
5407 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
5408 | uint32_t *payload_ptr; | |
5409 | uint32_t payload_len; | |
5410 | struct lpfc_rscn_event_header *rscn_event_data; | |
5411 | ||
5412 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
5413 | payload_ptr = (uint32_t *) pcmd->virt; | |
5414 | payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); | |
5415 | ||
5416 | rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + | |
5417 | payload_len, GFP_KERNEL); | |
5418 | if (!rscn_event_data) { | |
5419 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
5420 | "0147 Failed to allocate memory for RSCN event\n"); | |
5421 | return; | |
5422 | } | |
5423 | rscn_event_data->event_type = FC_REG_RSCN_EVENT; | |
5424 | rscn_event_data->payload_length = payload_len; | |
5425 | memcpy(rscn_event_data->rscn_payload, payload_ptr, | |
5426 | payload_len); | |
5427 | ||
5428 | fc_host_post_vendor_event(shost, | |
5429 | fc_get_event_number(), | |
6599eaaa | 5430 | sizeof(struct lpfc_rscn_event_header) + payload_len, |
ddcc50f0 JS |
5431 | (char *)rscn_event_data, |
5432 | LPFC_NL_VENDOR_ID); | |
5433 | ||
5434 | kfree(rscn_event_data); | |
5435 | } | |
5436 | ||
e59058c4 | 5437 | /** |
3621a710 | 5438 | * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb |
e59058c4 JS |
5439 | * @vport: pointer to a host virtual N_Port data structure. |
5440 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5441 | * @ndlp: pointer to a node-list data structure. | |
5442 | * | |
5443 | * This routine processes an unsolicited RSCN (Registration State Change | |
5444 | * Notification) IOCB. First, the payload of the unsolicited RSCN is walked | |
5445 | * to invoke fc_host_post_event() routine to the FC transport layer. If the | |
5446 | * discover state machine is about to begin discovery, it just accepts the | |
5447 | * RSCN and the discovery process will satisfy the RSCN. If this RSCN only | |
5448 | * contains N_Port IDs for other vports on this HBA, it just accepts the | |
5449 | * RSCN and ignore processing it. If the state machine is in the recovery | |
5450 | * state, the fc_rscn_id_list of this @vport is walked and the | |
5451 | * lpfc_rscn_recovery_check() routine is invoked to send recovery event for | |
5452 | * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() | |
5453 | * routine is invoked to handle the RSCN event. | |
5454 | * | |
5455 | * Return code | |
5456 | * 0 - Just sent the acc response | |
5457 | * 1 - Sent the acc response and waited for name server completion | |
5458 | **/ | |
dea3101e | 5459 | static int |
2e0fef85 | 5460 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 5461 | struct lpfc_nodelist *ndlp) |
dea3101e | 5462 | { |
2e0fef85 JS |
5463 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5464 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5465 | struct lpfc_dmabuf *pcmd; |
92d7f7b0 | 5466 | uint32_t *lp, *datap; |
92d7f7b0 | 5467 | uint32_t payload_len, length, nportid, *cmd; |
7f5f3d0d | 5468 | int rscn_cnt; |
92d7f7b0 | 5469 | int rscn_id = 0, hba_id = 0; |
d2873e4c | 5470 | int i; |
dea3101e | 5471 | |
dea3101e JB |
5472 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
5473 | lp = (uint32_t *) pcmd->virt; | |
5474 | ||
92d7f7b0 JS |
5475 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
5476 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 5477 | /* RSCN received */ |
e8b62011 JS |
5478 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5479 | "0214 RSCN received Data: x%x x%x x%x x%x\n", | |
7f5f3d0d JS |
5480 | vport->fc_flag, payload_len, *lp, |
5481 | vport->fc_rscn_id_cnt); | |
ddcc50f0 JS |
5482 | |
5483 | /* Send an RSCN event to the management application */ | |
5484 | lpfc_send_rscn_event(vport, cmdiocb); | |
5485 | ||
d2873e4c | 5486 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
2e0fef85 | 5487 | fc_host_post_event(shost, fc_get_event_number(), |
d2873e4c JS |
5488 | FCH_EVT_RSCN, lp[i]); |
5489 | ||
dea3101e JB |
5490 | /* If we are about to begin discovery, just ACC the RSCN. |
5491 | * Discovery processing will satisfy it. | |
5492 | */ | |
2e0fef85 | 5493 | if (vport->port_state <= LPFC_NS_QRY) { |
858c9f6c JS |
5494 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
5495 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", | |
5496 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
5497 | ||
51ef4c26 | 5498 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
c9f8735b | 5499 | return 0; |
dea3101e JB |
5500 | } |
5501 | ||
92d7f7b0 JS |
5502 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
5503 | * just ACC and ignore it. | |
5504 | */ | |
5505 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
3de2a653 | 5506 | !(vport->cfg_peer_port_login)) { |
92d7f7b0 JS |
5507 | i = payload_len; |
5508 | datap = lp; | |
5509 | while (i > 0) { | |
5510 | nportid = *datap++; | |
5511 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); | |
5512 | i -= sizeof(uint32_t); | |
5513 | rscn_id++; | |
549e55cd JS |
5514 | if (lpfc_find_vport_by_did(phba, nportid)) |
5515 | hba_id++; | |
92d7f7b0 JS |
5516 | } |
5517 | if (rscn_id == hba_id) { | |
5518 | /* ALL NPortIDs in RSCN are on HBA */ | |
e8b62011 | 5519 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
d7c255b2 | 5520 | "0219 Ignore RSCN " |
e8b62011 JS |
5521 | "Data: x%x x%x x%x x%x\n", |
5522 | vport->fc_flag, payload_len, | |
7f5f3d0d | 5523 | *lp, vport->fc_rscn_id_cnt); |
858c9f6c JS |
5524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
5525 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", | |
5526 | ndlp->nlp_DID, vport->port_state, | |
5527 | ndlp->nlp_flag); | |
5528 | ||
92d7f7b0 | 5529 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
51ef4c26 | 5530 | ndlp, NULL); |
92d7f7b0 JS |
5531 | return 0; |
5532 | } | |
5533 | } | |
5534 | ||
7f5f3d0d JS |
5535 | spin_lock_irq(shost->host_lock); |
5536 | if (vport->fc_rscn_flush) { | |
5537 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
7f5f3d0d | 5538 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
97957244 | 5539 | spin_unlock_irq(shost->host_lock); |
58da1ffb JS |
5540 | /* Send back ACC */ |
5541 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | |
7f5f3d0d JS |
5542 | return 0; |
5543 | } | |
5544 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
5545 | vport->fc_rscn_flush = 1; | |
5546 | spin_unlock_irq(shost->host_lock); | |
af901ca1 | 5547 | /* Get the array count after successfully have the token */ |
7f5f3d0d | 5548 | rscn_cnt = vport->fc_rscn_id_cnt; |
dea3101e JB |
5549 | /* If we are already processing an RSCN, save the received |
5550 | * RSCN payload buffer, cmdiocb->context2 to process later. | |
5551 | */ | |
2e0fef85 | 5552 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
858c9f6c JS |
5553 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
5554 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", | |
5555 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
5556 | ||
09372820 | 5557 | spin_lock_irq(shost->host_lock); |
92d7f7b0 JS |
5558 | vport->fc_flag |= FC_RSCN_DEFERRED; |
5559 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && | |
2e0fef85 | 5560 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
2e0fef85 JS |
5561 | vport->fc_flag |= FC_RSCN_MODE; |
5562 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 JS |
5563 | if (rscn_cnt) { |
5564 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; | |
5565 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); | |
5566 | } | |
5567 | if ((rscn_cnt) && | |
5568 | (payload_len + length <= LPFC_BPL_SIZE)) { | |
5569 | *cmd &= ELS_CMD_MASK; | |
7f5f3d0d | 5570 | *cmd |= cpu_to_be32(payload_len + length); |
92d7f7b0 JS |
5571 | memcpy(((uint8_t *)cmd) + length, lp, |
5572 | payload_len); | |
5573 | } else { | |
5574 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; | |
5575 | vport->fc_rscn_id_cnt++; | |
5576 | /* If we zero, cmdiocb->context2, the calling | |
5577 | * routine will not try to free it. | |
5578 | */ | |
5579 | cmdiocb->context2 = NULL; | |
5580 | } | |
dea3101e | 5581 | /* Deferred RSCN */ |
e8b62011 JS |
5582 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5583 | "0235 Deferred RSCN " | |
5584 | "Data: x%x x%x x%x\n", | |
5585 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
5586 | vport->port_state); | |
dea3101e | 5587 | } else { |
2e0fef85 JS |
5588 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
5589 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 5590 | /* ReDiscovery RSCN */ |
e8b62011 JS |
5591 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5592 | "0234 ReDiscovery RSCN " | |
5593 | "Data: x%x x%x x%x\n", | |
5594 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
5595 | vport->port_state); | |
dea3101e | 5596 | } |
7f5f3d0d JS |
5597 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
5598 | vport->fc_rscn_flush = 0; | |
dea3101e | 5599 | /* Send back ACC */ |
51ef4c26 | 5600 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 5601 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 5602 | lpfc_rscn_recovery_check(vport); |
09372820 | 5603 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 5604 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
09372820 | 5605 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 5606 | return 0; |
dea3101e | 5607 | } |
858c9f6c JS |
5608 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
5609 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", | |
5610 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
5611 | ||
2e0fef85 JS |
5612 | spin_lock_irq(shost->host_lock); |
5613 | vport->fc_flag |= FC_RSCN_MODE; | |
5614 | spin_unlock_irq(shost->host_lock); | |
5615 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; | |
7f5f3d0d JS |
5616 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
5617 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
5618 | /* |
5619 | * If we zero, cmdiocb->context2, the calling routine will | |
5620 | * not try to free it. | |
5621 | */ | |
5622 | cmdiocb->context2 = NULL; | |
2e0fef85 | 5623 | lpfc_set_disctmo(vport); |
dea3101e | 5624 | /* Send back ACC */ |
51ef4c26 | 5625 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 5626 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 5627 | lpfc_rscn_recovery_check(vport); |
2e0fef85 | 5628 | return lpfc_els_handle_rscn(vport); |
dea3101e JB |
5629 | } |
5630 | ||
e59058c4 | 5631 | /** |
3621a710 | 5632 | * lpfc_els_handle_rscn - Handle rscn for a vport |
e59058c4 JS |
5633 | * @vport: pointer to a host virtual N_Port data structure. |
5634 | * | |
5635 | * This routine handles the Registration State Configuration Notification | |
5636 | * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall | |
5637 | * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, | |
5638 | * if the ndlp to NameServer exists, a Common Transport (CT) command to the | |
5639 | * NameServer shall be issued. If CT command to the NameServer fails to be | |
5640 | * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any | |
5641 | * RSCN activities with the @vport. | |
5642 | * | |
5643 | * Return code | |
5644 | * 0 - Cleaned up rscn on the @vport | |
5645 | * 1 - Wait for plogi to name server before proceed | |
5646 | **/ | |
dea3101e | 5647 | int |
2e0fef85 | 5648 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
dea3101e JB |
5649 | { |
5650 | struct lpfc_nodelist *ndlp; | |
2e0fef85 | 5651 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 5652 | |
92d7f7b0 JS |
5653 | /* Ignore RSCN if the port is being torn down. */ |
5654 | if (vport->load_flag & FC_UNLOADING) { | |
5655 | lpfc_els_flush_rscn(vport); | |
5656 | return 0; | |
5657 | } | |
5658 | ||
dea3101e | 5659 | /* Start timer for RSCN processing */ |
2e0fef85 | 5660 | lpfc_set_disctmo(vport); |
dea3101e JB |
5661 | |
5662 | /* RSCN processed */ | |
e8b62011 JS |
5663 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5664 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", | |
5665 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, | |
5666 | vport->port_state); | |
dea3101e JB |
5667 | |
5668 | /* To process RSCN, first compare RSCN data with NameServer */ | |
2e0fef85 | 5669 | vport->fc_ns_retry = 0; |
0ff10d46 JS |
5670 | vport->num_disc_nodes = 0; |
5671 | ||
2e0fef85 | 5672 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 JS |
5673 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
5674 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { | |
dea3101e | 5675 | /* Good ndlp, issue CT Request to NameServer */ |
92d7f7b0 | 5676 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
dea3101e JB |
5677 | /* Wait for NameServer query cmpl before we can |
5678 | continue */ | |
c9f8735b | 5679 | return 1; |
dea3101e JB |
5680 | } else { |
5681 | /* If login to NameServer does not exist, issue one */ | |
5682 | /* Good status, issue PLOGI to NameServer */ | |
2e0fef85 | 5683 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 | 5684 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
dea3101e JB |
5685 | /* Wait for NameServer login cmpl before we can |
5686 | continue */ | |
c9f8735b | 5687 | return 1; |
2e0fef85 | 5688 | |
e47c9093 JS |
5689 | if (ndlp) { |
5690 | ndlp = lpfc_enable_node(vport, ndlp, | |
5691 | NLP_STE_PLOGI_ISSUE); | |
5692 | if (!ndlp) { | |
5693 | lpfc_els_flush_rscn(vport); | |
5694 | return 0; | |
5695 | } | |
5696 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; | |
dea3101e | 5697 | } else { |
e47c9093 JS |
5698 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
5699 | if (!ndlp) { | |
5700 | lpfc_els_flush_rscn(vport); | |
5701 | return 0; | |
5702 | } | |
2e0fef85 | 5703 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
5024ab17 | 5704 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 5705 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
dea3101e | 5706 | } |
e47c9093 JS |
5707 | ndlp->nlp_type |= NLP_FABRIC; |
5708 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); | |
5709 | /* Wait for NameServer login cmpl before we can | |
5710 | * continue | |
5711 | */ | |
5712 | return 1; | |
dea3101e JB |
5713 | } |
5714 | ||
2e0fef85 | 5715 | lpfc_els_flush_rscn(vport); |
c9f8735b | 5716 | return 0; |
dea3101e JB |
5717 | } |
5718 | ||
e59058c4 | 5719 | /** |
3621a710 | 5720 | * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb |
e59058c4 JS |
5721 | * @vport: pointer to a host virtual N_Port data structure. |
5722 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5723 | * @ndlp: pointer to a node-list data structure. | |
5724 | * | |
5725 | * This routine processes Fabric Login (FLOGI) IOCB received as an ELS | |
5726 | * unsolicited event. An unsolicited FLOGI can be received in a point-to- | |
5727 | * point topology. As an unsolicited FLOGI should not be received in a loop | |
5728 | * mode, any unsolicited FLOGI received in loop mode shall be ignored. The | |
5729 | * lpfc_check_sparm() routine is invoked to check the parameters in the | |
5730 | * unsolicited FLOGI. If parameters validation failed, the routine | |
5731 | * lpfc_els_rsp_reject() shall be called with reject reason code set to | |
5732 | * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the | |
5733 | * FLOGI shall be compared with the Port WWN of the @vport to determine who | |
5734 | * will initiate PLOGI. The higher lexicographical value party shall has | |
5735 | * higher priority (as the winning port) and will initiate PLOGI and | |
5736 | * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result | |
5737 | * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI | |
5738 | * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. | |
5739 | * | |
5740 | * Return code | |
5741 | * 0 - Successfully processed the unsolicited flogi | |
5742 | * 1 - Failed to process the unsolicited flogi | |
5743 | **/ | |
dea3101e | 5744 | static int |
2e0fef85 | 5745 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 5746 | struct lpfc_nodelist *ndlp) |
dea3101e | 5747 | { |
2e0fef85 JS |
5748 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5749 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5750 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
5751 | uint32_t *lp = (uint32_t *) pcmd->virt; | |
5752 | IOCB_t *icmd = &cmdiocb->iocb; | |
5753 | struct serv_parm *sp; | |
5754 | LPFC_MBOXQ_t *mbox; | |
dea3101e JB |
5755 | uint32_t cmd, did; |
5756 | int rc; | |
e74c03c8 JS |
5757 | uint32_t fc_flag = 0; |
5758 | uint32_t port_state = 0; | |
dea3101e JB |
5759 | |
5760 | cmd = *lp++; | |
5761 | sp = (struct serv_parm *) lp; | |
5762 | ||
5763 | /* FLOGI received */ | |
5764 | ||
2e0fef85 | 5765 | lpfc_set_disctmo(vport); |
dea3101e | 5766 | |
76a95d75 | 5767 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
dea3101e JB |
5768 | /* We should never receive a FLOGI in loop mode, ignore it */ |
5769 | did = icmd->un.elsreq64.remoteID; | |
5770 | ||
5771 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in | |
5772 | Loop Mode */ | |
e8b62011 JS |
5773 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
5774 | "0113 An FLOGI ELS command x%x was " | |
5775 | "received from DID x%x in Loop Mode\n", | |
5776 | cmd, did); | |
c9f8735b | 5777 | return 1; |
dea3101e JB |
5778 | } |
5779 | ||
d6de08cc | 5780 | (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); |
dea3101e | 5781 | |
dea3101e | 5782 | |
d6de08cc JS |
5783 | /* |
5784 | * If our portname is greater than the remote portname, | |
5785 | * then we initiate Nport login. | |
5786 | */ | |
939723a4 | 5787 | |
d6de08cc JS |
5788 | rc = memcmp(&vport->fc_portname, &sp->portName, |
5789 | sizeof(struct lpfc_name)); | |
939723a4 | 5790 | |
d6de08cc JS |
5791 | if (!rc) { |
5792 | if (phba->sli_rev < LPFC_SLI_REV4) { | |
5793 | mbox = mempool_alloc(phba->mbox_mem_pool, | |
5794 | GFP_KERNEL); | |
5795 | if (!mbox) | |
5796 | return 1; | |
5797 | lpfc_linkdown(phba); | |
5798 | lpfc_init_link(phba, mbox, | |
5799 | phba->cfg_topology, | |
5800 | phba->cfg_link_speed); | |
5801 | mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; | |
5802 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
5803 | mbox->vport = vport; | |
5804 | rc = lpfc_sli_issue_mbox(phba, mbox, | |
5805 | MBX_NOWAIT); | |
5806 | lpfc_set_loopback_flag(phba); | |
5807 | if (rc == MBX_NOT_FINISHED) | |
5808 | mempool_free(mbox, phba->mbox_mem_pool); | |
5809 | return 1; | |
5810 | } | |
5811 | ||
5812 | /* abort the flogi coming back to ourselves | |
5813 | * due to external loopback on the port. | |
939723a4 | 5814 | */ |
d6de08cc JS |
5815 | lpfc_els_abort_flogi(phba); |
5816 | return 0; | |
5817 | ||
5818 | } else if (rc > 0) { /* greater than */ | |
2e0fef85 | 5819 | spin_lock_irq(shost->host_lock); |
d6de08cc | 5820 | vport->fc_flag |= FC_PT2PT_PLOGI; |
2e0fef85 | 5821 | spin_unlock_irq(shost->host_lock); |
939723a4 | 5822 | |
d6de08cc JS |
5823 | /* If we have the high WWPN we can assign our own |
5824 | * myDID; otherwise, we have to WAIT for a PLOGI | |
5825 | * from the remote NPort to find out what it | |
5826 | * will be. | |
939723a4 | 5827 | */ |
d6de08cc | 5828 | vport->fc_myDID = PT2PT_LocalID; |
dea3101e | 5829 | } else { |
d6de08cc JS |
5830 | vport->fc_myDID = PT2PT_RemoteID; |
5831 | } | |
939723a4 | 5832 | |
d6de08cc JS |
5833 | /* |
5834 | * The vport state should go to LPFC_FLOGI only | |
5835 | * AFTER we issue a FLOGI, not receive one. | |
5836 | */ | |
5837 | spin_lock_irq(shost->host_lock); | |
5838 | fc_flag = vport->fc_flag; | |
5839 | port_state = vport->port_state; | |
5840 | vport->fc_flag |= FC_PT2PT; | |
5841 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
5842 | spin_unlock_irq(shost->host_lock); | |
5843 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
5844 | "3311 Rcv Flogi PS x%x new PS x%x " | |
5845 | "fc_flag x%x new fc_flag x%x\n", | |
5846 | port_state, vport->port_state, | |
5847 | fc_flag, vport->fc_flag); | |
939723a4 | 5848 | |
d6de08cc JS |
5849 | /* |
5850 | * We temporarily set fc_myDID to make it look like we are | |
5851 | * a Fabric. This is done just so we end up with the right | |
5852 | * did / sid on the FLOGI ACC rsp. | |
5853 | */ | |
5854 | did = vport->fc_myDID; | |
5855 | vport->fc_myDID = Fabric_DID; | |
dea3101e | 5856 | |
d6de08cc | 5857 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
eec3d312 | 5858 | |
dea3101e | 5859 | /* Send back ACC */ |
d6de08cc | 5860 | lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); |
dea3101e | 5861 | |
939723a4 JS |
5862 | /* Now lets put fc_myDID back to what its supposed to be */ |
5863 | vport->fc_myDID = did; | |
5864 | ||
c9f8735b | 5865 | return 0; |
dea3101e JB |
5866 | } |
5867 | ||
e59058c4 | 5868 | /** |
3621a710 | 5869 | * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb |
e59058c4 JS |
5870 | * @vport: pointer to a host virtual N_Port data structure. |
5871 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5872 | * @ndlp: pointer to a node-list data structure. | |
5873 | * | |
5874 | * This routine processes Request Node Identification Data (RNID) IOCB | |
5875 | * received as an ELS unsolicited event. Only when the RNID specified format | |
5876 | * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) | |
5877 | * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to | |
5878 | * Accept (ACC) the RNID ELS command. All the other RNID formats are | |
5879 | * rejected by invoking the lpfc_els_rsp_reject() routine. | |
5880 | * | |
5881 | * Return code | |
5882 | * 0 - Successfully processed rnid iocb (currently always return 0) | |
5883 | **/ | |
dea3101e | 5884 | static int |
2e0fef85 JS |
5885 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
5886 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
5887 | { |
5888 | struct lpfc_dmabuf *pcmd; | |
5889 | uint32_t *lp; | |
dea3101e JB |
5890 | RNID *rn; |
5891 | struct ls_rjt stat; | |
eb016566 | 5892 | uint32_t cmd; |
dea3101e | 5893 | |
dea3101e JB |
5894 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
5895 | lp = (uint32_t *) pcmd->virt; | |
5896 | ||
5897 | cmd = *lp++; | |
5898 | rn = (RNID *) lp; | |
5899 | ||
5900 | /* RNID received */ | |
5901 | ||
5902 | switch (rn->Format) { | |
5903 | case 0: | |
5904 | case RNID_TOPOLOGY_DISC: | |
5905 | /* Send back ACC */ | |
2e0fef85 | 5906 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
dea3101e JB |
5907 | break; |
5908 | default: | |
5909 | /* Reject this request because format not supported */ | |
5910 | stat.un.b.lsRjtRsvd0 = 0; | |
5911 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
5912 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
5913 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
5914 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
5915 | NULL); | |
dea3101e | 5916 | } |
c9f8735b | 5917 | return 0; |
dea3101e JB |
5918 | } |
5919 | ||
12265f68 JS |
5920 | /** |
5921 | * lpfc_els_rcv_echo - Process an unsolicited echo iocb | |
5922 | * @vport: pointer to a host virtual N_Port data structure. | |
5923 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5924 | * @ndlp: pointer to a node-list data structure. | |
5925 | * | |
5926 | * Return code | |
5927 | * 0 - Successfully processed echo iocb (currently always return 0) | |
5928 | **/ | |
5929 | static int | |
5930 | lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
5931 | struct lpfc_nodelist *ndlp) | |
5932 | { | |
5933 | uint8_t *pcmd; | |
5934 | ||
5935 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); | |
5936 | ||
5937 | /* skip over first word of echo command to find echo data */ | |
5938 | pcmd += sizeof(uint32_t); | |
5939 | ||
5940 | lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); | |
5941 | return 0; | |
5942 | } | |
5943 | ||
e59058c4 | 5944 | /** |
3621a710 | 5945 | * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb |
e59058c4 JS |
5946 | * @vport: pointer to a host virtual N_Port data structure. |
5947 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5948 | * @ndlp: pointer to a node-list data structure. | |
5949 | * | |
5950 | * This routine processes a Link Incident Report Registration(LIRR) IOCB | |
5951 | * received as an ELS unsolicited event. Currently, this function just invokes | |
5952 | * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. | |
5953 | * | |
5954 | * Return code | |
5955 | * 0 - Successfully processed lirr iocb (currently always return 0) | |
5956 | **/ | |
dea3101e | 5957 | static int |
2e0fef85 JS |
5958 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
5959 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
5960 | { |
5961 | struct ls_rjt stat; | |
5962 | ||
5963 | /* For now, unconditionally reject this command */ | |
5964 | stat.un.b.lsRjtRsvd0 = 0; | |
5965 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
5966 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
5967 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 5968 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
5969 | return 0; |
5970 | } | |
5971 | ||
5ffc266e JS |
5972 | /** |
5973 | * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb | |
5974 | * @vport: pointer to a host virtual N_Port data structure. | |
5975 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
5976 | * @ndlp: pointer to a node-list data structure. | |
5977 | * | |
5978 | * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB | |
5979 | * received as an ELS unsolicited event. A request to RRQ shall only | |
5980 | * be accepted if the Originator Nx_Port N_Port_ID or the Responder | |
5981 | * Nx_Port N_Port_ID of the target Exchange is the same as the | |
5982 | * N_Port_ID of the Nx_Port that makes the request. If the RRQ is | |
5983 | * not accepted, an LS_RJT with reason code "Unable to perform | |
5984 | * command request" and reason code explanation "Invalid Originator | |
5985 | * S_ID" shall be returned. For now, we just unconditionally accept | |
5986 | * RRQ from the target. | |
5987 | **/ | |
5988 | static void | |
5989 | lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
5990 | struct lpfc_nodelist *ndlp) | |
5991 | { | |
5992 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | |
19ca7609 JS |
5993 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
5994 | lpfc_els_clear_rrq(vport, cmdiocb, ndlp); | |
5ffc266e JS |
5995 | } |
5996 | ||
12265f68 JS |
5997 | /** |
5998 | * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd | |
5999 | * @phba: pointer to lpfc hba data structure. | |
6000 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
6001 | * | |
6002 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | |
6003 | * mailbox command. This callback function is to actually send the Accept | |
6004 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | |
6005 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | |
6006 | * mailbox command, constructs the RPS response with the link statistics | |
6007 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | |
6008 | * response to the RPS. | |
6009 | * | |
6010 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6011 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6012 | * will be stored into the context1 field of the IOCB for the completion | |
6013 | * callback function to the RPS Accept Response ELS IOCB command. | |
6014 | * | |
6015 | **/ | |
6016 | static void | |
6017 | lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
6018 | { | |
6019 | MAILBOX_t *mb; | |
6020 | IOCB_t *icmd; | |
6021 | struct RLS_RSP *rls_rsp; | |
6022 | uint8_t *pcmd; | |
6023 | struct lpfc_iocbq *elsiocb; | |
6024 | struct lpfc_nodelist *ndlp; | |
7851fe2c JS |
6025 | uint16_t oxid; |
6026 | uint16_t rxid; | |
12265f68 JS |
6027 | uint32_t cmdsize; |
6028 | ||
6029 | mb = &pmb->u.mb; | |
6030 | ||
6031 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
7851fe2c JS |
6032 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
6033 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | |
12265f68 JS |
6034 | pmb->context1 = NULL; |
6035 | pmb->context2 = NULL; | |
6036 | ||
6037 | if (mb->mbxStatus) { | |
6038 | mempool_free(pmb, phba->mbox_mem_pool); | |
6039 | return; | |
6040 | } | |
6041 | ||
6042 | cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); | |
12265f68 JS |
6043 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
6044 | lpfc_max_els_tries, ndlp, | |
6045 | ndlp->nlp_DID, ELS_CMD_ACC); | |
6046 | ||
6047 | /* Decrement the ndlp reference count from previous mbox command */ | |
6048 | lpfc_nlp_put(ndlp); | |
6049 | ||
37db57e3 JS |
6050 | if (!elsiocb) { |
6051 | mempool_free(pmb, phba->mbox_mem_pool); | |
12265f68 | 6052 | return; |
37db57e3 | 6053 | } |
12265f68 JS |
6054 | |
6055 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
6056 | icmd->ulpContext = rxid; |
6057 | icmd->unsli3.rcvsli3.ox_id = oxid; | |
12265f68 JS |
6058 | |
6059 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6060 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
6061 | pcmd += sizeof(uint32_t); /* Skip past command */ | |
6062 | rls_rsp = (struct RLS_RSP *)pcmd; | |
6063 | ||
6064 | rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | |
6065 | rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | |
6066 | rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | |
6067 | rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | |
6068 | rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | |
6069 | rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | |
37db57e3 | 6070 | mempool_free(pmb, phba->mbox_mem_pool); |
12265f68 JS |
6071 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ |
6072 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | |
6073 | "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " | |
6074 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
6075 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6076 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6077 | ndlp->nlp_rpi); | |
6078 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
6079 | phba->fc_stat.elsXmitACC++; | |
6080 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | |
6081 | lpfc_els_free_iocb(phba, elsiocb); | |
6082 | } | |
6083 | ||
e59058c4 | 6084 | /** |
3621a710 | 6085 | * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd |
e59058c4 JS |
6086 | * @phba: pointer to lpfc hba data structure. |
6087 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
6088 | * | |
6089 | * This routine is the completion callback function for the MBX_READ_LNK_STAT | |
6090 | * mailbox command. This callback function is to actually send the Accept | |
6091 | * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It | |
6092 | * collects the link statistics from the completion of the MBX_READ_LNK_STAT | |
6093 | * mailbox command, constructs the RPS response with the link statistics | |
6094 | * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC | |
6095 | * response to the RPS. | |
6096 | * | |
6097 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6098 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6099 | * will be stored into the context1 field of the IOCB for the completion | |
6100 | * callback function to the RPS Accept Response ELS IOCB command. | |
6101 | * | |
6102 | **/ | |
082c0266 | 6103 | static void |
329f9bc7 | 6104 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
7bb3b137 | 6105 | { |
7bb3b137 JW |
6106 | MAILBOX_t *mb; |
6107 | IOCB_t *icmd; | |
6108 | RPS_RSP *rps_rsp; | |
6109 | uint8_t *pcmd; | |
6110 | struct lpfc_iocbq *elsiocb; | |
6111 | struct lpfc_nodelist *ndlp; | |
7851fe2c JS |
6112 | uint16_t status; |
6113 | uint16_t oxid; | |
6114 | uint16_t rxid; | |
7bb3b137 JW |
6115 | uint32_t cmdsize; |
6116 | ||
04c68496 | 6117 | mb = &pmb->u.mb; |
7bb3b137 JW |
6118 | |
6119 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
7851fe2c JS |
6120 | rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff); |
6121 | oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff); | |
041976fb RD |
6122 | pmb->context1 = NULL; |
6123 | pmb->context2 = NULL; | |
7bb3b137 JW |
6124 | |
6125 | if (mb->mbxStatus) { | |
329f9bc7 | 6126 | mempool_free(pmb, phba->mbox_mem_pool); |
7bb3b137 JW |
6127 | return; |
6128 | } | |
6129 | ||
6130 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); | |
329f9bc7 | 6131 | mempool_free(pmb, phba->mbox_mem_pool); |
2e0fef85 JS |
6132 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
6133 | lpfc_max_els_tries, ndlp, | |
6134 | ndlp->nlp_DID, ELS_CMD_ACC); | |
fa4066b6 JS |
6135 | |
6136 | /* Decrement the ndlp reference count from previous mbox command */ | |
329f9bc7 | 6137 | lpfc_nlp_put(ndlp); |
fa4066b6 | 6138 | |
c9f8735b | 6139 | if (!elsiocb) |
7bb3b137 | 6140 | return; |
7bb3b137 JW |
6141 | |
6142 | icmd = &elsiocb->iocb; | |
7851fe2c JS |
6143 | icmd->ulpContext = rxid; |
6144 | icmd->unsli3.rcvsli3.ox_id = oxid; | |
7bb3b137 JW |
6145 | |
6146 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6147 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 6148 | pcmd += sizeof(uint32_t); /* Skip past command */ |
7bb3b137 JW |
6149 | rps_rsp = (RPS_RSP *)pcmd; |
6150 | ||
76a95d75 | 6151 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
7bb3b137 JW |
6152 | status = 0x10; |
6153 | else | |
6154 | status = 0x8; | |
2e0fef85 | 6155 | if (phba->pport->fc_flag & FC_FABRIC) |
7bb3b137 JW |
6156 | status |= 0x4; |
6157 | ||
6158 | rps_rsp->rsvd1 = 0; | |
09372820 JS |
6159 | rps_rsp->portStatus = cpu_to_be16(status); |
6160 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | |
6161 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | |
6162 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | |
6163 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | |
6164 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | |
6165 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | |
7bb3b137 | 6166 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
6167 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
6168 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " | |
6169 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
6170 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6171 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6172 | ndlp->nlp_rpi); | |
858c9f6c | 6173 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 | 6174 | phba->fc_stat.elsXmitACC++; |
3772a991 | 6175 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) |
7bb3b137 | 6176 | lpfc_els_free_iocb(phba, elsiocb); |
7bb3b137 JW |
6177 | return; |
6178 | } | |
6179 | ||
e59058c4 | 6180 | /** |
12265f68 JS |
6181 | * lpfc_els_rcv_rls - Process an unsolicited rls iocb |
6182 | * @vport: pointer to a host virtual N_Port data structure. | |
6183 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6184 | * @ndlp: pointer to a node-list data structure. | |
6185 | * | |
6186 | * This routine processes Read Port Status (RPL) IOCB received as an | |
6187 | * ELS unsolicited event. It first checks the remote port state. If the | |
6188 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6189 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | |
6190 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | |
6191 | * for reading the HBA link statistics. It is for the callback function, | |
6192 | * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command | |
6193 | * to actually sending out RPL Accept (ACC) response. | |
6194 | * | |
6195 | * Return codes | |
6196 | * 0 - Successfully processed rls iocb (currently always return 0) | |
6197 | **/ | |
6198 | static int | |
6199 | lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6200 | struct lpfc_nodelist *ndlp) | |
6201 | { | |
6202 | struct lpfc_hba *phba = vport->phba; | |
6203 | LPFC_MBOXQ_t *mbox; | |
12265f68 JS |
6204 | struct ls_rjt stat; |
6205 | ||
6206 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | |
6207 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | |
6208 | /* reject the unsolicited RPS request and done with it */ | |
6209 | goto reject_out; | |
6210 | ||
12265f68 JS |
6211 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
6212 | if (mbox) { | |
6213 | lpfc_read_lnk_stat(phba, mbox); | |
7851fe2c JS |
6214 | mbox->context1 = (void *)((unsigned long) |
6215 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | |
6216 | cmdiocb->iocb.ulpContext)); /* rx_id */ | |
12265f68 JS |
6217 | mbox->context2 = lpfc_nlp_get(ndlp); |
6218 | mbox->vport = vport; | |
6219 | mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; | |
6220 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) | |
6221 | != MBX_NOT_FINISHED) | |
6222 | /* Mbox completion will send ELS Response */ | |
6223 | return 0; | |
6224 | /* Decrement reference count used for the failed mbox | |
6225 | * command. | |
6226 | */ | |
6227 | lpfc_nlp_put(ndlp); | |
6228 | mempool_free(mbox, phba->mbox_mem_pool); | |
6229 | } | |
6230 | reject_out: | |
6231 | /* issue rejection response */ | |
6232 | stat.un.b.lsRjtRsvd0 = 0; | |
6233 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6234 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6235 | stat.un.b.vendorUnique = 0; | |
6236 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
6237 | return 0; | |
6238 | } | |
6239 | ||
6240 | /** | |
6241 | * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb | |
6242 | * @vport: pointer to a host virtual N_Port data structure. | |
6243 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6244 | * @ndlp: pointer to a node-list data structure. | |
6245 | * | |
6246 | * This routine processes Read Timout Value (RTV) IOCB received as an | |
6247 | * ELS unsolicited event. It first checks the remote port state. If the | |
6248 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6249 | * state, it invokes the lpfc_els_rsl_reject() routine to send the reject | |
6250 | * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout | |
6251 | * Value (RTV) unsolicited IOCB event. | |
6252 | * | |
6253 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6254 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6255 | * will be stored into the context1 field of the IOCB for the completion | |
6256 | * callback function to the RPS Accept Response ELS IOCB command. | |
6257 | * | |
6258 | * Return codes | |
6259 | * 0 - Successfully processed rtv iocb (currently always return 0) | |
6260 | **/ | |
6261 | static int | |
6262 | lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, | |
6263 | struct lpfc_nodelist *ndlp) | |
6264 | { | |
6265 | struct lpfc_hba *phba = vport->phba; | |
6266 | struct ls_rjt stat; | |
6267 | struct RTV_RSP *rtv_rsp; | |
6268 | uint8_t *pcmd; | |
6269 | struct lpfc_iocbq *elsiocb; | |
6270 | uint32_t cmdsize; | |
6271 | ||
6272 | ||
6273 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && | |
6274 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) | |
6275 | /* reject the unsolicited RPS request and done with it */ | |
6276 | goto reject_out; | |
6277 | ||
6278 | cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); | |
6279 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, | |
6280 | lpfc_max_els_tries, ndlp, | |
6281 | ndlp->nlp_DID, ELS_CMD_ACC); | |
6282 | ||
6283 | if (!elsiocb) | |
6284 | return 1; | |
6285 | ||
6286 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6287 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
6288 | pcmd += sizeof(uint32_t); /* Skip past command */ | |
6289 | ||
6290 | /* use the command's xri in the response */ | |
7851fe2c JS |
6291 | elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */ |
6292 | elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id; | |
12265f68 JS |
6293 | |
6294 | rtv_rsp = (struct RTV_RSP *)pcmd; | |
6295 | ||
6296 | /* populate RTV payload */ | |
6297 | rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ | |
6298 | rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); | |
6299 | bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); | |
6300 | bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ | |
6301 | rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); | |
6302 | ||
6303 | /* Xmit ELS RLS ACC response tag <ulpIoTag> */ | |
6304 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, | |
6305 | "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " | |
6306 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, " | |
6307 | "Data: x%x x%x x%x\n", | |
6308 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6309 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6310 | ndlp->nlp_rpi, | |
6311 | rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); | |
6312 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; | |
6313 | phba->fc_stat.elsXmitACC++; | |
6314 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR) | |
6315 | lpfc_els_free_iocb(phba, elsiocb); | |
6316 | return 0; | |
6317 | ||
6318 | reject_out: | |
6319 | /* issue rejection response */ | |
6320 | stat.un.b.lsRjtRsvd0 = 0; | |
6321 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6322 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6323 | stat.un.b.vendorUnique = 0; | |
6324 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
6325 | return 0; | |
6326 | } | |
6327 | ||
6328 | /* lpfc_els_rcv_rps - Process an unsolicited rps iocb | |
e59058c4 JS |
6329 | * @vport: pointer to a host virtual N_Port data structure. |
6330 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6331 | * @ndlp: pointer to a node-list data structure. | |
6332 | * | |
6333 | * This routine processes Read Port Status (RPS) IOCB received as an | |
6334 | * ELS unsolicited event. It first checks the remote port state. If the | |
6335 | * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE | |
6336 | * state, it invokes the lpfc_els_rsp_reject() routine to send the reject | |
6337 | * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command | |
6338 | * for reading the HBA link statistics. It is for the callback function, | |
6339 | * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command | |
6340 | * to actually sending out RPS Accept (ACC) response. | |
6341 | * | |
6342 | * Return codes | |
6343 | * 0 - Successfully processed rps iocb (currently always return 0) | |
6344 | **/ | |
7bb3b137 | 6345 | static int |
2e0fef85 JS |
6346 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6347 | struct lpfc_nodelist *ndlp) | |
dea3101e | 6348 | { |
2e0fef85 | 6349 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 6350 | uint32_t *lp; |
7bb3b137 JW |
6351 | uint8_t flag; |
6352 | LPFC_MBOXQ_t *mbox; | |
6353 | struct lpfc_dmabuf *pcmd; | |
6354 | RPS *rps; | |
6355 | struct ls_rjt stat; | |
6356 | ||
2fe165b6 | 6357 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
90160e01 JS |
6358 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) |
6359 | /* reject the unsolicited RPS request and done with it */ | |
6360 | goto reject_out; | |
7bb3b137 JW |
6361 | |
6362 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
6363 | lp = (uint32_t *) pcmd->virt; | |
6364 | flag = (be32_to_cpu(*lp++) & 0xf); | |
6365 | rps = (RPS *) lp; | |
6366 | ||
6367 | if ((flag == 0) || | |
6368 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || | |
2e0fef85 | 6369 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
92d7f7b0 | 6370 | sizeof(struct lpfc_name)) == 0))) { |
2e0fef85 | 6371 | |
92d7f7b0 JS |
6372 | printk("Fix me....\n"); |
6373 | dump_stack(); | |
2e0fef85 JS |
6374 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
6375 | if (mbox) { | |
7bb3b137 | 6376 | lpfc_read_lnk_stat(phba, mbox); |
7851fe2c JS |
6377 | mbox->context1 = (void *)((unsigned long) |
6378 | ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) | | |
6379 | cmdiocb->iocb.ulpContext)); /* rx_id */ | |
329f9bc7 | 6380 | mbox->context2 = lpfc_nlp_get(ndlp); |
92d7f7b0 | 6381 | mbox->vport = vport; |
7bb3b137 | 6382 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
fa4066b6 | 6383 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
0b727fea | 6384 | != MBX_NOT_FINISHED) |
7bb3b137 JW |
6385 | /* Mbox completion will send ELS Response */ |
6386 | return 0; | |
fa4066b6 JS |
6387 | /* Decrement reference count used for the failed mbox |
6388 | * command. | |
6389 | */ | |
329f9bc7 | 6390 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
6391 | mempool_free(mbox, phba->mbox_mem_pool); |
6392 | } | |
6393 | } | |
90160e01 JS |
6394 | |
6395 | reject_out: | |
6396 | /* issue rejection response */ | |
7bb3b137 JW |
6397 | stat.un.b.lsRjtRsvd0 = 0; |
6398 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6399 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6400 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 6401 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
6402 | return 0; |
6403 | } | |
6404 | ||
19ca7609 JS |
6405 | /* lpfc_issue_els_rrq - Process an unsolicited rps iocb |
6406 | * @vport: pointer to a host virtual N_Port data structure. | |
6407 | * @ndlp: pointer to a node-list data structure. | |
6408 | * @did: DID of the target. | |
6409 | * @rrq: Pointer to the rrq struct. | |
6410 | * | |
6411 | * Build a ELS RRQ command and send it to the target. If the issue_iocb is | |
6412 | * Successful the the completion handler will clear the RRQ. | |
6413 | * | |
6414 | * Return codes | |
6415 | * 0 - Successfully sent rrq els iocb. | |
6416 | * 1 - Failed to send rrq els iocb. | |
6417 | **/ | |
6418 | static int | |
6419 | lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
6420 | uint32_t did, struct lpfc_node_rrq *rrq) | |
6421 | { | |
6422 | struct lpfc_hba *phba = vport->phba; | |
6423 | struct RRQ *els_rrq; | |
19ca7609 JS |
6424 | struct lpfc_iocbq *elsiocb; |
6425 | uint8_t *pcmd; | |
6426 | uint16_t cmdsize; | |
6427 | int ret; | |
6428 | ||
6429 | ||
6430 | if (ndlp != rrq->ndlp) | |
6431 | ndlp = rrq->ndlp; | |
6432 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
6433 | return 1; | |
6434 | ||
6435 | /* If ndlp is not NULL, we will bump the reference count on it */ | |
6436 | cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); | |
6437 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, | |
6438 | ELS_CMD_RRQ); | |
6439 | if (!elsiocb) | |
6440 | return 1; | |
6441 | ||
19ca7609 JS |
6442 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
6443 | ||
6444 | /* For RRQ request, remainder of payload is Exchange IDs */ | |
6445 | *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; | |
6446 | pcmd += sizeof(uint32_t); | |
6447 | els_rrq = (struct RRQ *) pcmd; | |
6448 | ||
ee0f4fe1 | 6449 | bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); |
19ca7609 JS |
6450 | bf_set(rrq_rxid, els_rrq, rrq->rxid); |
6451 | bf_set(rrq_did, els_rrq, vport->fc_myDID); | |
6452 | els_rrq->rrq = cpu_to_be32(els_rrq->rrq); | |
6453 | els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); | |
6454 | ||
6455 | ||
6456 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
6457 | "Issue RRQ: did:x%x", | |
6458 | did, rrq->xritag, rrq->rxid); | |
6459 | elsiocb->context_un.rrq = rrq; | |
6460 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq; | |
6461 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); | |
6462 | ||
6463 | if (ret == IOCB_ERROR) { | |
6464 | lpfc_els_free_iocb(phba, elsiocb); | |
6465 | return 1; | |
6466 | } | |
6467 | return 0; | |
6468 | } | |
6469 | ||
6470 | /** | |
6471 | * lpfc_send_rrq - Sends ELS RRQ if needed. | |
6472 | * @phba: pointer to lpfc hba data structure. | |
6473 | * @rrq: pointer to the active rrq. | |
6474 | * | |
6475 | * This routine will call the lpfc_issue_els_rrq if the rrq is | |
6476 | * still active for the xri. If this function returns a failure then | |
6477 | * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. | |
6478 | * | |
6479 | * Returns 0 Success. | |
6480 | * 1 Failure. | |
6481 | **/ | |
6482 | int | |
6483 | lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) | |
6484 | { | |
6485 | struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, | |
6486 | rrq->nlp_DID); | |
6487 | if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) | |
6488 | return lpfc_issue_els_rrq(rrq->vport, ndlp, | |
6489 | rrq->nlp_DID, rrq); | |
6490 | else | |
6491 | return 1; | |
6492 | } | |
6493 | ||
e59058c4 | 6494 | /** |
3621a710 | 6495 | * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command |
e59058c4 JS |
6496 | * @vport: pointer to a host virtual N_Port data structure. |
6497 | * @cmdsize: size of the ELS command. | |
6498 | * @oldiocb: pointer to the original lpfc command iocb data structure. | |
6499 | * @ndlp: pointer to a node-list data structure. | |
6500 | * | |
6501 | * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. | |
6502 | * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. | |
6503 | * | |
6504 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
6505 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
6506 | * will be stored into the context1 field of the IOCB for the completion | |
6507 | * callback function to the RPL Accept Response ELS command. | |
6508 | * | |
6509 | * Return code | |
6510 | * 0 - Successfully issued ACC RPL ELS command | |
6511 | * 1 - Failed to issue ACC RPL ELS command | |
6512 | **/ | |
082c0266 | 6513 | static int |
2e0fef85 JS |
6514 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
6515 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | |
7bb3b137 | 6516 | { |
2e0fef85 JS |
6517 | struct lpfc_hba *phba = vport->phba; |
6518 | IOCB_t *icmd, *oldcmd; | |
7bb3b137 JW |
6519 | RPL_RSP rpl_rsp; |
6520 | struct lpfc_iocbq *elsiocb; | |
7bb3b137 | 6521 | uint8_t *pcmd; |
dea3101e | 6522 | |
2e0fef85 JS |
6523 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
6524 | ndlp->nlp_DID, ELS_CMD_ACC); | |
7bb3b137 | 6525 | |
488d1469 | 6526 | if (!elsiocb) |
7bb3b137 | 6527 | return 1; |
488d1469 | 6528 | |
7bb3b137 JW |
6529 | icmd = &elsiocb->iocb; |
6530 | oldcmd = &oldiocb->iocb; | |
7851fe2c JS |
6531 | icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ |
6532 | icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; | |
7bb3b137 JW |
6533 | |
6534 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
6535 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 6536 | pcmd += sizeof(uint16_t); |
7bb3b137 JW |
6537 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
6538 | pcmd += sizeof(uint16_t); | |
6539 | ||
6540 | /* Setup the RPL ACC payload */ | |
6541 | rpl_rsp.listLen = be32_to_cpu(1); | |
6542 | rpl_rsp.index = 0; | |
6543 | rpl_rsp.port_num_blk.portNum = 0; | |
2e0fef85 JS |
6544 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
6545 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, | |
7bb3b137 | 6546 | sizeof(struct lpfc_name)); |
7bb3b137 | 6547 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
7bb3b137 | 6548 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
e8b62011 JS |
6549 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
6550 | "0120 Xmit ELS RPL ACC response tag x%x " | |
6551 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
6552 | "rpi x%x\n", | |
6553 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
6554 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
6555 | ndlp->nlp_rpi); | |
858c9f6c | 6556 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 | 6557 | phba->fc_stat.elsXmitACC++; |
3772a991 JS |
6558 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
6559 | IOCB_ERROR) { | |
7bb3b137 JW |
6560 | lpfc_els_free_iocb(phba, elsiocb); |
6561 | return 1; | |
6562 | } | |
6563 | return 0; | |
6564 | } | |
6565 | ||
e59058c4 | 6566 | /** |
3621a710 | 6567 | * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb |
e59058c4 JS |
6568 | * @vport: pointer to a host virtual N_Port data structure. |
6569 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6570 | * @ndlp: pointer to a node-list data structure. | |
6571 | * | |
6572 | * This routine processes Read Port List (RPL) IOCB received as an ELS | |
6573 | * unsolicited event. It first checks the remote port state. If the remote | |
6574 | * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it | |
6575 | * invokes the lpfc_els_rsp_reject() routine to send reject response. | |
6576 | * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine | |
6577 | * to accept the RPL. | |
6578 | * | |
6579 | * Return code | |
6580 | * 0 - Successfully processed rpl iocb (currently always return 0) | |
6581 | **/ | |
7bb3b137 | 6582 | static int |
2e0fef85 JS |
6583 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6584 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
6585 | { |
6586 | struct lpfc_dmabuf *pcmd; | |
6587 | uint32_t *lp; | |
6588 | uint32_t maxsize; | |
6589 | uint16_t cmdsize; | |
6590 | RPL *rpl; | |
6591 | struct ls_rjt stat; | |
6592 | ||
2fe165b6 JW |
6593 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
6594 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | |
90160e01 | 6595 | /* issue rejection response */ |
7bb3b137 JW |
6596 | stat.un.b.lsRjtRsvd0 = 0; |
6597 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
6598 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
6599 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
6600 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
6601 | NULL); | |
90160e01 JS |
6602 | /* rejected the unsolicited RPL request and done with it */ |
6603 | return 0; | |
7bb3b137 JW |
6604 | } |
6605 | ||
dea3101e JB |
6606 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
6607 | lp = (uint32_t *) pcmd->virt; | |
7bb3b137 | 6608 | rpl = (RPL *) (lp + 1); |
7bb3b137 | 6609 | maxsize = be32_to_cpu(rpl->maxsize); |
dea3101e | 6610 | |
7bb3b137 JW |
6611 | /* We support only one port */ |
6612 | if ((rpl->index == 0) && | |
6613 | ((maxsize == 0) || | |
6614 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { | |
6615 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); | |
2fe165b6 | 6616 | } else { |
7bb3b137 JW |
6617 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
6618 | } | |
2e0fef85 | 6619 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
dea3101e JB |
6620 | |
6621 | return 0; | |
6622 | } | |
6623 | ||
e59058c4 | 6624 | /** |
3621a710 | 6625 | * lpfc_els_rcv_farp - Process an unsolicited farp request els command |
e59058c4 JS |
6626 | * @vport: pointer to a virtual N_Port data structure. |
6627 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6628 | * @ndlp: pointer to a node-list data structure. | |
6629 | * | |
6630 | * This routine processes Fibre Channel Address Resolution Protocol | |
6631 | * (FARP) Request IOCB received as an ELS unsolicited event. Currently, | |
6632 | * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, | |
6633 | * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the | |
6634 | * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the | |
6635 | * remote PortName is compared against the FC PortName stored in the @vport | |
6636 | * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is | |
6637 | * compared against the FC NodeName stored in the @vport data structure. | |
6638 | * If any of these matches and the FARP_REQUEST_FARPR flag is set in the | |
6639 | * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is | |
6640 | * invoked to send out FARP Response to the remote node. Before sending the | |
6641 | * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP | |
6642 | * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() | |
6643 | * routine is invoked to log into the remote port first. | |
6644 | * | |
6645 | * Return code | |
6646 | * 0 - Either the FARP Match Mode not supported or successfully processed | |
6647 | **/ | |
dea3101e | 6648 | static int |
2e0fef85 JS |
6649 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6650 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
6651 | { |
6652 | struct lpfc_dmabuf *pcmd; | |
6653 | uint32_t *lp; | |
6654 | IOCB_t *icmd; | |
6655 | FARP *fp; | |
6656 | uint32_t cmd, cnt, did; | |
6657 | ||
6658 | icmd = &cmdiocb->iocb; | |
6659 | did = icmd->un.elsreq64.remoteID; | |
6660 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
6661 | lp = (uint32_t *) pcmd->virt; | |
6662 | ||
6663 | cmd = *lp++; | |
6664 | fp = (FARP *) lp; | |
dea3101e | 6665 | /* FARP-REQ received from DID <did> */ |
e8b62011 JS |
6666 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
6667 | "0601 FARP-REQ received from DID x%x\n", did); | |
dea3101e JB |
6668 | /* We will only support match on WWPN or WWNN */ |
6669 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { | |
c9f8735b | 6670 | return 0; |
dea3101e JB |
6671 | } |
6672 | ||
6673 | cnt = 0; | |
6674 | /* If this FARP command is searching for my portname */ | |
6675 | if (fp->Mflags & FARP_MATCH_PORT) { | |
2e0fef85 | 6676 | if (memcmp(&fp->RportName, &vport->fc_portname, |
92d7f7b0 | 6677 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
6678 | cnt = 1; |
6679 | } | |
6680 | ||
6681 | /* If this FARP command is searching for my nodename */ | |
6682 | if (fp->Mflags & FARP_MATCH_NODE) { | |
2e0fef85 | 6683 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
92d7f7b0 | 6684 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
6685 | cnt = 1; |
6686 | } | |
6687 | ||
6688 | if (cnt) { | |
6689 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | |
6690 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { | |
6691 | /* Log back into the node before sending the FARP. */ | |
6692 | if (fp->Rflags & FARP_REQUEST_PLOGI) { | |
5024ab17 | 6693 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 6694 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 6695 | NLP_STE_PLOGI_ISSUE); |
2e0fef85 | 6696 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
dea3101e JB |
6697 | } |
6698 | ||
6699 | /* Send a FARP response to that node */ | |
2e0fef85 JS |
6700 | if (fp->Rflags & FARP_REQUEST_FARPR) |
6701 | lpfc_issue_els_farpr(vport, did, 0); | |
dea3101e JB |
6702 | } |
6703 | } | |
c9f8735b | 6704 | return 0; |
dea3101e JB |
6705 | } |
6706 | ||
e59058c4 | 6707 | /** |
3621a710 | 6708 | * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb |
e59058c4 JS |
6709 | * @vport: pointer to a host virtual N_Port data structure. |
6710 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6711 | * @ndlp: pointer to a node-list data structure. | |
6712 | * | |
6713 | * This routine processes Fibre Channel Address Resolution Protocol | |
6714 | * Response (FARPR) IOCB received as an ELS unsolicited event. It simply | |
6715 | * invokes the lpfc_els_rsp_acc() routine to the remote node to accept | |
6716 | * the FARP response request. | |
6717 | * | |
6718 | * Return code | |
6719 | * 0 - Successfully processed FARPR IOCB (currently always return 0) | |
6720 | **/ | |
dea3101e | 6721 | static int |
2e0fef85 JS |
6722 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6723 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
6724 | { |
6725 | struct lpfc_dmabuf *pcmd; | |
6726 | uint32_t *lp; | |
6727 | IOCB_t *icmd; | |
6728 | uint32_t cmd, did; | |
6729 | ||
6730 | icmd = &cmdiocb->iocb; | |
6731 | did = icmd->un.elsreq64.remoteID; | |
6732 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
6733 | lp = (uint32_t *) pcmd->virt; | |
6734 | ||
6735 | cmd = *lp++; | |
6736 | /* FARP-RSP received from DID <did> */ | |
e8b62011 JS |
6737 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
6738 | "0600 FARP-RSP received from DID x%x\n", did); | |
dea3101e | 6739 | /* ACCEPT the Farp resp request */ |
51ef4c26 | 6740 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e JB |
6741 | |
6742 | return 0; | |
6743 | } | |
6744 | ||
e59058c4 | 6745 | /** |
3621a710 | 6746 | * lpfc_els_rcv_fan - Process an unsolicited fan iocb command |
e59058c4 JS |
6747 | * @vport: pointer to a host virtual N_Port data structure. |
6748 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
6749 | * @fan_ndlp: pointer to a node-list data structure. | |
6750 | * | |
6751 | * This routine processes a Fabric Address Notification (FAN) IOCB | |
6752 | * command received as an ELS unsolicited event. The FAN ELS command will | |
6753 | * only be processed on a physical port (i.e., the @vport represents the | |
6754 | * physical port). The fabric NodeName and PortName from the FAN IOCB are | |
6755 | * compared against those in the phba data structure. If any of those is | |
6756 | * different, the lpfc_initial_flogi() routine is invoked to initialize | |
6757 | * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, | |
6758 | * if both of those are identical, the lpfc_issue_fabric_reglogin() routine | |
6759 | * is invoked to register login to the fabric. | |
6760 | * | |
6761 | * Return code | |
6762 | * 0 - Successfully processed fan iocb (currently always return 0). | |
6763 | **/ | |
dea3101e | 6764 | static int |
2e0fef85 JS |
6765 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
6766 | struct lpfc_nodelist *fan_ndlp) | |
dea3101e | 6767 | { |
0d2b6b83 | 6768 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 6769 | uint32_t *lp; |
5024ab17 | 6770 | FAN *fp; |
dea3101e | 6771 | |
0d2b6b83 JS |
6772 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
6773 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; | |
6774 | fp = (FAN *) ++lp; | |
5024ab17 | 6775 | /* FAN received; Fan does not have a reply sequence */ |
0d2b6b83 JS |
6776 | if ((vport == phba->pport) && |
6777 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { | |
5024ab17 | 6778 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
0d2b6b83 | 6779 | sizeof(struct lpfc_name))) || |
5024ab17 | 6780 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
0d2b6b83 JS |
6781 | sizeof(struct lpfc_name)))) { |
6782 | /* This port has switched fabrics. FLOGI is required */ | |
76a95d75 | 6783 | lpfc_issue_init_vfi(vport); |
0d2b6b83 JS |
6784 | } else { |
6785 | /* FAN verified - skip FLOGI */ | |
6786 | vport->fc_myDID = vport->fc_prevDID; | |
6fb120a7 JS |
6787 | if (phba->sli_rev < LPFC_SLI_REV4) |
6788 | lpfc_issue_fabric_reglogin(vport); | |
1b51197d JS |
6789 | else { |
6790 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
6791 | "3138 Need register VFI: (x%x/%x)\n", | |
6792 | vport->fc_prevDID, vport->fc_myDID); | |
6fb120a7 | 6793 | lpfc_issue_reg_vfi(vport); |
1b51197d | 6794 | } |
5024ab17 | 6795 | } |
dea3101e | 6796 | } |
c9f8735b | 6797 | return 0; |
dea3101e JB |
6798 | } |
6799 | ||
e59058c4 | 6800 | /** |
3621a710 | 6801 | * lpfc_els_timeout - Handler funciton to the els timer |
e59058c4 JS |
6802 | * @ptr: holder for the timer function associated data. |
6803 | * | |
6804 | * This routine is invoked by the ELS timer after timeout. It posts the ELS | |
6805 | * timer timeout event by setting the WORKER_ELS_TMO bit to the work port | |
6806 | * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake | |
6807 | * up the worker thread. It is for the worker thread to invoke the routine | |
6808 | * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. | |
6809 | **/ | |
dea3101e JB |
6810 | void |
6811 | lpfc_els_timeout(unsigned long ptr) | |
6812 | { | |
2e0fef85 JS |
6813 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
6814 | struct lpfc_hba *phba = vport->phba; | |
5e9d9b82 | 6815 | uint32_t tmo_posted; |
dea3101e JB |
6816 | unsigned long iflag; |
6817 | ||
2e0fef85 | 6818 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
5e9d9b82 | 6819 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
06918ac5 | 6820 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
2e0fef85 | 6821 | vport->work_port_events |= WORKER_ELS_TMO; |
5e9d9b82 | 6822 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
92d7f7b0 | 6823 | |
06918ac5 | 6824 | if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING))) |
5e9d9b82 | 6825 | lpfc_worker_wake_up(phba); |
dea3101e JB |
6826 | return; |
6827 | } | |
6828 | ||
2a9bf3d0 | 6829 | |
e59058c4 | 6830 | /** |
3621a710 | 6831 | * lpfc_els_timeout_handler - Process an els timeout event |
e59058c4 JS |
6832 | * @vport: pointer to a virtual N_Port data structure. |
6833 | * | |
6834 | * This routine is the actual handler function that processes an ELS timeout | |
6835 | * event. It walks the ELS ring to get and abort all the IOCBs (except the | |
6836 | * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by | |
6837 | * invoking the lpfc_sli_issue_abort_iotag() routine. | |
6838 | **/ | |
dea3101e | 6839 | void |
2e0fef85 | 6840 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
dea3101e | 6841 | { |
2e0fef85 | 6842 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
6843 | struct lpfc_sli_ring *pring; |
6844 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
6845 | IOCB_t *cmd = NULL; | |
6846 | struct lpfc_dmabuf *pcmd; | |
2e0fef85 | 6847 | uint32_t els_command = 0; |
dea3101e | 6848 | uint32_t timeout; |
2e0fef85 | 6849 | uint32_t remote_ID = 0xffffffff; |
2a9bf3d0 JS |
6850 | LIST_HEAD(abort_list); |
6851 | ||
dea3101e | 6852 | |
dea3101e JB |
6853 | timeout = (uint32_t)(phba->fc_ratov << 1); |
6854 | ||
6855 | pring = &phba->sli.ring[LPFC_ELS_RING]; | |
06918ac5 JS |
6856 | if ((phba->pport->load_flag & FC_UNLOADING)) |
6857 | return; | |
2a9bf3d0 | 6858 | spin_lock_irq(&phba->hbalock); |
0976e1a6 JS |
6859 | if (phba->sli_rev == LPFC_SLI_REV4) |
6860 | spin_lock(&pring->ring_lock); | |
2a9bf3d0 | 6861 | |
06918ac5 JS |
6862 | if ((phba->pport->load_flag & FC_UNLOADING)) { |
6863 | if (phba->sli_rev == LPFC_SLI_REV4) | |
6864 | spin_unlock(&pring->ring_lock); | |
6865 | spin_unlock_irq(&phba->hbalock); | |
6866 | return; | |
6867 | } | |
6868 | ||
0976e1a6 | 6869 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
dea3101e JB |
6870 | cmd = &piocb->iocb; |
6871 | ||
2e0fef85 JS |
6872 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
6873 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6874 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | |
dea3101e | 6875 | continue; |
2e0fef85 JS |
6876 | |
6877 | if (piocb->vport != vport) | |
6878 | continue; | |
6879 | ||
dea3101e | 6880 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
2e0fef85 JS |
6881 | if (pcmd) |
6882 | els_command = *(uint32_t *) (pcmd->virt); | |
dea3101e | 6883 | |
92d7f7b0 JS |
6884 | if (els_command == ELS_CMD_FARP || |
6885 | els_command == ELS_CMD_FARPR || | |
6886 | els_command == ELS_CMD_FDISC) | |
6887 | continue; | |
6888 | ||
dea3101e | 6889 | if (piocb->drvrTimeout > 0) { |
92d7f7b0 | 6890 | if (piocb->drvrTimeout >= timeout) |
dea3101e | 6891 | piocb->drvrTimeout -= timeout; |
92d7f7b0 | 6892 | else |
dea3101e | 6893 | piocb->drvrTimeout = 0; |
dea3101e JB |
6894 | continue; |
6895 | } | |
6896 | ||
2e0fef85 JS |
6897 | remote_ID = 0xffffffff; |
6898 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) | |
dea3101e | 6899 | remote_ID = cmd->un.elsreq64.remoteID; |
2e0fef85 JS |
6900 | else { |
6901 | struct lpfc_nodelist *ndlp; | |
6902 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); | |
58da1ffb | 6903 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
2e0fef85 | 6904 | remote_ID = ndlp->nlp_DID; |
dea3101e | 6905 | } |
2a9bf3d0 JS |
6906 | list_add_tail(&piocb->dlist, &abort_list); |
6907 | } | |
0976e1a6 JS |
6908 | if (phba->sli_rev == LPFC_SLI_REV4) |
6909 | spin_unlock(&pring->ring_lock); | |
2a9bf3d0 JS |
6910 | spin_unlock_irq(&phba->hbalock); |
6911 | ||
6912 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { | |
15026c9e | 6913 | cmd = &piocb->iocb; |
e8b62011 | 6914 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2a9bf3d0 JS |
6915 | "0127 ELS timeout Data: x%x x%x x%x " |
6916 | "x%x\n", els_command, | |
6917 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); | |
6918 | spin_lock_irq(&phba->hbalock); | |
6919 | list_del_init(&piocb->dlist); | |
07951076 | 6920 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
2a9bf3d0 | 6921 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 6922 | } |
5a0e326d | 6923 | |
0e9bb8d7 | 6924 | if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq)) |
06918ac5 JS |
6925 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
6926 | mod_timer(&vport->els_tmofunc, | |
6927 | jiffies + msecs_to_jiffies(1000 * timeout)); | |
dea3101e JB |
6928 | } |
6929 | ||
e59058c4 | 6930 | /** |
3621a710 | 6931 | * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport |
e59058c4 JS |
6932 | * @vport: pointer to a host virtual N_Port data structure. |
6933 | * | |
6934 | * This routine is used to clean up all the outstanding ELS commands on a | |
6935 | * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() | |
6936 | * routine. After that, it walks the ELS transmit queue to remove all the | |
6937 | * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For | |
6938 | * the IOCBs with a non-NULL completion callback function, the callback | |
6939 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | |
6940 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion | |
6941 | * callback function, the IOCB will simply be released. Finally, it walks | |
6942 | * the ELS transmit completion queue to issue an abort IOCB to any transmit | |
6943 | * completion queue IOCB that is associated with the @vport and is not | |
6944 | * an IOCB from libdfc (i.e., the management plane IOCBs that are not | |
6945 | * part of the discovery state machine) out to HBA by invoking the | |
6946 | * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the | |
6947 | * abort IOCB to any transmit completion queueed IOCB, it does not guarantee | |
6948 | * the IOCBs are aborted when this function returns. | |
6949 | **/ | |
dea3101e | 6950 | void |
2e0fef85 | 6951 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
dea3101e | 6952 | { |
0976e1a6 | 6953 | LIST_HEAD(abort_list); |
2e0fef85 | 6954 | struct lpfc_hba *phba = vport->phba; |
329f9bc7 | 6955 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e JB |
6956 | struct lpfc_iocbq *tmp_iocb, *piocb; |
6957 | IOCB_t *cmd = NULL; | |
92d7f7b0 JS |
6958 | |
6959 | lpfc_fabric_abort_vport(vport); | |
0976e1a6 JS |
6960 | /* |
6961 | * For SLI3, only the hbalock is required. But SLI4 needs to coordinate | |
6962 | * with the ring insert operation. Because lpfc_sli_issue_abort_iotag | |
6963 | * ultimately grabs the ring_lock, the driver must splice the list into | |
6964 | * a working list and release the locks before calling the abort. | |
6965 | */ | |
6966 | spin_lock_irq(&phba->hbalock); | |
6967 | if (phba->sli_rev == LPFC_SLI_REV4) | |
6968 | spin_lock(&pring->ring_lock); | |
6969 | ||
6970 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | |
6971 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | |
6972 | continue; | |
6973 | ||
6974 | if (piocb->vport != vport) | |
6975 | continue; | |
6976 | list_add_tail(&piocb->dlist, &abort_list); | |
6977 | } | |
6978 | if (phba->sli_rev == LPFC_SLI_REV4) | |
6979 | spin_unlock(&pring->ring_lock); | |
6980 | spin_unlock_irq(&phba->hbalock); | |
6981 | /* Abort each iocb on the aborted list and remove the dlist links. */ | |
6982 | list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { | |
6983 | spin_lock_irq(&phba->hbalock); | |
6984 | list_del_init(&piocb->dlist); | |
6985 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | |
6986 | spin_unlock_irq(&phba->hbalock); | |
6987 | } | |
6988 | if (!list_empty(&abort_list)) | |
6989 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
6990 | "3387 abort list for txq not empty\n"); | |
6991 | INIT_LIST_HEAD(&abort_list); | |
dea3101e | 6992 | |
2e0fef85 | 6993 | spin_lock_irq(&phba->hbalock); |
0976e1a6 JS |
6994 | if (phba->sli_rev == LPFC_SLI_REV4) |
6995 | spin_lock(&pring->ring_lock); | |
6996 | ||
dea3101e JB |
6997 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
6998 | cmd = &piocb->iocb; | |
6999 | ||
7000 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | |
7001 | continue; | |
7002 | } | |
7003 | ||
7004 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | |
329f9bc7 JS |
7005 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
7006 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | |
7007 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
7008 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | |
dea3101e | 7009 | continue; |
dea3101e | 7010 | |
2e0fef85 JS |
7011 | if (piocb->vport != vport) |
7012 | continue; | |
7013 | ||
0976e1a6 JS |
7014 | list_del_init(&piocb->list); |
7015 | list_add_tail(&piocb->list, &abort_list); | |
dea3101e | 7016 | } |
0976e1a6 JS |
7017 | if (phba->sli_rev == LPFC_SLI_REV4) |
7018 | spin_unlock(&pring->ring_lock); | |
2e0fef85 | 7019 | spin_unlock_irq(&phba->hbalock); |
2534ba75 | 7020 | |
a257bf90 | 7021 | /* Cancell all the IOCBs from the completions list */ |
0976e1a6 JS |
7022 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
7023 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); | |
2534ba75 | 7024 | |
dea3101e JB |
7025 | return; |
7026 | } | |
7027 | ||
e59058c4 | 7028 | /** |
3621a710 | 7029 | * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA |
e59058c4 JS |
7030 | * @phba: pointer to lpfc hba data structure. |
7031 | * | |
7032 | * This routine is used to clean up all the outstanding ELS commands on a | |
7033 | * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() | |
7034 | * routine. After that, it walks the ELS transmit queue to remove all the | |
7035 | * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For | |
7036 | * the IOCBs with the completion callback function associated, the callback | |
7037 | * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and | |
7038 | * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion | |
7039 | * callback function associated, the IOCB will simply be released. Finally, | |
7040 | * it walks the ELS transmit completion queue to issue an abort IOCB to any | |
7041 | * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the | |
7042 | * management plane IOCBs that are not part of the discovery state machine) | |
7043 | * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. | |
7044 | **/ | |
549e55cd JS |
7045 | void |
7046 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) | |
7047 | { | |
0976e1a6 JS |
7048 | struct lpfc_vport *vport; |
7049 | list_for_each_entry(vport, &phba->port_list, listentry) | |
7050 | lpfc_els_flush_cmd(vport); | |
a257bf90 | 7051 | |
549e55cd JS |
7052 | return; |
7053 | } | |
7054 | ||
ea2151b4 | 7055 | /** |
3621a710 | 7056 | * lpfc_send_els_failure_event - Posts an ELS command failure event |
ea2151b4 JS |
7057 | * @phba: Pointer to hba context object. |
7058 | * @cmdiocbp: Pointer to command iocb which reported error. | |
7059 | * @rspiocbp: Pointer to response iocb which reported error. | |
7060 | * | |
7061 | * This function sends an event when there is an ELS command | |
7062 | * failure. | |
7063 | **/ | |
7064 | void | |
7065 | lpfc_send_els_failure_event(struct lpfc_hba *phba, | |
7066 | struct lpfc_iocbq *cmdiocbp, | |
7067 | struct lpfc_iocbq *rspiocbp) | |
7068 | { | |
7069 | struct lpfc_vport *vport = cmdiocbp->vport; | |
7070 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7071 | struct lpfc_lsrjt_event lsrjt_event; | |
7072 | struct lpfc_fabric_event_header fabric_event; | |
7073 | struct ls_rjt stat; | |
7074 | struct lpfc_nodelist *ndlp; | |
7075 | uint32_t *pcmd; | |
7076 | ||
7077 | ndlp = cmdiocbp->context1; | |
7078 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
7079 | return; | |
7080 | ||
7081 | if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) { | |
7082 | lsrjt_event.header.event_type = FC_REG_ELS_EVENT; | |
7083 | lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; | |
7084 | memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, | |
7085 | sizeof(struct lpfc_name)); | |
7086 | memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, | |
7087 | sizeof(struct lpfc_name)); | |
7088 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) | |
7089 | cmdiocbp->context2)->virt); | |
49198b37 | 7090 | lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; |
ea2151b4 JS |
7091 | stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]); |
7092 | lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; | |
7093 | lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; | |
7094 | fc_host_post_vendor_event(shost, | |
7095 | fc_get_event_number(), | |
7096 | sizeof(lsrjt_event), | |
7097 | (char *)&lsrjt_event, | |
ddcc50f0 | 7098 | LPFC_NL_VENDOR_ID); |
ea2151b4 JS |
7099 | return; |
7100 | } | |
7101 | if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) || | |
7102 | (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) { | |
7103 | fabric_event.event_type = FC_REG_FABRIC_EVENT; | |
7104 | if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) | |
7105 | fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; | |
7106 | else | |
7107 | fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; | |
7108 | memcpy(fabric_event.wwpn, &ndlp->nlp_portname, | |
7109 | sizeof(struct lpfc_name)); | |
7110 | memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, | |
7111 | sizeof(struct lpfc_name)); | |
7112 | fc_host_post_vendor_event(shost, | |
7113 | fc_get_event_number(), | |
7114 | sizeof(fabric_event), | |
7115 | (char *)&fabric_event, | |
ddcc50f0 | 7116 | LPFC_NL_VENDOR_ID); |
ea2151b4 JS |
7117 | return; |
7118 | } | |
7119 | ||
7120 | } | |
7121 | ||
7122 | /** | |
3621a710 | 7123 | * lpfc_send_els_event - Posts unsolicited els event |
ea2151b4 JS |
7124 | * @vport: Pointer to vport object. |
7125 | * @ndlp: Pointer FC node object. | |
7126 | * @cmd: ELS command code. | |
7127 | * | |
7128 | * This function posts an event when there is an incoming | |
7129 | * unsolicited ELS command. | |
7130 | **/ | |
7131 | static void | |
7132 | lpfc_send_els_event(struct lpfc_vport *vport, | |
7133 | struct lpfc_nodelist *ndlp, | |
ddcc50f0 | 7134 | uint32_t *payload) |
ea2151b4 | 7135 | { |
ddcc50f0 JS |
7136 | struct lpfc_els_event_header *els_data = NULL; |
7137 | struct lpfc_logo_event *logo_data = NULL; | |
ea2151b4 JS |
7138 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
7139 | ||
ddcc50f0 JS |
7140 | if (*payload == ELS_CMD_LOGO) { |
7141 | logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); | |
7142 | if (!logo_data) { | |
7143 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7144 | "0148 Failed to allocate memory " | |
7145 | "for LOGO event\n"); | |
7146 | return; | |
7147 | } | |
7148 | els_data = &logo_data->header; | |
7149 | } else { | |
7150 | els_data = kmalloc(sizeof(struct lpfc_els_event_header), | |
7151 | GFP_KERNEL); | |
7152 | if (!els_data) { | |
7153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7154 | "0149 Failed to allocate memory " | |
7155 | "for ELS event\n"); | |
7156 | return; | |
7157 | } | |
7158 | } | |
7159 | els_data->event_type = FC_REG_ELS_EVENT; | |
7160 | switch (*payload) { | |
ea2151b4 | 7161 | case ELS_CMD_PLOGI: |
ddcc50f0 | 7162 | els_data->subcategory = LPFC_EVENT_PLOGI_RCV; |
ea2151b4 JS |
7163 | break; |
7164 | case ELS_CMD_PRLO: | |
ddcc50f0 | 7165 | els_data->subcategory = LPFC_EVENT_PRLO_RCV; |
ea2151b4 JS |
7166 | break; |
7167 | case ELS_CMD_ADISC: | |
ddcc50f0 JS |
7168 | els_data->subcategory = LPFC_EVENT_ADISC_RCV; |
7169 | break; | |
7170 | case ELS_CMD_LOGO: | |
7171 | els_data->subcategory = LPFC_EVENT_LOGO_RCV; | |
7172 | /* Copy the WWPN in the LOGO payload */ | |
7173 | memcpy(logo_data->logo_wwpn, &payload[2], | |
7174 | sizeof(struct lpfc_name)); | |
ea2151b4 JS |
7175 | break; |
7176 | default: | |
e916141c | 7177 | kfree(els_data); |
ea2151b4 JS |
7178 | return; |
7179 | } | |
ddcc50f0 JS |
7180 | memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); |
7181 | memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | |
7182 | if (*payload == ELS_CMD_LOGO) { | |
7183 | fc_host_post_vendor_event(shost, | |
7184 | fc_get_event_number(), | |
7185 | sizeof(struct lpfc_logo_event), | |
7186 | (char *)logo_data, | |
7187 | LPFC_NL_VENDOR_ID); | |
7188 | kfree(logo_data); | |
7189 | } else { | |
7190 | fc_host_post_vendor_event(shost, | |
7191 | fc_get_event_number(), | |
7192 | sizeof(struct lpfc_els_event_header), | |
7193 | (char *)els_data, | |
7194 | LPFC_NL_VENDOR_ID); | |
7195 | kfree(els_data); | |
7196 | } | |
ea2151b4 JS |
7197 | |
7198 | return; | |
7199 | } | |
7200 | ||
7201 | ||
e59058c4 | 7202 | /** |
3621a710 | 7203 | * lpfc_els_unsol_buffer - Process an unsolicited event data buffer |
e59058c4 JS |
7204 | * @phba: pointer to lpfc hba data structure. |
7205 | * @pring: pointer to a SLI ring. | |
7206 | * @vport: pointer to a host virtual N_Port data structure. | |
7207 | * @elsiocb: pointer to lpfc els command iocb data structure. | |
7208 | * | |
7209 | * This routine is used for processing the IOCB associated with a unsolicited | |
7210 | * event. It first determines whether there is an existing ndlp that matches | |
7211 | * the DID from the unsolicited IOCB. If not, it will create a new one with | |
7212 | * the DID from the unsolicited IOCB. The ELS command from the unsolicited | |
7213 | * IOCB is then used to invoke the proper routine and to set up proper state | |
7214 | * of the discovery state machine. | |
7215 | **/ | |
ed957684 JS |
7216 | static void |
7217 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
92d7f7b0 | 7218 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
dea3101e | 7219 | { |
87af33fe | 7220 | struct Scsi_Host *shost; |
dea3101e | 7221 | struct lpfc_nodelist *ndlp; |
dea3101e | 7222 | struct ls_rjt stat; |
92d7f7b0 | 7223 | uint32_t *payload; |
303f2f9c JS |
7224 | uint32_t cmd, did, newnode; |
7225 | uint8_t rjt_exp, rjt_err = 0; | |
ed957684 | 7226 | IOCB_t *icmd = &elsiocb->iocb; |
dea3101e | 7227 | |
e47c9093 | 7228 | if (!vport || !(elsiocb->context2)) |
dea3101e | 7229 | goto dropit; |
2e0fef85 | 7230 | |
dea3101e | 7231 | newnode = 0; |
92d7f7b0 JS |
7232 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
7233 | cmd = *payload; | |
ed957684 | 7234 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
495a714c | 7235 | lpfc_post_buffer(phba, pring, 1); |
dea3101e | 7236 | |
858c9f6c JS |
7237 | did = icmd->un.rcvels.remoteID; |
7238 | if (icmd->ulpStatus) { | |
7239 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7240 | "RCV Unsol ELS: status:x%x/x%x did:x%x", | |
7241 | icmd->ulpStatus, icmd->un.ulpWord[4], did); | |
dea3101e | 7242 | goto dropit; |
858c9f6c | 7243 | } |
dea3101e JB |
7244 | |
7245 | /* Check to see if link went down during discovery */ | |
ed957684 | 7246 | if (lpfc_els_chk_latt(vport)) |
dea3101e | 7247 | goto dropit; |
dea3101e | 7248 | |
c868595d | 7249 | /* Ignore traffic received during vport shutdown. */ |
92d7f7b0 JS |
7250 | if (vport->load_flag & FC_UNLOADING) |
7251 | goto dropit; | |
7252 | ||
92494144 JS |
7253 | /* If NPort discovery is delayed drop incoming ELS */ |
7254 | if ((vport->fc_flag & FC_DISC_DELAYED) && | |
7255 | (cmd != ELS_CMD_PLOGI)) | |
7256 | goto dropit; | |
7257 | ||
2e0fef85 | 7258 | ndlp = lpfc_findnode_did(vport, did); |
c9f8735b | 7259 | if (!ndlp) { |
dea3101e | 7260 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b | 7261 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
ed957684 | 7262 | if (!ndlp) |
dea3101e | 7263 | goto dropit; |
dea3101e | 7264 | |
2e0fef85 | 7265 | lpfc_nlp_init(vport, ndlp, did); |
98c9ea5c | 7266 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
dea3101e | 7267 | newnode = 1; |
e47c9093 | 7268 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
dea3101e | 7269 | ndlp->nlp_type |= NLP_FABRIC; |
58da1ffb JS |
7270 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
7271 | ndlp = lpfc_enable_node(vport, ndlp, | |
7272 | NLP_STE_UNUSED_NODE); | |
7273 | if (!ndlp) | |
7274 | goto dropit; | |
7275 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
7276 | newnode = 1; | |
7277 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
7278 | ndlp->nlp_type |= NLP_FABRIC; | |
7279 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
7280 | /* This is similar to the new node path */ | |
7281 | ndlp = lpfc_nlp_get(ndlp); | |
7282 | if (!ndlp) | |
7283 | goto dropit; | |
7284 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
7285 | newnode = 1; | |
87af33fe | 7286 | } |
dea3101e JB |
7287 | |
7288 | phba->fc_stat.elsRcvFrame++; | |
e47c9093 | 7289 | |
12838e74 JS |
7290 | /* |
7291 | * Do not process any unsolicited ELS commands | |
7292 | * if the ndlp is in DEV_LOSS | |
7293 | */ | |
466e840b JS |
7294 | shost = lpfc_shost_from_vport(vport); |
7295 | spin_lock_irq(shost->host_lock); | |
7296 | if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) { | |
7297 | spin_unlock_irq(shost->host_lock); | |
12838e74 | 7298 | goto dropit; |
466e840b JS |
7299 | } |
7300 | spin_unlock_irq(shost->host_lock); | |
12838e74 | 7301 | |
329f9bc7 | 7302 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
2e0fef85 | 7303 | elsiocb->vport = vport; |
dea3101e JB |
7304 | |
7305 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { | |
7306 | cmd &= ELS_CMD_MASK; | |
7307 | } | |
7308 | /* ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
7309 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
7310 | "0112 ELS command x%x received from NPORT x%x " | |
e74c03c8 JS |
7311 | "Data: x%x x%x x%x x%x\n", |
7312 | cmd, did, vport->port_state, vport->fc_flag, | |
7313 | vport->fc_myDID, vport->fc_prevDID); | |
eec3d312 JS |
7314 | |
7315 | /* reject till our FLOGI completes */ | |
7316 | if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && | |
d6de08cc | 7317 | (cmd != ELS_CMD_FLOGI)) { |
eec3d312 JS |
7318 | rjt_err = LSRJT_UNABLE_TPC; |
7319 | rjt_exp = LSEXP_NOTHING_MORE; | |
7320 | goto lsrjt; | |
7321 | } | |
7322 | ||
dea3101e JB |
7323 | switch (cmd) { |
7324 | case ELS_CMD_PLOGI: | |
858c9f6c JS |
7325 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7326 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", | |
7327 | did, vport->port_state, ndlp->nlp_flag); | |
7328 | ||
dea3101e | 7329 | phba->fc_stat.elsRcvPLOGI++; |
858c9f6c | 7330 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
e74c03c8 JS |
7331 | if (phba->sli_rev == LPFC_SLI_REV4 && |
7332 | (phba->pport->fc_flag & FC_PT2PT)) { | |
7333 | vport->fc_prevDID = vport->fc_myDID; | |
7334 | /* Our DID needs to be updated before registering | |
7335 | * the vfi. This is done in lpfc_rcv_plogi but | |
7336 | * that is called after the reg_vfi. | |
7337 | */ | |
7338 | vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo; | |
7339 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
7340 | "3312 Remote port assigned DID x%x " | |
7341 | "%x\n", vport->fc_myDID, | |
7342 | vport->fc_prevDID); | |
7343 | } | |
858c9f6c | 7344 | |
ddcc50f0 | 7345 | lpfc_send_els_event(vport, ndlp, payload); |
92494144 JS |
7346 | |
7347 | /* If Nport discovery is delayed, reject PLOGIs */ | |
7348 | if (vport->fc_flag & FC_DISC_DELAYED) { | |
7349 | rjt_err = LSRJT_UNABLE_TPC; | |
303f2f9c | 7350 | rjt_exp = LSEXP_NOTHING_MORE; |
92494144 JS |
7351 | break; |
7352 | } | |
d6de08cc | 7353 | |
858c9f6c | 7354 | if (vport->port_state < LPFC_DISC_AUTH) { |
1b32f6aa JS |
7355 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
7356 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { | |
7357 | rjt_err = LSRJT_UNABLE_TPC; | |
303f2f9c | 7358 | rjt_exp = LSEXP_NOTHING_MORE; |
1b32f6aa JS |
7359 | break; |
7360 | } | |
dea3101e | 7361 | } |
87af33fe | 7362 | |
87af33fe JS |
7363 | spin_lock_irq(shost->host_lock); |
7364 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; | |
7365 | spin_unlock_irq(shost->host_lock); | |
7366 | ||
2e0fef85 JS |
7367 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7368 | NLP_EVT_RCV_PLOGI); | |
858c9f6c | 7369 | |
dea3101e JB |
7370 | break; |
7371 | case ELS_CMD_FLOGI: | |
858c9f6c JS |
7372 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7373 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", | |
7374 | did, vport->port_state, ndlp->nlp_flag); | |
7375 | ||
dea3101e | 7376 | phba->fc_stat.elsRcvFLOGI++; |
51ef4c26 | 7377 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
87af33fe | 7378 | if (newnode) |
98c9ea5c | 7379 | lpfc_nlp_put(ndlp); |
dea3101e JB |
7380 | break; |
7381 | case ELS_CMD_LOGO: | |
858c9f6c JS |
7382 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7383 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", | |
7384 | did, vport->port_state, ndlp->nlp_flag); | |
7385 | ||
dea3101e | 7386 | phba->fc_stat.elsRcvLOGO++; |
ddcc50f0 | 7387 | lpfc_send_els_event(vport, ndlp, payload); |
2e0fef85 | 7388 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7389 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7390 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7391 | break; |
7392 | } | |
2e0fef85 | 7393 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
dea3101e JB |
7394 | break; |
7395 | case ELS_CMD_PRLO: | |
858c9f6c JS |
7396 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7397 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", | |
7398 | did, vport->port_state, ndlp->nlp_flag); | |
7399 | ||
dea3101e | 7400 | phba->fc_stat.elsRcvPRLO++; |
ddcc50f0 | 7401 | lpfc_send_els_event(vport, ndlp, payload); |
2e0fef85 | 7402 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7403 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7404 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7405 | break; |
7406 | } | |
2e0fef85 | 7407 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
dea3101e | 7408 | break; |
8b017a30 JS |
7409 | case ELS_CMD_LCB: |
7410 | phba->fc_stat.elsRcvLCB++; | |
7411 | lpfc_els_rcv_lcb(vport, elsiocb, ndlp); | |
7412 | break; | |
86478875 JS |
7413 | case ELS_CMD_RDP: |
7414 | phba->fc_stat.elsRcvRDP++; | |
7415 | lpfc_els_rcv_rdp(vport, elsiocb, ndlp); | |
7416 | break; | |
dea3101e JB |
7417 | case ELS_CMD_RSCN: |
7418 | phba->fc_stat.elsRcvRSCN++; | |
51ef4c26 | 7419 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
87af33fe | 7420 | if (newnode) |
98c9ea5c | 7421 | lpfc_nlp_put(ndlp); |
dea3101e JB |
7422 | break; |
7423 | case ELS_CMD_ADISC: | |
858c9f6c JS |
7424 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7425 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", | |
7426 | did, vport->port_state, ndlp->nlp_flag); | |
7427 | ||
ddcc50f0 | 7428 | lpfc_send_els_event(vport, ndlp, payload); |
dea3101e | 7429 | phba->fc_stat.elsRcvADISC++; |
2e0fef85 | 7430 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7431 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7432 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7433 | break; |
7434 | } | |
2e0fef85 JS |
7435 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7436 | NLP_EVT_RCV_ADISC); | |
dea3101e JB |
7437 | break; |
7438 | case ELS_CMD_PDISC: | |
858c9f6c JS |
7439 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7440 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", | |
7441 | did, vport->port_state, ndlp->nlp_flag); | |
7442 | ||
dea3101e | 7443 | phba->fc_stat.elsRcvPDISC++; |
2e0fef85 | 7444 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7445 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7446 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7447 | break; |
7448 | } | |
2e0fef85 JS |
7449 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
7450 | NLP_EVT_RCV_PDISC); | |
dea3101e JB |
7451 | break; |
7452 | case ELS_CMD_FARPR: | |
858c9f6c JS |
7453 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7454 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", | |
7455 | did, vport->port_state, ndlp->nlp_flag); | |
7456 | ||
dea3101e | 7457 | phba->fc_stat.elsRcvFARPR++; |
2e0fef85 | 7458 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
dea3101e JB |
7459 | break; |
7460 | case ELS_CMD_FARP: | |
858c9f6c JS |
7461 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7462 | "RCV FARP: did:x%x/ste:x%x flg:x%x", | |
7463 | did, vport->port_state, ndlp->nlp_flag); | |
7464 | ||
dea3101e | 7465 | phba->fc_stat.elsRcvFARP++; |
2e0fef85 | 7466 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
dea3101e JB |
7467 | break; |
7468 | case ELS_CMD_FAN: | |
858c9f6c JS |
7469 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7470 | "RCV FAN: did:x%x/ste:x%x flg:x%x", | |
7471 | did, vport->port_state, ndlp->nlp_flag); | |
7472 | ||
dea3101e | 7473 | phba->fc_stat.elsRcvFAN++; |
2e0fef85 | 7474 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
dea3101e | 7475 | break; |
dea3101e | 7476 | case ELS_CMD_PRLI: |
858c9f6c JS |
7477 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7478 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", | |
7479 | did, vport->port_state, ndlp->nlp_flag); | |
7480 | ||
dea3101e | 7481 | phba->fc_stat.elsRcvPRLI++; |
2e0fef85 | 7482 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 7483 | rjt_err = LSRJT_UNABLE_TPC; |
303f2f9c | 7484 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7485 | break; |
7486 | } | |
2e0fef85 | 7487 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
dea3101e | 7488 | break; |
7bb3b137 | 7489 | case ELS_CMD_LIRR: |
858c9f6c JS |
7490 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7491 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", | |
7492 | did, vport->port_state, ndlp->nlp_flag); | |
7493 | ||
7bb3b137 | 7494 | phba->fc_stat.elsRcvLIRR++; |
2e0fef85 | 7495 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
87af33fe | 7496 | if (newnode) |
98c9ea5c | 7497 | lpfc_nlp_put(ndlp); |
7bb3b137 | 7498 | break; |
12265f68 JS |
7499 | case ELS_CMD_RLS: |
7500 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7501 | "RCV RLS: did:x%x/ste:x%x flg:x%x", | |
7502 | did, vport->port_state, ndlp->nlp_flag); | |
7503 | ||
7504 | phba->fc_stat.elsRcvRLS++; | |
7505 | lpfc_els_rcv_rls(vport, elsiocb, ndlp); | |
7506 | if (newnode) | |
7507 | lpfc_nlp_put(ndlp); | |
7508 | break; | |
7bb3b137 | 7509 | case ELS_CMD_RPS: |
858c9f6c JS |
7510 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7511 | "RCV RPS: did:x%x/ste:x%x flg:x%x", | |
7512 | did, vport->port_state, ndlp->nlp_flag); | |
7513 | ||
7bb3b137 | 7514 | phba->fc_stat.elsRcvRPS++; |
2e0fef85 | 7515 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
87af33fe | 7516 | if (newnode) |
98c9ea5c | 7517 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
7518 | break; |
7519 | case ELS_CMD_RPL: | |
858c9f6c JS |
7520 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7521 | "RCV RPL: did:x%x/ste:x%x flg:x%x", | |
7522 | did, vport->port_state, ndlp->nlp_flag); | |
7523 | ||
7bb3b137 | 7524 | phba->fc_stat.elsRcvRPL++; |
2e0fef85 | 7525 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
87af33fe | 7526 | if (newnode) |
98c9ea5c | 7527 | lpfc_nlp_put(ndlp); |
7bb3b137 | 7528 | break; |
dea3101e | 7529 | case ELS_CMD_RNID: |
858c9f6c JS |
7530 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7531 | "RCV RNID: did:x%x/ste:x%x flg:x%x", | |
7532 | did, vport->port_state, ndlp->nlp_flag); | |
7533 | ||
dea3101e | 7534 | phba->fc_stat.elsRcvRNID++; |
2e0fef85 | 7535 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
87af33fe | 7536 | if (newnode) |
98c9ea5c | 7537 | lpfc_nlp_put(ndlp); |
dea3101e | 7538 | break; |
12265f68 JS |
7539 | case ELS_CMD_RTV: |
7540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7541 | "RCV RTV: did:x%x/ste:x%x flg:x%x", | |
7542 | did, vport->port_state, ndlp->nlp_flag); | |
7543 | phba->fc_stat.elsRcvRTV++; | |
7544 | lpfc_els_rcv_rtv(vport, elsiocb, ndlp); | |
7545 | if (newnode) | |
7546 | lpfc_nlp_put(ndlp); | |
7547 | break; | |
5ffc266e JS |
7548 | case ELS_CMD_RRQ: |
7549 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7550 | "RCV RRQ: did:x%x/ste:x%x flg:x%x", | |
7551 | did, vport->port_state, ndlp->nlp_flag); | |
7552 | ||
7553 | phba->fc_stat.elsRcvRRQ++; | |
7554 | lpfc_els_rcv_rrq(vport, elsiocb, ndlp); | |
7555 | if (newnode) | |
7556 | lpfc_nlp_put(ndlp); | |
7557 | break; | |
12265f68 JS |
7558 | case ELS_CMD_ECHO: |
7559 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
7560 | "RCV ECHO: did:x%x/ste:x%x flg:x%x", | |
7561 | did, vport->port_state, ndlp->nlp_flag); | |
7562 | ||
7563 | phba->fc_stat.elsRcvECHO++; | |
7564 | lpfc_els_rcv_echo(vport, elsiocb, ndlp); | |
7565 | if (newnode) | |
7566 | lpfc_nlp_put(ndlp); | |
7567 | break; | |
303f2f9c JS |
7568 | case ELS_CMD_REC: |
7569 | /* receive this due to exchange closed */ | |
7570 | rjt_err = LSRJT_UNABLE_TPC; | |
7571 | rjt_exp = LSEXP_INVALID_OX_RX; | |
7572 | break; | |
dea3101e | 7573 | default: |
858c9f6c JS |
7574 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
7575 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", | |
7576 | cmd, did, vport->port_state); | |
7577 | ||
dea3101e | 7578 | /* Unsupported ELS command, reject */ |
63e801ce | 7579 | rjt_err = LSRJT_CMD_UNSUPPORTED; |
303f2f9c | 7580 | rjt_exp = LSEXP_NOTHING_MORE; |
dea3101e JB |
7581 | |
7582 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
7583 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
7584 | "0115 Unknown ELS command x%x " | |
7585 | "received from NPORT x%x\n", cmd, did); | |
87af33fe | 7586 | if (newnode) |
98c9ea5c | 7587 | lpfc_nlp_put(ndlp); |
dea3101e JB |
7588 | break; |
7589 | } | |
7590 | ||
eec3d312 | 7591 | lsrjt: |
dea3101e JB |
7592 | /* check if need to LS_RJT received ELS cmd */ |
7593 | if (rjt_err) { | |
92d7f7b0 | 7594 | memset(&stat, 0, sizeof(stat)); |
858c9f6c | 7595 | stat.un.b.lsRjtRsnCode = rjt_err; |
303f2f9c | 7596 | stat.un.b.lsRjtRsnCodeExp = rjt_exp; |
858c9f6c JS |
7597 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
7598 | NULL); | |
dea3101e JB |
7599 | } |
7600 | ||
d7c255b2 JS |
7601 | lpfc_nlp_put(elsiocb->context1); |
7602 | elsiocb->context1 = NULL; | |
ed957684 JS |
7603 | return; |
7604 | ||
7605 | dropit: | |
98c9ea5c | 7606 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
6fb120a7 JS |
7607 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
7608 | "0111 Dropping received ELS cmd " | |
ed957684 | 7609 | "Data: x%x x%x x%x\n", |
6fb120a7 | 7610 | icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout); |
ed957684 JS |
7611 | phba->fc_stat.elsRcvDrop++; |
7612 | } | |
7613 | ||
e59058c4 | 7614 | /** |
3621a710 | 7615 | * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring |
e59058c4 JS |
7616 | * @phba: pointer to lpfc hba data structure. |
7617 | * @pring: pointer to a SLI ring. | |
7618 | * @elsiocb: pointer to lpfc els iocb data structure. | |
7619 | * | |
7620 | * This routine is used to process an unsolicited event received from a SLI | |
7621 | * (Service Level Interface) ring. The actual processing of the data buffer | |
7622 | * associated with the unsolicited event is done by invoking the routine | |
7623 | * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the | |
7624 | * SLI ring on which the unsolicited event was received. | |
7625 | **/ | |
ed957684 JS |
7626 | void |
7627 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7628 | struct lpfc_iocbq *elsiocb) | |
7629 | { | |
7630 | struct lpfc_vport *vport = phba->pport; | |
ed957684 | 7631 | IOCB_t *icmd = &elsiocb->iocb; |
ed957684 | 7632 | dma_addr_t paddr; |
92d7f7b0 JS |
7633 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
7634 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; | |
7635 | ||
d7c255b2 | 7636 | elsiocb->context1 = NULL; |
92d7f7b0 JS |
7637 | elsiocb->context2 = NULL; |
7638 | elsiocb->context3 = NULL; | |
ed957684 | 7639 | |
92d7f7b0 JS |
7640 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
7641 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
7642 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && | |
e3d2b802 JS |
7643 | (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
7644 | IOERR_RCV_BUFFER_WAITING) { | |
ed957684 JS |
7645 | phba->fc_stat.NoRcvBuf++; |
7646 | /* Not enough posted buffers; Try posting more buffers */ | |
92d7f7b0 | 7647 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
495a714c | 7648 | lpfc_post_buffer(phba, pring, 0); |
ed957684 JS |
7649 | return; |
7650 | } | |
7651 | ||
92d7f7b0 JS |
7652 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
7653 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || | |
7654 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
7655 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) | |
7656 | vport = phba->pport; | |
6fb120a7 JS |
7657 | else |
7658 | vport = lpfc_find_vport_by_vpid(phba, | |
6d368e53 | 7659 | icmd->unsli3.rcvsli3.vpi); |
92d7f7b0 | 7660 | } |
6d368e53 | 7661 | |
7f5f3d0d JS |
7662 | /* If there are no BDEs associated |
7663 | * with this IOCB, there is nothing to do. | |
7664 | */ | |
ed957684 JS |
7665 | if (icmd->ulpBdeCount == 0) |
7666 | return; | |
7667 | ||
7f5f3d0d JS |
7668 | /* type of ELS cmd is first 32bit word |
7669 | * in packet | |
7670 | */ | |
ed957684 | 7671 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
92d7f7b0 | 7672 | elsiocb->context2 = bdeBuf1; |
ed957684 JS |
7673 | } else { |
7674 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, | |
7675 | icmd->un.cont64[0].addrLow); | |
92d7f7b0 JS |
7676 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
7677 | paddr); | |
ed957684 JS |
7678 | } |
7679 | ||
92d7f7b0 JS |
7680 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
7681 | /* | |
7682 | * The different unsolicited event handlers would tell us | |
7683 | * if they are done with "mp" by setting context2 to NULL. | |
7684 | */ | |
dea3101e | 7685 | if (elsiocb->context2) { |
92d7f7b0 JS |
7686 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
7687 | elsiocb->context2 = NULL; | |
dea3101e | 7688 | } |
ed957684 JS |
7689 | |
7690 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ | |
92d7f7b0 | 7691 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
ed957684 | 7692 | icmd->ulpBdeCount == 2) { |
92d7f7b0 JS |
7693 | elsiocb->context2 = bdeBuf2; |
7694 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | |
ed957684 JS |
7695 | /* free mp if we are done with it */ |
7696 | if (elsiocb->context2) { | |
92d7f7b0 JS |
7697 | lpfc_in_buf_free(phba, elsiocb->context2); |
7698 | elsiocb->context2 = NULL; | |
7699 | } | |
7700 | } | |
7701 | } | |
7702 | ||
e59058c4 | 7703 | /** |
3621a710 | 7704 | * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr |
e59058c4 JS |
7705 | * @phba: pointer to lpfc hba data structure. |
7706 | * @vport: pointer to a virtual N_Port data structure. | |
7707 | * | |
7708 | * This routine issues a Port Login (PLOGI) to the Name Server with | |
7709 | * State Change Request (SCR) for a @vport. This routine will create an | |
7710 | * ndlp for the Name Server associated to the @vport if such node does | |
7711 | * not already exist. The PLOGI to Name Server is issued by invoking the | |
7712 | * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface | |
7713 | * (FDMI) is configured to the @vport, a FDMI node will be created and | |
7714 | * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. | |
7715 | **/ | |
92d7f7b0 JS |
7716 | void |
7717 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) | |
7718 | { | |
7719 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; | |
92494144 JS |
7720 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
7721 | ||
7722 | /* | |
7723 | * If lpfc_delay_discovery parameter is set and the clean address | |
7724 | * bit is cleared and fc fabric parameters chenged, delay FC NPort | |
7725 | * discovery. | |
7726 | */ | |
7727 | spin_lock_irq(shost->host_lock); | |
7728 | if (vport->fc_flag & FC_DISC_DELAYED) { | |
7729 | spin_unlock_irq(shost->host_lock); | |
18775708 JS |
7730 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, |
7731 | "3334 Delay fc port discovery for %d seconds\n", | |
7732 | phba->fc_ratov); | |
92494144 | 7733 | mod_timer(&vport->delayed_disc_tmo, |
256ec0d0 | 7734 | jiffies + msecs_to_jiffies(1000 * phba->fc_ratov)); |
92494144 JS |
7735 | return; |
7736 | } | |
7737 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 JS |
7738 | |
7739 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | |
7740 | if (!ndlp) { | |
7741 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
7742 | if (!ndlp) { | |
76a95d75 | 7743 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
92d7f7b0 JS |
7744 | lpfc_disc_start(vport); |
7745 | return; | |
7746 | } | |
7747 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
7748 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
7749 | "0251 NameServer login: no memory\n"); | |
92d7f7b0 JS |
7750 | return; |
7751 | } | |
7752 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | |
e47c9093 JS |
7753 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
7754 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
7755 | if (!ndlp) { | |
76a95d75 | 7756 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
e47c9093 JS |
7757 | lpfc_disc_start(vport); |
7758 | return; | |
7759 | } | |
7760 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
7761 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
7762 | "0348 NameServer login: node freed\n"); | |
7763 | return; | |
7764 | } | |
92d7f7b0 | 7765 | } |
58da1ffb | 7766 | ndlp->nlp_type |= NLP_FABRIC; |
92d7f7b0 JS |
7767 | |
7768 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
7769 | ||
7770 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { | |
7771 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
7772 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
7773 | "0252 Cannot issue NameServer login\n"); | |
92d7f7b0 JS |
7774 | return; |
7775 | } | |
7776 | ||
76b2c34a | 7777 | if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) { |
63e801ce JS |
7778 | /* If this is the first time, allocate an ndlp and initialize |
7779 | * it. Otherwise, make sure the node is enabled and then do the | |
7780 | * login. | |
7781 | */ | |
7782 | ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID); | |
7783 | if (!ndlp_fdmi) { | |
7784 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, | |
7785 | GFP_KERNEL); | |
7786 | if (ndlp_fdmi) { | |
7787 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); | |
7788 | ndlp_fdmi->nlp_type |= NLP_FABRIC; | |
7789 | } else | |
7790 | return; | |
7791 | } | |
7792 | if (!NLP_CHK_NODE_ACT(ndlp_fdmi)) | |
7793 | ndlp_fdmi = lpfc_enable_node(vport, | |
7794 | ndlp_fdmi, | |
7795 | NLP_STE_NPR_NODE); | |
7796 | ||
92d7f7b0 | 7797 | if (ndlp_fdmi) { |
58da1ffb | 7798 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
63e801ce JS |
7799 | NLP_STE_PLOGI_ISSUE); |
7800 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0); | |
92d7f7b0 JS |
7801 | } |
7802 | } | |
92d7f7b0 JS |
7803 | } |
7804 | ||
e59058c4 | 7805 | /** |
3621a710 | 7806 | * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport |
e59058c4 JS |
7807 | * @phba: pointer to lpfc hba data structure. |
7808 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
7809 | * | |
7810 | * This routine is the completion callback function to register new vport | |
7811 | * mailbox command. If the new vport mailbox command completes successfully, | |
7812 | * the fabric registration login shall be performed on physical port (the | |
7813 | * new vport created is actually a physical port, with VPI 0) or the port | |
7814 | * login to Name Server for State Change Request (SCR) will be performed | |
7815 | * on virtual port (real virtual port, with VPI greater than 0). | |
7816 | **/ | |
92d7f7b0 JS |
7817 | static void |
7818 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
7819 | { | |
7820 | struct lpfc_vport *vport = pmb->vport; | |
7821 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7822 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
04c68496 | 7823 | MAILBOX_t *mb = &pmb->u.mb; |
695a814e | 7824 | int rc; |
92d7f7b0 | 7825 | |
09372820 | 7826 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 7827 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
09372820 | 7828 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
7829 | |
7830 | if (mb->mbxStatus) { | |
e8b62011 | 7831 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
38b92ef8 JS |
7832 | "0915 Register VPI failed : Status: x%x" |
7833 | " upd bit: x%x \n", mb->mbxStatus, | |
7834 | mb->un.varRegVpi.upd); | |
7835 | if (phba->sli_rev == LPFC_SLI_REV4 && | |
7836 | mb->un.varRegVpi.upd) | |
7837 | goto mbox_err_exit ; | |
92d7f7b0 JS |
7838 | |
7839 | switch (mb->mbxStatus) { | |
7840 | case 0x11: /* unsupported feature */ | |
7841 | case 0x9603: /* max_vpi exceeded */ | |
7f5f3d0d | 7842 | case 0x9602: /* Link event since CLEAR_LA */ |
92d7f7b0 JS |
7843 | /* giving up on vport registration */ |
7844 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
7845 | spin_lock_irq(shost->host_lock); | |
7846 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
7847 | spin_unlock_irq(shost->host_lock); | |
7848 | lpfc_can_disctmo(vport); | |
7849 | break; | |
695a814e JS |
7850 | /* If reg_vpi fail with invalid VPI status, re-init VPI */ |
7851 | case 0x20: | |
7852 | spin_lock_irq(shost->host_lock); | |
7853 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
7854 | spin_unlock_irq(shost->host_lock); | |
7855 | lpfc_init_vpi(phba, pmb, vport->vpi); | |
7856 | pmb->vport = vport; | |
7857 | pmb->mbox_cmpl = lpfc_init_vpi_cmpl; | |
7858 | rc = lpfc_sli_issue_mbox(phba, pmb, | |
7859 | MBX_NOWAIT); | |
7860 | if (rc == MBX_NOT_FINISHED) { | |
7861 | lpfc_printf_vlog(vport, | |
7862 | KERN_ERR, LOG_MBOX, | |
7863 | "2732 Failed to issue INIT_VPI" | |
7864 | " mailbox command\n"); | |
7865 | } else { | |
7866 | lpfc_nlp_put(ndlp); | |
7867 | return; | |
7868 | } | |
7869 | ||
92d7f7b0 JS |
7870 | default: |
7871 | /* Try to recover from this error */ | |
5af5eee7 JS |
7872 | if (phba->sli_rev == LPFC_SLI_REV4) |
7873 | lpfc_sli4_unreg_all_rpis(vport); | |
92d7f7b0 | 7874 | lpfc_mbx_unreg_vpi(vport); |
09372820 | 7875 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 7876 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 7877 | spin_unlock_irq(shost->host_lock); |
4b40c59e JS |
7878 | if (vport->port_type == LPFC_PHYSICAL_PORT |
7879 | && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) | |
76a95d75 | 7880 | lpfc_issue_init_vfi(vport); |
7f5f3d0d JS |
7881 | else |
7882 | lpfc_initial_fdisc(vport); | |
92d7f7b0 JS |
7883 | break; |
7884 | } | |
92d7f7b0 | 7885 | } else { |
695a814e | 7886 | spin_lock_irq(shost->host_lock); |
1987807d | 7887 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
695a814e JS |
7888 | spin_unlock_irq(shost->host_lock); |
7889 | if (vport == phba->pport) { | |
6fb120a7 JS |
7890 | if (phba->sli_rev < LPFC_SLI_REV4) |
7891 | lpfc_issue_fabric_reglogin(vport); | |
695a814e | 7892 | else { |
fc2b989b JS |
7893 | /* |
7894 | * If the physical port is instantiated using | |
7895 | * FDISC, do not start vport discovery. | |
7896 | */ | |
7897 | if (vport->port_state != LPFC_FDISC) | |
7898 | lpfc_start_fdiscs(phba); | |
695a814e JS |
7899 | lpfc_do_scr_ns_plogi(phba, vport); |
7900 | } | |
7901 | } else | |
92d7f7b0 JS |
7902 | lpfc_do_scr_ns_plogi(phba, vport); |
7903 | } | |
38b92ef8 | 7904 | mbox_err_exit: |
fa4066b6 JS |
7905 | /* Now, we decrement the ndlp reference count held for this |
7906 | * callback function | |
7907 | */ | |
7908 | lpfc_nlp_put(ndlp); | |
7909 | ||
92d7f7b0 JS |
7910 | mempool_free(pmb, phba->mbox_mem_pool); |
7911 | return; | |
7912 | } | |
7913 | ||
e59058c4 | 7914 | /** |
3621a710 | 7915 | * lpfc_register_new_vport - Register a new vport with a HBA |
e59058c4 JS |
7916 | * @phba: pointer to lpfc hba data structure. |
7917 | * @vport: pointer to a host virtual N_Port data structure. | |
7918 | * @ndlp: pointer to a node-list data structure. | |
7919 | * | |
7920 | * This routine registers the @vport as a new virtual port with a HBA. | |
7921 | * It is done through a registering vpi mailbox command. | |
7922 | **/ | |
695a814e | 7923 | void |
92d7f7b0 JS |
7924 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
7925 | struct lpfc_nodelist *ndlp) | |
7926 | { | |
09372820 | 7927 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
92d7f7b0 JS |
7928 | LPFC_MBOXQ_t *mbox; |
7929 | ||
7930 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7931 | if (mbox) { | |
6fb120a7 | 7932 | lpfc_reg_vpi(vport, mbox); |
92d7f7b0 JS |
7933 | mbox->vport = vport; |
7934 | mbox->context2 = lpfc_nlp_get(ndlp); | |
7935 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; | |
0b727fea | 7936 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
92d7f7b0 | 7937 | == MBX_NOT_FINISHED) { |
fa4066b6 JS |
7938 | /* mailbox command not success, decrement ndlp |
7939 | * reference count for this command | |
7940 | */ | |
7941 | lpfc_nlp_put(ndlp); | |
92d7f7b0 | 7942 | mempool_free(mbox, phba->mbox_mem_pool); |
92d7f7b0 | 7943 | |
e8b62011 JS |
7944 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
7945 | "0253 Register VPI: Can't send mbox\n"); | |
fa4066b6 | 7946 | goto mbox_err_exit; |
92d7f7b0 JS |
7947 | } |
7948 | } else { | |
e8b62011 JS |
7949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
7950 | "0254 Register VPI: no memory\n"); | |
fa4066b6 | 7951 | goto mbox_err_exit; |
92d7f7b0 | 7952 | } |
fa4066b6 JS |
7953 | return; |
7954 | ||
7955 | mbox_err_exit: | |
7956 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
7957 | spin_lock_irq(shost->host_lock); | |
7958 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
7959 | spin_unlock_irq(shost->host_lock); | |
7960 | return; | |
92d7f7b0 JS |
7961 | } |
7962 | ||
695a814e | 7963 | /** |
0c9ab6f5 | 7964 | * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer |
695a814e JS |
7965 | * @phba: pointer to lpfc hba data structure. |
7966 | * | |
0c9ab6f5 | 7967 | * This routine cancels the retry delay timers to all the vports. |
695a814e JS |
7968 | **/ |
7969 | void | |
0c9ab6f5 | 7970 | lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) |
695a814e JS |
7971 | { |
7972 | struct lpfc_vport **vports; | |
7973 | struct lpfc_nodelist *ndlp; | |
695a814e | 7974 | uint32_t link_state; |
0c9ab6f5 | 7975 | int i; |
695a814e JS |
7976 | |
7977 | /* Treat this failure as linkdown for all vports */ | |
7978 | link_state = phba->link_state; | |
7979 | lpfc_linkdown(phba); | |
7980 | phba->link_state = link_state; | |
7981 | ||
7982 | vports = lpfc_create_vport_work_array(phba); | |
7983 | ||
7984 | if (vports) { | |
7985 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
7986 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); | |
7987 | if (ndlp) | |
7988 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); | |
7989 | lpfc_els_flush_cmd(vports[i]); | |
7990 | } | |
7991 | lpfc_destroy_vport_work_array(phba, vports); | |
7992 | } | |
0c9ab6f5 JS |
7993 | } |
7994 | ||
7995 | /** | |
7996 | * lpfc_retry_pport_discovery - Start timer to retry FLOGI. | |
7997 | * @phba: pointer to lpfc hba data structure. | |
7998 | * | |
7999 | * This routine abort all pending discovery commands and | |
8000 | * start a timer to retry FLOGI for the physical port | |
8001 | * discovery. | |
8002 | **/ | |
8003 | void | |
8004 | lpfc_retry_pport_discovery(struct lpfc_hba *phba) | |
8005 | { | |
8006 | struct lpfc_nodelist *ndlp; | |
8007 | struct Scsi_Host *shost; | |
8008 | ||
8009 | /* Cancel the all vports retry delay retry timers */ | |
8010 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
695a814e JS |
8011 | |
8012 | /* If fabric require FLOGI, then re-instantiate physical login */ | |
8013 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); | |
8014 | if (!ndlp) | |
8015 | return; | |
8016 | ||
695a814e | 8017 | shost = lpfc_shost_from_vport(phba->pport); |
256ec0d0 | 8018 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
695a814e JS |
8019 | spin_lock_irq(shost->host_lock); |
8020 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
8021 | spin_unlock_irq(shost->host_lock); | |
8022 | ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; | |
8023 | phba->pport->port_state = LPFC_FLOGI; | |
8024 | return; | |
8025 | } | |
8026 | ||
8027 | /** | |
8028 | * lpfc_fabric_login_reqd - Check if FLOGI required. | |
8029 | * @phba: pointer to lpfc hba data structure. | |
8030 | * @cmdiocb: pointer to FDISC command iocb. | |
8031 | * @rspiocb: pointer to FDISC response iocb. | |
8032 | * | |
8033 | * This routine checks if a FLOGI is reguired for FDISC | |
8034 | * to succeed. | |
8035 | **/ | |
8036 | static int | |
8037 | lpfc_fabric_login_reqd(struct lpfc_hba *phba, | |
8038 | struct lpfc_iocbq *cmdiocb, | |
8039 | struct lpfc_iocbq *rspiocb) | |
8040 | { | |
8041 | ||
8042 | if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) || | |
8043 | (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED)) | |
8044 | return 0; | |
8045 | else | |
8046 | return 1; | |
8047 | } | |
8048 | ||
e59058c4 | 8049 | /** |
3621a710 | 8050 | * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command |
e59058c4 JS |
8051 | * @phba: pointer to lpfc hba data structure. |
8052 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
8053 | * @rspiocb: pointer to lpfc response iocb data structure. | |
8054 | * | |
8055 | * This routine is the completion callback function to a Fabric Discover | |
8056 | * (FDISC) ELS command. Since all the FDISC ELS commands are issued | |
8057 | * single threaded, each FDISC completion callback function will reset | |
8058 | * the discovery timer for all vports such that the timers will not get | |
8059 | * unnecessary timeout. The function checks the FDISC IOCB status. If error | |
8060 | * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the | |
8061 | * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID | |
8062 | * assigned to the vport has been changed with the completion of the FDISC | |
8063 | * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) | |
8064 | * are unregistered from the HBA, and then the lpfc_register_new_vport() | |
8065 | * routine is invoked to register new vport with the HBA. Otherwise, the | |
8066 | * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name | |
8067 | * Server for State Change Request (SCR). | |
8068 | **/ | |
92d7f7b0 JS |
8069 | static void |
8070 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8071 | struct lpfc_iocbq *rspiocb) | |
8072 | { | |
8073 | struct lpfc_vport *vport = cmdiocb->vport; | |
8074 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8075 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
8076 | struct lpfc_nodelist *np; | |
8077 | struct lpfc_nodelist *next_np; | |
8078 | IOCB_t *irsp = &rspiocb->iocb; | |
8079 | struct lpfc_iocbq *piocb; | |
92494144 JS |
8080 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
8081 | struct serv_parm *sp; | |
8082 | uint8_t fabric_param_changed; | |
92d7f7b0 | 8083 | |
e8b62011 JS |
8084 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
8085 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", | |
8086 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
8087 | vport->fc_prevDID); | |
92d7f7b0 JS |
8088 | /* Since all FDISCs are being single threaded, we |
8089 | * must reset the discovery timer for ALL vports | |
8090 | * waiting to send FDISC when one completes. | |
8091 | */ | |
8092 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { | |
8093 | lpfc_set_disctmo(piocb->vport); | |
8094 | } | |
8095 | ||
858c9f6c JS |
8096 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8097 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", | |
8098 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); | |
8099 | ||
92d7f7b0 | 8100 | if (irsp->ulpStatus) { |
695a814e JS |
8101 | |
8102 | if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { | |
8103 | lpfc_retry_pport_discovery(phba); | |
8104 | goto out; | |
8105 | } | |
8106 | ||
92d7f7b0 JS |
8107 | /* Check for retry */ |
8108 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | |
8109 | goto out; | |
92d7f7b0 | 8110 | /* FDISC failed */ |
e8b62011 | 8111 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
6b5151fd | 8112 | "0126 FDISC failed. (x%x/x%x)\n", |
e8b62011 | 8113 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
d7c255b2 JS |
8114 | goto fdisc_failed; |
8115 | } | |
d7c255b2 | 8116 | spin_lock_irq(shost->host_lock); |
695a814e | 8117 | vport->fc_flag &= ~FC_VPORT_CVL_RCVD; |
4b40c59e | 8118 | vport->fc_flag &= ~FC_VPORT_LOGO_RCVD; |
d7c255b2 | 8119 | vport->fc_flag |= FC_FABRIC; |
76a95d75 | 8120 | if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
d7c255b2 JS |
8121 | vport->fc_flag |= FC_PUBLIC_LOOP; |
8122 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 | 8123 | |
d7c255b2 JS |
8124 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
8125 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); | |
92494144 | 8126 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
a2fc4aef JS |
8127 | if (!prsp) |
8128 | goto out; | |
92494144 JS |
8129 | sp = prsp->virt + sizeof(uint32_t); |
8130 | fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); | |
8131 | memcpy(&vport->fabric_portname, &sp->portName, | |
8132 | sizeof(struct lpfc_name)); | |
8133 | memcpy(&vport->fabric_nodename, &sp->nodeName, | |
8134 | sizeof(struct lpfc_name)); | |
8135 | if (fabric_param_changed && | |
d7c255b2 JS |
8136 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
8137 | /* If our NportID changed, we need to ensure all | |
8138 | * remaining NPORTs get unreg_login'ed so we can | |
8139 | * issue unreg_vpi. | |
8140 | */ | |
8141 | list_for_each_entry_safe(np, next_np, | |
8142 | &vport->fc_nodes, nlp_listp) { | |
8143 | if (!NLP_CHK_NODE_ACT(ndlp) || | |
8144 | (np->nlp_state != NLP_STE_NPR_NODE) || | |
8145 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
8146 | continue; | |
09372820 | 8147 | spin_lock_irq(shost->host_lock); |
d7c255b2 | 8148 | np->nlp_flag &= ~NLP_NPR_ADISC; |
09372820 | 8149 | spin_unlock_irq(shost->host_lock); |
d7c255b2 | 8150 | lpfc_unreg_rpi(vport, np); |
92d7f7b0 | 8151 | } |
78730cfe | 8152 | lpfc_cleanup_pending_mbox(vport); |
5af5eee7 JS |
8153 | |
8154 | if (phba->sli_rev == LPFC_SLI_REV4) | |
8155 | lpfc_sli4_unreg_all_rpis(vport); | |
8156 | ||
d7c255b2 JS |
8157 | lpfc_mbx_unreg_vpi(vport); |
8158 | spin_lock_irq(shost->host_lock); | |
8159 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
0f65ff68 JS |
8160 | if (phba->sli_rev == LPFC_SLI_REV4) |
8161 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
4b40c59e JS |
8162 | else |
8163 | vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; | |
d7c255b2 | 8164 | spin_unlock_irq(shost->host_lock); |
38b92ef8 JS |
8165 | } else if ((phba->sli_rev == LPFC_SLI_REV4) && |
8166 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
8167 | /* | |
8168 | * Driver needs to re-reg VPI in order for f/w | |
8169 | * to update the MAC address. | |
8170 | */ | |
8171 | lpfc_register_new_vport(phba, vport, ndlp); | |
5ac6b303 | 8172 | goto out; |
92d7f7b0 JS |
8173 | } |
8174 | ||
ecfd03c6 JS |
8175 | if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) |
8176 | lpfc_issue_init_vpi(vport); | |
8177 | else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | |
d7c255b2 JS |
8178 | lpfc_register_new_vport(phba, vport, ndlp); |
8179 | else | |
8180 | lpfc_do_scr_ns_plogi(phba, vport); | |
8181 | goto out; | |
8182 | fdisc_failed: | |
c84163d1 JS |
8183 | if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS) |
8184 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
d7c255b2 JS |
8185 | /* Cancel discovery timer */ |
8186 | lpfc_can_disctmo(vport); | |
8187 | lpfc_nlp_put(ndlp); | |
92d7f7b0 JS |
8188 | out: |
8189 | lpfc_els_free_iocb(phba, cmdiocb); | |
8190 | } | |
8191 | ||
e59058c4 | 8192 | /** |
3621a710 | 8193 | * lpfc_issue_els_fdisc - Issue a fdisc iocb command |
e59058c4 JS |
8194 | * @vport: pointer to a virtual N_Port data structure. |
8195 | * @ndlp: pointer to a node-list data structure. | |
8196 | * @retry: number of retries to the command IOCB. | |
8197 | * | |
8198 | * This routine prepares and issues a Fabric Discover (FDISC) IOCB to | |
8199 | * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() | |
8200 | * routine to issue the IOCB, which makes sure only one outstanding fabric | |
8201 | * IOCB will be sent off HBA at any given time. | |
8202 | * | |
8203 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
8204 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
8205 | * will be stored into the context1 field of the IOCB for the completion | |
8206 | * callback function to the FDISC ELS command. | |
8207 | * | |
8208 | * Return code | |
8209 | * 0 - Successfully issued fdisc iocb command | |
8210 | * 1 - Failed to issue fdisc iocb command | |
8211 | **/ | |
a6ababd2 | 8212 | static int |
92d7f7b0 JS |
8213 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
8214 | uint8_t retry) | |
8215 | { | |
8216 | struct lpfc_hba *phba = vport->phba; | |
8217 | IOCB_t *icmd; | |
8218 | struct lpfc_iocbq *elsiocb; | |
8219 | struct serv_parm *sp; | |
8220 | uint8_t *pcmd; | |
8221 | uint16_t cmdsize; | |
8222 | int did = ndlp->nlp_DID; | |
8223 | int rc; | |
92d7f7b0 | 8224 | |
5ffc266e | 8225 | vport->port_state = LPFC_FDISC; |
6b5151fd | 8226 | vport->fc_myDID = 0; |
92d7f7b0 JS |
8227 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
8228 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | |
8229 | ELS_CMD_FDISC); | |
8230 | if (!elsiocb) { | |
92d7f7b0 | 8231 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
8232 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8233 | "0255 Issue FDISC: no IOCB\n"); | |
92d7f7b0 JS |
8234 | return 1; |
8235 | } | |
8236 | ||
8237 | icmd = &elsiocb->iocb; | |
8238 | icmd->un.elsreq64.myID = 0; | |
8239 | icmd->un.elsreq64.fl = 1; | |
8240 | ||
73d91e50 JS |
8241 | /* |
8242 | * SLI3 ports require a different context type value than SLI4. | |
8243 | * Catch SLI3 ports here and override the prep. | |
8244 | */ | |
8245 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
f1126688 JS |
8246 | icmd->ulpCt_h = 1; |
8247 | icmd->ulpCt_l = 0; | |
8248 | } | |
92d7f7b0 JS |
8249 | |
8250 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
8251 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; | |
8252 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ | |
8253 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); | |
8254 | sp = (struct serv_parm *) pcmd; | |
8255 | /* Setup CSPs accordingly for Fabric */ | |
8256 | sp->cmn.e_d_tov = 0; | |
8257 | sp->cmn.w2.r_a_tov = 0; | |
df9e1b59 | 8258 | sp->cmn.virtual_fabric_support = 0; |
92d7f7b0 JS |
8259 | sp->cls1.classValid = 0; |
8260 | sp->cls2.seqDelivery = 1; | |
8261 | sp->cls3.seqDelivery = 1; | |
8262 | ||
8263 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ | |
8264 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ | |
8265 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ | |
8266 | pcmd += sizeof(uint32_t); /* Port Name */ | |
8267 | memcpy(pcmd, &vport->fc_portname, 8); | |
8268 | pcmd += sizeof(uint32_t); /* Node Name */ | |
8269 | pcmd += sizeof(uint32_t); /* Node Name */ | |
8270 | memcpy(pcmd, &vport->fc_nodename, 8); | |
8271 | ||
8272 | lpfc_set_disctmo(vport); | |
8273 | ||
8274 | phba->fc_stat.elsXmitFDISC++; | |
8275 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; | |
8276 | ||
858c9f6c JS |
8277 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8278 | "Issue FDISC: did:x%x", | |
8279 | did, 0, 0); | |
8280 | ||
92d7f7b0 JS |
8281 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
8282 | if (rc == IOCB_ERROR) { | |
8283 | lpfc_els_free_iocb(phba, elsiocb); | |
92d7f7b0 | 8284 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
8285 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
8286 | "0256 Issue FDISC: Cannot send IOCB\n"); | |
92d7f7b0 JS |
8287 | return 1; |
8288 | } | |
8289 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); | |
92d7f7b0 JS |
8290 | return 0; |
8291 | } | |
8292 | ||
e59058c4 | 8293 | /** |
3621a710 | 8294 | * lpfc_cmpl_els_npiv_logo - Completion function with vport logo |
e59058c4 JS |
8295 | * @phba: pointer to lpfc hba data structure. |
8296 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
8297 | * @rspiocb: pointer to lpfc response iocb data structure. | |
8298 | * | |
8299 | * This routine is the completion callback function to the issuing of a LOGO | |
8300 | * ELS command off a vport. It frees the command IOCB and then decrement the | |
8301 | * reference count held on ndlp for this completion function, indicating that | |
8302 | * the reference to the ndlp is no long needed. Note that the | |
8303 | * lpfc_els_free_iocb() routine decrements the ndlp reference held for this | |
8304 | * callback function and an additional explicit ndlp reference decrementation | |
8305 | * will trigger the actual release of the ndlp. | |
8306 | **/ | |
92d7f7b0 JS |
8307 | static void |
8308 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8309 | struct lpfc_iocbq *rspiocb) | |
8310 | { | |
8311 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c | 8312 | IOCB_t *irsp; |
e47c9093 | 8313 | struct lpfc_nodelist *ndlp; |
9589b062 | 8314 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
858c9f6c | 8315 | |
9589b062 | 8316 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
858c9f6c JS |
8317 | irsp = &rspiocb->iocb; |
8318 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
8319 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", | |
8320 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); | |
92d7f7b0 JS |
8321 | |
8322 | lpfc_els_free_iocb(phba, cmdiocb); | |
8323 | vport->unreg_vpi_cmpl = VPORT_ERROR; | |
e47c9093 JS |
8324 | |
8325 | /* Trigger the release of the ndlp after logo */ | |
8326 | lpfc_nlp_put(ndlp); | |
9589b062 JS |
8327 | |
8328 | /* NPIV LOGO completes to NPort <nlp_DID> */ | |
8329 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
8330 | "2928 NPIV LOGO completes to NPort x%x " | |
8331 | "Data: x%x x%x x%x x%x\n", | |
8332 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
8333 | irsp->ulpTimeout, vport->num_disc_nodes); | |
8334 | ||
8335 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { | |
8336 | spin_lock_irq(shost->host_lock); | |
73dc0dbe | 8337 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
9589b062 JS |
8338 | vport->fc_flag &= ~FC_FABRIC; |
8339 | spin_unlock_irq(shost->host_lock); | |
73dc0dbe | 8340 | lpfc_can_disctmo(vport); |
9589b062 | 8341 | } |
92d7f7b0 JS |
8342 | } |
8343 | ||
e59058c4 | 8344 | /** |
3621a710 | 8345 | * lpfc_issue_els_npiv_logo - Issue a logo off a vport |
e59058c4 JS |
8346 | * @vport: pointer to a virtual N_Port data structure. |
8347 | * @ndlp: pointer to a node-list data structure. | |
8348 | * | |
8349 | * This routine issues a LOGO ELS command to an @ndlp off a @vport. | |
8350 | * | |
8351 | * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp | |
8352 | * will be incremented by 1 for holding the ndlp and the reference to ndlp | |
8353 | * will be stored into the context1 field of the IOCB for the completion | |
8354 | * callback function to the LOGO ELS command. | |
8355 | * | |
8356 | * Return codes | |
8357 | * 0 - Successfully issued logo off the @vport | |
8358 | * 1 - Failed to issue logo off the @vport | |
8359 | **/ | |
92d7f7b0 JS |
8360 | int |
8361 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
8362 | { | |
8363 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8364 | struct lpfc_hba *phba = vport->phba; | |
92d7f7b0 JS |
8365 | struct lpfc_iocbq *elsiocb; |
8366 | uint8_t *pcmd; | |
8367 | uint16_t cmdsize; | |
8368 | ||
8369 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); | |
8370 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, | |
8371 | ELS_CMD_LOGO); | |
8372 | if (!elsiocb) | |
8373 | return 1; | |
8374 | ||
92d7f7b0 JS |
8375 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
8376 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
8377 | pcmd += sizeof(uint32_t); | |
8378 | ||
8379 | /* Fill in LOGO payload */ | |
8380 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | |
8381 | pcmd += sizeof(uint32_t); | |
8382 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
8383 | ||
858c9f6c JS |
8384 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
8385 | "Issue LOGO npiv did:x%x flg:x%x", | |
8386 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
8387 | ||
92d7f7b0 JS |
8388 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
8389 | spin_lock_irq(shost->host_lock); | |
8390 | ndlp->nlp_flag |= NLP_LOGO_SND; | |
8391 | spin_unlock_irq(shost->host_lock); | |
3772a991 JS |
8392 | if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == |
8393 | IOCB_ERROR) { | |
92d7f7b0 JS |
8394 | spin_lock_irq(shost->host_lock); |
8395 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | |
8396 | spin_unlock_irq(shost->host_lock); | |
8397 | lpfc_els_free_iocb(phba, elsiocb); | |
8398 | return 1; | |
8399 | } | |
8400 | return 0; | |
8401 | } | |
8402 | ||
e59058c4 | 8403 | /** |
3621a710 | 8404 | * lpfc_fabric_block_timeout - Handler function to the fabric block timer |
e59058c4 JS |
8405 | * @ptr: holder for the timer function associated data. |
8406 | * | |
8407 | * This routine is invoked by the fabric iocb block timer after | |
8408 | * timeout. It posts the fabric iocb block timeout event by setting the | |
8409 | * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes | |
8410 | * lpfc_worker_wake_up() routine to wake up the worker thread. It is for | |
8411 | * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the | |
8412 | * posted event WORKER_FABRIC_BLOCK_TMO. | |
8413 | **/ | |
92d7f7b0 JS |
8414 | void |
8415 | lpfc_fabric_block_timeout(unsigned long ptr) | |
8416 | { | |
8417 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
8418 | unsigned long iflags; | |
8419 | uint32_t tmo_posted; | |
5e9d9b82 | 8420 | |
92d7f7b0 JS |
8421 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
8422 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; | |
8423 | if (!tmo_posted) | |
8424 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; | |
8425 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
8426 | ||
5e9d9b82 JS |
8427 | if (!tmo_posted) |
8428 | lpfc_worker_wake_up(phba); | |
8429 | return; | |
92d7f7b0 JS |
8430 | } |
8431 | ||
e59058c4 | 8432 | /** |
3621a710 | 8433 | * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list |
e59058c4 JS |
8434 | * @phba: pointer to lpfc hba data structure. |
8435 | * | |
8436 | * This routine issues one fabric iocb from the driver internal list to | |
8437 | * the HBA. It first checks whether it's ready to issue one fabric iocb to | |
8438 | * the HBA (whether there is no outstanding fabric iocb). If so, it shall | |
8439 | * remove one pending fabric iocb from the driver internal list and invokes | |
8440 | * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. | |
8441 | **/ | |
92d7f7b0 JS |
8442 | static void |
8443 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) | |
8444 | { | |
8445 | struct lpfc_iocbq *iocb; | |
8446 | unsigned long iflags; | |
8447 | int ret; | |
92d7f7b0 JS |
8448 | IOCB_t *cmd; |
8449 | ||
8450 | repeat: | |
8451 | iocb = NULL; | |
8452 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7f5f3d0d | 8453 | /* Post any pending iocb to the SLI layer */ |
92d7f7b0 JS |
8454 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
8455 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), | |
8456 | list); | |
8457 | if (iocb) | |
7f5f3d0d | 8458 | /* Increment fabric iocb count to hold the position */ |
92d7f7b0 JS |
8459 | atomic_inc(&phba->fabric_iocb_count); |
8460 | } | |
8461 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8462 | if (iocb) { | |
8463 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
8464 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
8465 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
8466 | ||
858c9f6c JS |
8467 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
8468 | "Fabric sched1: ste:x%x", | |
8469 | iocb->vport->port_state, 0, 0); | |
8470 | ||
3772a991 | 8471 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
92d7f7b0 JS |
8472 | |
8473 | if (ret == IOCB_ERROR) { | |
8474 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
8475 | iocb->fabric_iocb_cmpl = NULL; | |
8476 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
8477 | cmd = &iocb->iocb; | |
8478 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
8479 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
8480 | iocb->iocb_cmpl(phba, iocb, iocb); | |
8481 | ||
8482 | atomic_dec(&phba->fabric_iocb_count); | |
8483 | goto repeat; | |
8484 | } | |
8485 | } | |
8486 | ||
8487 | return; | |
8488 | } | |
8489 | ||
e59058c4 | 8490 | /** |
3621a710 | 8491 | * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command |
e59058c4 JS |
8492 | * @phba: pointer to lpfc hba data structure. |
8493 | * | |
8494 | * This routine unblocks the issuing fabric iocb command. The function | |
8495 | * will clear the fabric iocb block bit and then invoke the routine | |
8496 | * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb | |
8497 | * from the driver internal fabric iocb list. | |
8498 | **/ | |
92d7f7b0 JS |
8499 | void |
8500 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) | |
8501 | { | |
8502 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
8503 | ||
8504 | lpfc_resume_fabric_iocbs(phba); | |
8505 | return; | |
8506 | } | |
8507 | ||
e59058c4 | 8508 | /** |
3621a710 | 8509 | * lpfc_block_fabric_iocbs - Block issuing fabric iocb command |
e59058c4 JS |
8510 | * @phba: pointer to lpfc hba data structure. |
8511 | * | |
8512 | * This routine blocks the issuing fabric iocb for a specified amount of | |
8513 | * time (currently 100 ms). This is done by set the fabric iocb block bit | |
8514 | * and set up a timeout timer for 100ms. When the block bit is set, no more | |
8515 | * fabric iocb will be issued out of the HBA. | |
8516 | **/ | |
92d7f7b0 JS |
8517 | static void |
8518 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) | |
8519 | { | |
8520 | int blocked; | |
8521 | ||
8522 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
7f5f3d0d | 8523 | /* Start a timer to unblock fabric iocbs after 100ms */ |
92d7f7b0 | 8524 | if (!blocked) |
256ec0d0 JS |
8525 | mod_timer(&phba->fabric_block_timer, |
8526 | jiffies + msecs_to_jiffies(100)); | |
92d7f7b0 JS |
8527 | |
8528 | return; | |
8529 | } | |
8530 | ||
e59058c4 | 8531 | /** |
3621a710 | 8532 | * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb |
e59058c4 JS |
8533 | * @phba: pointer to lpfc hba data structure. |
8534 | * @cmdiocb: pointer to lpfc command iocb data structure. | |
8535 | * @rspiocb: pointer to lpfc response iocb data structure. | |
8536 | * | |
8537 | * This routine is the callback function that is put to the fabric iocb's | |
8538 | * callback function pointer (iocb->iocb_cmpl). The original iocb's callback | |
8539 | * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback | |
8540 | * function first restores and invokes the original iocb's callback function | |
8541 | * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next | |
8542 | * fabric bound iocb from the driver internal fabric iocb list onto the wire. | |
8543 | **/ | |
92d7f7b0 JS |
8544 | static void |
8545 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8546 | struct lpfc_iocbq *rspiocb) | |
8547 | { | |
8548 | struct ls_rjt stat; | |
8549 | ||
8550 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) | |
8551 | BUG(); | |
8552 | ||
8553 | switch (rspiocb->iocb.ulpStatus) { | |
8554 | case IOSTAT_NPORT_RJT: | |
8555 | case IOSTAT_FABRIC_RJT: | |
8556 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
8557 | lpfc_block_fabric_iocbs(phba); | |
ed957684 | 8558 | } |
92d7f7b0 JS |
8559 | break; |
8560 | ||
8561 | case IOSTAT_NPORT_BSY: | |
8562 | case IOSTAT_FABRIC_BSY: | |
8563 | lpfc_block_fabric_iocbs(phba); | |
8564 | break; | |
8565 | ||
8566 | case IOSTAT_LS_RJT: | |
8567 | stat.un.lsRjtError = | |
8568 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); | |
8569 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || | |
8570 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) | |
8571 | lpfc_block_fabric_iocbs(phba); | |
8572 | break; | |
8573 | } | |
8574 | ||
8575 | if (atomic_read(&phba->fabric_iocb_count) == 0) | |
8576 | BUG(); | |
8577 | ||
8578 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; | |
8579 | cmdiocb->fabric_iocb_cmpl = NULL; | |
8580 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
8581 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); | |
8582 | ||
8583 | atomic_dec(&phba->fabric_iocb_count); | |
8584 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { | |
7f5f3d0d JS |
8585 | /* Post any pending iocbs to HBA */ |
8586 | lpfc_resume_fabric_iocbs(phba); | |
92d7f7b0 JS |
8587 | } |
8588 | } | |
8589 | ||
e59058c4 | 8590 | /** |
3621a710 | 8591 | * lpfc_issue_fabric_iocb - Issue a fabric iocb command |
e59058c4 JS |
8592 | * @phba: pointer to lpfc hba data structure. |
8593 | * @iocb: pointer to lpfc command iocb data structure. | |
8594 | * | |
8595 | * This routine is used as the top-level API for issuing a fabric iocb command | |
8596 | * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver | |
8597 | * function makes sure that only one fabric bound iocb will be outstanding at | |
8598 | * any given time. As such, this function will first check to see whether there | |
8599 | * is already an outstanding fabric iocb on the wire. If so, it will put the | |
8600 | * newly issued iocb onto the driver internal fabric iocb list, waiting to be | |
8601 | * issued later. Otherwise, it will issue the iocb on the wire and update the | |
8602 | * fabric iocb count it indicate that there is one fabric iocb on the wire. | |
8603 | * | |
8604 | * Note, this implementation has a potential sending out fabric IOCBs out of | |
8605 | * order. The problem is caused by the construction of the "ready" boolen does | |
8606 | * not include the condition that the internal fabric IOCB list is empty. As | |
8607 | * such, it is possible a fabric IOCB issued by this routine might be "jump" | |
8608 | * ahead of the fabric IOCBs in the internal list. | |
8609 | * | |
8610 | * Return code | |
8611 | * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully | |
8612 | * IOCB_ERROR - failed to issue fabric iocb | |
8613 | **/ | |
a6ababd2 | 8614 | static int |
92d7f7b0 JS |
8615 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
8616 | { | |
8617 | unsigned long iflags; | |
92d7f7b0 JS |
8618 | int ready; |
8619 | int ret; | |
8620 | ||
8621 | if (atomic_read(&phba->fabric_iocb_count) > 1) | |
8622 | BUG(); | |
8623 | ||
8624 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8625 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && | |
8626 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
8627 | ||
7f5f3d0d JS |
8628 | if (ready) |
8629 | /* Increment fabric iocb count to hold the position */ | |
8630 | atomic_inc(&phba->fabric_iocb_count); | |
92d7f7b0 JS |
8631 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
8632 | if (ready) { | |
8633 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
8634 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
8635 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
8636 | ||
858c9f6c JS |
8637 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
8638 | "Fabric sched2: ste:x%x", | |
8639 | iocb->vport->port_state, 0, 0); | |
8640 | ||
3772a991 | 8641 | ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); |
92d7f7b0 JS |
8642 | |
8643 | if (ret == IOCB_ERROR) { | |
8644 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
8645 | iocb->fabric_iocb_cmpl = NULL; | |
8646 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
8647 | atomic_dec(&phba->fabric_iocb_count); | |
8648 | } | |
8649 | } else { | |
8650 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8651 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); | |
8652 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8653 | ret = IOCB_SUCCESS; | |
8654 | } | |
8655 | return ret; | |
8656 | } | |
8657 | ||
e59058c4 | 8658 | /** |
3621a710 | 8659 | * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list |
e59058c4 JS |
8660 | * @vport: pointer to a virtual N_Port data structure. |
8661 | * | |
8662 | * This routine aborts all the IOCBs associated with a @vport from the | |
8663 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | |
8664 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | |
8665 | * list, removes each IOCB associated with the @vport off the list, set the | |
8666 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | |
8667 | * associated with the IOCB. | |
8668 | **/ | |
a6ababd2 | 8669 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
92d7f7b0 JS |
8670 | { |
8671 | LIST_HEAD(completions); | |
8672 | struct lpfc_hba *phba = vport->phba; | |
8673 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
92d7f7b0 JS |
8674 | |
8675 | spin_lock_irq(&phba->hbalock); | |
8676 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
8677 | list) { | |
8678 | ||
8679 | if (piocb->vport != vport) | |
8680 | continue; | |
8681 | ||
8682 | list_move_tail(&piocb->list, &completions); | |
8683 | } | |
8684 | spin_unlock_irq(&phba->hbalock); | |
8685 | ||
a257bf90 JS |
8686 | /* Cancel all the IOCBs from the completions list */ |
8687 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8688 | IOERR_SLI_ABORTED); | |
92d7f7b0 JS |
8689 | } |
8690 | ||
e59058c4 | 8691 | /** |
3621a710 | 8692 | * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list |
e59058c4 JS |
8693 | * @ndlp: pointer to a node-list data structure. |
8694 | * | |
8695 | * This routine aborts all the IOCBs associated with an @ndlp from the | |
8696 | * driver internal fabric IOCB list. The list contains fabric IOCBs to be | |
8697 | * issued to the ELS IOCB ring. This abort function walks the fabric IOCB | |
8698 | * list, removes each IOCB associated with the @ndlp off the list, set the | |
8699 | * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function | |
8700 | * associated with the IOCB. | |
8701 | **/ | |
92d7f7b0 JS |
8702 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
8703 | { | |
8704 | LIST_HEAD(completions); | |
a257bf90 | 8705 | struct lpfc_hba *phba = ndlp->phba; |
92d7f7b0 JS |
8706 | struct lpfc_iocbq *tmp_iocb, *piocb; |
8707 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
92d7f7b0 JS |
8708 | |
8709 | spin_lock_irq(&phba->hbalock); | |
8710 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
8711 | list) { | |
8712 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { | |
8713 | ||
8714 | list_move_tail(&piocb->list, &completions); | |
ed957684 | 8715 | } |
dea3101e | 8716 | } |
92d7f7b0 JS |
8717 | spin_unlock_irq(&phba->hbalock); |
8718 | ||
a257bf90 JS |
8719 | /* Cancel all the IOCBs from the completions list */ |
8720 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8721 | IOERR_SLI_ABORTED); | |
92d7f7b0 JS |
8722 | } |
8723 | ||
e59058c4 | 8724 | /** |
3621a710 | 8725 | * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list |
e59058c4 JS |
8726 | * @phba: pointer to lpfc hba data structure. |
8727 | * | |
8728 | * This routine aborts all the IOCBs currently on the driver internal | |
8729 | * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS | |
8730 | * IOCB ring. This function takes the entire IOCB list off the fabric IOCB | |
8731 | * list, removes IOCBs off the list, set the status feild to | |
8732 | * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with | |
8733 | * the IOCB. | |
8734 | **/ | |
92d7f7b0 JS |
8735 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
8736 | { | |
8737 | LIST_HEAD(completions); | |
92d7f7b0 JS |
8738 | |
8739 | spin_lock_irq(&phba->hbalock); | |
8740 | list_splice_init(&phba->fabric_iocb_list, &completions); | |
8741 | spin_unlock_irq(&phba->hbalock); | |
8742 | ||
a257bf90 JS |
8743 | /* Cancel all the IOCBs from the completions list */ |
8744 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8745 | IOERR_SLI_ABORTED); | |
dea3101e | 8746 | } |
6fb120a7 | 8747 | |
1151e3ec JS |
8748 | /** |
8749 | * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport | |
8750 | * @vport: pointer to lpfc vport data structure. | |
8751 | * | |
8752 | * This routine is invoked by the vport cleanup for deletions and the cleanup | |
8753 | * for an ndlp on removal. | |
8754 | **/ | |
8755 | void | |
8756 | lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) | |
8757 | { | |
8758 | struct lpfc_hba *phba = vport->phba; | |
8759 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | |
8760 | unsigned long iflag = 0; | |
8761 | ||
8762 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8763 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
8764 | list_for_each_entry_safe(sglq_entry, sglq_next, | |
8765 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | |
8766 | if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) | |
8767 | sglq_entry->ndlp = NULL; | |
8768 | } | |
8769 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
8770 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8771 | return; | |
8772 | } | |
8773 | ||
6fb120a7 JS |
8774 | /** |
8775 | * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort | |
8776 | * @phba: pointer to lpfc hba data structure. | |
8777 | * @axri: pointer to the els xri abort wcqe structure. | |
8778 | * | |
8779 | * This routine is invoked by the worker thread to process a SLI4 slow-path | |
8780 | * ELS aborted xri. | |
8781 | **/ | |
8782 | void | |
8783 | lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, | |
8784 | struct sli4_wcqe_xri_aborted *axri) | |
8785 | { | |
8786 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | |
19ca7609 | 8787 | uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); |
7851fe2c | 8788 | uint16_t lxri = 0; |
19ca7609 | 8789 | |
6fb120a7 JS |
8790 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
8791 | unsigned long iflag = 0; | |
19ca7609 | 8792 | struct lpfc_nodelist *ndlp; |
589a52d6 | 8793 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
6fb120a7 | 8794 | |
0f65ff68 JS |
8795 | spin_lock_irqsave(&phba->hbalock, iflag); |
8796 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
6fb120a7 JS |
8797 | list_for_each_entry_safe(sglq_entry, sglq_next, |
8798 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { | |
8799 | if (sglq_entry->sli4_xritag == xri) { | |
8800 | list_del(&sglq_entry->list); | |
19ca7609 JS |
8801 | ndlp = sglq_entry->ndlp; |
8802 | sglq_entry->ndlp = NULL; | |
dafe8cea | 8803 | spin_lock(&pring->ring_lock); |
6fb120a7 JS |
8804 | list_add_tail(&sglq_entry->list, |
8805 | &phba->sli4_hba.lpfc_sgl_list); | |
0f65ff68 | 8806 | sglq_entry->state = SGL_FREED; |
dafe8cea | 8807 | spin_unlock(&pring->ring_lock); |
0f65ff68 | 8808 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
6fb120a7 | 8809 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
ee0f4fe1 JS |
8810 | lpfc_set_rrq_active(phba, ndlp, |
8811 | sglq_entry->sli4_lxritag, | |
8812 | rxid, 1); | |
589a52d6 JS |
8813 | |
8814 | /* Check if TXQ queue needs to be serviced */ | |
0e9bb8d7 | 8815 | if (!(list_empty(&pring->txq))) |
589a52d6 | 8816 | lpfc_worker_wake_up(phba); |
6fb120a7 JS |
8817 | return; |
8818 | } | |
8819 | } | |
0f65ff68 | 8820 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); |
7851fe2c JS |
8821 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
8822 | if (lxri == NO_XRI) { | |
8823 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8824 | return; | |
8825 | } | |
dafe8cea | 8826 | spin_lock(&pring->ring_lock); |
7851fe2c | 8827 | sglq_entry = __lpfc_get_active_sglq(phba, lxri); |
0f65ff68 | 8828 | if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { |
dafe8cea | 8829 | spin_unlock(&pring->ring_lock); |
0f65ff68 JS |
8830 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
8831 | return; | |
8832 | } | |
8833 | sglq_entry->state = SGL_XRI_ABORTED; | |
dafe8cea | 8834 | spin_unlock(&pring->ring_lock); |
0f65ff68 JS |
8835 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
8836 | return; | |
6fb120a7 | 8837 | } |
086a345f JS |
8838 | |
8839 | /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. | |
8840 | * @vport: pointer to virtual port object. | |
8841 | * @ndlp: nodelist pointer for the impacted node. | |
8842 | * | |
8843 | * The driver calls this routine in response to an SLI4 XRI ABORT CQE | |
8844 | * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, | |
8845 | * the driver is required to send a LOGO to the remote node before it | |
8846 | * attempts to recover its login to the remote node. | |
8847 | */ | |
8848 | void | |
8849 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, | |
8850 | struct lpfc_nodelist *ndlp) | |
8851 | { | |
8852 | struct Scsi_Host *shost; | |
8853 | struct lpfc_hba *phba; | |
8854 | unsigned long flags = 0; | |
8855 | ||
8856 | shost = lpfc_shost_from_vport(vport); | |
8857 | phba = vport->phba; | |
8858 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { | |
8859 | lpfc_printf_log(phba, KERN_INFO, | |
8860 | LOG_SLI, "3093 No rport recovery needed. " | |
8861 | "rport in state 0x%x\n", ndlp->nlp_state); | |
8862 | return; | |
8863 | } | |
8864 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8865 | "3094 Start rport recovery on shost id 0x%x " | |
8866 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " | |
8867 | "flags 0x%x\n", | |
8868 | shost->host_no, ndlp->nlp_DID, | |
8869 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, | |
8870 | ndlp->nlp_flag); | |
8871 | /* | |
8872 | * The rport is not responding. Remove the FCP-2 flag to prevent | |
8873 | * an ADISC in the follow-up recovery code. | |
8874 | */ | |
8875 | spin_lock_irqsave(shost->host_lock, flags); | |
8876 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
8877 | spin_unlock_irqrestore(shost->host_lock, flags); | |
8878 | lpfc_issue_els_logo(vport, ndlp, 0); | |
8879 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); | |
8880 | } | |
8881 |