net/avf: initialize PMD
[dpdk.git] / drivers / net / avf / avf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _AVF_ETHDEV_H_
6 #define _AVF_ETHDEV_H_
7
8 #include <rte_kvargs.h>
9
10 #define AVF_AQ_LEN               32
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
16
17 #define AVF_MAX_NUM_QUEUES       16
18
19 #define AVF_NUM_MACADDR_MAX      64
20
21 #define AVF_DEFAULT_RX_PTHRESH      8
22 #define AVF_DEFAULT_RX_HTHRESH      8
23 #define AVF_DEFAULT_RX_WTHRESH      0
24
25 #define AVF_DEFAULT_RX_FREE_THRESH  32
26
27 #define AVF_DEFAULT_TX_PTHRESH      32
28 #define AVF_DEFAULT_TX_HTHRESH      0
29 #define AVF_DEFAULT_TX_WTHRESH      0
30
31 #define AVF_DEFAULT_TX_FREE_THRESH  32
32 #define AVF_DEFAULT_TX_RS_THRESH 32
33
34 #define AVF_BASIC_OFFLOAD_CAPS  ( \
35         VF_BASE_MODE_OFFLOADS | \
36         VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | \
37         VIRTCHNL_VF_OFFLOAD_RX_POLLING)
38
39 #define AVF_MISC_VEC_ID                RTE_INTR_VEC_ZERO_OFFSET
40 #define AVF_RX_VEC_START               RTE_INTR_VEC_RXTX_OFFSET
41
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 */
46
47 /* The overhead from MTU to max frame size.
48  * Considering QinQ packet, the VLAN tag needs to be counted twice.
49  */
50 #define AVF_VLAN_TAG_SIZE               4
51 #define AVF_ETH_OVERHEAD \
52         (ETHER_HDR_LEN + ETHER_CRC_LEN + AVF_VLAN_TAG_SIZE * 2)
53
54 struct avf_adapter;
55 struct avf_rx_queue;
56 struct avf_tx_queue;
57
58 /* Structure that defines a VSI, associated with a adapter. */
59 struct avf_vsi {
60         struct avf_adapter *adapter; /* Backreference to associated adapter */
61         uint16_t vsi_id;
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 */
65         uint16_t base_vector;
66         uint16_t msix_intr;      /* The MSIX interrupt binds to VSI */
67 };
68
69 /* TODO: is that correct to assume the max number to be 16 ?*/
70 #define AVF_MAX_MSIX_VECTORS   16
71
72 /* Structure to store private data specific for VF instance. */
73 struct avf_info {
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;
79
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 */
83
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 */
87
88         /* Event from pf */
89         bool dev_closed;
90         bool link_up;
91         enum virtchnl_link_speed link_speed;
92
93         struct avf_vsi vsi;
94         bool vf_reset;
95         uint64_t flags;
96
97         uint8_t *rss_lut;
98         uint8_t *rss_key;
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];
103 };
104
105 #define AVF_MAX_PKT_TYPE 256
106
107 /* Structure to store private data for each VF instance. */
108 struct avf_adapter {
109         struct avf_hw hw;
110         struct rte_eth_dev *eth_dev;
111         struct avf_info vf;
112 };
113
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)
121
122 /* AVF_VSI_TO */
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)
129
130 static inline void
131 avf_init_adminq_parameter(struct avf_hw *hw)
132 {
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;
137 }
138
139 static inline uint16_t
140 avf_calc_itr_interval(int16_t interval)
141 {
142         if (interval < 0 || interval > AVF_QUEUE_ITR_INTERVAL_MAX)
143                 interval = AVF_QUEUE_ITR_INTERVAL_DEFAULT;
144
145         /* Convert to hardware count, as writing each 1 represents 2 us */
146         return interval / 2;
147 }
148
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 */
156 };
157
158 /* clear current command. Only call in case execute
159  * _atomic_set_cmd successfully.
160  */
161 static inline void
162 _clear_cmd(struct avf_info *vf)
163 {
164         rte_wmb();
165         vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
166         vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
167 }
168
169 /* Check there is pending cmd in execution. If none, set new command. */
170 static inline int
171 _atomic_set_cmd(struct avf_info *vf, enum virtchnl_ops ops)
172 {
173         int ret = rte_atomic32_cmpset(&vf->pend_cmd, VIRTCHNL_OP_UNKNOWN, ops);
174
175         if (!ret)
176                 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
177
178         return !ret;
179 }
180
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_ */