Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
41415862 | 4 | * Copyright (C) 2004-2006 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/kthread.h> | |
25 | #include <linux/interrupt.h> | |
26 | ||
91886523 | 27 | #include <scsi/scsi.h> |
dea3101e | 28 | #include <scsi/scsi_device.h> |
29 | #include <scsi/scsi_host.h> | |
30 | #include <scsi/scsi_transport_fc.h> | |
31 | ||
32 | #include "lpfc_hw.h" | |
33 | #include "lpfc_disc.h" | |
34 | #include "lpfc_sli.h" | |
35 | #include "lpfc_scsi.h" | |
36 | #include "lpfc.h" | |
37 | #include "lpfc_logmsg.h" | |
38 | #include "lpfc_crtn.h" | |
39 | ||
40 | /* AlpaArray for assignment of scsid for scan-down and bind_method */ | |
41 | static uint8_t lpfcAlpaArray[] = { | |
42 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6, | |
43 | 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, | |
44 | 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, | |
45 | 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, | |
46 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97, | |
47 | 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79, | |
48 | 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, | |
49 | 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, | |
50 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, | |
51 | 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35, | |
52 | 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, | |
53 | 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, | |
54 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01 | |
55 | }; | |
56 | ||
57 | static void lpfc_disc_timeout_handler(struct lpfc_hba *); | |
58 | ||
c01f3208 JS |
59 | void |
60 | lpfc_terminate_rport_io(struct fc_rport *rport) | |
dea3101e | 61 | { |
c01f3208 JS |
62 | struct lpfc_rport_data *rdata; |
63 | struct lpfc_nodelist * ndlp; | |
64 | struct lpfc_hba *phba; | |
dea3101e | 65 | |
c01f3208 JS |
66 | rdata = rport->dd_data; |
67 | ndlp = rdata->pnode; | |
68 | ||
69 | if (!ndlp) { | |
70 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) | |
71 | printk(KERN_ERR "Cannot find remote node" | |
72 | " to terminate I/O Data x%x\n", | |
73 | rport->port_id); | |
dea3101e | 74 | return; |
75 | } | |
76 | ||
c01f3208 JS |
77 | phba = ndlp->nlp_phba; |
78 | ||
1a169689 | 79 | spin_lock_irq(phba->host->host_lock); |
c01f3208 JS |
80 | if (ndlp->nlp_sid != NLP_NO_SID) { |
81 | lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], | |
82 | ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT); | |
83 | } | |
84 | spin_unlock_irq(phba->host->host_lock); | |
85 | ||
86 | return; | |
87 | } | |
88 | ||
89 | /* | |
90 | * This function will be called when dev_loss_tmo fire. | |
91 | */ | |
92 | void | |
93 | lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) | |
94 | { | |
95 | struct lpfc_rport_data *rdata; | |
96 | struct lpfc_nodelist * ndlp; | |
97 | uint8_t *name; | |
98 | int warn_on = 0; | |
99 | struct lpfc_hba *phba; | |
100 | ||
101 | rdata = rport->dd_data; | |
102 | ndlp = rdata->pnode; | |
1a169689 | 103 | |
c01f3208 JS |
104 | if (!ndlp) { |
105 | if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) | |
106 | printk(KERN_ERR "Cannot find remote node" | |
107 | " for rport in dev_loss_tmo_callbk x%x\n", | |
108 | rport->port_id); | |
109 | return; | |
110 | } | |
111 | ||
112 | name = (uint8_t *)&ndlp->nlp_portname; | |
113 | phba = ndlp->nlp_phba; | |
114 | ||
115 | spin_lock_irq(phba->host->host_lock); | |
dea3101e | 116 | |
117 | if (ndlp->nlp_sid != NLP_NO_SID) { | |
6e8215e4 | 118 | warn_on = 1; |
dea3101e | 119 | /* flush the target */ |
120 | lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring], | |
121 | ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT); | |
122 | } | |
c01f3208 JS |
123 | if (phba->fc_flag & FC_UNLOADING) |
124 | warn_on = 0; | |
125 | ||
dea3101e | 126 | spin_unlock_irq(phba->host->host_lock); |
127 | ||
6e8215e4 JSEC |
128 | if (warn_on) { |
129 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
c01f3208 | 130 | "%d:0203 Devloss timeout on " |
488d1469 JS |
131 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
132 | "NPort x%x Data: x%x x%x x%x\n", | |
133 | phba->brd_no, | |
134 | *name, *(name+1), *(name+2), *(name+3), | |
135 | *(name+4), *(name+5), *(name+6), *(name+7), | |
136 | ndlp->nlp_DID, ndlp->nlp_flag, | |
6e8215e4 JSEC |
137 | ndlp->nlp_state, ndlp->nlp_rpi); |
138 | } else { | |
139 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
c01f3208 | 140 | "%d:0204 Devloss timeout on " |
488d1469 JS |
141 | "WWPN %x:%x:%x:%x:%x:%x:%x:%x " |
142 | "NPort x%x Data: x%x x%x x%x\n", | |
143 | phba->brd_no, | |
144 | *name, *(name+1), *(name+2), *(name+3), | |
145 | *(name+4), *(name+5), *(name+6), *(name+7), | |
146 | ndlp->nlp_DID, ndlp->nlp_flag, | |
6e8215e4 JSEC |
147 | ndlp->nlp_state, ndlp->nlp_rpi); |
148 | } | |
149 | ||
c01f3208 JS |
150 | ndlp->rport = NULL; |
151 | rdata->pnode = NULL; | |
152 | ||
153 | if (!(phba->fc_flag & FC_UNLOADING)) | |
154 | lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM); | |
155 | ||
dea3101e | 156 | return; |
157 | } | |
158 | ||
159 | static void | |
160 | lpfc_work_list_done(struct lpfc_hba * phba) | |
161 | { | |
162 | struct lpfc_work_evt *evtp = NULL; | |
163 | struct lpfc_nodelist *ndlp; | |
164 | int free_evt; | |
165 | ||
166 | spin_lock_irq(phba->host->host_lock); | |
167 | while(!list_empty(&phba->work_list)) { | |
168 | list_remove_head((&phba->work_list), evtp, typeof(*evtp), | |
169 | evt_listp); | |
170 | spin_unlock_irq(phba->host->host_lock); | |
171 | free_evt = 1; | |
2fe165b6 | 172 | switch (evtp->evt) { |
dea3101e | 173 | case LPFC_EVT_ELS_RETRY: |
174 | ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); | |
175 | lpfc_els_retry_delay_handler(ndlp); | |
176 | free_evt = 0; | |
177 | break; | |
178 | case LPFC_EVT_ONLINE: | |
41415862 JW |
179 | if (phba->hba_state < LPFC_LINK_DOWN) |
180 | *(int *)(evtp->evt_arg1) = lpfc_online(phba); | |
181 | else | |
182 | *(int *)(evtp->evt_arg1) = 0; | |
dea3101e | 183 | complete((struct completion *)(evtp->evt_arg2)); |
184 | break; | |
185 | case LPFC_EVT_OFFLINE: | |
41415862 JW |
186 | if (phba->hba_state >= LPFC_LINK_DOWN) |
187 | lpfc_offline(phba); | |
188 | lpfc_sli_brdrestart(phba); | |
189 | *(int *)(evtp->evt_arg1) = | |
190 | lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY); | |
191 | complete((struct completion *)(evtp->evt_arg2)); | |
192 | break; | |
193 | case LPFC_EVT_WARM_START: | |
194 | if (phba->hba_state >= LPFC_LINK_DOWN) | |
195 | lpfc_offline(phba); | |
9290831f | 196 | lpfc_reset_barrier(phba); |
41415862 JW |
197 | lpfc_sli_brdreset(phba); |
198 | lpfc_hba_down_post(phba); | |
199 | *(int *)(evtp->evt_arg1) = | |
200 | lpfc_sli_brdready(phba, HS_MBRDY); | |
201 | complete((struct completion *)(evtp->evt_arg2)); | |
202 | break; | |
203 | case LPFC_EVT_KILL: | |
204 | if (phba->hba_state >= LPFC_LINK_DOWN) | |
205 | lpfc_offline(phba); | |
9290831f JS |
206 | *(int *)(evtp->evt_arg1) |
207 | = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba); | |
dea3101e | 208 | complete((struct completion *)(evtp->evt_arg2)); |
209 | break; | |
210 | } | |
211 | if (free_evt) | |
212 | kfree(evtp); | |
213 | spin_lock_irq(phba->host->host_lock); | |
214 | } | |
215 | spin_unlock_irq(phba->host->host_lock); | |
216 | ||
217 | } | |
218 | ||
219 | static void | |
220 | lpfc_work_done(struct lpfc_hba * phba) | |
221 | { | |
222 | struct lpfc_sli_ring *pring; | |
223 | int i; | |
224 | uint32_t ha_copy; | |
225 | uint32_t control; | |
226 | uint32_t work_hba_events; | |
227 | ||
228 | spin_lock_irq(phba->host->host_lock); | |
229 | ha_copy = phba->work_ha; | |
230 | phba->work_ha = 0; | |
231 | work_hba_events=phba->work_hba_events; | |
232 | spin_unlock_irq(phba->host->host_lock); | |
233 | ||
2fe165b6 | 234 | if (ha_copy & HA_ERATT) |
dea3101e | 235 | lpfc_handle_eratt(phba); |
236 | ||
2fe165b6 | 237 | if (ha_copy & HA_MBATT) |
dea3101e | 238 | lpfc_sli_handle_mb_event(phba); |
239 | ||
2fe165b6 | 240 | if (ha_copy & HA_LATT) |
dea3101e | 241 | lpfc_handle_latt(phba); |
242 | ||
243 | if (work_hba_events & WORKER_DISC_TMO) | |
244 | lpfc_disc_timeout_handler(phba); | |
245 | ||
246 | if (work_hba_events & WORKER_ELS_TMO) | |
247 | lpfc_els_timeout_handler(phba); | |
248 | ||
249 | if (work_hba_events & WORKER_MBOX_TMO) | |
250 | lpfc_mbox_timeout_handler(phba); | |
251 | ||
252 | if (work_hba_events & WORKER_FDMI_TMO) | |
253 | lpfc_fdmi_tmo_handler(phba); | |
254 | ||
255 | spin_lock_irq(phba->host->host_lock); | |
256 | phba->work_hba_events &= ~work_hba_events; | |
257 | spin_unlock_irq(phba->host->host_lock); | |
258 | ||
259 | for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) { | |
260 | pring = &phba->sli.ring[i]; | |
261 | if ((ha_copy & HA_RXATT) | |
262 | || (pring->flag & LPFC_DEFERRED_RING_EVENT)) { | |
263 | if (pring->flag & LPFC_STOP_IOCB_MASK) { | |
264 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | |
265 | } else { | |
266 | lpfc_sli_handle_slow_ring_event(phba, pring, | |
267 | (ha_copy & | |
268 | HA_RXMASK)); | |
269 | pring->flag &= ~LPFC_DEFERRED_RING_EVENT; | |
270 | } | |
271 | /* | |
272 | * Turn on Ring interrupts | |
273 | */ | |
274 | spin_lock_irq(phba->host->host_lock); | |
275 | control = readl(phba->HCregaddr); | |
276 | control |= (HC_R0INT_ENA << i); | |
277 | writel(control, phba->HCregaddr); | |
278 | readl(phba->HCregaddr); /* flush */ | |
279 | spin_unlock_irq(phba->host->host_lock); | |
280 | } | |
281 | } | |
282 | ||
283 | lpfc_work_list_done (phba); | |
284 | ||
285 | } | |
286 | ||
287 | static int | |
288 | check_work_wait_done(struct lpfc_hba *phba) { | |
289 | ||
290 | spin_lock_irq(phba->host->host_lock); | |
291 | if (phba->work_ha || | |
292 | phba->work_hba_events || | |
293 | (!list_empty(&phba->work_list)) || | |
294 | kthread_should_stop()) { | |
295 | spin_unlock_irq(phba->host->host_lock); | |
296 | return 1; | |
297 | } else { | |
298 | spin_unlock_irq(phba->host->host_lock); | |
299 | return 0; | |
300 | } | |
301 | } | |
302 | ||
303 | int | |
304 | lpfc_do_work(void *p) | |
305 | { | |
306 | struct lpfc_hba *phba = p; | |
307 | int rc; | |
308 | DECLARE_WAIT_QUEUE_HEAD(work_waitq); | |
309 | ||
310 | set_user_nice(current, -20); | |
311 | phba->work_wait = &work_waitq; | |
312 | ||
313 | while (1) { | |
314 | ||
315 | rc = wait_event_interruptible(work_waitq, | |
316 | check_work_wait_done(phba)); | |
317 | BUG_ON(rc); | |
318 | ||
319 | if (kthread_should_stop()) | |
320 | break; | |
321 | ||
322 | lpfc_work_done(phba); | |
323 | ||
324 | } | |
325 | phba->work_wait = NULL; | |
326 | return 0; | |
327 | } | |
328 | ||
329 | /* | |
330 | * This is only called to handle FC worker events. Since this a rare | |
331 | * occurance, we allocate a struct lpfc_work_evt structure here instead of | |
332 | * embedding it in the IOCB. | |
333 | */ | |
334 | int | |
335 | lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2, | |
336 | uint32_t evt) | |
337 | { | |
338 | struct lpfc_work_evt *evtp; | |
339 | ||
340 | /* | |
341 | * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will | |
342 | * be queued to worker thread for processing | |
343 | */ | |
344 | evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL); | |
345 | if (!evtp) | |
346 | return 0; | |
347 | ||
348 | evtp->evt_arg1 = arg1; | |
349 | evtp->evt_arg2 = arg2; | |
350 | evtp->evt = evt; | |
351 | ||
dea3101e | 352 | spin_lock_irq(phba->host->host_lock); |
071fbd3d | 353 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
dea3101e | 354 | if (phba->work_wait) |
355 | wake_up(phba->work_wait); | |
356 | spin_unlock_irq(phba->host->host_lock); | |
357 | ||
358 | return 1; | |
359 | } | |
360 | ||
361 | int | |
362 | lpfc_linkdown(struct lpfc_hba * phba) | |
363 | { | |
364 | struct lpfc_sli *psli; | |
365 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
c9f8735b | 366 | struct list_head *listp, *node_list[7]; |
dea3101e | 367 | LPFC_MBOXQ_t *mb; |
368 | int rc, i; | |
369 | ||
370 | psli = &phba->sli; | |
c9f8735b | 371 | /* sysfs or selective reset may call this routine to clean up */ |
5024ab17 JW |
372 | if (phba->hba_state >= LPFC_LINK_DOWN) { |
373 | if (phba->hba_state == LPFC_LINK_DOWN) | |
374 | return 0; | |
375 | ||
c9f8735b JW |
376 | spin_lock_irq(phba->host->host_lock); |
377 | phba->hba_state = LPFC_LINK_DOWN; | |
378 | spin_unlock_irq(phba->host->host_lock); | |
379 | } | |
dea3101e | 380 | |
d2873e4c JS |
381 | fc_host_post_event(phba->host, fc_get_event_number(), |
382 | FCH_EVT_LINKDOWN, 0); | |
383 | ||
dea3101e | 384 | /* Clean up any firmware default rpi's */ |
385 | if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) { | |
386 | lpfc_unreg_did(phba, 0xffffffff, mb); | |
387 | mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl; | |
388 | if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB)) | |
389 | == MBX_NOT_FINISHED) { | |
390 | mempool_free( mb, phba->mbox_mem_pool); | |
391 | } | |
392 | } | |
393 | ||
394 | /* Cleanup any outstanding RSCN activity */ | |
395 | lpfc_els_flush_rscn(phba); | |
396 | ||
397 | /* Cleanup any outstanding ELS commands */ | |
398 | lpfc_els_flush_cmd(phba); | |
399 | ||
400 | /* Issue a LINK DOWN event to all nodes */ | |
401 | node_list[0] = &phba->fc_npr_list; /* MUST do this list first */ | |
402 | node_list[1] = &phba->fc_nlpmap_list; | |
403 | node_list[2] = &phba->fc_nlpunmap_list; | |
404 | node_list[3] = &phba->fc_prli_list; | |
405 | node_list[4] = &phba->fc_reglogin_list; | |
406 | node_list[5] = &phba->fc_adisc_list; | |
407 | node_list[6] = &phba->fc_plogi_list; | |
408 | for (i = 0; i < 7; i++) { | |
409 | listp = node_list[i]; | |
410 | if (list_empty(listp)) | |
411 | continue; | |
412 | ||
413 | list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) { | |
c9f8735b JW |
414 | |
415 | rc = lpfc_disc_state_machine(phba, ndlp, NULL, | |
416 | NLP_EVT_DEVICE_RECOVERY); | |
417 | ||
dea3101e | 418 | } |
419 | } | |
420 | ||
421 | /* free any ndlp's on unused list */ | |
422 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list, | |
423 | nlp_listp) { | |
424 | lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); | |
425 | } | |
426 | ||
427 | /* Setup myDID for link up if we are in pt2pt mode */ | |
428 | if (phba->fc_flag & FC_PT2PT) { | |
429 | phba->fc_myDID = 0; | |
430 | if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) { | |
431 | lpfc_config_link(phba, mb); | |
432 | mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl; | |
433 | if (lpfc_sli_issue_mbox | |
434 | (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB)) | |
435 | == MBX_NOT_FINISHED) { | |
436 | mempool_free( mb, phba->mbox_mem_pool); | |
437 | } | |
438 | } | |
439 | spin_lock_irq(phba->host->host_lock); | |
440 | phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI); | |
441 | spin_unlock_irq(phba->host->host_lock); | |
442 | } | |
443 | spin_lock_irq(phba->host->host_lock); | |
444 | phba->fc_flag &= ~FC_LBIT; | |
445 | spin_unlock_irq(phba->host->host_lock); | |
446 | ||
447 | /* Turn off discovery timer if its running */ | |
448 | lpfc_can_disctmo(phba); | |
449 | ||
450 | /* Must process IOCBs on all rings to handle ABORTed I/Os */ | |
2fe165b6 | 451 | return 0; |
dea3101e | 452 | } |
453 | ||
454 | static int | |
455 | lpfc_linkup(struct lpfc_hba * phba) | |
456 | { | |
457 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
c9f8735b JW |
458 | struct list_head *listp, *node_list[7]; |
459 | int i; | |
dea3101e | 460 | |
d2873e4c JS |
461 | fc_host_post_event(phba->host, fc_get_event_number(), |
462 | FCH_EVT_LINKUP, 0); | |
463 | ||
dea3101e | 464 | spin_lock_irq(phba->host->host_lock); |
465 | phba->hba_state = LPFC_LINK_UP; | |
466 | phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY | | |
467 | FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY); | |
468 | phba->fc_flag |= FC_NDISC_ACTIVE; | |
469 | phba->fc_ns_retry = 0; | |
470 | spin_unlock_irq(phba->host->host_lock); | |
471 | ||
472 | ||
c9f8735b JW |
473 | node_list[0] = &phba->fc_plogi_list; |
474 | node_list[1] = &phba->fc_adisc_list; | |
475 | node_list[2] = &phba->fc_reglogin_list; | |
476 | node_list[3] = &phba->fc_prli_list; | |
477 | node_list[4] = &phba->fc_nlpunmap_list; | |
478 | node_list[5] = &phba->fc_nlpmap_list; | |
479 | node_list[6] = &phba->fc_npr_list; | |
480 | for (i = 0; i < 7; i++) { | |
481 | listp = node_list[i]; | |
482 | if (list_empty(listp)) | |
483 | continue; | |
484 | ||
485 | list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) { | |
486 | if (phba->fc_flag & FC_LBIT) { | |
487 | if (ndlp->nlp_type & NLP_FABRIC) { | |
488 | /* On Linkup its safe to clean up the | |
489 | * ndlp from Fabric connections. | |
490 | */ | |
491 | lpfc_nlp_list(phba, ndlp, | |
492 | NLP_UNUSED_LIST); | |
493 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { | |
494 | /* Fail outstanding IO now since device | |
495 | * is marked for PLOGI. | |
496 | */ | |
497 | lpfc_unreg_rpi(phba, ndlp); | |
498 | } | |
499 | } | |
dea3101e | 500 | } |
501 | } | |
502 | ||
503 | /* free any ndlp's on unused list */ | |
504 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list, | |
505 | nlp_listp) { | |
506 | lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); | |
507 | } | |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
512 | /* | |
513 | * This routine handles processing a CLEAR_LA mailbox | |
514 | * command upon completion. It is setup in the LPFC_MBOXQ | |
515 | * as the completion routine when the command is | |
516 | * handed off to the SLI layer. | |
517 | */ | |
518 | void | |
519 | lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
520 | { | |
521 | struct lpfc_sli *psli; | |
522 | MAILBOX_t *mb; | |
523 | uint32_t control; | |
524 | ||
525 | psli = &phba->sli; | |
526 | mb = &pmb->mb; | |
527 | /* Since we don't do discovery right now, turn these off here */ | |
528 | psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT; | |
529 | psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT; | |
530 | psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT; | |
531 | ||
532 | /* Check for error */ | |
533 | if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) { | |
534 | /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */ | |
535 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
536 | "%d:0320 CLEAR_LA mbxStatus error x%x hba " | |
537 | "state x%x\n", | |
538 | phba->brd_no, mb->mbxStatus, phba->hba_state); | |
539 | ||
540 | phba->hba_state = LPFC_HBA_ERROR; | |
541 | goto out; | |
542 | } | |
543 | ||
544 | if (phba->fc_flag & FC_ABORT_DISCOVERY) | |
545 | goto out; | |
546 | ||
547 | phba->num_disc_nodes = 0; | |
548 | /* go thru NPR list and issue ELS PLOGIs */ | |
549 | if (phba->fc_npr_cnt) { | |
550 | lpfc_els_disc_plogi(phba); | |
551 | } | |
552 | ||
2fe165b6 | 553 | if (!phba->num_disc_nodes) { |
dea3101e | 554 | spin_lock_irq(phba->host->host_lock); |
555 | phba->fc_flag &= ~FC_NDISC_ACTIVE; | |
556 | spin_unlock_irq(phba->host->host_lock); | |
557 | } | |
558 | ||
559 | phba->hba_state = LPFC_HBA_READY; | |
560 | ||
561 | out: | |
562 | /* Device Discovery completes */ | |
563 | lpfc_printf_log(phba, | |
564 | KERN_INFO, | |
565 | LOG_DISCOVERY, | |
566 | "%d:0225 Device Discovery completes\n", | |
567 | phba->brd_no); | |
568 | ||
569 | mempool_free( pmb, phba->mbox_mem_pool); | |
570 | ||
571 | spin_lock_irq(phba->host->host_lock); | |
572 | phba->fc_flag &= ~FC_ABORT_DISCOVERY; | |
573 | if (phba->fc_flag & FC_ESTABLISH_LINK) { | |
574 | phba->fc_flag &= ~FC_ESTABLISH_LINK; | |
575 | } | |
576 | spin_unlock_irq(phba->host->host_lock); | |
577 | ||
578 | del_timer_sync(&phba->fc_estabtmo); | |
579 | ||
580 | lpfc_can_disctmo(phba); | |
581 | ||
582 | /* turn on Link Attention interrupts */ | |
583 | spin_lock_irq(phba->host->host_lock); | |
584 | psli->sli_flag |= LPFC_PROCESS_LA; | |
585 | control = readl(phba->HCregaddr); | |
586 | control |= HC_LAINT_ENA; | |
587 | writel(control, phba->HCregaddr); | |
588 | readl(phba->HCregaddr); /* flush */ | |
589 | spin_unlock_irq(phba->host->host_lock); | |
590 | ||
591 | return; | |
592 | } | |
593 | ||
594 | static void | |
25594c6b | 595 | lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 596 | { |
25594c6b JW |
597 | struct lpfc_sli *psli = &phba->sli; |
598 | int rc; | |
dea3101e | 599 | |
25594c6b | 600 | if (pmb->mb.mbxStatus) |
dea3101e | 601 | goto out; |
dea3101e | 602 | |
25594c6b JW |
603 | mempool_free(pmb, phba->mbox_mem_pool); |
604 | ||
605 | if (phba->fc_topology == TOPOLOGY_LOOP && | |
606 | phba->fc_flag & FC_PUBLIC_LOOP && | |
607 | !(phba->fc_flag & FC_LBIT)) { | |
608 | /* Need to wait for FAN - use discovery timer | |
609 | * for timeout. hba_state is identically | |
610 | * LPFC_LOCAL_CFG_LINK while waiting for FAN | |
611 | */ | |
612 | lpfc_set_disctmo(phba); | |
613 | return; | |
dea3101e | 614 | } |
615 | ||
25594c6b JW |
616 | /* Start discovery by sending a FLOGI. hba_state is identically |
617 | * LPFC_FLOGI while waiting for FLOGI cmpl | |
618 | */ | |
619 | phba->hba_state = LPFC_FLOGI; | |
620 | lpfc_set_disctmo(phba); | |
621 | lpfc_initial_flogi(phba); | |
622 | return; | |
dea3101e | 623 | |
624 | out: | |
25594c6b JW |
625 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
626 | "%d:0306 CONFIG_LINK mbxStatus error x%x " | |
627 | "HBA state x%x\n", | |
628 | phba->brd_no, pmb->mb.mbxStatus, phba->hba_state); | |
629 | ||
630 | lpfc_linkdown(phba); | |
631 | ||
632 | phba->hba_state = LPFC_HBA_ERROR; | |
633 | ||
634 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
dea3101e | 635 | "%d:0200 CONFIG_LINK bad hba state x%x\n", |
636 | phba->brd_no, phba->hba_state); | |
637 | ||
25594c6b JW |
638 | lpfc_clear_la(phba, pmb); |
639 | pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
640 | rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB)); | |
641 | if (rc == MBX_NOT_FINISHED) { | |
642 | mempool_free(pmb, phba->mbox_mem_pool); | |
643 | lpfc_disc_flush_list(phba); | |
644 | psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
645 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
646 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
647 | phba->hba_state = LPFC_HBA_READY; | |
dea3101e | 648 | } |
649 | return; | |
650 | } | |
651 | ||
652 | static void | |
653 | lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
654 | { | |
655 | struct lpfc_sli *psli = &phba->sli; | |
656 | MAILBOX_t *mb = &pmb->mb; | |
657 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1; | |
658 | ||
659 | ||
660 | /* Check for error */ | |
661 | if (mb->mbxStatus) { | |
662 | /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */ | |
663 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
664 | "%d:0319 READ_SPARAM mbxStatus error x%x " | |
665 | "hba state x%x>\n", | |
666 | phba->brd_no, mb->mbxStatus, phba->hba_state); | |
667 | ||
668 | lpfc_linkdown(phba); | |
669 | phba->hba_state = LPFC_HBA_ERROR; | |
670 | goto out; | |
671 | } | |
672 | ||
673 | memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt, | |
674 | sizeof (struct serv_parm)); | |
675 | memcpy((uint8_t *) & phba->fc_nodename, | |
676 | (uint8_t *) & phba->fc_sparam.nodeName, | |
677 | sizeof (struct lpfc_name)); | |
678 | memcpy((uint8_t *) & phba->fc_portname, | |
679 | (uint8_t *) & phba->fc_sparam.portName, | |
680 | sizeof (struct lpfc_name)); | |
681 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
682 | kfree(mp); | |
683 | mempool_free( pmb, phba->mbox_mem_pool); | |
684 | return; | |
685 | ||
686 | out: | |
687 | pmb->context1 = NULL; | |
688 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
689 | kfree(mp); | |
690 | if (phba->hba_state != LPFC_CLEAR_LA) { | |
691 | lpfc_clear_la(phba, pmb); | |
692 | pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
693 | if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB)) | |
694 | == MBX_NOT_FINISHED) { | |
695 | mempool_free( pmb, phba->mbox_mem_pool); | |
696 | lpfc_disc_flush_list(phba); | |
697 | psli->ring[(psli->ip_ring)].flag &= | |
698 | ~LPFC_STOP_IOCB_EVENT; | |
699 | psli->ring[(psli->fcp_ring)].flag &= | |
700 | ~LPFC_STOP_IOCB_EVENT; | |
701 | psli->ring[(psli->next_ring)].flag &= | |
702 | ~LPFC_STOP_IOCB_EVENT; | |
703 | phba->hba_state = LPFC_HBA_READY; | |
704 | } | |
705 | } else { | |
706 | mempool_free( pmb, phba->mbox_mem_pool); | |
707 | } | |
708 | return; | |
709 | } | |
710 | ||
711 | static void | |
712 | lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la) | |
713 | { | |
714 | int i; | |
715 | LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox; | |
716 | sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
717 | cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
718 | ||
719 | spin_lock_irq(phba->host->host_lock); | |
2fe165b6 | 720 | switch (la->UlnkSpeed) { |
dea3101e | 721 | case LA_1GHZ_LINK: |
722 | phba->fc_linkspeed = LA_1GHZ_LINK; | |
723 | break; | |
724 | case LA_2GHZ_LINK: | |
725 | phba->fc_linkspeed = LA_2GHZ_LINK; | |
726 | break; | |
727 | case LA_4GHZ_LINK: | |
728 | phba->fc_linkspeed = LA_4GHZ_LINK; | |
729 | break; | |
730 | default: | |
731 | phba->fc_linkspeed = LA_UNKNW_LINK; | |
732 | break; | |
733 | } | |
734 | ||
735 | phba->fc_topology = la->topology; | |
736 | ||
737 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
738 | /* Get Loop Map information */ | |
739 | ||
740 | if (la->il) | |
741 | phba->fc_flag |= FC_LBIT; | |
742 | ||
743 | phba->fc_myDID = la->granted_AL_PA; | |
744 | i = la->un.lilpBde64.tus.f.bdeSize; | |
745 | ||
746 | if (i == 0) { | |
747 | phba->alpa_map[0] = 0; | |
748 | } else { | |
749 | if (phba->cfg_log_verbose & LOG_LINK_EVENT) { | |
750 | int numalpa, j, k; | |
751 | union { | |
752 | uint8_t pamap[16]; | |
753 | struct { | |
754 | uint32_t wd1; | |
755 | uint32_t wd2; | |
756 | uint32_t wd3; | |
757 | uint32_t wd4; | |
758 | } pa; | |
759 | } un; | |
760 | numalpa = phba->alpa_map[0]; | |
761 | j = 0; | |
762 | while (j < numalpa) { | |
763 | memset(un.pamap, 0, 16); | |
764 | for (k = 1; j < numalpa; k++) { | |
765 | un.pamap[k - 1] = | |
766 | phba->alpa_map[j + 1]; | |
767 | j++; | |
768 | if (k == 16) | |
769 | break; | |
770 | } | |
771 | /* Link Up Event ALPA map */ | |
772 | lpfc_printf_log(phba, | |
773 | KERN_WARNING, | |
774 | LOG_LINK_EVENT, | |
775 | "%d:1304 Link Up Event " | |
776 | "ALPA map Data: x%x " | |
777 | "x%x x%x x%x\n", | |
778 | phba->brd_no, | |
779 | un.pa.wd1, un.pa.wd2, | |
780 | un.pa.wd3, un.pa.wd4); | |
781 | } | |
782 | } | |
783 | } | |
784 | } else { | |
785 | phba->fc_myDID = phba->fc_pref_DID; | |
786 | phba->fc_flag |= FC_LBIT; | |
787 | } | |
788 | spin_unlock_irq(phba->host->host_lock); | |
789 | ||
790 | lpfc_linkup(phba); | |
791 | if (sparam_mbox) { | |
792 | lpfc_read_sparam(phba, sparam_mbox); | |
793 | sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam; | |
794 | lpfc_sli_issue_mbox(phba, sparam_mbox, | |
795 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
796 | } | |
797 | ||
798 | if (cfglink_mbox) { | |
799 | phba->hba_state = LPFC_LOCAL_CFG_LINK; | |
800 | lpfc_config_link(phba, cfglink_mbox); | |
25594c6b | 801 | cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; |
dea3101e | 802 | lpfc_sli_issue_mbox(phba, cfglink_mbox, |
803 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
804 | } | |
805 | } | |
806 | ||
807 | static void | |
808 | lpfc_mbx_issue_link_down(struct lpfc_hba *phba) { | |
809 | uint32_t control; | |
810 | struct lpfc_sli *psli = &phba->sli; | |
811 | ||
812 | lpfc_linkdown(phba); | |
813 | ||
814 | /* turn on Link Attention interrupts - no CLEAR_LA needed */ | |
815 | spin_lock_irq(phba->host->host_lock); | |
816 | psli->sli_flag |= LPFC_PROCESS_LA; | |
817 | control = readl(phba->HCregaddr); | |
818 | control |= HC_LAINT_ENA; | |
819 | writel(control, phba->HCregaddr); | |
820 | readl(phba->HCregaddr); /* flush */ | |
821 | spin_unlock_irq(phba->host->host_lock); | |
822 | } | |
823 | ||
824 | /* | |
825 | * This routine handles processing a READ_LA mailbox | |
826 | * command upon completion. It is setup in the LPFC_MBOXQ | |
827 | * as the completion routine when the command is | |
828 | * handed off to the SLI layer. | |
829 | */ | |
830 | void | |
831 | lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
832 | { | |
833 | READ_LA_VAR *la; | |
834 | MAILBOX_t *mb = &pmb->mb; | |
835 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); | |
836 | ||
837 | /* Check for error */ | |
838 | if (mb->mbxStatus) { | |
839 | lpfc_printf_log(phba, | |
840 | KERN_INFO, | |
841 | LOG_LINK_EVENT, | |
842 | "%d:1307 READ_LA mbox error x%x state x%x\n", | |
843 | phba->brd_no, | |
844 | mb->mbxStatus, phba->hba_state); | |
845 | lpfc_mbx_issue_link_down(phba); | |
846 | phba->hba_state = LPFC_HBA_ERROR; | |
847 | goto lpfc_mbx_cmpl_read_la_free_mbuf; | |
848 | } | |
849 | ||
850 | la = (READ_LA_VAR *) & pmb->mb.un.varReadLA; | |
851 | ||
852 | memcpy(&phba->alpa_map[0], mp->virt, 128); | |
853 | ||
c9f8735b JW |
854 | spin_lock_irq(phba->host->host_lock); |
855 | if (la->pb) | |
856 | phba->fc_flag |= FC_BYPASSED_MODE; | |
857 | else | |
858 | phba->fc_flag &= ~FC_BYPASSED_MODE; | |
859 | spin_unlock_irq(phba->host->host_lock); | |
860 | ||
dea3101e | 861 | if (((phba->fc_eventTag + 1) < la->eventTag) || |
862 | (phba->fc_eventTag == la->eventTag)) { | |
863 | phba->fc_stat.LinkMultiEvent++; | |
864 | if (la->attType == AT_LINK_UP) { | |
865 | if (phba->fc_eventTag != 0) | |
866 | lpfc_linkdown(phba); | |
867 | } | |
868 | } | |
869 | ||
870 | phba->fc_eventTag = la->eventTag; | |
871 | ||
872 | if (la->attType == AT_LINK_UP) { | |
873 | phba->fc_stat.LinkUp++; | |
874 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
875 | "%d:1303 Link Up Event x%x received " | |
876 | "Data: x%x x%x x%x x%x\n", | |
877 | phba->brd_no, la->eventTag, phba->fc_eventTag, | |
878 | la->granted_AL_PA, la->UlnkSpeed, | |
879 | phba->alpa_map[0]); | |
880 | lpfc_mbx_process_link_up(phba, la); | |
881 | } else { | |
882 | phba->fc_stat.LinkDown++; | |
883 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
884 | "%d:1305 Link Down Event x%x received " | |
885 | "Data: x%x x%x x%x\n", | |
886 | phba->brd_no, la->eventTag, phba->fc_eventTag, | |
887 | phba->hba_state, phba->fc_flag); | |
888 | lpfc_mbx_issue_link_down(phba); | |
889 | } | |
890 | ||
891 | lpfc_mbx_cmpl_read_la_free_mbuf: | |
892 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
893 | kfree(mp); | |
894 | mempool_free(pmb, phba->mbox_mem_pool); | |
895 | return; | |
896 | } | |
897 | ||
898 | /* | |
899 | * This routine handles processing a REG_LOGIN mailbox | |
900 | * command upon completion. It is setup in the LPFC_MBOXQ | |
901 | * as the completion routine when the command is | |
902 | * handed off to the SLI layer. | |
903 | */ | |
904 | void | |
905 | lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
906 | { | |
907 | struct lpfc_sli *psli; | |
908 | MAILBOX_t *mb; | |
909 | struct lpfc_dmabuf *mp; | |
910 | struct lpfc_nodelist *ndlp; | |
911 | ||
912 | psli = &phba->sli; | |
913 | mb = &pmb->mb; | |
914 | ||
915 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
916 | mp = (struct lpfc_dmabuf *) (pmb->context1); | |
917 | ||
918 | pmb->context1 = NULL; | |
919 | ||
920 | /* Good status, call state machine */ | |
921 | lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN); | |
922 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
923 | kfree(mp); | |
924 | mempool_free( pmb, phba->mbox_mem_pool); | |
925 | ||
926 | return; | |
927 | } | |
928 | ||
929 | /* | |
930 | * This routine handles processing a Fabric REG_LOGIN mailbox | |
931 | * command upon completion. It is setup in the LPFC_MBOXQ | |
932 | * as the completion routine when the command is | |
933 | * handed off to the SLI layer. | |
934 | */ | |
935 | void | |
936 | lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
937 | { | |
938 | struct lpfc_sli *psli; | |
939 | MAILBOX_t *mb; | |
940 | struct lpfc_dmabuf *mp; | |
941 | struct lpfc_nodelist *ndlp; | |
942 | struct lpfc_nodelist *ndlp_fdmi; | |
943 | ||
944 | ||
945 | psli = &phba->sli; | |
946 | mb = &pmb->mb; | |
947 | ||
948 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
949 | mp = (struct lpfc_dmabuf *) (pmb->context1); | |
950 | ||
951 | if (mb->mbxStatus) { | |
952 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
953 | kfree(mp); | |
954 | mempool_free( pmb, phba->mbox_mem_pool); | |
955 | mempool_free( ndlp, phba->nlp_mem_pool); | |
956 | ||
957 | /* FLOGI failed, so just use loop map to make discovery list */ | |
958 | lpfc_disc_list_loopmap(phba); | |
959 | ||
960 | /* Start discovery */ | |
961 | lpfc_disc_start(phba); | |
962 | return; | |
963 | } | |
964 | ||
965 | pmb->context1 = NULL; | |
966 | ||
dea3101e | 967 | ndlp->nlp_rpi = mb->un.varWords[0]; |
dea3101e | 968 | ndlp->nlp_type |= NLP_FABRIC; |
969 | ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; | |
970 | lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST); | |
971 | ||
972 | if (phba->hba_state == LPFC_FABRIC_CFG_LINK) { | |
973 | /* This NPort has been assigned an NPort_ID by the fabric as a | |
974 | * result of the completed fabric login. Issue a State Change | |
975 | * Registration (SCR) ELS request to the fabric controller | |
976 | * (SCR_DID) so that this NPort gets RSCN events from the | |
977 | * fabric. | |
978 | */ | |
979 | lpfc_issue_els_scr(phba, SCR_DID, 0); | |
980 | ||
c9f8735b JW |
981 | ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID); |
982 | if (!ndlp) { | |
983 | /* Allocate a new node instance. If the pool is empty, | |
984 | * start the discovery process and skip the Nameserver | |
985 | * login process. This is attempted again later on. | |
986 | * Otherwise, issue a Port Login (PLOGI) to NameServer. | |
987 | */ | |
988 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); | |
989 | if (!ndlp) { | |
990 | lpfc_disc_start(phba); | |
991 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
992 | kfree(mp); | |
993 | mempool_free( pmb, phba->mbox_mem_pool); | |
994 | return; | |
995 | } else { | |
996 | lpfc_nlp_init(phba, ndlp, NameServer_DID); | |
997 | ndlp->nlp_type |= NLP_FABRIC; | |
998 | } | |
999 | } | |
1000 | ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; | |
1001 | lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST); | |
488d1469 | 1002 | lpfc_issue_els_plogi(phba, NameServer_DID, 0); |
c9f8735b JW |
1003 | if (phba->cfg_fdmi_on) { |
1004 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, | |
1005 | GFP_KERNEL); | |
1006 | if (ndlp_fdmi) { | |
1007 | lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID); | |
1008 | ndlp_fdmi->nlp_type |= NLP_FABRIC; | |
1009 | ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE; | |
488d1469 | 1010 | lpfc_issue_els_plogi(phba, FDMI_DID, 0); |
dea3101e | 1011 | } |
1012 | } | |
1013 | } | |
1014 | ||
1015 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1016 | kfree(mp); | |
1017 | mempool_free( pmb, phba->mbox_mem_pool); | |
dea3101e | 1018 | return; |
1019 | } | |
1020 | ||
1021 | /* | |
1022 | * This routine handles processing a NameServer REG_LOGIN mailbox | |
1023 | * command upon completion. It is setup in the LPFC_MBOXQ | |
1024 | * as the completion routine when the command is | |
1025 | * handed off to the SLI layer. | |
1026 | */ | |
1027 | void | |
1028 | lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
1029 | { | |
1030 | struct lpfc_sli *psli; | |
1031 | MAILBOX_t *mb; | |
1032 | struct lpfc_dmabuf *mp; | |
1033 | struct lpfc_nodelist *ndlp; | |
1034 | ||
1035 | psli = &phba->sli; | |
1036 | mb = &pmb->mb; | |
1037 | ||
1038 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
1039 | mp = (struct lpfc_dmabuf *) (pmb->context1); | |
1040 | ||
1041 | if (mb->mbxStatus) { | |
1042 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1043 | kfree(mp); | |
1044 | mempool_free( pmb, phba->mbox_mem_pool); | |
1045 | lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); | |
1046 | ||
1047 | /* RegLogin failed, so just use loop map to make discovery | |
1048 | list */ | |
1049 | lpfc_disc_list_loopmap(phba); | |
1050 | ||
1051 | /* Start discovery */ | |
1052 | lpfc_disc_start(phba); | |
1053 | return; | |
1054 | } | |
1055 | ||
1056 | pmb->context1 = NULL; | |
1057 | ||
dea3101e | 1058 | ndlp->nlp_rpi = mb->un.varWords[0]; |
dea3101e | 1059 | ndlp->nlp_type |= NLP_FABRIC; |
1060 | ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; | |
1061 | lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST); | |
1062 | ||
1063 | if (phba->hba_state < LPFC_HBA_READY) { | |
1064 | /* Link up discovery requires Fabrib registration. */ | |
1065 | lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID); | |
1066 | lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN); | |
1067 | lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID); | |
1068 | } | |
1069 | ||
1070 | phba->fc_ns_retry = 0; | |
1071 | /* Good status, issue CT Request to NameServer */ | |
1072 | if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) { | |
1073 | /* Cannot issue NameServer Query, so finish up discovery */ | |
1074 | lpfc_disc_start(phba); | |
1075 | } | |
1076 | ||
1077 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1078 | kfree(mp); | |
1079 | mempool_free( pmb, phba->mbox_mem_pool); | |
1080 | ||
1081 | return; | |
1082 | } | |
1083 | ||
1084 | static void | |
1085 | lpfc_register_remote_port(struct lpfc_hba * phba, | |
1086 | struct lpfc_nodelist * ndlp) | |
1087 | { | |
1088 | struct fc_rport *rport; | |
1089 | struct lpfc_rport_data *rdata; | |
1090 | struct fc_rport_identifiers rport_ids; | |
dea3101e | 1091 | |
1092 | /* Remote port has reappeared. Re-register w/ FC transport */ | |
68ce1eb5 AM |
1093 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
1094 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); | |
dea3101e | 1095 | rport_ids.port_id = ndlp->nlp_DID; |
1096 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; | |
dea3101e | 1097 | |
1098 | ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids); | |
1099 | if (!rport) { | |
1100 | dev_printk(KERN_WARNING, &phba->pcidev->dev, | |
1101 | "Warning: fc_remote_port_add failed\n"); | |
1102 | return; | |
1103 | } | |
1104 | ||
1105 | /* initialize static port data */ | |
1106 | rport->maxframe_size = ndlp->nlp_maxframe; | |
1107 | rport->supported_classes = ndlp->nlp_class_sup; | |
dea3101e | 1108 | rdata = rport->dd_data; |
1109 | rdata->pnode = ndlp; | |
23dc04f1 JSEC |
1110 | |
1111 | if (ndlp->nlp_type & NLP_FCP_TARGET) | |
1112 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; | |
1113 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) | |
1114 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; | |
1115 | ||
1116 | ||
1117 | if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN) | |
1118 | fc_remote_port_rolechg(rport, rport_ids.roles); | |
1119 | ||
071fbd3d | 1120 | if ((rport->scsi_target_id != -1) && |
e17da18e | 1121 | (rport->scsi_target_id < LPFC_MAX_TARGET)) { |
071fbd3d JS |
1122 | ndlp->nlp_sid = rport->scsi_target_id; |
1123 | } | |
19a7b4ae JSEC |
1124 | |
1125 | return; | |
1126 | } | |
1127 | ||
1128 | static void | |
1129 | lpfc_unregister_remote_port(struct lpfc_hba * phba, | |
1130 | struct lpfc_nodelist * ndlp) | |
1131 | { | |
1132 | struct fc_rport *rport = ndlp->rport; | |
1133 | struct lpfc_rport_data *rdata = rport->dd_data; | |
1134 | ||
c01f3208 JS |
1135 | if (rport->scsi_target_id == -1) { |
1136 | ndlp->rport = NULL; | |
1137 | rdata->pnode = NULL; | |
1138 | } | |
1139 | ||
19a7b4ae | 1140 | fc_remote_port_delete(rport); |
dea3101e | 1141 | |
1142 | return; | |
1143 | } | |
1144 | ||
1145 | int | |
1146 | lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list) | |
1147 | { | |
1148 | enum { none, unmapped, mapped } rport_add = none, rport_del = none; | |
1149 | struct lpfc_sli *psli; | |
1150 | ||
1151 | psli = &phba->sli; | |
1152 | /* Sanity check to ensure we are not moving to / from the same list */ | |
2fe165b6 | 1153 | if ((nlp->nlp_flag & NLP_LIST_MASK) == list) |
dea3101e | 1154 | if (list != NLP_NO_LIST) |
2fe165b6 | 1155 | return 0; |
dea3101e | 1156 | |
66a9ed66 | 1157 | spin_lock_irq(phba->host->host_lock); |
2fe165b6 | 1158 | switch (nlp->nlp_flag & NLP_LIST_MASK) { |
dea3101e | 1159 | case NLP_NO_LIST: /* Not on any list */ |
1160 | break; | |
1161 | case NLP_UNUSED_LIST: | |
1162 | phba->fc_unused_cnt--; | |
1163 | list_del(&nlp->nlp_listp); | |
1164 | break; | |
1165 | case NLP_PLOGI_LIST: | |
1166 | phba->fc_plogi_cnt--; | |
1167 | list_del(&nlp->nlp_listp); | |
1168 | break; | |
1169 | case NLP_ADISC_LIST: | |
1170 | phba->fc_adisc_cnt--; | |
1171 | list_del(&nlp->nlp_listp); | |
1172 | break; | |
1173 | case NLP_REGLOGIN_LIST: | |
1174 | phba->fc_reglogin_cnt--; | |
1175 | list_del(&nlp->nlp_listp); | |
1176 | break; | |
1177 | case NLP_PRLI_LIST: | |
1178 | phba->fc_prli_cnt--; | |
1179 | list_del(&nlp->nlp_listp); | |
1180 | break; | |
1181 | case NLP_UNMAPPED_LIST: | |
1182 | phba->fc_unmap_cnt--; | |
1183 | list_del(&nlp->nlp_listp); | |
dea3101e | 1184 | nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID; |
1185 | nlp->nlp_type &= ~NLP_FC_NODE; | |
dea3101e | 1186 | phba->nport_event_cnt++; |
1187 | if (nlp->rport) | |
1188 | rport_del = unmapped; | |
1189 | break; | |
1190 | case NLP_MAPPED_LIST: | |
1191 | phba->fc_map_cnt--; | |
1192 | list_del(&nlp->nlp_listp); | |
1193 | phba->nport_event_cnt++; | |
1194 | if (nlp->rport) | |
1195 | rport_del = mapped; | |
1196 | break; | |
1197 | case NLP_NPR_LIST: | |
1198 | phba->fc_npr_cnt--; | |
1199 | list_del(&nlp->nlp_listp); | |
1200 | /* Stop delay tmo if taking node off NPR list */ | |
1201 | if ((nlp->nlp_flag & NLP_DELAY_TMO) && | |
1202 | (list != NLP_NPR_LIST)) { | |
66a9ed66 | 1203 | spin_unlock_irq(phba->host->host_lock); |
fdcebe28 | 1204 | lpfc_cancel_retry_delay_tmo(phba, nlp); |
66a9ed66 | 1205 | spin_lock_irq(phba->host->host_lock); |
dea3101e | 1206 | } |
1207 | break; | |
1208 | } | |
1209 | ||
dea3101e | 1210 | nlp->nlp_flag &= ~NLP_LIST_MASK; |
dea3101e | 1211 | |
1212 | /* Add NPort <did> to <num> list */ | |
1213 | lpfc_printf_log(phba, | |
1214 | KERN_INFO, | |
1215 | LOG_NODE, | |
1216 | "%d:0904 Add NPort x%x to %d list Data: x%x\n", | |
1217 | phba->brd_no, | |
1218 | nlp->nlp_DID, list, nlp->nlp_flag); | |
1219 | ||
2fe165b6 | 1220 | switch (list) { |
dea3101e | 1221 | case NLP_NO_LIST: /* No list, just remove it */ |
66a9ed66 | 1222 | spin_unlock_irq(phba->host->host_lock); |
dea3101e | 1223 | lpfc_nlp_remove(phba, nlp); |
66a9ed66 | 1224 | spin_lock_irq(phba->host->host_lock); |
8cbdc5ff JSEC |
1225 | /* as node removed - stop further transport calls */ |
1226 | rport_del = none; | |
dea3101e | 1227 | break; |
1228 | case NLP_UNUSED_LIST: | |
dea3101e | 1229 | nlp->nlp_flag |= list; |
dea3101e | 1230 | /* Put it at the end of the unused list */ |
1231 | list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list); | |
1232 | phba->fc_unused_cnt++; | |
1233 | break; | |
1234 | case NLP_PLOGI_LIST: | |
dea3101e | 1235 | nlp->nlp_flag |= list; |
dea3101e | 1236 | /* Put it at the end of the plogi list */ |
1237 | list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list); | |
1238 | phba->fc_plogi_cnt++; | |
1239 | break; | |
1240 | case NLP_ADISC_LIST: | |
dea3101e | 1241 | nlp->nlp_flag |= list; |
dea3101e | 1242 | /* Put it at the end of the adisc list */ |
1243 | list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list); | |
1244 | phba->fc_adisc_cnt++; | |
1245 | break; | |
1246 | case NLP_REGLOGIN_LIST: | |
dea3101e | 1247 | nlp->nlp_flag |= list; |
dea3101e | 1248 | /* Put it at the end of the reglogin list */ |
1249 | list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list); | |
1250 | phba->fc_reglogin_cnt++; | |
1251 | break; | |
1252 | case NLP_PRLI_LIST: | |
dea3101e | 1253 | nlp->nlp_flag |= list; |
dea3101e | 1254 | /* Put it at the end of the prli list */ |
1255 | list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list); | |
1256 | phba->fc_prli_cnt++; | |
1257 | break; | |
1258 | case NLP_UNMAPPED_LIST: | |
1259 | rport_add = unmapped; | |
1260 | /* ensure all vestiges of "mapped" significance are gone */ | |
1261 | nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); | |
dea3101e | 1262 | nlp->nlp_flag |= list; |
dea3101e | 1263 | /* Put it at the end of the unmap list */ |
1264 | list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list); | |
1265 | phba->fc_unmap_cnt++; | |
1266 | phba->nport_event_cnt++; | |
a0f9b48d | 1267 | nlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
dea3101e | 1268 | nlp->nlp_type |= NLP_FC_NODE; |
1269 | break; | |
1270 | case NLP_MAPPED_LIST: | |
1271 | rport_add = mapped; | |
dea3101e | 1272 | nlp->nlp_flag |= list; |
dea3101e | 1273 | /* Put it at the end of the map list */ |
1274 | list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list); | |
1275 | phba->fc_map_cnt++; | |
1276 | phba->nport_event_cnt++; | |
a0f9b48d | 1277 | nlp->nlp_flag &= ~NLP_NODEV_REMOVE; |
dea3101e | 1278 | break; |
1279 | case NLP_NPR_LIST: | |
dea3101e | 1280 | nlp->nlp_flag |= list; |
dea3101e | 1281 | /* Put it at the end of the npr list */ |
1282 | list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list); | |
1283 | phba->fc_npr_cnt++; | |
1284 | ||
dea3101e | 1285 | nlp->nlp_flag &= ~NLP_RCV_PLOGI; |
dea3101e | 1286 | break; |
1287 | case NLP_JUST_DQ: | |
1288 | break; | |
1289 | } | |
1290 | ||
66a9ed66 JW |
1291 | spin_unlock_irq(phba->host->host_lock); |
1292 | ||
dea3101e | 1293 | /* |
1294 | * We make all the calls into the transport after we have | |
1295 | * moved the node between lists. This so that we don't | |
1296 | * release the lock while in-between lists. | |
1297 | */ | |
1298 | ||
1299 | /* Don't upcall midlayer if we're unloading */ | |
1300 | if (!(phba->fc_flag & FC_UNLOADING)) { | |
1301 | /* | |
1302 | * We revalidate the rport pointer as the "add" function | |
1303 | * may have removed the remote port. | |
1304 | */ | |
1305 | if ((rport_del != none) && nlp->rport) | |
19a7b4ae | 1306 | lpfc_unregister_remote_port(phba, nlp); |
dea3101e | 1307 | |
1308 | if (rport_add != none) { | |
1309 | /* | |
1310 | * Tell the fc transport about the port, if we haven't | |
1311 | * already. If we have, and it's a scsi entity, be | |
1312 | * sure to unblock any attached scsi devices | |
1313 | */ | |
c01f3208 JS |
1314 | if ((!nlp->rport) || (nlp->rport->port_state == |
1315 | FC_PORTSTATE_BLOCKED)) | |
dea3101e | 1316 | lpfc_register_remote_port(phba, nlp); |
dea3101e | 1317 | |
1318 | /* | |
1319 | * if we added to Mapped list, but the remote port | |
1320 | * registration failed or assigned a target id outside | |
1321 | * our presentable range - move the node to the | |
1322 | * Unmapped List | |
1323 | */ | |
1324 | if ((rport_add == mapped) && | |
1325 | ((!nlp->rport) || | |
1326 | (nlp->rport->scsi_target_id == -1) || | |
e17da18e | 1327 | (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) { |
dea3101e | 1328 | nlp->nlp_state = NLP_STE_UNMAPPED_NODE; |
1329 | spin_lock_irq(phba->host->host_lock); | |
1330 | nlp->nlp_flag |= NLP_TGT_NO_SCSIID; | |
1331 | spin_unlock_irq(phba->host->host_lock); | |
1332 | lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST); | |
1333 | } | |
1334 | } | |
1335 | } | |
2fe165b6 | 1336 | return 0; |
dea3101e | 1337 | } |
1338 | ||
1339 | /* | |
1340 | * Start / ReStart rescue timer for Discovery / RSCN handling | |
1341 | */ | |
1342 | void | |
1343 | lpfc_set_disctmo(struct lpfc_hba * phba) | |
1344 | { | |
1345 | uint32_t tmo; | |
1346 | ||
c9f8735b JW |
1347 | if (phba->hba_state == LPFC_LOCAL_CFG_LINK) { |
1348 | /* For FAN, timeout should be greater then edtov */ | |
1349 | tmo = (((phba->fc_edtov + 999) / 1000) + 1); | |
1350 | } else { | |
1351 | /* Normal discovery timeout should be > then ELS/CT timeout | |
1352 | * FC spec states we need 3 * ratov for CT requests | |
1353 | */ | |
1354 | tmo = ((phba->fc_ratov * 3) + 3); | |
1355 | } | |
dea3101e | 1356 | |
1357 | mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo); | |
1358 | spin_lock_irq(phba->host->host_lock); | |
1359 | phba->fc_flag |= FC_DISC_TMO; | |
1360 | spin_unlock_irq(phba->host->host_lock); | |
1361 | ||
1362 | /* Start Discovery Timer state <hba_state> */ | |
1363 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
1364 | "%d:0247 Start Discovery Timer state x%x " | |
1365 | "Data: x%x x%lx x%x x%x\n", | |
1366 | phba->brd_no, | |
1367 | phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo, | |
1368 | phba->fc_plogi_cnt, phba->fc_adisc_cnt); | |
1369 | ||
1370 | return; | |
1371 | } | |
1372 | ||
1373 | /* | |
1374 | * Cancel rescue timer for Discovery / RSCN handling | |
1375 | */ | |
1376 | int | |
1377 | lpfc_can_disctmo(struct lpfc_hba * phba) | |
1378 | { | |
1379 | /* Turn off discovery timer if its running */ | |
1380 | if (phba->fc_flag & FC_DISC_TMO) { | |
1381 | spin_lock_irq(phba->host->host_lock); | |
1382 | phba->fc_flag &= ~FC_DISC_TMO; | |
1383 | spin_unlock_irq(phba->host->host_lock); | |
1384 | del_timer_sync(&phba->fc_disctmo); | |
1385 | phba->work_hba_events &= ~WORKER_DISC_TMO; | |
1386 | } | |
1387 | ||
1388 | /* Cancel Discovery Timer state <hba_state> */ | |
1389 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
1390 | "%d:0248 Cancel Discovery Timer state x%x " | |
1391 | "Data: x%x x%x x%x\n", | |
1392 | phba->brd_no, phba->hba_state, phba->fc_flag, | |
1393 | phba->fc_plogi_cnt, phba->fc_adisc_cnt); | |
1394 | ||
2fe165b6 | 1395 | return 0; |
dea3101e | 1396 | } |
1397 | ||
1398 | /* | |
1399 | * Check specified ring for outstanding IOCB on the SLI queue | |
1400 | * Return true if iocb matches the specified nport | |
1401 | */ | |
1402 | int | |
1403 | lpfc_check_sli_ndlp(struct lpfc_hba * phba, | |
1404 | struct lpfc_sli_ring * pring, | |
1405 | struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp) | |
1406 | { | |
1407 | struct lpfc_sli *psli; | |
1408 | IOCB_t *icmd; | |
1409 | ||
1410 | psli = &phba->sli; | |
1411 | icmd = &iocb->iocb; | |
1412 | if (pring->ringno == LPFC_ELS_RING) { | |
1413 | switch (icmd->ulpCommand) { | |
1414 | case CMD_GEN_REQUEST64_CR: | |
1415 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) | |
2fe165b6 | 1416 | return 1; |
dea3101e | 1417 | case CMD_ELS_REQUEST64_CR: |
10d4e957 JS |
1418 | if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID) |
1419 | return 1; | |
dea3101e | 1420 | case CMD_XMIT_ELS_RSP64_CX: |
1421 | if (iocb->context1 == (uint8_t *) ndlp) | |
2fe165b6 | 1422 | return 1; |
dea3101e | 1423 | } |
1424 | } else if (pring->ringno == psli->ip_ring) { | |
1425 | ||
1426 | } else if (pring->ringno == psli->fcp_ring) { | |
1427 | /* Skip match check if waiting to relogin to FCP target */ | |
1428 | if ((ndlp->nlp_type & NLP_FCP_TARGET) && | |
1429 | (ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
2fe165b6 | 1430 | return 0; |
dea3101e | 1431 | } |
1432 | if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) { | |
2fe165b6 | 1433 | return 1; |
dea3101e | 1434 | } |
1435 | } else if (pring->ringno == psli->next_ring) { | |
1436 | ||
1437 | } | |
2fe165b6 | 1438 | return 0; |
dea3101e | 1439 | } |
1440 | ||
1441 | /* | |
1442 | * Free resources / clean up outstanding I/Os | |
1443 | * associated with nlp_rpi in the LPFC_NODELIST entry. | |
1444 | */ | |
1445 | static int | |
1446 | lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) | |
1447 | { | |
1448 | struct lpfc_sli *psli; | |
1449 | struct lpfc_sli_ring *pring; | |
1450 | struct lpfc_iocbq *iocb, *next_iocb; | |
1451 | IOCB_t *icmd; | |
1452 | uint32_t rpi, i; | |
1453 | ||
1454 | /* | |
1455 | * Everything that matches on txcmplq will be returned | |
1456 | * by firmware with a no rpi error. | |
1457 | */ | |
1458 | psli = &phba->sli; | |
1459 | rpi = ndlp->nlp_rpi; | |
1460 | if (rpi) { | |
1461 | /* Now process each ring */ | |
1462 | for (i = 0; i < psli->num_rings; i++) { | |
1463 | pring = &psli->ring[i]; | |
1464 | ||
1465 | spin_lock_irq(phba->host->host_lock); | |
1466 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, | |
1467 | list) { | |
1468 | /* | |
1469 | * Check to see if iocb matches the nport we are | |
1470 | * looking for | |
1471 | */ | |
1472 | if ((lpfc_check_sli_ndlp | |
1473 | (phba, pring, iocb, ndlp))) { | |
1474 | /* It matches, so deque and call compl | |
1475 | with an error */ | |
1476 | list_del(&iocb->list); | |
1477 | pring->txq_cnt--; | |
1478 | if (iocb->iocb_cmpl) { | |
1479 | icmd = &iocb->iocb; | |
1480 | icmd->ulpStatus = | |
1481 | IOSTAT_LOCAL_REJECT; | |
1482 | icmd->un.ulpWord[4] = | |
1483 | IOERR_SLI_ABORTED; | |
1484 | spin_unlock_irq(phba->host-> | |
1485 | host_lock); | |
1486 | (iocb->iocb_cmpl) (phba, | |
1487 | iocb, iocb); | |
1488 | spin_lock_irq(phba->host-> | |
1489 | host_lock); | |
604a3e30 JB |
1490 | } else |
1491 | lpfc_sli_release_iocbq(phba, | |
1492 | iocb); | |
dea3101e | 1493 | } |
1494 | } | |
1495 | spin_unlock_irq(phba->host->host_lock); | |
1496 | ||
1497 | } | |
1498 | } | |
2fe165b6 | 1499 | return 0; |
dea3101e | 1500 | } |
1501 | ||
1502 | /* | |
1503 | * Free rpi associated with LPFC_NODELIST entry. | |
1504 | * This routine is called from lpfc_freenode(), when we are removing | |
1505 | * a LPFC_NODELIST entry. It is also called if the driver initiates a | |
1506 | * LOGO that completes successfully, and we are waiting to PLOGI back | |
1507 | * to the remote NPort. In addition, it is called after we receive | |
1508 | * and unsolicated ELS cmd, send back a rsp, the rsp completes and | |
1509 | * we are waiting to PLOGI back to the remote NPort. | |
1510 | */ | |
1511 | int | |
1512 | lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) | |
1513 | { | |
1514 | LPFC_MBOXQ_t *mbox; | |
1515 | int rc; | |
1516 | ||
1517 | if (ndlp->nlp_rpi) { | |
1518 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) { | |
1519 | lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox); | |
1520 | mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl; | |
1521 | rc = lpfc_sli_issue_mbox | |
1522 | (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB)); | |
1523 | if (rc == MBX_NOT_FINISHED) | |
1524 | mempool_free( mbox, phba->mbox_mem_pool); | |
1525 | } | |
dea3101e | 1526 | lpfc_no_rpi(phba, ndlp); |
1527 | ndlp->nlp_rpi = 0; | |
1528 | return 1; | |
1529 | } | |
1530 | return 0; | |
1531 | } | |
1532 | ||
1533 | /* | |
1534 | * Free resources associated with LPFC_NODELIST entry | |
1535 | * so it can be freed. | |
1536 | */ | |
1537 | static int | |
1538 | lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) | |
1539 | { | |
1540 | LPFC_MBOXQ_t *mb; | |
1541 | LPFC_MBOXQ_t *nextmb; | |
1542 | struct lpfc_dmabuf *mp; | |
dea3101e | 1543 | |
1544 | /* Cleanup node for NPort <nlp_DID> */ | |
1545 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
1546 | "%d:0900 Cleanup node for NPort x%x " | |
1547 | "Data: x%x x%x x%x\n", | |
1548 | phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, | |
1549 | ndlp->nlp_state, ndlp->nlp_rpi); | |
1550 | ||
1551 | lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ); | |
1552 | ||
1553 | /* | |
1554 | * if unloading the driver - just leave the remote port in place. | |
1555 | * The driver unload will force the attached devices to detach | |
1556 | * and flush cache's w/o generating flush errors. | |
1557 | */ | |
1558 | if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) { | |
19a7b4ae | 1559 | lpfc_unregister_remote_port(phba, ndlp); |
dea3101e | 1560 | ndlp->nlp_sid = NLP_NO_SID; |
1561 | } | |
1562 | ||
1563 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ | |
1564 | if ((mb = phba->sli.mbox_active)) { | |
1565 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && | |
1566 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { | |
1567 | mb->context2 = NULL; | |
1568 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1569 | } | |
1570 | } | |
33ccf8d1 JS |
1571 | |
1572 | spin_lock_irq(phba->host->host_lock); | |
dea3101e | 1573 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
1574 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && | |
1575 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { | |
1576 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
1577 | if (mp) { | |
1578 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1579 | kfree(mp); | |
1580 | } | |
1581 | list_del(&mb->list); | |
1582 | mempool_free(mb, phba->mbox_mem_pool); | |
1583 | } | |
1584 | } | |
33ccf8d1 | 1585 | spin_unlock_irq(phba->host->host_lock); |
dea3101e | 1586 | |
1587 | lpfc_els_abort(phba,ndlp,0); | |
1588 | spin_lock_irq(phba->host->host_lock); | |
c01f3208 | 1589 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
dea3101e | 1590 | spin_unlock_irq(phba->host->host_lock); |
dea3101e | 1591 | |
5024ab17 | 1592 | ndlp->nlp_last_elscmd = 0; |
dea3101e | 1593 | del_timer_sync(&ndlp->nlp_delayfunc); |
1594 | ||
dea3101e | 1595 | if (!list_empty(&ndlp->els_retry_evt.evt_listp)) |
1596 | list_del_init(&ndlp->els_retry_evt.evt_listp); | |
1597 | ||
1598 | lpfc_unreg_rpi(phba, ndlp); | |
1599 | ||
2fe165b6 | 1600 | return 0; |
dea3101e | 1601 | } |
1602 | ||
1603 | /* | |
1604 | * Check to see if we can free the nlp back to the freelist. | |
1605 | * If we are in the middle of using the nlp in the discovery state | |
1606 | * machine, defer the free till we reach the end of the state machine. | |
1607 | */ | |
1608 | int | |
1609 | lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) | |
1610 | { | |
dea3101e | 1611 | |
1612 | if (ndlp->nlp_flag & NLP_DELAY_TMO) { | |
fdcebe28 | 1613 | lpfc_cancel_retry_delay_tmo(phba, ndlp); |
dea3101e | 1614 | } |
1615 | ||
1616 | if (ndlp->nlp_disc_refcnt) { | |
1617 | spin_lock_irq(phba->host->host_lock); | |
1618 | ndlp->nlp_flag |= NLP_DELAY_REMOVE; | |
1619 | spin_unlock_irq(phba->host->host_lock); | |
2fe165b6 | 1620 | } else { |
dea3101e | 1621 | lpfc_freenode(phba, ndlp); |
1622 | mempool_free( ndlp, phba->nlp_mem_pool); | |
1623 | } | |
2fe165b6 | 1624 | return 0; |
dea3101e | 1625 | } |
1626 | ||
1627 | static int | |
1628 | lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did) | |
1629 | { | |
1630 | D_ID mydid; | |
1631 | D_ID ndlpdid; | |
1632 | D_ID matchdid; | |
1633 | ||
1634 | if (did == Bcast_DID) | |
2fe165b6 | 1635 | return 0; |
dea3101e | 1636 | |
1637 | if (ndlp->nlp_DID == 0) { | |
2fe165b6 | 1638 | return 0; |
dea3101e | 1639 | } |
1640 | ||
1641 | /* First check for Direct match */ | |
1642 | if (ndlp->nlp_DID == did) | |
2fe165b6 | 1643 | return 1; |
dea3101e | 1644 | |
1645 | /* Next check for area/domain identically equals 0 match */ | |
1646 | mydid.un.word = phba->fc_myDID; | |
1647 | if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) { | |
2fe165b6 | 1648 | return 0; |
dea3101e | 1649 | } |
1650 | ||
1651 | matchdid.un.word = did; | |
1652 | ndlpdid.un.word = ndlp->nlp_DID; | |
1653 | if (matchdid.un.b.id == ndlpdid.un.b.id) { | |
1654 | if ((mydid.un.b.domain == matchdid.un.b.domain) && | |
1655 | (mydid.un.b.area == matchdid.un.b.area)) { | |
1656 | if ((ndlpdid.un.b.domain == 0) && | |
1657 | (ndlpdid.un.b.area == 0)) { | |
1658 | if (ndlpdid.un.b.id) | |
2fe165b6 | 1659 | return 1; |
dea3101e | 1660 | } |
2fe165b6 | 1661 | return 0; |
dea3101e | 1662 | } |
1663 | ||
1664 | matchdid.un.word = ndlp->nlp_DID; | |
1665 | if ((mydid.un.b.domain == ndlpdid.un.b.domain) && | |
1666 | (mydid.un.b.area == ndlpdid.un.b.area)) { | |
1667 | if ((matchdid.un.b.domain == 0) && | |
1668 | (matchdid.un.b.area == 0)) { | |
1669 | if (matchdid.un.b.id) | |
2fe165b6 | 1670 | return 1; |
dea3101e | 1671 | } |
1672 | } | |
1673 | } | |
2fe165b6 | 1674 | return 0; |
dea3101e | 1675 | } |
1676 | ||
1677 | /* Search for a nodelist entry on a specific list */ | |
1678 | struct lpfc_nodelist * | |
1679 | lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did) | |
1680 | { | |
1681 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
1682 | uint32_t data1; | |
1683 | ||
66a9ed66 | 1684 | spin_lock_irq(phba->host->host_lock); |
dea3101e | 1685 | if (order & NLP_SEARCH_UNMAPPED) { |
1686 | list_for_each_entry_safe(ndlp, next_ndlp, | |
1687 | &phba->fc_nlpunmap_list, nlp_listp) { | |
1688 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1689 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1690 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1691 | ((uint32_t) ndlp->nlp_type << 8) | | |
1692 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1693 | /* FIND node DID unmapped */ | |
1694 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
1695 | "%d:0929 FIND node DID unmapped" | |
1696 | " Data: x%p x%x x%x x%x\n", | |
1697 | phba->brd_no, | |
1698 | ndlp, ndlp->nlp_DID, | |
1699 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1700 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1701 | return ndlp; |
dea3101e | 1702 | } |
1703 | } | |
1704 | } | |
1705 | ||
1706 | if (order & NLP_SEARCH_MAPPED) { | |
1707 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list, | |
1708 | nlp_listp) { | |
1709 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1710 | ||
1711 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1712 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1713 | ((uint32_t) ndlp->nlp_type << 8) | | |
1714 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1715 | /* FIND node DID mapped */ | |
1716 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
1717 | "%d:0930 FIND node DID mapped " | |
1718 | "Data: x%p x%x x%x x%x\n", | |
1719 | phba->brd_no, | |
1720 | ndlp, ndlp->nlp_DID, | |
1721 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1722 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1723 | return ndlp; |
dea3101e | 1724 | } |
1725 | } | |
1726 | } | |
1727 | ||
1728 | if (order & NLP_SEARCH_PLOGI) { | |
1729 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list, | |
1730 | nlp_listp) { | |
1731 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1732 | ||
1733 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1734 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1735 | ((uint32_t) ndlp->nlp_type << 8) | | |
1736 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1737 | /* LOG change to PLOGI */ | |
1738 | /* FIND node DID plogi */ | |
1739 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
1740 | "%d:0908 FIND node DID plogi " | |
1741 | "Data: x%p x%x x%x x%x\n", | |
1742 | phba->brd_no, | |
1743 | ndlp, ndlp->nlp_DID, | |
1744 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1745 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1746 | return ndlp; |
dea3101e | 1747 | } |
1748 | } | |
1749 | } | |
1750 | ||
1751 | if (order & NLP_SEARCH_ADISC) { | |
1752 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list, | |
1753 | nlp_listp) { | |
1754 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1755 | ||
1756 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1757 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1758 | ((uint32_t) ndlp->nlp_type << 8) | | |
1759 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1760 | /* LOG change to ADISC */ | |
1761 | /* FIND node DID adisc */ | |
1762 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
1763 | "%d:0931 FIND node DID adisc " | |
1764 | "Data: x%p x%x x%x x%x\n", | |
1765 | phba->brd_no, | |
1766 | ndlp, ndlp->nlp_DID, | |
1767 | ndlp->nlp_flag, data1); | |
fc6c12bc | 1768 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1769 | return ndlp; |
dea3101e | 1770 | } |
1771 | } | |
1772 | } | |
1773 | ||
1774 | if (order & NLP_SEARCH_REGLOGIN) { | |
1775 | list_for_each_entry_safe(ndlp, next_ndlp, | |
1776 | &phba->fc_reglogin_list, nlp_listp) { | |
1777 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1778 | ||
1779 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1780 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1781 | ((uint32_t) ndlp->nlp_type << 8) | | |
1782 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1783 | /* LOG change to REGLOGIN */ | |
1784 | /* FIND node DID reglogin */ | |
1785 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
dca9479b | 1786 | "%d:0901 FIND node DID reglogin" |
dea3101e | 1787 | " Data: x%p x%x x%x x%x\n", |
1788 | phba->brd_no, | |
1789 | ndlp, ndlp->nlp_DID, | |
1790 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1791 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1792 | return ndlp; |
dea3101e | 1793 | } |
1794 | } | |
1795 | } | |
1796 | ||
1797 | if (order & NLP_SEARCH_PRLI) { | |
1798 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list, | |
1799 | nlp_listp) { | |
1800 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1801 | ||
1802 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1803 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1804 | ((uint32_t) ndlp->nlp_type << 8) | | |
1805 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1806 | /* LOG change to PRLI */ | |
1807 | /* FIND node DID prli */ | |
1808 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
dca9479b | 1809 | "%d:0902 FIND node DID prli " |
dea3101e | 1810 | "Data: x%p x%x x%x x%x\n", |
1811 | phba->brd_no, | |
1812 | ndlp, ndlp->nlp_DID, | |
1813 | ndlp->nlp_flag, data1); | |
fc6c12bc | 1814 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1815 | return ndlp; |
dea3101e | 1816 | } |
1817 | } | |
1818 | } | |
1819 | ||
1820 | if (order & NLP_SEARCH_NPR) { | |
1821 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, | |
1822 | nlp_listp) { | |
1823 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1824 | ||
1825 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1826 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1827 | ((uint32_t) ndlp->nlp_type << 8) | | |
1828 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1829 | /* LOG change to NPR */ | |
1830 | /* FIND node DID npr */ | |
1831 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
dca9479b | 1832 | "%d:0903 FIND node DID npr " |
dea3101e | 1833 | "Data: x%p x%x x%x x%x\n", |
1834 | phba->brd_no, | |
1835 | ndlp, ndlp->nlp_DID, | |
1836 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1837 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1838 | return ndlp; |
dea3101e | 1839 | } |
1840 | } | |
1841 | } | |
1842 | ||
1843 | if (order & NLP_SEARCH_UNUSED) { | |
1844 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list, | |
1845 | nlp_listp) { | |
1846 | if (lpfc_matchdid(phba, ndlp, did)) { | |
1847 | ||
1848 | data1 = (((uint32_t) ndlp->nlp_state << 24) | | |
1849 | ((uint32_t) ndlp->nlp_xri << 16) | | |
1850 | ((uint32_t) ndlp->nlp_type << 8) | | |
1851 | ((uint32_t) ndlp->nlp_rpi & 0xff)); | |
1852 | /* LOG change to UNUSED */ | |
1853 | /* FIND node DID unused */ | |
1854 | lpfc_printf_log(phba, KERN_INFO, LOG_NODE, | |
dca9479b | 1855 | "%d:0905 FIND node DID unused " |
dea3101e | 1856 | "Data: x%p x%x x%x x%x\n", |
1857 | phba->brd_no, | |
1858 | ndlp, ndlp->nlp_DID, | |
1859 | ndlp->nlp_flag, data1); | |
66a9ed66 | 1860 | spin_unlock_irq(phba->host->host_lock); |
2fe165b6 | 1861 | return ndlp; |
dea3101e | 1862 | } |
1863 | } | |
1864 | } | |
1865 | ||
66a9ed66 JW |
1866 | spin_unlock_irq(phba->host->host_lock); |
1867 | ||
dea3101e | 1868 | /* FIND node did <did> NOT FOUND */ |
1869 | lpfc_printf_log(phba, | |
1870 | KERN_INFO, | |
1871 | LOG_NODE, | |
1872 | "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n", | |
1873 | phba->brd_no, did, order); | |
1874 | ||
1875 | /* no match found */ | |
1876 | return NULL; | |
1877 | } | |
1878 | ||
1879 | struct lpfc_nodelist * | |
1880 | lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did) | |
1881 | { | |
1882 | struct lpfc_nodelist *ndlp; | |
1883 | uint32_t flg; | |
1884 | ||
c9f8735b JW |
1885 | ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did); |
1886 | if (!ndlp) { | |
1887 | if ((phba->fc_flag & FC_RSCN_MODE) && | |
dea3101e | 1888 | ((lpfc_rscn_payload_check(phba, did) == 0))) |
1889 | return NULL; | |
1890 | ndlp = (struct lpfc_nodelist *) | |
1891 | mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
1892 | if (!ndlp) | |
1893 | return NULL; | |
1894 | lpfc_nlp_init(phba, ndlp, did); | |
1895 | ndlp->nlp_state = NLP_STE_NPR_NODE; | |
1896 | lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST); | |
1897 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
1898 | return ndlp; | |
1899 | } | |
c9f8735b | 1900 | if (phba->fc_flag & FC_RSCN_MODE) { |
dea3101e | 1901 | if (lpfc_rscn_payload_check(phba, did)) { |
1902 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
c9f8735b JW |
1903 | |
1904 | /* Since this node is marked for discovery, | |
1905 | * delay timeout is not needed. | |
1906 | */ | |
fdcebe28 JS |
1907 | if (ndlp->nlp_flag & NLP_DELAY_TMO) |
1908 | lpfc_cancel_retry_delay_tmo(phba, ndlp); | |
071fbd3d | 1909 | } else |
dea3101e | 1910 | ndlp = NULL; |
2fe165b6 | 1911 | } else { |
dea3101e | 1912 | flg = ndlp->nlp_flag & NLP_LIST_MASK; |
c9f8735b | 1913 | if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST)) |
dea3101e | 1914 | return NULL; |
dea3101e | 1915 | ndlp->nlp_state = NLP_STE_NPR_NODE; |
1916 | lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST); | |
1917 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
1918 | } | |
1919 | return ndlp; | |
1920 | } | |
1921 | ||
1922 | /* Build a list of nodes to discover based on the loopmap */ | |
1923 | void | |
1924 | lpfc_disc_list_loopmap(struct lpfc_hba * phba) | |
1925 | { | |
1926 | int j; | |
1927 | uint32_t alpa, index; | |
1928 | ||
1929 | if (phba->hba_state <= LPFC_LINK_DOWN) { | |
1930 | return; | |
1931 | } | |
1932 | if (phba->fc_topology != TOPOLOGY_LOOP) { | |
1933 | return; | |
1934 | } | |
1935 | ||
1936 | /* Check for loop map present or not */ | |
1937 | if (phba->alpa_map[0]) { | |
1938 | for (j = 1; j <= phba->alpa_map[0]; j++) { | |
1939 | alpa = phba->alpa_map[j]; | |
1940 | ||
1941 | if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) { | |
1942 | continue; | |
1943 | } | |
1944 | lpfc_setup_disc_node(phba, alpa); | |
1945 | } | |
1946 | } else { | |
1947 | /* No alpamap, so try all alpa's */ | |
1948 | for (j = 0; j < FC_MAXLOOP; j++) { | |
1949 | /* If cfg_scan_down is set, start from highest | |
1950 | * ALPA (0xef) to lowest (0x1). | |
1951 | */ | |
1952 | if (phba->cfg_scan_down) | |
1953 | index = j; | |
1954 | else | |
1955 | index = FC_MAXLOOP - j - 1; | |
1956 | alpa = lpfcAlpaArray[index]; | |
1957 | if ((phba->fc_myDID & 0xff) == alpa) { | |
1958 | continue; | |
1959 | } | |
1960 | ||
1961 | lpfc_setup_disc_node(phba, alpa); | |
1962 | } | |
1963 | } | |
1964 | return; | |
1965 | } | |
1966 | ||
1967 | /* Start Link up / RSCN discovery on NPR list */ | |
1968 | void | |
1969 | lpfc_disc_start(struct lpfc_hba * phba) | |
1970 | { | |
1971 | struct lpfc_sli *psli; | |
1972 | LPFC_MBOXQ_t *mbox; | |
1973 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
1974 | uint32_t did_changed, num_sent; | |
1975 | uint32_t clear_la_pending; | |
1976 | int rc; | |
1977 | ||
1978 | psli = &phba->sli; | |
1979 | ||
1980 | if (phba->hba_state <= LPFC_LINK_DOWN) { | |
1981 | return; | |
1982 | } | |
1983 | if (phba->hba_state == LPFC_CLEAR_LA) | |
1984 | clear_la_pending = 1; | |
1985 | else | |
1986 | clear_la_pending = 0; | |
1987 | ||
1988 | if (phba->hba_state < LPFC_HBA_READY) { | |
1989 | phba->hba_state = LPFC_DISC_AUTH; | |
1990 | } | |
1991 | lpfc_set_disctmo(phba); | |
1992 | ||
1993 | if (phba->fc_prevDID == phba->fc_myDID) { | |
1994 | did_changed = 0; | |
1995 | } else { | |
1996 | did_changed = 1; | |
1997 | } | |
1998 | phba->fc_prevDID = phba->fc_myDID; | |
1999 | phba->num_disc_nodes = 0; | |
2000 | ||
2001 | /* Start Discovery state <hba_state> */ | |
2002 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, | |
2003 | "%d:0202 Start Discovery hba state x%x " | |
2004 | "Data: x%x x%x x%x\n", | |
2005 | phba->brd_no, phba->hba_state, phba->fc_flag, | |
2006 | phba->fc_plogi_cnt, phba->fc_adisc_cnt); | |
2007 | ||
2008 | /* If our did changed, we MUST do PLOGI */ | |
2009 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, | |
2010 | nlp_listp) { | |
2011 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
2012 | if (did_changed) { | |
2013 | spin_lock_irq(phba->host->host_lock); | |
2014 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2015 | spin_unlock_irq(phba->host->host_lock); | |
2016 | } | |
2017 | } | |
2018 | } | |
2019 | ||
2020 | /* First do ADISCs - if any */ | |
2021 | num_sent = lpfc_els_disc_adisc(phba); | |
2022 | ||
2023 | if (num_sent) | |
2024 | return; | |
2025 | ||
2026 | if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) { | |
2027 | /* If we get here, there is nothing to ADISC */ | |
2028 | if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) { | |
2029 | phba->hba_state = LPFC_CLEAR_LA; | |
2030 | lpfc_clear_la(phba, mbox); | |
2031 | mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
2032 | rc = lpfc_sli_issue_mbox(phba, mbox, | |
2033 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
2034 | if (rc == MBX_NOT_FINISHED) { | |
2035 | mempool_free( mbox, phba->mbox_mem_pool); | |
2036 | lpfc_disc_flush_list(phba); | |
2037 | psli->ring[(psli->ip_ring)].flag &= | |
2038 | ~LPFC_STOP_IOCB_EVENT; | |
2039 | psli->ring[(psli->fcp_ring)].flag &= | |
2040 | ~LPFC_STOP_IOCB_EVENT; | |
2041 | psli->ring[(psli->next_ring)].flag &= | |
2042 | ~LPFC_STOP_IOCB_EVENT; | |
2043 | phba->hba_state = LPFC_HBA_READY; | |
2044 | } | |
2045 | } | |
2046 | } else { | |
2047 | /* Next do PLOGIs - if any */ | |
2048 | num_sent = lpfc_els_disc_plogi(phba); | |
2049 | ||
2050 | if (num_sent) | |
2051 | return; | |
2052 | ||
2053 | if (phba->fc_flag & FC_RSCN_MODE) { | |
2054 | /* Check to see if more RSCNs came in while we | |
2055 | * were processing this one. | |
2056 | */ | |
2057 | if ((phba->fc_rscn_id_cnt == 0) && | |
2058 | (!(phba->fc_flag & FC_RSCN_DISCOVERY))) { | |
2059 | spin_lock_irq(phba->host->host_lock); | |
2060 | phba->fc_flag &= ~FC_RSCN_MODE; | |
2061 | spin_unlock_irq(phba->host->host_lock); | |
2fe165b6 | 2062 | } else |
dea3101e | 2063 | lpfc_els_handle_rscn(phba); |
2064 | } | |
2065 | } | |
2066 | return; | |
2067 | } | |
2068 | ||
2069 | /* | |
2070 | * Ignore completion for all IOCBs on tx and txcmpl queue for ELS | |
2071 | * ring the match the sppecified nodelist. | |
2072 | */ | |
2073 | static void | |
2074 | lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) | |
2075 | { | |
2076 | struct lpfc_sli *psli; | |
2077 | IOCB_t *icmd; | |
2078 | struct lpfc_iocbq *iocb, *next_iocb; | |
2079 | struct lpfc_sli_ring *pring; | |
2080 | struct lpfc_dmabuf *mp; | |
2081 | ||
2082 | psli = &phba->sli; | |
2083 | pring = &psli->ring[LPFC_ELS_RING]; | |
2084 | ||
2085 | /* Error matching iocb on txq or txcmplq | |
2086 | * First check the txq. | |
2087 | */ | |
2088 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { | |
2089 | if (iocb->context1 != ndlp) { | |
2090 | continue; | |
2091 | } | |
2092 | icmd = &iocb->iocb; | |
2093 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || | |
2094 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { | |
2095 | ||
2096 | list_del(&iocb->list); | |
2097 | pring->txq_cnt--; | |
2098 | lpfc_els_free_iocb(phba, iocb); | |
2099 | } | |
2100 | } | |
2101 | ||
2102 | /* Next check the txcmplq */ | |
2103 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { | |
2104 | if (iocb->context1 != ndlp) { | |
2105 | continue; | |
2106 | } | |
2107 | icmd = &iocb->iocb; | |
2108 | if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || | |
2109 | (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { | |
2110 | ||
2111 | iocb->iocb_cmpl = NULL; | |
2112 | /* context2 = cmd, context2->next = rsp, context3 = | |
2113 | bpl */ | |
2114 | if (iocb->context2) { | |
2115 | /* Free the response IOCB before handling the | |
2116 | command. */ | |
2117 | ||
2118 | mp = (struct lpfc_dmabuf *) (iocb->context2); | |
2119 | mp = list_get_first(&mp->list, | |
2120 | struct lpfc_dmabuf, | |
2121 | list); | |
2122 | if (mp) { | |
2123 | /* Delay before releasing rsp buffer to | |
2124 | * give UNREG mbox a chance to take | |
2125 | * effect. | |
2126 | */ | |
2127 | list_add(&mp->list, | |
2128 | &phba->freebufList); | |
2129 | } | |
2130 | lpfc_mbuf_free(phba, | |
2131 | ((struct lpfc_dmabuf *) | |
2132 | iocb->context2)->virt, | |
2133 | ((struct lpfc_dmabuf *) | |
2134 | iocb->context2)->phys); | |
2135 | kfree(iocb->context2); | |
2136 | } | |
2137 | ||
2138 | if (iocb->context3) { | |
2139 | lpfc_mbuf_free(phba, | |
2140 | ((struct lpfc_dmabuf *) | |
2141 | iocb->context3)->virt, | |
2142 | ((struct lpfc_dmabuf *) | |
2143 | iocb->context3)->phys); | |
2144 | kfree(iocb->context3); | |
2145 | } | |
2146 | } | |
2147 | } | |
2148 | ||
2149 | return; | |
2150 | } | |
2151 | ||
2152 | void | |
2153 | lpfc_disc_flush_list(struct lpfc_hba * phba) | |
2154 | { | |
2155 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2156 | ||
2157 | if (phba->fc_plogi_cnt) { | |
2158 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list, | |
2159 | nlp_listp) { | |
2160 | lpfc_free_tx(phba, ndlp); | |
2161 | lpfc_nlp_remove(phba, ndlp); | |
2162 | } | |
2163 | } | |
2164 | if (phba->fc_adisc_cnt) { | |
2165 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list, | |
2166 | nlp_listp) { | |
2167 | lpfc_free_tx(phba, ndlp); | |
2168 | lpfc_nlp_remove(phba, ndlp); | |
2169 | } | |
2170 | } | |
2171 | return; | |
2172 | } | |
2173 | ||
2174 | /*****************************************************************************/ | |
2175 | /* | |
2176 | * NAME: lpfc_disc_timeout | |
2177 | * | |
2178 | * FUNCTION: Fibre Channel driver discovery timeout routine. | |
2179 | * | |
2180 | * EXECUTION ENVIRONMENT: interrupt only | |
2181 | * | |
2182 | * CALLED FROM: | |
2183 | * Timer function | |
2184 | * | |
2185 | * RETURNS: | |
2186 | * none | |
2187 | */ | |
2188 | /*****************************************************************************/ | |
2189 | void | |
2190 | lpfc_disc_timeout(unsigned long ptr) | |
2191 | { | |
2192 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
2193 | unsigned long flags = 0; | |
2194 | ||
2195 | if (unlikely(!phba)) | |
2196 | return; | |
2197 | ||
2198 | spin_lock_irqsave(phba->host->host_lock, flags); | |
2199 | if (!(phba->work_hba_events & WORKER_DISC_TMO)) { | |
2200 | phba->work_hba_events |= WORKER_DISC_TMO; | |
2201 | if (phba->work_wait) | |
2202 | wake_up(phba->work_wait); | |
2203 | } | |
2204 | spin_unlock_irqrestore(phba->host->host_lock, flags); | |
2205 | return; | |
2206 | } | |
2207 | ||
2208 | static void | |
2209 | lpfc_disc_timeout_handler(struct lpfc_hba *phba) | |
2210 | { | |
2211 | struct lpfc_sli *psli; | |
c9f8735b | 2212 | struct lpfc_nodelist *ndlp, *next_ndlp; |
dea3101e | 2213 | LPFC_MBOXQ_t *clearlambox, *initlinkmbox; |
2214 | int rc, clrlaerr = 0; | |
2215 | ||
2216 | if (unlikely(!phba)) | |
2217 | return; | |
2218 | ||
2219 | if (!(phba->fc_flag & FC_DISC_TMO)) | |
2220 | return; | |
2221 | ||
2222 | psli = &phba->sli; | |
2223 | ||
2224 | spin_lock_irq(phba->host->host_lock); | |
2225 | phba->fc_flag &= ~FC_DISC_TMO; | |
2226 | spin_unlock_irq(phba->host->host_lock); | |
2227 | ||
2228 | switch (phba->hba_state) { | |
2229 | ||
2230 | case LPFC_LOCAL_CFG_LINK: | |
2231 | /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */ | |
2232 | /* FAN timeout */ | |
2233 | lpfc_printf_log(phba, | |
2234 | KERN_WARNING, | |
2235 | LOG_DISCOVERY, | |
2236 | "%d:0221 FAN timeout\n", | |
2237 | phba->brd_no); | |
2238 | ||
c9f8735b JW |
2239 | /* Start discovery by sending FLOGI, clean up old rpis */ |
2240 | list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, | |
2241 | nlp_listp) { | |
2242 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2243 | /* Clean up the ndlp on Fabric connections */ | |
2244 | lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); | |
2fe165b6 | 2245 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
c9f8735b JW |
2246 | /* Fail outstanding IO now since device |
2247 | * is marked for PLOGI. | |
2248 | */ | |
2249 | lpfc_unreg_rpi(phba, ndlp); | |
2250 | } | |
2251 | } | |
dea3101e | 2252 | phba->hba_state = LPFC_FLOGI; |
2253 | lpfc_set_disctmo(phba); | |
2254 | lpfc_initial_flogi(phba); | |
2255 | break; | |
2256 | ||
2257 | case LPFC_FLOGI: | |
2258 | /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */ | |
2259 | /* Initial FLOGI timeout */ | |
2260 | lpfc_printf_log(phba, | |
2261 | KERN_ERR, | |
2262 | LOG_DISCOVERY, | |
2263 | "%d:0222 Initial FLOGI timeout\n", | |
2264 | phba->brd_no); | |
2265 | ||
2266 | /* Assume no Fabric and go on with discovery. | |
2267 | * Check for outstanding ELS FLOGI to abort. | |
2268 | */ | |
2269 | ||
2270 | /* FLOGI failed, so just use loop map to make discovery list */ | |
2271 | lpfc_disc_list_loopmap(phba); | |
2272 | ||
2273 | /* Start discovery */ | |
2274 | lpfc_disc_start(phba); | |
2275 | break; | |
2276 | ||
2277 | case LPFC_FABRIC_CFG_LINK: | |
2278 | /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for | |
2279 | NameServer login */ | |
2280 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
2281 | "%d:0223 Timeout while waiting for NameServer " | |
2282 | "login\n", phba->brd_no); | |
2283 | ||
2284 | /* Next look for NameServer ndlp */ | |
2285 | ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID); | |
2286 | if (ndlp) | |
2287 | lpfc_nlp_remove(phba, ndlp); | |
2288 | /* Start discovery */ | |
2289 | lpfc_disc_start(phba); | |
2290 | break; | |
2291 | ||
2292 | case LPFC_NS_QRY: | |
2293 | /* Check for wait for NameServer Rsp timeout */ | |
2294 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
2295 | "%d:0224 NameServer Query timeout " | |
2296 | "Data: x%x x%x\n", | |
2297 | phba->brd_no, | |
2298 | phba->fc_ns_retry, LPFC_MAX_NS_RETRY); | |
2299 | ||
2300 | ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, | |
2301 | NameServer_DID); | |
2302 | if (ndlp) { | |
2303 | if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) { | |
2304 | /* Try it one more time */ | |
2305 | rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT); | |
2306 | if (rc == 0) | |
2307 | break; | |
2308 | } | |
2309 | phba->fc_ns_retry = 0; | |
2310 | } | |
2311 | ||
2312 | /* Nothing to authenticate, so CLEAR_LA right now */ | |
2313 | clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2314 | if (!clearlambox) { | |
2315 | clrlaerr = 1; | |
2316 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
2317 | "%d:0226 Device Discovery " | |
2318 | "completion error\n", | |
2319 | phba->brd_no); | |
2320 | phba->hba_state = LPFC_HBA_ERROR; | |
2321 | break; | |
2322 | } | |
2323 | ||
2324 | phba->hba_state = LPFC_CLEAR_LA; | |
2325 | lpfc_clear_la(phba, clearlambox); | |
2326 | clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
2327 | rc = lpfc_sli_issue_mbox(phba, clearlambox, | |
2328 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
2329 | if (rc == MBX_NOT_FINISHED) { | |
2330 | mempool_free(clearlambox, phba->mbox_mem_pool); | |
2331 | clrlaerr = 1; | |
2332 | break; | |
2333 | } | |
2334 | ||
2335 | /* Setup and issue mailbox INITIALIZE LINK command */ | |
2336 | initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2337 | if (!initlinkmbox) { | |
2338 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
dca9479b | 2339 | "%d:0206 Device Discovery " |
dea3101e | 2340 | "completion error\n", |
2341 | phba->brd_no); | |
2342 | phba->hba_state = LPFC_HBA_ERROR; | |
2343 | break; | |
2344 | } | |
2345 | ||
2346 | lpfc_linkdown(phba); | |
2347 | lpfc_init_link(phba, initlinkmbox, phba->cfg_topology, | |
2348 | phba->cfg_link_speed); | |
2349 | initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0; | |
2350 | rc = lpfc_sli_issue_mbox(phba, initlinkmbox, | |
2351 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
2352 | if (rc == MBX_NOT_FINISHED) | |
2353 | mempool_free(initlinkmbox, phba->mbox_mem_pool); | |
2354 | ||
2355 | break; | |
2356 | ||
2357 | case LPFC_DISC_AUTH: | |
2358 | /* Node Authentication timeout */ | |
2359 | lpfc_printf_log(phba, | |
2360 | KERN_ERR, | |
2361 | LOG_DISCOVERY, | |
2362 | "%d:0227 Node Authentication timeout\n", | |
2363 | phba->brd_no); | |
2364 | lpfc_disc_flush_list(phba); | |
2365 | clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2366 | if (!clearlambox) { | |
2367 | clrlaerr = 1; | |
2368 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | |
dca9479b | 2369 | "%d:0207 Device Discovery " |
dea3101e | 2370 | "completion error\n", |
2371 | phba->brd_no); | |
2372 | phba->hba_state = LPFC_HBA_ERROR; | |
2373 | break; | |
2374 | } | |
2375 | phba->hba_state = LPFC_CLEAR_LA; | |
2376 | lpfc_clear_la(phba, clearlambox); | |
2377 | clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la; | |
2378 | rc = lpfc_sli_issue_mbox(phba, clearlambox, | |
2379 | (MBX_NOWAIT | MBX_STOP_IOCB)); | |
2380 | if (rc == MBX_NOT_FINISHED) { | |
2381 | mempool_free(clearlambox, phba->mbox_mem_pool); | |
2382 | clrlaerr = 1; | |
2383 | } | |
2384 | break; | |
2385 | ||
2386 | case LPFC_CLEAR_LA: | |
2387 | /* CLEAR LA timeout */ | |
2388 | lpfc_printf_log(phba, | |
2389 | KERN_ERR, | |
2390 | LOG_DISCOVERY, | |
2391 | "%d:0228 CLEAR LA timeout\n", | |
2392 | phba->brd_no); | |
2393 | clrlaerr = 1; | |
2394 | break; | |
2395 | ||
2396 | case LPFC_HBA_READY: | |
2397 | if (phba->fc_flag & FC_RSCN_MODE) { | |
2398 | lpfc_printf_log(phba, | |
2399 | KERN_ERR, | |
2400 | LOG_DISCOVERY, | |
2401 | "%d:0231 RSCN timeout Data: x%x x%x\n", | |
2402 | phba->brd_no, | |
2403 | phba->fc_ns_retry, LPFC_MAX_NS_RETRY); | |
2404 | ||
2405 | /* Cleanup any outstanding ELS commands */ | |
2406 | lpfc_els_flush_cmd(phba); | |
2407 | ||
2408 | lpfc_els_flush_rscn(phba); | |
2409 | lpfc_disc_flush_list(phba); | |
2410 | } | |
2411 | break; | |
2412 | } | |
2413 | ||
2414 | if (clrlaerr) { | |
2415 | lpfc_disc_flush_list(phba); | |
2416 | psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
2417 | psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
2418 | psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT; | |
2419 | phba->hba_state = LPFC_HBA_READY; | |
2420 | } | |
2421 | ||
2422 | return; | |
2423 | } | |
2424 | ||
dea3101e | 2425 | /* |
2426 | * This routine handles processing a NameServer REG_LOGIN mailbox | |
2427 | * command upon completion. It is setup in the LPFC_MBOXQ | |
2428 | * as the completion routine when the command is | |
2429 | * handed off to the SLI layer. | |
2430 | */ | |
2431 | void | |
2432 | lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
2433 | { | |
2434 | struct lpfc_sli *psli; | |
2435 | MAILBOX_t *mb; | |
2436 | struct lpfc_dmabuf *mp; | |
2437 | struct lpfc_nodelist *ndlp; | |
2438 | ||
2439 | psli = &phba->sli; | |
2440 | mb = &pmb->mb; | |
2441 | ||
2442 | ndlp = (struct lpfc_nodelist *) pmb->context2; | |
2443 | mp = (struct lpfc_dmabuf *) (pmb->context1); | |
2444 | ||
2445 | pmb->context1 = NULL; | |
2446 | ||
dea3101e | 2447 | ndlp->nlp_rpi = mb->un.varWords[0]; |
dea3101e | 2448 | ndlp->nlp_type |= NLP_FABRIC; |
2449 | ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; | |
2450 | lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST); | |
2451 | ||
2452 | /* Start issuing Fabric-Device Management Interface (FDMI) | |
2453 | * command to 0xfffffa (FDMI well known port) | |
2454 | */ | |
2455 | if (phba->cfg_fdmi_on == 1) { | |
2456 | lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA); | |
2457 | } else { | |
2458 | /* | |
2459 | * Delay issuing FDMI command if fdmi-on=2 | |
2460 | * (supporting RPA/hostnmae) | |
2461 | */ | |
2462 | mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60); | |
2463 | } | |
2464 | ||
2465 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2466 | kfree(mp); | |
2467 | mempool_free( pmb, phba->mbox_mem_pool); | |
2468 | ||
2469 | return; | |
2470 | } | |
2471 | ||
2472 | /* | |
21568f53 JSEC |
2473 | * This routine looks up the ndlp lists |
2474 | * for the given RPI. If rpi found | |
dea3101e | 2475 | * it return the node list pointer |
21568f53 | 2476 | * else return NULL. |
dea3101e | 2477 | */ |
2478 | struct lpfc_nodelist * | |
2479 | lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi) | |
2480 | { | |
21568f53 JSEC |
2481 | struct lpfc_nodelist *ndlp; |
2482 | struct list_head * lists[]={&phba->fc_nlpunmap_list, | |
2483 | &phba->fc_nlpmap_list, | |
2484 | &phba->fc_plogi_list, | |
2485 | &phba->fc_adisc_list, | |
2486 | &phba->fc_reglogin_list}; | |
2487 | int i; | |
dea3101e | 2488 | |
66a9ed66 | 2489 | spin_lock_irq(phba->host->host_lock); |
21568f53 JSEC |
2490 | for (i = 0; i < ARRAY_SIZE(lists); i++ ) |
2491 | list_for_each_entry(ndlp, lists[i], nlp_listp) | |
66a9ed66 JW |
2492 | if (ndlp->nlp_rpi == rpi) { |
2493 | spin_unlock_irq(phba->host->host_lock); | |
2fe165b6 | 2494 | return ndlp; |
66a9ed66 JW |
2495 | } |
2496 | spin_unlock_irq(phba->host->host_lock); | |
21568f53 | 2497 | return NULL; |
dea3101e | 2498 | } |
2499 | ||
488d1469 JS |
2500 | /* |
2501 | * This routine looks up the ndlp lists | |
2502 | * for the given WWPN. If WWPN found | |
2503 | * it return the node list pointer | |
2504 | * else return NULL. | |
2505 | */ | |
2506 | struct lpfc_nodelist * | |
2507 | lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order, | |
2508 | struct lpfc_name * wwpn) | |
2509 | { | |
2510 | struct lpfc_nodelist *ndlp; | |
2511 | struct list_head * lists[]={&phba->fc_nlpunmap_list, | |
2512 | &phba->fc_nlpmap_list, | |
2513 | &phba->fc_npr_list, | |
2514 | &phba->fc_plogi_list, | |
2515 | &phba->fc_adisc_list, | |
2516 | &phba->fc_reglogin_list, | |
2517 | &phba->fc_prli_list}; | |
2518 | uint32_t search[]={NLP_SEARCH_UNMAPPED, | |
2519 | NLP_SEARCH_MAPPED, | |
2520 | NLP_SEARCH_NPR, | |
2521 | NLP_SEARCH_PLOGI, | |
2522 | NLP_SEARCH_ADISC, | |
2523 | NLP_SEARCH_REGLOGIN, | |
2524 | NLP_SEARCH_PRLI}; | |
2525 | int i; | |
2526 | ||
2527 | spin_lock_irq(phba->host->host_lock); | |
2528 | for (i = 0; i < ARRAY_SIZE(lists); i++ ) { | |
2529 | if (!(order & search[i])) | |
2530 | continue; | |
2531 | list_for_each_entry(ndlp, lists[i], nlp_listp) { | |
2532 | if (memcmp(&ndlp->nlp_portname, wwpn, | |
2533 | sizeof(struct lpfc_name)) == 0) { | |
2534 | spin_unlock_irq(phba->host->host_lock); | |
2535 | return ndlp; | |
2536 | } | |
2537 | } | |
2538 | } | |
2539 | spin_unlock_irq(phba->host->host_lock); | |
2540 | return NULL; | |
2541 | } | |
2542 | ||
dea3101e | 2543 | void |
2544 | lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, | |
2545 | uint32_t did) | |
2546 | { | |
2547 | memset(ndlp, 0, sizeof (struct lpfc_nodelist)); | |
dea3101e | 2548 | INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); |
dea3101e | 2549 | init_timer(&ndlp->nlp_delayfunc); |
2550 | ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; | |
2551 | ndlp->nlp_delayfunc.data = (unsigned long)ndlp; | |
2552 | ndlp->nlp_DID = did; | |
2553 | ndlp->nlp_phba = phba; | |
2554 | ndlp->nlp_sid = NLP_NO_SID; | |
2555 | return; | |
2556 | } |