ionic_dev.h 11.3 KB
Newer Older
1 2 3 4 5 6
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */

#ifndef _IONIC_DEV_H_
#define _IONIC_DEV_H_

7
#include <linux/atomic.h>
8 9 10 11 12 13
#include <linux/mutex.h>
#include <linux/workqueue.h>

#include "ionic_if.h"
#include "ionic_regs.h"

14 15
#define IONIC_MAX_TX_DESC		8192
#define IONIC_MAX_RX_DESC		16384
S
Shannon Nelson 已提交
16
#define IONIC_MIN_TXRX_DESC		64
17
#define IONIC_DEF_TXRX_DESC		4096
S
Shannon Nelson 已提交
18 19
#define IONIC_RX_FILL_THRESHOLD		16
#define IONIC_RX_FILL_DIV		8
S
Shannon Nelson 已提交
20
#define IONIC_LIFS_MAX			1024
21
#define IONIC_WATCHDOG_SECS		5
22
#define IONIC_ITR_COAL_USEC_DEFAULT	64
S
Shannon Nelson 已提交
23

24 25 26 27
#define IONIC_DEV_CMD_REG_VERSION	1
#define IONIC_DEV_INFO_REG_COUNT	32
#define IONIC_DEV_CMD_REG_COUNT		32

28 29 30 31 32 33 34
struct ionic_dev_bar {
	void __iomem *vaddr;
	phys_addr_t bus_addr;
	unsigned long len;
	int res_index;
};

S
Shannon Nelson 已提交
35
#ifndef __CHECKER__
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/* Registers */
static_assert(sizeof(struct ionic_intr) == 32);

static_assert(sizeof(struct ionic_doorbell) == 8);
static_assert(sizeof(struct ionic_intr_status) == 8);
static_assert(sizeof(union ionic_dev_regs) == 4096);
static_assert(sizeof(union ionic_dev_info_regs) == 2048);
static_assert(sizeof(union ionic_dev_cmd_regs) == 2048);
static_assert(sizeof(struct ionic_lif_stats) == 1024);

static_assert(sizeof(struct ionic_admin_cmd) == 64);
static_assert(sizeof(struct ionic_admin_comp) == 16);
static_assert(sizeof(struct ionic_nop_cmd) == 64);
static_assert(sizeof(struct ionic_nop_comp) == 16);

/* Device commands */
static_assert(sizeof(struct ionic_dev_identify_cmd) == 64);
static_assert(sizeof(struct ionic_dev_identify_comp) == 16);
static_assert(sizeof(struct ionic_dev_init_cmd) == 64);
static_assert(sizeof(struct ionic_dev_init_comp) == 16);
static_assert(sizeof(struct ionic_dev_reset_cmd) == 64);
static_assert(sizeof(struct ionic_dev_reset_comp) == 16);
static_assert(sizeof(struct ionic_dev_getattr_cmd) == 64);
static_assert(sizeof(struct ionic_dev_getattr_comp) == 16);
static_assert(sizeof(struct ionic_dev_setattr_cmd) == 64);
static_assert(sizeof(struct ionic_dev_setattr_comp) == 16);

/* Port commands */
static_assert(sizeof(struct ionic_port_identify_cmd) == 64);
static_assert(sizeof(struct ionic_port_identify_comp) == 16);
static_assert(sizeof(struct ionic_port_init_cmd) == 64);
static_assert(sizeof(struct ionic_port_init_comp) == 16);
static_assert(sizeof(struct ionic_port_reset_cmd) == 64);
static_assert(sizeof(struct ionic_port_reset_comp) == 16);
static_assert(sizeof(struct ionic_port_getattr_cmd) == 64);
static_assert(sizeof(struct ionic_port_getattr_comp) == 16);
static_assert(sizeof(struct ionic_port_setattr_cmd) == 64);
static_assert(sizeof(struct ionic_port_setattr_comp) == 16);

/* LIF commands */
static_assert(sizeof(struct ionic_lif_init_cmd) == 64);
static_assert(sizeof(struct ionic_lif_init_comp) == 16);
static_assert(sizeof(struct ionic_lif_reset_cmd) == 64);
static_assert(sizeof(ionic_lif_reset_comp) == 16);
static_assert(sizeof(struct ionic_lif_getattr_cmd) == 64);
static_assert(sizeof(struct ionic_lif_getattr_comp) == 16);
static_assert(sizeof(struct ionic_lif_setattr_cmd) == 64);
static_assert(sizeof(struct ionic_lif_setattr_comp) == 16);

