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