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