static_assert(sizeof(struct ionic_q_init_cmd) == 64);
static_assert(sizeof(struct ionic_q_init_comp) == 16);
static_assert(sizeof(struct ionic_q_control_cmd) == 64);
static_assert(sizeof(ionic_q_control_comp) == 16);
89 90
static_assert(sizeof(struct ionic_q_identify_cmd) == 64);
static_assert(sizeof(struct ionic_q_identify_comp) == 16);
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

static_assert(sizeof(struct ionic_rx_mode_set_cmd) == 64);
static_assert(sizeof(ionic_rx_mode_set_comp) == 16);
static_assert(sizeof(struct ionic_rx_filter_add_cmd) == 64);
static_assert(sizeof(struct ionic_rx_filter_add_comp) == 16);
static_assert(sizeof(struct ionic_rx_filter_del_cmd) == 64);
static_assert(sizeof(ionic_rx_filter_del_comp) == 16);

/* RDMA commands */
static_assert(sizeof(struct ionic_rdma_reset_cmd) == 64);
static_assert(sizeof(struct ionic_rdma_queue_cmd) == 64);

/* Events */
static_assert(sizeof(struct ionic_notifyq_cmd) == 4);
static_assert(sizeof(union ionic_notifyq_comp) == 64);
static_assert(sizeof(struct ionic_notifyq_event) == 64);
static_assert(sizeof(struct ionic_link_change_event) == 64);
static_assert(sizeof(struct ionic_reset_event) == 64);
static_assert(sizeof(struct ionic_heartbeat_event) == 64);
static_assert(sizeof(struct ionic_log_event) == 64);

/* I/O */
static_assert(sizeof(struct ionic_txq_desc) == 16);
static_assert(sizeof(struct ionic_txq_sg_desc) == 128);
static_assert(sizeof(struct ionic_txq_comp) == 16);

static_assert(sizeof(struct ionic_rxq_desc) == 16);
static_assert(sizeof(struct ionic_rxq_sg_desc) == 128);
static_assert(sizeof(struct ionic_rxq_comp) == 16);

121 122 123 124 125
/* SR/IOV */
static_assert(sizeof(struct ionic_vf_setattr_cmd) == 64);
static_assert(sizeof(struct ionic_vf_setattr_comp) == 16);
static_assert(sizeof(struct ionic_vf_getattr_cmd) == 64);
static_assert(sizeof(struct ionic_vf_getattr_comp) == 16);
S
Shannon Nelson 已提交
126
#endif /* __CHECKER__ */
127

128 129 130 131 132 133 134 135 136 137 138
struct ionic_devinfo {
	u8 asic_type;
	u8 asic_rev;
	char fw_version[IONIC_DEVINFO_FWVERS_BUFLEN + 1];
	char serial_num[IONIC_DEVINFO_SERIAL_BUFLEN + 1];
};

struct ionic_dev {
	union ionic_dev_info_regs __iomem *dev_info_regs;
	union ionic_dev_cmd_regs __iomem *dev_cmd_regs;

139
	atomic_long_t last_check_time;
S
Shannon Nelson 已提交
140
	unsigned long last_hb_time;
141 142 143
	u32 last_fw_hb;
	bool fw_hb_ready;
	bool fw_status_ready;
S
Shannon Nelson 已提交
144

145 146 147 148 149 150
	u64 __iomem *db_pages;
	dma_addr_t phy_db_pages;

	struct ionic_intr __iomem *intr_ctrl;
	u64 __iomem *intr_status;

151 152 153 154
	u32 port_info_sz;
	struct ionic_port_info *port_info;
	dma_addr_t port_info_pa;

155 156 157
	struct ionic_devinfo dev_info;
};

S
Shannon Nelson 已提交
158
struct ionic_cq_info {
159 160 161 162 163 164 165
	union {
		void *cq_desc;
		struct ionic_txq_comp *txcq;
		struct ionic_rxq_comp *rxcq;
		struct ionic_admin_comp *admincq;
		struct ionic_notifyq_event *notifyq;
	};
S
Shannon Nelson 已提交
166 167 168 169 170 171 172 173 174 175
};

struct ionic_queue;
struct ionic_qcq;
struct ionic_desc_info;

typedef void (*ionic_desc_cb)(struct ionic_queue *q,
			      struct ionic_desc_info *desc_info,
			      struct ionic_cq_info *cq_info, void *cb_arg);

S
Shannon Nelson 已提交
176 177 178 179 180 181
#define IONIC_PAGE_SIZE				PAGE_SIZE
#define IONIC_PAGE_SPLIT_SZ			(PAGE_SIZE / 2)
#define IONIC_PAGE_GFP_MASK			(GFP_ATOMIC | __GFP_NOWARN |\
						 __GFP_COMP | __GFP_MEMALLOC)

