]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
9413afff | 4 | * Copyright (C) 2004-2007 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
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 JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/delay.h> | |
24 | #include <linux/dma-mapping.h> | |
25 | #include <linux/idr.h> | |
26 | #include <linux/interrupt.h> | |
27 | #include <linux/kthread.h> | |
28 | #include <linux/pci.h> | |
29 | #include <linux/spinlock.h> | |
92d7f7b0 | 30 | #include <linux/ctype.h> |
dea3101e | 31 | |
91886523 | 32 | #include <scsi/scsi.h> |
dea3101e JB |
33 | #include <scsi/scsi_device.h> |
34 | #include <scsi/scsi_host.h> | |
35 | #include <scsi/scsi_transport_fc.h> | |
36 | ||
37 | #include "lpfc_hw.h" | |
38 | #include "lpfc_sli.h" | |
39 | #include "lpfc_disc.h" | |
40 | #include "lpfc_scsi.h" | |
41 | #include "lpfc.h" | |
42 | #include "lpfc_logmsg.h" | |
43 | #include "lpfc_crtn.h" | |
92d7f7b0 | 44 | #include "lpfc_vport.h" |
dea3101e JB |
45 | #include "lpfc_version.h" |
46 | ||
74b72a59 | 47 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); |
dea3101e JB |
48 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
49 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
50 | ||
51 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 52 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
53 | static DEFINE_IDR(lpfc_hba_index); |
54 | ||
55 | /************************************************************************/ | |
56 | /* */ | |
57 | /* lpfc_config_port_prep */ | |
58 | /* This routine will do LPFC initialization prior to the */ | |
59 | /* CONFIG_PORT mailbox command. This will be initialized */ | |
60 | /* as a SLI layer callback routine. */ | |
61 | /* This routine returns 0 on success or -ERESTART if it wants */ | |
62 | /* the SLI layer to reset the HBA and try again. Any */ | |
63 | /* other return value indicates an error. */ | |
64 | /* */ | |
65 | /************************************************************************/ | |
66 | int | |
2e0fef85 | 67 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
68 | { |
69 | lpfc_vpd_t *vp = &phba->vpd; | |
70 | int i = 0, rc; | |
71 | LPFC_MBOXQ_t *pmb; | |
72 | MAILBOX_t *mb; | |
73 | char *lpfc_vpd_data = NULL; | |
74 | uint16_t offset = 0; | |
75 | static char licensed[56] = | |
76 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 77 | static int init_key = 1; |
dea3101e JB |
78 | |
79 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
80 | if (!pmb) { | |
2e0fef85 | 81 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
82 | return -ENOMEM; |
83 | } | |
84 | ||
85 | mb = &pmb->mb; | |
2e0fef85 | 86 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
87 | |
88 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
89 | if (init_key) { |
90 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 91 | |
65a29c16 JS |
92 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
93 | *ptext = cpu_to_be32(*ptext); | |
94 | init_key = 0; | |
95 | } | |
dea3101e JB |
96 | |
97 | lpfc_read_nv(phba, pmb); | |
98 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
99 | sizeof (mb->un.varRDnvp.rsvd3)); | |
100 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
101 | sizeof (licensed)); | |
102 | ||
103 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
104 | ||
105 | if (rc != MBX_SUCCESS) { | |
ed957684 | 106 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 107 | "0324 Config Port initialization " |
dea3101e JB |
108 | "error, mbxCmd x%x READ_NVPARM, " |
109 | "mbxStatus x%x\n", | |
dea3101e JB |
110 | mb->mbxCommand, mb->mbxStatus); |
111 | mempool_free(pmb, phba->mbox_mem_pool); | |
112 | return -ERESTART; | |
113 | } | |
114 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
115 | sizeof(phba->wwnn)); |
116 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
117 | sizeof(phba->wwpn)); | |
dea3101e JB |
118 | } |
119 | ||
92d7f7b0 JS |
120 | phba->sli3_options = 0x0; |
121 | ||
dea3101e JB |
122 | /* Setup and issue mailbox READ REV command */ |
123 | lpfc_read_rev(phba, pmb); | |
124 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
125 | if (rc != MBX_SUCCESS) { | |
ed957684 | 126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 127 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 128 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
129 | mb->mbxCommand, mb->mbxStatus); |
130 | mempool_free( pmb, phba->mbox_mem_pool); | |
131 | return -ERESTART; | |
132 | } | |
133 | ||
92d7f7b0 | 134 | |
1de933f3 JSEC |
135 | /* |
136 | * The value of rr must be 1 since the driver set the cv field to 1. | |
137 | * This setting requires the FW to set all revision fields. | |
dea3101e | 138 | */ |
1de933f3 | 139 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 140 | vp->rev.rBit = 0; |
1de933f3 | 141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
142 | "0440 Adapter failed to init, READ_REV has " |
143 | "missing revision information.\n"); | |
dea3101e JB |
144 | mempool_free(pmb, phba->mbox_mem_pool); |
145 | return -ERESTART; | |
dea3101e JB |
146 | } |
147 | ||
ed957684 JS |
148 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) |
149 | return -EINVAL; | |
150 | ||
dea3101e | 151 | /* Save information as VPD data */ |
1de933f3 | 152 | vp->rev.rBit = 1; |
92d7f7b0 | 153 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
154 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
155 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
156 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
157 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
158 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
159 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
160 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
161 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
162 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
163 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
164 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
165 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
166 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
167 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
168 | ||
92d7f7b0 JS |
169 | /* If the sli feature level is less then 9, we must |
170 | * tear down all RPIs and VPIs on link down if NPIV | |
171 | * is enabled. | |
172 | */ | |
173 | if (vp->rev.feaLevelHigh < 9) | |
174 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
175 | ||
dea3101e JB |
176 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
177 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
178 | sizeof (phba->RandomData)); | |
179 | ||
dea3101e JB |
180 | /* Get adapter VPD information */ |
181 | pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL); | |
182 | if (!pmb->context2) | |
183 | goto out_free_mbox; | |
184 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); | |
185 | if (!lpfc_vpd_data) | |
186 | goto out_free_context2; | |
187 | ||
188 | do { | |
189 | lpfc_dump_mem(phba, pmb, offset); | |
190 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
191 | ||
192 | if (rc != MBX_SUCCESS) { | |
193 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 194 | "0441 VPD not present on adapter, " |
dea3101e | 195 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 196 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 197 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 198 | } |
74b72a59 JW |
199 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
200 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
dea3101e | 201 | lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset, |
92d7f7b0 | 202 | mb->un.varDmp.word_cnt); |
dea3101e | 203 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
204 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
205 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
206 | |
207 | kfree(lpfc_vpd_data); | |
208 | out_free_context2: | |
209 | kfree(pmb->context2); | |
210 | out_free_mbox: | |
211 | mempool_free(pmb, phba->mbox_mem_pool); | |
212 | return 0; | |
213 | } | |
214 | ||
57127f15 JS |
215 | /* Completion handler for config async event mailbox command. */ |
216 | static void | |
217 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
218 | { | |
219 | if (pmboxq->mb.mbxStatus == MBX_SUCCESS) | |
220 | phba->temp_sensor_support = 1; | |
221 | else | |
222 | phba->temp_sensor_support = 0; | |
223 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
224 | return; | |
225 | } | |
226 | ||
dea3101e JB |
227 | /************************************************************************/ |
228 | /* */ | |
229 | /* lpfc_config_port_post */ | |
230 | /* This routine will do LPFC initialization after the */ | |
231 | /* CONFIG_PORT mailbox command. This will be initialized */ | |
232 | /* as a SLI layer callback routine. */ | |
233 | /* This routine returns 0 on success. Any other return value */ | |
234 | /* indicates an error. */ | |
235 | /* */ | |
236 | /************************************************************************/ | |
237 | int | |
2e0fef85 | 238 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 239 | { |
2e0fef85 | 240 | struct lpfc_vport *vport = phba->pport; |
dea3101e JB |
241 | LPFC_MBOXQ_t *pmb; |
242 | MAILBOX_t *mb; | |
243 | struct lpfc_dmabuf *mp; | |
244 | struct lpfc_sli *psli = &phba->sli; | |
245 | uint32_t status, timeout; | |
2e0fef85 JS |
246 | int i, j; |
247 | int rc; | |
dea3101e | 248 | |
7af67051 JS |
249 | spin_lock_irq(&phba->hbalock); |
250 | /* | |
251 | * If the Config port completed correctly the HBA is not | |
252 | * over heated any more. | |
253 | */ | |
254 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
255 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
256 | spin_unlock_irq(&phba->hbalock); | |
257 | ||
dea3101e JB |
258 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
259 | if (!pmb) { | |
2e0fef85 | 260 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
261 | return -ENOMEM; |
262 | } | |
263 | mb = &pmb->mb; | |
264 | ||
dea3101e | 265 | /* Get login parameters for NID. */ |
92d7f7b0 | 266 | lpfc_read_sparam(phba, pmb, 0); |
ed957684 | 267 | pmb->vport = vport; |
dea3101e | 268 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 269 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 270 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 271 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 272 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 273 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
274 | mp = (struct lpfc_dmabuf *) pmb->context1; |
275 | mempool_free( pmb, phba->mbox_mem_pool); | |
276 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
277 | kfree(mp); | |
278 | return -EIO; | |
279 | } | |
280 | ||
281 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
282 | ||
2e0fef85 | 283 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
284 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
285 | kfree(mp); | |
286 | pmb->context1 = NULL; | |
287 | ||
a12e07bc | 288 | if (phba->cfg_soft_wwnn) |
2e0fef85 JS |
289 | u64_to_wwn(phba->cfg_soft_wwnn, |
290 | vport->fc_sparam.nodeName.u.wwn); | |
c3f28afa | 291 | if (phba->cfg_soft_wwpn) |
2e0fef85 JS |
292 | u64_to_wwn(phba->cfg_soft_wwpn, |
293 | vport->fc_sparam.portName.u.wwn); | |
294 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
dea3101e | 295 | sizeof (struct lpfc_name)); |
2e0fef85 | 296 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
dea3101e JB |
297 | sizeof (struct lpfc_name)); |
298 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ | |
299 | /* This should be consolidated into parse_vpd ? - mr */ | |
300 | if (phba->SerialNumber[0] == 0) { | |
301 | uint8_t *outptr; | |
302 | ||
2e0fef85 | 303 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
304 | for (i = 0; i < 12; i++) { |
305 | status = *outptr++; | |
306 | j = ((status & 0xf0) >> 4); | |
307 | if (j <= 9) | |
308 | phba->SerialNumber[i] = | |
309 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
310 | else | |
311 | phba->SerialNumber[i] = | |
312 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
313 | i++; | |
314 | j = (status & 0xf); | |
315 | if (j <= 9) | |
316 | phba->SerialNumber[i] = | |
317 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
318 | else | |
319 | phba->SerialNumber[i] = | |
320 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
321 | } | |
322 | } | |
323 | ||
dea3101e | 324 | lpfc_read_config(phba, pmb); |
ed957684 | 325 | pmb->vport = vport; |
dea3101e | 326 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 327 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 328 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 329 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 330 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 331 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
332 | mempool_free( pmb, phba->mbox_mem_pool); |
333 | return -EIO; | |
334 | } | |
335 | ||
336 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
337 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
338 | phba->cfg_hba_queue_depth = | |
339 | mb->un.varRdConfig.max_xri + 1; | |
340 | ||
341 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
342 | |
343 | /* Get the default values for Model Name and Description */ | |
344 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
345 | ||
346 | if ((phba->cfg_link_speed > LINK_SPEED_10G) | |
347 | || ((phba->cfg_link_speed == LINK_SPEED_1G) | |
348 | && !(phba->lmt & LMT_1Gb)) | |
349 | || ((phba->cfg_link_speed == LINK_SPEED_2G) | |
350 | && !(phba->lmt & LMT_2Gb)) | |
351 | || ((phba->cfg_link_speed == LINK_SPEED_4G) | |
352 | && !(phba->lmt & LMT_4Gb)) | |
353 | || ((phba->cfg_link_speed == LINK_SPEED_8G) | |
354 | && !(phba->lmt & LMT_8Gb)) | |
355 | || ((phba->cfg_link_speed == LINK_SPEED_10G) | |
356 | && !(phba->lmt & LMT_10Gb))) { | |
357 | /* Reset link speed to auto */ | |
ed957684 | 358 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
e8b62011 | 359 | "1302 Invalid speed for this board: " |
dea3101e | 360 | "Reset link speed to auto: x%x\n", |
dea3101e JB |
361 | phba->cfg_link_speed); |
362 | phba->cfg_link_speed = LINK_SPEED_AUTO; | |
363 | } | |
364 | ||
2e0fef85 | 365 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 366 | |
0b727fea | 367 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
a4bc3379 JS |
368 | if (psli->ring[psli->extra_ring].cmdringaddr) |
369 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e JB |
370 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
371 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
372 | if (psli->ring[psli->next_ring].cmdringaddr) | |
373 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
374 | ||
375 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
376 | if (phba->sli_rev != 3) |
377 | lpfc_post_rcv_buf(phba); | |
dea3101e JB |
378 | |
379 | /* Enable appropriate host interrupts */ | |
2e0fef85 | 380 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
381 | status = readl(phba->HCregaddr); |
382 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; | |
383 | if (psli->num_rings > 0) | |
384 | status |= HC_R0INT_ENA; | |
385 | if (psli->num_rings > 1) | |
386 | status |= HC_R1INT_ENA; | |
387 | if (psli->num_rings > 2) | |
388 | status |= HC_R2INT_ENA; | |
389 | if (psli->num_rings > 3) | |
390 | status |= HC_R3INT_ENA; | |
391 | ||
875fbdfe JSEC |
392 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
393 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
394 | status &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
395 | ||
dea3101e JB |
396 | writel(status, phba->HCregaddr); |
397 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 398 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
399 | |
400 | /* | |
401 | * Setup the ring 0 (els) timeout handler | |
402 | */ | |
403 | timeout = phba->fc_ratov << 1; | |
2e0fef85 | 404 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
858c9f6c JS |
405 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
406 | phba->hb_outstanding = 0; | |
407 | phba->last_completion_time = jiffies; | |
dea3101e JB |
408 | |
409 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); | |
410 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
ed957684 | 411 | pmb->vport = vport; |
8aee918a | 412 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
5b8bd0c9 | 413 | lpfc_set_loopback_flag(phba); |
8aee918a | 414 | if (rc != MBX_SUCCESS) { |
ed957684 | 415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 416 | "0454 Adapter failed to init, mbxCmd x%x " |
dea3101e | 417 | "INIT_LINK, mbxStatus x%x\n", |
dea3101e JB |
418 | mb->mbxCommand, mb->mbxStatus); |
419 | ||
420 | /* Clear all interrupt enable conditions */ | |
421 | writel(0, phba->HCregaddr); | |
422 | readl(phba->HCregaddr); /* flush */ | |
423 | /* Clear all pending interrupts */ | |
424 | writel(0xffffffff, phba->HAregaddr); | |
425 | readl(phba->HAregaddr); /* flush */ | |
426 | ||
2e0fef85 | 427 | phba->link_state = LPFC_HBA_ERROR; |
8aee918a JS |
428 | if (rc != MBX_BUSY) |
429 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
430 | return -EIO; |
431 | } | |
432 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 JS |
433 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
434 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); | |
435 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
436 | pmb->vport = phba->pport; | |
437 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 438 | |
57127f15 JS |
439 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
440 | lpfc_printf_log(phba, | |
441 | KERN_ERR, | |
442 | LOG_INIT, | |
443 | "0456 Adapter failed to issue " | |
444 | "ASYNCEVT_ENABLE mbox status x%x \n.", | |
445 | rc); | |
446 | mempool_free(pmb, phba->mbox_mem_pool); | |
447 | } | |
ce8b3ce5 JS |
448 | return (0); |
449 | } | |
450 | ||
dea3101e JB |
451 | /************************************************************************/ |
452 | /* */ | |
453 | /* lpfc_hba_down_prep */ | |
454 | /* This routine will do LPFC uninitialization before the */ | |
455 | /* HBA is reset when bringing down the SLI Layer. This will be */ | |
456 | /* initialized as a SLI layer callback routine. */ | |
457 | /* This routine returns 0 on success. Any other return value */ | |
458 | /* indicates an error. */ | |
459 | /* */ | |
460 | /************************************************************************/ | |
461 | int | |
2e0fef85 | 462 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e JB |
463 | { |
464 | /* Disable interrupts */ | |
465 | writel(0, phba->HCregaddr); | |
466 | readl(phba->HCregaddr); /* flush */ | |
467 | ||
51ef4c26 | 468 | lpfc_cleanup_discovery_resources(phba->pport); |
2e0fef85 | 469 | return 0; |
dea3101e JB |
470 | } |
471 | ||
41415862 JW |
472 | /************************************************************************/ |
473 | /* */ | |
474 | /* lpfc_hba_down_post */ | |
475 | /* This routine will do uninitialization after the HBA is reset */ | |
476 | /* when bringing down the SLI Layer. */ | |
477 | /* This routine returns 0 on success. Any other return value */ | |
478 | /* indicates an error. */ | |
479 | /* */ | |
480 | /************************************************************************/ | |
481 | int | |
2e0fef85 | 482 | lpfc_hba_down_post(struct lpfc_hba *phba) |
41415862 JW |
483 | { |
484 | struct lpfc_sli *psli = &phba->sli; | |
485 | struct lpfc_sli_ring *pring; | |
486 | struct lpfc_dmabuf *mp, *next_mp; | |
487 | int i; | |
488 | ||
92d7f7b0 JS |
489 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
490 | lpfc_sli_hbqbuf_free_all(phba); | |
491 | else { | |
492 | /* Cleanup preposted buffers on the ELS ring */ | |
493 | pring = &psli->ring[LPFC_ELS_RING]; | |
494 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
495 | list_del(&mp->list); | |
496 | pring->postbufq_cnt--; | |
497 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
498 | kfree(mp); | |
499 | } | |
41415862 JW |
500 | } |
501 | ||
502 | for (i = 0; i < psli->num_rings; i++) { | |
503 | pring = &psli->ring[i]; | |
504 | lpfc_sli_abort_iocb_ring(phba, pring); | |
505 | } | |
506 | ||
507 | return 0; | |
508 | } | |
509 | ||
858c9f6c JS |
510 | /* HBA heart beat timeout handler */ |
511 | void | |
512 | lpfc_hb_timeout(unsigned long ptr) | |
513 | { | |
514 | struct lpfc_hba *phba; | |
515 | unsigned long iflag; | |
516 | ||
517 | phba = (struct lpfc_hba *)ptr; | |
518 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
519 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) | |
520 | phba->pport->work_port_events |= WORKER_HB_TMO; | |
521 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
522 | ||
523 | if (phba->work_wait) | |
524 | wake_up(phba->work_wait); | |
525 | return; | |
526 | } | |
527 | ||
528 | static void | |
529 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
530 | { | |
531 | unsigned long drvr_flag; | |
532 | ||
533 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
534 | phba->hb_outstanding = 0; | |
535 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
536 | ||
537 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
538 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
539 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 540 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
541 | mod_timer(&phba->hb_tmofunc, |
542 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
543 | return; | |
544 | } | |
545 | ||
546 | void | |
547 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
548 | { | |
549 | LPFC_MBOXQ_t *pmboxq; | |
550 | int retval; | |
551 | struct lpfc_sli *psli = &phba->sli; | |
552 | ||
553 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
51ef4c26 | 554 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
555 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
556 | return; | |
557 | ||
558 | spin_lock_irq(&phba->pport->work_port_lock); | |
559 | /* If the timer is already canceled do nothing */ | |
560 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { | |
561 | spin_unlock_irq(&phba->pport->work_port_lock); | |
562 | return; | |
563 | } | |
564 | ||
565 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
566 | jiffies)) { | |
567 | spin_unlock_irq(&phba->pport->work_port_lock); | |
568 | if (!phba->hb_outstanding) | |
569 | mod_timer(&phba->hb_tmofunc, | |
570 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
571 | else | |
572 | mod_timer(&phba->hb_tmofunc, | |
573 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
574 | return; | |
575 | } | |
576 | spin_unlock_irq(&phba->pport->work_port_lock); | |
577 | ||
578 | /* If there is no heart beat outstanding, issue a heartbeat command */ | |
579 | if (!phba->hb_outstanding) { | |
580 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
581 | if (!pmboxq) { | |
582 | mod_timer(&phba->hb_tmofunc, | |
583 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
584 | return; | |
585 | } | |
586 | ||
587 | lpfc_heart_beat(phba, pmboxq); | |
588 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
589 | pmboxq->vport = phba->pport; | |
590 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
591 | ||
592 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { | |
593 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
594 | mod_timer(&phba->hb_tmofunc, | |
595 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
596 | return; | |
597 | } | |
598 | mod_timer(&phba->hb_tmofunc, | |
599 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
600 | phba->hb_outstanding = 1; | |
601 | return; | |
602 | } else { | |
603 | /* | |
604 | * If heart beat timeout called with hb_outstanding set we | |
605 | * need to take the HBA offline. | |
606 | */ | |
607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
608 | "0459 Adapter heartbeat failure, taking " |
609 | "this port offline.\n"); | |
858c9f6c JS |
610 | |
611 | spin_lock_irq(&phba->hbalock); | |
612 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | |
613 | spin_unlock_irq(&phba->hbalock); | |
614 | ||
615 | lpfc_offline_prep(phba); | |
616 | lpfc_offline(phba); | |
617 | lpfc_unblock_mgmt_io(phba); | |
618 | phba->link_state = LPFC_HBA_ERROR; | |
619 | lpfc_hba_down_post(phba); | |
620 | } | |
621 | } | |
622 | ||
dea3101e JB |
623 | /************************************************************************/ |
624 | /* */ | |
625 | /* lpfc_handle_eratt */ | |
626 | /* This routine will handle processing a Host Attention */ | |
627 | /* Error Status event. This will be initialized */ | |
628 | /* as a SLI layer callback routine. */ | |
629 | /* */ | |
630 | /************************************************************************/ | |
631 | void | |
2e0fef85 | 632 | lpfc_handle_eratt(struct lpfc_hba *phba) |
dea3101e | 633 | { |
2e0fef85 | 634 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 635 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 636 | struct lpfc_sli_ring *pring; |
549e55cd | 637 | struct lpfc_vport **vports; |
d2873e4c | 638 | uint32_t event_data; |
57127f15 JS |
639 | unsigned long temperature; |
640 | struct temp_event temp_event_data; | |
92d7f7b0 | 641 | struct Scsi_Host *shost; |
549e55cd | 642 | int i; |
2e0fef85 | 643 | |
8d63f375 LV |
644 | /* If the pci channel is offline, ignore possible errors, |
645 | * since we cannot communicate with the pci card anyway. */ | |
646 | if (pci_channel_offline(phba->pcidev)) | |
647 | return; | |
dea3101e | 648 | |
f5603511 JS |
649 | if (phba->work_hs & HS_FFER6 || |
650 | phba->work_hs & HS_FFER5) { | |
dea3101e JB |
651 | /* Re-establishing Link */ |
652 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
e8b62011 | 653 | "1301 Re-establishing Link " |
dea3101e | 654 | "Data: x%x x%x x%x\n", |
e8b62011 | 655 | phba->work_hs, |
dea3101e | 656 | phba->work_status[0], phba->work_status[1]); |
549e55cd JS |
657 | vports = lpfc_create_vport_work_array(phba); |
658 | if (vports != NULL) | |
659 | for(i = 0; | |
660 | i < LPFC_MAX_VPORTS && vports[i] != NULL; | |
661 | i++){ | |
662 | shost = lpfc_shost_from_vport(vports[i]); | |
663 | spin_lock_irq(shost->host_lock); | |
664 | vports[i]->fc_flag |= FC_ESTABLISH_LINK; | |
665 | spin_unlock_irq(shost->host_lock); | |
666 | } | |
667 | lpfc_destroy_vport_work_array(vports); | |
92d7f7b0 | 668 | spin_lock_irq(&phba->hbalock); |
9290831f | 669 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 670 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
671 | |
672 | /* | |
673 | * Firmware stops when it triggled erratt with HS_FFER6. | |
674 | * That could cause the I/Os dropped by the firmware. | |
675 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
676 | * retry it after re-establishing link. | |
677 | */ | |
678 | pring = &psli->ring[psli->fcp_ring]; | |
679 | lpfc_sli_abort_iocb_ring(phba, pring); | |
680 | ||
681 | ||
682 | /* | |
683 | * There was a firmware error. Take the hba offline and then | |
684 | * attempt to restart it. | |
685 | */ | |
46fa311e | 686 | lpfc_offline_prep(phba); |
dea3101e | 687 | lpfc_offline(phba); |
41415862 | 688 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
689 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
690 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); | |
46fa311e | 691 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
692 | return; |
693 | } | |
46fa311e | 694 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
695 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
696 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
697 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
698 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
699 | temp_event_data.data = (uint32_t)temperature; | |
700 | ||
701 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
702 | "0459 Adapter maximum temperature exceeded " | |
703 | "(%ld), taking this port offline " | |
704 | "Data: x%x x%x x%x\n", | |
705 | temperature, phba->work_hs, | |
706 | phba->work_status[0], phba->work_status[1]); | |
707 | ||
708 | shost = lpfc_shost_from_vport(phba->pport); | |
709 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
710 | sizeof(temp_event_data), | |
711 | (char *) &temp_event_data, | |
712 | SCSI_NL_VID_TYPE_PCI | |
713 | | PCI_VENDOR_ID_EMULEX); | |
714 | ||
7af67051 | 715 | spin_lock_irq(&phba->hbalock); |
57127f15 | 716 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
7af67051 JS |
717 | phba->over_temp_state = HBA_OVER_TEMP; |
718 | spin_unlock_irq(&phba->hbalock); | |
57127f15 JS |
719 | lpfc_offline_prep(phba); |
720 | lpfc_offline(phba); | |
721 | lpfc_unblock_mgmt_io(phba); | |
722 | phba->link_state = LPFC_HBA_ERROR; | |
723 | lpfc_hba_down_post(phba); | |
724 | ||
dea3101e JB |
725 | } else { |
726 | /* The if clause above forces this code path when the status | |
727 | * failure is a value other than FFER6. Do not call the offline | |
728 | * twice. This is the adapter hardware error path. | |
729 | */ | |
730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 731 | "0457 Adapter Hardware Error " |
dea3101e | 732 | "Data: x%x x%x x%x\n", |
e8b62011 | 733 | phba->work_hs, |
dea3101e JB |
734 | phba->work_status[0], phba->work_status[1]); |
735 | ||
d2873e4c | 736 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 737 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 738 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
739 | sizeof(event_data), (char *) &event_data, |
740 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
741 | ||
92d7f7b0 | 742 | spin_lock_irq(&phba->hbalock); |
9290831f | 743 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 744 | spin_unlock_irq(&phba->hbalock); |
46fa311e | 745 | lpfc_offline_prep(phba); |
dea3101e | 746 | lpfc_offline(phba); |
46fa311e | 747 | lpfc_unblock_mgmt_io(phba); |
2e0fef85 | 748 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 749 | lpfc_hba_down_post(phba); |
dea3101e JB |
750 | } |
751 | } | |
752 | ||
753 | /************************************************************************/ | |
754 | /* */ | |
755 | /* lpfc_handle_latt */ | |
756 | /* This routine will handle processing a Host Attention */ | |
757 | /* Link Status event. This will be initialized */ | |
758 | /* as a SLI layer callback routine. */ | |
759 | /* */ | |
760 | /************************************************************************/ | |
761 | void | |
2e0fef85 | 762 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 763 | { |
2e0fef85 JS |
764 | struct lpfc_vport *vport = phba->pport; |
765 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
766 | LPFC_MBOXQ_t *pmb; |
767 | volatile uint32_t control; | |
768 | struct lpfc_dmabuf *mp; | |
769 | int rc = -ENOMEM; | |
770 | ||
771 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
772 | if (!pmb) | |
773 | goto lpfc_handle_latt_err_exit; | |
774 | ||
775 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
776 | if (!mp) | |
777 | goto lpfc_handle_latt_free_pmb; | |
778 | ||
779 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
780 | if (!mp->virt) | |
781 | goto lpfc_handle_latt_free_mp; | |
782 | ||
783 | rc = -EIO; | |
784 | ||
6281bfe0 | 785 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 786 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
787 | |
788 | psli->slistat.link_event++; | |
789 | lpfc_read_la(phba, pmb, mp); | |
790 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; | |
2e0fef85 | 791 | pmb->vport = vport; |
0b727fea | 792 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
dea3101e | 793 | if (rc == MBX_NOT_FINISHED) |
14691150 | 794 | goto lpfc_handle_latt_free_mbuf; |
dea3101e JB |
795 | |
796 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 797 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
798 | writel(HA_LATT, phba->HAregaddr); |
799 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 800 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
801 | |
802 | return; | |
803 | ||
14691150 JS |
804 | lpfc_handle_latt_free_mbuf: |
805 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
dea3101e JB |
806 | lpfc_handle_latt_free_mp: |
807 | kfree(mp); | |
808 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 809 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
810 | lpfc_handle_latt_err_exit: |
811 | /* Enable Link attention interrupts */ | |
2e0fef85 | 812 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
813 | psli->sli_flag |= LPFC_PROCESS_LA; |
814 | control = readl(phba->HCregaddr); | |
815 | control |= HC_LAINT_ENA; | |
816 | writel(control, phba->HCregaddr); | |
817 | readl(phba->HCregaddr); /* flush */ | |
818 | ||
819 | /* Clear Link Attention in HA REG */ | |
820 | writel(HA_LATT, phba->HAregaddr); | |
821 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 822 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 823 | lpfc_linkdown(phba); |
2e0fef85 | 824 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
825 | |
826 | /* The other case is an error from issue_mbox */ | |
827 | if (rc == -ENOMEM) | |
ed957684 | 828 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
e8b62011 | 829 | "0300 READ_LA: no buffers\n"); |
dea3101e JB |
830 | |
831 | return; | |
832 | } | |
833 | ||
834 | /************************************************************************/ | |
835 | /* */ | |
836 | /* lpfc_parse_vpd */ | |
837 | /* This routine will parse the VPD data */ | |
838 | /* */ | |
839 | /************************************************************************/ | |
840 | static int | |
2e0fef85 | 841 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
842 | { |
843 | uint8_t lenlo, lenhi; | |
07da60c1 | 844 | int Length; |
dea3101e JB |
845 | int i, j; |
846 | int finished = 0; | |
847 | int index = 0; | |
848 | ||
849 | if (!vpd) | |
850 | return 0; | |
851 | ||
852 | /* Vital Product */ | |
ed957684 | 853 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 854 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
855 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
856 | (uint32_t) vpd[3]); | |
74b72a59 | 857 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
858 | switch (vpd[index]) { |
859 | case 0x82: | |
74b72a59 | 860 | case 0x91: |
dea3101e JB |
861 | index += 1; |
862 | lenlo = vpd[index]; | |
863 | index += 1; | |
864 | lenhi = vpd[index]; | |
865 | index += 1; | |
866 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
867 | index += i; | |
868 | break; | |
869 | case 0x90: | |
870 | index += 1; | |
871 | lenlo = vpd[index]; | |
872 | index += 1; | |
873 | lenhi = vpd[index]; | |
874 | index += 1; | |
875 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
876 | if (Length > len - index) |
877 | Length = len - index; | |
dea3101e JB |
878 | while (Length > 0) { |
879 | /* Look for Serial Number */ | |
880 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
881 | index += 2; | |
882 | i = vpd[index]; | |
883 | index += 1; | |
884 | j = 0; | |
885 | Length -= (3+i); | |
886 | while(i--) { | |
887 | phba->SerialNumber[j++] = vpd[index++]; | |
888 | if (j == 31) | |
889 | break; | |
890 | } | |
891 | phba->SerialNumber[j] = 0; | |
892 | continue; | |
893 | } | |
894 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
895 | phba->vpd_flag |= VPD_MODEL_DESC; | |
896 | index += 2; | |
897 | i = vpd[index]; | |
898 | index += 1; | |
899 | j = 0; | |
900 | Length -= (3+i); | |
901 | while(i--) { | |
902 | phba->ModelDesc[j++] = vpd[index++]; | |
903 | if (j == 255) | |
904 | break; | |
905 | } | |
906 | phba->ModelDesc[j] = 0; | |
907 | continue; | |
908 | } | |
909 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
910 | phba->vpd_flag |= VPD_MODEL_NAME; | |
911 | index += 2; | |
912 | i = vpd[index]; | |
913 | index += 1; | |
914 | j = 0; | |
915 | Length -= (3+i); | |
916 | while(i--) { | |
917 | phba->ModelName[j++] = vpd[index++]; | |
918 | if (j == 79) | |
919 | break; | |
920 | } | |
921 | phba->ModelName[j] = 0; | |
922 | continue; | |
923 | } | |
924 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
925 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
926 | index += 2; | |
927 | i = vpd[index]; | |
928 | index += 1; | |
929 | j = 0; | |
930 | Length -= (3+i); | |
931 | while(i--) { | |
932 | phba->ProgramType[j++] = vpd[index++]; | |
933 | if (j == 255) | |
934 | break; | |
935 | } | |
936 | phba->ProgramType[j] = 0; | |
937 | continue; | |
938 | } | |
939 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
940 | phba->vpd_flag |= VPD_PORT; | |
941 | index += 2; | |
942 | i = vpd[index]; | |
943 | index += 1; | |
944 | j = 0; | |
945 | Length -= (3+i); | |
946 | while(i--) { | |
947 | phba->Port[j++] = vpd[index++]; | |
948 | if (j == 19) | |
949 | break; | |
950 | } | |
951 | phba->Port[j] = 0; | |
952 | continue; | |
953 | } | |
954 | else { | |
955 | index += 2; | |
956 | i = vpd[index]; | |
957 | index += 1; | |
958 | index += i; | |
959 | Length -= (3 + i); | |
960 | } | |
961 | } | |
962 | finished = 0; | |
963 | break; | |
964 | case 0x78: | |
965 | finished = 1; | |
966 | break; | |
967 | default: | |
968 | index ++; | |
969 | break; | |
970 | } | |
74b72a59 | 971 | } |
dea3101e JB |
972 | |
973 | return(1); | |
974 | } | |
975 | ||
976 | static void | |
2e0fef85 | 977 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
978 | { |
979 | lpfc_vpd_t *vp; | |
fefcb2b6 | 980 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 981 | int max_speed; |
74b72a59 JW |
982 | struct { |
983 | char * name; | |
984 | int max_speed; | |
74b72a59 | 985 | char * bus; |
18a3b596 | 986 | } m = {"<Unknown>", 0, ""}; |
74b72a59 JW |
987 | |
988 | if (mdp && mdp[0] != '\0' | |
989 | && descp && descp[0] != '\0') | |
990 | return; | |
991 | ||
992 | if (phba->lmt & LMT_10Gb) | |
993 | max_speed = 10; | |
994 | else if (phba->lmt & LMT_8Gb) | |
995 | max_speed = 8; | |
996 | else if (phba->lmt & LMT_4Gb) | |
997 | max_speed = 4; | |
998 | else if (phba->lmt & LMT_2Gb) | |
999 | max_speed = 2; | |
1000 | else | |
1001 | max_speed = 1; | |
dea3101e JB |
1002 | |
1003 | vp = &phba->vpd; | |
dea3101e | 1004 | |
e4adb204 | 1005 | switch (dev_id) { |
06325e74 | 1006 | case PCI_DEVICE_ID_FIREFLY: |
18a3b596 | 1007 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
06325e74 | 1008 | break; |
dea3101e JB |
1009 | case PCI_DEVICE_ID_SUPERFLY: |
1010 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
18a3b596 | 1011 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
dea3101e | 1012 | else |
18a3b596 | 1013 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
dea3101e JB |
1014 | break; |
1015 | case PCI_DEVICE_ID_DRAGONFLY: | |
18a3b596 | 1016 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
dea3101e JB |
1017 | break; |
1018 | case PCI_DEVICE_ID_CENTAUR: | |
1019 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
18a3b596 | 1020 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
dea3101e | 1021 | else |
18a3b596 | 1022 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
dea3101e JB |
1023 | break; |
1024 | case PCI_DEVICE_ID_RFLY: | |
18a3b596 | 1025 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
dea3101e JB |
1026 | break; |
1027 | case PCI_DEVICE_ID_PEGASUS: | |
18a3b596 | 1028 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
dea3101e JB |
1029 | break; |
1030 | case PCI_DEVICE_ID_THOR: | |
18a3b596 | 1031 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
dea3101e JB |
1032 | break; |
1033 | case PCI_DEVICE_ID_VIPER: | |
18a3b596 | 1034 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
dea3101e JB |
1035 | break; |
1036 | case PCI_DEVICE_ID_PFLY: | |
18a3b596 | 1037 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
dea3101e JB |
1038 | break; |
1039 | case PCI_DEVICE_ID_TFLY: | |
18a3b596 | 1040 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
dea3101e JB |
1041 | break; |
1042 | case PCI_DEVICE_ID_HELIOS: | |
18a3b596 | 1043 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
dea3101e | 1044 | break; |
e4adb204 | 1045 | case PCI_DEVICE_ID_HELIOS_SCSP: |
18a3b596 | 1046 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
e4adb204 JSEC |
1047 | break; |
1048 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
18a3b596 | 1049 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
e4adb204 JSEC |
1050 | break; |
1051 | case PCI_DEVICE_ID_NEPTUNE: | |
18a3b596 | 1052 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
e4adb204 JSEC |
1053 | break; |
1054 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
18a3b596 | 1055 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
e4adb204 JSEC |
1056 | break; |
1057 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
18a3b596 | 1058 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
e4adb204 | 1059 | break; |
dea3101e | 1060 | case PCI_DEVICE_ID_BMID: |
18a3b596 | 1061 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
dea3101e JB |
1062 | break; |
1063 | case PCI_DEVICE_ID_BSMB: | |
18a3b596 | 1064 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
dea3101e JB |
1065 | break; |
1066 | case PCI_DEVICE_ID_ZEPHYR: | |
18a3b596 | 1067 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
dea3101e | 1068 | break; |
e4adb204 | 1069 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
18a3b596 | 1070 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
e4adb204 JSEC |
1071 | break; |
1072 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
18a3b596 | 1073 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
e4adb204 | 1074 | break; |
dea3101e | 1075 | case PCI_DEVICE_ID_ZMID: |
18a3b596 | 1076 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
dea3101e JB |
1077 | break; |
1078 | case PCI_DEVICE_ID_ZSMB: | |
18a3b596 | 1079 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
dea3101e JB |
1080 | break; |
1081 | case PCI_DEVICE_ID_LP101: | |
18a3b596 | 1082 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
dea3101e JB |
1083 | break; |
1084 | case PCI_DEVICE_ID_LP10000S: | |
18a3b596 | 1085 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
06325e74 | 1086 | break; |
e4adb204 | 1087 | case PCI_DEVICE_ID_LP11000S: |
18a3b596 JS |
1088 | m = (typeof(m)){"LP11000-S", max_speed, |
1089 | "PCI-X2"}; | |
1090 | break; | |
e4adb204 | 1091 | case PCI_DEVICE_ID_LPE11000S: |
18a3b596 JS |
1092 | m = (typeof(m)){"LPe11000-S", max_speed, |
1093 | "PCIe"}; | |
5cc36b3c | 1094 | break; |
b87eab38 JS |
1095 | case PCI_DEVICE_ID_SAT: |
1096 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; | |
1097 | break; | |
1098 | case PCI_DEVICE_ID_SAT_MID: | |
1099 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; | |
1100 | break; | |
1101 | case PCI_DEVICE_ID_SAT_SMB: | |
1102 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; | |
1103 | break; | |
1104 | case PCI_DEVICE_ID_SAT_DCSP: | |
1105 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; | |
1106 | break; | |
1107 | case PCI_DEVICE_ID_SAT_SCSP: | |
1108 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; | |
1109 | break; | |
1110 | case PCI_DEVICE_ID_SAT_S: | |
1111 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; | |
1112 | break; | |
5cc36b3c | 1113 | default: |
041976fb | 1114 | m = (typeof(m)){ NULL }; |
e4adb204 | 1115 | break; |
dea3101e | 1116 | } |
74b72a59 JW |
1117 | |
1118 | if (mdp && mdp[0] == '\0') | |
1119 | snprintf(mdp, 79,"%s", m.name); | |
1120 | if (descp && descp[0] == '\0') | |
1121 | snprintf(descp, 255, | |
18a3b596 JS |
1122 | "Emulex %s %dGb %s Fibre Channel Adapter", |
1123 | m.name, m.max_speed, m.bus); | |
dea3101e JB |
1124 | } |
1125 | ||
1126 | /**************************************************/ | |
1127 | /* lpfc_post_buffer */ | |
1128 | /* */ | |
1129 | /* This routine will post count buffers to the */ | |
1130 | /* ring with the QUE_RING_BUF_CN command. This */ | |
1131 | /* allows 3 buffers / command to be posted. */ | |
1132 | /* Returns the number of buffers NOT posted. */ | |
1133 | /**************************************************/ | |
1134 | int | |
2e0fef85 | 1135 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt, |
dea3101e JB |
1136 | int type) |
1137 | { | |
1138 | IOCB_t *icmd; | |
0bd4ca25 | 1139 | struct lpfc_iocbq *iocb; |
dea3101e JB |
1140 | struct lpfc_dmabuf *mp1, *mp2; |
1141 | ||
1142 | cnt += pring->missbufcnt; | |
1143 | ||
1144 | /* While there are buffers to post */ | |
1145 | while (cnt > 0) { | |
1146 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 1147 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
1148 | if (iocb == NULL) { |
1149 | pring->missbufcnt = cnt; | |
1150 | return cnt; | |
1151 | } | |
dea3101e JB |
1152 | icmd = &iocb->iocb; |
1153 | ||
1154 | /* 2 buffers can be posted per command */ | |
1155 | /* Allocate buffer to post */ | |
1156 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1157 | if (mp1) | |
98c9ea5c JS |
1158 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
1159 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 1160 | kfree(mp1); |
604a3e30 | 1161 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1162 | pring->missbufcnt = cnt; |
1163 | return cnt; | |
1164 | } | |
1165 | ||
1166 | INIT_LIST_HEAD(&mp1->list); | |
1167 | /* Allocate buffer to post */ | |
1168 | if (cnt > 1) { | |
1169 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1170 | if (mp2) | |
1171 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
1172 | &mp2->phys); | |
98c9ea5c | 1173 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 1174 | kfree(mp2); |
dea3101e JB |
1175 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1176 | kfree(mp1); | |
604a3e30 | 1177 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1178 | pring->missbufcnt = cnt; |
1179 | return cnt; | |
1180 | } | |
1181 | ||
1182 | INIT_LIST_HEAD(&mp2->list); | |
1183 | } else { | |
1184 | mp2 = NULL; | |
1185 | } | |
1186 | ||
1187 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
1188 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
1189 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
1190 | icmd->ulpBdeCount = 1; | |
1191 | cnt--; | |
1192 | if (mp2) { | |
1193 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
1194 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
1195 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
1196 | cnt--; | |
1197 | icmd->ulpBdeCount = 2; | |
1198 | } | |
1199 | ||
1200 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
1201 | icmd->ulpLe = 1; | |
1202 | ||
dea3101e JB |
1203 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
1204 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | |
1205 | kfree(mp1); | |
1206 | cnt++; | |
1207 | if (mp2) { | |
1208 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
1209 | kfree(mp2); | |
1210 | cnt++; | |
1211 | } | |
604a3e30 | 1212 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1213 | pring->missbufcnt = cnt; |
dea3101e JB |
1214 | return cnt; |
1215 | } | |
dea3101e | 1216 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 1217 | if (mp2) |
dea3101e | 1218 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
1219 | } |
1220 | pring->missbufcnt = 0; | |
1221 | return 0; | |
1222 | } | |
1223 | ||
1224 | /************************************************************************/ | |
1225 | /* */ | |
1226 | /* lpfc_post_rcv_buf */ | |
1227 | /* This routine post initial rcv buffers to the configured rings */ | |
1228 | /* */ | |
1229 | /************************************************************************/ | |
1230 | static int | |
2e0fef85 | 1231 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
1232 | { |
1233 | struct lpfc_sli *psli = &phba->sli; | |
1234 | ||
1235 | /* Ring 0, ELS / CT buffers */ | |
1236 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1); | |
1237 | /* Ring 2 - FCP no buffers needed */ | |
1238 | ||
1239 | return 0; | |
1240 | } | |
1241 | ||
1242 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
1243 | ||
1244 | /************************************************************************/ | |
1245 | /* */ | |
1246 | /* lpfc_sha_init */ | |
1247 | /* */ | |
1248 | /************************************************************************/ | |
1249 | static void | |
1250 | lpfc_sha_init(uint32_t * HashResultPointer) | |
1251 | { | |
1252 | HashResultPointer[0] = 0x67452301; | |
1253 | HashResultPointer[1] = 0xEFCDAB89; | |
1254 | HashResultPointer[2] = 0x98BADCFE; | |
1255 | HashResultPointer[3] = 0x10325476; | |
1256 | HashResultPointer[4] = 0xC3D2E1F0; | |
1257 | } | |
1258 | ||
1259 | /************************************************************************/ | |
1260 | /* */ | |
1261 | /* lpfc_sha_iterate */ | |
1262 | /* */ | |
1263 | /************************************************************************/ | |
1264 | static void | |
1265 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
1266 | { | |
1267 | int t; | |
1268 | uint32_t TEMP; | |
1269 | uint32_t A, B, C, D, E; | |
1270 | t = 16; | |
1271 | do { | |
1272 | HashWorkingPointer[t] = | |
1273 | S(1, | |
1274 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
1275 | 8] ^ | |
1276 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
1277 | } while (++t <= 79); | |
1278 | t = 0; | |
1279 | A = HashResultPointer[0]; | |
1280 | B = HashResultPointer[1]; | |
1281 | C = HashResultPointer[2]; | |
1282 | D = HashResultPointer[3]; | |
1283 | E = HashResultPointer[4]; | |
1284 | ||
1285 | do { | |
1286 | if (t < 20) { | |
1287 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
1288 | } else if (t < 40) { | |
1289 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
1290 | } else if (t < 60) { | |
1291 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
1292 | } else { | |
1293 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
1294 | } | |
1295 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
1296 | E = D; | |
1297 | D = C; | |
1298 | C = S(30, B); | |
1299 | B = A; | |
1300 | A = TEMP; | |
1301 | } while (++t <= 79); | |
1302 | ||
1303 | HashResultPointer[0] += A; | |
1304 | HashResultPointer[1] += B; | |
1305 | HashResultPointer[2] += C; | |
1306 | HashResultPointer[3] += D; | |
1307 | HashResultPointer[4] += E; | |
1308 | ||
1309 | } | |
1310 | ||
1311 | /************************************************************************/ | |
1312 | /* */ | |
1313 | /* lpfc_challenge_key */ | |
1314 | /* */ | |
1315 | /************************************************************************/ | |
1316 | static void | |
1317 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
1318 | { | |
1319 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
1320 | } | |
1321 | ||
1322 | /************************************************************************/ | |
1323 | /* */ | |
1324 | /* lpfc_hba_init */ | |
1325 | /* */ | |
1326 | /************************************************************************/ | |
1327 | void | |
1328 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
1329 | { | |
1330 | int t; | |
1331 | uint32_t *HashWorking; | |
2e0fef85 | 1332 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 1333 | |
bbfbbbc1 | 1334 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
1335 | if (!HashWorking) |
1336 | return; | |
1337 | ||
dea3101e JB |
1338 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
1339 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
1340 | ||
1341 | for (t = 0; t < 7; t++) | |
1342 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
1343 | ||
1344 | lpfc_sha_init(hbainit); | |
1345 | lpfc_sha_iterate(hbainit, HashWorking); | |
1346 | kfree(HashWorking); | |
1347 | } | |
1348 | ||
87af33fe | 1349 | void |
2e0fef85 | 1350 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 1351 | { |
87af33fe | 1352 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1353 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 1354 | int i = 0; |
dea3101e | 1355 | |
87af33fe JS |
1356 | if (phba->link_state > LPFC_LINK_DOWN) |
1357 | lpfc_port_link_failure(vport); | |
1358 | ||
1359 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
1360 | if (ndlp->nlp_type & NLP_FABRIC) | |
1361 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
1362 | NLP_EVT_DEVICE_RECOVERY); | |
1363 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
1364 | NLP_EVT_DEVICE_RM); | |
1365 | } | |
1366 | ||
a8adb832 JS |
1367 | /* At this point, ALL ndlp's should be gone |
1368 | * because of the previous NLP_EVT_DEVICE_RM. | |
1369 | * Lets wait for this to happen, if needed. | |
1370 | */ | |
87af33fe JS |
1371 | while (!list_empty(&vport->fc_nodes)) { |
1372 | ||
a8adb832 | 1373 | if (i++ > 3000) { |
87af33fe | 1374 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 JS |
1375 | "0233 Nodelist not empty\n"); |
1376 | break; | |
87af33fe | 1377 | } |
a8adb832 JS |
1378 | |
1379 | /* Wait for any activity on ndlps to settle */ | |
1380 | msleep(10); | |
87af33fe | 1381 | } |
dea3101e JB |
1382 | return; |
1383 | } | |
1384 | ||
1385 | static void | |
1386 | lpfc_establish_link_tmo(unsigned long ptr) | |
1387 | { | |
92d7f7b0 | 1388 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
549e55cd | 1389 | struct lpfc_vport **vports; |
dea3101e | 1390 | unsigned long iflag; |
549e55cd | 1391 | int i; |
dea3101e | 1392 | |
dea3101e JB |
1393 | /* Re-establishing Link, timer expired */ |
1394 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
e8b62011 | 1395 | "1300 Re-establishing Link, timer expired " |
dea3101e | 1396 | "Data: x%x x%x\n", |
e8b62011 | 1397 | phba->pport->fc_flag, phba->pport->port_state); |
549e55cd JS |
1398 | vports = lpfc_create_vport_work_array(phba); |
1399 | if (vports != NULL) | |
1400 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1401 | struct Scsi_Host *shost; | |
1402 | shost = lpfc_shost_from_vport(vports[i]); | |
1403 | spin_lock_irqsave(shost->host_lock, iflag); | |
1404 | vports[i]->fc_flag &= ~FC_ESTABLISH_LINK; | |
1405 | spin_unlock_irqrestore(shost->host_lock, iflag); | |
1406 | } | |
1407 | lpfc_destroy_vport_work_array(vports); | |
dea3101e JB |
1408 | } |
1409 | ||
92d7f7b0 JS |
1410 | void |
1411 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 1412 | { |
92d7f7b0 JS |
1413 | del_timer_sync(&vport->els_tmofunc); |
1414 | del_timer_sync(&vport->fc_fdmitmo); | |
1415 | lpfc_can_disctmo(vport); | |
1416 | return; | |
dea3101e JB |
1417 | } |
1418 | ||
2e0fef85 | 1419 | static void |
92d7f7b0 | 1420 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
dea3101e | 1421 | { |
875fbdfe | 1422 | del_timer_sync(&phba->fcp_poll_timer); |
dea3101e | 1423 | del_timer_sync(&phba->fc_estabtmo); |
51ef4c26 | 1424 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 1425 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 1426 | del_timer_sync(&phba->fabric_block_timer); |
858c9f6c JS |
1427 | phba->hb_outstanding = 0; |
1428 | del_timer_sync(&phba->hb_tmofunc); | |
2e0fef85 | 1429 | return; |
dea3101e JB |
1430 | } |
1431 | ||
1432 | int | |
2e0fef85 | 1433 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 1434 | { |
2e0fef85 | 1435 | struct lpfc_vport *vport = phba->pport; |
549e55cd JS |
1436 | struct lpfc_vport **vports; |
1437 | int i; | |
2e0fef85 | 1438 | |
dea3101e JB |
1439 | if (!phba) |
1440 | return 0; | |
1441 | ||
2e0fef85 | 1442 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
1443 | return 0; |
1444 | ||
ed957684 | 1445 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 1446 | "0458 Bring Adapter online\n"); |
dea3101e | 1447 | |
46fa311e JS |
1448 | lpfc_block_mgmt_io(phba); |
1449 | ||
1450 | if (!lpfc_sli_queue_setup(phba)) { | |
1451 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 1452 | return 1; |
46fa311e | 1453 | } |
dea3101e | 1454 | |
46fa311e JS |
1455 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
1456 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 1457 | return 1; |
46fa311e | 1458 | } |
dea3101e | 1459 | |
549e55cd JS |
1460 | vports = lpfc_create_vport_work_array(phba); |
1461 | if (vports != NULL) | |
1462 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1463 | struct Scsi_Host *shost; | |
1464 | shost = lpfc_shost_from_vport(vports[i]); | |
1465 | spin_lock_irq(shost->host_lock); | |
1466 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
1467 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
1468 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1469 | spin_unlock_irq(shost->host_lock); | |
1470 | } | |
1471 | lpfc_destroy_vport_work_array(vports); | |
dea3101e | 1472 | |
46fa311e | 1473 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1474 | return 0; |
1475 | } | |
1476 | ||
46fa311e JS |
1477 | void |
1478 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
dea3101e | 1479 | { |
dea3101e | 1480 | unsigned long iflag; |
dea3101e | 1481 | |
2e0fef85 JS |
1482 | spin_lock_irqsave(&phba->hbalock, iflag); |
1483 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
1484 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
1485 | } |
1486 | ||
1487 | void | |
1488 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
1489 | { | |
1490 | unsigned long iflag; | |
1491 | ||
2e0fef85 JS |
1492 | spin_lock_irqsave(&phba->hbalock, iflag); |
1493 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
1494 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
1495 | } |
1496 | ||
1497 | void | |
1498 | lpfc_offline_prep(struct lpfc_hba * phba) | |
1499 | { | |
2e0fef85 | 1500 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 1501 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe JS |
1502 | struct lpfc_vport **vports; |
1503 | int i; | |
dea3101e | 1504 | |
2e0fef85 | 1505 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 1506 | return; |
dea3101e | 1507 | |
46fa311e | 1508 | lpfc_block_mgmt_io(phba); |
dea3101e JB |
1509 | |
1510 | lpfc_linkdown(phba); | |
1511 | ||
87af33fe JS |
1512 | /* Issue an unreg_login to all nodes on all vports */ |
1513 | vports = lpfc_create_vport_work_array(phba); | |
1514 | if (vports != NULL) { | |
1515 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1516 | struct Scsi_Host *shost; | |
1517 | ||
a8adb832 JS |
1518 | if (vports[i]->load_flag & FC_UNLOADING) |
1519 | continue; | |
87af33fe JS |
1520 | shost = lpfc_shost_from_vport(vports[i]); |
1521 | list_for_each_entry_safe(ndlp, next_ndlp, | |
1522 | &vports[i]->fc_nodes, | |
1523 | nlp_listp) { | |
1524 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | |
1525 | continue; | |
1526 | if (ndlp->nlp_type & NLP_FABRIC) { | |
1527 | lpfc_disc_state_machine(vports[i], ndlp, | |
1528 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
1529 | lpfc_disc_state_machine(vports[i], ndlp, | |
1530 | NULL, NLP_EVT_DEVICE_RM); | |
1531 | } | |
1532 | spin_lock_irq(shost->host_lock); | |
1533 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
1534 | spin_unlock_irq(shost->host_lock); | |
1535 | lpfc_unreg_rpi(vports[i], ndlp); | |
1536 | } | |
1537 | } | |
1538 | } | |
1539 | lpfc_destroy_vport_work_array(vports); | |
dea3101e | 1540 | |
46fa311e JS |
1541 | lpfc_sli_flush_mbox_queue(phba); |
1542 | } | |
1543 | ||
1544 | void | |
2e0fef85 | 1545 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 1546 | { |
549e55cd JS |
1547 | struct Scsi_Host *shost; |
1548 | struct lpfc_vport **vports; | |
1549 | int i; | |
46fa311e | 1550 | |
549e55cd | 1551 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 1552 | return; |
688a8863 | 1553 | |
dea3101e | 1554 | /* stop all timers associated with this hba */ |
92d7f7b0 | 1555 | lpfc_stop_phba_timers(phba); |
51ef4c26 JS |
1556 | vports = lpfc_create_vport_work_array(phba); |
1557 | if (vports != NULL) | |
1558 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) | |
1559 | lpfc_stop_vport_timers(vports[i]); | |
1560 | lpfc_destroy_vport_work_array(vports); | |
92d7f7b0 | 1561 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 1562 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
1563 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
1564 | now. */ | |
1565 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 1566 | spin_lock_irq(&phba->hbalock); |
7054a606 | 1567 | phba->work_ha = 0; |
92d7f7b0 | 1568 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
1569 | vports = lpfc_create_vport_work_array(phba); |
1570 | if (vports != NULL) | |
1571 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1572 | shost = lpfc_shost_from_vport(vports[i]); | |
549e55cd JS |
1573 | spin_lock_irq(shost->host_lock); |
1574 | vports[i]->work_port_events = 0; | |
1575 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
1576 | spin_unlock_irq(shost->host_lock); | |
1577 | } | |
1578 | lpfc_destroy_vport_work_array(vports); | |
dea3101e JB |
1579 | } |
1580 | ||
1581 | /****************************************************************************** | |
1582 | * Function name: lpfc_scsi_free | |
1583 | * | |
1584 | * Description: Called from lpfc_pci_remove_one free internal driver resources | |
1585 | * | |
1586 | ******************************************************************************/ | |
1587 | static int | |
2e0fef85 | 1588 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
1589 | { |
1590 | struct lpfc_scsi_buf *sb, *sb_next; | |
1591 | struct lpfc_iocbq *io, *io_next; | |
1592 | ||
2e0fef85 | 1593 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1594 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1595 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { | |
1596 | list_del(&sb->list); | |
1597 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 1598 | sb->dma_handle); |
dea3101e JB |
1599 | kfree(sb); |
1600 | phba->total_scsi_bufs--; | |
1601 | } | |
1602 | ||
1603 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
1604 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
1605 | list_del(&io->list); | |
1606 | kfree(io); | |
1607 | phba->total_iocbq_bufs--; | |
1608 | } | |
1609 | ||
2e0fef85 | 1610 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1611 | |
1612 | return 0; | |
1613 | } | |
1614 | ||
2e0fef85 | 1615 | struct lpfc_vport * |
3de2a653 | 1616 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 1617 | { |
2e0fef85 JS |
1618 | struct lpfc_vport *vport; |
1619 | struct Scsi_Host *shost; | |
1620 | int error = 0; | |
47a8617c | 1621 | |
3de2a653 JS |
1622 | if (dev != &phba->pcidev->dev) |
1623 | shost = scsi_host_alloc(&lpfc_vport_template, | |
1624 | sizeof(struct lpfc_vport)); | |
1625 | else | |
1626 | shost = scsi_host_alloc(&lpfc_template, | |
1627 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
1628 | if (!shost) |
1629 | goto out; | |
47a8617c | 1630 | |
2e0fef85 JS |
1631 | vport = (struct lpfc_vport *) shost->hostdata; |
1632 | vport->phba = phba; | |
47a8617c | 1633 | |
2e0fef85 | 1634 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 1635 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
47a8617c | 1636 | |
3de2a653 | 1637 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
1638 | shost->unique_id = instance; |
1639 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 1640 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
1641 | shost->this_id = -1; |
1642 | shost->max_cmd_len = 16; | |
47a8617c | 1643 | /* |
2e0fef85 JS |
1644 | * Set initial can_queue value since 0 is no longer supported and |
1645 | * scsi_add_host will fail. This will be adjusted later based on the | |
1646 | * max xri value determined in hba setup. | |
47a8617c | 1647 | */ |
2e0fef85 | 1648 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 1649 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
1650 | shost->transportt = lpfc_vport_transport_template; |
1651 | vport->port_type = LPFC_NPIV_PORT; | |
1652 | } else { | |
1653 | shost->transportt = lpfc_transport_template; | |
1654 | vport->port_type = LPFC_PHYSICAL_PORT; | |
1655 | } | |
47a8617c | 1656 | |
2e0fef85 JS |
1657 | /* Initialize all internally managed lists. */ |
1658 | INIT_LIST_HEAD(&vport->fc_nodes); | |
1659 | spin_lock_init(&vport->work_port_lock); | |
47a8617c | 1660 | |
2e0fef85 JS |
1661 | init_timer(&vport->fc_disctmo); |
1662 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 1663 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 1664 | |
2e0fef85 JS |
1665 | init_timer(&vport->fc_fdmitmo); |
1666 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 1667 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 1668 | |
2e0fef85 JS |
1669 | init_timer(&vport->els_tmofunc); |
1670 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 1671 | vport->els_tmofunc.data = (unsigned long)vport; |
47a8617c | 1672 | |
3de2a653 | 1673 | error = scsi_add_host(shost, dev); |
2e0fef85 JS |
1674 | if (error) |
1675 | goto out_put_shost; | |
47a8617c | 1676 | |
549e55cd | 1677 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 1678 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 1679 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 1680 | return vport; |
47a8617c | 1681 | |
2e0fef85 JS |
1682 | out_put_shost: |
1683 | scsi_host_put(shost); | |
1684 | out: | |
1685 | return NULL; | |
47a8617c JS |
1686 | } |
1687 | ||
2e0fef85 JS |
1688 | void |
1689 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 1690 | { |
92d7f7b0 JS |
1691 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1692 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 1693 | |
92d7f7b0 | 1694 | kfree(vport->vname); |
47a8617c | 1695 | |
858c9f6c | 1696 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
1697 | fc_remove_host(shost); |
1698 | scsi_remove_host(shost); | |
47a8617c | 1699 | |
92d7f7b0 JS |
1700 | spin_lock_irq(&phba->hbalock); |
1701 | list_del_init(&vport->listentry); | |
1702 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 1703 | |
92d7f7b0 | 1704 | lpfc_cleanup(vport); |
47a8617c | 1705 | return; |
47a8617c JS |
1706 | } |
1707 | ||
92d7f7b0 JS |
1708 | int |
1709 | lpfc_get_instance(void) | |
1710 | { | |
1711 | int instance = 0; | |
47a8617c | 1712 | |
92d7f7b0 JS |
1713 | /* Assign an unused number */ |
1714 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
1715 | return -1; | |
1716 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
1717 | return -1; | |
1718 | return instance; | |
47a8617c JS |
1719 | } |
1720 | ||
858c9f6c JS |
1721 | /* |
1722 | * Note: there is no scan_start function as adapter initialization | |
1723 | * will have asynchronously kicked off the link initialization. | |
1724 | */ | |
47a8617c JS |
1725 | |
1726 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
1727 | { | |
2e0fef85 JS |
1728 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1729 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 1730 | int stat = 0; |
47a8617c | 1731 | |
858c9f6c JS |
1732 | spin_lock_irq(shost->host_lock); |
1733 | ||
51ef4c26 | 1734 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
1735 | stat = 1; |
1736 | goto finished; | |
1737 | } | |
2e0fef85 JS |
1738 | if (time >= 30 * HZ) { |
1739 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
1740 | "0461 Scanning longer than 30 " |
1741 | "seconds. Continuing initialization\n"); | |
858c9f6c | 1742 | stat = 1; |
47a8617c | 1743 | goto finished; |
2e0fef85 JS |
1744 | } |
1745 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
1746 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
1747 | "0465 Link down longer than 15 " |
1748 | "seconds. Continuing initialization\n"); | |
858c9f6c | 1749 | stat = 1; |
47a8617c | 1750 | goto finished; |
2e0fef85 | 1751 | } |
47a8617c | 1752 | |
2e0fef85 | 1753 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 1754 | goto finished; |
2e0fef85 | 1755 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 1756 | goto finished; |
2e0fef85 | 1757 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 1758 | goto finished; |
2e0fef85 | 1759 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
1760 | goto finished; |
1761 | ||
1762 | stat = 1; | |
47a8617c JS |
1763 | |
1764 | finished: | |
858c9f6c JS |
1765 | spin_unlock_irq(shost->host_lock); |
1766 | return stat; | |
92d7f7b0 | 1767 | } |
47a8617c | 1768 | |
92d7f7b0 JS |
1769 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
1770 | { | |
1771 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1772 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 1773 | /* |
2e0fef85 | 1774 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
1775 | */ |
1776 | ||
2e0fef85 JS |
1777 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
1778 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
1779 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
1780 | ||
1781 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 1782 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
1783 | fc_host_supported_fc4s(shost)[2] = 1; |
1784 | fc_host_supported_fc4s(shost)[7] = 1; | |
1785 | ||
92d7f7b0 JS |
1786 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
1787 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
1788 | |
1789 | fc_host_supported_speeds(shost) = 0; | |
1790 | if (phba->lmt & LMT_10Gb) | |
1791 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
1792 | if (phba->lmt & LMT_8Gb) |
1793 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
1794 | if (phba->lmt & LMT_4Gb) |
1795 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
1796 | if (phba->lmt & LMT_2Gb) | |
1797 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
1798 | if (phba->lmt & LMT_1Gb) | |
1799 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
1800 | ||
1801 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
1802 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
1803 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c JS |
1804 | |
1805 | /* This value is also unchanging */ | |
1806 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 1807 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
1808 | fc_host_active_fc4s(shost)[2] = 1; |
1809 | fc_host_active_fc4s(shost)[7] = 1; | |
1810 | ||
92d7f7b0 | 1811 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 1812 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 1813 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 1814 | spin_unlock_irq(shost->host_lock); |
47a8617c | 1815 | } |
dea3101e JB |
1816 | |
1817 | static int __devinit | |
1818 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
1819 | { | |
2e0fef85 JS |
1820 | struct lpfc_vport *vport = NULL; |
1821 | struct lpfc_hba *phba; | |
1822 | struct lpfc_sli *psli; | |
dea3101e | 1823 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
2e0fef85 | 1824 | struct Scsi_Host *shost = NULL; |
51ef4c26 | 1825 | void *ptr; |
dea3101e | 1826 | unsigned long bar0map_len, bar2map_len; |
98c9ea5c | 1827 | int error = -ENODEV, retval; |
51ef4c26 | 1828 | int i, hbq_count; |
604a3e30 | 1829 | uint16_t iotag; |
dea3101e JB |
1830 | |
1831 | if (pci_enable_device(pdev)) | |
1832 | goto out; | |
1833 | if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) | |
1834 | goto out_disable_device; | |
1835 | ||
2e0fef85 JS |
1836 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
1837 | if (!phba) | |
dea3101e JB |
1838 | goto out_release_regions; |
1839 | ||
2e0fef85 | 1840 | spin_lock_init(&phba->hbalock); |
dea3101e | 1841 | |
dea3101e JB |
1842 | phba->pcidev = pdev; |
1843 | ||
1844 | /* Assign an unused board number */ | |
92d7f7b0 | 1845 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
2e0fef85 | 1846 | goto out_free_phba; |
dea3101e | 1847 | |
2e0fef85 | 1848 | INIT_LIST_HEAD(&phba->port_list); |
2e0fef85 JS |
1849 | /* |
1850 | * Get all the module params for configuring this host and then | |
1851 | * establish the host. | |
1852 | */ | |
1853 | lpfc_get_cfgparam(phba); | |
92d7f7b0 | 1854 | phba->max_vpi = LPFC_MAX_VPI; |
dea3101e JB |
1855 | |
1856 | /* Initialize timers used by driver */ | |
1857 | init_timer(&phba->fc_estabtmo); | |
1858 | phba->fc_estabtmo.function = lpfc_establish_link_tmo; | |
1859 | phba->fc_estabtmo.data = (unsigned long)phba; | |
858c9f6c JS |
1860 | |
1861 | init_timer(&phba->hb_tmofunc); | |
1862 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
1863 | phba->hb_tmofunc.data = (unsigned long)phba; | |
1864 | ||
dea3101e JB |
1865 | psli = &phba->sli; |
1866 | init_timer(&psli->mbox_tmo); | |
1867 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 1868 | psli->mbox_tmo.data = (unsigned long) phba; |
875fbdfe JSEC |
1869 | init_timer(&phba->fcp_poll_timer); |
1870 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 1871 | phba->fcp_poll_timer.data = (unsigned long) phba; |
92d7f7b0 JS |
1872 | init_timer(&phba->fabric_block_timer); |
1873 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
1874 | phba->fabric_block_timer.data = (unsigned long) phba; | |
dea3101e | 1875 | |
dea3101e | 1876 | pci_set_master(pdev); |
694625c0 | 1877 | pci_try_set_mwi(pdev); |
dea3101e JB |
1878 | |
1879 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) | |
1880 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) | |
1881 | goto out_idr_remove; | |
1882 | ||
1883 | /* | |
1884 | * Get the bus address of Bar0 and Bar2 and the number of bytes | |
1885 | * required by each mapping. | |
1886 | */ | |
1887 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); | |
1888 | bar0map_len = pci_resource_len(phba->pcidev, 0); | |
1889 | ||
1890 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); | |
1891 | bar2map_len = pci_resource_len(phba->pcidev, 2); | |
1892 | ||
901a920f | 1893 | /* Map HBA SLIM to a kernel virtual address. */ |
dea3101e | 1894 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
901a920f JW |
1895 | if (!phba->slim_memmap_p) { |
1896 | error = -ENODEV; | |
1897 | dev_printk(KERN_ERR, &pdev->dev, | |
1898 | "ioremap failed for SLIM memory.\n"); | |
1899 | goto out_idr_remove; | |
1900 | } | |
1901 | ||
1902 | /* Map HBA Control Registers to a kernel virtual address. */ | |
dea3101e | 1903 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
901a920f JW |
1904 | if (!phba->ctrl_regs_memmap_p) { |
1905 | error = -ENODEV; | |
1906 | dev_printk(KERN_ERR, &pdev->dev, | |
1907 | "ioremap failed for HBA control registers.\n"); | |
1908 | goto out_iounmap_slim; | |
1909 | } | |
dea3101e JB |
1910 | |
1911 | /* Allocate memory for SLI-2 structures */ | |
1912 | phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE, | |
1913 | &phba->slim2p_mapping, GFP_KERNEL); | |
1914 | if (!phba->slim2p) | |
1915 | goto out_iounmap; | |
1916 | ||
f91b392c | 1917 | memset(phba->slim2p, 0, SLI2_SLIM_SIZE); |
dea3101e | 1918 | |
ed957684 JS |
1919 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
1920 | lpfc_sli_hbq_size(), | |
1921 | &phba->hbqslimp.phys, | |
1922 | GFP_KERNEL); | |
1923 | if (!phba->hbqslimp.virt) | |
1924 | goto out_free_slim; | |
1925 | ||
51ef4c26 JS |
1926 | hbq_count = lpfc_sli_hbq_count(); |
1927 | ptr = phba->hbqslimp.virt; | |
1928 | for (i = 0; i < hbq_count; ++i) { | |
1929 | phba->hbqs[i].hbq_virt = ptr; | |
1930 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
1931 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
1932 | sizeof(struct lpfc_hbq_entry)); | |
1933 | } | |
1934 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
1935 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
1936 | ||
ed957684 JS |
1937 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
1938 | ||
dea3101e JB |
1939 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
1940 | lpfc_sli_setup(phba); | |
1941 | lpfc_sli_queue_setup(phba); | |
1942 | ||
98c9ea5c JS |
1943 | retval = lpfc_mem_alloc(phba); |
1944 | if (retval) { | |
1945 | error = retval; | |
ed957684 | 1946 | goto out_free_hbqslimp; |
98c9ea5c | 1947 | } |
dea3101e JB |
1948 | |
1949 | /* Initialize and populate the iocb list per host. */ | |
1950 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
1951 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { | |
dd00cc48 | 1952 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
1953 | if (iocbq_entry == NULL) { |
1954 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
1955 | "expected %d count. Unloading driver.\n", | |
1956 | __FUNCTION__, i, LPFC_IOCB_LIST_CNT); | |
1957 | error = -ENOMEM; | |
1958 | goto out_free_iocbq; | |
1959 | } | |
1960 | ||
604a3e30 JB |
1961 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
1962 | if (iotag == 0) { | |
1963 | kfree (iocbq_entry); | |
1964 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | |
1965 | "Unloading driver.\n", | |
1966 | __FUNCTION__); | |
1967 | error = -ENOMEM; | |
1968 | goto out_free_iocbq; | |
1969 | } | |
2e0fef85 JS |
1970 | |
1971 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
1972 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
1973 | phba->total_iocbq_bufs++; | |
2e0fef85 | 1974 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1975 | } |
1976 | ||
1977 | /* Initialize HBA structure */ | |
1978 | phba->fc_edtov = FF_DEF_EDTOV; | |
1979 | phba->fc_ratov = FF_DEF_RATOV; | |
1980 | phba->fc_altov = FF_DEF_ALTOV; | |
1981 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
1982 | ||
1983 | INIT_LIST_HEAD(&phba->work_list); | |
1984 | phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); | |
1985 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
1986 | ||
1987 | /* Startup the kernel thread for this host adapter. */ | |
1988 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
1989 | "lpfc_worker_%d", phba->brd_no); | |
1990 | if (IS_ERR(phba->worker_thread)) { | |
1991 | error = PTR_ERR(phba->worker_thread); | |
1992 | goto out_free_iocbq; | |
1993 | } | |
1994 | ||
dea3101e | 1995 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ |
875fbdfe | 1996 | spin_lock_init(&phba->scsi_buf_list_lock); |
dea3101e JB |
1997 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
1998 | ||
92d7f7b0 JS |
1999 | /* Initialize list of fabric iocbs */ |
2000 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
2001 | ||
3de2a653 | 2002 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
2e0fef85 JS |
2003 | if (!vport) |
2004 | goto out_kthread_stop; | |
2005 | ||
2006 | shost = lpfc_shost_from_vport(vport); | |
2e0fef85 | 2007 | phba->pport = vport; |
858c9f6c | 2008 | lpfc_debugfs_initialize(vport); |
2e0fef85 | 2009 | |
92d7f7b0 | 2010 | pci_set_drvdata(pdev, shost); |
dea3101e | 2011 | |
4ff43246 | 2012 | if (phba->cfg_use_msi) { |
98c9ea5c JS |
2013 | retval = pci_enable_msi(phba->pcidev); |
2014 | if (!retval) | |
51ef4c26 JS |
2015 | phba->using_msi = 1; |
2016 | else | |
e8b62011 JS |
2017 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2018 | "0452 Enable MSI failed, continuing " | |
2019 | "with IRQ\n"); | |
4ff43246 JS |
2020 | } |
2021 | ||
98c9ea5c | 2022 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED, |
2e0fef85 | 2023 | LPFC_DRIVER_NAME, phba); |
98c9ea5c | 2024 | if (retval) { |
dea3101e | 2025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 2026 | "0451 Enable interrupt handler failed\n"); |
98c9ea5c | 2027 | error = retval; |
92d7f7b0 | 2028 | goto out_disable_msi; |
dea3101e | 2029 | } |
dea3101e | 2030 | |
2e0fef85 JS |
2031 | phba->MBslimaddr = phba->slim_memmap_p; |
2032 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
2033 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
2034 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
2035 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
2036 | ||
98c9ea5c JS |
2037 | if (lpfc_alloc_sysfs_attr(vport)) { |
2038 | error = -ENOMEM; | |
dea3101e | 2039 | goto out_free_irq; |
98c9ea5c | 2040 | } |
875fbdfe | 2041 | |
98c9ea5c JS |
2042 | if (lpfc_sli_hba_setup(phba)) { |
2043 | error = -ENODEV; | |
858c9f6c | 2044 | goto out_remove_device; |
98c9ea5c | 2045 | } |
858c9f6c JS |
2046 | |
2047 | /* | |
2048 | * hba setup may have changed the hba_queue_depth so we need to adjust | |
2049 | * the value of can_queue. | |
2050 | */ | |
2051 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
2052 | ||
2053 | lpfc_host_attrib_init(shost); | |
2054 | ||
2e0fef85 JS |
2055 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
2056 | spin_lock_irq(shost->host_lock); | |
2057 | lpfc_poll_start_timer(phba); | |
2058 | spin_unlock_irq(shost->host_lock); | |
2059 | } | |
dea3101e | 2060 | |
858c9f6c | 2061 | scsi_scan_host(shost); |
dea3101e | 2062 | |
dea3101e JB |
2063 | return 0; |
2064 | ||
858c9f6c JS |
2065 | out_remove_device: |
2066 | lpfc_free_sysfs_attr(vport); | |
2067 | spin_lock_irq(shost->host_lock); | |
51ef4c26 | 2068 | vport->load_flag |= FC_UNLOADING; |
858c9f6c | 2069 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2070 | out_free_irq: |
92d7f7b0 | 2071 | lpfc_stop_phba_timers(phba); |
2e0fef85 | 2072 | phba->pport->work_port_events = 0; |
dea3101e | 2073 | free_irq(phba->pcidev->irq, phba); |
92d7f7b0 | 2074 | out_disable_msi: |
51ef4c26 JS |
2075 | if (phba->using_msi) |
2076 | pci_disable_msi(phba->pcidev); | |
2e0fef85 | 2077 | destroy_port(vport); |
dea3101e JB |
2078 | out_kthread_stop: |
2079 | kthread_stop(phba->worker_thread); | |
2080 | out_free_iocbq: | |
2081 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
2082 | &phba->lpfc_iocb_list, list) { | |
dea3101e JB |
2083 | kfree(iocbq_entry); |
2084 | phba->total_iocbq_bufs--; | |
dea3101e JB |
2085 | } |
2086 | lpfc_mem_free(phba); | |
ed957684 JS |
2087 | out_free_hbqslimp: |
2088 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, | |
2089 | phba->hbqslimp.phys); | |
dea3101e JB |
2090 | out_free_slim: |
2091 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p, | |
2092 | phba->slim2p_mapping); | |
2093 | out_iounmap: | |
2094 | iounmap(phba->ctrl_regs_memmap_p); | |
901a920f | 2095 | out_iounmap_slim: |
dea3101e JB |
2096 | iounmap(phba->slim_memmap_p); |
2097 | out_idr_remove: | |
2098 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
2e0fef85 JS |
2099 | out_free_phba: |
2100 | kfree(phba); | |
dea3101e JB |
2101 | out_release_regions: |
2102 | pci_release_regions(pdev); | |
2103 | out_disable_device: | |
2104 | pci_disable_device(pdev); | |
2105 | out: | |
defbcf11 | 2106 | pci_set_drvdata(pdev, NULL); |
858c9f6c JS |
2107 | if (shost) |
2108 | scsi_host_put(shost); | |
dea3101e JB |
2109 | return error; |
2110 | } | |
2111 | ||
2112 | static void __devexit | |
2113 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
2114 | { | |
2e0fef85 JS |
2115 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2116 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2117 | struct lpfc_hba *phba = vport->phba; | |
549e55cd | 2118 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 2119 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 2120 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2121 | |
858c9f6c JS |
2122 | kfree(vport->vname); |
2123 | lpfc_free_sysfs_attr(vport); | |
2124 | ||
2125 | fc_remove_host(shost); | |
2126 | scsi_remove_host(shost); | |
87af33fe JS |
2127 | lpfc_cleanup(vport); |
2128 | ||
2e0fef85 JS |
2129 | /* |
2130 | * Bring down the SLI Layer. This step disable all interrupts, | |
2131 | * clears the rings, discards all mailbox commands, and resets | |
2132 | * the HBA. | |
2133 | */ | |
2134 | lpfc_sli_hba_down(phba); | |
2135 | lpfc_sli_brdrestart(phba); | |
2136 | ||
92d7f7b0 | 2137 | lpfc_stop_phba_timers(phba); |
858c9f6c JS |
2138 | spin_lock_irq(&phba->hbalock); |
2139 | list_del_init(&vport->listentry); | |
2140 | spin_unlock_irq(&phba->hbalock); | |
2141 | ||
858c9f6c | 2142 | lpfc_debugfs_terminate(vport); |
2e0fef85 JS |
2143 | |
2144 | kthread_stop(phba->worker_thread); | |
2145 | ||
2146 | /* Release the irq reservation */ | |
2147 | free_irq(phba->pcidev->irq, phba); | |
51ef4c26 JS |
2148 | if (phba->using_msi) |
2149 | pci_disable_msi(phba->pcidev); | |
dea3101e JB |
2150 | |
2151 | pci_set_drvdata(pdev, NULL); | |
858c9f6c | 2152 | scsi_host_put(shost); |
2e0fef85 JS |
2153 | |
2154 | /* | |
2155 | * Call scsi_free before mem_free since scsi bufs are released to their | |
2156 | * corresponding pools here. | |
2157 | */ | |
2158 | lpfc_scsi_free(phba); | |
2159 | lpfc_mem_free(phba); | |
2160 | ||
ed957684 JS |
2161 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
2162 | phba->hbqslimp.phys); | |
2163 | ||
2e0fef85 JS |
2164 | /* Free resources associated with SLI2 interface */ |
2165 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
2166 | phba->slim2p, phba->slim2p_mapping); | |
2167 | ||
2168 | /* unmap adapter SLIM and Control Registers */ | |
2169 | iounmap(phba->ctrl_regs_memmap_p); | |
2170 | iounmap(phba->slim_memmap_p); | |
2171 | ||
2172 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
2173 | ||
2174 | kfree(phba); | |
2175 | ||
2176 | pci_release_regions(pdev); | |
2177 | pci_disable_device(pdev); | |
dea3101e JB |
2178 | } |
2179 | ||
8d63f375 LV |
2180 | /** |
2181 | * lpfc_io_error_detected - called when PCI error is detected | |
2182 | * @pdev: Pointer to PCI device | |
2183 | * @state: The current pci conneection state | |
2184 | * | |
2185 | * This function is called after a PCI bus error affecting | |
2186 | * this device has been detected. | |
2187 | */ | |
2188 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | |
2189 | pci_channel_state_t state) | |
2190 | { | |
51ef4c26 JS |
2191 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2192 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2193 | struct lpfc_sli *psli = &phba->sli; |
2194 | struct lpfc_sli_ring *pring; | |
2195 | ||
5daa49ef | 2196 | if (state == pci_channel_io_perm_failure) |
8d63f375 | 2197 | return PCI_ERS_RESULT_DISCONNECT; |
5daa49ef | 2198 | |
8d63f375 LV |
2199 | pci_disable_device(pdev); |
2200 | /* | |
2201 | * There may be I/Os dropped by the firmware. | |
2202 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
2203 | * retry it after re-establishing link. | |
2204 | */ | |
2205 | pring = &psli->ring[psli->fcp_ring]; | |
2206 | lpfc_sli_abort_iocb_ring(phba, pring); | |
2207 | ||
51ef4c26 JS |
2208 | /* Release the irq reservation */ |
2209 | free_irq(phba->pcidev->irq, phba); | |
2210 | if (phba->using_msi) | |
2211 | pci_disable_msi(phba->pcidev); | |
2212 | ||
8d63f375 LV |
2213 | /* Request a slot reset. */ |
2214 | return PCI_ERS_RESULT_NEED_RESET; | |
2215 | } | |
2216 | ||
2217 | /** | |
2218 | * lpfc_io_slot_reset - called after the pci bus has been reset. | |
2219 | * @pdev: Pointer to PCI device | |
2220 | * | |
2221 | * Restart the card from scratch, as if from a cold-boot. | |
2222 | */ | |
2223 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |
2224 | { | |
51ef4c26 JS |
2225 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2226 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2227 | struct lpfc_sli *psli = &phba->sli; |
2228 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
2229 | ||
2230 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
2231 | if (pci_enable_device_bars(pdev, bars)) { | |
2232 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
2233 | "PCI device after reset.\n"); | |
2234 | return PCI_ERS_RESULT_DISCONNECT; | |
2235 | } | |
2236 | ||
2237 | pci_set_master(pdev); | |
2238 | ||
2239 | /* Re-establishing Link */ | |
51ef4c26 | 2240 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 2241 | phba->pport->fc_flag |= FC_ESTABLISH_LINK; |
51ef4c26 | 2242 | spin_unlock_irq(shost->host_lock); |
8d63f375 | 2243 | |
92d7f7b0 | 2244 | spin_lock_irq(&phba->hbalock); |
8d63f375 | 2245 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 2246 | spin_unlock_irq(&phba->hbalock); |
8d63f375 LV |
2247 | |
2248 | ||
2249 | /* Take device offline; this will perform cleanup */ | |
2250 | lpfc_offline(phba); | |
2251 | lpfc_sli_brdrestart(phba); | |
2252 | ||
2253 | return PCI_ERS_RESULT_RECOVERED; | |
2254 | } | |
2255 | ||
2256 | /** | |
2257 | * lpfc_io_resume - called when traffic can start flowing again. | |
2258 | * @pdev: Pointer to PCI device | |
2259 | * | |
2260 | * This callback is called when the error recovery driver tells us that | |
2261 | * its OK to resume normal operation. | |
2262 | */ | |
2263 | static void lpfc_io_resume(struct pci_dev *pdev) | |
2264 | { | |
51ef4c26 JS |
2265 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2266 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2267 | |
2268 | if (lpfc_online(phba) == 0) { | |
2269 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); | |
2270 | } | |
2271 | } | |
2272 | ||
dea3101e JB |
2273 | static struct pci_device_id lpfc_id_table[] = { |
2274 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
2275 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
2276 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
2277 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2278 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
2279 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2280 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
2281 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2282 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
2283 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2284 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
2285 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2286 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
2287 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2288 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
2289 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2290 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
2291 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2292 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
2293 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2294 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
2295 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2296 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
2297 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2298 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
2299 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2300 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
2301 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2302 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
2303 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2304 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
2305 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2306 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
2307 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2308 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
2309 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2310 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
2311 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2312 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
2313 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2314 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
2315 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2316 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
2317 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2318 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
2319 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2320 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
2321 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2322 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
2323 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2324 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
2325 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2326 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
2327 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
2328 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
2329 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2330 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
2331 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2332 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
2333 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2334 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
2335 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2336 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
2337 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2338 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
2339 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2340 | { 0 } |
2341 | }; | |
2342 | ||
2343 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
2344 | ||
8d63f375 LV |
2345 | static struct pci_error_handlers lpfc_err_handler = { |
2346 | .error_detected = lpfc_io_error_detected, | |
2347 | .slot_reset = lpfc_io_slot_reset, | |
2348 | .resume = lpfc_io_resume, | |
2349 | }; | |
2350 | ||
dea3101e JB |
2351 | static struct pci_driver lpfc_driver = { |
2352 | .name = LPFC_DRIVER_NAME, | |
2353 | .id_table = lpfc_id_table, | |
2354 | .probe = lpfc_pci_probe_one, | |
2355 | .remove = __devexit_p(lpfc_pci_remove_one), | |
2e0fef85 | 2356 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
2357 | }; |
2358 | ||
2359 | static int __init | |
2360 | lpfc_init(void) | |
2361 | { | |
2362 | int error = 0; | |
2363 | ||
2364 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 2365 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 2366 | |
7ee5d43e JS |
2367 | if (lpfc_enable_npiv) { |
2368 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
2369 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
2370 | } | |
dea3101e JB |
2371 | lpfc_transport_template = |
2372 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 2373 | if (lpfc_transport_template == NULL) |
dea3101e | 2374 | return -ENOMEM; |
7ee5d43e | 2375 | if (lpfc_enable_npiv) { |
7ee5d43e | 2376 | lpfc_vport_transport_template = |
98c9ea5c JS |
2377 | fc_attach_transport(&lpfc_vport_transport_functions); |
2378 | if (lpfc_vport_transport_template == NULL) { | |
2379 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 2380 | return -ENOMEM; |
98c9ea5c | 2381 | } |
7ee5d43e | 2382 | } |
dea3101e | 2383 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 2384 | if (error) { |
dea3101e | 2385 | fc_release_transport(lpfc_transport_template); |
92d7f7b0 JS |
2386 | fc_release_transport(lpfc_vport_transport_template); |
2387 | } | |
dea3101e JB |
2388 | |
2389 | return error; | |
2390 | } | |
2391 | ||
2392 | static void __exit | |
2393 | lpfc_exit(void) | |
2394 | { | |
2395 | pci_unregister_driver(&lpfc_driver); | |
2396 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
2397 | if (lpfc_enable_npiv) |
2398 | fc_release_transport(lpfc_vport_transport_template); | |
dea3101e JB |
2399 | } |
2400 | ||
2401 | module_init(lpfc_init); | |
2402 | module_exit(lpfc_exit); | |
2403 | MODULE_LICENSE("GPL"); | |
2404 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
2405 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
2406 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |