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_CFG_DONE 0xF0 /* VF configuration done */ 45 #define NIC_MBOX_MSG_SHUTDOWN 0xF1 /* VF is being shutdown */ 46 #define NIC_MBOX_MSG_MAX 0x100 /* Maximum number of messages */ 47 48 /* Get vNIC VF configuration */ 49 struct nic_cfg_msg { 50 uint8_t msg; 51 uint8_t vf_id; 52 uint8_t node_id; 53 bool tns_mode:1; 54 bool sqs_mode:1; 55 bool loopback_supported:1; 56 uint8_t mac_addr[NICVF_MAC_ADDR_SIZE]; 57 }; 58 59 /* Qset configuration */ 60 struct qs_cfg_msg { 61 uint8_t msg; 62 uint8_t num; 63 uint8_t sqs_count; 64 uint64_t cfg; 65 }; 66 67 /* Receive queue configuration */ 68 struct rq_cfg_msg { 69 uint8_t msg; 70 uint8_t qs_num; 71 uint8_t rq_num; 72 uint64_t cfg; 73 }; 74 75 /* Send queue configuration */ 76 struct sq_cfg_msg { 77 uint8_t msg; 78 uint8_t qs_num; 79 uint8_t sq_num; 80 bool sqs_mode; 81 uint64_t cfg; 82 }; 83 84 /* Set VF's MAC address */ 85 struct set_mac_msg { 86 uint8_t msg; 87 uint8_t vf_id; 88 uint8_t mac_addr[NICVF_MAC_ADDR_SIZE]; 89 }; 90 91 /* Set Maximum frame size */ 92 struct set_frs_msg { 93 uint8_t msg; 94 uint8_t vf_id; 95 uint16_t max_frs; 96 }; 97 98 /* Set CPI algorithm type */ 99 struct cpi_cfg_msg { 100 uint8_t msg; 101 uint8_t vf_id; 102 uint8_t rq_cnt; 103 uint8_t cpi_alg; 104 }; 105 106 /* Get RSS table size */ 107 struct rss_sz_msg { 108 uint8_t msg; 109 uint8_t vf_id; 110 uint16_t ind_tbl_size; 111 }; 112 113 /* Set RSS configuration */ 114 struct rss_cfg_msg { 115 uint8_t msg; 116 uint8_t vf_id; 117 uint8_t hash_bits; 118 uint8_t tbl_len; 119 uint8_t tbl_offset; 120 #define RSS_IND_TBL_LEN_PER_MBX_MSG 8 121 uint8_t ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG]; 122 }; 123 124 /* Physical interface link status */ 125 struct bgx_link_status { 126 uint8_t msg; 127 uint8_t mac_type; 128 uint8_t link_up; 129 uint8_t duplex; 130 uint32_t speed; 131 }; 132 133 /* Allocate additional SQS to VF */ 134 struct sqs_alloc { 135 uint8_t msg; 136 uint8_t spec; 137 uint8_t qs_count; 138 uint8_t svf[MAX_SQS_PER_VF]; 139 }; 140 141 /* Set interface in loopback mode */ 142 struct set_loopback { 143 uint8_t msg; 144 uint8_t vf_id; 145 bool enable; 146 }; 147 148 /* Reset statistics counters */ 149 struct reset_stat_cfg { 150 uint8_t msg; 151 /* Bitmap to select NIC_PF_VNIC(vf_id)_RX_STAT(0..13) */ 152 uint16_t rx_stat_mask; 153 /* Bitmap to select NIC_PF_VNIC(vf_id)_TX_STAT(0..4) */ 154 uint8_t tx_stat_mask; 155 /* Bitmap to select NIC_PF_QS(0..127)_RQ(0..7)_STAT(0..1) 156 * bit14, bit15 NIC_PF_QS(vf_id)_RQ7_STAT(0..1) 157 * bit12, bit13 NIC_PF_QS(vf_id)_RQ6_STAT(0..1) 158 * .. 159 * bit2, bit3 NIC_PF_QS(vf_id)_RQ1_STAT(0..1) 160 * bit0, bit1 NIC_PF_QS(vf_id)_RQ0_STAT(0..1) 161 */ 162 uint16_t rq_stat_mask; 163 /* Bitmap to select NIC_PF_QS(0..127)_SQ(0..7)_STAT(0..1) 164 * bit14, bit15 NIC_PF_QS(vf_id)_SQ7_STAT(0..1) 165 * bit12, bit13 NIC_PF_QS(vf_id)_SQ6_STAT(0..1) 166 * .. 167 * bit2, bit3 NIC_PF_QS(vf_id)_SQ1_STAT(0..1) 168 * bit0, bit1 NIC_PF_QS(vf_id)_SQ0_STAT(0..1) 169 */ 170 uint16_t sq_stat_mask; 171 }; 172 173 /* Set link up/down */ 174 struct set_link_state { 175 uint8_t msg; 176 uint8_t vf_id; 177 bool enable; 178 }; 179 180 struct nic_mbx { 181 /* 128 bit shared memory between PF and each VF */ 182 union { 183 struct { uint8_t msg; } msg; 184 struct nic_cfg_msg nic_cfg; 185 struct qs_cfg_msg qs; 186 struct rq_cfg_msg rq; 187 struct sq_cfg_msg sq; 188 struct set_mac_msg mac; 189 struct set_frs_msg frs; 190 struct cpi_cfg_msg cpi_cfg; 191 struct rss_sz_msg rss_size; 192 struct rss_cfg_msg rss_cfg; 193 struct bgx_link_status link_status; 194 struct sqs_alloc sqs_alloc; 195 struct set_loopback lbk; 196 struct reset_stat_cfg reset_stat; 197 struct set_link_state set_link; 198 }; 199 }; 200 201 NICVF_STATIC_ASSERT(sizeof(struct nic_mbx) <= 16); 202 203 int nicvf_handle_mbx_intr(struct nicvf *nic); 204 int nicvf_mbox_check_pf_ready(struct nicvf *nic); 205 int nicvf_mbox_qset_config(struct nicvf *nic, struct pf_qs_cfg *qs_cfg); 206 int nicvf_mbox_request_sqs(struct nicvf *nic); 207 int nicvf_mbox_rq_config(struct nicvf *nic, uint16_t qidx, 208 struct pf_rq_cfg *pf_rq_cfg); 209 int nicvf_mbox_sq_config(struct nicvf *nic, uint16_t qidx); 210 int nicvf_mbox_rq_drop_config(struct nicvf *nic, uint16_t qidx, bool enable); 211 int nicvf_mbox_rq_bp_config(struct nicvf *nic, uint16_t qidx, bool enable); 212 int nicvf_mbox_set_mac_addr(struct nicvf *nic, 213 const uint8_t mac[NICVF_MAC_ADDR_SIZE]); 214 int nicvf_mbox_config_cpi(struct nicvf *nic, uint32_t qcnt); 215 int nicvf_mbox_get_rss_size(struct nicvf *nic); 216 int nicvf_mbox_config_rss(struct nicvf *nic); 217 int nicvf_mbox_update_hw_max_frs(struct nicvf *nic, uint16_t mtu); 218 int nicvf_mbox_rq_sync(struct nicvf *nic); 219 int nicvf_mbox_loopback_config(struct nicvf *nic, bool enable); 220 int nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask, 221 uint8_t tx_stat_mask, uint16_t rq_stat_mask, uint16_t sq_stat_mask); 222 int nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable); 223 void nicvf_mbox_shutdown(struct nicvf *nic); 224 void nicvf_mbox_cfg_done(struct nicvf *nic); 225 226 #endif /* __THUNDERX_NICVF_MBOX__ */ 227