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