2 * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
4 * Copyright (c) 2008-2009 USI Co., Ltd.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
41 #include <linux/slab.h>
42 #include "pm8001_sas.h"
43 #include "pm8001_chips.h"
45 static struct scsi_transport_template
*pm8001_stt
;
47 static const struct pm8001_chip_info pm8001_chips
[] = {
48 [chip_8001
] = { 8, &pm8001_8001_dispatch
,},
54 struct workqueue_struct
*pm8001_wq
;
57 * The main structure which LLDD must register for scsi core.
59 static struct scsi_host_template pm8001_sht
= {
60 .module
= THIS_MODULE
,
62 .queuecommand
= sas_queuecommand
,
63 .target_alloc
= sas_target_alloc
,
64 .slave_configure
= sas_slave_configure
,
65 .scan_finished
= pm8001_scan_finished
,
66 .scan_start
= pm8001_scan_start
,
67 .change_queue_depth
= sas_change_queue_depth
,
68 .change_queue_type
= sas_change_queue_type
,
69 .bios_param
= sas_bios_param
,
73 .sg_tablesize
= SG_ALL
,
74 .max_sectors
= SCSI_DEFAULT_MAX_SECTORS
,
75 .use_clustering
= ENABLE_CLUSTERING
,
76 .eh_device_reset_handler
= sas_eh_device_reset_handler
,
77 .eh_bus_reset_handler
= sas_eh_bus_reset_handler
,
78 .target_destroy
= sas_target_destroy
,
80 .shost_attrs
= pm8001_host_attrs
,
84 * Sas layer call this function to execute specific task.
86 static struct sas_domain_function_template pm8001_transport_ops
= {
87 .lldd_dev_found
= pm8001_dev_found
,
88 .lldd_dev_gone
= pm8001_dev_gone
,
90 .lldd_execute_task
= pm8001_queue_command
,
91 .lldd_control_phy
= pm8001_phy_control
,
93 .lldd_abort_task
= pm8001_abort_task
,
94 .lldd_abort_task_set
= pm8001_abort_task_set
,
95 .lldd_clear_aca
= pm8001_clear_aca
,
96 .lldd_clear_task_set
= pm8001_clear_task_set
,
97 .lldd_I_T_nexus_reset
= pm8001_I_T_nexus_reset
,
98 .lldd_lu_reset
= pm8001_lu_reset
,
99 .lldd_query_task
= pm8001_query_task
,
103 *pm8001_phy_init - initiate our adapter phys
104 *@pm8001_ha: our hba structure.
107 static void __devinit
pm8001_phy_init(struct pm8001_hba_info
*pm8001_ha
,
110 struct pm8001_phy
*phy
= &pm8001_ha
->phy
[phy_id
];
111 struct asd_sas_phy
*sas_phy
= &phy
->sas_phy
;
113 phy
->pm8001_ha
= pm8001_ha
;
114 sas_phy
->enabled
= (phy_id
< pm8001_ha
->chip
->n_phy
) ? 1 : 0;
115 sas_phy
->class = SAS
;
116 sas_phy
->iproto
= SAS_PROTOCOL_ALL
;
118 sas_phy
->type
= PHY_TYPE_PHYSICAL
;
119 sas_phy
->role
= PHY_ROLE_INITIATOR
;
120 sas_phy
->oob_mode
= OOB_NOT_CONNECTED
;
121 sas_phy
->linkrate
= SAS_LINK_RATE_UNKNOWN
;
122 sas_phy
->id
= phy_id
;
123 sas_phy
->sas_addr
= &pm8001_ha
->sas_addr
[0];
124 sas_phy
->frame_rcvd
= &phy
->frame_rcvd
[0];
125 sas_phy
->ha
= (struct sas_ha_struct
*)pm8001_ha
->shost
->hostdata
;
126 sas_phy
->lldd_phy
= phy
;
130 *pm8001_free - free hba
131 *@pm8001_ha: our hba structure.
134 static void pm8001_free(struct pm8001_hba_info
*pm8001_ha
)
141 for (i
= 0; i
< USI_MAX_MEMCNT
; i
++) {
142 if (pm8001_ha
->memoryMap
.region
[i
].virt_ptr
!= NULL
) {
143 pci_free_consistent(pm8001_ha
->pdev
,
144 pm8001_ha
->memoryMap
.region
[i
].element_size
,
145 pm8001_ha
->memoryMap
.region
[i
].virt_ptr
,
146 pm8001_ha
->memoryMap
.region
[i
].phys_addr
);
149 PM8001_CHIP_DISP
->chip_iounmap(pm8001_ha
);
150 if (pm8001_ha
->shost
)
151 scsi_host_put(pm8001_ha
->shost
);
152 flush_workqueue(pm8001_wq
);
153 kfree(pm8001_ha
->tags
);
157 #ifdef PM8001_USE_TASKLET
158 static void pm8001_tasklet(unsigned long opaque
)
160 struct pm8001_hba_info
*pm8001_ha
;
161 pm8001_ha
= (struct pm8001_hba_info
*)opaque
;
162 if (unlikely(!pm8001_ha
))
164 PM8001_CHIP_DISP
->isr(pm8001_ha
);
170 * pm8001_interrupt - when HBA originate a interrupt,we should invoke this
171 * dispatcher to handle each case.
173 * @opaque: the passed general host adapter struct
175 static irqreturn_t
pm8001_interrupt(int irq
, void *opaque
)
177 struct pm8001_hba_info
*pm8001_ha
;
178 irqreturn_t ret
= IRQ_HANDLED
;
179 struct sas_ha_struct
*sha
= opaque
;
180 pm8001_ha
= sha
->lldd_ha
;
181 if (unlikely(!pm8001_ha
))
183 if (!PM8001_CHIP_DISP
->is_our_interupt(pm8001_ha
))
185 #ifdef PM8001_USE_TASKLET
186 tasklet_schedule(&pm8001_ha
->tasklet
);
188 ret
= PM8001_CHIP_DISP
->isr(pm8001_ha
);
194 * pm8001_alloc - initiate our hba structure and 6 DMAs area.
195 * @pm8001_ha:our hba structure.
198 static int __devinit
pm8001_alloc(struct pm8001_hba_info
*pm8001_ha
)
201 spin_lock_init(&pm8001_ha
->lock
);
202 for (i
= 0; i
< pm8001_ha
->chip
->n_phy
; i
++) {
203 pm8001_phy_init(pm8001_ha
, i
);
204 pm8001_ha
->port
[i
].wide_port_phymap
= 0;
205 pm8001_ha
->port
[i
].port_attached
= 0;
206 pm8001_ha
->port
[i
].port_state
= 0;
207 INIT_LIST_HEAD(&pm8001_ha
->port
[i
].list
);
210 pm8001_ha
->tags
= kzalloc(PM8001_MAX_CCB
, GFP_KERNEL
);
211 if (!pm8001_ha
->tags
)
213 /* MPI Memory region 1 for AAP Event Log for fw */
214 pm8001_ha
->memoryMap
.region
[AAP1
].num_elements
= 1;
215 pm8001_ha
->memoryMap
.region
[AAP1
].element_size
= PM8001_EVENT_LOG_SIZE
;
216 pm8001_ha
->memoryMap
.region
[AAP1
].total_len
= PM8001_EVENT_LOG_SIZE
;
217 pm8001_ha
->memoryMap
.region
[AAP1
].alignment
= 32;
219 /* MPI Memory region 2 for IOP Event Log for fw */
220 pm8001_ha
->memoryMap
.region
[IOP
].num_elements
= 1;
221 pm8001_ha
->memoryMap
.region
[IOP
].element_size
= PM8001_EVENT_LOG_SIZE
;
222 pm8001_ha
->memoryMap
.region
[IOP
].total_len
= PM8001_EVENT_LOG_SIZE
;
223 pm8001_ha
->memoryMap
.region
[IOP
].alignment
= 32;
225 /* MPI Memory region 3 for consumer Index of inbound queues */
226 pm8001_ha
->memoryMap
.region
[CI
].num_elements
= 1;
227 pm8001_ha
->memoryMap
.region
[CI
].element_size
= 4;
228 pm8001_ha
->memoryMap
.region
[CI
].total_len
= 4;
229 pm8001_ha
->memoryMap
.region
[CI
].alignment
= 4;
231 /* MPI Memory region 4 for producer Index of outbound queues */
232 pm8001_ha
->memoryMap
.region
[PI
].num_elements
= 1;
233 pm8001_ha
->memoryMap
.region
[PI
].element_size
= 4;
234 pm8001_ha
->memoryMap
.region
[PI
].total_len
= 4;
235 pm8001_ha
->memoryMap
.region
[PI
].alignment
= 4;
237 /* MPI Memory region 5 inbound queues */
238 pm8001_ha
->memoryMap
.region
[IB
].num_elements
= PM8001_MPI_QUEUE
;
239 pm8001_ha
->memoryMap
.region
[IB
].element_size
= 64;
240 pm8001_ha
->memoryMap
.region
[IB
].total_len
= PM8001_MPI_QUEUE
* 64;
241 pm8001_ha
->memoryMap
.region
[IB
].alignment
= 64;
243 /* MPI Memory region 6 outbound queues */
244 pm8001_ha
->memoryMap
.region
[OB
].num_elements
= PM8001_MPI_QUEUE
;
245 pm8001_ha
->memoryMap
.region
[OB
].element_size
= 64;
246 pm8001_ha
->memoryMap
.region
[OB
].total_len
= PM8001_MPI_QUEUE
* 64;
247 pm8001_ha
->memoryMap
.region
[OB
].alignment
= 64;
249 /* Memory region write DMA*/
250 pm8001_ha
->memoryMap
.region
[NVMD
].num_elements
= 1;
251 pm8001_ha
->memoryMap
.region
[NVMD
].element_size
= 4096;
252 pm8001_ha
->memoryMap
.region
[NVMD
].total_len
= 4096;
253 /* Memory region for devices*/
254 pm8001_ha
->memoryMap
.region
[DEV_MEM
].num_elements
= 1;
255 pm8001_ha
->memoryMap
.region
[DEV_MEM
].element_size
= PM8001_MAX_DEVICES
*
256 sizeof(struct pm8001_device
);
257 pm8001_ha
->memoryMap
.region
[DEV_MEM
].total_len
= PM8001_MAX_DEVICES
*
258 sizeof(struct pm8001_device
);
260 /* Memory region for ccb_info*/
261 pm8001_ha
->memoryMap
.region
[CCB_MEM
].num_elements
= 1;
262 pm8001_ha
->memoryMap
.region
[CCB_MEM
].element_size
= PM8001_MAX_CCB
*
263 sizeof(struct pm8001_ccb_info
);
264 pm8001_ha
->memoryMap
.region
[CCB_MEM
].total_len
= PM8001_MAX_CCB
*
265 sizeof(struct pm8001_ccb_info
);
267 for (i
= 0; i
< USI_MAX_MEMCNT
; i
++) {
268 if (pm8001_mem_alloc(pm8001_ha
->pdev
,
269 &pm8001_ha
->memoryMap
.region
[i
].virt_ptr
,
270 &pm8001_ha
->memoryMap
.region
[i
].phys_addr
,
271 &pm8001_ha
->memoryMap
.region
[i
].phys_addr_hi
,
272 &pm8001_ha
->memoryMap
.region
[i
].phys_addr_lo
,
273 pm8001_ha
->memoryMap
.region
[i
].total_len
,
274 pm8001_ha
->memoryMap
.region
[i
].alignment
) != 0) {
275 PM8001_FAIL_DBG(pm8001_ha
,
276 pm8001_printk("Mem%d alloc failed\n",
282 pm8001_ha
->devices
= pm8001_ha
->memoryMap
.region
[DEV_MEM
].virt_ptr
;
283 for (i
= 0; i
< PM8001_MAX_DEVICES
; i
++) {
284 pm8001_ha
->devices
[i
].dev_type
= NO_DEVICE
;
285 pm8001_ha
->devices
[i
].id
= i
;
286 pm8001_ha
->devices
[i
].device_id
= PM8001_MAX_DEVICES
;
287 pm8001_ha
->devices
[i
].running_req
= 0;
289 pm8001_ha
->ccb_info
= pm8001_ha
->memoryMap
.region
[CCB_MEM
].virt_ptr
;
290 for (i
= 0; i
< PM8001_MAX_CCB
; i
++) {
291 pm8001_ha
->ccb_info
[i
].ccb_dma_handle
=
292 pm8001_ha
->memoryMap
.region
[CCB_MEM
].phys_addr
+
293 i
* sizeof(struct pm8001_ccb_info
);
294 pm8001_ha
->ccb_info
[i
].task
= NULL
;
295 pm8001_ha
->ccb_info
[i
].ccb_tag
= 0xffffffff;
296 pm8001_ha
->ccb_info
[i
].device
= NULL
;
297 ++pm8001_ha
->tags_num
;
299 pm8001_ha
->flags
= PM8001F_INIT_TIME
;
300 /* Initialize tags */
301 pm8001_tag_init(pm8001_ha
);
308 * pm8001_ioremap - remap the pci high physical address to kernal virtual
309 * address so that we can access them.
310 * @pm8001_ha:our hba structure.
312 static int pm8001_ioremap(struct pm8001_hba_info
*pm8001_ha
)
316 struct pci_dev
*pdev
;
318 pdev
= pm8001_ha
->pdev
;
319 /* map pci mem (PMC pci base 0-3)*/
320 for (bar
= 0; bar
< 6; bar
++) {
322 ** logical BARs for SPC:
323 ** bar 0 and 1 - logical BAR0
324 ** bar 2 and 3 - logical BAR1
325 ** bar4 - logical BAR2
326 ** bar5 - logical BAR3
327 ** Skip the appropriate assignments:
329 if ((bar
== 1) || (bar
== 3))
331 if (pci_resource_flags(pdev
, bar
) & IORESOURCE_MEM
) {
332 pm8001_ha
->io_mem
[logicalBar
].membase
=
333 pci_resource_start(pdev
, bar
);
334 pm8001_ha
->io_mem
[logicalBar
].membase
&=
335 (u32
)PCI_BASE_ADDRESS_MEM_MASK
;
336 pm8001_ha
->io_mem
[logicalBar
].memsize
=
337 pci_resource_len(pdev
, bar
);
338 pm8001_ha
->io_mem
[logicalBar
].memvirtaddr
=
339 ioremap(pm8001_ha
->io_mem
[logicalBar
].membase
,
340 pm8001_ha
->io_mem
[logicalBar
].memsize
);
341 PM8001_INIT_DBG(pm8001_ha
,
342 pm8001_printk("PCI: bar %d, logicalBar %d "
343 "virt_addr=%lx,len=%d\n", bar
, logicalBar
,
345 pm8001_ha
->io_mem
[logicalBar
].memvirtaddr
,
346 pm8001_ha
->io_mem
[logicalBar
].memsize
));
348 pm8001_ha
->io_mem
[logicalBar
].membase
= 0;
349 pm8001_ha
->io_mem
[logicalBar
].memsize
= 0;
350 pm8001_ha
->io_mem
[logicalBar
].memvirtaddr
= 0;
358 * pm8001_pci_alloc - initialize our ha card structure
361 * @shost: scsi host struct which has been initialized before.
363 static struct pm8001_hba_info
*__devinit
364 pm8001_pci_alloc(struct pci_dev
*pdev
, u32 chip_id
, struct Scsi_Host
*shost
)
366 struct pm8001_hba_info
*pm8001_ha
;
367 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
370 pm8001_ha
= sha
->lldd_ha
;
374 pm8001_ha
->pdev
= pdev
;
375 pm8001_ha
->dev
= &pdev
->dev
;
376 pm8001_ha
->chip_id
= chip_id
;
377 pm8001_ha
->chip
= &pm8001_chips
[pm8001_ha
->chip_id
];
378 pm8001_ha
->irq
= pdev
->irq
;
379 pm8001_ha
->sas
= sha
;
380 pm8001_ha
->shost
= shost
;
381 pm8001_ha
->id
= pm8001_id
++;
382 pm8001_ha
->logging_level
= 0x01;
383 sprintf(pm8001_ha
->name
, "%s%d", DRV_NAME
, pm8001_ha
->id
);
384 #ifdef PM8001_USE_TASKLET
385 tasklet_init(&pm8001_ha
->tasklet
, pm8001_tasklet
,
386 (unsigned long)pm8001_ha
);
388 pm8001_ioremap(pm8001_ha
);
389 if (!pm8001_alloc(pm8001_ha
))
391 pm8001_free(pm8001_ha
);
396 * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
399 static int pci_go_44(struct pci_dev
*pdev
)
403 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(44))) {
404 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(44));
406 rc
= pci_set_consistent_dma_mask(pdev
,
409 dev_printk(KERN_ERR
, &pdev
->dev
,
410 "44-bit DMA enable failed\n");
415 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
417 dev_printk(KERN_ERR
, &pdev
->dev
,
418 "32-bit DMA enable failed\n");
421 rc
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
423 dev_printk(KERN_ERR
, &pdev
->dev
,
424 "32-bit consistent DMA enable failed\n");
432 * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
433 * @shost: scsi host which has been allocated outside.
434 * @chip_info: our ha struct.
436 static int __devinit
pm8001_prep_sas_ha_init(struct Scsi_Host
* shost
,
437 const struct pm8001_chip_info
*chip_info
)
440 struct asd_sas_phy
**arr_phy
;
441 struct asd_sas_port
**arr_port
;
442 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
444 phy_nr
= chip_info
->n_phy
;
446 memset(sha
, 0x00, sizeof(*sha
));
447 arr_phy
= kcalloc(phy_nr
, sizeof(void *), GFP_KERNEL
);
450 arr_port
= kcalloc(port_nr
, sizeof(void *), GFP_KERNEL
);
454 sha
->sas_phy
= arr_phy
;
455 sha
->sas_port
= arr_port
;
456 sha
->lldd_ha
= kzalloc(sizeof(struct pm8001_hba_info
), GFP_KERNEL
);
460 shost
->transportt
= pm8001_stt
;
461 shost
->max_id
= PM8001_MAX_DEVICES
;
463 shost
->max_channel
= 0;
464 shost
->unique_id
= pm8001_id
;
465 shost
->max_cmd_len
= 16;
466 shost
->can_queue
= PM8001_CAN_QUEUE
;
467 shost
->cmd_per_lun
= 32;
478 * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
479 * @shost: scsi host which has been allocated outside
480 * @chip_info: our ha struct.
482 static void __devinit
pm8001_post_sas_ha_init(struct Scsi_Host
*shost
,
483 const struct pm8001_chip_info
*chip_info
)
486 struct pm8001_hba_info
*pm8001_ha
;
487 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
489 pm8001_ha
= sha
->lldd_ha
;
490 for (i
= 0; i
< chip_info
->n_phy
; i
++) {
491 sha
->sas_phy
[i
] = &pm8001_ha
->phy
[i
].sas_phy
;
492 sha
->sas_port
[i
] = &pm8001_ha
->port
[i
].sas_port
;
494 sha
->sas_ha_name
= DRV_NAME
;
495 sha
->dev
= pm8001_ha
->dev
;
497 sha
->lldd_module
= THIS_MODULE
;
498 sha
->sas_addr
= &pm8001_ha
->sas_addr
[0];
499 sha
->num_phys
= chip_info
->n_phy
;
500 sha
->lldd_max_execute_num
= 1;
501 sha
->lldd_queue_size
= PM8001_CAN_QUEUE
;
502 sha
->core
.shost
= shost
;
506 * pm8001_init_sas_add - initialize sas address
507 * @chip_info: our ha struct.
509 * Currently we just set the fixed SAS address to our HBA,for manufacture,
510 * it should read from the EEPROM
512 static void pm8001_init_sas_add(struct pm8001_hba_info
*pm8001_ha
)
515 #ifdef PM8001_READ_VPD
516 DECLARE_COMPLETION_ONSTACK(completion
);
517 struct pm8001_ioctl_payload payload
;
518 pm8001_ha
->nvmd_completion
= &completion
;
519 payload
.minor_function
= 0;
520 payload
.length
= 128;
521 payload
.func_specific
= kzalloc(128, GFP_KERNEL
);
522 PM8001_CHIP_DISP
->get_nvmd_req(pm8001_ha
, &payload
);
523 wait_for_completion(&completion
);
524 for (i
= 0; i
< pm8001_ha
->chip
->n_phy
; i
++) {
525 memcpy(&pm8001_ha
->phy
[i
].dev_sas_addr
, pm8001_ha
->sas_addr
,
527 PM8001_INIT_DBG(pm8001_ha
,
528 pm8001_printk("phy %d sas_addr = %016llx \n", i
,
529 pm8001_ha
->phy
[i
].dev_sas_addr
));
532 for (i
= 0; i
< pm8001_ha
->chip
->n_phy
; i
++) {
533 pm8001_ha
->phy
[i
].dev_sas_addr
= 0x50010c600047f9d0ULL
;
534 pm8001_ha
->phy
[i
].dev_sas_addr
=
536 (*(u64
*)&pm8001_ha
->phy
[i
].dev_sas_addr
));
538 memcpy(pm8001_ha
->sas_addr
, &pm8001_ha
->phy
[0].dev_sas_addr
,
543 #ifdef PM8001_USE_MSIX
545 * pm8001_setup_msix - enable MSI-X interrupt
546 * @chip_info: our ha struct.
547 * @irq_handler: irq_handler
549 static u32
pm8001_setup_msix(struct pm8001_hba_info
*pm8001_ha
,
550 irq_handler_t irq_handler
)
553 u32 number_of_intr
= 1;
557 max_entry
= sizeof(pm8001_ha
->msix_entries
) /
558 sizeof(pm8001_ha
->msix_entries
[0]);
559 flag
|= IRQF_DISABLED
;
560 for (i
= 0; i
< max_entry
; i
++)
561 pm8001_ha
->msix_entries
[i
].entry
= i
;
562 rc
= pci_enable_msix(pm8001_ha
->pdev
, pm8001_ha
->msix_entries
,
564 pm8001_ha
->number_of_intr
= number_of_intr
;
566 for (i
= 0; i
< number_of_intr
; i
++) {
567 if (request_irq(pm8001_ha
->msix_entries
[i
].vector
,
568 irq_handler
, flag
, DRV_NAME
,
569 SHOST_TO_SAS_HA(pm8001_ha
->shost
))) {
570 for (j
= 0; j
< i
; j
++)
572 pm8001_ha
->msix_entries
[j
].vector
,
573 SHOST_TO_SAS_HA(pm8001_ha
->shost
));
574 pci_disable_msix(pm8001_ha
->pdev
);
584 * pm8001_request_irq - register interrupt
585 * @chip_info: our ha struct.
587 static u32
pm8001_request_irq(struct pm8001_hba_info
*pm8001_ha
)
589 struct pci_dev
*pdev
;
590 irq_handler_t irq_handler
= pm8001_interrupt
;
593 pdev
= pm8001_ha
->pdev
;
595 #ifdef PM8001_USE_MSIX
596 if (pci_find_capability(pdev
, PCI_CAP_ID_MSIX
))
597 return pm8001_setup_msix(pm8001_ha
, irq_handler
);
603 /* initialize the INT-X interrupt */
604 rc
= request_irq(pdev
->irq
, irq_handler
, IRQF_SHARED
, DRV_NAME
,
605 SHOST_TO_SAS_HA(pm8001_ha
->shost
));
610 * pm8001_pci_probe - probe supported device
611 * @pdev: pci device which kernel has been prepared for.
612 * @ent: pci device id
614 * This function is the main initialization function, when register a new
615 * pci driver it is invoked, all struct an hardware initilization should be done
616 * here, also, register interrupt
618 static int __devinit
pm8001_pci_probe(struct pci_dev
*pdev
,
619 const struct pci_device_id
*ent
)
623 struct pm8001_hba_info
*pm8001_ha
;
624 struct Scsi_Host
*shost
= NULL
;
625 const struct pm8001_chip_info
*chip
;
627 dev_printk(KERN_INFO
, &pdev
->dev
,
628 "pm8001: driver version %s\n", DRV_VERSION
);
629 rc
= pci_enable_device(pdev
);
632 pci_set_master(pdev
);
634 * Enable pci slot busmaster by setting pci command register.
635 * This is required by FW for Cyclone card.
638 pci_read_config_dword(pdev
, PCI_COMMAND
, &pci_reg
);
640 pci_write_config_dword(pdev
, PCI_COMMAND
, pci_reg
);
641 rc
= pci_request_regions(pdev
, DRV_NAME
);
643 goto err_out_disable
;
644 rc
= pci_go_44(pdev
);
646 goto err_out_regions
;
648 shost
= scsi_host_alloc(&pm8001_sht
, sizeof(void *));
651 goto err_out_regions
;
653 chip
= &pm8001_chips
[ent
->driver_data
];
654 SHOST_TO_SAS_HA(shost
) =
655 kzalloc(sizeof(struct sas_ha_struct
), GFP_KERNEL
);
656 if (!SHOST_TO_SAS_HA(shost
)) {
658 goto err_out_free_host
;
661 rc
= pm8001_prep_sas_ha_init(shost
, chip
);
666 pci_set_drvdata(pdev
, SHOST_TO_SAS_HA(shost
));
667 pm8001_ha
= pm8001_pci_alloc(pdev
, chip_8001
, shost
);
672 list_add_tail(&pm8001_ha
->list
, &hba_list
);
673 PM8001_CHIP_DISP
->chip_soft_rst(pm8001_ha
, 0x252acbcd);
674 rc
= PM8001_CHIP_DISP
->chip_init(pm8001_ha
);
676 goto err_out_ha_free
;
678 rc
= scsi_add_host(shost
, &pdev
->dev
);
680 goto err_out_ha_free
;
681 rc
= pm8001_request_irq(pm8001_ha
);
685 PM8001_CHIP_DISP
->interrupt_enable(pm8001_ha
);
686 pm8001_init_sas_add(pm8001_ha
);
687 pm8001_post_sas_ha_init(shost
, chip
);
688 rc
= sas_register_ha(SHOST_TO_SAS_HA(shost
));
691 scsi_scan_host(pm8001_ha
->shost
);
695 scsi_remove_host(pm8001_ha
->shost
);
697 pm8001_free(pm8001_ha
);
699 kfree(SHOST_TO_SAS_HA(shost
));
703 pci_release_regions(pdev
);
705 pci_disable_device(pdev
);
710 static void __devexit
pm8001_pci_remove(struct pci_dev
*pdev
)
712 struct sas_ha_struct
*sha
= pci_get_drvdata(pdev
);
713 struct pm8001_hba_info
*pm8001_ha
;
715 pm8001_ha
= sha
->lldd_ha
;
716 pci_set_drvdata(pdev
, NULL
);
717 sas_unregister_ha(sha
);
718 sas_remove_host(pm8001_ha
->shost
);
719 list_del(&pm8001_ha
->list
);
720 scsi_remove_host(pm8001_ha
->shost
);
721 PM8001_CHIP_DISP
->interrupt_disable(pm8001_ha
);
722 PM8001_CHIP_DISP
->chip_soft_rst(pm8001_ha
, 0x252acbcd);
724 #ifdef PM8001_USE_MSIX
725 for (i
= 0; i
< pm8001_ha
->number_of_intr
; i
++)
726 synchronize_irq(pm8001_ha
->msix_entries
[i
].vector
);
727 for (i
= 0; i
< pm8001_ha
->number_of_intr
; i
++)
728 free_irq(pm8001_ha
->msix_entries
[i
].vector
, sha
);
729 pci_disable_msix(pdev
);
731 free_irq(pm8001_ha
->irq
, sha
);
733 #ifdef PM8001_USE_TASKLET
734 tasklet_kill(&pm8001_ha
->tasklet
);
736 pm8001_free(pm8001_ha
);
738 kfree(sha
->sas_port
);
740 pci_release_regions(pdev
);
741 pci_disable_device(pdev
);
745 * pm8001_pci_suspend - power management suspend main entry point
746 * @pdev: PCI device struct
747 * @state: PM state change to (usually PCI_D3)
749 * Returns 0 success, anything else error.
751 static int pm8001_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
753 struct sas_ha_struct
*sha
= pci_get_drvdata(pdev
);
754 struct pm8001_hba_info
*pm8001_ha
;
757 pm8001_ha
= sha
->lldd_ha
;
758 flush_workqueue(pm8001_wq
);
759 scsi_block_requests(pm8001_ha
->shost
);
760 pos
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
762 printk(KERN_ERR
" PCI PM not supported\n");
765 PM8001_CHIP_DISP
->interrupt_disable(pm8001_ha
);
766 PM8001_CHIP_DISP
->chip_soft_rst(pm8001_ha
, 0x252acbcd);
767 #ifdef PM8001_USE_MSIX
768 for (i
= 0; i
< pm8001_ha
->number_of_intr
; i
++)
769 synchronize_irq(pm8001_ha
->msix_entries
[i
].vector
);
770 for (i
= 0; i
< pm8001_ha
->number_of_intr
; i
++)
771 free_irq(pm8001_ha
->msix_entries
[i
].vector
, sha
);
772 pci_disable_msix(pdev
);
774 free_irq(pm8001_ha
->irq
, sha
);
776 #ifdef PM8001_USE_TASKLET
777 tasklet_kill(&pm8001_ha
->tasklet
);
779 device_state
= pci_choose_state(pdev
, state
);
780 pm8001_printk("pdev=0x%p, slot=%s, entering "
781 "operating state [D%d]\n", pdev
,
782 pm8001_ha
->name
, device_state
);
783 pci_save_state(pdev
);
784 pci_disable_device(pdev
);
785 pci_set_power_state(pdev
, device_state
);
790 * pm8001_pci_resume - power management resume main entry point
791 * @pdev: PCI device struct
793 * Returns 0 success, anything else error.
795 static int pm8001_pci_resume(struct pci_dev
*pdev
)
797 struct sas_ha_struct
*sha
= pci_get_drvdata(pdev
);
798 struct pm8001_hba_info
*pm8001_ha
;
801 pm8001_ha
= sha
->lldd_ha
;
802 device_state
= pdev
->current_state
;
804 pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
805 "operating state [D%d]\n", pdev
, pm8001_ha
->name
, device_state
);
807 pci_set_power_state(pdev
, PCI_D0
);
808 pci_enable_wake(pdev
, PCI_D0
, 0);
809 pci_restore_state(pdev
);
810 rc
= pci_enable_device(pdev
);
812 pm8001_printk("slot=%s Enable device failed during resume\n",
817 pci_set_master(pdev
);
818 rc
= pci_go_44(pdev
);
820 goto err_out_disable
;
822 PM8001_CHIP_DISP
->chip_soft_rst(pm8001_ha
, 0x252acbcd);
823 rc
= PM8001_CHIP_DISP
->chip_init(pm8001_ha
);
825 goto err_out_disable
;
826 PM8001_CHIP_DISP
->interrupt_disable(pm8001_ha
);
827 rc
= pm8001_request_irq(pm8001_ha
);
829 goto err_out_disable
;
830 #ifdef PM8001_USE_TASKLET
831 tasklet_init(&pm8001_ha
->tasklet
, pm8001_tasklet
,
832 (unsigned long)pm8001_ha
);
834 PM8001_CHIP_DISP
->interrupt_enable(pm8001_ha
);
835 scsi_unblock_requests(pm8001_ha
->shost
);
839 scsi_remove_host(pm8001_ha
->shost
);
840 pci_disable_device(pdev
);
845 static struct pci_device_id __devinitdata pm8001_pci_table
[] = {
847 PCI_VDEVICE(PMC_Sierra
, 0x8001), chip_8001
850 PCI_DEVICE(0x117c, 0x0042),
851 .driver_data
= chip_8001
853 {} /* terminate list */
856 static struct pci_driver pm8001_pci_driver
= {
858 .id_table
= pm8001_pci_table
,
859 .probe
= pm8001_pci_probe
,
860 .remove
= __devexit_p(pm8001_pci_remove
),
861 .suspend
= pm8001_pci_suspend
,
862 .resume
= pm8001_pci_resume
,
866 * pm8001_init - initialize scsi transport template
868 static int __init
pm8001_init(void)
872 pm8001_wq
= alloc_workqueue("pm8001", 0, 0);
877 pm8001_stt
= sas_domain_attach_transport(&pm8001_transport_ops
);
880 rc
= pci_register_driver(&pm8001_pci_driver
);
886 sas_release_transport(pm8001_stt
);
888 destroy_workqueue(pm8001_wq
);
893 static void __exit
pm8001_exit(void)
895 pci_unregister_driver(&pm8001_pci_driver
);
896 sas_release_transport(pm8001_stt
);
897 destroy_workqueue(pm8001_wq
);
900 module_init(pm8001_init
);
901 module_exit(pm8001_exit
);
903 MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
904 MODULE_DESCRIPTION("PMC-Sierra PM8001 SAS/SATA controller driver");
905 MODULE_VERSION(DRV_VERSION
);
906 MODULE_LICENSE("GPL");
907 MODULE_DEVICE_TABLE(pci
, pm8001_pci_table
);