Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 1 | /* |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 2 | * Marvell 88SE64xx/88SE94xx pci init |
| 3 | * |
| 4 | * Copyright 2007 Red Hat, Inc. |
| 5 | * Copyright 2008 Marvell. <kewei@marvell.com> |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 6 | * Copyright 2009-2011 Marvell. <yuxiangl@marvell.com> |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 7 | * |
| 8 | * This file is licensed under GPLv2. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; version 2 of the |
| 13 | * License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 23 | * USA |
| 24 | */ |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 25 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 26 | |
| 27 | #include "mv_sas.h" |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 28 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 29 | static int lldd_max_execute_num = 1; |
| 30 | module_param_named(collector, lldd_max_execute_num, int, S_IRUGO); |
| 31 | MODULE_PARM_DESC(collector, "\n" |
| 32 | "\tIf greater than one, tells the SAS Layer to run in Task Collector\n" |
| 33 | "\tMode. If 1 or 0, tells the SAS Layer to run in Direct Mode.\n" |
| 34 | "\tThe mvsas SAS LLDD supports both modes.\n" |
| 35 | "\tDefault: 1 (Direct Mode).\n"); |
| 36 | |
Xiangliang Yu | 83c7b61 | 2011-05-24 22:31:47 +0800 | [diff] [blame^] | 37 | int interrupt_coalescing = 0x80; |
| 38 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 39 | static struct scsi_transport_template *mvs_stt; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 40 | struct kmem_cache *mvs_task_list_cache; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 41 | static const struct mvs_chip_info mvs_chips[] = { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 42 | [chip_6320] = { 1, 2, 0x400, 17, 16, 9, &mvs_64xx_dispatch, }, |
| 43 | [chip_6440] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, }, |
| 44 | [chip_6485] = { 1, 8, 0x800, 33, 32, 10, &mvs_64xx_dispatch, }, |
| 45 | [chip_9180] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, }, |
| 46 | [chip_9480] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, }, |
Xiangliang Yu | 8214028 | 2011-04-26 06:34:01 -0700 | [diff] [blame] | 47 | [chip_9445] = { 1, 4, 0x800, 17, 64, 11, &mvs_94xx_dispatch, }, |
| 48 | [chip_9485] = { 2, 4, 0x800, 17, 64, 11, &mvs_94xx_dispatch, }, |
Nick Cheng | f31491d | 2009-09-08 19:03:07 +0800 | [diff] [blame] | 49 | [chip_1300] = { 1, 4, 0x400, 17, 16, 9, &mvs_64xx_dispatch, }, |
| 50 | [chip_1320] = { 2, 4, 0x800, 17, 64, 9, &mvs_94xx_dispatch, }, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
Xiangliang Yu | 83c7b61 | 2011-05-24 22:31:47 +0800 | [diff] [blame^] | 53 | struct device_attribute *mvst_host_attrs[]; |
| 54 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 55 | #define SOC_SAS_NUM 2 |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 56 | #define SG_MX 64 |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 57 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 58 | static struct scsi_host_template mvs_sht = { |
| 59 | .module = THIS_MODULE, |
| 60 | .name = DRV_NAME, |
| 61 | .queuecommand = sas_queuecommand, |
| 62 | .target_alloc = sas_target_alloc, |
| 63 | .slave_configure = mvs_slave_configure, |
| 64 | .slave_destroy = sas_slave_destroy, |
| 65 | .scan_finished = mvs_scan_finished, |
| 66 | .scan_start = mvs_scan_start, |
| 67 | .change_queue_depth = sas_change_queue_depth, |
| 68 | .change_queue_type = sas_change_queue_type, |
| 69 | .bios_param = sas_bios_param, |
| 70 | .can_queue = 1, |
| 71 | .cmd_per_lun = 1, |
| 72 | .this_id = -1, |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 73 | .sg_tablesize = SG_MX, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 74 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, |
| 75 | .use_clustering = ENABLE_CLUSTERING, |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 76 | .eh_device_reset_handler = sas_eh_device_reset_handler, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 77 | .eh_bus_reset_handler = sas_eh_bus_reset_handler, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 78 | .slave_alloc = mvs_slave_alloc, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 79 | .target_destroy = sas_target_destroy, |
| 80 | .ioctl = sas_ioctl, |
Xiangliang Yu | 83c7b61 | 2011-05-24 22:31:47 +0800 | [diff] [blame^] | 81 | .shost_attrs = mvst_host_attrs, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static struct sas_domain_function_template mvs_transport_ops = { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 85 | .lldd_dev_found = mvs_dev_found, |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 86 | .lldd_dev_gone = mvs_dev_gone, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 87 | .lldd_execute_task = mvs_queue_command, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 88 | .lldd_control_phy = mvs_phy_control, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 89 | |
| 90 | .lldd_abort_task = mvs_abort_task, |
| 91 | .lldd_abort_task_set = mvs_abort_task_set, |
| 92 | .lldd_clear_aca = mvs_clear_aca, |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 93 | .lldd_clear_task_set = mvs_clear_task_set, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 94 | .lldd_I_T_nexus_reset = mvs_I_T_nexus_reset, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 95 | .lldd_lu_reset = mvs_lu_reset, |
| 96 | .lldd_query_task = mvs_query_task, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 97 | .lldd_port_formed = mvs_port_formed, |
| 98 | .lldd_port_deformed = mvs_port_deformed, |
| 99 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static void __devinit mvs_phy_init(struct mvs_info *mvi, int phy_id) |
| 103 | { |
| 104 | struct mvs_phy *phy = &mvi->phy[phy_id]; |
| 105 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
| 106 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 107 | phy->mvi = mvi; |
| 108 | init_timer(&phy->timer); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 109 | sas_phy->enabled = (phy_id < mvi->chip->n_phy) ? 1 : 0; |
| 110 | sas_phy->class = SAS; |
| 111 | sas_phy->iproto = SAS_PROTOCOL_ALL; |
| 112 | sas_phy->tproto = 0; |
| 113 | sas_phy->type = PHY_TYPE_PHYSICAL; |
| 114 | sas_phy->role = PHY_ROLE_INITIATOR; |
| 115 | sas_phy->oob_mode = OOB_NOT_CONNECTED; |
| 116 | sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
| 117 | |
| 118 | sas_phy->id = phy_id; |
| 119 | sas_phy->sas_addr = &mvi->sas_addr[0]; |
| 120 | sas_phy->frame_rcvd = &phy->frame_rcvd[0]; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 121 | sas_phy->ha = (struct sas_ha_struct *)mvi->shost->hostdata; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 122 | sas_phy->lldd_phy = phy; |
| 123 | } |
| 124 | |
| 125 | static void mvs_free(struct mvs_info *mvi) |
| 126 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 127 | struct mvs_wq *mwq; |
| 128 | int slot_nr; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 129 | |
| 130 | if (!mvi) |
| 131 | return; |
| 132 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 133 | if (mvi->flags & MVF_FLAG_SOC) |
| 134 | slot_nr = MVS_SOC_SLOTS; |
| 135 | else |
| 136 | slot_nr = MVS_SLOTS; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 137 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 138 | if (mvi->dma_pool) |
| 139 | pci_pool_destroy(mvi->dma_pool); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 140 | |
| 141 | if (mvi->tx) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 142 | dma_free_coherent(mvi->dev, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 143 | sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ, |
| 144 | mvi->tx, mvi->tx_dma); |
| 145 | if (mvi->rx_fis) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 146 | dma_free_coherent(mvi->dev, MVS_RX_FISL_SZ, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 147 | mvi->rx_fis, mvi->rx_fis_dma); |
| 148 | if (mvi->rx) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 149 | dma_free_coherent(mvi->dev, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 150 | sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1), |
| 151 | mvi->rx, mvi->rx_dma); |
| 152 | if (mvi->slot) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 153 | dma_free_coherent(mvi->dev, |
| 154 | sizeof(*mvi->slot) * slot_nr, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 155 | mvi->slot, mvi->slot_dma); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 156 | #ifndef DISABLE_HOTPLUG_DMA_FIX |
| 157 | if (mvi->bulk_buffer) |
| 158 | dma_free_coherent(mvi->dev, TRASH_BUCKET_SIZE, |
| 159 | mvi->bulk_buffer, mvi->bulk_buffer_dma); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 160 | #endif |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 161 | |
| 162 | MVS_CHIP_DISP->chip_iounmap(mvi); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 163 | if (mvi->shost) |
| 164 | scsi_host_put(mvi->shost); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 165 | list_for_each_entry(mwq, &mvi->wq_list, entry) |
| 166 | cancel_delayed_work(&mwq->work_q); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 167 | kfree(mvi); |
| 168 | } |
| 169 | |
| 170 | #ifdef MVS_USE_TASKLET |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 171 | struct tasklet_struct mv_tasklet; |
| 172 | static void mvs_tasklet(unsigned long opaque) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 173 | { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 174 | unsigned long flags; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 175 | u32 stat; |
| 176 | u16 core_nr, i = 0; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 177 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 178 | struct mvs_info *mvi; |
| 179 | struct sas_ha_struct *sha = (struct sas_ha_struct *)opaque; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 180 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 181 | core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 182 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0]; |
| 183 | |
| 184 | if (unlikely(!mvi)) |
| 185 | BUG_ON(1); |
| 186 | |
| 187 | for (i = 0; i < core_nr; i++) { |
| 188 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i]; |
| 189 | stat = MVS_CHIP_DISP->isr_status(mvi, mvi->irq); |
| 190 | if (stat) |
| 191 | MVS_CHIP_DISP->isr(mvi, mvi->irq, stat); |
| 192 | } |
| 193 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 194 | } |
| 195 | #endif |
| 196 | |
| 197 | static irqreturn_t mvs_interrupt(int irq, void *opaque) |
| 198 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 199 | u32 core_nr, i = 0; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 200 | u32 stat; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 201 | struct mvs_info *mvi; |
| 202 | struct sas_ha_struct *sha = opaque; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 203 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 204 | core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 205 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0]; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 206 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 207 | if (unlikely(!mvi)) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 208 | return IRQ_NONE; |
| 209 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 210 | stat = MVS_CHIP_DISP->isr_status(mvi, irq); |
| 211 | if (!stat) |
| 212 | return IRQ_NONE; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 213 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 214 | #ifdef MVS_USE_TASKLET |
| 215 | tasklet_schedule(&mv_tasklet); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 216 | #else |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 217 | for (i = 0; i < core_nr; i++) { |
| 218 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i]; |
| 219 | MVS_CHIP_DISP->isr(mvi, irq, stat); |
| 220 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 221 | #endif |
| 222 | return IRQ_HANDLED; |
| 223 | } |
| 224 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 225 | static int __devinit mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 226 | { |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 227 | int i = 0, slot_nr; |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 228 | char pool_name[32]; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 229 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 230 | if (mvi->flags & MVF_FLAG_SOC) |
| 231 | slot_nr = MVS_SOC_SLOTS; |
| 232 | else |
| 233 | slot_nr = MVS_SLOTS; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 234 | |
| 235 | spin_lock_init(&mvi->lock); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 236 | for (i = 0; i < mvi->chip->n_phy; i++) { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 237 | mvs_phy_init(mvi, i); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 238 | mvi->port[i].wide_port_phymap = 0; |
| 239 | mvi->port[i].port_attached = 0; |
| 240 | INIT_LIST_HEAD(&mvi->port[i].list); |
| 241 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 242 | for (i = 0; i < MVS_MAX_DEVICES; i++) { |
| 243 | mvi->devices[i].taskfileset = MVS_ID_NOT_MAPPED; |
| 244 | mvi->devices[i].dev_type = NO_DEVICE; |
| 245 | mvi->devices[i].device_id = i; |
| 246 | mvi->devices[i].dev_status = MVS_DEV_NORMAL; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 247 | init_timer(&mvi->devices[i].timer); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 248 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * alloc and init our DMA areas |
| 252 | */ |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 253 | mvi->tx = dma_alloc_coherent(mvi->dev, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 254 | sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ, |
| 255 | &mvi->tx_dma, GFP_KERNEL); |
| 256 | if (!mvi->tx) |
| 257 | goto err_out; |
| 258 | memset(mvi->tx, 0, sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 259 | mvi->rx_fis = dma_alloc_coherent(mvi->dev, MVS_RX_FISL_SZ, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 260 | &mvi->rx_fis_dma, GFP_KERNEL); |
| 261 | if (!mvi->rx_fis) |
| 262 | goto err_out; |
| 263 | memset(mvi->rx_fis, 0, MVS_RX_FISL_SZ); |
| 264 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 265 | mvi->rx = dma_alloc_coherent(mvi->dev, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 266 | sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1), |
| 267 | &mvi->rx_dma, GFP_KERNEL); |
| 268 | if (!mvi->rx) |
| 269 | goto err_out; |
| 270 | memset(mvi->rx, 0, sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 271 | mvi->rx[0] = cpu_to_le32(0xfff); |
| 272 | mvi->rx_cons = 0xfff; |
| 273 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 274 | mvi->slot = dma_alloc_coherent(mvi->dev, |
| 275 | sizeof(*mvi->slot) * slot_nr, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 276 | &mvi->slot_dma, GFP_KERNEL); |
| 277 | if (!mvi->slot) |
| 278 | goto err_out; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 279 | memset(mvi->slot, 0, sizeof(*mvi->slot) * slot_nr); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 280 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 281 | #ifndef DISABLE_HOTPLUG_DMA_FIX |
| 282 | mvi->bulk_buffer = dma_alloc_coherent(mvi->dev, |
| 283 | TRASH_BUCKET_SIZE, |
| 284 | &mvi->bulk_buffer_dma, GFP_KERNEL); |
| 285 | if (!mvi->bulk_buffer) |
| 286 | goto err_out; |
| 287 | #endif |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 288 | sprintf(pool_name, "%s%d", "mvs_dma_pool", mvi->id); |
| 289 | mvi->dma_pool = pci_pool_create(pool_name, mvi->pdev, MVS_SLOT_BUF_SZ, 16, 0); |
| 290 | if (!mvi->dma_pool) { |
| 291 | printk(KERN_DEBUG "failed to create dma pool %s.\n", pool_name); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 292 | goto err_out; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 293 | } |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 294 | mvi->tags_num = slot_nr; |
| 295 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 296 | /* Initialize tags */ |
| 297 | mvs_tag_init(mvi); |
| 298 | return 0; |
| 299 | err_out: |
| 300 | return 1; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex) |
| 305 | { |
| 306 | unsigned long res_start, res_len, res_flag, res_flag_ex = 0; |
| 307 | struct pci_dev *pdev = mvi->pdev; |
| 308 | if (bar_ex != -1) { |
| 309 | /* |
| 310 | * ioremap main and peripheral registers |
| 311 | */ |
| 312 | res_start = pci_resource_start(pdev, bar_ex); |
| 313 | res_len = pci_resource_len(pdev, bar_ex); |
| 314 | if (!res_start || !res_len) |
| 315 | goto err_out; |
| 316 | |
| 317 | res_flag_ex = pci_resource_flags(pdev, bar_ex); |
| 318 | if (res_flag_ex & IORESOURCE_MEM) { |
| 319 | if (res_flag_ex & IORESOURCE_CACHEABLE) |
| 320 | mvi->regs_ex = ioremap(res_start, res_len); |
| 321 | else |
| 322 | mvi->regs_ex = ioremap_nocache(res_start, |
| 323 | res_len); |
| 324 | } else |
| 325 | mvi->regs_ex = (void *)res_start; |
| 326 | if (!mvi->regs_ex) |
| 327 | goto err_out; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 330 | res_start = pci_resource_start(pdev, bar); |
| 331 | res_len = pci_resource_len(pdev, bar); |
| 332 | if (!res_start || !res_len) |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 333 | goto err_out; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 334 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 335 | res_flag = pci_resource_flags(pdev, bar); |
| 336 | if (res_flag & IORESOURCE_CACHEABLE) |
| 337 | mvi->regs = ioremap(res_start, res_len); |
| 338 | else |
| 339 | mvi->regs = ioremap_nocache(res_start, res_len); |
| 340 | |
| 341 | if (!mvi->regs) { |
| 342 | if (mvi->regs_ex && (res_flag_ex & IORESOURCE_MEM)) |
| 343 | iounmap(mvi->regs_ex); |
| 344 | mvi->regs_ex = NULL; |
| 345 | goto err_out; |
| 346 | } |
| 347 | |
| 348 | return 0; |
| 349 | err_out: |
| 350 | return -1; |
| 351 | } |
| 352 | |
| 353 | void mvs_iounmap(void __iomem *regs) |
| 354 | { |
| 355 | iounmap(regs); |
| 356 | } |
| 357 | |
| 358 | static struct mvs_info *__devinit mvs_pci_alloc(struct pci_dev *pdev, |
| 359 | const struct pci_device_id *ent, |
| 360 | struct Scsi_Host *shost, unsigned int id) |
| 361 | { |
| 362 | struct mvs_info *mvi; |
| 363 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 364 | |
| 365 | mvi = kzalloc(sizeof(*mvi) + MVS_SLOTS * sizeof(struct mvs_slot_info), |
| 366 | GFP_KERNEL); |
| 367 | if (!mvi) |
| 368 | return NULL; |
| 369 | |
| 370 | mvi->pdev = pdev; |
| 371 | mvi->dev = &pdev->dev; |
| 372 | mvi->chip_id = ent->driver_data; |
| 373 | mvi->chip = &mvs_chips[mvi->chip_id]; |
| 374 | INIT_LIST_HEAD(&mvi->wq_list); |
| 375 | mvi->irq = pdev->irq; |
| 376 | |
| 377 | ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi; |
| 378 | ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy; |
| 379 | |
| 380 | mvi->id = id; |
| 381 | mvi->sas = sha; |
| 382 | mvi->shost = shost; |
| 383 | #ifdef MVS_USE_TASKLET |
| 384 | tasklet_init(&mv_tasklet, mvs_tasklet, (unsigned long)sha); |
| 385 | #endif |
| 386 | |
| 387 | if (MVS_CHIP_DISP->chip_ioremap(mvi)) |
| 388 | goto err_out; |
| 389 | if (!mvs_alloc(mvi, shost)) |
| 390 | return mvi; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 391 | err_out: |
| 392 | mvs_free(mvi); |
| 393 | return NULL; |
| 394 | } |
| 395 | |
| 396 | /* move to PCI layer or libata core? */ |
| 397 | static int pci_go_64(struct pci_dev *pdev) |
| 398 | { |
| 399 | int rc; |
| 400 | |
| 401 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { |
| 402 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
| 403 | if (rc) { |
| 404 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 405 | if (rc) { |
| 406 | dev_printk(KERN_ERR, &pdev->dev, |
| 407 | "64-bit DMA enable failed\n"); |
| 408 | return rc; |
| 409 | } |
| 410 | } |
| 411 | } else { |
| 412 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 413 | if (rc) { |
| 414 | dev_printk(KERN_ERR, &pdev->dev, |
| 415 | "32-bit DMA enable failed\n"); |
| 416 | return rc; |
| 417 | } |
| 418 | rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 419 | if (rc) { |
| 420 | dev_printk(KERN_ERR, &pdev->dev, |
| 421 | "32-bit consistent DMA enable failed\n"); |
| 422 | return rc; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | return rc; |
| 427 | } |
| 428 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 429 | static int __devinit mvs_prep_sas_ha_init(struct Scsi_Host *shost, |
| 430 | const struct mvs_chip_info *chip_info) |
| 431 | { |
| 432 | int phy_nr, port_nr; unsigned short core_nr; |
| 433 | struct asd_sas_phy **arr_phy; |
| 434 | struct asd_sas_port **arr_port; |
| 435 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 436 | |
| 437 | core_nr = chip_info->n_host; |
| 438 | phy_nr = core_nr * chip_info->n_phy; |
| 439 | port_nr = phy_nr; |
| 440 | |
| 441 | memset(sha, 0x00, sizeof(struct sas_ha_struct)); |
| 442 | arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL); |
| 443 | arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL); |
| 444 | if (!arr_phy || !arr_port) |
| 445 | goto exit_free; |
| 446 | |
| 447 | sha->sas_phy = arr_phy; |
| 448 | sha->sas_port = arr_port; |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 449 | sha->core.shost = shost; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 450 | |
| 451 | sha->lldd_ha = kzalloc(sizeof(struct mvs_prv_info), GFP_KERNEL); |
| 452 | if (!sha->lldd_ha) |
| 453 | goto exit_free; |
| 454 | |
| 455 | ((struct mvs_prv_info *)sha->lldd_ha)->n_host = core_nr; |
| 456 | |
| 457 | shost->transportt = mvs_stt; |
| 458 | shost->max_id = 128; |
| 459 | shost->max_lun = ~0; |
| 460 | shost->max_channel = 1; |
| 461 | shost->max_cmd_len = 16; |
| 462 | |
| 463 | return 0; |
| 464 | exit_free: |
| 465 | kfree(arr_phy); |
| 466 | kfree(arr_port); |
| 467 | return -1; |
| 468 | |
| 469 | } |
| 470 | |
| 471 | static void __devinit mvs_post_sas_ha_init(struct Scsi_Host *shost, |
| 472 | const struct mvs_chip_info *chip_info) |
| 473 | { |
| 474 | int can_queue, i = 0, j = 0; |
| 475 | struct mvs_info *mvi = NULL; |
| 476 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 477 | unsigned short nr_core = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 478 | |
| 479 | for (j = 0; j < nr_core; j++) { |
| 480 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[j]; |
| 481 | for (i = 0; i < chip_info->n_phy; i++) { |
| 482 | sha->sas_phy[j * chip_info->n_phy + i] = |
| 483 | &mvi->phy[i].sas_phy; |
| 484 | sha->sas_port[j * chip_info->n_phy + i] = |
| 485 | &mvi->port[i].sas_port; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | sha->sas_ha_name = DRV_NAME; |
| 490 | sha->dev = mvi->dev; |
| 491 | sha->lldd_module = THIS_MODULE; |
| 492 | sha->sas_addr = &mvi->sas_addr[0]; |
| 493 | |
| 494 | sha->num_phys = nr_core * chip_info->n_phy; |
| 495 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 496 | sha->lldd_max_execute_num = lldd_max_execute_num; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 497 | |
| 498 | if (mvi->flags & MVF_FLAG_SOC) |
| 499 | can_queue = MVS_SOC_CAN_QUEUE; |
| 500 | else |
| 501 | can_queue = MVS_CAN_QUEUE; |
| 502 | |
| 503 | sha->lldd_queue_size = can_queue; |
| 504 | shost->can_queue = can_queue; |
| 505 | mvi->shost->cmd_per_lun = MVS_SLOTS/sha->num_phys; |
| 506 | sha->core.shost = mvi->shost; |
| 507 | } |
| 508 | |
| 509 | static void mvs_init_sas_add(struct mvs_info *mvi) |
| 510 | { |
| 511 | u8 i; |
| 512 | for (i = 0; i < mvi->chip->n_phy; i++) { |
| 513 | mvi->phy[i].dev_sas_addr = 0x5005043011ab0000ULL; |
| 514 | mvi->phy[i].dev_sas_addr = |
| 515 | cpu_to_be64((u64)(*(u64 *)&mvi->phy[i].dev_sas_addr)); |
| 516 | } |
| 517 | |
| 518 | memcpy(mvi->sas_addr, &mvi->phy[0].dev_sas_addr, SAS_ADDR_SIZE); |
| 519 | } |
| 520 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 521 | static int __devinit mvs_pci_init(struct pci_dev *pdev, |
| 522 | const struct pci_device_id *ent) |
| 523 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 524 | unsigned int rc, nhost = 0; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 525 | struct mvs_info *mvi; |
| 526 | irq_handler_t irq_handler = mvs_interrupt; |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 527 | struct Scsi_Host *shost = NULL; |
| 528 | const struct mvs_chip_info *chip; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 529 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 530 | dev_printk(KERN_INFO, &pdev->dev, |
| 531 | "mvsas: driver version %s\n", DRV_VERSION); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 532 | rc = pci_enable_device(pdev); |
| 533 | if (rc) |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 534 | goto err_out_enable; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 535 | |
| 536 | pci_set_master(pdev); |
| 537 | |
| 538 | rc = pci_request_regions(pdev, DRV_NAME); |
| 539 | if (rc) |
| 540 | goto err_out_disable; |
| 541 | |
| 542 | rc = pci_go_64(pdev); |
| 543 | if (rc) |
| 544 | goto err_out_regions; |
| 545 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 546 | shost = scsi_host_alloc(&mvs_sht, sizeof(void *)); |
| 547 | if (!shost) { |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 548 | rc = -ENOMEM; |
| 549 | goto err_out_regions; |
| 550 | } |
| 551 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 552 | chip = &mvs_chips[ent->driver_data]; |
| 553 | SHOST_TO_SAS_HA(shost) = |
| 554 | kcalloc(1, sizeof(struct sas_ha_struct), GFP_KERNEL); |
| 555 | if (!SHOST_TO_SAS_HA(shost)) { |
| 556 | kfree(shost); |
| 557 | rc = -ENOMEM; |
| 558 | goto err_out_regions; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 559 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 560 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 561 | rc = mvs_prep_sas_ha_init(shost, chip); |
| 562 | if (rc) { |
| 563 | kfree(shost); |
| 564 | rc = -ENOMEM; |
| 565 | goto err_out_regions; |
| 566 | } |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 567 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 568 | pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 569 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 570 | do { |
| 571 | mvi = mvs_pci_alloc(pdev, ent, shost, nhost); |
| 572 | if (!mvi) { |
| 573 | rc = -ENOMEM; |
| 574 | goto err_out_regions; |
| 575 | } |
| 576 | |
Xiangliang Yu | f1f82a9 | 2011-05-24 22:28:31 +0800 | [diff] [blame] | 577 | memset(&mvi->hba_info_param, 0xFF, |
| 578 | sizeof(struct hba_info_page)); |
| 579 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 580 | mvs_init_sas_add(mvi); |
| 581 | |
| 582 | mvi->instance = nhost; |
| 583 | rc = MVS_CHIP_DISP->chip_init(mvi); |
| 584 | if (rc) { |
| 585 | mvs_free(mvi); |
| 586 | goto err_out_regions; |
| 587 | } |
| 588 | nhost++; |
| 589 | } while (nhost < chip->n_host); |
Srinivas | 9dc9fd9 | 2010-02-15 00:00:00 -0600 | [diff] [blame] | 590 | #ifdef MVS_USE_TASKLET |
| 591 | tasklet_init(&mv_tasklet, mvs_tasklet, |
| 592 | (unsigned long)SHOST_TO_SAS_HA(shost)); |
| 593 | #endif |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 594 | |
| 595 | mvs_post_sas_ha_init(shost, chip); |
| 596 | |
| 597 | rc = scsi_add_host(shost, &pdev->dev); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 598 | if (rc) |
| 599 | goto err_out_shost; |
| 600 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 601 | rc = sas_register_ha(SHOST_TO_SAS_HA(shost)); |
| 602 | if (rc) |
| 603 | goto err_out_shost; |
| 604 | rc = request_irq(pdev->irq, irq_handler, IRQF_SHARED, |
| 605 | DRV_NAME, SHOST_TO_SAS_HA(shost)); |
| 606 | if (rc) |
| 607 | goto err_not_sas; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 608 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 609 | MVS_CHIP_DISP->interrupt_enable(mvi); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 610 | |
| 611 | scsi_scan_host(mvi->shost); |
| 612 | |
| 613 | return 0; |
| 614 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 615 | err_not_sas: |
| 616 | sas_unregister_ha(SHOST_TO_SAS_HA(shost)); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 617 | err_out_shost: |
| 618 | scsi_remove_host(mvi->shost); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 619 | err_out_regions: |
| 620 | pci_release_regions(pdev); |
| 621 | err_out_disable: |
| 622 | pci_disable_device(pdev); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 623 | err_out_enable: |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 624 | return rc; |
| 625 | } |
| 626 | |
| 627 | static void __devexit mvs_pci_remove(struct pci_dev *pdev) |
| 628 | { |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 629 | unsigned short core_nr, i = 0; |
| 630 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 631 | struct mvs_info *mvi = NULL; |
| 632 | |
| 633 | core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 634 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0]; |
| 635 | |
| 636 | #ifdef MVS_USE_TASKLET |
| 637 | tasklet_kill(&mv_tasklet); |
| 638 | #endif |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 639 | |
| 640 | pci_set_drvdata(pdev, NULL); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 641 | sas_unregister_ha(sha); |
| 642 | sas_remove_host(mvi->shost); |
| 643 | scsi_remove_host(mvi->shost); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 644 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 645 | MVS_CHIP_DISP->interrupt_disable(mvi); |
| 646 | free_irq(mvi->irq, sha); |
| 647 | for (i = 0; i < core_nr; i++) { |
| 648 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i]; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 649 | mvs_free(mvi); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 650 | } |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 651 | kfree(sha->sas_phy); |
| 652 | kfree(sha->sas_port); |
| 653 | kfree(sha); |
| 654 | pci_release_regions(pdev); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 655 | pci_disable_device(pdev); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 656 | return; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static struct pci_device_id __devinitdata mvs_pci_table[] = { |
| 660 | { PCI_VDEVICE(MARVELL, 0x6320), chip_6320 }, |
| 661 | { PCI_VDEVICE(MARVELL, 0x6340), chip_6440 }, |
| 662 | { |
| 663 | .vendor = PCI_VENDOR_ID_MARVELL, |
| 664 | .device = 0x6440, |
| 665 | .subvendor = PCI_ANY_ID, |
| 666 | .subdevice = 0x6480, |
| 667 | .class = 0, |
| 668 | .class_mask = 0, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 669 | .driver_data = chip_6485, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 670 | }, |
| 671 | { PCI_VDEVICE(MARVELL, 0x6440), chip_6440 }, |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 672 | { PCI_VDEVICE(MARVELL, 0x6485), chip_6485 }, |
| 673 | { PCI_VDEVICE(MARVELL, 0x9480), chip_9480 }, |
| 674 | { PCI_VDEVICE(MARVELL, 0x9180), chip_9180 }, |
Nick Cheng | f31491d | 2009-09-08 19:03:07 +0800 | [diff] [blame] | 675 | { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1300), chip_1300 }, |
| 676 | { PCI_VDEVICE(ARECA, PCI_DEVICE_ID_ARECA_1320), chip_1320 }, |
Srinivas | 7ec4ad0 | 2009-11-24 20:07:39 +0530 | [diff] [blame] | 677 | { PCI_VDEVICE(ADAPTEC2, 0x0450), chip_6440 }, |
HighPoint Linux Team | 463b897 | 2011-02-23 16:28:44 +0800 | [diff] [blame] | 678 | { PCI_VDEVICE(TTI, 0x2710), chip_9480 }, |
| 679 | { PCI_VDEVICE(TTI, 0x2720), chip_9480 }, |
| 680 | { PCI_VDEVICE(TTI, 0x2721), chip_9480 }, |
| 681 | { PCI_VDEVICE(TTI, 0x2722), chip_9480 }, |
| 682 | { PCI_VDEVICE(TTI, 0x2740), chip_9480 }, |
| 683 | { PCI_VDEVICE(TTI, 0x2744), chip_9480 }, |
| 684 | { PCI_VDEVICE(TTI, 0x2760), chip_9480 }, |
Xiangliang Yu | 8214028 | 2011-04-26 06:34:01 -0700 | [diff] [blame] | 685 | { |
| 686 | .vendor = 0x1b4b, |
| 687 | .device = 0x9445, |
| 688 | .subvendor = PCI_ANY_ID, |
| 689 | .subdevice = 0x9480, |
| 690 | .class = 0, |
| 691 | .class_mask = 0, |
| 692 | .driver_data = chip_9445, |
| 693 | }, |
| 694 | { |
| 695 | .vendor = 0x1b4b, |
| 696 | .device = 0x9485, |
| 697 | .subvendor = PCI_ANY_ID, |
| 698 | .subdevice = 0x9480, |
| 699 | .class = 0, |
| 700 | .class_mask = 0, |
| 701 | .driver_data = chip_9485, |
| 702 | }, |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 703 | |
| 704 | { } /* terminate list */ |
| 705 | }; |
| 706 | |
| 707 | static struct pci_driver mvs_pci_driver = { |
| 708 | .name = DRV_NAME, |
| 709 | .id_table = mvs_pci_table, |
| 710 | .probe = mvs_pci_init, |
| 711 | .remove = __devexit_p(mvs_pci_remove), |
| 712 | }; |
| 713 | |
Xiangliang Yu | 83c7b61 | 2011-05-24 22:31:47 +0800 | [diff] [blame^] | 714 | static ssize_t |
| 715 | mvs_show_driver_version(struct device *cdev, |
| 716 | struct device_attribute *attr, char *buffer) |
| 717 | { |
| 718 | return snprintf(buffer, PAGE_SIZE, "%s\n", DRV_VERSION); |
| 719 | } |
| 720 | |
| 721 | static DEVICE_ATTR(driver_version, |
| 722 | S_IRUGO, |
| 723 | mvs_show_driver_version, |
| 724 | NULL); |
| 725 | |
| 726 | static ssize_t |
| 727 | mvs_store_interrupt_coalescing(struct device *cdev, |
| 728 | struct device_attribute *attr, |
| 729 | const char *buffer, size_t size) |
| 730 | { |
| 731 | int val = 0; |
| 732 | struct mvs_info *mvi = NULL; |
| 733 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 734 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 735 | u8 i, core_nr; |
| 736 | if (buffer == NULL) |
| 737 | return size; |
| 738 | |
| 739 | if (sscanf(buffer, "%d", &val) != 1) |
| 740 | return -EINVAL; |
| 741 | |
| 742 | if (val >= 0x10000) { |
| 743 | mv_dprintk("interrupt coalescing timer %d us is" |
| 744 | "too long\n", val); |
| 745 | return strlen(buffer); |
| 746 | } |
| 747 | |
| 748 | interrupt_coalescing = val; |
| 749 | |
| 750 | core_nr = ((struct mvs_prv_info *)sha->lldd_ha)->n_host; |
| 751 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[0]; |
| 752 | |
| 753 | if (unlikely(!mvi)) |
| 754 | return -EINVAL; |
| 755 | |
| 756 | for (i = 0; i < core_nr; i++) { |
| 757 | mvi = ((struct mvs_prv_info *)sha->lldd_ha)->mvi[i]; |
| 758 | if (MVS_CHIP_DISP->tune_interrupt) |
| 759 | MVS_CHIP_DISP->tune_interrupt(mvi, |
| 760 | interrupt_coalescing); |
| 761 | } |
| 762 | mv_dprintk("set interrupt coalescing time to %d us\n", |
| 763 | interrupt_coalescing); |
| 764 | return strlen(buffer); |
| 765 | } |
| 766 | |
| 767 | static ssize_t mvs_show_interrupt_coalescing(struct device *cdev, |
| 768 | struct device_attribute *attr, char *buffer) |
| 769 | { |
| 770 | return snprintf(buffer, PAGE_SIZE, "%d\n", interrupt_coalescing); |
| 771 | } |
| 772 | |
| 773 | static DEVICE_ATTR(interrupt_coalescing, |
| 774 | S_IRUGO|S_IWUSR, |
| 775 | mvs_show_interrupt_coalescing, |
| 776 | mvs_store_interrupt_coalescing); |
| 777 | |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 778 | /* task handler */ |
| 779 | struct task_struct *mvs_th; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 780 | static int __init mvs_init(void) |
| 781 | { |
| 782 | int rc; |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 783 | mvs_stt = sas_domain_attach_transport(&mvs_transport_ops); |
| 784 | if (!mvs_stt) |
| 785 | return -ENOMEM; |
| 786 | |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 787 | mvs_task_list_cache = kmem_cache_create("mvs_task_list", sizeof(struct mvs_task_list), |
| 788 | 0, SLAB_HWCACHE_ALIGN, NULL); |
| 789 | if (!mvs_task_list_cache) { |
| 790 | rc = -ENOMEM; |
| 791 | mv_printk("%s: mvs_task_list_cache alloc failed! \n", __func__); |
| 792 | goto err_out; |
| 793 | } |
| 794 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 795 | rc = pci_register_driver(&mvs_pci_driver); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 796 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 797 | if (rc) |
| 798 | goto err_out; |
| 799 | |
| 800 | return 0; |
| 801 | |
| 802 | err_out: |
| 803 | sas_release_transport(mvs_stt); |
| 804 | return rc; |
| 805 | } |
| 806 | |
| 807 | static void __exit mvs_exit(void) |
| 808 | { |
| 809 | pci_unregister_driver(&mvs_pci_driver); |
| 810 | sas_release_transport(mvs_stt); |
Xiangliang Yu | 0b15fb1 | 2011-04-26 06:36:51 -0700 | [diff] [blame] | 811 | kmem_cache_destroy(mvs_task_list_cache); |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 812 | } |
| 813 | |
Xiangliang Yu | 83c7b61 | 2011-05-24 22:31:47 +0800 | [diff] [blame^] | 814 | struct device_attribute *mvst_host_attrs[] = { |
| 815 | &dev_attr_driver_version, |
| 816 | &dev_attr_interrupt_coalescing, |
| 817 | NULL, |
| 818 | }; |
| 819 | |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 820 | module_init(mvs_init); |
| 821 | module_exit(mvs_exit); |
| 822 | |
| 823 | MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>"); |
| 824 | MODULE_DESCRIPTION("Marvell 88SE6440 SAS/SATA controller driver"); |
| 825 | MODULE_VERSION(DRV_VERSION); |
| 826 | MODULE_LICENSE("GPL"); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 827 | #ifdef CONFIG_PCI |
Jeff Garzik | dd4969a | 2009-05-08 17:44:01 -0400 | [diff] [blame] | 828 | MODULE_DEVICE_TABLE(pci, mvs_pci_table); |
Andy Yan | 20b09c2 | 2009-05-08 17:46:40 -0400 | [diff] [blame] | 829 | #endif |