18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 38c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2 48c2ecf20Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed 58c2ecf20Sopenharmony_ci * separately from the Linux kernel or incorporated into other 68c2ecf20Sopenharmony_ci * software packages, subject to the following license: 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 98c2ecf20Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without 108c2ecf20Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify, 118c2ecf20Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software, 128c2ecf20Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to 138c2ecf20Sopenharmony_ci * the following conditions: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 168c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 218c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 228c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 238c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 248c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#ifndef __XEN_NETBACK__COMMON_H__ 288c2ecf20Sopenharmony_ci#define __XEN_NETBACK__COMMON_H__ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <linux/module.h> 338c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 348c2ecf20Sopenharmony_ci#include <linux/slab.h> 358c2ecf20Sopenharmony_ci#include <linux/ip.h> 368c2ecf20Sopenharmony_ci#include <linux/in.h> 378c2ecf20Sopenharmony_ci#include <linux/io.h> 388c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 398c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 408c2ecf20Sopenharmony_ci#include <linux/wait.h> 418c2ecf20Sopenharmony_ci#include <linux/sched.h> 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#include <xen/interface/io/netif.h> 448c2ecf20Sopenharmony_ci#include <xen/interface/grant_table.h> 458c2ecf20Sopenharmony_ci#include <xen/grant_table.h> 468c2ecf20Sopenharmony_ci#include <xen/xenbus.h> 478c2ecf20Sopenharmony_ci#include <xen/page.h> 488c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_citypedef unsigned int pending_ring_idx_t; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct pending_tx_info { 538c2ecf20Sopenharmony_ci struct xen_netif_tx_request req; /* tx request */ 548c2ecf20Sopenharmony_ci unsigned int extra_count; 558c2ecf20Sopenharmony_ci /* Callback data for released SKBs. The callback is always 568c2ecf20Sopenharmony_ci * xenvif_zerocopy_callback, desc contains the pending_idx, which is 578c2ecf20Sopenharmony_ci * also an index in pending_tx_info array. It is initialized in 588c2ecf20Sopenharmony_ci * xenvif_alloc and it never changes. 598c2ecf20Sopenharmony_ci * skb_shinfo(skb)->destructor_arg points to the first mapped slot's 608c2ecf20Sopenharmony_ci * callback_struct in this array of struct pending_tx_info's, then ctx 618c2ecf20Sopenharmony_ci * to the next, or NULL if there is no more slot for this skb. 628c2ecf20Sopenharmony_ci * ubuf_to_vif is a helper which finds the struct xenvif from a pointer 638c2ecf20Sopenharmony_ci * to this field. 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_ci struct ubuf_info callback_struct; 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, XEN_PAGE_SIZE) 698c2ecf20Sopenharmony_ci#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, XEN_PAGE_SIZE) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistruct xenvif_rx_meta { 728c2ecf20Sopenharmony_ci int id; 738c2ecf20Sopenharmony_ci int size; 748c2ecf20Sopenharmony_ci int gso_type; 758c2ecf20Sopenharmony_ci int gso_size; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define GSO_BIT(type) \ 798c2ecf20Sopenharmony_ci (1 << XEN_NETIF_GSO_TYPE_ ## type) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* Discriminate from any valid pending_idx value. */ 828c2ecf20Sopenharmony_ci#define INVALID_PENDING_IDX 0xFFFF 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define MAX_PENDING_REQS XEN_NETIF_TX_RING_SIZE 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* The maximum number of frags is derived from the size of a grant (same 878c2ecf20Sopenharmony_ci * as a Xen page size for now). 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_ci#define MAX_XEN_SKB_FRAGS (65536 / XEN_PAGE_SIZE + 1) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define NETBACK_INVALID_HANDLE -1 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* To avoid confusion, we define XEN_NETBK_LEGACY_SLOTS_MAX indicating 948c2ecf20Sopenharmony_ci * the maximum slots a valid packet can use. Now this value is defined 958c2ecf20Sopenharmony_ci * to be XEN_NETIF_NR_SLOTS_MIN, which is supposed to be supported by 968c2ecf20Sopenharmony_ci * all backend. 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci#define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* Queue name is interface name with "-qNNN" appended */ 1018c2ecf20Sopenharmony_ci#define QUEUE_NAME_SIZE (IFNAMSIZ + 5) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* IRQ name is queue name with "-tx" or "-rx" appended */ 1048c2ecf20Sopenharmony_ci#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistruct xenvif; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct xenvif_stats { 1098c2ecf20Sopenharmony_ci /* Stats fields to be updated per-queue. 1108c2ecf20Sopenharmony_ci * A subset of struct net_device_stats that contains only the 1118c2ecf20Sopenharmony_ci * fields that are updated in netback.c for each queue. 1128c2ecf20Sopenharmony_ci */ 1138c2ecf20Sopenharmony_ci u64 rx_bytes; 1148c2ecf20Sopenharmony_ci u64 rx_packets; 1158c2ecf20Sopenharmony_ci u64 tx_bytes; 1168c2ecf20Sopenharmony_ci u64 tx_packets; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* Additional stats used by xenvif */ 1198c2ecf20Sopenharmony_ci unsigned long rx_gso_checksum_fixup; 1208c2ecf20Sopenharmony_ci unsigned long tx_zerocopy_sent; 1218c2ecf20Sopenharmony_ci unsigned long tx_zerocopy_success; 1228c2ecf20Sopenharmony_ci unsigned long tx_zerocopy_fail; 1238c2ecf20Sopenharmony_ci unsigned long tx_frag_overflow; 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#define COPY_BATCH_SIZE 64 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistruct xenvif_copy_state { 1298c2ecf20Sopenharmony_ci struct gnttab_copy op[COPY_BATCH_SIZE]; 1308c2ecf20Sopenharmony_ci RING_IDX idx[COPY_BATCH_SIZE]; 1318c2ecf20Sopenharmony_ci unsigned int num; 1328c2ecf20Sopenharmony_ci struct sk_buff_head *completed; 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistruct xenvif_queue { /* Per-queue data for xenvif */ 1368c2ecf20Sopenharmony_ci unsigned int id; /* Queue ID, 0-based */ 1378c2ecf20Sopenharmony_ci char name[QUEUE_NAME_SIZE]; /* DEVNAME-qN */ 1388c2ecf20Sopenharmony_ci struct xenvif *vif; /* Parent VIF */ 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* 1418c2ecf20Sopenharmony_ci * TX/RX common EOI handling. 1428c2ecf20Sopenharmony_ci * When feature-split-event-channels = 0, interrupt handler sets 1438c2ecf20Sopenharmony_ci * NETBK_COMMON_EOI, otherwise NETBK_RX_EOI and NETBK_TX_EOI are set 1448c2ecf20Sopenharmony_ci * by the RX and TX interrupt handlers. 1458c2ecf20Sopenharmony_ci * RX and TX handler threads will issue an EOI when either 1468c2ecf20Sopenharmony_ci * NETBK_COMMON_EOI or their specific bits (NETBK_RX_EOI or 1478c2ecf20Sopenharmony_ci * NETBK_TX_EOI) are set and they will reset those bits. 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_ci atomic_t eoi_pending; 1508c2ecf20Sopenharmony_ci#define NETBK_RX_EOI 0x01 1518c2ecf20Sopenharmony_ci#define NETBK_TX_EOI 0x02 1528c2ecf20Sopenharmony_ci#define NETBK_COMMON_EOI 0x04 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* Use NAPI for guest TX */ 1558c2ecf20Sopenharmony_ci struct napi_struct napi; 1568c2ecf20Sopenharmony_ci /* When feature-split-event-channels = 0, tx_irq = rx_irq. */ 1578c2ecf20Sopenharmony_ci unsigned int tx_irq; 1588c2ecf20Sopenharmony_ci /* Only used when feature-split-event-channels = 1 */ 1598c2ecf20Sopenharmony_ci char tx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-tx */ 1608c2ecf20Sopenharmony_ci struct xen_netif_tx_back_ring tx; 1618c2ecf20Sopenharmony_ci struct sk_buff_head tx_queue; 1628c2ecf20Sopenharmony_ci struct page *mmap_pages[MAX_PENDING_REQS]; 1638c2ecf20Sopenharmony_ci pending_ring_idx_t pending_prod; 1648c2ecf20Sopenharmony_ci pending_ring_idx_t pending_cons; 1658c2ecf20Sopenharmony_ci u16 pending_ring[MAX_PENDING_REQS]; 1668c2ecf20Sopenharmony_ci struct pending_tx_info pending_tx_info[MAX_PENDING_REQS]; 1678c2ecf20Sopenharmony_ci grant_handle_t grant_tx_handle[MAX_PENDING_REQS]; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci struct gnttab_copy tx_copy_ops[2 * MAX_PENDING_REQS]; 1708c2ecf20Sopenharmony_ci struct gnttab_map_grant_ref tx_map_ops[MAX_PENDING_REQS]; 1718c2ecf20Sopenharmony_ci struct gnttab_unmap_grant_ref tx_unmap_ops[MAX_PENDING_REQS]; 1728c2ecf20Sopenharmony_ci /* passed to gnttab_[un]map_refs with pages under (un)mapping */ 1738c2ecf20Sopenharmony_ci struct page *pages_to_map[MAX_PENDING_REQS]; 1748c2ecf20Sopenharmony_ci struct page *pages_to_unmap[MAX_PENDING_REQS]; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci /* This prevents zerocopy callbacks to race over dealloc_ring */ 1778c2ecf20Sopenharmony_ci spinlock_t callback_lock; 1788c2ecf20Sopenharmony_ci /* This prevents dealloc thread and NAPI instance to race over response 1798c2ecf20Sopenharmony_ci * creation and pending_ring in xenvif_idx_release. In xenvif_tx_err 1808c2ecf20Sopenharmony_ci * it only protect response creation 1818c2ecf20Sopenharmony_ci */ 1828c2ecf20Sopenharmony_ci spinlock_t response_lock; 1838c2ecf20Sopenharmony_ci pending_ring_idx_t dealloc_prod; 1848c2ecf20Sopenharmony_ci pending_ring_idx_t dealloc_cons; 1858c2ecf20Sopenharmony_ci u16 dealloc_ring[MAX_PENDING_REQS]; 1868c2ecf20Sopenharmony_ci struct task_struct *dealloc_task; 1878c2ecf20Sopenharmony_ci wait_queue_head_t dealloc_wq; 1888c2ecf20Sopenharmony_ci atomic_t inflight_packets; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci /* Use kthread for guest RX */ 1918c2ecf20Sopenharmony_ci struct task_struct *task; 1928c2ecf20Sopenharmony_ci wait_queue_head_t wq; 1938c2ecf20Sopenharmony_ci /* When feature-split-event-channels = 0, tx_irq = rx_irq. */ 1948c2ecf20Sopenharmony_ci unsigned int rx_irq; 1958c2ecf20Sopenharmony_ci /* Only used when feature-split-event-channels = 1 */ 1968c2ecf20Sopenharmony_ci char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */ 1978c2ecf20Sopenharmony_ci struct xen_netif_rx_back_ring rx; 1988c2ecf20Sopenharmony_ci struct sk_buff_head rx_queue; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci unsigned int rx_queue_max; 2018c2ecf20Sopenharmony_ci unsigned int rx_queue_len; 2028c2ecf20Sopenharmony_ci unsigned long last_rx_time; 2038c2ecf20Sopenharmony_ci unsigned int rx_slots_needed; 2048c2ecf20Sopenharmony_ci bool stalled; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci struct xenvif_copy_state rx_copy; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */ 2098c2ecf20Sopenharmony_ci unsigned long credit_bytes; 2108c2ecf20Sopenharmony_ci unsigned long credit_usec; 2118c2ecf20Sopenharmony_ci unsigned long remaining_credit; 2128c2ecf20Sopenharmony_ci struct timer_list credit_timeout; 2138c2ecf20Sopenharmony_ci u64 credit_window_start; 2148c2ecf20Sopenharmony_ci bool rate_limited; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci /* Statistics */ 2178c2ecf20Sopenharmony_ci struct xenvif_stats stats; 2188c2ecf20Sopenharmony_ci}; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cienum state_bit_shift { 2218c2ecf20Sopenharmony_ci /* This bit marks that the vif is connected */ 2228c2ecf20Sopenharmony_ci VIF_STATUS_CONNECTED, 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistruct xenvif_mcast_addr { 2268c2ecf20Sopenharmony_ci struct list_head entry; 2278c2ecf20Sopenharmony_ci struct rcu_head rcu; 2288c2ecf20Sopenharmony_ci u8 addr[6]; 2298c2ecf20Sopenharmony_ci}; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#define XEN_NETBK_MCAST_MAX 64 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci#define XEN_NETBK_MAX_HASH_KEY_SIZE 40 2348c2ecf20Sopenharmony_ci#define XEN_NETBK_MAX_HASH_MAPPING_SIZE 128 2358c2ecf20Sopenharmony_ci#define XEN_NETBK_HASH_TAG_SIZE 40 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistruct xenvif_hash_cache_entry { 2388c2ecf20Sopenharmony_ci struct list_head link; 2398c2ecf20Sopenharmony_ci struct rcu_head rcu; 2408c2ecf20Sopenharmony_ci u8 tag[XEN_NETBK_HASH_TAG_SIZE]; 2418c2ecf20Sopenharmony_ci unsigned int len; 2428c2ecf20Sopenharmony_ci u32 val; 2438c2ecf20Sopenharmony_ci int seq; 2448c2ecf20Sopenharmony_ci}; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistruct xenvif_hash_cache { 2478c2ecf20Sopenharmony_ci spinlock_t lock; 2488c2ecf20Sopenharmony_ci struct list_head list; 2498c2ecf20Sopenharmony_ci unsigned int count; 2508c2ecf20Sopenharmony_ci atomic_t seq; 2518c2ecf20Sopenharmony_ci}; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistruct xenvif_hash { 2548c2ecf20Sopenharmony_ci unsigned int alg; 2558c2ecf20Sopenharmony_ci u32 flags; 2568c2ecf20Sopenharmony_ci bool mapping_sel; 2578c2ecf20Sopenharmony_ci u8 key[XEN_NETBK_MAX_HASH_KEY_SIZE]; 2588c2ecf20Sopenharmony_ci u32 mapping[2][XEN_NETBK_MAX_HASH_MAPPING_SIZE]; 2598c2ecf20Sopenharmony_ci unsigned int size; 2608c2ecf20Sopenharmony_ci struct xenvif_hash_cache cache; 2618c2ecf20Sopenharmony_ci}; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistruct backend_info { 2648c2ecf20Sopenharmony_ci struct xenbus_device *dev; 2658c2ecf20Sopenharmony_ci struct xenvif *vif; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci /* This is the state that will be reflected in xenstore when any 2688c2ecf20Sopenharmony_ci * active hotplug script completes. 2698c2ecf20Sopenharmony_ci */ 2708c2ecf20Sopenharmony_ci enum xenbus_state state; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci enum xenbus_state frontend_state; 2738c2ecf20Sopenharmony_ci struct xenbus_watch hotplug_status_watch; 2748c2ecf20Sopenharmony_ci u8 have_hotplug_status_watch:1; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci const char *hotplug_script; 2778c2ecf20Sopenharmony_ci}; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_cistruct xenvif { 2808c2ecf20Sopenharmony_ci /* Unique identifier for this interface. */ 2818c2ecf20Sopenharmony_ci domid_t domid; 2828c2ecf20Sopenharmony_ci unsigned int handle; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci u8 fe_dev_addr[6]; 2858c2ecf20Sopenharmony_ci struct list_head fe_mcast_addr; 2868c2ecf20Sopenharmony_ci unsigned int fe_mcast_count; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci /* Frontend feature information. */ 2898c2ecf20Sopenharmony_ci int gso_mask; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci u8 can_sg:1; 2928c2ecf20Sopenharmony_ci u8 ip_csum:1; 2938c2ecf20Sopenharmony_ci u8 ipv6_csum:1; 2948c2ecf20Sopenharmony_ci u8 multicast_control:1; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* headroom requested by xen-netfront */ 2978c2ecf20Sopenharmony_ci u16 xdp_headroom; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci /* Is this interface disabled? True when backend discovers 3008c2ecf20Sopenharmony_ci * frontend is rogue. 3018c2ecf20Sopenharmony_ci */ 3028c2ecf20Sopenharmony_ci bool disabled; 3038c2ecf20Sopenharmony_ci unsigned long status; 3048c2ecf20Sopenharmony_ci unsigned long drain_timeout; 3058c2ecf20Sopenharmony_ci unsigned long stall_timeout; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci /* Queues */ 3088c2ecf20Sopenharmony_ci struct xenvif_queue *queues; 3098c2ecf20Sopenharmony_ci unsigned int num_queues; /* active queues, resource allocated */ 3108c2ecf20Sopenharmony_ci unsigned int stalled_queues; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci struct xenvif_hash hash; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci struct xenbus_watch credit_watch; 3158c2ecf20Sopenharmony_ci struct xenbus_watch mcast_ctrl_watch; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci struct backend_info *be; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci spinlock_t lock; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 3228c2ecf20Sopenharmony_ci struct dentry *xenvif_dbg_root; 3238c2ecf20Sopenharmony_ci#endif 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci struct xen_netif_ctrl_back_ring ctrl; 3268c2ecf20Sopenharmony_ci unsigned int ctrl_irq; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci /* Miscellaneous private stuff. */ 3298c2ecf20Sopenharmony_ci struct net_device *dev; 3308c2ecf20Sopenharmony_ci}; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_cistruct xenvif_rx_cb { 3338c2ecf20Sopenharmony_ci unsigned long expires; 3348c2ecf20Sopenharmony_ci int meta_slots_used; 3358c2ecf20Sopenharmony_ci}; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb) 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistatic inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci return to_xenbus_device(vif->dev->dev.parent); 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_civoid xenvif_tx_credit_callback(struct timer_list *t); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_cistruct xenvif *xenvif_alloc(struct device *parent, 3478c2ecf20Sopenharmony_ci domid_t domid, 3488c2ecf20Sopenharmony_ci unsigned int handle); 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ciint xenvif_init_queue(struct xenvif_queue *queue); 3518c2ecf20Sopenharmony_civoid xenvif_deinit_queue(struct xenvif_queue *queue); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ciint xenvif_connect_data(struct xenvif_queue *queue, 3548c2ecf20Sopenharmony_ci unsigned long tx_ring_ref, 3558c2ecf20Sopenharmony_ci unsigned long rx_ring_ref, 3568c2ecf20Sopenharmony_ci unsigned int tx_evtchn, 3578c2ecf20Sopenharmony_ci unsigned int rx_evtchn); 3588c2ecf20Sopenharmony_civoid xenvif_disconnect_data(struct xenvif *vif); 3598c2ecf20Sopenharmony_ciint xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref, 3608c2ecf20Sopenharmony_ci unsigned int evtchn); 3618c2ecf20Sopenharmony_civoid xenvif_disconnect_ctrl(struct xenvif *vif); 3628c2ecf20Sopenharmony_civoid xenvif_free(struct xenvif *vif); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ciint xenvif_xenbus_init(void); 3658c2ecf20Sopenharmony_civoid xenvif_xenbus_fini(void); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci/* (Un)Map communication rings. */ 3688c2ecf20Sopenharmony_civoid xenvif_unmap_frontend_data_rings(struct xenvif_queue *queue); 3698c2ecf20Sopenharmony_ciint xenvif_map_frontend_data_rings(struct xenvif_queue *queue, 3708c2ecf20Sopenharmony_ci grant_ref_t tx_ring_ref, 3718c2ecf20Sopenharmony_ci grant_ref_t rx_ring_ref); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci/* Check for SKBs from frontend and schedule backend processing */ 3748c2ecf20Sopenharmony_civoid xenvif_napi_schedule_or_enable_events(struct xenvif_queue *queue); 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci/* Prevent the device from generating any further traffic. */ 3778c2ecf20Sopenharmony_civoid xenvif_carrier_off(struct xenvif *vif); 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ciint xenvif_tx_action(struct xenvif_queue *queue, int budget); 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ciint xenvif_kthread_guest_rx(void *data); 3828c2ecf20Sopenharmony_civoid xenvif_kick_thread(struct xenvif_queue *queue); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ciint xenvif_dealloc_kthread(void *data); 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ciirqreturn_t xenvif_ctrl_irq_fn(int irq, void *data); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cibool xenvif_have_rx_work(struct xenvif_queue *queue, bool test_kthread); 3898c2ecf20Sopenharmony_cibool xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_civoid xenvif_carrier_on(struct xenvif *vif); 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci/* Callback from stack when TX packet can be released */ 3948c2ecf20Sopenharmony_civoid xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_cistatic inline pending_ring_idx_t nr_pending_reqs(struct xenvif_queue *queue) 3978c2ecf20Sopenharmony_ci{ 3988c2ecf20Sopenharmony_ci return MAX_PENDING_REQS - 3998c2ecf20Sopenharmony_ci queue->pending_prod + queue->pending_cons; 4008c2ecf20Sopenharmony_ci} 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ciirqreturn_t xenvif_interrupt(int irq, void *dev_id); 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ciextern bool separate_tx_rx_irq; 4058c2ecf20Sopenharmony_ciextern bool provides_xdp_headroom; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ciextern unsigned int rx_drain_timeout_msecs; 4088c2ecf20Sopenharmony_ciextern unsigned int rx_stall_timeout_msecs; 4098c2ecf20Sopenharmony_ciextern unsigned int xenvif_max_queues; 4108c2ecf20Sopenharmony_ciextern unsigned int xenvif_hash_cache_size; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 4138c2ecf20Sopenharmony_ciextern struct dentry *xen_netback_dbg_root; 4148c2ecf20Sopenharmony_ci#endif 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_civoid xenvif_skb_zerocopy_prepare(struct xenvif_queue *queue, 4178c2ecf20Sopenharmony_ci struct sk_buff *skb); 4188c2ecf20Sopenharmony_civoid xenvif_skb_zerocopy_complete(struct xenvif_queue *queue); 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci/* Multicast control */ 4218c2ecf20Sopenharmony_cibool xenvif_mcast_match(struct xenvif *vif, const u8 *addr); 4228c2ecf20Sopenharmony_civoid xenvif_mcast_addr_list_free(struct xenvif *vif); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci/* Hash */ 4258c2ecf20Sopenharmony_civoid xenvif_init_hash(struct xenvif *vif); 4268c2ecf20Sopenharmony_civoid xenvif_deinit_hash(struct xenvif *vif); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ciu32 xenvif_set_hash_alg(struct xenvif *vif, u32 alg); 4298c2ecf20Sopenharmony_ciu32 xenvif_get_hash_flags(struct xenvif *vif, u32 *flags); 4308c2ecf20Sopenharmony_ciu32 xenvif_set_hash_flags(struct xenvif *vif, u32 flags); 4318c2ecf20Sopenharmony_ciu32 xenvif_set_hash_key(struct xenvif *vif, u32 gref, u32 len); 4328c2ecf20Sopenharmony_ciu32 xenvif_set_hash_mapping_size(struct xenvif *vif, u32 size); 4338c2ecf20Sopenharmony_ciu32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, 4348c2ecf20Sopenharmony_ci u32 off); 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_civoid xenvif_set_skb_hash(struct xenvif *vif, struct sk_buff *skb); 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 4398c2ecf20Sopenharmony_civoid xenvif_dump_hash_info(struct xenvif *vif, struct seq_file *m); 4408c2ecf20Sopenharmony_ci#endif 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci#endif /* __XEN_NETBACK__COMMON_H__ */ 443