2 * Copyright (c) 2015 Linaro Ltd.
3 * Copyright (c) 2015 Hisilicon Limited.
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.
15 #include <linux/dmapool.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/module.h>
18 #include <linux/of_address.h>
19 #include <linux/of_irq.h>
20 #include <linux/platform_device.h>
21 #include <linux/regmap.h>
22 #include <scsi/libsas.h>
24 #define DRV_VERSION "v1.0"
26 #define HISI_SAS_MAX_PHYS 9
27 #define HISI_SAS_MAX_QUEUES 32
28 #define HISI_SAS_QUEUE_SLOTS 512
29 #define HISI_SAS_MAX_ITCT_ENTRIES 4096
30 #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
31 #define HISI_SAS_COMMAND_ENTRIES 8192
33 #define HISI_SAS_STATUS_BUF_SZ \
34 (sizeof(struct hisi_sas_err_record) + 1024)
35 #define HISI_SAS_COMMAND_TABLE_SZ \
36 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
38 #define HISI_SAS_NAME_LEN 32
46 struct hisi_hba *hisi_hba;
47 struct hisi_sas_port *port;
48 struct asd_sas_phy sas_phy;
49 struct sas_identify identify;
50 struct timer_list timer;
51 u64 port_id; /* from hw */
58 enum sas_linkrate minimum_linkrate;
59 enum sas_linkrate maximum_linkrate;
62 struct hisi_sas_port {
63 struct asd_sas_port sas_port;
66 struct list_head list;
70 struct hisi_hba *hisi_hba;
74 struct hisi_sas_device {
75 enum sas_device_type dev_type;
80 struct hisi_sas_slot {
84 int (*hw_init)(struct hisi_hba *hisi_hba);
85 int complete_hdr_size;
89 /* This must be the first element, used by SHOST_TO_SAS_HA */
90 struct sas_ha_struct *p;
92 struct platform_device *pdev;
96 u32 ctrl_reset_sts_reg;
97 u32 ctrl_clock_ena_reg;
98 u8 sas_addr[SAS_ADDR_SIZE];
103 struct timer_list timer;
104 struct workqueue_struct *wq;
106 int slot_index_count;
107 unsigned long *slot_index_tags;
110 struct sas_ha_struct sha;
111 struct Scsi_Host *shost;
113 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
114 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
115 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
120 struct dma_pool *sge_page_pool;
121 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
122 struct dma_pool *command_table_pool;
123 struct dma_pool *status_buffer_pool;
124 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
125 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
126 void *complete_hdr[HISI_SAS_MAX_QUEUES];
127 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
128 struct hisi_sas_initial_fis *initial_fis;
129 dma_addr_t initial_fis_dma;
130 struct hisi_sas_itct *itct;
132 struct hisi_sas_iost *iost;
134 struct hisi_sas_breakpoint *breakpoint;
135 dma_addr_t breakpoint_dma;
136 struct hisi_sas_breakpoint *sata_breakpoint;
137 dma_addr_t sata_breakpoint_dma;
138 struct hisi_sas_slot *slot_info;
139 const struct hisi_sas_hw *hw; /* Low level hw interface */
142 /* Generic HW DMA host memory structures */
143 /* Delivery queue header */
144 struct hisi_sas_cmd_hdr {
155 __le32 transfer_tags;
158 __le32 data_transfer_len;
161 __le32 first_burst_num;
170 __le64 cmd_table_addr;
173 __le64 sts_buffer_addr;
176 __le64 prd_table_addr;
179 __le64 dif_prd_table_addr;
182 struct hisi_sas_itct {
188 __le64 qw_sata_ncq0_3;
189 __le64 qw_sata_ncq7_4;
190 __le64 qw_sata_ncq11_8;
191 __le64 qw_sata_ncq15_12;
192 __le64 qw_sata_ncq19_16;
193 __le64 qw_sata_ncq23_20;
194 __le64 qw_sata_ncq27_24;
195 __le64 qw_sata_ncq31_28;
196 __le64 qw_non_ncq_iptt;
201 struct hisi_sas_iost {
208 struct hisi_sas_err_record {
213 __le32 trans_tx_fail_type;
216 __le32 trans_rx_fail_type;
222 struct hisi_sas_initial_fis {
223 struct hisi_sas_err_record err_record;
224 struct dev_to_host_fis fis;
228 struct hisi_sas_breakpoint {
229 u8 data[128]; /*io128 byte*/
232 struct hisi_sas_sge {
240 struct hisi_sas_command_table_smp {
244 struct hisi_sas_command_table_stp {
245 struct host_to_dev_fis command_fis;
247 u8 atapi_cdb[ATAPI_CDB_LEN];
250 #define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
251 struct hisi_sas_sge_page {
252 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
255 struct hisi_sas_command_table_ssp {
256 struct ssp_frame_hdr hdr;
259 struct ssp_command_iu task;
262 struct ssp_tmf_iu ssp_task;
263 struct xfer_rdy_iu xfer_rdy;
264 struct ssp_response_iu ssp_res;
268 union hisi_sas_command_table {
269 struct hisi_sas_command_table_ssp ssp;
270 struct hisi_sas_command_table_smp smp;
271 struct hisi_sas_command_table_stp stp;
273 extern int hisi_sas_probe(struct platform_device *pdev,
274 const struct hisi_sas_hw *ops);
275 extern int hisi_sas_remove(struct platform_device *pdev);