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