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 | */ |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 202 | static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha, |
| 203 | const struct pci_device_id *ent) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 204 | { |
| 205 | int i; |
| 206 | spin_lock_init(&pm8001_ha->lock); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 207 | PM8001_INIT_DBG(pm8001_ha, |
| 208 | pm8001_printk("pm8001_alloc: PHY:%x\n", |
| 209 | pm8001_ha->chip->n_phy)); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 210 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 211 | pm8001_phy_init(pm8001_ha, i); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 212 | pm8001_ha->port[i].wide_port_phymap = 0; |
| 213 | pm8001_ha->port[i].port_attached = 0; |
| 214 | pm8001_ha->port[i].port_state = 0; |
| 215 | INIT_LIST_HEAD(&pm8001_ha->port[i].list); |
| 216 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 217 | |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 218 | pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL); |
| 219 | if (!pm8001_ha->tags) |
| 220 | goto err_out; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 221 | /* MPI Memory region 1 for AAP Event Log for fw */ |
| 222 | pm8001_ha->memoryMap.region[AAP1].num_elements = 1; |
| 223 | pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE; |
| 224 | pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE; |
| 225 | pm8001_ha->memoryMap.region[AAP1].alignment = 32; |
| 226 | |
| 227 | /* MPI Memory region 2 for IOP Event Log for fw */ |
| 228 | pm8001_ha->memoryMap.region[IOP].num_elements = 1; |
| 229 | pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE; |
| 230 | pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE; |
| 231 | pm8001_ha->memoryMap.region[IOP].alignment = 32; |
| 232 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 233 | for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) { |
| 234 | /* MPI Memory region 3 for consumer Index of inbound queues */ |
| 235 | pm8001_ha->memoryMap.region[CI+i].num_elements = 1; |
| 236 | pm8001_ha->memoryMap.region[CI+i].element_size = 4; |
| 237 | pm8001_ha->memoryMap.region[CI+i].total_len = 4; |
| 238 | pm8001_ha->memoryMap.region[CI+i].alignment = 4; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 239 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 240 | if ((ent->driver_data) != chip_8001) { |
| 241 | /* MPI Memory region 5 inbound queues */ |
| 242 | pm8001_ha->memoryMap.region[IB+i].num_elements = |
| 243 | PM8001_MPI_QUEUE; |
| 244 | pm8001_ha->memoryMap.region[IB+i].element_size = 128; |
| 245 | pm8001_ha->memoryMap.region[IB+i].total_len = |
| 246 | PM8001_MPI_QUEUE * 128; |
| 247 | pm8001_ha->memoryMap.region[IB+i].alignment = 128; |
| 248 | } else { |
| 249 | pm8001_ha->memoryMap.region[IB+i].num_elements = |
| 250 | PM8001_MPI_QUEUE; |
| 251 | pm8001_ha->memoryMap.region[IB+i].element_size = 64; |
| 252 | pm8001_ha->memoryMap.region[IB+i].total_len = |
| 253 | PM8001_MPI_QUEUE * 64; |
| 254 | pm8001_ha->memoryMap.region[IB+i].alignment = 64; |
| 255 | } |
| 256 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 257 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 258 | for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) { |
| 259 | /* MPI Memory region 4 for producer Index of outbound queues */ |
| 260 | pm8001_ha->memoryMap.region[PI+i].num_elements = 1; |
| 261 | pm8001_ha->memoryMap.region[PI+i].element_size = 4; |
| 262 | pm8001_ha->memoryMap.region[PI+i].total_len = 4; |
| 263 | pm8001_ha->memoryMap.region[PI+i].alignment = 4; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 264 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 265 | if (ent->driver_data != chip_8001) { |
| 266 | /* MPI Memory region 6 Outbound queues */ |
| 267 | pm8001_ha->memoryMap.region[OB+i].num_elements = |
| 268 | PM8001_MPI_QUEUE; |
| 269 | pm8001_ha->memoryMap.region[OB+i].element_size = 128; |
| 270 | pm8001_ha->memoryMap.region[OB+i].total_len = |
| 271 | PM8001_MPI_QUEUE * 128; |
| 272 | pm8001_ha->memoryMap.region[OB+i].alignment = 128; |
| 273 | } else { |
| 274 | /* MPI Memory region 6 Outbound queues */ |
| 275 | pm8001_ha->memoryMap.region[OB+i].num_elements = |
| 276 | PM8001_MPI_QUEUE; |
| 277 | pm8001_ha->memoryMap.region[OB+i].element_size = 64; |
| 278 | pm8001_ha->memoryMap.region[OB+i].total_len = |
| 279 | PM8001_MPI_QUEUE * 64; |
| 280 | pm8001_ha->memoryMap.region[OB+i].alignment = 64; |
| 281 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 282 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 283 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 284 | /* Memory region write DMA*/ |
| 285 | pm8001_ha->memoryMap.region[NVMD].num_elements = 1; |
| 286 | pm8001_ha->memoryMap.region[NVMD].element_size = 4096; |
| 287 | pm8001_ha->memoryMap.region[NVMD].total_len = 4096; |
| 288 | /* Memory region for devices*/ |
| 289 | pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1; |
| 290 | pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES * |
| 291 | sizeof(struct pm8001_device); |
| 292 | pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES * |
| 293 | sizeof(struct pm8001_device); |
| 294 | |
| 295 | /* Memory region for ccb_info*/ |
| 296 | pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1; |
| 297 | pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB * |
| 298 | sizeof(struct pm8001_ccb_info); |
| 299 | pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB * |
| 300 | sizeof(struct pm8001_ccb_info); |
| 301 | |
| 302 | for (i = 0; i < USI_MAX_MEMCNT; i++) { |
| 303 | if (pm8001_mem_alloc(pm8001_ha->pdev, |
| 304 | &pm8001_ha->memoryMap.region[i].virt_ptr, |
| 305 | &pm8001_ha->memoryMap.region[i].phys_addr, |
| 306 | &pm8001_ha->memoryMap.region[i].phys_addr_hi, |
| 307 | &pm8001_ha->memoryMap.region[i].phys_addr_lo, |
| 308 | pm8001_ha->memoryMap.region[i].total_len, |
| 309 | pm8001_ha->memoryMap.region[i].alignment) != 0) { |
| 310 | PM8001_FAIL_DBG(pm8001_ha, |
| 311 | pm8001_printk("Mem%d alloc failed\n", |
| 312 | i)); |
| 313 | goto err_out; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr; |
| 318 | for (i = 0; i < PM8001_MAX_DEVICES; i++) { |
| 319 | pm8001_ha->devices[i].dev_type = NO_DEVICE; |
| 320 | pm8001_ha->devices[i].id = i; |
| 321 | pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES; |
| 322 | pm8001_ha->devices[i].running_req = 0; |
| 323 | } |
| 324 | pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr; |
| 325 | for (i = 0; i < PM8001_MAX_CCB; i++) { |
| 326 | pm8001_ha->ccb_info[i].ccb_dma_handle = |
| 327 | pm8001_ha->memoryMap.region[CCB_MEM].phys_addr + |
| 328 | i * sizeof(struct pm8001_ccb_info); |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 329 | pm8001_ha->ccb_info[i].task = NULL; |
| 330 | pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff; |
| 331 | pm8001_ha->ccb_info[i].device = NULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 332 | ++pm8001_ha->tags_num; |
| 333 | } |
| 334 | pm8001_ha->flags = PM8001F_INIT_TIME; |
| 335 | /* Initialize tags */ |
| 336 | pm8001_tag_init(pm8001_ha); |
| 337 | return 0; |
| 338 | err_out: |
| 339 | return 1; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * pm8001_ioremap - remap the pci high physical address to kernal virtual |
| 344 | * address so that we can access them. |
| 345 | * @pm8001_ha:our hba structure. |
| 346 | */ |
| 347 | static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha) |
| 348 | { |
| 349 | u32 bar; |
| 350 | u32 logicalBar = 0; |
| 351 | struct pci_dev *pdev; |
| 352 | |
| 353 | pdev = pm8001_ha->pdev; |
| 354 | /* map pci mem (PMC pci base 0-3)*/ |
| 355 | for (bar = 0; bar < 6; bar++) { |
| 356 | /* |
| 357 | ** logical BARs for SPC: |
| 358 | ** bar 0 and 1 - logical BAR0 |
| 359 | ** bar 2 and 3 - logical BAR1 |
| 360 | ** bar4 - logical BAR2 |
| 361 | ** bar5 - logical BAR3 |
| 362 | ** Skip the appropriate assignments: |
| 363 | */ |
| 364 | if ((bar == 1) || (bar == 3)) |
| 365 | continue; |
| 366 | if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { |
| 367 | pm8001_ha->io_mem[logicalBar].membase = |
| 368 | pci_resource_start(pdev, bar); |
| 369 | pm8001_ha->io_mem[logicalBar].membase &= |
| 370 | (u32)PCI_BASE_ADDRESS_MEM_MASK; |
| 371 | pm8001_ha->io_mem[logicalBar].memsize = |
| 372 | pci_resource_len(pdev, bar); |
| 373 | pm8001_ha->io_mem[logicalBar].memvirtaddr = |
| 374 | ioremap(pm8001_ha->io_mem[logicalBar].membase, |
| 375 | pm8001_ha->io_mem[logicalBar].memsize); |
| 376 | PM8001_INIT_DBG(pm8001_ha, |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 377 | pm8001_printk("PCI: bar %d, logicalBar %d ", |
| 378 | bar, logicalBar)); |
| 379 | PM8001_INIT_DBG(pm8001_ha, pm8001_printk( |
| 380 | "base addr %llx virt_addr=%llx len=%d\n", |
| 381 | (u64)pm8001_ha->io_mem[logicalBar].membase, |
| 382 | (u64)pm8001_ha->io_mem[logicalBar].memvirtaddr, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 383 | pm8001_ha->io_mem[logicalBar].memsize)); |
| 384 | } else { |
| 385 | pm8001_ha->io_mem[logicalBar].membase = 0; |
| 386 | pm8001_ha->io_mem[logicalBar].memsize = 0; |
| 387 | pm8001_ha->io_mem[logicalBar].memvirtaddr = 0; |
| 388 | } |
| 389 | logicalBar++; |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * pm8001_pci_alloc - initialize our ha card structure |
| 396 | * @pdev: pci device. |
| 397 | * @ent: ent |
| 398 | * @shost: scsi host struct which has been initialized before. |
| 399 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 400 | static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev, |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 401 | const struct pci_device_id *ent, |
| 402 | struct Scsi_Host *shost) |
| 403 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 404 | { |
| 405 | struct pm8001_hba_info *pm8001_ha; |
| 406 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 407 | |
| 408 | |
| 409 | pm8001_ha = sha->lldd_ha; |
| 410 | if (!pm8001_ha) |
| 411 | return NULL; |
| 412 | |
| 413 | pm8001_ha->pdev = pdev; |
| 414 | pm8001_ha->dev = &pdev->dev; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 415 | pm8001_ha->chip_id = ent->driver_data; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 416 | pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id]; |
| 417 | pm8001_ha->irq = pdev->irq; |
| 418 | pm8001_ha->sas = sha; |
| 419 | pm8001_ha->shost = shost; |
| 420 | pm8001_ha->id = pm8001_id++; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 421 | pm8001_ha->logging_level = 0x01; |
| 422 | sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id); |
| 423 | #ifdef PM8001_USE_TASKLET |
| 424 | tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet, |
| 425 | (unsigned long)pm8001_ha); |
| 426 | #endif |
| 427 | pm8001_ioremap(pm8001_ha); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 428 | if (!pm8001_alloc(pm8001_ha, ent)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 429 | return pm8001_ha; |
| 430 | pm8001_free(pm8001_ha); |
| 431 | return NULL; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit |
| 436 | * @pdev: pci device. |
| 437 | */ |
| 438 | static int pci_go_44(struct pci_dev *pdev) |
| 439 | { |
| 440 | int rc; |
| 441 | |
| 442 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) { |
| 443 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44)); |
| 444 | if (rc) { |
| 445 | rc = pci_set_consistent_dma_mask(pdev, |
| 446 | DMA_BIT_MASK(32)); |
| 447 | if (rc) { |
| 448 | dev_printk(KERN_ERR, &pdev->dev, |
| 449 | "44-bit DMA enable failed\n"); |
| 450 | return rc; |
| 451 | } |
| 452 | } |
| 453 | } else { |
| 454 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 455 | if (rc) { |
| 456 | dev_printk(KERN_ERR, &pdev->dev, |
| 457 | "32-bit DMA enable failed\n"); |
| 458 | return rc; |
| 459 | } |
| 460 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 461 | if (rc) { |
| 462 | dev_printk(KERN_ERR, &pdev->dev, |
| 463 | "32-bit consistent DMA enable failed\n"); |
| 464 | return rc; |
| 465 | } |
| 466 | } |
| 467 | return rc; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them. |
| 472 | * @shost: scsi host which has been allocated outside. |
| 473 | * @chip_info: our ha struct. |
| 474 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 475 | static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost, |
| 476 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 477 | { |
| 478 | int phy_nr, port_nr; |
| 479 | struct asd_sas_phy **arr_phy; |
| 480 | struct asd_sas_port **arr_port; |
| 481 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 482 | |
| 483 | phy_nr = chip_info->n_phy; |
| 484 | port_nr = phy_nr; |
| 485 | memset(sha, 0x00, sizeof(*sha)); |
| 486 | arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL); |
| 487 | if (!arr_phy) |
| 488 | goto exit; |
| 489 | arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL); |
| 490 | if (!arr_port) |
| 491 | goto exit_free2; |
| 492 | |
| 493 | sha->sas_phy = arr_phy; |
| 494 | sha->sas_port = arr_port; |
| 495 | sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL); |
| 496 | if (!sha->lldd_ha) |
| 497 | goto exit_free1; |
| 498 | |
| 499 | shost->transportt = pm8001_stt; |
| 500 | shost->max_id = PM8001_MAX_DEVICES; |
| 501 | shost->max_lun = 8; |
| 502 | shost->max_channel = 0; |
| 503 | shost->unique_id = pm8001_id; |
| 504 | shost->max_cmd_len = 16; |
| 505 | shost->can_queue = PM8001_CAN_QUEUE; |
| 506 | shost->cmd_per_lun = 32; |
| 507 | return 0; |
| 508 | exit_free1: |
| 509 | kfree(arr_port); |
| 510 | exit_free2: |
| 511 | kfree(arr_phy); |
| 512 | exit: |
| 513 | return -1; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas |
| 518 | * @shost: scsi host which has been allocated outside |
| 519 | * @chip_info: our ha struct. |
| 520 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 521 | static void pm8001_post_sas_ha_init(struct Scsi_Host *shost, |
| 522 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 523 | { |
| 524 | int i = 0; |
| 525 | struct pm8001_hba_info *pm8001_ha; |
| 526 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 527 | |
| 528 | pm8001_ha = sha->lldd_ha; |
| 529 | for (i = 0; i < chip_info->n_phy; i++) { |
| 530 | sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy; |
| 531 | sha->sas_port[i] = &pm8001_ha->port[i].sas_port; |
| 532 | } |
| 533 | sha->sas_ha_name = DRV_NAME; |
| 534 | sha->dev = pm8001_ha->dev; |
| 535 | |
| 536 | sha->lldd_module = THIS_MODULE; |
| 537 | sha->sas_addr = &pm8001_ha->sas_addr[0]; |
| 538 | sha->num_phys = chip_info->n_phy; |
| 539 | sha->lldd_max_execute_num = 1; |
| 540 | sha->lldd_queue_size = PM8001_CAN_QUEUE; |
| 541 | sha->core.shost = shost; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * pm8001_init_sas_add - initialize sas address |
| 546 | * @chip_info: our ha struct. |
| 547 | * |
| 548 | * Currently we just set the fixed SAS address to our HBA,for manufacture, |
| 549 | * it should read from the EEPROM |
| 550 | */ |
| 551 | static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha) |
| 552 | { |
| 553 | u8 i; |
| 554 | #ifdef PM8001_READ_VPD |
| 555 | DECLARE_COMPLETION_ONSTACK(completion); |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 556 | struct pm8001_ioctl_payload payload; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 557 | pm8001_ha->nvmd_completion = &completion; |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 558 | payload.minor_function = 0; |
| 559 | payload.length = 128; |
| 560 | payload.func_specific = kzalloc(128, GFP_KERNEL); |
| 561 | PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 562 | wait_for_completion(&completion); |
| 563 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
| 564 | memcpy(&pm8001_ha->phy[i].dev_sas_addr, pm8001_ha->sas_addr, |
| 565 | SAS_ADDR_SIZE); |
| 566 | PM8001_INIT_DBG(pm8001_ha, |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 567 | pm8001_printk("phy %d sas_addr = %016llx \n", i, |
| 568 | pm8001_ha->phy[i].dev_sas_addr)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 569 | } |
| 570 | #else |
| 571 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 572 | pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 573 | pm8001_ha->phy[i].dev_sas_addr = |
| 574 | cpu_to_be64((u64) |
| 575 | (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr)); |
| 576 | } |
| 577 | memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr, |
| 578 | SAS_ADDR_SIZE); |
| 579 | #endif |
| 580 | } |
| 581 | |
| 582 | #ifdef PM8001_USE_MSIX |
| 583 | /** |
| 584 | * pm8001_setup_msix - enable MSI-X interrupt |
| 585 | * @chip_info: our ha struct. |
| 586 | * @irq_handler: irq_handler |
| 587 | */ |
| 588 | static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha, |
| 589 | irq_handler_t irq_handler) |
| 590 | { |
| 591 | u32 i = 0, j = 0; |
| 592 | u32 number_of_intr = 1; |
| 593 | int flag = 0; |
| 594 | u32 max_entry; |
| 595 | int rc; |
| 596 | max_entry = sizeof(pm8001_ha->msix_entries) / |
| 597 | sizeof(pm8001_ha->msix_entries[0]); |
| 598 | flag |= IRQF_DISABLED; |
| 599 | for (i = 0; i < max_entry ; i++) |
| 600 | pm8001_ha->msix_entries[i].entry = i; |
| 601 | rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries, |
| 602 | number_of_intr); |
| 603 | pm8001_ha->number_of_intr = number_of_intr; |
| 604 | if (!rc) { |
| 605 | for (i = 0; i < number_of_intr; i++) { |
| 606 | if (request_irq(pm8001_ha->msix_entries[i].vector, |
| 607 | irq_handler, flag, DRV_NAME, |
| 608 | SHOST_TO_SAS_HA(pm8001_ha->shost))) { |
| 609 | for (j = 0; j < i; j++) |
| 610 | free_irq( |
| 611 | pm8001_ha->msix_entries[j].vector, |
| 612 | SHOST_TO_SAS_HA(pm8001_ha->shost)); |
| 613 | pci_disable_msix(pm8001_ha->pdev); |
| 614 | break; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | return rc; |
| 619 | } |
| 620 | #endif |
| 621 | |
| 622 | /** |
| 623 | * pm8001_request_irq - register interrupt |
| 624 | * @chip_info: our ha struct. |
| 625 | */ |
| 626 | static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha) |
| 627 | { |
| 628 | struct pci_dev *pdev; |
| 629 | irq_handler_t irq_handler = pm8001_interrupt; |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 630 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 631 | |
| 632 | pdev = pm8001_ha->pdev; |
| 633 | |
| 634 | #ifdef PM8001_USE_MSIX |
| 635 | if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) |
| 636 | return pm8001_setup_msix(pm8001_ha, irq_handler); |
| 637 | else |
| 638 | goto intx; |
| 639 | #endif |
| 640 | |
| 641 | intx: |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 642 | /* initialize the INT-X interrupt */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 643 | rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED, DRV_NAME, |
| 644 | SHOST_TO_SAS_HA(pm8001_ha->shost)); |
| 645 | return rc; |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * pm8001_pci_probe - probe supported device |
| 650 | * @pdev: pci device which kernel has been prepared for. |
| 651 | * @ent: pci device id |
| 652 | * |
| 653 | * This function is the main initialization function, when register a new |
| 654 | * pci driver it is invoked, all struct an hardware initilization should be done |
| 655 | * here, also, register interrupt |
| 656 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 657 | static int pm8001_pci_probe(struct pci_dev *pdev, |
| 658 | const struct pci_device_id *ent) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 659 | { |
| 660 | unsigned int rc; |
| 661 | u32 pci_reg; |
| 662 | struct pm8001_hba_info *pm8001_ha; |
| 663 | struct Scsi_Host *shost = NULL; |
| 664 | const struct pm8001_chip_info *chip; |
| 665 | |
| 666 | dev_printk(KERN_INFO, &pdev->dev, |
| 667 | "pm8001: driver version %s\n", DRV_VERSION); |
| 668 | rc = pci_enable_device(pdev); |
| 669 | if (rc) |
| 670 | goto err_out_enable; |
| 671 | pci_set_master(pdev); |
| 672 | /* |
| 673 | * Enable pci slot busmaster by setting pci command register. |
| 674 | * This is required by FW for Cyclone card. |
| 675 | */ |
| 676 | |
| 677 | pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg); |
| 678 | pci_reg |= 0x157; |
| 679 | pci_write_config_dword(pdev, PCI_COMMAND, pci_reg); |
| 680 | rc = pci_request_regions(pdev, DRV_NAME); |
| 681 | if (rc) |
| 682 | goto err_out_disable; |
| 683 | rc = pci_go_44(pdev); |
| 684 | if (rc) |
| 685 | goto err_out_regions; |
| 686 | |
| 687 | shost = scsi_host_alloc(&pm8001_sht, sizeof(void *)); |
| 688 | if (!shost) { |
| 689 | rc = -ENOMEM; |
| 690 | goto err_out_regions; |
| 691 | } |
| 692 | chip = &pm8001_chips[ent->driver_data]; |
| 693 | SHOST_TO_SAS_HA(shost) = |
Julia Lawall | 3dbf6c0 | 2009-12-19 08:17:27 +0100 | [diff] [blame] | 694 | kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 695 | if (!SHOST_TO_SAS_HA(shost)) { |
| 696 | rc = -ENOMEM; |
| 697 | goto err_out_free_host; |
| 698 | } |
| 699 | |
| 700 | rc = pm8001_prep_sas_ha_init(shost, chip); |
| 701 | if (rc) { |
| 702 | rc = -ENOMEM; |
| 703 | goto err_out_free; |
| 704 | } |
| 705 | pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost)); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame^] | 706 | /* ent->driver variable is used to differentiate between controllers */ |
| 707 | pm8001_ha = pm8001_pci_alloc(pdev, ent, shost); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 708 | if (!pm8001_ha) { |
| 709 | rc = -ENOMEM; |
| 710 | goto err_out_free; |
| 711 | } |
| 712 | list_add_tail(&pm8001_ha->list, &hba_list); |
| 713 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 714 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
| 715 | if (rc) |
| 716 | goto err_out_ha_free; |
| 717 | |
| 718 | rc = scsi_add_host(shost, &pdev->dev); |
| 719 | if (rc) |
| 720 | goto err_out_ha_free; |
| 721 | rc = pm8001_request_irq(pm8001_ha); |
| 722 | if (rc) |
| 723 | goto err_out_shost; |
| 724 | |
| 725 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha); |
| 726 | pm8001_init_sas_add(pm8001_ha); |
| 727 | pm8001_post_sas_ha_init(shost, chip); |
| 728 | rc = sas_register_ha(SHOST_TO_SAS_HA(shost)); |
| 729 | if (rc) |
| 730 | goto err_out_shost; |
| 731 | scsi_scan_host(pm8001_ha->shost); |
| 732 | return 0; |
| 733 | |
| 734 | err_out_shost: |
| 735 | scsi_remove_host(pm8001_ha->shost); |
| 736 | err_out_ha_free: |
| 737 | pm8001_free(pm8001_ha); |
| 738 | err_out_free: |
| 739 | kfree(SHOST_TO_SAS_HA(shost)); |
| 740 | err_out_free_host: |
| 741 | kfree(shost); |
| 742 | err_out_regions: |
| 743 | pci_release_regions(pdev); |
| 744 | err_out_disable: |
| 745 | pci_disable_device(pdev); |
| 746 | err_out_enable: |
| 747 | return rc; |
| 748 | } |
| 749 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 750 | static void pm8001_pci_remove(struct pci_dev *pdev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 751 | { |
| 752 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 753 | struct pm8001_hba_info *pm8001_ha; |
| 754 | int i; |
| 755 | pm8001_ha = sha->lldd_ha; |
| 756 | pci_set_drvdata(pdev, NULL); |
| 757 | sas_unregister_ha(sha); |
| 758 | sas_remove_host(pm8001_ha->shost); |
| 759 | list_del(&pm8001_ha->list); |
| 760 | scsi_remove_host(pm8001_ha->shost); |
| 761 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 762 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 763 | |
| 764 | #ifdef PM8001_USE_MSIX |
| 765 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 766 | synchronize_irq(pm8001_ha->msix_entries[i].vector); |
| 767 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 768 | free_irq(pm8001_ha->msix_entries[i].vector, sha); |
| 769 | pci_disable_msix(pdev); |
| 770 | #else |
| 771 | free_irq(pm8001_ha->irq, sha); |
| 772 | #endif |
| 773 | #ifdef PM8001_USE_TASKLET |
| 774 | tasklet_kill(&pm8001_ha->tasklet); |
| 775 | #endif |
| 776 | pm8001_free(pm8001_ha); |
| 777 | kfree(sha->sas_phy); |
| 778 | kfree(sha->sas_port); |
| 779 | kfree(sha); |
| 780 | pci_release_regions(pdev); |
| 781 | pci_disable_device(pdev); |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * pm8001_pci_suspend - power management suspend main entry point |
| 786 | * @pdev: PCI device struct |
| 787 | * @state: PM state change to (usually PCI_D3) |
| 788 | * |
| 789 | * Returns 0 success, anything else error. |
| 790 | */ |
| 791 | static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 792 | { |
| 793 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 794 | struct pm8001_hba_info *pm8001_ha; |
| 795 | int i , pos; |
| 796 | u32 device_state; |
| 797 | pm8001_ha = sha->lldd_ha; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 798 | flush_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 799 | scsi_block_requests(pm8001_ha->shost); |
| 800 | pos = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 801 | if (pos == 0) { |
| 802 | printk(KERN_ERR " PCI PM not supported\n"); |
| 803 | return -ENODEV; |
| 804 | } |
| 805 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 806 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 807 | #ifdef PM8001_USE_MSIX |
| 808 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 809 | synchronize_irq(pm8001_ha->msix_entries[i].vector); |
| 810 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
| 811 | free_irq(pm8001_ha->msix_entries[i].vector, sha); |
| 812 | pci_disable_msix(pdev); |
| 813 | #else |
| 814 | free_irq(pm8001_ha->irq, sha); |
| 815 | #endif |
| 816 | #ifdef PM8001_USE_TASKLET |
| 817 | tasklet_kill(&pm8001_ha->tasklet); |
| 818 | #endif |
| 819 | device_state = pci_choose_state(pdev, state); |
| 820 | pm8001_printk("pdev=0x%p, slot=%s, entering " |
| 821 | "operating state [D%d]\n", pdev, |
| 822 | pm8001_ha->name, device_state); |
| 823 | pci_save_state(pdev); |
| 824 | pci_disable_device(pdev); |
| 825 | pci_set_power_state(pdev, device_state); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * pm8001_pci_resume - power management resume main entry point |
| 831 | * @pdev: PCI device struct |
| 832 | * |
| 833 | * Returns 0 success, anything else error. |
| 834 | */ |
| 835 | static int pm8001_pci_resume(struct pci_dev *pdev) |
| 836 | { |
| 837 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 838 | struct pm8001_hba_info *pm8001_ha; |
| 839 | int rc; |
| 840 | u32 device_state; |
| 841 | pm8001_ha = sha->lldd_ha; |
| 842 | device_state = pdev->current_state; |
| 843 | |
| 844 | pm8001_printk("pdev=0x%p, slot=%s, resuming from previous " |
| 845 | "operating state [D%d]\n", pdev, pm8001_ha->name, device_state); |
| 846 | |
| 847 | pci_set_power_state(pdev, PCI_D0); |
| 848 | pci_enable_wake(pdev, PCI_D0, 0); |
| 849 | pci_restore_state(pdev); |
| 850 | rc = pci_enable_device(pdev); |
| 851 | if (rc) { |
| 852 | pm8001_printk("slot=%s Enable device failed during resume\n", |
| 853 | pm8001_ha->name); |
| 854 | goto err_out_enable; |
| 855 | } |
| 856 | |
| 857 | pci_set_master(pdev); |
| 858 | rc = pci_go_44(pdev); |
| 859 | if (rc) |
| 860 | goto err_out_disable; |
| 861 | |
| 862 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha, 0x252acbcd); |
| 863 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
| 864 | if (rc) |
| 865 | goto err_out_disable; |
| 866 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha); |
| 867 | rc = pm8001_request_irq(pm8001_ha); |
| 868 | if (rc) |
| 869 | goto err_out_disable; |
| 870 | #ifdef PM8001_USE_TASKLET |
| 871 | tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet, |
| 872 | (unsigned long)pm8001_ha); |
| 873 | #endif |
| 874 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha); |
| 875 | scsi_unblock_requests(pm8001_ha->shost); |
| 876 | return 0; |
| 877 | |
| 878 | err_out_disable: |
| 879 | scsi_remove_host(pm8001_ha->shost); |
| 880 | pci_disable_device(pdev); |
| 881 | err_out_enable: |
| 882 | return rc; |
| 883 | } |
| 884 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 885 | /* update of pci device, vendor id and driver data with |
| 886 | * unique value for each of the controller |
| 887 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 888 | static struct pci_device_id pm8001_pci_table[] = { |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 889 | { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 }, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 890 | { |
| 891 | PCI_DEVICE(0x117c, 0x0042), |
| 892 | .driver_data = chip_8001 |
| 893 | }, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 894 | /* Support for SPC/SPCv/SPCve controllers */ |
| 895 | { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 }, |
| 896 | { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 }, |
| 897 | { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 }, |
| 898 | { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 }, |
| 899 | { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 }, |
| 900 | { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 }, |
| 901 | { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 }, |
| 902 | { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 }, |
| 903 | { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 }, |
| 904 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 905 | PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 }, |
| 906 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 907 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 }, |
| 908 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 909 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 }, |
| 910 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 911 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 }, |
| 912 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 913 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 }, |
| 914 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 915 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 }, |
| 916 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 917 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 }, |
| 918 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 919 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 }, |
| 920 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 921 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 }, |
| 922 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 923 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 }, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 924 | {} /* terminate list */ |
| 925 | }; |
| 926 | |
| 927 | static struct pci_driver pm8001_pci_driver = { |
| 928 | .name = DRV_NAME, |
| 929 | .id_table = pm8001_pci_table, |
| 930 | .probe = pm8001_pci_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 931 | .remove = pm8001_pci_remove, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 932 | .suspend = pm8001_pci_suspend, |
| 933 | .resume = pm8001_pci_resume, |
| 934 | }; |
| 935 | |
| 936 | /** |
| 937 | * pm8001_init - initialize scsi transport template |
| 938 | */ |
| 939 | static int __init pm8001_init(void) |
| 940 | { |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 941 | int rc = -ENOMEM; |
| 942 | |
| 943 | pm8001_wq = alloc_workqueue("pm8001", 0, 0); |
| 944 | if (!pm8001_wq) |
| 945 | goto err; |
| 946 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 947 | pm8001_id = 0; |
| 948 | pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops); |
| 949 | if (!pm8001_stt) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 950 | goto err_wq; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 951 | rc = pci_register_driver(&pm8001_pci_driver); |
| 952 | if (rc) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 953 | goto err_tp; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 954 | return 0; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 955 | |
| 956 | err_tp: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 957 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 958 | err_wq: |
| 959 | destroy_workqueue(pm8001_wq); |
| 960 | err: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 961 | return rc; |
| 962 | } |
| 963 | |
| 964 | static void __exit pm8001_exit(void) |
| 965 | { |
| 966 | pci_unregister_driver(&pm8001_pci_driver); |
| 967 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 968 | destroy_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | module_init(pm8001_init); |
| 972 | module_exit(pm8001_exit); |
| 973 | |
| 974 | MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>"); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 975 | MODULE_DESCRIPTION( |
| 976 | "PMC-Sierra PM8001/8081/8088/8089 SAS/SATA controller driver"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 977 | MODULE_VERSION(DRV_VERSION); |
| 978 | MODULE_LICENSE("GPL"); |
| 979 | MODULE_DEVICE_TABLE(pci, pm8001_pci_table); |
| 980 | |