20363389a0d65901452dfde79be0ac165a05f40f
[dpdk.git] / drivers / net / netvsc / hn_var.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2009-2018 Microsoft Corp.
3  * Copyright (c) 2016 Brocade Communications Systems, Inc.
4  * Copyright (c) 2012 NetApp Inc.
5  * Copyright (c) 2012 Citrix Inc.
6  * All rights reserved.
7  */
8
9 /*
10  * Tunable ethdev params
11  */
12 #define HN_MIN_RX_BUF_SIZE      1024
13 #define HN_MAX_XFER_LEN         2048
14 #define HN_MAX_MAC_ADDRS        1
15 #define HN_MAX_CHANNELS         64
16
17 /* Claimed to be 12232B */
18 #define HN_MTU_MAX              (9 * 1024)
19
20 /* Retry interval */
21 #define HN_CHAN_INTERVAL_US     100
22
23 /* Host monitor interval */
24 #define HN_CHAN_LATENCY_NS      50000
25
26 /* Buffers need to be aligned */
27 #ifndef PAGE_SIZE
28 #define PAGE_SIZE 4096
29 #endif
30
31 #ifndef PAGE_MASK
32 #define PAGE_MASK (PAGE_SIZE - 1)
33 #endif
34
35 struct hn_data;
36 struct hn_txdesc;
37
38 struct hn_stats {
39         uint64_t        packets;
40         uint64_t        bytes;
41         uint64_t        errors;
42         uint64_t        ring_full;
43         uint64_t        channel_full;
44         uint64_t        multicast;
45         uint64_t        broadcast;
46         /* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */
47         uint64_t        size_bins[8];
48 };
49
50 struct hn_tx_queue {
51         struct hn_data  *hv;
52         struct vmbus_channel *chan;
53         uint16_t        port_id;
54         uint16_t        queue_id;
55         uint32_t        free_thresh;
56         struct rte_mempool *txdesc_pool;
57         void            *tx_rndis;
58
59         /* Applied packet transmission aggregation limits. */
60         uint32_t        agg_szmax;
61         uint32_t        agg_pktmax;
62         uint32_t        agg_align;
63
64         /* Packet transmission aggregation states */
65         struct hn_txdesc *agg_txd;
66         uint32_t        agg_pktleft;
67         uint32_t        agg_szleft;
68         struct rndis_packet_msg *agg_prevpkt;
69
70         struct hn_stats stats;
71 };
72
73 struct hn_rx_queue {
74         struct hn_data  *hv;
75         struct vmbus_channel *chan;
76         struct rte_mempool *mb_pool;
77         struct rte_ring *rx_ring;
78
79         rte_spinlock_t ring_lock;
80         uint32_t event_sz;
81         uint16_t port_id;
82         uint16_t queue_id;
83         struct hn_stats stats;
84
85         void *event_buf;
86 };
87
88
89 /* multi-packet data from host */
90 struct hn_rx_bufinfo {
91         struct vmbus_channel *chan;
92         struct hn_data *hv;
93         uint64_t        xactid;
94         struct rte_mbuf_ext_shared_info shinfo;
95 } __rte_cache_aligned;
96
97 #define HN_INVALID_PORT UINT16_MAX
98
99 struct hn_data {
100         struct rte_vmbus_device *vmbus;
101         struct hn_rx_queue *primary;
102         rte_rwlock_t    vf_lock;
103         uint16_t        port_id;
104         uint16_t        vf_port;
105
106         uint8_t         vf_present;
107         uint8_t         closed;
108         uint8_t         vlan_strip;
109
110         uint32_t        link_status;
111         uint32_t        link_speed;
112
113         struct rte_mem_resource *rxbuf_res;     /* UIO resource for Rx */
114         struct hn_rx_bufinfo *rxbuf_info;
115         uint32_t        rxbuf_section_cnt;      /* # of Rx sections */
116         volatile uint32_t rxbuf_outstanding;
117         uint16_t        max_queues;             /* Max available queues */
118         uint16_t        num_queues;
119         uint64_t        rss_offloads;
120
121         rte_spinlock_t  chim_lock;
122         struct rte_mem_resource *chim_res;      /* UIO resource for Tx */
123         struct rte_bitmap *chim_bmap;           /* Send buffer map */
124         void            *chim_bmem;
125         uint32_t        chim_szmax;             /* Max size per buffer */
126         uint32_t        chim_cnt;               /* Max packets per buffer */
127
128         uint32_t        latency;
129         uint32_t        nvs_ver;
130         uint32_t        ndis_ver;
131         uint32_t        rndis_agg_size;
132         uint32_t        rndis_agg_pkts;
133         uint32_t        rndis_agg_align;
134
135         volatile uint32_t  rndis_pending;
136         rte_atomic32_t  rndis_req_id;
137         uint8_t         rndis_resp[256];
138
139         uint32_t        rss_hash;
140         uint8_t         rss_key[40];
141         uint16_t        rss_ind[128];
142
143         struct rte_eth_dev_owner owner;
144         struct rte_intr_handle vf_intr;
145
146         struct vmbus_channel *channels[HN_MAX_CHANNELS];
147 };
148
149 static inline struct vmbus_channel *
150 hn_primary_chan(const struct hn_data *hv)
151 {
152         return hv->channels[0];
153 }
154
155 uint32_t hn_process_events(struct hn_data *hv, uint16_t queue_id,
156                        uint32_t tx_limit);
157
158 uint16_t hn_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
159                       uint16_t nb_pkts);
160 uint16_t hn_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
161                       uint16_t nb_pkts);
162
163 int     hn_chim_init(struct rte_eth_dev *dev);
164 void    hn_chim_uninit(struct rte_eth_dev *dev);
165 int     hn_dev_link_update(struct rte_eth_dev *dev, int wait);
166 int     hn_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
167                               uint16_t nb_desc, unsigned int socket_id,
168                               const struct rte_eth_txconf *tx_conf);
169 void    hn_dev_tx_queue_release(void *arg);
170 void    hn_dev_tx_queue_info(struct rte_eth_dev *dev, uint16_t queue_idx,
171                              struct rte_eth_txq_info *qinfo);
172 int     hn_dev_tx_done_cleanup(void *arg, uint32_t free_cnt);
173 int     hn_dev_tx_descriptor_status(void *arg, uint16_t offset);
174
175 struct hn_rx_queue *hn_rx_queue_alloc(struct hn_data *hv,
176                                       uint16_t queue_id,
177                                       unsigned int socket_id);
178 int     hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
179                               uint16_t queue_idx, uint16_t nb_desc,
180                               unsigned int socket_id,
181                               const struct rte_eth_rxconf *rx_conf,
182                               struct rte_mempool *mp);
183 void    hn_dev_rx_queue_info(struct rte_eth_dev *dev, uint16_t queue_id,
184                              struct rte_eth_rxq_info *qinfo);
185 void    hn_dev_rx_queue_release(void *arg);
186 uint32_t hn_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_id);
187 int     hn_dev_rx_queue_status(void *rxq, uint16_t offset);
188 void    hn_dev_free_queues(struct rte_eth_dev *dev);
189
190 /* Check if VF is attached */
191 static inline bool
192 hn_vf_attached(const struct hn_data *hv)
193 {
194         return hv->vf_port != HN_INVALID_PORT;
195 }
196
197 /*
198  * Get VF device for existing netvsc device
199  * Assumes vf_lock is held.
200  */
201 static inline struct rte_eth_dev *
202 hn_get_vf_dev(const struct hn_data *hv)
203 {
204         uint16_t vf_port = hv->vf_port;
205
206         if (vf_port == HN_INVALID_PORT)
207                 return NULL;
208         else
209                 return &rte_eth_devices[vf_port];
210 }
211
212 int     hn_vf_info_get(struct hn_data *hv,
213                        struct rte_eth_dev_info *info);
214 int     hn_vf_add(struct rte_eth_dev *dev, struct hn_data *hv);
215 int     hn_vf_configure(struct rte_eth_dev *dev,
216                         const struct rte_eth_conf *dev_conf);
217 const uint32_t *hn_vf_supported_ptypes(struct rte_eth_dev *dev);
218 int     hn_vf_start(struct rte_eth_dev *dev);
219 void    hn_vf_reset(struct rte_eth_dev *dev);
220 void    hn_vf_stop(struct rte_eth_dev *dev);
221 void    hn_vf_close(struct rte_eth_dev *dev);
222
223 int     hn_vf_allmulticast_enable(struct rte_eth_dev *dev);
224 int     hn_vf_allmulticast_disable(struct rte_eth_dev *dev);
225 int     hn_vf_promiscuous_enable(struct rte_eth_dev *dev);
226 int     hn_vf_promiscuous_disable(struct rte_eth_dev *dev);
227 int     hn_vf_mc_addr_list(struct rte_eth_dev *dev,
228                            struct rte_ether_addr *mc_addr_set,
229                            uint32_t nb_mc_addr);
230
231 int     hn_vf_link_update(struct rte_eth_dev *dev,
232                           int wait_to_complete);
233 int     hn_vf_tx_queue_setup(struct rte_eth_dev *dev,
234                              uint16_t queue_idx, uint16_t nb_desc,
235                              unsigned int socket_id,
236                              const struct rte_eth_txconf *tx_conf);
237 void    hn_vf_tx_queue_release(struct hn_data *hv, uint16_t queue_id);
238 int     hn_vf_tx_queue_status(struct hn_data *hv, uint16_t queue_id, uint16_t offset);
239
240 int     hn_vf_rx_queue_setup(struct rte_eth_dev *dev,
241                              uint16_t queue_idx, uint16_t nb_desc,
242                              unsigned int socket_id,
243                              const struct rte_eth_rxconf *rx_conf,
244                              struct rte_mempool *mp);
245 void    hn_vf_rx_queue_release(struct hn_data *hv, uint16_t queue_id);
246
247 int     hn_vf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
248 int     hn_vf_stats_reset(struct rte_eth_dev *dev);
249 int     hn_vf_xstats_get_names(struct rte_eth_dev *dev,
250                                struct rte_eth_xstat_name *xstats_names,
251                                unsigned int size);
252 int     hn_vf_xstats_get(struct rte_eth_dev *dev,
253                          struct rte_eth_xstat *xstats,
254                          unsigned int offset, unsigned int n);
255 int     hn_vf_xstats_reset(struct rte_eth_dev *dev);
256 int     hn_vf_rss_hash_update(struct rte_eth_dev *dev,
257                               struct rte_eth_rss_conf *rss_conf);
258 int     hn_vf_reta_hash_update(struct rte_eth_dev *dev,
259                                struct rte_eth_rss_reta_entry64 *reta_conf,
260                                uint16_t reta_size);