]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
e47c9093 | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
09372820 | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ |
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | ||
91886523 | 26 | #include <scsi/scsi.h> |
dea3101e JB |
27 | #include <scsi/scsi_device.h> |
28 | #include <scsi/scsi_host.h> | |
29 | #include <scsi/scsi_transport_fc.h> | |
30 | ||
31 | #include "lpfc_hw.h" | |
32 | #include "lpfc_sli.h" | |
33 | #include "lpfc_disc.h" | |
34 | #include "lpfc_scsi.h" | |
35 | #include "lpfc.h" | |
36 | #include "lpfc_logmsg.h" | |
37 | #include "lpfc_crtn.h" | |
92d7f7b0 | 38 | #include "lpfc_vport.h" |
858c9f6c | 39 | #include "lpfc_debugfs.h" |
dea3101e JB |
40 | |
41 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, | |
42 | struct lpfc_iocbq *); | |
92d7f7b0 JS |
43 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
44 | struct lpfc_iocbq *); | |
a6ababd2 AB |
45 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
46 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, | |
47 | struct lpfc_nodelist *ndlp, uint8_t retry); | |
48 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, | |
49 | struct lpfc_iocbq *iocb); | |
50 | static void lpfc_register_new_vport(struct lpfc_hba *phba, | |
51 | struct lpfc_vport *vport, | |
52 | struct lpfc_nodelist *ndlp); | |
92d7f7b0 | 53 | |
dea3101e JB |
54 | static int lpfc_max_els_tries = 3; |
55 | ||
858c9f6c | 56 | int |
2e0fef85 | 57 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
dea3101e | 58 | { |
2e0fef85 JS |
59 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
60 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 61 | uint32_t ha_copy; |
dea3101e | 62 | |
2e0fef85 JS |
63 | if (vport->port_state >= LPFC_VPORT_READY || |
64 | phba->link_state == LPFC_LINK_DOWN) | |
dea3101e JB |
65 | return 0; |
66 | ||
67 | /* Read the HBA Host Attention Register */ | |
dea3101e | 68 | ha_copy = readl(phba->HAregaddr); |
dea3101e JB |
69 | |
70 | if (!(ha_copy & HA_LATT)) | |
71 | return 0; | |
72 | ||
73 | /* Pending Link Event during Discovery */ | |
e8b62011 JS |
74 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
75 | "0237 Pending Link Event during " | |
76 | "Discovery: State x%x\n", | |
77 | phba->pport->port_state); | |
dea3101e JB |
78 | |
79 | /* CLEAR_LA should re-enable link attention events and | |
80 | * we should then imediately take a LATT event. The | |
81 | * LATT processing should call lpfc_linkdown() which | |
82 | * will cleanup any left over in-progress discovery | |
83 | * events. | |
84 | */ | |
2e0fef85 JS |
85 | spin_lock_irq(shost->host_lock); |
86 | vport->fc_flag |= FC_ABORT_DISCOVERY; | |
87 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 88 | |
92d7f7b0 | 89 | if (phba->link_state != LPFC_CLEAR_LA) |
ed957684 | 90 | lpfc_issue_clear_la(phba, vport); |
dea3101e | 91 | |
c9f8735b | 92 | return 1; |
dea3101e JB |
93 | } |
94 | ||
95 | static struct lpfc_iocbq * | |
2e0fef85 JS |
96 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
97 | uint16_t cmdSize, uint8_t retry, | |
98 | struct lpfc_nodelist *ndlp, uint32_t did, | |
99 | uint32_t elscmd) | |
dea3101e | 100 | { |
2e0fef85 | 101 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 | 102 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
103 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
104 | struct ulp_bde64 *bpl; | |
105 | IOCB_t *icmd; | |
106 | ||
dea3101e | 107 | |
2e0fef85 JS |
108 | if (!lpfc_is_link_up(phba)) |
109 | return NULL; | |
dea3101e | 110 | |
dea3101e | 111 | /* Allocate buffer for command iocb */ |
0bd4ca25 | 112 | elsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
113 | |
114 | if (elsiocb == NULL) | |
115 | return NULL; | |
e47c9093 | 116 | |
dea3101e JB |
117 | icmd = &elsiocb->iocb; |
118 | ||
119 | /* fill in BDEs for command */ | |
120 | /* Allocate buffer for command payload */ | |
98c9ea5c JS |
121 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
122 | if (pcmd) | |
123 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); | |
fa4066b6 JS |
124 | if (!pcmd || !pcmd->virt) |
125 | goto els_iocb_free_pcmb_exit; | |
dea3101e JB |
126 | |
127 | INIT_LIST_HEAD(&pcmd->list); | |
128 | ||
129 | /* Allocate buffer for response payload */ | |
130 | if (expectRsp) { | |
92d7f7b0 | 131 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e JB |
132 | if (prsp) |
133 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
134 | &prsp->phys); | |
fa4066b6 JS |
135 | if (!prsp || !prsp->virt) |
136 | goto els_iocb_free_prsp_exit; | |
dea3101e | 137 | INIT_LIST_HEAD(&prsp->list); |
e47c9093 | 138 | } else |
dea3101e | 139 | prsp = NULL; |
dea3101e JB |
140 | |
141 | /* Allocate buffer for Buffer ptr list */ | |
92d7f7b0 | 142 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e | 143 | if (pbuflist) |
ed957684 JS |
144 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
145 | &pbuflist->phys); | |
fa4066b6 JS |
146 | if (!pbuflist || !pbuflist->virt) |
147 | goto els_iocb_free_pbuf_exit; | |
dea3101e JB |
148 | |
149 | INIT_LIST_HEAD(&pbuflist->list); | |
150 | ||
151 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); | |
152 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); | |
153 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; | |
2e0fef85 | 154 | icmd->un.elsreq64.remoteID = did; /* DID */ |
dea3101e | 155 | if (expectRsp) { |
92d7f7b0 | 156 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
dea3101e | 157 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
2680eeaa | 158 | icmd->ulpTimeout = phba->fc_ratov * 2; |
dea3101e | 159 | } else { |
92d7f7b0 | 160 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
dea3101e JB |
161 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
162 | } | |
dea3101e JB |
163 | icmd->ulpBdeCount = 1; |
164 | icmd->ulpLe = 1; | |
165 | icmd->ulpClass = CLASS3; | |
166 | ||
92d7f7b0 JS |
167 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
168 | icmd->un.elsreq64.myID = vport->fc_myDID; | |
169 | ||
170 | /* For ELS_REQUEST64_CR, use the VPI by default */ | |
171 | icmd->ulpContext = vport->vpi; | |
172 | icmd->ulpCt_h = 0; | |
173 | icmd->ulpCt_l = 1; | |
174 | } | |
175 | ||
dea3101e JB |
176 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
177 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); | |
178 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); | |
179 | bpl->tus.f.bdeSize = cmdSize; | |
180 | bpl->tus.f.bdeFlags = 0; | |
181 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
182 | ||
183 | if (expectRsp) { | |
184 | bpl++; | |
185 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); | |
186 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); | |
187 | bpl->tus.f.bdeSize = FCELSSIZE; | |
188 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; | |
189 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
190 | } | |
191 | ||
fa4066b6 | 192 | /* prevent preparing iocb with NULL ndlp reference */ |
51ef4c26 | 193 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
fa4066b6 JS |
194 | if (!elsiocb->context1) |
195 | goto els_iocb_free_pbuf_exit; | |
329f9bc7 JS |
196 | elsiocb->context2 = pcmd; |
197 | elsiocb->context3 = pbuflist; | |
dea3101e | 198 | elsiocb->retry = retry; |
2e0fef85 | 199 | elsiocb->vport = vport; |
dea3101e JB |
200 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
201 | ||
202 | if (prsp) { | |
203 | list_add(&prsp->list, &pcmd->list); | |
204 | } | |
dea3101e JB |
205 | if (expectRsp) { |
206 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
207 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
208 | "0116 Xmit ELS command x%x to remote " | |
209 | "NPORT x%x I/O tag: x%x, port state: x%x\n", | |
210 | elscmd, did, elsiocb->iotag, | |
211 | vport->port_state); | |
dea3101e JB |
212 | } else { |
213 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
214 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
215 | "0117 Xmit ELS response x%x to remote " | |
216 | "NPORT x%x I/O tag: x%x, size: x%x\n", | |
217 | elscmd, ndlp->nlp_DID, elsiocb->iotag, | |
218 | cmdSize); | |
dea3101e | 219 | } |
c9f8735b | 220 | return elsiocb; |
dea3101e | 221 | |
fa4066b6 JS |
222 | els_iocb_free_pbuf_exit: |
223 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); | |
224 | kfree(pbuflist); | |
225 | ||
226 | els_iocb_free_prsp_exit: | |
227 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); | |
228 | kfree(prsp); | |
229 | ||
230 | els_iocb_free_pcmb_exit: | |
231 | kfree(pcmd); | |
232 | lpfc_sli_release_iocbq(phba, elsiocb); | |
233 | return NULL; | |
234 | } | |
dea3101e JB |
235 | |
236 | static int | |
92d7f7b0 | 237 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
dea3101e | 238 | { |
2e0fef85 | 239 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 240 | LPFC_MBOXQ_t *mbox; |
14691150 | 241 | struct lpfc_dmabuf *mp; |
92d7f7b0 JS |
242 | struct lpfc_nodelist *ndlp; |
243 | struct serv_parm *sp; | |
dea3101e | 244 | int rc; |
98c9ea5c | 245 | int err = 0; |
dea3101e | 246 | |
92d7f7b0 JS |
247 | sp = &phba->fc_fabparam; |
248 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
e47c9093 | 249 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
98c9ea5c | 250 | err = 1; |
92d7f7b0 | 251 | goto fail; |
98c9ea5c | 252 | } |
92d7f7b0 JS |
253 | |
254 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
255 | if (!mbox) { |
256 | err = 2; | |
92d7f7b0 | 257 | goto fail; |
98c9ea5c | 258 | } |
92d7f7b0 JS |
259 | |
260 | vport->port_state = LPFC_FABRIC_CFG_LINK; | |
261 | lpfc_config_link(phba, mbox); | |
262 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
263 | mbox->vport = vport; | |
264 | ||
0b727fea | 265 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
266 | if (rc == MBX_NOT_FINISHED) { |
267 | err = 3; | |
92d7f7b0 | 268 | goto fail_free_mbox; |
98c9ea5c | 269 | } |
92d7f7b0 JS |
270 | |
271 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
98c9ea5c JS |
272 | if (!mbox) { |
273 | err = 4; | |
92d7f7b0 | 274 | goto fail; |
98c9ea5c | 275 | } |
92d7f7b0 JS |
276 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
277 | 0); | |
98c9ea5c JS |
278 | if (rc) { |
279 | err = 5; | |
92d7f7b0 | 280 | goto fail_free_mbox; |
98c9ea5c | 281 | } |
92d7f7b0 JS |
282 | |
283 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; | |
284 | mbox->vport = vport; | |
e47c9093 JS |
285 | /* increment the reference count on ndlp to hold reference |
286 | * for the callback routine. | |
287 | */ | |
92d7f7b0 JS |
288 | mbox->context2 = lpfc_nlp_get(ndlp); |
289 | ||
0b727fea | 290 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
98c9ea5c JS |
291 | if (rc == MBX_NOT_FINISHED) { |
292 | err = 6; | |
92d7f7b0 | 293 | goto fail_issue_reg_login; |
98c9ea5c | 294 | } |
92d7f7b0 JS |
295 | |
296 | return 0; | |
297 | ||
298 | fail_issue_reg_login: | |
e47c9093 JS |
299 | /* decrement the reference count on ndlp just incremented |
300 | * for the failed mbox command. | |
301 | */ | |
92d7f7b0 JS |
302 | lpfc_nlp_put(ndlp); |
303 | mp = (struct lpfc_dmabuf *) mbox->context1; | |
304 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
305 | kfree(mp); | |
306 | fail_free_mbox: | |
307 | mempool_free(mbox, phba->mbox_mem_pool); | |
308 | ||
309 | fail: | |
310 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 | 311 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
98c9ea5c | 312 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
92d7f7b0 JS |
313 | return -ENXIO; |
314 | } | |
315 | ||
316 | static int | |
317 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
318 | struct serv_parm *sp, IOCB_t *irsp) | |
319 | { | |
320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
321 | struct lpfc_hba *phba = vport->phba; | |
322 | struct lpfc_nodelist *np; | |
323 | struct lpfc_nodelist *next_np; | |
324 | ||
2e0fef85 JS |
325 | spin_lock_irq(shost->host_lock); |
326 | vport->fc_flag |= FC_FABRIC; | |
327 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
328 | |
329 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); | |
330 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ | |
331 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; | |
332 | ||
333 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; | |
334 | ||
335 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
2e0fef85 JS |
336 | spin_lock_irq(shost->host_lock); |
337 | vport->fc_flag |= FC_PUBLIC_LOOP; | |
338 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
339 | } else { |
340 | /* | |
341 | * If we are a N-port connected to a Fabric, fixup sparam's so | |
342 | * logins to devices on remote loops work. | |
343 | */ | |
2e0fef85 | 344 | vport->fc_sparam.cmn.altBbCredit = 1; |
dea3101e JB |
345 | } |
346 | ||
2e0fef85 | 347 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
dea3101e | 348 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
92d7f7b0 | 349 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
dea3101e JB |
350 | ndlp->nlp_class_sup = 0; |
351 | if (sp->cls1.classValid) | |
352 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
353 | if (sp->cls2.classValid) | |
354 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
355 | if (sp->cls3.classValid) | |
356 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
357 | if (sp->cls4.classValid) | |
358 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
359 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | | |
360 | sp->cmn.bbRcvSizeLsb; | |
361 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); | |
362 | ||
92d7f7b0 JS |
363 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
364 | if (sp->cmn.response_multiple_NPort) { | |
e8b62011 JS |
365 | lpfc_printf_vlog(vport, KERN_WARNING, |
366 | LOG_ELS | LOG_VPORT, | |
367 | "1816 FLOGI NPIV supported, " | |
368 | "response data 0x%x\n", | |
369 | sp->cmn.response_multiple_NPort); | |
92d7f7b0 | 370 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
92d7f7b0 JS |
371 | } else { |
372 | /* Because we asked f/w for NPIV it still expects us | |
e8b62011 JS |
373 | to call reg_vnpid atleast for the physcial host */ |
374 | lpfc_printf_vlog(vport, KERN_WARNING, | |
375 | LOG_ELS | LOG_VPORT, | |
376 | "1817 Fabric does not support NPIV " | |
377 | "- configuring single port mode.\n"); | |
92d7f7b0 JS |
378 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
379 | } | |
380 | } | |
dea3101e | 381 | |
92d7f7b0 JS |
382 | if ((vport->fc_prevDID != vport->fc_myDID) && |
383 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
dea3101e | 384 | |
92d7f7b0 JS |
385 | /* If our NportID changed, we need to ensure all |
386 | * remaining NPORTs get unreg_login'ed. | |
387 | */ | |
388 | list_for_each_entry_safe(np, next_np, | |
389 | &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
390 | if (!NLP_CHK_NODE_ACT(ndlp)) |
391 | continue; | |
92d7f7b0 JS |
392 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
393 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
394 | continue; | |
395 | spin_lock_irq(shost->host_lock); | |
396 | np->nlp_flag &= ~NLP_NPR_ADISC; | |
397 | spin_unlock_irq(shost->host_lock); | |
398 | lpfc_unreg_rpi(vport, np); | |
399 | } | |
400 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { | |
401 | lpfc_mbx_unreg_vpi(vport); | |
09372820 | 402 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 403 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 404 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
405 | } |
406 | } | |
dea3101e | 407 | |
92d7f7b0 | 408 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
dea3101e | 409 | |
92d7f7b0 JS |
410 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
411 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { | |
412 | lpfc_register_new_vport(phba, vport, ndlp); | |
413 | return 0; | |
414 | } | |
415 | lpfc_issue_fabric_reglogin(vport); | |
dea3101e | 416 | return 0; |
dea3101e JB |
417 | } |
418 | ||
419 | /* | |
420 | * We FLOGIed into an NPort, initiate pt2pt protocol | |
421 | */ | |
422 | static int | |
2e0fef85 JS |
423 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
424 | struct serv_parm *sp) | |
dea3101e | 425 | { |
2e0fef85 JS |
426 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
427 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
428 | LPFC_MBOXQ_t *mbox; |
429 | int rc; | |
430 | ||
2e0fef85 JS |
431 | spin_lock_irq(shost->host_lock); |
432 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
433 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
434 | |
435 | phba->fc_edtov = FF_DEF_EDTOV; | |
436 | phba->fc_ratov = FF_DEF_RATOV; | |
2e0fef85 | 437 | rc = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 438 | sizeof(vport->fc_portname)); |
dea3101e JB |
439 | if (rc >= 0) { |
440 | /* This side will initiate the PLOGI */ | |
2e0fef85 JS |
441 | spin_lock_irq(shost->host_lock); |
442 | vport->fc_flag |= FC_PT2PT_PLOGI; | |
443 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
444 | |
445 | /* | |
446 | * N_Port ID cannot be 0, set our to LocalID the other | |
447 | * side will be RemoteID. | |
448 | */ | |
449 | ||
450 | /* not equal */ | |
451 | if (rc) | |
2e0fef85 | 452 | vport->fc_myDID = PT2PT_LocalID; |
dea3101e JB |
453 | |
454 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
455 | if (!mbox) | |
456 | goto fail; | |
457 | ||
458 | lpfc_config_link(phba, mbox); | |
459 | ||
460 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
ed957684 | 461 | mbox->vport = vport; |
0b727fea | 462 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
dea3101e JB |
463 | if (rc == MBX_NOT_FINISHED) { |
464 | mempool_free(mbox, phba->mbox_mem_pool); | |
465 | goto fail; | |
466 | } | |
e47c9093 JS |
467 | /* Decrement ndlp reference count indicating that ndlp can be |
468 | * safely released when other references to it are done. | |
469 | */ | |
329f9bc7 | 470 | lpfc_nlp_put(ndlp); |
dea3101e | 471 | |
2e0fef85 | 472 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
dea3101e JB |
473 | if (!ndlp) { |
474 | /* | |
475 | * Cannot find existing Fabric ndlp, so allocate a | |
476 | * new one | |
477 | */ | |
478 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
479 | if (!ndlp) | |
480 | goto fail; | |
2e0fef85 | 481 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
e47c9093 JS |
482 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
483 | ndlp = lpfc_enable_node(vport, ndlp, | |
484 | NLP_STE_UNUSED_NODE); | |
485 | if(!ndlp) | |
486 | goto fail; | |
dea3101e JB |
487 | } |
488 | ||
489 | memcpy(&ndlp->nlp_portname, &sp->portName, | |
2e0fef85 | 490 | sizeof(struct lpfc_name)); |
dea3101e | 491 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
2e0fef85 | 492 | sizeof(struct lpfc_name)); |
e47c9093 | 493 | /* Set state will put ndlp onto node list if not already done */ |
2e0fef85 JS |
494 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
495 | spin_lock_irq(shost->host_lock); | |
dea3101e | 496 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 497 | spin_unlock_irq(shost->host_lock); |
e47c9093 JS |
498 | } else |
499 | /* This side will wait for the PLOGI, decrement ndlp reference | |
500 | * count indicating that ndlp can be released when other | |
501 | * references to it are done. | |
502 | */ | |
329f9bc7 | 503 | lpfc_nlp_put(ndlp); |
dea3101e | 504 | |
09372820 JS |
505 | /* If we are pt2pt with another NPort, force NPIV off! */ |
506 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; | |
507 | ||
2e0fef85 JS |
508 | spin_lock_irq(shost->host_lock); |
509 | vport->fc_flag |= FC_PT2PT; | |
510 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
511 | |
512 | /* Start discovery - this should just do CLEAR_LA */ | |
2e0fef85 | 513 | lpfc_disc_start(vport); |
dea3101e | 514 | return 0; |
92d7f7b0 | 515 | fail: |
dea3101e JB |
516 | return -ENXIO; |
517 | } | |
518 | ||
519 | static void | |
329f9bc7 JS |
520 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
521 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 522 | { |
2e0fef85 JS |
523 | struct lpfc_vport *vport = cmdiocb->vport; |
524 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e JB |
525 | IOCB_t *irsp = &rspiocb->iocb; |
526 | struct lpfc_nodelist *ndlp = cmdiocb->context1; | |
527 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; | |
528 | struct serv_parm *sp; | |
529 | int rc; | |
530 | ||
531 | /* Check to see if link went down during discovery */ | |
2e0fef85 | 532 | if (lpfc_els_chk_latt(vport)) { |
fa4066b6 JS |
533 | /* One additional decrement on node reference count to |
534 | * trigger the release of the node | |
535 | */ | |
329f9bc7 | 536 | lpfc_nlp_put(ndlp); |
dea3101e JB |
537 | goto out; |
538 | } | |
539 | ||
858c9f6c JS |
540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
541 | "FLOGI cmpl: status:x%x/x%x state:x%x", | |
542 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
543 | vport->port_state); | |
544 | ||
dea3101e JB |
545 | if (irsp->ulpStatus) { |
546 | /* Check for retry */ | |
2e0fef85 | 547 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
dea3101e | 548 | goto out; |
2e0fef85 | 549 | |
dea3101e | 550 | /* FLOGI failed, so there is no fabric */ |
2e0fef85 JS |
551 | spin_lock_irq(shost->host_lock); |
552 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
553 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 554 | |
329f9bc7 | 555 | /* If private loop, then allow max outstanding els to be |
dea3101e JB |
556 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
557 | * alpa map would take too long otherwise. | |
558 | */ | |
559 | if (phba->alpa_map[0] == 0) { | |
3de2a653 | 560 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
dea3101e JB |
561 | } |
562 | ||
563 | /* FLOGI failure */ | |
e8b62011 JS |
564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
565 | "0100 FLOGI failure Data: x%x x%x " | |
566 | "x%x\n", | |
567 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
568 | irsp->ulpTimeout); | |
dea3101e JB |
569 | goto flogifail; |
570 | } | |
571 | ||
572 | /* | |
573 | * The FLogI succeeded. Sync the data for the CPU before | |
574 | * accessing it. | |
575 | */ | |
576 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); | |
577 | ||
578 | sp = prsp->virt + sizeof(uint32_t); | |
579 | ||
580 | /* FLOGI completes successfully */ | |
e8b62011 JS |
581 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
582 | "0101 FLOGI completes sucessfully " | |
583 | "Data: x%x x%x x%x x%x\n", | |
584 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, | |
585 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); | |
dea3101e | 586 | |
2e0fef85 | 587 | if (vport->port_state == LPFC_FLOGI) { |
dea3101e JB |
588 | /* |
589 | * If Common Service Parameters indicate Nport | |
590 | * we are point to point, if Fport we are Fabric. | |
591 | */ | |
592 | if (sp->cmn.fPort) | |
2e0fef85 | 593 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
dea3101e | 594 | else |
2e0fef85 | 595 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
dea3101e JB |
596 | |
597 | if (!rc) | |
598 | goto out; | |
599 | } | |
600 | ||
601 | flogifail: | |
329f9bc7 | 602 | lpfc_nlp_put(ndlp); |
dea3101e | 603 | |
858c9f6c | 604 | if (!lpfc_error_lost_link(irsp)) { |
dea3101e | 605 | /* FLOGI failed, so just use loop map to make discovery list */ |
2e0fef85 | 606 | lpfc_disc_list_loopmap(vport); |
dea3101e JB |
607 | |
608 | /* Start discovery */ | |
2e0fef85 | 609 | lpfc_disc_start(vport); |
87af33fe JS |
610 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
611 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && | |
612 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && | |
613 | (phba->link_state != LPFC_CLEAR_LA)) { | |
614 | /* If FLOGI failed enable link interrupt. */ | |
615 | lpfc_issue_clear_la(phba, vport); | |
dea3101e | 616 | } |
dea3101e JB |
617 | out: |
618 | lpfc_els_free_iocb(phba, cmdiocb); | |
619 | } | |
620 | ||
621 | static int | |
2e0fef85 | 622 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
623 | uint8_t retry) |
624 | { | |
2e0fef85 | 625 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
626 | struct serv_parm *sp; |
627 | IOCB_t *icmd; | |
628 | struct lpfc_iocbq *elsiocb; | |
629 | struct lpfc_sli_ring *pring; | |
630 | uint8_t *pcmd; | |
631 | uint16_t cmdsize; | |
632 | uint32_t tmo; | |
633 | int rc; | |
634 | ||
635 | pring = &phba->sli.ring[LPFC_ELS_RING]; | |
636 | ||
92d7f7b0 | 637 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
2e0fef85 JS |
638 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
639 | ndlp->nlp_DID, ELS_CMD_FLOGI); | |
92d7f7b0 | 640 | |
488d1469 | 641 | if (!elsiocb) |
c9f8735b | 642 | return 1; |
dea3101e JB |
643 | |
644 | icmd = &elsiocb->iocb; | |
645 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
646 | ||
647 | /* For FLOGI request, remainder of payload is service parameters */ | |
648 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; | |
92d7f7b0 JS |
649 | pcmd += sizeof(uint32_t); |
650 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
651 | sp = (struct serv_parm *) pcmd; |
652 | ||
653 | /* Setup CSPs accordingly for Fabric */ | |
654 | sp->cmn.e_d_tov = 0; | |
655 | sp->cmn.w2.r_a_tov = 0; | |
656 | sp->cls1.classValid = 0; | |
657 | sp->cls2.seqDelivery = 1; | |
658 | sp->cls3.seqDelivery = 1; | |
659 | if (sp->cmn.fcphLow < FC_PH3) | |
660 | sp->cmn.fcphLow = FC_PH3; | |
661 | if (sp->cmn.fcphHigh < FC_PH3) | |
662 | sp->cmn.fcphHigh = FC_PH3; | |
663 | ||
92d7f7b0 JS |
664 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
665 | sp->cmn.request_multiple_Nport = 1; | |
666 | ||
667 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ | |
668 | icmd->ulpCt_h = 1; | |
669 | icmd->ulpCt_l = 0; | |
670 | } | |
671 | ||
858c9f6c JS |
672 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
673 | icmd->un.elsreq64.myID = 0; | |
674 | icmd->un.elsreq64.fl = 1; | |
675 | } | |
676 | ||
dea3101e JB |
677 | tmo = phba->fc_ratov; |
678 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; | |
2e0fef85 | 679 | lpfc_set_disctmo(vport); |
dea3101e JB |
680 | phba->fc_ratov = tmo; |
681 | ||
682 | phba->fc_stat.elsXmitFLOGI++; | |
683 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; | |
858c9f6c JS |
684 | |
685 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
686 | "Issue FLOGI: opt:x%x", | |
687 | phba->sli3_options, 0, 0); | |
688 | ||
92d7f7b0 | 689 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
dea3101e JB |
690 | if (rc == IOCB_ERROR) { |
691 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 692 | return 1; |
dea3101e | 693 | } |
c9f8735b | 694 | return 0; |
dea3101e JB |
695 | } |
696 | ||
697 | int | |
2e0fef85 | 698 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
dea3101e JB |
699 | { |
700 | struct lpfc_sli_ring *pring; | |
701 | struct lpfc_iocbq *iocb, *next_iocb; | |
702 | struct lpfc_nodelist *ndlp; | |
703 | IOCB_t *icmd; | |
704 | ||
705 | /* Abort outstanding I/O on NPort <nlp_DID> */ | |
706 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
e8b62011 JS |
707 | "0201 Abort outstanding I/O on NPort x%x\n", |
708 | Fabric_DID); | |
dea3101e JB |
709 | |
710 | pring = &phba->sli.ring[LPFC_ELS_RING]; | |
711 | ||
712 | /* | |
713 | * Check the txcmplq for an iocb that matches the nport the driver is | |
714 | * searching for. | |
715 | */ | |
2e0fef85 | 716 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
717 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
718 | icmd = &iocb->iocb; | |
2e0fef85 JS |
719 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
720 | icmd->un.elsreq64.bdl.ulpIoTag32) { | |
dea3101e | 721 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
58da1ffb JS |
722 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
723 | (ndlp->nlp_DID == Fabric_DID)) | |
07951076 | 724 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
dea3101e JB |
725 | } |
726 | } | |
2e0fef85 | 727 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
728 | |
729 | return 0; | |
730 | } | |
731 | ||
732 | int | |
2e0fef85 | 733 | lpfc_initial_flogi(struct lpfc_vport *vport) |
dea3101e | 734 | { |
2e0fef85 | 735 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
736 | struct lpfc_nodelist *ndlp; |
737 | ||
98c9ea5c JS |
738 | vport->port_state = LPFC_FLOGI; |
739 | lpfc_set_disctmo(vport); | |
740 | ||
c9f8735b | 741 | /* First look for the Fabric ndlp */ |
2e0fef85 | 742 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
c9f8735b | 743 | if (!ndlp) { |
dea3101e | 744 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b JW |
745 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
746 | if (!ndlp) | |
747 | return 0; | |
2e0fef85 | 748 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
e47c9093 JS |
749 | /* Put ndlp onto node list */ |
750 | lpfc_enqueue_node(vport, ndlp); | |
751 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
752 | /* re-setup ndlp without removing from node list */ | |
753 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
754 | if (!ndlp) | |
755 | return 0; | |
dea3101e | 756 | } |
87af33fe | 757 | |
e47c9093 | 758 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
fa4066b6 JS |
759 | /* This decrement of reference count to node shall kick off |
760 | * the release of the node. | |
761 | */ | |
329f9bc7 | 762 | lpfc_nlp_put(ndlp); |
e47c9093 | 763 | |
c9f8735b | 764 | return 1; |
dea3101e JB |
765 | } |
766 | ||
92d7f7b0 JS |
767 | int |
768 | lpfc_initial_fdisc(struct lpfc_vport *vport) | |
769 | { | |
770 | struct lpfc_hba *phba = vport->phba; | |
771 | struct lpfc_nodelist *ndlp; | |
772 | ||
773 | /* First look for the Fabric ndlp */ | |
774 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
775 | if (!ndlp) { | |
776 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
777 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
778 | if (!ndlp) | |
779 | return 0; | |
780 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
e47c9093 JS |
781 | /* Put ndlp onto node list */ |
782 | lpfc_enqueue_node(vport, ndlp); | |
783 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
784 | /* re-setup ndlp without removing from node list */ | |
785 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
786 | if (!ndlp) | |
787 | return 0; | |
92d7f7b0 | 788 | } |
e47c9093 | 789 | |
92d7f7b0 | 790 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
fa4066b6 JS |
791 | /* decrement node reference count to trigger the release of |
792 | * the node. | |
793 | */ | |
92d7f7b0 | 794 | lpfc_nlp_put(ndlp); |
fa4066b6 | 795 | return 0; |
92d7f7b0 JS |
796 | } |
797 | return 1; | |
798 | } | |
87af33fe JS |
799 | |
800 | void | |
2e0fef85 | 801 | lpfc_more_plogi(struct lpfc_vport *vport) |
dea3101e JB |
802 | { |
803 | int sentplogi; | |
804 | ||
2e0fef85 JS |
805 | if (vport->num_disc_nodes) |
806 | vport->num_disc_nodes--; | |
dea3101e JB |
807 | |
808 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ | |
e8b62011 JS |
809 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
810 | "0232 Continue discovery with %d PLOGIs to go " | |
811 | "Data: x%x x%x x%x\n", | |
812 | vport->num_disc_nodes, vport->fc_plogi_cnt, | |
813 | vport->fc_flag, vport->port_state); | |
dea3101e | 814 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 JS |
815 | if (vport->fc_flag & FC_NLP_MORE) |
816 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ | |
817 | sentplogi = lpfc_els_disc_plogi(vport); | |
818 | ||
dea3101e JB |
819 | return; |
820 | } | |
821 | ||
488d1469 | 822 | static struct lpfc_nodelist * |
92d7f7b0 | 823 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
488d1469 JS |
824 | struct lpfc_nodelist *ndlp) |
825 | { | |
2e0fef85 | 826 | struct lpfc_vport *vport = ndlp->vport; |
488d1469 | 827 | struct lpfc_nodelist *new_ndlp; |
0ff10d46 JS |
828 | struct lpfc_rport_data *rdata; |
829 | struct fc_rport *rport; | |
488d1469 | 830 | struct serv_parm *sp; |
92d7f7b0 | 831 | uint8_t name[sizeof(struct lpfc_name)]; |
58da1ffb | 832 | uint32_t rc, keepDID = 0; |
488d1469 | 833 | |
2fb9bd8b JS |
834 | /* Fabric nodes can have the same WWPN so we don't bother searching |
835 | * by WWPN. Just return the ndlp that was given to us. | |
836 | */ | |
837 | if (ndlp->nlp_type & NLP_FABRIC) | |
838 | return ndlp; | |
839 | ||
92d7f7b0 | 840 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
685f0bf7 | 841 | memset(name, 0, sizeof(struct lpfc_name)); |
488d1469 | 842 | |
685f0bf7 | 843 | /* Now we find out if the NPort we are logging into, matches the WWPN |
488d1469 JS |
844 | * we have for that ndlp. If not, we have some work to do. |
845 | */ | |
2e0fef85 | 846 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
488d1469 | 847 | |
e47c9093 | 848 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
488d1469 | 849 | return ndlp; |
488d1469 JS |
850 | |
851 | if (!new_ndlp) { | |
2e0fef85 JS |
852 | rc = memcmp(&ndlp->nlp_portname, name, |
853 | sizeof(struct lpfc_name)); | |
92795650 JS |
854 | if (!rc) |
855 | return ndlp; | |
488d1469 JS |
856 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
857 | if (!new_ndlp) | |
858 | return ndlp; | |
2e0fef85 | 859 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
e47c9093 | 860 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
58da1ffb JS |
861 | rc = memcmp(&ndlp->nlp_portname, name, |
862 | sizeof(struct lpfc_name)); | |
863 | if (!rc) | |
864 | return ndlp; | |
e47c9093 JS |
865 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
866 | NLP_STE_UNUSED_NODE); | |
867 | if (!new_ndlp) | |
868 | return ndlp; | |
58da1ffb JS |
869 | keepDID = new_ndlp->nlp_DID; |
870 | } else | |
871 | keepDID = new_ndlp->nlp_DID; | |
488d1469 | 872 | |
2e0fef85 | 873 | lpfc_unreg_rpi(vport, new_ndlp); |
488d1469 | 874 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
92795650 | 875 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
0ff10d46 JS |
876 | |
877 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) | |
878 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
879 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | |
880 | ||
e47c9093 | 881 | /* Set state will put new_ndlp on to node list if not already done */ |
2e0fef85 | 882 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
488d1469 | 883 | |
2e0fef85 | 884 | /* Move this back to NPR state */ |
87af33fe JS |
885 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
886 | /* The new_ndlp is replacing ndlp totally, so we need | |
887 | * to put ndlp on UNUSED list and try to free it. | |
888 | */ | |
0ff10d46 JS |
889 | |
890 | /* Fix up the rport accordingly */ | |
891 | rport = ndlp->rport; | |
892 | if (rport) { | |
893 | rdata = rport->dd_data; | |
894 | if (rdata->pnode == ndlp) { | |
895 | lpfc_nlp_put(ndlp); | |
896 | ndlp->rport = NULL; | |
897 | rdata->pnode = lpfc_nlp_get(new_ndlp); | |
898 | new_ndlp->rport = rport; | |
899 | } | |
900 | new_ndlp->nlp_type = ndlp->nlp_type; | |
901 | } | |
58da1ffb JS |
902 | /* We shall actually free the ndlp with both nlp_DID and |
903 | * nlp_portname fields equals 0 to avoid any ndlp on the | |
904 | * nodelist never to be used. | |
905 | */ | |
906 | if (ndlp->nlp_DID == 0) { | |
907 | spin_lock_irq(&phba->ndlp_lock); | |
908 | NLP_SET_FREE_REQ(ndlp); | |
909 | spin_unlock_irq(&phba->ndlp_lock); | |
910 | } | |
0ff10d46 | 911 | |
58da1ffb JS |
912 | /* Two ndlps cannot have the same did on the nodelist */ |
913 | ndlp->nlp_DID = keepDID; | |
2e0fef85 | 914 | lpfc_drop_node(vport, ndlp); |
87af33fe | 915 | } |
92795650 | 916 | else { |
2e0fef85 | 917 | lpfc_unreg_rpi(vport, ndlp); |
58da1ffb JS |
918 | /* Two ndlps cannot have the same did */ |
919 | ndlp->nlp_DID = keepDID; | |
2e0fef85 | 920 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
92795650 | 921 | } |
488d1469 JS |
922 | return new_ndlp; |
923 | } | |
924 | ||
87af33fe JS |
925 | void |
926 | lpfc_end_rscn(struct lpfc_vport *vport) | |
927 | { | |
928 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
929 | ||
930 | if (vport->fc_flag & FC_RSCN_MODE) { | |
931 | /* | |
932 | * Check to see if more RSCNs came in while we were | |
933 | * processing this one. | |
934 | */ | |
935 | if (vport->fc_rscn_id_cnt || | |
936 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) | |
937 | lpfc_els_handle_rscn(vport); | |
938 | else { | |
939 | spin_lock_irq(shost->host_lock); | |
940 | vport->fc_flag &= ~FC_RSCN_MODE; | |
941 | spin_unlock_irq(shost->host_lock); | |
942 | } | |
943 | } | |
944 | } | |
945 | ||
dea3101e | 946 | static void |
2e0fef85 JS |
947 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
948 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 949 | { |
2e0fef85 JS |
950 | struct lpfc_vport *vport = cmdiocb->vport; |
951 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 952 | IOCB_t *irsp; |
dea3101e | 953 | struct lpfc_nodelist *ndlp; |
92795650 | 954 | struct lpfc_dmabuf *prsp; |
dea3101e JB |
955 | int disc, rc, did, type; |
956 | ||
dea3101e JB |
957 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
958 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
959 | ||
960 | irsp = &rspiocb->iocb; | |
858c9f6c JS |
961 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
962 | "PLOGI cmpl: status:x%x/x%x did:x%x", | |
963 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
964 | irsp->un.elsreq64.remoteID); | |
965 | ||
2e0fef85 | 966 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
e47c9093 | 967 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
e8b62011 JS |
968 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
969 | "0136 PLOGI completes to NPort x%x " | |
970 | "with no ndlp. Data: x%x x%x x%x\n", | |
971 | irsp->un.elsreq64.remoteID, | |
972 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
973 | irsp->ulpIoTag); | |
488d1469 | 974 | goto out; |
ed957684 | 975 | } |
dea3101e JB |
976 | |
977 | /* Since ndlp can be freed in the disc state machine, note if this node | |
978 | * is being used during discovery. | |
979 | */ | |
2e0fef85 | 980 | spin_lock_irq(shost->host_lock); |
dea3101e | 981 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
488d1469 | 982 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 | 983 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
984 | rc = 0; |
985 | ||
986 | /* PLOGI completes to NPort <nlp_DID> */ | |
e8b62011 JS |
987 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
988 | "0102 PLOGI completes to NPort x%x " | |
989 | "Data: x%x x%x x%x x%x x%x\n", | |
990 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
991 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | |
dea3101e | 992 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
993 | if (lpfc_els_chk_latt(vport)) { |
994 | spin_lock_irq(shost->host_lock); | |
dea3101e | 995 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 996 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
997 | goto out; |
998 | } | |
999 | ||
1000 | /* ndlp could be freed in DSM, save these values now */ | |
1001 | type = ndlp->nlp_type; | |
1002 | did = ndlp->nlp_DID; | |
1003 | ||
1004 | if (irsp->ulpStatus) { | |
1005 | /* Check for retry */ | |
1006 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
1007 | /* ELS command is being retried */ | |
1008 | if (disc) { | |
2e0fef85 | 1009 | spin_lock_irq(shost->host_lock); |
dea3101e | 1010 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1011 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1012 | } |
1013 | goto out; | |
1014 | } | |
dea3101e JB |
1015 | /* PLOGI failed */ |
1016 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | |
e47c9093 | 1017 | if (lpfc_error_lost_link(irsp)) |
c9f8735b | 1018 | rc = NLP_STE_FREED_NODE; |
e47c9093 | 1019 | else |
2e0fef85 | 1020 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1021 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1022 | } else { |
1023 | /* Good status, call state machine */ | |
92795650 | 1024 | prsp = list_entry(((struct lpfc_dmabuf *) |
92d7f7b0 JS |
1025 | cmdiocb->context2)->list.next, |
1026 | struct lpfc_dmabuf, list); | |
1027 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); | |
2e0fef85 | 1028 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1029 | NLP_EVT_CMPL_PLOGI); |
dea3101e JB |
1030 | } |
1031 | ||
2e0fef85 | 1032 | if (disc && vport->num_disc_nodes) { |
dea3101e | 1033 | /* Check to see if there are more PLOGIs to be sent */ |
2e0fef85 | 1034 | lpfc_more_plogi(vport); |
dea3101e | 1035 | |
2e0fef85 JS |
1036 | if (vport->num_disc_nodes == 0) { |
1037 | spin_lock_irq(shost->host_lock); | |
1038 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
1039 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1040 | |
2e0fef85 | 1041 | lpfc_can_disctmo(vport); |
87af33fe | 1042 | lpfc_end_rscn(vport); |
dea3101e JB |
1043 | } |
1044 | } | |
1045 | ||
1046 | out: | |
1047 | lpfc_els_free_iocb(phba, cmdiocb); | |
1048 | return; | |
1049 | } | |
1050 | ||
1051 | int | |
2e0fef85 | 1052 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
dea3101e | 1053 | { |
2e0fef85 | 1054 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1055 | struct serv_parm *sp; |
1056 | IOCB_t *icmd; | |
98c9ea5c | 1057 | struct lpfc_nodelist *ndlp; |
dea3101e JB |
1058 | struct lpfc_iocbq *elsiocb; |
1059 | struct lpfc_sli_ring *pring; | |
1060 | struct lpfc_sli *psli; | |
1061 | uint8_t *pcmd; | |
1062 | uint16_t cmdsize; | |
92d7f7b0 | 1063 | int ret; |
dea3101e JB |
1064 | |
1065 | psli = &phba->sli; | |
1066 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
1067 | ||
98c9ea5c | 1068 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
1069 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
1070 | ndlp = NULL; | |
98c9ea5c | 1071 | |
e47c9093 | 1072 | /* If ndlp is not NULL, we will bump the reference count on it */ |
92d7f7b0 | 1073 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
98c9ea5c | 1074 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
2e0fef85 | 1075 | ELS_CMD_PLOGI); |
c9f8735b JW |
1076 | if (!elsiocb) |
1077 | return 1; | |
dea3101e JB |
1078 | |
1079 | icmd = &elsiocb->iocb; | |
1080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1081 | ||
1082 | /* For PLOGI request, remainder of payload is service parameters */ | |
1083 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; | |
92d7f7b0 JS |
1084 | pcmd += sizeof(uint32_t); |
1085 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
dea3101e JB |
1086 | sp = (struct serv_parm *) pcmd; |
1087 | ||
1088 | if (sp->cmn.fcphLow < FC_PH_4_3) | |
1089 | sp->cmn.fcphLow = FC_PH_4_3; | |
1090 | ||
1091 | if (sp->cmn.fcphHigh < FC_PH3) | |
1092 | sp->cmn.fcphHigh = FC_PH3; | |
1093 | ||
858c9f6c JS |
1094 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1095 | "Issue PLOGI: did:x%x", | |
1096 | did, 0, 0); | |
1097 | ||
dea3101e JB |
1098 | phba->fc_stat.elsXmitPLOGI++; |
1099 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; | |
92d7f7b0 JS |
1100 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
1101 | ||
1102 | if (ret == IOCB_ERROR) { | |
dea3101e | 1103 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1104 | return 1; |
dea3101e | 1105 | } |
c9f8735b | 1106 | return 0; |
dea3101e JB |
1107 | } |
1108 | ||
1109 | static void | |
2e0fef85 JS |
1110 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1111 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1112 | { |
2e0fef85 JS |
1113 | struct lpfc_vport *vport = cmdiocb->vport; |
1114 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e JB |
1115 | IOCB_t *irsp; |
1116 | struct lpfc_sli *psli; | |
1117 | struct lpfc_nodelist *ndlp; | |
1118 | ||
1119 | psli = &phba->sli; | |
1120 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
1121 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1122 | ||
1123 | irsp = &(rspiocb->iocb); | |
1124 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
2e0fef85 | 1125 | spin_lock_irq(shost->host_lock); |
dea3101e | 1126 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 1127 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1128 | |
858c9f6c JS |
1129 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1130 | "PRLI cmpl: status:x%x/x%x did:x%x", | |
1131 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1132 | ndlp->nlp_DID); | |
dea3101e | 1133 | /* PRLI completes to NPort <nlp_DID> */ |
e8b62011 JS |
1134 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1135 | "0103 PRLI completes to NPort x%x " | |
1136 | "Data: x%x x%x x%x x%x\n", | |
1137 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1138 | irsp->ulpTimeout, vport->num_disc_nodes); | |
dea3101e | 1139 | |
2e0fef85 | 1140 | vport->fc_prli_sent--; |
dea3101e | 1141 | /* Check to see if link went down during discovery */ |
2e0fef85 | 1142 | if (lpfc_els_chk_latt(vport)) |
dea3101e JB |
1143 | goto out; |
1144 | ||
1145 | if (irsp->ulpStatus) { | |
1146 | /* Check for retry */ | |
1147 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
1148 | /* ELS command is being retried */ | |
1149 | goto out; | |
1150 | } | |
1151 | /* PRLI failed */ | |
1152 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | |
e47c9093 | 1153 | if (lpfc_error_lost_link(irsp)) |
dea3101e | 1154 | goto out; |
e47c9093 | 1155 | else |
2e0fef85 | 1156 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1157 | NLP_EVT_CMPL_PRLI); |
e47c9093 | 1158 | } else |
dea3101e | 1159 | /* Good status, call state machine */ |
2e0fef85 | 1160 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1161 | NLP_EVT_CMPL_PRLI); |
dea3101e JB |
1162 | out: |
1163 | lpfc_els_free_iocb(phba, cmdiocb); | |
1164 | return; | |
1165 | } | |
1166 | ||
1167 | int | |
2e0fef85 | 1168 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
1169 | uint8_t retry) |
1170 | { | |
2e0fef85 JS |
1171 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1172 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
1173 | PRLI *npr; |
1174 | IOCB_t *icmd; | |
1175 | struct lpfc_iocbq *elsiocb; | |
1176 | struct lpfc_sli_ring *pring; | |
1177 | struct lpfc_sli *psli; | |
1178 | uint8_t *pcmd; | |
1179 | uint16_t cmdsize; | |
1180 | ||
1181 | psli = &phba->sli; | |
1182 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
1183 | ||
92d7f7b0 | 1184 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
2e0fef85 JS |
1185 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
1186 | ndlp->nlp_DID, ELS_CMD_PRLI); | |
488d1469 | 1187 | if (!elsiocb) |
c9f8735b | 1188 | return 1; |
dea3101e JB |
1189 | |
1190 | icmd = &elsiocb->iocb; | |
1191 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1192 | ||
1193 | /* For PRLI request, remainder of payload is service parameters */ | |
92d7f7b0 | 1194 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
dea3101e | 1195 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
92d7f7b0 | 1196 | pcmd += sizeof(uint32_t); |
dea3101e JB |
1197 | |
1198 | /* For PRLI, remainder of payload is PRLI parameter page */ | |
1199 | npr = (PRLI *) pcmd; | |
1200 | /* | |
1201 | * If our firmware version is 3.20 or later, | |
1202 | * set the following bits for FC-TAPE support. | |
1203 | */ | |
1204 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { | |
1205 | npr->ConfmComplAllowed = 1; | |
1206 | npr->Retry = 1; | |
1207 | npr->TaskRetryIdReq = 1; | |
1208 | } | |
1209 | npr->estabImagePair = 1; | |
1210 | npr->readXferRdyDis = 1; | |
1211 | ||
1212 | /* For FCP support */ | |
1213 | npr->prliType = PRLI_FCP_TYPE; | |
1214 | npr->initiatorFunc = 1; | |
1215 | ||
858c9f6c JS |
1216 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1217 | "Issue PRLI: did:x%x", | |
1218 | ndlp->nlp_DID, 0, 0); | |
1219 | ||
dea3101e JB |
1220 | phba->fc_stat.elsXmitPRLI++; |
1221 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; | |
2e0fef85 | 1222 | spin_lock_irq(shost->host_lock); |
dea3101e | 1223 | ndlp->nlp_flag |= NLP_PRLI_SND; |
2e0fef85 | 1224 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1225 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
2e0fef85 | 1226 | spin_lock_irq(shost->host_lock); |
dea3101e | 1227 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
2e0fef85 | 1228 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1229 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1230 | return 1; |
dea3101e | 1231 | } |
2e0fef85 | 1232 | vport->fc_prli_sent++; |
c9f8735b | 1233 | return 0; |
dea3101e JB |
1234 | } |
1235 | ||
0ff10d46 | 1236 | void |
2e0fef85 | 1237 | lpfc_more_adisc(struct lpfc_vport *vport) |
dea3101e JB |
1238 | { |
1239 | int sentadisc; | |
1240 | ||
2e0fef85 JS |
1241 | if (vport->num_disc_nodes) |
1242 | vport->num_disc_nodes--; | |
dea3101e | 1243 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
e8b62011 JS |
1244 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1245 | "0210 Continue discovery with %d ADISCs to go " | |
1246 | "Data: x%x x%x x%x\n", | |
1247 | vport->num_disc_nodes, vport->fc_adisc_cnt, | |
1248 | vport->fc_flag, vport->port_state); | |
dea3101e | 1249 | /* Check to see if there are more ADISCs to be sent */ |
2e0fef85 JS |
1250 | if (vport->fc_flag & FC_NLP_MORE) { |
1251 | lpfc_set_disctmo(vport); | |
1252 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ | |
1253 | sentadisc = lpfc_els_disc_adisc(vport); | |
dea3101e JB |
1254 | } |
1255 | return; | |
1256 | } | |
1257 | ||
1258 | static void | |
2e0fef85 | 1259 | lpfc_rscn_disc(struct lpfc_vport *vport) |
dea3101e | 1260 | { |
858c9f6c JS |
1261 | lpfc_can_disctmo(vport); |
1262 | ||
dea3101e | 1263 | /* RSCN discovery */ |
2e0fef85 JS |
1264 | /* go thru NPR nodes and issue ELS PLOGIs */ |
1265 | if (vport->fc_npr_cnt) | |
1266 | if (lpfc_els_disc_plogi(vport)) | |
dea3101e | 1267 | return; |
2e0fef85 | 1268 | |
87af33fe | 1269 | lpfc_end_rscn(vport); |
dea3101e JB |
1270 | } |
1271 | ||
1272 | static void | |
2e0fef85 JS |
1273 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1274 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1275 | { |
2e0fef85 JS |
1276 | struct lpfc_vport *vport = cmdiocb->vport; |
1277 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e | 1278 | IOCB_t *irsp; |
dea3101e | 1279 | struct lpfc_nodelist *ndlp; |
2e0fef85 | 1280 | int disc; |
dea3101e JB |
1281 | |
1282 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
1283 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1284 | ||
1285 | irsp = &(rspiocb->iocb); | |
1286 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
dea3101e | 1287 | |
858c9f6c JS |
1288 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1289 | "ADISC cmpl: status:x%x/x%x did:x%x", | |
1290 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1291 | ndlp->nlp_DID); | |
1292 | ||
dea3101e JB |
1293 | /* Since ndlp can be freed in the disc state machine, note if this node |
1294 | * is being used during discovery. | |
1295 | */ | |
2e0fef85 | 1296 | spin_lock_irq(shost->host_lock); |
dea3101e | 1297 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
c9f8735b | 1298 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
2e0fef85 | 1299 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1300 | /* ADISC completes to NPort <nlp_DID> */ |
e8b62011 JS |
1301 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1302 | "0104 ADISC completes to NPort x%x " | |
1303 | "Data: x%x x%x x%x x%x x%x\n", | |
1304 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1305 | irsp->ulpTimeout, disc, vport->num_disc_nodes); | |
dea3101e | 1306 | /* Check to see if link went down during discovery */ |
2e0fef85 JS |
1307 | if (lpfc_els_chk_latt(vport)) { |
1308 | spin_lock_irq(shost->host_lock); | |
dea3101e | 1309 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 1310 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1311 | goto out; |
1312 | } | |
1313 | ||
1314 | if (irsp->ulpStatus) { | |
1315 | /* Check for retry */ | |
1316 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { | |
1317 | /* ELS command is being retried */ | |
1318 | if (disc) { | |
2e0fef85 | 1319 | spin_lock_irq(shost->host_lock); |
dea3101e | 1320 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 JS |
1321 | spin_unlock_irq(shost->host_lock); |
1322 | lpfc_set_disctmo(vport); | |
dea3101e JB |
1323 | } |
1324 | goto out; | |
1325 | } | |
1326 | /* ADISC failed */ | |
1327 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | |
e47c9093 | 1328 | if (!lpfc_error_lost_link(irsp)) |
2e0fef85 | 1329 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
858c9f6c | 1330 | NLP_EVT_CMPL_ADISC); |
e47c9093 | 1331 | } else |
dea3101e | 1332 | /* Good status, call state machine */ |
2e0fef85 | 1333 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
dea3101e | 1334 | NLP_EVT_CMPL_ADISC); |
dea3101e | 1335 | |
2e0fef85 | 1336 | if (disc && vport->num_disc_nodes) { |
dea3101e | 1337 | /* Check to see if there are more ADISCs to be sent */ |
2e0fef85 | 1338 | lpfc_more_adisc(vport); |
dea3101e JB |
1339 | |
1340 | /* Check to see if we are done with ADISC authentication */ | |
2e0fef85 | 1341 | if (vport->num_disc_nodes == 0) { |
92d7f7b0 JS |
1342 | /* If we get here, there is nothing left to ADISC */ |
1343 | /* | |
1344 | * For NPIV, cmpl_reg_vpi will set port_state to READY, | |
1345 | * and continue discovery. | |
1346 | */ | |
1347 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
1348 | !(vport->fc_flag & FC_RSCN_MODE)) { | |
1349 | lpfc_issue_reg_vpi(phba, vport); | |
1350 | goto out; | |
1351 | } | |
1352 | /* | |
1353 | * For SLI2, we need to set port_state to READY | |
1354 | * and continue discovery. | |
1355 | */ | |
1356 | if (vport->port_state < LPFC_VPORT_READY) { | |
1357 | /* If we get here, there is nothing to ADISC */ | |
ed957684 | 1358 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
2e0fef85 | 1359 | lpfc_issue_clear_la(phba, vport); |
92d7f7b0 JS |
1360 | |
1361 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { | |
1362 | vport->num_disc_nodes = 0; | |
1363 | /* go thru NPR list, issue ELS PLOGIs */ | |
1364 | if (vport->fc_npr_cnt) | |
1365 | lpfc_els_disc_plogi(vport); | |
1366 | ||
1367 | if (!vport->num_disc_nodes) { | |
1368 | spin_lock_irq(shost->host_lock); | |
1369 | vport->fc_flag &= | |
1370 | ~FC_NDISC_ACTIVE; | |
1371 | spin_unlock_irq( | |
1372 | shost->host_lock); | |
1373 | lpfc_can_disctmo(vport); | |
1374 | } | |
1375 | } | |
1376 | vport->port_state = LPFC_VPORT_READY; | |
dea3101e | 1377 | } else { |
2e0fef85 | 1378 | lpfc_rscn_disc(vport); |
dea3101e JB |
1379 | } |
1380 | } | |
1381 | } | |
dea3101e JB |
1382 | out: |
1383 | lpfc_els_free_iocb(phba, cmdiocb); | |
1384 | return; | |
1385 | } | |
1386 | ||
1387 | int | |
2e0fef85 | 1388 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
1389 | uint8_t retry) |
1390 | { | |
2e0fef85 JS |
1391 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1392 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
1393 | ADISC *ap; |
1394 | IOCB_t *icmd; | |
1395 | struct lpfc_iocbq *elsiocb; | |
2e0fef85 JS |
1396 | struct lpfc_sli *psli = &phba->sli; |
1397 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
dea3101e JB |
1398 | uint8_t *pcmd; |
1399 | uint16_t cmdsize; | |
1400 | ||
92d7f7b0 | 1401 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
2e0fef85 JS |
1402 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
1403 | ndlp->nlp_DID, ELS_CMD_ADISC); | |
488d1469 | 1404 | if (!elsiocb) |
c9f8735b | 1405 | return 1; |
dea3101e JB |
1406 | |
1407 | icmd = &elsiocb->iocb; | |
1408 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1409 | ||
1410 | /* For ADISC request, remainder of payload is service parameters */ | |
1411 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; | |
92d7f7b0 | 1412 | pcmd += sizeof(uint32_t); |
dea3101e JB |
1413 | |
1414 | /* Fill in ADISC payload */ | |
1415 | ap = (ADISC *) pcmd; | |
1416 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
1417 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
1418 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 1419 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 1420 | |
858c9f6c JS |
1421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1422 | "Issue ADISC: did:x%x", | |
1423 | ndlp->nlp_DID, 0, 0); | |
1424 | ||
dea3101e JB |
1425 | phba->fc_stat.elsXmitADISC++; |
1426 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; | |
2e0fef85 | 1427 | spin_lock_irq(shost->host_lock); |
dea3101e | 1428 | ndlp->nlp_flag |= NLP_ADISC_SND; |
2e0fef85 | 1429 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1430 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
2e0fef85 | 1431 | spin_lock_irq(shost->host_lock); |
dea3101e | 1432 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
2e0fef85 | 1433 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1434 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1435 | return 1; |
dea3101e | 1436 | } |
c9f8735b | 1437 | return 0; |
dea3101e JB |
1438 | } |
1439 | ||
1440 | static void | |
2e0fef85 JS |
1441 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1442 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1443 | { |
2e0fef85 JS |
1444 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
1445 | struct lpfc_vport *vport = ndlp->vport; | |
1446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
dea3101e JB |
1447 | IOCB_t *irsp; |
1448 | struct lpfc_sli *psli; | |
dea3101e JB |
1449 | |
1450 | psli = &phba->sli; | |
1451 | /* we pass cmdiocb to state machine which needs rspiocb as well */ | |
1452 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1453 | ||
1454 | irsp = &(rspiocb->iocb); | |
2e0fef85 | 1455 | spin_lock_irq(shost->host_lock); |
dea3101e | 1456 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 1457 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1458 | |
858c9f6c JS |
1459 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1460 | "LOGO cmpl: status:x%x/x%x did:x%x", | |
1461 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1462 | ndlp->nlp_DID); | |
dea3101e | 1463 | /* LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
1464 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1465 | "0105 LOGO completes to NPort x%x " | |
1466 | "Data: x%x x%x x%x x%x\n", | |
1467 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], | |
1468 | irsp->ulpTimeout, vport->num_disc_nodes); | |
dea3101e | 1469 | /* Check to see if link went down during discovery */ |
2e0fef85 | 1470 | if (lpfc_els_chk_latt(vport)) |
dea3101e JB |
1471 | goto out; |
1472 | ||
92d7f7b0 JS |
1473 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
1474 | /* NLP_EVT_DEVICE_RM should unregister the RPI | |
1475 | * which should abort all outstanding IOs. | |
1476 | */ | |
1477 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, | |
1478 | NLP_EVT_DEVICE_RM); | |
1479 | goto out; | |
1480 | } | |
1481 | ||
dea3101e JB |
1482 | if (irsp->ulpStatus) { |
1483 | /* Check for retry */ | |
2e0fef85 | 1484 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
dea3101e JB |
1485 | /* ELS command is being retried */ |
1486 | goto out; | |
dea3101e JB |
1487 | /* LOGO failed */ |
1488 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ | |
858c9f6c | 1489 | if (lpfc_error_lost_link(irsp)) |
dea3101e | 1490 | goto out; |
858c9f6c | 1491 | else |
2e0fef85 | 1492 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1493 | NLP_EVT_CMPL_LOGO); |
e47c9093 | 1494 | } else |
5024ab17 JW |
1495 | /* Good status, call state machine. |
1496 | * This will unregister the rpi if needed. | |
1497 | */ | |
2e0fef85 | 1498 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
92d7f7b0 | 1499 | NLP_EVT_CMPL_LOGO); |
dea3101e JB |
1500 | out: |
1501 | lpfc_els_free_iocb(phba, cmdiocb); | |
1502 | return; | |
1503 | } | |
1504 | ||
1505 | int | |
2e0fef85 | 1506 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
1507 | uint8_t retry) |
1508 | { | |
2e0fef85 JS |
1509 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1510 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
1511 | IOCB_t *icmd; |
1512 | struct lpfc_iocbq *elsiocb; | |
1513 | struct lpfc_sli_ring *pring; | |
1514 | struct lpfc_sli *psli; | |
1515 | uint8_t *pcmd; | |
1516 | uint16_t cmdsize; | |
92d7f7b0 | 1517 | int rc; |
dea3101e JB |
1518 | |
1519 | psli = &phba->sli; | |
1520 | pring = &psli->ring[LPFC_ELS_RING]; | |
1521 | ||
98c9ea5c JS |
1522 | spin_lock_irq(shost->host_lock); |
1523 | if (ndlp->nlp_flag & NLP_LOGO_SND) { | |
1524 | spin_unlock_irq(shost->host_lock); | |
1525 | return 0; | |
1526 | } | |
1527 | spin_unlock_irq(shost->host_lock); | |
1528 | ||
92d7f7b0 | 1529 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
2e0fef85 JS |
1530 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
1531 | ndlp->nlp_DID, ELS_CMD_LOGO); | |
488d1469 | 1532 | if (!elsiocb) |
c9f8735b | 1533 | return 1; |
dea3101e JB |
1534 | |
1535 | icmd = &elsiocb->iocb; | |
1536 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1537 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
92d7f7b0 | 1538 | pcmd += sizeof(uint32_t); |
dea3101e JB |
1539 | |
1540 | /* Fill in LOGO payload */ | |
2e0fef85 | 1541 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
92d7f7b0 JS |
1542 | pcmd += sizeof(uint32_t); |
1543 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
dea3101e | 1544 | |
858c9f6c JS |
1545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1546 | "Issue LOGO: did:x%x", | |
1547 | ndlp->nlp_DID, 0, 0); | |
1548 | ||
dea3101e JB |
1549 | phba->fc_stat.elsXmitLOGO++; |
1550 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; | |
2e0fef85 | 1551 | spin_lock_irq(shost->host_lock); |
dea3101e | 1552 | ndlp->nlp_flag |= NLP_LOGO_SND; |
2e0fef85 | 1553 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
1554 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
1555 | ||
1556 | if (rc == IOCB_ERROR) { | |
2e0fef85 | 1557 | spin_lock_irq(shost->host_lock); |
dea3101e | 1558 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
2e0fef85 | 1559 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1560 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1561 | return 1; |
dea3101e | 1562 | } |
c9f8735b | 1563 | return 0; |
dea3101e JB |
1564 | } |
1565 | ||
1566 | static void | |
2e0fef85 JS |
1567 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1568 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1569 | { |
2e0fef85 | 1570 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
1571 | IOCB_t *irsp; |
1572 | ||
1573 | irsp = &rspiocb->iocb; | |
1574 | ||
858c9f6c JS |
1575 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1576 | "ELS cmd cmpl: status:x%x/x%x did:x%x", | |
1577 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
1578 | irsp->un.elsreq64.remoteID); | |
dea3101e | 1579 | /* ELS cmd tag <ulpIoTag> completes */ |
e8b62011 JS |
1580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1581 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", | |
1582 | irsp->ulpIoTag, irsp->ulpStatus, | |
1583 | irsp->un.ulpWord[4], irsp->ulpTimeout); | |
dea3101e | 1584 | /* Check to see if link went down during discovery */ |
2e0fef85 | 1585 | lpfc_els_chk_latt(vport); |
dea3101e JB |
1586 | lpfc_els_free_iocb(phba, cmdiocb); |
1587 | return; | |
1588 | } | |
1589 | ||
1590 | int | |
2e0fef85 | 1591 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 1592 | { |
2e0fef85 | 1593 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1594 | IOCB_t *icmd; |
1595 | struct lpfc_iocbq *elsiocb; | |
1596 | struct lpfc_sli_ring *pring; | |
1597 | struct lpfc_sli *psli; | |
1598 | uint8_t *pcmd; | |
1599 | uint16_t cmdsize; | |
1600 | struct lpfc_nodelist *ndlp; | |
1601 | ||
1602 | psli = &phba->sli; | |
1603 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
92d7f7b0 | 1604 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
dea3101e | 1605 | |
e47c9093 JS |
1606 | ndlp = lpfc_findnode_did(vport, nportid); |
1607 | if (!ndlp) { | |
1608 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
1609 | if (!ndlp) | |
1610 | return 1; | |
1611 | lpfc_nlp_init(vport, ndlp, nportid); | |
1612 | lpfc_enqueue_node(vport, ndlp); | |
1613 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1614 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1615 | if (!ndlp) | |
1616 | return 1; | |
1617 | } | |
2e0fef85 JS |
1618 | |
1619 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
1620 | ndlp->nlp_DID, ELS_CMD_SCR); | |
dea3101e | 1621 | |
488d1469 | 1622 | if (!elsiocb) { |
fa4066b6 JS |
1623 | /* This will trigger the release of the node just |
1624 | * allocated | |
1625 | */ | |
329f9bc7 | 1626 | lpfc_nlp_put(ndlp); |
c9f8735b | 1627 | return 1; |
dea3101e JB |
1628 | } |
1629 | ||
1630 | icmd = &elsiocb->iocb; | |
1631 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1632 | ||
1633 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; | |
92d7f7b0 | 1634 | pcmd += sizeof(uint32_t); |
dea3101e JB |
1635 | |
1636 | /* For SCR, remainder of payload is SCR parameter page */ | |
92d7f7b0 | 1637 | memset(pcmd, 0, sizeof(SCR)); |
dea3101e JB |
1638 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
1639 | ||
858c9f6c JS |
1640 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1641 | "Issue SCR: did:x%x", | |
1642 | ndlp->nlp_DID, 0, 0); | |
1643 | ||
dea3101e JB |
1644 | phba->fc_stat.elsXmitSCR++; |
1645 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
dea3101e | 1646 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
fa4066b6 JS |
1647 | /* The additional lpfc_nlp_put will cause the following |
1648 | * lpfc_els_free_iocb routine to trigger the rlease of | |
1649 | * the node. | |
1650 | */ | |
329f9bc7 | 1651 | lpfc_nlp_put(ndlp); |
dea3101e | 1652 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1653 | return 1; |
dea3101e | 1654 | } |
fa4066b6 JS |
1655 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
1656 | * trigger the release of node. | |
1657 | */ | |
329f9bc7 | 1658 | lpfc_nlp_put(ndlp); |
c9f8735b | 1659 | return 0; |
dea3101e JB |
1660 | } |
1661 | ||
1662 | static int | |
2e0fef85 | 1663 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
dea3101e | 1664 | { |
2e0fef85 | 1665 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1666 | IOCB_t *icmd; |
1667 | struct lpfc_iocbq *elsiocb; | |
1668 | struct lpfc_sli_ring *pring; | |
1669 | struct lpfc_sli *psli; | |
1670 | FARP *fp; | |
1671 | uint8_t *pcmd; | |
1672 | uint32_t *lp; | |
1673 | uint16_t cmdsize; | |
1674 | struct lpfc_nodelist *ondlp; | |
1675 | struct lpfc_nodelist *ndlp; | |
1676 | ||
1677 | psli = &phba->sli; | |
1678 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
92d7f7b0 | 1679 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
dea3101e | 1680 | |
e47c9093 JS |
1681 | ndlp = lpfc_findnode_did(vport, nportid); |
1682 | if (!ndlp) { | |
1683 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
1684 | if (!ndlp) | |
1685 | return 1; | |
1686 | lpfc_nlp_init(vport, ndlp, nportid); | |
1687 | lpfc_enqueue_node(vport, ndlp); | |
1688 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
1689 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
1690 | if (!ndlp) | |
1691 | return 1; | |
1692 | } | |
2e0fef85 JS |
1693 | |
1694 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, | |
1695 | ndlp->nlp_DID, ELS_CMD_RNID); | |
488d1469 | 1696 | if (!elsiocb) { |
fa4066b6 JS |
1697 | /* This will trigger the release of the node just |
1698 | * allocated | |
1699 | */ | |
329f9bc7 | 1700 | lpfc_nlp_put(ndlp); |
c9f8735b | 1701 | return 1; |
dea3101e JB |
1702 | } |
1703 | ||
1704 | icmd = &elsiocb->iocb; | |
1705 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
1706 | ||
1707 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; | |
92d7f7b0 | 1708 | pcmd += sizeof(uint32_t); |
dea3101e JB |
1709 | |
1710 | /* Fill in FARPR payload */ | |
1711 | fp = (FARP *) (pcmd); | |
92d7f7b0 | 1712 | memset(fp, 0, sizeof(FARP)); |
dea3101e JB |
1713 | lp = (uint32_t *) pcmd; |
1714 | *lp++ = be32_to_cpu(nportid); | |
2e0fef85 | 1715 | *lp++ = be32_to_cpu(vport->fc_myDID); |
dea3101e JB |
1716 | fp->Rflags = 0; |
1717 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); | |
1718 | ||
92d7f7b0 JS |
1719 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
1720 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 1721 | ondlp = lpfc_findnode_did(vport, nportid); |
e47c9093 | 1722 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
dea3101e | 1723 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
92d7f7b0 | 1724 | sizeof(struct lpfc_name)); |
dea3101e | 1725 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
92d7f7b0 | 1726 | sizeof(struct lpfc_name)); |
dea3101e JB |
1727 | } |
1728 | ||
858c9f6c JS |
1729 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1730 | "Issue FARPR: did:x%x", | |
1731 | ndlp->nlp_DID, 0, 0); | |
1732 | ||
dea3101e JB |
1733 | phba->fc_stat.elsXmitFARPR++; |
1734 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; | |
dea3101e | 1735 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
fa4066b6 JS |
1736 | /* The additional lpfc_nlp_put will cause the following |
1737 | * lpfc_els_free_iocb routine to trigger the release of | |
1738 | * the node. | |
1739 | */ | |
329f9bc7 | 1740 | lpfc_nlp_put(ndlp); |
dea3101e | 1741 | lpfc_els_free_iocb(phba, elsiocb); |
c9f8735b | 1742 | return 1; |
dea3101e | 1743 | } |
fa4066b6 JS |
1744 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
1745 | * trigger the release of the node. | |
1746 | */ | |
329f9bc7 | 1747 | lpfc_nlp_put(ndlp); |
c9f8735b | 1748 | return 0; |
dea3101e JB |
1749 | } |
1750 | ||
fdcebe28 | 1751 | void |
2e0fef85 | 1752 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
fdcebe28 | 1753 | { |
2e0fef85 | 1754 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
e47c9093 | 1755 | struct lpfc_work_evt *evtp; |
2e0fef85 | 1756 | |
0d2b6b83 JS |
1757 | if (!(nlp->nlp_flag & NLP_DELAY_TMO)) |
1758 | return; | |
2e0fef85 | 1759 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 1760 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
2e0fef85 | 1761 | spin_unlock_irq(shost->host_lock); |
fdcebe28 JS |
1762 | del_timer_sync(&nlp->nlp_delayfunc); |
1763 | nlp->nlp_last_elscmd = 0; | |
e47c9093 | 1764 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
fdcebe28 | 1765 | list_del_init(&nlp->els_retry_evt.evt_listp); |
e47c9093 JS |
1766 | /* Decrement nlp reference count held for the delayed retry */ |
1767 | evtp = &nlp->els_retry_evt; | |
1768 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | |
1769 | } | |
fdcebe28 | 1770 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
2e0fef85 | 1771 | spin_lock_irq(shost->host_lock); |
fdcebe28 | 1772 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
2e0fef85 JS |
1773 | spin_unlock_irq(shost->host_lock); |
1774 | if (vport->num_disc_nodes) { | |
0d2b6b83 JS |
1775 | if (vport->port_state < LPFC_VPORT_READY) { |
1776 | /* Check if there are more ADISCs to be sent */ | |
1777 | lpfc_more_adisc(vport); | |
1778 | if ((vport->num_disc_nodes == 0) && | |
1779 | (vport->fc_npr_cnt)) | |
1780 | lpfc_els_disc_plogi(vport); | |
1781 | } else { | |
1782 | /* Check if there are more PLOGIs to be sent */ | |
1783 | lpfc_more_plogi(vport); | |
1784 | } | |
2e0fef85 JS |
1785 | if (vport->num_disc_nodes == 0) { |
1786 | spin_lock_irq(shost->host_lock); | |
1787 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
1788 | spin_unlock_irq(shost->host_lock); | |
1789 | lpfc_can_disctmo(vport); | |
ed957684 | 1790 | lpfc_end_rscn(vport); |
fdcebe28 JS |
1791 | } |
1792 | } | |
1793 | } | |
1794 | return; | |
1795 | } | |
1796 | ||
dea3101e JB |
1797 | void |
1798 | lpfc_els_retry_delay(unsigned long ptr) | |
1799 | { | |
2e0fef85 JS |
1800 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
1801 | struct lpfc_vport *vport = ndlp->vport; | |
2e0fef85 | 1802 | struct lpfc_hba *phba = vport->phba; |
92d7f7b0 | 1803 | unsigned long flags; |
2e0fef85 | 1804 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
dea3101e | 1805 | |
92d7f7b0 | 1806 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 1807 | if (!list_empty(&evtp->evt_listp)) { |
92d7f7b0 | 1808 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
1809 | return; |
1810 | } | |
1811 | ||
fa4066b6 JS |
1812 | /* We need to hold the node by incrementing the reference |
1813 | * count until the queued work is done | |
1814 | */ | |
1815 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); | |
5e9d9b82 JS |
1816 | if (evtp->evt_arg1) { |
1817 | evtp->evt = LPFC_EVT_ELS_RETRY; | |
1818 | list_add_tail(&evtp->evt_listp, &phba->work_list); | |
92d7f7b0 | 1819 | lpfc_worker_wake_up(phba); |
5e9d9b82 | 1820 | } |
92d7f7b0 | 1821 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e JB |
1822 | return; |
1823 | } | |
1824 | ||
1825 | void | |
1826 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) | |
1827 | { | |
2e0fef85 JS |
1828 | struct lpfc_vport *vport = ndlp->vport; |
1829 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
1830 | uint32_t cmd, did, retry; | |
dea3101e | 1831 | |
2e0fef85 | 1832 | spin_lock_irq(shost->host_lock); |
5024ab17 JW |
1833 | did = ndlp->nlp_DID; |
1834 | cmd = ndlp->nlp_last_elscmd; | |
1835 | ndlp->nlp_last_elscmd = 0; | |
dea3101e JB |
1836 | |
1837 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
2e0fef85 | 1838 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
1839 | return; |
1840 | } | |
1841 | ||
1842 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | |
2e0fef85 | 1843 | spin_unlock_irq(shost->host_lock); |
1a169689 JS |
1844 | /* |
1845 | * If a discovery event readded nlp_delayfunc after timer | |
1846 | * firing and before processing the timer, cancel the | |
1847 | * nlp_delayfunc. | |
1848 | */ | |
1849 | del_timer_sync(&ndlp->nlp_delayfunc); | |
dea3101e JB |
1850 | retry = ndlp->nlp_retry; |
1851 | ||
1852 | switch (cmd) { | |
1853 | case ELS_CMD_FLOGI: | |
2e0fef85 | 1854 | lpfc_issue_els_flogi(vport, ndlp, retry); |
dea3101e JB |
1855 | break; |
1856 | case ELS_CMD_PLOGI: | |
2e0fef85 | 1857 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
5024ab17 | 1858 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 1859 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
6ad42535 | 1860 | } |
dea3101e JB |
1861 | break; |
1862 | case ELS_CMD_ADISC: | |
2e0fef85 | 1863 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
5024ab17 | 1864 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 1865 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
6ad42535 | 1866 | } |
dea3101e JB |
1867 | break; |
1868 | case ELS_CMD_PRLI: | |
2e0fef85 | 1869 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
5024ab17 | 1870 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 1871 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
6ad42535 | 1872 | } |
dea3101e JB |
1873 | break; |
1874 | case ELS_CMD_LOGO: | |
2e0fef85 | 1875 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
5024ab17 | 1876 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 1877 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
6ad42535 | 1878 | } |
dea3101e | 1879 | break; |
92d7f7b0 JS |
1880 | case ELS_CMD_FDISC: |
1881 | lpfc_issue_els_fdisc(vport, ndlp, retry); | |
1882 | break; | |
dea3101e JB |
1883 | } |
1884 | return; | |
1885 | } | |
1886 | ||
1887 | static int | |
2e0fef85 JS |
1888 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1889 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1890 | { |
2e0fef85 JS |
1891 | struct lpfc_vport *vport = cmdiocb->vport; |
1892 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
1893 | IOCB_t *irsp = &rspiocb->iocb; | |
1894 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
1895 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
dea3101e JB |
1896 | uint32_t *elscmd; |
1897 | struct ls_rjt stat; | |
2e0fef85 | 1898 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
98c9ea5c | 1899 | int logerr = 0; |
2e0fef85 | 1900 | uint32_t cmd = 0; |
488d1469 | 1901 | uint32_t did; |
dea3101e | 1902 | |
488d1469 | 1903 | |
dea3101e JB |
1904 | /* Note: context2 may be 0 for internal driver abort |
1905 | * of delays ELS command. | |
1906 | */ | |
1907 | ||
1908 | if (pcmd && pcmd->virt) { | |
1909 | elscmd = (uint32_t *) (pcmd->virt); | |
1910 | cmd = *elscmd++; | |
1911 | } | |
1912 | ||
e47c9093 | 1913 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
488d1469 JS |
1914 | did = ndlp->nlp_DID; |
1915 | else { | |
1916 | /* We should only hit this case for retrying PLOGI */ | |
1917 | did = irsp->un.elsreq64.remoteID; | |
2e0fef85 | 1918 | ndlp = lpfc_findnode_did(vport, did); |
e47c9093 JS |
1919 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
1920 | && (cmd != ELS_CMD_PLOGI)) | |
488d1469 JS |
1921 | return 1; |
1922 | } | |
1923 | ||
858c9f6c JS |
1924 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1925 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", | |
1926 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); | |
1927 | ||
dea3101e JB |
1928 | switch (irsp->ulpStatus) { |
1929 | case IOSTAT_FCP_RSP_ERROR: | |
1930 | case IOSTAT_REMOTE_STOP: | |
1931 | break; | |
1932 | ||
1933 | case IOSTAT_LOCAL_REJECT: | |
1934 | switch ((irsp->un.ulpWord[4] & 0xff)) { | |
1935 | case IOERR_LOOP_OPEN_FAILURE: | |
2e0fef85 | 1936 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
92d7f7b0 | 1937 | delay = 1000; |
dea3101e JB |
1938 | retry = 1; |
1939 | break; | |
1940 | ||
92d7f7b0 | 1941 | case IOERR_ILLEGAL_COMMAND: |
7f5f3d0d JS |
1942 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
1943 | "0124 Retry illegal cmd x%x " | |
1944 | "retry:x%x delay:x%x\n", | |
1945 | cmd, cmdiocb->retry, delay); | |
1946 | retry = 1; | |
1947 | /* All command's retry policy */ | |
1948 | maxretry = 8; | |
1949 | if (cmdiocb->retry > 2) | |
1950 | delay = 1000; | |
92d7f7b0 JS |
1951 | break; |
1952 | ||
dea3101e | 1953 | case IOERR_NO_RESOURCES: |
98c9ea5c | 1954 | logerr = 1; /* HBA out of resources */ |
858c9f6c JS |
1955 | retry = 1; |
1956 | if (cmdiocb->retry > 100) | |
1957 | delay = 100; | |
1958 | maxretry = 250; | |
1959 | break; | |
1960 | ||
1961 | case IOERR_ILLEGAL_FRAME: | |
92d7f7b0 | 1962 | delay = 100; |
dea3101e JB |
1963 | retry = 1; |
1964 | break; | |
1965 | ||
858c9f6c | 1966 | case IOERR_SEQUENCE_TIMEOUT: |
dea3101e JB |
1967 | case IOERR_INVALID_RPI: |
1968 | retry = 1; | |
1969 | break; | |
1970 | } | |
1971 | break; | |
1972 | ||
1973 | case IOSTAT_NPORT_RJT: | |
1974 | case IOSTAT_FABRIC_RJT: | |
1975 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
1976 | retry = 1; | |
1977 | break; | |
1978 | } | |
1979 | break; | |
1980 | ||
1981 | case IOSTAT_NPORT_BSY: | |
1982 | case IOSTAT_FABRIC_BSY: | |
98c9ea5c | 1983 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
dea3101e JB |
1984 | retry = 1; |
1985 | break; | |
1986 | ||
1987 | case IOSTAT_LS_RJT: | |
1988 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); | |
1989 | /* Added for Vendor specifc support | |
1990 | * Just keep retrying for these Rsn / Exp codes | |
1991 | */ | |
1992 | switch (stat.un.b.lsRjtRsnCode) { | |
1993 | case LSRJT_UNABLE_TPC: | |
1994 | if (stat.un.b.lsRjtRsnCodeExp == | |
1995 | LSEXP_CMD_IN_PROGRESS) { | |
1996 | if (cmd == ELS_CMD_PLOGI) { | |
92d7f7b0 | 1997 | delay = 1000; |
dea3101e JB |
1998 | maxretry = 48; |
1999 | } | |
2000 | retry = 1; | |
2001 | break; | |
2002 | } | |
2003 | if (cmd == ELS_CMD_PLOGI) { | |
92d7f7b0 | 2004 | delay = 1000; |
dea3101e JB |
2005 | maxretry = lpfc_max_els_tries + 1; |
2006 | retry = 1; | |
2007 | break; | |
2008 | } | |
92d7f7b0 JS |
2009 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
2010 | (cmd == ELS_CMD_FDISC) && | |
2011 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ | |
e8b62011 JS |
2012 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2013 | "0125 FDISC Failed (x%x). " | |
2014 | "Fabric out of resources\n", | |
2015 | stat.un.lsRjtError); | |
92d7f7b0 JS |
2016 | lpfc_vport_set_state(vport, |
2017 | FC_VPORT_NO_FABRIC_RSCS); | |
2018 | } | |
dea3101e JB |
2019 | break; |
2020 | ||
2021 | case LSRJT_LOGICAL_BSY: | |
858c9f6c JS |
2022 | if ((cmd == ELS_CMD_PLOGI) || |
2023 | (cmd == ELS_CMD_PRLI)) { | |
92d7f7b0 | 2024 | delay = 1000; |
dea3101e | 2025 | maxretry = 48; |
92d7f7b0 | 2026 | } else if (cmd == ELS_CMD_FDISC) { |
51ef4c26 JS |
2027 | /* FDISC retry policy */ |
2028 | maxretry = 48; | |
2029 | if (cmdiocb->retry >= 32) | |
2030 | delay = 1000; | |
dea3101e JB |
2031 | } |
2032 | retry = 1; | |
2033 | break; | |
92d7f7b0 JS |
2034 | |
2035 | case LSRJT_LOGICAL_ERR: | |
7f5f3d0d JS |
2036 | /* There are some cases where switches return this |
2037 | * error when they are not ready and should be returning | |
2038 | * Logical Busy. We should delay every time. | |
2039 | */ | |
2040 | if (cmd == ELS_CMD_FDISC && | |
2041 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { | |
2042 | maxretry = 3; | |
2043 | delay = 1000; | |
2044 | retry = 1; | |
2045 | break; | |
2046 | } | |
92d7f7b0 JS |
2047 | case LSRJT_PROTOCOL_ERR: |
2048 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
2049 | (cmd == ELS_CMD_FDISC) && | |
2050 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || | |
2051 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) | |
2052 | ) { | |
e8b62011 JS |
2053 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2054 | "0123 FDISC Failed (x%x). " | |
2055 | "Fabric Detected Bad WWN\n", | |
2056 | stat.un.lsRjtError); | |
92d7f7b0 JS |
2057 | lpfc_vport_set_state(vport, |
2058 | FC_VPORT_FABRIC_REJ_WWN); | |
2059 | } | |
2060 | break; | |
dea3101e JB |
2061 | } |
2062 | break; | |
2063 | ||
2064 | case IOSTAT_INTERMED_RSP: | |
2065 | case IOSTAT_BA_RJT: | |
2066 | break; | |
2067 | ||
2068 | default: | |
2069 | break; | |
2070 | } | |
2071 | ||
488d1469 | 2072 | if (did == FDMI_DID) |
dea3101e | 2073 | retry = 1; |
dea3101e | 2074 | |
98c9ea5c | 2075 | if ((cmd == ELS_CMD_FLOGI) && |
1b32f6aa JS |
2076 | (phba->fc_topology != TOPOLOGY_LOOP) && |
2077 | !lpfc_error_lost_link(irsp)) { | |
98c9ea5c JS |
2078 | /* FLOGI retry policy */ |
2079 | retry = 1; | |
2080 | maxretry = 48; | |
2081 | if (cmdiocb->retry >= 32) | |
2082 | delay = 1000; | |
2083 | } | |
2084 | ||
dea3101e JB |
2085 | if ((++cmdiocb->retry) >= maxretry) { |
2086 | phba->fc_stat.elsRetryExceeded++; | |
2087 | retry = 0; | |
2088 | } | |
2089 | ||
ed957684 JS |
2090 | if ((vport->load_flag & FC_UNLOADING) != 0) |
2091 | retry = 0; | |
2092 | ||
dea3101e JB |
2093 | if (retry) { |
2094 | ||
2095 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ | |
e8b62011 JS |
2096 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2097 | "0107 Retry ELS command x%x to remote " | |
2098 | "NPORT x%x Data: x%x x%x\n", | |
2099 | cmd, did, cmdiocb->retry, delay); | |
dea3101e | 2100 | |
858c9f6c JS |
2101 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
2102 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || | |
2103 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { | |
2104 | /* Don't reset timer for no resources */ | |
2105 | ||
dea3101e | 2106 | /* If discovery / RSCN timer is running, reset it */ |
2e0fef85 | 2107 | if (timer_pending(&vport->fc_disctmo) || |
92d7f7b0 | 2108 | (vport->fc_flag & FC_RSCN_MODE)) |
2e0fef85 | 2109 | lpfc_set_disctmo(vport); |
dea3101e JB |
2110 | } |
2111 | ||
2112 | phba->fc_stat.elsXmitRetry++; | |
58da1ffb | 2113 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
dea3101e JB |
2114 | phba->fc_stat.elsDelayRetry++; |
2115 | ndlp->nlp_retry = cmdiocb->retry; | |
2116 | ||
92d7f7b0 JS |
2117 | /* delay is specified in milliseconds */ |
2118 | mod_timer(&ndlp->nlp_delayfunc, | |
2119 | jiffies + msecs_to_jiffies(delay)); | |
2e0fef85 | 2120 | spin_lock_irq(shost->host_lock); |
dea3101e | 2121 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 2122 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2123 | |
5024ab17 | 2124 | ndlp->nlp_prev_state = ndlp->nlp_state; |
858c9f6c JS |
2125 | if (cmd == ELS_CMD_PRLI) |
2126 | lpfc_nlp_set_state(vport, ndlp, | |
2127 | NLP_STE_REG_LOGIN_ISSUE); | |
2128 | else | |
2129 | lpfc_nlp_set_state(vport, ndlp, | |
2130 | NLP_STE_NPR_NODE); | |
dea3101e JB |
2131 | ndlp->nlp_last_elscmd = cmd; |
2132 | ||
c9f8735b | 2133 | return 1; |
dea3101e JB |
2134 | } |
2135 | switch (cmd) { | |
2136 | case ELS_CMD_FLOGI: | |
2e0fef85 | 2137 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
c9f8735b | 2138 | return 1; |
92d7f7b0 JS |
2139 | case ELS_CMD_FDISC: |
2140 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); | |
2141 | return 1; | |
dea3101e | 2142 | case ELS_CMD_PLOGI: |
58da1ffb | 2143 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
488d1469 | 2144 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 2145 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 2146 | NLP_STE_PLOGI_ISSUE); |
488d1469 | 2147 | } |
2e0fef85 | 2148 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
c9f8735b | 2149 | return 1; |
dea3101e | 2150 | case ELS_CMD_ADISC: |
5024ab17 | 2151 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
2152 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
2153 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 2154 | return 1; |
dea3101e | 2155 | case ELS_CMD_PRLI: |
5024ab17 | 2156 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
2157 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
2158 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 2159 | return 1; |
dea3101e | 2160 | case ELS_CMD_LOGO: |
5024ab17 | 2161 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
2162 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
2163 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); | |
c9f8735b | 2164 | return 1; |
dea3101e JB |
2165 | } |
2166 | } | |
dea3101e | 2167 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
98c9ea5c JS |
2168 | if (logerr) { |
2169 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
2170 | "0137 No retry ELS command x%x to remote " | |
2171 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", | |
2172 | cmd, did, irsp->ulpStatus, | |
2173 | irsp->un.ulpWord[4]); | |
2174 | } | |
2175 | else { | |
2176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, | |
a58cbd52 JS |
2177 | "0108 No retry ELS command x%x to remote " |
2178 | "NPORT x%x Retried:%d Error:x%x/%x\n", | |
2179 | cmd, did, cmdiocb->retry, irsp->ulpStatus, | |
2180 | irsp->un.ulpWord[4]); | |
98c9ea5c | 2181 | } |
c9f8735b | 2182 | return 0; |
dea3101e JB |
2183 | } |
2184 | ||
09372820 | 2185 | static int |
87af33fe JS |
2186 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
2187 | { | |
2188 | struct lpfc_dmabuf *buf_ptr; | |
2189 | ||
2190 | /* Free the response before processing the command. */ | |
2191 | if (!list_empty(&buf_ptr1->list)) { | |
2192 | list_remove_head(&buf_ptr1->list, buf_ptr, | |
2193 | struct lpfc_dmabuf, | |
2194 | list); | |
2195 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
2196 | kfree(buf_ptr); | |
2197 | } | |
2198 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); | |
2199 | kfree(buf_ptr1); | |
2200 | return 0; | |
2201 | } | |
2202 | ||
09372820 | 2203 | static int |
87af33fe JS |
2204 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
2205 | { | |
2206 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
2207 | kfree(buf_ptr); | |
2208 | return 0; | |
2209 | } | |
2210 | ||
dea3101e | 2211 | int |
329f9bc7 | 2212 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
dea3101e JB |
2213 | { |
2214 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; | |
a8adb832 JS |
2215 | struct lpfc_nodelist *ndlp; |
2216 | ||
2217 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; | |
2218 | if (ndlp) { | |
2219 | if (ndlp->nlp_flag & NLP_DEFER_RM) { | |
2220 | lpfc_nlp_put(ndlp); | |
dea3101e | 2221 | |
a8adb832 JS |
2222 | /* If the ndlp is not being used by another discovery |
2223 | * thread, free it. | |
2224 | */ | |
2225 | if (!lpfc_nlp_not_used(ndlp)) { | |
2226 | /* If ndlp is being used by another discovery | |
2227 | * thread, just clear NLP_DEFER_RM | |
2228 | */ | |
2229 | ndlp->nlp_flag &= ~NLP_DEFER_RM; | |
2230 | } | |
2231 | } | |
2232 | else | |
2233 | lpfc_nlp_put(ndlp); | |
329f9bc7 JS |
2234 | elsiocb->context1 = NULL; |
2235 | } | |
dea3101e JB |
2236 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
2237 | if (elsiocb->context2) { | |
0ff10d46 JS |
2238 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
2239 | /* Firmware could still be in progress of DMAing | |
2240 | * payload, so don't free data buffer till after | |
2241 | * a hbeat. | |
2242 | */ | |
2243 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; | |
2244 | buf_ptr = elsiocb->context2; | |
2245 | elsiocb->context2 = NULL; | |
2246 | if (buf_ptr) { | |
2247 | buf_ptr1 = NULL; | |
2248 | spin_lock_irq(&phba->hbalock); | |
2249 | if (!list_empty(&buf_ptr->list)) { | |
2250 | list_remove_head(&buf_ptr->list, | |
2251 | buf_ptr1, struct lpfc_dmabuf, | |
2252 | list); | |
2253 | INIT_LIST_HEAD(&buf_ptr1->list); | |
2254 | list_add_tail(&buf_ptr1->list, | |
2255 | &phba->elsbuf); | |
2256 | phba->elsbuf_cnt++; | |
2257 | } | |
2258 | INIT_LIST_HEAD(&buf_ptr->list); | |
2259 | list_add_tail(&buf_ptr->list, &phba->elsbuf); | |
2260 | phba->elsbuf_cnt++; | |
2261 | spin_unlock_irq(&phba->hbalock); | |
2262 | } | |
2263 | } else { | |
2264 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; | |
2265 | lpfc_els_free_data(phba, buf_ptr1); | |
2266 | } | |
dea3101e JB |
2267 | } |
2268 | ||
2269 | if (elsiocb->context3) { | |
2270 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; | |
87af33fe | 2271 | lpfc_els_free_bpl(phba, buf_ptr); |
dea3101e | 2272 | } |
604a3e30 | 2273 | lpfc_sli_release_iocbq(phba, elsiocb); |
dea3101e JB |
2274 | return 0; |
2275 | } | |
2276 | ||
2277 | static void | |
2e0fef85 JS |
2278 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
2279 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 2280 | { |
2e0fef85 JS |
2281 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
2282 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c JS |
2283 | IOCB_t *irsp; |
2284 | ||
2285 | irsp = &rspiocb->iocb; | |
2286 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
2287 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", | |
2288 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); | |
dea3101e | 2289 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
e8b62011 JS |
2290 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2291 | "0109 ACC to LOGO completes to NPort x%x " | |
2292 | "Data: x%x x%x x%x\n", | |
2293 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2294 | ndlp->nlp_rpi); | |
87af33fe JS |
2295 | |
2296 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | |
2297 | /* NPort Recovery mode or node is just allocated */ | |
2298 | if (!lpfc_nlp_not_used(ndlp)) { | |
2299 | /* If the ndlp is being used by another discovery | |
2300 | * thread, just unregister the RPI. | |
2301 | */ | |
2302 | lpfc_unreg_rpi(vport, ndlp); | |
fa4066b6 JS |
2303 | } else { |
2304 | /* Indicate the node has already released, should | |
2305 | * not reference to it from within lpfc_els_free_iocb. | |
2306 | */ | |
2307 | cmdiocb->context1 = NULL; | |
87af33fe | 2308 | } |
dea3101e JB |
2309 | } |
2310 | lpfc_els_free_iocb(phba, cmdiocb); | |
2311 | return; | |
2312 | } | |
2313 | ||
858c9f6c JS |
2314 | void |
2315 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
2316 | { | |
2317 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | |
2318 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
2319 | ||
2320 | pmb->context1 = NULL; | |
2321 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2322 | kfree(mp); | |
2323 | mempool_free(pmb, phba->mbox_mem_pool); | |
58da1ffb | 2324 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
a8adb832 | 2325 | lpfc_nlp_put(ndlp); |
a8adb832 JS |
2326 | /* This is the end of the default RPI cleanup logic for this |
2327 | * ndlp. If no other discovery threads are using this ndlp. | |
2328 | * we should free all resources associated with it. | |
2329 | */ | |
2330 | lpfc_nlp_not_used(ndlp); | |
2331 | } | |
858c9f6c JS |
2332 | return; |
2333 | } | |
2334 | ||
dea3101e | 2335 | static void |
858c9f6c | 2336 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
329f9bc7 | 2337 | struct lpfc_iocbq *rspiocb) |
dea3101e | 2338 | { |
2e0fef85 JS |
2339 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
2340 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; | |
2341 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; | |
87af33fe JS |
2342 | IOCB_t *irsp; |
2343 | uint8_t *pcmd; | |
dea3101e | 2344 | LPFC_MBOXQ_t *mbox = NULL; |
2e0fef85 | 2345 | struct lpfc_dmabuf *mp = NULL; |
87af33fe | 2346 | uint32_t ls_rjt = 0; |
dea3101e | 2347 | |
33ccf8d1 JS |
2348 | irsp = &rspiocb->iocb; |
2349 | ||
dea3101e JB |
2350 | if (cmdiocb->context_un.mbox) |
2351 | mbox = cmdiocb->context_un.mbox; | |
2352 | ||
fa4066b6 JS |
2353 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
2354 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. | |
2355 | */ | |
87af33fe | 2356 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
58da1ffb JS |
2357 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
2358 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { | |
fa4066b6 JS |
2359 | /* A LS_RJT associated with Default RPI cleanup has its own |
2360 | * seperate code path. | |
87af33fe JS |
2361 | */ |
2362 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
2363 | ls_rjt = 1; | |
2364 | } | |
2365 | ||
dea3101e | 2366 | /* Check to see if link went down during discovery */ |
58da1ffb | 2367 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
dea3101e | 2368 | if (mbox) { |
14691150 JS |
2369 | mp = (struct lpfc_dmabuf *) mbox->context1; |
2370 | if (mp) { | |
2371 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2372 | kfree(mp); | |
2373 | } | |
329f9bc7 | 2374 | mempool_free(mbox, phba->mbox_mem_pool); |
dea3101e | 2375 | } |
58da1ffb JS |
2376 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
2377 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) | |
fa4066b6 | 2378 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 2379 | ndlp = NULL; |
fa4066b6 JS |
2380 | /* Indicate the node has already released, |
2381 | * should not reference to it from within | |
2382 | * the routine lpfc_els_free_iocb. | |
2383 | */ | |
2384 | cmdiocb->context1 = NULL; | |
2385 | } | |
dea3101e JB |
2386 | goto out; |
2387 | } | |
2388 | ||
858c9f6c | 2389 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
51ef4c26 | 2390 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
858c9f6c | 2391 | irsp->ulpStatus, irsp->un.ulpWord[4], |
51ef4c26 | 2392 | cmdiocb->iocb.un.elsreq64.remoteID); |
dea3101e | 2393 | /* ELS response tag <ulpIoTag> completes */ |
e8b62011 JS |
2394 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2395 | "0110 ELS response tag x%x completes " | |
2396 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", | |
2397 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, | |
2398 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, | |
2399 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2400 | ndlp->nlp_rpi); | |
dea3101e JB |
2401 | if (mbox) { |
2402 | if ((rspiocb->iocb.ulpStatus == 0) | |
2403 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { | |
2e0fef85 | 2404 | lpfc_unreg_rpi(vport, ndlp); |
e47c9093 JS |
2405 | /* Increment reference count to ndlp to hold the |
2406 | * reference to ndlp for the callback function. | |
2407 | */ | |
329f9bc7 | 2408 | mbox->context2 = lpfc_nlp_get(ndlp); |
2e0fef85 | 2409 | mbox->vport = vport; |
858c9f6c JS |
2410 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
2411 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
2412 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
2413 | } | |
2414 | else { | |
2415 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | |
2416 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
2417 | lpfc_nlp_set_state(vport, ndlp, | |
2e0fef85 | 2418 | NLP_STE_REG_LOGIN_ISSUE); |
858c9f6c | 2419 | } |
0b727fea | 2420 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
e47c9093 | 2421 | != MBX_NOT_FINISHED) |
dea3101e | 2422 | goto out; |
e47c9093 JS |
2423 | else |
2424 | /* Decrement the ndlp reference count we | |
2425 | * set for this failed mailbox command. | |
2426 | */ | |
2427 | lpfc_nlp_put(ndlp); | |
98c9ea5c JS |
2428 | |
2429 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ | |
2430 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
2431 | "0138 ELS rsp: Cannot issue reg_login for x%x " | |
2432 | "Data: x%x x%x x%x\n", | |
2433 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2434 | ndlp->nlp_rpi); | |
2435 | ||
fa4066b6 | 2436 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 2437 | ndlp = NULL; |
fa4066b6 JS |
2438 | /* Indicate node has already been released, |
2439 | * should not reference to it from within | |
2440 | * the routine lpfc_els_free_iocb. | |
2441 | */ | |
2442 | cmdiocb->context1 = NULL; | |
2443 | } | |
dea3101e | 2444 | } else { |
858c9f6c JS |
2445 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
2446 | if (!lpfc_error_lost_link(irsp) && | |
2447 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | |
fa4066b6 | 2448 | if (lpfc_nlp_not_used(ndlp)) { |
98c9ea5c | 2449 | ndlp = NULL; |
fa4066b6 JS |
2450 | /* Indicate node has already been |
2451 | * released, should not reference | |
2452 | * to it from within the routine | |
2453 | * lpfc_els_free_iocb. | |
2454 | */ | |
2455 | cmdiocb->context1 = NULL; | |
2456 | } | |
dea3101e JB |
2457 | } |
2458 | } | |
14691150 JS |
2459 | mp = (struct lpfc_dmabuf *) mbox->context1; |
2460 | if (mp) { | |
2461 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2462 | kfree(mp); | |
2463 | } | |
2464 | mempool_free(mbox, phba->mbox_mem_pool); | |
dea3101e JB |
2465 | } |
2466 | out: | |
58da1ffb | 2467 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
2e0fef85 | 2468 | spin_lock_irq(shost->host_lock); |
858c9f6c | 2469 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
2e0fef85 | 2470 | spin_unlock_irq(shost->host_lock); |
87af33fe JS |
2471 | |
2472 | /* If the node is not being used by another discovery thread, | |
2473 | * and we are sending a reject, we are done with it. | |
2474 | * Release driver reference count here and free associated | |
2475 | * resources. | |
2476 | */ | |
2477 | if (ls_rjt) | |
fa4066b6 JS |
2478 | if (lpfc_nlp_not_used(ndlp)) |
2479 | /* Indicate node has already been released, | |
2480 | * should not reference to it from within | |
2481 | * the routine lpfc_els_free_iocb. | |
2482 | */ | |
2483 | cmdiocb->context1 = NULL; | |
dea3101e | 2484 | } |
87af33fe | 2485 | |
dea3101e JB |
2486 | lpfc_els_free_iocb(phba, cmdiocb); |
2487 | return; | |
2488 | } | |
2489 | ||
2490 | int | |
2e0fef85 JS |
2491 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
2492 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, | |
51ef4c26 | 2493 | LPFC_MBOXQ_t *mbox) |
dea3101e | 2494 | { |
2e0fef85 JS |
2495 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2496 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
2497 | IOCB_t *icmd; |
2498 | IOCB_t *oldcmd; | |
2499 | struct lpfc_iocbq *elsiocb; | |
2500 | struct lpfc_sli_ring *pring; | |
2501 | struct lpfc_sli *psli; | |
2502 | uint8_t *pcmd; | |
2503 | uint16_t cmdsize; | |
2504 | int rc; | |
82d9a2a2 | 2505 | ELS_PKT *els_pkt_ptr; |
dea3101e JB |
2506 | |
2507 | psli = &phba->sli; | |
2508 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
2509 | oldcmd = &oldiocb->iocb; | |
2510 | ||
2511 | switch (flag) { | |
2512 | case ELS_CMD_ACC: | |
92d7f7b0 | 2513 | cmdsize = sizeof(uint32_t); |
2e0fef85 JS |
2514 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
2515 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 2516 | if (!elsiocb) { |
2e0fef85 | 2517 | spin_lock_irq(shost->host_lock); |
5024ab17 | 2518 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
2e0fef85 | 2519 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 2520 | return 1; |
dea3101e | 2521 | } |
2e0fef85 | 2522 | |
dea3101e JB |
2523 | icmd = &elsiocb->iocb; |
2524 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
2525 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
2526 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 2527 | pcmd += sizeof(uint32_t); |
858c9f6c JS |
2528 | |
2529 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
2530 | "Issue ACC: did:x%x flg:x%x", | |
2531 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
dea3101e JB |
2532 | break; |
2533 | case ELS_CMD_PLOGI: | |
92d7f7b0 | 2534 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
2e0fef85 JS |
2535 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
2536 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 2537 | if (!elsiocb) |
c9f8735b | 2538 | return 1; |
488d1469 | 2539 | |
dea3101e JB |
2540 | icmd = &elsiocb->iocb; |
2541 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
2542 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
2543 | ||
2544 | if (mbox) | |
2545 | elsiocb->context_un.mbox = mbox; | |
2546 | ||
2547 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 JS |
2548 | pcmd += sizeof(uint32_t); |
2549 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); | |
858c9f6c JS |
2550 | |
2551 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
2552 | "Issue ACC PLOGI: did:x%x flg:x%x", | |
2553 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
dea3101e | 2554 | break; |
82d9a2a2 | 2555 | case ELS_CMD_PRLO: |
92d7f7b0 | 2556 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
2e0fef85 | 2557 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
82d9a2a2 JS |
2558 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
2559 | if (!elsiocb) | |
2560 | return 1; | |
2561 | ||
2562 | icmd = &elsiocb->iocb; | |
2563 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
2564 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
2565 | ||
2566 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, | |
92d7f7b0 | 2567 | sizeof(uint32_t) + sizeof(PRLO)); |
82d9a2a2 JS |
2568 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
2569 | els_pkt_ptr = (ELS_PKT *) pcmd; | |
2570 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; | |
858c9f6c JS |
2571 | |
2572 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, | |
2573 | "Issue ACC PRLO: did:x%x flg:x%x", | |
2574 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
82d9a2a2 | 2575 | break; |
dea3101e | 2576 | default: |
c9f8735b | 2577 | return 1; |
dea3101e | 2578 | } |
dea3101e | 2579 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
2580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2581 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " | |
2582 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", | |
2583 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
2584 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2585 | ndlp->nlp_rpi); | |
dea3101e | 2586 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
2e0fef85 | 2587 | spin_lock_irq(shost->host_lock); |
c9f8735b | 2588 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
2e0fef85 | 2589 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
2590 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
2591 | } else { | |
858c9f6c | 2592 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e JB |
2593 | } |
2594 | ||
2595 | phba->fc_stat.elsXmitACC++; | |
dea3101e | 2596 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
dea3101e JB |
2597 | if (rc == IOCB_ERROR) { |
2598 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 2599 | return 1; |
dea3101e | 2600 | } |
c9f8735b | 2601 | return 0; |
dea3101e JB |
2602 | } |
2603 | ||
2604 | int | |
2e0fef85 | 2605 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
858c9f6c JS |
2606 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
2607 | LPFC_MBOXQ_t *mbox) | |
dea3101e | 2608 | { |
2e0fef85 | 2609 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
2610 | IOCB_t *icmd; |
2611 | IOCB_t *oldcmd; | |
2612 | struct lpfc_iocbq *elsiocb; | |
2613 | struct lpfc_sli_ring *pring; | |
2614 | struct lpfc_sli *psli; | |
2615 | uint8_t *pcmd; | |
2616 | uint16_t cmdsize; | |
2617 | int rc; | |
2618 | ||
2619 | psli = &phba->sli; | |
2620 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
2621 | ||
92d7f7b0 | 2622 | cmdsize = 2 * sizeof(uint32_t); |
2e0fef85 JS |
2623 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
2624 | ndlp->nlp_DID, ELS_CMD_LS_RJT); | |
488d1469 | 2625 | if (!elsiocb) |
c9f8735b | 2626 | return 1; |
dea3101e JB |
2627 | |
2628 | icmd = &elsiocb->iocb; | |
2629 | oldcmd = &oldiocb->iocb; | |
2630 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
2631 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
2632 | ||
2633 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; | |
92d7f7b0 | 2634 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2635 | *((uint32_t *) (pcmd)) = rejectError; |
2636 | ||
51ef4c26 | 2637 | if (mbox) |
858c9f6c | 2638 | elsiocb->context_un.mbox = mbox; |
858c9f6c | 2639 | |
dea3101e | 2640 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
e8b62011 JS |
2641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2642 | "0129 Xmit ELS RJT x%x response tag x%x " | |
2643 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
2644 | "rpi x%x\n", | |
2645 | rejectError, elsiocb->iotag, | |
2646 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, | |
2647 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); | |
858c9f6c JS |
2648 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
2649 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", | |
2650 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); | |
2651 | ||
dea3101e | 2652 | phba->fc_stat.elsXmitLSRJT++; |
858c9f6c | 2653 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 2654 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
51ef4c26 | 2655 | |
dea3101e JB |
2656 | if (rc == IOCB_ERROR) { |
2657 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 2658 | return 1; |
dea3101e | 2659 | } |
c9f8735b | 2660 | return 0; |
dea3101e JB |
2661 | } |
2662 | ||
2663 | int | |
2e0fef85 JS |
2664 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
2665 | struct lpfc_nodelist *ndlp) | |
dea3101e | 2666 | { |
2e0fef85 JS |
2667 | struct lpfc_hba *phba = vport->phba; |
2668 | struct lpfc_sli *psli = &phba->sli; | |
2669 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
dea3101e | 2670 | ADISC *ap; |
2e0fef85 | 2671 | IOCB_t *icmd, *oldcmd; |
dea3101e | 2672 | struct lpfc_iocbq *elsiocb; |
dea3101e JB |
2673 | uint8_t *pcmd; |
2674 | uint16_t cmdsize; | |
2675 | int rc; | |
2676 | ||
92d7f7b0 | 2677 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
2e0fef85 JS |
2678 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
2679 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 2680 | if (!elsiocb) |
c9f8735b | 2681 | return 1; |
dea3101e | 2682 | |
5b8bd0c9 JS |
2683 | icmd = &elsiocb->iocb; |
2684 | oldcmd = &oldiocb->iocb; | |
2685 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
2686 | ||
dea3101e | 2687 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
e8b62011 JS |
2688 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2689 | "0130 Xmit ADISC ACC response iotag x%x xri: " | |
2690 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", | |
2691 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
2692 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2693 | ndlp->nlp_rpi); | |
dea3101e JB |
2694 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2695 | ||
2696 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 2697 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2698 | |
2699 | ap = (ADISC *) (pcmd); | |
2700 | ap->hardAL_PA = phba->fc_pref_ALPA; | |
92d7f7b0 JS |
2701 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
2702 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
2e0fef85 | 2703 | ap->DID = be32_to_cpu(vport->fc_myDID); |
dea3101e | 2704 | |
858c9f6c JS |
2705 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
2706 | "Issue ACC ADISC: did:x%x flg:x%x", | |
2707 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
2708 | ||
dea3101e | 2709 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 2710 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 2711 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
dea3101e JB |
2712 | if (rc == IOCB_ERROR) { |
2713 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 2714 | return 1; |
dea3101e | 2715 | } |
c9f8735b | 2716 | return 0; |
dea3101e JB |
2717 | } |
2718 | ||
2719 | int | |
2e0fef85 | 2720 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
5b8bd0c9 | 2721 | struct lpfc_nodelist *ndlp) |
dea3101e | 2722 | { |
2e0fef85 | 2723 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
2724 | PRLI *npr; |
2725 | lpfc_vpd_t *vpd; | |
2726 | IOCB_t *icmd; | |
2727 | IOCB_t *oldcmd; | |
2728 | struct lpfc_iocbq *elsiocb; | |
2729 | struct lpfc_sli_ring *pring; | |
2730 | struct lpfc_sli *psli; | |
2731 | uint8_t *pcmd; | |
2732 | uint16_t cmdsize; | |
2733 | int rc; | |
2734 | ||
2735 | psli = &phba->sli; | |
2736 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ | |
2737 | ||
92d7f7b0 | 2738 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
2e0fef85 | 2739 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
92d7f7b0 | 2740 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
c9f8735b JW |
2741 | if (!elsiocb) |
2742 | return 1; | |
dea3101e | 2743 | |
5b8bd0c9 JS |
2744 | icmd = &elsiocb->iocb; |
2745 | oldcmd = &oldiocb->iocb; | |
2746 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
dea3101e | 2747 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
e8b62011 JS |
2748 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2749 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " | |
2750 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
2751 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
2752 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
2753 | ndlp->nlp_rpi); | |
dea3101e JB |
2754 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
2755 | ||
2756 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); | |
92d7f7b0 | 2757 | pcmd += sizeof(uint32_t); |
dea3101e JB |
2758 | |
2759 | /* For PRLI, remainder of payload is PRLI parameter page */ | |
92d7f7b0 | 2760 | memset(pcmd, 0, sizeof(PRLI)); |
dea3101e JB |
2761 | |
2762 | npr = (PRLI *) pcmd; | |
2763 | vpd = &phba->vpd; | |
2764 | /* | |
0d2b6b83 JS |
2765 | * If the remote port is a target and our firmware version is 3.20 or |
2766 | * later, set the following bits for FC-TAPE support. | |
dea3101e | 2767 | */ |
0d2b6b83 JS |
2768 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && |
2769 | (vpd->rev.feaLevelHigh >= 0x02)) { | |
dea3101e JB |
2770 | npr->ConfmComplAllowed = 1; |
2771 | npr->Retry = 1; | |
2772 | npr->TaskRetryIdReq = 1; | |
2773 | } | |
2774 | ||
2775 | npr->acceptRspCode = PRLI_REQ_EXECUTED; | |
2776 | npr->estabImagePair = 1; | |
2777 | npr->readXferRdyDis = 1; | |
2778 | npr->ConfmComplAllowed = 1; | |
2779 | ||
2780 | npr->prliType = PRLI_FCP_TYPE; | |
2781 | npr->initiatorFunc = 1; | |
2782 | ||
858c9f6c JS |
2783 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
2784 | "Issue ACC PRLI: did:x%x flg:x%x", | |
2785 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
2786 | ||
dea3101e | 2787 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 2788 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
dea3101e | 2789 | |
dea3101e | 2790 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
dea3101e JB |
2791 | if (rc == IOCB_ERROR) { |
2792 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 2793 | return 1; |
dea3101e | 2794 | } |
c9f8735b | 2795 | return 0; |
dea3101e JB |
2796 | } |
2797 | ||
2798 | static int | |
2e0fef85 | 2799 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
329f9bc7 | 2800 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
dea3101e | 2801 | { |
2e0fef85 | 2802 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2803 | RNID *rn; |
2e0fef85 | 2804 | IOCB_t *icmd, *oldcmd; |
dea3101e JB |
2805 | struct lpfc_iocbq *elsiocb; |
2806 | struct lpfc_sli_ring *pring; | |
2807 | struct lpfc_sli *psli; | |
2808 | uint8_t *pcmd; | |
2809 | uint16_t cmdsize; | |
2810 | int rc; | |
2811 | ||
2812 | psli = &phba->sli; | |
2813 | pring = &psli->ring[LPFC_ELS_RING]; | |
2814 | ||
92d7f7b0 JS |
2815 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
2816 | + (2 * sizeof(struct lpfc_name)); | |
dea3101e | 2817 | if (format) |
92d7f7b0 | 2818 | cmdsize += sizeof(RNID_TOP_DISC); |
dea3101e | 2819 | |
2e0fef85 JS |
2820 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
2821 | ndlp->nlp_DID, ELS_CMD_ACC); | |
488d1469 | 2822 | if (!elsiocb) |
c9f8735b | 2823 | return 1; |
dea3101e | 2824 | |
5b8bd0c9 JS |
2825 | icmd = &elsiocb->iocb; |
2826 | oldcmd = &oldiocb->iocb; | |
2827 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
dea3101e | 2828 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
e8b62011 JS |
2829 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
2830 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", | |
2831 | elsiocb->iotag, elsiocb->iocb.ulpContext); | |
dea3101e | 2832 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
dea3101e | 2833 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
92d7f7b0 | 2834 | pcmd += sizeof(uint32_t); |
dea3101e | 2835 | |
92d7f7b0 | 2836 | memset(pcmd, 0, sizeof(RNID)); |
dea3101e JB |
2837 | rn = (RNID *) (pcmd); |
2838 | rn->Format = format; | |
92d7f7b0 JS |
2839 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
2840 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); | |
2841 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
dea3101e JB |
2842 | switch (format) { |
2843 | case 0: | |
2844 | rn->SpecificLen = 0; | |
2845 | break; | |
2846 | case RNID_TOPOLOGY_DISC: | |
92d7f7b0 | 2847 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
dea3101e | 2848 | memcpy(&rn->un.topologyDisc.portName, |
92d7f7b0 | 2849 | &vport->fc_portname, sizeof(struct lpfc_name)); |
dea3101e JB |
2850 | rn->un.topologyDisc.unitType = RNID_HBA; |
2851 | rn->un.topologyDisc.physPort = 0; | |
2852 | rn->un.topologyDisc.attachedNodes = 0; | |
2853 | break; | |
2854 | default: | |
2855 | rn->CommonLen = 0; | |
2856 | rn->SpecificLen = 0; | |
2857 | break; | |
2858 | } | |
2859 | ||
858c9f6c JS |
2860 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
2861 | "Issue ACC RNID: did:x%x flg:x%x", | |
2862 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
2863 | ||
dea3101e | 2864 | phba->fc_stat.elsXmitACC++; |
858c9f6c | 2865 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
329f9bc7 | 2866 | lpfc_nlp_put(ndlp); |
dea3101e JB |
2867 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
2868 | * it could be freed */ | |
2869 | ||
dea3101e | 2870 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
dea3101e JB |
2871 | if (rc == IOCB_ERROR) { |
2872 | lpfc_els_free_iocb(phba, elsiocb); | |
c9f8735b | 2873 | return 1; |
dea3101e | 2874 | } |
c9f8735b | 2875 | return 0; |
dea3101e JB |
2876 | } |
2877 | ||
2878 | int | |
2e0fef85 | 2879 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
dea3101e | 2880 | { |
2e0fef85 | 2881 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 2882 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 2883 | int sentadisc = 0; |
dea3101e | 2884 | |
685f0bf7 | 2885 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
2e0fef85 | 2886 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
2887 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2888 | continue; | |
685f0bf7 JS |
2889 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
2890 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | |
2891 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { | |
2e0fef85 | 2892 | spin_lock_irq(shost->host_lock); |
685f0bf7 | 2893 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 2894 | spin_unlock_irq(shost->host_lock); |
685f0bf7 | 2895 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 JS |
2896 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
2897 | lpfc_issue_els_adisc(vport, ndlp, 0); | |
685f0bf7 | 2898 | sentadisc++; |
2e0fef85 JS |
2899 | vport->num_disc_nodes++; |
2900 | if (vport->num_disc_nodes >= | |
3de2a653 | 2901 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
2902 | spin_lock_irq(shost->host_lock); |
2903 | vport->fc_flag |= FC_NLP_MORE; | |
2904 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 2905 | break; |
dea3101e JB |
2906 | } |
2907 | } | |
2908 | } | |
2909 | if (sentadisc == 0) { | |
2e0fef85 JS |
2910 | spin_lock_irq(shost->host_lock); |
2911 | vport->fc_flag &= ~FC_NLP_MORE; | |
2912 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 2913 | } |
2fe165b6 | 2914 | return sentadisc; |
dea3101e JB |
2915 | } |
2916 | ||
2917 | int | |
2e0fef85 | 2918 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
dea3101e | 2919 | { |
2e0fef85 | 2920 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 2921 | struct lpfc_nodelist *ndlp, *next_ndlp; |
2e0fef85 | 2922 | int sentplogi = 0; |
dea3101e | 2923 | |
2e0fef85 JS |
2924 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
2925 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2926 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2927 | continue; | |
685f0bf7 JS |
2928 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
2929 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && | |
2930 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && | |
2931 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { | |
2932 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
2e0fef85 JS |
2933 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
2934 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
685f0bf7 | 2935 | sentplogi++; |
2e0fef85 JS |
2936 | vport->num_disc_nodes++; |
2937 | if (vport->num_disc_nodes >= | |
3de2a653 | 2938 | vport->cfg_discovery_threads) { |
2e0fef85 JS |
2939 | spin_lock_irq(shost->host_lock); |
2940 | vport->fc_flag |= FC_NLP_MORE; | |
2941 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 2942 | break; |
dea3101e JB |
2943 | } |
2944 | } | |
2945 | } | |
87af33fe JS |
2946 | if (sentplogi) { |
2947 | lpfc_set_disctmo(vport); | |
2948 | } | |
2949 | else { | |
2e0fef85 JS |
2950 | spin_lock_irq(shost->host_lock); |
2951 | vport->fc_flag &= ~FC_NLP_MORE; | |
2952 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 2953 | } |
2fe165b6 | 2954 | return sentplogi; |
dea3101e JB |
2955 | } |
2956 | ||
92d7f7b0 | 2957 | void |
2e0fef85 | 2958 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
dea3101e | 2959 | { |
2e0fef85 JS |
2960 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2961 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
2962 | int i; |
2963 | ||
7f5f3d0d JS |
2964 | spin_lock_irq(shost->host_lock); |
2965 | if (vport->fc_rscn_flush) { | |
2966 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
2967 | spin_unlock_irq(shost->host_lock); | |
2968 | return; | |
2969 | } | |
2970 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ | |
2971 | vport->fc_rscn_flush = 1; | |
2972 | spin_unlock_irq(shost->host_lock); | |
2973 | ||
2e0fef85 | 2974 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 | 2975 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
2e0fef85 | 2976 | vport->fc_rscn_id_list[i] = NULL; |
dea3101e | 2977 | } |
2e0fef85 JS |
2978 | spin_lock_irq(shost->host_lock); |
2979 | vport->fc_rscn_id_cnt = 0; | |
2980 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); | |
2981 | spin_unlock_irq(shost->host_lock); | |
2982 | lpfc_can_disctmo(vport); | |
7f5f3d0d JS |
2983 | /* Indicate we are done walking this fc_rscn_id_list */ |
2984 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
2985 | } |
2986 | ||
2987 | int | |
2e0fef85 | 2988 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
dea3101e JB |
2989 | { |
2990 | D_ID ns_did; | |
2991 | D_ID rscn_did; | |
dea3101e | 2992 | uint32_t *lp; |
92d7f7b0 | 2993 | uint32_t payload_len, i; |
7f5f3d0d | 2994 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
2995 | |
2996 | ns_did.un.word = did; | |
dea3101e JB |
2997 | |
2998 | /* Never match fabric nodes for RSCNs */ | |
2999 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
2e0fef85 | 3000 | return 0; |
dea3101e JB |
3001 | |
3002 | /* If we are doing a FULL RSCN rediscovery, match everything */ | |
2e0fef85 | 3003 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
c9f8735b | 3004 | return did; |
dea3101e | 3005 | |
7f5f3d0d JS |
3006 | spin_lock_irq(shost->host_lock); |
3007 | if (vport->fc_rscn_flush) { | |
3008 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
3009 | spin_unlock_irq(shost->host_lock); | |
3010 | return 0; | |
3011 | } | |
3012 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
3013 | vport->fc_rscn_flush = 1; | |
3014 | spin_unlock_irq(shost->host_lock); | |
2e0fef85 | 3015 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
92d7f7b0 JS |
3016 | lp = vport->fc_rscn_id_list[i]->virt; |
3017 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); | |
3018 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 3019 | while (payload_len) { |
92d7f7b0 JS |
3020 | rscn_did.un.word = be32_to_cpu(*lp++); |
3021 | payload_len -= sizeof(uint32_t); | |
dea3101e JB |
3022 | switch (rscn_did.un.b.resv) { |
3023 | case 0: /* Single N_Port ID effected */ | |
2e0fef85 | 3024 | if (ns_did.un.word == rscn_did.un.word) |
7f5f3d0d | 3025 | goto return_did_out; |
dea3101e JB |
3026 | break; |
3027 | case 1: /* Whole N_Port Area effected */ | |
3028 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) | |
3029 | && (ns_did.un.b.area == rscn_did.un.b.area)) | |
7f5f3d0d | 3030 | goto return_did_out; |
dea3101e JB |
3031 | break; |
3032 | case 2: /* Whole N_Port Domain effected */ | |
3033 | if (ns_did.un.b.domain == rscn_did.un.b.domain) | |
7f5f3d0d | 3034 | goto return_did_out; |
dea3101e JB |
3035 | break; |
3036 | default: | |
2e0fef85 | 3037 | /* Unknown Identifier in RSCN node */ |
e8b62011 JS |
3038 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
3039 | "0217 Unknown Identifier in " | |
3040 | "RSCN payload Data: x%x\n", | |
3041 | rscn_did.un.word); | |
92d7f7b0 | 3042 | case 3: /* Whole Fabric effected */ |
7f5f3d0d | 3043 | goto return_did_out; |
dea3101e JB |
3044 | } |
3045 | } | |
92d7f7b0 | 3046 | } |
7f5f3d0d JS |
3047 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
3048 | vport->fc_rscn_flush = 0; | |
92d7f7b0 | 3049 | return 0; |
7f5f3d0d JS |
3050 | return_did_out: |
3051 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ | |
3052 | vport->fc_rscn_flush = 0; | |
3053 | return did; | |
dea3101e JB |
3054 | } |
3055 | ||
3056 | static int | |
2e0fef85 | 3057 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
dea3101e | 3058 | { |
685f0bf7 | 3059 | struct lpfc_nodelist *ndlp = NULL; |
dea3101e | 3060 | |
0d2b6b83 | 3061 | /* Move all affected nodes by pending RSCNs to NPR state. */ |
2e0fef85 | 3062 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 | 3063 | if (!NLP_CHK_NODE_ACT(ndlp) || |
0d2b6b83 JS |
3064 | (ndlp->nlp_state == NLP_STE_UNUSED_NODE) || |
3065 | !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) | |
685f0bf7 | 3066 | continue; |
2e0fef85 | 3067 | lpfc_disc_state_machine(vport, ndlp, NULL, |
0d2b6b83 JS |
3068 | NLP_EVT_DEVICE_RECOVERY); |
3069 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
dea3101e | 3070 | } |
c9f8735b | 3071 | return 0; |
dea3101e JB |
3072 | } |
3073 | ||
3074 | static int | |
2e0fef85 | 3075 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 3076 | struct lpfc_nodelist *ndlp) |
dea3101e | 3077 | { |
2e0fef85 JS |
3078 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3079 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3080 | struct lpfc_dmabuf *pcmd; |
92d7f7b0 | 3081 | uint32_t *lp, *datap; |
dea3101e | 3082 | IOCB_t *icmd; |
92d7f7b0 | 3083 | uint32_t payload_len, length, nportid, *cmd; |
7f5f3d0d | 3084 | int rscn_cnt; |
92d7f7b0 | 3085 | int rscn_id = 0, hba_id = 0; |
d2873e4c | 3086 | int i; |
dea3101e JB |
3087 | |
3088 | icmd = &cmdiocb->iocb; | |
3089 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
3090 | lp = (uint32_t *) pcmd->virt; | |
3091 | ||
92d7f7b0 JS |
3092 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
3093 | payload_len -= sizeof(uint32_t); /* take off word 0 */ | |
dea3101e | 3094 | /* RSCN received */ |
e8b62011 JS |
3095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3096 | "0214 RSCN received Data: x%x x%x x%x x%x\n", | |
7f5f3d0d JS |
3097 | vport->fc_flag, payload_len, *lp, |
3098 | vport->fc_rscn_id_cnt); | |
d2873e4c | 3099 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
2e0fef85 | 3100 | fc_host_post_event(shost, fc_get_event_number(), |
d2873e4c JS |
3101 | FCH_EVT_RSCN, lp[i]); |
3102 | ||
dea3101e JB |
3103 | /* If we are about to begin discovery, just ACC the RSCN. |
3104 | * Discovery processing will satisfy it. | |
3105 | */ | |
2e0fef85 | 3106 | if (vport->port_state <= LPFC_NS_QRY) { |
858c9f6c JS |
3107 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
3108 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", | |
3109 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
3110 | ||
51ef4c26 | 3111 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
c9f8735b | 3112 | return 0; |
dea3101e JB |
3113 | } |
3114 | ||
92d7f7b0 JS |
3115 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
3116 | * just ACC and ignore it. | |
3117 | */ | |
3118 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
3de2a653 | 3119 | !(vport->cfg_peer_port_login)) { |
92d7f7b0 JS |
3120 | i = payload_len; |
3121 | datap = lp; | |
3122 | while (i > 0) { | |
3123 | nportid = *datap++; | |
3124 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); | |
3125 | i -= sizeof(uint32_t); | |
3126 | rscn_id++; | |
549e55cd JS |
3127 | if (lpfc_find_vport_by_did(phba, nportid)) |
3128 | hba_id++; | |
92d7f7b0 JS |
3129 | } |
3130 | if (rscn_id == hba_id) { | |
3131 | /* ALL NPortIDs in RSCN are on HBA */ | |
e8b62011 JS |
3132 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3133 | "0214 Ignore RSCN " | |
3134 | "Data: x%x x%x x%x x%x\n", | |
3135 | vport->fc_flag, payload_len, | |
7f5f3d0d | 3136 | *lp, vport->fc_rscn_id_cnt); |
858c9f6c JS |
3137 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
3138 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", | |
3139 | ndlp->nlp_DID, vport->port_state, | |
3140 | ndlp->nlp_flag); | |
3141 | ||
92d7f7b0 | 3142 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
51ef4c26 | 3143 | ndlp, NULL); |
92d7f7b0 JS |
3144 | return 0; |
3145 | } | |
3146 | } | |
3147 | ||
7f5f3d0d JS |
3148 | spin_lock_irq(shost->host_lock); |
3149 | if (vport->fc_rscn_flush) { | |
3150 | /* Another thread is walking fc_rscn_id_list on this vport */ | |
3151 | spin_unlock_irq(shost->host_lock); | |
3152 | vport->fc_flag |= FC_RSCN_DISCOVERY; | |
58da1ffb JS |
3153 | /* Send back ACC */ |
3154 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); | |
7f5f3d0d JS |
3155 | return 0; |
3156 | } | |
3157 | /* Indicate we are walking fc_rscn_id_list on this vport */ | |
3158 | vport->fc_rscn_flush = 1; | |
3159 | spin_unlock_irq(shost->host_lock); | |
3160 | /* Get the array count after sucessfully have the token */ | |
3161 | rscn_cnt = vport->fc_rscn_id_cnt; | |
dea3101e JB |
3162 | /* If we are already processing an RSCN, save the received |
3163 | * RSCN payload buffer, cmdiocb->context2 to process later. | |
3164 | */ | |
2e0fef85 | 3165 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
858c9f6c JS |
3166 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
3167 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", | |
3168 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
3169 | ||
09372820 | 3170 | spin_lock_irq(shost->host_lock); |
92d7f7b0 JS |
3171 | vport->fc_flag |= FC_RSCN_DEFERRED; |
3172 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && | |
2e0fef85 | 3173 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
2e0fef85 JS |
3174 | vport->fc_flag |= FC_RSCN_MODE; |
3175 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 JS |
3176 | if (rscn_cnt) { |
3177 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; | |
3178 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); | |
3179 | } | |
3180 | if ((rscn_cnt) && | |
3181 | (payload_len + length <= LPFC_BPL_SIZE)) { | |
3182 | *cmd &= ELS_CMD_MASK; | |
7f5f3d0d | 3183 | *cmd |= cpu_to_be32(payload_len + length); |
92d7f7b0 JS |
3184 | memcpy(((uint8_t *)cmd) + length, lp, |
3185 | payload_len); | |
3186 | } else { | |
3187 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; | |
3188 | vport->fc_rscn_id_cnt++; | |
3189 | /* If we zero, cmdiocb->context2, the calling | |
3190 | * routine will not try to free it. | |
3191 | */ | |
3192 | cmdiocb->context2 = NULL; | |
3193 | } | |
dea3101e | 3194 | /* Deferred RSCN */ |
e8b62011 JS |
3195 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3196 | "0235 Deferred RSCN " | |
3197 | "Data: x%x x%x x%x\n", | |
3198 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
3199 | vport->port_state); | |
dea3101e | 3200 | } else { |
2e0fef85 JS |
3201 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
3202 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 3203 | /* ReDiscovery RSCN */ |
e8b62011 JS |
3204 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3205 | "0234 ReDiscovery RSCN " | |
3206 | "Data: x%x x%x x%x\n", | |
3207 | vport->fc_rscn_id_cnt, vport->fc_flag, | |
3208 | vport->port_state); | |
dea3101e | 3209 | } |
7f5f3d0d JS |
3210 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
3211 | vport->fc_rscn_flush = 0; | |
dea3101e | 3212 | /* Send back ACC */ |
51ef4c26 | 3213 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 3214 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 3215 | lpfc_rscn_recovery_check(vport); |
09372820 | 3216 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 3217 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
09372820 | 3218 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 3219 | return 0; |
dea3101e | 3220 | } |
858c9f6c JS |
3221 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
3222 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", | |
3223 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); | |
3224 | ||
2e0fef85 JS |
3225 | spin_lock_irq(shost->host_lock); |
3226 | vport->fc_flag |= FC_RSCN_MODE; | |
3227 | spin_unlock_irq(shost->host_lock); | |
3228 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; | |
7f5f3d0d JS |
3229 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
3230 | vport->fc_rscn_flush = 0; | |
dea3101e JB |
3231 | /* |
3232 | * If we zero, cmdiocb->context2, the calling routine will | |
3233 | * not try to free it. | |
3234 | */ | |
3235 | cmdiocb->context2 = NULL; | |
2e0fef85 | 3236 | lpfc_set_disctmo(vport); |
dea3101e | 3237 | /* Send back ACC */ |
51ef4c26 | 3238 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 3239 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
2e0fef85 | 3240 | lpfc_rscn_recovery_check(vport); |
2e0fef85 | 3241 | return lpfc_els_handle_rscn(vport); |
dea3101e JB |
3242 | } |
3243 | ||
3244 | int | |
2e0fef85 | 3245 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
dea3101e JB |
3246 | { |
3247 | struct lpfc_nodelist *ndlp; | |
2e0fef85 | 3248 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 3249 | |
92d7f7b0 JS |
3250 | /* Ignore RSCN if the port is being torn down. */ |
3251 | if (vport->load_flag & FC_UNLOADING) { | |
3252 | lpfc_els_flush_rscn(vport); | |
3253 | return 0; | |
3254 | } | |
3255 | ||
dea3101e | 3256 | /* Start timer for RSCN processing */ |
2e0fef85 | 3257 | lpfc_set_disctmo(vport); |
dea3101e JB |
3258 | |
3259 | /* RSCN processed */ | |
e8b62011 JS |
3260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3261 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", | |
3262 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, | |
3263 | vport->port_state); | |
dea3101e JB |
3264 | |
3265 | /* To process RSCN, first compare RSCN data with NameServer */ | |
2e0fef85 | 3266 | vport->fc_ns_retry = 0; |
0ff10d46 JS |
3267 | vport->num_disc_nodes = 0; |
3268 | ||
2e0fef85 | 3269 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 JS |
3270 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
3271 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { | |
dea3101e | 3272 | /* Good ndlp, issue CT Request to NameServer */ |
92d7f7b0 | 3273 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
dea3101e JB |
3274 | /* Wait for NameServer query cmpl before we can |
3275 | continue */ | |
c9f8735b | 3276 | return 1; |
dea3101e JB |
3277 | } else { |
3278 | /* If login to NameServer does not exist, issue one */ | |
3279 | /* Good status, issue PLOGI to NameServer */ | |
2e0fef85 | 3280 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 | 3281 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
dea3101e JB |
3282 | /* Wait for NameServer login cmpl before we can |
3283 | continue */ | |
c9f8735b | 3284 | return 1; |
2e0fef85 | 3285 | |
e47c9093 JS |
3286 | if (ndlp) { |
3287 | ndlp = lpfc_enable_node(vport, ndlp, | |
3288 | NLP_STE_PLOGI_ISSUE); | |
3289 | if (!ndlp) { | |
3290 | lpfc_els_flush_rscn(vport); | |
3291 | return 0; | |
3292 | } | |
3293 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; | |
dea3101e | 3294 | } else { |
e47c9093 JS |
3295 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
3296 | if (!ndlp) { | |
3297 | lpfc_els_flush_rscn(vport); | |
3298 | return 0; | |
3299 | } | |
2e0fef85 | 3300 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
5024ab17 | 3301 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3302 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
dea3101e | 3303 | } |
e47c9093 JS |
3304 | ndlp->nlp_type |= NLP_FABRIC; |
3305 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); | |
3306 | /* Wait for NameServer login cmpl before we can | |
3307 | * continue | |
3308 | */ | |
3309 | return 1; | |
dea3101e JB |
3310 | } |
3311 | ||
2e0fef85 | 3312 | lpfc_els_flush_rscn(vport); |
c9f8735b | 3313 | return 0; |
dea3101e JB |
3314 | } |
3315 | ||
3316 | static int | |
2e0fef85 | 3317 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
51ef4c26 | 3318 | struct lpfc_nodelist *ndlp) |
dea3101e | 3319 | { |
2e0fef85 JS |
3320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3321 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
3322 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
3323 | uint32_t *lp = (uint32_t *) pcmd->virt; | |
3324 | IOCB_t *icmd = &cmdiocb->iocb; | |
3325 | struct serv_parm *sp; | |
3326 | LPFC_MBOXQ_t *mbox; | |
3327 | struct ls_rjt stat; | |
3328 | uint32_t cmd, did; | |
3329 | int rc; | |
3330 | ||
3331 | cmd = *lp++; | |
3332 | sp = (struct serv_parm *) lp; | |
3333 | ||
3334 | /* FLOGI received */ | |
3335 | ||
2e0fef85 | 3336 | lpfc_set_disctmo(vport); |
dea3101e JB |
3337 | |
3338 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
3339 | /* We should never receive a FLOGI in loop mode, ignore it */ | |
3340 | did = icmd->un.elsreq64.remoteID; | |
3341 | ||
3342 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in | |
3343 | Loop Mode */ | |
e8b62011 JS |
3344 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3345 | "0113 An FLOGI ELS command x%x was " | |
3346 | "received from DID x%x in Loop Mode\n", | |
3347 | cmd, did); | |
c9f8735b | 3348 | return 1; |
dea3101e JB |
3349 | } |
3350 | ||
3351 | did = Fabric_DID; | |
3352 | ||
2e0fef85 | 3353 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
dea3101e JB |
3354 | /* For a FLOGI we accept, then if our portname is greater |
3355 | * then the remote portname we initiate Nport login. | |
3356 | */ | |
3357 | ||
2e0fef85 | 3358 | rc = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 3359 | sizeof(struct lpfc_name)); |
dea3101e JB |
3360 | |
3361 | if (!rc) { | |
2e0fef85 JS |
3362 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3363 | if (!mbox) | |
c9f8735b | 3364 | return 1; |
2e0fef85 | 3365 | |
dea3101e JB |
3366 | lpfc_linkdown(phba); |
3367 | lpfc_init_link(phba, mbox, | |
3368 | phba->cfg_topology, | |
3369 | phba->cfg_link_speed); | |
3370 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; | |
3371 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
ed957684 | 3372 | mbox->vport = vport; |
0b727fea | 3373 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
5b8bd0c9 | 3374 | lpfc_set_loopback_flag(phba); |
dea3101e | 3375 | if (rc == MBX_NOT_FINISHED) { |
329f9bc7 | 3376 | mempool_free(mbox, phba->mbox_mem_pool); |
dea3101e | 3377 | } |
c9f8735b | 3378 | return 1; |
2fe165b6 | 3379 | } else if (rc > 0) { /* greater than */ |
2e0fef85 JS |
3380 | spin_lock_irq(shost->host_lock); |
3381 | vport->fc_flag |= FC_PT2PT_PLOGI; | |
3382 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 3383 | } |
2e0fef85 JS |
3384 | spin_lock_irq(shost->host_lock); |
3385 | vport->fc_flag |= FC_PT2PT; | |
3386 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
3387 | spin_unlock_irq(shost->host_lock); | |
dea3101e JB |
3388 | } else { |
3389 | /* Reject this request because invalid parameters */ | |
3390 | stat.un.b.lsRjtRsvd0 = 0; | |
3391 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3392 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | |
3393 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
3394 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
3395 | NULL); | |
c9f8735b | 3396 | return 1; |
dea3101e JB |
3397 | } |
3398 | ||
3399 | /* Send back ACC */ | |
51ef4c26 | 3400 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
dea3101e | 3401 | |
c9f8735b | 3402 | return 0; |
dea3101e JB |
3403 | } |
3404 | ||
3405 | static int | |
2e0fef85 JS |
3406 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3407 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
3408 | { |
3409 | struct lpfc_dmabuf *pcmd; | |
3410 | uint32_t *lp; | |
3411 | IOCB_t *icmd; | |
3412 | RNID *rn; | |
3413 | struct ls_rjt stat; | |
3414 | uint32_t cmd, did; | |
3415 | ||
3416 | icmd = &cmdiocb->iocb; | |
3417 | did = icmd->un.elsreq64.remoteID; | |
3418 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
3419 | lp = (uint32_t *) pcmd->virt; | |
3420 | ||
3421 | cmd = *lp++; | |
3422 | rn = (RNID *) lp; | |
3423 | ||
3424 | /* RNID received */ | |
3425 | ||
3426 | switch (rn->Format) { | |
3427 | case 0: | |
3428 | case RNID_TOPOLOGY_DISC: | |
3429 | /* Send back ACC */ | |
2e0fef85 | 3430 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
dea3101e JB |
3431 | break; |
3432 | default: | |
3433 | /* Reject this request because format not supported */ | |
3434 | stat.un.b.lsRjtRsvd0 = 0; | |
3435 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3436 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
3437 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
3438 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
3439 | NULL); | |
dea3101e | 3440 | } |
c9f8735b | 3441 | return 0; |
dea3101e JB |
3442 | } |
3443 | ||
3444 | static int | |
2e0fef85 JS |
3445 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3446 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
3447 | { |
3448 | struct ls_rjt stat; | |
3449 | ||
3450 | /* For now, unconditionally reject this command */ | |
3451 | stat.un.b.lsRjtRsvd0 = 0; | |
3452 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3453 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
3454 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 3455 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
3456 | return 0; |
3457 | } | |
3458 | ||
082c0266 | 3459 | static void |
329f9bc7 | 3460 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
7bb3b137 | 3461 | { |
2e0fef85 JS |
3462 | struct lpfc_sli *psli = &phba->sli; |
3463 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
7bb3b137 JW |
3464 | MAILBOX_t *mb; |
3465 | IOCB_t *icmd; | |
3466 | RPS_RSP *rps_rsp; | |
3467 | uint8_t *pcmd; | |
3468 | struct lpfc_iocbq *elsiocb; | |
3469 | struct lpfc_nodelist *ndlp; | |
3470 | uint16_t xri, status; | |
3471 | uint32_t cmdsize; | |
3472 | ||
7bb3b137 JW |
3473 | mb = &pmb->mb; |
3474 | ||
3475 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
3476 | xri = (uint16_t) ((unsigned long)(pmb->context1)); | |
041976fb RD |
3477 | pmb->context1 = NULL; |
3478 | pmb->context2 = NULL; | |
7bb3b137 JW |
3479 | |
3480 | if (mb->mbxStatus) { | |
329f9bc7 | 3481 | mempool_free(pmb, phba->mbox_mem_pool); |
7bb3b137 JW |
3482 | return; |
3483 | } | |
3484 | ||
3485 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); | |
329f9bc7 | 3486 | mempool_free(pmb, phba->mbox_mem_pool); |
2e0fef85 JS |
3487 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
3488 | lpfc_max_els_tries, ndlp, | |
3489 | ndlp->nlp_DID, ELS_CMD_ACC); | |
fa4066b6 JS |
3490 | |
3491 | /* Decrement the ndlp reference count from previous mbox command */ | |
329f9bc7 | 3492 | lpfc_nlp_put(ndlp); |
fa4066b6 | 3493 | |
c9f8735b | 3494 | if (!elsiocb) |
7bb3b137 | 3495 | return; |
7bb3b137 JW |
3496 | |
3497 | icmd = &elsiocb->iocb; | |
3498 | icmd->ulpContext = xri; | |
3499 | ||
3500 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
3501 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 3502 | pcmd += sizeof(uint32_t); /* Skip past command */ |
7bb3b137 JW |
3503 | rps_rsp = (RPS_RSP *)pcmd; |
3504 | ||
3505 | if (phba->fc_topology != TOPOLOGY_LOOP) | |
3506 | status = 0x10; | |
3507 | else | |
3508 | status = 0x8; | |
2e0fef85 | 3509 | if (phba->pport->fc_flag & FC_FABRIC) |
7bb3b137 JW |
3510 | status |= 0x4; |
3511 | ||
3512 | rps_rsp->rsvd1 = 0; | |
09372820 JS |
3513 | rps_rsp->portStatus = cpu_to_be16(status); |
3514 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); | |
3515 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); | |
3516 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); | |
3517 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); | |
3518 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); | |
3519 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); | |
7bb3b137 | 3520 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
e8b62011 JS |
3521 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
3522 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " | |
3523 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", | |
3524 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
3525 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3526 | ndlp->nlp_rpi); | |
858c9f6c | 3527 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 | 3528 | phba->fc_stat.elsXmitACC++; |
ed957684 | 3529 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
7bb3b137 | 3530 | lpfc_els_free_iocb(phba, elsiocb); |
7bb3b137 JW |
3531 | return; |
3532 | } | |
3533 | ||
3534 | static int | |
2e0fef85 JS |
3535 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3536 | struct lpfc_nodelist *ndlp) | |
dea3101e | 3537 | { |
2e0fef85 | 3538 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 3539 | uint32_t *lp; |
7bb3b137 JW |
3540 | uint8_t flag; |
3541 | LPFC_MBOXQ_t *mbox; | |
3542 | struct lpfc_dmabuf *pcmd; | |
3543 | RPS *rps; | |
3544 | struct ls_rjt stat; | |
3545 | ||
2fe165b6 JW |
3546 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
3547 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | |
7bb3b137 JW |
3548 | stat.un.b.lsRjtRsvd0 = 0; |
3549 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3550 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
3551 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
3552 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
3553 | NULL); | |
7bb3b137 JW |
3554 | } |
3555 | ||
3556 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
3557 | lp = (uint32_t *) pcmd->virt; | |
3558 | flag = (be32_to_cpu(*lp++) & 0xf); | |
3559 | rps = (RPS *) lp; | |
3560 | ||
3561 | if ((flag == 0) || | |
3562 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || | |
2e0fef85 | 3563 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
92d7f7b0 | 3564 | sizeof(struct lpfc_name)) == 0))) { |
2e0fef85 | 3565 | |
92d7f7b0 JS |
3566 | printk("Fix me....\n"); |
3567 | dump_stack(); | |
2e0fef85 JS |
3568 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
3569 | if (mbox) { | |
7bb3b137 JW |
3570 | lpfc_read_lnk_stat(phba, mbox); |
3571 | mbox->context1 = | |
92d7f7b0 | 3572 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
329f9bc7 | 3573 | mbox->context2 = lpfc_nlp_get(ndlp); |
92d7f7b0 | 3574 | mbox->vport = vport; |
7bb3b137 | 3575 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
fa4066b6 | 3576 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
0b727fea | 3577 | != MBX_NOT_FINISHED) |
7bb3b137 JW |
3578 | /* Mbox completion will send ELS Response */ |
3579 | return 0; | |
fa4066b6 JS |
3580 | /* Decrement reference count used for the failed mbox |
3581 | * command. | |
3582 | */ | |
329f9bc7 | 3583 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
3584 | mempool_free(mbox, phba->mbox_mem_pool); |
3585 | } | |
3586 | } | |
3587 | stat.un.b.lsRjtRsvd0 = 0; | |
3588 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3589 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
3590 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 3591 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
7bb3b137 JW |
3592 | return 0; |
3593 | } | |
3594 | ||
082c0266 | 3595 | static int |
2e0fef85 JS |
3596 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
3597 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) | |
7bb3b137 | 3598 | { |
2e0fef85 JS |
3599 | struct lpfc_hba *phba = vport->phba; |
3600 | IOCB_t *icmd, *oldcmd; | |
7bb3b137 JW |
3601 | RPL_RSP rpl_rsp; |
3602 | struct lpfc_iocbq *elsiocb; | |
2e0fef85 JS |
3603 | struct lpfc_sli *psli = &phba->sli; |
3604 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
7bb3b137 | 3605 | uint8_t *pcmd; |
dea3101e | 3606 | |
2e0fef85 JS |
3607 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
3608 | ndlp->nlp_DID, ELS_CMD_ACC); | |
7bb3b137 | 3609 | |
488d1469 | 3610 | if (!elsiocb) |
7bb3b137 | 3611 | return 1; |
488d1469 | 3612 | |
7bb3b137 JW |
3613 | icmd = &elsiocb->iocb; |
3614 | oldcmd = &oldiocb->iocb; | |
3615 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ | |
3616 | ||
3617 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
3618 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; | |
92d7f7b0 | 3619 | pcmd += sizeof(uint16_t); |
7bb3b137 JW |
3620 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
3621 | pcmd += sizeof(uint16_t); | |
3622 | ||
3623 | /* Setup the RPL ACC payload */ | |
3624 | rpl_rsp.listLen = be32_to_cpu(1); | |
3625 | rpl_rsp.index = 0; | |
3626 | rpl_rsp.port_num_blk.portNum = 0; | |
2e0fef85 JS |
3627 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
3628 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, | |
7bb3b137 | 3629 | sizeof(struct lpfc_name)); |
7bb3b137 | 3630 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
7bb3b137 | 3631 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
e8b62011 JS |
3632 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3633 | "0120 Xmit ELS RPL ACC response tag x%x " | |
3634 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " | |
3635 | "rpi x%x\n", | |
3636 | elsiocb->iotag, elsiocb->iocb.ulpContext, | |
3637 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
3638 | ndlp->nlp_rpi); | |
858c9f6c | 3639 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
7bb3b137 JW |
3640 | phba->fc_stat.elsXmitACC++; |
3641 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | |
3642 | lpfc_els_free_iocb(phba, elsiocb); | |
3643 | return 1; | |
3644 | } | |
3645 | return 0; | |
3646 | } | |
3647 | ||
3648 | static int | |
2e0fef85 JS |
3649 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3650 | struct lpfc_nodelist *ndlp) | |
7bb3b137 JW |
3651 | { |
3652 | struct lpfc_dmabuf *pcmd; | |
3653 | uint32_t *lp; | |
3654 | uint32_t maxsize; | |
3655 | uint16_t cmdsize; | |
3656 | RPL *rpl; | |
3657 | struct ls_rjt stat; | |
3658 | ||
2fe165b6 JW |
3659 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
3660 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { | |
7bb3b137 JW |
3661 | stat.un.b.lsRjtRsvd0 = 0; |
3662 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
3663 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; | |
3664 | stat.un.b.vendorUnique = 0; | |
858c9f6c JS |
3665 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
3666 | NULL); | |
7bb3b137 JW |
3667 | } |
3668 | ||
dea3101e JB |
3669 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
3670 | lp = (uint32_t *) pcmd->virt; | |
7bb3b137 | 3671 | rpl = (RPL *) (lp + 1); |
dea3101e | 3672 | |
7bb3b137 | 3673 | maxsize = be32_to_cpu(rpl->maxsize); |
dea3101e | 3674 | |
7bb3b137 JW |
3675 | /* We support only one port */ |
3676 | if ((rpl->index == 0) && | |
3677 | ((maxsize == 0) || | |
3678 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { | |
3679 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); | |
2fe165b6 | 3680 | } else { |
7bb3b137 JW |
3681 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
3682 | } | |
2e0fef85 | 3683 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
dea3101e JB |
3684 | |
3685 | return 0; | |
3686 | } | |
3687 | ||
3688 | static int | |
2e0fef85 JS |
3689 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3690 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
3691 | { |
3692 | struct lpfc_dmabuf *pcmd; | |
3693 | uint32_t *lp; | |
3694 | IOCB_t *icmd; | |
3695 | FARP *fp; | |
3696 | uint32_t cmd, cnt, did; | |
3697 | ||
3698 | icmd = &cmdiocb->iocb; | |
3699 | did = icmd->un.elsreq64.remoteID; | |
3700 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
3701 | lp = (uint32_t *) pcmd->virt; | |
3702 | ||
3703 | cmd = *lp++; | |
3704 | fp = (FARP *) lp; | |
dea3101e | 3705 | /* FARP-REQ received from DID <did> */ |
e8b62011 JS |
3706 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3707 | "0601 FARP-REQ received from DID x%x\n", did); | |
dea3101e JB |
3708 | /* We will only support match on WWPN or WWNN */ |
3709 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { | |
c9f8735b | 3710 | return 0; |
dea3101e JB |
3711 | } |
3712 | ||
3713 | cnt = 0; | |
3714 | /* If this FARP command is searching for my portname */ | |
3715 | if (fp->Mflags & FARP_MATCH_PORT) { | |
2e0fef85 | 3716 | if (memcmp(&fp->RportName, &vport->fc_portname, |
92d7f7b0 | 3717 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
3718 | cnt = 1; |
3719 | } | |
3720 | ||
3721 | /* If this FARP command is searching for my nodename */ | |
3722 | if (fp->Mflags & FARP_MATCH_NODE) { | |
2e0fef85 | 3723 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
92d7f7b0 | 3724 | sizeof(struct lpfc_name)) == 0) |
dea3101e JB |
3725 | cnt = 1; |
3726 | } | |
3727 | ||
3728 | if (cnt) { | |
3729 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || | |
3730 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { | |
3731 | /* Log back into the node before sending the FARP. */ | |
3732 | if (fp->Rflags & FARP_REQUEST_PLOGI) { | |
5024ab17 | 3733 | ndlp->nlp_prev_state = ndlp->nlp_state; |
2e0fef85 | 3734 | lpfc_nlp_set_state(vport, ndlp, |
de0c5b32 | 3735 | NLP_STE_PLOGI_ISSUE); |
2e0fef85 | 3736 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
dea3101e JB |
3737 | } |
3738 | ||
3739 | /* Send a FARP response to that node */ | |
2e0fef85 JS |
3740 | if (fp->Rflags & FARP_REQUEST_FARPR) |
3741 | lpfc_issue_els_farpr(vport, did, 0); | |
dea3101e JB |
3742 | } |
3743 | } | |
c9f8735b | 3744 | return 0; |
dea3101e JB |
3745 | } |
3746 | ||
3747 | static int | |
2e0fef85 JS |
3748 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3749 | struct lpfc_nodelist *ndlp) | |
dea3101e JB |
3750 | { |
3751 | struct lpfc_dmabuf *pcmd; | |
3752 | uint32_t *lp; | |
3753 | IOCB_t *icmd; | |
3754 | uint32_t cmd, did; | |
3755 | ||
3756 | icmd = &cmdiocb->iocb; | |
3757 | did = icmd->un.elsreq64.remoteID; | |
3758 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
3759 | lp = (uint32_t *) pcmd->virt; | |
3760 | ||
3761 | cmd = *lp++; | |
3762 | /* FARP-RSP received from DID <did> */ | |
e8b62011 JS |
3763 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
3764 | "0600 FARP-RSP received from DID x%x\n", did); | |
dea3101e | 3765 | /* ACCEPT the Farp resp request */ |
51ef4c26 | 3766 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e JB |
3767 | |
3768 | return 0; | |
3769 | } | |
3770 | ||
3771 | static int | |
2e0fef85 JS |
3772 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
3773 | struct lpfc_nodelist *fan_ndlp) | |
dea3101e | 3774 | { |
0d2b6b83 | 3775 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 3776 | uint32_t *lp; |
5024ab17 | 3777 | FAN *fp; |
dea3101e | 3778 | |
0d2b6b83 JS |
3779 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); |
3780 | lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt; | |
3781 | fp = (FAN *) ++lp; | |
5024ab17 | 3782 | /* FAN received; Fan does not have a reply sequence */ |
0d2b6b83 JS |
3783 | if ((vport == phba->pport) && |
3784 | (vport->port_state == LPFC_LOCAL_CFG_LINK)) { | |
5024ab17 | 3785 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
0d2b6b83 | 3786 | sizeof(struct lpfc_name))) || |
5024ab17 | 3787 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
0d2b6b83 JS |
3788 | sizeof(struct lpfc_name)))) { |
3789 | /* This port has switched fabrics. FLOGI is required */ | |
2e0fef85 | 3790 | lpfc_initial_flogi(vport); |
0d2b6b83 JS |
3791 | } else { |
3792 | /* FAN verified - skip FLOGI */ | |
3793 | vport->fc_myDID = vport->fc_prevDID; | |
3794 | lpfc_issue_fabric_reglogin(vport); | |
5024ab17 | 3795 | } |
dea3101e | 3796 | } |
c9f8735b | 3797 | return 0; |
dea3101e JB |
3798 | } |
3799 | ||
3800 | void | |
3801 | lpfc_els_timeout(unsigned long ptr) | |
3802 | { | |
2e0fef85 JS |
3803 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
3804 | struct lpfc_hba *phba = vport->phba; | |
5e9d9b82 | 3805 | uint32_t tmo_posted; |
dea3101e JB |
3806 | unsigned long iflag; |
3807 | ||
2e0fef85 | 3808 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
5e9d9b82 JS |
3809 | tmo_posted = vport->work_port_events & WORKER_ELS_TMO; |
3810 | if (!tmo_posted) | |
2e0fef85 | 3811 | vport->work_port_events |= WORKER_ELS_TMO; |
5e9d9b82 | 3812 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
92d7f7b0 | 3813 | |
5e9d9b82 JS |
3814 | if (!tmo_posted) |
3815 | lpfc_worker_wake_up(phba); | |
dea3101e JB |
3816 | return; |
3817 | } | |
3818 | ||
3819 | void | |
2e0fef85 | 3820 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
dea3101e | 3821 | { |
2e0fef85 | 3822 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
3823 | struct lpfc_sli_ring *pring; |
3824 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
3825 | IOCB_t *cmd = NULL; | |
3826 | struct lpfc_dmabuf *pcmd; | |
2e0fef85 | 3827 | uint32_t els_command = 0; |
dea3101e | 3828 | uint32_t timeout; |
2e0fef85 | 3829 | uint32_t remote_ID = 0xffffffff; |
dea3101e | 3830 | |
dea3101e | 3831 | /* If the timer is already canceled do nothing */ |
2e0fef85 | 3832 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
dea3101e JB |
3833 | return; |
3834 | } | |
2e0fef85 | 3835 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
3836 | timeout = (uint32_t)(phba->fc_ratov << 1); |
3837 | ||
3838 | pring = &phba->sli.ring[LPFC_ELS_RING]; | |
dea3101e JB |
3839 | |
3840 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | |
3841 | cmd = &piocb->iocb; | |
3842 | ||
2e0fef85 JS |
3843 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
3844 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
3845 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | |
dea3101e | 3846 | continue; |
2e0fef85 JS |
3847 | |
3848 | if (piocb->vport != vport) | |
3849 | continue; | |
3850 | ||
dea3101e | 3851 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
2e0fef85 JS |
3852 | if (pcmd) |
3853 | els_command = *(uint32_t *) (pcmd->virt); | |
dea3101e | 3854 | |
92d7f7b0 JS |
3855 | if (els_command == ELS_CMD_FARP || |
3856 | els_command == ELS_CMD_FARPR || | |
3857 | els_command == ELS_CMD_FDISC) | |
3858 | continue; | |
3859 | ||
3860 | if (vport != piocb->vport) | |
dea3101e | 3861 | continue; |
dea3101e JB |
3862 | |
3863 | if (piocb->drvrTimeout > 0) { | |
92d7f7b0 | 3864 | if (piocb->drvrTimeout >= timeout) |
dea3101e | 3865 | piocb->drvrTimeout -= timeout; |
92d7f7b0 | 3866 | else |
dea3101e | 3867 | piocb->drvrTimeout = 0; |
dea3101e JB |
3868 | continue; |
3869 | } | |
3870 | ||
2e0fef85 JS |
3871 | remote_ID = 0xffffffff; |
3872 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) | |
dea3101e | 3873 | remote_ID = cmd->un.elsreq64.remoteID; |
2e0fef85 JS |
3874 | else { |
3875 | struct lpfc_nodelist *ndlp; | |
3876 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); | |
58da1ffb | 3877 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
2e0fef85 | 3878 | remote_ID = ndlp->nlp_DID; |
dea3101e | 3879 | } |
e8b62011 JS |
3880 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
3881 | "0127 ELS timeout Data: x%x x%x x%x " | |
3882 | "x%x\n", els_command, | |
3883 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); | |
07951076 | 3884 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
dea3101e | 3885 | } |
2e0fef85 | 3886 | spin_unlock_irq(&phba->hbalock); |
5a0e326d | 3887 | |
2e0fef85 JS |
3888 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
3889 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); | |
dea3101e JB |
3890 | } |
3891 | ||
3892 | void | |
2e0fef85 | 3893 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
dea3101e | 3894 | { |
2534ba75 | 3895 | LIST_HEAD(completions); |
2e0fef85 | 3896 | struct lpfc_hba *phba = vport->phba; |
329f9bc7 | 3897 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e JB |
3898 | struct lpfc_iocbq *tmp_iocb, *piocb; |
3899 | IOCB_t *cmd = NULL; | |
92d7f7b0 JS |
3900 | |
3901 | lpfc_fabric_abort_vport(vport); | |
dea3101e | 3902 | |
2e0fef85 | 3903 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
3904 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
3905 | cmd = &piocb->iocb; | |
3906 | ||
3907 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { | |
3908 | continue; | |
3909 | } | |
3910 | ||
3911 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | |
329f9bc7 JS |
3912 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
3913 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | |
3914 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
3915 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | |
dea3101e | 3916 | continue; |
dea3101e | 3917 | |
2e0fef85 JS |
3918 | if (piocb->vport != vport) |
3919 | continue; | |
3920 | ||
2534ba75 | 3921 | list_move_tail(&piocb->list, &completions); |
1dcb58e5 | 3922 | pring->txq_cnt--; |
dea3101e JB |
3923 | } |
3924 | ||
3925 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | |
dea3101e JB |
3926 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
3927 | continue; | |
3928 | } | |
dea3101e | 3929 | |
2e0fef85 JS |
3930 | if (piocb->vport != vport) |
3931 | continue; | |
3932 | ||
07951076 | 3933 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
dea3101e | 3934 | } |
2e0fef85 | 3935 | spin_unlock_irq(&phba->hbalock); |
2534ba75 | 3936 | |
2e0fef85 | 3937 | while (!list_empty(&completions)) { |
2534ba75 JS |
3938 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
3939 | cmd = &piocb->iocb; | |
92d7f7b0 | 3940 | list_del_init(&piocb->list); |
2534ba75 | 3941 | |
2e0fef85 JS |
3942 | if (!piocb->iocb_cmpl) |
3943 | lpfc_sli_release_iocbq(phba, piocb); | |
3944 | else { | |
2534ba75 JS |
3945 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
3946 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
3947 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
2e0fef85 | 3948 | } |
2534ba75 JS |
3949 | } |
3950 | ||
dea3101e JB |
3951 | return; |
3952 | } | |
3953 | ||
549e55cd JS |
3954 | void |
3955 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) | |
3956 | { | |
3957 | LIST_HEAD(completions); | |
3958 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
3959 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
3960 | IOCB_t *cmd = NULL; | |
3961 | ||
3962 | lpfc_fabric_abort_hba(phba); | |
3963 | spin_lock_irq(&phba->hbalock); | |
3964 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { | |
3965 | cmd = &piocb->iocb; | |
3966 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | |
3967 | continue; | |
3968 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ | |
3969 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || | |
3970 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || | |
3971 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
3972 | cmd->ulpCommand == CMD_ABORT_XRI_CN) | |
3973 | continue; | |
3974 | list_move_tail(&piocb->list, &completions); | |
3975 | pring->txq_cnt--; | |
3976 | } | |
3977 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { | |
3978 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) | |
3979 | continue; | |
3980 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); | |
3981 | } | |
3982 | spin_unlock_irq(&phba->hbalock); | |
3983 | while (!list_empty(&completions)) { | |
3984 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
3985 | cmd = &piocb->iocb; | |
3986 | list_del_init(&piocb->list); | |
3987 | if (!piocb->iocb_cmpl) | |
3988 | lpfc_sli_release_iocbq(phba, piocb); | |
3989 | else { | |
3990 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
3991 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
3992 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
3993 | } | |
3994 | } | |
3995 | return; | |
3996 | } | |
3997 | ||
ed957684 JS |
3998 | static void |
3999 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
92d7f7b0 | 4000 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
dea3101e | 4001 | { |
87af33fe | 4002 | struct Scsi_Host *shost; |
dea3101e | 4003 | struct lpfc_nodelist *ndlp; |
dea3101e | 4004 | struct ls_rjt stat; |
92d7f7b0 | 4005 | uint32_t *payload; |
2e0fef85 | 4006 | uint32_t cmd, did, newnode, rjt_err = 0; |
ed957684 | 4007 | IOCB_t *icmd = &elsiocb->iocb; |
dea3101e | 4008 | |
e47c9093 | 4009 | if (!vport || !(elsiocb->context2)) |
dea3101e | 4010 | goto dropit; |
2e0fef85 | 4011 | |
dea3101e | 4012 | newnode = 0; |
92d7f7b0 JS |
4013 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
4014 | cmd = *payload; | |
ed957684 JS |
4015 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
4016 | lpfc_post_buffer(phba, pring, 1, 1); | |
dea3101e | 4017 | |
858c9f6c JS |
4018 | did = icmd->un.rcvels.remoteID; |
4019 | if (icmd->ulpStatus) { | |
4020 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, | |
4021 | "RCV Unsol ELS: status:x%x/x%x did:x%x", | |
4022 | icmd->ulpStatus, icmd->un.ulpWord[4], did); | |
dea3101e | 4023 | goto dropit; |
858c9f6c | 4024 | } |
dea3101e JB |
4025 | |
4026 | /* Check to see if link went down during discovery */ | |
ed957684 | 4027 | if (lpfc_els_chk_latt(vport)) |
dea3101e | 4028 | goto dropit; |
dea3101e | 4029 | |
92d7f7b0 JS |
4030 | /* Ignore traffic recevied during vport shutdown. */ |
4031 | if (vport->load_flag & FC_UNLOADING) | |
4032 | goto dropit; | |
4033 | ||
2e0fef85 | 4034 | ndlp = lpfc_findnode_did(vport, did); |
c9f8735b | 4035 | if (!ndlp) { |
dea3101e | 4036 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
c9f8735b | 4037 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
ed957684 | 4038 | if (!ndlp) |
dea3101e | 4039 | goto dropit; |
dea3101e | 4040 | |
2e0fef85 | 4041 | lpfc_nlp_init(vport, ndlp, did); |
98c9ea5c | 4042 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
dea3101e | 4043 | newnode = 1; |
e47c9093 | 4044 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
dea3101e | 4045 | ndlp->nlp_type |= NLP_FABRIC; |
58da1ffb JS |
4046 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
4047 | ndlp = lpfc_enable_node(vport, ndlp, | |
4048 | NLP_STE_UNUSED_NODE); | |
4049 | if (!ndlp) | |
4050 | goto dropit; | |
4051 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
4052 | newnode = 1; | |
4053 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) | |
4054 | ndlp->nlp_type |= NLP_FABRIC; | |
4055 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
4056 | /* This is similar to the new node path */ | |
4057 | ndlp = lpfc_nlp_get(ndlp); | |
4058 | if (!ndlp) | |
4059 | goto dropit; | |
4060 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
4061 | newnode = 1; | |
87af33fe | 4062 | } |
dea3101e JB |
4063 | |
4064 | phba->fc_stat.elsRcvFrame++; | |
329f9bc7 JS |
4065 | if (elsiocb->context1) |
4066 | lpfc_nlp_put(elsiocb->context1); | |
e47c9093 | 4067 | |
329f9bc7 | 4068 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
2e0fef85 | 4069 | elsiocb->vport = vport; |
dea3101e JB |
4070 | |
4071 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { | |
4072 | cmd &= ELS_CMD_MASK; | |
4073 | } | |
4074 | /* ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
4075 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4076 | "0112 ELS command x%x received from NPORT x%x " | |
4077 | "Data: x%x\n", cmd, did, vport->port_state); | |
dea3101e JB |
4078 | switch (cmd) { |
4079 | case ELS_CMD_PLOGI: | |
858c9f6c JS |
4080 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4081 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", | |
4082 | did, vport->port_state, ndlp->nlp_flag); | |
4083 | ||
dea3101e | 4084 | phba->fc_stat.elsRcvPLOGI++; |
858c9f6c JS |
4085 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
4086 | ||
4087 | if (vport->port_state < LPFC_DISC_AUTH) { | |
1b32f6aa JS |
4088 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
4089 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { | |
4090 | rjt_err = LSRJT_UNABLE_TPC; | |
4091 | break; | |
4092 | } | |
4093 | /* We get here, and drop thru, if we are PT2PT with | |
4094 | * another NPort and the other side has initiated | |
4095 | * the PLOGI before responding to our FLOGI. | |
4096 | */ | |
dea3101e | 4097 | } |
87af33fe JS |
4098 | |
4099 | shost = lpfc_shost_from_vport(vport); | |
4100 | spin_lock_irq(shost->host_lock); | |
4101 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; | |
4102 | spin_unlock_irq(shost->host_lock); | |
4103 | ||
2e0fef85 JS |
4104 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
4105 | NLP_EVT_RCV_PLOGI); | |
858c9f6c | 4106 | |
dea3101e JB |
4107 | break; |
4108 | case ELS_CMD_FLOGI: | |
858c9f6c JS |
4109 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4110 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", | |
4111 | did, vport->port_state, ndlp->nlp_flag); | |
4112 | ||
dea3101e | 4113 | phba->fc_stat.elsRcvFLOGI++; |
51ef4c26 | 4114 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
87af33fe | 4115 | if (newnode) |
98c9ea5c | 4116 | lpfc_nlp_put(ndlp); |
dea3101e JB |
4117 | break; |
4118 | case ELS_CMD_LOGO: | |
858c9f6c JS |
4119 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4120 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", | |
4121 | did, vport->port_state, ndlp->nlp_flag); | |
4122 | ||
dea3101e | 4123 | phba->fc_stat.elsRcvLOGO++; |
2e0fef85 | 4124 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 4125 | rjt_err = LSRJT_UNABLE_TPC; |
dea3101e JB |
4126 | break; |
4127 | } | |
2e0fef85 | 4128 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
dea3101e JB |
4129 | break; |
4130 | case ELS_CMD_PRLO: | |
858c9f6c JS |
4131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4132 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", | |
4133 | did, vport->port_state, ndlp->nlp_flag); | |
4134 | ||
dea3101e | 4135 | phba->fc_stat.elsRcvPRLO++; |
2e0fef85 | 4136 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 4137 | rjt_err = LSRJT_UNABLE_TPC; |
dea3101e JB |
4138 | break; |
4139 | } | |
2e0fef85 | 4140 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
dea3101e JB |
4141 | break; |
4142 | case ELS_CMD_RSCN: | |
4143 | phba->fc_stat.elsRcvRSCN++; | |
51ef4c26 | 4144 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
87af33fe | 4145 | if (newnode) |
98c9ea5c | 4146 | lpfc_nlp_put(ndlp); |
dea3101e JB |
4147 | break; |
4148 | case ELS_CMD_ADISC: | |
858c9f6c JS |
4149 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4150 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", | |
4151 | did, vport->port_state, ndlp->nlp_flag); | |
4152 | ||
dea3101e | 4153 | phba->fc_stat.elsRcvADISC++; |
2e0fef85 | 4154 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 4155 | rjt_err = LSRJT_UNABLE_TPC; |
dea3101e JB |
4156 | break; |
4157 | } | |
2e0fef85 JS |
4158 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
4159 | NLP_EVT_RCV_ADISC); | |
dea3101e JB |
4160 | break; |
4161 | case ELS_CMD_PDISC: | |
858c9f6c JS |
4162 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4163 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", | |
4164 | did, vport->port_state, ndlp->nlp_flag); | |
4165 | ||
dea3101e | 4166 | phba->fc_stat.elsRcvPDISC++; |
2e0fef85 | 4167 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 4168 | rjt_err = LSRJT_UNABLE_TPC; |
dea3101e JB |
4169 | break; |
4170 | } | |
2e0fef85 JS |
4171 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
4172 | NLP_EVT_RCV_PDISC); | |
dea3101e JB |
4173 | break; |
4174 | case ELS_CMD_FARPR: | |
858c9f6c JS |
4175 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4176 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", | |
4177 | did, vport->port_state, ndlp->nlp_flag); | |
4178 | ||
dea3101e | 4179 | phba->fc_stat.elsRcvFARPR++; |
2e0fef85 | 4180 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
dea3101e JB |
4181 | break; |
4182 | case ELS_CMD_FARP: | |
858c9f6c JS |
4183 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4184 | "RCV FARP: did:x%x/ste:x%x flg:x%x", | |
4185 | did, vport->port_state, ndlp->nlp_flag); | |
4186 | ||
dea3101e | 4187 | phba->fc_stat.elsRcvFARP++; |
2e0fef85 | 4188 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
dea3101e JB |
4189 | break; |
4190 | case ELS_CMD_FAN: | |
858c9f6c JS |
4191 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4192 | "RCV FAN: did:x%x/ste:x%x flg:x%x", | |
4193 | did, vport->port_state, ndlp->nlp_flag); | |
4194 | ||
dea3101e | 4195 | phba->fc_stat.elsRcvFAN++; |
2e0fef85 | 4196 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
dea3101e | 4197 | break; |
dea3101e | 4198 | case ELS_CMD_PRLI: |
858c9f6c JS |
4199 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4200 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", | |
4201 | did, vport->port_state, ndlp->nlp_flag); | |
4202 | ||
dea3101e | 4203 | phba->fc_stat.elsRcvPRLI++; |
2e0fef85 | 4204 | if (vport->port_state < LPFC_DISC_AUTH) { |
858c9f6c | 4205 | rjt_err = LSRJT_UNABLE_TPC; |
dea3101e JB |
4206 | break; |
4207 | } | |
2e0fef85 | 4208 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
dea3101e | 4209 | break; |
7bb3b137 | 4210 | case ELS_CMD_LIRR: |
858c9f6c JS |
4211 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4212 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", | |
4213 | did, vport->port_state, ndlp->nlp_flag); | |
4214 | ||
7bb3b137 | 4215 | phba->fc_stat.elsRcvLIRR++; |
2e0fef85 | 4216 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
87af33fe | 4217 | if (newnode) |
98c9ea5c | 4218 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
4219 | break; |
4220 | case ELS_CMD_RPS: | |
858c9f6c JS |
4221 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4222 | "RCV RPS: did:x%x/ste:x%x flg:x%x", | |
4223 | did, vport->port_state, ndlp->nlp_flag); | |
4224 | ||
7bb3b137 | 4225 | phba->fc_stat.elsRcvRPS++; |
2e0fef85 | 4226 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
87af33fe | 4227 | if (newnode) |
98c9ea5c | 4228 | lpfc_nlp_put(ndlp); |
7bb3b137 JW |
4229 | break; |
4230 | case ELS_CMD_RPL: | |
858c9f6c JS |
4231 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4232 | "RCV RPL: did:x%x/ste:x%x flg:x%x", | |
4233 | did, vport->port_state, ndlp->nlp_flag); | |
4234 | ||
7bb3b137 | 4235 | phba->fc_stat.elsRcvRPL++; |
2e0fef85 | 4236 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
87af33fe | 4237 | if (newnode) |
98c9ea5c | 4238 | lpfc_nlp_put(ndlp); |
7bb3b137 | 4239 | break; |
dea3101e | 4240 | case ELS_CMD_RNID: |
858c9f6c JS |
4241 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4242 | "RCV RNID: did:x%x/ste:x%x flg:x%x", | |
4243 | did, vport->port_state, ndlp->nlp_flag); | |
4244 | ||
dea3101e | 4245 | phba->fc_stat.elsRcvRNID++; |
2e0fef85 | 4246 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
87af33fe | 4247 | if (newnode) |
98c9ea5c | 4248 | lpfc_nlp_put(ndlp); |
dea3101e JB |
4249 | break; |
4250 | default: | |
858c9f6c JS |
4251 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
4252 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", | |
4253 | cmd, did, vport->port_state); | |
4254 | ||
dea3101e | 4255 | /* Unsupported ELS command, reject */ |
858c9f6c | 4256 | rjt_err = LSRJT_INVALID_CMD; |
dea3101e JB |
4257 | |
4258 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ | |
e8b62011 JS |
4259 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4260 | "0115 Unknown ELS command x%x " | |
4261 | "received from NPORT x%x\n", cmd, did); | |
87af33fe | 4262 | if (newnode) |
98c9ea5c | 4263 | lpfc_nlp_put(ndlp); |
dea3101e JB |
4264 | break; |
4265 | } | |
4266 | ||
4267 | /* check if need to LS_RJT received ELS cmd */ | |
4268 | if (rjt_err) { | |
92d7f7b0 | 4269 | memset(&stat, 0, sizeof(stat)); |
858c9f6c | 4270 | stat.un.b.lsRjtRsnCode = rjt_err; |
1f679caf | 4271 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
858c9f6c JS |
4272 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
4273 | NULL); | |
dea3101e JB |
4274 | } |
4275 | ||
ed957684 JS |
4276 | return; |
4277 | ||
4278 | dropit: | |
98c9ea5c JS |
4279 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
4280 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
e8b62011 | 4281 | "(%d):0111 Dropping received ELS cmd " |
ed957684 | 4282 | "Data: x%x x%x x%x\n", |
98c9ea5c | 4283 | vport->vpi, icmd->ulpStatus, |
e8b62011 | 4284 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
ed957684 JS |
4285 | phba->fc_stat.elsRcvDrop++; |
4286 | } | |
4287 | ||
92d7f7b0 JS |
4288 | static struct lpfc_vport * |
4289 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) | |
4290 | { | |
4291 | struct lpfc_vport *vport; | |
549e55cd | 4292 | unsigned long flags; |
92d7f7b0 | 4293 | |
549e55cd | 4294 | spin_lock_irqsave(&phba->hbalock, flags); |
92d7f7b0 | 4295 | list_for_each_entry(vport, &phba->port_list, listentry) { |
549e55cd JS |
4296 | if (vport->vpi == vpi) { |
4297 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
92d7f7b0 | 4298 | return vport; |
549e55cd | 4299 | } |
92d7f7b0 | 4300 | } |
549e55cd | 4301 | spin_unlock_irqrestore(&phba->hbalock, flags); |
92d7f7b0 JS |
4302 | return NULL; |
4303 | } | |
ed957684 JS |
4304 | |
4305 | void | |
4306 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
4307 | struct lpfc_iocbq *elsiocb) | |
4308 | { | |
4309 | struct lpfc_vport *vport = phba->pport; | |
ed957684 | 4310 | IOCB_t *icmd = &elsiocb->iocb; |
ed957684 | 4311 | dma_addr_t paddr; |
92d7f7b0 JS |
4312 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
4313 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; | |
4314 | ||
4315 | elsiocb->context2 = NULL; | |
4316 | elsiocb->context3 = NULL; | |
ed957684 | 4317 | |
92d7f7b0 JS |
4318 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
4319 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
4320 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && | |
4321 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { | |
ed957684 JS |
4322 | phba->fc_stat.NoRcvBuf++; |
4323 | /* Not enough posted buffers; Try posting more buffers */ | |
92d7f7b0 | 4324 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
ed957684 JS |
4325 | lpfc_post_buffer(phba, pring, 0, 1); |
4326 | return; | |
4327 | } | |
4328 | ||
92d7f7b0 JS |
4329 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
4330 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || | |
4331 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
4332 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) | |
4333 | vport = phba->pport; | |
4334 | else { | |
4335 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; | |
4336 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
4337 | } | |
4338 | } | |
7f5f3d0d JS |
4339 | /* If there are no BDEs associated |
4340 | * with this IOCB, there is nothing to do. | |
4341 | */ | |
ed957684 JS |
4342 | if (icmd->ulpBdeCount == 0) |
4343 | return; | |
4344 | ||
7f5f3d0d JS |
4345 | /* type of ELS cmd is first 32bit word |
4346 | * in packet | |
4347 | */ | |
ed957684 | 4348 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
92d7f7b0 | 4349 | elsiocb->context2 = bdeBuf1; |
ed957684 JS |
4350 | } else { |
4351 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, | |
4352 | icmd->un.cont64[0].addrLow); | |
92d7f7b0 JS |
4353 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
4354 | paddr); | |
ed957684 JS |
4355 | } |
4356 | ||
92d7f7b0 JS |
4357 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
4358 | /* | |
4359 | * The different unsolicited event handlers would tell us | |
4360 | * if they are done with "mp" by setting context2 to NULL. | |
4361 | */ | |
329f9bc7 JS |
4362 | lpfc_nlp_put(elsiocb->context1); |
4363 | elsiocb->context1 = NULL; | |
dea3101e | 4364 | if (elsiocb->context2) { |
92d7f7b0 JS |
4365 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
4366 | elsiocb->context2 = NULL; | |
dea3101e | 4367 | } |
ed957684 JS |
4368 | |
4369 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ | |
92d7f7b0 | 4370 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
ed957684 | 4371 | icmd->ulpBdeCount == 2) { |
92d7f7b0 JS |
4372 | elsiocb->context2 = bdeBuf2; |
4373 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); | |
ed957684 JS |
4374 | /* free mp if we are done with it */ |
4375 | if (elsiocb->context2) { | |
92d7f7b0 JS |
4376 | lpfc_in_buf_free(phba, elsiocb->context2); |
4377 | elsiocb->context2 = NULL; | |
4378 | } | |
4379 | } | |
4380 | } | |
4381 | ||
4382 | void | |
4383 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) | |
4384 | { | |
4385 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; | |
4386 | ||
4387 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | |
4388 | if (!ndlp) { | |
4389 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
4390 | if (!ndlp) { | |
4391 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
4392 | lpfc_disc_start(vport); | |
4393 | return; | |
4394 | } | |
4395 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
4396 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4397 | "0251 NameServer login: no memory\n"); | |
92d7f7b0 JS |
4398 | return; |
4399 | } | |
4400 | lpfc_nlp_init(vport, ndlp, NameServer_DID); | |
e47c9093 JS |
4401 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
4402 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
4403 | if (!ndlp) { | |
4404 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
4405 | lpfc_disc_start(vport); | |
4406 | return; | |
4407 | } | |
4408 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
4409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
4410 | "0348 NameServer login: node freed\n"); | |
4411 | return; | |
4412 | } | |
92d7f7b0 | 4413 | } |
58da1ffb | 4414 | ndlp->nlp_type |= NLP_FABRIC; |
92d7f7b0 JS |
4415 | |
4416 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
4417 | ||
4418 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { | |
4419 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
4420 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4421 | "0252 Cannot issue NameServer login\n"); | |
92d7f7b0 JS |
4422 | return; |
4423 | } | |
4424 | ||
3de2a653 | 4425 | if (vport->cfg_fdmi_on) { |
92d7f7b0 JS |
4426 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
4427 | GFP_KERNEL); | |
4428 | if (ndlp_fdmi) { | |
4429 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); | |
4430 | ndlp_fdmi->nlp_type |= NLP_FABRIC; | |
58da1ffb JS |
4431 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
4432 | NLP_STE_PLOGI_ISSUE); | |
92d7f7b0 JS |
4433 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
4434 | 0); | |
4435 | } | |
4436 | } | |
4437 | return; | |
4438 | } | |
4439 | ||
4440 | static void | |
4441 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
4442 | { | |
4443 | struct lpfc_vport *vport = pmb->vport; | |
4444 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4445 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; | |
4446 | MAILBOX_t *mb = &pmb->mb; | |
4447 | ||
09372820 | 4448 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 4449 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
09372820 | 4450 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
4451 | |
4452 | if (mb->mbxStatus) { | |
e8b62011 JS |
4453 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
4454 | "0915 Register VPI failed: 0x%x\n", | |
4455 | mb->mbxStatus); | |
92d7f7b0 JS |
4456 | |
4457 | switch (mb->mbxStatus) { | |
4458 | case 0x11: /* unsupported feature */ | |
4459 | case 0x9603: /* max_vpi exceeded */ | |
7f5f3d0d | 4460 | case 0x9602: /* Link event since CLEAR_LA */ |
92d7f7b0 JS |
4461 | /* giving up on vport registration */ |
4462 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
4463 | spin_lock_irq(shost->host_lock); | |
4464 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
4465 | spin_unlock_irq(shost->host_lock); | |
4466 | lpfc_can_disctmo(vport); | |
4467 | break; | |
4468 | default: | |
4469 | /* Try to recover from this error */ | |
4470 | lpfc_mbx_unreg_vpi(vport); | |
09372820 | 4471 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 4472 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 4473 | spin_unlock_irq(shost->host_lock); |
7f5f3d0d JS |
4474 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
4475 | lpfc_initial_flogi(vport); | |
4476 | else | |
4477 | lpfc_initial_fdisc(vport); | |
92d7f7b0 JS |
4478 | break; |
4479 | } | |
4480 | ||
4481 | } else { | |
4482 | if (vport == phba->pport) | |
4483 | lpfc_issue_fabric_reglogin(vport); | |
4484 | else | |
4485 | lpfc_do_scr_ns_plogi(phba, vport); | |
4486 | } | |
fa4066b6 JS |
4487 | |
4488 | /* Now, we decrement the ndlp reference count held for this | |
4489 | * callback function | |
4490 | */ | |
4491 | lpfc_nlp_put(ndlp); | |
4492 | ||
92d7f7b0 JS |
4493 | mempool_free(pmb, phba->mbox_mem_pool); |
4494 | return; | |
4495 | } | |
4496 | ||
a6ababd2 | 4497 | static void |
92d7f7b0 JS |
4498 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
4499 | struct lpfc_nodelist *ndlp) | |
4500 | { | |
09372820 | 4501 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
92d7f7b0 JS |
4502 | LPFC_MBOXQ_t *mbox; |
4503 | ||
4504 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4505 | if (mbox) { | |
4506 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); | |
4507 | mbox->vport = vport; | |
4508 | mbox->context2 = lpfc_nlp_get(ndlp); | |
4509 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; | |
0b727fea | 4510 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
92d7f7b0 | 4511 | == MBX_NOT_FINISHED) { |
fa4066b6 JS |
4512 | /* mailbox command not success, decrement ndlp |
4513 | * reference count for this command | |
4514 | */ | |
4515 | lpfc_nlp_put(ndlp); | |
92d7f7b0 | 4516 | mempool_free(mbox, phba->mbox_mem_pool); |
92d7f7b0 | 4517 | |
e8b62011 JS |
4518 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
4519 | "0253 Register VPI: Can't send mbox\n"); | |
fa4066b6 | 4520 | goto mbox_err_exit; |
92d7f7b0 JS |
4521 | } |
4522 | } else { | |
e8b62011 JS |
4523 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
4524 | "0254 Register VPI: no memory\n"); | |
fa4066b6 | 4525 | goto mbox_err_exit; |
92d7f7b0 | 4526 | } |
fa4066b6 JS |
4527 | return; |
4528 | ||
4529 | mbox_err_exit: | |
4530 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
4531 | spin_lock_irq(shost->host_lock); | |
4532 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
4533 | spin_unlock_irq(shost->host_lock); | |
4534 | return; | |
92d7f7b0 JS |
4535 | } |
4536 | ||
4537 | static void | |
4538 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
4539 | struct lpfc_iocbq *rspiocb) | |
4540 | { | |
4541 | struct lpfc_vport *vport = cmdiocb->vport; | |
4542 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4543 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; | |
4544 | struct lpfc_nodelist *np; | |
4545 | struct lpfc_nodelist *next_np; | |
4546 | IOCB_t *irsp = &rspiocb->iocb; | |
4547 | struct lpfc_iocbq *piocb; | |
4548 | ||
e8b62011 JS |
4549 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
4550 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", | |
4551 | irsp->ulpStatus, irsp->un.ulpWord[4], | |
4552 | vport->fc_prevDID); | |
92d7f7b0 JS |
4553 | /* Since all FDISCs are being single threaded, we |
4554 | * must reset the discovery timer for ALL vports | |
4555 | * waiting to send FDISC when one completes. | |
4556 | */ | |
4557 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { | |
4558 | lpfc_set_disctmo(piocb->vport); | |
4559 | } | |
4560 | ||
858c9f6c JS |
4561 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
4562 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", | |
4563 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); | |
4564 | ||
92d7f7b0 JS |
4565 | if (irsp->ulpStatus) { |
4566 | /* Check for retry */ | |
4567 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) | |
4568 | goto out; | |
92d7f7b0 | 4569 | /* FDISC failed */ |
e8b62011 JS |
4570 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4571 | "0124 FDISC failed. (%d/%d)\n", | |
4572 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
92d7f7b0 JS |
4573 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
4574 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
92d7f7b0 JS |
4575 | lpfc_nlp_put(ndlp); |
4576 | /* giving up on FDISC. Cancel discovery timer */ | |
4577 | lpfc_can_disctmo(vport); | |
4578 | } else { | |
4579 | spin_lock_irq(shost->host_lock); | |
4580 | vport->fc_flag |= FC_FABRIC; | |
4581 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) | |
4582 | vport->fc_flag |= FC_PUBLIC_LOOP; | |
4583 | spin_unlock_irq(shost->host_lock); | |
4584 | ||
4585 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; | |
4586 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); | |
4587 | if ((vport->fc_prevDID != vport->fc_myDID) && | |
4588 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { | |
4589 | /* If our NportID changed, we need to ensure all | |
4590 | * remaining NPORTs get unreg_login'ed so we can | |
4591 | * issue unreg_vpi. | |
4592 | */ | |
4593 | list_for_each_entry_safe(np, next_np, | |
4594 | &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
4595 | if (!NLP_CHK_NODE_ACT(ndlp) || |
4596 | (np->nlp_state != NLP_STE_NPR_NODE) || | |
4597 | !(np->nlp_flag & NLP_NPR_ADISC)) | |
92d7f7b0 JS |
4598 | continue; |
4599 | spin_lock_irq(shost->host_lock); | |
4600 | np->nlp_flag &= ~NLP_NPR_ADISC; | |
4601 | spin_unlock_irq(shost->host_lock); | |
4602 | lpfc_unreg_rpi(vport, np); | |
4603 | } | |
4604 | lpfc_mbx_unreg_vpi(vport); | |
09372820 | 4605 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 4606 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 4607 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
4608 | } |
4609 | ||
4610 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) | |
4611 | lpfc_register_new_vport(phba, vport, ndlp); | |
4612 | else | |
4613 | lpfc_do_scr_ns_plogi(phba, vport); | |
4614 | ||
fa4066b6 JS |
4615 | /* Unconditionaly kick off releasing fabric node for vports */ |
4616 | lpfc_nlp_put(ndlp); | |
92d7f7b0 JS |
4617 | } |
4618 | ||
4619 | out: | |
4620 | lpfc_els_free_iocb(phba, cmdiocb); | |
4621 | } | |
4622 | ||
a6ababd2 | 4623 | static int |
92d7f7b0 JS |
4624 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
4625 | uint8_t retry) | |
4626 | { | |
4627 | struct lpfc_hba *phba = vport->phba; | |
4628 | IOCB_t *icmd; | |
4629 | struct lpfc_iocbq *elsiocb; | |
4630 | struct serv_parm *sp; | |
4631 | uint8_t *pcmd; | |
4632 | uint16_t cmdsize; | |
4633 | int did = ndlp->nlp_DID; | |
4634 | int rc; | |
92d7f7b0 JS |
4635 | |
4636 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); | |
4637 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, | |
4638 | ELS_CMD_FDISC); | |
4639 | if (!elsiocb) { | |
92d7f7b0 | 4640 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
4641 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4642 | "0255 Issue FDISC: no IOCB\n"); | |
92d7f7b0 JS |
4643 | return 1; |
4644 | } | |
4645 | ||
4646 | icmd = &elsiocb->iocb; | |
4647 | icmd->un.elsreq64.myID = 0; | |
4648 | icmd->un.elsreq64.fl = 1; | |
4649 | ||
4650 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ | |
4651 | icmd->ulpCt_h = 1; | |
4652 | icmd->ulpCt_l = 0; | |
4653 | ||
4654 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4655 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; | |
4656 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ | |
4657 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); | |
4658 | sp = (struct serv_parm *) pcmd; | |
4659 | /* Setup CSPs accordingly for Fabric */ | |
4660 | sp->cmn.e_d_tov = 0; | |
4661 | sp->cmn.w2.r_a_tov = 0; | |
4662 | sp->cls1.classValid = 0; | |
4663 | sp->cls2.seqDelivery = 1; | |
4664 | sp->cls3.seqDelivery = 1; | |
4665 | ||
4666 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ | |
4667 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ | |
4668 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ | |
4669 | pcmd += sizeof(uint32_t); /* Port Name */ | |
4670 | memcpy(pcmd, &vport->fc_portname, 8); | |
4671 | pcmd += sizeof(uint32_t); /* Node Name */ | |
4672 | pcmd += sizeof(uint32_t); /* Node Name */ | |
4673 | memcpy(pcmd, &vport->fc_nodename, 8); | |
4674 | ||
4675 | lpfc_set_disctmo(vport); | |
4676 | ||
4677 | phba->fc_stat.elsXmitFDISC++; | |
4678 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; | |
4679 | ||
858c9f6c JS |
4680 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
4681 | "Issue FDISC: did:x%x", | |
4682 | did, 0, 0); | |
4683 | ||
92d7f7b0 JS |
4684 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
4685 | if (rc == IOCB_ERROR) { | |
4686 | lpfc_els_free_iocb(phba, elsiocb); | |
92d7f7b0 | 4687 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
4688 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4689 | "0256 Issue FDISC: Cannot send IOCB\n"); | |
92d7f7b0 JS |
4690 | return 1; |
4691 | } | |
4692 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); | |
4693 | vport->port_state = LPFC_FDISC; | |
4694 | return 0; | |
4695 | } | |
4696 | ||
4697 | static void | |
4698 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
4699 | struct lpfc_iocbq *rspiocb) | |
4700 | { | |
4701 | struct lpfc_vport *vport = cmdiocb->vport; | |
858c9f6c | 4702 | IOCB_t *irsp; |
e47c9093 JS |
4703 | struct lpfc_nodelist *ndlp; |
4704 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; | |
858c9f6c JS |
4705 | |
4706 | irsp = &rspiocb->iocb; | |
4707 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
4708 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", | |
4709 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); | |
92d7f7b0 JS |
4710 | |
4711 | lpfc_els_free_iocb(phba, cmdiocb); | |
4712 | vport->unreg_vpi_cmpl = VPORT_ERROR; | |
e47c9093 JS |
4713 | |
4714 | /* Trigger the release of the ndlp after logo */ | |
4715 | lpfc_nlp_put(ndlp); | |
92d7f7b0 JS |
4716 | } |
4717 | ||
4718 | int | |
4719 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
4720 | { | |
4721 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4722 | struct lpfc_hba *phba = vport->phba; | |
4723 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4724 | IOCB_t *icmd; | |
4725 | struct lpfc_iocbq *elsiocb; | |
4726 | uint8_t *pcmd; | |
4727 | uint16_t cmdsize; | |
4728 | ||
4729 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); | |
4730 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, | |
4731 | ELS_CMD_LOGO); | |
4732 | if (!elsiocb) | |
4733 | return 1; | |
4734 | ||
4735 | icmd = &elsiocb->iocb; | |
4736 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); | |
4737 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; | |
4738 | pcmd += sizeof(uint32_t); | |
4739 | ||
4740 | /* Fill in LOGO payload */ | |
4741 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); | |
4742 | pcmd += sizeof(uint32_t); | |
4743 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); | |
4744 | ||
858c9f6c JS |
4745 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
4746 | "Issue LOGO npiv did:x%x flg:x%x", | |
4747 | ndlp->nlp_DID, ndlp->nlp_flag, 0); | |
4748 | ||
92d7f7b0 JS |
4749 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
4750 | spin_lock_irq(shost->host_lock); | |
4751 | ndlp->nlp_flag |= NLP_LOGO_SND; | |
4752 | spin_unlock_irq(shost->host_lock); | |
4753 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { | |
4754 | spin_lock_irq(shost->host_lock); | |
4755 | ndlp->nlp_flag &= ~NLP_LOGO_SND; | |
4756 | spin_unlock_irq(shost->host_lock); | |
4757 | lpfc_els_free_iocb(phba, elsiocb); | |
4758 | return 1; | |
4759 | } | |
4760 | return 0; | |
4761 | } | |
4762 | ||
4763 | void | |
4764 | lpfc_fabric_block_timeout(unsigned long ptr) | |
4765 | { | |
4766 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
4767 | unsigned long iflags; | |
4768 | uint32_t tmo_posted; | |
5e9d9b82 | 4769 | |
92d7f7b0 JS |
4770 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
4771 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; | |
4772 | if (!tmo_posted) | |
4773 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; | |
4774 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
4775 | ||
5e9d9b82 JS |
4776 | if (!tmo_posted) |
4777 | lpfc_worker_wake_up(phba); | |
4778 | return; | |
92d7f7b0 JS |
4779 | } |
4780 | ||
4781 | static void | |
4782 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) | |
4783 | { | |
4784 | struct lpfc_iocbq *iocb; | |
4785 | unsigned long iflags; | |
4786 | int ret; | |
4787 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4788 | IOCB_t *cmd; | |
4789 | ||
4790 | repeat: | |
4791 | iocb = NULL; | |
4792 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7f5f3d0d | 4793 | /* Post any pending iocb to the SLI layer */ |
92d7f7b0 JS |
4794 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
4795 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), | |
4796 | list); | |
4797 | if (iocb) | |
7f5f3d0d | 4798 | /* Increment fabric iocb count to hold the position */ |
92d7f7b0 JS |
4799 | atomic_inc(&phba->fabric_iocb_count); |
4800 | } | |
4801 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
4802 | if (iocb) { | |
4803 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
4804 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
4805 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
4806 | ||
858c9f6c JS |
4807 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
4808 | "Fabric sched1: ste:x%x", | |
4809 | iocb->vport->port_state, 0, 0); | |
4810 | ||
92d7f7b0 JS |
4811 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
4812 | ||
4813 | if (ret == IOCB_ERROR) { | |
4814 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
4815 | iocb->fabric_iocb_cmpl = NULL; | |
4816 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
4817 | cmd = &iocb->iocb; | |
4818 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
4819 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
4820 | iocb->iocb_cmpl(phba, iocb, iocb); | |
4821 | ||
4822 | atomic_dec(&phba->fabric_iocb_count); | |
4823 | goto repeat; | |
4824 | } | |
4825 | } | |
4826 | ||
4827 | return; | |
4828 | } | |
4829 | ||
4830 | void | |
4831 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) | |
4832 | { | |
4833 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
4834 | ||
4835 | lpfc_resume_fabric_iocbs(phba); | |
4836 | return; | |
4837 | } | |
4838 | ||
4839 | static void | |
4840 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) | |
4841 | { | |
4842 | int blocked; | |
4843 | ||
4844 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
7f5f3d0d | 4845 | /* Start a timer to unblock fabric iocbs after 100ms */ |
92d7f7b0 JS |
4846 | if (!blocked) |
4847 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); | |
4848 | ||
4849 | return; | |
4850 | } | |
4851 | ||
4852 | static void | |
4853 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
4854 | struct lpfc_iocbq *rspiocb) | |
4855 | { | |
4856 | struct ls_rjt stat; | |
4857 | ||
4858 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) | |
4859 | BUG(); | |
4860 | ||
4861 | switch (rspiocb->iocb.ulpStatus) { | |
4862 | case IOSTAT_NPORT_RJT: | |
4863 | case IOSTAT_FABRIC_RJT: | |
4864 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { | |
4865 | lpfc_block_fabric_iocbs(phba); | |
ed957684 | 4866 | } |
92d7f7b0 JS |
4867 | break; |
4868 | ||
4869 | case IOSTAT_NPORT_BSY: | |
4870 | case IOSTAT_FABRIC_BSY: | |
4871 | lpfc_block_fabric_iocbs(phba); | |
4872 | break; | |
4873 | ||
4874 | case IOSTAT_LS_RJT: | |
4875 | stat.un.lsRjtError = | |
4876 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); | |
4877 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || | |
4878 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) | |
4879 | lpfc_block_fabric_iocbs(phba); | |
4880 | break; | |
4881 | } | |
4882 | ||
4883 | if (atomic_read(&phba->fabric_iocb_count) == 0) | |
4884 | BUG(); | |
4885 | ||
4886 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; | |
4887 | cmdiocb->fabric_iocb_cmpl = NULL; | |
4888 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
4889 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); | |
4890 | ||
4891 | atomic_dec(&phba->fabric_iocb_count); | |
4892 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { | |
7f5f3d0d JS |
4893 | /* Post any pending iocbs to HBA */ |
4894 | lpfc_resume_fabric_iocbs(phba); | |
92d7f7b0 JS |
4895 | } |
4896 | } | |
4897 | ||
a6ababd2 | 4898 | static int |
92d7f7b0 JS |
4899 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
4900 | { | |
4901 | unsigned long iflags; | |
4902 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4903 | int ready; | |
4904 | int ret; | |
4905 | ||
4906 | if (atomic_read(&phba->fabric_iocb_count) > 1) | |
4907 | BUG(); | |
4908 | ||
4909 | spin_lock_irqsave(&phba->hbalock, iflags); | |
4910 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && | |
4911 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
4912 | ||
7f5f3d0d JS |
4913 | if (ready) |
4914 | /* Increment fabric iocb count to hold the position */ | |
4915 | atomic_inc(&phba->fabric_iocb_count); | |
92d7f7b0 JS |
4916 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4917 | if (ready) { | |
4918 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; | |
4919 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; | |
4920 | iocb->iocb_flag |= LPFC_IO_FABRIC; | |
4921 | ||
858c9f6c JS |
4922 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
4923 | "Fabric sched2: ste:x%x", | |
4924 | iocb->vport->port_state, 0, 0); | |
4925 | ||
92d7f7b0 JS |
4926 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
4927 | ||
4928 | if (ret == IOCB_ERROR) { | |
4929 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; | |
4930 | iocb->fabric_iocb_cmpl = NULL; | |
4931 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; | |
4932 | atomic_dec(&phba->fabric_iocb_count); | |
4933 | } | |
4934 | } else { | |
4935 | spin_lock_irqsave(&phba->hbalock, iflags); | |
4936 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); | |
4937 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
4938 | ret = IOCB_SUCCESS; | |
4939 | } | |
4940 | return ret; | |
4941 | } | |
4942 | ||
4943 | ||
a6ababd2 | 4944 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
92d7f7b0 JS |
4945 | { |
4946 | LIST_HEAD(completions); | |
4947 | struct lpfc_hba *phba = vport->phba; | |
4948 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
4949 | IOCB_t *cmd; | |
4950 | ||
4951 | spin_lock_irq(&phba->hbalock); | |
4952 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
4953 | list) { | |
4954 | ||
4955 | if (piocb->vport != vport) | |
4956 | continue; | |
4957 | ||
4958 | list_move_tail(&piocb->list, &completions); | |
4959 | } | |
4960 | spin_unlock_irq(&phba->hbalock); | |
4961 | ||
4962 | while (!list_empty(&completions)) { | |
4963 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
4964 | list_del_init(&piocb->list); | |
4965 | ||
4966 | cmd = &piocb->iocb; | |
4967 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
4968 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
4969 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
4970 | } | |
4971 | } | |
4972 | ||
4973 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) | |
4974 | { | |
4975 | LIST_HEAD(completions); | |
4976 | struct lpfc_hba *phba = ndlp->vport->phba; | |
4977 | struct lpfc_iocbq *tmp_iocb, *piocb; | |
4978 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4979 | IOCB_t *cmd; | |
4980 | ||
4981 | spin_lock_irq(&phba->hbalock); | |
4982 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, | |
4983 | list) { | |
4984 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { | |
4985 | ||
4986 | list_move_tail(&piocb->list, &completions); | |
ed957684 | 4987 | } |
dea3101e | 4988 | } |
92d7f7b0 JS |
4989 | spin_unlock_irq(&phba->hbalock); |
4990 | ||
4991 | while (!list_empty(&completions)) { | |
4992 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
4993 | list_del_init(&piocb->list); | |
4994 | ||
4995 | cmd = &piocb->iocb; | |
4996 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
4997 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
4998 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
4999 | } | |
5000 | } | |
5001 | ||
5002 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) | |
5003 | { | |
5004 | LIST_HEAD(completions); | |
5005 | struct lpfc_iocbq *piocb; | |
5006 | IOCB_t *cmd; | |
5007 | ||
5008 | spin_lock_irq(&phba->hbalock); | |
5009 | list_splice_init(&phba->fabric_iocb_list, &completions); | |
5010 | spin_unlock_irq(&phba->hbalock); | |
5011 | ||
5012 | while (!list_empty(&completions)) { | |
5013 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
5014 | list_del_init(&piocb->list); | |
5015 | ||
5016 | cmd = &piocb->iocb; | |
5017 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; | |
5018 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
5019 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
5020 | } | |
dea3101e | 5021 | } |