hisi_sas.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2015 Linaro Ltd.
 * Copyright (c) 2015 Hisilicon Limited.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

#ifndef _HISI_SAS_H_
#define _HISI_SAS_H_

15
#include <linux/acpi.h>
16 17 18 19 20
#include <linux/dmapool.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
21
#include <linux/property.h>
22
#include <linux/regmap.h>
23
#include <scsi/sas_ata.h>
24 25
#include <scsi/libsas.h>

26
#define DRV_VERSION "v1.2"
27

J
John Garry 已提交
28
#define HISI_SAS_MAX_PHYS	9
29 30
#define HISI_SAS_MAX_QUEUES	32
#define HISI_SAS_QUEUE_SLOTS 512
J
John Garry 已提交
31
#define HISI_SAS_MAX_ITCT_ENTRIES 2048
J
John Garry 已提交
32 33
#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES

34 35 36 37 38
#define HISI_SAS_STATUS_BUF_SZ \
		(sizeof(struct hisi_sas_err_record) + 1024)
#define HISI_SAS_COMMAND_TABLE_SZ \
		(((sizeof(union hisi_sas_command_table)+3)/4)*4)

J
John Garry 已提交
39
#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
J
John Garry 已提交
40
#define HISI_SAS_MAX_SMP_RESP_SZ 1028
41
#define HISI_SAS_MAX_STP_RESP_SZ 28
J
John Garry 已提交
42

J
John Garry 已提交
43 44 45 46
#define DEV_IS_EXPANDER(type) \
	((type == SAS_EDGE_EXPANDER_DEVICE) || \
	(type == SAS_FANOUT_EXPANDER_DEVICE))

J
John Garry 已提交
47
struct hisi_hba;
J
John Garry 已提交
48

49 50 51 52 53
enum {
	PORT_TYPE_SAS = (1U << 1),
	PORT_TYPE_SATA = (1U << 0),
};

J
John Garry 已提交
54 55 56 57
enum dev_status {
	HISI_SAS_DEV_NORMAL,
	HISI_SAS_DEV_EH,
};
J
John Garry 已提交
58 59 60 61 62 63 64

enum hisi_sas_dev_type {
	HISI_SAS_DEV_TYPE_STP = 0,
	HISI_SAS_DEV_TYPE_SSP,
	HISI_SAS_DEV_TYPE_SATA,
};

J
John Garry 已提交
65
struct hisi_sas_phy {
J
John Garry 已提交
66 67
	struct hisi_hba	*hisi_hba;
	struct hisi_sas_port	*port;
J
John Garry 已提交
68
	struct asd_sas_phy	sas_phy;
J
John Garry 已提交
69 70
	struct sas_identify	identify;
	struct timer_list	timer;
71
	struct work_struct	phyup_ws;
J
John Garry 已提交
72
	u64		port_id; /* from hw */
73
	u64		dev_sas_addr;
J
John Garry 已提交
74 75 76 77 78 79 80
	u64		phy_type;
	u64		frame_rcvd_size;
	u8		frame_rcvd[32];
	u8		phy_attached;
	u8		reserved[3];
	enum sas_linkrate	minimum_linkrate;
	enum sas_linkrate	maximum_linkrate;
J
John Garry 已提交
81 82 83 84
};

struct hisi_sas_port {
	struct asd_sas_port	sas_port;
J
John Garry 已提交
85 86 87
	u8	port_attached;
	u8	id; /* from hw */
	struct list_head	list;
J
John Garry 已提交
88 89
};

90 91 92 93 94
struct hisi_sas_cq {
	struct hisi_hba *hisi_hba;
	int	id;
};

J
John Garry 已提交
95 96
struct hisi_sas_device {
	enum sas_device_type	dev_type;
J
John Garry 已提交
97 98 99
	struct hisi_hba		*hisi_hba;
	struct domain_device	*sas_device;
	u64 attached_phy;
J
John Garry 已提交
100
	u64 device_id;
J
John Garry 已提交
101
	u64 running_req;
J
John Garry 已提交
102 103 104
	u8 dev_status;
};

