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