struct ionic_buf_info {
182 183
	struct page *page;
	dma_addr_t dma_addr;
S
Shannon Nelson 已提交
184
	u32 page_offset;
185
	u32 len;
186 187
};

188 189
#define IONIC_MAX_FRAGS			(1 + IONIC_TX_MAX_SG_ELEMS_V1)

S
Shannon Nelson 已提交
190
struct ionic_desc_info {
191 192 193 194 195 196 197 198 199 200 201
	union {
		void *desc;
		struct ionic_txq_desc *txq_desc;
		struct ionic_rxq_desc *rxq_desc;
		struct ionic_admin_cmd *adminq_desc;
	};
	union {
		void *sg_desc;
		struct ionic_txq_sg_desc *txq_sg_desc;
		struct ionic_rxq_sg_desc *rxq_sgl_desc;
	};
202
	unsigned int bytes;
S
Shannon Nelson 已提交
203
	unsigned int nbufs;
204
	struct ionic_buf_info bufs[IONIC_MAX_FRAGS];
S
Shannon Nelson 已提交
205 206 207 208
	ionic_desc_cb cb;
	void *cb_arg;
};

S
Shannon Nelson 已提交
209
#define IONIC_QUEUE_NAME_MAX_SZ		32
S
Shannon Nelson 已提交
210 211

struct ionic_queue {
212
	struct device *dev;
S
Shannon Nelson 已提交
213 214
	struct ionic_lif *lif;
	struct ionic_desc_info *info;
215
	u64 dbval;
216 217
	u16 head_idx;
	u16 tail_idx;
S
Shannon Nelson 已提交
218
	unsigned int index;
219
	unsigned int num_descs;
220
	unsigned int max_sg_elems;
221 222 223 224 225
	u64 dbell_count;
	u64 stop;
	u64 wake;
	u64 drop;
	struct ionic_dev *idev;
S
Shannon Nelson 已提交
226 227 228
	unsigned int type;
	unsigned int hw_index;
	unsigned int hw_type;
229 230 231 232 233 234 235 236 237 238 239
	union {
		void *base;
		struct ionic_txq_desc *txq;
		struct ionic_rxq_desc *rxq;
		struct ionic_admin_cmd *adminq;
	};
	union {
		void *sg_base;
		struct ionic_txq_sg_desc *txq_sgl;
		struct ionic_rxq_sg_desc *rxq_sgl;
	};
S
Shannon Nelson 已提交
240 241 242 243 244
	dma_addr_t base_pa;
	dma_addr_t sg_base_pa;
	unsigned int desc_size;
	unsigned int sg_desc_size;
	unsigned int pid;
S
Shannon Nelson 已提交
245
	char name[IONIC_QUEUE_NAME_MAX_SZ];
246
} ____cacheline_aligned_in_smp;
S
Shannon Nelson 已提交
247

S
Shannon Nelson 已提交
248 249
#define IONIC_INTR_INDEX_NOT_ASSIGNED	-1
#define IONIC_INTR_NAME_MAX_SZ		32
250 251

struct ionic_intr_info {
S
Shannon Nelson 已提交
252
	char name[IONIC_INTR_NAME_MAX_SZ];
253 254 255 256 257
	unsigned int index;
	unsigned int vector;
	u64 rearm_count;
	unsigned int cpu;
	cpumask_t affinity_mask;
258
	u32 dim_coal_hw;
259 260
};

S
Shannon Nelson 已提交
261 262 263 264 265
struct ionic_cq {
	struct ionic_lif *lif;
	struct ionic_cq_info *info;
	struct ionic_queue *bound_q;
	struct ionic_intr_info *bound_intr;
266
	u16 tail_idx;
S
Shannon Nelson 已提交
267 268 269
	bool done_color;
	unsigned int num_descs;
	unsigned int desc_size;
270 271 272
	u64 compl_count;
	void *base;
	dma_addr_t base_pa;
273
} ____cacheline_aligned_in_smp;
S
Shannon Nelson 已提交
274

275 276
struct ionic;

277 278 279 280 281 282 283 284
static inline void ionic_intr_init(struct ionic_dev *idev,
				   struct ionic_intr_info *intr,
				   unsigned long index)
{
	ionic_intr_clean(idev->intr_ctrl, index);
	intr->index = index;
}

