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