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