]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/scsi/hisi_sas/hisi_sas_main.c
hisi_sas: Add scsi host registration
[mirror_ubuntu-eoan-kernel.git] / drivers / scsi / hisi_sas / hisi_sas_main.c
CommitLineData
e8899fad
JG
1/*
2 * Copyright (c) 2015 Linaro Ltd.
3 * Copyright (c) 2015 Hisilicon Limited.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 */
11
12#include "hisi_sas.h"
13#define DRV_NAME "hisi_sas"
14
15static struct scsi_transport_template *hisi_sas_stt;
16
7eb7869f
JG
17static struct scsi_host_template hisi_sas_sht = {
18 .module = THIS_MODULE,
19 .name = DRV_NAME,
20 .queuecommand = sas_queuecommand,
21 .target_alloc = sas_target_alloc,
22 .slave_configure = sas_slave_configure,
23 .change_queue_depth = sas_change_queue_depth,
24 .bios_param = sas_bios_param,
25 .can_queue = 1,
26 .this_id = -1,
27 .sg_tablesize = SG_ALL,
28 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
29 .use_clustering = ENABLE_CLUSTERING,
30 .eh_device_reset_handler = sas_eh_device_reset_handler,
31 .eh_bus_reset_handler = sas_eh_bus_reset_handler,
32 .target_destroy = sas_target_destroy,
33 .ioctl = sas_ioctl,
34};
35
e8899fad
JG
36static struct sas_domain_function_template hisi_sas_transport_ops = {
37};
38
7eb7869f
JG
39static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,
40 const struct hisi_sas_hw *hw)
41{
42 struct Scsi_Host *shost;
43 struct hisi_hba *hisi_hba;
44 struct device *dev = &pdev->dev;
45
46 shost = scsi_host_alloc(&hisi_sas_sht, sizeof(*hisi_hba));
47 if (!shost)
48 goto err_out;
49 hisi_hba = shost_priv(shost);
50
51 hisi_hba->hw = hw;
52 hisi_hba->pdev = pdev;
53 hisi_hba->shost = shost;
54 SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
55
56 return shost;
57err_out:
58 dev_err(dev, "shost alloc failed\n");
59 return NULL;
60}
61
62int hisi_sas_probe(struct platform_device *pdev,
63 const struct hisi_sas_hw *hw)
64{
65 struct Scsi_Host *shost;
66 struct hisi_hba *hisi_hba;
67 struct device *dev = &pdev->dev;
68 struct asd_sas_phy **arr_phy;
69 struct asd_sas_port **arr_port;
70 struct sas_ha_struct *sha;
71 int rc, phy_nr, port_nr, i;
72
73 shost = hisi_sas_shost_alloc(pdev, hw);
74 if (!shost) {
75 rc = -ENOMEM;
76 goto err_out_ha;
77 }
78
79 sha = SHOST_TO_SAS_HA(shost);
80 hisi_hba = shost_priv(shost);
81 platform_set_drvdata(pdev, sha);
82 hisi_hba->n_phy = HISI_SAS_MAX_PHYS;
83 phy_nr = port_nr = hisi_hba->n_phy;
84
85 arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
86 arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
87 if (!arr_phy || !arr_port)
88 return -ENOMEM;
89
90 sha->sas_phy = arr_phy;
91 sha->sas_port = arr_port;
92 sha->core.shost = shost;
93 sha->lldd_ha = hisi_hba;
94
95 shost->transportt = hisi_sas_stt;
96 shost->max_id = HISI_SAS_MAX_DEVICES;
97 shost->max_lun = ~0;
98 shost->max_channel = 1;
99 shost->max_cmd_len = 16;
100 shost->sg_tablesize = min_t(u16, SG_ALL, HISI_SAS_SGE_PAGE_CNT);
101 shost->can_queue = HISI_SAS_COMMAND_ENTRIES;
102 shost->cmd_per_lun = HISI_SAS_COMMAND_ENTRIES;
103
104 sha->sas_ha_name = DRV_NAME;
105 sha->dev = &hisi_hba->pdev->dev;
106 sha->lldd_module = THIS_MODULE;
107 sha->sas_addr = &hisi_hba->sas_addr[0];
108 sha->num_phys = hisi_hba->n_phy;
109 sha->core.shost = hisi_hba->shost;
110
111 for (i = 0; i < hisi_hba->n_phy; i++) {
112 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
113 sha->sas_port[i] = &hisi_hba->port[i].sas_port;
114 }
115
116 rc = scsi_add_host(shost, &pdev->dev);
117 if (rc)
118 goto err_out_ha;
119
120 rc = sas_register_ha(sha);
121 if (rc)
122 goto err_out_register_ha;
123
124 scsi_scan_host(shost);
125
126 return 0;
127
128err_out_register_ha:
129 scsi_remove_host(shost);
130err_out_ha:
131 kfree(shost);
132 return rc;
133}
134EXPORT_SYMBOL_GPL(hisi_sas_probe);
135
e8899fad
JG
136static __init int hisi_sas_init(void)
137{
138 pr_info("hisi_sas: driver version %s\n", DRV_VERSION);
139
140 hisi_sas_stt = sas_domain_attach_transport(&hisi_sas_transport_ops);
141 if (!hisi_sas_stt)
142 return -ENOMEM;
143
144 return 0;
145}
146
147static __exit void hisi_sas_exit(void)
148{
149 sas_release_transport(hisi_sas_stt);
150}
151
152module_init(hisi_sas_init);
153module_exit(hisi_sas_exit);
154
155MODULE_VERSION(DRV_VERSION);
156MODULE_LICENSE("GPL");
157MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
158MODULE_DESCRIPTION("HISILICON SAS controller driver");
159MODULE_ALIAS("platform:" DRV_NAME);