S
Shannon Nelson 已提交
285 286
static inline unsigned int ionic_q_space_avail(struct ionic_queue *q)
{
287
	unsigned int avail = q->tail_idx;
S
Shannon Nelson 已提交
288

289 290
	if (q->head_idx >= avail)
		avail += q->num_descs - q->head_idx - 1;
S
Shannon Nelson 已提交
291
	else
292
		avail -= q->head_idx + 1;
S
Shannon Nelson 已提交
293 294 295 296 297 298 299 300 301

	return avail;
}

static inline bool ionic_q_has_space(struct ionic_queue *q, unsigned int want)
{
	return ionic_q_space_avail(q) >= want;
}

302 303 304 305 306 307 308 309 310 311 312 313
void ionic_init_devinfo(struct ionic *ionic);
int ionic_dev_setup(struct ionic *ionic);

void ionic_dev_cmd_go(struct ionic_dev *idev, union ionic_dev_cmd *cmd);
u8 ionic_dev_cmd_status(struct ionic_dev *idev);
bool ionic_dev_cmd_done(struct ionic_dev *idev);
void ionic_dev_cmd_comp(struct ionic_dev *idev, union ionic_dev_cmd_comp *comp);

void ionic_dev_cmd_identify(struct ionic_dev *idev, u8 ver);
void ionic_dev_cmd_init(struct ionic_dev *idev);
void ionic_dev_cmd_reset(struct ionic_dev *idev);

314 315 316 317 318 319 320 321 322
void ionic_dev_cmd_port_identify(struct ionic_dev *idev);
void ionic_dev_cmd_port_init(struct ionic_dev *idev);
void ionic_dev_cmd_port_reset(struct ionic_dev *idev);
void ionic_dev_cmd_port_state(struct ionic_dev *idev, u8 state);
void ionic_dev_cmd_port_speed(struct ionic_dev *idev, u32 speed);
void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, u8 an_enable);
void ionic_dev_cmd_port_fec(struct ionic_dev *idev, u8 fec_type);
void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type);

323
int ionic_set_vf_config(struct ionic *ionic, int vf, u8 attr, u8 *data);
324 325
void ionic_dev_cmd_queue_identify(struct ionic_dev *idev,
				  u16 lif_type, u8 qtype, u8 qver);
S
Shannon Nelson 已提交
326 327 328 329
void ionic_dev_cmd_lif_identify(struct ionic_dev *idev, u8 type, u8 ver);
void ionic_dev_cmd_lif_init(struct ionic_dev *idev, u16 lif_index,
			    dma_addr_t addr);
void ionic_dev_cmd_lif_reset(struct ionic_dev *idev, u16 lif_index);
S
Shannon Nelson 已提交
330 331
void ionic_dev_cmd_adminq_init(struct ionic_dev *idev, struct ionic_qcq *qcq,
			       u16 lif_index, u16 intr_index);
S
Shannon Nelson 已提交
332

333 334
int ionic_db_page_num(struct ionic_lif *lif, int pid);

S
Shannon Nelson 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
int ionic_cq_init(struct ionic_lif *lif, struct ionic_cq *cq,
		  struct ionic_intr_info *intr,
		  unsigned int num_descs, size_t desc_size);
void ionic_cq_map(struct ionic_cq *cq, void *base, dma_addr_t base_pa);
void ionic_cq_bind(struct ionic_cq *cq, struct ionic_queue *q);
typedef bool (*ionic_cq_cb)(struct ionic_cq *cq, struct ionic_cq_info *cq_info);
typedef void (*ionic_cq_done_cb)(void *done_arg);
unsigned int ionic_cq_service(struct ionic_cq *cq, unsigned int work_to_do,
			      ionic_cq_cb cb, ionic_cq_done_cb done_cb,
			      void *done_arg);

int ionic_q_init(struct ionic_lif *lif, struct ionic_dev *idev,
		 struct ionic_queue *q, unsigned int index, const char *name,
		 unsigned int num_descs, size_t desc_size,
		 size_t sg_desc_size, unsigned int pid);
void ionic_q_map(struct ionic_queue *q, void *base, dma_addr_t base_pa);
void ionic_q_sg_map(struct ionic_queue *q, void *base, dma_addr_t base_pa);
void ionic_q_post(struct ionic_queue *q, bool ring_doorbell, ionic_desc_cb cb,
		  void *cb_arg);
void ionic_q_rewind(struct ionic_queue *q, struct ionic_desc_info *start);
void ionic_q_service(struct ionic_queue *q, struct ionic_cq_info *cq_info,
		     unsigned int stop_index);
S
Shannon Nelson 已提交
357
int ionic_heartbeat_check(struct ionic *ionic);
S
Shannon Nelson 已提交
358

359
#endif /* _IONIC_DEV_H_ */