1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
7 #include <linux/mutex.h>
8 #include <linux/workqueue.h>
11 #include "ionic_regs.h"
13 #define IONIC_MIN_MTU ETH_MIN_MTU
14 #define IONIC_MAX_MTU 9194
15 #define IONIC_MAX_TXRX_DESC 16384
16 #define IONIC_MIN_TXRX_DESC 16
17 #define IONIC_DEF_TXRX_DESC 4096
18 #define IONIC_LIFS_MAX 1024
19 #define IONIC_WATCHDOG_SECS 5
20 #define IONIC_ITR_COAL_USEC_DEFAULT 64
22 #define IONIC_DEV_CMD_REG_VERSION 1
23 #define IONIC_DEV_INFO_REG_COUNT 32
24 #define IONIC_DEV_CMD_REG_COUNT 32
26 struct ionic_dev_bar
{
34 static_assert(sizeof(struct ionic_intr
) == 32);
36 static_assert(sizeof(struct ionic_doorbell
) == 8);
37 static_assert(sizeof(struct ionic_intr_status
) == 8);
38 static_assert(sizeof(union ionic_dev_regs
) == 4096);
39 static_assert(sizeof(union ionic_dev_info_regs
) == 2048);
40 static_assert(sizeof(union ionic_dev_cmd_regs
) == 2048);
41 static_assert(sizeof(struct ionic_lif_stats
) == 1024);
43 static_assert(sizeof(struct ionic_admin_cmd
) == 64);
44 static_assert(sizeof(struct ionic_admin_comp
) == 16);
45 static_assert(sizeof(struct ionic_nop_cmd
) == 64);
46 static_assert(sizeof(struct ionic_nop_comp
) == 16);
49 static_assert(sizeof(struct ionic_dev_identify_cmd
) == 64);
50 static_assert(sizeof(struct ionic_dev_identify_comp
) == 16);
51 static_assert(sizeof(struct ionic_dev_init_cmd
) == 64);
52 static_assert(sizeof(struct ionic_dev_init_comp
) == 16);
53 static_assert(sizeof(struct ionic_dev_reset_cmd
) == 64);
54 static_assert(sizeof(struct ionic_dev_reset_comp
) == 16);
55 static_assert(sizeof(struct ionic_dev_getattr_cmd
) == 64);
56 static_assert(sizeof(struct ionic_dev_getattr_comp
) == 16);
57 static_assert(sizeof(struct ionic_dev_setattr_cmd
) == 64);
58 static_assert(sizeof(struct ionic_dev_setattr_comp
) == 16);
61 static_assert(sizeof(struct ionic_port_identify_cmd
) == 64);
62 static_assert(sizeof(struct ionic_port_identify_comp
) == 16);
63 static_assert(sizeof(struct ionic_port_init_cmd
) == 64);
64 static_assert(sizeof(struct ionic_port_init_comp
) == 16);
65 static_assert(sizeof(struct ionic_port_reset_cmd
) == 64);
66 static_assert(sizeof(struct ionic_port_reset_comp
) == 16);
67 static_assert(sizeof(struct ionic_port_getattr_cmd
) == 64);
68 static_assert(sizeof(struct ionic_port_getattr_comp
) == 16);
69 static_assert(sizeof(struct ionic_port_setattr_cmd
) == 64);
70 static_assert(sizeof(struct ionic_port_setattr_comp
) == 16);
73 static_assert(sizeof(struct ionic_lif_init_cmd
) == 64);
74 static_assert(sizeof(struct ionic_lif_init_comp
) == 16);
75 static_assert(sizeof(struct ionic_lif_reset_cmd
) == 64);
76 static_assert(sizeof(ionic_lif_reset_comp
) == 16);
77 static_assert(sizeof(struct ionic_lif_getattr_cmd
) == 64);
78 static_assert(sizeof(struct ionic_lif_getattr_comp
) == 16);
79 static_assert(sizeof(struct ionic_lif_setattr_cmd
) == 64);
80 static_assert(sizeof(struct ionic_lif_setattr_comp
) == 16);
82 static_assert(sizeof(struct ionic_q_init_cmd
) == 64);
83 static_assert(sizeof(struct ionic_q_init_comp
) == 16);
84 static_assert(sizeof(struct ionic_q_control_cmd
) == 64);
85 static_assert(sizeof(ionic_q_control_comp
) == 16);
87 static_assert(sizeof(struct ionic_rx_mode_set_cmd
) == 64);
88 static_assert(sizeof(ionic_rx_mode_set_comp
) == 16);
89 static_assert(sizeof(struct ionic_rx_filter_add_cmd
) == 64);
90 static_assert(sizeof(struct ionic_rx_filter_add_comp
) == 16);
91 static_assert(sizeof(struct ionic_rx_filter_del_cmd
) == 64);
92 static_assert(sizeof(ionic_rx_filter_del_comp
) == 16);
95 static_assert(sizeof(struct ionic_rdma_reset_cmd
) == 64);
96 static_assert(sizeof(struct ionic_rdma_queue_cmd
) == 64);
99 static_assert(sizeof(struct ionic_notifyq_cmd
) == 4);
100 static_assert(sizeof(union ionic_notifyq_comp
) == 64);
101 static_assert(sizeof(struct ionic_notifyq_event
) == 64);
102 static_assert(sizeof(struct ionic_link_change_event
) == 64);
103 static_assert(sizeof(struct ionic_reset_event
) == 64);
104 static_assert(sizeof(struct ionic_heartbeat_event
) == 64);
105 static_assert(sizeof(struct ionic_log_event
) == 64);
108 static_assert(sizeof(struct ionic_txq_desc
) == 16);
109 static_assert(sizeof(struct ionic_txq_sg_desc
) == 128);
110 static_assert(sizeof(struct ionic_txq_comp
) == 16);
112 static_assert(sizeof(struct ionic_rxq_desc
) == 16);
113 static_assert(sizeof(struct ionic_rxq_sg_desc
) == 128);
114 static_assert(sizeof(struct ionic_rxq_comp
) == 16);
116 struct ionic_devinfo
{
119 char fw_version
[IONIC_DEVINFO_FWVERS_BUFLEN
+ 1];
120 char serial_num
[IONIC_DEVINFO_SERIAL_BUFLEN
+ 1];
124 union ionic_dev_info_regs __iomem
*dev_info_regs
;
125 union ionic_dev_cmd_regs __iomem
*dev_cmd_regs
;
127 unsigned long last_hb_time
;
130 u64 __iomem
*db_pages
;
131 dma_addr_t phy_db_pages
;
133 struct ionic_intr __iomem
*intr_ctrl
;
134 u64 __iomem
*intr_status
;
137 struct ionic_port_info
*port_info
;
138 dma_addr_t port_info_pa
;
140 struct ionic_devinfo dev_info
;
143 struct ionic_cq_info
{
145 struct ionic_cq_info
*next
;
152 struct ionic_desc_info
;
154 typedef void (*ionic_desc_cb
)(struct ionic_queue
*q
,
155 struct ionic_desc_info
*desc_info
,
156 struct ionic_cq_info
*cq_info
, void *cb_arg
);
158 struct ionic_page_info
{
163 struct ionic_desc_info
{
166 struct ionic_desc_info
*next
;
170 struct ionic_page_info pages
[IONIC_RX_MAX_SG_ELEMS
+ 1];
175 #define QUEUE_NAME_MAX_SZ 32
182 struct ionic_lif
*lif
;
183 struct ionic_desc_info
*info
;
184 struct ionic_desc_info
*tail
;
185 struct ionic_desc_info
*head
;
186 struct ionic_dev
*idev
;
189 unsigned int hw_index
;
190 unsigned int hw_type
;
195 dma_addr_t sg_base_pa
;
196 unsigned int num_descs
;
197 unsigned int desc_size
;
198 unsigned int sg_desc_size
;
200 char name
[QUEUE_NAME_MAX_SZ
];
203 #define INTR_INDEX_NOT_ASSIGNED -1
204 #define INTR_NAME_MAX_SZ 32
206 struct ionic_intr_info
{
207 char name
[INTR_NAME_MAX_SZ
];
212 cpumask_t affinity_mask
;
218 struct ionic_lif
*lif
;
219 struct ionic_cq_info
*info
;
220 struct ionic_cq_info
*tail
;
221 struct ionic_queue
*bound_q
;
222 struct ionic_intr_info
*bound_intr
;
224 unsigned int num_descs
;
226 unsigned int desc_size
;
231 static inline void ionic_intr_init(struct ionic_dev
*idev
,
232 struct ionic_intr_info
*intr
,
235 ionic_intr_clean(idev
->intr_ctrl
, index
);
239 static inline unsigned int ionic_q_space_avail(struct ionic_queue
*q
)
241 unsigned int avail
= q
->tail
->index
;
243 if (q
->head
->index
>= avail
)
244 avail
+= q
->head
->left
- 1;
246 avail
-= q
->head
->index
+ 1;
251 static inline bool ionic_q_has_space(struct ionic_queue
*q
, unsigned int want
)
253 return ionic_q_space_avail(q
) >= want
;
256 void ionic_init_devinfo(struct ionic
*ionic
);
257 int ionic_dev_setup(struct ionic
*ionic
);
258 void ionic_dev_teardown(struct ionic
*ionic
);
260 void ionic_dev_cmd_go(struct ionic_dev
*idev
, union ionic_dev_cmd
*cmd
);
261 u8
ionic_dev_cmd_status(struct ionic_dev
*idev
);
262 bool ionic_dev_cmd_done(struct ionic_dev
*idev
);
263 void ionic_dev_cmd_comp(struct ionic_dev
*idev
, union ionic_dev_cmd_comp
*comp
);
265 void ionic_dev_cmd_identify(struct ionic_dev
*idev
, u8 ver
);
266 void ionic_dev_cmd_init(struct ionic_dev
*idev
);
267 void ionic_dev_cmd_reset(struct ionic_dev
*idev
);
269 void ionic_dev_cmd_port_identify(struct ionic_dev
*idev
);
270 void ionic_dev_cmd_port_init(struct ionic_dev
*idev
);
271 void ionic_dev_cmd_port_reset(struct ionic_dev
*idev
);
272 void ionic_dev_cmd_port_state(struct ionic_dev
*idev
, u8 state
);
273 void ionic_dev_cmd_port_speed(struct ionic_dev
*idev
, u32 speed
);
274 void ionic_dev_cmd_port_autoneg(struct ionic_dev
*idev
, u8 an_enable
);
275 void ionic_dev_cmd_port_fec(struct ionic_dev
*idev
, u8 fec_type
);
276 void ionic_dev_cmd_port_pause(struct ionic_dev
*idev
, u8 pause_type
);
278 void ionic_dev_cmd_lif_identify(struct ionic_dev
*idev
, u8 type
, u8 ver
);
279 void ionic_dev_cmd_lif_init(struct ionic_dev
*idev
, u16 lif_index
,
281 void ionic_dev_cmd_lif_reset(struct ionic_dev
*idev
, u16 lif_index
);
282 void ionic_dev_cmd_adminq_init(struct ionic_dev
*idev
, struct ionic_qcq
*qcq
,
283 u16 lif_index
, u16 intr_index
);
285 int ionic_db_page_num(struct ionic_lif
*lif
, int pid
);
287 int ionic_cq_init(struct ionic_lif
*lif
, struct ionic_cq
*cq
,
288 struct ionic_intr_info
*intr
,
289 unsigned int num_descs
, size_t desc_size
);
290 void ionic_cq_map(struct ionic_cq
*cq
, void *base
, dma_addr_t base_pa
);
291 void ionic_cq_bind(struct ionic_cq
*cq
, struct ionic_queue
*q
);
292 typedef bool (*ionic_cq_cb
)(struct ionic_cq
*cq
, struct ionic_cq_info
*cq_info
);
293 typedef void (*ionic_cq_done_cb
)(void *done_arg
);
294 unsigned int ionic_cq_service(struct ionic_cq
*cq
, unsigned int work_to_do
,
295 ionic_cq_cb cb
, ionic_cq_done_cb done_cb
,
298 int ionic_q_init(struct ionic_lif
*lif
, struct ionic_dev
*idev
,
299 struct ionic_queue
*q
, unsigned int index
, const char *name
,
300 unsigned int num_descs
, size_t desc_size
,
301 size_t sg_desc_size
, unsigned int pid
);
302 void ionic_q_map(struct ionic_queue
*q
, void *base
, dma_addr_t base_pa
);
303 void ionic_q_sg_map(struct ionic_queue
*q
, void *base
, dma_addr_t base_pa
);
304 void ionic_q_post(struct ionic_queue
*q
, bool ring_doorbell
, ionic_desc_cb cb
,
306 void ionic_q_rewind(struct ionic_queue
*q
, struct ionic_desc_info
*start
);
307 void ionic_q_service(struct ionic_queue
*q
, struct ionic_cq_info
*cq_info
,
308 unsigned int stop_index
);
309 int ionic_heartbeat_check(struct ionic
*ionic
);
311 #endif /* _IONIC_DEV_H_ */