]>
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 | 510 | /* HBA heart beat timeout handler */ |
a6ababd2 | 511 | static void |
858c9f6c JS |
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; | |
0ff10d46 | 550 | struct lpfc_dmabuf *buf_ptr; |
858c9f6c JS |
551 | int retval; |
552 | struct lpfc_sli *psli = &phba->sli; | |
0ff10d46 | 553 | LIST_HEAD(completions); |
858c9f6c JS |
554 | |
555 | if ((phba->link_state == LPFC_HBA_ERROR) || | |
51ef4c26 | 556 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
557 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
558 | return; | |
559 | ||
560 | spin_lock_irq(&phba->pport->work_port_lock); | |
561 | /* If the timer is already canceled do nothing */ | |
562 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { | |
563 | spin_unlock_irq(&phba->pport->work_port_lock); | |
564 | return; | |
565 | } | |
566 | ||
567 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
568 | jiffies)) { | |
569 | spin_unlock_irq(&phba->pport->work_port_lock); | |
570 | if (!phba->hb_outstanding) | |
571 | mod_timer(&phba->hb_tmofunc, | |
572 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
573 | else | |
574 | mod_timer(&phba->hb_tmofunc, | |
575 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
576 | return; | |
577 | } | |
578 | spin_unlock_irq(&phba->pport->work_port_lock); | |
579 | ||
0ff10d46 JS |
580 | if (phba->elsbuf_cnt && |
581 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
582 | spin_lock_irq(&phba->hbalock); | |
583 | list_splice_init(&phba->elsbuf, &completions); | |
584 | phba->elsbuf_cnt = 0; | |
585 | phba->elsbuf_prev_cnt = 0; | |
586 | spin_unlock_irq(&phba->hbalock); | |
587 | ||
588 | while (!list_empty(&completions)) { | |
589 | list_remove_head(&completions, buf_ptr, | |
590 | struct lpfc_dmabuf, list); | |
591 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
592 | kfree(buf_ptr); | |
593 | } | |
594 | } | |
595 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
596 | ||
597 | ||
858c9f6c JS |
598 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
599 | if (!phba->hb_outstanding) { | |
600 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
601 | if (!pmboxq) { | |
602 | mod_timer(&phba->hb_tmofunc, | |
603 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
604 | return; | |
605 | } | |
606 | ||
607 | lpfc_heart_beat(phba, pmboxq); | |
608 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
609 | pmboxq->vport = phba->pport; | |
610 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
611 | ||
612 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { | |
613 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
614 | mod_timer(&phba->hb_tmofunc, | |
615 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
616 | return; | |
617 | } | |
618 | mod_timer(&phba->hb_tmofunc, | |
619 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
620 | phba->hb_outstanding = 1; | |
621 | return; | |
622 | } else { | |
623 | /* | |
624 | * If heart beat timeout called with hb_outstanding set we | |
625 | * need to take the HBA offline. | |
626 | */ | |
627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
628 | "0459 Adapter heartbeat failure, taking " |
629 | "this port offline.\n"); | |
858c9f6c JS |
630 | |
631 | spin_lock_irq(&phba->hbalock); | |
632 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | |
633 | spin_unlock_irq(&phba->hbalock); | |
634 | ||
635 | lpfc_offline_prep(phba); | |
636 | lpfc_offline(phba); | |
637 | lpfc_unblock_mgmt_io(phba); | |
638 | phba->link_state = LPFC_HBA_ERROR; | |
639 | lpfc_hba_down_post(phba); | |
640 | } | |
641 | } | |
642 | ||
dea3101e JB |
643 | /************************************************************************/ |
644 | /* */ | |
645 | /* lpfc_handle_eratt */ | |
646 | /* This routine will handle processing a Host Attention */ | |
647 | /* Error Status event. This will be initialized */ | |
648 | /* as a SLI layer callback routine. */ | |
649 | /* */ | |
650 | /************************************************************************/ | |
651 | void | |
2e0fef85 | 652 | lpfc_handle_eratt(struct lpfc_hba *phba) |
dea3101e | 653 | { |
2e0fef85 | 654 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 655 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 656 | struct lpfc_sli_ring *pring; |
549e55cd | 657 | struct lpfc_vport **vports; |
d2873e4c | 658 | uint32_t event_data; |
57127f15 JS |
659 | unsigned long temperature; |
660 | struct temp_event temp_event_data; | |
92d7f7b0 | 661 | struct Scsi_Host *shost; |
549e55cd | 662 | int i; |
2e0fef85 | 663 | |
8d63f375 LV |
664 | /* If the pci channel is offline, ignore possible errors, |
665 | * since we cannot communicate with the pci card anyway. */ | |
666 | if (pci_channel_offline(phba->pcidev)) | |
667 | return; | |
dea3101e | 668 | |
f5603511 JS |
669 | if (phba->work_hs & HS_FFER6 || |
670 | phba->work_hs & HS_FFER5) { | |
dea3101e JB |
671 | /* Re-establishing Link */ |
672 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
e8b62011 | 673 | "1301 Re-establishing Link " |
dea3101e | 674 | "Data: x%x x%x x%x\n", |
e8b62011 | 675 | phba->work_hs, |
dea3101e | 676 | phba->work_status[0], phba->work_status[1]); |
549e55cd JS |
677 | vports = lpfc_create_vport_work_array(phba); |
678 | if (vports != NULL) | |
679 | for(i = 0; | |
680 | i < LPFC_MAX_VPORTS && vports[i] != NULL; | |
681 | i++){ | |
682 | shost = lpfc_shost_from_vport(vports[i]); | |
683 | spin_lock_irq(shost->host_lock); | |
684 | vports[i]->fc_flag |= FC_ESTABLISH_LINK; | |
685 | spin_unlock_irq(shost->host_lock); | |
686 | } | |
687 | lpfc_destroy_vport_work_array(vports); | |
92d7f7b0 | 688 | spin_lock_irq(&phba->hbalock); |
9290831f | 689 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 690 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
691 | |
692 | /* | |
693 | * Firmware stops when it triggled erratt with HS_FFER6. | |
694 | * That could cause the I/Os dropped by the firmware. | |
695 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
696 | * retry it after re-establishing link. | |
697 | */ | |
698 | pring = &psli->ring[psli->fcp_ring]; | |
699 | lpfc_sli_abort_iocb_ring(phba, pring); | |
700 | ||
701 | ||
702 | /* | |
703 | * There was a firmware error. Take the hba offline and then | |
704 | * attempt to restart it. | |
705 | */ | |
46fa311e | 706 | lpfc_offline_prep(phba); |
dea3101e | 707 | lpfc_offline(phba); |
41415862 | 708 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
709 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
710 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); | |
46fa311e | 711 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
712 | return; |
713 | } | |
46fa311e | 714 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
715 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
716 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
717 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
718 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
719 | temp_event_data.data = (uint32_t)temperature; | |
720 | ||
721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
722 | "0459 Adapter maximum temperature exceeded " | |
723 | "(%ld), taking this port offline " | |
724 | "Data: x%x x%x x%x\n", | |
725 | temperature, phba->work_hs, | |
726 | phba->work_status[0], phba->work_status[1]); | |
727 | ||
728 | shost = lpfc_shost_from_vport(phba->pport); | |
729 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
730 | sizeof(temp_event_data), | |
731 | (char *) &temp_event_data, | |
732 | SCSI_NL_VID_TYPE_PCI | |
733 | | PCI_VENDOR_ID_EMULEX); | |
734 | ||
7af67051 | 735 | spin_lock_irq(&phba->hbalock); |
57127f15 | 736 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
7af67051 JS |
737 | phba->over_temp_state = HBA_OVER_TEMP; |
738 | spin_unlock_irq(&phba->hbalock); | |
57127f15 JS |
739 | lpfc_offline_prep(phba); |
740 | lpfc_offline(phba); | |
741 | lpfc_unblock_mgmt_io(phba); | |
742 | phba->link_state = LPFC_HBA_ERROR; | |
743 | lpfc_hba_down_post(phba); | |
744 | ||
dea3101e JB |
745 | } else { |
746 | /* The if clause above forces this code path when the status | |
747 | * failure is a value other than FFER6. Do not call the offline | |
748 | * twice. This is the adapter hardware error path. | |
749 | */ | |
750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 751 | "0457 Adapter Hardware Error " |
dea3101e | 752 | "Data: x%x x%x x%x\n", |
e8b62011 | 753 | phba->work_hs, |
dea3101e JB |
754 | phba->work_status[0], phba->work_status[1]); |
755 | ||
d2873e4c | 756 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 757 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 758 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
759 | sizeof(event_data), (char *) &event_data, |
760 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
761 | ||
92d7f7b0 | 762 | spin_lock_irq(&phba->hbalock); |
9290831f | 763 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 764 | spin_unlock_irq(&phba->hbalock); |
46fa311e | 765 | lpfc_offline_prep(phba); |
dea3101e | 766 | lpfc_offline(phba); |
46fa311e | 767 | lpfc_unblock_mgmt_io(phba); |
2e0fef85 | 768 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 769 | lpfc_hba_down_post(phba); |
dea3101e JB |
770 | } |
771 | } | |
772 | ||
773 | /************************************************************************/ | |
774 | /* */ | |
775 | /* lpfc_handle_latt */ | |
776 | /* This routine will handle processing a Host Attention */ | |
777 | /* Link Status event. This will be initialized */ | |
778 | /* as a SLI layer callback routine. */ | |
779 | /* */ | |
780 | /************************************************************************/ | |
781 | void | |
2e0fef85 | 782 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 783 | { |
2e0fef85 JS |
784 | struct lpfc_vport *vport = phba->pport; |
785 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
786 | LPFC_MBOXQ_t *pmb; |
787 | volatile uint32_t control; | |
788 | struct lpfc_dmabuf *mp; | |
789 | int rc = -ENOMEM; | |
790 | ||
791 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
792 | if (!pmb) | |
793 | goto lpfc_handle_latt_err_exit; | |
794 | ||
795 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
796 | if (!mp) | |
797 | goto lpfc_handle_latt_free_pmb; | |
798 | ||
799 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
800 | if (!mp->virt) | |
801 | goto lpfc_handle_latt_free_mp; | |
802 | ||
803 | rc = -EIO; | |
804 | ||
6281bfe0 | 805 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 806 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
807 | |
808 | psli->slistat.link_event++; | |
809 | lpfc_read_la(phba, pmb, mp); | |
810 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; | |
2e0fef85 | 811 | pmb->vport = vport; |
0b727fea | 812 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
dea3101e | 813 | if (rc == MBX_NOT_FINISHED) |
14691150 | 814 | goto lpfc_handle_latt_free_mbuf; |
dea3101e JB |
815 | |
816 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 817 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
818 | writel(HA_LATT, phba->HAregaddr); |
819 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 820 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
821 | |
822 | return; | |
823 | ||
14691150 JS |
824 | lpfc_handle_latt_free_mbuf: |
825 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
dea3101e JB |
826 | lpfc_handle_latt_free_mp: |
827 | kfree(mp); | |
828 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 829 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
830 | lpfc_handle_latt_err_exit: |
831 | /* Enable Link attention interrupts */ | |
2e0fef85 | 832 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
833 | psli->sli_flag |= LPFC_PROCESS_LA; |
834 | control = readl(phba->HCregaddr); | |
835 | control |= HC_LAINT_ENA; | |
836 | writel(control, phba->HCregaddr); | |
837 | readl(phba->HCregaddr); /* flush */ | |
838 | ||
839 | /* Clear Link Attention in HA REG */ | |
840 | writel(HA_LATT, phba->HAregaddr); | |
841 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 842 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 843 | lpfc_linkdown(phba); |
2e0fef85 | 844 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
845 | |
846 | /* The other case is an error from issue_mbox */ | |
847 | if (rc == -ENOMEM) | |
ed957684 | 848 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
e8b62011 | 849 | "0300 READ_LA: no buffers\n"); |
dea3101e JB |
850 | |
851 | return; | |
852 | } | |
853 | ||
854 | /************************************************************************/ | |
855 | /* */ | |
856 | /* lpfc_parse_vpd */ | |
857 | /* This routine will parse the VPD data */ | |
858 | /* */ | |
859 | /************************************************************************/ | |
860 | static int | |
2e0fef85 | 861 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
862 | { |
863 | uint8_t lenlo, lenhi; | |
07da60c1 | 864 | int Length; |
dea3101e JB |
865 | int i, j; |
866 | int finished = 0; | |
867 | int index = 0; | |
868 | ||
869 | if (!vpd) | |
870 | return 0; | |
871 | ||
872 | /* Vital Product */ | |
ed957684 | 873 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 874 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
875 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
876 | (uint32_t) vpd[3]); | |
74b72a59 | 877 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
878 | switch (vpd[index]) { |
879 | case 0x82: | |
74b72a59 | 880 | case 0x91: |
dea3101e JB |
881 | index += 1; |
882 | lenlo = vpd[index]; | |
883 | index += 1; | |
884 | lenhi = vpd[index]; | |
885 | index += 1; | |
886 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
887 | index += i; | |
888 | break; | |
889 | case 0x90: | |
890 | index += 1; | |
891 | lenlo = vpd[index]; | |
892 | index += 1; | |
893 | lenhi = vpd[index]; | |
894 | index += 1; | |
895 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
896 | if (Length > len - index) |
897 | Length = len - index; | |
dea3101e JB |
898 | while (Length > 0) { |
899 | /* Look for Serial Number */ | |
900 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
901 | index += 2; | |
902 | i = vpd[index]; | |
903 | index += 1; | |
904 | j = 0; | |
905 | Length -= (3+i); | |
906 | while(i--) { | |
907 | phba->SerialNumber[j++] = vpd[index++]; | |
908 | if (j == 31) | |
909 | break; | |
910 | } | |
911 | phba->SerialNumber[j] = 0; | |
912 | continue; | |
913 | } | |
914 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
915 | phba->vpd_flag |= VPD_MODEL_DESC; | |
916 | index += 2; | |
917 | i = vpd[index]; | |
918 | index += 1; | |
919 | j = 0; | |
920 | Length -= (3+i); | |
921 | while(i--) { | |
922 | phba->ModelDesc[j++] = vpd[index++]; | |
923 | if (j == 255) | |
924 | break; | |
925 | } | |
926 | phba->ModelDesc[j] = 0; | |
927 | continue; | |
928 | } | |
929 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
930 | phba->vpd_flag |= VPD_MODEL_NAME; | |
931 | index += 2; | |
932 | i = vpd[index]; | |
933 | index += 1; | |
934 | j = 0; | |
935 | Length -= (3+i); | |
936 | while(i--) { | |
937 | phba->ModelName[j++] = vpd[index++]; | |
938 | if (j == 79) | |
939 | break; | |
940 | } | |
941 | phba->ModelName[j] = 0; | |
942 | continue; | |
943 | } | |
944 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
945 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
946 | index += 2; | |
947 | i = vpd[index]; | |
948 | index += 1; | |
949 | j = 0; | |
950 | Length -= (3+i); | |
951 | while(i--) { | |
952 | phba->ProgramType[j++] = vpd[index++]; | |
953 | if (j == 255) | |
954 | break; | |
955 | } | |
956 | phba->ProgramType[j] = 0; | |
957 | continue; | |
958 | } | |
959 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
960 | phba->vpd_flag |= VPD_PORT; | |
961 | index += 2; | |
962 | i = vpd[index]; | |
963 | index += 1; | |
964 | j = 0; | |
965 | Length -= (3+i); | |
966 | while(i--) { | |
967 | phba->Port[j++] = vpd[index++]; | |
968 | if (j == 19) | |
969 | break; | |
970 | } | |
971 | phba->Port[j] = 0; | |
972 | continue; | |
973 | } | |
974 | else { | |
975 | index += 2; | |
976 | i = vpd[index]; | |
977 | index += 1; | |
978 | index += i; | |
979 | Length -= (3 + i); | |
980 | } | |
981 | } | |
982 | finished = 0; | |
983 | break; | |
984 | case 0x78: | |
985 | finished = 1; | |
986 | break; | |
987 | default: | |
988 | index ++; | |
989 | break; | |
990 | } | |
74b72a59 | 991 | } |
dea3101e JB |
992 | |
993 | return(1); | |
994 | } | |
995 | ||
996 | static void | |
2e0fef85 | 997 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
998 | { |
999 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1000 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1001 | int max_speed; |
74b72a59 JW |
1002 | struct { |
1003 | char * name; | |
1004 | int max_speed; | |
74b72a59 | 1005 | char * bus; |
18a3b596 | 1006 | } m = {"<Unknown>", 0, ""}; |
74b72a59 JW |
1007 | |
1008 | if (mdp && mdp[0] != '\0' | |
1009 | && descp && descp[0] != '\0') | |
1010 | return; | |
1011 | ||
1012 | if (phba->lmt & LMT_10Gb) | |
1013 | max_speed = 10; | |
1014 | else if (phba->lmt & LMT_8Gb) | |
1015 | max_speed = 8; | |
1016 | else if (phba->lmt & LMT_4Gb) | |
1017 | max_speed = 4; | |
1018 | else if (phba->lmt & LMT_2Gb) | |
1019 | max_speed = 2; | |
1020 | else | |
1021 | max_speed = 1; | |
dea3101e JB |
1022 | |
1023 | vp = &phba->vpd; | |
dea3101e | 1024 | |
e4adb204 | 1025 | switch (dev_id) { |
06325e74 | 1026 | case PCI_DEVICE_ID_FIREFLY: |
18a3b596 | 1027 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
06325e74 | 1028 | break; |
dea3101e JB |
1029 | case PCI_DEVICE_ID_SUPERFLY: |
1030 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
18a3b596 | 1031 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
dea3101e | 1032 | else |
18a3b596 | 1033 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
dea3101e JB |
1034 | break; |
1035 | case PCI_DEVICE_ID_DRAGONFLY: | |
18a3b596 | 1036 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
dea3101e JB |
1037 | break; |
1038 | case PCI_DEVICE_ID_CENTAUR: | |
1039 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
18a3b596 | 1040 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
dea3101e | 1041 | else |
18a3b596 | 1042 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
dea3101e JB |
1043 | break; |
1044 | case PCI_DEVICE_ID_RFLY: | |
18a3b596 | 1045 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
dea3101e JB |
1046 | break; |
1047 | case PCI_DEVICE_ID_PEGASUS: | |
18a3b596 | 1048 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
dea3101e JB |
1049 | break; |
1050 | case PCI_DEVICE_ID_THOR: | |
18a3b596 | 1051 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
dea3101e JB |
1052 | break; |
1053 | case PCI_DEVICE_ID_VIPER: | |
18a3b596 | 1054 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
dea3101e JB |
1055 | break; |
1056 | case PCI_DEVICE_ID_PFLY: | |
18a3b596 | 1057 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
dea3101e JB |
1058 | break; |
1059 | case PCI_DEVICE_ID_TFLY: | |
18a3b596 | 1060 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
dea3101e JB |
1061 | break; |
1062 | case PCI_DEVICE_ID_HELIOS: | |
18a3b596 | 1063 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
dea3101e | 1064 | break; |
e4adb204 | 1065 | case PCI_DEVICE_ID_HELIOS_SCSP: |
18a3b596 | 1066 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
e4adb204 JSEC |
1067 | break; |
1068 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
18a3b596 | 1069 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
e4adb204 JSEC |
1070 | break; |
1071 | case PCI_DEVICE_ID_NEPTUNE: | |
18a3b596 | 1072 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
e4adb204 JSEC |
1073 | break; |
1074 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
18a3b596 | 1075 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
e4adb204 JSEC |
1076 | break; |
1077 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
18a3b596 | 1078 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
e4adb204 | 1079 | break; |
dea3101e | 1080 | case PCI_DEVICE_ID_BMID: |
18a3b596 | 1081 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
dea3101e JB |
1082 | break; |
1083 | case PCI_DEVICE_ID_BSMB: | |
18a3b596 | 1084 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
dea3101e JB |
1085 | break; |
1086 | case PCI_DEVICE_ID_ZEPHYR: | |
18a3b596 | 1087 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
dea3101e | 1088 | break; |
e4adb204 | 1089 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
18a3b596 | 1090 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
e4adb204 JSEC |
1091 | break; |
1092 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
18a3b596 | 1093 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
e4adb204 | 1094 | break; |
dea3101e | 1095 | case PCI_DEVICE_ID_ZMID: |
18a3b596 | 1096 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
dea3101e JB |
1097 | break; |
1098 | case PCI_DEVICE_ID_ZSMB: | |
18a3b596 | 1099 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
dea3101e JB |
1100 | break; |
1101 | case PCI_DEVICE_ID_LP101: | |
18a3b596 | 1102 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
dea3101e JB |
1103 | break; |
1104 | case PCI_DEVICE_ID_LP10000S: | |
18a3b596 | 1105 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
06325e74 | 1106 | break; |
e4adb204 | 1107 | case PCI_DEVICE_ID_LP11000S: |
18a3b596 JS |
1108 | m = (typeof(m)){"LP11000-S", max_speed, |
1109 | "PCI-X2"}; | |
1110 | break; | |
e4adb204 | 1111 | case PCI_DEVICE_ID_LPE11000S: |
18a3b596 JS |
1112 | m = (typeof(m)){"LPe11000-S", max_speed, |
1113 | "PCIe"}; | |
5cc36b3c | 1114 | break; |
b87eab38 JS |
1115 | case PCI_DEVICE_ID_SAT: |
1116 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; | |
1117 | break; | |
1118 | case PCI_DEVICE_ID_SAT_MID: | |
1119 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; | |
1120 | break; | |
1121 | case PCI_DEVICE_ID_SAT_SMB: | |
1122 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; | |
1123 | break; | |
1124 | case PCI_DEVICE_ID_SAT_DCSP: | |
1125 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; | |
1126 | break; | |
1127 | case PCI_DEVICE_ID_SAT_SCSP: | |
1128 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; | |
1129 | break; | |
1130 | case PCI_DEVICE_ID_SAT_S: | |
1131 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; | |
1132 | break; | |
5cc36b3c | 1133 | default: |
041976fb | 1134 | m = (typeof(m)){ NULL }; |
e4adb204 | 1135 | break; |
dea3101e | 1136 | } |
74b72a59 JW |
1137 | |
1138 | if (mdp && mdp[0] == '\0') | |
1139 | snprintf(mdp, 79,"%s", m.name); | |
1140 | if (descp && descp[0] == '\0') | |
1141 | snprintf(descp, 255, | |
18a3b596 JS |
1142 | "Emulex %s %dGb %s Fibre Channel Adapter", |
1143 | m.name, m.max_speed, m.bus); | |
dea3101e JB |
1144 | } |
1145 | ||
1146 | /**************************************************/ | |
1147 | /* lpfc_post_buffer */ | |
1148 | /* */ | |
1149 | /* This routine will post count buffers to the */ | |
1150 | /* ring with the QUE_RING_BUF_CN command. This */ | |
1151 | /* allows 3 buffers / command to be posted. */ | |
1152 | /* Returns the number of buffers NOT posted. */ | |
1153 | /**************************************************/ | |
1154 | int | |
2e0fef85 | 1155 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt, |
dea3101e JB |
1156 | int type) |
1157 | { | |
1158 | IOCB_t *icmd; | |
0bd4ca25 | 1159 | struct lpfc_iocbq *iocb; |
dea3101e JB |
1160 | struct lpfc_dmabuf *mp1, *mp2; |
1161 | ||
1162 | cnt += pring->missbufcnt; | |
1163 | ||
1164 | /* While there are buffers to post */ | |
1165 | while (cnt > 0) { | |
1166 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 1167 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
1168 | if (iocb == NULL) { |
1169 | pring->missbufcnt = cnt; | |
1170 | return cnt; | |
1171 | } | |
dea3101e JB |
1172 | icmd = &iocb->iocb; |
1173 | ||
1174 | /* 2 buffers can be posted per command */ | |
1175 | /* Allocate buffer to post */ | |
1176 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1177 | if (mp1) | |
98c9ea5c JS |
1178 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
1179 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 1180 | kfree(mp1); |
604a3e30 | 1181 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1182 | pring->missbufcnt = cnt; |
1183 | return cnt; | |
1184 | } | |
1185 | ||
1186 | INIT_LIST_HEAD(&mp1->list); | |
1187 | /* Allocate buffer to post */ | |
1188 | if (cnt > 1) { | |
1189 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1190 | if (mp2) | |
1191 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
1192 | &mp2->phys); | |
98c9ea5c | 1193 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 1194 | kfree(mp2); |
dea3101e JB |
1195 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1196 | kfree(mp1); | |
604a3e30 | 1197 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1198 | pring->missbufcnt = cnt; |
1199 | return cnt; | |
1200 | } | |
1201 | ||
1202 | INIT_LIST_HEAD(&mp2->list); | |
1203 | } else { | |
1204 | mp2 = NULL; | |
1205 | } | |
1206 | ||
1207 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
1208 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
1209 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
1210 | icmd->ulpBdeCount = 1; | |
1211 | cnt--; | |
1212 | if (mp2) { | |
1213 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
1214 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
1215 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
1216 | cnt--; | |
1217 | icmd->ulpBdeCount = 2; | |
1218 | } | |
1219 | ||
1220 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
1221 | icmd->ulpLe = 1; | |
1222 | ||
dea3101e JB |
1223 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
1224 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | |
1225 | kfree(mp1); | |
1226 | cnt++; | |
1227 | if (mp2) { | |
1228 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
1229 | kfree(mp2); | |
1230 | cnt++; | |
1231 | } | |
604a3e30 | 1232 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1233 | pring->missbufcnt = cnt; |
dea3101e JB |
1234 | return cnt; |
1235 | } | |
dea3101e | 1236 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 1237 | if (mp2) |
dea3101e | 1238 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
1239 | } |
1240 | pring->missbufcnt = 0; | |
1241 | return 0; | |
1242 | } | |
1243 | ||
1244 | /************************************************************************/ | |
1245 | /* */ | |
1246 | /* lpfc_post_rcv_buf */ | |
1247 | /* This routine post initial rcv buffers to the configured rings */ | |
1248 | /* */ | |
1249 | /************************************************************************/ | |
1250 | static int | |
2e0fef85 | 1251 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
1252 | { |
1253 | struct lpfc_sli *psli = &phba->sli; | |
1254 | ||
1255 | /* Ring 0, ELS / CT buffers */ | |
1256 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1); | |
1257 | /* Ring 2 - FCP no buffers needed */ | |
1258 | ||
1259 | return 0; | |
1260 | } | |
1261 | ||
1262 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
1263 | ||
1264 | /************************************************************************/ | |
1265 | /* */ | |
1266 | /* lpfc_sha_init */ | |
1267 | /* */ | |
1268 | /************************************************************************/ | |
1269 | static void | |
1270 | lpfc_sha_init(uint32_t * HashResultPointer) | |
1271 | { | |
1272 | HashResultPointer[0] = 0x67452301; | |
1273 | HashResultPointer[1] = 0xEFCDAB89; | |
1274 | HashResultPointer[2] = 0x98BADCFE; | |
1275 | HashResultPointer[3] = 0x10325476; | |
1276 | HashResultPointer[4] = 0xC3D2E1F0; | |
1277 | } | |
1278 | ||
1279 | /************************************************************************/ | |
1280 | /* */ | |
1281 | /* lpfc_sha_iterate */ | |
1282 | /* */ | |
1283 | /************************************************************************/ | |
1284 | static void | |
1285 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
1286 | { | |
1287 | int t; | |
1288 | uint32_t TEMP; | |
1289 | uint32_t A, B, C, D, E; | |
1290 | t = 16; | |
1291 | do { | |
1292 | HashWorkingPointer[t] = | |
1293 | S(1, | |
1294 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
1295 | 8] ^ | |
1296 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
1297 | } while (++t <= 79); | |
1298 | t = 0; | |
1299 | A = HashResultPointer[0]; | |
1300 | B = HashResultPointer[1]; | |
1301 | C = HashResultPointer[2]; | |
1302 | D = HashResultPointer[3]; | |
1303 | E = HashResultPointer[4]; | |
1304 | ||
1305 | do { | |
1306 | if (t < 20) { | |
1307 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
1308 | } else if (t < 40) { | |
1309 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
1310 | } else if (t < 60) { | |
1311 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
1312 | } else { | |
1313 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
1314 | } | |
1315 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
1316 | E = D; | |
1317 | D = C; | |
1318 | C = S(30, B); | |
1319 | B = A; | |
1320 | A = TEMP; | |
1321 | } while (++t <= 79); | |
1322 | ||
1323 | HashResultPointer[0] += A; | |
1324 | HashResultPointer[1] += B; | |
1325 | HashResultPointer[2] += C; | |
1326 | HashResultPointer[3] += D; | |
1327 | HashResultPointer[4] += E; | |
1328 | ||
1329 | } | |
1330 | ||
1331 | /************************************************************************/ | |
1332 | /* */ | |
1333 | /* lpfc_challenge_key */ | |
1334 | /* */ | |
1335 | /************************************************************************/ | |
1336 | static void | |
1337 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
1338 | { | |
1339 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
1340 | } | |
1341 | ||
1342 | /************************************************************************/ | |
1343 | /* */ | |
1344 | /* lpfc_hba_init */ | |
1345 | /* */ | |
1346 | /************************************************************************/ | |
1347 | void | |
1348 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
1349 | { | |
1350 | int t; | |
1351 | uint32_t *HashWorking; | |
2e0fef85 | 1352 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 1353 | |
bbfbbbc1 | 1354 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
1355 | if (!HashWorking) |
1356 | return; | |
1357 | ||
dea3101e JB |
1358 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
1359 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
1360 | ||
1361 | for (t = 0; t < 7; t++) | |
1362 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
1363 | ||
1364 | lpfc_sha_init(hbainit); | |
1365 | lpfc_sha_iterate(hbainit, HashWorking); | |
1366 | kfree(HashWorking); | |
1367 | } | |
1368 | ||
87af33fe | 1369 | void |
2e0fef85 | 1370 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 1371 | { |
87af33fe | 1372 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1373 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 1374 | int i = 0; |
dea3101e | 1375 | |
87af33fe JS |
1376 | if (phba->link_state > LPFC_LINK_DOWN) |
1377 | lpfc_port_link_failure(vport); | |
1378 | ||
1379 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
1380 | if (ndlp->nlp_type & NLP_FABRIC) | |
1381 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
1382 | NLP_EVT_DEVICE_RECOVERY); | |
1383 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
1384 | NLP_EVT_DEVICE_RM); | |
1385 | } | |
1386 | ||
a8adb832 JS |
1387 | /* At this point, ALL ndlp's should be gone |
1388 | * because of the previous NLP_EVT_DEVICE_RM. | |
1389 | * Lets wait for this to happen, if needed. | |
1390 | */ | |
87af33fe JS |
1391 | while (!list_empty(&vport->fc_nodes)) { |
1392 | ||
a8adb832 | 1393 | if (i++ > 3000) { |
87af33fe | 1394 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 JS |
1395 | "0233 Nodelist not empty\n"); |
1396 | break; | |
87af33fe | 1397 | } |
a8adb832 JS |
1398 | |
1399 | /* Wait for any activity on ndlps to settle */ | |
1400 | msleep(10); | |
87af33fe | 1401 | } |
dea3101e JB |
1402 | return; |
1403 | } | |
1404 | ||
1405 | static void | |
1406 | lpfc_establish_link_tmo(unsigned long ptr) | |
1407 | { | |
92d7f7b0 | 1408 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
549e55cd | 1409 | struct lpfc_vport **vports; |
dea3101e | 1410 | unsigned long iflag; |
549e55cd | 1411 | int i; |
dea3101e | 1412 | |
dea3101e JB |
1413 | /* Re-establishing Link, timer expired */ |
1414 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
e8b62011 | 1415 | "1300 Re-establishing Link, timer expired " |
dea3101e | 1416 | "Data: x%x x%x\n", |
e8b62011 | 1417 | phba->pport->fc_flag, phba->pport->port_state); |
549e55cd JS |
1418 | vports = lpfc_create_vport_work_array(phba); |
1419 | if (vports != NULL) | |
1420 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1421 | struct Scsi_Host *shost; | |
1422 | shost = lpfc_shost_from_vport(vports[i]); | |
1423 | spin_lock_irqsave(shost->host_lock, iflag); | |
1424 | vports[i]->fc_flag &= ~FC_ESTABLISH_LINK; | |
1425 | spin_unlock_irqrestore(shost->host_lock, iflag); | |
1426 | } | |
1427 | lpfc_destroy_vport_work_array(vports); | |
dea3101e JB |
1428 | } |
1429 | ||
92d7f7b0 JS |
1430 | void |
1431 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 1432 | { |
92d7f7b0 JS |
1433 | del_timer_sync(&vport->els_tmofunc); |
1434 | del_timer_sync(&vport->fc_fdmitmo); | |
1435 | lpfc_can_disctmo(vport); | |
1436 | return; | |
dea3101e JB |
1437 | } |
1438 | ||
2e0fef85 | 1439 | static void |
92d7f7b0 | 1440 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
dea3101e | 1441 | { |
875fbdfe | 1442 | del_timer_sync(&phba->fcp_poll_timer); |
dea3101e | 1443 | del_timer_sync(&phba->fc_estabtmo); |
51ef4c26 | 1444 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 1445 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 1446 | del_timer_sync(&phba->fabric_block_timer); |
858c9f6c JS |
1447 | phba->hb_outstanding = 0; |
1448 | del_timer_sync(&phba->hb_tmofunc); | |
2e0fef85 | 1449 | return; |
dea3101e JB |
1450 | } |
1451 | ||
a6ababd2 AB |
1452 | static void |
1453 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
1454 | { | |
1455 | unsigned long iflag; | |
1456 | ||
1457 | spin_lock_irqsave(&phba->hbalock, iflag); | |
1458 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
1459 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
1460 | } | |
1461 | ||
dea3101e | 1462 | int |
2e0fef85 | 1463 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 1464 | { |
2e0fef85 | 1465 | struct lpfc_vport *vport = phba->pport; |
549e55cd JS |
1466 | struct lpfc_vport **vports; |
1467 | int i; | |
2e0fef85 | 1468 | |
dea3101e JB |
1469 | if (!phba) |
1470 | return 0; | |
1471 | ||
2e0fef85 | 1472 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
1473 | return 0; |
1474 | ||
ed957684 | 1475 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 1476 | "0458 Bring Adapter online\n"); |
dea3101e | 1477 | |
46fa311e JS |
1478 | lpfc_block_mgmt_io(phba); |
1479 | ||
1480 | if (!lpfc_sli_queue_setup(phba)) { | |
1481 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 1482 | return 1; |
46fa311e | 1483 | } |
dea3101e | 1484 | |
46fa311e JS |
1485 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
1486 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 1487 | return 1; |
46fa311e | 1488 | } |
dea3101e | 1489 | |
549e55cd JS |
1490 | vports = lpfc_create_vport_work_array(phba); |
1491 | if (vports != NULL) | |
1492 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1493 | struct Scsi_Host *shost; | |
1494 | shost = lpfc_shost_from_vport(vports[i]); | |
1495 | spin_lock_irq(shost->host_lock); | |
1496 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
1497 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
1498 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1499 | spin_unlock_irq(shost->host_lock); | |
1500 | } | |
1501 | lpfc_destroy_vport_work_array(vports); | |
dea3101e | 1502 | |
46fa311e | 1503 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1504 | return 0; |
1505 | } | |
1506 | ||
46fa311e JS |
1507 | void |
1508 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
1509 | { | |
1510 | unsigned long iflag; | |
1511 | ||
2e0fef85 JS |
1512 | spin_lock_irqsave(&phba->hbalock, iflag); |
1513 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
1514 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
1515 | } |
1516 | ||
1517 | void | |
1518 | lpfc_offline_prep(struct lpfc_hba * phba) | |
1519 | { | |
2e0fef85 | 1520 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 1521 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe JS |
1522 | struct lpfc_vport **vports; |
1523 | int i; | |
dea3101e | 1524 | |
2e0fef85 | 1525 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 1526 | return; |
dea3101e | 1527 | |
46fa311e | 1528 | lpfc_block_mgmt_io(phba); |
dea3101e JB |
1529 | |
1530 | lpfc_linkdown(phba); | |
1531 | ||
87af33fe JS |
1532 | /* Issue an unreg_login to all nodes on all vports */ |
1533 | vports = lpfc_create_vport_work_array(phba); | |
1534 | if (vports != NULL) { | |
1535 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1536 | struct Scsi_Host *shost; | |
1537 | ||
a8adb832 JS |
1538 | if (vports[i]->load_flag & FC_UNLOADING) |
1539 | continue; | |
87af33fe JS |
1540 | shost = lpfc_shost_from_vport(vports[i]); |
1541 | list_for_each_entry_safe(ndlp, next_ndlp, | |
1542 | &vports[i]->fc_nodes, | |
1543 | nlp_listp) { | |
1544 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | |
1545 | continue; | |
1546 | if (ndlp->nlp_type & NLP_FABRIC) { | |
1547 | lpfc_disc_state_machine(vports[i], ndlp, | |
1548 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
1549 | lpfc_disc_state_machine(vports[i], ndlp, | |
1550 | NULL, NLP_EVT_DEVICE_RM); | |
1551 | } | |
1552 | spin_lock_irq(shost->host_lock); | |
1553 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
1554 | spin_unlock_irq(shost->host_lock); | |
1555 | lpfc_unreg_rpi(vports[i], ndlp); | |
1556 | } | |
1557 | } | |
1558 | } | |
1559 | lpfc_destroy_vport_work_array(vports); | |
dea3101e | 1560 | |
46fa311e JS |
1561 | lpfc_sli_flush_mbox_queue(phba); |
1562 | } | |
1563 | ||
1564 | void | |
2e0fef85 | 1565 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 1566 | { |
549e55cd JS |
1567 | struct Scsi_Host *shost; |
1568 | struct lpfc_vport **vports; | |
1569 | int i; | |
46fa311e | 1570 | |
549e55cd | 1571 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 1572 | return; |
688a8863 | 1573 | |
dea3101e | 1574 | /* stop all timers associated with this hba */ |
92d7f7b0 | 1575 | lpfc_stop_phba_timers(phba); |
51ef4c26 JS |
1576 | vports = lpfc_create_vport_work_array(phba); |
1577 | if (vports != NULL) | |
1578 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) | |
1579 | lpfc_stop_vport_timers(vports[i]); | |
1580 | lpfc_destroy_vport_work_array(vports); | |
92d7f7b0 | 1581 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 1582 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
1583 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
1584 | now. */ | |
1585 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 1586 | spin_lock_irq(&phba->hbalock); |
7054a606 | 1587 | phba->work_ha = 0; |
92d7f7b0 | 1588 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
1589 | vports = lpfc_create_vport_work_array(phba); |
1590 | if (vports != NULL) | |
1591 | for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) { | |
1592 | shost = lpfc_shost_from_vport(vports[i]); | |
549e55cd JS |
1593 | spin_lock_irq(shost->host_lock); |
1594 | vports[i]->work_port_events = 0; | |
1595 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
1596 | spin_unlock_irq(shost->host_lock); | |
1597 | } | |
1598 | lpfc_destroy_vport_work_array(vports); | |
dea3101e JB |
1599 | } |
1600 | ||
1601 | /****************************************************************************** | |
1602 | * Function name: lpfc_scsi_free | |
1603 | * | |
1604 | * Description: Called from lpfc_pci_remove_one free internal driver resources | |
1605 | * | |
1606 | ******************************************************************************/ | |
1607 | static int | |
2e0fef85 | 1608 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
1609 | { |
1610 | struct lpfc_scsi_buf *sb, *sb_next; | |
1611 | struct lpfc_iocbq *io, *io_next; | |
1612 | ||
2e0fef85 | 1613 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1614 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1615 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { | |
1616 | list_del(&sb->list); | |
1617 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 1618 | sb->dma_handle); |
dea3101e JB |
1619 | kfree(sb); |
1620 | phba->total_scsi_bufs--; | |
1621 | } | |
1622 | ||
1623 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
1624 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
1625 | list_del(&io->list); | |
1626 | kfree(io); | |
1627 | phba->total_iocbq_bufs--; | |
1628 | } | |
1629 | ||
2e0fef85 | 1630 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1631 | |
1632 | return 0; | |
1633 | } | |
1634 | ||
2e0fef85 | 1635 | struct lpfc_vport * |
3de2a653 | 1636 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 1637 | { |
2e0fef85 JS |
1638 | struct lpfc_vport *vport; |
1639 | struct Scsi_Host *shost; | |
1640 | int error = 0; | |
47a8617c | 1641 | |
3de2a653 JS |
1642 | if (dev != &phba->pcidev->dev) |
1643 | shost = scsi_host_alloc(&lpfc_vport_template, | |
1644 | sizeof(struct lpfc_vport)); | |
1645 | else | |
1646 | shost = scsi_host_alloc(&lpfc_template, | |
1647 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
1648 | if (!shost) |
1649 | goto out; | |
47a8617c | 1650 | |
2e0fef85 JS |
1651 | vport = (struct lpfc_vport *) shost->hostdata; |
1652 | vport->phba = phba; | |
47a8617c | 1653 | |
2e0fef85 | 1654 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 1655 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
47a8617c | 1656 | |
3de2a653 | 1657 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
1658 | shost->unique_id = instance; |
1659 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 1660 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
1661 | shost->this_id = -1; |
1662 | shost->max_cmd_len = 16; | |
47a8617c | 1663 | /* |
2e0fef85 JS |
1664 | * Set initial can_queue value since 0 is no longer supported and |
1665 | * scsi_add_host will fail. This will be adjusted later based on the | |
1666 | * max xri value determined in hba setup. | |
47a8617c | 1667 | */ |
2e0fef85 | 1668 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 1669 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
1670 | shost->transportt = lpfc_vport_transport_template; |
1671 | vport->port_type = LPFC_NPIV_PORT; | |
1672 | } else { | |
1673 | shost->transportt = lpfc_transport_template; | |
1674 | vport->port_type = LPFC_PHYSICAL_PORT; | |
1675 | } | |
47a8617c | 1676 | |
2e0fef85 JS |
1677 | /* Initialize all internally managed lists. */ |
1678 | INIT_LIST_HEAD(&vport->fc_nodes); | |
1679 | spin_lock_init(&vport->work_port_lock); | |
47a8617c | 1680 | |
2e0fef85 JS |
1681 | init_timer(&vport->fc_disctmo); |
1682 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 1683 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 1684 | |
2e0fef85 JS |
1685 | init_timer(&vport->fc_fdmitmo); |
1686 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 1687 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 1688 | |
2e0fef85 JS |
1689 | init_timer(&vport->els_tmofunc); |
1690 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 1691 | vport->els_tmofunc.data = (unsigned long)vport; |
47a8617c | 1692 | |
3de2a653 | 1693 | error = scsi_add_host(shost, dev); |
2e0fef85 JS |
1694 | if (error) |
1695 | goto out_put_shost; | |
47a8617c | 1696 | |
549e55cd | 1697 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 1698 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 1699 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 1700 | return vport; |
47a8617c | 1701 | |
2e0fef85 JS |
1702 | out_put_shost: |
1703 | scsi_host_put(shost); | |
1704 | out: | |
1705 | return NULL; | |
47a8617c JS |
1706 | } |
1707 | ||
2e0fef85 JS |
1708 | void |
1709 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 1710 | { |
92d7f7b0 JS |
1711 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1712 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 1713 | |
92d7f7b0 | 1714 | kfree(vport->vname); |
47a8617c | 1715 | |
858c9f6c | 1716 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
1717 | fc_remove_host(shost); |
1718 | scsi_remove_host(shost); | |
47a8617c | 1719 | |
92d7f7b0 JS |
1720 | spin_lock_irq(&phba->hbalock); |
1721 | list_del_init(&vport->listentry); | |
1722 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 1723 | |
92d7f7b0 | 1724 | lpfc_cleanup(vport); |
47a8617c | 1725 | return; |
47a8617c JS |
1726 | } |
1727 | ||
92d7f7b0 JS |
1728 | int |
1729 | lpfc_get_instance(void) | |
1730 | { | |
1731 | int instance = 0; | |
47a8617c | 1732 | |
92d7f7b0 JS |
1733 | /* Assign an unused number */ |
1734 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
1735 | return -1; | |
1736 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
1737 | return -1; | |
1738 | return instance; | |
47a8617c JS |
1739 | } |
1740 | ||
858c9f6c JS |
1741 | /* |
1742 | * Note: there is no scan_start function as adapter initialization | |
1743 | * will have asynchronously kicked off the link initialization. | |
1744 | */ | |
47a8617c JS |
1745 | |
1746 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
1747 | { | |
2e0fef85 JS |
1748 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1749 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 1750 | int stat = 0; |
47a8617c | 1751 | |
858c9f6c JS |
1752 | spin_lock_irq(shost->host_lock); |
1753 | ||
51ef4c26 | 1754 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
1755 | stat = 1; |
1756 | goto finished; | |
1757 | } | |
2e0fef85 JS |
1758 | if (time >= 30 * HZ) { |
1759 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
1760 | "0461 Scanning longer than 30 " |
1761 | "seconds. Continuing initialization\n"); | |
858c9f6c | 1762 | stat = 1; |
47a8617c | 1763 | goto finished; |
2e0fef85 JS |
1764 | } |
1765 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
1766 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
1767 | "0465 Link down longer than 15 " |
1768 | "seconds. Continuing initialization\n"); | |
858c9f6c | 1769 | stat = 1; |
47a8617c | 1770 | goto finished; |
2e0fef85 | 1771 | } |
47a8617c | 1772 | |
2e0fef85 | 1773 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 1774 | goto finished; |
2e0fef85 | 1775 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 1776 | goto finished; |
2e0fef85 | 1777 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 1778 | goto finished; |
2e0fef85 | 1779 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
1780 | goto finished; |
1781 | ||
1782 | stat = 1; | |
47a8617c JS |
1783 | |
1784 | finished: | |
858c9f6c JS |
1785 | spin_unlock_irq(shost->host_lock); |
1786 | return stat; | |
92d7f7b0 | 1787 | } |
47a8617c | 1788 | |
92d7f7b0 JS |
1789 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
1790 | { | |
1791 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1792 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 1793 | /* |
2e0fef85 | 1794 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
1795 | */ |
1796 | ||
2e0fef85 JS |
1797 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
1798 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
1799 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
1800 | ||
1801 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 1802 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
1803 | fc_host_supported_fc4s(shost)[2] = 1; |
1804 | fc_host_supported_fc4s(shost)[7] = 1; | |
1805 | ||
92d7f7b0 JS |
1806 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
1807 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
1808 | |
1809 | fc_host_supported_speeds(shost) = 0; | |
1810 | if (phba->lmt & LMT_10Gb) | |
1811 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
1812 | if (phba->lmt & LMT_8Gb) |
1813 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
1814 | if (phba->lmt & LMT_4Gb) |
1815 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
1816 | if (phba->lmt & LMT_2Gb) | |
1817 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
1818 | if (phba->lmt & LMT_1Gb) | |
1819 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
1820 | ||
1821 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
1822 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
1823 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c JS |
1824 | |
1825 | /* This value is also unchanging */ | |
1826 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 1827 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
1828 | fc_host_active_fc4s(shost)[2] = 1; |
1829 | fc_host_active_fc4s(shost)[7] = 1; | |
1830 | ||
92d7f7b0 | 1831 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 1832 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 1833 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 1834 | spin_unlock_irq(shost->host_lock); |
47a8617c | 1835 | } |
dea3101e JB |
1836 | |
1837 | static int __devinit | |
1838 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
1839 | { | |
2e0fef85 JS |
1840 | struct lpfc_vport *vport = NULL; |
1841 | struct lpfc_hba *phba; | |
1842 | struct lpfc_sli *psli; | |
dea3101e | 1843 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
2e0fef85 | 1844 | struct Scsi_Host *shost = NULL; |
51ef4c26 | 1845 | void *ptr; |
dea3101e | 1846 | unsigned long bar0map_len, bar2map_len; |
98c9ea5c | 1847 | int error = -ENODEV, retval; |
51ef4c26 | 1848 | int i, hbq_count; |
604a3e30 | 1849 | uint16_t iotag; |
dea3101e JB |
1850 | |
1851 | if (pci_enable_device(pdev)) | |
1852 | goto out; | |
1853 | if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) | |
1854 | goto out_disable_device; | |
1855 | ||
2e0fef85 JS |
1856 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
1857 | if (!phba) | |
dea3101e JB |
1858 | goto out_release_regions; |
1859 | ||
2e0fef85 | 1860 | spin_lock_init(&phba->hbalock); |
dea3101e | 1861 | |
dea3101e JB |
1862 | phba->pcidev = pdev; |
1863 | ||
1864 | /* Assign an unused board number */ | |
92d7f7b0 | 1865 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
2e0fef85 | 1866 | goto out_free_phba; |
dea3101e | 1867 | |
2e0fef85 | 1868 | INIT_LIST_HEAD(&phba->port_list); |
2e0fef85 JS |
1869 | /* |
1870 | * Get all the module params for configuring this host and then | |
1871 | * establish the host. | |
1872 | */ | |
1873 | lpfc_get_cfgparam(phba); | |
92d7f7b0 | 1874 | phba->max_vpi = LPFC_MAX_VPI; |
dea3101e JB |
1875 | |
1876 | /* Initialize timers used by driver */ | |
1877 | init_timer(&phba->fc_estabtmo); | |
1878 | phba->fc_estabtmo.function = lpfc_establish_link_tmo; | |
1879 | phba->fc_estabtmo.data = (unsigned long)phba; | |
858c9f6c JS |
1880 | |
1881 | init_timer(&phba->hb_tmofunc); | |
1882 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
1883 | phba->hb_tmofunc.data = (unsigned long)phba; | |
1884 | ||
dea3101e JB |
1885 | psli = &phba->sli; |
1886 | init_timer(&psli->mbox_tmo); | |
1887 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 1888 | psli->mbox_tmo.data = (unsigned long) phba; |
875fbdfe JSEC |
1889 | init_timer(&phba->fcp_poll_timer); |
1890 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 1891 | phba->fcp_poll_timer.data = (unsigned long) phba; |
92d7f7b0 JS |
1892 | init_timer(&phba->fabric_block_timer); |
1893 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
1894 | phba->fabric_block_timer.data = (unsigned long) phba; | |
dea3101e | 1895 | |
dea3101e | 1896 | pci_set_master(pdev); |
694625c0 | 1897 | pci_try_set_mwi(pdev); |
dea3101e JB |
1898 | |
1899 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) | |
1900 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) | |
1901 | goto out_idr_remove; | |
1902 | ||
1903 | /* | |
1904 | * Get the bus address of Bar0 and Bar2 and the number of bytes | |
1905 | * required by each mapping. | |
1906 | */ | |
1907 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); | |
1908 | bar0map_len = pci_resource_len(phba->pcidev, 0); | |
1909 | ||
1910 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); | |
1911 | bar2map_len = pci_resource_len(phba->pcidev, 2); | |
1912 | ||
901a920f | 1913 | /* Map HBA SLIM to a kernel virtual address. */ |
dea3101e | 1914 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
901a920f JW |
1915 | if (!phba->slim_memmap_p) { |
1916 | error = -ENODEV; | |
1917 | dev_printk(KERN_ERR, &pdev->dev, | |
1918 | "ioremap failed for SLIM memory.\n"); | |
1919 | goto out_idr_remove; | |
1920 | } | |
1921 | ||
1922 | /* Map HBA Control Registers to a kernel virtual address. */ | |
dea3101e | 1923 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
901a920f JW |
1924 | if (!phba->ctrl_regs_memmap_p) { |
1925 | error = -ENODEV; | |
1926 | dev_printk(KERN_ERR, &pdev->dev, | |
1927 | "ioremap failed for HBA control registers.\n"); | |
1928 | goto out_iounmap_slim; | |
1929 | } | |
dea3101e JB |
1930 | |
1931 | /* Allocate memory for SLI-2 structures */ | |
1932 | phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE, | |
1933 | &phba->slim2p_mapping, GFP_KERNEL); | |
1934 | if (!phba->slim2p) | |
1935 | goto out_iounmap; | |
1936 | ||
f91b392c | 1937 | memset(phba->slim2p, 0, SLI2_SLIM_SIZE); |
dea3101e | 1938 | |
ed957684 JS |
1939 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
1940 | lpfc_sli_hbq_size(), | |
1941 | &phba->hbqslimp.phys, | |
1942 | GFP_KERNEL); | |
1943 | if (!phba->hbqslimp.virt) | |
1944 | goto out_free_slim; | |
1945 | ||
51ef4c26 JS |
1946 | hbq_count = lpfc_sli_hbq_count(); |
1947 | ptr = phba->hbqslimp.virt; | |
1948 | for (i = 0; i < hbq_count; ++i) { | |
1949 | phba->hbqs[i].hbq_virt = ptr; | |
1950 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
1951 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
1952 | sizeof(struct lpfc_hbq_entry)); | |
1953 | } | |
1954 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
1955 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
1956 | ||
ed957684 JS |
1957 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
1958 | ||
dea3101e JB |
1959 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
1960 | lpfc_sli_setup(phba); | |
1961 | lpfc_sli_queue_setup(phba); | |
1962 | ||
98c9ea5c JS |
1963 | retval = lpfc_mem_alloc(phba); |
1964 | if (retval) { | |
1965 | error = retval; | |
ed957684 | 1966 | goto out_free_hbqslimp; |
98c9ea5c | 1967 | } |
dea3101e JB |
1968 | |
1969 | /* Initialize and populate the iocb list per host. */ | |
1970 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
1971 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { | |
dd00cc48 | 1972 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
1973 | if (iocbq_entry == NULL) { |
1974 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
1975 | "expected %d count. Unloading driver.\n", | |
1976 | __FUNCTION__, i, LPFC_IOCB_LIST_CNT); | |
1977 | error = -ENOMEM; | |
1978 | goto out_free_iocbq; | |
1979 | } | |
1980 | ||
604a3e30 JB |
1981 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
1982 | if (iotag == 0) { | |
1983 | kfree (iocbq_entry); | |
1984 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | |
1985 | "Unloading driver.\n", | |
1986 | __FUNCTION__); | |
1987 | error = -ENOMEM; | |
1988 | goto out_free_iocbq; | |
1989 | } | |
2e0fef85 JS |
1990 | |
1991 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
1992 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
1993 | phba->total_iocbq_bufs++; | |
2e0fef85 | 1994 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1995 | } |
1996 | ||
1997 | /* Initialize HBA structure */ | |
1998 | phba->fc_edtov = FF_DEF_EDTOV; | |
1999 | phba->fc_ratov = FF_DEF_RATOV; | |
2000 | phba->fc_altov = FF_DEF_ALTOV; | |
2001 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
2002 | ||
2003 | INIT_LIST_HEAD(&phba->work_list); | |
2004 | phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT); | |
2005 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
2006 | ||
2007 | /* Startup the kernel thread for this host adapter. */ | |
2008 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
2009 | "lpfc_worker_%d", phba->brd_no); | |
2010 | if (IS_ERR(phba->worker_thread)) { | |
2011 | error = PTR_ERR(phba->worker_thread); | |
2012 | goto out_free_iocbq; | |
2013 | } | |
2014 | ||
dea3101e | 2015 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ |
875fbdfe | 2016 | spin_lock_init(&phba->scsi_buf_list_lock); |
dea3101e JB |
2017 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
2018 | ||
92d7f7b0 JS |
2019 | /* Initialize list of fabric iocbs */ |
2020 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
2021 | ||
0ff10d46 JS |
2022 | /* Initialize list to save ELS buffers */ |
2023 | INIT_LIST_HEAD(&phba->elsbuf); | |
2024 | ||
3de2a653 | 2025 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
2e0fef85 JS |
2026 | if (!vport) |
2027 | goto out_kthread_stop; | |
2028 | ||
2029 | shost = lpfc_shost_from_vport(vport); | |
2e0fef85 | 2030 | phba->pport = vport; |
858c9f6c | 2031 | lpfc_debugfs_initialize(vport); |
2e0fef85 | 2032 | |
92d7f7b0 | 2033 | pci_set_drvdata(pdev, shost); |
dea3101e | 2034 | |
4ff43246 | 2035 | if (phba->cfg_use_msi) { |
98c9ea5c JS |
2036 | retval = pci_enable_msi(phba->pcidev); |
2037 | if (!retval) | |
51ef4c26 JS |
2038 | phba->using_msi = 1; |
2039 | else | |
e8b62011 JS |
2040 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2041 | "0452 Enable MSI failed, continuing " | |
2042 | "with IRQ\n"); | |
4ff43246 JS |
2043 | } |
2044 | ||
98c9ea5c | 2045 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED, |
2e0fef85 | 2046 | LPFC_DRIVER_NAME, phba); |
98c9ea5c | 2047 | if (retval) { |
dea3101e | 2048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 2049 | "0451 Enable interrupt handler failed\n"); |
98c9ea5c | 2050 | error = retval; |
92d7f7b0 | 2051 | goto out_disable_msi; |
dea3101e | 2052 | } |
dea3101e | 2053 | |
2e0fef85 JS |
2054 | phba->MBslimaddr = phba->slim_memmap_p; |
2055 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
2056 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
2057 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
2058 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
2059 | ||
98c9ea5c JS |
2060 | if (lpfc_alloc_sysfs_attr(vport)) { |
2061 | error = -ENOMEM; | |
dea3101e | 2062 | goto out_free_irq; |
98c9ea5c | 2063 | } |
875fbdfe | 2064 | |
98c9ea5c JS |
2065 | if (lpfc_sli_hba_setup(phba)) { |
2066 | error = -ENODEV; | |
858c9f6c | 2067 | goto out_remove_device; |
98c9ea5c | 2068 | } |
858c9f6c JS |
2069 | |
2070 | /* | |
2071 | * hba setup may have changed the hba_queue_depth so we need to adjust | |
2072 | * the value of can_queue. | |
2073 | */ | |
2074 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
2075 | ||
2076 | lpfc_host_attrib_init(shost); | |
2077 | ||
2e0fef85 JS |
2078 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
2079 | spin_lock_irq(shost->host_lock); | |
2080 | lpfc_poll_start_timer(phba); | |
2081 | spin_unlock_irq(shost->host_lock); | |
2082 | } | |
dea3101e | 2083 | |
858c9f6c | 2084 | scsi_scan_host(shost); |
dea3101e | 2085 | |
dea3101e JB |
2086 | return 0; |
2087 | ||
858c9f6c JS |
2088 | out_remove_device: |
2089 | lpfc_free_sysfs_attr(vport); | |
2090 | spin_lock_irq(shost->host_lock); | |
51ef4c26 | 2091 | vport->load_flag |= FC_UNLOADING; |
858c9f6c | 2092 | spin_unlock_irq(shost->host_lock); |
dea3101e | 2093 | out_free_irq: |
92d7f7b0 | 2094 | lpfc_stop_phba_timers(phba); |
2e0fef85 | 2095 | phba->pport->work_port_events = 0; |
dea3101e | 2096 | free_irq(phba->pcidev->irq, phba); |
92d7f7b0 | 2097 | out_disable_msi: |
51ef4c26 JS |
2098 | if (phba->using_msi) |
2099 | pci_disable_msi(phba->pcidev); | |
2e0fef85 | 2100 | destroy_port(vport); |
dea3101e JB |
2101 | out_kthread_stop: |
2102 | kthread_stop(phba->worker_thread); | |
2103 | out_free_iocbq: | |
2104 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
2105 | &phba->lpfc_iocb_list, list) { | |
dea3101e JB |
2106 | kfree(iocbq_entry); |
2107 | phba->total_iocbq_bufs--; | |
dea3101e JB |
2108 | } |
2109 | lpfc_mem_free(phba); | |
ed957684 JS |
2110 | out_free_hbqslimp: |
2111 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, | |
2112 | phba->hbqslimp.phys); | |
dea3101e JB |
2113 | out_free_slim: |
2114 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p, | |
2115 | phba->slim2p_mapping); | |
2116 | out_iounmap: | |
2117 | iounmap(phba->ctrl_regs_memmap_p); | |
901a920f | 2118 | out_iounmap_slim: |
dea3101e JB |
2119 | iounmap(phba->slim_memmap_p); |
2120 | out_idr_remove: | |
2121 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
2e0fef85 JS |
2122 | out_free_phba: |
2123 | kfree(phba); | |
dea3101e JB |
2124 | out_release_regions: |
2125 | pci_release_regions(pdev); | |
2126 | out_disable_device: | |
2127 | pci_disable_device(pdev); | |
2128 | out: | |
defbcf11 | 2129 | pci_set_drvdata(pdev, NULL); |
858c9f6c JS |
2130 | if (shost) |
2131 | scsi_host_put(shost); | |
dea3101e JB |
2132 | return error; |
2133 | } | |
2134 | ||
2135 | static void __devexit | |
2136 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
2137 | { | |
2e0fef85 JS |
2138 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2139 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2140 | struct lpfc_hba *phba = vport->phba; | |
549e55cd | 2141 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 2142 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 2143 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2144 | |
858c9f6c JS |
2145 | kfree(vport->vname); |
2146 | lpfc_free_sysfs_attr(vport); | |
2147 | ||
2148 | fc_remove_host(shost); | |
2149 | scsi_remove_host(shost); | |
87af33fe JS |
2150 | lpfc_cleanup(vport); |
2151 | ||
2e0fef85 JS |
2152 | /* |
2153 | * Bring down the SLI Layer. This step disable all interrupts, | |
2154 | * clears the rings, discards all mailbox commands, and resets | |
2155 | * the HBA. | |
2156 | */ | |
2157 | lpfc_sli_hba_down(phba); | |
2158 | lpfc_sli_brdrestart(phba); | |
2159 | ||
92d7f7b0 | 2160 | lpfc_stop_phba_timers(phba); |
858c9f6c JS |
2161 | spin_lock_irq(&phba->hbalock); |
2162 | list_del_init(&vport->listentry); | |
2163 | spin_unlock_irq(&phba->hbalock); | |
2164 | ||
858c9f6c | 2165 | lpfc_debugfs_terminate(vport); |
2e0fef85 JS |
2166 | |
2167 | kthread_stop(phba->worker_thread); | |
2168 | ||
2169 | /* Release the irq reservation */ | |
2170 | free_irq(phba->pcidev->irq, phba); | |
51ef4c26 JS |
2171 | if (phba->using_msi) |
2172 | pci_disable_msi(phba->pcidev); | |
dea3101e JB |
2173 | |
2174 | pci_set_drvdata(pdev, NULL); | |
858c9f6c | 2175 | scsi_host_put(shost); |
2e0fef85 JS |
2176 | |
2177 | /* | |
2178 | * Call scsi_free before mem_free since scsi bufs are released to their | |
2179 | * corresponding pools here. | |
2180 | */ | |
2181 | lpfc_scsi_free(phba); | |
2182 | lpfc_mem_free(phba); | |
2183 | ||
ed957684 JS |
2184 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt, |
2185 | phba->hbqslimp.phys); | |
2186 | ||
2e0fef85 JS |
2187 | /* Free resources associated with SLI2 interface */ |
2188 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
2189 | phba->slim2p, phba->slim2p_mapping); | |
2190 | ||
2191 | /* unmap adapter SLIM and Control Registers */ | |
2192 | iounmap(phba->ctrl_regs_memmap_p); | |
2193 | iounmap(phba->slim_memmap_p); | |
2194 | ||
2195 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
2196 | ||
2197 | kfree(phba); | |
2198 | ||
2199 | pci_release_regions(pdev); | |
2200 | pci_disable_device(pdev); | |
dea3101e JB |
2201 | } |
2202 | ||
8d63f375 LV |
2203 | /** |
2204 | * lpfc_io_error_detected - called when PCI error is detected | |
2205 | * @pdev: Pointer to PCI device | |
2206 | * @state: The current pci conneection state | |
2207 | * | |
2208 | * This function is called after a PCI bus error affecting | |
2209 | * this device has been detected. | |
2210 | */ | |
2211 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | |
2212 | pci_channel_state_t state) | |
2213 | { | |
51ef4c26 JS |
2214 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2215 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2216 | struct lpfc_sli *psli = &phba->sli; |
2217 | struct lpfc_sli_ring *pring; | |
2218 | ||
5daa49ef | 2219 | if (state == pci_channel_io_perm_failure) |
8d63f375 | 2220 | return PCI_ERS_RESULT_DISCONNECT; |
5daa49ef | 2221 | |
8d63f375 LV |
2222 | pci_disable_device(pdev); |
2223 | /* | |
2224 | * There may be I/Os dropped by the firmware. | |
2225 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
2226 | * retry it after re-establishing link. | |
2227 | */ | |
2228 | pring = &psli->ring[psli->fcp_ring]; | |
2229 | lpfc_sli_abort_iocb_ring(phba, pring); | |
2230 | ||
51ef4c26 JS |
2231 | /* Release the irq reservation */ |
2232 | free_irq(phba->pcidev->irq, phba); | |
2233 | if (phba->using_msi) | |
2234 | pci_disable_msi(phba->pcidev); | |
2235 | ||
8d63f375 LV |
2236 | /* Request a slot reset. */ |
2237 | return PCI_ERS_RESULT_NEED_RESET; | |
2238 | } | |
2239 | ||
2240 | /** | |
2241 | * lpfc_io_slot_reset - called after the pci bus has been reset. | |
2242 | * @pdev: Pointer to PCI device | |
2243 | * | |
2244 | * Restart the card from scratch, as if from a cold-boot. | |
2245 | */ | |
2246 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |
2247 | { | |
51ef4c26 JS |
2248 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2249 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2250 | struct lpfc_sli *psli = &phba->sli; |
2251 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
2252 | ||
2253 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
2254 | if (pci_enable_device_bars(pdev, bars)) { | |
2255 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
2256 | "PCI device after reset.\n"); | |
2257 | return PCI_ERS_RESULT_DISCONNECT; | |
2258 | } | |
2259 | ||
2260 | pci_set_master(pdev); | |
2261 | ||
2262 | /* Re-establishing Link */ | |
51ef4c26 | 2263 | spin_lock_irq(shost->host_lock); |
92d7f7b0 | 2264 | phba->pport->fc_flag |= FC_ESTABLISH_LINK; |
51ef4c26 | 2265 | spin_unlock_irq(shost->host_lock); |
8d63f375 | 2266 | |
92d7f7b0 | 2267 | spin_lock_irq(&phba->hbalock); |
8d63f375 | 2268 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
92d7f7b0 | 2269 | spin_unlock_irq(&phba->hbalock); |
8d63f375 LV |
2270 | |
2271 | ||
2272 | /* Take device offline; this will perform cleanup */ | |
2273 | lpfc_offline(phba); | |
2274 | lpfc_sli_brdrestart(phba); | |
2275 | ||
2276 | return PCI_ERS_RESULT_RECOVERED; | |
2277 | } | |
2278 | ||
2279 | /** | |
2280 | * lpfc_io_resume - called when traffic can start flowing again. | |
2281 | * @pdev: Pointer to PCI device | |
2282 | * | |
2283 | * This callback is called when the error recovery driver tells us that | |
2284 | * its OK to resume normal operation. | |
2285 | */ | |
2286 | static void lpfc_io_resume(struct pci_dev *pdev) | |
2287 | { | |
51ef4c26 JS |
2288 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2289 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8d63f375 LV |
2290 | |
2291 | if (lpfc_online(phba) == 0) { | |
2292 | mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); | |
2293 | } | |
2294 | } | |
2295 | ||
dea3101e JB |
2296 | static struct pci_device_id lpfc_id_table[] = { |
2297 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
2298 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
2299 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
2300 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2301 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
2302 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2303 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
2304 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2305 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
2306 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2307 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
2308 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2309 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
2310 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2311 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
2312 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2313 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
2314 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2315 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
2316 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2317 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
2318 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2319 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
2320 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2321 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
2322 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2323 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
2324 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2325 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
2326 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2327 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
2328 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2329 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
2330 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2331 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
2332 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2333 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
2334 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2335 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
2336 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2337 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
2338 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2339 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
2340 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2341 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
2342 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2343 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
2344 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2345 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
2346 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
2347 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
2348 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2349 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
2350 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
2351 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
2352 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2353 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
2354 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2355 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
2356 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2357 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
2358 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2359 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
2360 | PCI_ANY_ID, PCI_ANY_ID, }, | |
2361 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
2362 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
2363 | { 0 } |
2364 | }; | |
2365 | ||
2366 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
2367 | ||
8d63f375 LV |
2368 | static struct pci_error_handlers lpfc_err_handler = { |
2369 | .error_detected = lpfc_io_error_detected, | |
2370 | .slot_reset = lpfc_io_slot_reset, | |
2371 | .resume = lpfc_io_resume, | |
2372 | }; | |
2373 | ||
dea3101e JB |
2374 | static struct pci_driver lpfc_driver = { |
2375 | .name = LPFC_DRIVER_NAME, | |
2376 | .id_table = lpfc_id_table, | |
2377 | .probe = lpfc_pci_probe_one, | |
2378 | .remove = __devexit_p(lpfc_pci_remove_one), | |
2e0fef85 | 2379 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
2380 | }; |
2381 | ||
2382 | static int __init | |
2383 | lpfc_init(void) | |
2384 | { | |
2385 | int error = 0; | |
2386 | ||
2387 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 2388 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 2389 | |
7ee5d43e JS |
2390 | if (lpfc_enable_npiv) { |
2391 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
2392 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
2393 | } | |
dea3101e JB |
2394 | lpfc_transport_template = |
2395 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 2396 | if (lpfc_transport_template == NULL) |
dea3101e | 2397 | return -ENOMEM; |
7ee5d43e | 2398 | if (lpfc_enable_npiv) { |
7ee5d43e | 2399 | lpfc_vport_transport_template = |
98c9ea5c JS |
2400 | fc_attach_transport(&lpfc_vport_transport_functions); |
2401 | if (lpfc_vport_transport_template == NULL) { | |
2402 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 2403 | return -ENOMEM; |
98c9ea5c | 2404 | } |
7ee5d43e | 2405 | } |
dea3101e | 2406 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 2407 | if (error) { |
dea3101e | 2408 | fc_release_transport(lpfc_transport_template); |
92d7f7b0 JS |
2409 | fc_release_transport(lpfc_vport_transport_template); |
2410 | } | |
dea3101e JB |
2411 | |
2412 | return error; | |
2413 | } | |
2414 | ||
2415 | static void __exit | |
2416 | lpfc_exit(void) | |
2417 | { | |
2418 | pci_unregister_driver(&lpfc_driver); | |
2419 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
2420 | if (lpfc_enable_npiv) |
2421 | fc_release_transport(lpfc_vport_transport_template); | |
dea3101e JB |
2422 | } |
2423 | ||
2424 | module_init(lpfc_init); | |
2425 | module_exit(lpfc_exit); | |
2426 | MODULE_LICENSE("GPL"); | |
2427 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
2428 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
2429 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |