Branch data Line data Source code
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 : : #include <rte_eal_paging.h>
10 : : #include <ethdev_driver.h>
11 : :
12 : : /*
13 : : * Tunable ethdev params
14 : : */
15 : : #define HN_MIN_RX_BUF_SIZE 1024
16 : : #define HN_MAX_XFER_LEN RTE_ETHER_MAX_JUMBO_FRAME_LEN
17 : : #define HN_MAX_MAC_ADDRS 1
18 : : #define HN_MAX_CHANNELS 64
19 : :
20 : : /* Claimed to be 12232B */
21 : : #define HN_MTU_MAX (9 * 1024)
22 : :
23 : : /* Retry interval */
24 : : #define HN_CHAN_INTERVAL_US 100
25 : :
26 : : /* Host monitor interval */
27 : : #define HN_CHAN_LATENCY_NS 50000
28 : :
29 : : #define HN_TXCOPY_THRESHOLD 512
30 : : #define HN_RXCOPY_THRESHOLD 256
31 : :
32 : : #define HN_RX_EXTMBUF_ENABLE 0
33 : :
34 : : struct hn_data;
35 : : struct hn_txdesc;
36 : :
37 : : struct hn_stats {
38 : : uint64_t packets;
39 : : uint64_t bytes;
40 : : uint64_t errors;
41 : : uint64_t ring_full;
42 : : uint64_t channel_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 : : struct rte_mempool *txdesc_pool;
56 : : const struct rte_memzone *tx_rndis_mz;
57 : : void *tx_rndis;
58 : : rte_iova_t tx_rndis_iova;
59 : :
60 : : /* Applied packet transmission aggregation limits. */
61 : : uint32_t agg_szmax;
62 : : uint32_t agg_pktmax;
63 : : uint32_t agg_align;
64 : :
65 : : /* Packet transmission aggregation states */
66 : : struct hn_txdesc *agg_txd;
67 : : uint32_t agg_pktleft;
68 : : uint32_t agg_szleft;
69 : : struct rndis_packet_msg *agg_prevpkt;
70 : :
71 : : struct hn_stats stats;
72 : : };
73 : :
74 : : struct hn_rx_queue {
75 : : struct hn_data *hv;
76 : : struct vmbus_channel *chan;
77 : : struct rte_mempool *mb_pool;
78 : : struct rte_ring *rx_ring;
79 : :
80 : : rte_spinlock_t ring_lock;
81 : : uint32_t event_sz;
82 : : uint16_t port_id;
83 : : uint16_t queue_id;
84 : : struct hn_stats stats;
85 : :
86 : : void *event_buf;
87 : : struct hn_rx_bufinfo *rxbuf_info;
88 : : rte_atomic32_t rxbuf_outstanding;
89 : : };
90 : :
91 : :
92 : : /* multi-packet data from host */
93 : : struct __rte_cache_aligned hn_rx_bufinfo {
94 : : struct vmbus_channel *chan;
95 : : struct hn_rx_queue *rxq;
96 : : uint64_t xactid;
97 : : struct rte_mbuf_ext_shared_info shinfo;
98 : : };
99 : :
100 : : #define HN_INVALID_PORT UINT16_MAX
101 : :
102 : : enum vf_device_state {
103 : : vf_unknown = 0,
104 : : vf_removed,
105 : : vf_configured,
106 : : vf_started,
107 : : vf_stopped,
108 : : };
109 : :
110 : : struct hn_vf_ctx {
111 : : uint16_t vf_port;
112 : :
113 : : /* We have taken ownership of this VF port from DPDK */
114 : : bool vf_attached;
115 : :
116 : : /* VSC has requested to switch data path to VF */
117 : : bool vf_vsc_switched;
118 : :
119 : : /* VSP has reported the VF is present for this NIC */
120 : : bool vf_vsp_reported;
121 : :
122 : : enum vf_device_state vf_state;
123 : : };
124 : :
125 : : struct hv_hotadd_context {
126 : : LIST_ENTRY(hv_hotadd_context) list;
127 : : struct hn_data *hv;
128 : : struct rte_devargs da;
129 : : int eal_hot_plug_retry;
130 : : };
131 : :
132 : : struct hn_data {
133 : : struct rte_vmbus_device *vmbus;
134 : : struct hn_rx_queue *primary;
135 : : rte_rwlock_t vf_lock;
136 : : uint16_t port_id;
137 : :
138 : : struct hn_vf_ctx vf_ctx;
139 : :
140 : : uint8_t closed;
141 : : uint8_t vlan_strip;
142 : :
143 : : uint32_t link_status;
144 : : uint32_t link_speed;
145 : :
146 : : struct rte_mem_resource rxbuf_res; /* UIO resource for Rx */
147 : : uint32_t rxbuf_section_cnt; /* # of Rx sections */
148 : : uint32_t rx_copybreak;
149 : : uint32_t rx_extmbuf_enable;
150 : : uint16_t max_queues; /* Max available queues */
151 : : uint16_t num_queues;
152 : : uint64_t rss_offloads;
153 : :
154 : : rte_spinlock_t chim_lock;
155 : : struct rte_mem_resource chim_res; /* UIO resource for Tx */
156 : : struct rte_bitmap *chim_bmap; /* Send buffer map */
157 : : void *chim_bmem;
158 : : uint32_t tx_copybreak;
159 : : uint32_t chim_szmax; /* Max size per buffer */
160 : : uint32_t chim_cnt; /* Max packets per buffer */
161 : :
162 : : uint32_t latency;
163 : : uint32_t nvs_ver;
164 : : uint32_t ndis_ver;
165 : : uint32_t rndis_agg_size;
166 : : uint32_t rndis_agg_pkts;
167 : : uint32_t rndis_agg_align;
168 : :
169 : : volatile uint32_t rndis_pending;
170 : : rte_atomic32_t rndis_req_id;
171 : : uint8_t rndis_resp[256];
172 : :
173 : : uint32_t rss_hash;
174 : : uint8_t rss_key[40];
175 : : uint16_t rss_ind[128];
176 : :
177 : : struct rte_eth_dev_owner owner;
178 : :
179 : : struct vmbus_channel *channels[HN_MAX_CHANNELS];
180 : :
181 : : rte_spinlock_t hotadd_lock;
182 : : LIST_HEAD(hotadd_list, hv_hotadd_context) hotadd_list;
183 : : char *vf_devargs;
184 : : };
185 : :
186 : : static inline struct vmbus_channel *
187 : : hn_primary_chan(const struct hn_data *hv)
188 : : {
189 [ # # ]: 0 : return hv->channels[0];
190 : : }
191 : :
192 : : uint32_t hn_process_events(struct hn_data *hv, uint16_t queue_id,
193 : : uint32_t tx_limit);
194 : :
195 : : uint16_t hn_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
196 : : uint16_t nb_pkts);
197 : : uint16_t hn_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
198 : : uint16_t nb_pkts);
199 : :
200 : : int hn_chim_init(struct rte_eth_dev *dev);
201 : : void hn_chim_uninit(struct rte_eth_dev *dev);
202 : : int hn_dev_link_update(struct rte_eth_dev *dev, int wait);
203 : : int hn_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
204 : : uint16_t nb_desc, unsigned int socket_id,
205 : : const struct rte_eth_txconf *tx_conf);
206 : : void hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
207 : : void hn_dev_tx_queue_info(struct rte_eth_dev *dev, uint16_t queue_idx,
208 : : struct rte_eth_txq_info *qinfo);
209 : : int hn_dev_tx_done_cleanup(void *arg, uint32_t free_cnt);
210 : : int hn_dev_tx_descriptor_status(void *arg, uint16_t offset);
211 : :
212 : : struct hn_rx_queue *hn_rx_queue_alloc(struct hn_data *hv,
213 : : uint16_t queue_id,
214 : : unsigned int socket_id);
215 : : int hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
216 : : uint16_t queue_idx, uint16_t nb_desc,
217 : : unsigned int socket_id,
218 : : const struct rte_eth_rxconf *rx_conf,
219 : : struct rte_mempool *mp);
220 : : void hn_dev_rx_queue_info(struct rte_eth_dev *dev, uint16_t queue_id,
221 : : struct rte_eth_rxq_info *qinfo);
222 : : void hn_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
223 : : uint32_t hn_dev_rx_queue_count(void *rx_queue);
224 : : int hn_dev_rx_queue_status(void *rxq, uint16_t offset);
225 : : void hn_dev_free_queues(struct rte_eth_dev *dev);
226 : :
227 : : /*
228 : : * Get VF device for existing netvsc device
229 : : * Assumes vf_lock is held.
230 : : */
231 : : static inline struct rte_eth_dev *
232 : : hn_get_vf_dev(const struct hn_data *hv)
233 : : {
234 [ # # # # : 0 : if (hv->vf_ctx.vf_attached)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
235 [ # # # # : 0 : return &rte_eth_devices[hv->vf_ctx.vf_port];
# # # # #
# ]
236 : : else
237 : : return NULL;
238 : : }
239 : :
240 : : int hn_vf_info_get(struct hn_data *hv,
241 : : struct rte_eth_dev_info *info);
242 : : int hn_vf_add(struct rte_eth_dev *dev, struct hn_data *hv);
243 : : int hn_vf_configure_locked(struct rte_eth_dev *dev,
244 : : const struct rte_eth_conf *dev_conf);
245 : : const uint32_t *hn_vf_supported_ptypes(struct rte_eth_dev *dev,
246 : : size_t *no_of_elements);
247 : : int hn_vf_start(struct rte_eth_dev *dev);
248 : : int hn_vf_close(struct rte_eth_dev *dev);
249 : : int hn_vf_stop(struct rte_eth_dev *dev);
250 : :
251 : : int hn_vf_allmulticast_enable(struct rte_eth_dev *dev);
252 : : int hn_vf_allmulticast_disable(struct rte_eth_dev *dev);
253 : : int hn_vf_promiscuous_enable(struct rte_eth_dev *dev);
254 : : int hn_vf_promiscuous_disable(struct rte_eth_dev *dev);
255 : : int hn_vf_mc_addr_list(struct rte_eth_dev *dev,
256 : : struct rte_ether_addr *mc_addr_set,
257 : : uint32_t nb_mc_addr);
258 : :
259 : : int hn_vf_tx_queue_setup(struct rte_eth_dev *dev,
260 : : uint16_t queue_idx, uint16_t nb_desc,
261 : : unsigned int socket_id,
262 : : const struct rte_eth_txconf *tx_conf);
263 : : void hn_vf_tx_queue_release(struct hn_data *hv, uint16_t queue_id);
264 : : int hn_vf_tx_queue_status(struct hn_data *hv, uint16_t queue_id, uint16_t offset);
265 : :
266 : : int hn_vf_rx_queue_setup(struct rte_eth_dev *dev,
267 : : uint16_t queue_idx, uint16_t nb_desc,
268 : : unsigned int socket_id,
269 : : const struct rte_eth_rxconf *rx_conf,
270 : : struct rte_mempool *mp);
271 : : void hn_vf_rx_queue_release(struct hn_data *hv, uint16_t queue_id);
272 : :
273 : : int hn_vf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
274 : : int hn_vf_stats_reset(struct rte_eth_dev *dev);
275 : : int hn_vf_xstats_get_names(struct rte_eth_dev *dev,
276 : : struct rte_eth_xstat_name *xstats_names,
277 : : unsigned int size);
278 : : int hn_vf_xstats_get(struct rte_eth_dev *dev,
279 : : struct rte_eth_xstat *xstats,
280 : : unsigned int offset, unsigned int n);
281 : : int hn_vf_xstats_reset(struct rte_eth_dev *dev);
282 : : int hn_vf_rss_hash_update(struct rte_eth_dev *dev,
283 : : struct rte_eth_rss_conf *rss_conf);
284 : : int hn_vf_reta_hash_update(struct rte_eth_dev *dev,
285 : : struct rte_eth_rss_reta_entry64 *reta_conf,
286 : : uint16_t reta_size);
287 : : int hn_vf_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
288 : : int hn_eth_rmv_event_callback(uint16_t port_id,
289 : : enum rte_eth_event_type event __rte_unused,
290 : : void *cb_arg, void *out __rte_unused);
|