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