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