New upstream version 18.11.2
[deb_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        multicast;
44         uint64_t        broadcast;
45         /* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */
46         uint64_t        size_bins[8];
47 };
48
49 struct hn_tx_queue {
50         struct hn_data  *hv;
51         struct vmbus_channel *chan;
52         uint16_t        port_id;
53         uint16_t        queue_id;
54         uint32_t        free_thresh;
55
56         /* Applied packet transmission aggregation limits. */
57         uint32_t        agg_szmax;
58         uint32_t        agg_pktmax;
59         uint32_t        agg_align;
60
61         /* Packet transmission aggregation states */
62         struct hn_txdesc *agg_txd;
63         uint32_t        agg_pktleft;
64         uint32_t        agg_szleft;
65         struct rndis_packet_msg *agg_prevpkt;
66
67         struct hn_stats stats;
68 };
69
70 struct hn_rx_queue {
71         struct hn_data  *hv;
72         struct vmbus_channel *chan;
73         struct rte_mempool *mb_pool;
74         struct rte_ring *rx_ring;
75
76         rte_spinlock_t ring_lock;
77         uint32_t event_sz;
78         uint16_t port_id;
79         uint16_t queue_id;
80         struct hn_stats stats;
81
82         void *event_buf;
83 };
84
85
86 /* multi-packet data from host */
87 struct hn_rx_bufinfo {
88         struct vmbus_channel *chan;
89         struct hn_data *hv;
90         uint64_t        xactid;
91         struct rte_mbuf_ext_shared_info shinfo;
92 } __rte_cache_aligned;
93
94 #define HN_INVALID_PORT UINT16_MAX
95
96 struct hn_data {
97         struct rte_vmbus_device *vmbus;
98         struct hn_rx_queue *primary;
99         rte_spinlock_t  vf_lock;
100         uint16_t        port_id;
101         uint16_t        vf_port;
102
103         uint8_t         vf_present;
104         uint8_t         closed;
105
106         uint32_t        link_status;
107         uint32_t        link_speed;
108
109         struct rte_mem_resource *rxbuf_res;     /* UIO resource for Rx */
110         struct hn_rx_bufinfo *rxbuf_info;
111         uint32_t        rxbuf_section_cnt;      /* # of Rx sections */
112         volatile uint32_t rxbuf_outstanding;
113         uint16_t        max_queues;             /* Max available queues */
114         uint16_t        num_queues;
115         uint64_t        rss_offloads;
116
117         struct rte_mem_resource *chim_res;      /* UIO resource for Tx */
118         struct rte_mempool *tx_pool;            /* Tx descriptors */
119         uint32_t        chim_szmax;             /* Max size per buffer */
120         uint32_t        chim_cnt;               /* Max packets per buffer */
121
122         uint32_t        latency;
123         uint32_t        nvs_ver;
124         uint32_t        ndis_ver;
125         uint32_t        rndis_agg_size;
126         uint32_t        rndis_agg_pkts;
127         uint32_t        rndis_agg_align;
128
129         volatile uint32_t  rndis_pending;
130         rte_atomic32_t  rndis_req_id;
131         uint8_t         rndis_resp[256];
132
133         struct ether_addr mac_addr;
134
135         struct rte_eth_dev_owner owner;
136         struct rte_intr_handle vf_intr;
137
138         struct vmbus_channel *channels[HN_MAX_CHANNELS];
139 };
140
141 static inline struct vmbus_channel *
142 hn_primary_chan(const struct hn_data *hv)
143 {
144         return hv->channels[0];
145 }
146
147 uint32_t hn_process_events(struct hn_data *hv, uint16_t queue_id,
148                        uint32_t tx_limit);
149
150 uint16_t hn_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
151                       uint16_t nb_pkts);
152 uint16_t hn_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
153                       uint16_t nb_pkts);
154
155 int     hn_tx_pool_init(struct rte_eth_dev *dev);
156 void    hn_tx_pool_uninit(struct rte_eth_dev *dev);
157 int     hn_dev_link_update(struct rte_eth_dev *dev, int wait);
158 int     hn_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
159                               uint16_t nb_desc, unsigned int socket_id,
160                               const struct rte_eth_txconf *tx_conf);
161 void    hn_dev_tx_queue_release(void *arg);
162 void    hn_dev_tx_queue_info(struct rte_eth_dev *dev, uint16_t queue_idx,
163                              struct rte_eth_txq_info *qinfo);
164 int     hn_dev_tx_done_cleanup(void *arg, uint32_t free_cnt);
165
166 struct hn_rx_queue *hn_rx_queue_alloc(struct hn_data *hv,
167                                       uint16_t queue_id,
168                                       unsigned int socket_id);
169 int     hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
170                               uint16_t queue_idx, uint16_t nb_desc,
171                               unsigned int socket_id,
172                               const struct rte_eth_rxconf *rx_conf,
173                               struct rte_mempool *mp);
174 void    hn_dev_rx_queue_release(void *arg);
175
176 /* Check if VF is attached */
177 static inline bool
178 hn_vf_attached(const struct hn_data *hv)
179 {
180         return hv->vf_port != HN_INVALID_PORT;
181 }
182
183 /* Get VF device for existing netvsc device */
184 static inline struct rte_eth_dev *
185 hn_get_vf_dev(const struct hn_data *hv)
186 {
187         uint16_t vf_port = hv->vf_port;
188
189         /* make sure vf_port is loaded */
190         rte_smp_rmb();
191
192         if (vf_port == HN_INVALID_PORT)
193                 return NULL;
194         else
195                 return &rte_eth_devices[vf_port];
196 }
197
198 void    hn_vf_info_get(struct hn_data *hv,
199                        struct rte_eth_dev_info *info);
200 int     hn_vf_add(struct rte_eth_dev *dev, struct hn_data *hv);
201 int     hn_vf_configure(struct rte_eth_dev *dev,
202                         const struct rte_eth_conf *dev_conf);
203 const uint32_t *hn_vf_supported_ptypes(struct rte_eth_dev *dev);
204 int     hn_vf_start(struct rte_eth_dev *dev);
205 void    hn_vf_reset(struct rte_eth_dev *dev);
206 void    hn_vf_stop(struct rte_eth_dev *dev);
207 void    hn_vf_close(struct rte_eth_dev *dev);
208
209 void    hn_vf_allmulticast_enable(struct rte_eth_dev *dev);
210 void    hn_vf_allmulticast_disable(struct rte_eth_dev *dev);
211 void    hn_vf_promiscuous_enable(struct rte_eth_dev *dev);
212 void    hn_vf_promiscuous_disable(struct rte_eth_dev *dev);
213 int     hn_vf_mc_addr_list(struct rte_eth_dev *dev,
214                            struct ether_addr *mc_addr_set,
215                            uint32_t nb_mc_addr);
216
217 int     hn_vf_link_update(struct rte_eth_dev *dev,
218                           int wait_to_complete);
219 int     hn_vf_tx_queue_setup(struct rte_eth_dev *dev,
220                              uint16_t queue_idx, uint16_t nb_desc,
221                              unsigned int socket_id,
222                              const struct rte_eth_txconf *tx_conf);
223 void    hn_vf_tx_queue_release(struct hn_data *hv, uint16_t queue_id);
224 int     hn_vf_rx_queue_setup(struct rte_eth_dev *dev,
225                              uint16_t queue_idx, uint16_t nb_desc,
226                              unsigned int socket_id,
227                              const struct rte_eth_rxconf *rx_conf,
228                              struct rte_mempool *mp);
229 void    hn_vf_rx_queue_release(struct hn_data *hv, uint16_t queue_id);
230
231 int     hn_vf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
232 void    hn_vf_stats_reset(struct rte_eth_dev *dev);
233 int     hn_vf_xstats_get_names(struct rte_eth_dev *dev,
234                                struct rte_eth_xstat_name *xstats_names,
235                                unsigned int size);
236 int     hn_vf_xstats_get(struct rte_eth_dev *dev,
237                          struct rte_eth_xstat *xstats,
238                          unsigned int n);
239 void    hn_vf_xstats_reset(struct rte_eth_dev *dev);