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