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_RSS_OFFLOAD_ALL ( \
41 ETH_RSS_NONFRAG_IPV4_TCP | \
42 ETH_RSS_NONFRAG_IPV4_UDP | \
43 ETH_RSS_NONFRAG_IPV4_SCTP | \
44 ETH_RSS_NONFRAG_IPV4_OTHER)
46 #define AVF_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
47 #define AVF_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
49 /* Default queue interrupt throttling time in microseconds */
50 #define AVF_ITR_INDEX_DEFAULT 0
51 #define AVF_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
52 #define AVF_QUEUE_ITR_INTERVAL_MAX 8160 /* 8160 us */
54 /* The overhead from MTU to max frame size.
55 * Considering QinQ packet, the VLAN tag needs to be counted twice.
57 #define AVF_VLAN_TAG_SIZE 4
58 #define AVF_ETH_OVERHEAD \
59 (ETHER_HDR_LEN + ETHER_CRC_LEN + AVF_VLAN_TAG_SIZE * 2)
65 /* Structure that defines a VSI, associated with a adapter. */
67 struct avf_adapter *adapter; /* Backreference to associated adapter */
69 uint16_t nb_qps; /* Number of queue pairs VSI can occupy */
70 uint16_t nb_used_qps; /* Number of queue pairs VSI uses */
71 uint16_t max_macaddrs; /* Maximum number of MAC addresses */
73 uint16_t msix_intr; /* The MSIX interrupt binds to VSI */
76 /* TODO: is that correct to assume the max number to be 16 ?*/
77 #define AVF_MAX_MSIX_VECTORS 16
79 /* Structure to store private data specific for VF instance. */
81 uint16_t num_queue_pairs;
82 uint16_t max_pkt_len; /* Maximum packet length */
83 uint16_t mac_num; /* Number of MAC addresses */
84 bool promisc_unicast_enabled;
85 bool promisc_multicast_enabled;
87 struct virtchnl_version_info virtchnl_version;
88 struct virtchnl_vf_resource *vf_res; /* VF resource */
89 struct virtchnl_vsi_resource *vsi_res; /* LAN VSI */
91 volatile enum virtchnl_ops pend_cmd; /* pending command not finished */
92 uint32_t cmd_retval; /* return value of the cmd response from PF */
93 uint8_t *aq_resp; /* buffer to store the adminq response from PF */
98 enum virtchnl_link_speed link_speed;
106 uint16_t nb_msix; /* number of MSI-X interrupts on Rx */
107 uint16_t msix_base; /* msix vector base from */
108 /* queue bitmask for each vector */
109 uint16_t rxq_map[AVF_MAX_MSIX_VECTORS];
112 #define AVF_MAX_PKT_TYPE 256
114 /* Structure to store private data for each VF instance. */
117 struct rte_eth_dev *eth_dev;
121 /* AVF_DEV_PRIVATE_TO */
122 #define AVF_DEV_PRIVATE_TO_ADAPTER(adapter) \
123 ((struct avf_adapter *)adapter)
124 #define AVF_DEV_PRIVATE_TO_VF(adapter) \
125 (&((struct avf_adapter *)adapter)->vf)
126 #define AVF_DEV_PRIVATE_TO_HW(adapter) \
127 (&((struct avf_adapter *)adapter)->hw)
130 #define AVF_VSI_TO_HW(vsi) \
131 (&(((struct avf_vsi *)vsi)->adapter->hw))
132 #define AVF_VSI_TO_VF(vsi) \
133 (&(((struct avf_vsi *)vsi)->adapter->vf))
134 #define AVF_VSI_TO_ETH_DEV(vsi) \
135 (((struct avf_vsi *)vsi)->adapter->eth_dev)
138 avf_init_adminq_parameter(struct avf_hw *hw)
140 hw->aq.num_arq_entries = AVF_AQ_LEN;
141 hw->aq.num_asq_entries = AVF_AQ_LEN;
142 hw->aq.arq_buf_size = AVF_AQ_BUF_SZ;
143 hw->aq.asq_buf_size = AVF_AQ_BUF_SZ;
146 static inline uint16_t
147 avf_calc_itr_interval(int16_t interval)
149 if (interval < 0 || interval > AVF_QUEUE_ITR_INTERVAL_MAX)
150 interval = AVF_QUEUE_ITR_INTERVAL_DEFAULT;
152 /* Convert to hardware count, as writing each 1 represents 2 us */
156 /* structure used for sending and checking response of virtchnl ops */
157 struct avf_cmd_info {
158 enum virtchnl_ops ops;
159 uint8_t *in_args; /* buffer for sending */
160 uint32_t in_args_size; /* buffer size for sending */
161 uint8_t *out_buffer; /* buffer for response */
162 uint32_t out_size; /* buffer size for response */
165 /* clear current command. Only call in case execute
166 * _atomic_set_cmd successfully.
169 _clear_cmd(struct avf_info *vf)
172 vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
173 vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
176 /* Check there is pending cmd in execution. If none, set new command. */
178 _atomic_set_cmd(struct avf_info *vf, enum virtchnl_ops ops)
180 int ret = rte_atomic32_cmpset(&vf->pend_cmd, VIRTCHNL_OP_UNKNOWN, ops);
183 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
188 int avf_check_api_version(struct avf_adapter *adapter);
189 int avf_get_vf_resource(struct avf_adapter *adapter);
190 void avf_handle_virtchnl_msg(struct rte_eth_dev *dev);
191 int avf_enable_vlan_strip(struct avf_adapter *adapter);
192 int avf_disable_vlan_strip(struct avf_adapter *adapter);
193 int avf_switch_queue(struct avf_adapter *adapter, uint16_t qid,
195 int avf_enable_queues(struct avf_adapter *adapter);
196 int avf_disable_queues(struct avf_adapter *adapter);
197 int avf_configure_rss_lut(struct avf_adapter *adapter);
198 int avf_configure_rss_key(struct avf_adapter *adapter);
199 int avf_configure_queues(struct avf_adapter *adapter);
200 int avf_config_irq_map(struct avf_adapter *adapter);
201 void avf_add_del_all_mac_addr(struct avf_adapter *adapter, bool add);
202 #endif /* _AVF_ETHDEV_H_ */