Skip to content

Commit e21fe3a

Browse files
John Garrymartinkpetersen
authored andcommitted
scsi: hisi_sas: add initialisation for v3 pci-based controller
Add the code to initialise the controller which is based on pci device in hisi_sas_v3_hw.c The core controller routines are still in hisi_sas_main.c; some common initialisation functions are also exported from hisi_sas_main.c For pci-based controller, the device properties, like phy count and sas address are read from the firmware, same as platform device-based controller. Signed-off-by: John Garry <john.garry@huawei.com> Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 92f61e3 commit e21fe3a

3 files changed

Lines changed: 172 additions & 6 deletions

File tree

drivers/scsi/hisi_sas/hisi_sas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ union hisi_sas_command_table {
366366
struct hisi_sas_command_table_stp stp;
367367
};
368368

369+
extern struct scsi_transport_template *hisi_sas_stt;
370+
extern struct scsi_host_template *hisi_sas_sht;
371+
372+
extern void hisi_sas_init_add(struct hisi_hba *hisi_hba);
373+
extern int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost);
374+
extern void hisi_sas_free(struct hisi_hba *hisi_hba);
369375
extern u8 hisi_sas_get_ata_protocol(u8 cmd, int direction);
370376
extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
371377
extern void hisi_sas_sata_done(struct sas_task *task,

drivers/scsi/hisi_sas/hisi_sas_main.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,10 @@ void hisi_sas_rescan_topology(struct hisi_hba *hisi_hba, u32 old_state,
14761476
}
14771477
EXPORT_SYMBOL_GPL(hisi_sas_rescan_topology);
14781478

1479-
static struct scsi_transport_template *hisi_sas_stt;
1479+
struct scsi_transport_template *hisi_sas_stt;
1480+
EXPORT_SYMBOL_GPL(hisi_sas_stt);
14801481

1481-
static struct scsi_host_template hisi_sas_sht = {
1482+
static struct scsi_host_template _hisi_sas_sht = {
14821483
.module = THIS_MODULE,
14831484
.name = DRV_NAME,
14841485
.queuecommand = sas_queuecommand,
@@ -1498,6 +1499,8 @@ static struct scsi_host_template hisi_sas_sht = {
14981499
.target_destroy = sas_target_destroy,
14991500
.ioctl = sas_ioctl,
15001501
};
1502+
struct scsi_host_template *hisi_sas_sht = &_hisi_sas_sht;
1503+
EXPORT_SYMBOL_GPL(hisi_sas_sht);
15011504

15021505
static struct sas_domain_function_template hisi_sas_transport_ops = {
15031506
.lldd_dev_found = hisi_sas_dev_found,
@@ -1545,7 +1548,7 @@ void hisi_sas_init_mem(struct hisi_hba *hisi_hba)
15451548
}
15461549
EXPORT_SYMBOL_GPL(hisi_sas_init_mem);
15471550

1548-
static int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
1551+
int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
15491552
{
15501553
struct device *dev = hisi_hba->dev;
15511554
int i, s, max_command_entries = hisi_hba->hw->max_command_entries;
@@ -1664,8 +1667,9 @@ static int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
16641667
err_out:
16651668
return -ENOMEM;
16661669
}
1670+
EXPORT_SYMBOL_GPL(hisi_sas_alloc);
16671671

1668-
static void hisi_sas_free(struct hisi_hba *hisi_hba)
1672+
void hisi_sas_free(struct hisi_hba *hisi_hba)
16691673
{
16701674
struct device *dev = hisi_hba->dev;
16711675
int i, s, max_command_entries = hisi_hba->hw->max_command_entries;
@@ -1720,6 +1724,7 @@ static void hisi_sas_free(struct hisi_hba *hisi_hba)
17201724
if (hisi_hba->wq)
17211725
destroy_workqueue(hisi_hba->wq);
17221726
}
1727+
EXPORT_SYMBOL_GPL(hisi_sas_free);
17231728

17241729
static void hisi_sas_rst_work_handler(struct work_struct *work)
17251730
{
@@ -1805,7 +1810,7 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
18051810
struct hisi_hba *hisi_hba;
18061811
struct device *dev = &pdev->dev;
18071812

1808-
shost = scsi_host_alloc(&hisi_sas_sht, sizeof(*hisi_hba));
1813+
shost = scsi_host_alloc(hisi_sas_sht, sizeof(*hisi_hba));
18091814
if (!shost) {
18101815
dev_err(dev, "scsi host alloc failed\n");
18111816
return NULL;
@@ -1847,7 +1852,7 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
18471852
return NULL;
18481853
}
18491854

1850-
static void hisi_sas_init_add(struct hisi_hba *hisi_hba)
1855+
void hisi_sas_init_add(struct hisi_hba *hisi_hba)
18511856
{
18521857
int i;
18531858

@@ -1856,6 +1861,7 @@ static void hisi_sas_init_add(struct hisi_hba *hisi_hba)
18561861
hisi_hba->sas_addr,
18571862
SAS_ADDR_SIZE);
18581863
}
1864+
EXPORT_SYMBOL_GPL(hisi_sas_init_add);
18591865

18601866
int hisi_sas_probe(struct platform_device *pdev,
18611867
const struct hisi_sas_hw *hw)

drivers/scsi/hisi_sas/hisi_sas_v3_hw.c

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,168 @@
1111
#include "hisi_sas.h"
1212
#define DRV_NAME "hisi_sas_v3_hw"
1313

14+
static const struct hisi_sas_hw hisi_sas_v3_hw = {
15+
};
16+
17+
static struct Scsi_Host *
18+
hisi_sas_shost_alloc_pci(struct pci_dev *pdev)
19+
{
20+
struct Scsi_Host *shost;
21+
struct hisi_hba *hisi_hba;
22+
struct device *dev = &pdev->dev;
23+
24+
shost = scsi_host_alloc(hisi_sas_sht, sizeof(*hisi_hba));
25+
if (!shost)
26+
goto err_out;
27+
hisi_hba = shost_priv(shost);
28+
29+
hisi_hba->hw = &hisi_sas_v3_hw;
30+
hisi_hba->pci_dev = pdev;
31+
hisi_hba->dev = dev;
32+
hisi_hba->shost = shost;
33+
SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
34+
35+
init_timer(&hisi_hba->timer);
36+
37+
if (hisi_sas_get_fw_info(hisi_hba) < 0)
38+
goto err_out;
39+
40+
if (hisi_sas_alloc(hisi_hba, shost)) {
41+
hisi_sas_free(hisi_hba);
42+
goto err_out;
43+
}
44+
45+
return shost;
46+
err_out:
47+
dev_err(dev, "shost alloc failed\n");
48+
return NULL;
49+
}
50+
1451
static int
1552
hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1653
{
54+
struct Scsi_Host *shost;
55+
struct hisi_hba *hisi_hba;
56+
struct device *dev = &pdev->dev;
57+
struct asd_sas_phy **arr_phy;
58+
struct asd_sas_port **arr_port;
59+
struct sas_ha_struct *sha;
60+
int rc, phy_nr, port_nr, i;
61+
62+
rc = pci_enable_device(pdev);
63+
if (rc)
64+
goto err_out;
65+
66+
pci_set_master(pdev);
67+
68+
rc = pci_request_regions(pdev, DRV_NAME);
69+
if (rc)
70+
goto err_out_disable_device;
71+
72+
if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
73+
(pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
74+
if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
75+
(pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
76+
dev_err(dev, "No usable DMA addressing method\n");
77+
rc = -EIO;
78+
goto err_out_regions;
79+
}
80+
}
81+
82+
shost = hisi_sas_shost_alloc_pci(pdev);
83+
if (!shost) {
84+
rc = -ENOMEM;
85+
goto err_out_regions;
86+
}
87+
88+
sha = SHOST_TO_SAS_HA(shost);
89+
hisi_hba = shost_priv(shost);
90+
dev_set_drvdata(dev, sha);
91+
92+
hisi_hba->regs = pcim_iomap(pdev, 5, 0);
93+
if (!hisi_hba->regs) {
94+
dev_err(dev, "cannot map register.\n");
95+
rc = -ENOMEM;
96+
goto err_out_ha;
97+
}
98+
99+
phy_nr = port_nr = hisi_hba->n_phy;
100+
101+
arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
102+
arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
103+
if (!arr_phy || !arr_port) {
104+
rc = -ENOMEM;
105+
goto err_out_ha;
106+
}
107+
108+
sha->sas_phy = arr_phy;
109+
sha->sas_port = arr_port;
110+
sha->core.shost = shost;
111+
sha->lldd_ha = hisi_hba;
112+
113+
shost->transportt = hisi_sas_stt;
114+
shost->max_id = HISI_SAS_MAX_DEVICES;
115+
shost->max_lun = ~0;
116+
shost->max_channel = 1;
117+
shost->max_cmd_len = 16;
118+
shost->sg_tablesize = min_t(u16, SG_ALL, HISI_SAS_SGE_PAGE_CNT);
119+
shost->can_queue = hisi_hba->hw->max_command_entries;
120+
shost->cmd_per_lun = hisi_hba->hw->max_command_entries;
121+
122+
sha->sas_ha_name = DRV_NAME;
123+
sha->dev = dev;
124+
sha->lldd_module = THIS_MODULE;
125+
sha->sas_addr = &hisi_hba->sas_addr[0];
126+
sha->num_phys = hisi_hba->n_phy;
127+
sha->core.shost = hisi_hba->shost;
128+
129+
for (i = 0; i < hisi_hba->n_phy; i++) {
130+
sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
131+
sha->sas_port[i] = &hisi_hba->port[i].sas_port;
132+
}
133+
134+
hisi_sas_init_add(hisi_hba);
135+
136+
rc = scsi_add_host(shost, dev);
137+
if (rc)
138+
goto err_out_ha;
139+
140+
rc = sas_register_ha(sha);
141+
if (rc)
142+
goto err_out_register_ha;
143+
144+
rc = hisi_hba->hw->hw_init(hisi_hba);
145+
if (rc)
146+
goto err_out_register_ha;
147+
148+
scsi_scan_host(shost);
149+
17150
return 0;
151+
152+
err_out_register_ha:
153+
scsi_remove_host(shost);
154+
err_out_ha:
155+
kfree(shost);
156+
err_out_regions:
157+
pci_release_regions(pdev);
158+
err_out_disable_device:
159+
pci_disable_device(pdev);
160+
err_out:
161+
return rc;
18162
}
19163

20164
static void hisi_sas_v3_remove(struct pci_dev *pdev)
21165
{
166+
struct device *dev = &pdev->dev;
167+
struct sas_ha_struct *sha = dev_get_drvdata(dev);
168+
struct hisi_hba *hisi_hba = sha->lldd_ha;
169+
170+
sas_unregister_ha(sha);
171+
sas_remove_host(sha->core.shost);
172+
173+
hisi_sas_free(hisi_hba);
174+
pci_release_regions(pdev);
175+
pci_disable_device(pdev);
22176
}
23177

24178
enum {

0 commit comments

Comments
 (0)