1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 3 4 #ifndef _IONIC_DEV_H_ 5 #define _IONIC_DEV_H_ 6 7 #include <linux/mutex.h> 8 #include <linux/workqueue.h> 9 10 #include "ionic_if.h" 11 #include "ionic_regs.h" 12 13 #define IONIC_MAX_TX_DESC 8192 14 #define IONIC_MAX_RX_DESC 16384 15 #define IONIC_MIN_TXRX_DESC 16 16 #define IONIC_DEF_TXRX_DESC 4096 17 #define IONIC_LIFS_MAX 1024 18 #define IONIC_WATCHDOG_SECS 5 19 #define IONIC_ITR_COAL_USEC_DEFAULT 64 20 21 #define IONIC_DEV_CMD_REG_VERSION 1 22 #define IONIC_DEV_INFO_REG_COUNT 32 23 #define IONIC_DEV_CMD_REG_COUNT 32 24 25 struct ionic_dev_bar { 26 void __iomem *vaddr; 27 phys_addr_t bus_addr; 28 unsigned long len; 29 int res_index; 30 }; 31 32 /* Registers */ 33 static_assert(sizeof(struct ionic_intr) == 32); 34 35 static_assert(sizeof(struct ionic_doorbell) == 8); 36 static_assert(sizeof(struct ionic_intr_status) == 8); 37 static_assert(sizeof(union ionic_dev_regs) == 4096); 38 static_assert(sizeof(union ionic_dev_info_regs) == 2048); 39 static_assert(sizeof(union ionic_dev_cmd_regs) == 2048); 40 static_assert(sizeof(struct ionic_lif_stats) == 1024); 41 42 static_assert(sizeof(struct ionic_admin_cmd) == 64); 43 static_assert(sizeof(struct ionic_admin_comp) == 16); 44 static_assert(sizeof(struct ionic_nop_cmd) == 64); 45 static_assert(sizeof(struct ionic_nop_comp) == 16); 46 47 /* Device commands */ 48 static_assert(sizeof(struct ionic_dev_identify_cmd) == 64); 49 static_assert(sizeof(struct ionic_dev_identify_comp) == 16); 50 static_assert(sizeof(struct ionic_dev_init_cmd) == 64); 51 static_assert(sizeof(struct ionic_dev_init_comp) == 16); 52 static_assert(sizeof(struct ionic_dev_reset_cmd) == 64); 53 static_assert(sizeof(struct ionic_dev_reset_comp) == 16); 54 static_assert(sizeof(struct ionic_dev_getattr_cmd) == 64); 55 static_assert(sizeof(struct ionic_dev_getattr_comp) == 16); 56 static_assert(sizeof(struct ionic_dev_setattr_cmd) == 64); 57 static_assert(sizeof(struct ionic_dev_setattr_comp) == 16); 58 59 /* Port commands */ 60 static_assert(sizeof(struct ionic_port_identify_cmd) == 64); 61 static_assert(sizeof(struct ionic_port_identify_comp) == 16); 62 static_assert(sizeof(struct ionic_port_init_cmd) == 64); 63 static_assert(sizeof(struct ionic_port_init_comp) == 16); 64 static_assert(sizeof(struct ionic_port_reset_cmd) == 64); 65 static_assert(sizeof(struct ionic_port_reset_comp) == 16); 66 static_assert(sizeof(struct ionic_port_getattr_cmd) == 64); 67 static_assert(sizeof(struct ionic_port_getattr_comp) == 16); 68 static_assert(sizeof(struct ionic_port_setattr_cmd) == 64); 69 static_assert(sizeof(struct ionic_port_setattr_comp) == 16); 70 71 /* LIF commands */ 72 static_assert(sizeof(struct ionic_lif_init_cmd) == 64); 73 static_assert(sizeof(struct ionic_lif_init_comp) == 16); 74 static_assert(sizeof(struct ionic_lif_reset_cmd) == 64); 75 static_assert(sizeof(ionic_lif_reset_comp) == 16); 76 static_assert(sizeof(struct ionic_lif_getattr_cmd) == 64); 77 static_assert(sizeof(struct ionic_lif_getattr_comp) == 16); 78 static_assert(sizeof(struct ionic_lif_setattr_cmd) == 64); 79 static_assert(sizeof(struct ionic_lif_setattr_comp) == 16); 80 81 static_assert(sizeof(struct ionic_q_init_cmd) == 64); 82 static_assert(sizeof(struct ionic_q_init_comp) == 16); 83 static_assert(sizeof(struct ionic_q_control_cmd) == 64); 84 static_assert(sizeof(ionic_q_control_comp) == 16); 85 static_assert(sizeof(struct ionic_q_identify_cmd) == 64); 86 static_assert(sizeof(struct ionic_q_identify_comp) == 16); 87 88 static_assert(sizeof(struct ionic_rx_mode_set_cmd) == 64); 89 static_assert(sizeof(ionic_rx_mode_set_comp) == 16); 90 static_assert(sizeof(struct ionic_rx_filter_add_cmd) == 64); 91 static_assert(sizeof(struct ionic_rx_filter_add_comp) == 16); 92 static_assert(sizeof(struct ionic_rx_filter_del_cmd) == 64); 93 static_assert(sizeof(ionic_rx_filter_del_comp) == 16); 94 95 /* RDMA commands */ 96 static_assert(sizeof(struct ionic_rdma_reset_cmd) == 64); 97 static_assert(sizeof(struct ionic_rdma_queue_cmd) == 64); 98 99 /* Events */ 100 static_assert(sizeof(struct ionic_notifyq_cmd) == 4); 101 static_assert(sizeof(union ionic_notifyq_comp) == 64); 102 static_assert(sizeof(struct ionic_notifyq_event) == 64); 103 static_assert(sizeof(struct ionic_link_change_event) == 64); 104 static_assert(sizeof(struct ionic_reset_event) == 64); 105 static_assert(sizeof(struct ionic_heartbeat_event) == 64); 106 static_assert(sizeof(struct ionic_log_event) == 64); 107 108 /* I/O */ 109 static_assert(sizeof(struct ionic_txq_desc) == 16); 110 static_assert(sizeof(struct ionic_txq_sg_desc) == 128); 111 static_assert(sizeof(struct ionic_txq_comp) == 16); 112 113 static_assert(sizeof(struct ionic_rxq_desc) == 16); 114 static_assert(sizeof(struct ionic_rxq_sg_desc) == 128); 115 static_assert(sizeof(struct ionic_rxq_comp) == 16); 116 117 /* SR/IOV */ 118 static_assert(sizeof(struct ionic_vf_setattr_cmd) == 64); 119 static_assert(sizeof(struct ionic_vf_setattr_comp) == 16); 120 static_assert(sizeof(struct ionic_vf_getattr_cmd) == 64); 121 static_assert(sizeof(struct ionic_vf_getattr_comp) == 16); 122 123 struct ionic_devinfo { 124 u8 asic_type; 125 u8 asic_rev; 126 char fw_version[IONIC_DEVINFO_FWVERS_BUFLEN + 1]; 127 char serial_num[IONIC_DEVINFO_SERIAL_BUFLEN + 1]; 128 }; 129 130 struct ionic_dev { 131 union ionic_dev_info_regs __iomem *dev_info_regs; 132 union ionic_dev_cmd_regs __iomem *dev_cmd_regs; 133 134 unsigned long last_hb_time; 135 u32 last_hb; 136 u8 last_fw_status; 137 138 u64 __iomem *db_pages; 139 dma_addr_t phy_db_pages; 140 141 struct ionic_intr __iomem *intr_ctrl; 142 u64 __iomem *intr_status; 143 144 u32 port_info_sz; 145 struct ionic_port_info *port_info; 146 dma_addr_t port_info_pa; 147 148 struct ionic_devinfo dev_info; 149 }; 150 151 struct ionic_cq_info { 152 union { 153 void *cq_desc; 154 struct ionic_txq_comp *txcq; 155 struct ionic_rxq_comp *rxcq; 156 struct ionic_admin_comp *admincq; 157 struct ionic_notifyq_event *notifyq; 158 }; 159 }; 160 161 struct ionic_queue; 162 struct ionic_qcq; 163 struct ionic_desc_info; 164 165 typedef void (*ionic_desc_cb)(struct ionic_queue *q, 166 struct ionic_desc_info *desc_info, 167 struct ionic_cq_info *cq_info, void *cb_arg); 168 169 struct ionic_page_info { 170 struct page *page; 171 dma_addr_t dma_addr; 172 }; 173 174 struct ionic_desc_info { 175 union { 176 void *desc; 177 struct ionic_txq_desc *txq_desc; 178 struct ionic_rxq_desc *rxq_desc; 179 struct ionic_admin_cmd *adminq_desc; 180 }; 181 union { 182 void *sg_desc; 183 struct ionic_txq_sg_desc *txq_sg_desc; 184 struct ionic_rxq_sg_desc *rxq_sgl_desc; 185 }; 186 unsigned int npages; 187 struct ionic_page_info pages[IONIC_RX_MAX_SG_ELEMS + 1]; 188 ionic_desc_cb cb; 189 void *cb_arg; 190 }; 191 192 #define IONIC_QUEUE_NAME_MAX_SZ 32 193 194 struct ionic_queue { 195 struct device *dev; 196 struct ionic_lif *lif; 197 struct ionic_desc_info *info; 198 u16 head_idx; 199 u16 tail_idx; 200 unsigned int index; 201 unsigned int num_descs; 202 u64 dbell_count; 203 u64 stop; 204 u64 wake; 205 u64 drop; 206 struct ionic_dev *idev; 207 unsigned int type; 208 unsigned int hw_index; 209 unsigned int hw_type; 210 u64 dbval; 211 union { 212 void *base; 213 struct ionic_txq_desc *txq; 214 struct ionic_rxq_desc *rxq; 215 struct ionic_admin_cmd *adminq; 216 }; 217 union { 218 void *sg_base; 219 struct ionic_txq_sg_desc *txq_sgl; 220 struct ionic_rxq_sg_desc *rxq_sgl; 221 }; 222 dma_addr_t base_pa; 223 dma_addr_t sg_base_pa; 224 unsigned int desc_size; 225 unsigned int sg_desc_size; 226 unsigned int pid; 227 char name[IONIC_QUEUE_NAME_MAX_SZ]; 228 }; 229 230 #define IONIC_INTR_INDEX_NOT_ASSIGNED -1 231 #define IONIC_INTR_NAME_MAX_SZ 32 232 233 struct ionic_intr_info { 234 char name[IONIC_INTR_NAME_MAX_SZ]; 235 unsigned int index; 236 unsigned int vector; 237 u64 rearm_count; 238 unsigned int cpu; 239 cpumask_t affinity_mask; 240 u32 dim_coal_hw; 241 }; 242 243 struct ionic_cq { 244 struct ionic_lif *lif; 245 struct ionic_cq_info *info; 246 struct ionic_queue *bound_q; 247 struct ionic_intr_info *bound_intr; 248 u16 tail_idx; 249 bool done_color; 250 unsigned int num_descs; 251 unsigned int desc_size; 252 u64 compl_count; 253 void *base; 254 dma_addr_t base_pa; 255 }; 256 257 struct ionic; 258 259 static inline void ionic_intr_init(struct ionic_dev *idev, 260 struct ionic_intr_info *intr, 261 unsigned long index) 262 { 263 ionic_intr_clean(idev->intr_ctrl, index); 264 intr->index = index; 265 } 266 267 static inline unsigned int ionic_q_space_avail(struct ionic_queue *q) 268 { 269 unsigned int avail = q->tail_idx; 270 271 if (q->head_idx >= avail) 272 avail += q->num_descs - q->head_idx - 1; 273 else 274 avail -= q->head_idx + 1; 275 276 return avail; 277 } 278 279 static inline bool ionic_q_has_space(struct ionic_queue *q, unsigned int want) 280 { 281 return ionic_q_space_avail(q) >= want; 282 } 283 284 void ionic_init_devinfo(struct ionic *ionic); 285 int ionic_dev_setup(struct ionic *ionic); 286 287 void ionic_dev_cmd_go(struct ionic_dev *idev, union ionic_dev_cmd *cmd); 288 u8 ionic_dev_cmd_status(struct ionic_dev *idev); 289 bool ionic_dev_cmd_done(struct ionic_dev *idev); 290 void ionic_dev_cmd_comp(struct ionic_dev *idev, union ionic_dev_cmd_comp *comp); 291 292 void ionic_dev_cmd_identify(struct ionic_dev *idev, u8 ver); 293 void ionic_dev_cmd_init(struct ionic_dev *idev); 294 void ionic_dev_cmd_reset(struct ionic_dev *idev); 295 296 void ionic_dev_cmd_port_identify(struct ionic_dev *idev); 297 void ionic_dev_cmd_port_init(struct ionic_dev *idev); 298 void ionic_dev_cmd_port_reset(struct ionic_dev *idev); 299 void ionic_dev_cmd_port_state(struct ionic_dev *idev, u8 state); 300 void ionic_dev_cmd_port_speed(struct ionic_dev *idev, u32 speed); 301 void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, u8 an_enable); 302 void ionic_dev_cmd_port_fec(struct ionic_dev *idev, u8 fec_type); 303 void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type); 304 305 int ionic_set_vf_config(struct ionic *ionic, int vf, u8 attr, u8 *data); 306 void ionic_dev_cmd_queue_identify(struct ionic_dev *idev, 307 u16 lif_type, u8 qtype, u8 qver); 308 void ionic_dev_cmd_lif_identify(struct ionic_dev *idev, u8 type, u8 ver); 309 void ionic_dev_cmd_lif_init(struct ionic_dev *idev, u16 lif_index, 310 dma_addr_t addr); 311 void ionic_dev_cmd_lif_reset(struct ionic_dev *idev, u16 lif_index); 312 void ionic_dev_cmd_adminq_init(struct ionic_dev *idev, struct ionic_qcq *qcq, 313 u16 lif_index, u16 intr_index); 314 315 int ionic_db_page_num(struct ionic_lif *lif, int pid); 316 317 int ionic_cq_init(struct ionic_lif *lif, struct ionic_cq *cq, 318 struct ionic_intr_info *intr, 319 unsigned int num_descs, size_t desc_size); 320 void ionic_cq_map(struct ionic_cq *cq, void *base, dma_addr_t base_pa); 321 void ionic_cq_bind(struct ionic_cq *cq, struct ionic_queue *q); 322 typedef bool (*ionic_cq_cb)(struct ionic_cq *cq, struct ionic_cq_info *cq_info); 323 typedef void (*ionic_cq_done_cb)(void *done_arg); 324 unsigned int ionic_cq_service(struct ionic_cq *cq, unsigned int work_to_do, 325 ionic_cq_cb cb, ionic_cq_done_cb done_cb, 326 void *done_arg); 327 328 int ionic_q_init(struct ionic_lif *lif, struct ionic_dev *idev, 329 struct ionic_queue *q, unsigned int index, const char *name, 330 unsigned int num_descs, size_t desc_size, 331 size_t sg_desc_size, unsigned int pid); 332 void ionic_q_map(struct ionic_queue *q, void *base, dma_addr_t base_pa); 333 void ionic_q_sg_map(struct ionic_queue *q, void *base, dma_addr_t base_pa); 334 void ionic_q_post(struct ionic_queue *q, bool ring_doorbell, ionic_desc_cb cb, 335 void *cb_arg); 336 void ionic_q_rewind(struct ionic_queue *q, struct ionic_desc_info *start); 337 void ionic_q_service(struct ionic_queue *q, struct ionic_cq_info *cq_info, 338 unsigned int stop_index); 339 int ionic_heartbeat_check(struct ionic *ionic); 340 341 #endif /* _IONIC_DEV_H_ */ 342