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