1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
8 #include <rte_kvargs.h>
11 #define AVF_AQ_BUF_SZ 4096
12 #define AVF_RESET_WAIT_CNT 50
13 #define AVF_BUF_SIZE_MIN 1024
14 #define AVF_FRAME_SIZE_MAX 9728
15 #define AVF_QUEUE_BASE_ADDR_UNIT 128
17 #define AVF_MAX_NUM_QUEUES 16
19 #define AVF_NUM_MACADDR_MAX 64
21 #define AVF_DEFAULT_RX_PTHRESH 8
22 #define AVF_DEFAULT_RX_HTHRESH 8
23 #define AVF_DEFAULT_RX_WTHRESH 0
25 #define AVF_DEFAULT_RX_FREE_THRESH 32
27 #define AVF_DEFAULT_TX_PTHRESH 32
28 #define AVF_DEFAULT_TX_HTHRESH 0
29 #define AVF_DEFAULT_TX_WTHRESH 0
31 #define AVF_DEFAULT_TX_FREE_THRESH 32
32 #define AVF_DEFAULT_TX_RS_THRESH 32
34 #define AVF_BASIC_OFFLOAD_CAPS ( \
35 VF_BASE_MODE_OFFLOADS | \
36 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | \
37 VIRTCHNL_VF_OFFLOAD_RX_POLLING)
39 #define AVF_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
40 #define AVF_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
42 /* Default queue interrupt throttling time in microseconds */
43 #define AVF_ITR_INDEX_DEFAULT 0
44 #define AVF_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
45 #define AVF_QUEUE_ITR_INTERVAL_MAX 8160 /* 8160 us */
47 /* The overhead from MTU to max frame size.
48 * Considering QinQ packet, the VLAN tag needs to be counted twice.
50 #define AVF_VLAN_TAG_SIZE 4
51 #define AVF_ETH_OVERHEAD \
52 (ETHER_HDR_LEN + ETHER_CRC_LEN + AVF_VLAN_TAG_SIZE * 2)
58 /* Structure that defines a VSI, associated with a adapter. */
60 struct avf_adapter *adapter; /* Backreference to associated adapter */
62 uint16_t nb_qps; /* Number of queue pairs VSI can occupy */
63 uint16_t nb_used_qps; /* Number of queue pairs VSI uses */
64 uint16_t max_macaddrs; /* Maximum number of MAC addresses */
66 uint16_t msix_intr; /* The MSIX interrupt binds to VSI */
69 /* TODO: is that correct to assume the max number to be 16 ?*/
70 #define AVF_MAX_MSIX_VECTORS 16
72 /* Structure to store private data specific for VF instance. */
74 uint16_t num_queue_pairs;
75 uint16_t max_pkt_len; /* Maximum packet length */
76 uint16_t mac_num; /* Number of MAC addresses */
77 bool promisc_unicast_enabled;
78 bool promisc_multicast_enabled;
80 struct virtchnl_version_info virtchnl_version;
81 struct virtchnl_vf_resource *vf_res; /* VF resource */
82 struct virtchnl_vsi_resource *vsi_res; /* LAN VSI */
84 volatile enum virtchnl_ops pend_cmd; /* pending command not finished */
85 uint32_t cmd_retval; /* return value of the cmd response from PF */
86 uint8_t *aq_resp; /* buffer to store the adminq response from PF */
91 enum virtchnl_link_speed link_speed;
99 uint16_t nb_msix; /* number of MSI-X interrupts on Rx */
100 uint16_t msix_base; /* msix vector base from */
101 /* queue bitmask for each vector */
102 uint16_t rxq_map[AVF_MAX_MSIX_VECTORS];
105 #define AVF_MAX_PKT_TYPE 256
107 /* Structure to store private data for each VF instance. */
110 struct rte_eth_dev *eth_dev;
114 /* AVF_DEV_PRIVATE_TO */
115 #define AVF_DEV_PRIVATE_TO_ADAPTER(adapter) \
116 ((struct avf_adapter *)adapter)
117 #define AVF_DEV_PRIVATE_TO_VF(adapter) \
118 (&((struct avf_adapter *)adapter)->vf)
119 #define AVF_DEV_PRIVATE_TO_HW(adapter) \
120 (&((struct avf_adapter *)adapter)->hw)
123 #define AVF_VSI_TO_HW(vsi) \
124 (&(((struct avf_vsi *)vsi)->adapter->hw))
125 #define AVF_VSI_TO_VF(vsi) \
126 (&(((struct avf_vsi *)vsi)->adapter->vf))
127 #define AVF_VSI_TO_ETH_DEV(vsi) \
128 (((struct avf_vsi *)vsi)->adapter->eth_dev)
131 avf_init_adminq_parameter(struct avf_hw *hw)
133 hw->aq.num_arq_entries = AVF_AQ_LEN;
134 hw->aq.num_asq_entries = AVF_AQ_LEN;
135 hw->aq.arq_buf_size = AVF_AQ_BUF_SZ;
136 hw->aq.asq_buf_size = AVF_AQ_BUF_SZ;
139 static inline uint16_t
140 avf_calc_itr_interval(int16_t interval)
142 if (interval < 0 || interval > AVF_QUEUE_ITR_INTERVAL_MAX)
143 interval = AVF_QUEUE_ITR_INTERVAL_DEFAULT;
145 /* Convert to hardware count, as writing each 1 represents 2 us */
149 /* structure used for sending and checking response of virtchnl ops */
150 struct avf_cmd_info {
151 enum virtchnl_ops ops;
152 uint8_t *in_args; /* buffer for sending */
153 uint32_t in_args_size; /* buffer size for sending */
154 uint8_t *out_buffer; /* buffer for response */
155 uint32_t out_size; /* buffer size for response */
158 /* clear current command. Only call in case execute
159 * _atomic_set_cmd successfully.
162 _clear_cmd(struct avf_info *vf)
165 vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
166 vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
169 /* Check there is pending cmd in execution. If none, set new command. */
171 _atomic_set_cmd(struct avf_info *vf, enum virtchnl_ops ops)
173 int ret = rte_atomic32_cmpset(&vf->pend_cmd, VIRTCHNL_OP_UNKNOWN, ops);
176 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
181 int avf_check_api_version(struct avf_adapter *adapter);
182 int avf_get_vf_resource(struct avf_adapter *adapter);
183 void avf_handle_virtchnl_msg(struct rte_eth_dev *dev);
184 #endif /* _AVF_ETHDEV_H_ */