1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
10 #include "ionic_osdep.h"
12 #include "ionic_regs.h"
14 #define IONIC_MIN_MTU RTE_ETHER_MIN_MTU
15 #define IONIC_MAX_MTU 9194
17 #define IONIC_MAX_RING_DESC 32768
18 #define IONIC_MIN_RING_DESC 16
19 #define IONIC_DEF_TXRX_DESC 4096
21 #define IONIC_LIFS_MAX 1024
23 #define IONIC_DEVCMD_TIMEOUT 30 /* devcmd_timeout */
24 #define IONIC_ALIGN 4096
28 struct ionic_dev_bar {
34 static inline void ionic_struct_size_checks(void)
36 RTE_BUILD_BUG_ON(sizeof(struct ionic_doorbell) != 8);
37 RTE_BUILD_BUG_ON(sizeof(struct ionic_intr) != 32);
38 RTE_BUILD_BUG_ON(sizeof(struct ionic_intr_status) != 8);
40 RTE_BUILD_BUG_ON(sizeof(union ionic_dev_regs) != 4096);
41 RTE_BUILD_BUG_ON(sizeof(union ionic_dev_info_regs) != 2048);
42 RTE_BUILD_BUG_ON(sizeof(union ionic_dev_cmd_regs) != 2048);
44 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_stats) != 1024);
46 RTE_BUILD_BUG_ON(sizeof(struct ionic_admin_cmd) != 64);
47 RTE_BUILD_BUG_ON(sizeof(struct ionic_admin_comp) != 16);
48 RTE_BUILD_BUG_ON(sizeof(struct ionic_nop_cmd) != 64);
49 RTE_BUILD_BUG_ON(sizeof(struct ionic_nop_comp) != 16);
52 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_identify_cmd) != 64);
53 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_identify_comp) != 16);
54 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_init_cmd) != 64);
55 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_init_comp) != 16);
56 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_reset_cmd) != 64);
57 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_reset_comp) != 16);
58 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_getattr_cmd) != 64);
59 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_getattr_comp) != 16);
60 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_setattr_cmd) != 64);
61 RTE_BUILD_BUG_ON(sizeof(struct ionic_dev_setattr_comp) != 16);
64 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_identify_cmd) != 64);
65 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_identify_comp) != 16);
66 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_init_cmd) != 64);
67 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_init_comp) != 16);
68 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_reset_cmd) != 64);
69 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_reset_comp) != 16);
70 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_getattr_cmd) != 64);
71 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_getattr_comp) != 16);
72 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_setattr_cmd) != 64);
73 RTE_BUILD_BUG_ON(sizeof(struct ionic_port_setattr_comp) != 16);
76 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_init_cmd) != 64);
77 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_init_comp) != 16);
78 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_reset_cmd) != 64);
79 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_getattr_cmd) != 64);
80 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_getattr_comp) != 16);
81 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_setattr_cmd) != 64);
82 RTE_BUILD_BUG_ON(sizeof(struct ionic_lif_setattr_comp) != 16);
84 RTE_BUILD_BUG_ON(sizeof(struct ionic_q_init_cmd) != 64);
85 RTE_BUILD_BUG_ON(sizeof(struct ionic_q_init_comp) != 16);
86 RTE_BUILD_BUG_ON(sizeof(struct ionic_q_control_cmd) != 64);
88 RTE_BUILD_BUG_ON(sizeof(struct ionic_rx_mode_set_cmd) != 64);
89 RTE_BUILD_BUG_ON(sizeof(struct ionic_rx_filter_add_cmd) != 64);
90 RTE_BUILD_BUG_ON(sizeof(struct ionic_rx_filter_add_comp) != 16);
91 RTE_BUILD_BUG_ON(sizeof(struct ionic_rx_filter_del_cmd) != 64);
94 RTE_BUILD_BUG_ON(sizeof(struct ionic_rdma_reset_cmd) != 64);
95 RTE_BUILD_BUG_ON(sizeof(struct ionic_rdma_queue_cmd) != 64);
98 RTE_BUILD_BUG_ON(sizeof(struct ionic_notifyq_cmd) != 4);
99 RTE_BUILD_BUG_ON(sizeof(union ionic_notifyq_comp) != 64);
100 RTE_BUILD_BUG_ON(sizeof(struct ionic_notifyq_event) != 64);
101 RTE_BUILD_BUG_ON(sizeof(struct ionic_link_change_event) != 64);
102 RTE_BUILD_BUG_ON(sizeof(struct ionic_reset_event) != 64);
103 RTE_BUILD_BUG_ON(sizeof(struct ionic_heartbeat_event) != 64);
104 RTE_BUILD_BUG_ON(sizeof(struct ionic_log_event) != 64);
107 RTE_BUILD_BUG_ON(sizeof(struct ionic_txq_desc) != 16);
108 RTE_BUILD_BUG_ON(sizeof(struct ionic_txq_sg_desc) != 128);
109 RTE_BUILD_BUG_ON(sizeof(struct ionic_txq_comp) != 16);
111 RTE_BUILD_BUG_ON(sizeof(struct ionic_rxq_desc) != 16);
112 RTE_BUILD_BUG_ON(sizeof(struct ionic_rxq_sg_desc) != 128);
113 RTE_BUILD_BUG_ON(sizeof(struct ionic_rxq_comp) != 16);
117 union ionic_dev_info_regs __iomem *dev_info;
118 union ionic_dev_cmd_regs __iomem *dev_cmd;
120 struct ionic_doorbell __iomem *db_pages;
121 rte_iova_t phy_db_pages;
123 struct ionic_intr __iomem *intr_ctrl;
125 struct ionic_intr_status __iomem *intr_status;
127 struct ionic_port_info *port_info;
128 const struct rte_memzone *port_info_z;
129 rte_iova_t port_info_pa;
130 uint32_t port_info_sz;
134 struct ionic_desc_info;
136 typedef void (*desc_cb)(struct ionic_queue *q,
137 uint32_t q_desc_index,
138 uint32_t cq_desc_index,
139 void *cb_arg, void *service_cb_arg);
141 struct ionic_desc_info {
147 struct ionic_dev *idev;
148 struct ionic_lif *lif;
149 struct ionic_cq *bound_cq;
157 rte_iova_t sg_base_pa;
158 struct ionic_desc_info *info;
163 uint32_t sg_desc_size;
167 struct ionic_doorbell __iomem *db;
171 #define IONIC_INTR_INDEX_NOT_ASSIGNED (-1)
172 #define IONIC_INTR_NAME_MAX_SZ (32)
174 struct ionic_intr_info {
175 char name[IONIC_INTR_NAME_MAX_SZ];
178 struct ionic_intr __iomem *ctrl;
182 struct ionic_lif *lif;
183 struct ionic_queue *bound_q;
190 struct ionic_intr_info *bound_intr;
193 /** ionic_admin_ctx - Admin command context.
194 * @pending_work: Flag that indicates a completion.
195 * @cmd: Admin command (64B) to be copied to the queue.
196 * @comp: Admin completion (16B) copied from the queue.
198 struct ionic_admin_ctx {
200 union ionic_adminq_cmd cmd;
201 union ionic_adminq_comp comp;
205 struct ionic_adapter;
208 void ionic_intr_init(struct ionic_dev *idev, struct ionic_intr_info *intr,
209 unsigned long index);
211 int ionic_dev_setup(struct ionic_adapter *adapter);
213 void ionic_dev_cmd_go(struct ionic_dev *idev, union ionic_dev_cmd *cmd);
214 uint8_t ionic_dev_cmd_status(struct ionic_dev *idev);
215 bool ionic_dev_cmd_done(struct ionic_dev *idev);
216 void ionic_dev_cmd_comp(struct ionic_dev *idev, void *mem);
218 void ionic_dev_cmd_identify(struct ionic_dev *idev, uint8_t ver);
219 void ionic_dev_cmd_init(struct ionic_dev *idev);
220 void ionic_dev_cmd_reset(struct ionic_dev *idev);
222 void ionic_dev_cmd_port_identify(struct ionic_dev *idev);
223 void ionic_dev_cmd_port_init(struct ionic_dev *idev);
224 void ionic_dev_cmd_port_reset(struct ionic_dev *idev);
225 void ionic_dev_cmd_port_state(struct ionic_dev *idev, uint8_t state);
226 void ionic_dev_cmd_port_speed(struct ionic_dev *idev, uint32_t speed);
227 void ionic_dev_cmd_port_mtu(struct ionic_dev *idev, uint32_t mtu);
228 void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, uint8_t an_enable);
229 void ionic_dev_cmd_port_fec(struct ionic_dev *idev, uint8_t fec_type);
230 void ionic_dev_cmd_port_pause(struct ionic_dev *idev, uint8_t pause_type);
231 void ionic_dev_cmd_port_loopback(struct ionic_dev *idev,
232 uint8_t loopback_mode);
234 void ionic_dev_cmd_lif_identify(struct ionic_dev *idev, uint8_t type,
236 void ionic_dev_cmd_lif_init(struct ionic_dev *idev, uint16_t lif_index,
238 void ionic_dev_cmd_lif_reset(struct ionic_dev *idev, uint16_t lif_index);
239 void ionic_dev_cmd_adminq_init(struct ionic_dev *idev, struct ionic_qcq *qcq,
240 uint16_t lif_index, uint16_t intr_index);
242 struct ionic_doorbell __iomem *ionic_db_map(struct ionic_lif *lif,
243 struct ionic_queue *q);
244 int ionic_db_page_num(struct ionic_lif *lif, int pid);
246 int ionic_cq_init(struct ionic_lif *lif, struct ionic_cq *cq,
247 struct ionic_intr_info *intr, uint32_t num_descs,
249 void ionic_cq_map(struct ionic_cq *cq, void *base, rte_iova_t base_pa);
250 void ionic_cq_bind(struct ionic_cq *cq, struct ionic_queue *q);
251 typedef bool (*ionic_cq_cb)(struct ionic_cq *cq, uint32_t cq_desc_index,
253 uint32_t ionic_cq_service(struct ionic_cq *cq, uint32_t work_to_do,
254 ionic_cq_cb cb, void *cb_arg);
256 int ionic_q_init(struct ionic_lif *lif, struct ionic_dev *idev,
257 struct ionic_queue *q, uint32_t index, uint32_t num_descs,
258 size_t desc_size, size_t sg_desc_size, uint32_t pid);
259 void ionic_q_map(struct ionic_queue *q, void *base, rte_iova_t base_pa);
260 void ionic_q_sg_map(struct ionic_queue *q, void *base, rte_iova_t base_pa);
261 void ionic_q_flush(struct ionic_queue *q);
262 void ionic_q_post(struct ionic_queue *q, bool ring_doorbell, desc_cb cb,
264 uint32_t ionic_q_space_avail(struct ionic_queue *q);
265 bool ionic_q_has_space(struct ionic_queue *q, uint32_t want);
266 void ionic_q_service(struct ionic_queue *q, uint32_t cq_desc_index,
267 uint32_t stop_index, void *service_cb_arg);
269 int ionic_adminq_post(struct ionic_lif *lif, struct ionic_admin_ctx *ctx);
271 #endif /* _IONIC_DEV_H_ */