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