1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2016 Cavium, Inc 3 */ 4 5 #ifndef __THUNDERX_NICVF_MBOX__ 6 #define __THUNDERX_NICVF_MBOX__ 7 8 #include <stdint.h> 9 10 #include "nicvf_plat.h" 11 #include "../nicvf_struct.h" 12 13 /* PF <--> VF Mailbox communication 14 * Two 64bit registers are shared between PF and VF for each VF 15 * Writing into second register means end of message. 16 */ 17 18 /* PF <--> VF mailbox communication */ 19 #define NIC_PF_VF_MAILBOX_SIZE 2 20 #define NIC_MBOX_MSG_TIMEOUT 2000 /* ms */ 21 22 /* Mailbox message types */ 23 #define NIC_MBOX_MSG_INVALID 0x00 /* Invalid message */ 24 #define NIC_MBOX_MSG_READY 0x01 /* Is PF ready to rcv msgs */ 25 #define NIC_MBOX_MSG_ACK 0x02 /* ACK the message received */ 26 #define NIC_MBOX_MSG_NACK 0x03 /* NACK the message received */ 27 #define NIC_MBOX_MSG_QS_CFG 0x04 /* Configure Qset */ 28 #define NIC_MBOX_MSG_RQ_CFG 0x05 /* Configure receive queue */ 29 #define NIC_MBOX_MSG_SQ_CFG 0x06 /* Configure Send queue */ 30 #define NIC_MBOX_MSG_RQ_DROP_CFG 0x07 /* Configure receive queue */ 31 #define NIC_MBOX_MSG_SET_MAC 0x08 /* Add MAC ID to DMAC filter */ 32 #define NIC_MBOX_MSG_SET_MAX_FRS 0x09 /* Set max frame size */ 33 #define NIC_MBOX_MSG_CPI_CFG 0x0A /* Config CPI, RSSI */ 34 #define NIC_MBOX_MSG_RSS_SIZE 0x0B /* Get RSS indir_tbl size */ 35 #define NIC_MBOX_MSG_RSS_CFG 0x0C /* Config RSS table */ 36 #define NIC_MBOX_MSG_RSS_CFG_CONT 0x0D /* RSS config continuation */ 37 #define NIC_MBOX_MSG_RQ_BP_CFG 0x0E /* RQ backpressure config */ 38 #define NIC_MBOX_MSG_RQ_SW_SYNC 0x0F /* Flush inflight pkts to RQ */ 39 #define NIC_MBOX_MSG_BGX_LINK_CHANGE 0x11 /* BGX:LMAC link status */ 40 #define NIC_MBOX_MSG_ALLOC_SQS 0x12 /* Allocate secondary Qset */ 41 #define NIC_MBOX_MSG_LOOPBACK 0x16 /* Set interface in loopback */ 42 #define NIC_MBOX_MSG_RESET_STAT_COUNTER 0x17 /* Reset statistics counters */ 43 #define NIC_MBOX_MSG_SET_LINK 0x21 /* Set link up/down */ 44 #define NIC_MBOX_MSG_CHANGE_MODE 0x22 /* Change mode */ 45 #define NIC_MBOX_MSG_CFG_DONE 0xF0 /* VF configuration done */ 46 #define NIC_MBOX_MSG_SHUTDOWN 0xF1 /* VF is being shutdown */ 47 #define NIC_MBOX_MSG_RESET_XCAST 0xF2 /* Reset DCAM filtering mode */ 48 #define NIC_MBOX_MSG_ADD_MCAST 0xF3 /* ADD MAC to DCAM filters */ 49 #define NIC_MBOX_MSG_SET_XCAST 0xF4 /* Set MCAST/BCAST Rx mode */ 50 #define NIC_MBOX_MSG_MAX 0x100 /* Maximum number of messages */ 51 52 /* Get vNIC VF configuration */ 53 struct nic_cfg_msg { 54 uint8_t msg; 55 uint8_t vf_id; 56 uint8_t node_id; 57 bool tns_mode:1; 58 bool sqs_mode:1; 59 bool loopback_supported:1; 60 uint8_t mac_addr[NICVF_MAC_ADDR_SIZE]; 61 }; 62 63 /* Qset configuration */ 64 struct qs_cfg_msg { 65 uint8_t msg; 66 uint8_t num; 67 uint8_t sqs_count; 68 uint64_t cfg; 69 }; 70 71 /* Receive queue configuration */ 72 struct rq_cfg_msg { 73 uint8_t msg; 74 uint8_t qs_num; 75 uint8_t rq_num; 76 uint64_t cfg; 77 }; 78 79 /* Send queue configuration */ 80 struct sq_cfg_msg { 81 uint8_t msg; 82 uint8_t qs_num; 83 uint8_t sq_num; 84 bool sqs_mode; 85 uint64_t cfg; 86 }; 87 88 /* Set VF's MAC address */ 89 struct set_mac_msg { 90 uint8_t msg; 91 uint8_t vf_id; 92 uint8_t mac_addr[NICVF_MAC_ADDR_SIZE]; 93 }; 94 95 /* Set Maximum frame size */ 96 struct set_frs_msg { 97 uint8_t msg; 98 uint8_t vf_id; 99 uint16_t max_frs; 100 }; 101 102 /* Set CPI algorithm type */ 103 struct cpi_cfg_msg { 104 uint8_t msg; 105 uint8_t vf_id; 106 uint8_t rq_cnt; 107 uint8_t cpi_alg; 108 }; 109 110 /* Get RSS table size */ 111 struct rss_sz_msg { 112 uint8_t msg; 113 uint8_t vf_id; 114 uint16_t ind_tbl_size; 115 }; 116 117 /* Set RSS configuration */ 118 struct rss_cfg_msg { 119 uint8_t msg; 120 uint8_t vf_id; 121 uint8_t hash_bits; 122 uint8_t tbl_len; 123 uint8_t tbl_offset; 124 #define RSS_IND_TBL_LEN_PER_MBX_MSG 8 125 uint8_t ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG]; 126 }; 127 128 /* Physical interface link status */ 129 struct bgx_link_status { 130 uint8_t msg; 131 uint8_t mac_type; 132 uint8_t link_up; 133 uint8_t duplex; 134 uint32_t speed; 135 }; 136 137 /* Allocate additional SQS to VF */ 138 struct sqs_alloc { 139 uint8_t msg; 140 uint8_t spec; 141 uint8_t qs_count; 142 uint8_t svf[MAX_SQS_PER_VF]; 143 }; 144 145 /* Set interface in loopback mode */ 146 struct set_loopback { 147 uint8_t msg; 148 uint8_t vf_id; 149 bool enable; 150 }; 151 152 /* Reset statistics counters */ 153 struct reset_stat_cfg { 154 uint8_t msg; 155 /* Bitmap to select NIC_PF_VNIC(vf_id)_RX_STAT(0..13) */ 156 uint16_t rx_stat_mask; 157 /* Bitmap to select NIC_PF_VNIC(vf_id)_TX_STAT(0..4) */ 158 uint8_t tx_stat_mask; 159 /* Bitmap to select NIC_PF_QS(0..127)_RQ(0..7)_STAT(0..1) 160 * bit14, bit15 NIC_PF_QS(vf_id)_RQ7_STAT(0..1) 161 * bit12, bit13 NIC_PF_QS(vf_id)_RQ6_STAT(0..1) 162 * .. 163 * bit2, bit3 NIC_PF_QS(vf_id)_RQ1_STAT(0..1) 164 * bit0, bit1 NIC_PF_QS(vf_id)_RQ0_STAT(0..1) 165 */ 166 uint16_t rq_stat_mask; 167 /* Bitmap to select NIC_PF_QS(0..127)_SQ(0..7)_STAT(0..1) 168 * bit14, bit15 NIC_PF_QS(vf_id)_SQ7_STAT(0..1) 169 * bit12, bit13 NIC_PF_QS(vf_id)_SQ6_STAT(0..1) 170 * .. 171 * bit2, bit3 NIC_PF_QS(vf_id)_SQ1_STAT(0..1) 172 * bit0, bit1 NIC_PF_QS(vf_id)_SQ0_STAT(0..1) 173 */ 174 uint16_t sq_stat_mask; 175 }; 176 177 /* Set link up/down */ 178 struct set_link_state { 179 uint8_t msg; 180 uint8_t vf_id; 181 bool enable; 182 }; 183 184 /* Change link mode */ 185 struct change_link_mode_msg { 186 uint8_t msg; 187 uint8_t vf_id; 188 uint8_t qlm_mode; 189 bool autoneg; 190 uint8_t duplex; 191 uint32_t speed; 192 193 }; 194 195 struct xcast { 196 uint8_t msg; 197 uint8_t mode; 198 uint64_t mac:48; 199 }; 200 201 struct nic_mbx { 202 /* 128 bit shared memory between PF and each VF */ 203 union { 204 struct { uint8_t msg; } msg; 205 struct nic_cfg_msg nic_cfg; 206 struct qs_cfg_msg qs; 207 struct rq_cfg_msg rq; 208 struct sq_cfg_msg sq; 209 struct set_mac_msg mac; 210 struct set_frs_msg frs; 211 struct cpi_cfg_msg cpi_cfg; 212 struct rss_sz_msg rss_size; 213 struct rss_cfg_msg rss_cfg; 214 struct bgx_link_status link_status; 215 struct sqs_alloc sqs_alloc; 216 struct set_loopback lbk; 217 struct reset_stat_cfg reset_stat; 218 struct set_link_state set_link; 219 struct change_link_mode_msg mode; 220 struct xcast xcast; 221 }; 222 }; 223 224 NICVF_STATIC_ASSERT(sizeof(struct nic_mbx) <= 16); 225 226 int nicvf_handle_mbx_intr(struct nicvf *nic); 227 int nicvf_mbox_check_pf_ready(struct nicvf *nic); 228 int nicvf_mbox_qset_config(struct nicvf *nic, struct pf_qs_cfg *qs_cfg); 229 int nicvf_mbox_request_sqs(struct nicvf *nic); 230 int nicvf_mbox_rq_config(struct nicvf *nic, uint16_t qidx, 231 struct pf_rq_cfg *pf_rq_cfg); 232 int nicvf_mbox_sq_config(struct nicvf *nic, uint16_t qidx); 233 int nicvf_mbox_rq_drop_config(struct nicvf *nic, uint16_t qidx, bool enable); 234 int nicvf_mbox_rq_bp_config(struct nicvf *nic, uint16_t qidx, bool enable); 235 int nicvf_mbox_set_mac_addr(struct nicvf *nic, 236 const uint8_t mac[NICVF_MAC_ADDR_SIZE]); 237 int nicvf_mbox_config_cpi(struct nicvf *nic, uint32_t qcnt); 238 int nicvf_mbox_get_rss_size(struct nicvf *nic); 239 int nicvf_mbox_config_rss(struct nicvf *nic); 240 int nicvf_mbox_update_hw_max_frs(struct nicvf *nic, uint16_t mtu); 241 int nicvf_mbox_rq_sync(struct nicvf *nic); 242 int nicvf_mbox_loopback_config(struct nicvf *nic, bool enable); 243 int nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask, 244 uint8_t tx_stat_mask, uint16_t rq_stat_mask, uint16_t sq_stat_mask); 245 int nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable); 246 void nicvf_mbox_shutdown(struct nicvf *nic); 247 void nicvf_mbox_cfg_done(struct nicvf *nic); 248 void nicvf_mbox_link_change(struct nicvf *nic); 249 void nicvf_mbox_reset_xcast(struct nicvf *nic); 250 int nicvf_mbox_change_mode(struct nicvf *nic, struct change_link_mode *cfg); 251 int nicvf_mbox_set_xcast(struct nicvf *nic, uint8_t mode, uint64_t mac); 252 253 #endif /* __THUNDERX_NICVF_MBOX__ */ 254