105
struct hisi_sas_slot {
J
John Garry 已提交
106 107 108 109 110 111
	struct list_head entry;
	struct sas_task *task;
	struct hisi_sas_port	*port;
	u64	n_elem;
	int	dlvry_queue;
	int	dlvry_queue_slot;
J
John Garry 已提交
112 113
	int	cmplt_queue;
	int	cmplt_queue_slot;
J
John Garry 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127
	int	idx;
	void	*cmd_hdr;
	dma_addr_t cmd_hdr_dma;
	void	*status_buffer;
	dma_addr_t status_buffer_dma;
	void *command_table;
	dma_addr_t command_table_dma;
	struct hisi_sas_sge_page *sge_page;
	dma_addr_t sge_page_dma;
};

struct hisi_sas_tmf_task {
	u8 tmf;
	u16 tag_of_task_to_be_managed;
128 129
};

J
John Garry 已提交
130
struct hisi_sas_hw {
131
	int (*hw_init)(struct hisi_hba *hisi_hba);
J
John Garry 已提交
132 133
	void (*setup_itct)(struct hisi_hba *hisi_hba,
			   struct hisi_sas_device *device);
134
	void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
J
John Garry 已提交
135 136 137 138 139
	int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
	void (*start_delivery)(struct hisi_hba *hisi_hba);
	int (*prep_ssp)(struct hisi_hba *hisi_hba,
			struct hisi_sas_slot *slot, int is_tmf,
			struct hisi_sas_tmf_task *tmf);
J
John Garry 已提交
140 141
	int (*prep_smp)(struct hisi_hba *hisi_hba,
			struct hisi_sas_slot *slot);
142 143
	int (*prep_stp)(struct hisi_hba *hisi_hba,
			struct hisi_sas_slot *slot);
J
John Garry 已提交
144 145
	int (*slot_complete)(struct hisi_hba *hisi_hba,
			     struct hisi_sas_slot *slot, int abort);
J
John Garry 已提交
146 147 148
	void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
	void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
	void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
J
John Garry 已提交
149 150
	void (*free_device)(struct hisi_hba *hisi_hba,
			    struct hisi_sas_device *dev);
J
John Garry 已提交
151
	int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
152
	int max_command_entries;
153
	int complete_hdr_size;
J
John Garry 已提交
154 155 156 157 158 159 160
};

struct hisi_hba {
	/* This must be the first element, used by SHOST_TO_SAS_HA */
	struct sas_ha_struct *p;

	struct platform_device *pdev;
J
John Garry 已提交
161 162 163 164 165
	void __iomem *regs;
	struct regmap *ctrl;
	u32 ctrl_reset_reg;
	u32 ctrl_reset_sts_reg;
	u32 ctrl_clock_ena_reg;
J
John Garry 已提交
166 167 168
	u8 sas_addr[SAS_ADDR_SIZE];

	int n_phy;
J
John Garry 已提交
169
	int scan_finished;
J
John Garry 已提交
170
	spinlock_t lock;
J
John Garry 已提交
171

J
John Garry 已提交
172
	struct timer_list timer;
J
John Garry 已提交
173
	struct workqueue_struct *wq;
J
John Garry 已提交
174 175 176 177

	int slot_index_count;
	unsigned long *slot_index_tags;

J
John Garry 已提交
178 179 180
	/* SCSI/SAS glue */
	struct sas_ha_struct sha;
	struct Scsi_Host *shost;
181 182

	struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
J
John Garry 已提交
183 184
	struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
	struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
J
John Garry 已提交
185 186

	int	queue_count;
J
John Garry 已提交
187 188
	int	queue;
	struct hisi_sas_slot	*slot_prep;
189 190

