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