blob: 613455a3e686d88b1ca54aedf121a284699e7fb4 [file] [log] [blame]
jack wangdbf9bfe2009-10-14 16:19:21 +08001/*
Sakthivel Ke5742102013-04-17 16:26:36 +05302 * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver
jack wangdbf9bfe2009-10-14 16:19:21 +08003 *
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 Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
jack wangdbf9bfe2009-10-14 16:19:21 +080042#include "pm8001_sas.h"
43#include "pm8001_chips.h"
peter chang3e253d92019-11-14 15:39:07 +053044#include "pm80xx_hwi.h"
jack wangdbf9bfe2009-10-14 16:19:21 +080045
peter chang73706722019-11-14 15:39:02 +053046static ulong logging_level = PM8001_FAIL_LOGGING | PM8001_IOERR_LOGGING;
47module_param(logging_level, ulong, 0644);
48MODULE_PARM_DESC(logging_level, " bits for enabling logging info.");
49
peter chang3e253d92019-11-14 15:39:07 +053050static ulong link_rate = LINKRATE_15 | LINKRATE_30 | LINKRATE_60 | LINKRATE_120;
51module_param(link_rate, ulong, 0644);
52MODULE_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 wangdbf9bfe2009-10-14 16:19:21 +080058static struct scsi_transport_template *pm8001_stt;
Viswas G5a141312020-10-05 20:20:10 +053059static int pm8001_init_ccb_tag(struct pm8001_hba_info *, struct Scsi_Host *, struct pci_dev *);
jack wangdbf9bfe2009-10-14 16:19:21 +080060
Lee Jonese802fc42020-07-13 08:46:42 +010061/*
Sakthivel Ke5742102013-04-17 16:26:36 +053062 * chip info structure to identify chip key functionality as
63 * encryption available/not, no of ports, hw specific function ref
64 */
jack wangdbf9bfe2009-10-14 16:19:21 +080065static const struct pm8001_chip_info pm8001_chips[] = {
Sakthivel Ke5742102013-04-17 16:26:36 +053066 [chip_8001] = {0, 8, &pm8001_8001_dispatch,},
Sakthivel Kf5860992013-04-17 16:37:02 +053067 [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 Santhanama9a923e2013-09-03 15:09:42 +053071 [chip_8074] = {0, 8, &pm8001_80xx_dispatch,},
72 [chip_8076] = {0, 16, &pm8001_80xx_dispatch,},
73 [chip_8077] = {0, 16, &pm8001_80xx_dispatch,},
Suresh Thiagarajand8571b12015-02-12 12:04:37 +053074 [chip_8006] = {0, 16, &pm8001_80xx_dispatch,},
Benjamin Rooddb9d4032015-10-30 10:53:25 -040075 [chip_8070] = {0, 8, &pm8001_80xx_dispatch,},
76 [chip_8072] = {0, 16, &pm8001_80xx_dispatch,},
jack wangdbf9bfe2009-10-14 16:19:21 +080077};
78static int pm8001_id;
79
80LIST_HEAD(hba_list);
81
Tejun Heo429305e2011-01-24 14:57:29 +010082struct workqueue_struct *pm8001_wq;
83
Lee Jonese802fc42020-07-13 08:46:42 +010084/*
jack wangdbf9bfe2009-10-14 16:19:21 +080085 * The main structure which LLDD must register for scsi core.
86 */
87static struct scsi_host_template pm8001_sht = {
88 .module = THIS_MODULE,
89 .name = DRV_NAME,
90 .queuecommand = sas_queuecommand,
Christoph Hellwigb8f1d1e2020-06-15 08:46:24 +020091 .dma_need_drain = ata_scsi_dma_need_drain,
jack wangdbf9bfe2009-10-14 16:19:21 +080092 .target_alloc = sas_target_alloc,
Dan Williams11e16362011-09-20 15:11:03 -070093 .slave_configure = sas_slave_configure,
jack wangdbf9bfe2009-10-14 16:19:21 +080094 .scan_finished = pm8001_scan_finished,
95 .scan_start = pm8001_scan_start,
96 .change_queue_depth = sas_change_queue_depth,
jack wangdbf9bfe2009-10-14 16:19:21 +080097 .bios_param = sas_bios_param,
98 .can_queue = 1,
jack wangdbf9bfe2009-10-14 16:19:21 +080099 .this_id = -1,
Peter Chang58bf14c2020-03-16 13:19:01 +0530100 .sg_tablesize = PM8001_MAX_DMA_SG,
jack wangdbf9bfe2009-10-14 16:19:21 +0800101 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
jack wangdbf9bfe2009-10-14 16:19:21 +0800102 .eh_device_reset_handler = sas_eh_device_reset_handler,
Hannes Reineckecc199e72017-08-25 13:57:02 +0200103 .eh_target_reset_handler = sas_eh_target_reset_handler,
Yufen Yu49da96d2021-06-22 11:40:37 +0800104 .slave_alloc = sas_slave_alloc,
jack wangdbf9bfe2009-10-14 16:19:21 +0800105 .target_destroy = sas_target_destroy,
106 .ioctl = sas_ioctl,
Arnd Bergmann75c0b0e2019-11-30 20:28:12 +0100107#ifdef CONFIG_COMPAT
108 .compat_ioctl = sas_ioctl,
109#endif
jack wangdbf9bfe2009-10-14 16:19:21 +0800110 .shost_attrs = pm8001_host_attrs,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100111 .track_queue_depth = 1,
jack wangdbf9bfe2009-10-14 16:19:21 +0800112};
113
Lee Jonese802fc42020-07-13 08:46:42 +0100114/*
jack wangdbf9bfe2009-10-14 16:19:21 +0800115 * Sas layer call this function to execute specific task.
116 */
117static 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 Koshy08d0a992021-09-06 22:34:01 +0530131 .lldd_port_formed = pm8001_port_formed,
jack wangdbf9bfe2009-10-14 16:19:21 +0800132};
133
134/**
Lee Jonese802fc42020-07-13 08:46:42 +0100135 * pm8001_phy_init - initiate our adapter phys
136 * @pm8001_ha: our hba structure.
137 * @phy_id: phy id.
jack wangdbf9bfe2009-10-14 16:19:21 +0800138 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800139static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +0800140{
141 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
142 struct asd_sas_phy *sas_phy = &phy->sas_phy;
Deepak Ukeycd135752018-09-11 14:18:02 +0530143 phy->phy_state = PHY_LINK_DISABLE;
jack wangdbf9bfe2009-10-14 16:19:21 +0800144 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 G6c85e4b2017-10-18 11:39:09 +0530154 sas_phy->sas_addr = (u8 *)&phy->dev_sas_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800155 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 Jonese802fc42020-07-13 08:46:42 +0100161 * pm8001_free - free hba
162 * @pm8001_ha: our hba structure.
jack wangdbf9bfe2009-10-14 16:19:21 +0800163 */
164static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
165{
166 int i;
jack wangdbf9bfe2009-10-14 16:19:21 +0800167
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 Hellwigf73bdeb2018-10-10 19:59:50 +0200173 dma_free_coherent(&pm8001_ha->pdev->dev,
Sakthivel Kbfb48092013-02-04 12:10:02 +0530174 (pm8001_ha->memoryMap.region[i].total_len +
175 pm8001_ha->memoryMap.region[i].alignment),
jack wangdbf9bfe2009-10-14 16:19:21 +0800176 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 Heo429305e2011-01-24 14:57:29 +0100181 flush_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +0800182 kfree(pm8001_ha->tags);
183 kfree(pm8001_ha);
184}
185
186#ifdef PM8001_USE_TASKLET
Sakthivel K1245ee52013-03-19 17:56:17 +0530187
188/**
Lee Jonesbd1050e2021-03-03 14:46:09 +0000189 * pm8001_tasklet() - tasklet for 64 msi-x interrupt handler
Sakthivel K1245ee52013-03-19 17:56:17 +0530190 * @opaque: the passed general host adapter struct
191 * Note: pm8001_tasklet is common for pm8001 & pm80xx
192 */
jack wangdbf9bfe2009-10-14 16:19:21 +0800193static void pm8001_tasklet(unsigned long opaque)
194{
195 struct pm8001_hba_info *pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530196 struct isr_param *irq_vector;
197
198 irq_vector = (struct isr_param *)opaque;
199 pm8001_ha = irq_vector->drv_inst;
jack wangdbf9bfe2009-10-14 16:19:21 +0800200 if (unlikely(!pm8001_ha))
201 BUG_ON(1);
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530202 PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
jack wangdbf9bfe2009-10-14 16:19:21 +0800203}
204#endif
205
Sakthivel K1245ee52013-03-19 17:56:17 +0530206/**
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 Jonese802fc42020-07-13 08:46:42 +0100210 * @irq: interrupt number
Sakthivel K1245ee52013-03-19 17:56:17 +0530211 * @opaque: the passed outbound queue/vector. Host structure is
212 * retrieved from the same.
213 */
214static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
215{
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530216 struct isr_param *irq_vector;
217 struct pm8001_hba_info *pm8001_ha;
Sakthivel K1245ee52013-03-19 17:56:17 +0530218 irqreturn_t ret = IRQ_HANDLED;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530219 irq_vector = (struct isr_param *)opaque;
220 pm8001_ha = irq_vector->drv_inst;
221
Sakthivel K1245ee52013-03-19 17:56:17 +0530222 if (unlikely(!pm8001_ha))
223 return IRQ_NONE;
Colin Ian Kingf310a4e2019-03-29 23:44:23 +0000224 if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
Sakthivel K1245ee52013-03-19 17:56:17 +0530225 return IRQ_NONE;
Sakthivel K1245ee52013-03-19 17:56:17 +0530226#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530227 tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
Sakthivel K1245ee52013-03-19 17:56:17 +0530228#else
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530229 ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
Sakthivel K1245ee52013-03-19 17:56:17 +0530230#endif
231 return ret;
232}
233
234/**
235 * pm8001_interrupt_handler_intx - main INTx interrupt handler.
Lee Jonese802fc42020-07-13 08:46:42 +0100236 * @irq: interrupt number
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700237 * @dev_id: sas_ha structure. The HBA is retrieved from sas_ha structure.
Sakthivel K1245ee52013-03-19 17:56:17 +0530238 */
239
240static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id)
jack wangdbf9bfe2009-10-14 16:19:21 +0800241{
242 struct pm8001_hba_info *pm8001_ha;
243 irqreturn_t ret = IRQ_HANDLED;
Sakthivel K1245ee52013-03-19 17:56:17 +0530244 struct sas_ha_struct *sha = dev_id;
jack wangdbf9bfe2009-10-14 16:19:21 +0800245 pm8001_ha = sha->lldd_ha;
246 if (unlikely(!pm8001_ha))
247 return IRQ_NONE;
Colin Ian Kingf310a4e2019-03-29 23:44:23 +0000248 if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
jack wangdbf9bfe2009-10-14 16:19:21 +0800249 return IRQ_NONE;
Sakthivel K1245ee52013-03-19 17:56:17 +0530250
jack wangdbf9bfe2009-10-14 16:19:21 +0800251#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530252 tasklet_schedule(&pm8001_ha->tasklet[0]);
jack wangdbf9bfe2009-10-14 16:19:21 +0800253#else
Sakthivel Kf74cf272013-02-27 20:27:43 +0530254 ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800255#endif
256 return ret;
257}
258
Vikram Auradkard384be62020-03-16 13:19:02 +0530259static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha);
260static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha);
261
jack wangdbf9bfe2009-10-14 16:19:21 +0800262/**
263 * pm8001_alloc - initiate our hba structure and 6 DMAs area.
Lee Jonese802fc42020-07-13 08:46:42 +0100264 * @pm8001_ha: our hba structure.
265 * @ent: PCI device ID structure to match on
jack wangdbf9bfe2009-10-14 16:19:21 +0800266 */
Sakthivel Ke590adf2013-02-27 20:25:25 +0530267static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
268 const struct pci_device_id *ent)
jack wangdbf9bfe2009-10-14 16:19:21 +0800269{
Viswas G05c6c022020-10-05 20:20:08 +0530270 int i, count = 0, rc = 0;
271 u32 ci_offset, ib_offset, ob_offset, pi_offset;
Viswas G1f02bef2021-04-15 16:03:52 +0530272 struct inbound_queue_table *ibq;
273 struct outbound_queue_table *obq;
Viswas G05c6c022020-10-05 20:20:08 +0530274
jack wangdbf9bfe2009-10-14 16:19:21 +0800275 spin_lock_init(&pm8001_ha->lock);
Tomas Henzl646cdf02014-07-09 17:21:01 +0530276 spin_lock_init(&pm8001_ha->bitmap_lock);
Joe Perches1b5d2792020-11-20 15:16:09 -0800277 pm8001_dbg(pm8001_ha, INIT, "pm8001_alloc: PHY:%x\n",
278 pm8001_ha->chip->n_phy);
Viswas G05c6c022020-10-05 20:20:08 +0530279
280 /* Setup Interrupt */
281 rc = pm8001_setup_irq(pm8001_ha);
282 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800283 pm8001_dbg(pm8001_ha, FAIL,
284 "pm8001_setup_irq failed [ret: %d]\n", rc);
Viswas G05c6c022020-10-05 20:20:08 +0530285 goto err_out_shost;
286 }
287 /* Request Interrupt */
288 rc = pm8001_request_irq(pm8001_ha);
289 if (rc)
290 goto err_out_shost;
291
292 count = pm8001_ha->max_q_num;
293 /* Queues are chosen based on the number of cores/msix availability */
Viswas G27bc43b2020-10-05 20:20:09 +0530294 ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE;
Viswas G05c6c022020-10-05 20:20:08 +0530295 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 wang1cc943a2009-12-07 17:22:42 +0800300 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800301 pm8001_phy_init(pm8001_ha, i);
jack wang1cc943a2009-12-07 17:22:42 +0800302 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 wangdbf9bfe2009-10-14 16:19:21 +0800307
jack wangdbf9bfe2009-10-14 16:19:21 +0800308 /* 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 G05c6c022020-10-05 20:20:08 +0530320 for (i = 0; i < count; i++) {
Viswas G1f02bef2021-04-15 16:03:52 +0530321 ibq = &pm8001_ha->inbnd_q_tbl[i];
322 spin_lock_init(&ibq->iq_lock);
Sakthivel Ke590adf2013-02-27 20:25:25 +0530323 /* MPI Memory region 3 for consumer Index of inbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530324 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 wangdbf9bfe2009-10-14 16:19:21 +0800328
Sakthivel Ke590adf2013-02-27 20:25:25 +0530329 if ((ent->driver_data) != chip_8001) {
330 /* MPI Memory region 5 inbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530331 pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530332 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530333 pm8001_ha->memoryMap.region[ib_offset+i].element_size
334 = 128;
335 pm8001_ha->memoryMap.region[ib_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530336 PM8001_MPI_QUEUE * 128;
Viswas G05c6c022020-10-05 20:20:08 +0530337 pm8001_ha->memoryMap.region[ib_offset+i].alignment
338 = 128;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530339 } else {
Viswas G05c6c022020-10-05 20:20:08 +0530340 pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530341 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530342 pm8001_ha->memoryMap.region[ib_offset+i].element_size
343 = 64;
344 pm8001_ha->memoryMap.region[ib_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530345 PM8001_MPI_QUEUE * 64;
Viswas G05c6c022020-10-05 20:20:08 +0530346 pm8001_ha->memoryMap.region[ib_offset+i].alignment = 64;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530347 }
348 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800349
Viswas G05c6c022020-10-05 20:20:08 +0530350 for (i = 0; i < count; i++) {
Viswas G1f02bef2021-04-15 16:03:52 +0530351 obq = &pm8001_ha->outbnd_q_tbl[i];
352 spin_lock_init(&obq->oq_lock);
Sakthivel Ke590adf2013-02-27 20:25:25 +0530353 /* MPI Memory region 4 for producer Index of outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530354 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 wangdbf9bfe2009-10-14 16:19:21 +0800358
Sakthivel Ke590adf2013-02-27 20:25:25 +0530359 if (ent->driver_data != chip_8001) {
360 /* MPI Memory region 6 Outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530361 pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530362 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530363 pm8001_ha->memoryMap.region[ob_offset+i].element_size
364 = 128;
365 pm8001_ha->memoryMap.region[ob_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530366 PM8001_MPI_QUEUE * 128;
Viswas G05c6c022020-10-05 20:20:08 +0530367 pm8001_ha->memoryMap.region[ob_offset+i].alignment
368 = 128;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530369 } else {
370 /* MPI Memory region 6 Outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530371 pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530372 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530373 pm8001_ha->memoryMap.region[ob_offset+i].element_size
374 = 64;
375 pm8001_ha->memoryMap.region[ob_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530376 PM8001_MPI_QUEUE * 64;
Viswas G05c6c022020-10-05 20:20:08 +0530377 pm8001_ha->memoryMap.region[ob_offset+i].alignment = 64;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530378 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800379
Sakthivel Ke590adf2013-02-27 20:25:25 +0530380 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800381 /* 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 wangdbf9bfe2009-10-14 16:19:21 +0800385
Sakthivel K1c75a672013-03-19 18:06:40 +0530386 /* Memory region for fw flash */
387 pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
388
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530389 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 G05c6c022020-10-05 20:20:08 +0530393 for (i = 0; i < pm8001_ha->max_memcnt; i++) {
Joe Perches9aed5782020-11-23 20:36:04 -0800394 struct mpi_mem *region = &pm8001_ha->memoryMap.region[i];
395
jack wangdbf9bfe2009-10-14 16:19:21 +0800396 if (pm8001_mem_alloc(pm8001_ha->pdev,
Joe Perches9aed5782020-11-23 20:36:04 -0800397 &region->virt_ptr,
398 &region->phys_addr,
399 &region->phys_addr_hi,
400 &region->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 wangdbf9bfe2009-10-14 16:19:21 +0800405 }
406 }
407
Viswas G27bc43b2020-10-05 20:20:09 +0530408 /* 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 wangdbf9bfe2009-10-14 16:19:21 +0800415 for (i = 0; i < PM8001_MAX_DEVICES; i++) {
James Bottomleyaa9f8322013-05-07 14:44:06 -0700416 pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
jack wangdbf9bfe2009-10-14 16:19:21 +0800417 pm8001_ha->devices[i].id = i;
418 pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
Viswas G4a2efd42020-11-02 22:25:26 +0530419 atomic_set(&pm8001_ha->devices[i].running_req, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800420 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800421 pm8001_ha->flags = PM8001F_INIT_TIME;
422 /* Initialize tags */
423 pm8001_tag_init(pm8001_ha);
424 return 0;
Viswas G27bc43b2020-10-05 20:20:09 +0530425
Viswas G05c6c022020-10-05 20:20:08 +0530426err_out_shost:
427 scsi_remove_host(pm8001_ha->shost);
Viswas G27bc43b2020-10-05 20:20:09 +0530428err_out_nodev:
429 for (i = 0; i < pm8001_ha->max_memcnt; i++) {
430 if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
Christophe JAILLET8e60a7d2021-01-17 14:24:45 +0100431 dma_free_coherent(&pm8001_ha->pdev->dev,
Viswas G27bc43b2020-10-05 20:20:09 +0530432 (pm8001_ha->memoryMap.region[i].total_len +
433 pm8001_ha->memoryMap.region[i].alignment),
434 pm8001_ha->memoryMap.region[i].virt_ptr,
435 pm8001_ha->memoryMap.region[i].phys_addr);
436 }
437 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800438err_out:
439 return 1;
440}
441
442/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700443 * pm8001_ioremap - remap the pci high physical address to kernel virtual
jack wangdbf9bfe2009-10-14 16:19:21 +0800444 * address so that we can access them.
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700445 * @pm8001_ha: our hba structure.
jack wangdbf9bfe2009-10-14 16:19:21 +0800446 */
447static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
448{
449 u32 bar;
450 u32 logicalBar = 0;
451 struct pci_dev *pdev;
452
453 pdev = pm8001_ha->pdev;
454 /* map pci mem (PMC pci base 0-3)*/
Denis Efremovc9c13ba2019-09-28 02:43:08 +0300455 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800456 /*
457 ** logical BARs for SPC:
458 ** bar 0 and 1 - logical BAR0
459 ** bar 2 and 3 - logical BAR1
460 ** bar4 - logical BAR2
461 ** bar5 - logical BAR3
462 ** Skip the appropriate assignments:
463 */
464 if ((bar == 1) || (bar == 3))
465 continue;
466 if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
467 pm8001_ha->io_mem[logicalBar].membase =
468 pci_resource_start(pdev, bar);
jack wangdbf9bfe2009-10-14 16:19:21 +0800469 pm8001_ha->io_mem[logicalBar].memsize =
470 pci_resource_len(pdev, bar);
471 pm8001_ha->io_mem[logicalBar].memvirtaddr =
472 ioremap(pm8001_ha->io_mem[logicalBar].membase,
473 pm8001_ha->io_mem[logicalBar].memsize);
akshatzen95652f92021-01-09 18:08:44 +0530474 if (!pm8001_ha->io_mem[logicalBar].memvirtaddr) {
475 pm8001_dbg(pm8001_ha, INIT,
476 "Failed to ioremap bar %d, logicalBar %d",
Joe Perches1b5d2792020-11-20 15:16:09 -0800477 bar, logicalBar);
akshatzen95652f92021-01-09 18:08:44 +0530478 return -ENOMEM;
479 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800480 pm8001_dbg(pm8001_ha, INIT,
481 "base addr %llx virt_addr=%llx len=%d\n",
482 (u64)pm8001_ha->io_mem[logicalBar].membase,
483 (u64)(unsigned long)
484 pm8001_ha->io_mem[logicalBar].memvirtaddr,
485 pm8001_ha->io_mem[logicalBar].memsize);
jack wangdbf9bfe2009-10-14 16:19:21 +0800486 } else {
487 pm8001_ha->io_mem[logicalBar].membase = 0;
488 pm8001_ha->io_mem[logicalBar].memsize = 0;
Saurav Girepunje62fb8b32019-10-25 19:20:14 +0530489 pm8001_ha->io_mem[logicalBar].memvirtaddr = NULL;
jack wangdbf9bfe2009-10-14 16:19:21 +0800490 }
491 logicalBar++;
492 }
493 return 0;
494}
495
496/**
497 * pm8001_pci_alloc - initialize our ha card structure
498 * @pdev: pci device.
499 * @ent: ent
500 * @shost: scsi host struct which has been initialized before.
501 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800502static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
Sakthivel Ke590adf2013-02-27 20:25:25 +0530503 const struct pci_device_id *ent,
504 struct Scsi_Host *shost)
505
jack wangdbf9bfe2009-10-14 16:19:21 +0800506{
507 struct pm8001_hba_info *pm8001_ha;
508 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530509 int j;
jack wangdbf9bfe2009-10-14 16:19:21 +0800510
511 pm8001_ha = sha->lldd_ha;
512 if (!pm8001_ha)
513 return NULL;
514
515 pm8001_ha->pdev = pdev;
516 pm8001_ha->dev = &pdev->dev;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530517 pm8001_ha->chip_id = ent->driver_data;
jack wangdbf9bfe2009-10-14 16:19:21 +0800518 pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
519 pm8001_ha->irq = pdev->irq;
520 pm8001_ha->sas = sha;
521 pm8001_ha->shost = shost;
522 pm8001_ha->id = pm8001_id++;
peter chang73706722019-11-14 15:39:02 +0530523 pm8001_ha->logging_level = logging_level;
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530524 pm8001_ha->non_fatal_count = 0;
peter chang3e253d92019-11-14 15:39:07 +0530525 if (link_rate >= 1 && link_rate <= 15)
526 pm8001_ha->link_rate = (link_rate << 8);
527 else {
528 pm8001_ha->link_rate = LINKRATE_15 | LINKRATE_30 |
529 LINKRATE_60 | LINKRATE_120;
Joe Perches1b5d2792020-11-20 15:16:09 -0800530 pm8001_dbg(pm8001_ha, FAIL,
531 "Setting link rate to default value\n");
peter chang3e253d92019-11-14 15:39:07 +0530532 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800533 sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
Sakthivel Kf74cf272013-02-27 20:27:43 +0530534 /* IOMB size is 128 for 8088/89 controllers */
535 if (pm8001_ha->chip_id != chip_8001)
536 pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
537 else
538 pm8001_ha->iomb_size = IOMB_SIZE_SPC;
539
jack wangdbf9bfe2009-10-14 16:19:21 +0800540#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530541 /* Tasklet for non msi-x interrupt handler */
Benjamin Roodc913df32015-10-30 10:53:31 -0400542 if ((!pdev->msix_cap || !pci_msi_enabled())
543 || (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530544 tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
545 (unsigned long)&(pm8001_ha->irq_vector[0]));
546 else
547 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
548 tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
549 (unsigned long)&(pm8001_ha->irq_vector[j]));
jack wangdbf9bfe2009-10-14 16:19:21 +0800550#endif
akshatzen95652f92021-01-09 18:08:44 +0530551 if (pm8001_ioremap(pm8001_ha))
552 goto failed_pci_alloc;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530553 if (!pm8001_alloc(pm8001_ha, ent))
jack wangdbf9bfe2009-10-14 16:19:21 +0800554 return pm8001_ha;
akshatzen95652f92021-01-09 18:08:44 +0530555failed_pci_alloc:
jack wangdbf9bfe2009-10-14 16:19:21 +0800556 pm8001_free(pm8001_ha);
557 return NULL;
558}
559
560/**
561 * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
562 * @pdev: pci device.
563 */
564static int pci_go_44(struct pci_dev *pdev)
565{
566 int rc;
567
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +0200568 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
569 if (rc) {
570 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
571 if (rc)
jack wangdbf9bfe2009-10-14 16:19:21 +0800572 dev_printk(KERN_ERR, &pdev->dev,
573 "32-bit DMA enable failed\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800574 }
575 return rc;
576}
577
578/**
579 * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
580 * @shost: scsi host which has been allocated outside.
581 * @chip_info: our ha struct.
582 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800583static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
584 const struct pm8001_chip_info *chip_info)
jack wangdbf9bfe2009-10-14 16:19:21 +0800585{
586 int phy_nr, port_nr;
587 struct asd_sas_phy **arr_phy;
588 struct asd_sas_port **arr_port;
589 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
590
591 phy_nr = chip_info->n_phy;
592 port_nr = phy_nr;
593 memset(sha, 0x00, sizeof(*sha));
594 arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
595 if (!arr_phy)
596 goto exit;
597 arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
598 if (!arr_port)
599 goto exit_free2;
600
601 sha->sas_phy = arr_phy;
602 sha->sas_port = arr_port;
603 sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
604 if (!sha->lldd_ha)
605 goto exit_free1;
606
607 shost->transportt = pm8001_stt;
608 shost->max_id = PM8001_MAX_DEVICES;
609 shost->max_lun = 8;
610 shost->max_channel = 0;
611 shost->unique_id = pm8001_id;
612 shost->max_cmd_len = 16;
613 shost->can_queue = PM8001_CAN_QUEUE;
614 shost->cmd_per_lun = 32;
615 return 0;
616exit_free1:
617 kfree(arr_port);
618exit_free2:
619 kfree(arr_phy);
620exit:
621 return -1;
622}
623
624/**
625 * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
626 * @shost: scsi host which has been allocated outside
627 * @chip_info: our ha struct.
628 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800629static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
630 const struct pm8001_chip_info *chip_info)
jack wangdbf9bfe2009-10-14 16:19:21 +0800631{
632 int i = 0;
633 struct pm8001_hba_info *pm8001_ha;
634 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
635
636 pm8001_ha = sha->lldd_ha;
637 for (i = 0; i < chip_info->n_phy; i++) {
638 sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
639 sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
Viswas G6c85e4b2017-10-18 11:39:09 +0530640 sha->sas_phy[i]->sas_addr =
641 (u8 *)&pm8001_ha->phy[i].dev_sas_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800642 }
643 sha->sas_ha_name = DRV_NAME;
644 sha->dev = pm8001_ha->dev;
Viswas G6c85e4b2017-10-18 11:39:09 +0530645 sha->strict_wide_ports = 1;
jack wangdbf9bfe2009-10-14 16:19:21 +0800646 sha->lldd_module = THIS_MODULE;
647 sha->sas_addr = &pm8001_ha->sas_addr[0];
648 sha->num_phys = chip_info->n_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +0800649 sha->core.shost = shost;
650}
651
652/**
653 * pm8001_init_sas_add - initialize sas address
Lee Jonese802fc42020-07-13 08:46:42 +0100654 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +0800655 *
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700656 * Currently we just set the fixed SAS address to our HBA, for manufacture,
jack wangdbf9bfe2009-10-14 16:19:21 +0800657 * it should read from the EEPROM
658 */
659static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
660{
Sakthivel Ka33a0152013-03-19 18:07:35 +0530661 u8 i, j;
Viswas G6c85e4b2017-10-18 11:39:09 +0530662 u8 sas_add[8];
jack wangdbf9bfe2009-10-14 16:19:21 +0800663#ifdef PM8001_READ_VPD
Sakthivel Ka33a0152013-03-19 18:07:35 +0530664 /* For new SPC controllers WWN is stored in flash vpd
665 * For SPC/SPCve controllers WWN is stored in EEPROM
666 * For Older SPC WWN is stored in NVMD
667 */
jack wangdbf9bfe2009-10-14 16:19:21 +0800668 DECLARE_COMPLETION_ONSTACK(completion);
jack wang7c8356d2009-12-07 17:23:08 +0800669 struct pm8001_ioctl_payload payload;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530670 u16 deviceid;
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530671 int rc;
672
Sakthivel Ka33a0152013-03-19 18:07:35 +0530673 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
jack wangdbf9bfe2009-10-14 16:19:21 +0800674 pm8001_ha->nvmd_completion = &completion;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530675
676 if (pm8001_ha->chip_id == chip_8001) {
Bradley Grovef49d2132013-12-19 10:50:56 -0500677 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel Ka33a0152013-03-19 18:07:35 +0530678 payload.minor_function = 4;
Viswas G9b889842020-03-16 13:19:06 +0530679 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530680 } else {
681 payload.minor_function = 0;
Viswas G9b889842020-03-16 13:19:06 +0530682 payload.rd_length = 128;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530683 }
Benjamin Rood10efa462015-11-02 15:39:23 -0500684 } else if ((pm8001_ha->chip_id == chip_8070 ||
685 pm8001_ha->chip_id == chip_8072) &&
686 pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
687 payload.minor_function = 4;
Viswas G9b889842020-03-16 13:19:06 +0530688 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530689 } else {
690 payload.minor_function = 1;
Viswas G9b889842020-03-16 13:19:06 +0530691 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530692 }
693 payload.offset = 0;
Viswas G9b889842020-03-16 13:19:06 +0530694 payload.func_specific = kzalloc(payload.rd_length, GFP_KERNEL);
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530695 if (!payload.func_specific) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800696 pm8001_dbg(pm8001_ha, INIT, "mem alloc fail\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530697 return;
698 }
699 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
700 if (rc) {
701 kfree(payload.func_specific);
Joe Perches1b5d2792020-11-20 15:16:09 -0800702 pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530703 return;
704 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800705 wait_for_completion(&completion);
Sakthivel Ka33a0152013-03-19 18:07:35 +0530706
707 for (i = 0, j = 0; i <= 7; i++, j++) {
708 if (pm8001_ha->chip_id == chip_8001) {
709 if (deviceid == 0x8081)
710 pm8001_ha->sas_addr[j] =
711 payload.func_specific[0x704 + i];
Bradley Grovef49d2132013-12-19 10:50:56 -0500712 else if (deviceid == 0x0042)
713 pm8001_ha->sas_addr[j] =
714 payload.func_specific[0x010 + i];
Benjamin Rood10efa462015-11-02 15:39:23 -0500715 } else if ((pm8001_ha->chip_id == chip_8070 ||
716 pm8001_ha->chip_id == chip_8072) &&
717 pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
718 pm8001_ha->sas_addr[j] =
719 payload.func_specific[0x010 + i];
Sakthivel Ka33a0152013-03-19 18:07:35 +0530720 } else
721 pm8001_ha->sas_addr[j] =
722 payload.func_specific[0x804 + i];
723 }
Viswas G6c85e4b2017-10-18 11:39:09 +0530724 memcpy(sas_add, pm8001_ha->sas_addr, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800725 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
Viswas G6c85e4b2017-10-18 11:39:09 +0530726 if (i && ((i % 4) == 0))
727 sas_add[7] = sas_add[7] + 4;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530728 memcpy(&pm8001_ha->phy[i].dev_sas_addr,
Viswas G6c85e4b2017-10-18 11:39:09 +0530729 sas_add, SAS_ADDR_SIZE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800730 pm8001_dbg(pm8001_ha, INIT, "phy %d sas_addr = %016llx\n", i,
731 pm8001_ha->phy[i].dev_sas_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800732 }
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530733 kfree(payload.func_specific);
jack wangdbf9bfe2009-10-14 16:19:21 +0800734#else
735 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
jack wang7c8356d2009-12-07 17:23:08 +0800736 pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
jack wangdbf9bfe2009-10-14 16:19:21 +0800737 pm8001_ha->phy[i].dev_sas_addr =
738 cpu_to_be64((u64)
739 (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
740 }
741 memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
742 SAS_ADDR_SIZE);
743#endif
744}
745
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530746/*
747 * pm8001_get_phy_settings_info : Read phy setting values.
748 * @pm8001_ha : our hba.
749 */
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200750static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530751{
752
753#ifdef PM8001_READ_VPD
754 /*OPTION ROM FLASH read for the SPC cards */
755 DECLARE_COMPLETION_ONSTACK(completion);
756 struct pm8001_ioctl_payload payload;
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530757 int rc;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530758
759 pm8001_ha->nvmd_completion = &completion;
760 /* SAS ADDRESS read from flash / EEPROM */
761 payload.minor_function = 6;
762 payload.offset = 0;
Viswas G9b889842020-03-16 13:19:06 +0530763 payload.rd_length = 4096;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530764 payload.func_specific = kzalloc(4096, GFP_KERNEL);
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200765 if (!payload.func_specific)
766 return -ENOMEM;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530767 /* Read phy setting values from flash */
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530768 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
769 if (rc) {
770 kfree(payload.func_specific);
Joe Perches1b5d2792020-11-20 15:16:09 -0800771 pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530772 return -ENOMEM;
773 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530774 wait_for_completion(&completion);
775 pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200776 kfree(payload.func_specific);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530777#endif
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200778 return 0;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530779}
780
Benjamin Roodc5614df2015-10-30 10:53:28 -0400781struct pm8001_mpi3_phy_pg_trx_config {
782 u32 LaneLosCfg;
783 u32 LanePgaCfg1;
784 u32 LanePisoCfg1;
785 u32 LanePisoCfg2;
786 u32 LanePisoCfg3;
787 u32 LanePisoCfg4;
788 u32 LanePisoCfg5;
789 u32 LanePisoCfg6;
790 u32 LaneBctCtrl;
791};
792
793/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700794 * pm8001_get_internal_phy_settings - Retrieves the internal PHY settings
Benjamin Roodc5614df2015-10-30 10:53:28 -0400795 * @pm8001_ha : our adapter
796 * @phycfg : PHY config page to populate
797 */
798static
799void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
800 struct pm8001_mpi3_phy_pg_trx_config *phycfg)
801{
802 phycfg->LaneLosCfg = 0x00000132;
803 phycfg->LanePgaCfg1 = 0x00203949;
804 phycfg->LanePisoCfg1 = 0x000000FF;
805 phycfg->LanePisoCfg2 = 0xFF000001;
806 phycfg->LanePisoCfg3 = 0xE7011300;
807 phycfg->LanePisoCfg4 = 0x631C40C0;
808 phycfg->LanePisoCfg5 = 0xF8102036;
809 phycfg->LanePisoCfg6 = 0xF74A1000;
810 phycfg->LaneBctCtrl = 0x00FB33F8;
811}
812
813/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700814 * pm8001_get_external_phy_settings - Retrieves the external PHY settings
Benjamin Roodc5614df2015-10-30 10:53:28 -0400815 * @pm8001_ha : our adapter
816 * @phycfg : PHY config page to populate
817 */
818static
819void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
820 struct pm8001_mpi3_phy_pg_trx_config *phycfg)
821{
822 phycfg->LaneLosCfg = 0x00000132;
823 phycfg->LanePgaCfg1 = 0x00203949;
824 phycfg->LanePisoCfg1 = 0x000000FF;
825 phycfg->LanePisoCfg2 = 0xFF000001;
826 phycfg->LanePisoCfg3 = 0xE7011300;
827 phycfg->LanePisoCfg4 = 0x63349140;
828 phycfg->LanePisoCfg5 = 0xF8102036;
829 phycfg->LanePisoCfg6 = 0xF80D9300;
830 phycfg->LaneBctCtrl = 0x00FB33F8;
831}
832
833/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700834 * pm8001_get_phy_mask - Retrieves the mask that denotes if a PHY is int/ext
Benjamin Roodc5614df2015-10-30 10:53:28 -0400835 * @pm8001_ha : our adapter
836 * @phymask : The PHY mask
837 */
838static
839void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
840{
841 switch (pm8001_ha->pdev->subsystem_device) {
842 case 0x0070: /* H1280 - 8 external 0 internal */
843 case 0x0072: /* H12F0 - 16 external 0 internal */
844 *phymask = 0x0000;
845 break;
846
847 case 0x0071: /* H1208 - 0 external 8 internal */
848 case 0x0073: /* H120F - 0 external 16 internal */
849 *phymask = 0xFFFF;
850 break;
851
852 case 0x0080: /* H1244 - 4 external 4 internal */
853 *phymask = 0x00F0;
854 break;
855
856 case 0x0081: /* H1248 - 4 external 8 internal */
857 *phymask = 0x0FF0;
858 break;
859
860 case 0x0082: /* H1288 - 8 external 8 internal */
861 *phymask = 0xFF00;
862 break;
863
864 default:
Joe Perches1b5d2792020-11-20 15:16:09 -0800865 pm8001_dbg(pm8001_ha, INIT,
866 "Unknown subsystem device=0x%.04x\n",
867 pm8001_ha->pdev->subsystem_device);
Benjamin Roodc5614df2015-10-30 10:53:28 -0400868 }
869}
870
871/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700872 * pm8001_set_phy_settings_ven_117c_12G() - Configure ATTO 12Gb PHY settings
Benjamin Roodc5614df2015-10-30 10:53:28 -0400873 * @pm8001_ha : our adapter
874 */
875static
876int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
877{
878 struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
879 struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
880 int phymask = 0;
881 int i = 0;
882
883 memset(&phycfg_int, 0, sizeof(phycfg_int));
884 memset(&phycfg_ext, 0, sizeof(phycfg_ext));
885
886 pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
887 pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
888 pm8001_get_phy_mask(pm8001_ha, &phymask);
889
890 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
891 if (phymask & (1 << i)) {/* Internal PHY */
892 pm8001_set_phy_profile_single(pm8001_ha, i,
893 sizeof(phycfg_int) / sizeof(u32),
894 (u32 *)&phycfg_int);
895
896 } else { /* External PHY */
897 pm8001_set_phy_profile_single(pm8001_ha, i,
898 sizeof(phycfg_ext) / sizeof(u32),
899 (u32 *)&phycfg_ext);
900 }
901 }
902
903 return 0;
904}
905
Benjamin Roodda2dd612015-10-30 10:53:24 -0400906/**
Randy Dunlapbb6beab2021-07-08 09:57:23 -0700907 * pm8001_configure_phy_settings - Configures PHY settings based on vendor ID.
Benjamin Roodda2dd612015-10-30 10:53:24 -0400908 * @pm8001_ha : our hba.
909 */
910static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
911{
912 switch (pm8001_ha->pdev->subsystem_vendor) {
913 case PCI_VENDOR_ID_ATTO:
Benjamin Roodc5614df2015-10-30 10:53:28 -0400914 if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
915 return 0;
916 else
917 return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
918
Benjamin Roodda2dd612015-10-30 10:53:24 -0400919 case PCI_VENDOR_ID_ADAPTEC2:
920 case 0:
921 return 0;
922
923 default:
924 return pm8001_get_phy_settings_info(pm8001_ha);
925 }
926}
927
jack wangdbf9bfe2009-10-14 16:19:21 +0800928#ifdef PM8001_USE_MSIX
929/**
930 * pm8001_setup_msix - enable MSI-X interrupt
Lee Jonese802fc42020-07-13 08:46:42 +0100931 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +0800932 */
Sakthivel K1245ee52013-03-19 17:56:17 +0530933static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800934{
Sakthivel K1245ee52013-03-19 17:56:17 +0530935 u32 number_of_intr;
Viswas G05c6c022020-10-05 20:20:08 +0530936 int rc, cpu_online_count;
937 unsigned int allocated_irq_vectors;
Sakthivel K1245ee52013-03-19 17:56:17 +0530938
939 /* SPCv controllers supports 64 msi-x */
940 if (pm8001_ha->chip_id == chip_8001) {
941 number_of_intr = 1;
Sakthivel K1245ee52013-03-19 17:56:17 +0530942 } else {
943 number_of_intr = PM8001_MAX_MSIX_VEC;
Sakthivel K1245ee52013-03-19 17:56:17 +0530944 }
945
Viswas G05c6c022020-10-05 20:20:08 +0530946 cpu_online_count = num_online_cpus();
947 number_of_intr = min_t(int, cpu_online_count, number_of_intr);
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100948 rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr,
949 number_of_intr, PCI_IRQ_MSIX);
Viswas G05c6c022020-10-05 20:20:08 +0530950 allocated_irq_vectors = rc;
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100951 if (rc < 0)
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200952 return rc;
Viswas G05c6c022020-10-05 20:20:08 +0530953
954 /* Assigns the number of interrupts */
955 number_of_intr = min_t(int, allocated_irq_vectors, number_of_intr);
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100956 pm8001_ha->number_of_intr = number_of_intr;
Sakthivel K1245ee52013-03-19 17:56:17 +0530957
Viswas G05c6c022020-10-05 20:20:08 +0530958 /* Maximum queue number updating in HBA structure */
959 pm8001_ha->max_q_num = number_of_intr;
960
Joe Perches1b5d2792020-11-20 15:16:09 -0800961 pm8001_dbg(pm8001_ha, INIT,
962 "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
963 rc, pm8001_ha->number_of_intr);
Vikram Auradkard384be62020-03-16 13:19:02 +0530964 return 0;
965}
Sakthivel K1245ee52013-03-19 17:56:17 +0530966
Vikram Auradkard384be62020-03-16 13:19:02 +0530967static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
968{
969 u32 i = 0, j = 0;
970 int flag = 0, rc = 0;
Arnd Bergmannc2255ec2021-03-23 13:54:23 +0100971 int nr_irqs = pm8001_ha->number_of_intr;
Vikram Auradkard384be62020-03-16 13:19:02 +0530972
973 if (pm8001_ha->chip_id != chip_8001)
974 flag &= ~IRQF_SHARED;
975
Joe Perches1b5d2792020-11-20 15:16:09 -0800976 pm8001_dbg(pm8001_ha, INIT,
977 "pci_enable_msix request number of intr %d\n",
978 pm8001_ha->number_of_intr);
Vikram Auradkard384be62020-03-16 13:19:02 +0530979
Arnd Bergmannc2255ec2021-03-23 13:54:23 +0100980 if (nr_irqs > ARRAY_SIZE(pm8001_ha->intr_drvname))
981 nr_irqs = ARRAY_SIZE(pm8001_ha->intr_drvname);
982
983 for (i = 0; i < nr_irqs; i++) {
Vikram Auradkar72954932019-11-14 15:39:09 +0530984 snprintf(pm8001_ha->intr_drvname[i],
985 sizeof(pm8001_ha->intr_drvname[0]),
986 "%s-%d", pm8001_ha->name, i);
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200987 pm8001_ha->irq_vector[i].irq_id = i;
988 pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530989
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100990 rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200991 pm8001_interrupt_handler_msix, flag,
Vikram Auradkar72954932019-11-14 15:39:09 +0530992 pm8001_ha->intr_drvname[i],
993 &(pm8001_ha->irq_vector[i]));
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200994 if (rc) {
995 for (j = 0; j < i; j++) {
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100996 free_irq(pci_irq_vector(pm8001_ha->pdev, i),
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530997 &(pm8001_ha->irq_vector[i]));
jack wangdbf9bfe2009-10-14 16:19:21 +0800998 }
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100999 pci_free_irq_vectors(pm8001_ha->pdev);
Alexander Gordeevb4d511e2014-07-16 20:05:22 +02001000 break;
jack wangdbf9bfe2009-10-14 16:19:21 +08001001 }
1002 }
Alexander Gordeevb4d511e2014-07-16 20:05:22 +02001003
jack wangdbf9bfe2009-10-14 16:19:21 +08001004 return rc;
1005}
1006#endif
1007
Vikram Auradkard384be62020-03-16 13:19:02 +05301008static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha)
1009{
1010 struct pci_dev *pdev;
1011
1012 pdev = pm8001_ha->pdev;
1013
1014#ifdef PM8001_USE_MSIX
1015 if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
1016 return pm8001_setup_msix(pm8001_ha);
Joe Perches1b5d2792020-11-20 15:16:09 -08001017 pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
Vikram Auradkard384be62020-03-16 13:19:02 +05301018#endif
1019 return 0;
1020}
1021
jack wangdbf9bfe2009-10-14 16:19:21 +08001022/**
1023 * pm8001_request_irq - register interrupt
Lee Jonese802fc42020-07-13 08:46:42 +01001024 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +08001025 */
1026static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
1027{
1028 struct pci_dev *pdev;
jack_wang97ee2082009-11-05 22:33:51 +08001029 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08001030
1031 pdev = pm8001_ha->pdev;
1032
1033#ifdef PM8001_USE_MSIX
Benjamin Roodc913df32015-10-30 10:53:31 -04001034 if (pdev->msix_cap && pci_msi_enabled())
Vikram Auradkard384be62020-03-16 13:19:02 +05301035 return pm8001_request_msix(pm8001_ha);
Sakthivel K1245ee52013-03-19 17:56:17 +05301036 else {
Joe Perches1b5d2792020-11-20 15:16:09 -08001037 pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001038 goto intx;
Sakthivel K1245ee52013-03-19 17:56:17 +05301039 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001040#endif
1041
1042intx:
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001043 /* initialize the INT-X interrupt */
Benjamin Roodc913df32015-10-30 10:53:31 -04001044 pm8001_ha->irq_vector[0].irq_id = 0;
1045 pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
Sakthivel K1245ee52013-03-19 17:56:17 +05301046 rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
Vikram Auradkar72954932019-11-14 15:39:09 +05301047 pm8001_ha->name, SHOST_TO_SAS_HA(pm8001_ha->shost));
jack wangdbf9bfe2009-10-14 16:19:21 +08001048 return rc;
1049}
1050
1051/**
1052 * pm8001_pci_probe - probe supported device
1053 * @pdev: pci device which kernel has been prepared for.
1054 * @ent: pci device id
1055 *
1056 * This function is the main initialization function, when register a new
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001057 * pci driver it is invoked, all struct and hardware initialization should be
1058 * done here, also, register interrupt.
jack wangdbf9bfe2009-10-14 16:19:21 +08001059 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001060static int pm8001_pci_probe(struct pci_dev *pdev,
1061 const struct pci_device_id *ent)
jack wangdbf9bfe2009-10-14 16:19:21 +08001062{
1063 unsigned int rc;
1064 u32 pci_reg;
Sakthivel K1245ee52013-03-19 17:56:17 +05301065 u8 i = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08001066 struct pm8001_hba_info *pm8001_ha;
1067 struct Scsi_Host *shost = NULL;
1068 const struct pm8001_chip_info *chip;
Peter Changb40f2882020-03-16 13:19:04 +05301069 struct sas_ha_struct *sha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001070
1071 dev_printk(KERN_INFO, &pdev->dev,
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301072 "pm80xx: driver version %s\n", DRV_VERSION);
jack wangdbf9bfe2009-10-14 16:19:21 +08001073 rc = pci_enable_device(pdev);
1074 if (rc)
1075 goto err_out_enable;
1076 pci_set_master(pdev);
1077 /*
1078 * Enable pci slot busmaster by setting pci command register.
1079 * This is required by FW for Cyclone card.
1080 */
1081
1082 pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
1083 pci_reg |= 0x157;
1084 pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
1085 rc = pci_request_regions(pdev, DRV_NAME);
1086 if (rc)
1087 goto err_out_disable;
1088 rc = pci_go_44(pdev);
1089 if (rc)
1090 goto err_out_regions;
1091
1092 shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
1093 if (!shost) {
1094 rc = -ENOMEM;
1095 goto err_out_regions;
1096 }
1097 chip = &pm8001_chips[ent->driver_data];
Peter Changb40f2882020-03-16 13:19:04 +05301098 sha = kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
1099 if (!sha) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001100 rc = -ENOMEM;
1101 goto err_out_free_host;
1102 }
Peter Changb40f2882020-03-16 13:19:04 +05301103 SHOST_TO_SAS_HA(shost) = sha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001104
1105 rc = pm8001_prep_sas_ha_init(shost, chip);
1106 if (rc) {
1107 rc = -ENOMEM;
1108 goto err_out_free;
1109 }
1110 pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
Sakthivel Ke590adf2013-02-27 20:25:25 +05301111 /* ent->driver variable is used to differentiate between controllers */
1112 pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001113 if (!pm8001_ha) {
1114 rc = -ENOMEM;
1115 goto err_out_free;
1116 }
Peter Changb40f2882020-03-16 13:19:04 +05301117
Sakthivel Kf5860992013-04-17 16:37:02 +05301118 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001119 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301120 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001121 pm8001_dbg(pm8001_ha, FAIL,
1122 "chip_init failed [ret: %d]\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08001123 goto err_out_ha_free;
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301124 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001125
Viswas G5a141312020-10-05 20:20:10 +05301126 rc = pm8001_init_ccb_tag(pm8001_ha, shost, pdev);
1127 if (rc)
1128 goto err_out_enable;
1129
jack wangdbf9bfe2009-10-14 16:19:21 +08001130 rc = scsi_add_host(shost, &pdev->dev);
1131 if (rc)
1132 goto err_out_ha_free;
jack wangdbf9bfe2009-10-14 16:19:21 +08001133
Sakthivel Kf74cf272013-02-27 20:27:43 +05301134 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
Sakthivel K1245ee52013-03-19 17:56:17 +05301135 if (pm8001_ha->chip_id != chip_8001) {
1136 for (i = 1; i < pm8001_ha->number_of_intr; i++)
1137 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301138 /* setup thermal configuration. */
1139 pm80xx_set_thermal_config(pm8001_ha);
Sakthivel K1245ee52013-03-19 17:56:17 +05301140 }
1141
jack wangdbf9bfe2009-10-14 16:19:21 +08001142 pm8001_init_sas_add(pm8001_ha);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05301143 /* phy setting support for motherboard controller */
Zhang Qilong97031cc2020-12-05 19:55:51 +08001144 rc = pm8001_configure_phy_settings(pm8001_ha);
1145 if (rc)
Benjamin Roodda2dd612015-10-30 10:53:24 -04001146 goto err_out_shost;
1147
jack wangdbf9bfe2009-10-14 16:19:21 +08001148 pm8001_post_sas_ha_init(shost, chip);
1149 rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
Peter Changb40f2882020-03-16 13:19:04 +05301150 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001151 pm8001_dbg(pm8001_ha, FAIL,
1152 "sas_register_ha failed [ret: %d]\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08001153 goto err_out_shost;
Peter Changb40f2882020-03-16 13:19:04 +05301154 }
1155 list_add_tail(&pm8001_ha->list, &hba_list);
Deepak Ukeycd135752018-09-11 14:18:02 +05301156 pm8001_ha->flags = PM8001F_RUN_TIME;
Ajish Koshyd1acd812021-05-05 17:31:03 +05301157 scsi_scan_host(pm8001_ha->shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001158 return 0;
1159
1160err_out_shost:
1161 scsi_remove_host(pm8001_ha->shost);
1162err_out_ha_free:
1163 pm8001_free(pm8001_ha);
1164err_out_free:
Peter Changb40f2882020-03-16 13:19:04 +05301165 kfree(sha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001166err_out_free_host:
Pan Bianbc1371c2017-08-08 19:40:30 +08001167 scsi_host_put(shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001168err_out_regions:
1169 pci_release_regions(pdev);
1170err_out_disable:
1171 pci_disable_device(pdev);
1172err_out_enable:
1173 return rc;
1174}
1175
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001176/**
Viswas G5a141312020-10-05 20:20:10 +05301177 * pm8001_init_ccb_tag - allocate memory to CCB and tag.
1178 * @pm8001_ha: our hba card information.
1179 * @shost: scsi host which has been allocated outside.
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001180 * @pdev: pci device.
Viswas G5a141312020-10-05 20:20:10 +05301181 */
1182static int
1183pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost,
1184 struct pci_dev *pdev)
1185{
1186 int i = 0;
1187 u32 max_out_io, ccb_count;
1188 u32 can_queue;
1189
1190 max_out_io = pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io;
1191 ccb_count = min_t(int, PM8001_MAX_CCB, max_out_io);
1192
1193 /* Update to the scsi host*/
1194 can_queue = ccb_count - PM8001_RESERVE_SLOT;
1195 shost->can_queue = can_queue;
1196
1197 pm8001_ha->tags = kzalloc(ccb_count, GFP_KERNEL);
1198 if (!pm8001_ha->tags)
1199 goto err_out;
1200
1201 /* Memory region for ccb_info*/
Xu Wang27a34942020-11-20 08:36:48 +00001202 pm8001_ha->ccb_info =
Viswas G5a141312020-10-05 20:20:10 +05301203 kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL);
1204 if (!pm8001_ha->ccb_info) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001205 pm8001_dbg(pm8001_ha, FAIL,
1206 "Unable to allocate memory for ccb\n");
Viswas G5a141312020-10-05 20:20:10 +05301207 goto err_out_noccb;
1208 }
1209 for (i = 0; i < ccb_count; i++) {
Christophe JAILLET8e60a7d2021-01-17 14:24:45 +01001210 pm8001_ha->ccb_info[i].buf_prd = dma_alloc_coherent(&pdev->dev,
Viswas G5a141312020-10-05 20:20:10 +05301211 sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
Christophe JAILLET8e60a7d2021-01-17 14:24:45 +01001212 &pm8001_ha->ccb_info[i].ccb_dma_handle,
1213 GFP_KERNEL);
Viswas G5a141312020-10-05 20:20:10 +05301214 if (!pm8001_ha->ccb_info[i].buf_prd) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001215 pm8001_dbg(pm8001_ha, FAIL,
Christophe JAILLET8e60a7d2021-01-17 14:24:45 +01001216 "ccb prd memory allocation error\n");
Viswas G5a141312020-10-05 20:20:10 +05301217 goto err_out;
1218 }
1219 pm8001_ha->ccb_info[i].task = NULL;
1220 pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
1221 pm8001_ha->ccb_info[i].device = NULL;
1222 ++pm8001_ha->tags_num;
1223 }
1224 return 0;
1225
1226err_out_noccb:
1227 kfree(pm8001_ha->devices);
1228err_out:
1229 return -ENOMEM;
1230}
1231
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001232static void pm8001_pci_remove(struct pci_dev *pdev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001233{
1234 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
1235 struct pm8001_hba_info *pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301236 int i, j;
jack wangdbf9bfe2009-10-14 16:19:21 +08001237 pm8001_ha = sha->lldd_ha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001238 sas_unregister_ha(sha);
1239 sas_remove_host(pm8001_ha->shost);
1240 list_del(&pm8001_ha->list);
Sakthivel K1245ee52013-03-19 17:56:17 +05301241 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301242 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001243
1244#ifdef PM8001_USE_MSIX
1245 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001246 synchronize_irq(pci_irq_vector(pdev, i));
jack wangdbf9bfe2009-10-14 16:19:21 +08001247 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001248 free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1249 pci_free_irq_vectors(pdev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001250#else
1251 free_irq(pm8001_ha->irq, sha);
1252#endif
1253#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301254 /* For non-msix and msix interrupts */
Benjamin Roodc913df32015-10-30 10:53:31 -04001255 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1256 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301257 tasklet_kill(&pm8001_ha->tasklet[0]);
1258 else
1259 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1260 tasklet_kill(&pm8001_ha->tasklet[j]);
jack wangdbf9bfe2009-10-14 16:19:21 +08001261#endif
Pan Bianbc1371c2017-08-08 19:40:30 +08001262 scsi_host_put(pm8001_ha->shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001263 pm8001_free(pm8001_ha);
1264 kfree(sha->sas_phy);
1265 kfree(sha->sas_port);
1266 kfree(sha);
1267 pci_release_regions(pdev);
1268 pci_disable_device(pdev);
1269}
1270
1271/**
1272 * pm8001_pci_suspend - power management suspend main entry point
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301273 * @dev: Device struct
jack wangdbf9bfe2009-10-14 16:19:21 +08001274 *
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001275 * Return: 0 on success, anything else on error.
jack wangdbf9bfe2009-10-14 16:19:21 +08001276 */
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301277static int __maybe_unused pm8001_pci_suspend(struct device *dev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001278{
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301279 struct pci_dev *pdev = to_pci_dev(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001280 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301281 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301282 int i, j;
Bradley Grove9f176092014-07-09 17:20:23 +05301283 sas_suspend_ha(sha);
Tejun Heo429305e2011-01-24 14:57:29 +01001284 flush_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +08001285 scsi_block_requests(pm8001_ha->shost);
Yijing Wangc8a2ba32013-06-27 15:02:49 +08001286 if (!pdev->pm_cap) {
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301287 dev_err(dev, " PCI PM not supported\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001288 return -ENODEV;
1289 }
Sakthivel K1245ee52013-03-19 17:56:17 +05301290 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301291 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001292#ifdef PM8001_USE_MSIX
1293 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001294 synchronize_irq(pci_irq_vector(pdev, i));
jack wangdbf9bfe2009-10-14 16:19:21 +08001295 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001296 free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1297 pci_free_irq_vectors(pdev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001298#else
1299 free_irq(pm8001_ha->irq, sha);
1300#endif
1301#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301302 /* For non-msix and msix interrupts */
Benjamin Roodc913df32015-10-30 10:53:31 -04001303 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1304 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301305 tasklet_kill(&pm8001_ha->tasklet[0]);
1306 else
1307 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1308 tasklet_kill(&pm8001_ha->tasklet[j]);
jack wangdbf9bfe2009-10-14 16:19:21 +08001309#endif
Joe Perches2ce6e202020-11-23 20:36:03 -08001310 pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, entering "
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301311 "suspended state\n", pdev,
1312 pm8001_ha->name);
jack wangdbf9bfe2009-10-14 16:19:21 +08001313 return 0;
1314}
1315
1316/**
1317 * pm8001_pci_resume - power management resume main entry point
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301318 * @dev: Device struct
jack wangdbf9bfe2009-10-14 16:19:21 +08001319 *
Randy Dunlapbb6beab2021-07-08 09:57:23 -07001320 * Return: 0 on success, anything else on error.
jack wangdbf9bfe2009-10-14 16:19:21 +08001321 */
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301322static int __maybe_unused pm8001_pci_resume(struct device *dev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001323{
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301324 struct pci_dev *pdev = to_pci_dev(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001325 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
1326 struct pm8001_hba_info *pm8001_ha;
1327 int rc;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301328 u8 i = 0, j;
jack wangdbf9bfe2009-10-14 16:19:21 +08001329 u32 device_state;
Bradley Grove9f176092014-07-09 17:20:23 +05301330 DECLARE_COMPLETION_ONSTACK(completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08001331 pm8001_ha = sha->lldd_ha;
1332 device_state = pdev->current_state;
1333
Joe Perches2ce6e202020-11-23 20:36:03 -08001334 pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, resuming from previous operating state [D%d]\n",
Joe Perches89eddb42020-11-20 15:16:10 -08001335 pdev, pm8001_ha->name, device_state);
jack wangdbf9bfe2009-10-14 16:19:21 +08001336
jack wangdbf9bfe2009-10-14 16:19:21 +08001337 rc = pci_go_44(pdev);
1338 if (rc)
1339 goto err_out_disable;
Bradley Grove9f176092014-07-09 17:20:23 +05301340 sas_prep_resume_ha(sha);
Sakthivel Kf5860992013-04-17 16:37:02 +05301341 /* chip soft rst only for spc */
1342 if (pm8001_ha->chip_id == chip_8001) {
1343 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
Joe Perches1b5d2792020-11-20 15:16:09 -08001344 pm8001_dbg(pm8001_ha, INIT, "chip soft reset successful\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301345 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001346 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
1347 if (rc)
1348 goto err_out_disable;
Sakthivel K1245ee52013-03-19 17:56:17 +05301349
1350 /* disable all the interrupt bits */
1351 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
1352
jack wangdbf9bfe2009-10-14 16:19:21 +08001353 rc = pm8001_request_irq(pm8001_ha);
1354 if (rc)
1355 goto err_out_disable;
Sakthivel K1245ee52013-03-19 17:56:17 +05301356#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301357 /* Tasklet for non msi-x interrupt handler */
Benjamin Roodc913df32015-10-30 10:53:31 -04001358 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1359 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301360 tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
1361 (unsigned long)&(pm8001_ha->irq_vector[0]));
1362 else
1363 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1364 tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
1365 (unsigned long)&(pm8001_ha->irq_vector[j]));
Sakthivel K1245ee52013-03-19 17:56:17 +05301366#endif
Sakthivel Kf74cf272013-02-27 20:27:43 +05301367 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
Sakthivel K1245ee52013-03-19 17:56:17 +05301368 if (pm8001_ha->chip_id != chip_8001) {
1369 for (i = 1; i < pm8001_ha->number_of_intr; i++)
1370 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
1371 }
Benjamin Roodb650a882015-11-02 15:42:29 -05001372
1373 /* Chip documentation for the 8070 and 8072 SPCv */
1374 /* states that a 500ms minimum delay is required */
Julia Lawall014e8ba2016-05-17 16:38:44 +02001375 /* before issuing commands. Otherwise, the firmware */
Benjamin Roodb650a882015-11-02 15:42:29 -05001376 /* will enter an unrecoverable state. */
1377
1378 if (pm8001_ha->chip_id == chip_8070 ||
1379 pm8001_ha->chip_id == chip_8072) {
1380 mdelay(500);
1381 }
1382
1383 /* Spin up the PHYs */
1384
Bradley Grove9f176092014-07-09 17:20:23 +05301385 pm8001_ha->flags = PM8001F_RUN_TIME;
1386 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
1387 pm8001_ha->phy[i].enable_completion = &completion;
1388 PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
1389 wait_for_completion(&completion);
1390 }
1391 sas_resume_ha(sha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001392 return 0;
1393
1394err_out_disable:
1395 scsi_remove_host(pm8001_ha->shost);
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301396
jack wangdbf9bfe2009-10-14 16:19:21 +08001397 return rc;
1398}
1399
Sakthivel Ke5742102013-04-17 16:26:36 +05301400/* update of pci device, vendor id and driver data with
1401 * unique value for each of the controller
1402 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001403static struct pci_device_id pm8001_pci_table[] = {
Sakthivel Ke5742102013-04-17 16:26:36 +05301404 { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
Suresh Thiagarajand8571b12015-02-12 12:04:37 +05301405 { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
1406 { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
Bradley Grovef49d2132013-12-19 10:50:56 -05001407 { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
Sakthivel Ke5742102013-04-17 16:26:36 +05301408 /* Support for SPC/SPCv/SPCve controllers */
1409 { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
1410 { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
1411 { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
1412 { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
1413 { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
1414 { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
1415 { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
1416 { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
1417 { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301418 { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
1419 { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
1420 { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
1421 { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
1422 { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
1423 { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
Sakthivel Ke5742102013-04-17 16:26:36 +05301424 { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
1425 PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
1426 { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
1427 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
1428 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1429 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
1430 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1431 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
1432 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1433 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
1434 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1435 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
1436 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1437 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
1438 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1439 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
1440 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1441 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
1442 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1443 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301444 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1445 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
1446 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1447 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
1448 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1449 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
1450 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1451 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
1452 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1453 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
1454 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1455 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
1456 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1457 PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
1458 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1459 PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
1460 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1461 PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
Benjamin Roodb2dece42015-10-30 10:53:26 -04001462 { PCI_VENDOR_ID_ATTO, 0x8070,
1463 PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
1464 { PCI_VENDOR_ID_ATTO, 0x8070,
1465 PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
1466 { PCI_VENDOR_ID_ATTO, 0x8072,
1467 PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
1468 { PCI_VENDOR_ID_ATTO, 0x8072,
1469 PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
1470 { PCI_VENDOR_ID_ATTO, 0x8070,
1471 PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
1472 { PCI_VENDOR_ID_ATTO, 0x8072,
1473 PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
1474 { PCI_VENDOR_ID_ATTO, 0x8072,
1475 PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
jack wangdbf9bfe2009-10-14 16:19:21 +08001476 {} /* terminate list */
1477};
1478
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301479static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
1480 pm8001_pci_suspend,
1481 pm8001_pci_resume);
1482
jack wangdbf9bfe2009-10-14 16:19:21 +08001483static struct pci_driver pm8001_pci_driver = {
1484 .name = DRV_NAME,
1485 .id_table = pm8001_pci_table,
1486 .probe = pm8001_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001487 .remove = pm8001_pci_remove,
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301488 .driver.pm = &pm8001_pci_pm_ops,
jack wangdbf9bfe2009-10-14 16:19:21 +08001489};
1490
1491/**
1492 * pm8001_init - initialize scsi transport template
1493 */
1494static int __init pm8001_init(void)
1495{
Tejun Heo429305e2011-01-24 14:57:29 +01001496 int rc = -ENOMEM;
1497
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301498 pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
Tejun Heo429305e2011-01-24 14:57:29 +01001499 if (!pm8001_wq)
1500 goto err;
1501
jack wangdbf9bfe2009-10-14 16:19:21 +08001502 pm8001_id = 0;
1503 pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
1504 if (!pm8001_stt)
Tejun Heo429305e2011-01-24 14:57:29 +01001505 goto err_wq;
jack wangdbf9bfe2009-10-14 16:19:21 +08001506 rc = pci_register_driver(&pm8001_pci_driver);
1507 if (rc)
Tejun Heo429305e2011-01-24 14:57:29 +01001508 goto err_tp;
jack wangdbf9bfe2009-10-14 16:19:21 +08001509 return 0;
Tejun Heo429305e2011-01-24 14:57:29 +01001510
1511err_tp:
jack wangdbf9bfe2009-10-14 16:19:21 +08001512 sas_release_transport(pm8001_stt);
Tejun Heo429305e2011-01-24 14:57:29 +01001513err_wq:
1514 destroy_workqueue(pm8001_wq);
1515err:
jack wangdbf9bfe2009-10-14 16:19:21 +08001516 return rc;
1517}
1518
1519static void __exit pm8001_exit(void)
1520{
1521 pci_unregister_driver(&pm8001_pci_driver);
1522 sas_release_transport(pm8001_stt);
Tejun Heo429305e2011-01-24 14:57:29 +01001523 destroy_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +08001524}
1525
1526module_init(pm8001_init);
1527module_exit(pm8001_exit);
1528
1529MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301530MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
1531MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
Nikith Ganigarakoppal94f33c12013-11-13 15:35:23 +05301532MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
Sakthivel Ke5742102013-04-17 16:26:36 +05301533MODULE_DESCRIPTION(
Benjamin Rooddb9d4032015-10-30 10:53:25 -04001534 "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301535 "SAS/SATA controller driver");
jack wangdbf9bfe2009-10-14 16:19:21 +08001536MODULE_VERSION(DRV_VERSION);
1537MODULE_LICENSE("GPL");
1538MODULE_DEVICE_TABLE(pci, pm8001_pci_table);
1539