	struct dma_pool *sge_page_pool;
J
John Garry 已提交
191
	struct hisi_sas_device	devices[HISI_SAS_MAX_DEVICES];
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	struct dma_pool *command_table_pool;
	struct dma_pool *status_buffer_pool;
	struct hisi_sas_cmd_hdr	*cmd_hdr[HISI_SAS_MAX_QUEUES];
	dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
	void *complete_hdr[HISI_SAS_MAX_QUEUES];
	dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
	struct hisi_sas_initial_fis *initial_fis;
	dma_addr_t initial_fis_dma;
	struct hisi_sas_itct *itct;
	dma_addr_t itct_dma;
	struct hisi_sas_iost *iost;
	dma_addr_t iost_dma;
	struct hisi_sas_breakpoint *breakpoint;
	dma_addr_t breakpoint_dma;
	struct hisi_sas_breakpoint *sata_breakpoint;
	dma_addr_t sata_breakpoint_dma;
	struct hisi_sas_slot	*slot_info;
J
John Garry 已提交
209 210 211
	const struct hisi_sas_hw *hw;	/* Low level hw interface */
};

J
John Garry 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
/* Generic HW DMA host memory structures */
/* Delivery queue header */
struct hisi_sas_cmd_hdr {
	/* dw0 */
	__le32 dw0;

	/* dw1 */
	__le32 dw1;

	/* dw2 */
	__le32 dw2;

	/* dw3 */
	__le32 transfer_tags;

	/* dw4 */
	__le32 data_transfer_len;

	/* dw5 */
	__le32 first_burst_num;

	/* dw6 */
	__le32 sg_len;

	/* dw7 */
	__le32 dw7;

	/* dw8-9 */
	__le64 cmd_table_addr;

	/* dw10-11 */
	__le64 sts_buffer_addr;

	/* dw12-13 */
	__le64 prd_table_addr;

	/* dw14-15 */
	__le64 dif_prd_table_addr;
};

struct hisi_sas_itct {
	__le64 qw0;
	__le64 sas_addr;
	__le64 qw2;
	__le64 qw3;
257
	__le64 qw4_15[12];
J
John Garry 已提交
258 259 260 261 262 263 264 265 266 267
};

struct hisi_sas_iost {
	__le64 qw0;
	__le64 qw1;
	__le64 qw2;
	__le64 qw3;
};

struct hisi_sas_err_record {
268
	u32	data[4];
J
John Garry 已提交
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
};

struct hisi_sas_initial_fis {
	struct hisi_sas_err_record err_record;
	struct dev_to_host_fis fis;
	u32 rsvd[3];
};

struct hisi_sas_breakpoint {
	u8	data[128];	/*io128 byte*/
};

struct hisi_sas_sge {
	__le64 addr;
	__le32 page_ctrl_0;
	__le32 page_ctrl_1;
	__le32 data_len;
	__le32 data_off;
};

struct hisi_sas_command_table_smp {
	u8 bytes[44];
};

struct hisi_sas_command_table_stp {
	struct	host_to_dev_fis command_fis;
	u8	dummy[12];
	u8	atapi_cdb[ATAPI_CDB_LEN];
};

J
John Garry 已提交
299
#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
J
John Garry 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
struct hisi_sas_sge_page {
	struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
};

struct hisi_sas_command_table_ssp {
	struct ssp_frame_hdr hdr;
	union {
		struct {
			struct ssp_command_iu task;
			u32 prot[6];
		};
		struct ssp_tmf_iu ssp_task;
		struct xfer_rdy_iu xfer_rdy;
		struct ssp_response_iu ssp_res;
	} u;
};

union hisi_sas_command_table {
	struct hisi_sas_command_table_ssp ssp;
	struct hisi_sas_command_table_smp smp;
	struct hisi_sas_command_table_stp stp;
};
J
John Garry 已提交
322 323 324
extern int hisi_sas_probe(struct platform_device *pdev,
			  const struct hisi_sas_hw *ops);
extern int hisi_sas_remove(struct platform_device *pdev);
J
John Garry 已提交
325

J
John Garry 已提交
326
extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
J
John Garry 已提交
327 328 329
extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
				    struct sas_task *task,
				    struct hisi_sas_slot *slot);
330
#endif