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