jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1 | /* |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 2 | * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2008-2009 USI Co., Ltd. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 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. |
| 21 | * |
| 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. |
| 25 | * |
| 26 | * NO WARRANTY |
| 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. |
| 38 | * |
| 39 | */ |
| 40 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 42 | #include "pm8001_sas.h" |
| 43 | #include "pm8001_chips.h" |
| 44 | |
| 45 | static struct scsi_transport_template *pm8001_stt; |
| 46 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 47 | /** |
| 48 | * chip info structure to identify chip key functionality as |
| 49 | * encryption available/not, no of ports, hw specific function ref |
| 50 | */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 51 | static const struct pm8001_chip_info pm8001_chips[] = { |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 52 | [chip_8001] = {0, 8, &pm8001_8001_dispatch,}, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 53 | }; |
| 54 | static int pm8001_id; |
| 55 | |
| 56 | LIST_HEAD(hba_list); |
| 57 | |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 58 | struct workqueue_struct *pm8001_wq; |
| 59 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 60 | /** |
| 61 | * The main structure which LLDD must register for scsi core. |
| 62 | */ |
| 63 | static struct scsi_host_template pm8001_sht = { |
| 64 | .module = THIS_MODULE, |
| 65 | .name = DRV_NAME, |
| 66 | .queuecommand = sas_queuecommand, |
| 67 | .target_alloc = sas_target_alloc, |
Dan Williams | 11e1636 | 2011-09-20 15:11:03 -0700 | [diff] [blame] | 68 | .slave_configure = sas_slave_configure, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 69 | .scan_finished = pm8001_scan_finished, |
| 70 | .scan_start = pm8001_scan_start, |
| 71 | .change_queue_depth = sas_change_queue_depth, |
| 72 | .change_queue_type = sas_change_queue_type, |
| 73 | .bios_param = sas_bios_param, |
| 74 | .can_queue = 1, |
| 75 | .cmd_per_lun = 1, |
| 76 | .this_id = -1, |
| 77 | .sg_tablesize = SG_ALL, |
| 78 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, |
| 79 | .use_clustering = ENABLE_CLUSTERING, |
| 80 | .eh_device_reset_handler = sas_eh_device_reset_handler, |
| 81 | .eh_bus_reset_handler = sas_eh_bus_reset_handler, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 82 | .target_destroy = sas_target_destroy, |
| 83 | .ioctl = sas_ioctl, |
| 84 | .shost_attrs = pm8001_host_attrs, |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * Sas layer call this function to execute specific task. |
| 89 | */ |
| 90 | static struct sas_domain_function_template pm8001_transport_ops = { |
| 91 | .lldd_dev_found = pm8001_dev_found, |
| 92 | .lldd_dev_gone = pm8001_dev_gone, |
| 93 | |
| 94 | .lldd_execute_task = pm8001_queue_command, |
| 95 | .lldd_control_phy = pm8001_phy_control, |
| 96 | |
| 97 | .lldd_abort_task = pm8001_abort_task, |
| 98 | .lldd_abort_task_set = pm8001_abort_task_set, |
| 99 | .lldd_clear_aca = pm8001_clear_aca, |
| 100 | .lldd_clear_task_set = pm8001_clear_task_set, |
| 101 | .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset, |
| 102 | .lldd_lu_reset = pm8001_lu_reset, |
| 103 | .lldd_query_task = pm8001_query_task, |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | *pm8001_phy_init - initiate our adapter phys |
| 108 | *@pm8001_ha: our hba structure. |
| 109 | *@phy_id: phy id. |
| 110 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 111 | static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 112 | { |
| 113 | struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; |
| 114 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 115 | phy->phy_state = 0; |
| 116 | phy->pm8001_ha = pm8001_ha; |
| 117 | sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0; |
| 118 | sas_phy->class = SAS; |
| 119 | sas_phy->iproto = SAS_PROTOCOL_ALL; |
| 120 | sas_phy->tproto = 0; |
| 121 | sas_phy->type = PHY_TYPE_PHYSICAL; |
| 122 | sas_phy->role = PHY_ROLE_INITIATOR; |
| 123 | sas_phy->oob_mode = OOB_NOT_CONNECTED; |
| 124 | sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
| 125 | sas_phy->id = phy_id; |
| 126 | sas_phy->sas_addr = &pm8001_ha->sas_addr[0]; |
| 127 | sas_phy->frame_rcvd = &phy->frame_rcvd[0]; |
| 128 | sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata; |
| 129 | sas_phy->lldd_phy = phy; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | *pm8001_free - free hba |
| 134 | *@pm8001_ha: our hba structure. |
| 135 | * |
| 136 | */ |
| 137 | static void pm8001_free(struct pm8001_hba_info *pm8001_ha) |
| 138 | { |
| 139 | int i; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 140 | |
| 141 | if (!pm8001_ha) |
| 142 | return; |
| 143 | |
| 144 | for (i = 0; i < USI_MAX_MEMCNT; i++) { |
| 145 | if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) { |
| 146 | pci_free_consistent(pm8001_ha->pdev, |
Sakthivel K | bfb4809 | 2013-02-04 12:10:02 +0530 | [diff] [blame] | 147 | (pm8001_ha->memoryMap.region[i].total_len + |
| 148 | pm8001_ha->memoryMap.region[i].alignment), |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 149 | pm8001_ha->memoryMap.region[i].virt_ptr, |
| 150 | pm8001_ha->memoryMap.region[i].phys_addr); |
| 151 | } |
| 152 | } |
| 153 | PM8001_CHIP_DISP->chip_iounmap(pm8001_ha); |
| 154 | if (pm8001_ha->shost) |
| 155 | scsi_host_put(pm8001_ha->shost); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 156 | flush_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 157 | kfree(pm8001_ha->tags); |
| 158 | kfree(pm8001_ha); |
| 159 | } |
| 160 | |
| 161 | #ifdef PM8001_USE_TASKLET |
| 162 | static void pm8001_tasklet(unsigned long opaque) |
| 163 | { |
| 164 | struct pm8001_hba_info *pm8001_ha; |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 165 | pm8001_ha = (struct pm8001_hba_info *)opaque; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 166 | if (unlikely(!pm8001_ha)) |
| 167 | BUG_ON(1); |
| 168 | PM8001_CHIP_DISP->isr(pm8001_ha); |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | |
| 173 | /** |
| 174 | * pm8001_interrupt - when HBA originate a interrupt,we should invoke this |
| 175 | * dispatcher to handle each case. |
| 176 | * @irq: irq number. |
| 177 | * @opaque: the passed general host adapter struct |
| 178 | */ |
| 179 | static irqreturn_t pm8001_interrupt(int irq, void *opaque) |
| 180 | { |
| 181 | struct pm8001_hba_info *pm8001_ha; |
| 182 | irqreturn_t ret = IRQ_HANDLED; |
| 183 | struct sas_ha_struct *sha = opaque; |
| 184 | pm8001_ha = sha->lldd_ha; |
| 185 | if (unlikely(!pm8001_ha)) |
| 186 | return IRQ_NONE; |
| 187 | if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha)) |
| 188 | return IRQ_NONE; |
| 189 | #ifdef PM8001_USE_TASKLET |
| 190 | tasklet_schedule(&pm8001_ha->tasklet); |
| 191 | #else |
| 192 | ret = PM8001_CHIP_DISP->isr(pm8001_ha); |
| 193 | #endif |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * pm8001_alloc - initiate our hba structure and 6 DMAs area. |
| 199 | * @pm8001_ha:our hba structure. |
| 200 | * |
| 201 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 202 | static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 203 | { |
| 204 | int i; |
| 205 | spin_lock_init(&pm8001_ha->lock); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 206 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 207 | pm8001_phy_init(pm8001_ha, i); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 208 | pm8001_ha->port[i].wide_port_phymap = 0; |
| 209 | pm8001_ha->port[i].port_attached = 0; |
| 210 | pm8001_ha->port[i].port_state = 0; |
| 211 | INIT_LIST_HEAD(&pm8001_ha->port[i].list); |
| 212 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 213 | |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 214 | pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL); |
| 215 | if (!pm8001_ha->tags) |
| 216 | goto err_out; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 217 | /* MPI Memory region 1 for AAP Event Log for fw */ |
| 218 | pm8001_ha->memoryMap.region[AAP1].num_elements = 1; |
| 219 | pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE; |
| 220 | pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE; |
| 221 | pm8001_ha->memoryMap.region[AAP1].alignment = 32; |
| 222 | |
| 223 | /* MPI Memory region 2 for IOP Event Log for fw */ |
| 224 | pm8001_ha->memoryMap.region[IOP].num_elements = 1; |
| 225 | pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE; |
| 226 | pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE; |
| 227 | pm8001_ha->memoryMap.region[IOP].alignment = 32; |
| 228 | |
| 229 | /* MPI Memory region 3 for consumer Index of inbound queues */ |
| 230 | pm8001_ha->memoryMap.region[CI].num_elements = 1; |
| 231 | pm8001_ha->memoryMap.region[CI].element_size = 4; |
| 232 | pm8001_ha->memoryMap.region[CI].total_len = 4; |
| 233 | pm8001_ha->memoryMap.region[CI].alignment = 4; |
| 234 | |
| 235 | /* MPI Memory region 4 for producer Index of outbound queues */ |
| 236 | pm8001_ha->memoryMap.region[PI].num_elements = 1; |
| 237 | pm8001_ha->memoryMap.region[PI].element_size = 4; |
| 238 | pm8001_ha->memoryMap.region[PI].total_len = 4; |
| 239 | pm8001_ha->memoryMap.region[PI].alignment = 4; |
| 240 | |
| 241 | /* MPI Memory region 5 inbound queues */ |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 242 | pm8001_ha->memoryMap.region[IB].num_elements = PM8001_MPI_QUEUE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 243 | pm8001_ha->memoryMap.region[IB].element_size = 64; |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 244 | pm8001_ha->memoryMap.region[IB].total_len = PM8001_MPI_QUEUE * 64; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 245 | pm8001_ha->memoryMap.region[IB].alignment = 64; |
| 246 | |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 247 | /* MPI Memory region 6 outbound queues */ |
| 248 | pm8001_ha->memoryMap.region[OB].num_elements = PM8001_MPI_QUEUE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 249 | pm8001_ha->memoryMap.region[OB].element_size = 64; |
Mark Salyzyn | 99c72eb | 2012-04-25 13:02:04 -0400 | [diff] [blame] | 250 | pm8001_ha->memoryMap.region[OB].total_len = PM8001_MPI_QUEUE * 64; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 251 | pm8001_ha->memoryMap.region[OB].alignment = 64; |
| 252 | |
| 253 | /* Memory region write DMA*/ |
| 254 | pm8001_ha->memoryMap.region[NVMD].num_elements = 1; |
| 255 | pm8001_ha->memoryMap.region[NVMD].element_size = 4096; |
| 256 | pm8001_ha->memoryMap.region[NVMD].total_len = 4096; |
| 257 | /* Memory region for devices*/ |
| 258 | pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1; |
| 259 | pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES * |
| 260 | sizeof(struct pm8001_device); |
| 261 | pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES * |
| 262 | sizeof(struct pm8001_device); |
| 263 | |
| 264 | /* Memory region for ccb_info*/ |
| 265 | pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1; |
| 266 | pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB * |
| 267 | sizeof(struct pm8001_ccb_info); |
| 268 | pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB * |
| 269 | sizeof(struct pm8001_ccb_info); |
| 270 | |
| 271 | for (i = 0; i < USI_MAX_MEMCNT; i++) { |
| 272 | if (pm8001_mem_alloc(pm8001_ha->pdev, |
| 273 | &pm8001_ha->memoryMap.region[i].virt_ptr, |
| 274 | &pm8001_ha->memoryMap.region[i].phys_addr, |
| 275 | &pm8001_ha->memoryMap.region[i].phys_addr_hi, |
| 276 | &pm8001_ha->memoryMap.region[i].phys_addr_lo, |
| 277 | pm8001_ha->memoryMap.region[i].total_len, |
| 278 | pm8001_ha->memoryMap.region[i].alignment) != 0) { |
| 279 | PM8001_FAIL_DBG(pm8001_ha, |
| 280 | pm8001_printk("Mem%d alloc failed\n", |
| 281 | i)); |
| 282 | goto err_out; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr; |
| 287 | for (i = 0; i < PM8001_MAX_DEVICES; i++) { |
| 288 | pm8001_ha->devices[i].dev_type = NO_DEVICE; |
| 289 | pm8001_ha->devices[i].id = i; |
| 290 | pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES; |
| 291 | pm8001_ha->devices[i].running_req = 0; |
| 292 | } |
| 293 | pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr; |
| 294 | for (i = 0; i < PM8001_MAX_CCB; i++) { |
| 295 | pm8001_ha->ccb_info[i].ccb_dma_handle = |
| 296 | pm8001_ha->memoryMap.region[CCB_MEM].phys_addr + |
| 297 | i * sizeof(struct pm8001_ccb_info); |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 298 | pm8001_ha->ccb_info[i].task = NULL; |
| 299 | pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff; |
| 300 | pm8001_ha->ccb_info[i].device = NULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 301 | ++pm8001_ha->tags_num; |
| 302 | } |
| 303 | pm8001_ha->flags = PM8001F_INIT_TIME; |
| 304 | /* Initialize tags */ |
| 305 | pm8001_tag_init(pm8001_ha); |
| 306 | return 0; |
| 307 | err_out: |
| 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * pm8001_ioremap - remap the pci high physical address to kernal virtual |
| 313 | * address so that we can access them. |
| 314 | * @pm8001_ha:our hba structure. |
| 315 | */ |
| 316 | static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha) |
| 317 | { |
| 318 | u32 bar; |
| 319 | u32 logicalBar = 0; |
| 320 | struct pci_dev *pdev; |
| 321 | |
| 322 | pdev = pm8001_ha->pdev; |
| 323 | /* map pci mem (PMC pci base 0-3)*/ |
| 324 | for (bar = 0; bar < 6; bar++) { |
| 325 | /* |
| 326 | ** logical BARs for SPC: |
| 327 | ** bar 0 and 1 - logical BAR0 |
| 328 | ** bar 2 and 3 - logical BAR1 |
| 329 | ** bar4 - logical BAR2 |
| 330 | ** bar5 - logical BAR3 |
| 331 | ** Skip the appropriate assignments: |
| 332 | */ |
| 333 | if ((bar == 1) || (bar == 3)) |
| 334 | continue; |
| 335 | if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { |
| 336 | pm8001_ha->io_mem[logicalBar].membase = |
| 337 | pci_resource_start(pdev, bar); |
| 338 | pm8001_ha->io_mem[logicalBar].membase &= |
| 339 | (u32)PCI_BASE_ADDRESS_MEM_MASK; |
| 340 | pm8001_ha->io_mem[logicalBar].memsize = |
| 341 | pci_resource_len(pdev, bar); |
| 342 | pm8001_ha->io_mem[logicalBar].memvirtaddr = |
| 343 | ioremap(pm8001_ha->io_mem[logicalBar].membase, |
| 344 | pm8001_ha->io_mem[logicalBar].memsize); |
| 345 | PM8001_INIT_DBG(pm8001_ha, |
| 346 | pm8001_printk("PCI: bar %d, logicalBar %d " |
| 347 | "virt_addr=%lx,len=%d\n", bar, logicalBar, |
| 348 | (unsigned long) |
| 349 | pm8001_ha->io_mem[logicalBar].memvirtaddr, |
| 350 | pm8001_ha->io_mem[logicalBar].memsize)); |
| 351 | } else { |
| 352 | pm8001_ha->io_mem[logicalBar].membase = 0; |
| 353 | pm8001_ha->io_mem[logicalBar].memsize = 0; |
| 354 | pm8001_ha->io_mem[logicalBar].memvirtaddr = 0; |
| 355 | } |
| 356 | logicalBar++; |
| 357 | } |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * pm8001_pci_alloc - initialize our ha card structure |
| 363 | * @pdev: pci device. |
| 364 | * @ent: ent |
| 365 | * @shost: scsi host struct which has been initialized before. |
| 366 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 367 | static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev, |
| 368 | u32 chip_id, |
| 369 | struct Scsi_Host *shost) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 370 | { |
| 371 | struct pm8001_hba_info *pm8001_ha; |
| 372 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 373 | |
| 374 | |
| 375 | pm8001_ha = sha->lldd_ha; |
| 376 | if (!pm8001_ha) |
| 377 | return NULL; |
| 378 | |
| 379 | pm8001_ha->pdev = pdev; |
| 380 | pm8001_ha->dev = &pdev->dev; |
| 381 | pm8001_ha->chip_id = chip_id; |
| 382 | pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id]; |
| 383 | pm8001_ha->irq = pdev->irq; |
| 384 | pm8001_ha->sas = sha; |
| 385 | pm8001_ha->shost = shost; |
| 386 | pm8001_ha->id = pm8001_id++; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 387 | pm8001_ha->logging_level = 0x01; |
| 388 | sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id); |
| 389 | #ifdef PM8001_USE_TASKLET |
| 390 | tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet, |
| 391 | (unsigned long)pm8001_ha); |
| 392 | #endif |
| 393 | pm8001_ioremap(pm8001_ha); |
| 394 | if (!pm8001_alloc(pm8001_ha)) |
| 395 | return pm8001_ha; |
| 396 | pm8001_free(pm8001_ha); |
| 397 | return NULL; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit |
| 402 | * @pdev: pci device. |
| 403 | */ |
| 404 | static int pci_go_44(struct pci_dev *pdev) |
| 405 | { |
| 406 | int rc; |
| 407 | |
| 408 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) { |
| 409 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44)); |
| 410 | if (rc) { |
| 411 | rc = pci_set_consistent_dma_mask(pdev, |
| 412 | DMA_BIT_MASK(32)); |
| 413 | if (rc) { |
| 414 | dev_printk(KERN_ERR, &pdev->dev, |
| 415 | "44-bit DMA enable failed\n"); |
| 416 | return rc; |
| 417 | } |
| 418 | } |
| 419 | } else { |
| 420 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 421 | if (rc) { |
| 422 | dev_printk(KERN_ERR, &pdev->dev, |
| 423 | "32-bit DMA enable failed\n"); |
| 424 | return rc; |
| 425 | } |
| 426 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 427 | if (rc) { |
| 428 | dev_printk(KERN_ERR, &pdev->dev, |
| 429 | "32-bit consistent DMA enable failed\n"); |
| 430 | return rc; |
| 431 | } |
| 432 | } |
| 433 | return rc; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them. |
| 438 | * @shost: scsi host which has been allocated outside. |
| 439 | * @chip_info: our ha struct. |
| 440 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 441 | static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost, |
| 442 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 443 | { |
| 444 | int phy_nr, port_nr; |
| 445 | struct asd_sas_phy **arr_phy; |
| 446 | struct asd_sas_port **arr_port; |
| 447 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 448 | |
| 449 | phy_nr = chip_info->n_phy; |
| 450 | port_nr = phy_nr; |
| 451 | memset(sha, 0x00, sizeof(*sha)); |
| 452 | arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL); |
| 453 | if (!arr_phy) |
| 454 | goto exit; |
| 455 | arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL); |
| 456 | if (!arr_port) |
| 457 | goto exit_free2; |
| 458 | |
| 459 | sha->sas_phy = arr_phy; |
| 460 | sha->sas_port = arr_port; |
| 461 | sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL); |
| 462 | if (!sha->lldd_ha) |
| 463 | goto exit_free1; |
| 464 | |
| 465 | shost->transportt = pm8001_stt; |
| 466 | shost->max_id = PM8001_MAX_DEVICES; |
| 467 | shost->max_lun = 8; |
| 468 | shost->max_channel = 0; |
| 469 | shost->unique_id = pm8001_id; |
| 470 | shost->max_cmd_len = 16; |
| 471 | shost->can_queue = PM8001_CAN_QUEUE; |
| 472 | shost->cmd_per_lun = 32; |
| 473 | return 0; |
| 474 | exit_free1: |
| 475 | kfree(arr_port); |
| 476 | exit_free2: |
| 477 | kfree(arr_phy); |
| 478 | exit: |
| 479 | return -1; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas |
| 484 | * @shost: scsi host which has been allocated outside |
| 485 | * @chip_info: our ha struct. |
| 486 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 487 | static void pm8001_post_sas_ha_init(struct Scsi_Host *shost, |
| 488 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 489 | { |
| 490 | int i = 0; |
| 491 | struct pm8001_hba_info *pm8001_ha; |
| 492 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 493 | |
| 494 | pm8001_ha = sha->lldd_ha; |
| 495 | for (i = 0; i < chip_info->n_phy; i++) { |
| 496 | sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy; |
| 497 | sha->sas_port[i] = &pm8001_ha->port[i].sas_port; |
| 498 | } |
| 499 | sha->sas_ha_name = DRV_NAME; |
| 500 | sha->dev = pm8001_ha->dev; |
| 501 | |
| 502 | sha->lldd_module = THIS_MODULE; |
| 503 | sha->sas_addr = &pm8001_ha->sas_addr[0]; |
| 504 | sha->num_phys = chip_info->n_phy; |
| 505 | sha->lldd_max_execute_num = 1; |
| 506 | sha->lldd_queue_size = PM8001_CAN_QUEUE; |
| 507 | sha->core.shost = shost; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * pm8001_init_sas_add - initialize sas address |
| 512 | * @chip_info: our ha struct. |
| 513 | * |
| 514 | * Currently we just set the fixed SAS address to our HBA,for manufacture, |
| 515 | * it should read from the EEPROM |
| 516 | */ |
| 517 | static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha) |
| 518 | { |
| 519 | u8 i; |
| 520 | #ifdef PM8001_READ_VPD |
| 521 | DECLARE_COMPLETION_ONSTACK(completion); |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 522 | struct pm8001_ioctl_payload payload; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 523 | pm8001_ha->nvmd_completion = &completion; |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 524 | payload.minor_function = 0; |
| 525 | payload.length = 128; |
| 526 | payload.func_specific = kzalloc(128, GFP_KERNEL); |
| 527 | PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 528 | wait_for_completion(&completion); |
| 529 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
| 530 | memcpy(&pm8001_ha->phy[i].dev_sas_addr, pm8001_ha->sas_addr, |
| 531 | SAS_ADDR_SIZE); |
| 532 | PM8001_INIT_DBG(pm8001_ha, |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 533 | pm8001_printk("phy %d sas_addr = %016llx \n", i, |
| 534 | pm8001_ha->phy[i].dev_sas_addr)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 535 | } |
| 536 | #else |
| 537 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 538 | pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 539 | pm8001_ha->phy[i].dev_sas_addr = |
| 540 | cpu_to_be64((u64) |
| 541 | (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr)); |
| 542 | } |
| 543 | memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr, |
| 544 | SAS_ADDR_SIZE); |
| 545 | #endif |
| 546 | } |
| 547 | |
| 548 | #ifdef PM8001_USE_MSIX |
| 549 | /** |
| 550 | * pm8001_setup_msix - enable MSI-X interrupt |
| 551 | * @chip_info: our ha struct. |
| 552 | * @irq_handler: irq_handler |
| 553 | */ |
| 554 | static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha, |
| 555 | irq_handler_t irq_handler) |
| 556 | { |
| 557 | u32 i = 0, j = 0; |
| 558 | u32 number_of_intr = 1; |
| 559 | int flag = 0; |
| 560 | u32 max_entry; |
| 561 | int rc; |
| 562 | max_entry = sizeof(pm8001_ha->msix_entries) / |
| 563 | sizeof(pm8001_ha->msix_entries[0]); |
| 564 | flag |= IRQF_DISABLED; |
| 565 | for (i = 0; i < max_entry ; i++) |
| 566 | pm8001_ha->msix_entries[i].entry = i; |
| 567 | rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries, |
| 568 | number_of_intr); |
| 569 | pm8001_ha->number_of_intr = number_of_intr; |
| 570 | if (!rc) { |
| 571 | for (i = 0; i < number_of_intr; i++) { |
| 572 | if (request_irq(pm8001_ha->msix_entries[i].vector, |
| 573 | irq_handler, flag, DRV_NAME, |
| 574 | SHOST_TO_SAS_HA(pm8001_ha->shost))) { |
| 575 | for (j = 0; j < i; j++) |
| 576 | free_irq( |
| 577 | pm8001_ha->msix_entries[j].vector, |
| 578 | SHOST_TO_SAS_HA(pm8001_ha->shost)); |
| 579 | pci_disable_msix(pm8001_ha->pdev); |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | return rc; |
| 585 | } |
| 586 | #endif |
| 587 | |
| 588 | /** |
| 589 | * pm8001_request_irq - register interrupt |
| 590 | * @chip_info: our ha struct. |
| 591 | */ |
| 592 | static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha) |
| 593 | { |
| 594 | struct pci_dev *pdev; |
| 595 | irq_handler_t irq_handler = pm8001_interrupt; |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 596 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 597 | |
| 598 | pdev = pm8001_ha->pdev; |
| 599 | |
| 600 | #ifdef PM8001_USE_MSIX |
| 601 | if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) |
| 602 | return pm8001_setup_msix(pm8001_ha, irq_handler); |
| 603 | else |
| 604 | goto intx; |
| 605 | #endif |
| 606 | |
| 607 | intx: |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 608 | /* initialize the INT-X interrupt */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 609 | rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED, DRV_NAME, |
| 610 | SHOST_TO_SAS_HA(pm8001_ha->shost)); |
| 611 | return rc; |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * pm8001_pci_probe - probe supported device |
| 616 | * @pdev: pci device which kernel has been prepared for. |
| 617 | * @ent: pci device id |
| 618 | * |
| 619 | * This function is the main initialization function, when register a new |
| 620 | * pci driver it is invoked, all struct an hardware initilization should be done |
| 621 | * here, also, register interrupt |
| 622 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 623 | static int pm8001_pci_probe(struct pci_dev *pdev, |
| 624 | const struct pci_device_id *ent) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 625 | { |
| 626 | unsigned int rc; |
| 627 | u32 pci_reg; |
| 628 | struct pm8001_hba_info *pm8001_ha; |
| 629 | struct Scsi_Host *shost = NULL; |
| 630 | const struct pm8001_chip_info *chip; |
| 631 | |
| 632 | dev_printk(KERN_INFO, &pdev->dev, |
| 633 | "pm8001: driver version %s\n", DRV_VERSION); |
| 634 | rc = pci_enable_device(pdev); |
| 635 | if (rc) |
| 636 | goto err_out_enable; |
| 637 | pci_set_master(pdev); |
| 638 | /* |
| 639 | * Enable pci slot busmaster by setting pci command register. |
| 640 | * This is required by FW for Cyclone card. |
| 641 | */ |
| 642 | |
| 643 | pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg); |
| 644 | pci_reg |= 0x157; |
| 645 | pci_write_config_dword(pdev, PCI_COMMAND, pci_reg); |
| 646 | rc = pci_request_regions(pdev, DRV_NAME); |
| 647 | if (rc) |
| 648 | goto err_out_disable; |
| 649 | rc = pci_go_44(pdev); |
| 650 | if (rc) |
| 651 | goto err_out_regions; |
| 652 | |
| 653 | shost = scsi_host_alloc(&pm8001_sht, sizeof(void *)); |
| 654 | if (!shost) { |
| 655 | rc = -ENOMEM; |
| 656 | goto err_out_regions; |
| 657 | } |
| 658 | chip = &pm8001_chips[ent->driver_data]; |
| 659 | SHOST_TO_SAS_HA(shost) = |
Julia Lawall | 3dbf6c0 | 2009-12-19 08:17:27 +0100 | [diff] [blame] | 660 | kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 661 | if (!SHOST_TO_SAS_HA(shost)) { |
| 662 | rc = -ENOMEM; |
| 663 | goto err_out_free_host; |
| 664 | } |
| 665 | |
| 666 | rc = pm8001_prep_sas_ha_init(shost, chip); |
| 667 | if (rc) { |
| 668 | rc = -ENOMEM; |
| 669 | goto err_out_free; |
| 670 | } |
| 671 | pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost)); |
| 672 | pm8001_ha = pm8001_pci_alloc(pdev, chip_8001, shost); |
| 673 | if (!pm8001_ha) { |
| 674 | rc = -ENOMEM; |
| 675 | goto err_out_free; |
| 676 | } |
| 677 | list_add_tail(&pm8001_ha->list, &hba_list); |
| 678 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 679 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
| 680 | if (rc) |
| 681 | goto err_out_ha_free; |
| 682 | |
| 683 | rc = scsi_add_host(shost, &pdev->dev); |
| 684 | if (rc) |
| 685 | goto err_out_ha_free; |
| 686 | rc = pm8001_request_irq(pm8001_ha); |
| 687 | if (rc) |
| 688 | goto err_out_shost; |
| 689 | |
| 690 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha); |
| 691 | pm8001_init_sas_add(pm8001_ha); |
| 692 | pm8001_post_sas_ha_init(shost, chip); |
| 693 | rc = sas_register_ha(SHOST_TO_SAS_HA(shost)); |
| 694 | if (rc) |
| 695 | goto err_out_shost; |
| 696 | scsi_scan_host(pm8001_ha->shost); |
| 697 | return 0; |
| 698 | |
| 699 | err_out_shost: |
| 700 | scsi_remove_host(pm8001_ha->shost); |
| 701 | err_out_ha_free: |
| 702 | pm8001_free(pm8001_ha); |
| 703 | err_out_free: |
| 704 | kfree(SHOST_TO_SAS_HA(shost)); |
| 705 | err_out_free_host: |
| 706 | kfree(shost); |
| 707 | err_out_regions: |
| 708 | pci_release_regions(pdev); |
| 709 | err_out_disable: |
| 710 | pci_disable_device(pdev); |
| 711 | err_out_enable: |
| 712 | return rc; |
| 713 | } |
| 714 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 715 | static void pm8001_pci_remove(struct pci_dev *pdev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 716 | { |
| 717 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 718 | struct pm8001_hba_info *pm8001_ha; |
| 719 | int i; |
| 720 | pm8001_ha = sha->lldd_ha; |
| 721 | pci_set_drvdata(pdev, NULL); |
| 722 | sas_unregister_ha(sha); |
| 723 | sas_remove_host(pm8001_ha->shost); |
| 724 | list_del(&pm8001_ha->list); |
| 725 | scsi_remove_host(pm8001_ha->shost); |
| 726 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 727 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 728 | |
| 729 | #ifdef PM8001_USE_MSIX |
| 730 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 731 | synchronize_irq(pm8001_ha->msix_entries[i].vector); |
| 732 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 733 | free_irq(pm8001_ha->msix_entries[i].vector, sha); |
| 734 | pci_disable_msix(pdev); |
| 735 | #else |
| 736 | free_irq(pm8001_ha->irq, sha); |
| 737 | #endif |
| 738 | #ifdef PM8001_USE_TASKLET |
| 739 | tasklet_kill(&pm8001_ha->tasklet); |
| 740 | #endif |
| 741 | pm8001_free(pm8001_ha); |
| 742 | kfree(sha->sas_phy); |
| 743 | kfree(sha->sas_port); |
| 744 | kfree(sha); |
| 745 | pci_release_regions(pdev); |
| 746 | pci_disable_device(pdev); |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * pm8001_pci_suspend - power management suspend main entry point |
| 751 | * @pdev: PCI device struct |
| 752 | * @state: PM state change to (usually PCI_D3) |
| 753 | * |
| 754 | * Returns 0 success, anything else error. |
| 755 | */ |
| 756 | static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 757 | { |
| 758 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 759 | struct pm8001_hba_info *pm8001_ha; |
| 760 | int i , pos; |
| 761 | u32 device_state; |
| 762 | pm8001_ha = sha->lldd_ha; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 763 | flush_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 764 | scsi_block_requests(pm8001_ha->shost); |
| 765 | pos = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 766 | if (pos == 0) { |
| 767 | printk(KERN_ERR " PCI PM not supported\n"); |
| 768 | return -ENODEV; |
| 769 | } |
| 770 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 771 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 772 | #ifdef PM8001_USE_MSIX |
| 773 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 774 | synchronize_irq(pm8001_ha->msix_entries[i].vector); |
| 775 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 776 | free_irq(pm8001_ha->msix_entries[i].vector, sha); |
| 777 | pci_disable_msix(pdev); |
| 778 | #else |
| 779 | free_irq(pm8001_ha->irq, sha); |
| 780 | #endif |
| 781 | #ifdef PM8001_USE_TASKLET |
| 782 | tasklet_kill(&pm8001_ha->tasklet); |
| 783 | #endif |
| 784 | device_state = pci_choose_state(pdev, state); |
| 785 | pm8001_printk("pdev=0x%p, slot=%s, entering " |
| 786 | "operating state [D%d]\n", pdev, |
| 787 | pm8001_ha->name, device_state); |
| 788 | pci_save_state(pdev); |
| 789 | pci_disable_device(pdev); |
| 790 | pci_set_power_state(pdev, device_state); |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * pm8001_pci_resume - power management resume main entry point |
| 796 | * @pdev: PCI device struct |
| 797 | * |
| 798 | * Returns 0 success, anything else error. |
| 799 | */ |
| 800 | static int pm8001_pci_resume(struct pci_dev *pdev) |
| 801 | { |
| 802 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 803 | struct pm8001_hba_info *pm8001_ha; |
| 804 | int rc; |
| 805 | u32 device_state; |
| 806 | pm8001_ha = sha->lldd_ha; |
| 807 | device_state = pdev->current_state; |
| 808 | |
| 809 | pm8001_printk("pdev=0x%p, slot=%s, resuming from previous " |
| 810 | "operating state [D%d]\n", pdev, pm8001_ha->name, device_state); |
| 811 | |
| 812 | pci_set_power_state(pdev, PCI_D0); |
| 813 | pci_enable_wake(pdev, PCI_D0, 0); |
| 814 | pci_restore_state(pdev); |
| 815 | rc = pci_enable_device(pdev); |
| 816 | if (rc) { |
| 817 | pm8001_printk("slot=%s Enable device failed during resume\n", |
| 818 | pm8001_ha->name); |
| 819 | goto err_out_enable; |
| 820 | } |
| 821 | |
| 822 | pci_set_master(pdev); |
| 823 | rc = pci_go_44(pdev); |
| 824 | if (rc) |
| 825 | goto err_out_disable; |
| 826 | |
| 827 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 828 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
| 829 | if (rc) |
| 830 | goto err_out_disable; |
| 831 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 832 | rc = pm8001_request_irq(pm8001_ha); |
| 833 | if (rc) |
| 834 | goto err_out_disable; |
| 835 | #ifdef PM8001_USE_TASKLET |
| 836 | tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet, |
| 837 | (unsigned long)pm8001_ha); |
| 838 | #endif |
| 839 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha); |
| 840 | scsi_unblock_requests(pm8001_ha->shost); |
| 841 | return 0; |
| 842 | |
| 843 | err_out_disable: |
| 844 | scsi_remove_host(pm8001_ha->shost); |
| 845 | pci_disable_device(pdev); |
| 846 | err_out_enable: |
| 847 | return rc; |
| 848 | } |
| 849 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 850 | /* update of pci device, vendor id and driver data with |
| 851 | * unique value for each of the controller |
| 852 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 853 | static struct pci_device_id pm8001_pci_table[] = { |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 854 | { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 }, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 855 | { |
| 856 | PCI_DEVICE(0x117c, 0x0042), |
| 857 | .driver_data = chip_8001 |
| 858 | }, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 859 | /* Support for SPC/SPCv/SPCve controllers */ |
| 860 | { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 }, |
| 861 | { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 }, |
| 862 | { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 }, |
| 863 | { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 }, |
| 864 | { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 }, |
| 865 | { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 }, |
| 866 | { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 }, |
| 867 | { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 }, |
| 868 | { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 }, |
| 869 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 870 | PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 }, |
| 871 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 872 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 }, |
| 873 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 874 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 }, |
| 875 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 876 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 }, |
| 877 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 878 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 }, |
| 879 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 880 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 }, |
| 881 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 882 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 }, |
| 883 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 884 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 }, |
| 885 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 886 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 }, |
| 887 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 888 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 }, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 889 | {} /* terminate list */ |
| 890 | }; |
| 891 | |
| 892 | static struct pci_driver pm8001_pci_driver = { |
| 893 | .name = DRV_NAME, |
| 894 | .id_table = pm8001_pci_table, |
| 895 | .probe = pm8001_pci_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 896 | .remove = pm8001_pci_remove, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 897 | .suspend = pm8001_pci_suspend, |
| 898 | .resume = pm8001_pci_resume, |
| 899 | }; |
| 900 | |
| 901 | /** |
| 902 | * pm8001_init - initialize scsi transport template |
| 903 | */ |
| 904 | static int __init pm8001_init(void) |
| 905 | { |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 906 | int rc = -ENOMEM; |
| 907 | |
| 908 | pm8001_wq = alloc_workqueue("pm8001", 0, 0); |
| 909 | if (!pm8001_wq) |
| 910 | goto err; |
| 911 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 912 | pm8001_id = 0; |
| 913 | pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops); |
| 914 | if (!pm8001_stt) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 915 | goto err_wq; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 916 | rc = pci_register_driver(&pm8001_pci_driver); |
| 917 | if (rc) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 918 | goto err_tp; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 919 | return 0; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 920 | |
| 921 | err_tp: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 922 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 923 | err_wq: |
| 924 | destroy_workqueue(pm8001_wq); |
| 925 | err: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 926 | return rc; |
| 927 | } |
| 928 | |
| 929 | static void __exit pm8001_exit(void) |
| 930 | { |
| 931 | pci_unregister_driver(&pm8001_pci_driver); |
| 932 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 933 | destroy_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | module_init(pm8001_init); |
| 937 | module_exit(pm8001_exit); |
| 938 | |
| 939 | MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>"); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame^] | 940 | MODULE_DESCRIPTION( |
| 941 | "PMC-Sierra PM8001/8081/8088/8089 SAS/SATA controller driver"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 942 | MODULE_VERSION(DRV_VERSION); |
| 943 | MODULE_LICENSE("GPL"); |
| 944 | MODULE_DEVICE_TABLE(pci, pm8001_pci_table); |
| 945 | |