blob: d21078ca7fb38ef9184da98ebfab1bb516befa56 [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,
jack wangdbf9bfe2009-10-14 16:19:21 +0800104 .target_destroy = sas_target_destroy,
105 .ioctl = sas_ioctl,
Arnd Bergmann75c0b0e2019-11-30 20:28:12 +0100106#ifdef CONFIG_COMPAT
107 .compat_ioctl = sas_ioctl,
108#endif
jack wangdbf9bfe2009-10-14 16:19:21 +0800109 .shost_attrs = pm8001_host_attrs,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100110 .track_queue_depth = 1,
jack wangdbf9bfe2009-10-14 16:19:21 +0800111};
112
Lee Jonese802fc42020-07-13 08:46:42 +0100113/*
jack wangdbf9bfe2009-10-14 16:19:21 +0800114 * Sas layer call this function to execute specific task.
115 */
116static struct sas_domain_function_template pm8001_transport_ops = {
117 .lldd_dev_found = pm8001_dev_found,
118 .lldd_dev_gone = pm8001_dev_gone,
119
120 .lldd_execute_task = pm8001_queue_command,
121 .lldd_control_phy = pm8001_phy_control,
122
123 .lldd_abort_task = pm8001_abort_task,
124 .lldd_abort_task_set = pm8001_abort_task_set,
125 .lldd_clear_aca = pm8001_clear_aca,
126 .lldd_clear_task_set = pm8001_clear_task_set,
127 .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
128 .lldd_lu_reset = pm8001_lu_reset,
129 .lldd_query_task = pm8001_query_task,
130};
131
132/**
Lee Jonese802fc42020-07-13 08:46:42 +0100133 * pm8001_phy_init - initiate our adapter phys
134 * @pm8001_ha: our hba structure.
135 * @phy_id: phy id.
jack wangdbf9bfe2009-10-14 16:19:21 +0800136 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800137static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
jack wangdbf9bfe2009-10-14 16:19:21 +0800138{
139 struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
140 struct asd_sas_phy *sas_phy = &phy->sas_phy;
Deepak Ukeycd135752018-09-11 14:18:02 +0530141 phy->phy_state = PHY_LINK_DISABLE;
jack wangdbf9bfe2009-10-14 16:19:21 +0800142 phy->pm8001_ha = pm8001_ha;
143 sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
144 sas_phy->class = SAS;
145 sas_phy->iproto = SAS_PROTOCOL_ALL;
146 sas_phy->tproto = 0;
147 sas_phy->type = PHY_TYPE_PHYSICAL;
148 sas_phy->role = PHY_ROLE_INITIATOR;
149 sas_phy->oob_mode = OOB_NOT_CONNECTED;
150 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
151 sas_phy->id = phy_id;
Viswas G6c85e4b2017-10-18 11:39:09 +0530152 sas_phy->sas_addr = (u8 *)&phy->dev_sas_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800153 sas_phy->frame_rcvd = &phy->frame_rcvd[0];
154 sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
155 sas_phy->lldd_phy = phy;
156}
157
158/**
Lee Jonese802fc42020-07-13 08:46:42 +0100159 * pm8001_free - free hba
160 * @pm8001_ha: our hba structure.
jack wangdbf9bfe2009-10-14 16:19:21 +0800161 */
162static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
163{
164 int i;
jack wangdbf9bfe2009-10-14 16:19:21 +0800165
166 if (!pm8001_ha)
167 return;
168
169 for (i = 0; i < USI_MAX_MEMCNT; i++) {
170 if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +0200171 dma_free_coherent(&pm8001_ha->pdev->dev,
Sakthivel Kbfb48092013-02-04 12:10:02 +0530172 (pm8001_ha->memoryMap.region[i].total_len +
173 pm8001_ha->memoryMap.region[i].alignment),
jack wangdbf9bfe2009-10-14 16:19:21 +0800174 pm8001_ha->memoryMap.region[i].virt_ptr,
175 pm8001_ha->memoryMap.region[i].phys_addr);
176 }
177 }
178 PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
Tejun Heo429305e2011-01-24 14:57:29 +0100179 flush_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +0800180 kfree(pm8001_ha->tags);
181 kfree(pm8001_ha);
182}
183
184#ifdef PM8001_USE_TASKLET
Sakthivel K1245ee52013-03-19 17:56:17 +0530185
186/**
187 * tasklet for 64 msi-x interrupt handler
188 * @opaque: the passed general host adapter struct
189 * Note: pm8001_tasklet is common for pm8001 & pm80xx
190 */
jack wangdbf9bfe2009-10-14 16:19:21 +0800191static void pm8001_tasklet(unsigned long opaque)
192{
193 struct pm8001_hba_info *pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530194 struct isr_param *irq_vector;
195
196 irq_vector = (struct isr_param *)opaque;
197 pm8001_ha = irq_vector->drv_inst;
jack wangdbf9bfe2009-10-14 16:19:21 +0800198 if (unlikely(!pm8001_ha))
199 BUG_ON(1);
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530200 PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
jack wangdbf9bfe2009-10-14 16:19:21 +0800201}
202#endif
203
Sakthivel K1245ee52013-03-19 17:56:17 +0530204/**
205 * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
206 * It obtains the vector number and calls the equivalent bottom
207 * half or services directly.
Lee Jonese802fc42020-07-13 08:46:42 +0100208 * @irq: interrupt number
Sakthivel K1245ee52013-03-19 17:56:17 +0530209 * @opaque: the passed outbound queue/vector. Host structure is
210 * retrieved from the same.
211 */
212static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
213{
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530214 struct isr_param *irq_vector;
215 struct pm8001_hba_info *pm8001_ha;
Sakthivel K1245ee52013-03-19 17:56:17 +0530216 irqreturn_t ret = IRQ_HANDLED;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530217 irq_vector = (struct isr_param *)opaque;
218 pm8001_ha = irq_vector->drv_inst;
219
Sakthivel K1245ee52013-03-19 17:56:17 +0530220 if (unlikely(!pm8001_ha))
221 return IRQ_NONE;
Colin Ian Kingf310a4e2019-03-29 23:44:23 +0000222 if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
Sakthivel K1245ee52013-03-19 17:56:17 +0530223 return IRQ_NONE;
Sakthivel K1245ee52013-03-19 17:56:17 +0530224#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530225 tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
Sakthivel K1245ee52013-03-19 17:56:17 +0530226#else
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530227 ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
Sakthivel K1245ee52013-03-19 17:56:17 +0530228#endif
229 return ret;
230}
231
232/**
233 * pm8001_interrupt_handler_intx - main INTx interrupt handler.
Lee Jonese802fc42020-07-13 08:46:42 +0100234 * @irq: interrupt number
Sakthivel K1245ee52013-03-19 17:56:17 +0530235 * @dev_id: sas_ha structure. The HBA is retrieved from sas_has structure.
236 */
237
238static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id)
jack wangdbf9bfe2009-10-14 16:19:21 +0800239{
240 struct pm8001_hba_info *pm8001_ha;
241 irqreturn_t ret = IRQ_HANDLED;
Sakthivel K1245ee52013-03-19 17:56:17 +0530242 struct sas_ha_struct *sha = dev_id;
jack wangdbf9bfe2009-10-14 16:19:21 +0800243 pm8001_ha = sha->lldd_ha;
244 if (unlikely(!pm8001_ha))
245 return IRQ_NONE;
Colin Ian Kingf310a4e2019-03-29 23:44:23 +0000246 if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
jack wangdbf9bfe2009-10-14 16:19:21 +0800247 return IRQ_NONE;
Sakthivel K1245ee52013-03-19 17:56:17 +0530248
jack wangdbf9bfe2009-10-14 16:19:21 +0800249#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530250 tasklet_schedule(&pm8001_ha->tasklet[0]);
jack wangdbf9bfe2009-10-14 16:19:21 +0800251#else
Sakthivel Kf74cf272013-02-27 20:27:43 +0530252 ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800253#endif
254 return ret;
255}
256
Vikram Auradkard384be62020-03-16 13:19:02 +0530257static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha);
258static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha);
259
jack wangdbf9bfe2009-10-14 16:19:21 +0800260/**
261 * pm8001_alloc - initiate our hba structure and 6 DMAs area.
Lee Jonese802fc42020-07-13 08:46:42 +0100262 * @pm8001_ha: our hba structure.
263 * @ent: PCI device ID structure to match on
jack wangdbf9bfe2009-10-14 16:19:21 +0800264 */
Sakthivel Ke590adf2013-02-27 20:25:25 +0530265static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
266 const struct pci_device_id *ent)
jack wangdbf9bfe2009-10-14 16:19:21 +0800267{
Viswas G05c6c022020-10-05 20:20:08 +0530268 int i, count = 0, rc = 0;
269 u32 ci_offset, ib_offset, ob_offset, pi_offset;
270 struct inbound_queue_table *circularQ;
271
jack wangdbf9bfe2009-10-14 16:19:21 +0800272 spin_lock_init(&pm8001_ha->lock);
Tomas Henzl646cdf02014-07-09 17:21:01 +0530273 spin_lock_init(&pm8001_ha->bitmap_lock);
Joe Perches1b5d2792020-11-20 15:16:09 -0800274 pm8001_dbg(pm8001_ha, INIT, "pm8001_alloc: PHY:%x\n",
275 pm8001_ha->chip->n_phy);
Viswas G05c6c022020-10-05 20:20:08 +0530276
277 /* Setup Interrupt */
278 rc = pm8001_setup_irq(pm8001_ha);
279 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800280 pm8001_dbg(pm8001_ha, FAIL,
281 "pm8001_setup_irq failed [ret: %d]\n", rc);
Viswas G05c6c022020-10-05 20:20:08 +0530282 goto err_out_shost;
283 }
284 /* Request Interrupt */
285 rc = pm8001_request_irq(pm8001_ha);
286 if (rc)
287 goto err_out_shost;
288
289 count = pm8001_ha->max_q_num;
290 /* Queues are chosen based on the number of cores/msix availability */
Viswas G27bc43b2020-10-05 20:20:09 +0530291 ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE;
Viswas G05c6c022020-10-05 20:20:08 +0530292 ci_offset = pm8001_ha->ci_offset = ib_offset + count;
293 ob_offset = pm8001_ha->ob_offset = ci_offset + count;
294 pi_offset = pm8001_ha->pi_offset = ob_offset + count;
295 pm8001_ha->max_memcnt = pi_offset + count;
296
jack wang1cc943a2009-12-07 17:22:42 +0800297 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800298 pm8001_phy_init(pm8001_ha, i);
jack wang1cc943a2009-12-07 17:22:42 +0800299 pm8001_ha->port[i].wide_port_phymap = 0;
300 pm8001_ha->port[i].port_attached = 0;
301 pm8001_ha->port[i].port_state = 0;
302 INIT_LIST_HEAD(&pm8001_ha->port[i].list);
303 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800304
jack wangdbf9bfe2009-10-14 16:19:21 +0800305 /* MPI Memory region 1 for AAP Event Log for fw */
306 pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
307 pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
308 pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE;
309 pm8001_ha->memoryMap.region[AAP1].alignment = 32;
310
311 /* MPI Memory region 2 for IOP Event Log for fw */
312 pm8001_ha->memoryMap.region[IOP].num_elements = 1;
313 pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE;
314 pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
315 pm8001_ha->memoryMap.region[IOP].alignment = 32;
316
Viswas G05c6c022020-10-05 20:20:08 +0530317 for (i = 0; i < count; i++) {
318 circularQ = &pm8001_ha->inbnd_q_tbl[i];
319 spin_lock_init(&circularQ->iq_lock);
Sakthivel Ke590adf2013-02-27 20:25:25 +0530320 /* MPI Memory region 3 for consumer Index of inbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530321 pm8001_ha->memoryMap.region[ci_offset+i].num_elements = 1;
322 pm8001_ha->memoryMap.region[ci_offset+i].element_size = 4;
323 pm8001_ha->memoryMap.region[ci_offset+i].total_len = 4;
324 pm8001_ha->memoryMap.region[ci_offset+i].alignment = 4;
jack wangdbf9bfe2009-10-14 16:19:21 +0800325
Sakthivel Ke590adf2013-02-27 20:25:25 +0530326 if ((ent->driver_data) != chip_8001) {
327 /* MPI Memory region 5 inbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530328 pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530329 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530330 pm8001_ha->memoryMap.region[ib_offset+i].element_size
331 = 128;
332 pm8001_ha->memoryMap.region[ib_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530333 PM8001_MPI_QUEUE * 128;
Viswas G05c6c022020-10-05 20:20:08 +0530334 pm8001_ha->memoryMap.region[ib_offset+i].alignment
335 = 128;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530336 } else {
Viswas G05c6c022020-10-05 20:20:08 +0530337 pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530338 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530339 pm8001_ha->memoryMap.region[ib_offset+i].element_size
340 = 64;
341 pm8001_ha->memoryMap.region[ib_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530342 PM8001_MPI_QUEUE * 64;
Viswas G05c6c022020-10-05 20:20:08 +0530343 pm8001_ha->memoryMap.region[ib_offset+i].alignment = 64;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530344 }
345 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800346
Viswas G05c6c022020-10-05 20:20:08 +0530347 for (i = 0; i < count; i++) {
Sakthivel Ke590adf2013-02-27 20:25:25 +0530348 /* MPI Memory region 4 for producer Index of outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530349 pm8001_ha->memoryMap.region[pi_offset+i].num_elements = 1;
350 pm8001_ha->memoryMap.region[pi_offset+i].element_size = 4;
351 pm8001_ha->memoryMap.region[pi_offset+i].total_len = 4;
352 pm8001_ha->memoryMap.region[pi_offset+i].alignment = 4;
jack wangdbf9bfe2009-10-14 16:19:21 +0800353
Sakthivel Ke590adf2013-02-27 20:25:25 +0530354 if (ent->driver_data != chip_8001) {
355 /* MPI Memory region 6 Outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530356 pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530357 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530358 pm8001_ha->memoryMap.region[ob_offset+i].element_size
359 = 128;
360 pm8001_ha->memoryMap.region[ob_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530361 PM8001_MPI_QUEUE * 128;
Viswas G05c6c022020-10-05 20:20:08 +0530362 pm8001_ha->memoryMap.region[ob_offset+i].alignment
363 = 128;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530364 } else {
365 /* MPI Memory region 6 Outbound queues */
Viswas G05c6c022020-10-05 20:20:08 +0530366 pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530367 PM8001_MPI_QUEUE;
Viswas G05c6c022020-10-05 20:20:08 +0530368 pm8001_ha->memoryMap.region[ob_offset+i].element_size
369 = 64;
370 pm8001_ha->memoryMap.region[ob_offset+i].total_len =
Sakthivel Ke590adf2013-02-27 20:25:25 +0530371 PM8001_MPI_QUEUE * 64;
Viswas G05c6c022020-10-05 20:20:08 +0530372 pm8001_ha->memoryMap.region[ob_offset+i].alignment = 64;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530373 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800374
Sakthivel Ke590adf2013-02-27 20:25:25 +0530375 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800376 /* Memory region write DMA*/
377 pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
378 pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
379 pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
jack wangdbf9bfe2009-10-14 16:19:21 +0800380
Sakthivel K1c75a672013-03-19 18:06:40 +0530381 /* Memory region for fw flash */
382 pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
383
Anand Kumar Santhanamd078b512013-09-04 12:57:00 +0530384 pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
385 pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
386 pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
387 pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
Viswas G05c6c022020-10-05 20:20:08 +0530388 for (i = 0; i < pm8001_ha->max_memcnt; i++) {
Joe Perches9aed5782020-11-23 20:36:04 -0800389 struct mpi_mem *region = &pm8001_ha->memoryMap.region[i];
390
jack wangdbf9bfe2009-10-14 16:19:21 +0800391 if (pm8001_mem_alloc(pm8001_ha->pdev,
Joe Perches9aed5782020-11-23 20:36:04 -0800392 &region->virt_ptr,
393 &region->phys_addr,
394 &region->phys_addr_hi,
395 &region->phys_addr_lo,
396 region->total_len,
397 region->alignment) != 0) {
398 pm8001_dbg(pm8001_ha, FAIL, "Mem%d alloc failed\n", i);
399 goto err_out;
jack wangdbf9bfe2009-10-14 16:19:21 +0800400 }
401 }
402
Viswas G27bc43b2020-10-05 20:20:09 +0530403 /* Memory region for devices*/
404 pm8001_ha->devices = kzalloc(PM8001_MAX_DEVICES
405 * sizeof(struct pm8001_device), GFP_KERNEL);
406 if (!pm8001_ha->devices) {
407 rc = -ENOMEM;
408 goto err_out_nodev;
409 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800410 for (i = 0; i < PM8001_MAX_DEVICES; i++) {
James Bottomleyaa9f8322013-05-07 14:44:06 -0700411 pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
jack wangdbf9bfe2009-10-14 16:19:21 +0800412 pm8001_ha->devices[i].id = i;
413 pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
Viswas G4a2efd42020-11-02 22:25:26 +0530414 atomic_set(&pm8001_ha->devices[i].running_req, 0);
jack wangdbf9bfe2009-10-14 16:19:21 +0800415 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800416 pm8001_ha->flags = PM8001F_INIT_TIME;
417 /* Initialize tags */
418 pm8001_tag_init(pm8001_ha);
419 return 0;
Viswas G27bc43b2020-10-05 20:20:09 +0530420
Viswas G05c6c022020-10-05 20:20:08 +0530421err_out_shost:
422 scsi_remove_host(pm8001_ha->shost);
Viswas G27bc43b2020-10-05 20:20:09 +0530423err_out_nodev:
424 for (i = 0; i < pm8001_ha->max_memcnt; i++) {
425 if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
426 pci_free_consistent(pm8001_ha->pdev,
427 (pm8001_ha->memoryMap.region[i].total_len +
428 pm8001_ha->memoryMap.region[i].alignment),
429 pm8001_ha->memoryMap.region[i].virt_ptr,
430 pm8001_ha->memoryMap.region[i].phys_addr);
431 }
432 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800433err_out:
434 return 1;
435}
436
437/**
438 * pm8001_ioremap - remap the pci high physical address to kernal virtual
439 * address so that we can access them.
440 * @pm8001_ha:our hba structure.
441 */
442static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
443{
444 u32 bar;
445 u32 logicalBar = 0;
446 struct pci_dev *pdev;
447
448 pdev = pm8001_ha->pdev;
449 /* map pci mem (PMC pci base 0-3)*/
Denis Efremovc9c13ba2019-09-28 02:43:08 +0300450 for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
jack wangdbf9bfe2009-10-14 16:19:21 +0800451 /*
452 ** logical BARs for SPC:
453 ** bar 0 and 1 - logical BAR0
454 ** bar 2 and 3 - logical BAR1
455 ** bar4 - logical BAR2
456 ** bar5 - logical BAR3
457 ** Skip the appropriate assignments:
458 */
459 if ((bar == 1) || (bar == 3))
460 continue;
461 if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
462 pm8001_ha->io_mem[logicalBar].membase =
463 pci_resource_start(pdev, bar);
jack wangdbf9bfe2009-10-14 16:19:21 +0800464 pm8001_ha->io_mem[logicalBar].memsize =
465 pci_resource_len(pdev, bar);
466 pm8001_ha->io_mem[logicalBar].memvirtaddr =
467 ioremap(pm8001_ha->io_mem[logicalBar].membase,
468 pm8001_ha->io_mem[logicalBar].memsize);
akshatzen95652f92021-01-09 18:08:44 +0530469 if (!pm8001_ha->io_mem[logicalBar].memvirtaddr) {
470 pm8001_dbg(pm8001_ha, INIT,
471 "Failed to ioremap bar %d, logicalBar %d",
Joe Perches1b5d2792020-11-20 15:16:09 -0800472 bar, logicalBar);
akshatzen95652f92021-01-09 18:08:44 +0530473 return -ENOMEM;
474 }
Joe Perches1b5d2792020-11-20 15:16:09 -0800475 pm8001_dbg(pm8001_ha, INIT,
476 "base addr %llx virt_addr=%llx len=%d\n",
477 (u64)pm8001_ha->io_mem[logicalBar].membase,
478 (u64)(unsigned long)
479 pm8001_ha->io_mem[logicalBar].memvirtaddr,
480 pm8001_ha->io_mem[logicalBar].memsize);
jack wangdbf9bfe2009-10-14 16:19:21 +0800481 } else {
482 pm8001_ha->io_mem[logicalBar].membase = 0;
483 pm8001_ha->io_mem[logicalBar].memsize = 0;
Saurav Girepunje62fb8b32019-10-25 19:20:14 +0530484 pm8001_ha->io_mem[logicalBar].memvirtaddr = NULL;
jack wangdbf9bfe2009-10-14 16:19:21 +0800485 }
486 logicalBar++;
487 }
488 return 0;
489}
490
491/**
492 * pm8001_pci_alloc - initialize our ha card structure
493 * @pdev: pci device.
494 * @ent: ent
495 * @shost: scsi host struct which has been initialized before.
496 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800497static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
Sakthivel Ke590adf2013-02-27 20:25:25 +0530498 const struct pci_device_id *ent,
499 struct Scsi_Host *shost)
500
jack wangdbf9bfe2009-10-14 16:19:21 +0800501{
502 struct pm8001_hba_info *pm8001_ha;
503 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530504 int j;
jack wangdbf9bfe2009-10-14 16:19:21 +0800505
506 pm8001_ha = sha->lldd_ha;
507 if (!pm8001_ha)
508 return NULL;
509
510 pm8001_ha->pdev = pdev;
511 pm8001_ha->dev = &pdev->dev;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530512 pm8001_ha->chip_id = ent->driver_data;
jack wangdbf9bfe2009-10-14 16:19:21 +0800513 pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
514 pm8001_ha->irq = pdev->irq;
515 pm8001_ha->sas = sha;
516 pm8001_ha->shost = shost;
517 pm8001_ha->id = pm8001_id++;
peter chang73706722019-11-14 15:39:02 +0530518 pm8001_ha->logging_level = logging_level;
Deepak Ukeydba2cc02020-03-16 13:19:05 +0530519 pm8001_ha->non_fatal_count = 0;
peter chang3e253d92019-11-14 15:39:07 +0530520 if (link_rate >= 1 && link_rate <= 15)
521 pm8001_ha->link_rate = (link_rate << 8);
522 else {
523 pm8001_ha->link_rate = LINKRATE_15 | LINKRATE_30 |
524 LINKRATE_60 | LINKRATE_120;
Joe Perches1b5d2792020-11-20 15:16:09 -0800525 pm8001_dbg(pm8001_ha, FAIL,
526 "Setting link rate to default value\n");
peter chang3e253d92019-11-14 15:39:07 +0530527 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800528 sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
Sakthivel Kf74cf272013-02-27 20:27:43 +0530529 /* IOMB size is 128 for 8088/89 controllers */
530 if (pm8001_ha->chip_id != chip_8001)
531 pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
532 else
533 pm8001_ha->iomb_size = IOMB_SIZE_SPC;
534
jack wangdbf9bfe2009-10-14 16:19:21 +0800535#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530536 /* Tasklet for non msi-x interrupt handler */
Benjamin Roodc913df32015-10-30 10:53:31 -0400537 if ((!pdev->msix_cap || !pci_msi_enabled())
538 || (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530539 tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
540 (unsigned long)&(pm8001_ha->irq_vector[0]));
541 else
542 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
543 tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
544 (unsigned long)&(pm8001_ha->irq_vector[j]));
jack wangdbf9bfe2009-10-14 16:19:21 +0800545#endif
akshatzen95652f92021-01-09 18:08:44 +0530546 if (pm8001_ioremap(pm8001_ha))
547 goto failed_pci_alloc;
Sakthivel Ke590adf2013-02-27 20:25:25 +0530548 if (!pm8001_alloc(pm8001_ha, ent))
jack wangdbf9bfe2009-10-14 16:19:21 +0800549 return pm8001_ha;
akshatzen95652f92021-01-09 18:08:44 +0530550failed_pci_alloc:
jack wangdbf9bfe2009-10-14 16:19:21 +0800551 pm8001_free(pm8001_ha);
552 return NULL;
553}
554
555/**
556 * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
557 * @pdev: pci device.
558 */
559static int pci_go_44(struct pci_dev *pdev)
560{
561 int rc;
562
Christoph Hellwigf73bdeb2018-10-10 19:59:50 +0200563 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
564 if (rc) {
565 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
566 if (rc)
jack wangdbf9bfe2009-10-14 16:19:21 +0800567 dev_printk(KERN_ERR, &pdev->dev,
568 "32-bit DMA enable failed\n");
jack wangdbf9bfe2009-10-14 16:19:21 +0800569 }
570 return rc;
571}
572
573/**
574 * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
575 * @shost: scsi host which has been allocated outside.
576 * @chip_info: our ha struct.
577 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800578static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
579 const struct pm8001_chip_info *chip_info)
jack wangdbf9bfe2009-10-14 16:19:21 +0800580{
581 int phy_nr, port_nr;
582 struct asd_sas_phy **arr_phy;
583 struct asd_sas_port **arr_port;
584 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
585
586 phy_nr = chip_info->n_phy;
587 port_nr = phy_nr;
588 memset(sha, 0x00, sizeof(*sha));
589 arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
590 if (!arr_phy)
591 goto exit;
592 arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
593 if (!arr_port)
594 goto exit_free2;
595
596 sha->sas_phy = arr_phy;
597 sha->sas_port = arr_port;
598 sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
599 if (!sha->lldd_ha)
600 goto exit_free1;
601
602 shost->transportt = pm8001_stt;
603 shost->max_id = PM8001_MAX_DEVICES;
604 shost->max_lun = 8;
605 shost->max_channel = 0;
606 shost->unique_id = pm8001_id;
607 shost->max_cmd_len = 16;
608 shost->can_queue = PM8001_CAN_QUEUE;
609 shost->cmd_per_lun = 32;
610 return 0;
611exit_free1:
612 kfree(arr_port);
613exit_free2:
614 kfree(arr_phy);
615exit:
616 return -1;
617}
618
619/**
620 * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
621 * @shost: scsi host which has been allocated outside
622 * @chip_info: our ha struct.
623 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800624static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
625 const struct pm8001_chip_info *chip_info)
jack wangdbf9bfe2009-10-14 16:19:21 +0800626{
627 int i = 0;
628 struct pm8001_hba_info *pm8001_ha;
629 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
630
631 pm8001_ha = sha->lldd_ha;
632 for (i = 0; i < chip_info->n_phy; i++) {
633 sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
634 sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
Viswas G6c85e4b2017-10-18 11:39:09 +0530635 sha->sas_phy[i]->sas_addr =
636 (u8 *)&pm8001_ha->phy[i].dev_sas_addr;
jack wangdbf9bfe2009-10-14 16:19:21 +0800637 }
638 sha->sas_ha_name = DRV_NAME;
639 sha->dev = pm8001_ha->dev;
Viswas G6c85e4b2017-10-18 11:39:09 +0530640 sha->strict_wide_ports = 1;
jack wangdbf9bfe2009-10-14 16:19:21 +0800641 sha->lldd_module = THIS_MODULE;
642 sha->sas_addr = &pm8001_ha->sas_addr[0];
643 sha->num_phys = chip_info->n_phy;
jack wangdbf9bfe2009-10-14 16:19:21 +0800644 sha->core.shost = shost;
645}
646
647/**
648 * pm8001_init_sas_add - initialize sas address
Lee Jonese802fc42020-07-13 08:46:42 +0100649 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +0800650 *
651 * Currently we just set the fixed SAS address to our HBA,for manufacture,
652 * it should read from the EEPROM
653 */
654static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
655{
Sakthivel Ka33a0152013-03-19 18:07:35 +0530656 u8 i, j;
Viswas G6c85e4b2017-10-18 11:39:09 +0530657 u8 sas_add[8];
jack wangdbf9bfe2009-10-14 16:19:21 +0800658#ifdef PM8001_READ_VPD
Sakthivel Ka33a0152013-03-19 18:07:35 +0530659 /* For new SPC controllers WWN is stored in flash vpd
660 * For SPC/SPCve controllers WWN is stored in EEPROM
661 * For Older SPC WWN is stored in NVMD
662 */
jack wangdbf9bfe2009-10-14 16:19:21 +0800663 DECLARE_COMPLETION_ONSTACK(completion);
jack wang7c8356d2009-12-07 17:23:08 +0800664 struct pm8001_ioctl_payload payload;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530665 u16 deviceid;
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530666 int rc;
667
Sakthivel Ka33a0152013-03-19 18:07:35 +0530668 pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
jack wangdbf9bfe2009-10-14 16:19:21 +0800669 pm8001_ha->nvmd_completion = &completion;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530670
671 if (pm8001_ha->chip_id == chip_8001) {
Bradley Grovef49d2132013-12-19 10:50:56 -0500672 if (deviceid == 0x8081 || deviceid == 0x0042) {
Sakthivel Ka33a0152013-03-19 18:07:35 +0530673 payload.minor_function = 4;
Viswas G9b889842020-03-16 13:19:06 +0530674 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530675 } else {
676 payload.minor_function = 0;
Viswas G9b889842020-03-16 13:19:06 +0530677 payload.rd_length = 128;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530678 }
Benjamin Rood10efa462015-11-02 15:39:23 -0500679 } else if ((pm8001_ha->chip_id == chip_8070 ||
680 pm8001_ha->chip_id == chip_8072) &&
681 pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
682 payload.minor_function = 4;
Viswas G9b889842020-03-16 13:19:06 +0530683 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530684 } else {
685 payload.minor_function = 1;
Viswas G9b889842020-03-16 13:19:06 +0530686 payload.rd_length = 4096;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530687 }
688 payload.offset = 0;
Viswas G9b889842020-03-16 13:19:06 +0530689 payload.func_specific = kzalloc(payload.rd_length, GFP_KERNEL);
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530690 if (!payload.func_specific) {
Joe Perches1b5d2792020-11-20 15:16:09 -0800691 pm8001_dbg(pm8001_ha, INIT, "mem alloc fail\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530692 return;
693 }
694 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
695 if (rc) {
696 kfree(payload.func_specific);
Joe Perches1b5d2792020-11-20 15:16:09 -0800697 pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530698 return;
699 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800700 wait_for_completion(&completion);
Sakthivel Ka33a0152013-03-19 18:07:35 +0530701
702 for (i = 0, j = 0; i <= 7; i++, j++) {
703 if (pm8001_ha->chip_id == chip_8001) {
704 if (deviceid == 0x8081)
705 pm8001_ha->sas_addr[j] =
706 payload.func_specific[0x704 + i];
Bradley Grovef49d2132013-12-19 10:50:56 -0500707 else if (deviceid == 0x0042)
708 pm8001_ha->sas_addr[j] =
709 payload.func_specific[0x010 + i];
Benjamin Rood10efa462015-11-02 15:39:23 -0500710 } else if ((pm8001_ha->chip_id == chip_8070 ||
711 pm8001_ha->chip_id == chip_8072) &&
712 pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
713 pm8001_ha->sas_addr[j] =
714 payload.func_specific[0x010 + i];
Sakthivel Ka33a0152013-03-19 18:07:35 +0530715 } else
716 pm8001_ha->sas_addr[j] =
717 payload.func_specific[0x804 + i];
718 }
Viswas G6c85e4b2017-10-18 11:39:09 +0530719 memcpy(sas_add, pm8001_ha->sas_addr, SAS_ADDR_SIZE);
jack wangdbf9bfe2009-10-14 16:19:21 +0800720 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
Viswas G6c85e4b2017-10-18 11:39:09 +0530721 if (i && ((i % 4) == 0))
722 sas_add[7] = sas_add[7] + 4;
Sakthivel Ka33a0152013-03-19 18:07:35 +0530723 memcpy(&pm8001_ha->phy[i].dev_sas_addr,
Viswas G6c85e4b2017-10-18 11:39:09 +0530724 sas_add, SAS_ADDR_SIZE);
Joe Perches1b5d2792020-11-20 15:16:09 -0800725 pm8001_dbg(pm8001_ha, INIT, "phy %d sas_addr = %016llx\n", i,
726 pm8001_ha->phy[i].dev_sas_addr);
jack wangdbf9bfe2009-10-14 16:19:21 +0800727 }
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530728 kfree(payload.func_specific);
jack wangdbf9bfe2009-10-14 16:19:21 +0800729#else
730 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
jack wang7c8356d2009-12-07 17:23:08 +0800731 pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
jack wangdbf9bfe2009-10-14 16:19:21 +0800732 pm8001_ha->phy[i].dev_sas_addr =
733 cpu_to_be64((u64)
734 (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
735 }
736 memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
737 SAS_ADDR_SIZE);
738#endif
739}
740
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530741/*
742 * pm8001_get_phy_settings_info : Read phy setting values.
743 * @pm8001_ha : our hba.
744 */
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200745static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530746{
747
748#ifdef PM8001_READ_VPD
749 /*OPTION ROM FLASH read for the SPC cards */
750 DECLARE_COMPLETION_ONSTACK(completion);
751 struct pm8001_ioctl_payload payload;
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530752 int rc;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530753
754 pm8001_ha->nvmd_completion = &completion;
755 /* SAS ADDRESS read from flash / EEPROM */
756 payload.minor_function = 6;
757 payload.offset = 0;
Viswas G9b889842020-03-16 13:19:06 +0530758 payload.rd_length = 4096;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530759 payload.func_specific = kzalloc(4096, GFP_KERNEL);
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200760 if (!payload.func_specific)
761 return -ENOMEM;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530762 /* Read phy setting values from flash */
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530763 rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
764 if (rc) {
765 kfree(payload.func_specific);
Joe Perches1b5d2792020-11-20 15:16:09 -0800766 pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
Tomas Henzl5b4ce882014-07-09 17:21:11 +0530767 return -ENOMEM;
768 }
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530769 wait_for_completion(&completion);
770 pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200771 kfree(payload.func_specific);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530772#endif
Maurizio Lombardif2c6f182014-06-17 13:15:40 +0200773 return 0;
Anand Kumar Santhanam27909402013-09-18 13:02:44 +0530774}
775
Benjamin Roodc5614df2015-10-30 10:53:28 -0400776struct pm8001_mpi3_phy_pg_trx_config {
777 u32 LaneLosCfg;
778 u32 LanePgaCfg1;
779 u32 LanePisoCfg1;
780 u32 LanePisoCfg2;
781 u32 LanePisoCfg3;
782 u32 LanePisoCfg4;
783 u32 LanePisoCfg5;
784 u32 LanePisoCfg6;
785 u32 LaneBctCtrl;
786};
787
788/**
789 * pm8001_get_internal_phy_settings : Retrieves the internal PHY settings
790 * @pm8001_ha : our adapter
791 * @phycfg : PHY config page to populate
792 */
793static
794void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
795 struct pm8001_mpi3_phy_pg_trx_config *phycfg)
796{
797 phycfg->LaneLosCfg = 0x00000132;
798 phycfg->LanePgaCfg1 = 0x00203949;
799 phycfg->LanePisoCfg1 = 0x000000FF;
800 phycfg->LanePisoCfg2 = 0xFF000001;
801 phycfg->LanePisoCfg3 = 0xE7011300;
802 phycfg->LanePisoCfg4 = 0x631C40C0;
803 phycfg->LanePisoCfg5 = 0xF8102036;
804 phycfg->LanePisoCfg6 = 0xF74A1000;
805 phycfg->LaneBctCtrl = 0x00FB33F8;
806}
807
808/**
809 * pm8001_get_external_phy_settings : Retrieves the external PHY settings
810 * @pm8001_ha : our adapter
811 * @phycfg : PHY config page to populate
812 */
813static
814void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
815 struct pm8001_mpi3_phy_pg_trx_config *phycfg)
816{
817 phycfg->LaneLosCfg = 0x00000132;
818 phycfg->LanePgaCfg1 = 0x00203949;
819 phycfg->LanePisoCfg1 = 0x000000FF;
820 phycfg->LanePisoCfg2 = 0xFF000001;
821 phycfg->LanePisoCfg3 = 0xE7011300;
822 phycfg->LanePisoCfg4 = 0x63349140;
823 phycfg->LanePisoCfg5 = 0xF8102036;
824 phycfg->LanePisoCfg6 = 0xF80D9300;
825 phycfg->LaneBctCtrl = 0x00FB33F8;
826}
827
828/**
829 * pm8001_get_phy_mask : Retrieves the mask that denotes if a PHY is int/ext
830 * @pm8001_ha : our adapter
831 * @phymask : The PHY mask
832 */
833static
834void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
835{
836 switch (pm8001_ha->pdev->subsystem_device) {
837 case 0x0070: /* H1280 - 8 external 0 internal */
838 case 0x0072: /* H12F0 - 16 external 0 internal */
839 *phymask = 0x0000;
840 break;
841
842 case 0x0071: /* H1208 - 0 external 8 internal */
843 case 0x0073: /* H120F - 0 external 16 internal */
844 *phymask = 0xFFFF;
845 break;
846
847 case 0x0080: /* H1244 - 4 external 4 internal */
848 *phymask = 0x00F0;
849 break;
850
851 case 0x0081: /* H1248 - 4 external 8 internal */
852 *phymask = 0x0FF0;
853 break;
854
855 case 0x0082: /* H1288 - 8 external 8 internal */
856 *phymask = 0xFF00;
857 break;
858
859 default:
Joe Perches1b5d2792020-11-20 15:16:09 -0800860 pm8001_dbg(pm8001_ha, INIT,
861 "Unknown subsystem device=0x%.04x\n",
862 pm8001_ha->pdev->subsystem_device);
Benjamin Roodc5614df2015-10-30 10:53:28 -0400863 }
864}
865
866/**
867 * pm8001_set_phy_settings_ven_117c_12Gb : Configure ATTO 12Gb PHY settings
868 * @pm8001_ha : our adapter
869 */
870static
871int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
872{
873 struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
874 struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
875 int phymask = 0;
876 int i = 0;
877
878 memset(&phycfg_int, 0, sizeof(phycfg_int));
879 memset(&phycfg_ext, 0, sizeof(phycfg_ext));
880
881 pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
882 pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
883 pm8001_get_phy_mask(pm8001_ha, &phymask);
884
885 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
886 if (phymask & (1 << i)) {/* Internal PHY */
887 pm8001_set_phy_profile_single(pm8001_ha, i,
888 sizeof(phycfg_int) / sizeof(u32),
889 (u32 *)&phycfg_int);
890
891 } else { /* External PHY */
892 pm8001_set_phy_profile_single(pm8001_ha, i,
893 sizeof(phycfg_ext) / sizeof(u32),
894 (u32 *)&phycfg_ext);
895 }
896 }
897
898 return 0;
899}
900
Benjamin Roodda2dd612015-10-30 10:53:24 -0400901/**
902 * pm8001_configure_phy_settings : Configures PHY settings based on vendor ID.
903 * @pm8001_ha : our hba.
904 */
905static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
906{
907 switch (pm8001_ha->pdev->subsystem_vendor) {
908 case PCI_VENDOR_ID_ATTO:
Benjamin Roodc5614df2015-10-30 10:53:28 -0400909 if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
910 return 0;
911 else
912 return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
913
Benjamin Roodda2dd612015-10-30 10:53:24 -0400914 case PCI_VENDOR_ID_ADAPTEC2:
915 case 0:
916 return 0;
917
918 default:
919 return pm8001_get_phy_settings_info(pm8001_ha);
920 }
921}
922
jack wangdbf9bfe2009-10-14 16:19:21 +0800923#ifdef PM8001_USE_MSIX
924/**
925 * pm8001_setup_msix - enable MSI-X interrupt
Lee Jonese802fc42020-07-13 08:46:42 +0100926 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +0800927 */
Sakthivel K1245ee52013-03-19 17:56:17 +0530928static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
jack wangdbf9bfe2009-10-14 16:19:21 +0800929{
Sakthivel K1245ee52013-03-19 17:56:17 +0530930 u32 number_of_intr;
Viswas G05c6c022020-10-05 20:20:08 +0530931 int rc, cpu_online_count;
932 unsigned int allocated_irq_vectors;
Sakthivel K1245ee52013-03-19 17:56:17 +0530933
934 /* SPCv controllers supports 64 msi-x */
935 if (pm8001_ha->chip_id == chip_8001) {
936 number_of_intr = 1;
Sakthivel K1245ee52013-03-19 17:56:17 +0530937 } else {
938 number_of_intr = PM8001_MAX_MSIX_VEC;
Sakthivel K1245ee52013-03-19 17:56:17 +0530939 }
940
Viswas G05c6c022020-10-05 20:20:08 +0530941 cpu_online_count = num_online_cpus();
942 number_of_intr = min_t(int, cpu_online_count, number_of_intr);
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100943 rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr,
944 number_of_intr, PCI_IRQ_MSIX);
Viswas G05c6c022020-10-05 20:20:08 +0530945 allocated_irq_vectors = rc;
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100946 if (rc < 0)
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200947 return rc;
Viswas G05c6c022020-10-05 20:20:08 +0530948
949 /* Assigns the number of interrupts */
950 number_of_intr = min_t(int, allocated_irq_vectors, number_of_intr);
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100951 pm8001_ha->number_of_intr = number_of_intr;
Sakthivel K1245ee52013-03-19 17:56:17 +0530952
Viswas G05c6c022020-10-05 20:20:08 +0530953 /* Maximum queue number updating in HBA structure */
954 pm8001_ha->max_q_num = number_of_intr;
955
Joe Perches1b5d2792020-11-20 15:16:09 -0800956 pm8001_dbg(pm8001_ha, INIT,
957 "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
958 rc, pm8001_ha->number_of_intr);
Vikram Auradkard384be62020-03-16 13:19:02 +0530959 return 0;
960}
Sakthivel K1245ee52013-03-19 17:56:17 +0530961
Vikram Auradkard384be62020-03-16 13:19:02 +0530962static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
963{
964 u32 i = 0, j = 0;
965 int flag = 0, rc = 0;
966
967 if (pm8001_ha->chip_id != chip_8001)
968 flag &= ~IRQF_SHARED;
969
Joe Perches1b5d2792020-11-20 15:16:09 -0800970 pm8001_dbg(pm8001_ha, INIT,
971 "pci_enable_msix request number of intr %d\n",
972 pm8001_ha->number_of_intr);
Vikram Auradkard384be62020-03-16 13:19:02 +0530973
974 for (i = 0; i < pm8001_ha->number_of_intr; i++) {
Vikram Auradkar72954932019-11-14 15:39:09 +0530975 snprintf(pm8001_ha->intr_drvname[i],
976 sizeof(pm8001_ha->intr_drvname[0]),
977 "%s-%d", pm8001_ha->name, i);
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200978 pm8001_ha->irq_vector[i].irq_id = i;
979 pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530980
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100981 rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200982 pm8001_interrupt_handler_msix, flag,
Vikram Auradkar72954932019-11-14 15:39:09 +0530983 pm8001_ha->intr_drvname[i],
984 &(pm8001_ha->irq_vector[i]));
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200985 if (rc) {
986 for (j = 0; j < i; j++) {
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100987 free_irq(pci_irq_vector(pm8001_ha->pdev, i),
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +0530988 &(pm8001_ha->irq_vector[i]));
jack wangdbf9bfe2009-10-14 16:19:21 +0800989 }
Christoph Hellwiga76037f2017-02-01 15:11:07 +0100990 pci_free_irq_vectors(pm8001_ha->pdev);
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200991 break;
jack wangdbf9bfe2009-10-14 16:19:21 +0800992 }
993 }
Alexander Gordeevb4d511e2014-07-16 20:05:22 +0200994
jack wangdbf9bfe2009-10-14 16:19:21 +0800995 return rc;
996}
997#endif
998
Vikram Auradkard384be62020-03-16 13:19:02 +0530999static u32 pm8001_setup_irq(struct pm8001_hba_info *pm8001_ha)
1000{
1001 struct pci_dev *pdev;
1002
1003 pdev = pm8001_ha->pdev;
1004
1005#ifdef PM8001_USE_MSIX
1006 if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
1007 return pm8001_setup_msix(pm8001_ha);
Joe Perches1b5d2792020-11-20 15:16:09 -08001008 pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
Vikram Auradkard384be62020-03-16 13:19:02 +05301009#endif
1010 return 0;
1011}
1012
jack wangdbf9bfe2009-10-14 16:19:21 +08001013/**
1014 * pm8001_request_irq - register interrupt
Lee Jonese802fc42020-07-13 08:46:42 +01001015 * @pm8001_ha: our ha struct.
jack wangdbf9bfe2009-10-14 16:19:21 +08001016 */
1017static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
1018{
1019 struct pci_dev *pdev;
jack_wang97ee2082009-11-05 22:33:51 +08001020 int rc;
jack wangdbf9bfe2009-10-14 16:19:21 +08001021
1022 pdev = pm8001_ha->pdev;
1023
1024#ifdef PM8001_USE_MSIX
Benjamin Roodc913df32015-10-30 10:53:31 -04001025 if (pdev->msix_cap && pci_msi_enabled())
Vikram Auradkard384be62020-03-16 13:19:02 +05301026 return pm8001_request_msix(pm8001_ha);
Sakthivel K1245ee52013-03-19 17:56:17 +05301027 else {
Joe Perches1b5d2792020-11-20 15:16:09 -08001028 pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001029 goto intx;
Sakthivel K1245ee52013-03-19 17:56:17 +05301030 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001031#endif
1032
1033intx:
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001034 /* initialize the INT-X interrupt */
Benjamin Roodc913df32015-10-30 10:53:31 -04001035 pm8001_ha->irq_vector[0].irq_id = 0;
1036 pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
Sakthivel K1245ee52013-03-19 17:56:17 +05301037 rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
Vikram Auradkar72954932019-11-14 15:39:09 +05301038 pm8001_ha->name, SHOST_TO_SAS_HA(pm8001_ha->shost));
jack wangdbf9bfe2009-10-14 16:19:21 +08001039 return rc;
1040}
1041
1042/**
1043 * pm8001_pci_probe - probe supported device
1044 * @pdev: pci device which kernel has been prepared for.
1045 * @ent: pci device id
1046 *
1047 * This function is the main initialization function, when register a new
1048 * pci driver it is invoked, all struct an hardware initilization should be done
1049 * here, also, register interrupt
1050 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001051static int pm8001_pci_probe(struct pci_dev *pdev,
1052 const struct pci_device_id *ent)
jack wangdbf9bfe2009-10-14 16:19:21 +08001053{
1054 unsigned int rc;
1055 u32 pci_reg;
Sakthivel K1245ee52013-03-19 17:56:17 +05301056 u8 i = 0;
jack wangdbf9bfe2009-10-14 16:19:21 +08001057 struct pm8001_hba_info *pm8001_ha;
1058 struct Scsi_Host *shost = NULL;
1059 const struct pm8001_chip_info *chip;
Peter Changb40f2882020-03-16 13:19:04 +05301060 struct sas_ha_struct *sha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001061
1062 dev_printk(KERN_INFO, &pdev->dev,
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301063 "pm80xx: driver version %s\n", DRV_VERSION);
jack wangdbf9bfe2009-10-14 16:19:21 +08001064 rc = pci_enable_device(pdev);
1065 if (rc)
1066 goto err_out_enable;
1067 pci_set_master(pdev);
1068 /*
1069 * Enable pci slot busmaster by setting pci command register.
1070 * This is required by FW for Cyclone card.
1071 */
1072
1073 pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
1074 pci_reg |= 0x157;
1075 pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
1076 rc = pci_request_regions(pdev, DRV_NAME);
1077 if (rc)
1078 goto err_out_disable;
1079 rc = pci_go_44(pdev);
1080 if (rc)
1081 goto err_out_regions;
1082
1083 shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
1084 if (!shost) {
1085 rc = -ENOMEM;
1086 goto err_out_regions;
1087 }
1088 chip = &pm8001_chips[ent->driver_data];
Peter Changb40f2882020-03-16 13:19:04 +05301089 sha = kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
1090 if (!sha) {
jack wangdbf9bfe2009-10-14 16:19:21 +08001091 rc = -ENOMEM;
1092 goto err_out_free_host;
1093 }
Peter Changb40f2882020-03-16 13:19:04 +05301094 SHOST_TO_SAS_HA(shost) = sha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001095
1096 rc = pm8001_prep_sas_ha_init(shost, chip);
1097 if (rc) {
1098 rc = -ENOMEM;
1099 goto err_out_free;
1100 }
1101 pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
Sakthivel Ke590adf2013-02-27 20:25:25 +05301102 /* ent->driver variable is used to differentiate between controllers */
1103 pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001104 if (!pm8001_ha) {
1105 rc = -ENOMEM;
1106 goto err_out_free;
1107 }
Peter Changb40f2882020-03-16 13:19:04 +05301108
Sakthivel Kf5860992013-04-17 16:37:02 +05301109 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001110 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301111 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001112 pm8001_dbg(pm8001_ha, FAIL,
1113 "chip_init failed [ret: %d]\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08001114 goto err_out_ha_free;
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301115 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001116
Viswas G5a141312020-10-05 20:20:10 +05301117 rc = pm8001_init_ccb_tag(pm8001_ha, shost, pdev);
1118 if (rc)
1119 goto err_out_enable;
1120
jack wangdbf9bfe2009-10-14 16:19:21 +08001121 rc = scsi_add_host(shost, &pdev->dev);
1122 if (rc)
1123 goto err_out_ha_free;
jack wangdbf9bfe2009-10-14 16:19:21 +08001124
Sakthivel Kf74cf272013-02-27 20:27:43 +05301125 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
Sakthivel K1245ee52013-03-19 17:56:17 +05301126 if (pm8001_ha->chip_id != chip_8001) {
1127 for (i = 1; i < pm8001_ha->number_of_intr; i++)
1128 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
Sakthivel Ka6cb3d02013-03-19 18:08:40 +05301129 /* setup thermal configuration. */
1130 pm80xx_set_thermal_config(pm8001_ha);
Sakthivel K1245ee52013-03-19 17:56:17 +05301131 }
1132
jack wangdbf9bfe2009-10-14 16:19:21 +08001133 pm8001_init_sas_add(pm8001_ha);
Anand Kumar Santhanam27909402013-09-18 13:02:44 +05301134 /* phy setting support for motherboard controller */
Zhang Qilong97031cc2020-12-05 19:55:51 +08001135 rc = pm8001_configure_phy_settings(pm8001_ha);
1136 if (rc)
Benjamin Roodda2dd612015-10-30 10:53:24 -04001137 goto err_out_shost;
1138
jack wangdbf9bfe2009-10-14 16:19:21 +08001139 pm8001_post_sas_ha_init(shost, chip);
1140 rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
Peter Changb40f2882020-03-16 13:19:04 +05301141 if (rc) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001142 pm8001_dbg(pm8001_ha, FAIL,
1143 "sas_register_ha failed [ret: %d]\n", rc);
jack wangdbf9bfe2009-10-14 16:19:21 +08001144 goto err_out_shost;
Peter Changb40f2882020-03-16 13:19:04 +05301145 }
1146 list_add_tail(&pm8001_ha->list, &hba_list);
jack wangdbf9bfe2009-10-14 16:19:21 +08001147 scsi_scan_host(pm8001_ha->shost);
Deepak Ukeycd135752018-09-11 14:18:02 +05301148 pm8001_ha->flags = PM8001F_RUN_TIME;
jack wangdbf9bfe2009-10-14 16:19:21 +08001149 return 0;
1150
1151err_out_shost:
1152 scsi_remove_host(pm8001_ha->shost);
1153err_out_ha_free:
1154 pm8001_free(pm8001_ha);
1155err_out_free:
Peter Changb40f2882020-03-16 13:19:04 +05301156 kfree(sha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001157err_out_free_host:
Pan Bianbc1371c2017-08-08 19:40:30 +08001158 scsi_host_put(shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001159err_out_regions:
1160 pci_release_regions(pdev);
1161err_out_disable:
1162 pci_disable_device(pdev);
1163err_out_enable:
1164 return rc;
1165}
1166
Viswas G5a141312020-10-05 20:20:10 +05301167/*
1168 * pm8001_init_ccb_tag - allocate memory to CCB and tag.
1169 * @pm8001_ha: our hba card information.
1170 * @shost: scsi host which has been allocated outside.
1171 */
1172static int
1173pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost,
1174 struct pci_dev *pdev)
1175{
1176 int i = 0;
1177 u32 max_out_io, ccb_count;
1178 u32 can_queue;
1179
1180 max_out_io = pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io;
1181 ccb_count = min_t(int, PM8001_MAX_CCB, max_out_io);
1182
1183 /* Update to the scsi host*/
1184 can_queue = ccb_count - PM8001_RESERVE_SLOT;
1185 shost->can_queue = can_queue;
1186
1187 pm8001_ha->tags = kzalloc(ccb_count, GFP_KERNEL);
1188 if (!pm8001_ha->tags)
1189 goto err_out;
1190
1191 /* Memory region for ccb_info*/
Xu Wang27a34942020-11-20 08:36:48 +00001192 pm8001_ha->ccb_info =
Viswas G5a141312020-10-05 20:20:10 +05301193 kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL);
1194 if (!pm8001_ha->ccb_info) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001195 pm8001_dbg(pm8001_ha, FAIL,
1196 "Unable to allocate memory for ccb\n");
Viswas G5a141312020-10-05 20:20:10 +05301197 goto err_out_noccb;
1198 }
1199 for (i = 0; i < ccb_count; i++) {
1200 pm8001_ha->ccb_info[i].buf_prd = pci_alloc_consistent(pdev,
1201 sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
1202 &pm8001_ha->ccb_info[i].ccb_dma_handle);
1203 if (!pm8001_ha->ccb_info[i].buf_prd) {
Joe Perches1b5d2792020-11-20 15:16:09 -08001204 pm8001_dbg(pm8001_ha, FAIL,
1205 "pm80xx: ccb prd memory allocation error\n");
Viswas G5a141312020-10-05 20:20:10 +05301206 goto err_out;
1207 }
1208 pm8001_ha->ccb_info[i].task = NULL;
1209 pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
1210 pm8001_ha->ccb_info[i].device = NULL;
1211 ++pm8001_ha->tags_num;
1212 }
1213 return 0;
1214
1215err_out_noccb:
1216 kfree(pm8001_ha->devices);
1217err_out:
1218 return -ENOMEM;
1219}
1220
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001221static void pm8001_pci_remove(struct pci_dev *pdev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001222{
1223 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
1224 struct pm8001_hba_info *pm8001_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301225 int i, j;
jack wangdbf9bfe2009-10-14 16:19:21 +08001226 pm8001_ha = sha->lldd_ha;
jack wangdbf9bfe2009-10-14 16:19:21 +08001227 sas_unregister_ha(sha);
1228 sas_remove_host(pm8001_ha->shost);
1229 list_del(&pm8001_ha->list);
Sakthivel K1245ee52013-03-19 17:56:17 +05301230 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301231 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001232
1233#ifdef PM8001_USE_MSIX
1234 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001235 synchronize_irq(pci_irq_vector(pdev, i));
jack wangdbf9bfe2009-10-14 16:19:21 +08001236 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001237 free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1238 pci_free_irq_vectors(pdev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001239#else
1240 free_irq(pm8001_ha->irq, sha);
1241#endif
1242#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301243 /* For non-msix and msix interrupts */
Benjamin Roodc913df32015-10-30 10:53:31 -04001244 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1245 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301246 tasklet_kill(&pm8001_ha->tasklet[0]);
1247 else
1248 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1249 tasklet_kill(&pm8001_ha->tasklet[j]);
jack wangdbf9bfe2009-10-14 16:19:21 +08001250#endif
Pan Bianbc1371c2017-08-08 19:40:30 +08001251 scsi_host_put(pm8001_ha->shost);
jack wangdbf9bfe2009-10-14 16:19:21 +08001252 pm8001_free(pm8001_ha);
1253 kfree(sha->sas_phy);
1254 kfree(sha->sas_port);
1255 kfree(sha);
1256 pci_release_regions(pdev);
1257 pci_disable_device(pdev);
1258}
1259
1260/**
1261 * pm8001_pci_suspend - power management suspend main entry point
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301262 * @dev: Device struct
jack wangdbf9bfe2009-10-14 16:19:21 +08001263 *
1264 * Returns 0 success, anything else error.
1265 */
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301266static int __maybe_unused pm8001_pci_suspend(struct device *dev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001267{
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301268 struct pci_dev *pdev = to_pci_dev(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001269 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301270 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301271 int i, j;
Bradley Grove9f176092014-07-09 17:20:23 +05301272 sas_suspend_ha(sha);
Tejun Heo429305e2011-01-24 14:57:29 +01001273 flush_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +08001274 scsi_block_requests(pm8001_ha->shost);
Yijing Wangc8a2ba32013-06-27 15:02:49 +08001275 if (!pdev->pm_cap) {
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301276 dev_err(dev, " PCI PM not supported\n");
jack wangdbf9bfe2009-10-14 16:19:21 +08001277 return -ENODEV;
1278 }
Sakthivel K1245ee52013-03-19 17:56:17 +05301279 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
Sakthivel Kf5860992013-04-17 16:37:02 +05301280 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001281#ifdef PM8001_USE_MSIX
1282 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001283 synchronize_irq(pci_irq_vector(pdev, i));
jack wangdbf9bfe2009-10-14 16:19:21 +08001284 for (i = 0; i < pm8001_ha->number_of_intr; i++)
Christoph Hellwiga76037f2017-02-01 15:11:07 +01001285 free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1286 pci_free_irq_vectors(pdev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001287#else
1288 free_irq(pm8001_ha->irq, sha);
1289#endif
1290#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301291 /* For non-msix and msix interrupts */
Benjamin Roodc913df32015-10-30 10:53:31 -04001292 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1293 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301294 tasklet_kill(&pm8001_ha->tasklet[0]);
1295 else
1296 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1297 tasklet_kill(&pm8001_ha->tasklet[j]);
jack wangdbf9bfe2009-10-14 16:19:21 +08001298#endif
Joe Perches2ce6e202020-11-23 20:36:03 -08001299 pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, entering "
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301300 "suspended state\n", pdev,
1301 pm8001_ha->name);
jack wangdbf9bfe2009-10-14 16:19:21 +08001302 return 0;
1303}
1304
1305/**
1306 * pm8001_pci_resume - power management resume main entry point
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301307 * @dev: Device struct
jack wangdbf9bfe2009-10-14 16:19:21 +08001308 *
1309 * Returns 0 success, anything else error.
1310 */
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301311static int __maybe_unused pm8001_pci_resume(struct device *dev)
jack wangdbf9bfe2009-10-14 16:19:21 +08001312{
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301313 struct pci_dev *pdev = to_pci_dev(dev);
jack wangdbf9bfe2009-10-14 16:19:21 +08001314 struct sas_ha_struct *sha = pci_get_drvdata(pdev);
1315 struct pm8001_hba_info *pm8001_ha;
1316 int rc;
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301317 u8 i = 0, j;
jack wangdbf9bfe2009-10-14 16:19:21 +08001318 u32 device_state;
Bradley Grove9f176092014-07-09 17:20:23 +05301319 DECLARE_COMPLETION_ONSTACK(completion);
jack wangdbf9bfe2009-10-14 16:19:21 +08001320 pm8001_ha = sha->lldd_ha;
1321 device_state = pdev->current_state;
1322
Joe Perches2ce6e202020-11-23 20:36:03 -08001323 pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, resuming from previous operating state [D%d]\n",
Joe Perches89eddb42020-11-20 15:16:10 -08001324 pdev, pm8001_ha->name, device_state);
jack wangdbf9bfe2009-10-14 16:19:21 +08001325
jack wangdbf9bfe2009-10-14 16:19:21 +08001326 rc = pci_go_44(pdev);
1327 if (rc)
1328 goto err_out_disable;
Bradley Grove9f176092014-07-09 17:20:23 +05301329 sas_prep_resume_ha(sha);
Sakthivel Kf5860992013-04-17 16:37:02 +05301330 /* chip soft rst only for spc */
1331 if (pm8001_ha->chip_id == chip_8001) {
1332 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
Joe Perches1b5d2792020-11-20 15:16:09 -08001333 pm8001_dbg(pm8001_ha, INIT, "chip soft reset successful\n");
Sakthivel Kf5860992013-04-17 16:37:02 +05301334 }
jack wangdbf9bfe2009-10-14 16:19:21 +08001335 rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
1336 if (rc)
1337 goto err_out_disable;
Sakthivel K1245ee52013-03-19 17:56:17 +05301338
1339 /* disable all the interrupt bits */
1340 PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
1341
jack wangdbf9bfe2009-10-14 16:19:21 +08001342 rc = pm8001_request_irq(pm8001_ha);
1343 if (rc)
1344 goto err_out_disable;
Sakthivel K1245ee52013-03-19 17:56:17 +05301345#ifdef PM8001_USE_TASKLET
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301346 /* Tasklet for non msi-x interrupt handler */
Benjamin Roodc913df32015-10-30 10:53:31 -04001347 if ((!pdev->msix_cap || !pci_msi_enabled()) ||
1348 (pm8001_ha->chip_id == chip_8001))
Nikith Ganigarakoppal6cd60b32013-11-11 15:28:14 +05301349 tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
1350 (unsigned long)&(pm8001_ha->irq_vector[0]));
1351 else
1352 for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
1353 tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
1354 (unsigned long)&(pm8001_ha->irq_vector[j]));
Sakthivel K1245ee52013-03-19 17:56:17 +05301355#endif
Sakthivel Kf74cf272013-02-27 20:27:43 +05301356 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
Sakthivel K1245ee52013-03-19 17:56:17 +05301357 if (pm8001_ha->chip_id != chip_8001) {
1358 for (i = 1; i < pm8001_ha->number_of_intr; i++)
1359 PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
1360 }
Benjamin Roodb650a882015-11-02 15:42:29 -05001361
1362 /* Chip documentation for the 8070 and 8072 SPCv */
1363 /* states that a 500ms minimum delay is required */
Julia Lawall014e8ba2016-05-17 16:38:44 +02001364 /* before issuing commands. Otherwise, the firmware */
Benjamin Roodb650a882015-11-02 15:42:29 -05001365 /* will enter an unrecoverable state. */
1366
1367 if (pm8001_ha->chip_id == chip_8070 ||
1368 pm8001_ha->chip_id == chip_8072) {
1369 mdelay(500);
1370 }
1371
1372 /* Spin up the PHYs */
1373
Bradley Grove9f176092014-07-09 17:20:23 +05301374 pm8001_ha->flags = PM8001F_RUN_TIME;
1375 for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
1376 pm8001_ha->phy[i].enable_completion = &completion;
1377 PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
1378 wait_for_completion(&completion);
1379 }
1380 sas_resume_ha(sha);
jack wangdbf9bfe2009-10-14 16:19:21 +08001381 return 0;
1382
1383err_out_disable:
1384 scsi_remove_host(pm8001_ha->shost);
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301385
jack wangdbf9bfe2009-10-14 16:19:21 +08001386 return rc;
1387}
1388
Sakthivel Ke5742102013-04-17 16:26:36 +05301389/* update of pci device, vendor id and driver data with
1390 * unique value for each of the controller
1391 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001392static struct pci_device_id pm8001_pci_table[] = {
Sakthivel Ke5742102013-04-17 16:26:36 +05301393 { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
Suresh Thiagarajand8571b12015-02-12 12:04:37 +05301394 { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
1395 { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
Bradley Grovef49d2132013-12-19 10:50:56 -05001396 { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
Sakthivel Ke5742102013-04-17 16:26:36 +05301397 /* Support for SPC/SPCv/SPCve controllers */
1398 { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
1399 { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
1400 { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
1401 { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
1402 { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
1403 { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
1404 { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
1405 { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
1406 { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301407 { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
1408 { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
1409 { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
1410 { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
1411 { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
1412 { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
Sakthivel Ke5742102013-04-17 16:26:36 +05301413 { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
1414 PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
1415 { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
1416 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
1417 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1418 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
1419 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1420 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
1421 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1422 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
1423 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1424 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
1425 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1426 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
1427 { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
1428 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
1429 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1430 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
1431 { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
1432 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301433 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1434 PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
1435 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1436 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
1437 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1438 PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
1439 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1440 PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
1441 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1442 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
1443 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1444 PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
1445 { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
1446 PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
1447 { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
1448 PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
1449 { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
1450 PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
Benjamin Roodb2dece42015-10-30 10:53:26 -04001451 { PCI_VENDOR_ID_ATTO, 0x8070,
1452 PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
1453 { PCI_VENDOR_ID_ATTO, 0x8070,
1454 PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
1455 { PCI_VENDOR_ID_ATTO, 0x8072,
1456 PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
1457 { PCI_VENDOR_ID_ATTO, 0x8072,
1458 PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
1459 { PCI_VENDOR_ID_ATTO, 0x8070,
1460 PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
1461 { PCI_VENDOR_ID_ATTO, 0x8072,
1462 PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
1463 { PCI_VENDOR_ID_ATTO, 0x8072,
1464 PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
jack wangdbf9bfe2009-10-14 16:19:21 +08001465 {} /* terminate list */
1466};
1467
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301468static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
1469 pm8001_pci_suspend,
1470 pm8001_pci_resume);
1471
jack wangdbf9bfe2009-10-14 16:19:21 +08001472static struct pci_driver pm8001_pci_driver = {
1473 .name = DRV_NAME,
1474 .id_table = pm8001_pci_table,
1475 .probe = pm8001_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001476 .remove = pm8001_pci_remove,
Vaibhav Gupta47c37c42020-11-02 22:17:20 +05301477 .driver.pm = &pm8001_pci_pm_ops,
jack wangdbf9bfe2009-10-14 16:19:21 +08001478};
1479
1480/**
1481 * pm8001_init - initialize scsi transport template
1482 */
1483static int __init pm8001_init(void)
1484{
Tejun Heo429305e2011-01-24 14:57:29 +01001485 int rc = -ENOMEM;
1486
Sakthivel Ka70b8fc2013-03-19 18:07:09 +05301487 pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
Tejun Heo429305e2011-01-24 14:57:29 +01001488 if (!pm8001_wq)
1489 goto err;
1490
jack wangdbf9bfe2009-10-14 16:19:21 +08001491 pm8001_id = 0;
1492 pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
1493 if (!pm8001_stt)
Tejun Heo429305e2011-01-24 14:57:29 +01001494 goto err_wq;
jack wangdbf9bfe2009-10-14 16:19:21 +08001495 rc = pci_register_driver(&pm8001_pci_driver);
1496 if (rc)
Tejun Heo429305e2011-01-24 14:57:29 +01001497 goto err_tp;
jack wangdbf9bfe2009-10-14 16:19:21 +08001498 return 0;
Tejun Heo429305e2011-01-24 14:57:29 +01001499
1500err_tp:
jack wangdbf9bfe2009-10-14 16:19:21 +08001501 sas_release_transport(pm8001_stt);
Tejun Heo429305e2011-01-24 14:57:29 +01001502err_wq:
1503 destroy_workqueue(pm8001_wq);
1504err:
jack wangdbf9bfe2009-10-14 16:19:21 +08001505 return rc;
1506}
1507
1508static void __exit pm8001_exit(void)
1509{
1510 pci_unregister_driver(&pm8001_pci_driver);
1511 sas_release_transport(pm8001_stt);
Tejun Heo429305e2011-01-24 14:57:29 +01001512 destroy_workqueue(pm8001_wq);
jack wangdbf9bfe2009-10-14 16:19:21 +08001513}
1514
1515module_init(pm8001_init);
1516module_exit(pm8001_exit);
1517
1518MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301519MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
1520MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
Nikith Ganigarakoppal94f33c12013-11-13 15:35:23 +05301521MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
Sakthivel Ke5742102013-04-17 16:26:36 +05301522MODULE_DESCRIPTION(
Benjamin Rooddb9d4032015-10-30 10:53:25 -04001523 "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
Anand Kumar Santhanama9a923e2013-09-03 15:09:42 +05301524 "SAS/SATA controller driver");
jack wangdbf9bfe2009-10-14 16:19:21 +08001525MODULE_VERSION(DRV_VERSION);
1526MODULE_LICENSE("GPL");
1527MODULE_DEVICE_TABLE(pci, pm8001_pci_table);
1528