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