Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
0d041215 | 4 | * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term * |
4ae2ebde | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
c44ce173 | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 10 | * * |
11 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
12 | * modify it under the terms of version 2 of the GNU General * |
13 | * Public License as published by the Free Software Foundation. * | |
14 | * This program is distributed in the hope that it will be useful. * | |
15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
20 | * more details, a copy of which can be found in the file COPYING * | |
21 | * included with this package. * | |
dea3101e | 22 | *******************************************************************/ |
23 | ||
dea3101e | 24 | #include <linux/blkdev.h> |
a93ff37a | 25 | #include <linux/delay.h> |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | #include <linux/pci.h> |
28 | #include <linux/kthread.h> | |
29 | #include <linux/interrupt.h> | |
1c2ba475 | 30 | #include <linux/lockdep.h> |
dea3101e | 31 | |
91886523 | 32 | #include <scsi/scsi.h> |
dea3101e | 33 | #include <scsi/scsi_device.h> |
34 | #include <scsi/scsi_host.h> | |
35 | #include <scsi/scsi_transport_fc.h> | |
a0f2d3ef JS |
36 | #include <scsi/fc/fc_fs.h> |
37 | ||
38 | #include <linux/nvme-fc-driver.h> | |
dea3101e | 39 | |
da0436e9 | 40 | #include "lpfc_hw4.h" |
dea3101e | 41 | #include "lpfc_hw.h" |
ea2151b4 | 42 | #include "lpfc_nl.h" |
dea3101e | 43 | #include "lpfc_disc.h" |
44 | #include "lpfc_sli.h" | |
da0436e9 | 45 | #include "lpfc_sli4.h" |
dea3101e | 46 | #include "lpfc.h" |
a0f2d3ef JS |
47 | #include "lpfc_scsi.h" |
48 | #include "lpfc_nvme.h" | |
dea3101e | 49 | #include "lpfc_logmsg.h" |
50 | #include "lpfc_crtn.h" | |
92d7f7b0 | 51 | #include "lpfc_vport.h" |
858c9f6c | 52 | #include "lpfc_debugfs.h" |
dea3101e | 53 | |
54 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ | |
55 | static uint8_t lpfcAlpaArray[] = { | |
56 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, | |
57 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, | |
58 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, | |
59 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, | |
60 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, | |
61 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, | |
62 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, | |
63 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, | |
64 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, | |
65 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, | |
66 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, | |
67 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, | |
68 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 | |
69 | }; | |
70 | ||
2e0fef85 | 71 | static void lpfc_disc_timeout_handler(struct lpfc_vport *); |
a6ababd2 | 72 | static void lpfc_disc_flush_list(struct lpfc_vport *vport); |
32b9793f | 73 | static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); |
a93ff37a | 74 | static int lpfc_fcf_inuse(struct lpfc_hba *); |
dea3101e | 75 | |
c01f3208 JS |
76 | void |
77 | lpfc_terminate_rport_io(struct fc_rport *rport) | |
dea3101e | 78 | { |
c01f3208 JS |
79 | struct lpfc_rport_data *rdata; |
80 | struct lpfc_nodelist * ndlp; | |
81 | struct lpfc_hba *phba; | |
dea3101e | 82 | |
c01f3208 JS |
83 | rdata = rport->dd_data; |
84 | ndlp = rdata->pnode; | |
85 | ||
58da1ffb | 86 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
c01f3208 JS |
87 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) |
88 | printk(KERN_ERR "Cannot find remote node" | |
89 | " to terminate I/O Data x%x\n", | |
90 | rport->port_id); | |
dea3101e | 91 | return; |
92 | } | |
93 | ||
a257bf90 | 94 | phba = ndlp->phba; |
c01f3208 | 95 | |
858c9f6c JS |
96 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT, |
97 | "rport terminate: sid:x%x did:x%x flg:x%x", | |
98 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); | |
99 | ||
c01f3208 | 100 | if (ndlp->nlp_sid != NLP_NO_SID) { |
51ef4c26 | 101 | lpfc_sli_abort_iocb(ndlp->vport, |
895427bd | 102 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
51ef4c26 | 103 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
c01f3208 | 104 | } |
c01f3208 JS |
105 | } |
106 | ||
107 | /* | |
108 | * This function will be called when dev_loss_tmo fire. | |
109 | */ | |
110 | void | |
111 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) | |
112 | { | |
113 | struct lpfc_rport_data *rdata; | |
114 | struct lpfc_nodelist * ndlp; | |
2e0fef85 | 115 | struct lpfc_vport *vport; |
466e840b | 116 | struct Scsi_Host *shost; |
858c9f6c | 117 | struct lpfc_hba *phba; |
858c9f6c | 118 | struct lpfc_work_evt *evtp; |
a8adb832 JS |
119 | int put_node; |
120 | int put_rport; | |
894bb17f | 121 | unsigned long iflags; |
c01f3208 JS |
122 | |
123 | rdata = rport->dd_data; | |
124 | ndlp = rdata->pnode; | |
58da1ffb | 125 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
c01f3208 | 126 | return; |
c01f3208 | 127 | |
858c9f6c JS |
128 | vport = ndlp->vport; |
129 | phba = vport->phba; | |
130 | ||
131 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, | |
132 | "rport devlosscb: sid:x%x did:x%x flg:x%x", | |
133 | ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag); | |
134 | ||
34f5ad8b JS |
135 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
136 | "3181 dev_loss_callbk x%06x, rport %p flg x%x\n", | |
137 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); | |
138 | ||
a8adb832 JS |
139 | /* Don't defer this if we are in the process of deleting the vport |
140 | * or unloading the driver. The unload will cleanup the node | |
141 | * appropriately we just need to cleanup the ndlp rport info here. | |
142 | */ | |
143 | if (vport->load_flag & FC_UNLOADING) { | |
144 | put_node = rdata->pnode != NULL; | |
145 | put_rport = ndlp->rport != NULL; | |
146 | rdata->pnode = NULL; | |
147 | ndlp->rport = NULL; | |
148 | if (put_node) | |
149 | lpfc_nlp_put(ndlp); | |
150 | if (put_rport) | |
151 | put_device(&rport->dev); | |
152 | return; | |
153 | } | |
154 | ||
155 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) | |
156 | return; | |
157 | ||
466e840b JS |
158 | if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) |
159 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, | |
160 | "6789 rport name %llx != node port name %llx", | |
161 | rport->port_name, | |
162 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); | |
34f5ad8b | 163 | |
858c9f6c JS |
164 | evtp = &ndlp->dev_loss_evt; |
165 | ||
466e840b JS |
166 | if (!list_empty(&evtp->evt_listp)) { |
167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, | |
168 | "6790 rport name %llx dev_loss_evt pending", | |
169 | rport->port_name); | |
858c9f6c | 170 | return; |
466e840b | 171 | } |
858c9f6c | 172 | |
466e840b | 173 | shost = lpfc_shost_from_vport(vport); |
894bb17f | 174 | spin_lock_irqsave(shost->host_lock, iflags); |
466e840b | 175 | ndlp->nlp_flag |= NLP_IN_DEV_LOSS; |
894bb17f | 176 | spin_unlock_irqrestore(shost->host_lock, iflags); |
a62a435a | 177 | |
fa4066b6 JS |
178 | /* We need to hold the node by incrementing the reference |
179 | * count until this queued work is done | |
180 | */ | |
466e840b JS |
181 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
182 | ||
894bb17f | 183 | spin_lock_irqsave(&phba->hbalock, iflags); |
5e9d9b82 JS |
184 | if (evtp->evt_arg1) { |
185 | evtp->evt = LPFC_EVT_DEV_LOSS; | |
186 | list_add_tail(&evtp->evt_listp, &phba->work_list); | |
187 | lpfc_worker_wake_up(phba); | |
188 | } | |
894bb17f | 189 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
858c9f6c | 190 | |
858c9f6c JS |
191 | return; |
192 | } | |
193 | ||
a93ff37a JS |
194 | /** |
195 | * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler | |
196 | * @ndlp: Pointer to remote node object. | |
197 | * | |
198 | * This function is called from the worker thread when devloss timeout timer | |
199 | * expires. For SLI4 host, this routine shall return 1 when at lease one | |
200 | * remote node, including this @ndlp, is still in use of FCF; otherwise, this | |
201 | * routine shall return 0 when there is no remote node is still in use of FCF | |
202 | * when devloss timeout happened to this @ndlp. | |
203 | **/ | |
204 | static int | |
858c9f6c JS |
205 | lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp) |
206 | { | |
207 | struct lpfc_rport_data *rdata; | |
208 | struct fc_rport *rport; | |
209 | struct lpfc_vport *vport; | |
210 | struct lpfc_hba *phba; | |
466e840b | 211 | struct Scsi_Host *shost; |
858c9f6c | 212 | uint8_t *name; |
87af33fe | 213 | int put_node; |
858c9f6c | 214 | int warn_on = 0; |
a93ff37a | 215 | int fcf_inuse = 0; |
894bb17f | 216 | unsigned long iflags; |
858c9f6c JS |
217 | |
218 | rport = ndlp->rport; | |
466e840b JS |
219 | vport = ndlp->vport; |
220 | shost = lpfc_shost_from_vport(vport); | |
858c9f6c | 221 | |
894bb17f | 222 | spin_lock_irqsave(shost->host_lock, iflags); |
466e840b | 223 | ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS; |
894bb17f | 224 | spin_unlock_irqrestore(shost->host_lock, iflags); |
466e840b JS |
225 | |
226 | if (!rport) | |
a93ff37a | 227 | return fcf_inuse; |
858c9f6c | 228 | |
858c9f6c | 229 | name = (uint8_t *) &ndlp->nlp_portname; |
858c9f6c JS |
230 | phba = vport->phba; |
231 | ||
a93ff37a JS |
232 | if (phba->sli_rev == LPFC_SLI_REV4) |
233 | fcf_inuse = lpfc_fcf_inuse(phba); | |
234 | ||
858c9f6c JS |
235 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
236 | "rport devlosstmo:did:x%x type:x%x id:x%x", | |
237 | ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id); | |
238 | ||
34f5ad8b JS |
239 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
240 | "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n", | |
241 | ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag); | |
242 | ||
466e840b JS |
243 | /* |
244 | * lpfc_nlp_remove if reached with dangling rport drops the | |
245 | * reference. To make sure that does not happen clear rport | |
246 | * pointer in ndlp before lpfc_nlp_put. | |
247 | */ | |
248 | rdata = rport->dd_data; | |
249 | ||
a8adb832 JS |
250 | /* Don't defer this if we are in the process of deleting the vport |
251 | * or unloading the driver. The unload will cleanup the node | |
252 | * appropriately we just need to cleanup the ndlp rport info here. | |
253 | */ | |
254 | if (vport->load_flag & FC_UNLOADING) { | |
09372820 JS |
255 | if (ndlp->nlp_sid != NLP_NO_SID) { |
256 | /* flush the target */ | |
257 | lpfc_sli_abort_iocb(vport, | |
895427bd JS |
258 | &phba->sli.sli3_ring[LPFC_FCP_RING], |
259 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); | |
09372820 | 260 | } |
a8adb832 | 261 | put_node = rdata->pnode != NULL; |
a8adb832 JS |
262 | rdata->pnode = NULL; |
263 | ndlp->rport = NULL; | |
264 | if (put_node) | |
265 | lpfc_nlp_put(ndlp); | |
466e840b JS |
266 | put_device(&rport->dev); |
267 | ||
a93ff37a | 268 | return fcf_inuse; |
a8adb832 JS |
269 | } |
270 | ||
d7c255b2 JS |
271 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
273 | "0284 Devloss timeout Ignored on " | |
274 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " | |
275 | "NPort x%x\n", | |
276 | *name, *(name+1), *(name+2), *(name+3), | |
277 | *(name+4), *(name+5), *(name+6), *(name+7), | |
278 | ndlp->nlp_DID); | |
a93ff37a | 279 | return fcf_inuse; |
d7c255b2 | 280 | } |
858c9f6c | 281 | |
466e840b JS |
282 | put_node = rdata->pnode != NULL; |
283 | rdata->pnode = NULL; | |
284 | ndlp->rport = NULL; | |
285 | if (put_node) | |
286 | lpfc_nlp_put(ndlp); | |
287 | put_device(&rport->dev); | |
288 | ||
289 | if (ndlp->nlp_type & NLP_FABRIC) | |
a93ff37a | 290 | return fcf_inuse; |
82085718 | 291 | |
dea3101e | 292 | if (ndlp->nlp_sid != NLP_NO_SID) { |
6e8215e4 | 293 | warn_on = 1; |
895427bd | 294 | lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING], |
51ef4c26 | 295 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
dea3101e | 296 | } |
c01f3208 | 297 | |
6e8215e4 | 298 | if (warn_on) { |
e8b62011 JS |
299 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
300 | "0203 Devloss timeout on " | |
58da1ffb JS |
301 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
302 | "NPort x%06x Data: x%x x%x x%x\n", | |
e8b62011 JS |
303 | *name, *(name+1), *(name+2), *(name+3), |
304 | *(name+4), *(name+5), *(name+6), *(name+7), | |
305 | ndlp->nlp_DID, ndlp->nlp_flag, | |
306 | ndlp->nlp_state, ndlp->nlp_rpi); | |
6e8215e4 | 307 | } else { |
e8b62011 JS |
308 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
309 | "0204 Devloss timeout on " | |
58da1ffb JS |
310 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x " |
311 | "NPort x%06x Data: x%x x%x x%x\n", | |
e8b62011 JS |
312 | *name, *(name+1), *(name+2), *(name+3), |
313 | *(name+4), *(name+5), *(name+6), *(name+7), | |
314 | ndlp->nlp_DID, ndlp->nlp_flag, | |
315 | ndlp->nlp_state, ndlp->nlp_rpi); | |
6e8215e4 JSEC |
316 | } |
317 | ||
2ade92ae | 318 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
82085718 | 319 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && |
ffc95493 | 320 | (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
589a52d6 JS |
321 | (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && |
322 | (ndlp->nlp_state != NLP_STE_PRLI_ISSUE)) | |
2e0fef85 | 323 | lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); |
6fb120a7 | 324 | |
a93ff37a JS |
325 | return fcf_inuse; |
326 | } | |
327 | ||
328 | /** | |
329 | * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler | |
330 | * @phba: Pointer to hba context object. | |
331 | * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler. | |
332 | * @nlp_did: remote node identifer with devloss timeout. | |
333 | * | |
334 | * This function is called from the worker thread after invoking devloss | |
335 | * timeout handler and releasing the reference count for the ndlp with | |
336 | * which the devloss timeout was handled for SLI4 host. For the devloss | |
337 | * timeout of the last remote node which had been in use of FCF, when this | |
338 | * routine is invoked, it shall be guaranteed that none of the remote are | |
339 | * in-use of FCF. When devloss timeout to the last remote using the FCF, | |
340 | * if the FIP engine is neither in FCF table scan process nor roundrobin | |
341 | * failover process, the in-use FCF shall be unregistered. If the FIP | |
342 | * engine is in FCF discovery process, the devloss timeout state shall | |
343 | * be set for either the FCF table scan process or roundrobin failover | |
344 | * process to unregister the in-use FCF. | |
345 | **/ | |
346 | static void | |
347 | lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse, | |
348 | uint32_t nlp_did) | |
349 | { | |
350 | /* If devloss timeout happened to a remote node when FCF had no | |
351 | * longer been in-use, do nothing. | |
352 | */ | |
353 | if (!fcf_inuse) | |
354 | return; | |
355 | ||
356 | if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) { | |
357 | spin_lock_irq(&phba->hbalock); | |
358 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { | |
359 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { | |
360 | spin_unlock_irq(&phba->hbalock); | |
361 | return; | |
362 | } | |
363 | phba->hba_flag |= HBA_DEVLOSS_TMO; | |
364 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
365 | "2847 Last remote node (x%x) using " | |
366 | "FCF devloss tmo\n", nlp_did); | |
367 | } | |
368 | if (phba->fcf.fcf_flag & FCF_REDISC_PROG) { | |
369 | spin_unlock_irq(&phba->hbalock); | |
370 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
371 | "2868 Devloss tmo to FCF rediscovery " | |
372 | "in progress\n"); | |
373 | return; | |
374 | } | |
375 | if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) { | |
376 | spin_unlock_irq(&phba->hbalock); | |
377 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
378 | "2869 Devloss tmo to idle FIP engine, " | |
379 | "unreg in-use FCF and rescan.\n"); | |
380 | /* Unregister in-use FCF and rescan */ | |
381 | lpfc_unregister_fcf_rescan(phba); | |
382 | return; | |
383 | } | |
384 | spin_unlock_irq(&phba->hbalock); | |
385 | if (phba->hba_flag & FCF_TS_INPROG) | |
386 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
387 | "2870 FCF table scan in progress\n"); | |
388 | if (phba->hba_flag & FCF_RR_INPROG) | |
389 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
390 | "2871 FLOGI roundrobin FCF failover " | |
391 | "in progress\n"); | |
392 | } | |
6fb120a7 | 393 | lpfc_unregister_unused_fcf(phba); |
92d7f7b0 | 394 | } |
c01f3208 | 395 | |
ea2151b4 | 396 | /** |
3621a710 | 397 | * lpfc_alloc_fast_evt - Allocates data structure for posting event |
ea2151b4 JS |
398 | * @phba: Pointer to hba context object. |
399 | * | |
400 | * This function is called from the functions which need to post | |
401 | * events from interrupt context. This function allocates data | |
402 | * structure required for posting event. It also keeps track of | |
403 | * number of events pending and prevent event storm when there are | |
404 | * too many events. | |
405 | **/ | |
406 | struct lpfc_fast_path_event * | |
407 | lpfc_alloc_fast_evt(struct lpfc_hba *phba) { | |
408 | struct lpfc_fast_path_event *ret; | |
409 | ||
410 | /* If there are lot of fast event do not exhaust memory due to this */ | |
411 | if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT) | |
412 | return NULL; | |
413 | ||
414 | ret = kzalloc(sizeof(struct lpfc_fast_path_event), | |
415 | GFP_ATOMIC); | |
6fb120a7 | 416 | if (ret) { |
ea2151b4 | 417 | atomic_inc(&phba->fast_event_count); |
6fb120a7 JS |
418 | INIT_LIST_HEAD(&ret->work_evt.evt_listp); |
419 | ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; | |
420 | } | |
ea2151b4 JS |
421 | return ret; |
422 | } | |
423 | ||
424 | /** | |
3621a710 | 425 | * lpfc_free_fast_evt - Frees event data structure |
ea2151b4 JS |
426 | * @phba: Pointer to hba context object. |
427 | * @evt: Event object which need to be freed. | |
428 | * | |
429 | * This function frees the data structure required for posting | |
430 | * events. | |
431 | **/ | |
432 | void | |
433 | lpfc_free_fast_evt(struct lpfc_hba *phba, | |
434 | struct lpfc_fast_path_event *evt) { | |
435 | ||
436 | atomic_dec(&phba->fast_event_count); | |
437 | kfree(evt); | |
438 | } | |
439 | ||
440 | /** | |
3621a710 | 441 | * lpfc_send_fastpath_evt - Posts events generated from fast path |
ea2151b4 JS |
442 | * @phba: Pointer to hba context object. |
443 | * @evtp: Event data structure. | |
444 | * | |
445 | * This function is called from worker thread, when the interrupt | |
446 | * context need to post an event. This function posts the event | |
447 | * to fc transport netlink interface. | |
448 | **/ | |
449 | static void | |
450 | lpfc_send_fastpath_evt(struct lpfc_hba *phba, | |
451 | struct lpfc_work_evt *evtp) | |
452 | { | |
453 | unsigned long evt_category, evt_sub_category; | |
454 | struct lpfc_fast_path_event *fast_evt_data; | |
455 | char *evt_data; | |
456 | uint32_t evt_data_size; | |
457 | struct Scsi_Host *shost; | |
458 | ||
459 | fast_evt_data = container_of(evtp, struct lpfc_fast_path_event, | |
460 | work_evt); | |
461 | ||
462 | evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type; | |
463 | evt_sub_category = (unsigned long) fast_evt_data->un. | |
464 | fabric_evt.subcategory; | |
465 | shost = lpfc_shost_from_vport(fast_evt_data->vport); | |
466 | if (evt_category == FC_REG_FABRIC_EVENT) { | |
467 | if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) { | |
468 | evt_data = (char *) &fast_evt_data->un.read_check_error; | |
469 | evt_data_size = sizeof(fast_evt_data->un. | |
470 | read_check_error); | |
471 | } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) || | |
eaf15d5b | 472 | (evt_sub_category == LPFC_EVENT_PORT_BUSY)) { |
ea2151b4 JS |
473 | evt_data = (char *) &fast_evt_data->un.fabric_evt; |
474 | evt_data_size = sizeof(fast_evt_data->un.fabric_evt); | |
475 | } else { | |
476 | lpfc_free_fast_evt(phba, fast_evt_data); | |
477 | return; | |
478 | } | |
479 | } else if (evt_category == FC_REG_SCSI_EVENT) { | |
480 | switch (evt_sub_category) { | |
481 | case LPFC_EVENT_QFULL: | |
482 | case LPFC_EVENT_DEVBSY: | |
483 | evt_data = (char *) &fast_evt_data->un.scsi_evt; | |
484 | evt_data_size = sizeof(fast_evt_data->un.scsi_evt); | |
485 | break; | |
486 | case LPFC_EVENT_CHECK_COND: | |
487 | evt_data = (char *) &fast_evt_data->un.check_cond_evt; | |
488 | evt_data_size = sizeof(fast_evt_data->un. | |
489 | check_cond_evt); | |
490 | break; | |
491 | case LPFC_EVENT_VARQUEDEPTH: | |
492 | evt_data = (char *) &fast_evt_data->un.queue_depth_evt; | |
493 | evt_data_size = sizeof(fast_evt_data->un. | |
494 | queue_depth_evt); | |
495 | break; | |
496 | default: | |
497 | lpfc_free_fast_evt(phba, fast_evt_data); | |
498 | return; | |
499 | } | |
500 | } else { | |
501 | lpfc_free_fast_evt(phba, fast_evt_data); | |
502 | return; | |
503 | } | |
504 | ||
895427bd JS |
505 | if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
506 | fc_host_post_vendor_event(shost, | |
507 | fc_get_event_number(), | |
508 | evt_data_size, | |
509 | evt_data, | |
510 | LPFC_NL_VENDOR_ID); | |
ea2151b4 JS |
511 | |
512 | lpfc_free_fast_evt(phba, fast_evt_data); | |
513 | return; | |
514 | } | |
515 | ||
dea3101e | 516 | static void |
2e0fef85 | 517 | lpfc_work_list_done(struct lpfc_hba *phba) |
dea3101e | 518 | { |
519 | struct lpfc_work_evt *evtp = NULL; | |
520 | struct lpfc_nodelist *ndlp; | |
521 | int free_evt; | |
a93ff37a JS |
522 | int fcf_inuse; |
523 | uint32_t nlp_did; | |
dea3101e | 524 | |
2e0fef85 JS |
525 | spin_lock_irq(&phba->hbalock); |
526 | while (!list_empty(&phba->work_list)) { | |
dea3101e | 527 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), |
528 | evt_listp); | |
2e0fef85 | 529 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 530 | free_evt = 1; |
2fe165b6 | 531 | switch (evtp->evt) { |
dea3101e | 532 | case LPFC_EVT_ELS_RETRY: |
2e0fef85 | 533 | ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); |
dea3101e | 534 | lpfc_els_retry_delay_handler(ndlp); |
92d7f7b0 | 535 | free_evt = 0; /* evt is part of ndlp */ |
fa4066b6 JS |
536 | /* decrement the node reference count held |
537 | * for this queued work | |
538 | */ | |
539 | lpfc_nlp_put(ndlp); | |
dea3101e | 540 | break; |
858c9f6c JS |
541 | case LPFC_EVT_DEV_LOSS: |
542 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); | |
a93ff37a | 543 | fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp); |
858c9f6c | 544 | free_evt = 0; |
fa4066b6 JS |
545 | /* decrement the node reference count held for |
546 | * this queued work | |
547 | */ | |
a93ff37a | 548 | nlp_did = ndlp->nlp_DID; |
858c9f6c | 549 | lpfc_nlp_put(ndlp); |
a93ff37a JS |
550 | if (phba->sli_rev == LPFC_SLI_REV4) |
551 | lpfc_sli4_post_dev_loss_tmo_handler(phba, | |
552 | fcf_inuse, | |
553 | nlp_did); | |
858c9f6c | 554 | break; |
dea3101e | 555 | case LPFC_EVT_ONLINE: |
2e0fef85 JS |
556 | if (phba->link_state < LPFC_LINK_DOWN) |
557 | *(int *) (evtp->evt_arg1) = lpfc_online(phba); | |
41415862 | 558 | else |
2e0fef85 | 559 | *(int *) (evtp->evt_arg1) = 0; |
dea3101e | 560 | complete((struct completion *)(evtp->evt_arg2)); |
561 | break; | |
46fa311e | 562 | case LPFC_EVT_OFFLINE_PREP: |
2e0fef85 | 563 | if (phba->link_state >= LPFC_LINK_DOWN) |
618a5230 | 564 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
46fa311e JS |
565 | *(int *)(evtp->evt_arg1) = 0; |
566 | complete((struct completion *)(evtp->evt_arg2)); | |
567 | break; | |
568 | case LPFC_EVT_OFFLINE: | |
569 | lpfc_offline(phba); | |
41415862 JW |
570 | lpfc_sli_brdrestart(phba); |
571 | *(int *)(evtp->evt_arg1) = | |
46fa311e JS |
572 | lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY); |
573 | lpfc_unblock_mgmt_io(phba); | |
41415862 JW |
574 | complete((struct completion *)(evtp->evt_arg2)); |
575 | break; | |
576 | case LPFC_EVT_WARM_START: | |
46fa311e | 577 | lpfc_offline(phba); |
9290831f | 578 | lpfc_reset_barrier(phba); |
41415862 JW |
579 | lpfc_sli_brdreset(phba); |
580 | lpfc_hba_down_post(phba); | |
581 | *(int *)(evtp->evt_arg1) = | |
582 | lpfc_sli_brdready(phba, HS_MBRDY); | |
46fa311e | 583 | lpfc_unblock_mgmt_io(phba); |
41415862 JW |
584 | complete((struct completion *)(evtp->evt_arg2)); |
585 | break; | |
586 | case LPFC_EVT_KILL: | |
46fa311e | 587 | lpfc_offline(phba); |
9290831f | 588 | *(int *)(evtp->evt_arg1) |
2e0fef85 JS |
589 | = (phba->pport->stopped) |
590 | ? 0 : lpfc_sli_brdkill(phba); | |
46fa311e | 591 | lpfc_unblock_mgmt_io(phba); |
dea3101e | 592 | complete((struct completion *)(evtp->evt_arg2)); |
593 | break; | |
ea2151b4 JS |
594 | case LPFC_EVT_FASTPATH_MGMT_EVT: |
595 | lpfc_send_fastpath_evt(phba, evtp); | |
596 | free_evt = 0; | |
597 | break; | |
78730cfe JS |
598 | case LPFC_EVT_RESET_HBA: |
599 | if (!(phba->pport->load_flag & FC_UNLOADING)) | |
600 | lpfc_reset_hba(phba); | |
601 | break; | |
dea3101e | 602 | } |
603 | if (free_evt) | |
604 | kfree(evtp); | |
2e0fef85 | 605 | spin_lock_irq(&phba->hbalock); |
dea3101e | 606 | } |
2e0fef85 | 607 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 608 | |
609 | } | |
610 | ||
311464ec | 611 | static void |
2e0fef85 | 612 | lpfc_work_done(struct lpfc_hba *phba) |
dea3101e | 613 | { |
614 | struct lpfc_sli_ring *pring; | |
858c9f6c | 615 | uint32_t ha_copy, status, control, work_port_events; |
549e55cd | 616 | struct lpfc_vport **vports; |
51ef4c26 | 617 | struct lpfc_vport *vport; |
549e55cd | 618 | int i; |
dea3101e | 619 | |
2e0fef85 | 620 | spin_lock_irq(&phba->hbalock); |
dea3101e | 621 | ha_copy = phba->work_ha; |
622 | phba->work_ha = 0; | |
2e0fef85 | 623 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 624 | |
da0436e9 JS |
625 | /* First, try to post the next mailbox command to SLI4 device */ |
626 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) | |
627 | lpfc_sli4_post_async_mbox(phba); | |
628 | ||
2fe165b6 | 629 | if (ha_copy & HA_ERATT) |
9399627f | 630 | /* Handle the error attention event */ |
dea3101e | 631 | lpfc_handle_eratt(phba); |
632 | ||
2fe165b6 | 633 | if (ha_copy & HA_MBATT) |
dea3101e | 634 | lpfc_sli_handle_mb_event(phba); |
635 | ||
2fe165b6 | 636 | if (ha_copy & HA_LATT) |
dea3101e | 637 | lpfc_handle_latt(phba); |
9399627f | 638 | |
da0436e9 JS |
639 | /* Process SLI4 events */ |
640 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { | |
19ca7609 JS |
641 | if (phba->hba_flag & HBA_RRQ_ACTIVE) |
642 | lpfc_handle_rrq_active(phba); | |
da0436e9 JS |
643 | if (phba->hba_flag & ELS_XRI_ABORT_EVENT) |
644 | lpfc_sli4_els_xri_abort_event_proc(phba); | |
645 | if (phba->hba_flag & ASYNC_EVENT) | |
646 | lpfc_sli4_async_event_proc(phba); | |
647 | if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) { | |
648 | spin_lock_irq(&phba->hbalock); | |
649 | phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER; | |
650 | spin_unlock_irq(&phba->hbalock); | |
651 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
652 | } | |
ecfd03c6 JS |
653 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) |
654 | lpfc_sli4_fcf_redisc_event_proc(phba); | |
da0436e9 JS |
655 | } |
656 | ||
549e55cd JS |
657 | vports = lpfc_create_vport_work_array(phba); |
658 | if (vports != NULL) | |
da0436e9 | 659 | for (i = 0; i <= phba->max_vports; i++) { |
51ef4c26 JS |
660 | /* |
661 | * We could have no vports in array if unloading, so if | |
662 | * this happens then just use the pport | |
663 | */ | |
664 | if (vports[i] == NULL && i == 0) | |
665 | vport = phba->pport; | |
666 | else | |
667 | vport = vports[i]; | |
668 | if (vport == NULL) | |
669 | break; | |
58da1ffb | 670 | spin_lock_irq(&vport->work_port_lock); |
51ef4c26 | 671 | work_port_events = vport->work_port_events; |
58da1ffb JS |
672 | vport->work_port_events &= ~work_port_events; |
673 | spin_unlock_irq(&vport->work_port_lock); | |
549e55cd | 674 | if (work_port_events & WORKER_DISC_TMO) |
51ef4c26 | 675 | lpfc_disc_timeout_handler(vport); |
549e55cd | 676 | if (work_port_events & WORKER_ELS_TMO) |
51ef4c26 | 677 | lpfc_els_timeout_handler(vport); |
549e55cd JS |
678 | if (work_port_events & WORKER_HB_TMO) |
679 | lpfc_hb_timeout_handler(phba); | |
680 | if (work_port_events & WORKER_MBOX_TMO) | |
681 | lpfc_mbox_timeout_handler(phba); | |
682 | if (work_port_events & WORKER_FABRIC_BLOCK_TMO) | |
683 | lpfc_unblock_fabric_iocbs(phba); | |
549e55cd JS |
684 | if (work_port_events & WORKER_RAMP_DOWN_QUEUE) |
685 | lpfc_ramp_down_queue_handler(phba); | |
92494144 JS |
686 | if (work_port_events & WORKER_DELAYED_DISC_TMO) |
687 | lpfc_delayed_disc_timeout_handler(vport); | |
92d7f7b0 | 688 | } |
09372820 | 689 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 690 | |
895427bd | 691 | pring = lpfc_phba_elsring(phba); |
858c9f6c JS |
692 | status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
693 | status >>= (4*LPFC_ELS_RING); | |
0c9c6a75 JS |
694 | if (pring && (status & HA_RXMASK || |
695 | pring->flag & LPFC_DEFERRED_RING_EVENT || | |
696 | phba->hba_flag & HBA_SP_QUEUE_EVT)) { | |
0b727fea | 697 | if (pring->flag & LPFC_STOP_IOCB_EVENT) { |
858c9f6c | 698 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
161df4f0 JS |
699 | /* Preserve legacy behavior. */ |
700 | if (!(phba->hba_flag & HBA_SP_QUEUE_EVT)) | |
701 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
858c9f6c | 702 | } else { |
ae9e28f3 JS |
703 | if (phba->link_state >= LPFC_LINK_UP || |
704 | phba->link_flag & LS_MDS_LOOPBACK) { | |
94661504 JS |
705 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; |
706 | lpfc_sli_handle_slow_ring_event(phba, pring, | |
707 | (status & | |
708 | HA_RXMASK)); | |
709 | } | |
858c9f6c | 710 | } |
dc19e3b4 | 711 | if (phba->sli_rev == LPFC_SLI_REV4) |
2a9bf3d0 | 712 | lpfc_drain_txq(phba); |
858c9f6c JS |
713 | /* |
714 | * Turn on Ring interrupts | |
715 | */ | |
3772a991 JS |
716 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
717 | spin_lock_irq(&phba->hbalock); | |
718 | control = readl(phba->HCregaddr); | |
719 | if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) { | |
720 | lpfc_debugfs_slow_ring_trc(phba, | |
721 | "WRK Enable ring: cntl:x%x hacopy:x%x", | |
722 | control, ha_copy, 0); | |
723 | ||
724 | control |= (HC_R0INT_ENA << LPFC_ELS_RING); | |
725 | writel(control, phba->HCregaddr); | |
726 | readl(phba->HCregaddr); /* flush */ | |
727 | } else { | |
728 | lpfc_debugfs_slow_ring_trc(phba, | |
729 | "WRK Ring ok: cntl:x%x hacopy:x%x", | |
730 | control, ha_copy, 0); | |
731 | } | |
732 | spin_unlock_irq(&phba->hbalock); | |
a58cbd52 | 733 | } |
dea3101e | 734 | } |
2e0fef85 | 735 | lpfc_work_list_done(phba); |
dea3101e | 736 | } |
737 | ||
dea3101e | 738 | int |
739 | lpfc_do_work(void *p) | |
740 | { | |
741 | struct lpfc_hba *phba = p; | |
742 | int rc; | |
dea3101e | 743 | |
8698a745 | 744 | set_user_nice(current, MIN_NICE); |
043c956f | 745 | current->flags |= PF_NOFREEZE; |
5e9d9b82 | 746 | phba->data_flags = 0; |
dea3101e | 747 | |
3a55b532 | 748 | while (!kthread_should_stop()) { |
5e9d9b82 JS |
749 | /* wait and check worker queue activities */ |
750 | rc = wait_event_interruptible(phba->work_waitq, | |
751 | (test_and_clear_bit(LPFC_DATA_READY, | |
752 | &phba->data_flags) | |
753 | || kthread_should_stop())); | |
3a55b532 JS |
754 | /* Signal wakeup shall terminate the worker thread */ |
755 | if (rc) { | |
756 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
757 | "0433 Wakeup on signal: rc=x%x\n", rc); | |
dea3101e | 758 | break; |
3a55b532 | 759 | } |
dea3101e | 760 | |
5e9d9b82 | 761 | /* Attend pending lpfc data processing */ |
dea3101e | 762 | lpfc_work_done(phba); |
dea3101e | 763 | } |
3a55b532 JS |
764 | phba->worker_thread = NULL; |
765 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
766 | "0432 Worker thread stopped.\n"); | |
dea3101e | 767 | return 0; |
768 | } | |
769 | ||
770 | /* | |
771 | * This is only called to handle FC worker events. Since this a rare | |
25985edc | 772 | * occurrence, we allocate a struct lpfc_work_evt structure here instead of |
dea3101e | 773 | * embedding it in the IOCB. |
774 | */ | |
775 | int | |
2e0fef85 | 776 | lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2, |
dea3101e | 777 | uint32_t evt) |
778 | { | |
779 | struct lpfc_work_evt *evtp; | |
ed957684 | 780 | unsigned long flags; |
dea3101e | 781 | |
782 | /* | |
783 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will | |
784 | * be queued to worker thread for processing | |
785 | */ | |
92d7f7b0 | 786 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC); |
dea3101e | 787 | if (!evtp) |
788 | return 0; | |
789 | ||
790 | evtp->evt_arg1 = arg1; | |
791 | evtp->evt_arg2 = arg2; | |
792 | evtp->evt = evt; | |
793 | ||
ed957684 | 794 | spin_lock_irqsave(&phba->hbalock, flags); |
071fbd3d | 795 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
ed957684 | 796 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 797 | |
5e9d9b82 JS |
798 | lpfc_worker_wake_up(phba); |
799 | ||
dea3101e | 800 | return 1; |
801 | } | |
802 | ||
92d7f7b0 JS |
803 | void |
804 | lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove) | |
805 | { | |
09372820 | 806 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
92d7f7b0 JS |
807 | struct lpfc_hba *phba = vport->phba; |
808 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
92d7f7b0 JS |
809 | |
810 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
811 | if (!NLP_CHK_NODE_ACT(ndlp)) |
812 | continue; | |
92d7f7b0 JS |
813 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
814 | continue; | |
98c9ea5c JS |
815 | if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) || |
816 | ((vport->port_type == LPFC_NPIV_PORT) && | |
817 | (ndlp->nlp_DID == NameServer_DID))) | |
92d7f7b0 JS |
818 | lpfc_unreg_rpi(vport, ndlp); |
819 | ||
820 | /* Leave Fabric nodes alone on link down */ | |
4d9ab994 JS |
821 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
822 | (!remove && ndlp->nlp_type & NLP_FABRIC)) | |
92d7f7b0 | 823 | continue; |
db6f1c2f SH |
824 | lpfc_disc_state_machine(vport, ndlp, NULL, |
825 | remove | |
826 | ? NLP_EVT_DEVICE_RM | |
827 | : NLP_EVT_DEVICE_RECOVERY); | |
92d7f7b0 JS |
828 | } |
829 | if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) { | |
5af5eee7 JS |
830 | if (phba->sli_rev == LPFC_SLI_REV4) |
831 | lpfc_sli4_unreg_all_rpis(vport); | |
92d7f7b0 | 832 | lpfc_mbx_unreg_vpi(vport); |
09372820 | 833 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 834 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
09372820 | 835 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
836 | } |
837 | } | |
838 | ||
87af33fe | 839 | void |
98c9ea5c | 840 | lpfc_port_link_failure(struct lpfc_vport *vport) |
92d7f7b0 | 841 | { |
695a814e JS |
842 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
843 | ||
45ed1190 JS |
844 | /* Cleanup any outstanding received buffers */ |
845 | lpfc_cleanup_rcv_buffers(vport); | |
846 | ||
92d7f7b0 JS |
847 | /* Cleanup any outstanding RSCN activity */ |
848 | lpfc_els_flush_rscn(vport); | |
849 | ||
850 | /* Cleanup any outstanding ELS commands */ | |
851 | lpfc_els_flush_cmd(vport); | |
852 | ||
853 | lpfc_cleanup_rpis(vport, 0); | |
854 | ||
92d7f7b0 JS |
855 | /* Turn off discovery timer if its running */ |
856 | lpfc_can_disctmo(vport); | |
857 | } | |
858 | ||
3772a991 | 859 | void |
98c9ea5c JS |
860 | lpfc_linkdown_port(struct lpfc_vport *vport) |
861 | { | |
862 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
863 | ||
f6e84790 | 864 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
a0f2d3ef JS |
865 | fc_host_post_event(shost, fc_get_event_number(), |
866 | FCH_EVT_LINKDOWN, 0); | |
98c9ea5c JS |
867 | |
868 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
869 | "Link Down: state:x%x rtry:x%x flg:x%x", | |
870 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); | |
871 | ||
872 | lpfc_port_link_failure(vport); | |
873 | ||
92494144 JS |
874 | /* Stop delayed Nport discovery */ |
875 | spin_lock_irq(shost->host_lock); | |
876 | vport->fc_flag &= ~FC_DISC_DELAYED; | |
877 | spin_unlock_irq(shost->host_lock); | |
878 | del_timer_sync(&vport->delayed_disc_tmo); | |
98c9ea5c JS |
879 | } |
880 | ||
dea3101e | 881 | int |
685f0bf7 | 882 | lpfc_linkdown(struct lpfc_hba *phba) |
dea3101e | 883 | { |
2e0fef85 JS |
884 | struct lpfc_vport *vport = phba->pport; |
885 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
549e55cd | 886 | struct lpfc_vport **vports; |
685f0bf7 | 887 | LPFC_MBOXQ_t *mb; |
549e55cd | 888 | int i; |
dea3101e | 889 | |
19193ff3 | 890 | if (phba->link_state == LPFC_LINK_DOWN) |
2e0fef85 | 891 | return 0; |
19193ff3 | 892 | |
aacc20e3 JS |
893 | /* Block all SCSI stack I/Os */ |
894 | lpfc_scsi_dev_block(phba); | |
895 | ||
0a9e9687 JS |
896 | phba->defer_flogi_acc_flag = false; |
897 | ||
2e0fef85 | 898 | spin_lock_irq(&phba->hbalock); |
ecfd03c6 | 899 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
72100cc4 | 900 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 901 | if (phba->link_state > LPFC_LINK_DOWN) { |
2e0fef85 | 902 | phba->link_state = LPFC_LINK_DOWN; |
2977a095 JS |
903 | if (phba->sli4_hba.conf_trunk) { |
904 | phba->trunk_link.link0.state = 0; | |
905 | phba->trunk_link.link1.state = 0; | |
906 | phba->trunk_link.link2.state = 0; | |
907 | phba->trunk_link.link3.state = 0; | |
845d0327 JS |
908 | phba->sli4_hba.link_state.logical_speed = |
909 | LPFC_LINK_SPEED_UNKNOWN; | |
2977a095 | 910 | } |
72100cc4 | 911 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 912 | phba->pport->fc_flag &= ~FC_LBIT; |
72100cc4 | 913 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 | 914 | } |
549e55cd | 915 | vports = lpfc_create_vport_work_array(phba); |
895427bd | 916 | if (vports != NULL) { |
6fb120a7 | 917 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
918 | /* Issue a LINK DOWN event to all nodes */ |
919 | lpfc_linkdown_port(vports[i]); | |
895427bd JS |
920 | |
921 | vports[i]->fc_myDID = 0; | |
922 | ||
f6e84790 JS |
923 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
924 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { | |
d613b6a7 JS |
925 | if (phba->nvmet_support) |
926 | lpfc_nvmet_update_targetport(phba); | |
927 | else | |
8c258641 | 928 | lpfc_nvme_update_localport(vports[i]); |
8c258641 | 929 | } |
549e55cd | 930 | } |
895427bd | 931 | } |
09372820 | 932 | lpfc_destroy_vport_work_array(phba, vports); |
c95a3b4b JS |
933 | |
934 | /* Clean up any SLI3 firmware default rpi's */ | |
935 | if (phba->sli_rev > LPFC_SLI_REV3) | |
936 | goto skip_unreg_did; | |
937 | ||
2e0fef85 JS |
938 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
939 | if (mb) { | |
6d368e53 | 940 | lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb); |
ed957684 | 941 | mb->vport = vport; |
2e0fef85 | 942 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
0b727fea | 943 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
dea3101e | 944 | == MBX_NOT_FINISHED) { |
2e0fef85 | 945 | mempool_free(mb, phba->mbox_mem_pool); |
dea3101e | 946 | } |
947 | } | |
948 | ||
c95a3b4b | 949 | skip_unreg_did: |
dea3101e | 950 | /* Setup myDID for link up if we are in pt2pt mode */ |
92d7f7b0 | 951 | if (phba->pport->fc_flag & FC_PT2PT) { |
2e0fef85 JS |
952 | mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
953 | if (mb) { | |
dea3101e | 954 | lpfc_config_link(phba, mb); |
92d7f7b0 | 955 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
ed957684 | 956 | mb->vport = vport; |
0b727fea | 957 | if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT) |
dea3101e | 958 | == MBX_NOT_FINISHED) { |
2e0fef85 | 959 | mempool_free(mb, phba->mbox_mem_pool); |
dea3101e | 960 | } |
961 | } | |
2e0fef85 | 962 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 963 | phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); |
d496b9a7 | 964 | phba->pport->rcv_flogi_cnt = 0; |
2e0fef85 | 965 | spin_unlock_irq(shost->host_lock); |
dea3101e | 966 | } |
92d7f7b0 JS |
967 | return 0; |
968 | } | |
dea3101e | 969 | |
92d7f7b0 JS |
970 | static void |
971 | lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport) | |
972 | { | |
973 | struct lpfc_nodelist *ndlp; | |
dea3101e | 974 | |
92d7f7b0 | 975 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
a3da825b | 976 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
e47c9093 JS |
977 | if (!NLP_CHK_NODE_ACT(ndlp)) |
978 | continue; | |
92d7f7b0 JS |
979 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
980 | continue; | |
92d7f7b0 | 981 | if (ndlp->nlp_type & NLP_FABRIC) { |
e47c9093 JS |
982 | /* On Linkup its safe to clean up the ndlp |
983 | * from Fabric connections. | |
984 | */ | |
92d7f7b0 JS |
985 | if (ndlp->nlp_DID != Fabric_DID) |
986 | lpfc_unreg_rpi(vport, ndlp); | |
987 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
988 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { | |
e47c9093 JS |
989 | /* Fail outstanding IO now since device is |
990 | * marked for PLOGI. | |
991 | */ | |
92d7f7b0 JS |
992 | lpfc_unreg_rpi(vport, ndlp); |
993 | } | |
994 | } | |
dea3101e | 995 | } |
996 | ||
92d7f7b0 JS |
997 | static void |
998 | lpfc_linkup_port(struct lpfc_vport *vport) | |
dea3101e | 999 | { |
92d7f7b0 | 1000 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
92d7f7b0 JS |
1001 | struct lpfc_hba *phba = vport->phba; |
1002 | ||
1003 | if ((vport->load_flag & FC_UNLOADING) != 0) | |
1004 | return; | |
1005 | ||
858c9f6c JS |
1006 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
1007 | "Link Up: top:x%x speed:x%x flg:x%x", | |
1008 | phba->fc_topology, phba->fc_linkspeed, phba->link_flag); | |
1009 | ||
92d7f7b0 JS |
1010 | /* If NPIV is not enabled, only bring the physical port up */ |
1011 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && | |
1012 | (vport != phba->pport)) | |
1013 | return; | |
dea3101e | 1014 | |
f6e84790 | 1015 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
a0f2d3ef JS |
1016 | fc_host_post_event(shost, fc_get_event_number(), |
1017 | FCH_EVT_LINKUP, 0); | |
d2873e4c | 1018 | |
2e0fef85 | 1019 | spin_lock_irq(shost->host_lock); |
2e0fef85 JS |
1020 | vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | |
1021 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); | |
1022 | vport->fc_flag |= FC_NDISC_ACTIVE; | |
1023 | vport->fc_ns_retry = 0; | |
1024 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 1025 | |
92d7f7b0 JS |
1026 | if (vport->fc_flag & FC_LBIT) |
1027 | lpfc_linkup_cleanup_nodes(vport); | |
dea3101e | 1028 | |
92d7f7b0 JS |
1029 | } |
1030 | ||
1031 | static int | |
1032 | lpfc_linkup(struct lpfc_hba *phba) | |
1033 | { | |
549e55cd JS |
1034 | struct lpfc_vport **vports; |
1035 | int i; | |
d496b9a7 | 1036 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
92d7f7b0 JS |
1037 | |
1038 | phba->link_state = LPFC_LINK_UP; | |
1039 | ||
1040 | /* Unblock fabric iocbs if they are blocked */ | |
1041 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); | |
1042 | del_timer_sync(&phba->fabric_block_timer); | |
1043 | ||
549e55cd JS |
1044 | vports = lpfc_create_vport_work_array(phba); |
1045 | if (vports != NULL) | |
6fb120a7 | 1046 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
549e55cd | 1047 | lpfc_linkup_port(vports[i]); |
09372820 | 1048 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 1049 | |
d496b9a7 JS |
1050 | /* Clear the pport flogi counter in case the link down was |
1051 | * absorbed without an ACQE. No lock here - in worker thread | |
1052 | * and discovery is synchronized. | |
1053 | */ | |
1054 | spin_lock_irq(shost->host_lock); | |
1055 | phba->pport->rcv_flogi_cnt = 0; | |
1056 | spin_unlock_irq(shost->host_lock); | |
0a9e9687 JS |
1057 | |
1058 | /* reinitialize initial FLOGI flag */ | |
1059 | phba->hba_flag &= ~(HBA_FLOGI_ISSUED); | |
1060 | phba->defer_flogi_acc_flag = false; | |
1061 | ||
dea3101e | 1062 | return 0; |
1063 | } | |
1064 | ||
1065 | /* | |
1066 | * This routine handles processing a CLEAR_LA mailbox | |
1067 | * command upon completion. It is setup in the LPFC_MBOXQ | |
1068 | * as the completion routine when the command is | |
895427bd | 1069 | * handed off to the SLI layer. SLI3 only. |
dea3101e | 1070 | */ |
a6ababd2 | 1071 | static void |
2e0fef85 | 1072 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 1073 | { |
2e0fef85 JS |
1074 | struct lpfc_vport *vport = pmb->vport; |
1075 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
1076 | struct lpfc_sli *psli = &phba->sli; | |
04c68496 | 1077 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 1078 | uint32_t control; |
1079 | ||
dea3101e | 1080 | /* Since we don't do discovery right now, turn these off here */ |
895427bd JS |
1081 | psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
1082 | psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT; | |
dea3101e | 1083 | |
1084 | /* Check for error */ | |
1085 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { | |
92d7f7b0 | 1086 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ |
e8b62011 JS |
1087 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
1088 | "0320 CLEAR_LA mbxStatus error x%x hba " | |
1089 | "state x%x\n", | |
1090 | mb->mbxStatus, vport->port_state); | |
2e0fef85 | 1091 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1092 | goto out; |
1093 | } | |
1094 | ||
92d7f7b0 JS |
1095 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
1096 | phba->link_state = LPFC_HBA_READY; | |
1097 | ||
1098 | spin_lock_irq(&phba->hbalock); | |
1099 | psli->sli_flag |= LPFC_PROCESS_LA; | |
1100 | control = readl(phba->HCregaddr); | |
1101 | control |= HC_LAINT_ENA; | |
1102 | writel(control, phba->HCregaddr); | |
1103 | readl(phba->HCregaddr); /* flush */ | |
1104 | spin_unlock_irq(&phba->hbalock); | |
1b32f6aa | 1105 | mempool_free(pmb, phba->mbox_mem_pool); |
92d7f7b0 | 1106 | return; |
dea3101e | 1107 | |
dea3101e | 1108 | out: |
1109 | /* Device Discovery completes */ | |
e8b62011 JS |
1110 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1111 | "0225 Device Discovery completes\n"); | |
2e0fef85 | 1112 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 1113 | |
2e0fef85 | 1114 | spin_lock_irq(shost->host_lock); |
58da1ffb | 1115 | vport->fc_flag &= ~FC_ABORT_DISCOVERY; |
2e0fef85 | 1116 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1117 | |
2e0fef85 | 1118 | lpfc_can_disctmo(vport); |
dea3101e | 1119 | |
1120 | /* turn on Link Attention interrupts */ | |
2e0fef85 JS |
1121 | |
1122 | spin_lock_irq(&phba->hbalock); | |
dea3101e | 1123 | psli->sli_flag |= LPFC_PROCESS_LA; |
1124 | control = readl(phba->HCregaddr); | |
1125 | control |= HC_LAINT_ENA; | |
1126 | writel(control, phba->HCregaddr); | |
1127 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 1128 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1129 | |
1130 | return; | |
1131 | } | |
1132 | ||
2e0fef85 | 1133 | |
d6de08cc | 1134 | void |
25594c6b | 1135 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 1136 | { |
2e0fef85 | 1137 | struct lpfc_vport *vport = pmb->vport; |
44fd7fe3 | 1138 | uint8_t bbscn = 0; |
dea3101e | 1139 | |
04c68496 | 1140 | if (pmb->u.mb.mbxStatus) |
dea3101e | 1141 | goto out; |
dea3101e | 1142 | |
25594c6b JW |
1143 | mempool_free(pmb, phba->mbox_mem_pool); |
1144 | ||
1b51197d JS |
1145 | /* don't perform discovery for SLI4 loopback diagnostic test */ |
1146 | if ((phba->sli_rev == LPFC_SLI_REV4) && | |
1147 | !(phba->hba_flag & HBA_FCOE_MODE) && | |
1148 | (phba->link_flag & LS_LOOPBACK_MODE)) | |
1149 | return; | |
1150 | ||
76a95d75 | 1151 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && |
2e0fef85 JS |
1152 | vport->fc_flag & FC_PUBLIC_LOOP && |
1153 | !(vport->fc_flag & FC_LBIT)) { | |
25594c6b | 1154 | /* Need to wait for FAN - use discovery timer |
2e0fef85 | 1155 | * for timeout. port_state is identically |
25594c6b JW |
1156 | * LPFC_LOCAL_CFG_LINK while waiting for FAN |
1157 | */ | |
2e0fef85 | 1158 | lpfc_set_disctmo(vport); |
25594c6b | 1159 | return; |
92d7f7b0 | 1160 | } |
dea3101e | 1161 | |
2e0fef85 | 1162 | /* Start discovery by sending a FLOGI. port_state is identically |
25594c6b JW |
1163 | * LPFC_FLOGI while waiting for FLOGI cmpl |
1164 | */ | |
44fd7fe3 JS |
1165 | if (vport->port_state != LPFC_FLOGI) { |
1166 | if (phba->bbcredit_support && phba->cfg_enable_bbcr) { | |
1167 | bbscn = bf_get(lpfc_bbscn_def, | |
1168 | &phba->sli4_hba.bbscn_params); | |
1169 | vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; | |
1170 | vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4); | |
1171 | } | |
92d7f7b0 | 1172 | lpfc_initial_flogi(vport); |
44fd7fe3 | 1173 | } else if (vport->fc_flag & FC_PT2PT) { |
d6de08cc | 1174 | lpfc_disc_start(vport); |
44fd7fe3 | 1175 | } |
25594c6b | 1176 | return; |
dea3101e | 1177 | |
1178 | out: | |
e8b62011 JS |
1179 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
1180 | "0306 CONFIG_LINK mbxStatus error x%x " | |
1181 | "HBA state x%x\n", | |
04c68496 | 1182 | pmb->u.mb.mbxStatus, vport->port_state); |
92d7f7b0 | 1183 | mempool_free(pmb, phba->mbox_mem_pool); |
25594c6b | 1184 | |
92d7f7b0 | 1185 | lpfc_linkdown(phba); |
25594c6b | 1186 | |
e8b62011 JS |
1187 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1188 | "0200 CONFIG_LINK bad hba state x%x\n", | |
1189 | vport->port_state); | |
dea3101e | 1190 | |
92d7f7b0 | 1191 | lpfc_issue_clear_la(phba, vport); |
dea3101e | 1192 | return; |
1193 | } | |
1194 | ||
7d791df7 JS |
1195 | /** |
1196 | * lpfc_sli4_clear_fcf_rr_bmask | |
1197 | * @phba pointer to the struct lpfc_hba for this port. | |
1198 | * This fucnction resets the round robin bit mask and clears the | |
1199 | * fcf priority list. The list deletions are done while holding the | |
1200 | * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared | |
1201 | * from the lpfc_fcf_pri record. | |
1202 | **/ | |
1203 | void | |
1204 | lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba) | |
1205 | { | |
1206 | struct lpfc_fcf_pri *fcf_pri; | |
1207 | struct lpfc_fcf_pri *next_fcf_pri; | |
1208 | memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask)); | |
1209 | spin_lock_irq(&phba->hbalock); | |
1210 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, | |
1211 | &phba->fcf.fcf_pri_list, list) { | |
1212 | list_del_init(&fcf_pri->list); | |
1213 | fcf_pri->fcf_rec.flag = 0; | |
1214 | } | |
1215 | spin_unlock_irq(&phba->hbalock); | |
1216 | } | |
6fb120a7 JS |
1217 | static void |
1218 | lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
1219 | { | |
1220 | struct lpfc_vport *vport = mboxq->vport; | |
6fb120a7 JS |
1221 | |
1222 | if (mboxq->u.mb.mbxStatus) { | |
1223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, | |
1224 | "2017 REG_FCFI mbxStatus error x%x " | |
1225 | "HBA state x%x\n", | |
1226 | mboxq->u.mb.mbxStatus, vport->port_state); | |
a93ff37a | 1227 | goto fail_out; |
6fb120a7 JS |
1228 | } |
1229 | ||
1230 | /* Start FCoE discovery by sending a FLOGI. */ | |
1231 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi); | |
1232 | /* Set the FCFI registered flag */ | |
d439d286 | 1233 | spin_lock_irq(&phba->hbalock); |
6fb120a7 | 1234 | phba->fcf.fcf_flag |= FCF_REGISTERED; |
d439d286 | 1235 | spin_unlock_irq(&phba->hbalock); |
a93ff37a | 1236 | |
32b9793f | 1237 | /* If there is a pending FCoE event, restart FCF table scan. */ |
7d791df7 JS |
1238 | if ((!(phba->hba_flag & FCF_RR_INPROG)) && |
1239 | lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF)) | |
a93ff37a JS |
1240 | goto fail_out; |
1241 | ||
1242 | /* Mark successful completion of FCF table scan */ | |
d439d286 | 1243 | spin_lock_irq(&phba->hbalock); |
ecfd03c6 | 1244 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
a93ff37a JS |
1245 | phba->hba_flag &= ~FCF_TS_INPROG; |
1246 | if (vport->port_state != LPFC_FLOGI) { | |
1247 | phba->hba_flag |= FCF_RR_INPROG; | |
1248 | spin_unlock_irq(&phba->hbalock); | |
76a95d75 | 1249 | lpfc_issue_init_vfi(vport); |
a93ff37a JS |
1250 | goto out; |
1251 | } | |
1252 | spin_unlock_irq(&phba->hbalock); | |
1253 | goto out; | |
6fb120a7 | 1254 | |
a93ff37a JS |
1255 | fail_out: |
1256 | spin_lock_irq(&phba->hbalock); | |
1257 | phba->hba_flag &= ~FCF_RR_INPROG; | |
1258 | spin_unlock_irq(&phba->hbalock); | |
1259 | out: | |
6fb120a7 | 1260 | mempool_free(mboxq, phba->mbox_mem_pool); |
6fb120a7 JS |
1261 | } |
1262 | ||
1263 | /** | |
1264 | * lpfc_fab_name_match - Check if the fcf fabric name match. | |
1265 | * @fab_name: pointer to fabric name. | |
1266 | * @new_fcf_record: pointer to fcf record. | |
1267 | * | |
1268 | * This routine compare the fcf record's fabric name with provided | |
1269 | * fabric name. If the fabric name are identical this function | |
1270 | * returns 1 else return 0. | |
1271 | **/ | |
1272 | static uint32_t | |
1273 | lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) | |
1274 | { | |
ecfd03c6 JS |
1275 | if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) |
1276 | return 0; | |
1277 | if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) | |
1278 | return 0; | |
1279 | if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) | |
1280 | return 0; | |
1281 | if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) | |
1282 | return 0; | |
1283 | if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) | |
1284 | return 0; | |
1285 | if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) | |
6fb120a7 | 1286 | return 0; |
ecfd03c6 JS |
1287 | if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) |
1288 | return 0; | |
1289 | if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)) | |
1290 | return 0; | |
1291 | return 1; | |
6fb120a7 JS |
1292 | } |
1293 | ||
8fa38513 JS |
1294 | /** |
1295 | * lpfc_sw_name_match - Check if the fcf switch name match. | |
1296 | * @fab_name: pointer to fabric name. | |
1297 | * @new_fcf_record: pointer to fcf record. | |
1298 | * | |
1299 | * This routine compare the fcf record's switch name with provided | |
1300 | * switch name. If the switch name are identical this function | |
1301 | * returns 1 else return 0. | |
1302 | **/ | |
1303 | static uint32_t | |
1304 | lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) | |
1305 | { | |
ecfd03c6 JS |
1306 | if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) |
1307 | return 0; | |
1308 | if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) | |
1309 | return 0; | |
1310 | if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) | |
8fa38513 | 1311 | return 0; |
ecfd03c6 JS |
1312 | if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) |
1313 | return 0; | |
1314 | if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) | |
1315 | return 0; | |
1316 | if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) | |
1317 | return 0; | |
1318 | if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) | |
1319 | return 0; | |
1320 | if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)) | |
1321 | return 0; | |
1322 | return 1; | |
8fa38513 JS |
1323 | } |
1324 | ||
6fb120a7 JS |
1325 | /** |
1326 | * lpfc_mac_addr_match - Check if the fcf mac address match. | |
ecfd03c6 | 1327 | * @mac_addr: pointer to mac address. |
6fb120a7 JS |
1328 | * @new_fcf_record: pointer to fcf record. |
1329 | * | |
1330 | * This routine compare the fcf record's mac address with HBA's | |
1331 | * FCF mac address. If the mac addresses are identical this function | |
1332 | * returns 1 else return 0. | |
1333 | **/ | |
1334 | static uint32_t | |
ecfd03c6 | 1335 | lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record) |
6fb120a7 | 1336 | { |
ecfd03c6 JS |
1337 | if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) |
1338 | return 0; | |
1339 | if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) | |
1340 | return 0; | |
1341 | if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) | |
1342 | return 0; | |
1343 | if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) | |
1344 | return 0; | |
1345 | if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) | |
1346 | return 0; | |
1347 | if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record)) | |
6fb120a7 | 1348 | return 0; |
ecfd03c6 JS |
1349 | return 1; |
1350 | } | |
1351 | ||
1352 | static bool | |
1353 | lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id) | |
1354 | { | |
1355 | return (curr_vlan_id == new_vlan_id); | |
6fb120a7 JS |
1356 | } |
1357 | ||
7d791df7 JS |
1358 | /** |
1359 | * lpfc_update_fcf_record - Update driver fcf record | |
1360 | * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record. | |
1361 | * @phba: pointer to lpfc hba data structure. | |
1362 | * @fcf_index: Index for the lpfc_fcf_record. | |
1363 | * @new_fcf_record: pointer to hba fcf record. | |
1364 | * | |
1365 | * This routine updates the driver FCF priority record from the new HBA FCF | |
1366 | * record. This routine is called with the host lock held. | |
1367 | **/ | |
1368 | static void | |
1369 | __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index, | |
1370 | struct fcf_record *new_fcf_record | |
1371 | ) | |
1372 | { | |
1373 | struct lpfc_fcf_pri *fcf_pri; | |
1374 | ||
1c2ba475 JT |
1375 | lockdep_assert_held(&phba->hbalock); |
1376 | ||
7d791df7 JS |
1377 | fcf_pri = &phba->fcf.fcf_pri[fcf_index]; |
1378 | fcf_pri->fcf_rec.fcf_index = fcf_index; | |
1379 | /* FCF record priority */ | |
1380 | fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; | |
1381 | ||
1382 | } | |
1383 | ||
6fb120a7 JS |
1384 | /** |
1385 | * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. | |
ecfd03c6 | 1386 | * @fcf: pointer to driver fcf record. |
6fb120a7 JS |
1387 | * @new_fcf_record: pointer to fcf record. |
1388 | * | |
1389 | * This routine copies the FCF information from the FCF | |
1390 | * record to lpfc_hba data structure. | |
1391 | **/ | |
1392 | static void | |
ecfd03c6 JS |
1393 | lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec, |
1394 | struct fcf_record *new_fcf_record) | |
6fb120a7 | 1395 | { |
ecfd03c6 JS |
1396 | /* Fabric name */ |
1397 | fcf_rec->fabric_name[0] = | |
6fb120a7 | 1398 | bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); |
ecfd03c6 | 1399 | fcf_rec->fabric_name[1] = |
6fb120a7 | 1400 | bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); |
ecfd03c6 | 1401 | fcf_rec->fabric_name[2] = |
6fb120a7 | 1402 | bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); |
ecfd03c6 | 1403 | fcf_rec->fabric_name[3] = |
6fb120a7 | 1404 | bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); |
ecfd03c6 | 1405 | fcf_rec->fabric_name[4] = |
6fb120a7 | 1406 | bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); |
ecfd03c6 | 1407 | fcf_rec->fabric_name[5] = |
6fb120a7 | 1408 | bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); |
ecfd03c6 | 1409 | fcf_rec->fabric_name[6] = |
6fb120a7 | 1410 | bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); |
ecfd03c6 | 1411 | fcf_rec->fabric_name[7] = |
6fb120a7 | 1412 | bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); |
ecfd03c6 JS |
1413 | /* Mac address */ |
1414 | fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record); | |
1415 | fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record); | |
1416 | fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record); | |
1417 | fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record); | |
1418 | fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record); | |
1419 | fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record); | |
1420 | /* FCF record index */ | |
1421 | fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); | |
1422 | /* FCF record priority */ | |
1423 | fcf_rec->priority = new_fcf_record->fip_priority; | |
1424 | /* Switch name */ | |
1425 | fcf_rec->switch_name[0] = | |
8fa38513 | 1426 | bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); |
ecfd03c6 | 1427 | fcf_rec->switch_name[1] = |
8fa38513 | 1428 | bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); |
ecfd03c6 | 1429 | fcf_rec->switch_name[2] = |
8fa38513 | 1430 | bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); |
ecfd03c6 | 1431 | fcf_rec->switch_name[3] = |
8fa38513 | 1432 | bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); |
ecfd03c6 | 1433 | fcf_rec->switch_name[4] = |
8fa38513 | 1434 | bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); |
ecfd03c6 | 1435 | fcf_rec->switch_name[5] = |
8fa38513 | 1436 | bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); |
ecfd03c6 | 1437 | fcf_rec->switch_name[6] = |
8fa38513 | 1438 | bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); |
ecfd03c6 | 1439 | fcf_rec->switch_name[7] = |
8fa38513 | 1440 | bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); |
6fb120a7 JS |
1441 | } |
1442 | ||
ecfd03c6 JS |
1443 | /** |
1444 | * lpfc_update_fcf_record - Update driver fcf record | |
1445 | * @phba: pointer to lpfc hba data structure. | |
1446 | * @fcf_rec: pointer to driver fcf record. | |
1447 | * @new_fcf_record: pointer to hba fcf record. | |
1448 | * @addr_mode: address mode to be set to the driver fcf record. | |
1449 | * @vlan_id: vlan tag to be set to the driver fcf record. | |
1450 | * @flag: flag bits to be set to the driver fcf record. | |
1451 | * | |
1452 | * This routine updates the driver FCF record from the new HBA FCF record | |
1453 | * together with the address mode, vlan_id, and other informations. This | |
1454 | * routine is called with the host lock held. | |
1455 | **/ | |
1456 | static void | |
1457 | __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec, | |
1458 | struct fcf_record *new_fcf_record, uint32_t addr_mode, | |
1459 | uint16_t vlan_id, uint32_t flag) | |
1460 | { | |
1c2ba475 JT |
1461 | lockdep_assert_held(&phba->hbalock); |
1462 | ||
ecfd03c6 JS |
1463 | /* Copy the fields from the HBA's FCF record */ |
1464 | lpfc_copy_fcf_record(fcf_rec, new_fcf_record); | |
1465 | /* Update other fields of driver FCF record */ | |
1466 | fcf_rec->addr_mode = addr_mode; | |
1467 | fcf_rec->vlan_id = vlan_id; | |
1468 | fcf_rec->flag |= (flag | RECORD_VALID); | |
7d791df7 JS |
1469 | __lpfc_update_fcf_record_pri(phba, |
1470 | bf_get(lpfc_fcf_record_fcf_index, new_fcf_record), | |
1471 | new_fcf_record); | |
ecfd03c6 JS |
1472 | } |
1473 | ||
6fb120a7 JS |
1474 | /** |
1475 | * lpfc_register_fcf - Register the FCF with hba. | |
1476 | * @phba: pointer to lpfc hba data structure. | |
1477 | * | |
1478 | * This routine issues a register fcfi mailbox command to register | |
1479 | * the fcf with HBA. | |
1480 | **/ | |
1481 | static void | |
1482 | lpfc_register_fcf(struct lpfc_hba *phba) | |
1483 | { | |
1484 | LPFC_MBOXQ_t *fcf_mbxq; | |
1485 | int rc; | |
6fb120a7 | 1486 | |
d439d286 | 1487 | spin_lock_irq(&phba->hbalock); |
25985edc | 1488 | /* If the FCF is not available do nothing. */ |
6fb120a7 | 1489 | if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) { |
a93ff37a | 1490 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
d439d286 | 1491 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 JS |
1492 | return; |
1493 | } | |
1494 | ||
1495 | /* The FCF is already registered, start discovery */ | |
1496 | if (phba->fcf.fcf_flag & FCF_REGISTERED) { | |
ecfd03c6 | 1497 | phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE); |
a93ff37a | 1498 | phba->hba_flag &= ~FCF_TS_INPROG; |
e74c03c8 JS |
1499 | if (phba->pport->port_state != LPFC_FLOGI && |
1500 | phba->pport->fc_flag & FC_FABRIC) { | |
a93ff37a JS |
1501 | phba->hba_flag |= FCF_RR_INPROG; |
1502 | spin_unlock_irq(&phba->hbalock); | |
bf08611b | 1503 | lpfc_initial_flogi(phba->pport); |
a93ff37a JS |
1504 | return; |
1505 | } | |
1506 | spin_unlock_irq(&phba->hbalock); | |
6fb120a7 JS |
1507 | return; |
1508 | } | |
d439d286 | 1509 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 | 1510 | |
a93ff37a | 1511 | fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4d9ab994 | 1512 | if (!fcf_mbxq) { |
d439d286 | 1513 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 1514 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
d439d286 | 1515 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 | 1516 | return; |
4d9ab994 | 1517 | } |
6fb120a7 JS |
1518 | |
1519 | lpfc_reg_fcfi(phba, fcf_mbxq); | |
1520 | fcf_mbxq->vport = phba->pport; | |
1521 | fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi; | |
1522 | rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT); | |
4d9ab994 | 1523 | if (rc == MBX_NOT_FINISHED) { |
d439d286 | 1524 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 1525 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
d439d286 | 1526 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 | 1527 | mempool_free(fcf_mbxq, phba->mbox_mem_pool); |
4d9ab994 | 1528 | } |
6fb120a7 JS |
1529 | |
1530 | return; | |
1531 | } | |
1532 | ||
1533 | /** | |
1534 | * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery. | |
1535 | * @phba: pointer to lpfc hba data structure. | |
1536 | * @new_fcf_record: pointer to fcf record. | |
1537 | * @boot_flag: Indicates if this record used by boot bios. | |
1538 | * @addr_mode: The address mode to be used by this FCF | |
ecfd03c6 | 1539 | * @vlan_id: The vlan id to be used as vlan tagging by this FCF. |
6fb120a7 JS |
1540 | * |
1541 | * This routine compare the fcf record with connect list obtained from the | |
1542 | * config region to decide if this FCF can be used for SAN discovery. It returns | |
1543 | * 1 if this record can be used for SAN discovery else return zero. If this FCF | |
1544 | * record can be used for SAN discovery, the boot_flag will indicate if this FCF | |
1545 | * is used by boot bios and addr_mode will indicate the addressing mode to be | |
1546 | * used for this FCF when the function returns. | |
1547 | * If the FCF record need to be used with a particular vlan id, the vlan is | |
1548 | * set in the vlan_id on return of the function. If not VLAN tagging need to | |
dbb6b3ab | 1549 | * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID; |
6fb120a7 JS |
1550 | **/ |
1551 | static int | |
1552 | lpfc_match_fcf_conn_list(struct lpfc_hba *phba, | |
1553 | struct fcf_record *new_fcf_record, | |
1554 | uint32_t *boot_flag, uint32_t *addr_mode, | |
1555 | uint16_t *vlan_id) | |
1556 | { | |
1557 | struct lpfc_fcf_conn_entry *conn_entry; | |
4d9ab994 JS |
1558 | int i, j, fcf_vlan_id = 0; |
1559 | ||
1560 | /* Find the lowest VLAN id in the FCF record */ | |
1561 | for (i = 0; i < 512; i++) { | |
1562 | if (new_fcf_record->vlan_bitmap[i]) { | |
1563 | fcf_vlan_id = i * 8; | |
1564 | j = 0; | |
1565 | while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) { | |
1566 | j++; | |
1567 | fcf_vlan_id++; | |
1568 | } | |
1569 | break; | |
1570 | } | |
1571 | } | |
6fb120a7 | 1572 | |
26979ced | 1573 | /* FCF not valid/available or solicitation in progress */ |
0c287589 | 1574 | if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) || |
26979ced JS |
1575 | !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) || |
1576 | bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record)) | |
0c287589 JS |
1577 | return 0; |
1578 | ||
45ed1190 | 1579 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
6fb120a7 JS |
1580 | *boot_flag = 0; |
1581 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, | |
1582 | new_fcf_record); | |
1583 | if (phba->valid_vlan) | |
1584 | *vlan_id = phba->vlan_id; | |
1585 | else | |
dbb6b3ab | 1586 | *vlan_id = LPFC_FCOE_NULL_VID; |
6fb120a7 JS |
1587 | return 1; |
1588 | } | |
1589 | ||
1590 | /* | |
1591 | * If there are no FCF connection table entry, driver connect to all | |
1592 | * FCFs. | |
1593 | */ | |
1594 | if (list_empty(&phba->fcf_conn_rec_list)) { | |
1595 | *boot_flag = 0; | |
1596 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, | |
1597 | new_fcf_record); | |
0c287589 JS |
1598 | |
1599 | /* | |
1600 | * When there are no FCF connect entries, use driver's default | |
1601 | * addressing mode - FPMA. | |
1602 | */ | |
1603 | if (*addr_mode & LPFC_FCF_FPMA) | |
1604 | *addr_mode = LPFC_FCF_FPMA; | |
1605 | ||
4d9ab994 JS |
1606 | /* If FCF record report a vlan id use that vlan id */ |
1607 | if (fcf_vlan_id) | |
1608 | *vlan_id = fcf_vlan_id; | |
1609 | else | |
dbb6b3ab | 1610 | *vlan_id = LPFC_FCOE_NULL_VID; |
6fb120a7 JS |
1611 | return 1; |
1612 | } | |
1613 | ||
ecfd03c6 JS |
1614 | list_for_each_entry(conn_entry, |
1615 | &phba->fcf_conn_rec_list, list) { | |
6fb120a7 JS |
1616 | if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) |
1617 | continue; | |
1618 | ||
1619 | if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) && | |
1620 | !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name, | |
8fa38513 JS |
1621 | new_fcf_record)) |
1622 | continue; | |
1623 | if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) && | |
1624 | !lpfc_sw_name_match(conn_entry->conn_rec.switch_name, | |
1625 | new_fcf_record)) | |
6fb120a7 | 1626 | continue; |
6fb120a7 JS |
1627 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) { |
1628 | /* | |
1629 | * If the vlan bit map does not have the bit set for the | |
1630 | * vlan id to be used, then it is not a match. | |
1631 | */ | |
1632 | if (!(new_fcf_record->vlan_bitmap | |
1633 | [conn_entry->conn_rec.vlan_tag / 8] & | |
1634 | (1 << (conn_entry->conn_rec.vlan_tag % 8)))) | |
1635 | continue; | |
1636 | } | |
1637 | ||
0c287589 JS |
1638 | /* |
1639 | * If connection record does not support any addressing mode, | |
1640 | * skip the FCF record. | |
1641 | */ | |
1642 | if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record) | |
1643 | & (LPFC_FCF_FPMA | LPFC_FCF_SPMA))) | |
1644 | continue; | |
1645 | ||
6fb120a7 JS |
1646 | /* |
1647 | * Check if the connection record specifies a required | |
1648 | * addressing mode. | |
1649 | */ | |
1650 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && | |
1651 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) { | |
1652 | ||
1653 | /* | |
1654 | * If SPMA required but FCF not support this continue. | |
1655 | */ | |
1656 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && | |
1657 | !(bf_get(lpfc_fcf_record_mac_addr_prov, | |
1658 | new_fcf_record) & LPFC_FCF_SPMA)) | |
1659 | continue; | |
1660 | ||
1661 | /* | |
1662 | * If FPMA required but FCF not support this continue. | |
1663 | */ | |
1664 | if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && | |
1665 | !(bf_get(lpfc_fcf_record_mac_addr_prov, | |
1666 | new_fcf_record) & LPFC_FCF_FPMA)) | |
1667 | continue; | |
1668 | } | |
1669 | ||
1670 | /* | |
1671 | * This fcf record matches filtering criteria. | |
1672 | */ | |
1673 | if (conn_entry->conn_rec.flags & FCFCNCT_BOOT) | |
1674 | *boot_flag = 1; | |
1675 | else | |
1676 | *boot_flag = 0; | |
1677 | ||
0c287589 JS |
1678 | /* |
1679 | * If user did not specify any addressing mode, or if the | |
25985edc | 1680 | * preferred addressing mode specified by user is not supported |
0c287589 JS |
1681 | * by FCF, allow fabric to pick the addressing mode. |
1682 | */ | |
6fb120a7 JS |
1683 | *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov, |
1684 | new_fcf_record); | |
1685 | /* | |
1686 | * If the user specified a required address mode, assign that | |
1687 | * address mode | |
1688 | */ | |
1689 | if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && | |
1690 | (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED))) | |
1691 | *addr_mode = (conn_entry->conn_rec.flags & | |
1692 | FCFCNCT_AM_SPMA) ? | |
1693 | LPFC_FCF_SPMA : LPFC_FCF_FPMA; | |
1694 | /* | |
25985edc | 1695 | * If the user specified a preferred address mode, use the |
6fb120a7 JS |
1696 | * addr mode only if FCF support the addr_mode. |
1697 | */ | |
1698 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && | |
1699 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && | |
1700 | (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && | |
1701 | (*addr_mode & LPFC_FCF_SPMA)) | |
1702 | *addr_mode = LPFC_FCF_SPMA; | |
1703 | else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) && | |
1704 | (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) && | |
1705 | !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) && | |
1706 | (*addr_mode & LPFC_FCF_FPMA)) | |
1707 | *addr_mode = LPFC_FCF_FPMA; | |
6fb120a7 | 1708 | |
4d9ab994 | 1709 | /* If matching connect list has a vlan id, use it */ |
6fb120a7 JS |
1710 | if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) |
1711 | *vlan_id = conn_entry->conn_rec.vlan_tag; | |
4d9ab994 JS |
1712 | /* |
1713 | * If no vlan id is specified in connect list, use the vlan id | |
1714 | * in the FCF record | |
1715 | */ | |
1716 | else if (fcf_vlan_id) | |
1717 | *vlan_id = fcf_vlan_id; | |
6fb120a7 | 1718 | else |
dbb6b3ab | 1719 | *vlan_id = LPFC_FCOE_NULL_VID; |
6fb120a7 JS |
1720 | |
1721 | return 1; | |
1722 | } | |
1723 | ||
1724 | return 0; | |
1725 | } | |
1726 | ||
32b9793f JS |
1727 | /** |
1728 | * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event. | |
1729 | * @phba: pointer to lpfc hba data structure. | |
1730 | * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned. | |
1731 | * | |
1732 | * This function check if there is any fcoe event pending while driver | |
1733 | * scan FCF entries. If there is any pending event, it will restart the | |
1734 | * FCF saning and return 1 else return 0. | |
1735 | */ | |
1736 | int | |
1737 | lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf) | |
1738 | { | |
32b9793f JS |
1739 | /* |
1740 | * If the Link is up and no FCoE events while in the | |
1741 | * FCF discovery, no need to restart FCF discovery. | |
1742 | */ | |
1743 | if ((phba->link_state >= LPFC_LINK_UP) && | |
a93ff37a | 1744 | (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan)) |
32b9793f JS |
1745 | return 0; |
1746 | ||
0c9ab6f5 JS |
1747 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
1748 | "2768 Pending link or FCF event during current " | |
1749 | "handling of the previous event: link_state:x%x, " | |
1750 | "evt_tag_at_scan:x%x, evt_tag_current:x%x\n", | |
1751 | phba->link_state, phba->fcoe_eventtag_at_fcf_scan, | |
1752 | phba->fcoe_eventtag); | |
1753 | ||
32b9793f JS |
1754 | spin_lock_irq(&phba->hbalock); |
1755 | phba->fcf.fcf_flag &= ~FCF_AVAILABLE; | |
1756 | spin_unlock_irq(&phba->hbalock); | |
1757 | ||
0c9ab6f5 JS |
1758 | if (phba->link_state >= LPFC_LINK_UP) { |
1759 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
1760 | "2780 Restart FCF table scan due to " | |
1761 | "pending FCF event:evt_tag_at_scan:x%x, " | |
1762 | "evt_tag_current:x%x\n", | |
1763 | phba->fcoe_eventtag_at_fcf_scan, | |
1764 | phba->fcoe_eventtag); | |
1765 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); | |
1766 | } else { | |
4d9ab994 | 1767 | /* |
a93ff37a | 1768 | * Do not continue FCF discovery and clear FCF_TS_INPROG |
4d9ab994 JS |
1769 | * flag |
1770 | */ | |
dbb6b3ab JS |
1771 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
1772 | "2833 Stop FCF discovery process due to link " | |
1773 | "state change (x%x)\n", phba->link_state); | |
1c6f4ef5 | 1774 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 1775 | phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG); |
0c9ab6f5 | 1776 | phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY); |
1c6f4ef5 JS |
1777 | spin_unlock_irq(&phba->hbalock); |
1778 | } | |
32b9793f | 1779 | |
0c9ab6f5 | 1780 | /* Unregister the currently registered FCF if required */ |
32b9793f JS |
1781 | if (unreg_fcf) { |
1782 | spin_lock_irq(&phba->hbalock); | |
1783 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; | |
1784 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 1785 | lpfc_sli4_unregister_fcf(phba); |
32b9793f | 1786 | } |
32b9793f JS |
1787 | return 1; |
1788 | } | |
1789 | ||
6fb120a7 | 1790 | /** |
999d813f JS |
1791 | * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record |
1792 | * @phba: pointer to lpfc hba data structure. | |
1793 | * @fcf_cnt: number of eligible fcf record seen so far. | |
1794 | * | |
1795 | * This function makes an running random selection decision on FCF record to | |
1796 | * use through a sequence of @fcf_cnt eligible FCF records with equal | |
1797 | * probability. To perform integer manunipulation of random numbers with | |
1798 | * size unit32_t, the lower 16 bits of the 32-bit random number returned | |
3b60a64f | 1799 | * from prandom_u32() are taken as the random random number generated. |
999d813f JS |
1800 | * |
1801 | * Returns true when outcome is for the newly read FCF record should be | |
1802 | * chosen; otherwise, return false when outcome is for keeping the previously | |
1803 | * chosen FCF record. | |
1804 | **/ | |
1805 | static bool | |
1806 | lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt) | |
1807 | { | |
1808 | uint32_t rand_num; | |
1809 | ||
1810 | /* Get 16-bit uniform random number */ | |
3b60a64f | 1811 | rand_num = 0xFFFF & prandom_u32(); |
999d813f JS |
1812 | |
1813 | /* Decision with probability 1/fcf_cnt */ | |
1814 | if ((fcf_cnt * rand_num) < 0xFFFF) | |
1815 | return true; | |
1816 | else | |
1817 | return false; | |
1818 | } | |
1819 | ||
1820 | /** | |
3804dc84 | 1821 | * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command. |
6fb120a7 JS |
1822 | * @phba: pointer to lpfc hba data structure. |
1823 | * @mboxq: pointer to mailbox object. | |
0c9ab6f5 | 1824 | * @next_fcf_index: pointer to holder of next fcf index. |
6fb120a7 | 1825 | * |
0c9ab6f5 JS |
1826 | * This routine parses the non-embedded fcf mailbox command by performing the |
1827 | * necessarily error checking, non-embedded read FCF record mailbox command | |
1828 | * SGE parsing, and endianness swapping. | |
1829 | * | |
1830 | * Returns the pointer to the new FCF record in the non-embedded mailbox | |
1831 | * command DMA memory if successfully, other NULL. | |
6fb120a7 | 1832 | */ |
0c9ab6f5 JS |
1833 | static struct fcf_record * |
1834 | lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
1835 | uint16_t *next_fcf_index) | |
6fb120a7 JS |
1836 | { |
1837 | void *virt_addr; | |
6fb120a7 JS |
1838 | struct lpfc_mbx_sge sge; |
1839 | struct lpfc_mbx_read_fcf_tbl *read_fcf; | |
f818ea7a | 1840 | uint32_t shdr_status, shdr_add_status, if_type; |
6fb120a7 JS |
1841 | union lpfc_sli4_cfg_shdr *shdr; |
1842 | struct fcf_record *new_fcf_record; | |
32b9793f | 1843 | |
6fb120a7 JS |
1844 | /* Get the first SGE entry from the non-embedded DMA memory. This |
1845 | * routine only uses a single SGE. | |
1846 | */ | |
1847 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
6fb120a7 JS |
1848 | if (unlikely(!mboxq->sge_array)) { |
1849 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
1850 | "2524 Failed to get the non-embedded SGE " | |
1851 | "virtual address\n"); | |
0c9ab6f5 | 1852 | return NULL; |
6fb120a7 JS |
1853 | } |
1854 | virt_addr = mboxq->sge_array->addr[0]; | |
1855 | ||
1856 | shdr = (union lpfc_sli4_cfg_shdr *)virt_addr; | |
2562669c JS |
1857 | lpfc_sli_pcimem_bcopy(shdr, shdr, |
1858 | sizeof(union lpfc_sli4_cfg_shdr)); | |
6fb120a7 | 1859 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
f818ea7a | 1860 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
0c9ab6f5 | 1861 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
6fb120a7 | 1862 | if (shdr_status || shdr_add_status) { |
f818ea7a JS |
1863 | if (shdr_status == STATUS_FCF_TABLE_EMPTY || |
1864 | if_type == LPFC_SLI_INTF_IF_TYPE_2) | |
0c9ab6f5 | 1865 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
def9c7a9 JS |
1866 | "2726 READ_FCF_RECORD Indicates empty " |
1867 | "FCF table.\n"); | |
0c9ab6f5 JS |
1868 | else |
1869 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
def9c7a9 | 1870 | "2521 READ_FCF_RECORD mailbox failed " |
0c9ab6f5 JS |
1871 | "with status x%x add_status x%x, " |
1872 | "mbx\n", shdr_status, shdr_add_status); | |
1873 | return NULL; | |
6fb120a7 | 1874 | } |
0c9ab6f5 JS |
1875 | |
1876 | /* Interpreting the returned information of the FCF record */ | |
6fb120a7 JS |
1877 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
1878 | lpfc_sli_pcimem_bcopy(read_fcf, read_fcf, | |
1879 | sizeof(struct lpfc_mbx_read_fcf_tbl)); | |
0c9ab6f5 | 1880 | *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf); |
6fb120a7 JS |
1881 | new_fcf_record = (struct fcf_record *)(virt_addr + |
1882 | sizeof(struct lpfc_mbx_read_fcf_tbl)); | |
1883 | lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record, | |
cb5172ea JS |
1884 | offsetof(struct fcf_record, vlan_bitmap)); |
1885 | new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137); | |
1886 | new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138); | |
6fb120a7 | 1887 | |
0c9ab6f5 JS |
1888 | return new_fcf_record; |
1889 | } | |
1890 | ||
1891 | /** | |
1892 | * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record | |
1893 | * @phba: pointer to lpfc hba data structure. | |
1894 | * @fcf_record: pointer to the fcf record. | |
1895 | * @vlan_id: the lowest vlan identifier associated to this fcf record. | |
1896 | * @next_fcf_index: the index to the next fcf record in hba's fcf table. | |
1897 | * | |
1898 | * This routine logs the detailed FCF record if the LOG_FIP loggin is | |
1899 | * enabled. | |
1900 | **/ | |
1901 | static void | |
1902 | lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba, | |
1903 | struct fcf_record *fcf_record, | |
1904 | uint16_t vlan_id, | |
1905 | uint16_t next_fcf_index) | |
1906 | { | |
1907 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
1908 | "2764 READ_FCF_RECORD:\n" | |
1909 | "\tFCF_Index : x%x\n" | |
1910 | "\tFCF_Avail : x%x\n" | |
1911 | "\tFCF_Valid : x%x\n" | |
26979ced | 1912 | "\tFCF_SOL : x%x\n" |
0c9ab6f5 JS |
1913 | "\tFIP_Priority : x%x\n" |
1914 | "\tMAC_Provider : x%x\n" | |
1915 | "\tLowest VLANID : x%x\n" | |
1916 | "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n" | |
1917 | "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" | |
1918 | "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n" | |
1919 | "\tNext_FCF_Index: x%x\n", | |
1920 | bf_get(lpfc_fcf_record_fcf_index, fcf_record), | |
1921 | bf_get(lpfc_fcf_record_fcf_avail, fcf_record), | |
1922 | bf_get(lpfc_fcf_record_fcf_valid, fcf_record), | |
26979ced | 1923 | bf_get(lpfc_fcf_record_fcf_sol, fcf_record), |
0c9ab6f5 JS |
1924 | fcf_record->fip_priority, |
1925 | bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record), | |
1926 | vlan_id, | |
1927 | bf_get(lpfc_fcf_record_mac_0, fcf_record), | |
1928 | bf_get(lpfc_fcf_record_mac_1, fcf_record), | |
1929 | bf_get(lpfc_fcf_record_mac_2, fcf_record), | |
1930 | bf_get(lpfc_fcf_record_mac_3, fcf_record), | |
1931 | bf_get(lpfc_fcf_record_mac_4, fcf_record), | |
1932 | bf_get(lpfc_fcf_record_mac_5, fcf_record), | |
1933 | bf_get(lpfc_fcf_record_fab_name_0, fcf_record), | |
1934 | bf_get(lpfc_fcf_record_fab_name_1, fcf_record), | |
1935 | bf_get(lpfc_fcf_record_fab_name_2, fcf_record), | |
1936 | bf_get(lpfc_fcf_record_fab_name_3, fcf_record), | |
1937 | bf_get(lpfc_fcf_record_fab_name_4, fcf_record), | |
1938 | bf_get(lpfc_fcf_record_fab_name_5, fcf_record), | |
1939 | bf_get(lpfc_fcf_record_fab_name_6, fcf_record), | |
1940 | bf_get(lpfc_fcf_record_fab_name_7, fcf_record), | |
1941 | bf_get(lpfc_fcf_record_switch_name_0, fcf_record), | |
1942 | bf_get(lpfc_fcf_record_switch_name_1, fcf_record), | |
1943 | bf_get(lpfc_fcf_record_switch_name_2, fcf_record), | |
1944 | bf_get(lpfc_fcf_record_switch_name_3, fcf_record), | |
1945 | bf_get(lpfc_fcf_record_switch_name_4, fcf_record), | |
1946 | bf_get(lpfc_fcf_record_switch_name_5, fcf_record), | |
1947 | bf_get(lpfc_fcf_record_switch_name_6, fcf_record), | |
1948 | bf_get(lpfc_fcf_record_switch_name_7, fcf_record), | |
1949 | next_fcf_index); | |
1950 | } | |
1951 | ||
dbb6b3ab JS |
1952 | /** |
1953 | lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF | |
1954 | * @phba: pointer to lpfc hba data structure. | |
1955 | * @fcf_rec: pointer to an existing FCF record. | |
1956 | * @new_fcf_record: pointer to a new FCF record. | |
1957 | * @new_vlan_id: vlan id from the new FCF record. | |
1958 | * | |
1959 | * This function performs matching test of a new FCF record against an existing | |
1960 | * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id | |
1961 | * will not be used as part of the FCF record matching criteria. | |
1962 | * | |
1963 | * Returns true if all the fields matching, otherwise returns false. | |
1964 | */ | |
1965 | static bool | |
1966 | lpfc_sli4_fcf_record_match(struct lpfc_hba *phba, | |
1967 | struct lpfc_fcf_rec *fcf_rec, | |
1968 | struct fcf_record *new_fcf_record, | |
1969 | uint16_t new_vlan_id) | |
1970 | { | |
1971 | if (new_vlan_id != LPFC_FCOE_IGNORE_VID) | |
1972 | if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id)) | |
1973 | return false; | |
1974 | if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record)) | |
1975 | return false; | |
1976 | if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record)) | |
1977 | return false; | |
1978 | if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record)) | |
1979 | return false; | |
7d791df7 JS |
1980 | if (fcf_rec->priority != new_fcf_record->fip_priority) |
1981 | return false; | |
dbb6b3ab JS |
1982 | return true; |
1983 | } | |
1984 | ||
a93ff37a JS |
1985 | /** |
1986 | * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf | |
1987 | * @vport: Pointer to vport object. | |
1988 | * @fcf_index: index to next fcf. | |
1989 | * | |
1990 | * This function processing the roundrobin fcf failover to next fcf index. | |
1991 | * When this function is invoked, there will be a current fcf registered | |
1992 | * for flogi. | |
1993 | * Return: 0 for continue retrying flogi on currently registered fcf; | |
1994 | * 1 for stop flogi on currently registered fcf; | |
1995 | */ | |
1996 | int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index) | |
1997 | { | |
1998 | struct lpfc_hba *phba = vport->phba; | |
1999 | int rc; | |
2000 | ||
2001 | if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { | |
2002 | spin_lock_irq(&phba->hbalock); | |
2003 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { | |
2004 | spin_unlock_irq(&phba->hbalock); | |
2005 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2006 | "2872 Devloss tmo with no eligible " | |
2007 | "FCF, unregister in-use FCF (x%x) " | |
2008 | "and rescan FCF table\n", | |
2009 | phba->fcf.current_rec.fcf_indx); | |
2010 | lpfc_unregister_fcf_rescan(phba); | |
2011 | goto stop_flogi_current_fcf; | |
2012 | } | |
2013 | /* Mark the end to FLOGI roundrobin failover */ | |
2014 | phba->hba_flag &= ~FCF_RR_INPROG; | |
2015 | /* Allow action to new fcf asynchronous event */ | |
2016 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
2017 | spin_unlock_irq(&phba->hbalock); | |
2018 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2019 | "2865 No FCF available, stop roundrobin FCF " | |
2020 | "failover and change port state:x%x/x%x\n", | |
2021 | phba->pport->port_state, LPFC_VPORT_UNKNOWN); | |
2022 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
036cad1f JS |
2023 | |
2024 | if (!phba->fcf.fcf_redisc_attempted) { | |
2025 | lpfc_unregister_fcf(phba); | |
2026 | ||
2027 | rc = lpfc_sli4_redisc_fcf_table(phba); | |
2028 | if (!rc) { | |
2029 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2030 | "3195 Rediscover FCF table\n"); | |
2031 | phba->fcf.fcf_redisc_attempted = 1; | |
2032 | lpfc_sli4_clear_fcf_rr_bmask(phba); | |
2033 | } else { | |
2034 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
2035 | "3196 Rediscover FCF table " | |
2036 | "failed. Status:x%x\n", rc); | |
2037 | } | |
2038 | } else { | |
2039 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
2040 | "3197 Already rediscover FCF table " | |
2041 | "attempted. No more retry\n"); | |
2042 | } | |
a93ff37a JS |
2043 | goto stop_flogi_current_fcf; |
2044 | } else { | |
2045 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS, | |
2046 | "2794 Try FLOGI roundrobin FCF failover to " | |
2047 | "(x%x)\n", fcf_index); | |
2048 | rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index); | |
2049 | if (rc) | |
2050 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, | |
2051 | "2761 FLOGI roundrobin FCF failover " | |
2052 | "failed (rc:x%x) to read FCF (x%x)\n", | |
2053 | rc, phba->fcf.current_rec.fcf_indx); | |
2054 | else | |
2055 | goto stop_flogi_current_fcf; | |
2056 | } | |
2057 | return 0; | |
2058 | ||
2059 | stop_flogi_current_fcf: | |
2060 | lpfc_can_disctmo(vport); | |
2061 | return 1; | |
2062 | } | |
2063 | ||
7d791df7 JS |
2064 | /** |
2065 | * lpfc_sli4_fcf_pri_list_del | |
2066 | * @phba: pointer to lpfc hba data structure. | |
2067 | * @fcf_index the index of the fcf record to delete | |
2068 | * This routine checks the on list flag of the fcf_index to be deleted. | |
2069 | * If it is one the list then it is removed from the list, and the flag | |
2070 | * is cleared. This routine grab the hbalock before removing the fcf | |
2071 | * record from the list. | |
2072 | **/ | |
2073 | static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba, | |
2074 | uint16_t fcf_index) | |
2075 | { | |
2076 | struct lpfc_fcf_pri *new_fcf_pri; | |
2077 | ||
2078 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; | |
2079 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2080 | "3058 deleting idx x%x pri x%x flg x%x\n", | |
2081 | fcf_index, new_fcf_pri->fcf_rec.priority, | |
2082 | new_fcf_pri->fcf_rec.flag); | |
2083 | spin_lock_irq(&phba->hbalock); | |
2084 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) { | |
2085 | if (phba->fcf.current_rec.priority == | |
2086 | new_fcf_pri->fcf_rec.priority) | |
2087 | phba->fcf.eligible_fcf_cnt--; | |
2088 | list_del_init(&new_fcf_pri->list); | |
2089 | new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST; | |
2090 | } | |
2091 | spin_unlock_irq(&phba->hbalock); | |
2092 | } | |
2093 | ||
2094 | /** | |
2095 | * lpfc_sli4_set_fcf_flogi_fail | |
2096 | * @phba: pointer to lpfc hba data structure. | |
2097 | * @fcf_index the index of the fcf record to update | |
2098 | * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED | |
2099 | * flag so the the round robin slection for the particular priority level | |
2100 | * will try a different fcf record that does not have this bit set. | |
2101 | * If the fcf record is re-read for any reason this flag is cleared brfore | |
2102 | * adding it to the priority list. | |
2103 | **/ | |
2104 | void | |
2105 | lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index) | |
2106 | { | |
2107 | struct lpfc_fcf_pri *new_fcf_pri; | |
2108 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; | |
2109 | spin_lock_irq(&phba->hbalock); | |
2110 | new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED; | |
2111 | spin_unlock_irq(&phba->hbalock); | |
2112 | } | |
2113 | ||
2114 | /** | |
2115 | * lpfc_sli4_fcf_pri_list_add | |
2116 | * @phba: pointer to lpfc hba data structure. | |
2117 | * @fcf_index the index of the fcf record to add | |
2118 | * This routine checks the priority of the fcf_index to be added. | |
2119 | * If it is a lower priority than the current head of the fcf_pri list | |
2120 | * then it is added to the list in the right order. | |
2121 | * If it is the same priority as the current head of the list then it | |
2122 | * is added to the head of the list and its bit in the rr_bmask is set. | |
2123 | * If the fcf_index to be added is of a higher priority than the current | |
2124 | * head of the list then the rr_bmask is cleared, its bit is set in the | |
2125 | * rr_bmask and it is added to the head of the list. | |
2126 | * returns: | |
2127 | * 0=success 1=failure | |
2128 | **/ | |
b86a6756 RK |
2129 | static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, |
2130 | uint16_t fcf_index, | |
7d791df7 JS |
2131 | struct fcf_record *new_fcf_record) |
2132 | { | |
2133 | uint16_t current_fcf_pri; | |
2134 | uint16_t last_index; | |
2135 | struct lpfc_fcf_pri *fcf_pri; | |
2136 | struct lpfc_fcf_pri *next_fcf_pri; | |
2137 | struct lpfc_fcf_pri *new_fcf_pri; | |
2138 | int ret; | |
2139 | ||
2140 | new_fcf_pri = &phba->fcf.fcf_pri[fcf_index]; | |
2141 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2142 | "3059 adding idx x%x pri x%x flg x%x\n", | |
2143 | fcf_index, new_fcf_record->fip_priority, | |
2144 | new_fcf_pri->fcf_rec.flag); | |
2145 | spin_lock_irq(&phba->hbalock); | |
2146 | if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) | |
2147 | list_del_init(&new_fcf_pri->list); | |
2148 | new_fcf_pri->fcf_rec.fcf_index = fcf_index; | |
2149 | new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority; | |
2150 | if (list_empty(&phba->fcf.fcf_pri_list)) { | |
2151 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); | |
2152 | ret = lpfc_sli4_fcf_rr_index_set(phba, | |
2153 | new_fcf_pri->fcf_rec.fcf_index); | |
2154 | goto out; | |
2155 | } | |
2156 | ||
2157 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
2158 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
2159 | if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
2160 | ret = 0; /* Empty rr list */ | |
2161 | goto out; | |
2162 | } | |
2163 | current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority; | |
2164 | if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) { | |
2165 | list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list); | |
2166 | if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) { | |
2167 | memset(phba->fcf.fcf_rr_bmask, 0, | |
2168 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
2169 | /* fcfs_at_this_priority_level = 1; */ | |
2170 | phba->fcf.eligible_fcf_cnt = 1; | |
2171 | } else | |
2172 | /* fcfs_at_this_priority_level++; */ | |
2173 | phba->fcf.eligible_fcf_cnt++; | |
2174 | ret = lpfc_sli4_fcf_rr_index_set(phba, | |
2175 | new_fcf_pri->fcf_rec.fcf_index); | |
2176 | goto out; | |
2177 | } | |
2178 | ||
2179 | list_for_each_entry_safe(fcf_pri, next_fcf_pri, | |
2180 | &phba->fcf.fcf_pri_list, list) { | |
2181 | if (new_fcf_pri->fcf_rec.priority <= | |
2182 | fcf_pri->fcf_rec.priority) { | |
2183 | if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list) | |
2184 | list_add(&new_fcf_pri->list, | |
2185 | &phba->fcf.fcf_pri_list); | |
2186 | else | |
2187 | list_add(&new_fcf_pri->list, | |
2188 | &((struct lpfc_fcf_pri *) | |
2189 | fcf_pri->list.prev)->list); | |
2190 | ret = 0; | |
2191 | goto out; | |
2192 | } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list | |
2193 | || new_fcf_pri->fcf_rec.priority < | |
2194 | next_fcf_pri->fcf_rec.priority) { | |
2195 | list_add(&new_fcf_pri->list, &fcf_pri->list); | |
2196 | ret = 0; | |
2197 | goto out; | |
2198 | } | |
2199 | if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority) | |
2200 | continue; | |
2201 | ||
2202 | } | |
2203 | ret = 1; | |
2204 | out: | |
2205 | /* we use = instead of |= to clear the FLOGI_FAILED flag. */ | |
2206 | new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST; | |
2207 | spin_unlock_irq(&phba->hbalock); | |
2208 | return ret; | |
2209 | } | |
2210 | ||
0c9ab6f5 JS |
2211 | /** |
2212 | * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler. | |
2213 | * @phba: pointer to lpfc hba data structure. | |
2214 | * @mboxq: pointer to mailbox object. | |
2215 | * | |
2216 | * This function iterates through all the fcf records available in | |
2217 | * HBA and chooses the optimal FCF record for discovery. After finding | |
2218 | * the FCF for discovery it registers the FCF record and kicks start | |
2219 | * discovery. | |
2220 | * If FCF_IN_USE flag is set in currently used FCF, the routine tries to | |
2221 | * use an FCF record which matches fabric name and mac address of the | |
2222 | * currently used FCF record. | |
2223 | * If the driver supports only one FCF, it will try to use the FCF record | |
2224 | * used by BOOT_BIOS. | |
2225 | */ | |
2226 | void | |
2227 | lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
2228 | { | |
2229 | struct fcf_record *new_fcf_record; | |
2230 | uint32_t boot_flag, addr_mode; | |
2231 | uint16_t fcf_index, next_fcf_index; | |
2232 | struct lpfc_fcf_rec *fcf_rec = NULL; | |
2ade92ae | 2233 | uint16_t vlan_id = LPFC_FCOE_NULL_VID; |
999d813f | 2234 | bool select_new_fcf; |
0c9ab6f5 JS |
2235 | int rc; |
2236 | ||
2237 | /* If there is pending FCoE event restart FCF table scan */ | |
a93ff37a | 2238 | if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) { |
0c9ab6f5 JS |
2239 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
2240 | return; | |
2241 | } | |
2242 | ||
2243 | /* Parse the FCF record from the non-embedded mailbox command */ | |
2244 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, | |
2245 | &next_fcf_index); | |
2246 | if (!new_fcf_record) { | |
a93ff37a | 2247 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
0c9ab6f5 JS |
2248 | "2765 Mailbox command READ_FCF_RECORD " |
2249 | "failed to retrieve a FCF record.\n"); | |
2250 | /* Let next new FCF event trigger fast failover */ | |
2251 | spin_lock_irq(&phba->hbalock); | |
a93ff37a | 2252 | phba->hba_flag &= ~FCF_TS_INPROG; |
0c9ab6f5 JS |
2253 | spin_unlock_irq(&phba->hbalock); |
2254 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
2255 | return; | |
2256 | } | |
2257 | ||
2258 | /* Check the FCF record against the connection list */ | |
ecfd03c6 JS |
2259 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
2260 | &addr_mode, &vlan_id); | |
0c9ab6f5 JS |
2261 | |
2262 | /* Log the FCF record information if turned on */ | |
2263 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, | |
2264 | next_fcf_index); | |
2265 | ||
6fb120a7 JS |
2266 | /* |
2267 | * If the fcf record does not match with connect list entries | |
0c9ab6f5 | 2268 | * read the next entry; otherwise, this is an eligible FCF |
a93ff37a | 2269 | * record for roundrobin FCF failover. |
6fb120a7 | 2270 | */ |
0c9ab6f5 | 2271 | if (!rc) { |
7d791df7 JS |
2272 | lpfc_sli4_fcf_pri_list_del(phba, |
2273 | bf_get(lpfc_fcf_record_fcf_index, | |
2274 | new_fcf_record)); | |
0c9ab6f5 | 2275 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
a93ff37a | 2276 | "2781 FCF (x%x) failed connection " |
26979ced | 2277 | "list check: (x%x/x%x/%x)\n", |
0c9ab6f5 JS |
2278 | bf_get(lpfc_fcf_record_fcf_index, |
2279 | new_fcf_record), | |
2280 | bf_get(lpfc_fcf_record_fcf_avail, | |
2281 | new_fcf_record), | |
2282 | bf_get(lpfc_fcf_record_fcf_valid, | |
26979ced JS |
2283 | new_fcf_record), |
2284 | bf_get(lpfc_fcf_record_fcf_sol, | |
0c9ab6f5 | 2285 | new_fcf_record)); |
dbb6b3ab JS |
2286 | if ((phba->fcf.fcf_flag & FCF_IN_USE) && |
2287 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, | |
2288 | new_fcf_record, LPFC_FCOE_IGNORE_VID)) { | |
5ac6b303 JS |
2289 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) != |
2290 | phba->fcf.current_rec.fcf_indx) { | |
2291 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
2292 | "2862 FCF (x%x) matches property " | |
2293 | "of in-use FCF (x%x)\n", | |
2294 | bf_get(lpfc_fcf_record_fcf_index, | |
2295 | new_fcf_record), | |
2296 | phba->fcf.current_rec.fcf_indx); | |
2297 | goto read_next_fcf; | |
2298 | } | |
dbb6b3ab JS |
2299 | /* |
2300 | * In case the current in-use FCF record becomes | |
2301 | * invalid/unavailable during FCF discovery that | |
2302 | * was not triggered by fast FCF failover process, | |
2303 | * treat it as fast FCF failover. | |
2304 | */ | |
2305 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) && | |
2306 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { | |
2307 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
2308 | "2835 Invalid in-use FCF " | |
a93ff37a JS |
2309 | "(x%x), enter FCF failover " |
2310 | "table scan.\n", | |
dbb6b3ab JS |
2311 | phba->fcf.current_rec.fcf_indx); |
2312 | spin_lock_irq(&phba->hbalock); | |
2313 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
2314 | spin_unlock_irq(&phba->hbalock); | |
2315 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
2316 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, | |
2317 | LPFC_FCOE_FCF_GET_FIRST); | |
2318 | return; | |
2319 | } | |
2320 | } | |
6fb120a7 | 2321 | goto read_next_fcf; |
0c9ab6f5 JS |
2322 | } else { |
2323 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); | |
7d791df7 JS |
2324 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, |
2325 | new_fcf_record); | |
0c9ab6f5 JS |
2326 | if (rc) |
2327 | goto read_next_fcf; | |
2328 | } | |
2329 | ||
6fb120a7 JS |
2330 | /* |
2331 | * If this is not the first FCF discovery of the HBA, use last | |
ecfd03c6 JS |
2332 | * FCF record for the discovery. The condition that a rescan |
2333 | * matches the in-use FCF record: fabric name, switch name, mac | |
2334 | * address, and vlan_id. | |
6fb120a7 | 2335 | */ |
0c9ab6f5 | 2336 | spin_lock_irq(&phba->hbalock); |
6fb120a7 | 2337 | if (phba->fcf.fcf_flag & FCF_IN_USE) { |
7d791df7 JS |
2338 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
2339 | lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec, | |
dbb6b3ab | 2340 | new_fcf_record, vlan_id)) { |
5ac6b303 JS |
2341 | if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) == |
2342 | phba->fcf.current_rec.fcf_indx) { | |
2343 | phba->fcf.fcf_flag |= FCF_AVAILABLE; | |
2344 | if (phba->fcf.fcf_flag & FCF_REDISC_PEND) | |
2345 | /* Stop FCF redisc wait timer */ | |
2346 | __lpfc_sli4_stop_fcf_redisc_wait_timer( | |
2347 | phba); | |
2348 | else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) | |
2349 | /* Fast failover, mark completed */ | |
2350 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; | |
2351 | spin_unlock_irq(&phba->hbalock); | |
2352 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2353 | "2836 New FCF matches in-use " | |
88f43a08 JS |
2354 | "FCF (x%x), port_state:x%x, " |
2355 | "fc_flag:x%x\n", | |
2356 | phba->fcf.current_rec.fcf_indx, | |
2357 | phba->pport->port_state, | |
2358 | phba->pport->fc_flag); | |
5ac6b303 JS |
2359 | goto out; |
2360 | } else | |
2361 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
2362 | "2863 New FCF (x%x) matches " | |
2363 | "property of in-use FCF (x%x)\n", | |
dbb6b3ab | 2364 | bf_get(lpfc_fcf_record_fcf_index, |
5ac6b303 JS |
2365 | new_fcf_record), |
2366 | phba->fcf.current_rec.fcf_indx); | |
6fb120a7 | 2367 | } |
ecfd03c6 JS |
2368 | /* |
2369 | * Read next FCF record from HBA searching for the matching | |
2370 | * with in-use record only if not during the fast failover | |
2371 | * period. In case of fast failover period, it shall try to | |
2372 | * determine whether the FCF record just read should be the | |
2373 | * next candidate. | |
2374 | */ | |
2375 | if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { | |
0c9ab6f5 | 2376 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
2377 | goto read_next_fcf; |
2378 | } | |
6fb120a7 | 2379 | } |
ecfd03c6 JS |
2380 | /* |
2381 | * Update on failover FCF record only if it's in FCF fast-failover | |
2382 | * period; otherwise, update on current FCF record. | |
2383 | */ | |
fc2b989b JS |
2384 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) |
2385 | fcf_rec = &phba->fcf.failover_rec; | |
2386 | else | |
ecfd03c6 JS |
2387 | fcf_rec = &phba->fcf.current_rec; |
2388 | ||
6fb120a7 JS |
2389 | if (phba->fcf.fcf_flag & FCF_AVAILABLE) { |
2390 | /* | |
ecfd03c6 JS |
2391 | * If the driver FCF record does not have boot flag |
2392 | * set and new hba fcf record has boot flag set, use | |
2393 | * the new hba fcf record. | |
6fb120a7 | 2394 | */ |
ecfd03c6 JS |
2395 | if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) { |
2396 | /* Choose this FCF record */ | |
dbb6b3ab JS |
2397 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
2398 | "2837 Update current FCF record " | |
2399 | "(x%x) with new FCF record (x%x)\n", | |
2400 | fcf_rec->fcf_indx, | |
2401 | bf_get(lpfc_fcf_record_fcf_index, | |
2402 | new_fcf_record)); | |
ecfd03c6 JS |
2403 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
2404 | addr_mode, vlan_id, BOOT_ENABLE); | |
0c9ab6f5 | 2405 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 JS |
2406 | goto read_next_fcf; |
2407 | } | |
2408 | /* | |
ecfd03c6 JS |
2409 | * If the driver FCF record has boot flag set and the |
2410 | * new hba FCF record does not have boot flag, read | |
2411 | * the next FCF record. | |
6fb120a7 | 2412 | */ |
ecfd03c6 | 2413 | if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) { |
0c9ab6f5 | 2414 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 JS |
2415 | goto read_next_fcf; |
2416 | } | |
2417 | /* | |
ecfd03c6 JS |
2418 | * If the new hba FCF record has lower priority value |
2419 | * than the driver FCF record, use the new record. | |
6fb120a7 | 2420 | */ |
fc2b989b | 2421 | if (new_fcf_record->fip_priority < fcf_rec->priority) { |
999d813f | 2422 | /* Choose the new FCF record with lower priority */ |
dbb6b3ab JS |
2423 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
2424 | "2838 Update current FCF record " | |
2425 | "(x%x) with new FCF record (x%x)\n", | |
2426 | fcf_rec->fcf_indx, | |
2427 | bf_get(lpfc_fcf_record_fcf_index, | |
2428 | new_fcf_record)); | |
ecfd03c6 JS |
2429 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
2430 | addr_mode, vlan_id, 0); | |
999d813f JS |
2431 | /* Reset running random FCF selection count */ |
2432 | phba->fcf.eligible_fcf_cnt = 1; | |
2433 | } else if (new_fcf_record->fip_priority == fcf_rec->priority) { | |
2434 | /* Update running random FCF selection count */ | |
2435 | phba->fcf.eligible_fcf_cnt++; | |
2436 | select_new_fcf = lpfc_sli4_new_fcf_random_select(phba, | |
2437 | phba->fcf.eligible_fcf_cnt); | |
dbb6b3ab JS |
2438 | if (select_new_fcf) { |
2439 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2440 | "2839 Update current FCF record " | |
2441 | "(x%x) with new FCF record (x%x)\n", | |
2442 | fcf_rec->fcf_indx, | |
2443 | bf_get(lpfc_fcf_record_fcf_index, | |
2444 | new_fcf_record)); | |
999d813f JS |
2445 | /* Choose the new FCF by random selection */ |
2446 | __lpfc_update_fcf_record(phba, fcf_rec, | |
2447 | new_fcf_record, | |
2448 | addr_mode, vlan_id, 0); | |
dbb6b3ab | 2449 | } |
6fb120a7 | 2450 | } |
0c9ab6f5 | 2451 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 JS |
2452 | goto read_next_fcf; |
2453 | } | |
2454 | /* | |
ecfd03c6 JS |
2455 | * This is the first suitable FCF record, choose this record for |
2456 | * initial best-fit FCF. | |
6fb120a7 | 2457 | */ |
ecfd03c6 | 2458 | if (fcf_rec) { |
dbb6b3ab | 2459 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
2460 | "2840 Update initial FCF candidate " |
2461 | "with FCF (x%x)\n", | |
dbb6b3ab JS |
2462 | bf_get(lpfc_fcf_record_fcf_index, |
2463 | new_fcf_record)); | |
ecfd03c6 JS |
2464 | __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record, |
2465 | addr_mode, vlan_id, (boot_flag ? | |
2466 | BOOT_ENABLE : 0)); | |
2467 | phba->fcf.fcf_flag |= FCF_AVAILABLE; | |
999d813f JS |
2468 | /* Setup initial running random FCF selection count */ |
2469 | phba->fcf.eligible_fcf_cnt = 1; | |
6fb120a7 | 2470 | } |
0c9ab6f5 | 2471 | spin_unlock_irq(&phba->hbalock); |
6fb120a7 JS |
2472 | goto read_next_fcf; |
2473 | ||
2474 | read_next_fcf: | |
2475 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
ecfd03c6 JS |
2476 | if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) { |
2477 | if (phba->fcf.fcf_flag & FCF_REDISC_FOV) { | |
2478 | /* | |
2479 | * Case of FCF fast failover scan | |
2480 | */ | |
2481 | ||
2482 | /* | |
2483 | * It has not found any suitable FCF record, cancel | |
2484 | * FCF scan inprogress, and do nothing | |
2485 | */ | |
2486 | if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) { | |
0c9ab6f5 | 2487 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
a93ff37a JS |
2488 | "2782 No suitable FCF found: " |
2489 | "(x%x/x%x)\n", | |
0c9ab6f5 JS |
2490 | phba->fcoe_eventtag_at_fcf_scan, |
2491 | bf_get(lpfc_fcf_record_fcf_index, | |
2492 | new_fcf_record)); | |
a93ff37a JS |
2493 | spin_lock_irq(&phba->hbalock); |
2494 | if (phba->hba_flag & HBA_DEVLOSS_TMO) { | |
2495 | phba->hba_flag &= ~FCF_TS_INPROG; | |
2496 | spin_unlock_irq(&phba->hbalock); | |
2497 | /* Unregister in-use FCF and rescan */ | |
2498 | lpfc_printf_log(phba, KERN_INFO, | |
2499 | LOG_FIP, | |
2500 | "2864 On devloss tmo " | |
2501 | "unreg in-use FCF and " | |
2502 | "rescan FCF table\n"); | |
2503 | lpfc_unregister_fcf_rescan(phba); | |
2504 | return; | |
2505 | } | |
0c9ab6f5 | 2506 | /* |
a93ff37a | 2507 | * Let next new FCF event trigger fast failover |
0c9ab6f5 | 2508 | */ |
a93ff37a | 2509 | phba->hba_flag &= ~FCF_TS_INPROG; |
0c9ab6f5 | 2510 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
2511 | return; |
2512 | } | |
2513 | /* | |
2514 | * It has found a suitable FCF record that is not | |
2515 | * the same as in-use FCF record, unregister the | |
2516 | * in-use FCF record, replace the in-use FCF record | |
2517 | * with the new FCF record, mark FCF fast failover | |
2518 | * completed, and then start register the new FCF | |
2519 | * record. | |
2520 | */ | |
2521 | ||
0c9ab6f5 | 2522 | /* Unregister the current in-use FCF record */ |
ecfd03c6 | 2523 | lpfc_unregister_fcf(phba); |
0c9ab6f5 JS |
2524 | |
2525 | /* Replace in-use record with the new record */ | |
dbb6b3ab | 2526 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
2527 | "2842 Replace in-use FCF (x%x) " |
2528 | "with failover FCF (x%x)\n", | |
dbb6b3ab JS |
2529 | phba->fcf.current_rec.fcf_indx, |
2530 | phba->fcf.failover_rec.fcf_indx); | |
ecfd03c6 JS |
2531 | memcpy(&phba->fcf.current_rec, |
2532 | &phba->fcf.failover_rec, | |
2533 | sizeof(struct lpfc_fcf_rec)); | |
3804dc84 JS |
2534 | /* |
2535 | * Mark the fast FCF failover rediscovery completed | |
2536 | * and the start of the first round of the roundrobin | |
2537 | * FCF failover. | |
2538 | */ | |
0c9ab6f5 | 2539 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 2540 | phba->fcf.fcf_flag &= ~FCF_REDISC_FOV; |
0c9ab6f5 | 2541 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
2542 | /* Register to the new FCF record */ |
2543 | lpfc_register_fcf(phba); | |
2544 | } else { | |
2545 | /* | |
2546 | * In case of transaction period to fast FCF failover, | |
2547 | * do nothing when search to the end of the FCF table. | |
2548 | */ | |
2549 | if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) || | |
2550 | (phba->fcf.fcf_flag & FCF_REDISC_PEND)) | |
2551 | return; | |
dbb6b3ab | 2552 | |
7d791df7 JS |
2553 | if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV && |
2554 | phba->fcf.fcf_flag & FCF_IN_USE) { | |
dbb6b3ab JS |
2555 | /* |
2556 | * In case the current in-use FCF record no | |
2557 | * longer existed during FCF discovery that | |
2558 | * was not triggered by fast FCF failover | |
2559 | * process, treat it as fast FCF failover. | |
2560 | */ | |
2561 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2562 | "2841 In-use FCF record (x%x) " | |
2563 | "not reported, entering fast " | |
2564 | "FCF failover mode scanning.\n", | |
2565 | phba->fcf.current_rec.fcf_indx); | |
2566 | spin_lock_irq(&phba->hbalock); | |
2567 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
2568 | spin_unlock_irq(&phba->hbalock); | |
dbb6b3ab JS |
2569 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
2570 | LPFC_FCOE_FCF_GET_FIRST); | |
2571 | return; | |
2572 | } | |
0c9ab6f5 | 2573 | /* Register to the new FCF record */ |
ecfd03c6 JS |
2574 | lpfc_register_fcf(phba); |
2575 | } | |
2576 | } else | |
0c9ab6f5 | 2577 | lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index); |
6fb120a7 JS |
2578 | return; |
2579 | ||
2580 | out: | |
2581 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
2582 | lpfc_register_fcf(phba); | |
2583 | ||
2584 | return; | |
2585 | } | |
2586 | ||
0c9ab6f5 | 2587 | /** |
a93ff37a | 2588 | * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler |
0c9ab6f5 JS |
2589 | * @phba: pointer to lpfc hba data structure. |
2590 | * @mboxq: pointer to mailbox object. | |
2591 | * | |
a93ff37a | 2592 | * This is the callback function for FLOGI failure roundrobin FCF failover |
0c9ab6f5 JS |
2593 | * read FCF record mailbox command from the eligible FCF record bmask for |
2594 | * performing the failover. If the FCF read back is not valid/available, it | |
2595 | * fails through to retrying FLOGI to the currently registered FCF again. | |
2596 | * Otherwise, if the FCF read back is valid and available, it will set the | |
2597 | * newly read FCF record to the failover FCF record, unregister currently | |
2598 | * registered FCF record, copy the failover FCF record to the current | |
2599 | * FCF record, and then register the current FCF record before proceeding | |
2600 | * to trying FLOGI on the new failover FCF. | |
2601 | */ | |
2602 | void | |
2603 | lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
2604 | { | |
2605 | struct fcf_record *new_fcf_record; | |
2606 | uint32_t boot_flag, addr_mode; | |
a93ff37a | 2607 | uint16_t next_fcf_index, fcf_index; |
0c9ab6f5 JS |
2608 | uint16_t current_fcf_index; |
2609 | uint16_t vlan_id; | |
a93ff37a | 2610 | int rc; |
0c9ab6f5 | 2611 | |
a93ff37a | 2612 | /* If link state is not up, stop the roundrobin failover process */ |
0c9ab6f5 JS |
2613 | if (phba->link_state < LPFC_LINK_UP) { |
2614 | spin_lock_irq(&phba->hbalock); | |
2615 | phba->fcf.fcf_flag &= ~FCF_DISCOVERY; | |
a93ff37a | 2616 | phba->hba_flag &= ~FCF_RR_INPROG; |
0c9ab6f5 | 2617 | spin_unlock_irq(&phba->hbalock); |
a93ff37a | 2618 | goto out; |
0c9ab6f5 JS |
2619 | } |
2620 | ||
2621 | /* Parse the FCF record from the non-embedded mailbox command */ | |
2622 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, | |
2623 | &next_fcf_index); | |
2624 | if (!new_fcf_record) { | |
2625 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
2626 | "2766 Mailbox command READ_FCF_RECORD " | |
646a2dd7 JS |
2627 | "failed to retrieve a FCF record. " |
2628 | "hba_flg x%x fcf_flg x%x\n", phba->hba_flag, | |
2629 | phba->fcf.fcf_flag); | |
2630 | lpfc_unregister_fcf_rescan(phba); | |
2631 | goto out; | |
0c9ab6f5 JS |
2632 | } |
2633 | ||
2634 | /* Get the needed parameters from FCF record */ | |
a93ff37a JS |
2635 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, |
2636 | &addr_mode, &vlan_id); | |
0c9ab6f5 JS |
2637 | |
2638 | /* Log the FCF record information if turned on */ | |
2639 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, | |
2640 | next_fcf_index); | |
2641 | ||
a93ff37a JS |
2642 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); |
2643 | if (!rc) { | |
2644 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2645 | "2848 Remove ineligible FCF (x%x) from " | |
2646 | "from roundrobin bmask\n", fcf_index); | |
2647 | /* Clear roundrobin bmask bit for ineligible FCF */ | |
2648 | lpfc_sli4_fcf_rr_index_clear(phba, fcf_index); | |
2649 | /* Perform next round of roundrobin FCF failover */ | |
2650 | fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); | |
2651 | rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index); | |
2652 | if (rc) | |
2653 | goto out; | |
2654 | goto error_out; | |
2655 | } | |
2656 | ||
2657 | if (fcf_index == phba->fcf.current_rec.fcf_indx) { | |
2658 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2659 | "2760 Perform FLOGI roundrobin FCF failover: " | |
2660 | "FCF (x%x) back to FCF (x%x)\n", | |
2661 | phba->fcf.current_rec.fcf_indx, fcf_index); | |
2662 | /* Wait 500 ms before retrying FLOGI to current FCF */ | |
2663 | msleep(500); | |
76a95d75 | 2664 | lpfc_issue_init_vfi(phba->pport); |
a93ff37a JS |
2665 | goto out; |
2666 | } | |
2667 | ||
0c9ab6f5 | 2668 | /* Upload new FCF record to the failover FCF record */ |
dbb6b3ab | 2669 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
2670 | "2834 Update current FCF (x%x) with new FCF (x%x)\n", |
2671 | phba->fcf.failover_rec.fcf_indx, fcf_index); | |
0c9ab6f5 JS |
2672 | spin_lock_irq(&phba->hbalock); |
2673 | __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec, | |
2674 | new_fcf_record, addr_mode, vlan_id, | |
2675 | (boot_flag ? BOOT_ENABLE : 0)); | |
2676 | spin_unlock_irq(&phba->hbalock); | |
2677 | ||
2678 | current_fcf_index = phba->fcf.current_rec.fcf_indx; | |
2679 | ||
2680 | /* Unregister the current in-use FCF record */ | |
2681 | lpfc_unregister_fcf(phba); | |
2682 | ||
2683 | /* Replace in-use record with the new record */ | |
2684 | memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec, | |
2685 | sizeof(struct lpfc_fcf_rec)); | |
2686 | ||
2687 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a JS |
2688 | "2783 Perform FLOGI roundrobin FCF failover: FCF " |
2689 | "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index); | |
0c9ab6f5 | 2690 | |
a93ff37a JS |
2691 | error_out: |
2692 | lpfc_register_fcf(phba); | |
0c9ab6f5 JS |
2693 | out: |
2694 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
0c9ab6f5 JS |
2695 | } |
2696 | ||
2697 | /** | |
2698 | * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler. | |
2699 | * @phba: pointer to lpfc hba data structure. | |
2700 | * @mboxq: pointer to mailbox object. | |
2701 | * | |
2702 | * This is the callback function of read FCF record mailbox command for | |
a93ff37a | 2703 | * updating the eligible FCF bmask for FLOGI failure roundrobin FCF |
0c9ab6f5 JS |
2704 | * failover when a new FCF event happened. If the FCF read back is |
2705 | * valid/available and it passes the connection list check, it updates | |
a93ff37a | 2706 | * the bmask for the eligible FCF record for roundrobin failover. |
0c9ab6f5 JS |
2707 | */ |
2708 | void | |
2709 | lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
2710 | { | |
2711 | struct fcf_record *new_fcf_record; | |
2712 | uint32_t boot_flag, addr_mode; | |
2713 | uint16_t fcf_index, next_fcf_index; | |
2714 | uint16_t vlan_id; | |
2715 | int rc; | |
2716 | ||
2717 | /* If link state is not up, no need to proceed */ | |
2718 | if (phba->link_state < LPFC_LINK_UP) | |
2719 | goto out; | |
2720 | ||
2721 | /* If FCF discovery period is over, no need to proceed */ | |
3804dc84 | 2722 | if (!(phba->fcf.fcf_flag & FCF_DISCOVERY)) |
0c9ab6f5 JS |
2723 | goto out; |
2724 | ||
2725 | /* Parse the FCF record from the non-embedded mailbox command */ | |
2726 | new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq, | |
2727 | &next_fcf_index); | |
2728 | if (!new_fcf_record) { | |
2729 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
2730 | "2767 Mailbox command READ_FCF_RECORD " | |
2731 | "failed to retrieve a FCF record.\n"); | |
2732 | goto out; | |
2733 | } | |
2734 | ||
2735 | /* Check the connection list for eligibility */ | |
2736 | rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag, | |
2737 | &addr_mode, &vlan_id); | |
2738 | ||
2739 | /* Log the FCF record information if turned on */ | |
2740 | lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id, | |
2741 | next_fcf_index); | |
2742 | ||
2743 | if (!rc) | |
2744 | goto out; | |
2745 | ||
2746 | /* Update the eligible FCF record index bmask */ | |
2747 | fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); | |
7d791df7 JS |
2748 | |
2749 | rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record); | |
0c9ab6f5 JS |
2750 | |
2751 | out: | |
2752 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
2753 | } | |
2754 | ||
76a95d75 JS |
2755 | /** |
2756 | * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command. | |
2757 | * @phba: pointer to lpfc hba data structure. | |
2758 | * @mboxq: pointer to mailbox data structure. | |
2759 | * | |
2760 | * This function handles completion of init vfi mailbox command. | |
2761 | */ | |
b86a6756 | 2762 | static void |
76a95d75 JS |
2763 | lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
2764 | { | |
2765 | struct lpfc_vport *vport = mboxq->vport; | |
2766 | ||
df9e1b59 JS |
2767 | /* |
2768 | * VFI not supported on interface type 0, just do the flogi | |
2769 | * Also continue if the VFI is in use - just use the same one. | |
2770 | */ | |
2771 | if (mboxq->u.mb.mbxStatus && | |
2772 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
2773 | LPFC_SLI_INTF_IF_TYPE_0) && | |
2774 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { | |
76a95d75 JS |
2775 | lpfc_printf_vlog(vport, KERN_ERR, |
2776 | LOG_MBOX, | |
2777 | "2891 Init VFI mailbox failed 0x%x\n", | |
2778 | mboxq->u.mb.mbxStatus); | |
2779 | mempool_free(mboxq, phba->mbox_mem_pool); | |
2780 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
2781 | return; | |
2782 | } | |
73d91e50 | 2783 | |
76a95d75 JS |
2784 | lpfc_initial_flogi(vport); |
2785 | mempool_free(mboxq, phba->mbox_mem_pool); | |
2786 | return; | |
2787 | } | |
2788 | ||
2789 | /** | |
2790 | * lpfc_issue_init_vfi - Issue init_vfi mailbox command. | |
2791 | * @vport: pointer to lpfc_vport data structure. | |
2792 | * | |
2793 | * This function issue a init_vfi mailbox command to initialize the VFI and | |
2794 | * VPI for the physical port. | |
2795 | */ | |
2796 | void | |
2797 | lpfc_issue_init_vfi(struct lpfc_vport *vport) | |
2798 | { | |
2799 | LPFC_MBOXQ_t *mboxq; | |
2800 | int rc; | |
2801 | struct lpfc_hba *phba = vport->phba; | |
2802 | ||
2803 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2804 | if (!mboxq) { | |
2805 | lpfc_printf_vlog(vport, KERN_ERR, | |
2806 | LOG_MBOX, "2892 Failed to allocate " | |
2807 | "init_vfi mailbox\n"); | |
2808 | return; | |
2809 | } | |
2810 | lpfc_init_vfi(mboxq, vport); | |
2811 | mboxq->mbox_cmpl = lpfc_init_vfi_cmpl; | |
2812 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
2813 | if (rc == MBX_NOT_FINISHED) { | |
2814 | lpfc_printf_vlog(vport, KERN_ERR, | |
2815 | LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n"); | |
2816 | mempool_free(mboxq, vport->phba->mbox_mem_pool); | |
2817 | } | |
2818 | } | |
2819 | ||
1c6834a7 JS |
2820 | /** |
2821 | * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command. | |
2822 | * @phba: pointer to lpfc hba data structure. | |
2823 | * @mboxq: pointer to mailbox data structure. | |
2824 | * | |
2825 | * This function handles completion of init vpi mailbox command. | |
2826 | */ | |
695a814e | 2827 | void |
1c6834a7 JS |
2828 | lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
2829 | { | |
2830 | struct lpfc_vport *vport = mboxq->vport; | |
695a814e | 2831 | struct lpfc_nodelist *ndlp; |
72100cc4 JS |
2832 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2833 | ||
1c6834a7 JS |
2834 | if (mboxq->u.mb.mbxStatus) { |
2835 | lpfc_printf_vlog(vport, KERN_ERR, | |
2836 | LOG_MBOX, | |
2837 | "2609 Init VPI mailbox failed 0x%x\n", | |
2838 | mboxq->u.mb.mbxStatus); | |
2839 | mempool_free(mboxq, phba->mbox_mem_pool); | |
2840 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
2841 | return; | |
2842 | } | |
72100cc4 | 2843 | spin_lock_irq(shost->host_lock); |
1c6834a7 | 2844 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
72100cc4 | 2845 | spin_unlock_irq(shost->host_lock); |
1c6834a7 | 2846 | |
695a814e JS |
2847 | /* If this port is physical port or FDISC is done, do reg_vpi */ |
2848 | if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) { | |
2849 | ndlp = lpfc_findnode_did(vport, Fabric_DID); | |
2850 | if (!ndlp) | |
2851 | lpfc_printf_vlog(vport, KERN_ERR, | |
2852 | LOG_DISCOVERY, | |
2853 | "2731 Cannot find fabric " | |
2854 | "controller node\n"); | |
2855 | else | |
2856 | lpfc_register_new_vport(phba, vport, ndlp); | |
2857 | mempool_free(mboxq, phba->mbox_mem_pool); | |
2858 | return; | |
2859 | } | |
2860 | ||
1c6834a7 JS |
2861 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
2862 | lpfc_initial_fdisc(vport); | |
2863 | else { | |
2864 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); | |
6a9c52cf JS |
2865 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
2866 | "2606 No NPIV Fabric support\n"); | |
1c6834a7 | 2867 | } |
695a814e | 2868 | mempool_free(mboxq, phba->mbox_mem_pool); |
1c6834a7 JS |
2869 | return; |
2870 | } | |
2871 | ||
ecfd03c6 JS |
2872 | /** |
2873 | * lpfc_issue_init_vpi - Issue init_vpi mailbox command. | |
2874 | * @vport: pointer to lpfc_vport data structure. | |
2875 | * | |
2876 | * This function issue a init_vpi mailbox command to initialize | |
2877 | * VPI for the vport. | |
2878 | */ | |
2879 | void | |
2880 | lpfc_issue_init_vpi(struct lpfc_vport *vport) | |
2881 | { | |
2882 | LPFC_MBOXQ_t *mboxq; | |
16a3a208 JS |
2883 | int rc, vpi; |
2884 | ||
2885 | if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) { | |
2886 | vpi = lpfc_alloc_vpi(vport->phba); | |
2887 | if (!vpi) { | |
2888 | lpfc_printf_vlog(vport, KERN_ERR, | |
2889 | LOG_MBOX, | |
2890 | "3303 Failed to obtain vport vpi\n"); | |
2891 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
2892 | return; | |
2893 | } | |
2894 | vport->vpi = vpi; | |
2895 | } | |
ecfd03c6 JS |
2896 | |
2897 | mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL); | |
2898 | if (!mboxq) { | |
2899 | lpfc_printf_vlog(vport, KERN_ERR, | |
2900 | LOG_MBOX, "2607 Failed to allocate " | |
2901 | "init_vpi mailbox\n"); | |
2902 | return; | |
2903 | } | |
2904 | lpfc_init_vpi(vport->phba, mboxq, vport->vpi); | |
2905 | mboxq->vport = vport; | |
2906 | mboxq->mbox_cmpl = lpfc_init_vpi_cmpl; | |
2907 | rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT); | |
2908 | if (rc == MBX_NOT_FINISHED) { | |
2909 | lpfc_printf_vlog(vport, KERN_ERR, | |
2910 | LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n"); | |
2911 | mempool_free(mboxq, vport->phba->mbox_mem_pool); | |
2912 | } | |
2913 | } | |
2914 | ||
6fb120a7 JS |
2915 | /** |
2916 | * lpfc_start_fdiscs - send fdiscs for each vports on this port. | |
2917 | * @phba: pointer to lpfc hba data structure. | |
2918 | * | |
2919 | * This function loops through the list of vports on the @phba and issues an | |
2920 | * FDISC if possible. | |
2921 | */ | |
2922 | void | |
2923 | lpfc_start_fdiscs(struct lpfc_hba *phba) | |
2924 | { | |
2925 | struct lpfc_vport **vports; | |
2926 | int i; | |
2927 | ||
2928 | vports = lpfc_create_vport_work_array(phba); | |
2929 | if (vports != NULL) { | |
2930 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
2931 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
2932 | continue; | |
2933 | /* There are no vpi for this vport */ | |
2934 | if (vports[i]->vpi > phba->max_vpi) { | |
2935 | lpfc_vport_set_state(vports[i], | |
2936 | FC_VPORT_FAILED); | |
2937 | continue; | |
2938 | } | |
76a95d75 | 2939 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
6fb120a7 JS |
2940 | lpfc_vport_set_state(vports[i], |
2941 | FC_VPORT_LINKDOWN); | |
2942 | continue; | |
2943 | } | |
1c6834a7 | 2944 | if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { |
ecfd03c6 | 2945 | lpfc_issue_init_vpi(vports[i]); |
1c6834a7 JS |
2946 | continue; |
2947 | } | |
6fb120a7 JS |
2948 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) |
2949 | lpfc_initial_fdisc(vports[i]); | |
2950 | else { | |
2951 | lpfc_vport_set_state(vports[i], | |
2952 | FC_VPORT_NO_FABRIC_SUPP); | |
2953 | lpfc_printf_vlog(vports[i], KERN_ERR, | |
2954 | LOG_ELS, | |
2955 | "0259 No NPIV " | |
2956 | "Fabric support\n"); | |
2957 | } | |
2958 | } | |
2959 | } | |
2960 | lpfc_destroy_vport_work_array(phba, vports); | |
2961 | } | |
2962 | ||
2963 | void | |
2964 | lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
2965 | { | |
3e1f0718 | 2966 | struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf; |
6fb120a7 | 2967 | struct lpfc_vport *vport = mboxq->vport; |
72100cc4 | 2968 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
6fb120a7 | 2969 | |
f5eca9be JS |
2970 | /* |
2971 | * VFI not supported for interface type 0, so ignore any mailbox | |
2972 | * error (except VFI in use) and continue with the discovery. | |
2973 | */ | |
2974 | if (mboxq->u.mb.mbxStatus && | |
2975 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
2976 | LPFC_SLI_INTF_IF_TYPE_0) && | |
2977 | mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) { | |
6fb120a7 JS |
2978 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
2979 | "2018 REG_VFI mbxStatus error x%x " | |
2980 | "HBA state x%x\n", | |
2981 | mboxq->u.mb.mbxStatus, vport->port_state); | |
76a95d75 | 2982 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
6fb120a7 JS |
2983 | /* FLOGI failed, use loop map to make discovery list */ |
2984 | lpfc_disc_list_loopmap(vport); | |
2985 | /* Start discovery */ | |
2986 | lpfc_disc_start(vport); | |
1b51197d | 2987 | goto out_free_mem; |
6fb120a7 JS |
2988 | } |
2989 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
1b51197d | 2990 | goto out_free_mem; |
6fb120a7 | 2991 | } |
ae05ebe3 | 2992 | |
e74c03c8 JS |
2993 | /* If the VFI is already registered, there is nothing else to do |
2994 | * Unless this was a VFI update and we are in PT2PT mode, then | |
2995 | * we should drop through to set the port state to ready. | |
2996 | */ | |
ae05ebe3 | 2997 | if (vport->fc_flag & FC_VFI_REGISTERED) |
e74c03c8 JS |
2998 | if (!(phba->sli_rev == LPFC_SLI_REV4 && |
2999 | vport->fc_flag & FC_PT2PT)) | |
3000 | goto out_free_mem; | |
ae05ebe3 | 3001 | |
c868595d | 3002 | /* The VPI is implicitly registered when the VFI is registered */ |
72100cc4 | 3003 | spin_lock_irq(shost->host_lock); |
c868595d | 3004 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
695a814e | 3005 | vport->fc_flag |= FC_VFI_REGISTERED; |
695a814e | 3006 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
5248a749 | 3007 | vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; |
72100cc4 | 3008 | spin_unlock_irq(shost->host_lock); |
6fb120a7 | 3009 | |
1b51197d JS |
3010 | /* In case SLI4 FC loopback test, we are ready */ |
3011 | if ((phba->sli_rev == LPFC_SLI_REV4) && | |
3012 | (phba->link_flag & LS_LOOPBACK_MODE)) { | |
3013 | phba->link_state = LPFC_HBA_READY; | |
3014 | goto out_free_mem; | |
3015 | } | |
3016 | ||
e74c03c8 JS |
3017 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
3018 | "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x " | |
3019 | "alpacnt:%d LinkState:%x topology:%x\n", | |
3020 | vport->port_state, vport->fc_flag, vport->fc_myDID, | |
3021 | vport->phba->alpa_map[0], | |
3022 | phba->link_state, phba->fc_topology); | |
3023 | ||
6fb120a7 | 3024 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
939723a4 JS |
3025 | /* |
3026 | * For private loop or for NPort pt2pt, | |
3027 | * just start discovery and we are done. | |
3028 | */ | |
3029 | if ((vport->fc_flag & FC_PT2PT) || | |
3030 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && | |
3031 | !(vport->fc_flag & FC_PUBLIC_LOOP))) { | |
3032 | ||
76a95d75 JS |
3033 | /* Use loop map to make discovery list */ |
3034 | lpfc_disc_list_loopmap(vport); | |
3035 | /* Start discovery */ | |
e74c03c8 JS |
3036 | if (vport->fc_flag & FC_PT2PT) |
3037 | vport->port_state = LPFC_VPORT_READY; | |
3038 | else | |
3039 | lpfc_disc_start(vport); | |
76a95d75 JS |
3040 | } else { |
3041 | lpfc_start_fdiscs(phba); | |
3042 | lpfc_do_scr_ns_plogi(phba, vport); | |
3043 | } | |
6fb120a7 JS |
3044 | } |
3045 | ||
1b51197d | 3046 | out_free_mem: |
6fb120a7 | 3047 | mempool_free(mboxq, phba->mbox_mem_pool); |
d6de08cc JS |
3048 | if (dmabuf) { |
3049 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); | |
3050 | kfree(dmabuf); | |
3051 | } | |
6fb120a7 JS |
3052 | return; |
3053 | } | |
3054 | ||
dea3101e | 3055 | static void |
2e0fef85 | 3056 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 3057 | { |
6fb120a7 | 3058 | MAILBOX_t *mb = &pmb->u.mb; |
3e1f0718 | 3059 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
2e0fef85 | 3060 | struct lpfc_vport *vport = pmb->vport; |
aeb3c817 | 3061 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
21bf0b97 JS |
3062 | struct serv_parm *sp = &vport->fc_sparam; |
3063 | uint32_t ed_tov; | |
dea3101e | 3064 | |
3065 | /* Check for error */ | |
3066 | if (mb->mbxStatus) { | |
3067 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ | |
e8b62011 JS |
3068 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
3069 | "0319 READ_SPARAM mbxStatus error x%x " | |
3070 | "hba state x%x>\n", | |
3071 | mb->mbxStatus, vport->port_state); | |
dea3101e | 3072 | lpfc_linkdown(phba); |
dea3101e | 3073 | goto out; |
3074 | } | |
3075 | ||
2e0fef85 | 3076 | memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt, |
dea3101e | 3077 | sizeof (struct serv_parm)); |
21bf0b97 JS |
3078 | |
3079 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); | |
3080 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ | |
3081 | ed_tov = (ed_tov + 999999) / 1000000; | |
3082 | ||
3083 | phba->fc_edtov = ed_tov; | |
3084 | phba->fc_ratov = (2 * ed_tov) / 1000; | |
3085 | if (phba->fc_ratov < FF_DEF_RATOV) { | |
3086 | /* RA_TOV should be atleast 10sec for initial flogi */ | |
3087 | phba->fc_ratov = FF_DEF_RATOV; | |
3088 | } | |
3089 | ||
0558056c | 3090 | lpfc_update_vport_wwn(vport); |
aeb3c817 | 3091 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
92d7f7b0 JS |
3092 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
3093 | memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn)); | |
3094 | memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn)); | |
3095 | } | |
3096 | ||
dea3101e | 3097 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3098 | kfree(mp); | |
2e0fef85 | 3099 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 3100 | return; |
3101 | ||
3102 | out: | |
3e1f0718 | 3103 | pmb->ctx_buf = NULL; |
dea3101e | 3104 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3105 | kfree(mp); | |
92d7f7b0 JS |
3106 | lpfc_issue_clear_la(phba, vport); |
3107 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 3108 | return; |
3109 | } | |
3110 | ||
3111 | static void | |
76a95d75 | 3112 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la) |
dea3101e | 3113 | { |
92d7f7b0 | 3114 | struct lpfc_vport *vport = phba->pport; |
6fb120a7 | 3115 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL; |
df9e1b59 | 3116 | struct Scsi_Host *shost; |
2e0fef85 | 3117 | int i; |
14691150 JS |
3118 | struct lpfc_dmabuf *mp; |
3119 | int rc; | |
6fb120a7 | 3120 | struct fcf_record *fcf_record; |
38c20673 | 3121 | uint32_t fc_flags = 0; |
894bb17f | 3122 | unsigned long iflags; |
14691150 | 3123 | |
894bb17f | 3124 | spin_lock_irqsave(&phba->hbalock, iflags); |
a085e87c JS |
3125 | phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la); |
3126 | ||
3127 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3128 | switch (bf_get(lpfc_mbx_read_top_link_spd, la)) { | |
3129 | case LPFC_LINK_SPEED_1GHZ: | |
3130 | case LPFC_LINK_SPEED_2GHZ: | |
3131 | case LPFC_LINK_SPEED_4GHZ: | |
3132 | case LPFC_LINK_SPEED_8GHZ: | |
3133 | case LPFC_LINK_SPEED_10GHZ: | |
3134 | case LPFC_LINK_SPEED_16GHZ: | |
3135 | case LPFC_LINK_SPEED_32GHZ: | |
fbd8a6ba | 3136 | case LPFC_LINK_SPEED_64GHZ: |
1dc5ec24 | 3137 | case LPFC_LINK_SPEED_128GHZ: |
a085e87c JS |
3138 | break; |
3139 | default: | |
3140 | phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN; | |
3141 | break; | |
3142 | } | |
dea3101e | 3143 | } |
3144 | ||
e74c03c8 JS |
3145 | if (phba->fc_topology && |
3146 | phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) { | |
3147 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3148 | "3314 Toplogy changed was 0x%x is 0x%x\n", | |
3149 | phba->fc_topology, | |
3150 | bf_get(lpfc_mbx_read_top_topology, la)); | |
3151 | phba->fc_topology_changed = 1; | |
3152 | } | |
3153 | ||
76a95d75 | 3154 | phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la); |
92d7f7b0 | 3155 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
dea3101e | 3156 | |
df9e1b59 | 3157 | shost = lpfc_shost_from_vport(vport); |
76a95d75 | 3158 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
92d7f7b0 | 3159 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
dea3101e | 3160 | |
6a9c52cf JS |
3161 | /* if npiv is enabled and this adapter supports npiv log |
3162 | * a message that npiv is not supported in this topology | |
3163 | */ | |
3164 | if (phba->cfg_enable_npiv && phba->max_vpi) | |
495a714c JS |
3165 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
3166 | "1309 Link Up Event npiv not supported in loop " | |
3167 | "topology\n"); | |
92d7f7b0 | 3168 | /* Get Loop Map information */ |
38c20673 JS |
3169 | if (bf_get(lpfc_mbx_read_top_il, la)) |
3170 | fc_flags |= FC_LBIT; | |
dea3101e | 3171 | |
76a95d75 JS |
3172 | vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la); |
3173 | i = la->lilpBde64.tus.f.bdeSize; | |
dea3101e | 3174 | |
3175 | if (i == 0) { | |
3176 | phba->alpa_map[0] = 0; | |
3177 | } else { | |
e8b62011 | 3178 | if (vport->cfg_log_verbose & LOG_LINK_EVENT) { |
dea3101e | 3179 | int numalpa, j, k; |
3180 | union { | |
3181 | uint8_t pamap[16]; | |
3182 | struct { | |
3183 | uint32_t wd1; | |
3184 | uint32_t wd2; | |
3185 | uint32_t wd3; | |
3186 | uint32_t wd4; | |
3187 | } pa; | |
3188 | } un; | |
3189 | numalpa = phba->alpa_map[0]; | |
3190 | j = 0; | |
3191 | while (j < numalpa) { | |
3192 | memset(un.pamap, 0, 16); | |
3193 | for (k = 1; j < numalpa; k++) { | |
3194 | un.pamap[k - 1] = | |
3195 | phba->alpa_map[j + 1]; | |
3196 | j++; | |
3197 | if (k == 16) | |
3198 | break; | |
3199 | } | |
3200 | /* Link Up Event ALPA map */ | |
3201 | lpfc_printf_log(phba, | |
92d7f7b0 JS |
3202 | KERN_WARNING, |
3203 | LOG_LINK_EVENT, | |
e8b62011 | 3204 | "1304 Link Up Event " |
92d7f7b0 JS |
3205 | "ALPA map Data: x%x " |
3206 | "x%x x%x x%x\n", | |
92d7f7b0 JS |
3207 | un.pa.wd1, un.pa.wd2, |
3208 | un.pa.wd3, un.pa.wd4); | |
dea3101e | 3209 | } |
3210 | } | |
3211 | } | |
3212 | } else { | |
92d7f7b0 | 3213 | if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) { |
78b2d852 | 3214 | if (phba->max_vpi && phba->cfg_enable_npiv && |
df9e1b59 | 3215 | (phba->sli_rev >= LPFC_SLI_REV3)) |
92d7f7b0 JS |
3216 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
3217 | } | |
2e0fef85 | 3218 | vport->fc_myDID = phba->fc_pref_DID; |
38c20673 | 3219 | fc_flags |= FC_LBIT; |
dea3101e | 3220 | } |
894bb17f | 3221 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e | 3222 | |
38c20673 | 3223 | if (fc_flags) { |
894bb17f | 3224 | spin_lock_irqsave(shost->host_lock, iflags); |
38c20673 | 3225 | vport->fc_flag |= fc_flags; |
894bb17f | 3226 | spin_unlock_irqrestore(shost->host_lock, iflags); |
38c20673 JS |
3227 | } |
3228 | ||
dea3101e | 3229 | lpfc_linkup(phba); |
9f1177a3 JS |
3230 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3231 | if (!sparam_mbox) | |
3232 | goto out; | |
3233 | ||
3234 | rc = lpfc_read_sparam(phba, sparam_mbox, 0); | |
3235 | if (rc) { | |
3236 | mempool_free(sparam_mbox, phba->mbox_mem_pool); | |
3237 | goto out; | |
3238 | } | |
3239 | sparam_mbox->vport = vport; | |
3240 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; | |
3241 | rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT); | |
3242 | if (rc == MBX_NOT_FINISHED) { | |
3e1f0718 | 3243 | mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf; |
9f1177a3 JS |
3244 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3245 | kfree(mp); | |
3246 | mempool_free(sparam_mbox, phba->mbox_mem_pool); | |
3247 | goto out; | |
dea3101e | 3248 | } |
3249 | ||
76a95d75 | 3250 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6fb120a7 JS |
3251 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3252 | if (!cfglink_mbox) | |
3253 | goto out; | |
2e0fef85 | 3254 | vport->port_state = LPFC_LOCAL_CFG_LINK; |
dea3101e | 3255 | lpfc_config_link(phba, cfglink_mbox); |
2e0fef85 | 3256 | cfglink_mbox->vport = vport; |
25594c6b | 3257 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
0b727fea | 3258 | rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT); |
6fb120a7 JS |
3259 | if (rc == MBX_NOT_FINISHED) { |
3260 | mempool_free(cfglink_mbox, phba->mbox_mem_pool); | |
3261 | goto out; | |
3262 | } | |
3263 | } else { | |
32b9793f | 3264 | vport->port_state = LPFC_VPORT_UNKNOWN; |
6fb120a7 JS |
3265 | /* |
3266 | * Add the driver's default FCF record at FCF index 0 now. This | |
3267 | * is phase 1 implementation that support FCF index 0 and driver | |
3268 | * defaults. | |
3269 | */ | |
45ed1190 | 3270 | if (!(phba->hba_flag & HBA_FIP_SUPPORT)) { |
6fb120a7 JS |
3271 | fcf_record = kzalloc(sizeof(struct fcf_record), |
3272 | GFP_KERNEL); | |
3273 | if (unlikely(!fcf_record)) { | |
3274 | lpfc_printf_log(phba, KERN_ERR, | |
3275 | LOG_MBOX | LOG_SLI, | |
b595076a | 3276 | "2554 Could not allocate memory for " |
6fb120a7 JS |
3277 | "fcf record\n"); |
3278 | rc = -ENODEV; | |
3279 | goto out; | |
3280 | } | |
3281 | ||
3282 | lpfc_sli4_build_dflt_fcf_record(phba, fcf_record, | |
3283 | LPFC_FCOE_FCF_DEF_INDEX); | |
3284 | rc = lpfc_sli4_add_fcf_record(phba, fcf_record); | |
3285 | if (unlikely(rc)) { | |
3286 | lpfc_printf_log(phba, KERN_ERR, | |
3287 | LOG_MBOX | LOG_SLI, | |
3288 | "2013 Could not manually add FCF " | |
3289 | "record 0, status %d\n", rc); | |
3290 | rc = -ENODEV; | |
3291 | kfree(fcf_record); | |
3292 | goto out; | |
3293 | } | |
3294 | kfree(fcf_record); | |
3295 | } | |
3296 | /* | |
3297 | * The driver is expected to do FIP/FCF. Call the port | |
3298 | * and get the FCF Table. | |
3299 | */ | |
894bb17f | 3300 | spin_lock_irqsave(&phba->hbalock, iflags); |
a93ff37a | 3301 | if (phba->hba_flag & FCF_TS_INPROG) { |
894bb17f | 3302 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
32b9793f JS |
3303 | return; |
3304 | } | |
0c9ab6f5 JS |
3305 | /* This is the initial FCF discovery scan */ |
3306 | phba->fcf.fcf_flag |= FCF_INIT_DISC; | |
894bb17f | 3307 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
0c9ab6f5 JS |
3308 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3309 | "2778 Start FCF table scan at linkup\n"); | |
0c9ab6f5 JS |
3310 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
3311 | LPFC_FCOE_FCF_GET_FIRST); | |
3312 | if (rc) { | |
894bb17f | 3313 | spin_lock_irqsave(&phba->hbalock, iflags); |
0c9ab6f5 | 3314 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; |
894bb17f | 3315 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
6fb120a7 | 3316 | goto out; |
0c9ab6f5 | 3317 | } |
38b92ef8 | 3318 | /* Reset FCF roundrobin bmask for new discovery */ |
7d791df7 | 3319 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
dea3101e | 3320 | } |
6fb120a7 JS |
3321 | |
3322 | return; | |
92d7f7b0 JS |
3323 | out: |
3324 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
3325 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
3326 | "0263 Discovery Mailbox error: state: 0x%x : %p %p\n", | |
3327 | vport->port_state, sparam_mbox, cfglink_mbox); | |
92d7f7b0 JS |
3328 | lpfc_issue_clear_la(phba, vport); |
3329 | return; | |
dea3101e | 3330 | } |
3331 | ||
3332 | static void | |
84774a4d | 3333 | lpfc_enable_la(struct lpfc_hba *phba) |
2e0fef85 | 3334 | { |
dea3101e | 3335 | uint32_t control; |
3336 | struct lpfc_sli *psli = &phba->sli; | |
2e0fef85 | 3337 | spin_lock_irq(&phba->hbalock); |
dea3101e | 3338 | psli->sli_flag |= LPFC_PROCESS_LA; |
3772a991 JS |
3339 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
3340 | control = readl(phba->HCregaddr); | |
3341 | control |= HC_LAINT_ENA; | |
3342 | writel(control, phba->HCregaddr); | |
3343 | readl(phba->HCregaddr); /* flush */ | |
3344 | } | |
2e0fef85 | 3345 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3346 | } |
3347 | ||
84774a4d JS |
3348 | static void |
3349 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) | |
3350 | { | |
3351 | lpfc_linkdown(phba); | |
3352 | lpfc_enable_la(phba); | |
6fb120a7 | 3353 | lpfc_unregister_unused_fcf(phba); |
84774a4d JS |
3354 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ |
3355 | } | |
3356 | ||
3357 | ||
dea3101e | 3358 | /* |
76a95d75 | 3359 | * This routine handles processing a READ_TOPOLOGY mailbox |
dea3101e | 3360 | * command upon completion. It is setup in the LPFC_MBOXQ |
3361 | * as the completion routine when the command is | |
895427bd | 3362 | * handed off to the SLI layer. SLI4 only. |
dea3101e | 3363 | */ |
3364 | void | |
76a95d75 | 3365 | lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 3366 | { |
2e0fef85 JS |
3367 | struct lpfc_vport *vport = pmb->vport; |
3368 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
76a95d75 | 3369 | struct lpfc_mbx_read_top *la; |
895427bd | 3370 | struct lpfc_sli_ring *pring; |
04c68496 | 3371 | MAILBOX_t *mb = &pmb->u.mb; |
3e1f0718 | 3372 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
aeb3c817 | 3373 | uint8_t attn_type; |
894bb17f | 3374 | unsigned long iflags; |
dea3101e | 3375 | |
0d2b6b83 | 3376 | /* Unblock ELS traffic */ |
895427bd | 3377 | pring = lpfc_phba_elsring(phba); |
1234a6d5 DK |
3378 | if (pring) |
3379 | pring->flag &= ~LPFC_STOP_IOCB_EVENT; | |
895427bd | 3380 | |
dea3101e | 3381 | /* Check for error */ |
3382 | if (mb->mbxStatus) { | |
ed957684 | 3383 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
e8b62011 JS |
3384 | "1307 READ_LA mbox error x%x state x%x\n", |
3385 | mb->mbxStatus, vport->port_state); | |
dea3101e | 3386 | lpfc_mbx_issue_link_down(phba); |
2e0fef85 | 3387 | phba->link_state = LPFC_HBA_ERROR; |
76a95d75 | 3388 | goto lpfc_mbx_cmpl_read_topology_free_mbuf; |
dea3101e | 3389 | } |
3390 | ||
76a95d75 | 3391 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
aeb3c817 | 3392 | attn_type = bf_get(lpfc_mbx_read_top_att_type, la); |
dea3101e | 3393 | |
3394 | memcpy(&phba->alpa_map[0], mp->virt, 128); | |
3395 | ||
894bb17f | 3396 | spin_lock_irqsave(shost->host_lock, iflags); |
76a95d75 | 3397 | if (bf_get(lpfc_mbx_read_top_pb, la)) |
2e0fef85 | 3398 | vport->fc_flag |= FC_BYPASSED_MODE; |
c9f8735b | 3399 | else |
2e0fef85 | 3400 | vport->fc_flag &= ~FC_BYPASSED_MODE; |
894bb17f | 3401 | spin_unlock_irqrestore(shost->host_lock, iflags); |
c9f8735b | 3402 | |
be0c0080 | 3403 | if (phba->fc_eventTag <= la->eventTag) { |
dea3101e | 3404 | phba->fc_stat.LinkMultiEvent++; |
aeb3c817 | 3405 | if (attn_type == LPFC_ATT_LINK_UP) |
dea3101e | 3406 | if (phba->fc_eventTag != 0) |
3407 | lpfc_linkdown(phba); | |
92d7f7b0 | 3408 | } |
dea3101e | 3409 | |
3410 | phba->fc_eventTag = la->eventTag; | |
be0c0080 | 3411 | if (phba->sli_rev < LPFC_SLI_REV4) { |
894bb17f | 3412 | spin_lock_irqsave(&phba->hbalock, iflags); |
be0c0080 JS |
3413 | if (bf_get(lpfc_mbx_read_top_mm, la)) |
3414 | phba->sli.sli_flag |= LPFC_MENLO_MAINT; | |
3415 | else | |
3416 | phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; | |
894bb17f | 3417 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
be0c0080 | 3418 | } |
dea3101e | 3419 | |
4d9ab994 | 3420 | phba->link_events++; |
aeb3c817 | 3421 | if ((attn_type == LPFC_ATT_LINK_UP) && |
be0c0080 | 3422 | !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) { |
dea3101e | 3423 | phba->fc_stat.LinkUp++; |
2e0fef85 | 3424 | if (phba->link_flag & LS_LOOPBACK_MODE) { |
3163f725 | 3425 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
e8b62011 JS |
3426 | "1306 Link Up Event in loop back mode " |
3427 | "x%x received Data: x%x x%x x%x x%x\n", | |
3428 | la->eventTag, phba->fc_eventTag, | |
76a95d75 JS |
3429 | bf_get(lpfc_mbx_read_top_alpa_granted, |
3430 | la), | |
3431 | bf_get(lpfc_mbx_read_top_link_spd, la), | |
e8b62011 | 3432 | phba->alpa_map[0]); |
5b8bd0c9 JS |
3433 | } else { |
3434 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
e8b62011 | 3435 | "1303 Link Up Event x%x received " |
84774a4d | 3436 | "Data: x%x x%x x%x x%x x%x x%x %d\n", |
e8b62011 | 3437 | la->eventTag, phba->fc_eventTag, |
76a95d75 JS |
3438 | bf_get(lpfc_mbx_read_top_alpa_granted, |
3439 | la), | |
3440 | bf_get(lpfc_mbx_read_top_link_spd, la), | |
84774a4d | 3441 | phba->alpa_map[0], |
76a95d75 JS |
3442 | bf_get(lpfc_mbx_read_top_mm, la), |
3443 | bf_get(lpfc_mbx_read_top_fa, la), | |
84774a4d | 3444 | phba->wait_4_mlo_maint_flg); |
5b8bd0c9 | 3445 | } |
92d7f7b0 | 3446 | lpfc_mbx_process_link_up(phba, la); |
aeb3c817 JS |
3447 | } else if (attn_type == LPFC_ATT_LINK_DOWN || |
3448 | attn_type == LPFC_ATT_UNEXP_WWPN) { | |
dea3101e | 3449 | phba->fc_stat.LinkDown++; |
1b51197d | 3450 | if (phba->link_flag & LS_LOOPBACK_MODE) |
3163f725 JS |
3451 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
3452 | "1308 Link Down Event in loop back mode " | |
3453 | "x%x received " | |
3454 | "Data: x%x x%x x%x\n", | |
3455 | la->eventTag, phba->fc_eventTag, | |
3456 | phba->pport->port_state, vport->fc_flag); | |
aeb3c817 JS |
3457 | else if (attn_type == LPFC_ATT_UNEXP_WWPN) |
3458 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
3459 | "1313 Link Down UNEXP WWPN Event x%x received " | |
3460 | "Data: x%x x%x x%x x%x x%x\n", | |
3461 | la->eventTag, phba->fc_eventTag, | |
3462 | phba->pport->port_state, vport->fc_flag, | |
3463 | bf_get(lpfc_mbx_read_top_mm, la), | |
3464 | bf_get(lpfc_mbx_read_top_fa, la)); | |
1b51197d | 3465 | else |
3163f725 | 3466 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
e8b62011 | 3467 | "1305 Link Down Event x%x received " |
84774a4d JS |
3468 | "Data: x%x x%x x%x x%x x%x\n", |
3469 | la->eventTag, phba->fc_eventTag, | |
3470 | phba->pport->port_state, vport->fc_flag, | |
76a95d75 JS |
3471 | bf_get(lpfc_mbx_read_top_mm, la), |
3472 | bf_get(lpfc_mbx_read_top_fa, la)); | |
84774a4d JS |
3473 | lpfc_mbx_issue_link_down(phba); |
3474 | } | |
aeb3c817 JS |
3475 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT && |
3476 | attn_type == LPFC_ATT_LINK_UP) { | |
84774a4d JS |
3477 | if (phba->link_state != LPFC_LINK_DOWN) { |
3478 | phba->fc_stat.LinkDown++; | |
3479 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
3480 | "1312 Link Down Event x%x received " | |
dea3101e | 3481 | "Data: x%x x%x x%x\n", |
e8b62011 | 3482 | la->eventTag, phba->fc_eventTag, |
2e0fef85 | 3483 | phba->pport->port_state, vport->fc_flag); |
84774a4d JS |
3484 | lpfc_mbx_issue_link_down(phba); |
3485 | } else | |
3486 | lpfc_enable_la(phba); | |
3487 | ||
3488 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
3489 | "1310 Menlo Maint Mode Link up Event x%x rcvd " | |
3490 | "Data: x%x x%x x%x\n", | |
3491 | la->eventTag, phba->fc_eventTag, | |
3492 | phba->pport->port_state, vport->fc_flag); | |
3493 | /* | |
3494 | * The cmnd that triggered this will be waiting for this | |
3495 | * signal. | |
3496 | */ | |
3497 | /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */ | |
3498 | if (phba->wait_4_mlo_maint_flg) { | |
3499 | phba->wait_4_mlo_maint_flg = 0; | |
3500 | wake_up_interruptible(&phba->wait_4_mlo_m_q); | |
3163f725 | 3501 | } |
84774a4d JS |
3502 | } |
3503 | ||
be0c0080 JS |
3504 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
3505 | bf_get(lpfc_mbx_read_top_fa, la)) { | |
3506 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) | |
84774a4d JS |
3507 | lpfc_issue_clear_la(phba, vport); |
3508 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
76a95d75 JS |
3509 | "1311 fa %d\n", |
3510 | bf_get(lpfc_mbx_read_top_fa, la)); | |
dea3101e | 3511 | } |
3512 | ||
76a95d75 | 3513 | lpfc_mbx_cmpl_read_topology_free_mbuf: |
dea3101e | 3514 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3515 | kfree(mp); | |
3516 | mempool_free(pmb, phba->mbox_mem_pool); | |
3517 | return; | |
3518 | } | |
3519 | ||
3520 | /* | |
3521 | * This routine handles processing a REG_LOGIN mailbox | |
3522 | * command upon completion. It is setup in the LPFC_MBOXQ | |
3523 | * as the completion routine when the command is | |
3524 | * handed off to the SLI layer. | |
3525 | */ | |
3526 | void | |
2e0fef85 | 3527 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 3528 | { |
2e0fef85 | 3529 | struct lpfc_vport *vport = pmb->vport; |
3e1f0718 JS |
3530 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
3531 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; | |
ffc95493 | 3532 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 3533 | |
3e1f0718 JS |
3534 | pmb->ctx_buf = NULL; |
3535 | pmb->ctx_ndlp = NULL; | |
dea3101e | 3536 | |
be6bb941 JS |
3537 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
3538 | "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", | |
3539 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 3540 | kref_read(&ndlp->kref), |
be6bb941 | 3541 | ndlp->nlp_usg_map, ndlp); |
ffc95493 JS |
3542 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
3543 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; | |
3544 | ||
4042629e JS |
3545 | if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL || |
3546 | ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) { | |
ffc95493 JS |
3547 | /* We rcvd a rscn after issuing this |
3548 | * mbox reg login, we may have cycled | |
3549 | * back through the state and be | |
3550 | * back at reg login state so this | |
3551 | * mbox needs to be ignored becase | |
3552 | * there is another reg login in | |
25985edc | 3553 | * process. |
ffc95493 JS |
3554 | */ |
3555 | spin_lock_irq(shost->host_lock); | |
3556 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
3557 | spin_unlock_irq(shost->host_lock); | |
895427bd JS |
3558 | |
3559 | /* | |
3560 | * We cannot leave the RPI registered because | |
3561 | * if we go thru discovery again for this ndlp | |
3562 | * a subsequent REG_RPI will fail. | |
3563 | */ | |
3564 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; | |
3565 | lpfc_unreg_rpi(vport, ndlp); | |
4b7789b7 JS |
3566 | } |
3567 | ||
3568 | /* Call state machine */ | |
3569 | lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); | |
ffc95493 | 3570 | |
dea3101e | 3571 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3572 | kfree(mp); | |
2e0fef85 | 3573 | mempool_free(pmb, phba->mbox_mem_pool); |
fa4066b6 JS |
3574 | /* decrement the node reference count held for this callback |
3575 | * function. | |
3576 | */ | |
329f9bc7 | 3577 | lpfc_nlp_put(ndlp); |
dea3101e | 3578 | |
3579 | return; | |
3580 | } | |
3581 | ||
92d7f7b0 JS |
3582 | static void |
3583 | lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
3584 | { | |
04c68496 | 3585 | MAILBOX_t *mb = &pmb->u.mb; |
92d7f7b0 JS |
3586 | struct lpfc_vport *vport = pmb->vport; |
3587 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
3588 | ||
3589 | switch (mb->mbxStatus) { | |
3590 | case 0x0011: | |
3591 | case 0x0020: | |
e8b62011 JS |
3592 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
3593 | "0911 cmpl_unreg_vpi, mb status = 0x%x\n", | |
3594 | mb->mbxStatus); | |
92d7f7b0 | 3595 | break; |
78730cfe JS |
3596 | /* If VPI is busy, reset the HBA */ |
3597 | case 0x9700: | |
3598 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, | |
3599 | "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n", | |
3600 | vport->vpi, mb->mbxStatus); | |
3601 | if (!(phba->pport->load_flag & FC_UNLOADING)) | |
3602 | lpfc_workq_post_event(phba, NULL, NULL, | |
3603 | LPFC_EVT_RESET_HBA); | |
92d7f7b0 | 3604 | } |
72100cc4 | 3605 | spin_lock_irq(shost->host_lock); |
c868595d | 3606 | vport->vpi_state &= ~LPFC_VPI_REGISTERED; |
1987807d | 3607 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
72100cc4 | 3608 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
3609 | vport->unreg_vpi_cmpl = VPORT_OK; |
3610 | mempool_free(pmb, phba->mbox_mem_pool); | |
1151e3ec | 3611 | lpfc_cleanup_vports_rrqs(vport, NULL); |
92d7f7b0 JS |
3612 | /* |
3613 | * This shost reference might have been taken at the beginning of | |
3614 | * lpfc_vport_delete() | |
3615 | */ | |
1c6f4ef5 | 3616 | if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport)) |
92d7f7b0 JS |
3617 | scsi_host_put(shost); |
3618 | } | |
3619 | ||
d7c255b2 | 3620 | int |
92d7f7b0 JS |
3621 | lpfc_mbx_unreg_vpi(struct lpfc_vport *vport) |
3622 | { | |
3623 | struct lpfc_hba *phba = vport->phba; | |
3624 | LPFC_MBOXQ_t *mbox; | |
3625 | int rc; | |
3626 | ||
3627 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3628 | if (!mbox) | |
d7c255b2 | 3629 | return 1; |
92d7f7b0 JS |
3630 | |
3631 | lpfc_unreg_vpi(phba, vport->vpi, mbox); | |
3632 | mbox->vport = vport; | |
3633 | mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi; | |
0b727fea | 3634 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
92d7f7b0 | 3635 | if (rc == MBX_NOT_FINISHED) { |
e8b62011 JS |
3636 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
3637 | "1800 Could not issue unreg_vpi\n"); | |
92d7f7b0 JS |
3638 | mempool_free(mbox, phba->mbox_mem_pool); |
3639 | vport->unreg_vpi_cmpl = VPORT_ERROR; | |
d7c255b2 | 3640 | return rc; |
92d7f7b0 | 3641 | } |
d7c255b2 | 3642 | return 0; |
92d7f7b0 JS |
3643 | } |
3644 | ||
3645 | static void | |
3646 | lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
3647 | { | |
3648 | struct lpfc_vport *vport = pmb->vport; | |
3649 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
04c68496 | 3650 | MAILBOX_t *mb = &pmb->u.mb; |
92d7f7b0 JS |
3651 | |
3652 | switch (mb->mbxStatus) { | |
3653 | case 0x0011: | |
3654 | case 0x9601: | |
3655 | case 0x9602: | |
e8b62011 JS |
3656 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
3657 | "0912 cmpl_reg_vpi, mb status = 0x%x\n", | |
3658 | mb->mbxStatus); | |
92d7f7b0 JS |
3659 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
3660 | spin_lock_irq(shost->host_lock); | |
3661 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); | |
3662 | spin_unlock_irq(shost->host_lock); | |
3663 | vport->fc_myDID = 0; | |
a0f2d3ef | 3664 | |
f6e84790 JS |
3665 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
3666 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { | |
d613b6a7 JS |
3667 | if (phba->nvmet_support) |
3668 | lpfc_nvmet_update_targetport(phba); | |
3669 | else | |
8c258641 | 3670 | lpfc_nvme_update_localport(vport); |
8c258641 | 3671 | } |
92d7f7b0 JS |
3672 | goto out; |
3673 | } | |
92d7f7b0 | 3674 | |
72100cc4 | 3675 | spin_lock_irq(shost->host_lock); |
c868595d | 3676 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
695a814e | 3677 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
72100cc4 | 3678 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 JS |
3679 | vport->num_disc_nodes = 0; |
3680 | /* go thru NPR list and issue ELS PLOGIs */ | |
3681 | if (vport->fc_npr_cnt) | |
3682 | lpfc_els_disc_plogi(vport); | |
3683 | ||
3684 | if (!vport->num_disc_nodes) { | |
3685 | spin_lock_irq(shost->host_lock); | |
3686 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
3687 | spin_unlock_irq(shost->host_lock); | |
3688 | lpfc_can_disctmo(vport); | |
3689 | } | |
3690 | vport->port_state = LPFC_VPORT_READY; | |
3691 | ||
3692 | out: | |
3693 | mempool_free(pmb, phba->mbox_mem_pool); | |
3694 | return; | |
3695 | } | |
3696 | ||
21e9a0a5 JS |
3697 | /** |
3698 | * lpfc_create_static_vport - Read HBA config region to create static vports. | |
3699 | * @phba: pointer to lpfc hba data structure. | |
3700 | * | |
3701 | * This routine issue a DUMP mailbox command for config region 22 to get | |
3702 | * the list of static vports to be created. The function create vports | |
3703 | * based on the information returned from the HBA. | |
3704 | **/ | |
3705 | void | |
3706 | lpfc_create_static_vport(struct lpfc_hba *phba) | |
3707 | { | |
3708 | LPFC_MBOXQ_t *pmb = NULL; | |
3709 | MAILBOX_t *mb; | |
3710 | struct static_vport_info *vport_info; | |
cdcc2343 | 3711 | int mbx_wait_rc = 0, i; |
21e9a0a5 JS |
3712 | struct fc_vport_identifiers vport_id; |
3713 | struct fc_vport *new_fc_vport; | |
3714 | struct Scsi_Host *shost; | |
3715 | struct lpfc_vport *vport; | |
3716 | uint16_t offset = 0; | |
3717 | uint8_t *vport_buff; | |
1c6834a7 JS |
3718 | struct lpfc_dmabuf *mp; |
3719 | uint32_t byte_count = 0; | |
21e9a0a5 JS |
3720 | |
3721 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3722 | if (!pmb) { | |
3723 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3724 | "0542 lpfc_create_static_vport failed to" | |
3725 | " allocate mailbox memory\n"); | |
3726 | return; | |
3727 | } | |
cdcc2343 | 3728 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
21e9a0a5 JS |
3729 | mb = &pmb->u.mb; |
3730 | ||
3731 | vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL); | |
3732 | if (!vport_info) { | |
3733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3734 | "0543 lpfc_create_static_vport failed to" | |
3735 | " allocate vport_info\n"); | |
3736 | mempool_free(pmb, phba->mbox_mem_pool); | |
3737 | return; | |
3738 | } | |
3739 | ||
3740 | vport_buff = (uint8_t *) vport_info; | |
3741 | do { | |
cdcc2343 | 3742 | /* free dma buffer from previous round */ |
3e1f0718 JS |
3743 | if (pmb->ctx_buf) { |
3744 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; | |
cdcc2343 JS |
3745 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3746 | kfree(mp); | |
3747 | } | |
1c6834a7 JS |
3748 | if (lpfc_dump_static_vport(phba, pmb, offset)) |
3749 | goto out; | |
3750 | ||
21e9a0a5 | 3751 | pmb->vport = phba->pport; |
cdcc2343 JS |
3752 | mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb, |
3753 | LPFC_MBOX_TMO); | |
21e9a0a5 | 3754 | |
cdcc2343 | 3755 | if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) { |
21e9a0a5 JS |
3756 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
3757 | "0544 lpfc_create_static_vport failed to" | |
3758 | " issue dump mailbox command ret 0x%x " | |
3759 | "status 0x%x\n", | |
cdcc2343 | 3760 | mbx_wait_rc, mb->mbxStatus); |
21e9a0a5 JS |
3761 | goto out; |
3762 | } | |
3763 | ||
1c6834a7 JS |
3764 | if (phba->sli_rev == LPFC_SLI_REV4) { |
3765 | byte_count = pmb->u.mqe.un.mb_words[5]; | |
3e1f0718 | 3766 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
1c6834a7 JS |
3767 | if (byte_count > sizeof(struct static_vport_info) - |
3768 | offset) | |
3769 | byte_count = sizeof(struct static_vport_info) | |
3770 | - offset; | |
3771 | memcpy(vport_buff + offset, mp->virt, byte_count); | |
3772 | offset += byte_count; | |
3773 | } else { | |
3774 | if (mb->un.varDmp.word_cnt > | |
3775 | sizeof(struct static_vport_info) - offset) | |
3776 | mb->un.varDmp.word_cnt = | |
3777 | sizeof(struct static_vport_info) | |
3778 | - offset; | |
3779 | byte_count = mb->un.varDmp.word_cnt; | |
3780 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
3781 | vport_buff + offset, | |
3782 | byte_count); | |
3783 | ||
3784 | offset += byte_count; | |
3785 | } | |
21e9a0a5 | 3786 | |
1c6834a7 | 3787 | } while (byte_count && |
21e9a0a5 JS |
3788 | offset < sizeof(struct static_vport_info)); |
3789 | ||
3790 | ||
3791 | if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) || | |
3792 | ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK) | |
3793 | != VPORT_INFO_REV)) { | |
3794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3795 | "0545 lpfc_create_static_vport bad" | |
3796 | " information header 0x%x 0x%x\n", | |
3797 | le32_to_cpu(vport_info->signature), | |
3798 | le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK); | |
3799 | ||
3800 | goto out; | |
3801 | } | |
3802 | ||
3803 | shost = lpfc_shost_from_vport(phba->pport); | |
3804 | ||
3805 | for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) { | |
3806 | memset(&vport_id, 0, sizeof(vport_id)); | |
3807 | vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn); | |
3808 | vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn); | |
3809 | if (!vport_id.port_name || !vport_id.node_name) | |
3810 | continue; | |
3811 | ||
3812 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; | |
3813 | vport_id.vport_type = FC_PORTTYPE_NPIV; | |
3814 | vport_id.disable = false; | |
3815 | new_fc_vport = fc_vport_create(shost, 0, &vport_id); | |
3816 | ||
3817 | if (!new_fc_vport) { | |
3818 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
3819 | "0546 lpfc_create_static_vport failed to" | |
e4e74273 | 3820 | " create vport\n"); |
21e9a0a5 JS |
3821 | continue; |
3822 | } | |
3823 | ||
3824 | vport = *(struct lpfc_vport **)new_fc_vport->dd_data; | |
3825 | vport->vport_flag |= STATIC_VPORT; | |
3826 | } | |
3827 | ||
3828 | out: | |
21e9a0a5 | 3829 | kfree(vport_info); |
cdcc2343 | 3830 | if (mbx_wait_rc != MBX_TIMEOUT) { |
3e1f0718 JS |
3831 | if (pmb->ctx_buf) { |
3832 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; | |
1c6834a7 JS |
3833 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3834 | kfree(mp); | |
3835 | } | |
21e9a0a5 | 3836 | mempool_free(pmb, phba->mbox_mem_pool); |
1c6834a7 | 3837 | } |
21e9a0a5 JS |
3838 | |
3839 | return; | |
3840 | } | |
3841 | ||
dea3101e | 3842 | /* |
3843 | * This routine handles processing a Fabric REG_LOGIN mailbox | |
3844 | * command upon completion. It is setup in the LPFC_MBOXQ | |
3845 | * as the completion routine when the command is | |
3846 | * handed off to the SLI layer. | |
3847 | */ | |
3848 | void | |
2e0fef85 | 3849 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 3850 | { |
92d7f7b0 | 3851 | struct lpfc_vport *vport = pmb->vport; |
21e9a0a5 | 3852 | MAILBOX_t *mb = &pmb->u.mb; |
3e1f0718 | 3853 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
92d7f7b0 | 3854 | struct lpfc_nodelist *ndlp; |
df9e1b59 | 3855 | struct Scsi_Host *shost; |
dea3101e | 3856 | |
3e1f0718 JS |
3857 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
3858 | pmb->ctx_ndlp = NULL; | |
3859 | pmb->ctx_buf = NULL; | |
d439d286 | 3860 | |
dea3101e | 3861 | if (mb->mbxStatus) { |
21e9a0a5 JS |
3862 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
3863 | "0258 Register Fabric login error: 0x%x\n", | |
3864 | mb->mbxStatus); | |
dea3101e | 3865 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
3866 | kfree(mp); | |
329f9bc7 | 3867 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 3868 | |
76a95d75 | 3869 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
92d7f7b0 JS |
3870 | /* FLOGI failed, use loop map to make discovery list */ |
3871 | lpfc_disc_list_loopmap(vport); | |
3872 | ||
3873 | /* Start discovery */ | |
3874 | lpfc_disc_start(vport); | |
e47c9093 JS |
3875 | /* Decrement the reference count to ndlp after the |
3876 | * reference to the ndlp are done. | |
3877 | */ | |
3878 | lpfc_nlp_put(ndlp); | |
92d7f7b0 JS |
3879 | return; |
3880 | } | |
3881 | ||
3882 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e47c9093 JS |
3883 | /* Decrement the reference count to ndlp after the reference |
3884 | * to the ndlp are done. | |
3885 | */ | |
3886 | lpfc_nlp_put(ndlp); | |
dea3101e | 3887 | return; |
3888 | } | |
3889 | ||
6d368e53 JS |
3890 | if (phba->sli_rev < LPFC_SLI_REV4) |
3891 | ndlp->nlp_rpi = mb->un.varWords[0]; | |
4042629e | 3892 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
dea3101e | 3893 | ndlp->nlp_type |= NLP_FABRIC; |
2e0fef85 | 3894 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
dea3101e | 3895 | |
2e0fef85 | 3896 | if (vport->port_state == LPFC_FABRIC_CFG_LINK) { |
4b40c59e JS |
3897 | /* when physical port receive logo donot start |
3898 | * vport discovery */ | |
3899 | if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) | |
3900 | lpfc_start_fdiscs(phba); | |
df9e1b59 JS |
3901 | else { |
3902 | shost = lpfc_shost_from_vport(vport); | |
3903 | spin_lock_irq(shost->host_lock); | |
4b40c59e | 3904 | vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ; |
df9e1b59 JS |
3905 | spin_unlock_irq(shost->host_lock); |
3906 | } | |
92d7f7b0 | 3907 | lpfc_do_scr_ns_plogi(phba, vport); |
dea3101e | 3908 | } |
3909 | ||
3910 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
3911 | kfree(mp); | |
329f9bc7 | 3912 | mempool_free(pmb, phba->mbox_mem_pool); |
e47c9093 JS |
3913 | |
3914 | /* Drop the reference count from the mbox at the end after | |
3915 | * all the current reference to the ndlp have been done. | |
3916 | */ | |
3917 | lpfc_nlp_put(ndlp); | |
dea3101e | 3918 | return; |
3919 | } | |
3920 | ||
a0f2d3ef JS |
3921 | /* |
3922 | * This routine will issue a GID_FT for each FC4 Type supported | |
3923 | * by the driver. ALL GID_FTs must complete before discovery is started. | |
3924 | */ | |
3925 | int | |
3926 | lpfc_issue_gidft(struct lpfc_vport *vport) | |
3927 | { | |
a0f2d3ef | 3928 | /* Good status, issue CT Request to NameServer */ |
f6e84790 JS |
3929 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
3930 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) { | |
a0f2d3ef JS |
3931 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) { |
3932 | /* Cannot issue NameServer FCP Query, so finish up | |
3933 | * discovery | |
3934 | */ | |
3935 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, | |
3936 | "0604 %s FC TYPE %x %s\n", | |
3937 | "Failed to issue GID_FT to ", | |
3938 | FC_TYPE_FCP, | |
3939 | "Finishing discovery."); | |
3940 | return 0; | |
3941 | } | |
3942 | vport->gidft_inp++; | |
3943 | } | |
3944 | ||
f6e84790 JS |
3945 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
3946 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { | |
a0f2d3ef JS |
3947 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) { |
3948 | /* Cannot issue NameServer NVME Query, so finish up | |
3949 | * discovery | |
3950 | */ | |
3951 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, | |
3952 | "0605 %s FC_TYPE %x %s %d\n", | |
3953 | "Failed to issue GID_FT to ", | |
3954 | FC_TYPE_NVME, | |
3955 | "Finishing discovery: gidftinp ", | |
3956 | vport->gidft_inp); | |
3957 | if (vport->gidft_inp == 0) | |
3958 | return 0; | |
3959 | } else | |
3960 | vport->gidft_inp++; | |
3961 | } | |
3962 | return vport->gidft_inp; | |
3963 | } | |
3964 | ||
7ea92eb4 JS |
3965 | /** |
3966 | * lpfc_issue_gidpt - issue a GID_PT for all N_Ports | |
3967 | * @vport: The virtual port for which this call is being executed. | |
3968 | * | |
3969 | * This routine will issue a GID_PT to get a list of all N_Ports | |
3970 | * | |
3971 | * Return value : | |
3972 | * 0 - Failure to issue a GID_PT | |
3973 | * 1 - GID_PT issued | |
3974 | **/ | |
3975 | int | |
3976 | lpfc_issue_gidpt(struct lpfc_vport *vport) | |
3977 | { | |
3978 | /* Good status, issue CT Request to NameServer */ | |
3979 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) { | |
3980 | /* Cannot issue NameServer FCP Query, so finish up | |
3981 | * discovery | |
3982 | */ | |
3983 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, | |
3984 | "0606 %s Port TYPE %x %s\n", | |
3985 | "Failed to issue GID_PT to ", | |
3986 | GID_PT_N_PORT, | |
3987 | "Finishing discovery."); | |
3988 | return 0; | |
3989 | } | |
3990 | vport->gidft_inp++; | |
3991 | return 1; | |
3992 | } | |
3993 | ||
dea3101e | 3994 | /* |
3995 | * This routine handles processing a NameServer REG_LOGIN mailbox | |
3996 | * command upon completion. It is setup in the LPFC_MBOXQ | |
3997 | * as the completion routine when the command is | |
3998 | * handed off to the SLI layer. | |
3999 | */ | |
4000 | void | |
2e0fef85 | 4001 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 4002 | { |
21e9a0a5 | 4003 | MAILBOX_t *mb = &pmb->u.mb; |
3e1f0718 JS |
4004 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
4005 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; | |
2e0fef85 | 4006 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 4007 | |
3e1f0718 JS |
4008 | pmb->ctx_buf = NULL; |
4009 | pmb->ctx_ndlp = NULL; | |
a0f2d3ef | 4010 | vport->gidft_inp = 0; |
d439d286 | 4011 | |
dea3101e | 4012 | if (mb->mbxStatus) { |
21e9a0a5 JS |
4013 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
4014 | "0260 Register NameServer error: 0x%x\n", | |
4015 | mb->mbxStatus); | |
a0f2d3ef JS |
4016 | |
4017 | out: | |
fa4066b6 JS |
4018 | /* decrement the node reference count held for this |
4019 | * callback function. | |
4020 | */ | |
329f9bc7 | 4021 | lpfc_nlp_put(ndlp); |
dea3101e | 4022 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4023 | kfree(mp); | |
de0c5b32 | 4024 | mempool_free(pmb, phba->mbox_mem_pool); |
87af33fe JS |
4025 | |
4026 | /* If no other thread is using the ndlp, free it */ | |
4027 | lpfc_nlp_not_used(ndlp); | |
dea3101e | 4028 | |
76a95d75 | 4029 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
92d7f7b0 JS |
4030 | /* |
4031 | * RegLogin failed, use loop map to make discovery | |
4032 | * list | |
4033 | */ | |
4034 | lpfc_disc_list_loopmap(vport); | |
dea3101e | 4035 | |
92d7f7b0 JS |
4036 | /* Start discovery */ |
4037 | lpfc_disc_start(vport); | |
4038 | return; | |
4039 | } | |
4040 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
dea3101e | 4041 | return; |
4042 | } | |
4043 | ||
6d368e53 JS |
4044 | if (phba->sli_rev < LPFC_SLI_REV4) |
4045 | ndlp->nlp_rpi = mb->un.varWords[0]; | |
4042629e | 4046 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
dea3101e | 4047 | ndlp->nlp_type |= NLP_FABRIC; |
2e0fef85 | 4048 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
be6bb941 JS |
4049 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
4050 | "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", | |
4051 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 4052 | kref_read(&ndlp->kref), |
be6bb941 | 4053 | ndlp->nlp_usg_map, ndlp); |
dea3101e | 4054 | |
2e0fef85 JS |
4055 | if (vport->port_state < LPFC_VPORT_READY) { |
4056 | /* Link up discovery requires Fabric registration. */ | |
92d7f7b0 JS |
4057 | lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); |
4058 | lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); | |
4059 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); | |
4060 | lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); | |
a0f2d3ef | 4061 | |
f6e84790 JS |
4062 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
4063 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) | |
a0f2d3ef JS |
4064 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP); |
4065 | ||
f6e84790 JS |
4066 | if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
4067 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) | |
01649561 JS |
4068 | lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, |
4069 | FC_TYPE_NVME); | |
92d7f7b0 JS |
4070 | |
4071 | /* Issue SCR just before NameServer GID_FT Query */ | |
4072 | lpfc_issue_els_scr(vport, SCR_DID, 0); | |
dea3101e | 4073 | } |
4074 | ||
2e0fef85 | 4075 | vport->fc_ns_retry = 0; |
a0f2d3ef | 4076 | if (lpfc_issue_gidft(vport) == 0) |
92d7f7b0 | 4077 | goto out; |
dea3101e | 4078 | |
a0f2d3ef JS |
4079 | /* |
4080 | * At this point in time we may need to wait for multiple | |
4081 | * SLI_CTNS_GID_FT CT commands to complete before we start discovery. | |
4082 | * | |
4083 | * decrement the node reference count held for this | |
fa4066b6 JS |
4084 | * callback function. |
4085 | */ | |
329f9bc7 | 4086 | lpfc_nlp_put(ndlp); |
dea3101e | 4087 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4088 | kfree(mp); | |
2e0fef85 | 4089 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 4090 | |
4091 | return; | |
4092 | } | |
4093 | ||
4094 | static void | |
2e0fef85 | 4095 | lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 4096 | { |
2e0fef85 JS |
4097 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
4098 | struct fc_rport *rport; | |
dea3101e | 4099 | struct lpfc_rport_data *rdata; |
4100 | struct fc_rport_identifiers rport_ids; | |
2e0fef85 | 4101 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 4102 | |
f6e84790 | 4103 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
895427bd JS |
4104 | return; |
4105 | ||
dea3101e | 4106 | /* Remote port has reappeared. Re-register w/ FC transport */ |
68ce1eb5 AM |
4107 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
4108 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); | |
dea3101e | 4109 | rport_ids.port_id = ndlp->nlp_DID; |
4110 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; | |
dea3101e | 4111 | |
329f9bc7 JS |
4112 | /* |
4113 | * We leave our node pointer in rport->dd_data when we unregister a | |
4114 | * FCP target port. But fc_remote_port_add zeros the space to which | |
4115 | * rport->dd_data points. So, if we're reusing a previously | |
4116 | * registered port, drop the reference that we took the last time we | |
4117 | * registered the port. | |
4118 | */ | |
466e840b JS |
4119 | rport = ndlp->rport; |
4120 | if (rport) { | |
4121 | rdata = rport->dd_data; | |
4122 | /* break the link before dropping the ref */ | |
4123 | ndlp->rport = NULL; | |
2ade92ae JS |
4124 | if (rdata) { |
4125 | if (rdata->pnode == ndlp) | |
4126 | lpfc_nlp_put(ndlp); | |
4127 | rdata->pnode = NULL; | |
4128 | } | |
466e840b JS |
4129 | /* drop reference for earlier registeration */ |
4130 | put_device(&rport->dev); | |
4131 | } | |
858c9f6c JS |
4132 | |
4133 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, | |
4134 | "rport add: did:x%x flg:x%x type x%x", | |
4135 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); | |
4136 | ||
9589b062 JS |
4137 | /* Don't add the remote port if unloading. */ |
4138 | if (vport->load_flag & FC_UNLOADING) | |
4139 | return; | |
4140 | ||
2e0fef85 | 4141 | ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids); |
329f9bc7 | 4142 | if (!rport || !get_device(&rport->dev)) { |
dea3101e | 4143 | dev_printk(KERN_WARNING, &phba->pcidev->dev, |
4144 | "Warning: fc_remote_port_add failed\n"); | |
4145 | return; | |
4146 | } | |
4147 | ||
4148 | /* initialize static port data */ | |
4149 | rport->maxframe_size = ndlp->nlp_maxframe; | |
4150 | rport->supported_classes = ndlp->nlp_class_sup; | |
dea3101e | 4151 | rdata = rport->dd_data; |
329f9bc7 | 4152 | rdata->pnode = lpfc_nlp_get(ndlp); |
23dc04f1 JSEC |
4153 | |
4154 | if (ndlp->nlp_type & NLP_FCP_TARGET) | |
a6a6d058 | 4155 | rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET; |
23dc04f1 | 4156 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
a6a6d058 HR |
4157 | rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR; |
4158 | if (ndlp->nlp_type & NLP_NVME_INITIATOR) | |
4159 | rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR; | |
4160 | if (ndlp->nlp_type & NLP_NVME_TARGET) | |
4161 | rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET; | |
4162 | if (ndlp->nlp_type & NLP_NVME_DISCOVERY) | |
4163 | rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY; | |
23dc04f1 | 4164 | |
23dc04f1 JSEC |
4165 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) |
4166 | fc_remote_port_rolechg(rport, rport_ids.roles); | |
4167 | ||
34f5ad8b JS |
4168 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
4169 | "3183 rport register x%06x, rport %p role x%x\n", | |
4170 | ndlp->nlp_DID, rport, rport_ids.roles); | |
4171 | ||
071fbd3d | 4172 | if ((rport->scsi_target_id != -1) && |
92d7f7b0 | 4173 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
071fbd3d JS |
4174 | ndlp->nlp_sid = rport->scsi_target_id; |
4175 | } | |
19a7b4ae JSEC |
4176 | return; |
4177 | } | |
4178 | ||
4179 | static void | |
2e0fef85 | 4180 | lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp) |
19a7b4ae JSEC |
4181 | { |
4182 | struct fc_rport *rport = ndlp->rport; | |
2ea259ee | 4183 | struct lpfc_vport *vport = ndlp->vport; |
a0f2d3ef | 4184 | |
f6e84790 | 4185 | if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) |
a0f2d3ef | 4186 | return; |
c01f3208 | 4187 | |
2ea259ee | 4188 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, |
858c9f6c JS |
4189 | "rport delete: did:x%x flg:x%x type x%x", |
4190 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); | |
4191 | ||
2ea259ee | 4192 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
34f5ad8b JS |
4193 | "3184 rport unregister x%06x, rport %p\n", |
4194 | ndlp->nlp_DID, rport); | |
4195 | ||
19a7b4ae | 4196 | fc_remote_port_delete(rport); |
dea3101e | 4197 | |
4198 | return; | |
4199 | } | |
4200 | ||
de0c5b32 | 4201 | static void |
2e0fef85 | 4202 | lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count) |
dea3101e | 4203 | { |
2e0fef85 | 4204 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
894bb17f | 4205 | unsigned long iflags; |
2e0fef85 | 4206 | |
894bb17f | 4207 | spin_lock_irqsave(shost->host_lock, iflags); |
de0c5b32 JS |
4208 | switch (state) { |
4209 | case NLP_STE_UNUSED_NODE: | |
2e0fef85 | 4210 | vport->fc_unused_cnt += count; |
de0c5b32 JS |
4211 | break; |
4212 | case NLP_STE_PLOGI_ISSUE: | |
2e0fef85 | 4213 | vport->fc_plogi_cnt += count; |
de0c5b32 JS |
4214 | break; |
4215 | case NLP_STE_ADISC_ISSUE: | |
2e0fef85 | 4216 | vport->fc_adisc_cnt += count; |
dea3101e | 4217 | break; |
de0c5b32 | 4218 | case NLP_STE_REG_LOGIN_ISSUE: |
2e0fef85 | 4219 | vport->fc_reglogin_cnt += count; |
de0c5b32 JS |
4220 | break; |
4221 | case NLP_STE_PRLI_ISSUE: | |
2e0fef85 | 4222 | vport->fc_prli_cnt += count; |
de0c5b32 JS |
4223 | break; |
4224 | case NLP_STE_UNMAPPED_NODE: | |
2e0fef85 | 4225 | vport->fc_unmap_cnt += count; |
de0c5b32 JS |
4226 | break; |
4227 | case NLP_STE_MAPPED_NODE: | |
2e0fef85 | 4228 | vport->fc_map_cnt += count; |
de0c5b32 JS |
4229 | break; |
4230 | case NLP_STE_NPR_NODE: | |
646a2dd7 JS |
4231 | if (vport->fc_npr_cnt == 0 && count == -1) |
4232 | vport->fc_npr_cnt = 0; | |
4233 | else | |
4234 | vport->fc_npr_cnt += count; | |
de0c5b32 JS |
4235 | break; |
4236 | } | |
894bb17f | 4237 | spin_unlock_irqrestore(shost->host_lock, iflags); |
de0c5b32 | 4238 | } |
66a9ed66 | 4239 | |
de0c5b32 | 4240 | static void |
2e0fef85 | 4241 | lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
de0c5b32 JS |
4242 | int old_state, int new_state) |
4243 | { | |
2e0fef85 JS |
4244 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
4245 | ||
de0c5b32 | 4246 | if (new_state == NLP_STE_UNMAPPED_NODE) { |
de0c5b32 JS |
4247 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
4248 | ndlp->nlp_type |= NLP_FC_NODE; | |
4249 | } | |
4250 | if (new_state == NLP_STE_MAPPED_NODE) | |
4251 | ndlp->nlp_flag &= ~NLP_NODEV_REMOVE; | |
4252 | if (new_state == NLP_STE_NPR_NODE) | |
4253 | ndlp->nlp_flag &= ~NLP_RCV_PLOGI; | |
4254 | ||
a0f2d3ef JS |
4255 | /* FCP and NVME Transport interface */ |
4256 | if ((old_state == NLP_STE_MAPPED_NODE || | |
4257 | old_state == NLP_STE_UNMAPPED_NODE)) { | |
4258 | if (ndlp->rport) { | |
4259 | vport->phba->nport_event_cnt++; | |
4260 | lpfc_unregister_remote_port(ndlp); | |
4261 | } | |
4262 | ||
1c5b12f7 | 4263 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
a0f2d3ef | 4264 | vport->phba->nport_event_cnt++; |
3b5bde69 JS |
4265 | if (vport->phba->nvmet_support == 0) { |
4266 | /* Start devloss if target. */ | |
4267 | if (ndlp->nlp_type & NLP_NVME_TARGET) | |
4268 | lpfc_nvme_unregister_port(vport, ndlp); | |
4269 | } else { | |
6599e124 JS |
4270 | /* NVMET has no upcall. */ |
4271 | lpfc_nlp_put(ndlp); | |
3b5bde69 | 4272 | } |
a0f2d3ef | 4273 | } |
de0c5b32 | 4274 | } |
dea3101e | 4275 | |
a0f2d3ef JS |
4276 | /* FCP and NVME Transport interfaces */ |
4277 | ||
de0c5b32 JS |
4278 | if (new_state == NLP_STE_MAPPED_NODE || |
4279 | new_state == NLP_STE_UNMAPPED_NODE) { | |
01a8aed6 | 4280 | if (ndlp->nlp_fc4_type || |
92721c3b JS |
4281 | ndlp->nlp_DID == Fabric_DID || |
4282 | ndlp->nlp_DID == NameServer_DID || | |
4283 | ndlp->nlp_DID == FDMI_DID) { | |
a0f2d3ef JS |
4284 | vport->phba->nport_event_cnt++; |
4285 | /* | |
4286 | * Tell the fc transport about the port, if we haven't | |
4287 | * already. If we have, and it's a scsi entity, be | |
4288 | */ | |
4289 | lpfc_register_remote_port(vport, ndlp); | |
4290 | } | |
4291 | /* Notify the NVME transport of this new rport. */ | |
09559e81 JS |
4292 | if (vport->phba->sli_rev >= LPFC_SLI_REV4 && |
4293 | ndlp->nlp_fc4_type & NLP_FC4_NVME) { | |
a0f2d3ef JS |
4294 | if (vport->phba->nvmet_support == 0) { |
4295 | /* Register this rport with the transport. | |
3b5bde69 JS |
4296 | * Only NVME Target Rports are registered with |
4297 | * the transport. | |
a0f2d3ef | 4298 | */ |
3b5bde69 JS |
4299 | if (ndlp->nlp_type & NLP_NVME_TARGET) { |
4300 | vport->phba->nport_event_cnt++; | |
4301 | lpfc_nvme_register_port(vport, ndlp); | |
4302 | } | |
8c258641 JS |
4303 | } else { |
4304 | /* Just take an NDLP ref count since the | |
4305 | * target does not register rports. | |
4306 | */ | |
4307 | lpfc_nlp_get(ndlp); | |
a0f2d3ef JS |
4308 | } |
4309 | } | |
de0c5b32 | 4310 | } |
a0f2d3ef | 4311 | |
ea2151b4 JS |
4312 | if ((new_state == NLP_STE_MAPPED_NODE) && |
4313 | (vport->stat_data_enabled)) { | |
4314 | /* | |
4315 | * A new target is discovered, if there is no buffer for | |
4316 | * statistical data collection allocate buffer. | |
4317 | */ | |
4318 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, | |
4319 | sizeof(struct lpfc_scsicmd_bkt), | |
4320 | GFP_KERNEL); | |
4321 | ||
4322 | if (!ndlp->lat_data) | |
4323 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, | |
4324 | "0286 lpfc_nlp_state_cleanup failed to " | |
4325 | "allocate statistical data buffer DID " | |
4326 | "0x%x\n", ndlp->nlp_DID); | |
4327 | } | |
858c9f6c | 4328 | /* |
a0f2d3ef JS |
4329 | * If the node just added to Mapped list was an FCP target, |
4330 | * but the remote port registration failed or assigned a target | |
4331 | * id outside the presentable range - move the node to the | |
4332 | * Unmapped List. | |
858c9f6c | 4333 | */ |
a0f2d3ef JS |
4334 | if ((new_state == NLP_STE_MAPPED_NODE) && |
4335 | (ndlp->nlp_type & NLP_FCP_TARGET) && | |
de0c5b32 JS |
4336 | (!ndlp->rport || |
4337 | ndlp->rport->scsi_target_id == -1 || | |
4338 | ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) { | |
2e0fef85 | 4339 | spin_lock_irq(shost->host_lock); |
de0c5b32 | 4340 | ndlp->nlp_flag |= NLP_TGT_NO_SCSIID; |
2e0fef85 JS |
4341 | spin_unlock_irq(shost->host_lock); |
4342 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | |
dea3101e | 4343 | } |
de0c5b32 JS |
4344 | } |
4345 | ||
685f0bf7 JS |
4346 | static char * |
4347 | lpfc_nlp_state_name(char *buffer, size_t size, int state) | |
4348 | { | |
4349 | static char *states[] = { | |
4350 | [NLP_STE_UNUSED_NODE] = "UNUSED", | |
4351 | [NLP_STE_PLOGI_ISSUE] = "PLOGI", | |
4352 | [NLP_STE_ADISC_ISSUE] = "ADISC", | |
4353 | [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN", | |
4354 | [NLP_STE_PRLI_ISSUE] = "PRLI", | |
086a345f | 4355 | [NLP_STE_LOGO_ISSUE] = "LOGO", |
685f0bf7 JS |
4356 | [NLP_STE_UNMAPPED_NODE] = "UNMAPPED", |
4357 | [NLP_STE_MAPPED_NODE] = "MAPPED", | |
4358 | [NLP_STE_NPR_NODE] = "NPR", | |
4359 | }; | |
4360 | ||
311464ec | 4361 | if (state < NLP_STE_MAX_STATE && states[state]) |
685f0bf7 JS |
4362 | strlcpy(buffer, states[state], size); |
4363 | else | |
4364 | snprintf(buffer, size, "unknown (%d)", state); | |
4365 | return buffer; | |
4366 | } | |
4367 | ||
de0c5b32 | 4368 | void |
2e0fef85 JS |
4369 | lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
4370 | int state) | |
de0c5b32 | 4371 | { |
2e0fef85 | 4372 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
de0c5b32 | 4373 | int old_state = ndlp->nlp_state; |
685f0bf7 | 4374 | char name1[16], name2[16]; |
de0c5b32 | 4375 | |
e8b62011 JS |
4376 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
4377 | "0904 NPort state transition x%06x, %s -> %s\n", | |
4378 | ndlp->nlp_DID, | |
4379 | lpfc_nlp_state_name(name1, sizeof(name1), old_state), | |
4380 | lpfc_nlp_state_name(name2, sizeof(name2), state)); | |
858c9f6c JS |
4381 | |
4382 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, | |
4383 | "node statechg did:x%x old:%d ste:%d", | |
4384 | ndlp->nlp_DID, old_state, state); | |
4385 | ||
de0c5b32 | 4386 | if (old_state == NLP_STE_NPR_NODE && |
de0c5b32 | 4387 | state != NLP_STE_NPR_NODE) |
2e0fef85 | 4388 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
de0c5b32 JS |
4389 | if (old_state == NLP_STE_UNMAPPED_NODE) { |
4390 | ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; | |
4391 | ndlp->nlp_type &= ~NLP_FC_NODE; | |
4392 | } | |
4393 | ||
685f0bf7 | 4394 | if (list_empty(&ndlp->nlp_listp)) { |
2e0fef85 JS |
4395 | spin_lock_irq(shost->host_lock); |
4396 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); | |
4397 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 | 4398 | } else if (old_state) |
2e0fef85 | 4399 | lpfc_nlp_counters(vport, old_state, -1); |
de0c5b32 JS |
4400 | |
4401 | ndlp->nlp_state = state; | |
2e0fef85 JS |
4402 | lpfc_nlp_counters(vport, state, 1); |
4403 | lpfc_nlp_state_cleanup(vport, ndlp, old_state, state); | |
de0c5b32 JS |
4404 | } |
4405 | ||
e47c9093 JS |
4406 | void |
4407 | lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) | |
4408 | { | |
4409 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4410 | ||
4411 | if (list_empty(&ndlp->nlp_listp)) { | |
4412 | spin_lock_irq(shost->host_lock); | |
4413 | list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes); | |
4414 | spin_unlock_irq(shost->host_lock); | |
4415 | } | |
4416 | } | |
4417 | ||
de0c5b32 | 4418 | void |
2e0fef85 | 4419 | lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
de0c5b32 | 4420 | { |
2e0fef85 JS |
4421 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
4422 | ||
0d2b6b83 | 4423 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
de0c5b32 | 4424 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
2e0fef85 JS |
4425 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); |
4426 | spin_lock_irq(shost->host_lock); | |
685f0bf7 | 4427 | list_del_init(&ndlp->nlp_listp); |
2e0fef85 | 4428 | spin_unlock_irq(shost->host_lock); |
858c9f6c | 4429 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, |
e47c9093 JS |
4430 | NLP_STE_UNUSED_NODE); |
4431 | } | |
4432 | ||
4d9db01e | 4433 | static void |
e47c9093 JS |
4434 | lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
4435 | { | |
0d2b6b83 | 4436 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
e47c9093 JS |
4437 | if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp)) |
4438 | lpfc_nlp_counters(vport, ndlp->nlp_state, -1); | |
4439 | lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, | |
4440 | NLP_STE_UNUSED_NODE); | |
4441 | } | |
109f6ed0 | 4442 | /** |
3621a710 | 4443 | * lpfc_initialize_node - Initialize all fields of node object |
109f6ed0 JS |
4444 | * @vport: Pointer to Virtual Port object. |
4445 | * @ndlp: Pointer to FC node object. | |
4446 | * @did: FC_ID of the node. | |
a257bf90 JS |
4447 | * |
4448 | * This function is always called when node object need to be initialized. | |
4449 | * It initializes all the fields of the node object. Although the reference | |
4450 | * to phba from @ndlp can be obtained indirectly through it's reference to | |
4451 | * @vport, a direct reference to phba is taken here by @ndlp. This is due | |
4452 | * to the life-span of the @ndlp might go beyond the existence of @vport as | |
4453 | * the final release of ndlp is determined by its reference count. And, the | |
4454 | * operation on @ndlp needs the reference to phba. | |
109f6ed0 JS |
4455 | **/ |
4456 | static inline void | |
4457 | lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
4458 | uint32_t did) | |
4459 | { | |
4460 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); | |
4461 | INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); | |
f22eb4d3 | 4462 | timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0); |
109f6ed0 JS |
4463 | ndlp->nlp_DID = did; |
4464 | ndlp->vport = vport; | |
a257bf90 | 4465 | ndlp->phba = vport->phba; |
109f6ed0 | 4466 | ndlp->nlp_sid = NLP_NO_SID; |
a0f2d3ef | 4467 | ndlp->nlp_fc4_type = NLP_FC4_NONE; |
109f6ed0 JS |
4468 | kref_init(&ndlp->kref); |
4469 | NLP_INT_NODE_ACT(ndlp); | |
4470 | atomic_set(&ndlp->cmd_pending, 0); | |
7dc517df | 4471 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
dea16bda | 4472 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
109f6ed0 | 4473 | } |
e47c9093 JS |
4474 | |
4475 | struct lpfc_nodelist * | |
4476 | lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
4477 | int state) | |
4478 | { | |
4479 | struct lpfc_hba *phba = vport->phba; | |
dea16bda | 4480 | uint32_t did, flag; |
e47c9093 | 4481 | unsigned long flags; |
cff261f6 | 4482 | unsigned long *active_rrqs_xri_bitmap = NULL; |
9d3d340d | 4483 | int rpi = LPFC_RPI_ALLOC_ERROR; |
dea16bda | 4484 | uint32_t defer_did = 0; |
e47c9093 JS |
4485 | |
4486 | if (!ndlp) | |
4487 | return NULL; | |
4488 | ||
9d3d340d | 4489 | if (phba->sli_rev == LPFC_SLI_REV4) { |
b95b2119 JS |
4490 | if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR) |
4491 | rpi = lpfc_sli4_alloc_rpi(vport->phba); | |
4492 | else | |
4493 | rpi = ndlp->nlp_rpi; | |
4494 | ||
4495 | if (rpi == LPFC_RPI_ALLOC_ERROR) { | |
4496 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
4497 | "0359 %s: ndlp:x%px " | |
4498 | "usgmap:x%x refcnt:%d FAILED RPI " | |
4499 | " ALLOC\n", | |
4500 | __func__, | |
4501 | (void *)ndlp, ndlp->nlp_usg_map, | |
4502 | kref_read(&ndlp->kref)); | |
9d3d340d | 4503 | return NULL; |
b95b2119 | 4504 | } |
9d3d340d JS |
4505 | } |
4506 | ||
e47c9093 JS |
4507 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
4508 | /* The ndlp should not be in memory free mode */ | |
4509 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
4510 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
4511 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
4512 | "0277 lpfc_enable_node: ndlp:x%p " | |
4513 | "usgmap:x%x refcnt:%d\n", | |
4514 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 4515 | kref_read(&ndlp->kref)); |
9d3d340d | 4516 | goto free_rpi; |
e47c9093 JS |
4517 | } |
4518 | /* The ndlp should not already be in active mode */ | |
4519 | if (NLP_CHK_NODE_ACT(ndlp)) { | |
4520 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
4521 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
4522 | "0278 lpfc_enable_node: ndlp:x%p " | |
4523 | "usgmap:x%x refcnt:%d\n", | |
4524 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 4525 | kref_read(&ndlp->kref)); |
9d3d340d | 4526 | goto free_rpi; |
e47c9093 JS |
4527 | } |
4528 | ||
dea16bda | 4529 | /* First preserve the orginal DID, xri_bitmap and some flags */ |
e47c9093 | 4530 | did = ndlp->nlp_DID; |
dea16bda JS |
4531 | flag = (ndlp->nlp_flag & NLP_UNREG_INP); |
4532 | if (flag & NLP_UNREG_INP) | |
4533 | defer_did = ndlp->nlp_defer_did; | |
cff261f6 JS |
4534 | if (phba->sli_rev == LPFC_SLI_REV4) |
4535 | active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap; | |
e47c9093 | 4536 | |
dea16bda | 4537 | /* Zero ndlp except of ndlp linked list pointer */ |
e47c9093 JS |
4538 | memset((((char *)ndlp) + sizeof (struct list_head)), 0, |
4539 | sizeof (struct lpfc_nodelist) - sizeof (struct list_head)); | |
e47c9093 | 4540 | |
dea16bda JS |
4541 | /* Next reinitialize and restore saved objects */ |
4542 | lpfc_initialize_node(vport, ndlp, did); | |
4543 | ndlp->nlp_flag |= flag; | |
4544 | if (flag & NLP_UNREG_INP) | |
4545 | ndlp->nlp_defer_did = defer_did; | |
cff261f6 JS |
4546 | if (phba->sli_rev == LPFC_SLI_REV4) |
4547 | ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap; | |
4548 | ||
e47c9093 | 4549 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
be6bb941 | 4550 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
9d3d340d | 4551 | ndlp->nlp_rpi = rpi; |
be6bb941 JS |
4552 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
4553 | "0008 rpi:%x DID:%x flg:%x refcnt:%d " | |
4554 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, | |
4555 | ndlp->nlp_flag, | |
2c935bc5 | 4556 | kref_read(&ndlp->kref), |
be6bb941 JS |
4557 | ndlp->nlp_usg_map, ndlp); |
4558 | } | |
725dd399 | 4559 | |
e47c9093 JS |
4560 | |
4561 | if (state != NLP_STE_UNUSED_NODE) | |
4562 | lpfc_nlp_set_state(vport, ndlp, state); | |
b95b2119 JS |
4563 | else |
4564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, | |
4565 | "0013 rpi:%x DID:%x flg:%x refcnt:%d " | |
4566 | "map:%x x%px STATE=UNUSED\n", | |
4567 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
4568 | ndlp->nlp_flag, | |
4569 | kref_read(&ndlp->kref), | |
4570 | ndlp->nlp_usg_map, ndlp); | |
e47c9093 JS |
4571 | |
4572 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, | |
4573 | "node enable: did:x%x", | |
4574 | ndlp->nlp_DID, 0, 0); | |
4575 | return ndlp; | |
9d3d340d JS |
4576 | |
4577 | free_rpi: | |
4578 | if (phba->sli_rev == LPFC_SLI_REV4) | |
4579 | lpfc_sli4_free_rpi(vport->phba, rpi); | |
4580 | return NULL; | |
de0c5b32 JS |
4581 | } |
4582 | ||
4583 | void | |
2e0fef85 | 4584 | lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
de0c5b32 | 4585 | { |
87af33fe | 4586 | /* |
fa4066b6 | 4587 | * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should |
87af33fe | 4588 | * be used if we wish to issue the "last" lpfc_nlp_put() to remove |
fa4066b6 JS |
4589 | * the ndlp from the vport. The ndlp marked as UNUSED on the list |
4590 | * until ALL other outstanding threads have completed. We check | |
4591 | * that the ndlp not already in the UNUSED state before we proceed. | |
87af33fe | 4592 | */ |
fa4066b6 JS |
4593 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
4594 | return; | |
51ef4c26 | 4595 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); |
be6bb941 | 4596 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
1151e3ec | 4597 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
be6bb941 | 4598 | lpfc_unreg_rpi(vport, ndlp); |
be6bb941 | 4599 | } |
0290217a JS |
4600 | |
4601 | lpfc_nlp_put(ndlp); | |
98c9ea5c | 4602 | return; |
dea3101e | 4603 | } |
4604 | ||
4605 | /* | |
4606 | * Start / ReStart rescue timer for Discovery / RSCN handling | |
4607 | */ | |
4608 | void | |
2e0fef85 | 4609 | lpfc_set_disctmo(struct lpfc_vport *vport) |
dea3101e | 4610 | { |
2e0fef85 JS |
4611 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
4612 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4613 | uint32_t tmo; |
4614 | ||
2e0fef85 | 4615 | if (vport->port_state == LPFC_LOCAL_CFG_LINK) { |
025dfdaf | 4616 | /* For FAN, timeout should be greater than edtov */ |
c9f8735b JW |
4617 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); |
4618 | } else { | |
025dfdaf | 4619 | /* Normal discovery timeout should be > than ELS/CT timeout |
c9f8735b JW |
4620 | * FC spec states we need 3 * ratov for CT requests |
4621 | */ | |
4622 | tmo = ((phba->fc_ratov * 3) + 3); | |
4623 | } | |
dea3101e | 4624 | |
858c9f6c JS |
4625 | |
4626 | if (!timer_pending(&vport->fc_disctmo)) { | |
4627 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, | |
4628 | "set disc timer: tmo:x%x state:x%x flg:x%x", | |
4629 | tmo, vport->port_state, vport->fc_flag); | |
4630 | } | |
4631 | ||
256ec0d0 | 4632 | mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo)); |
2e0fef85 JS |
4633 | spin_lock_irq(shost->host_lock); |
4634 | vport->fc_flag |= FC_DISC_TMO; | |
4635 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 4636 | |
4637 | /* Start Discovery Timer state <hba_state> */ | |
e8b62011 JS |
4638 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
4639 | "0247 Start Discovery Timer state x%x " | |
4640 | "Data: x%x x%lx x%x x%x\n", | |
4641 | vport->port_state, tmo, | |
4642 | (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt, | |
4643 | vport->fc_adisc_cnt); | |
dea3101e | 4644 | |
4645 | return; | |
4646 | } | |
4647 | ||
4648 | /* | |
4649 | * Cancel rescue timer for Discovery / RSCN handling | |
4650 | */ | |
4651 | int | |
2e0fef85 | 4652 | lpfc_can_disctmo(struct lpfc_vport *vport) |
dea3101e | 4653 | { |
2e0fef85 | 4654 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2e0fef85 JS |
4655 | unsigned long iflags; |
4656 | ||
858c9f6c JS |
4657 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
4658 | "can disc timer: state:x%x rtry:x%x flg:x%x", | |
4659 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); | |
4660 | ||
dea3101e | 4661 | /* Turn off discovery timer if its running */ |
2e0fef85 JS |
4662 | if (vport->fc_flag & FC_DISC_TMO) { |
4663 | spin_lock_irqsave(shost->host_lock, iflags); | |
4664 | vport->fc_flag &= ~FC_DISC_TMO; | |
4665 | spin_unlock_irqrestore(shost->host_lock, iflags); | |
4666 | del_timer_sync(&vport->fc_disctmo); | |
4667 | spin_lock_irqsave(&vport->work_port_lock, iflags); | |
4668 | vport->work_port_events &= ~WORKER_DISC_TMO; | |
4669 | spin_unlock_irqrestore(&vport->work_port_lock, iflags); | |
dea3101e | 4670 | } |
4671 | ||
4672 | /* Cancel Discovery Timer state <hba_state> */ | |
e8b62011 JS |
4673 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
4674 | "0248 Cancel Discovery Timer state x%x " | |
4675 | "Data: x%x x%x x%x\n", | |
4676 | vport->port_state, vport->fc_flag, | |
4677 | vport->fc_plogi_cnt, vport->fc_adisc_cnt); | |
2fe165b6 | 4678 | return 0; |
dea3101e | 4679 | } |
4680 | ||
4681 | /* | |
4682 | * Check specified ring for outstanding IOCB on the SLI queue | |
4683 | * Return true if iocb matches the specified nport | |
4684 | */ | |
4685 | int | |
2e0fef85 JS |
4686 | lpfc_check_sli_ndlp(struct lpfc_hba *phba, |
4687 | struct lpfc_sli_ring *pring, | |
4688 | struct lpfc_iocbq *iocb, | |
4689 | struct lpfc_nodelist *ndlp) | |
dea3101e | 4690 | { |
2e0fef85 | 4691 | IOCB_t *icmd = &iocb->iocb; |
92d7f7b0 JS |
4692 | struct lpfc_vport *vport = ndlp->vport; |
4693 | ||
4694 | if (iocb->vport != vport) | |
4695 | return 0; | |
4696 | ||
dea3101e | 4697 | if (pring->ringno == LPFC_ELS_RING) { |
4698 | switch (icmd->ulpCommand) { | |
4699 | case CMD_GEN_REQUEST64_CR: | |
21e9a0a5 | 4700 | if (iocb->context_un.ndlp == ndlp) |
2fe165b6 | 4701 | return 1; |
cd05c155 | 4702 | /* fall through */ |
dea3101e | 4703 | case CMD_ELS_REQUEST64_CR: |
10d4e957 JS |
4704 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
4705 | return 1; | |
cd05c155 | 4706 | /* fall through */ |
dea3101e | 4707 | case CMD_XMIT_ELS_RSP64_CX: |
4708 | if (iocb->context1 == (uint8_t *) ndlp) | |
2fe165b6 | 4709 | return 1; |
cd05c155 | 4710 | /* fall through */ |
dea3101e | 4711 | } |
895427bd | 4712 | } else if (pring->ringno == LPFC_FCP_RING) { |
dea3101e | 4713 | /* Skip match check if waiting to relogin to FCP target */ |
4714 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && | |
92d7f7b0 | 4715 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { |
2fe165b6 | 4716 | return 0; |
dea3101e | 4717 | } |
4718 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { | |
2fe165b6 | 4719 | return 1; |
dea3101e | 4720 | } |
dea3101e | 4721 | } |
2fe165b6 | 4722 | return 0; |
dea3101e | 4723 | } |
4724 | ||
895427bd JS |
4725 | static void |
4726 | __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba, | |
4727 | struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring, | |
4728 | struct list_head *dequeue_list) | |
4729 | { | |
4730 | struct lpfc_iocbq *iocb, *next_iocb; | |
4731 | ||
4732 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { | |
4733 | /* Check to see if iocb matches the nport */ | |
4734 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) | |
4735 | /* match, dequeue */ | |
4736 | list_move_tail(&iocb->list, dequeue_list); | |
4737 | } | |
4738 | } | |
4739 | ||
4740 | static void | |
4741 | lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba, | |
4742 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) | |
4743 | { | |
4744 | struct lpfc_sli *psli = &phba->sli; | |
4745 | uint32_t i; | |
4746 | ||
4747 | spin_lock_irq(&phba->hbalock); | |
4748 | for (i = 0; i < psli->num_rings; i++) | |
4749 | __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i], | |
4750 | dequeue_list); | |
4751 | spin_unlock_irq(&phba->hbalock); | |
4752 | } | |
4753 | ||
4754 | static void | |
4755 | lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba, | |
4756 | struct lpfc_nodelist *ndlp, struct list_head *dequeue_list) | |
4757 | { | |
4758 | struct lpfc_sli_ring *pring; | |
4759 | struct lpfc_queue *qp = NULL; | |
4760 | ||
4761 | spin_lock_irq(&phba->hbalock); | |
4762 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
4763 | pring = qp->pring; | |
4764 | if (!pring) | |
4765 | continue; | |
2ade92ae | 4766 | spin_lock(&pring->ring_lock); |
895427bd | 4767 | __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); |
2ade92ae | 4768 | spin_unlock(&pring->ring_lock); |
895427bd JS |
4769 | } |
4770 | spin_unlock_irq(&phba->hbalock); | |
4771 | } | |
4772 | ||
dea3101e | 4773 | /* |
4774 | * Free resources / clean up outstanding I/Os | |
4775 | * associated with nlp_rpi in the LPFC_NODELIST entry. | |
4776 | */ | |
4777 | static int | |
2e0fef85 | 4778 | lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 4779 | { |
2534ba75 | 4780 | LIST_HEAD(completions); |
dea3101e | 4781 | |
92d7f7b0 JS |
4782 | lpfc_fabric_abort_nport(ndlp); |
4783 | ||
dea3101e | 4784 | /* |
4785 | * Everything that matches on txcmplq will be returned | |
4786 | * by firmware with a no rpi error. | |
4787 | */ | |
4042629e | 4788 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
895427bd JS |
4789 | if (phba->sli_rev != LPFC_SLI_REV4) |
4790 | lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions); | |
4791 | else | |
4792 | lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions); | |
dea3101e | 4793 | } |
2534ba75 | 4794 | |
a257bf90 JS |
4795 | /* Cancel all the IOCBs from the completions list */ |
4796 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
4797 | IOERR_SLI_ABORTED); | |
2534ba75 | 4798 | |
2fe165b6 | 4799 | return 0; |
dea3101e | 4800 | } |
4801 | ||
086a345f JS |
4802 | /** |
4803 | * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO | |
4804 | * @phba: Pointer to HBA context object. | |
4805 | * @pmb: Pointer to mailbox object. | |
4806 | * | |
4807 | * This function will issue an ELS LOGO command after completing | |
4808 | * the UNREG_RPI. | |
4809 | **/ | |
b86a6756 | 4810 | static void |
086a345f JS |
4811 | lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
4812 | { | |
4813 | struct lpfc_vport *vport = pmb->vport; | |
4814 | struct lpfc_nodelist *ndlp; | |
4815 | ||
3e1f0718 | 4816 | ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp); |
086a345f JS |
4817 | if (!ndlp) |
4818 | return; | |
4819 | lpfc_issue_els_logo(vport, ndlp, 0); | |
4aa74c3c | 4820 | mempool_free(pmb, phba->mbox_mem_pool); |
dea16bda JS |
4821 | |
4822 | /* Check to see if there are any deferred events to process */ | |
4823 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && | |
4824 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { | |
4825 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
4826 | "1434 UNREG cmpl deferred logo x%x " | |
4827 | "on NPort x%x Data: x%x %p\n", | |
4828 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
4829 | ndlp->nlp_defer_did, ndlp); | |
4830 | ||
4831 | ndlp->nlp_flag &= ~NLP_UNREG_INP; | |
4832 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; | |
4833 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
00292e03 | 4834 | } else { |
4f1a2fef JS |
4835 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
4836 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); | |
4837 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; | |
4838 | } | |
00292e03 | 4839 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
dea16bda | 4840 | } |
086a345f JS |
4841 | } |
4842 | ||
dea3101e | 4843 | /* |
4844 | * Free rpi associated with LPFC_NODELIST entry. | |
4845 | * This routine is called from lpfc_freenode(), when we are removing | |
4846 | * a LPFC_NODELIST entry. It is also called if the driver initiates a | |
4847 | * LOGO that completes successfully, and we are waiting to PLOGI back | |
4848 | * to the remote NPort. In addition, it is called after we receive | |
4849 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and | |
4850 | * we are waiting to PLOGI back to the remote NPort. | |
4851 | */ | |
4852 | int | |
2e0fef85 | 4853 | lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 4854 | { |
2e0fef85 JS |
4855 | struct lpfc_hba *phba = vport->phba; |
4856 | LPFC_MBOXQ_t *mbox; | |
7c5e518c | 4857 | int rc, acc_plogi = 1; |
6d368e53 | 4858 | uint16_t rpi; |
dea3101e | 4859 | |
f454a9ac JS |
4860 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED || |
4861 | ndlp->nlp_flag & NLP_REG_LOGIN_SEND) { | |
4862 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) | |
4863 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, | |
4864 | "3366 RPI x%x needs to be " | |
4865 | "unregistered nlp_flag x%x " | |
4866 | "did x%x\n", | |
4867 | ndlp->nlp_rpi, ndlp->nlp_flag, | |
4868 | ndlp->nlp_DID); | |
dea16bda JS |
4869 | |
4870 | /* If there is already an UNREG in progress for this ndlp, | |
4871 | * no need to queue up another one. | |
4872 | */ | |
4873 | if (ndlp->nlp_flag & NLP_UNREG_INP) { | |
4874 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
4875 | "1436 unreg_rpi SKIP UNREG x%x on " | |
4876 | "NPort x%x deferred x%x flg x%x " | |
4877 | "Data: %p\n", | |
4878 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
4879 | ndlp->nlp_defer_did, | |
4880 | ndlp->nlp_flag, ndlp); | |
4881 | goto out; | |
4882 | } | |
4883 | ||
2e0fef85 JS |
4884 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4885 | if (mbox) { | |
6d368e53 JS |
4886 | /* SLI4 ports require the physical rpi value. */ |
4887 | rpi = ndlp->nlp_rpi; | |
4888 | if (phba->sli_rev == LPFC_SLI_REV4) | |
4889 | rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; | |
086a345f | 4890 | |
6d368e53 | 4891 | lpfc_unreg_login(phba, vport->vpi, rpi, mbox); |
ed957684 | 4892 | mbox->vport = vport; |
086a345f | 4893 | if (ndlp->nlp_flag & NLP_ISSUE_LOGO) { |
3e1f0718 | 4894 | mbox->ctx_ndlp = ndlp; |
086a345f JS |
4895 | mbox->mbox_cmpl = lpfc_nlp_logo_unreg; |
4896 | } else { | |
be6bb941 JS |
4897 | if (phba->sli_rev == LPFC_SLI_REV4 && |
4898 | (!(vport->load_flag & FC_UNLOADING)) && | |
4899 | (bf_get(lpfc_sli_intf_if_type, | |
719162bd | 4900 | &phba->sli4_hba.sli_intf) >= |
a6517db9 | 4901 | LPFC_SLI_INTF_IF_TYPE_2) && |
2c935bc5 | 4902 | (kref_read(&ndlp->kref) > 0)) { |
3e1f0718 | 4903 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
be6bb941 JS |
4904 | mbox->mbox_cmpl = |
4905 | lpfc_sli4_unreg_rpi_cmpl_clr; | |
7c5e518c JS |
4906 | /* |
4907 | * accept PLOGIs after unreg_rpi_cmpl | |
4908 | */ | |
4909 | acc_plogi = 0; | |
9b164068 JS |
4910 | } else if (vport->load_flag & FC_UNLOADING) { |
4911 | mbox->ctx_ndlp = NULL; | |
4912 | mbox->mbox_cmpl = | |
4913 | lpfc_sli_def_mbox_cmpl; | |
dea16bda JS |
4914 | } else { |
4915 | mbox->ctx_ndlp = ndlp; | |
be6bb941 JS |
4916 | mbox->mbox_cmpl = |
4917 | lpfc_sli_def_mbox_cmpl; | |
dea16bda | 4918 | } |
086a345f | 4919 | } |
dea16bda JS |
4920 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != |
4921 | Fabric_DID_MASK) && | |
4922 | (!(vport->fc_flag & FC_OFFLINE_MODE))) | |
4923 | ndlp->nlp_flag |= NLP_UNREG_INP; | |
4924 | ||
4925 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
4926 | "1433 unreg_rpi UNREG x%x on " | |
4927 | "NPort x%x deferred flg x%x Data:%p\n", | |
4928 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
4929 | ndlp->nlp_flag, ndlp); | |
086a345f | 4930 | |
0b727fea | 4931 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
7c5e518c | 4932 | if (rc == MBX_NOT_FINISHED) { |
2e0fef85 | 4933 | mempool_free(mbox, phba->mbox_mem_pool); |
7c5e518c JS |
4934 | acc_plogi = 1; |
4935 | } | |
dea3101e | 4936 | } |
dea3101e | 4937 | lpfc_no_rpi(phba, ndlp); |
dea16bda | 4938 | out: |
4042629e JS |
4939 | if (phba->sli_rev != LPFC_SLI_REV4) |
4940 | ndlp->nlp_rpi = 0; | |
4941 | ndlp->nlp_flag &= ~NLP_RPI_REGISTERED; | |
0c287589 | 4942 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
7c5e518c JS |
4943 | if (acc_plogi) |
4944 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; | |
dea3101e | 4945 | return 1; |
4946 | } | |
7c5e518c | 4947 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
dea3101e | 4948 | return 0; |
4949 | } | |
4950 | ||
ecfd03c6 JS |
4951 | /** |
4952 | * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba. | |
4953 | * @phba: pointer to lpfc hba data structure. | |
4954 | * | |
4955 | * This routine is invoked to unregister all the currently registered RPIs | |
4956 | * to the HBA. | |
4957 | **/ | |
4958 | void | |
4959 | lpfc_unreg_hba_rpis(struct lpfc_hba *phba) | |
4960 | { | |
4961 | struct lpfc_vport **vports; | |
4962 | struct lpfc_nodelist *ndlp; | |
4963 | struct Scsi_Host *shost; | |
4964 | int i; | |
4965 | ||
4966 | vports = lpfc_create_vport_work_array(phba); | |
63e801ce JS |
4967 | if (!vports) { |
4968 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
4969 | "2884 Vport array allocation failed \n"); | |
4970 | return; | |
4971 | } | |
ecfd03c6 JS |
4972 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
4973 | shost = lpfc_shost_from_vport(vports[i]); | |
4974 | spin_lock_irq(shost->host_lock); | |
4975 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { | |
4042629e | 4976 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
0c9ab6f5 JS |
4977 | /* The mempool_alloc might sleep */ |
4978 | spin_unlock_irq(shost->host_lock); | |
ecfd03c6 | 4979 | lpfc_unreg_rpi(vports[i], ndlp); |
0c9ab6f5 JS |
4980 | spin_lock_irq(shost->host_lock); |
4981 | } | |
ecfd03c6 JS |
4982 | } |
4983 | spin_unlock_irq(shost->host_lock); | |
4984 | } | |
4985 | lpfc_destroy_vport_work_array(phba, vports); | |
4986 | } | |
4987 | ||
92d7f7b0 JS |
4988 | void |
4989 | lpfc_unreg_all_rpis(struct lpfc_vport *vport) | |
4990 | { | |
4991 | struct lpfc_hba *phba = vport->phba; | |
4992 | LPFC_MBOXQ_t *mbox; | |
4993 | int rc; | |
4994 | ||
5af5eee7 JS |
4995 | if (phba->sli_rev == LPFC_SLI_REV4) { |
4996 | lpfc_sli4_unreg_all_rpis(vport); | |
4997 | return; | |
4998 | } | |
4999 | ||
92d7f7b0 JS |
5000 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5001 | if (mbox) { | |
6d368e53 JS |
5002 | lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT, |
5003 | mbox); | |
92d7f7b0 JS |
5004 | mbox->vport = vport; |
5005 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3e1f0718 | 5006 | mbox->ctx_ndlp = NULL; |
09372820 | 5007 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
a257bf90 | 5008 | if (rc != MBX_TIMEOUT) |
92d7f7b0 | 5009 | mempool_free(mbox, phba->mbox_mem_pool); |
a257bf90 JS |
5010 | |
5011 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) | |
5012 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, | |
5013 | "1836 Could not issue " | |
5014 | "unreg_login(all_rpis) status %d\n", rc); | |
92d7f7b0 JS |
5015 | } |
5016 | } | |
5017 | ||
5018 | void | |
5019 | lpfc_unreg_default_rpis(struct lpfc_vport *vport) | |
5020 | { | |
5021 | struct lpfc_hba *phba = vport->phba; | |
5022 | LPFC_MBOXQ_t *mbox; | |
5023 | int rc; | |
5024 | ||
c95a3b4b JS |
5025 | /* Unreg DID is an SLI3 operation. */ |
5026 | if (phba->sli_rev > LPFC_SLI_REV3) | |
5027 | return; | |
5028 | ||
92d7f7b0 JS |
5029 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5030 | if (mbox) { | |
6d368e53 JS |
5031 | lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS, |
5032 | mbox); | |
92d7f7b0 JS |
5033 | mbox->vport = vport; |
5034 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3e1f0718 | 5035 | mbox->ctx_ndlp = NULL; |
09372820 | 5036 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
a257bf90 JS |
5037 | if (rc != MBX_TIMEOUT) |
5038 | mempool_free(mbox, phba->mbox_mem_pool); | |
5039 | ||
5040 | if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED)) | |
e8b62011 JS |
5041 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT, |
5042 | "1815 Could not issue " | |
a257bf90 JS |
5043 | "unreg_did (default rpis) status %d\n", |
5044 | rc); | |
92d7f7b0 JS |
5045 | } |
5046 | } | |
5047 | ||
dea3101e | 5048 | /* |
5049 | * Free resources associated with LPFC_NODELIST entry | |
5050 | * so it can be freed. | |
5051 | */ | |
5052 | static int | |
2e0fef85 | 5053 | lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 5054 | { |
2e0fef85 JS |
5055 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5056 | struct lpfc_hba *phba = vport->phba; | |
5057 | LPFC_MBOXQ_t *mb, *nextmb; | |
dea3101e | 5058 | struct lpfc_dmabuf *mp; |
dea3101e | 5059 | |
5060 | /* Cleanup node for NPort <nlp_DID> */ | |
e8b62011 JS |
5061 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
5062 | "0900 Cleanup node for NPort x%x " | |
5063 | "Data: x%x x%x x%x\n", | |
5064 | ndlp->nlp_DID, ndlp->nlp_flag, | |
5065 | ndlp->nlp_state, ndlp->nlp_rpi); | |
e47c9093 JS |
5066 | if (NLP_CHK_FREE_REQ(ndlp)) { |
5067 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
5068 | "0280 lpfc_cleanup_node: ndlp:x%p " | |
5069 | "usgmap:x%x refcnt:%d\n", | |
5070 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 5071 | kref_read(&ndlp->kref)); |
e47c9093 JS |
5072 | lpfc_dequeue_node(vport, ndlp); |
5073 | } else { | |
5074 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
5075 | "0281 lpfc_cleanup_node: ndlp:x%p " | |
5076 | "usgmap:x%x refcnt:%d\n", | |
5077 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 5078 | kref_read(&ndlp->kref)); |
e47c9093 JS |
5079 | lpfc_disable_node(vport, ndlp); |
5080 | } | |
dea3101e | 5081 | |
086a345f JS |
5082 | |
5083 | /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */ | |
5084 | ||
dea3101e | 5085 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
5086 | if ((mb = phba->sli.mbox_active)) { | |
04c68496 | 5087 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
086a345f | 5088 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
3e1f0718 JS |
5089 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
5090 | mb->ctx_ndlp = NULL; | |
dea3101e | 5091 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
5092 | } | |
5093 | } | |
33ccf8d1 | 5094 | |
2e0fef85 | 5095 | spin_lock_irq(&phba->hbalock); |
5ac6b303 JS |
5096 | /* Cleanup REG_LOGIN completions which are not yet processed */ |
5097 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
5098 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) || | |
086a345f | 5099 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG) || |
3e1f0718 | 5100 | (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp)) |
5ac6b303 JS |
5101 | continue; |
5102 | ||
3e1f0718 | 5103 | mb->ctx_ndlp = NULL; |
5ac6b303 JS |
5104 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
5105 | } | |
5106 | ||
dea3101e | 5107 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
04c68496 | 5108 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
086a345f | 5109 | !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) && |
3e1f0718 JS |
5110 | (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) { |
5111 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); | |
dea3101e | 5112 | if (mp) { |
2e0fef85 | 5113 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e | 5114 | kfree(mp); |
5115 | } | |
5116 | list_del(&mb->list); | |
5117 | mempool_free(mb, phba->mbox_mem_pool); | |
e47c9093 JS |
5118 | /* We shall not invoke the lpfc_nlp_put to decrement |
5119 | * the ndlp reference count as we are in the process | |
5120 | * of lpfc_nlp_release. | |
5121 | */ | |
dea3101e | 5122 | } |
5123 | } | |
2e0fef85 | 5124 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 5125 | |
e47c9093 JS |
5126 | lpfc_els_abort(phba, ndlp); |
5127 | ||
2e0fef85 | 5128 | spin_lock_irq(shost->host_lock); |
c01f3208 | 5129 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
2e0fef85 | 5130 | spin_unlock_irq(shost->host_lock); |
dea3101e | 5131 | |
5024ab17 | 5132 | ndlp->nlp_last_elscmd = 0; |
dea3101e | 5133 | del_timer_sync(&ndlp->nlp_delayfunc); |
5134 | ||
0d2b6b83 JS |
5135 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
5136 | list_del_init(&ndlp->dev_loss_evt.evt_listp); | |
1151e3ec | 5137 | lpfc_cleanup_vports_rrqs(vport, ndlp); |
4f1a2fef JS |
5138 | if (phba->sli_rev == LPFC_SLI_REV4) |
5139 | ndlp->nlp_flag |= NLP_RELEASE_RPI; | |
2e0fef85 | 5140 | lpfc_unreg_rpi(vport, ndlp); |
dea3101e | 5141 | |
2fe165b6 | 5142 | return 0; |
dea3101e | 5143 | } |
5144 | ||
5145 | /* | |
5146 | * Check to see if we can free the nlp back to the freelist. | |
5147 | * If we are in the middle of using the nlp in the discovery state | |
5148 | * machine, defer the free till we reach the end of the state machine. | |
5149 | */ | |
329f9bc7 | 5150 | static void |
2e0fef85 | 5151 | lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 5152 | { |
a8adb832 | 5153 | struct lpfc_hba *phba = vport->phba; |
1dcb58e5 | 5154 | struct lpfc_rport_data *rdata; |
466e840b | 5155 | struct fc_rport *rport; |
a8adb832 JS |
5156 | LPFC_MBOXQ_t *mbox; |
5157 | int rc; | |
dea3101e | 5158 | |
0d2b6b83 | 5159 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
21e9a0a5 | 5160 | if ((ndlp->nlp_flag & NLP_DEFER_RM) && |
4042629e | 5161 | !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) && |
e8bcf0ae DK |
5162 | !(ndlp->nlp_flag & NLP_RPI_REGISTERED) && |
5163 | phba->sli_rev != LPFC_SLI_REV4) { | |
a8adb832 JS |
5164 | /* For this case we need to cleanup the default rpi |
5165 | * allocated by the firmware. | |
5166 | */ | |
be6bb941 JS |
5167 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
5168 | "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", | |
5169 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 5170 | kref_read(&ndlp->kref), |
be6bb941 | 5171 | ndlp->nlp_usg_map, ndlp); |
a8adb832 JS |
5172 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) |
5173 | != NULL) { | |
21e9a0a5 | 5174 | rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID, |
4042629e | 5175 | (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi); |
a8adb832 JS |
5176 | if (rc) { |
5177 | mempool_free(mbox, phba->mbox_mem_pool); | |
5178 | } | |
5179 | else { | |
5180 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
5181 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
5182 | mbox->vport = vport; | |
3e1f0718 | 5183 | mbox->ctx_ndlp = ndlp; |
a8adb832 JS |
5184 | rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
5185 | if (rc == MBX_NOT_FINISHED) { | |
5186 | mempool_free(mbox, phba->mbox_mem_pool); | |
5187 | } | |
5188 | } | |
5189 | } | |
5190 | } | |
2e0fef85 | 5191 | lpfc_cleanup_node(vport, ndlp); |
1dcb58e5 | 5192 | |
2e0fef85 | 5193 | /* |
466e840b JS |
5194 | * ndlp->rport must be set to NULL before it reaches here |
5195 | * i.e. break rport/node link before doing lpfc_nlp_put for | |
5196 | * registered rport and then drop the reference of rport. | |
2e0fef85 | 5197 | */ |
92d7f7b0 | 5198 | if (ndlp->rport) { |
466e840b JS |
5199 | /* |
5200 | * extra lpfc_nlp_put dropped the reference of ndlp | |
5201 | * for registered rport so need to cleanup rport | |
5202 | */ | |
5203 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, | |
5204 | "0940 removed node x%p DID x%x " | |
5205 | " rport not null %p\n", | |
5206 | ndlp, ndlp->nlp_DID, ndlp->rport); | |
5207 | rport = ndlp->rport; | |
5208 | rdata = rport->dd_data; | |
329f9bc7 JS |
5209 | rdata->pnode = NULL; |
5210 | ndlp->rport = NULL; | |
466e840b | 5211 | put_device(&rport->dev); |
dea3101e | 5212 | } |
dea3101e | 5213 | } |
5214 | ||
5215 | static int | |
2e0fef85 JS |
5216 | lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
5217 | uint32_t did) | |
dea3101e | 5218 | { |
2e0fef85 | 5219 | D_ID mydid, ndlpdid, matchdid; |
dea3101e | 5220 | |
5221 | if (did == Bcast_DID) | |
2fe165b6 | 5222 | return 0; |
dea3101e | 5223 | |
dea3101e | 5224 | /* First check for Direct match */ |
5225 | if (ndlp->nlp_DID == did) | |
2fe165b6 | 5226 | return 1; |
dea3101e | 5227 | |
5228 | /* Next check for area/domain identically equals 0 match */ | |
2e0fef85 | 5229 | mydid.un.word = vport->fc_myDID; |
dea3101e | 5230 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { |
2fe165b6 | 5231 | return 0; |
dea3101e | 5232 | } |
5233 | ||
5234 | matchdid.un.word = did; | |
5235 | ndlpdid.un.word = ndlp->nlp_DID; | |
5236 | if (matchdid.un.b.id == ndlpdid.un.b.id) { | |
5237 | if ((mydid.un.b.domain == matchdid.un.b.domain) && | |
5238 | (mydid.un.b.area == matchdid.un.b.area)) { | |
6b337e03 JS |
5239 | /* This code is supposed to match the ID |
5240 | * for a private loop device that is | |
5241 | * connect to fl_port. But we need to | |
5242 | * check that the port did not just go | |
5243 | * from pt2pt to fabric or we could end | |
5244 | * up matching ndlp->nlp_DID 000001 to | |
5245 | * fabric DID 0x20101 | |
5246 | */ | |
dea3101e | 5247 | if ((ndlpdid.un.b.domain == 0) && |
5248 | (ndlpdid.un.b.area == 0)) { | |
6b337e03 JS |
5249 | if (ndlpdid.un.b.id && |
5250 | vport->phba->fc_topology == | |
5251 | LPFC_TOPOLOGY_LOOP) | |
2fe165b6 | 5252 | return 1; |
dea3101e | 5253 | } |
2fe165b6 | 5254 | return 0; |
dea3101e | 5255 | } |
5256 | ||
5257 | matchdid.un.word = ndlp->nlp_DID; | |
5258 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && | |
5259 | (mydid.un.b.area == ndlpdid.un.b.area)) { | |
5260 | if ((matchdid.un.b.domain == 0) && | |
5261 | (matchdid.un.b.area == 0)) { | |
5262 | if (matchdid.un.b.id) | |
2fe165b6 | 5263 | return 1; |
dea3101e | 5264 | } |
5265 | } | |
5266 | } | |
2fe165b6 | 5267 | return 0; |
dea3101e | 5268 | } |
5269 | ||
685f0bf7 | 5270 | /* Search for a nodelist entry */ |
2e0fef85 JS |
5271 | static struct lpfc_nodelist * |
5272 | __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) | |
dea3101e | 5273 | { |
2fb9bd8b | 5274 | struct lpfc_nodelist *ndlp; |
dea3101e | 5275 | uint32_t data1; |
5276 | ||
2e0fef85 JS |
5277 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
5278 | if (lpfc_matchdid(vport, ndlp, did)) { | |
b95b2119 JS |
5279 | data1 = (((uint32_t)ndlp->nlp_state << 24) | |
5280 | ((uint32_t)ndlp->nlp_xri << 16) | | |
5281 | ((uint32_t)ndlp->nlp_type << 8) | | |
5282 | ((uint32_t)ndlp->nlp_usg_map & 0xff)); | |
e8b62011 JS |
5283 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
5284 | "0929 FIND node DID " | |
b95b2119 | 5285 | "Data: x%px x%x x%x x%x x%x x%px\n", |
e8b62011 | 5286 | ndlp, ndlp->nlp_DID, |
b95b2119 | 5287 | ndlp->nlp_flag, data1, ndlp->nlp_rpi, |
cff261f6 | 5288 | ndlp->active_rrqs_xri_bitmap); |
685f0bf7 | 5289 | return ndlp; |
dea3101e | 5290 | } |
5291 | } | |
66a9ed66 | 5292 | |
dea3101e | 5293 | /* FIND node did <did> NOT FOUND */ |
e8b62011 JS |
5294 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
5295 | "0932 FIND node did x%x NOT FOUND.\n", did); | |
dea3101e | 5296 | return NULL; |
5297 | } | |
5298 | ||
5299 | struct lpfc_nodelist * | |
2e0fef85 JS |
5300 | lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did) |
5301 | { | |
5302 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
5303 | struct lpfc_nodelist *ndlp; | |
fedd3b7b | 5304 | unsigned long iflags; |
2e0fef85 | 5305 | |
fedd3b7b | 5306 | spin_lock_irqsave(shost->host_lock, iflags); |
2e0fef85 | 5307 | ndlp = __lpfc_findnode_did(vport, did); |
fedd3b7b | 5308 | spin_unlock_irqrestore(shost->host_lock, iflags); |
2e0fef85 JS |
5309 | return ndlp; |
5310 | } | |
5311 | ||
f60cb93b JS |
5312 | struct lpfc_nodelist * |
5313 | lpfc_findnode_mapped(struct lpfc_vport *vport) | |
5314 | { | |
5315 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
5316 | struct lpfc_nodelist *ndlp; | |
5317 | uint32_t data1; | |
5318 | unsigned long iflags; | |
5319 | ||
5320 | spin_lock_irqsave(shost->host_lock, iflags); | |
5321 | ||
5322 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
5323 | if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE || | |
5324 | ndlp->nlp_state == NLP_STE_MAPPED_NODE) { | |
5325 | data1 = (((uint32_t)ndlp->nlp_state << 24) | | |
5326 | ((uint32_t)ndlp->nlp_xri << 16) | | |
5327 | ((uint32_t)ndlp->nlp_type << 8) | | |
5328 | ((uint32_t)ndlp->nlp_rpi & 0xff)); | |
5329 | spin_unlock_irqrestore(shost->host_lock, iflags); | |
5330 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, | |
5331 | "2025 FIND node DID " | |
5332 | "Data: x%p x%x x%x x%x %p\n", | |
5333 | ndlp, ndlp->nlp_DID, | |
5334 | ndlp->nlp_flag, data1, | |
5335 | ndlp->active_rrqs_xri_bitmap); | |
5336 | return ndlp; | |
5337 | } | |
5338 | } | |
5339 | spin_unlock_irqrestore(shost->host_lock, iflags); | |
5340 | ||
5341 | /* FIND node did <did> NOT FOUND */ | |
5342 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, | |
5343 | "2026 FIND mapped did NOT FOUND.\n"); | |
5344 | return NULL; | |
5345 | } | |
5346 | ||
2e0fef85 JS |
5347 | struct lpfc_nodelist * |
5348 | lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did) | |
dea3101e | 5349 | { |
2e0fef85 | 5350 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 5351 | struct lpfc_nodelist *ndlp; |
dea3101e | 5352 | |
2e0fef85 | 5353 | ndlp = lpfc_findnode_did(vport, did); |
c9f8735b | 5354 | if (!ndlp) { |
1c5b12f7 JS |
5355 | if (vport->phba->nvmet_support) |
5356 | return NULL; | |
2e0fef85 JS |
5357 | if ((vport->fc_flag & FC_RSCN_MODE) != 0 && |
5358 | lpfc_rscn_payload_check(vport, did) == 0) | |
dea3101e | 5359 | return NULL; |
9d3d340d | 5360 | ndlp = lpfc_nlp_init(vport, did); |
dea3101e | 5361 | if (!ndlp) |
5362 | return NULL; | |
2e0fef85 JS |
5363 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
5364 | spin_lock_irq(shost->host_lock); | |
dea3101e | 5365 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 5366 | spin_unlock_irq(shost->host_lock); |
dea3101e | 5367 | return ndlp; |
e47c9093 | 5368 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
1c5b12f7 JS |
5369 | if (vport->phba->nvmet_support) |
5370 | return NULL; | |
e47c9093 | 5371 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE); |
b95b2119 JS |
5372 | if (!ndlp) { |
5373 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, | |
5374 | "0014 Could not enable ndlp\n"); | |
e47c9093 | 5375 | return NULL; |
b95b2119 | 5376 | } |
e47c9093 JS |
5377 | spin_lock_irq(shost->host_lock); |
5378 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
5379 | spin_unlock_irq(shost->host_lock); | |
5380 | return ndlp; | |
dea3101e | 5381 | } |
e47c9093 | 5382 | |
1c5b12f7 JS |
5383 | /* The NVME Target does not want to actively manage an rport. |
5384 | * The goal is to allow the target to reset its state and clear | |
5385 | * pending IO in preparation for the initiator to recover. | |
5386 | */ | |
58da1ffb JS |
5387 | if ((vport->fc_flag & FC_RSCN_MODE) && |
5388 | !(vport->fc_flag & FC_NDISC_ACTIVE)) { | |
2e0fef85 | 5389 | if (lpfc_rscn_payload_check(vport, did)) { |
87af33fe | 5390 | |
c9f8735b JW |
5391 | /* Since this node is marked for discovery, |
5392 | * delay timeout is not needed. | |
5393 | */ | |
0d2b6b83 | 5394 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
1c5b12f7 JS |
5395 | |
5396 | /* NVME Target mode waits until rport is known to be | |
5397 | * impacted by the RSCN before it transitions. No | |
5398 | * active management - just go to NPR provided the | |
5399 | * node had a valid login. | |
5400 | */ | |
8c258641 JS |
5401 | if (vport->phba->nvmet_support) |
5402 | return ndlp; | |
1c5b12f7 JS |
5403 | |
5404 | /* If we've already received a PLOGI from this NPort | |
5405 | * we don't need to try to discover it again. | |
5406 | */ | |
5407 | if (ndlp->nlp_flag & NLP_RCV_PLOGI) | |
5408 | return NULL; | |
5409 | ||
a257bf90 JS |
5410 | spin_lock_irq(shost->host_lock); |
5411 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
5412 | spin_unlock_irq(shost->host_lock); | |
071fbd3d | 5413 | } else |
dea3101e | 5414 | ndlp = NULL; |
2fe165b6 | 5415 | } else { |
1c5b12f7 JS |
5416 | /* If the initiator received a PLOGI from this NPort or if the |
5417 | * initiator is already in the process of discovery on it, | |
5418 | * there's no need to try to discover it again. | |
87af33fe | 5419 | */ |
685f0bf7 | 5420 | if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE || |
87af33fe | 5421 | ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
1c5b12f7 JS |
5422 | (!vport->phba->nvmet_support && |
5423 | ndlp->nlp_flag & NLP_RCV_PLOGI)) | |
dea3101e | 5424 | return NULL; |
1c5b12f7 | 5425 | |
8c258641 JS |
5426 | if (vport->phba->nvmet_support) |
5427 | return ndlp; | |
1c5b12f7 JS |
5428 | |
5429 | /* Moving to NPR state clears unsolicited flags and | |
5430 | * allows for rediscovery | |
5431 | */ | |
5432 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
5433 | ||
2e0fef85 | 5434 | spin_lock_irq(shost->host_lock); |
dea3101e | 5435 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
2e0fef85 | 5436 | spin_unlock_irq(shost->host_lock); |
dea3101e | 5437 | } |
5438 | return ndlp; | |
5439 | } | |
5440 | ||
5441 | /* Build a list of nodes to discover based on the loopmap */ | |
5442 | void | |
2e0fef85 | 5443 | lpfc_disc_list_loopmap(struct lpfc_vport *vport) |
dea3101e | 5444 | { |
2e0fef85 | 5445 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 5446 | int j; |
5447 | uint32_t alpa, index; | |
5448 | ||
2e0fef85 | 5449 | if (!lpfc_is_link_up(phba)) |
dea3101e | 5450 | return; |
2e0fef85 | 5451 | |
76a95d75 | 5452 | if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) |
dea3101e | 5453 | return; |
dea3101e | 5454 | |
5455 | /* Check for loop map present or not */ | |
5456 | if (phba->alpa_map[0]) { | |
5457 | for (j = 1; j <= phba->alpa_map[0]; j++) { | |
5458 | alpa = phba->alpa_map[j]; | |
2e0fef85 | 5459 | if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0)) |
dea3101e | 5460 | continue; |
2e0fef85 | 5461 | lpfc_setup_disc_node(vport, alpa); |
dea3101e | 5462 | } |
5463 | } else { | |
5464 | /* No alpamap, so try all alpa's */ | |
5465 | for (j = 0; j < FC_MAXLOOP; j++) { | |
5466 | /* If cfg_scan_down is set, start from highest | |
5467 | * ALPA (0xef) to lowest (0x1). | |
5468 | */ | |
3de2a653 | 5469 | if (vport->cfg_scan_down) |
dea3101e | 5470 | index = j; |
5471 | else | |
5472 | index = FC_MAXLOOP - j - 1; | |
5473 | alpa = lpfcAlpaArray[index]; | |
2e0fef85 | 5474 | if ((vport->fc_myDID & 0xff) == alpa) |
dea3101e | 5475 | continue; |
2e0fef85 | 5476 | lpfc_setup_disc_node(vport, alpa); |
dea3101e | 5477 | } |
5478 | } | |
5479 | return; | |
5480 | } | |
5481 | ||
895427bd | 5482 | /* SLI3 only */ |
dea3101e | 5483 | void |
2e0fef85 | 5484 | lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport) |
dea3101e | 5485 | { |
dea3101e | 5486 | LPFC_MBOXQ_t *mbox; |
2e0fef85 | 5487 | struct lpfc_sli *psli = &phba->sli; |
895427bd JS |
5488 | struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
5489 | struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING]; | |
2e0fef85 JS |
5490 | int rc; |
5491 | ||
92d7f7b0 JS |
5492 | /* |
5493 | * if it's not a physical port or if we already send | |
5494 | * clear_la then don't send it. | |
5495 | */ | |
5496 | if ((phba->link_state >= LPFC_CLEAR_LA) || | |
da0436e9 JS |
5497 | (vport->port_type != LPFC_PHYSICAL_PORT) || |
5498 | (phba->sli_rev == LPFC_SLI_REV4)) | |
92d7f7b0 JS |
5499 | return; |
5500 | ||
2e0fef85 JS |
5501 | /* Link up discovery */ |
5502 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) { | |
5503 | phba->link_state = LPFC_CLEAR_LA; | |
5504 | lpfc_clear_la(phba, mbox); | |
5505 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
5506 | mbox->vport = vport; | |
0b727fea | 5507 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
2e0fef85 JS |
5508 | if (rc == MBX_NOT_FINISHED) { |
5509 | mempool_free(mbox, phba->mbox_mem_pool); | |
5510 | lpfc_disc_flush_list(vport); | |
5511 | extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT; | |
5512 | fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT; | |
92d7f7b0 JS |
5513 | phba->link_state = LPFC_HBA_ERROR; |
5514 | } | |
5515 | } | |
5516 | } | |
5517 | ||
5518 | /* Reg_vpi to tell firmware to resume normal operations */ | |
5519 | void | |
5520 | lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport) | |
5521 | { | |
5522 | LPFC_MBOXQ_t *regvpimbox; | |
5523 | ||
5524 | regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5525 | if (regvpimbox) { | |
da0436e9 | 5526 | lpfc_reg_vpi(vport, regvpimbox); |
92d7f7b0 JS |
5527 | regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi; |
5528 | regvpimbox->vport = vport; | |
0b727fea | 5529 | if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT) |
92d7f7b0 JS |
5530 | == MBX_NOT_FINISHED) { |
5531 | mempool_free(regvpimbox, phba->mbox_mem_pool); | |
2e0fef85 JS |
5532 | } |
5533 | } | |
5534 | } | |
5535 | ||
5536 | /* Start Link up / RSCN discovery on NPR nodes */ | |
5537 | void | |
5538 | lpfc_disc_start(struct lpfc_vport *vport) | |
5539 | { | |
5540 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
5541 | struct lpfc_hba *phba = vport->phba; | |
685f0bf7 | 5542 | uint32_t num_sent; |
dea3101e | 5543 | uint32_t clear_la_pending; |
dea3101e | 5544 | |
e74c03c8 JS |
5545 | if (!lpfc_is_link_up(phba)) { |
5546 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, | |
5547 | "3315 Link is not up %x\n", | |
5548 | phba->link_state); | |
dea3101e | 5549 | return; |
e74c03c8 | 5550 | } |
2e0fef85 JS |
5551 | |
5552 | if (phba->link_state == LPFC_CLEAR_LA) | |
dea3101e | 5553 | clear_la_pending = 1; |
5554 | else | |
5555 | clear_la_pending = 0; | |
5556 | ||
2e0fef85 JS |
5557 | if (vport->port_state < LPFC_VPORT_READY) |
5558 | vport->port_state = LPFC_DISC_AUTH; | |
dea3101e | 5559 | |
2e0fef85 JS |
5560 | lpfc_set_disctmo(vport); |
5561 | ||
2e0fef85 JS |
5562 | vport->fc_prevDID = vport->fc_myDID; |
5563 | vport->num_disc_nodes = 0; | |
dea3101e | 5564 | |
5565 | /* Start Discovery state <hba_state> */ | |
e8b62011 JS |
5566 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
5567 | "0202 Start Discovery hba state x%x " | |
5568 | "Data: x%x x%x x%x\n", | |
5569 | vport->port_state, vport->fc_flag, vport->fc_plogi_cnt, | |
5570 | vport->fc_adisc_cnt); | |
dea3101e | 5571 | |
5572 | /* First do ADISCs - if any */ | |
2e0fef85 | 5573 | num_sent = lpfc_els_disc_adisc(vport); |
dea3101e | 5574 | |
5575 | if (num_sent) | |
5576 | return; | |
5577 | ||
6fa139f3 | 5578 | /* Register the VPI for SLI3, NPIV only. */ |
92d7f7b0 | 5579 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
1b32f6aa | 5580 | !(vport->fc_flag & FC_PT2PT) && |
da0436e9 JS |
5581 | !(vport->fc_flag & FC_RSCN_MODE) && |
5582 | (phba->sli_rev < LPFC_SLI_REV4)) { | |
85c0f177 | 5583 | lpfc_issue_clear_la(phba, vport); |
92d7f7b0 JS |
5584 | lpfc_issue_reg_vpi(phba, vport); |
5585 | return; | |
5586 | } | |
5587 | ||
5588 | /* | |
5589 | * For SLI2, we need to set port_state to READY and continue | |
5590 | * discovery. | |
5591 | */ | |
2e0fef85 | 5592 | if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) { |
dea3101e | 5593 | /* If we get here, there is nothing to ADISC */ |
85c0f177 | 5594 | lpfc_issue_clear_la(phba, vport); |
2e0fef85 | 5595 | |
92d7f7b0 | 5596 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
2e0fef85 JS |
5597 | vport->num_disc_nodes = 0; |
5598 | /* go thru NPR nodes and issue ELS PLOGIs */ | |
5599 | if (vport->fc_npr_cnt) | |
5600 | lpfc_els_disc_plogi(vport); | |
5601 | ||
5602 | if (!vport->num_disc_nodes) { | |
5603 | spin_lock_irq(shost->host_lock); | |
5604 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
5605 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 | 5606 | lpfc_can_disctmo(vport); |
dea3101e | 5607 | } |
5608 | } | |
92d7f7b0 | 5609 | vport->port_state = LPFC_VPORT_READY; |
dea3101e | 5610 | } else { |
5611 | /* Next do PLOGIs - if any */ | |
2e0fef85 | 5612 | num_sent = lpfc_els_disc_plogi(vport); |
dea3101e | 5613 | |
5614 | if (num_sent) | |
5615 | return; | |
5616 | ||
2e0fef85 | 5617 | if (vport->fc_flag & FC_RSCN_MODE) { |
dea3101e | 5618 | /* Check to see if more RSCNs came in while we |
5619 | * were processing this one. | |
5620 | */ | |
2e0fef85 JS |
5621 | if ((vport->fc_rscn_id_cnt == 0) && |
5622 | (!(vport->fc_flag & FC_RSCN_DISCOVERY))) { | |
5623 | spin_lock_irq(shost->host_lock); | |
5624 | vport->fc_flag &= ~FC_RSCN_MODE; | |
5625 | spin_unlock_irq(shost->host_lock); | |
92d7f7b0 | 5626 | lpfc_can_disctmo(vport); |
2fe165b6 | 5627 | } else |
2e0fef85 | 5628 | lpfc_els_handle_rscn(vport); |
dea3101e | 5629 | } |
5630 | } | |
5631 | return; | |
5632 | } | |
5633 | ||
5634 | /* | |
5635 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS | |
5636 | * ring the match the sppecified nodelist. | |
5637 | */ | |
5638 | static void | |
2e0fef85 | 5639 | lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 5640 | { |
2534ba75 | 5641 | LIST_HEAD(completions); |
dea3101e | 5642 | IOCB_t *icmd; |
5643 | struct lpfc_iocbq *iocb, *next_iocb; | |
5644 | struct lpfc_sli_ring *pring; | |
dea3101e | 5645 | |
895427bd | 5646 | pring = lpfc_phba_elsring(phba); |
1234a6d5 DK |
5647 | if (unlikely(!pring)) |
5648 | return; | |
dea3101e | 5649 | |
5650 | /* Error matching iocb on txq or txcmplq | |
5651 | * First check the txq. | |
5652 | */ | |
2e0fef85 | 5653 | spin_lock_irq(&phba->hbalock); |
dea3101e | 5654 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
5655 | if (iocb->context1 != ndlp) { | |
5656 | continue; | |
5657 | } | |
5658 | icmd = &iocb->iocb; | |
5659 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || | |
5660 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { | |
5661 | ||
2534ba75 | 5662 | list_move_tail(&iocb->list, &completions); |
dea3101e | 5663 | } |
5664 | } | |
5665 | ||
5666 | /* Next check the txcmplq */ | |
5667 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { | |
5668 | if (iocb->context1 != ndlp) { | |
5669 | continue; | |
5670 | } | |
5671 | icmd = &iocb->iocb; | |
2e0fef85 JS |
5672 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR || |
5673 | icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) { | |
2534ba75 JS |
5674 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
5675 | } | |
5676 | } | |
2e0fef85 | 5677 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 5678 | |
a257bf90 JS |
5679 | /* Cancel all the IOCBs from the completions list */ |
5680 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
5681 | IOERR_SLI_ABORTED); | |
dea3101e | 5682 | } |
5683 | ||
a6ababd2 | 5684 | static void |
2e0fef85 | 5685 | lpfc_disc_flush_list(struct lpfc_vport *vport) |
dea3101e | 5686 | { |
5687 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2e0fef85 | 5688 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 5689 | |
2e0fef85 JS |
5690 | if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) { |
5691 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, | |
685f0bf7 | 5692 | nlp_listp) { |
e47c9093 JS |
5693 | if (!NLP_CHK_NODE_ACT(ndlp)) |
5694 | continue; | |
685f0bf7 JS |
5695 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || |
5696 | ndlp->nlp_state == NLP_STE_ADISC_ISSUE) { | |
5697 | lpfc_free_tx(phba, ndlp); | |
685f0bf7 | 5698 | } |
dea3101e | 5699 | } |
5700 | } | |
dea3101e | 5701 | } |
5702 | ||
92d7f7b0 JS |
5703 | void |
5704 | lpfc_cleanup_discovery_resources(struct lpfc_vport *vport) | |
5705 | { | |
5706 | lpfc_els_flush_rscn(vport); | |
5707 | lpfc_els_flush_cmd(vport); | |
5708 | lpfc_disc_flush_list(vport); | |
5709 | } | |
5710 | ||
dea3101e | 5711 | /*****************************************************************************/ |
5712 | /* | |
5713 | * NAME: lpfc_disc_timeout | |
5714 | * | |
5715 | * FUNCTION: Fibre Channel driver discovery timeout routine. | |
5716 | * | |
5717 | * EXECUTION ENVIRONMENT: interrupt only | |
5718 | * | |
5719 | * CALLED FROM: | |
5720 | * Timer function | |
5721 | * | |
5722 | * RETURNS: | |
5723 | * none | |
5724 | */ | |
5725 | /*****************************************************************************/ | |
5726 | void | |
f22eb4d3 | 5727 | lpfc_disc_timeout(struct timer_list *t) |
dea3101e | 5728 | { |
f22eb4d3 | 5729 | struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo); |
2e0fef85 | 5730 | struct lpfc_hba *phba = vport->phba; |
5e9d9b82 | 5731 | uint32_t tmo_posted; |
dea3101e | 5732 | unsigned long flags = 0; |
5733 | ||
5734 | if (unlikely(!phba)) | |
5735 | return; | |
5736 | ||
5e9d9b82 JS |
5737 | spin_lock_irqsave(&vport->work_port_lock, flags); |
5738 | tmo_posted = vport->work_port_events & WORKER_DISC_TMO; | |
5739 | if (!tmo_posted) | |
2e0fef85 | 5740 | vport->work_port_events |= WORKER_DISC_TMO; |
5e9d9b82 | 5741 | spin_unlock_irqrestore(&vport->work_port_lock, flags); |
2e0fef85 | 5742 | |
5e9d9b82 JS |
5743 | if (!tmo_posted) |
5744 | lpfc_worker_wake_up(phba); | |
dea3101e | 5745 | return; |
5746 | } | |
5747 | ||
5748 | static void | |
2e0fef85 | 5749 | lpfc_disc_timeout_handler(struct lpfc_vport *vport) |
dea3101e | 5750 | { |
2e0fef85 JS |
5751 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
5752 | struct lpfc_hba *phba = vport->phba; | |
5753 | struct lpfc_sli *psli = &phba->sli; | |
c9f8735b | 5754 | struct lpfc_nodelist *ndlp, *next_ndlp; |
92d7f7b0 | 5755 | LPFC_MBOXQ_t *initlinkmbox; |
dea3101e | 5756 | int rc, clrlaerr = 0; |
5757 | ||
2e0fef85 | 5758 | if (!(vport->fc_flag & FC_DISC_TMO)) |
dea3101e | 5759 | return; |
5760 | ||
2e0fef85 JS |
5761 | spin_lock_irq(shost->host_lock); |
5762 | vport->fc_flag &= ~FC_DISC_TMO; | |
5763 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 5764 | |
858c9f6c JS |
5765 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
5766 | "disc timeout: state:x%x rtry:x%x flg:x%x", | |
5767 | vport->port_state, vport->fc_ns_retry, vport->fc_flag); | |
5768 | ||
2e0fef85 | 5769 | switch (vport->port_state) { |
dea3101e | 5770 | |
5771 | case LPFC_LOCAL_CFG_LINK: | |
a0f2d3ef JS |
5772 | /* |
5773 | * port_state is identically LPFC_LOCAL_CFG_LINK while | |
5774 | * waiting for FAN timeout | |
5775 | */ | |
e8b62011 JS |
5776 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
5777 | "0221 FAN timeout\n"); | |
a0f2d3ef | 5778 | |
c9f8735b | 5779 | /* Start discovery by sending FLOGI, clean up old rpis */ |
2e0fef85 | 5780 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
685f0bf7 | 5781 | nlp_listp) { |
e47c9093 JS |
5782 | if (!NLP_CHK_NODE_ACT(ndlp)) |
5783 | continue; | |
685f0bf7 JS |
5784 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
5785 | continue; | |
c9f8735b JW |
5786 | if (ndlp->nlp_type & NLP_FABRIC) { |
5787 | /* Clean up the ndlp on Fabric connections */ | |
2e0fef85 | 5788 | lpfc_drop_node(vport, ndlp); |
87af33fe | 5789 | |
2fe165b6 | 5790 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
c9f8735b JW |
5791 | /* Fail outstanding IO now since device |
5792 | * is marked for PLOGI. | |
5793 | */ | |
2e0fef85 | 5794 | lpfc_unreg_rpi(vport, ndlp); |
c9f8735b JW |
5795 | } |
5796 | } | |
92d7f7b0 | 5797 | if (vport->port_state != LPFC_FLOGI) { |
76a95d75 JS |
5798 | if (phba->sli_rev <= LPFC_SLI_REV3) |
5799 | lpfc_initial_flogi(vport); | |
5800 | else | |
5801 | lpfc_issue_init_vfi(vport); | |
0ff10d46 | 5802 | return; |
92d7f7b0 | 5803 | } |
dea3101e | 5804 | break; |
5805 | ||
92d7f7b0 | 5806 | case LPFC_FDISC: |
dea3101e | 5807 | case LPFC_FLOGI: |
2e0fef85 | 5808 | /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ |
dea3101e | 5809 | /* Initial FLOGI timeout */ |
e8b62011 JS |
5810 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5811 | "0222 Initial %s timeout\n", | |
87af33fe | 5812 | vport->vpi ? "FDISC" : "FLOGI"); |
dea3101e | 5813 | |
5814 | /* Assume no Fabric and go on with discovery. | |
5815 | * Check for outstanding ELS FLOGI to abort. | |
5816 | */ | |
5817 | ||
5818 | /* FLOGI failed, so just use loop map to make discovery list */ | |
2e0fef85 | 5819 | lpfc_disc_list_loopmap(vport); |
dea3101e | 5820 | |
5821 | /* Start discovery */ | |
2e0fef85 | 5822 | lpfc_disc_start(vport); |
dea3101e | 5823 | break; |
5824 | ||
5825 | case LPFC_FABRIC_CFG_LINK: | |
5826 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for | |
5827 | NameServer login */ | |
e8b62011 JS |
5828 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5829 | "0223 Timeout while waiting for " | |
5830 | "NameServer login\n"); | |
dea3101e | 5831 | /* Next look for NameServer ndlp */ |
2e0fef85 | 5832 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
e47c9093 | 5833 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
87af33fe JS |
5834 | lpfc_els_abort(phba, ndlp); |
5835 | ||
5836 | /* ReStart discovery */ | |
5837 | goto restart_disc; | |
dea3101e | 5838 | |
5839 | case LPFC_NS_QRY: | |
5840 | /* Check for wait for NameServer Rsp timeout */ | |
e8b62011 JS |
5841 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5842 | "0224 NameServer Query timeout " | |
5843 | "Data: x%x x%x\n", | |
5844 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); | |
dea3101e | 5845 | |
92d7f7b0 JS |
5846 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
5847 | /* Try it one more time */ | |
5848 | vport->fc_ns_retry++; | |
a0f2d3ef JS |
5849 | vport->gidft_inp = 0; |
5850 | rc = lpfc_issue_gidft(vport); | |
92d7f7b0 JS |
5851 | if (rc == 0) |
5852 | break; | |
dea3101e | 5853 | } |
92d7f7b0 | 5854 | vport->fc_ns_retry = 0; |
dea3101e | 5855 | |
87af33fe | 5856 | restart_disc: |
92d7f7b0 JS |
5857 | /* |
5858 | * Discovery is over. | |
5859 | * set port_state to PORT_READY if SLI2. | |
5860 | * cmpl_reg_vpi will set port_state to READY for SLI3. | |
5861 | */ | |
3772a991 JS |
5862 | if (phba->sli_rev < LPFC_SLI_REV4) { |
5863 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
5864 | lpfc_issue_reg_vpi(phba, vport); | |
6d368e53 | 5865 | else { |
3772a991 JS |
5866 | lpfc_issue_clear_la(phba, vport); |
5867 | vport->port_state = LPFC_VPORT_READY; | |
5868 | } | |
dea3101e | 5869 | } |
5870 | ||
5871 | /* Setup and issue mailbox INITIALIZE LINK command */ | |
5872 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5873 | if (!initlinkmbox) { | |
e8b62011 JS |
5874 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5875 | "0206 Device Discovery " | |
5876 | "completion error\n"); | |
2e0fef85 | 5877 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 5878 | break; |
5879 | } | |
5880 | ||
5881 | lpfc_linkdown(phba); | |
5882 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, | |
5883 | phba->cfg_link_speed); | |
04c68496 | 5884 | initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; |
ed957684 | 5885 | initlinkmbox->vport = vport; |
92d7f7b0 | 5886 | initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
0b727fea | 5887 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT); |
5b8bd0c9 | 5888 | lpfc_set_loopback_flag(phba); |
dea3101e | 5889 | if (rc == MBX_NOT_FINISHED) |
5890 | mempool_free(initlinkmbox, phba->mbox_mem_pool); | |
5891 | ||
5892 | break; | |
5893 | ||
5894 | case LPFC_DISC_AUTH: | |
5895 | /* Node Authentication timeout */ | |
e8b62011 JS |
5896 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5897 | "0227 Node Authentication timeout\n"); | |
2e0fef85 JS |
5898 | lpfc_disc_flush_list(vport); |
5899 | ||
92d7f7b0 JS |
5900 | /* |
5901 | * set port_state to PORT_READY if SLI2. | |
5902 | * cmpl_reg_vpi will set port_state to READY for SLI3. | |
5903 | */ | |
3772a991 JS |
5904 | if (phba->sli_rev < LPFC_SLI_REV4) { |
5905 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
5906 | lpfc_issue_reg_vpi(phba, vport); | |
5907 | else { /* NPIV Not enabled */ | |
5908 | lpfc_issue_clear_la(phba, vport); | |
5909 | vport->port_state = LPFC_VPORT_READY; | |
5910 | } | |
dea3101e | 5911 | } |
5912 | break; | |
5913 | ||
2e0fef85 JS |
5914 | case LPFC_VPORT_READY: |
5915 | if (vport->fc_flag & FC_RSCN_MODE) { | |
e8b62011 JS |
5916 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5917 | "0231 RSCN timeout Data: x%x " | |
5918 | "x%x\n", | |
5919 | vport->fc_ns_retry, LPFC_MAX_NS_RETRY); | |
dea3101e | 5920 | |
5921 | /* Cleanup any outstanding ELS commands */ | |
2e0fef85 | 5922 | lpfc_els_flush_cmd(vport); |
dea3101e | 5923 | |
2e0fef85 JS |
5924 | lpfc_els_flush_rscn(vport); |
5925 | lpfc_disc_flush_list(vport); | |
dea3101e | 5926 | } |
5927 | break; | |
2e0fef85 | 5928 | |
92d7f7b0 | 5929 | default: |
e8b62011 | 5930 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
d7c255b2 | 5931 | "0273 Unexpected discovery timeout, " |
e8b62011 | 5932 | "vport State x%x\n", vport->port_state); |
2e0fef85 JS |
5933 | break; |
5934 | } | |
5935 | ||
5936 | switch (phba->link_state) { | |
5937 | case LPFC_CLEAR_LA: | |
92d7f7b0 | 5938 | /* CLEAR LA timeout */ |
e8b62011 JS |
5939 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5940 | "0228 CLEAR LA timeout\n"); | |
2e0fef85 JS |
5941 | clrlaerr = 1; |
5942 | break; | |
5943 | ||
09372820 JS |
5944 | case LPFC_LINK_UP: |
5945 | lpfc_issue_clear_la(phba, vport); | |
cd05c155 | 5946 | /* fall through */ |
2e0fef85 JS |
5947 | case LPFC_LINK_UNKNOWN: |
5948 | case LPFC_WARM_START: | |
5949 | case LPFC_INIT_START: | |
5950 | case LPFC_INIT_MBX_CMDS: | |
5951 | case LPFC_LINK_DOWN: | |
2e0fef85 | 5952 | case LPFC_HBA_ERROR: |
e8b62011 JS |
5953 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
5954 | "0230 Unexpected timeout, hba link " | |
5955 | "state x%x\n", phba->link_state); | |
2e0fef85 JS |
5956 | clrlaerr = 1; |
5957 | break; | |
92d7f7b0 JS |
5958 | |
5959 | case LPFC_HBA_READY: | |
5960 | break; | |
dea3101e | 5961 | } |
5962 | ||
5963 | if (clrlaerr) { | |
2e0fef85 | 5964 | lpfc_disc_flush_list(vport); |
895427bd JS |
5965 | if (phba->sli_rev != LPFC_SLI_REV4) { |
5966 | psli->sli3_ring[(LPFC_EXTRA_RING)].flag &= | |
5967 | ~LPFC_STOP_IOCB_EVENT; | |
5968 | psli->sli3_ring[LPFC_FCP_RING].flag &= | |
5969 | ~LPFC_STOP_IOCB_EVENT; | |
5970 | } | |
2e0fef85 | 5971 | vport->port_state = LPFC_VPORT_READY; |
dea3101e | 5972 | } |
dea3101e | 5973 | return; |
5974 | } | |
5975 | ||
dea3101e | 5976 | /* |
5977 | * This routine handles processing a NameServer REG_LOGIN mailbox | |
5978 | * command upon completion. It is setup in the LPFC_MBOXQ | |
5979 | * as the completion routine when the command is | |
5980 | * handed off to the SLI layer. | |
5981 | */ | |
5982 | void | |
2e0fef85 | 5983 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 5984 | { |
04c68496 | 5985 | MAILBOX_t *mb = &pmb->u.mb; |
3e1f0718 JS |
5986 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
5987 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; | |
2e0fef85 | 5988 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 5989 | |
3e1f0718 JS |
5990 | pmb->ctx_buf = NULL; |
5991 | pmb->ctx_ndlp = NULL; | |
dea3101e | 5992 | |
6d368e53 JS |
5993 | if (phba->sli_rev < LPFC_SLI_REV4) |
5994 | ndlp->nlp_rpi = mb->un.varWords[0]; | |
4042629e | 5995 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
dea3101e | 5996 | ndlp->nlp_type |= NLP_FABRIC; |
2e0fef85 | 5997 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
be6bb941 JS |
5998 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
5999 | "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", | |
6000 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 6001 | kref_read(&ndlp->kref), |
be6bb941 | 6002 | ndlp->nlp_usg_map, ndlp); |
2e0fef85 JS |
6003 | /* |
6004 | * Start issuing Fabric-Device Management Interface (FDMI) command to | |
4258e98e JS |
6005 | * 0xfffffa (FDMI well known port). |
6006 | * DHBA -> DPRT -> RHBA -> RPA (physical port) | |
6007 | * DPRT -> RPRT (vports) | |
dea3101e | 6008 | */ |
4258e98e JS |
6009 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
6010 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); | |
76b2c34a | 6011 | else |
4258e98e JS |
6012 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
6013 | ||
dea3101e | 6014 | |
fa4066b6 JS |
6015 | /* decrement the node reference count held for this callback |
6016 | * function. | |
6017 | */ | |
329f9bc7 | 6018 | lpfc_nlp_put(ndlp); |
dea3101e | 6019 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
6020 | kfree(mp); | |
329f9bc7 | 6021 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 6022 | |
6023 | return; | |
6024 | } | |
6025 | ||
685f0bf7 JS |
6026 | static int |
6027 | lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param) | |
6028 | { | |
6029 | uint16_t *rpi = param; | |
6030 | ||
eff4a01b JS |
6031 | /* check for active node */ |
6032 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
6033 | return 0; | |
6034 | ||
685f0bf7 JS |
6035 | return ndlp->nlp_rpi == *rpi; |
6036 | } | |
6037 | ||
6038 | static int | |
6039 | lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param) | |
6040 | { | |
6041 | return memcmp(&ndlp->nlp_portname, param, | |
6042 | sizeof(ndlp->nlp_portname)) == 0; | |
6043 | } | |
6044 | ||
a6ababd2 | 6045 | static struct lpfc_nodelist * |
2e0fef85 | 6046 | __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param) |
dea3101e | 6047 | { |
21568f53 | 6048 | struct lpfc_nodelist *ndlp; |
dea3101e | 6049 | |
2e0fef85 | 6050 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
34f5ad8b JS |
6051 | if (filter(ndlp, param)) { |
6052 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, | |
6053 | "3185 FIND node filter %p DID " | |
4938250e JS |
6054 | "ndlp %p did x%x flg x%x st x%x " |
6055 | "xri x%x type x%x rpi x%x\n", | |
34f5ad8b | 6056 | filter, ndlp, ndlp->nlp_DID, |
4938250e JS |
6057 | ndlp->nlp_flag, ndlp->nlp_state, |
6058 | ndlp->nlp_xri, ndlp->nlp_type, | |
6059 | ndlp->nlp_rpi); | |
685f0bf7 | 6060 | return ndlp; |
34f5ad8b | 6061 | } |
685f0bf7 | 6062 | } |
34f5ad8b JS |
6063 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
6064 | "3186 FIND node filter %p NOT FOUND.\n", filter); | |
21568f53 | 6065 | return NULL; |
dea3101e | 6066 | } |
6067 | ||
685f0bf7 JS |
6068 | /* |
6069 | * This routine looks up the ndlp lists for the given RPI. If rpi found it | |
2e0fef85 | 6070 | * returns the node list element pointer else return NULL. |
685f0bf7 JS |
6071 | */ |
6072 | struct lpfc_nodelist * | |
2e0fef85 | 6073 | __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) |
685f0bf7 | 6074 | { |
2e0fef85 | 6075 | return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi); |
685f0bf7 JS |
6076 | } |
6077 | ||
488d1469 | 6078 | /* |
685f0bf7 | 6079 | * This routine looks up the ndlp lists for the given WWPN. If WWPN found it |
2e0fef85 | 6080 | * returns the node element list pointer else return NULL. |
488d1469 JS |
6081 | */ |
6082 | struct lpfc_nodelist * | |
2e0fef85 | 6083 | lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn) |
488d1469 | 6084 | { |
2e0fef85 | 6085 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
488d1469 | 6086 | struct lpfc_nodelist *ndlp; |
488d1469 | 6087 | |
2e0fef85 JS |
6088 | spin_lock_irq(shost->host_lock); |
6089 | ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn); | |
6090 | spin_unlock_irq(shost->host_lock); | |
858c9f6c | 6091 | return ndlp; |
488d1469 JS |
6092 | } |
6093 | ||
cb69f7de JS |
6094 | /* |
6095 | * This routine looks up the ndlp lists for the given RPI. If the rpi | |
6096 | * is found, the routine returns the node element list pointer else | |
6097 | * return NULL. | |
6098 | */ | |
6099 | struct lpfc_nodelist * | |
6100 | lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi) | |
6101 | { | |
6102 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
6103 | struct lpfc_nodelist *ndlp; | |
78d4b132 | 6104 | unsigned long flags; |
cb69f7de | 6105 | |
78d4b132 | 6106 | spin_lock_irqsave(shost->host_lock, flags); |
cb69f7de | 6107 | ndlp = __lpfc_findnode_rpi(vport, rpi); |
78d4b132 | 6108 | spin_unlock_irqrestore(shost->host_lock, flags); |
cb69f7de JS |
6109 | return ndlp; |
6110 | } | |
6111 | ||
6112 | /** | |
6113 | * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier | |
6114 | * @phba: pointer to lpfc hba data structure. | |
6115 | * @vpi: the physical host virtual N_Port identifier. | |
6116 | * | |
6117 | * This routine finds a vport on a HBA (referred by @phba) through a | |
6118 | * @vpi. The function walks the HBA's vport list and returns the address | |
6119 | * of the vport with the matching @vpi. | |
6120 | * | |
6121 | * Return code | |
6122 | * NULL - No vport with the matching @vpi found | |
6123 | * Otherwise - Address to the vport with the matching @vpi. | |
6124 | **/ | |
6125 | struct lpfc_vport * | |
6126 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) | |
6127 | { | |
6128 | struct lpfc_vport *vport; | |
6129 | unsigned long flags; | |
6130 | int i = 0; | |
6131 | ||
6132 | /* The physical ports are always vpi 0 - translate is unnecessary. */ | |
6133 | if (vpi > 0) { | |
6134 | /* | |
6135 | * Translate the physical vpi to the logical vpi. The | |
6136 | * vport stores the logical vpi. | |
6137 | */ | |
6138 | for (i = 0; i < phba->max_vpi; i++) { | |
6139 | if (vpi == phba->vpi_ids[i]) | |
6140 | break; | |
6141 | } | |
6142 | ||
6143 | if (i >= phba->max_vpi) { | |
6144 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
6145 | "2936 Could not find Vport mapped " | |
6146 | "to vpi %d\n", vpi); | |
6147 | return NULL; | |
6148 | } | |
6149 | } | |
6150 | ||
523128e5 | 6151 | spin_lock_irqsave(&phba->port_list_lock, flags); |
cb69f7de JS |
6152 | list_for_each_entry(vport, &phba->port_list, listentry) { |
6153 | if (vport->vpi == i) { | |
523128e5 | 6154 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
cb69f7de JS |
6155 | return vport; |
6156 | } | |
6157 | } | |
523128e5 | 6158 | spin_unlock_irqrestore(&phba->port_list_lock, flags); |
cb69f7de JS |
6159 | return NULL; |
6160 | } | |
6161 | ||
9d3d340d JS |
6162 | struct lpfc_nodelist * |
6163 | lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did) | |
dea3101e | 6164 | { |
9d3d340d JS |
6165 | struct lpfc_nodelist *ndlp; |
6166 | int rpi = LPFC_RPI_ALLOC_ERROR; | |
6167 | ||
6168 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { | |
6169 | rpi = lpfc_sli4_alloc_rpi(vport->phba); | |
6170 | if (rpi == LPFC_RPI_ALLOC_ERROR) | |
6171 | return NULL; | |
6172 | } | |
6173 | ||
6174 | ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL); | |
6175 | if (!ndlp) { | |
6176 | if (vport->phba->sli_rev == LPFC_SLI_REV4) | |
6177 | lpfc_sli4_free_rpi(vport->phba, rpi); | |
6178 | return NULL; | |
6179 | } | |
6180 | ||
dea3101e | 6181 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); |
109f6ed0 JS |
6182 | |
6183 | lpfc_initialize_node(vport, ndlp, did); | |
685f0bf7 | 6184 | INIT_LIST_HEAD(&ndlp->nlp_listp); |
cff261f6 | 6185 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { |
9d3d340d | 6186 | ndlp->nlp_rpi = rpi; |
be6bb941 JS |
6187 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, |
6188 | "0007 rpi:%x DID:%x flg:%x refcnt:%d " | |
6189 | "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, | |
6190 | ndlp->nlp_flag, | |
2c935bc5 | 6191 | kref_read(&ndlp->kref), |
be6bb941 JS |
6192 | ndlp->nlp_usg_map, ndlp); |
6193 | ||
cff261f6 JS |
6194 | ndlp->active_rrqs_xri_bitmap = |
6195 | mempool_alloc(vport->phba->active_rrq_pool, | |
6196 | GFP_KERNEL); | |
59c5f61f JS |
6197 | if (ndlp->active_rrqs_xri_bitmap) |
6198 | memset(ndlp->active_rrqs_xri_bitmap, 0, | |
6199 | ndlp->phba->cfg_rrq_xri_bitmap_sz); | |
cff261f6 JS |
6200 | } |
6201 | ||
725dd399 | 6202 | |
858c9f6c JS |
6203 | |
6204 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, | |
6205 | "node init: did:x%x", | |
6206 | ndlp->nlp_DID, 0, 0); | |
6207 | ||
9d3d340d | 6208 | return ndlp; |
dea3101e | 6209 | } |
329f9bc7 | 6210 | |
98c9ea5c JS |
6211 | /* This routine releases all resources associated with a specifc NPort's ndlp |
6212 | * and mempool_free's the nodelist. | |
6213 | */ | |
311464ec | 6214 | static void |
329f9bc7 JS |
6215 | lpfc_nlp_release(struct kref *kref) |
6216 | { | |
e47c9093 JS |
6217 | struct lpfc_hba *phba; |
6218 | unsigned long flags; | |
329f9bc7 JS |
6219 | struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist, |
6220 | kref); | |
858c9f6c JS |
6221 | |
6222 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, | |
6223 | "node release: did:x%x flg:x%x type:x%x", | |
6224 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type); | |
6225 | ||
e47c9093 | 6226 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
939723a4 | 6227 | "0279 lpfc_nlp_release: ndlp:x%p did %x " |
be6bb941 | 6228 | "usgmap:x%x refcnt:%d rpi:%x\n", |
939723a4 | 6229 | (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, |
2c935bc5 | 6230 | kref_read(&ndlp->kref), ndlp->nlp_rpi); |
e47c9093 JS |
6231 | |
6232 | /* remove ndlp from action. */ | |
2e0fef85 | 6233 | lpfc_nlp_remove(ndlp->vport, ndlp); |
e47c9093 JS |
6234 | |
6235 | /* clear the ndlp active flag for all release cases */ | |
a257bf90 | 6236 | phba = ndlp->phba; |
e47c9093 JS |
6237 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
6238 | NLP_CLR_NODE_ACT(ndlp); | |
6239 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
6240 | ||
6241 | /* free ndlp memory for final ndlp release */ | |
ea2151b4 JS |
6242 | if (NLP_CHK_FREE_REQ(ndlp)) { |
6243 | kfree(ndlp->lat_data); | |
cff261f6 JS |
6244 | if (phba->sli_rev == LPFC_SLI_REV4) |
6245 | mempool_free(ndlp->active_rrqs_xri_bitmap, | |
6246 | ndlp->phba->active_rrq_pool); | |
a257bf90 | 6247 | mempool_free(ndlp, ndlp->phba->nlp_mem_pool); |
ea2151b4 | 6248 | } |
329f9bc7 JS |
6249 | } |
6250 | ||
98c9ea5c JS |
6251 | /* This routine bumps the reference count for a ndlp structure to ensure |
6252 | * that one discovery thread won't free a ndlp while another discovery thread | |
6253 | * is using it. | |
6254 | */ | |
329f9bc7 JS |
6255 | struct lpfc_nodelist * |
6256 | lpfc_nlp_get(struct lpfc_nodelist *ndlp) | |
6257 | { | |
e47c9093 JS |
6258 | struct lpfc_hba *phba; |
6259 | unsigned long flags; | |
6260 | ||
98c9ea5c JS |
6261 | if (ndlp) { |
6262 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, | |
6263 | "node get: did:x%x flg:x%x refcnt:x%x", | |
6264 | ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 6265 | kref_read(&ndlp->kref)); |
e47c9093 JS |
6266 | /* The check of ndlp usage to prevent incrementing the |
6267 | * ndlp reference count that is in the process of being | |
6268 | * released. | |
6269 | */ | |
a257bf90 | 6270 | phba = ndlp->phba; |
e47c9093 JS |
6271 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
6272 | if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) { | |
6273 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
6274 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, | |
6275 | "0276 lpfc_nlp_get: ndlp:x%p " | |
6276 | "usgmap:x%x refcnt:%d\n", | |
6277 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 6278 | kref_read(&ndlp->kref)); |
e47c9093 JS |
6279 | return NULL; |
6280 | } else | |
6281 | kref_get(&ndlp->kref); | |
6282 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
98c9ea5c | 6283 | } |
329f9bc7 JS |
6284 | return ndlp; |
6285 | } | |
6286 | ||
98c9ea5c | 6287 | /* This routine decrements the reference count for a ndlp structure. If the |
e47c9093 JS |
6288 | * count goes to 0, this indicates the the associated nodelist should be |
6289 | * freed. Returning 1 indicates the ndlp resource has been released; on the | |
6290 | * other hand, returning 0 indicates the ndlp resource has not been released | |
6291 | * yet. | |
98c9ea5c | 6292 | */ |
329f9bc7 JS |
6293 | int |
6294 | lpfc_nlp_put(struct lpfc_nodelist *ndlp) | |
6295 | { | |
e47c9093 JS |
6296 | struct lpfc_hba *phba; |
6297 | unsigned long flags; | |
6298 | ||
6299 | if (!ndlp) | |
6300 | return 1; | |
6301 | ||
6302 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, | |
6303 | "node put: did:x%x flg:x%x refcnt:x%x", | |
6304 | ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 | 6305 | kref_read(&ndlp->kref)); |
a257bf90 | 6306 | phba = ndlp->phba; |
e47c9093 JS |
6307 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
6308 | /* Check the ndlp memory free acknowledge flag to avoid the | |
6309 | * possible race condition that kref_put got invoked again | |
6310 | * after previous one has done ndlp memory free. | |
6311 | */ | |
6312 | if (NLP_CHK_FREE_ACK(ndlp)) { | |
6313 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
6314 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, | |
6315 | "0274 lpfc_nlp_put: ndlp:x%p " | |
6316 | "usgmap:x%x refcnt:%d\n", | |
6317 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 6318 | kref_read(&ndlp->kref)); |
e47c9093 JS |
6319 | return 1; |
6320 | } | |
6321 | /* Check the ndlp inactivate log flag to avoid the possible | |
6322 | * race condition that kref_put got invoked again after ndlp | |
6323 | * is already in inactivating state. | |
6324 | */ | |
6325 | if (NLP_CHK_IACT_REQ(ndlp)) { | |
6326 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
6327 | lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE, | |
6328 | "0275 lpfc_nlp_put: ndlp:x%p " | |
6329 | "usgmap:x%x refcnt:%d\n", | |
6330 | (void *)ndlp, ndlp->nlp_usg_map, | |
2c935bc5 | 6331 | kref_read(&ndlp->kref)); |
e47c9093 | 6332 | return 1; |
98c9ea5c | 6333 | } |
e47c9093 JS |
6334 | /* For last put, mark the ndlp usage flags to make sure no |
6335 | * other kref_get and kref_put on the same ndlp shall get | |
6336 | * in between the process when the final kref_put has been | |
6337 | * invoked on this ndlp. | |
6338 | */ | |
2c935bc5 | 6339 | if (kref_read(&ndlp->kref) == 1) { |
e47c9093 JS |
6340 | /* Indicate ndlp is put to inactive state. */ |
6341 | NLP_SET_IACT_REQ(ndlp); | |
6342 | /* Acknowledge ndlp memory free has been seen. */ | |
6343 | if (NLP_CHK_FREE_REQ(ndlp)) | |
6344 | NLP_SET_FREE_ACK(ndlp); | |
6345 | } | |
6346 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); | |
6347 | /* Note, the kref_put returns 1 when decrementing a reference | |
6348 | * count that was 1, it invokes the release callback function, | |
6349 | * but it still left the reference count as 1 (not actually | |
6350 | * performs the last decrementation). Otherwise, it actually | |
6351 | * decrements the reference count and returns 0. | |
6352 | */ | |
6353 | return kref_put(&ndlp->kref, lpfc_nlp_release); | |
329f9bc7 | 6354 | } |
98c9ea5c JS |
6355 | |
6356 | /* This routine free's the specified nodelist if it is not in use | |
e47c9093 JS |
6357 | * by any other discovery thread. This routine returns 1 if the |
6358 | * ndlp has been freed. A return value of 0 indicates the ndlp is | |
6359 | * not yet been released. | |
98c9ea5c JS |
6360 | */ |
6361 | int | |
6362 | lpfc_nlp_not_used(struct lpfc_nodelist *ndlp) | |
6363 | { | |
6364 | lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, | |
6365 | "node not used: did:x%x flg:x%x refcnt:x%x", | |
6366 | ndlp->nlp_DID, ndlp->nlp_flag, | |
2c935bc5 PZ |
6367 | kref_read(&ndlp->kref)); |
6368 | if (kref_read(&ndlp->kref) == 1) | |
e47c9093 JS |
6369 | if (lpfc_nlp_put(ndlp)) |
6370 | return 1; | |
98c9ea5c JS |
6371 | return 0; |
6372 | } | |
6fb120a7 JS |
6373 | |
6374 | /** | |
6375 | * lpfc_fcf_inuse - Check if FCF can be unregistered. | |
6376 | * @phba: Pointer to hba context object. | |
6377 | * | |
6378 | * This function iterate through all FC nodes associated | |
6379 | * will all vports to check if there is any node with | |
6380 | * fc_rports associated with it. If there is an fc_rport | |
6381 | * associated with the node, then the node is either in | |
6382 | * discovered state or its devloss_timer is pending. | |
6383 | */ | |
6384 | static int | |
6385 | lpfc_fcf_inuse(struct lpfc_hba *phba) | |
6386 | { | |
6387 | struct lpfc_vport **vports; | |
6388 | int i, ret = 0; | |
6389 | struct lpfc_nodelist *ndlp; | |
6390 | struct Scsi_Host *shost; | |
6391 | ||
6392 | vports = lpfc_create_vport_work_array(phba); | |
6393 | ||
63e801ce JS |
6394 | /* If driver cannot allocate memory, indicate fcf is in use */ |
6395 | if (!vports) | |
6396 | return 1; | |
6397 | ||
6fb120a7 JS |
6398 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
6399 | shost = lpfc_shost_from_vport(vports[i]); | |
6400 | spin_lock_irq(shost->host_lock); | |
0558056c JS |
6401 | /* |
6402 | * IF the CVL_RCVD bit is not set then we have sent the | |
6403 | * flogi. | |
6404 | * If dev_loss fires while we are waiting we do not want to | |
6405 | * unreg the fcf. | |
6406 | */ | |
6407 | if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) { | |
6408 | spin_unlock_irq(shost->host_lock); | |
6409 | ret = 1; | |
6410 | goto out; | |
6411 | } | |
6fb120a7 JS |
6412 | list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) { |
6413 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport && | |
6414 | (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { | |
6415 | ret = 1; | |
6416 | spin_unlock_irq(shost->host_lock); | |
6417 | goto out; | |
80c17849 JS |
6418 | } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { |
6419 | ret = 1; | |
891478a2 | 6420 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
80c17849 JS |
6421 | "2624 RPI %x DID %x flag %x " |
6422 | "still logged in\n", | |
6423 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
6424 | ndlp->nlp_flag); | |
6fb120a7 JS |
6425 | } |
6426 | } | |
6427 | spin_unlock_irq(shost->host_lock); | |
6428 | } | |
6429 | out: | |
6430 | lpfc_destroy_vport_work_array(phba, vports); | |
6431 | return ret; | |
6432 | } | |
6433 | ||
6434 | /** | |
6435 | * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi. | |
6436 | * @phba: Pointer to hba context object. | |
6437 | * @mboxq: Pointer to mailbox object. | |
6438 | * | |
6439 | * This function frees memory associated with the mailbox command. | |
6440 | */ | |
1b51197d | 6441 | void |
6fb120a7 JS |
6442 | lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
6443 | { | |
6444 | struct lpfc_vport *vport = mboxq->vport; | |
38b92ef8 | 6445 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
6fb120a7 JS |
6446 | |
6447 | if (mboxq->u.mb.mbxStatus) { | |
6448 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
6449 | "2555 UNREG_VFI mbxStatus error x%x " | |
6450 | "HBA state x%x\n", | |
6451 | mboxq->u.mb.mbxStatus, vport->port_state); | |
6452 | } | |
38b92ef8 JS |
6453 | spin_lock_irq(shost->host_lock); |
6454 | phba->pport->fc_flag &= ~FC_VFI_REGISTERED; | |
6455 | spin_unlock_irq(shost->host_lock); | |
6fb120a7 JS |
6456 | mempool_free(mboxq, phba->mbox_mem_pool); |
6457 | return; | |
6458 | } | |
6459 | ||
6460 | /** | |
6461 | * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi. | |
6462 | * @phba: Pointer to hba context object. | |
6463 | * @mboxq: Pointer to mailbox object. | |
6464 | * | |
6465 | * This function frees memory associated with the mailbox command. | |
6466 | */ | |
6467 | static void | |
6468 | lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
6469 | { | |
6470 | struct lpfc_vport *vport = mboxq->vport; | |
6471 | ||
6472 | if (mboxq->u.mb.mbxStatus) { | |
6473 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
6474 | "2550 UNREG_FCFI mbxStatus error x%x " | |
6475 | "HBA state x%x\n", | |
6476 | mboxq->u.mb.mbxStatus, vport->port_state); | |
6477 | } | |
6478 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6479 | return; | |
6480 | } | |
6481 | ||
6482 | /** | |
ecfd03c6 | 6483 | * lpfc_unregister_fcf_prep - Unregister fcf record preparation |
6fb120a7 JS |
6484 | * @phba: Pointer to hba context object. |
6485 | * | |
ecfd03c6 JS |
6486 | * This function prepare the HBA for unregistering the currently registered |
6487 | * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and | |
6488 | * VFIs. | |
6fb120a7 | 6489 | */ |
ecfd03c6 JS |
6490 | int |
6491 | lpfc_unregister_fcf_prep(struct lpfc_hba *phba) | |
6fb120a7 | 6492 | { |
6fb120a7 | 6493 | struct lpfc_vport **vports; |
695a814e | 6494 | struct lpfc_nodelist *ndlp; |
72100cc4 | 6495 | struct Scsi_Host *shost; |
e74c03c8 | 6496 | int i = 0, rc; |
6fb120a7 | 6497 | |
ecfd03c6 | 6498 | /* Unregister RPIs */ |
6fb120a7 | 6499 | if (lpfc_fcf_inuse(phba)) |
ecfd03c6 | 6500 | lpfc_unreg_hba_rpis(phba); |
6fb120a7 | 6501 | |
4d9ab994 JS |
6502 | /* At this point, all discovery is aborted */ |
6503 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
6fb120a7 JS |
6504 | |
6505 | /* Unregister VPIs */ | |
6506 | vports = lpfc_create_vport_work_array(phba); | |
ecfd03c6 | 6507 | if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) |
6fb120a7 | 6508 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
695a814e JS |
6509 | /* Stop FLOGI/FDISC retries */ |
6510 | ndlp = lpfc_findnode_did(vports[i], Fabric_DID); | |
6511 | if (ndlp) | |
6512 | lpfc_cancel_retry_delay_tmo(vports[i], ndlp); | |
78730cfe | 6513 | lpfc_cleanup_pending_mbox(vports[i]); |
5af5eee7 JS |
6514 | if (phba->sli_rev == LPFC_SLI_REV4) |
6515 | lpfc_sli4_unreg_all_rpis(vports[i]); | |
6fb120a7 | 6516 | lpfc_mbx_unreg_vpi(vports[i]); |
72100cc4 JS |
6517 | shost = lpfc_shost_from_vport(vports[i]); |
6518 | spin_lock_irq(shost->host_lock); | |
891478a2 | 6519 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
c868595d | 6520 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
72100cc4 | 6521 | spin_unlock_irq(shost->host_lock); |
6fb120a7 JS |
6522 | } |
6523 | lpfc_destroy_vport_work_array(phba, vports); | |
e74c03c8 JS |
6524 | if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) { |
6525 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); | |
6526 | if (ndlp) | |
6527 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); | |
6528 | lpfc_cleanup_pending_mbox(phba->pport); | |
6529 | if (phba->sli_rev == LPFC_SLI_REV4) | |
6530 | lpfc_sli4_unreg_all_rpis(phba->pport); | |
6531 | lpfc_mbx_unreg_vpi(phba->pport); | |
6532 | shost = lpfc_shost_from_vport(phba->pport); | |
6533 | spin_lock_irq(shost->host_lock); | |
6534 | phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
6535 | phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED; | |
6536 | spin_unlock_irq(shost->host_lock); | |
6537 | } | |
6fb120a7 | 6538 | |
695a814e JS |
6539 | /* Cleanup any outstanding ELS commands */ |
6540 | lpfc_els_flush_all_cmd(phba); | |
6541 | ||
1b51197d JS |
6542 | /* Unregister the physical port VFI */ |
6543 | rc = lpfc_issue_unreg_vfi(phba->pport); | |
6544 | return rc; | |
ecfd03c6 JS |
6545 | } |
6546 | ||
6547 | /** | |
6548 | * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record | |
6549 | * @phba: Pointer to hba context object. | |
6550 | * | |
6551 | * This function issues synchronous unregister FCF mailbox command to HBA to | |
6552 | * unregister the currently registered FCF record. The driver does not reset | |
6553 | * the driver FCF usage state flags. | |
6554 | * | |
6555 | * Return 0 if successfully issued, none-zero otherwise. | |
6556 | */ | |
6557 | int | |
6558 | lpfc_sli4_unregister_fcf(struct lpfc_hba *phba) | |
6559 | { | |
6560 | LPFC_MBOXQ_t *mbox; | |
6561 | int rc; | |
6562 | ||
6fb120a7 JS |
6563 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
6564 | if (!mbox) { | |
6565 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, | |
ecfd03c6 JS |
6566 | "2551 UNREG_FCFI mbox allocation failed" |
6567 | "HBA state x%x\n", phba->pport->port_state); | |
6568 | return -ENOMEM; | |
6fb120a7 | 6569 | } |
6fb120a7 JS |
6570 | lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); |
6571 | mbox->vport = phba->pport; | |
6572 | mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; | |
6573 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
6574 | ||
6575 | if (rc == MBX_NOT_FINISHED) { | |
ecfd03c6 JS |
6576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6577 | "2552 Unregister FCFI command failed rc x%x " | |
6578 | "HBA state x%x\n", | |
6579 | rc, phba->pport->port_state); | |
6580 | return -EINVAL; | |
6581 | } | |
6582 | return 0; | |
6583 | } | |
6584 | ||
6585 | /** | |
6586 | * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan | |
6587 | * @phba: Pointer to hba context object. | |
6588 | * | |
6589 | * This function unregisters the currently reigstered FCF. This function | |
6590 | * also tries to find another FCF for discovery by rescan the HBA FCF table. | |
6591 | */ | |
6592 | void | |
6593 | lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) | |
6594 | { | |
6595 | int rc; | |
6596 | ||
6597 | /* Preparation for unregistering fcf */ | |
6598 | rc = lpfc_unregister_fcf_prep(phba); | |
6599 | if (rc) { | |
6600 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
6601 | "2748 Failed to prepare for unregistering " | |
6602 | "HBA's FCF record: rc=%d\n", rc); | |
6fb120a7 JS |
6603 | return; |
6604 | } | |
6605 | ||
ecfd03c6 JS |
6606 | /* Now, unregister FCF record and reset HBA FCF state */ |
6607 | rc = lpfc_sli4_unregister_fcf(phba); | |
6608 | if (rc) | |
6609 | return; | |
6610 | /* Reset HBA FCF states after successful unregister FCF */ | |
6611 | phba->fcf.fcf_flag = 0; | |
fc2b989b | 6612 | phba->fcf.current_rec.flag = 0; |
6fb120a7 JS |
6613 | |
6614 | /* | |
6615 | * If driver is not unloading, check if there is any other | |
6616 | * FCF record that can be used for discovery. | |
6617 | */ | |
6618 | if ((phba->pport->load_flag & FC_UNLOADING) || | |
ecfd03c6 | 6619 | (phba->link_state < LPFC_LINK_UP)) |
6fb120a7 JS |
6620 | return; |
6621 | ||
0c9ab6f5 JS |
6622 | /* This is considered as the initial FCF discovery scan */ |
6623 | spin_lock_irq(&phba->hbalock); | |
6624 | phba->fcf.fcf_flag |= FCF_INIT_DISC; | |
6625 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 JS |
6626 | |
6627 | /* Reset FCF roundrobin bmask for new discovery */ | |
7d791df7 | 6628 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
38b92ef8 | 6629 | |
0c9ab6f5 | 6630 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
6fb120a7 | 6631 | |
0c9ab6f5 JS |
6632 | if (rc) { |
6633 | spin_lock_irq(&phba->hbalock); | |
6634 | phba->fcf.fcf_flag &= ~FCF_INIT_DISC; | |
6635 | spin_unlock_irq(&phba->hbalock); | |
6fb120a7 | 6636 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, |
ecfd03c6 JS |
6637 | "2553 lpfc_unregister_unused_fcf failed " |
6638 | "to read FCF record HBA state x%x\n", | |
6639 | phba->pport->port_state); | |
0c9ab6f5 | 6640 | } |
ecfd03c6 JS |
6641 | } |
6642 | ||
6643 | /** | |
6644 | * lpfc_unregister_fcf - Unregister the currently registered fcf record | |
6645 | * @phba: Pointer to hba context object. | |
6646 | * | |
6647 | * This function just unregisters the currently reigstered FCF. It does not | |
6648 | * try to find another FCF for discovery. | |
6649 | */ | |
6650 | void | |
6651 | lpfc_unregister_fcf(struct lpfc_hba *phba) | |
6652 | { | |
6653 | int rc; | |
6654 | ||
6655 | /* Preparation for unregistering fcf */ | |
6656 | rc = lpfc_unregister_fcf_prep(phba); | |
6657 | if (rc) { | |
6658 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
6659 | "2749 Failed to prepare for unregistering " | |
6660 | "HBA's FCF record: rc=%d\n", rc); | |
6661 | return; | |
6662 | } | |
6663 | ||
6664 | /* Now, unregister FCF record and reset HBA FCF state */ | |
6665 | rc = lpfc_sli4_unregister_fcf(phba); | |
6666 | if (rc) | |
6667 | return; | |
6668 | /* Set proper HBA FCF states after successful unregister FCF */ | |
6669 | spin_lock_irq(&phba->hbalock); | |
6670 | phba->fcf.fcf_flag &= ~FCF_REGISTERED; | |
6671 | spin_unlock_irq(&phba->hbalock); | |
6672 | } | |
6673 | ||
6674 | /** | |
6675 | * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. | |
6676 | * @phba: Pointer to hba context object. | |
6677 | * | |
6678 | * This function check if there are any connected remote port for the FCF and | |
6679 | * if all the devices are disconnected, this function unregister FCFI. | |
6680 | * This function also tries to use another FCF for discovery. | |
6681 | */ | |
6682 | void | |
6683 | lpfc_unregister_unused_fcf(struct lpfc_hba *phba) | |
6684 | { | |
6685 | /* | |
3804dc84 JS |
6686 | * If HBA is not running in FIP mode, if HBA does not support |
6687 | * FCoE, if FCF discovery is ongoing, or if FCF has not been | |
6688 | * registered, do nothing. | |
ecfd03c6 JS |
6689 | */ |
6690 | spin_lock_irq(&phba->hbalock); | |
76a95d75 | 6691 | if (!(phba->hba_flag & HBA_FCOE_MODE) || |
ecfd03c6 | 6692 | !(phba->fcf.fcf_flag & FCF_REGISTERED) || |
dbb6b3ab | 6693 | !(phba->hba_flag & HBA_FIP_SUPPORT) || |
3804dc84 | 6694 | (phba->fcf.fcf_flag & FCF_DISCOVERY) || |
dbb6b3ab | 6695 | (phba->pport->port_state == LPFC_FLOGI)) { |
ecfd03c6 JS |
6696 | spin_unlock_irq(&phba->hbalock); |
6697 | return; | |
6698 | } | |
6699 | spin_unlock_irq(&phba->hbalock); | |
6700 | ||
6701 | if (lpfc_fcf_inuse(phba)) | |
6702 | return; | |
6703 | ||
6704 | lpfc_unregister_fcf_rescan(phba); | |
6fb120a7 JS |
6705 | } |
6706 | ||
6707 | /** | |
6708 | * lpfc_read_fcf_conn_tbl - Create driver FCF connection table. | |
6709 | * @phba: Pointer to hba context object. | |
6710 | * @buff: Buffer containing the FCF connection table as in the config | |
6711 | * region. | |
6712 | * This function create driver data structure for the FCF connection | |
6713 | * record table read from config region 23. | |
6714 | */ | |
6715 | static void | |
6716 | lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba, | |
6717 | uint8_t *buff) | |
6718 | { | |
6719 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
6720 | struct lpfc_fcf_conn_hdr *conn_hdr; | |
6721 | struct lpfc_fcf_conn_rec *conn_rec; | |
6722 | uint32_t record_count; | |
6723 | int i; | |
6724 | ||
6725 | /* Free the current connect table */ | |
6726 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
6727 | &phba->fcf_conn_rec_list, list) { |
6728 | list_del_init(&conn_entry->list); | |
6fb120a7 | 6729 | kfree(conn_entry); |
4d9ab994 | 6730 | } |
6fb120a7 JS |
6731 | |
6732 | conn_hdr = (struct lpfc_fcf_conn_hdr *) buff; | |
6733 | record_count = conn_hdr->length * sizeof(uint32_t)/ | |
6734 | sizeof(struct lpfc_fcf_conn_rec); | |
6735 | ||
6736 | conn_rec = (struct lpfc_fcf_conn_rec *) | |
6737 | (buff + sizeof(struct lpfc_fcf_conn_hdr)); | |
6738 | ||
6739 | for (i = 0; i < record_count; i++) { | |
6740 | if (!(conn_rec[i].flags & FCFCNCT_VALID)) | |
6741 | continue; | |
6742 | conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry), | |
6743 | GFP_KERNEL); | |
6744 | if (!conn_entry) { | |
6745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6746 | "2566 Failed to allocate connection" | |
6747 | " table entry\n"); | |
6748 | return; | |
6749 | } | |
6750 | ||
6751 | memcpy(&conn_entry->conn_rec, &conn_rec[i], | |
6752 | sizeof(struct lpfc_fcf_conn_rec)); | |
6fb120a7 JS |
6753 | list_add_tail(&conn_entry->list, |
6754 | &phba->fcf_conn_rec_list); | |
6755 | } | |
df0d085f JS |
6756 | |
6757 | if (!list_empty(&phba->fcf_conn_rec_list)) { | |
6758 | i = 0; | |
6759 | list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, | |
6760 | list) { | |
6761 | conn_rec = &conn_entry->conn_rec; | |
6762 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6763 | "3345 FCF connection list rec[%02d]: " | |
6764 | "flags:x%04x, vtag:x%04x, " | |
6765 | "fabric_name:x%02x:%02x:%02x:%02x:" | |
6766 | "%02x:%02x:%02x:%02x, " | |
6767 | "switch_name:x%02x:%02x:%02x:%02x:" | |
6768 | "%02x:%02x:%02x:%02x\n", i++, | |
6769 | conn_rec->flags, conn_rec->vlan_tag, | |
6770 | conn_rec->fabric_name[0], | |
6771 | conn_rec->fabric_name[1], | |
6772 | conn_rec->fabric_name[2], | |
6773 | conn_rec->fabric_name[3], | |
6774 | conn_rec->fabric_name[4], | |
6775 | conn_rec->fabric_name[5], | |
6776 | conn_rec->fabric_name[6], | |
6777 | conn_rec->fabric_name[7], | |
6778 | conn_rec->switch_name[0], | |
6779 | conn_rec->switch_name[1], | |
6780 | conn_rec->switch_name[2], | |
6781 | conn_rec->switch_name[3], | |
6782 | conn_rec->switch_name[4], | |
6783 | conn_rec->switch_name[5], | |
6784 | conn_rec->switch_name[6], | |
6785 | conn_rec->switch_name[7]); | |
6786 | } | |
6787 | } | |
6fb120a7 JS |
6788 | } |
6789 | ||
6790 | /** | |
6791 | * lpfc_read_fcoe_param - Read FCoe parameters from conf region.. | |
6792 | * @phba: Pointer to hba context object. | |
6793 | * @buff: Buffer containing the FCoE parameter data structure. | |
6794 | * | |
6795 | * This function update driver data structure with config | |
6796 | * parameters read from config region 23. | |
6797 | */ | |
6798 | static void | |
6799 | lpfc_read_fcoe_param(struct lpfc_hba *phba, | |
6800 | uint8_t *buff) | |
6801 | { | |
6802 | struct lpfc_fip_param_hdr *fcoe_param_hdr; | |
6803 | struct lpfc_fcoe_params *fcoe_param; | |
6804 | ||
6805 | fcoe_param_hdr = (struct lpfc_fip_param_hdr *) | |
6806 | buff; | |
6807 | fcoe_param = (struct lpfc_fcoe_params *) | |
32b9793f | 6808 | (buff + sizeof(struct lpfc_fip_param_hdr)); |
6fb120a7 JS |
6809 | |
6810 | if ((fcoe_param_hdr->parm_version != FIPP_VERSION) || | |
6811 | (fcoe_param_hdr->length != FCOE_PARAM_LENGTH)) | |
6812 | return; | |
6813 | ||
6fb120a7 JS |
6814 | if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) { |
6815 | phba->valid_vlan = 1; | |
6816 | phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) & | |
6817 | 0xFFF; | |
6818 | } | |
6819 | ||
6820 | phba->fc_map[0] = fcoe_param->fc_map[0]; | |
6821 | phba->fc_map[1] = fcoe_param->fc_map[1]; | |
6822 | phba->fc_map[2] = fcoe_param->fc_map[2]; | |
6823 | return; | |
6824 | } | |
6825 | ||
6826 | /** | |
6827 | * lpfc_get_rec_conf23 - Get a record type in config region data. | |
6828 | * @buff: Buffer containing config region 23 data. | |
6829 | * @size: Size of the data buffer. | |
6830 | * @rec_type: Record type to be searched. | |
6831 | * | |
25985edc | 6832 | * This function searches config region data to find the beginning |
6fb120a7 JS |
6833 | * of the record specified by record_type. If record found, this |
6834 | * function return pointer to the record else return NULL. | |
6835 | */ | |
6836 | static uint8_t * | |
6837 | lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type) | |
6838 | { | |
6839 | uint32_t offset = 0, rec_length; | |
6840 | ||
6841 | if ((buff[0] == LPFC_REGION23_LAST_REC) || | |
6842 | (size < sizeof(uint32_t))) | |
6843 | return NULL; | |
6844 | ||
6845 | rec_length = buff[offset + 1]; | |
6846 | ||
6847 | /* | |
6848 | * One TLV record has one word header and number of data words | |
6849 | * specified in the rec_length field of the record header. | |
6850 | */ | |
6851 | while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t)) | |
6852 | <= size) { | |
6853 | if (buff[offset] == rec_type) | |
6854 | return &buff[offset]; | |
6855 | ||
6856 | if (buff[offset] == LPFC_REGION23_LAST_REC) | |
6857 | return NULL; | |
6858 | ||
6859 | offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t); | |
6860 | rec_length = buff[offset + 1]; | |
6861 | } | |
6862 | return NULL; | |
6863 | } | |
6864 | ||
6865 | /** | |
6866 | * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23. | |
6867 | * @phba: Pointer to lpfc_hba data structure. | |
6868 | * @buff: Buffer containing config region 23 data. | |
6869 | * @size: Size of the data buffer. | |
6870 | * | |
eef35c2d | 6871 | * This function parses the FCoE config parameters in config region 23 and |
6fb120a7 JS |
6872 | * populate driver data structure with the parameters. |
6873 | */ | |
6874 | void | |
6875 | lpfc_parse_fcoe_conf(struct lpfc_hba *phba, | |
6876 | uint8_t *buff, | |
6877 | uint32_t size) | |
6878 | { | |
eb016566 | 6879 | uint32_t offset = 0; |
6fb120a7 JS |
6880 | uint8_t *rec_ptr; |
6881 | ||
6882 | /* | |
6883 | * If data size is less than 2 words signature and version cannot be | |
6884 | * verified. | |
6885 | */ | |
6886 | if (size < 2*sizeof(uint32_t)) | |
6887 | return; | |
6888 | ||
6889 | /* Check the region signature first */ | |
6890 | if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) { | |
6891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6892 | "2567 Config region 23 has bad signature\n"); | |
6893 | return; | |
6894 | } | |
6895 | ||
6896 | offset += 4; | |
6897 | ||
6898 | /* Check the data structure version */ | |
6899 | if (buff[offset] != LPFC_REGION23_VERSION) { | |
6900 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6901 | "2568 Config region 23 has bad version\n"); | |
6902 | return; | |
6903 | } | |
6904 | offset += 4; | |
6905 | ||
6fb120a7 JS |
6906 | /* Read FCoE param record */ |
6907 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], | |
6908 | size - offset, FCOE_PARAM_TYPE); | |
6909 | if (rec_ptr) | |
6910 | lpfc_read_fcoe_param(phba, rec_ptr); | |
6911 | ||
6912 | /* Read FCF connection table */ | |
6913 | rec_ptr = lpfc_get_rec_conf23(&buff[offset], | |
6914 | size - offset, FCOE_CONN_TBL_TYPE); | |
6915 | if (rec_ptr) | |
6916 | lpfc_read_fcf_conn_tbl(phba, rec_ptr); | |
6917 | ||
6918 | } |