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