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