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