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" |
peter chang | 3e253d9 | 2019-11-14 15:39:07 +0530 | [diff] [blame] | 44 | #include "pm80xx_hwi.h" |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 45 | |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 46 | static ulong logging_level = PM8001_FAIL_LOGGING | PM8001_IOERR_LOGGING; |
| 47 | module_param(logging_level, ulong, 0644); |
| 48 | MODULE_PARM_DESC(logging_level, " bits for enabling logging info."); |
| 49 | |
peter chang | 3e253d9 | 2019-11-14 15:39:07 +0530 | [diff] [blame] | 50 | static ulong link_rate = LINKRATE_15 | LINKRATE_30 | LINKRATE_60 | LINKRATE_120; |
| 51 | module_param(link_rate, ulong, 0644); |
| 52 | MODULE_PARM_DESC(link_rate, "Enable link rate.\n" |
| 53 | " 1: Link rate 1.5G\n" |
| 54 | " 2: Link rate 3.0G\n" |
| 55 | " 4: Link rate 6.0G\n" |
| 56 | " 8: Link rate 12.0G\n"); |
| 57 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 58 | static struct scsi_transport_template *pm8001_stt; |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 59 | static int pm8001_init_ccb_tag(struct pm8001_hba_info *, struct Scsi_Host *, struct pci_dev *); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 60 | |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 61 | /* |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 62 | * chip info structure to identify chip key functionality as |
| 63 | * encryption available/not, no of ports, hw specific function ref |
| 64 | */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 65 | static const struct pm8001_chip_info pm8001_chips[] = { |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 66 | [chip_8001] = {0, 8, &pm8001_8001_dispatch,}, |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 67 | [chip_8008] = {0, 8, &pm8001_80xx_dispatch,}, |
| 68 | [chip_8009] = {1, 8, &pm8001_80xx_dispatch,}, |
| 69 | [chip_8018] = {0, 16, &pm8001_80xx_dispatch,}, |
| 70 | [chip_8019] = {1, 16, &pm8001_80xx_dispatch,}, |
Anand Kumar Santhanam | a9a923e | 2013-09-03 15:09:42 +0530 | [diff] [blame] | 71 | [chip_8074] = {0, 8, &pm8001_80xx_dispatch,}, |
| 72 | [chip_8076] = {0, 16, &pm8001_80xx_dispatch,}, |
| 73 | [chip_8077] = {0, 16, &pm8001_80xx_dispatch,}, |
Suresh Thiagarajan | d8571b1 | 2015-02-12 12:04:37 +0530 | [diff] [blame] | 74 | [chip_8006] = {0, 16, &pm8001_80xx_dispatch,}, |
Benjamin Rood | db9d403 | 2015-10-30 10:53:25 -0400 | [diff] [blame] | 75 | [chip_8070] = {0, 8, &pm8001_80xx_dispatch,}, |
| 76 | [chip_8072] = {0, 16, &pm8001_80xx_dispatch,}, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 77 | }; |
| 78 | static int pm8001_id; |
| 79 | |
| 80 | LIST_HEAD(hba_list); |
| 81 | |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 82 | struct workqueue_struct *pm8001_wq; |
| 83 | |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 84 | /* |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 85 | * The main structure which LLDD must register for scsi core. |
| 86 | */ |
| 87 | static struct scsi_host_template pm8001_sht = { |
| 88 | .module = THIS_MODULE, |
| 89 | .name = DRV_NAME, |
| 90 | .queuecommand = sas_queuecommand, |
Christoph Hellwig | b8f1d1e | 2020-06-15 08:46:24 +0200 | [diff] [blame] | 91 | .dma_need_drain = ata_scsi_dma_need_drain, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 92 | .target_alloc = sas_target_alloc, |
Dan Williams | 11e1636 | 2011-09-20 15:11:03 -0700 | [diff] [blame] | 93 | .slave_configure = sas_slave_configure, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 94 | .scan_finished = pm8001_scan_finished, |
| 95 | .scan_start = pm8001_scan_start, |
| 96 | .change_queue_depth = sas_change_queue_depth, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 97 | .bios_param = sas_bios_param, |
| 98 | .can_queue = 1, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 99 | .this_id = -1, |
Peter Chang | 58bf14c | 2020-03-16 13:19:01 +0530 | [diff] [blame] | 100 | .sg_tablesize = PM8001_MAX_DMA_SG, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 101 | .max_sectors = SCSI_DEFAULT_MAX_SECTORS, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 102 | .eh_device_reset_handler = sas_eh_device_reset_handler, |
Hannes Reinecke | cc199e7 | 2017-08-25 13:57:02 +0200 | [diff] [blame] | 103 | .eh_target_reset_handler = sas_eh_target_reset_handler, |
Yufen Yu | 49da96d | 2021-06-22 11:40:37 +0800 | [diff] [blame] | 104 | .slave_alloc = sas_slave_alloc, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 105 | .target_destroy = sas_target_destroy, |
| 106 | .ioctl = sas_ioctl, |
Arnd Bergmann | 75c0b0e | 2019-11-30 20:28:12 +0100 | [diff] [blame] | 107 | #ifdef CONFIG_COMPAT |
| 108 | .compat_ioctl = sas_ioctl, |
| 109 | #endif |
Bart Van Assche | c03b72b | 2021-10-12 16:35:47 -0700 | [diff] [blame] | 110 | .shost_groups = pm8001_host_groups, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 111 | .track_queue_depth = 1, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 112 | }; |
| 113 | |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 114 | /* |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 115 | * Sas layer call this function to execute specific task. |
| 116 | */ |
| 117 | static struct sas_domain_function_template pm8001_transport_ops = { |
| 118 | .lldd_dev_found = pm8001_dev_found, |
| 119 | .lldd_dev_gone = pm8001_dev_gone, |
| 120 | |
| 121 | .lldd_execute_task = pm8001_queue_command, |
| 122 | .lldd_control_phy = pm8001_phy_control, |
| 123 | |
| 124 | .lldd_abort_task = pm8001_abort_task, |
| 125 | .lldd_abort_task_set = pm8001_abort_task_set, |
| 126 | .lldd_clear_aca = pm8001_clear_aca, |
| 127 | .lldd_clear_task_set = pm8001_clear_task_set, |
| 128 | .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset, |
| 129 | .lldd_lu_reset = pm8001_lu_reset, |
| 130 | .lldd_query_task = pm8001_query_task, |
Ajish Koshy | 08d0a99 | 2021-09-06 22:34:01 +0530 | [diff] [blame] | 131 | .lldd_port_formed = pm8001_port_formed, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /** |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 135 | * pm8001_phy_init - initiate our adapter phys |
| 136 | * @pm8001_ha: our hba structure. |
| 137 | * @phy_id: phy id. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 138 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 139 | 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] | 140 | { |
| 141 | struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; |
| 142 | struct asd_sas_phy *sas_phy = &phy->sas_phy; |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 143 | phy->phy_state = PHY_LINK_DISABLE; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 144 | phy->pm8001_ha = pm8001_ha; |
| 145 | sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0; |
| 146 | sas_phy->class = SAS; |
| 147 | sas_phy->iproto = SAS_PROTOCOL_ALL; |
| 148 | sas_phy->tproto = 0; |
| 149 | sas_phy->type = PHY_TYPE_PHYSICAL; |
| 150 | sas_phy->role = PHY_ROLE_INITIATOR; |
| 151 | sas_phy->oob_mode = OOB_NOT_CONNECTED; |
| 152 | sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; |
| 153 | sas_phy->id = phy_id; |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 154 | sas_phy->sas_addr = (u8 *)&phy->dev_sas_addr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 155 | sas_phy->frame_rcvd = &phy->frame_rcvd[0]; |
| 156 | sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata; |
| 157 | sas_phy->lldd_phy = phy; |
| 158 | } |
| 159 | |
| 160 | /** |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 161 | * pm8001_free - free hba |
| 162 | * @pm8001_ha: our hba structure. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 163 | */ |
| 164 | static void pm8001_free(struct pm8001_hba_info *pm8001_ha) |
| 165 | { |
| 166 | int i; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 167 | |
| 168 | if (!pm8001_ha) |
| 169 | return; |
| 170 | |
| 171 | for (i = 0; i < USI_MAX_MEMCNT; i++) { |
| 172 | if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) { |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 173 | dma_free_coherent(&pm8001_ha->pdev->dev, |
Sakthivel K | bfb4809 | 2013-02-04 12:10:02 +0530 | [diff] [blame] | 174 | (pm8001_ha->memoryMap.region[i].total_len + |
| 175 | pm8001_ha->memoryMap.region[i].alignment), |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 176 | pm8001_ha->memoryMap.region[i].virt_ptr, |
| 177 | pm8001_ha->memoryMap.region[i].phys_addr); |
| 178 | } |
| 179 | } |
| 180 | PM8001_CHIP_DISP->chip_iounmap(pm8001_ha); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 181 | flush_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 182 | kfree(pm8001_ha->tags); |
| 183 | kfree(pm8001_ha); |
| 184 | } |
| 185 | |
| 186 | #ifdef PM8001_USE_TASKLET |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 187 | |
| 188 | /** |
Lee Jones | bd1050e | 2021-03-03 14:46:09 +0000 | [diff] [blame] | 189 | * pm8001_tasklet() - tasklet for 64 msi-x interrupt handler |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 190 | * @opaque: the passed general host adapter struct |
| 191 | * Note: pm8001_tasklet is common for pm8001 & pm80xx |
| 192 | */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 193 | static void pm8001_tasklet(unsigned long opaque) |
| 194 | { |
| 195 | struct pm8001_hba_info *pm8001_ha; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 196 | struct isr_param *irq_vector; |
| 197 | |
| 198 | irq_vector = (struct isr_param *)opaque; |
| 199 | pm8001_ha = irq_vector->drv_inst; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 200 | if (unlikely(!pm8001_ha)) |
| 201 | BUG_ON(1); |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 202 | PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 203 | } |
| 204 | #endif |
| 205 | |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 206 | /** |
| 207 | * pm8001_interrupt_handler_msix - main MSIX interrupt handler. |
| 208 | * It obtains the vector number and calls the equivalent bottom |
| 209 | * half or services directly. |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 210 | * @irq: interrupt number |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 211 | * @opaque: the passed outbound queue/vector. Host structure is |
| 212 | * retrieved from the same. |
| 213 | */ |
| 214 | static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque) |
| 215 | { |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 216 | struct isr_param *irq_vector; |
| 217 | struct pm8001_hba_info *pm8001_ha; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 218 | irqreturn_t ret = IRQ_HANDLED; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 219 | irq_vector = (struct isr_param *)opaque; |
| 220 | pm8001_ha = irq_vector->drv_inst; |
| 221 | |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 222 | if (unlikely(!pm8001_ha)) |
| 223 | return IRQ_NONE; |
Colin Ian King | f310a4e | 2019-03-29 23:44:23 +0000 | [diff] [blame] | 224 | if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha)) |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 225 | return IRQ_NONE; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 226 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 227 | tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 228 | #else |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 229 | ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 230 | #endif |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * pm8001_interrupt_handler_intx - main INTx interrupt handler. |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 236 | * @irq: interrupt number |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 237 | * @dev_id: sas_ha structure. The HBA is retrieved from sas_ha structure. |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 238 | */ |
| 239 | |
| 240 | static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 241 | { |
| 242 | struct pm8001_hba_info *pm8001_ha; |
| 243 | irqreturn_t ret = IRQ_HANDLED; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 244 | struct sas_ha_struct *sha = dev_id; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 245 | pm8001_ha = sha->lldd_ha; |
| 246 | if (unlikely(!pm8001_ha)) |
| 247 | return IRQ_NONE; |
Colin Ian King | f310a4e | 2019-03-29 23:44:23 +0000 | [diff] [blame] | 248 | if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 249 | return IRQ_NONE; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 250 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 251 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 252 | tasklet_schedule(&pm8001_ha->tasklet[0]); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 253 | #else |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 254 | ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 255 | #endif |
| 256 | return ret; |
| 257 | } |
| 258 | |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 259 | static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha); |
| 260 | static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha); |
| 261 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 262 | /** |
| 263 | * pm8001_alloc - initiate our hba structure and 6 DMAs area. |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 264 | * @pm8001_ha: our hba structure. |
| 265 | * @ent: PCI device ID structure to match on |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 266 | */ |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 267 | static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha, |
| 268 | const struct pci_device_id *ent) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 269 | { |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 270 | int i, count = 0, rc = 0; |
| 271 | u32 ci_offset, ib_offset, ob_offset, pi_offset; |
Viswas G | 1f02bef | 2021-04-15 16:03:52 +0530 | [diff] [blame] | 272 | struct inbound_queue_table *ibq; |
| 273 | struct outbound_queue_table *obq; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 274 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 275 | spin_lock_init(&pm8001_ha->lock); |
Tomas Henzl | 646cdf0 | 2014-07-09 17:21:01 +0530 | [diff] [blame] | 276 | spin_lock_init(&pm8001_ha->bitmap_lock); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 277 | pm8001_dbg(pm8001_ha, INIT, "pm8001_alloc: PHY:%x\n", |
| 278 | pm8001_ha->chip->n_phy); |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 279 | |
| 280 | /* Setup Interrupt */ |
| 281 | rc = pm8001_setup_irq(pm8001_ha); |
| 282 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 283 | pm8001_dbg(pm8001_ha, FAIL, |
| 284 | "pm8001_setup_irq failed [ret: %d]\n", rc); |
Igor Pylypiv | 6539262 | 2021-11-30 20:16:27 -0800 | [diff] [blame^] | 285 | goto err_out; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 286 | } |
| 287 | /* Request Interrupt */ |
| 288 | rc = pm8001_request_irq(pm8001_ha); |
| 289 | if (rc) |
Igor Pylypiv | 6539262 | 2021-11-30 20:16:27 -0800 | [diff] [blame^] | 290 | goto err_out; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 291 | |
| 292 | count = pm8001_ha->max_q_num; |
| 293 | /* Queues are chosen based on the number of cores/msix availability */ |
Viswas G | 27bc43b | 2020-10-05 20:20:09 +0530 | [diff] [blame] | 294 | ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 295 | ci_offset = pm8001_ha->ci_offset = ib_offset + count; |
| 296 | ob_offset = pm8001_ha->ob_offset = ci_offset + count; |
| 297 | pi_offset = pm8001_ha->pi_offset = ob_offset + count; |
| 298 | pm8001_ha->max_memcnt = pi_offset + count; |
| 299 | |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 300 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 301 | pm8001_phy_init(pm8001_ha, i); |
jack wang | 1cc943a | 2009-12-07 17:22:42 +0800 | [diff] [blame] | 302 | pm8001_ha->port[i].wide_port_phymap = 0; |
| 303 | pm8001_ha->port[i].port_attached = 0; |
| 304 | pm8001_ha->port[i].port_state = 0; |
| 305 | INIT_LIST_HEAD(&pm8001_ha->port[i].list); |
| 306 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 307 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 308 | /* MPI Memory region 1 for AAP Event Log for fw */ |
| 309 | pm8001_ha->memoryMap.region[AAP1].num_elements = 1; |
| 310 | pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE; |
| 311 | pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE; |
| 312 | pm8001_ha->memoryMap.region[AAP1].alignment = 32; |
| 313 | |
| 314 | /* MPI Memory region 2 for IOP Event Log for fw */ |
| 315 | pm8001_ha->memoryMap.region[IOP].num_elements = 1; |
| 316 | pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE; |
| 317 | pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE; |
| 318 | pm8001_ha->memoryMap.region[IOP].alignment = 32; |
| 319 | |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 320 | for (i = 0; i < count; i++) { |
Viswas G | 1f02bef | 2021-04-15 16:03:52 +0530 | [diff] [blame] | 321 | ibq = &pm8001_ha->inbnd_q_tbl[i]; |
| 322 | spin_lock_init(&ibq->iq_lock); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 323 | /* MPI Memory region 3 for consumer Index of inbound queues */ |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 324 | pm8001_ha->memoryMap.region[ci_offset+i].num_elements = 1; |
| 325 | pm8001_ha->memoryMap.region[ci_offset+i].element_size = 4; |
| 326 | pm8001_ha->memoryMap.region[ci_offset+i].total_len = 4; |
| 327 | pm8001_ha->memoryMap.region[ci_offset+i].alignment = 4; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 328 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 329 | if ((ent->driver_data) != chip_8001) { |
| 330 | /* MPI Memory region 5 inbound queues */ |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 331 | pm8001_ha->memoryMap.region[ib_offset+i].num_elements = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 332 | PM8001_MPI_QUEUE; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 333 | pm8001_ha->memoryMap.region[ib_offset+i].element_size |
| 334 | = 128; |
| 335 | pm8001_ha->memoryMap.region[ib_offset+i].total_len = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 336 | PM8001_MPI_QUEUE * 128; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 337 | pm8001_ha->memoryMap.region[ib_offset+i].alignment |
| 338 | = 128; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 339 | } else { |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 340 | pm8001_ha->memoryMap.region[ib_offset+i].num_elements = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 341 | PM8001_MPI_QUEUE; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 342 | pm8001_ha->memoryMap.region[ib_offset+i].element_size |
| 343 | = 64; |
| 344 | pm8001_ha->memoryMap.region[ib_offset+i].total_len = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 345 | PM8001_MPI_QUEUE * 64; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 346 | pm8001_ha->memoryMap.region[ib_offset+i].alignment = 64; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 347 | } |
| 348 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 349 | |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 350 | for (i = 0; i < count; i++) { |
Viswas G | 1f02bef | 2021-04-15 16:03:52 +0530 | [diff] [blame] | 351 | obq = &pm8001_ha->outbnd_q_tbl[i]; |
| 352 | spin_lock_init(&obq->oq_lock); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 353 | /* MPI Memory region 4 for producer Index of outbound queues */ |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 354 | pm8001_ha->memoryMap.region[pi_offset+i].num_elements = 1; |
| 355 | pm8001_ha->memoryMap.region[pi_offset+i].element_size = 4; |
| 356 | pm8001_ha->memoryMap.region[pi_offset+i].total_len = 4; |
| 357 | pm8001_ha->memoryMap.region[pi_offset+i].alignment = 4; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 358 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 359 | if (ent->driver_data != chip_8001) { |
| 360 | /* MPI Memory region 6 Outbound queues */ |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 361 | pm8001_ha->memoryMap.region[ob_offset+i].num_elements = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 362 | PM8001_MPI_QUEUE; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 363 | pm8001_ha->memoryMap.region[ob_offset+i].element_size |
| 364 | = 128; |
| 365 | pm8001_ha->memoryMap.region[ob_offset+i].total_len = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 366 | PM8001_MPI_QUEUE * 128; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 367 | pm8001_ha->memoryMap.region[ob_offset+i].alignment |
| 368 | = 128; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 369 | } else { |
| 370 | /* MPI Memory region 6 Outbound queues */ |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 371 | pm8001_ha->memoryMap.region[ob_offset+i].num_elements = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 372 | PM8001_MPI_QUEUE; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 373 | pm8001_ha->memoryMap.region[ob_offset+i].element_size |
| 374 | = 64; |
| 375 | pm8001_ha->memoryMap.region[ob_offset+i].total_len = |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 376 | PM8001_MPI_QUEUE * 64; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 377 | pm8001_ha->memoryMap.region[ob_offset+i].alignment = 64; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 378 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 379 | |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 380 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 381 | /* Memory region write DMA*/ |
| 382 | pm8001_ha->memoryMap.region[NVMD].num_elements = 1; |
| 383 | pm8001_ha->memoryMap.region[NVMD].element_size = 4096; |
| 384 | pm8001_ha->memoryMap.region[NVMD].total_len = 4096; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 385 | |
Sakthivel K | 1c75a67 | 2013-03-19 18:06:40 +0530 | [diff] [blame] | 386 | /* Memory region for fw flash */ |
| 387 | pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096; |
| 388 | |
Anand Kumar Santhanam | d078b51 | 2013-09-04 12:57:00 +0530 | [diff] [blame] | 389 | pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1; |
| 390 | pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000; |
| 391 | pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000; |
| 392 | pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 393 | for (i = 0; i < pm8001_ha->max_memcnt; i++) { |
Joe Perches | 9aed578 | 2020-11-23 20:36:04 -0800 | [diff] [blame] | 394 | struct mpi_mem *region = &pm8001_ha->memoryMap.region[i]; |
| 395 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 396 | if (pm8001_mem_alloc(pm8001_ha->pdev, |
Joe Perches | 9aed578 | 2020-11-23 20:36:04 -0800 | [diff] [blame] | 397 | ®ion->virt_ptr, |
| 398 | ®ion->phys_addr, |
| 399 | ®ion->phys_addr_hi, |
| 400 | ®ion->phys_addr_lo, |
| 401 | region->total_len, |
| 402 | region->alignment) != 0) { |
| 403 | pm8001_dbg(pm8001_ha, FAIL, "Mem%d alloc failed\n", i); |
| 404 | goto err_out; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
Viswas G | 27bc43b | 2020-10-05 20:20:09 +0530 | [diff] [blame] | 408 | /* Memory region for devices*/ |
| 409 | pm8001_ha->devices = kzalloc(PM8001_MAX_DEVICES |
| 410 | * sizeof(struct pm8001_device), GFP_KERNEL); |
| 411 | if (!pm8001_ha->devices) { |
| 412 | rc = -ENOMEM; |
| 413 | goto err_out_nodev; |
| 414 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 415 | for (i = 0; i < PM8001_MAX_DEVICES; i++) { |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 416 | pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 417 | pm8001_ha->devices[i].id = i; |
| 418 | pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES; |
Viswas G | 4a2efd4 | 2020-11-02 22:25:26 +0530 | [diff] [blame] | 419 | atomic_set(&pm8001_ha->devices[i].running_req, 0); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 420 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 421 | pm8001_ha->flags = PM8001F_INIT_TIME; |
| 422 | /* Initialize tags */ |
| 423 | pm8001_tag_init(pm8001_ha); |
| 424 | return 0; |
Viswas G | 27bc43b | 2020-10-05 20:20:09 +0530 | [diff] [blame] | 425 | |
Viswas G | 27bc43b | 2020-10-05 20:20:09 +0530 | [diff] [blame] | 426 | err_out_nodev: |
| 427 | for (i = 0; i < pm8001_ha->max_memcnt; i++) { |
| 428 | if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) { |
Christophe JAILLET | 8e60a7d | 2021-01-17 14:24:45 +0100 | [diff] [blame] | 429 | dma_free_coherent(&pm8001_ha->pdev->dev, |
Viswas G | 27bc43b | 2020-10-05 20:20:09 +0530 | [diff] [blame] | 430 | (pm8001_ha->memoryMap.region[i].total_len + |
| 431 | pm8001_ha->memoryMap.region[i].alignment), |
| 432 | pm8001_ha->memoryMap.region[i].virt_ptr, |
| 433 | pm8001_ha->memoryMap.region[i].phys_addr); |
| 434 | } |
| 435 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 436 | err_out: |
| 437 | return 1; |
| 438 | } |
| 439 | |
| 440 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 441 | * pm8001_ioremap - remap the pci high physical address to kernel virtual |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 442 | * address so that we can access them. |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 443 | * @pm8001_ha: our hba structure. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 444 | */ |
| 445 | static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha) |
| 446 | { |
| 447 | u32 bar; |
| 448 | u32 logicalBar = 0; |
| 449 | struct pci_dev *pdev; |
| 450 | |
| 451 | pdev = pm8001_ha->pdev; |
| 452 | /* map pci mem (PMC pci base 0-3)*/ |
Denis Efremov | c9c13ba | 2019-09-28 02:43:08 +0300 | [diff] [blame] | 453 | for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 454 | /* |
| 455 | ** logical BARs for SPC: |
| 456 | ** bar 0 and 1 - logical BAR0 |
| 457 | ** bar 2 and 3 - logical BAR1 |
| 458 | ** bar4 - logical BAR2 |
| 459 | ** bar5 - logical BAR3 |
| 460 | ** Skip the appropriate assignments: |
| 461 | */ |
| 462 | if ((bar == 1) || (bar == 3)) |
| 463 | continue; |
| 464 | if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) { |
| 465 | pm8001_ha->io_mem[logicalBar].membase = |
| 466 | pci_resource_start(pdev, bar); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 467 | pm8001_ha->io_mem[logicalBar].memsize = |
| 468 | pci_resource_len(pdev, bar); |
| 469 | pm8001_ha->io_mem[logicalBar].memvirtaddr = |
| 470 | ioremap(pm8001_ha->io_mem[logicalBar].membase, |
| 471 | pm8001_ha->io_mem[logicalBar].memsize); |
akshatzen | 95652f9 | 2021-01-09 18:08:44 +0530 | [diff] [blame] | 472 | if (!pm8001_ha->io_mem[logicalBar].memvirtaddr) { |
| 473 | pm8001_dbg(pm8001_ha, INIT, |
| 474 | "Failed to ioremap bar %d, logicalBar %d", |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 475 | bar, logicalBar); |
akshatzen | 95652f9 | 2021-01-09 18:08:44 +0530 | [diff] [blame] | 476 | return -ENOMEM; |
| 477 | } |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 478 | pm8001_dbg(pm8001_ha, INIT, |
| 479 | "base addr %llx virt_addr=%llx len=%d\n", |
| 480 | (u64)pm8001_ha->io_mem[logicalBar].membase, |
| 481 | (u64)(unsigned long) |
| 482 | pm8001_ha->io_mem[logicalBar].memvirtaddr, |
| 483 | pm8001_ha->io_mem[logicalBar].memsize); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 484 | } else { |
| 485 | pm8001_ha->io_mem[logicalBar].membase = 0; |
| 486 | pm8001_ha->io_mem[logicalBar].memsize = 0; |
Saurav Girepunje | 62fb8b3 | 2019-10-25 19:20:14 +0530 | [diff] [blame] | 487 | pm8001_ha->io_mem[logicalBar].memvirtaddr = NULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 488 | } |
| 489 | logicalBar++; |
| 490 | } |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * pm8001_pci_alloc - initialize our ha card structure |
| 496 | * @pdev: pci device. |
| 497 | * @ent: ent |
| 498 | * @shost: scsi host struct which has been initialized before. |
| 499 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 500 | static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev, |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 501 | const struct pci_device_id *ent, |
| 502 | struct Scsi_Host *shost) |
| 503 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 504 | { |
| 505 | struct pm8001_hba_info *pm8001_ha; |
| 506 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 507 | int j; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 508 | |
| 509 | pm8001_ha = sha->lldd_ha; |
| 510 | if (!pm8001_ha) |
| 511 | return NULL; |
| 512 | |
| 513 | pm8001_ha->pdev = pdev; |
| 514 | pm8001_ha->dev = &pdev->dev; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 515 | pm8001_ha->chip_id = ent->driver_data; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 516 | pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id]; |
| 517 | pm8001_ha->irq = pdev->irq; |
| 518 | pm8001_ha->sas = sha; |
| 519 | pm8001_ha->shost = shost; |
| 520 | pm8001_ha->id = pm8001_id++; |
peter chang | 7370672 | 2019-11-14 15:39:02 +0530 | [diff] [blame] | 521 | pm8001_ha->logging_level = logging_level; |
Deepak Ukey | dba2cc0 | 2020-03-16 13:19:05 +0530 | [diff] [blame] | 522 | pm8001_ha->non_fatal_count = 0; |
peter chang | 3e253d9 | 2019-11-14 15:39:07 +0530 | [diff] [blame] | 523 | if (link_rate >= 1 && link_rate <= 15) |
| 524 | pm8001_ha->link_rate = (link_rate << 8); |
| 525 | else { |
| 526 | pm8001_ha->link_rate = LINKRATE_15 | LINKRATE_30 | |
| 527 | LINKRATE_60 | LINKRATE_120; |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 528 | pm8001_dbg(pm8001_ha, FAIL, |
| 529 | "Setting link rate to default value\n"); |
peter chang | 3e253d9 | 2019-11-14 15:39:07 +0530 | [diff] [blame] | 530 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 531 | sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id); |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 532 | /* IOMB size is 128 for 8088/89 controllers */ |
| 533 | if (pm8001_ha->chip_id != chip_8001) |
| 534 | pm8001_ha->iomb_size = IOMB_SIZE_SPCV; |
| 535 | else |
| 536 | pm8001_ha->iomb_size = IOMB_SIZE_SPC; |
| 537 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 538 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 539 | /* Tasklet for non msi-x interrupt handler */ |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 540 | if ((!pdev->msix_cap || !pci_msi_enabled()) |
| 541 | || (pm8001_ha->chip_id == chip_8001)) |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 542 | tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet, |
| 543 | (unsigned long)&(pm8001_ha->irq_vector[0])); |
| 544 | else |
| 545 | for (j = 0; j < PM8001_MAX_MSIX_VEC; j++) |
| 546 | tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet, |
| 547 | (unsigned long)&(pm8001_ha->irq_vector[j])); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 548 | #endif |
akshatzen | 95652f9 | 2021-01-09 18:08:44 +0530 | [diff] [blame] | 549 | if (pm8001_ioremap(pm8001_ha)) |
| 550 | goto failed_pci_alloc; |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 551 | if (!pm8001_alloc(pm8001_ha, ent)) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 552 | return pm8001_ha; |
akshatzen | 95652f9 | 2021-01-09 18:08:44 +0530 | [diff] [blame] | 553 | failed_pci_alloc: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 554 | pm8001_free(pm8001_ha); |
| 555 | return NULL; |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit |
| 560 | * @pdev: pci device. |
| 561 | */ |
| 562 | static int pci_go_44(struct pci_dev *pdev) |
| 563 | { |
| 564 | int rc; |
| 565 | |
Christoph Hellwig | f73bdeb | 2018-10-10 19:59:50 +0200 | [diff] [blame] | 566 | rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44)); |
| 567 | if (rc) { |
| 568 | rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 569 | if (rc) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 570 | dev_printk(KERN_ERR, &pdev->dev, |
| 571 | "32-bit DMA enable failed\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 572 | } |
| 573 | return rc; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them. |
| 578 | * @shost: scsi host which has been allocated outside. |
| 579 | * @chip_info: our ha struct. |
| 580 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 581 | static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost, |
| 582 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 583 | { |
| 584 | int phy_nr, port_nr; |
| 585 | struct asd_sas_phy **arr_phy; |
| 586 | struct asd_sas_port **arr_port; |
| 587 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 588 | |
| 589 | phy_nr = chip_info->n_phy; |
| 590 | port_nr = phy_nr; |
| 591 | memset(sha, 0x00, sizeof(*sha)); |
| 592 | arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL); |
| 593 | if (!arr_phy) |
| 594 | goto exit; |
| 595 | arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL); |
| 596 | if (!arr_port) |
| 597 | goto exit_free2; |
| 598 | |
| 599 | sha->sas_phy = arr_phy; |
| 600 | sha->sas_port = arr_port; |
| 601 | sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL); |
| 602 | if (!sha->lldd_ha) |
| 603 | goto exit_free1; |
| 604 | |
| 605 | shost->transportt = pm8001_stt; |
| 606 | shost->max_id = PM8001_MAX_DEVICES; |
| 607 | shost->max_lun = 8; |
| 608 | shost->max_channel = 0; |
| 609 | shost->unique_id = pm8001_id; |
| 610 | shost->max_cmd_len = 16; |
| 611 | shost->can_queue = PM8001_CAN_QUEUE; |
| 612 | shost->cmd_per_lun = 32; |
| 613 | return 0; |
| 614 | exit_free1: |
| 615 | kfree(arr_port); |
| 616 | exit_free2: |
| 617 | kfree(arr_phy); |
| 618 | exit: |
| 619 | return -1; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas |
| 624 | * @shost: scsi host which has been allocated outside |
| 625 | * @chip_info: our ha struct. |
| 626 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 627 | static void pm8001_post_sas_ha_init(struct Scsi_Host *shost, |
| 628 | const struct pm8001_chip_info *chip_info) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 629 | { |
| 630 | int i = 0; |
| 631 | struct pm8001_hba_info *pm8001_ha; |
| 632 | struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost); |
| 633 | |
| 634 | pm8001_ha = sha->lldd_ha; |
| 635 | for (i = 0; i < chip_info->n_phy; i++) { |
| 636 | sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy; |
| 637 | sha->sas_port[i] = &pm8001_ha->port[i].sas_port; |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 638 | sha->sas_phy[i]->sas_addr = |
| 639 | (u8 *)&pm8001_ha->phy[i].dev_sas_addr; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 640 | } |
| 641 | sha->sas_ha_name = DRV_NAME; |
| 642 | sha->dev = pm8001_ha->dev; |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 643 | sha->strict_wide_ports = 1; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 644 | sha->lldd_module = THIS_MODULE; |
| 645 | sha->sas_addr = &pm8001_ha->sas_addr[0]; |
| 646 | sha->num_phys = chip_info->n_phy; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 647 | sha->core.shost = shost; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * pm8001_init_sas_add - initialize sas address |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 652 | * @pm8001_ha: our ha struct. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 653 | * |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 654 | * Currently we just set the fixed SAS address to our HBA, for manufacture, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 655 | * it should read from the EEPROM |
| 656 | */ |
| 657 | static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha) |
| 658 | { |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 659 | u8 i, j; |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 660 | u8 sas_add[8]; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 661 | #ifdef PM8001_READ_VPD |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 662 | /* For new SPC controllers WWN is stored in flash vpd |
| 663 | * For SPC/SPCve controllers WWN is stored in EEPROM |
| 664 | * For Older SPC WWN is stored in NVMD |
| 665 | */ |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 666 | DECLARE_COMPLETION_ONSTACK(completion); |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 667 | struct pm8001_ioctl_payload payload; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 668 | u16 deviceid; |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 669 | int rc; |
| 670 | |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 671 | pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 672 | pm8001_ha->nvmd_completion = &completion; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 673 | |
| 674 | if (pm8001_ha->chip_id == chip_8001) { |
Bradley Grove | f49d213 | 2013-12-19 10:50:56 -0500 | [diff] [blame] | 675 | if (deviceid == 0x8081 || deviceid == 0x0042) { |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 676 | payload.minor_function = 4; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 677 | payload.rd_length = 4096; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 678 | } else { |
| 679 | payload.minor_function = 0; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 680 | payload.rd_length = 128; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 681 | } |
Benjamin Rood | 10efa46 | 2015-11-02 15:39:23 -0500 | [diff] [blame] | 682 | } else if ((pm8001_ha->chip_id == chip_8070 || |
| 683 | pm8001_ha->chip_id == chip_8072) && |
| 684 | pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) { |
| 685 | payload.minor_function = 4; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 686 | payload.rd_length = 4096; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 687 | } else { |
| 688 | payload.minor_function = 1; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 689 | payload.rd_length = 4096; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 690 | } |
| 691 | payload.offset = 0; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 692 | payload.func_specific = kzalloc(payload.rd_length, GFP_KERNEL); |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 693 | if (!payload.func_specific) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 694 | pm8001_dbg(pm8001_ha, INIT, "mem alloc fail\n"); |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload); |
| 698 | if (rc) { |
| 699 | kfree(payload.func_specific); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 700 | pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n"); |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 701 | return; |
| 702 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 703 | wait_for_completion(&completion); |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 704 | |
| 705 | for (i = 0, j = 0; i <= 7; i++, j++) { |
| 706 | if (pm8001_ha->chip_id == chip_8001) { |
| 707 | if (deviceid == 0x8081) |
| 708 | pm8001_ha->sas_addr[j] = |
| 709 | payload.func_specific[0x704 + i]; |
Bradley Grove | f49d213 | 2013-12-19 10:50:56 -0500 | [diff] [blame] | 710 | else if (deviceid == 0x0042) |
| 711 | pm8001_ha->sas_addr[j] = |
| 712 | payload.func_specific[0x010 + i]; |
Benjamin Rood | 10efa46 | 2015-11-02 15:39:23 -0500 | [diff] [blame] | 713 | } else if ((pm8001_ha->chip_id == chip_8070 || |
| 714 | pm8001_ha->chip_id == chip_8072) && |
| 715 | pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) { |
| 716 | pm8001_ha->sas_addr[j] = |
| 717 | payload.func_specific[0x010 + i]; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 718 | } else |
| 719 | pm8001_ha->sas_addr[j] = |
| 720 | payload.func_specific[0x804 + i]; |
| 721 | } |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 722 | memcpy(sas_add, pm8001_ha->sas_addr, SAS_ADDR_SIZE); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 723 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 724 | if (i && ((i % 4) == 0)) |
| 725 | sas_add[7] = sas_add[7] + 4; |
Sakthivel K | a33a015 | 2013-03-19 18:07:35 +0530 | [diff] [blame] | 726 | memcpy(&pm8001_ha->phy[i].dev_sas_addr, |
Viswas G | 6c85e4b | 2017-10-18 11:39:09 +0530 | [diff] [blame] | 727 | sas_add, SAS_ADDR_SIZE); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 728 | pm8001_dbg(pm8001_ha, INIT, "phy %d sas_addr = %016llx\n", i, |
| 729 | pm8001_ha->phy[i].dev_sas_addr); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 730 | } |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 731 | kfree(payload.func_specific); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 732 | #else |
| 733 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
jack wang | 7c8356d | 2009-12-07 17:23:08 +0800 | [diff] [blame] | 734 | pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 735 | pm8001_ha->phy[i].dev_sas_addr = |
| 736 | cpu_to_be64((u64) |
| 737 | (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr)); |
| 738 | } |
| 739 | memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr, |
| 740 | SAS_ADDR_SIZE); |
| 741 | #endif |
| 742 | } |
| 743 | |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 744 | /* |
| 745 | * pm8001_get_phy_settings_info : Read phy setting values. |
| 746 | * @pm8001_ha : our hba. |
| 747 | */ |
Maurizio Lombardi | f2c6f18 | 2014-06-17 13:15:40 +0200 | [diff] [blame] | 748 | static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha) |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 749 | { |
| 750 | |
| 751 | #ifdef PM8001_READ_VPD |
| 752 | /*OPTION ROM FLASH read for the SPC cards */ |
| 753 | DECLARE_COMPLETION_ONSTACK(completion); |
| 754 | struct pm8001_ioctl_payload payload; |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 755 | int rc; |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 756 | |
| 757 | pm8001_ha->nvmd_completion = &completion; |
| 758 | /* SAS ADDRESS read from flash / EEPROM */ |
| 759 | payload.minor_function = 6; |
| 760 | payload.offset = 0; |
Viswas G | 9b88984 | 2020-03-16 13:19:06 +0530 | [diff] [blame] | 761 | payload.rd_length = 4096; |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 762 | payload.func_specific = kzalloc(4096, GFP_KERNEL); |
Maurizio Lombardi | f2c6f18 | 2014-06-17 13:15:40 +0200 | [diff] [blame] | 763 | if (!payload.func_specific) |
| 764 | return -ENOMEM; |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 765 | /* Read phy setting values from flash */ |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 766 | rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload); |
| 767 | if (rc) { |
| 768 | kfree(payload.func_specific); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 769 | pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n"); |
Tomas Henzl | 5b4ce88 | 2014-07-09 17:21:11 +0530 | [diff] [blame] | 770 | return -ENOMEM; |
| 771 | } |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 772 | wait_for_completion(&completion); |
| 773 | pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific); |
Maurizio Lombardi | f2c6f18 | 2014-06-17 13:15:40 +0200 | [diff] [blame] | 774 | kfree(payload.func_specific); |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 775 | #endif |
Maurizio Lombardi | f2c6f18 | 2014-06-17 13:15:40 +0200 | [diff] [blame] | 776 | return 0; |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 777 | } |
| 778 | |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 779 | struct pm8001_mpi3_phy_pg_trx_config { |
| 780 | u32 LaneLosCfg; |
| 781 | u32 LanePgaCfg1; |
| 782 | u32 LanePisoCfg1; |
| 783 | u32 LanePisoCfg2; |
| 784 | u32 LanePisoCfg3; |
| 785 | u32 LanePisoCfg4; |
| 786 | u32 LanePisoCfg5; |
| 787 | u32 LanePisoCfg6; |
| 788 | u32 LaneBctCtrl; |
| 789 | }; |
| 790 | |
| 791 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 792 | * pm8001_get_internal_phy_settings - Retrieves the internal PHY settings |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 793 | * @pm8001_ha : our adapter |
| 794 | * @phycfg : PHY config page to populate |
| 795 | */ |
| 796 | static |
| 797 | void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha, |
| 798 | struct pm8001_mpi3_phy_pg_trx_config *phycfg) |
| 799 | { |
| 800 | phycfg->LaneLosCfg = 0x00000132; |
| 801 | phycfg->LanePgaCfg1 = 0x00203949; |
| 802 | phycfg->LanePisoCfg1 = 0x000000FF; |
| 803 | phycfg->LanePisoCfg2 = 0xFF000001; |
| 804 | phycfg->LanePisoCfg3 = 0xE7011300; |
| 805 | phycfg->LanePisoCfg4 = 0x631C40C0; |
| 806 | phycfg->LanePisoCfg5 = 0xF8102036; |
| 807 | phycfg->LanePisoCfg6 = 0xF74A1000; |
| 808 | phycfg->LaneBctCtrl = 0x00FB33F8; |
| 809 | } |
| 810 | |
| 811 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 812 | * pm8001_get_external_phy_settings - Retrieves the external PHY settings |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 813 | * @pm8001_ha : our adapter |
| 814 | * @phycfg : PHY config page to populate |
| 815 | */ |
| 816 | static |
| 817 | void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha, |
| 818 | struct pm8001_mpi3_phy_pg_trx_config *phycfg) |
| 819 | { |
| 820 | phycfg->LaneLosCfg = 0x00000132; |
| 821 | phycfg->LanePgaCfg1 = 0x00203949; |
| 822 | phycfg->LanePisoCfg1 = 0x000000FF; |
| 823 | phycfg->LanePisoCfg2 = 0xFF000001; |
| 824 | phycfg->LanePisoCfg3 = 0xE7011300; |
| 825 | phycfg->LanePisoCfg4 = 0x63349140; |
| 826 | phycfg->LanePisoCfg5 = 0xF8102036; |
| 827 | phycfg->LanePisoCfg6 = 0xF80D9300; |
| 828 | phycfg->LaneBctCtrl = 0x00FB33F8; |
| 829 | } |
| 830 | |
| 831 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 832 | * pm8001_get_phy_mask - Retrieves the mask that denotes if a PHY is int/ext |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 833 | * @pm8001_ha : our adapter |
| 834 | * @phymask : The PHY mask |
| 835 | */ |
| 836 | static |
| 837 | void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask) |
| 838 | { |
| 839 | switch (pm8001_ha->pdev->subsystem_device) { |
| 840 | case 0x0070: /* H1280 - 8 external 0 internal */ |
| 841 | case 0x0072: /* H12F0 - 16 external 0 internal */ |
| 842 | *phymask = 0x0000; |
| 843 | break; |
| 844 | |
| 845 | case 0x0071: /* H1208 - 0 external 8 internal */ |
| 846 | case 0x0073: /* H120F - 0 external 16 internal */ |
| 847 | *phymask = 0xFFFF; |
| 848 | break; |
| 849 | |
| 850 | case 0x0080: /* H1244 - 4 external 4 internal */ |
| 851 | *phymask = 0x00F0; |
| 852 | break; |
| 853 | |
| 854 | case 0x0081: /* H1248 - 4 external 8 internal */ |
| 855 | *phymask = 0x0FF0; |
| 856 | break; |
| 857 | |
| 858 | case 0x0082: /* H1288 - 8 external 8 internal */ |
| 859 | *phymask = 0xFF00; |
| 860 | break; |
| 861 | |
| 862 | default: |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 863 | pm8001_dbg(pm8001_ha, INIT, |
| 864 | "Unknown subsystem device=0x%.04x\n", |
| 865 | pm8001_ha->pdev->subsystem_device); |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 870 | * pm8001_set_phy_settings_ven_117c_12G() - Configure ATTO 12Gb PHY settings |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 871 | * @pm8001_ha : our adapter |
| 872 | */ |
| 873 | static |
| 874 | int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha) |
| 875 | { |
| 876 | struct pm8001_mpi3_phy_pg_trx_config phycfg_int; |
| 877 | struct pm8001_mpi3_phy_pg_trx_config phycfg_ext; |
| 878 | int phymask = 0; |
| 879 | int i = 0; |
| 880 | |
| 881 | memset(&phycfg_int, 0, sizeof(phycfg_int)); |
| 882 | memset(&phycfg_ext, 0, sizeof(phycfg_ext)); |
| 883 | |
| 884 | pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int); |
| 885 | pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext); |
| 886 | pm8001_get_phy_mask(pm8001_ha, &phymask); |
| 887 | |
| 888 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
| 889 | if (phymask & (1 << i)) {/* Internal PHY */ |
| 890 | pm8001_set_phy_profile_single(pm8001_ha, i, |
| 891 | sizeof(phycfg_int) / sizeof(u32), |
| 892 | (u32 *)&phycfg_int); |
| 893 | |
| 894 | } else { /* External PHY */ |
| 895 | pm8001_set_phy_profile_single(pm8001_ha, i, |
| 896 | sizeof(phycfg_ext) / sizeof(u32), |
| 897 | (u32 *)&phycfg_ext); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
Benjamin Rood | da2dd61 | 2015-10-30 10:53:24 -0400 | [diff] [blame] | 904 | /** |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 905 | * pm8001_configure_phy_settings - Configures PHY settings based on vendor ID. |
Benjamin Rood | da2dd61 | 2015-10-30 10:53:24 -0400 | [diff] [blame] | 906 | * @pm8001_ha : our hba. |
| 907 | */ |
| 908 | static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha) |
| 909 | { |
| 910 | switch (pm8001_ha->pdev->subsystem_vendor) { |
| 911 | case PCI_VENDOR_ID_ATTO: |
Benjamin Rood | c5614df | 2015-10-30 10:53:28 -0400 | [diff] [blame] | 912 | if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */ |
| 913 | return 0; |
| 914 | else |
| 915 | return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha); |
| 916 | |
Benjamin Rood | da2dd61 | 2015-10-30 10:53:24 -0400 | [diff] [blame] | 917 | case PCI_VENDOR_ID_ADAPTEC2: |
| 918 | case 0: |
| 919 | return 0; |
| 920 | |
| 921 | default: |
| 922 | return pm8001_get_phy_settings_info(pm8001_ha); |
| 923 | } |
| 924 | } |
| 925 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 926 | #ifdef PM8001_USE_MSIX |
| 927 | /** |
| 928 | * pm8001_setup_msix - enable MSI-X interrupt |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 929 | * @pm8001_ha: our ha struct. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 930 | */ |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 931 | static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 932 | { |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 933 | u32 number_of_intr; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 934 | int rc, cpu_online_count; |
| 935 | unsigned int allocated_irq_vectors; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 936 | |
| 937 | /* SPCv controllers supports 64 msi-x */ |
| 938 | if (pm8001_ha->chip_id == chip_8001) { |
| 939 | number_of_intr = 1; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 940 | } else { |
| 941 | number_of_intr = PM8001_MAX_MSIX_VEC; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 942 | } |
| 943 | |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 944 | cpu_online_count = num_online_cpus(); |
| 945 | number_of_intr = min_t(int, cpu_online_count, number_of_intr); |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 946 | rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr, |
| 947 | number_of_intr, PCI_IRQ_MSIX); |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 948 | allocated_irq_vectors = rc; |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 949 | if (rc < 0) |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 950 | return rc; |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 951 | |
| 952 | /* Assigns the number of interrupts */ |
| 953 | number_of_intr = min_t(int, allocated_irq_vectors, number_of_intr); |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 954 | pm8001_ha->number_of_intr = number_of_intr; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 955 | |
Viswas G | 05c6c02 | 2020-10-05 20:20:08 +0530 | [diff] [blame] | 956 | /* Maximum queue number updating in HBA structure */ |
| 957 | pm8001_ha->max_q_num = number_of_intr; |
| 958 | |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 959 | pm8001_dbg(pm8001_ha, INIT, |
| 960 | "pci_alloc_irq_vectors request ret:%d no of intr %d\n", |
| 961 | rc, pm8001_ha->number_of_intr); |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 962 | return 0; |
| 963 | } |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 964 | |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 965 | static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha) |
| 966 | { |
| 967 | u32 i = 0, j = 0; |
| 968 | int flag = 0, rc = 0; |
Arnd Bergmann | c2255ec | 2021-03-23 13:54:23 +0100 | [diff] [blame] | 969 | int nr_irqs = pm8001_ha->number_of_intr; |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 970 | |
| 971 | if (pm8001_ha->chip_id != chip_8001) |
| 972 | flag &= ~IRQF_SHARED; |
| 973 | |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 974 | pm8001_dbg(pm8001_ha, INIT, |
| 975 | "pci_enable_msix request number of intr %d\n", |
| 976 | pm8001_ha->number_of_intr); |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 977 | |
Arnd Bergmann | c2255ec | 2021-03-23 13:54:23 +0100 | [diff] [blame] | 978 | if (nr_irqs > ARRAY_SIZE(pm8001_ha->intr_drvname)) |
| 979 | nr_irqs = ARRAY_SIZE(pm8001_ha->intr_drvname); |
| 980 | |
| 981 | for (i = 0; i < nr_irqs; i++) { |
Vikram Auradkar | 7295493 | 2019-11-14 15:39:09 +0530 | [diff] [blame] | 982 | snprintf(pm8001_ha->intr_drvname[i], |
| 983 | sizeof(pm8001_ha->intr_drvname[0]), |
| 984 | "%s-%d", pm8001_ha->name, i); |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 985 | pm8001_ha->irq_vector[i].irq_id = i; |
| 986 | pm8001_ha->irq_vector[i].drv_inst = pm8001_ha; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 987 | |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 988 | rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i), |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 989 | pm8001_interrupt_handler_msix, flag, |
Vikram Auradkar | 7295493 | 2019-11-14 15:39:09 +0530 | [diff] [blame] | 990 | pm8001_ha->intr_drvname[i], |
| 991 | &(pm8001_ha->irq_vector[i])); |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 992 | if (rc) { |
| 993 | for (j = 0; j < i; j++) { |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 994 | free_irq(pci_irq_vector(pm8001_ha->pdev, i), |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 995 | &(pm8001_ha->irq_vector[i])); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 996 | } |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 997 | pci_free_irq_vectors(pm8001_ha->pdev); |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 998 | break; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 999 | } |
| 1000 | } |
Alexander Gordeev | b4d511e | 2014-07-16 20:05:22 +0200 | [diff] [blame] | 1001 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1002 | return rc; |
| 1003 | } |
| 1004 | #endif |
| 1005 | |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 1006 | static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha) |
| 1007 | { |
| 1008 | struct pci_dev *pdev; |
| 1009 | |
| 1010 | pdev = pm8001_ha->pdev; |
| 1011 | |
| 1012 | #ifdef PM8001_USE_MSIX |
| 1013 | if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) |
| 1014 | return pm8001_setup_msix(pm8001_ha); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1015 | pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n"); |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 1016 | #endif |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1020 | /** |
| 1021 | * pm8001_request_irq - register interrupt |
Lee Jones | e802fc4 | 2020-07-13 08:46:42 +0100 | [diff] [blame] | 1022 | * @pm8001_ha: our ha struct. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1023 | */ |
| 1024 | static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha) |
| 1025 | { |
| 1026 | struct pci_dev *pdev; |
jack_wang | 97ee208 | 2009-11-05 22:33:51 +0800 | [diff] [blame] | 1027 | int rc; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1028 | |
| 1029 | pdev = pm8001_ha->pdev; |
| 1030 | |
| 1031 | #ifdef PM8001_USE_MSIX |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 1032 | if (pdev->msix_cap && pci_msi_enabled()) |
Vikram Auradkar | d384be6 | 2020-03-16 13:19:02 +0530 | [diff] [blame] | 1033 | return pm8001_request_msix(pm8001_ha); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1034 | else { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1035 | pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1036 | goto intx; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1037 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1038 | #endif |
| 1039 | |
| 1040 | intx: |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 1041 | /* initialize the INT-X interrupt */ |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 1042 | pm8001_ha->irq_vector[0].irq_id = 0; |
| 1043 | pm8001_ha->irq_vector[0].drv_inst = pm8001_ha; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1044 | rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED, |
Vikram Auradkar | 7295493 | 2019-11-14 15:39:09 +0530 | [diff] [blame] | 1045 | pm8001_ha->name, SHOST_TO_SAS_HA(pm8001_ha->shost)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1046 | return rc; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * pm8001_pci_probe - probe supported device |
| 1051 | * @pdev: pci device which kernel has been prepared for. |
| 1052 | * @ent: pci device id |
| 1053 | * |
| 1054 | * This function is the main initialization function, when register a new |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 1055 | * pci driver it is invoked, all struct and hardware initialization should be |
| 1056 | * done here, also, register interrupt. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1057 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1058 | static int pm8001_pci_probe(struct pci_dev *pdev, |
| 1059 | const struct pci_device_id *ent) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1060 | { |
| 1061 | unsigned int rc; |
| 1062 | u32 pci_reg; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1063 | u8 i = 0; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1064 | struct pm8001_hba_info *pm8001_ha; |
| 1065 | struct Scsi_Host *shost = NULL; |
| 1066 | const struct pm8001_chip_info *chip; |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1067 | struct sas_ha_struct *sha; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1068 | |
| 1069 | dev_printk(KERN_INFO, &pdev->dev, |
Sakthivel K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 1070 | "pm80xx: driver version %s\n", DRV_VERSION); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1071 | rc = pci_enable_device(pdev); |
| 1072 | if (rc) |
| 1073 | goto err_out_enable; |
| 1074 | pci_set_master(pdev); |
| 1075 | /* |
| 1076 | * Enable pci slot busmaster by setting pci command register. |
| 1077 | * This is required by FW for Cyclone card. |
| 1078 | */ |
| 1079 | |
| 1080 | pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg); |
| 1081 | pci_reg |= 0x157; |
| 1082 | pci_write_config_dword(pdev, PCI_COMMAND, pci_reg); |
| 1083 | rc = pci_request_regions(pdev, DRV_NAME); |
| 1084 | if (rc) |
| 1085 | goto err_out_disable; |
| 1086 | rc = pci_go_44(pdev); |
| 1087 | if (rc) |
| 1088 | goto err_out_regions; |
| 1089 | |
| 1090 | shost = scsi_host_alloc(&pm8001_sht, sizeof(void *)); |
| 1091 | if (!shost) { |
| 1092 | rc = -ENOMEM; |
| 1093 | goto err_out_regions; |
| 1094 | } |
| 1095 | chip = &pm8001_chips[ent->driver_data]; |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1096 | sha = kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL); |
| 1097 | if (!sha) { |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1098 | rc = -ENOMEM; |
| 1099 | goto err_out_free_host; |
| 1100 | } |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1101 | SHOST_TO_SAS_HA(shost) = sha; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1102 | |
| 1103 | rc = pm8001_prep_sas_ha_init(shost, chip); |
| 1104 | if (rc) { |
| 1105 | rc = -ENOMEM; |
| 1106 | goto err_out_free; |
| 1107 | } |
| 1108 | pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost)); |
Sakthivel K | e590adf | 2013-02-27 20:25:25 +0530 | [diff] [blame] | 1109 | /* ent->driver variable is used to differentiate between controllers */ |
| 1110 | pm8001_ha = pm8001_pci_alloc(pdev, ent, shost); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1111 | if (!pm8001_ha) { |
| 1112 | rc = -ENOMEM; |
| 1113 | goto err_out_free; |
| 1114 | } |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1115 | |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 1116 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1117 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
Sakthivel K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 1118 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1119 | pm8001_dbg(pm8001_ha, FAIL, |
| 1120 | "chip_init failed [ret: %d]\n", rc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1121 | goto err_out_ha_free; |
Sakthivel K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 1122 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1123 | |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1124 | rc = pm8001_init_ccb_tag(pm8001_ha, shost, pdev); |
| 1125 | if (rc) |
| 1126 | goto err_out_enable; |
| 1127 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1128 | rc = scsi_add_host(shost, &pdev->dev); |
| 1129 | if (rc) |
| 1130 | goto err_out_ha_free; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1131 | |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1132 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1133 | if (pm8001_ha->chip_id != chip_8001) { |
| 1134 | for (i = 1; i < pm8001_ha->number_of_intr; i++) |
| 1135 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i); |
Sakthivel K | a6cb3d0 | 2013-03-19 18:08:40 +0530 | [diff] [blame] | 1136 | /* setup thermal configuration. */ |
| 1137 | pm80xx_set_thermal_config(pm8001_ha); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1138 | } |
| 1139 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1140 | pm8001_init_sas_add(pm8001_ha); |
Anand Kumar Santhanam | 2790940 | 2013-09-18 13:02:44 +0530 | [diff] [blame] | 1141 | /* phy setting support for motherboard controller */ |
Zhang Qilong | 97031cc | 2020-12-05 19:55:51 +0800 | [diff] [blame] | 1142 | rc = pm8001_configure_phy_settings(pm8001_ha); |
| 1143 | if (rc) |
Benjamin Rood | da2dd61 | 2015-10-30 10:53:24 -0400 | [diff] [blame] | 1144 | goto err_out_shost; |
| 1145 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1146 | pm8001_post_sas_ha_init(shost, chip); |
| 1147 | rc = sas_register_ha(SHOST_TO_SAS_HA(shost)); |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1148 | if (rc) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1149 | pm8001_dbg(pm8001_ha, FAIL, |
| 1150 | "sas_register_ha failed [ret: %d]\n", rc); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1151 | goto err_out_shost; |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1152 | } |
| 1153 | list_add_tail(&pm8001_ha->list, &hba_list); |
Deepak Ukey | cd13575 | 2018-09-11 14:18:02 +0530 | [diff] [blame] | 1154 | pm8001_ha->flags = PM8001F_RUN_TIME; |
Ajish Koshy | d1acd81 | 2021-05-05 17:31:03 +0530 | [diff] [blame] | 1155 | scsi_scan_host(pm8001_ha->shost); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1156 | return 0; |
| 1157 | |
| 1158 | err_out_shost: |
| 1159 | scsi_remove_host(pm8001_ha->shost); |
| 1160 | err_out_ha_free: |
| 1161 | pm8001_free(pm8001_ha); |
| 1162 | err_out_free: |
Peter Chang | b40f288 | 2020-03-16 13:19:04 +0530 | [diff] [blame] | 1163 | kfree(sha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1164 | err_out_free_host: |
Pan Bian | bc1371c | 2017-08-08 19:40:30 +0800 | [diff] [blame] | 1165 | scsi_host_put(shost); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1166 | err_out_regions: |
| 1167 | pci_release_regions(pdev); |
| 1168 | err_out_disable: |
| 1169 | pci_disable_device(pdev); |
| 1170 | err_out_enable: |
| 1171 | return rc; |
| 1172 | } |
| 1173 | |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 1174 | /** |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1175 | * pm8001_init_ccb_tag - allocate memory to CCB and tag. |
| 1176 | * @pm8001_ha: our hba card information. |
| 1177 | * @shost: scsi host which has been allocated outside. |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 1178 | * @pdev: pci device. |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1179 | */ |
| 1180 | static int |
| 1181 | pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost, |
| 1182 | struct pci_dev *pdev) |
| 1183 | { |
| 1184 | int i = 0; |
| 1185 | u32 max_out_io, ccb_count; |
| 1186 | u32 can_queue; |
| 1187 | |
| 1188 | max_out_io = pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io; |
| 1189 | ccb_count = min_t(int, PM8001_MAX_CCB, max_out_io); |
| 1190 | |
| 1191 | /* Update to the scsi host*/ |
| 1192 | can_queue = ccb_count - PM8001_RESERVE_SLOT; |
| 1193 | shost->can_queue = can_queue; |
| 1194 | |
| 1195 | pm8001_ha->tags = kzalloc(ccb_count, GFP_KERNEL); |
| 1196 | if (!pm8001_ha->tags) |
| 1197 | goto err_out; |
| 1198 | |
| 1199 | /* Memory region for ccb_info*/ |
Ajish Koshy | 51e6ed8 | 2021-09-06 22:34:04 +0530 | [diff] [blame] | 1200 | pm8001_ha->ccb_count = ccb_count; |
Xu Wang | 27a3494 | 2020-11-20 08:36:48 +0000 | [diff] [blame] | 1201 | pm8001_ha->ccb_info = |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1202 | kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL); |
| 1203 | if (!pm8001_ha->ccb_info) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1204 | pm8001_dbg(pm8001_ha, FAIL, |
| 1205 | "Unable to allocate memory for ccb\n"); |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1206 | goto err_out_noccb; |
| 1207 | } |
| 1208 | for (i = 0; i < ccb_count; i++) { |
Christophe JAILLET | 8e60a7d | 2021-01-17 14:24:45 +0100 | [diff] [blame] | 1209 | pm8001_ha->ccb_info[i].buf_prd = dma_alloc_coherent(&pdev->dev, |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1210 | sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG, |
Christophe JAILLET | 8e60a7d | 2021-01-17 14:24:45 +0100 | [diff] [blame] | 1211 | &pm8001_ha->ccb_info[i].ccb_dma_handle, |
| 1212 | GFP_KERNEL); |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1213 | if (!pm8001_ha->ccb_info[i].buf_prd) { |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1214 | pm8001_dbg(pm8001_ha, FAIL, |
Christophe JAILLET | 8e60a7d | 2021-01-17 14:24:45 +0100 | [diff] [blame] | 1215 | "ccb prd memory allocation error\n"); |
Viswas G | 5a14131 | 2020-10-05 20:20:10 +0530 | [diff] [blame] | 1216 | goto err_out; |
| 1217 | } |
| 1218 | pm8001_ha->ccb_info[i].task = NULL; |
| 1219 | pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff; |
| 1220 | pm8001_ha->ccb_info[i].device = NULL; |
| 1221 | ++pm8001_ha->tags_num; |
| 1222 | } |
| 1223 | return 0; |
| 1224 | |
| 1225 | err_out_noccb: |
| 1226 | kfree(pm8001_ha->devices); |
| 1227 | err_out: |
| 1228 | return -ENOMEM; |
| 1229 | } |
| 1230 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1231 | static void pm8001_pci_remove(struct pci_dev *pdev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1232 | { |
| 1233 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 1234 | struct pm8001_hba_info *pm8001_ha; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1235 | int i, j; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1236 | pm8001_ha = sha->lldd_ha; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1237 | sas_unregister_ha(sha); |
| 1238 | sas_remove_host(pm8001_ha->shost); |
| 1239 | list_del(&pm8001_ha->list); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1240 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF); |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 1241 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1242 | |
| 1243 | #ifdef PM8001_USE_MSIX |
| 1244 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 1245 | synchronize_irq(pci_irq_vector(pdev, i)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1246 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 1247 | free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]); |
| 1248 | pci_free_irq_vectors(pdev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1249 | #else |
| 1250 | free_irq(pm8001_ha->irq, sha); |
| 1251 | #endif |
| 1252 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1253 | /* For non-msix and msix interrupts */ |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 1254 | if ((!pdev->msix_cap || !pci_msi_enabled()) || |
| 1255 | (pm8001_ha->chip_id == chip_8001)) |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1256 | tasklet_kill(&pm8001_ha->tasklet[0]); |
| 1257 | else |
| 1258 | for (j = 0; j < PM8001_MAX_MSIX_VEC; j++) |
| 1259 | tasklet_kill(&pm8001_ha->tasklet[j]); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1260 | #endif |
Pan Bian | bc1371c | 2017-08-08 19:40:30 +0800 | [diff] [blame] | 1261 | scsi_host_put(pm8001_ha->shost); |
Ajish Koshy | 51e6ed8 | 2021-09-06 22:34:04 +0530 | [diff] [blame] | 1262 | |
| 1263 | for (i = 0; i < pm8001_ha->ccb_count; i++) { |
| 1264 | dma_free_coherent(&pm8001_ha->pdev->dev, |
| 1265 | sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG, |
| 1266 | pm8001_ha->ccb_info[i].buf_prd, |
| 1267 | pm8001_ha->ccb_info[i].ccb_dma_handle); |
| 1268 | } |
| 1269 | kfree(pm8001_ha->ccb_info); |
| 1270 | kfree(pm8001_ha->devices); |
| 1271 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1272 | pm8001_free(pm8001_ha); |
| 1273 | kfree(sha->sas_phy); |
| 1274 | kfree(sha->sas_port); |
| 1275 | kfree(sha); |
| 1276 | pci_release_regions(pdev); |
| 1277 | pci_disable_device(pdev); |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * pm8001_pci_suspend - power management suspend main entry point |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1282 | * @dev: Device struct |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1283 | * |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 1284 | * Return: 0 on success, anything else on error. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1285 | */ |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1286 | static int __maybe_unused pm8001_pci_suspend(struct device *dev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1287 | { |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1288 | struct pci_dev *pdev = to_pci_dev(dev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1289 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1290 | struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1291 | int i, j; |
Bradley Grove | 9f17609 | 2014-07-09 17:20:23 +0530 | [diff] [blame] | 1292 | sas_suspend_ha(sha); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1293 | flush_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1294 | scsi_block_requests(pm8001_ha->shost); |
Yijing Wang | c8a2ba3 | 2013-06-27 15:02:49 +0800 | [diff] [blame] | 1295 | if (!pdev->pm_cap) { |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1296 | dev_err(dev, " PCI PM not supported\n"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1297 | return -ENODEV; |
| 1298 | } |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1299 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF); |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 1300 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1301 | #ifdef PM8001_USE_MSIX |
| 1302 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 1303 | synchronize_irq(pci_irq_vector(pdev, i)); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1304 | for (i = 0; i < pm8001_ha->number_of_intr; i++) |
Christoph Hellwig | a76037f | 2017-02-01 15:11:07 +0100 | [diff] [blame] | 1305 | free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]); |
| 1306 | pci_free_irq_vectors(pdev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1307 | #else |
| 1308 | free_irq(pm8001_ha->irq, sha); |
| 1309 | #endif |
| 1310 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1311 | /* For non-msix and msix interrupts */ |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 1312 | if ((!pdev->msix_cap || !pci_msi_enabled()) || |
| 1313 | (pm8001_ha->chip_id == chip_8001)) |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1314 | tasklet_kill(&pm8001_ha->tasklet[0]); |
| 1315 | else |
| 1316 | for (j = 0; j < PM8001_MAX_MSIX_VEC; j++) |
| 1317 | tasklet_kill(&pm8001_ha->tasklet[j]); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1318 | #endif |
Joe Perches | 2ce6e20 | 2020-11-23 20:36:03 -0800 | [diff] [blame] | 1319 | pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, entering " |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1320 | "suspended state\n", pdev, |
| 1321 | pm8001_ha->name); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * pm8001_pci_resume - power management resume main entry point |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1327 | * @dev: Device struct |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1328 | * |
Randy Dunlap | bb6beab | 2021-07-08 09:57:23 -0700 | [diff] [blame] | 1329 | * Return: 0 on success, anything else on error. |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1330 | */ |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1331 | static int __maybe_unused pm8001_pci_resume(struct device *dev) |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1332 | { |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1333 | struct pci_dev *pdev = to_pci_dev(dev); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1334 | struct sas_ha_struct *sha = pci_get_drvdata(pdev); |
| 1335 | struct pm8001_hba_info *pm8001_ha; |
| 1336 | int rc; |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1337 | u8 i = 0, j; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1338 | u32 device_state; |
Bradley Grove | 9f17609 | 2014-07-09 17:20:23 +0530 | [diff] [blame] | 1339 | DECLARE_COMPLETION_ONSTACK(completion); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1340 | pm8001_ha = sha->lldd_ha; |
| 1341 | device_state = pdev->current_state; |
| 1342 | |
Joe Perches | 2ce6e20 | 2020-11-23 20:36:03 -0800 | [diff] [blame] | 1343 | pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, resuming from previous operating state [D%d]\n", |
Joe Perches | 89eddb4 | 2020-11-20 15:16:10 -0800 | [diff] [blame] | 1344 | pdev, pm8001_ha->name, device_state); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1345 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1346 | rc = pci_go_44(pdev); |
| 1347 | if (rc) |
| 1348 | goto err_out_disable; |
Bradley Grove | 9f17609 | 2014-07-09 17:20:23 +0530 | [diff] [blame] | 1349 | sas_prep_resume_ha(sha); |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 1350 | /* chip soft rst only for spc */ |
| 1351 | if (pm8001_ha->chip_id == chip_8001) { |
| 1352 | PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha); |
Joe Perches | 1b5d279 | 2020-11-20 15:16:09 -0800 | [diff] [blame] | 1353 | pm8001_dbg(pm8001_ha, INIT, "chip soft reset successful\n"); |
Sakthivel K | f586099 | 2013-04-17 16:37:02 +0530 | [diff] [blame] | 1354 | } |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1355 | rc = PM8001_CHIP_DISP->chip_init(pm8001_ha); |
| 1356 | if (rc) |
| 1357 | goto err_out_disable; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1358 | |
| 1359 | /* disable all the interrupt bits */ |
| 1360 | PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF); |
| 1361 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1362 | rc = pm8001_request_irq(pm8001_ha); |
| 1363 | if (rc) |
| 1364 | goto err_out_disable; |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1365 | #ifdef PM8001_USE_TASKLET |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1366 | /* Tasklet for non msi-x interrupt handler */ |
Benjamin Rood | c913df3 | 2015-10-30 10:53:31 -0400 | [diff] [blame] | 1367 | if ((!pdev->msix_cap || !pci_msi_enabled()) || |
| 1368 | (pm8001_ha->chip_id == chip_8001)) |
Nikith Ganigarakoppal | 6cd60b3 | 2013-11-11 15:28:14 +0530 | [diff] [blame] | 1369 | tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet, |
| 1370 | (unsigned long)&(pm8001_ha->irq_vector[0])); |
| 1371 | else |
| 1372 | for (j = 0; j < PM8001_MAX_MSIX_VEC; j++) |
| 1373 | tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet, |
| 1374 | (unsigned long)&(pm8001_ha->irq_vector[j])); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1375 | #endif |
Sakthivel K | f74cf27 | 2013-02-27 20:27:43 +0530 | [diff] [blame] | 1376 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0); |
Sakthivel K | 1245ee5 | 2013-03-19 17:56:17 +0530 | [diff] [blame] | 1377 | if (pm8001_ha->chip_id != chip_8001) { |
| 1378 | for (i = 1; i < pm8001_ha->number_of_intr; i++) |
| 1379 | PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i); |
| 1380 | } |
Benjamin Rood | b650a88 | 2015-11-02 15:42:29 -0500 | [diff] [blame] | 1381 | |
| 1382 | /* Chip documentation for the 8070 and 8072 SPCv */ |
| 1383 | /* states that a 500ms minimum delay is required */ |
Julia Lawall | 014e8ba | 2016-05-17 16:38:44 +0200 | [diff] [blame] | 1384 | /* before issuing commands. Otherwise, the firmware */ |
Benjamin Rood | b650a88 | 2015-11-02 15:42:29 -0500 | [diff] [blame] | 1385 | /* will enter an unrecoverable state. */ |
| 1386 | |
| 1387 | if (pm8001_ha->chip_id == chip_8070 || |
| 1388 | pm8001_ha->chip_id == chip_8072) { |
| 1389 | mdelay(500); |
| 1390 | } |
| 1391 | |
| 1392 | /* Spin up the PHYs */ |
| 1393 | |
Bradley Grove | 9f17609 | 2014-07-09 17:20:23 +0530 | [diff] [blame] | 1394 | pm8001_ha->flags = PM8001F_RUN_TIME; |
| 1395 | for (i = 0; i < pm8001_ha->chip->n_phy; i++) { |
| 1396 | pm8001_ha->phy[i].enable_completion = &completion; |
| 1397 | PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i); |
| 1398 | wait_for_completion(&completion); |
| 1399 | } |
| 1400 | sas_resume_ha(sha); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1401 | return 0; |
| 1402 | |
| 1403 | err_out_disable: |
| 1404 | scsi_remove_host(pm8001_ha->shost); |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1405 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1406 | return rc; |
| 1407 | } |
| 1408 | |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 1409 | /* update of pci device, vendor id and driver data with |
| 1410 | * unique value for each of the controller |
| 1411 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1412 | static struct pci_device_id pm8001_pci_table[] = { |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 1413 | { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 }, |
Suresh Thiagarajan | d8571b1 | 2015-02-12 12:04:37 +0530 | [diff] [blame] | 1414 | { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 }, |
| 1415 | { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 }, |
Bradley Grove | f49d213 | 2013-12-19 10:50:56 -0500 | [diff] [blame] | 1416 | { PCI_VDEVICE(ATTO, 0x0042), chip_8001 }, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 1417 | /* Support for SPC/SPCv/SPCve controllers */ |
| 1418 | { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 }, |
| 1419 | { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 }, |
| 1420 | { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 }, |
| 1421 | { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 }, |
| 1422 | { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 }, |
| 1423 | { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 }, |
| 1424 | { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 }, |
| 1425 | { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 }, |
| 1426 | { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 }, |
Anand Kumar Santhanam | a9a923e | 2013-09-03 15:09:42 +0530 | [diff] [blame] | 1427 | { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 }, |
| 1428 | { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 }, |
| 1429 | { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 }, |
| 1430 | { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 }, |
| 1431 | { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 }, |
| 1432 | { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 }, |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 1433 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 1434 | PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 }, |
| 1435 | { PCI_VENDOR_ID_ADAPTEC2, 0x8081, |
| 1436 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 }, |
| 1437 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 1438 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 }, |
| 1439 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 1440 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 }, |
| 1441 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 1442 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 }, |
| 1443 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 1444 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 }, |
| 1445 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 1446 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 }, |
| 1447 | { PCI_VENDOR_ID_ADAPTEC2, 0x8088, |
| 1448 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 }, |
| 1449 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 1450 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 }, |
| 1451 | { PCI_VENDOR_ID_ADAPTEC2, 0x8089, |
| 1452 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 }, |
Anand Kumar Santhanam | a9a923e | 2013-09-03 15:09:42 +0530 | [diff] [blame] | 1453 | { PCI_VENDOR_ID_ADAPTEC2, 0x8074, |
| 1454 | PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 }, |
| 1455 | { PCI_VENDOR_ID_ADAPTEC2, 0x8076, |
| 1456 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 }, |
| 1457 | { PCI_VENDOR_ID_ADAPTEC2, 0x8077, |
| 1458 | PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 }, |
| 1459 | { PCI_VENDOR_ID_ADAPTEC2, 0x8074, |
| 1460 | PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 }, |
| 1461 | { PCI_VENDOR_ID_ADAPTEC2, 0x8076, |
| 1462 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 }, |
| 1463 | { PCI_VENDOR_ID_ADAPTEC2, 0x8077, |
| 1464 | PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 }, |
| 1465 | { PCI_VENDOR_ID_ADAPTEC2, 0x8076, |
| 1466 | PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 }, |
| 1467 | { PCI_VENDOR_ID_ADAPTEC2, 0x8077, |
| 1468 | PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 }, |
| 1469 | { PCI_VENDOR_ID_ADAPTEC2, 0x8074, |
| 1470 | PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 }, |
Benjamin Rood | b2dece4 | 2015-10-30 10:53:26 -0400 | [diff] [blame] | 1471 | { PCI_VENDOR_ID_ATTO, 0x8070, |
| 1472 | PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 }, |
| 1473 | { PCI_VENDOR_ID_ATTO, 0x8070, |
| 1474 | PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 }, |
| 1475 | { PCI_VENDOR_ID_ATTO, 0x8072, |
| 1476 | PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 }, |
| 1477 | { PCI_VENDOR_ID_ATTO, 0x8072, |
| 1478 | PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 }, |
| 1479 | { PCI_VENDOR_ID_ATTO, 0x8070, |
| 1480 | PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 }, |
| 1481 | { PCI_VENDOR_ID_ATTO, 0x8072, |
| 1482 | PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 }, |
| 1483 | { PCI_VENDOR_ID_ATTO, 0x8072, |
| 1484 | PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 }, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1485 | {} /* terminate list */ |
| 1486 | }; |
| 1487 | |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1488 | static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops, |
| 1489 | pm8001_pci_suspend, |
| 1490 | pm8001_pci_resume); |
| 1491 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1492 | static struct pci_driver pm8001_pci_driver = { |
| 1493 | .name = DRV_NAME, |
| 1494 | .id_table = pm8001_pci_table, |
| 1495 | .probe = pm8001_pci_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1496 | .remove = pm8001_pci_remove, |
Vaibhav Gupta | 47c37c4 | 2020-11-02 22:17:20 +0530 | [diff] [blame] | 1497 | .driver.pm = &pm8001_pci_pm_ops, |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1498 | }; |
| 1499 | |
| 1500 | /** |
| 1501 | * pm8001_init - initialize scsi transport template |
| 1502 | */ |
| 1503 | static int __init pm8001_init(void) |
| 1504 | { |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1505 | int rc = -ENOMEM; |
| 1506 | |
Sakthivel K | a70b8fc | 2013-03-19 18:07:09 +0530 | [diff] [blame] | 1507 | pm8001_wq = alloc_workqueue("pm80xx", 0, 0); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1508 | if (!pm8001_wq) |
| 1509 | goto err; |
| 1510 | |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1511 | pm8001_id = 0; |
| 1512 | pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops); |
| 1513 | if (!pm8001_stt) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1514 | goto err_wq; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1515 | rc = pci_register_driver(&pm8001_pci_driver); |
| 1516 | if (rc) |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1517 | goto err_tp; |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1518 | return 0; |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1519 | |
| 1520 | err_tp: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1521 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1522 | err_wq: |
| 1523 | destroy_workqueue(pm8001_wq); |
| 1524 | err: |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1525 | return rc; |
| 1526 | } |
| 1527 | |
| 1528 | static void __exit pm8001_exit(void) |
| 1529 | { |
| 1530 | pci_unregister_driver(&pm8001_pci_driver); |
| 1531 | sas_release_transport(pm8001_stt); |
Tejun Heo | 429305e | 2011-01-24 14:57:29 +0100 | [diff] [blame] | 1532 | destroy_workqueue(pm8001_wq); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | module_init(pm8001_init); |
| 1536 | module_exit(pm8001_exit); |
| 1537 | |
| 1538 | MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>"); |
Anand Kumar Santhanam | a9a923e | 2013-09-03 15:09:42 +0530 | [diff] [blame] | 1539 | MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>"); |
| 1540 | MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>"); |
Nikith Ganigarakoppal | 94f33c1 | 2013-11-13 15:35:23 +0530 | [diff] [blame] | 1541 | MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>"); |
Sakthivel K | e574210 | 2013-04-17 16:26:36 +0530 | [diff] [blame] | 1542 | MODULE_DESCRIPTION( |
Benjamin Rood | db9d403 | 2015-10-30 10:53:25 -0400 | [diff] [blame] | 1543 | "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 " |
Anand Kumar Santhanam | a9a923e | 2013-09-03 15:09:42 +0530 | [diff] [blame] | 1544 | "SAS/SATA controller driver"); |
jack wang | dbf9bfe | 2009-10-14 16:19:21 +0800 | [diff] [blame] | 1545 | MODULE_VERSION(DRV_VERSION); |
| 1546 | MODULE_LICENSE("GPL"); |
| 1547 | MODULE_DEVICE_TABLE(pci, pm8001_pci_table); |
| 1548 | |