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