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