New upstream version 18.08
[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 /* Buffers need to be aligned */
24 #ifndef PAGE_SIZE
25 #define PAGE_SIZE 4096
26 #endif
27
28 #ifndef PAGE_MASK
29 #define PAGE_MASK (PAGE_SIZE - 1)
30 #endif
31
32 struct hn_data;
33 struct hn_txdesc;
34
35 struct hn_stats {
36         uint64_t        packets;
37         uint64_t        bytes;
38         uint64_t        errors;
39         uint64_t        nomemory;
40         uint64_t        multicast;
41         uint64_t        broadcast;
42         /* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */
43         uint64_t        size_bins[8];
44 };
45
46 struct hn_tx_queue {
47         struct hn_data  *hv;
48         struct vmbus_channel *chan;
49         uint16_t        port_id;
50         uint16_t        queue_id;
51         uint32_t        free_thresh;
52
53         /* Applied packet transmission aggregation limits. */
54         uint32_t        agg_szmax;
55         uint32_t        agg_pktmax;
56         uint32_t        agg_align;
57
58         /* Packet transmission aggregation states */
59         struct hn_txdesc *agg_txd;
60         uint32_t        agg_pktleft;
61         uint32_t        agg_szleft;
62         struct rndis_packet_msg *agg_prevpkt;
63
64         struct hn_stats stats;
65 };
66
67 struct hn_rx_queue {
68         struct hn_data  *hv;
69         struct vmbus_channel *chan;
70         struct rte_mempool *mb_pool;
71         struct rte_ring *rx_ring;
72
73         rte_spinlock_t ring_lock;
74         uint32_t event_sz;
75         uint16_t port_id;
76         uint16_t queue_id;
77         struct hn_stats stats;
78         uint64_t ring_full;
79
80         uint8_t event_buf[];
81 };
82
83
84 /* multi-packet data from host */
85 struct hn_rx_bufinfo {
86         struct vmbus_channel *chan;
87         struct hn_data *hv;
88         uint64_t        xactid;
89         struct rte_mbuf_ext_shared_info shinfo;
90 } __rte_cache_aligned;
91
92 struct hn_data {
93         struct rte_vmbus_device *vmbus;
94         struct hn_rx_queue *primary;
95         uint16_t        port_id;
96         bool            closed;
97         uint32_t        link_status;
98         uint32_t        link_speed;
99
100         struct rte_mem_resource *rxbuf_res;     /* UIO resource for Rx */
101         struct hn_rx_bufinfo *rxbuf_info;
102         uint32_t        rxbuf_section_cnt;      /* # of Rx sections */
103         volatile uint32_t rxbuf_outstanding;
104         uint16_t        max_queues;             /* Max available queues */
105         uint16_t        num_queues;
106         uint64_t        rss_offloads;
107
108         struct rte_mem_resource *chim_res;      /* UIO resource for Tx */
109         struct rte_mempool *tx_pool;            /* Tx descriptors */
110         uint32_t        chim_szmax;             /* Max size per buffer */
111         uint32_t        chim_cnt;               /* Max packets per buffer */
112
113         uint32_t        nvs_ver;
114         uint32_t        ndis_ver;
115         uint32_t        rndis_agg_size;
116         uint32_t        rndis_agg_pkts;
117         uint32_t        rndis_agg_align;
118
119         volatile uint32_t  rndis_pending;
120         rte_atomic32_t  rndis_req_id;
121         uint8_t         rndis_resp[256];
122
123         struct ether_addr mac_addr;
124         struct vmbus_channel *channels[HN_MAX_CHANNELS];
125 };
126
127 static inline struct vmbus_channel *
128 hn_primary_chan(const struct hn_data *hv)
129 {
130         return hv->channels[0];
131 }
132
133 void hn_process_events(struct hn_data *hv, uint16_t queue_id);
134
135 uint16_t hn_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
136                       uint16_t nb_pkts);
137 uint16_t hn_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
138                       uint16_t nb_pkts);
139
140 int     hn_tx_pool_init(struct rte_eth_dev *dev);
141 int     hn_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
142                               uint16_t nb_desc, unsigned int socket_id,
143                               const struct rte_eth_txconf *tx_conf);
144 void    hn_dev_tx_queue_release(void *arg);
145 void    hn_dev_tx_queue_info(struct rte_eth_dev *dev, uint16_t queue_idx,
146                              struct rte_eth_txq_info *qinfo);
147
148 struct hn_rx_queue *hn_rx_queue_alloc(struct hn_data *hv,
149                                       uint16_t queue_id,
150                                       unsigned int socket_id);
151 int     hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
152                               uint16_t queue_idx, uint16_t nb_desc,
153                               unsigned int socket_id,
154                               const struct rte_eth_rxconf *rx_conf,
155                               struct rte_mempool *mp);
156 void    hn_dev_rx_queue_release(void *arg);
157 void    hn_dev_rx_queue_info(struct rte_eth_dev *dev, uint16_t queue_idx,
158                              struct rte_eth_rxq_info *qinfo);