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