162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or 362306a36Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2 462306a36Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed 562306a36Sopenharmony_ci * separately from the Linux kernel or incorporated into other 662306a36Sopenharmony_ci * software packages, subject to the following license: 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 962306a36Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without 1062306a36Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify, 1162306a36Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software, 1262306a36Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to 1362306a36Sopenharmony_ci * the following conditions: 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1662306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1962306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2062306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2162306a36Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2262306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2362306a36Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2462306a36Sopenharmony_ci * IN THE SOFTWARE. 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#ifndef __XEN_NETBACK__COMMON_H__ 2862306a36Sopenharmony_ci#define __XEN_NETBACK__COMMON_H__ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#include <linux/module.h> 3362306a36Sopenharmony_ci#include <linux/interrupt.h> 3462306a36Sopenharmony_ci#include <linux/slab.h> 3562306a36Sopenharmony_ci#include <linux/ip.h> 3662306a36Sopenharmony_ci#include <linux/in.h> 3762306a36Sopenharmony_ci#include <linux/io.h> 3862306a36Sopenharmony_ci#include <linux/netdevice.h> 3962306a36Sopenharmony_ci#include <linux/etherdevice.h> 4062306a36Sopenharmony_ci#include <linux/wait.h> 4162306a36Sopenharmony_ci#include <linux/sched.h> 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#include <xen/interface/io/netif.h> 4462306a36Sopenharmony_ci#include <xen/interface/grant_table.h> 4562306a36Sopenharmony_ci#include <xen/grant_table.h> 4662306a36Sopenharmony_ci#include <xen/xenbus.h> 4762306a36Sopenharmony_ci#include <xen/page.h> 4862306a36Sopenharmony_ci#include <linux/debugfs.h> 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_citypedef unsigned int pending_ring_idx_t; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistruct pending_tx_info { 5362306a36Sopenharmony_ci struct xen_netif_tx_request req; /* tx request */ 5462306a36Sopenharmony_ci unsigned int extra_count; 5562306a36Sopenharmony_ci /* Callback data for released SKBs. The callback is always 5662306a36Sopenharmony_ci * xenvif_zerocopy_callback, desc contains the pending_idx, which is 5762306a36Sopenharmony_ci * also an index in pending_tx_info array. It is initialized in 5862306a36Sopenharmony_ci * xenvif_alloc and it never changes. 5962306a36Sopenharmony_ci * skb_shinfo(skb)->destructor_arg points to the first mapped slot's 6062306a36Sopenharmony_ci * callback_struct in this array of struct pending_tx_info's, then ctx 6162306a36Sopenharmony_ci * to the next, or NULL if there is no more slot for this skb. 6262306a36Sopenharmony_ci * ubuf_to_vif is a helper which finds the struct xenvif from a pointer 6362306a36Sopenharmony_ci * to this field. 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_ci struct ubuf_info_msgzc callback_struct; 6662306a36Sopenharmony_ci}; 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, XEN_PAGE_SIZE) 6962306a36Sopenharmony_ci#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, XEN_PAGE_SIZE) 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistruct xenvif_rx_meta { 7262306a36Sopenharmony_ci int id; 7362306a36Sopenharmony_ci int size; 7462306a36Sopenharmony_ci int gso_type; 7562306a36Sopenharmony_ci int gso_size; 7662306a36Sopenharmony_ci}; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define GSO_BIT(type) \ 7962306a36Sopenharmony_ci (1 << XEN_NETIF_GSO_TYPE_ ## type) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Discriminate from any valid pending_idx value. */ 8262306a36Sopenharmony_ci#define INVALID_PENDING_IDX 0xFFFF 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#define MAX_PENDING_REQS XEN_NETIF_TX_RING_SIZE 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* The maximum number of frags is derived from the size of a grant (same 8762306a36Sopenharmony_ci * as a Xen page size for now). 8862306a36Sopenharmony_ci */ 8962306a36Sopenharmony_ci#define MAX_XEN_SKB_FRAGS (65536 / XEN_PAGE_SIZE + 1) 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#define NETBACK_INVALID_HANDLE -1 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* To avoid confusion, we define XEN_NETBK_LEGACY_SLOTS_MAX indicating 9462306a36Sopenharmony_ci * the maximum slots a valid packet can use. Now this value is defined 9562306a36Sopenharmony_ci * to be XEN_NETIF_NR_SLOTS_MIN, which is supposed to be supported by 9662306a36Sopenharmony_ci * all backend. 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_ci#define XEN_NETBK_LEGACY_SLOTS_MAX XEN_NETIF_NR_SLOTS_MIN 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* Queue name is interface name with "-qNNN" appended */ 10162306a36Sopenharmony_ci#define QUEUE_NAME_SIZE (IFNAMSIZ + 5) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* IRQ name is queue name with "-tx" or "-rx" appended */ 10462306a36Sopenharmony_ci#define IRQ_NAME_SIZE (QUEUE_NAME_SIZE + 3) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_cistruct xenvif; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistruct xenvif_stats { 10962306a36Sopenharmony_ci /* Stats fields to be updated per-queue. 11062306a36Sopenharmony_ci * A subset of struct net_device_stats that contains only the 11162306a36Sopenharmony_ci * fields that are updated in netback.c for each queue. 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_ci u64 rx_bytes; 11462306a36Sopenharmony_ci u64 rx_packets; 11562306a36Sopenharmony_ci u64 tx_bytes; 11662306a36Sopenharmony_ci u64 tx_packets; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci /* Additional stats used by xenvif */ 11962306a36Sopenharmony_ci unsigned long rx_gso_checksum_fixup; 12062306a36Sopenharmony_ci unsigned long tx_zerocopy_sent; 12162306a36Sopenharmony_ci unsigned long tx_zerocopy_success; 12262306a36Sopenharmony_ci unsigned long tx_zerocopy_fail; 12362306a36Sopenharmony_ci unsigned long tx_frag_overflow; 12462306a36Sopenharmony_ci}; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#define COPY_BATCH_SIZE 64 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_cistruct xenvif_copy_state { 12962306a36Sopenharmony_ci struct gnttab_copy op[COPY_BATCH_SIZE]; 13062306a36Sopenharmony_ci RING_IDX idx[COPY_BATCH_SIZE]; 13162306a36Sopenharmony_ci unsigned int num; 13262306a36Sopenharmony_ci struct sk_buff_head *completed; 13362306a36Sopenharmony_ci}; 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_cistruct xenvif_queue { /* Per-queue data for xenvif */ 13662306a36Sopenharmony_ci unsigned int id; /* Queue ID, 0-based */ 13762306a36Sopenharmony_ci char name[QUEUE_NAME_SIZE]; /* DEVNAME-qN */ 13862306a36Sopenharmony_ci struct xenvif *vif; /* Parent VIF */ 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci /* 14162306a36Sopenharmony_ci * TX/RX common EOI handling. 14262306a36Sopenharmony_ci * When feature-split-event-channels = 0, interrupt handler sets 14362306a36Sopenharmony_ci * NETBK_COMMON_EOI, otherwise NETBK_RX_EOI and NETBK_TX_EOI are set 14462306a36Sopenharmony_ci * by the RX and TX interrupt handlers. 14562306a36Sopenharmony_ci * RX and TX handler threads will issue an EOI when either 14662306a36Sopenharmony_ci * NETBK_COMMON_EOI or their specific bits (NETBK_RX_EOI or 14762306a36Sopenharmony_ci * NETBK_TX_EOI) are set and they will reset those bits. 14862306a36Sopenharmony_ci */ 14962306a36Sopenharmony_ci atomic_t eoi_pending; 15062306a36Sopenharmony_ci#define NETBK_RX_EOI 0x01 15162306a36Sopenharmony_ci#define NETBK_TX_EOI 0x02 15262306a36Sopenharmony_ci#define NETBK_COMMON_EOI 0x04 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci /* Use NAPI for guest TX */ 15562306a36Sopenharmony_ci struct napi_struct napi; 15662306a36Sopenharmony_ci /* When feature-split-event-channels = 0, tx_irq = rx_irq. */ 15762306a36Sopenharmony_ci unsigned int tx_irq; 15862306a36Sopenharmony_ci /* Only used when feature-split-event-channels = 1 */ 15962306a36Sopenharmony_ci char tx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-tx */ 16062306a36Sopenharmony_ci struct xen_netif_tx_back_ring tx; 16162306a36Sopenharmony_ci struct sk_buff_head tx_queue; 16262306a36Sopenharmony_ci struct page *mmap_pages[MAX_PENDING_REQS]; 16362306a36Sopenharmony_ci pending_ring_idx_t pending_prod; 16462306a36Sopenharmony_ci pending_ring_idx_t pending_cons; 16562306a36Sopenharmony_ci u16 pending_ring[MAX_PENDING_REQS]; 16662306a36Sopenharmony_ci struct pending_tx_info pending_tx_info[MAX_PENDING_REQS]; 16762306a36Sopenharmony_ci grant_handle_t grant_tx_handle[MAX_PENDING_REQS]; 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci struct gnttab_copy tx_copy_ops[2 * MAX_PENDING_REQS]; 17062306a36Sopenharmony_ci struct gnttab_map_grant_ref tx_map_ops[MAX_PENDING_REQS]; 17162306a36Sopenharmony_ci struct gnttab_unmap_grant_ref tx_unmap_ops[MAX_PENDING_REQS]; 17262306a36Sopenharmony_ci /* passed to gnttab_[un]map_refs with pages under (un)mapping */ 17362306a36Sopenharmony_ci struct page *pages_to_map[MAX_PENDING_REQS]; 17462306a36Sopenharmony_ci struct page *pages_to_unmap[MAX_PENDING_REQS]; 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci /* This prevents zerocopy callbacks to race over dealloc_ring */ 17762306a36Sopenharmony_ci spinlock_t callback_lock; 17862306a36Sopenharmony_ci /* This prevents dealloc thread and NAPI instance to race over response 17962306a36Sopenharmony_ci * creation and pending_ring in xenvif_idx_release. In xenvif_tx_err 18062306a36Sopenharmony_ci * it only protect response creation 18162306a36Sopenharmony_ci */ 18262306a36Sopenharmony_ci spinlock_t response_lock; 18362306a36Sopenharmony_ci pending_ring_idx_t dealloc_prod; 18462306a36Sopenharmony_ci pending_ring_idx_t dealloc_cons; 18562306a36Sopenharmony_ci u16 dealloc_ring[MAX_PENDING_REQS]; 18662306a36Sopenharmony_ci struct task_struct *dealloc_task; 18762306a36Sopenharmony_ci wait_queue_head_t dealloc_wq; 18862306a36Sopenharmony_ci atomic_t inflight_packets; 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci /* Use kthread for guest RX */ 19162306a36Sopenharmony_ci struct task_struct *task; 19262306a36Sopenharmony_ci wait_queue_head_t wq; 19362306a36Sopenharmony_ci /* When feature-split-event-channels = 0, tx_irq = rx_irq. */ 19462306a36Sopenharmony_ci unsigned int rx_irq; 19562306a36Sopenharmony_ci /* Only used when feature-split-event-channels = 1 */ 19662306a36Sopenharmony_ci char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */ 19762306a36Sopenharmony_ci struct xen_netif_rx_back_ring rx; 19862306a36Sopenharmony_ci struct sk_buff_head rx_queue; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci unsigned int rx_queue_max; 20162306a36Sopenharmony_ci unsigned int rx_queue_len; 20262306a36Sopenharmony_ci unsigned long last_rx_time; 20362306a36Sopenharmony_ci unsigned int rx_slots_needed; 20462306a36Sopenharmony_ci bool stalled; 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci struct xenvif_copy_state rx_copy; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */ 20962306a36Sopenharmony_ci unsigned long credit_bytes; 21062306a36Sopenharmony_ci unsigned long credit_usec; 21162306a36Sopenharmony_ci unsigned long remaining_credit; 21262306a36Sopenharmony_ci struct timer_list credit_timeout; 21362306a36Sopenharmony_ci u64 credit_window_start; 21462306a36Sopenharmony_ci bool rate_limited; 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci /* Statistics */ 21762306a36Sopenharmony_ci struct xenvif_stats stats; 21862306a36Sopenharmony_ci}; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_cienum state_bit_shift { 22162306a36Sopenharmony_ci /* This bit marks that the vif is connected */ 22262306a36Sopenharmony_ci VIF_STATUS_CONNECTED, 22362306a36Sopenharmony_ci}; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_cistruct xenvif_mcast_addr { 22662306a36Sopenharmony_ci struct list_head entry; 22762306a36Sopenharmony_ci struct rcu_head rcu; 22862306a36Sopenharmony_ci u8 addr[6]; 22962306a36Sopenharmony_ci}; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci#define XEN_NETBK_MCAST_MAX 64 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci#define XEN_NETBK_MAX_HASH_KEY_SIZE 40 23462306a36Sopenharmony_ci#define XEN_NETBK_MAX_HASH_MAPPING_SIZE 128 23562306a36Sopenharmony_ci#define XEN_NETBK_HASH_TAG_SIZE 40 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_cistruct xenvif_hash_cache_entry { 23862306a36Sopenharmony_ci struct list_head link; 23962306a36Sopenharmony_ci struct rcu_head rcu; 24062306a36Sopenharmony_ci u8 tag[XEN_NETBK_HASH_TAG_SIZE]; 24162306a36Sopenharmony_ci unsigned int len; 24262306a36Sopenharmony_ci u32 val; 24362306a36Sopenharmony_ci int seq; 24462306a36Sopenharmony_ci}; 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_cistruct xenvif_hash_cache { 24762306a36Sopenharmony_ci spinlock_t lock; 24862306a36Sopenharmony_ci struct list_head list; 24962306a36Sopenharmony_ci unsigned int count; 25062306a36Sopenharmony_ci atomic_t seq; 25162306a36Sopenharmony_ci}; 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_cistruct xenvif_hash { 25462306a36Sopenharmony_ci unsigned int alg; 25562306a36Sopenharmony_ci u32 flags; 25662306a36Sopenharmony_ci bool mapping_sel; 25762306a36Sopenharmony_ci u8 key[XEN_NETBK_MAX_HASH_KEY_SIZE]; 25862306a36Sopenharmony_ci u32 mapping[2][XEN_NETBK_MAX_HASH_MAPPING_SIZE]; 25962306a36Sopenharmony_ci unsigned int size; 26062306a36Sopenharmony_ci struct xenvif_hash_cache cache; 26162306a36Sopenharmony_ci}; 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_cistruct backend_info { 26462306a36Sopenharmony_ci struct xenbus_device *dev; 26562306a36Sopenharmony_ci struct xenvif *vif; 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci /* This is the state that will be reflected in xenstore when any 26862306a36Sopenharmony_ci * active hotplug script completes. 26962306a36Sopenharmony_ci */ 27062306a36Sopenharmony_ci enum xenbus_state state; 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci enum xenbus_state frontend_state; 27362306a36Sopenharmony_ci struct xenbus_watch hotplug_status_watch; 27462306a36Sopenharmony_ci u8 have_hotplug_status_watch:1; 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci const char *hotplug_script; 27762306a36Sopenharmony_ci}; 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_cistruct xenvif { 28062306a36Sopenharmony_ci /* Unique identifier for this interface. */ 28162306a36Sopenharmony_ci domid_t domid; 28262306a36Sopenharmony_ci unsigned int handle; 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci u8 fe_dev_addr[6]; 28562306a36Sopenharmony_ci struct list_head fe_mcast_addr; 28662306a36Sopenharmony_ci unsigned int fe_mcast_count; 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci /* Frontend feature information. */ 28962306a36Sopenharmony_ci int gso_mask; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci u8 can_sg:1; 29262306a36Sopenharmony_ci u8 ip_csum:1; 29362306a36Sopenharmony_ci u8 ipv6_csum:1; 29462306a36Sopenharmony_ci u8 multicast_control:1; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci /* headroom requested by xen-netfront */ 29762306a36Sopenharmony_ci u16 xdp_headroom; 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci /* Is this interface disabled? True when backend discovers 30062306a36Sopenharmony_ci * frontend is rogue. 30162306a36Sopenharmony_ci */ 30262306a36Sopenharmony_ci bool disabled; 30362306a36Sopenharmony_ci unsigned long status; 30462306a36Sopenharmony_ci unsigned long drain_timeout; 30562306a36Sopenharmony_ci unsigned long stall_timeout; 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci /* Queues */ 30862306a36Sopenharmony_ci struct xenvif_queue *queues; 30962306a36Sopenharmony_ci unsigned int num_queues; /* active queues, resource allocated */ 31062306a36Sopenharmony_ci unsigned int stalled_queues; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci struct xenvif_hash hash; 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci struct xenbus_watch credit_watch; 31562306a36Sopenharmony_ci struct xenbus_watch mcast_ctrl_watch; 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci struct backend_info *be; 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci spinlock_t lock; 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 32262306a36Sopenharmony_ci struct dentry *xenvif_dbg_root; 32362306a36Sopenharmony_ci#endif 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci struct xen_netif_ctrl_back_ring ctrl; 32662306a36Sopenharmony_ci unsigned int ctrl_irq; 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci /* Miscellaneous private stuff. */ 32962306a36Sopenharmony_ci struct net_device *dev; 33062306a36Sopenharmony_ci}; 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_cistruct xenvif_rx_cb { 33362306a36Sopenharmony_ci unsigned long expires; 33462306a36Sopenharmony_ci int meta_slots_used; 33562306a36Sopenharmony_ci}; 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb) 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_cistatic inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) 34062306a36Sopenharmony_ci{ 34162306a36Sopenharmony_ci return to_xenbus_device(vif->dev->dev.parent); 34262306a36Sopenharmony_ci} 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_civoid xenvif_tx_credit_callback(struct timer_list *t); 34562306a36Sopenharmony_ci 34662306a36Sopenharmony_cistruct xenvif *xenvif_alloc(struct device *parent, 34762306a36Sopenharmony_ci domid_t domid, 34862306a36Sopenharmony_ci unsigned int handle); 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ciint xenvif_init_queue(struct xenvif_queue *queue); 35162306a36Sopenharmony_civoid xenvif_deinit_queue(struct xenvif_queue *queue); 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ciint xenvif_connect_data(struct xenvif_queue *queue, 35462306a36Sopenharmony_ci unsigned long tx_ring_ref, 35562306a36Sopenharmony_ci unsigned long rx_ring_ref, 35662306a36Sopenharmony_ci unsigned int tx_evtchn, 35762306a36Sopenharmony_ci unsigned int rx_evtchn); 35862306a36Sopenharmony_civoid xenvif_disconnect_data(struct xenvif *vif); 35962306a36Sopenharmony_ciint xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref, 36062306a36Sopenharmony_ci unsigned int evtchn); 36162306a36Sopenharmony_civoid xenvif_disconnect_ctrl(struct xenvif *vif); 36262306a36Sopenharmony_civoid xenvif_free(struct xenvif *vif); 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ciint xenvif_xenbus_init(void); 36562306a36Sopenharmony_civoid xenvif_xenbus_fini(void); 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci/* (Un)Map communication rings. */ 36862306a36Sopenharmony_civoid xenvif_unmap_frontend_data_rings(struct xenvif_queue *queue); 36962306a36Sopenharmony_ciint xenvif_map_frontend_data_rings(struct xenvif_queue *queue, 37062306a36Sopenharmony_ci grant_ref_t tx_ring_ref, 37162306a36Sopenharmony_ci grant_ref_t rx_ring_ref); 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci/* Check for SKBs from frontend and schedule backend processing */ 37462306a36Sopenharmony_civoid xenvif_napi_schedule_or_enable_events(struct xenvif_queue *queue); 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci/* Prevent the device from generating any further traffic. */ 37762306a36Sopenharmony_civoid xenvif_carrier_off(struct xenvif *vif); 37862306a36Sopenharmony_ci 37962306a36Sopenharmony_ciint xenvif_tx_action(struct xenvif_queue *queue, int budget); 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ciint xenvif_kthread_guest_rx(void *data); 38262306a36Sopenharmony_civoid xenvif_kick_thread(struct xenvif_queue *queue); 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ciint xenvif_dealloc_kthread(void *data); 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ciirqreturn_t xenvif_ctrl_irq_fn(int irq, void *data); 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_cibool xenvif_have_rx_work(struct xenvif_queue *queue, bool test_kthread); 38962306a36Sopenharmony_cibool xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb); 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_civoid xenvif_carrier_on(struct xenvif *vif); 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_ci/* Callback from stack when TX packet can be released */ 39462306a36Sopenharmony_civoid xenvif_zerocopy_callback(struct sk_buff *skb, struct ubuf_info *ubuf, 39562306a36Sopenharmony_ci bool zerocopy_success); 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_cistatic inline pending_ring_idx_t nr_pending_reqs(struct xenvif_queue *queue) 39862306a36Sopenharmony_ci{ 39962306a36Sopenharmony_ci return MAX_PENDING_REQS - 40062306a36Sopenharmony_ci queue->pending_prod + queue->pending_cons; 40162306a36Sopenharmony_ci} 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ciirqreturn_t xenvif_interrupt(int irq, void *dev_id); 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ciextern bool separate_tx_rx_irq; 40662306a36Sopenharmony_ciextern bool provides_xdp_headroom; 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ciextern unsigned int rx_drain_timeout_msecs; 40962306a36Sopenharmony_ciextern unsigned int rx_stall_timeout_msecs; 41062306a36Sopenharmony_ciextern unsigned int xenvif_max_queues; 41162306a36Sopenharmony_ciextern unsigned int xenvif_hash_cache_size; 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 41462306a36Sopenharmony_ciextern struct dentry *xen_netback_dbg_root; 41562306a36Sopenharmony_ci#endif 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_civoid xenvif_skb_zerocopy_prepare(struct xenvif_queue *queue, 41862306a36Sopenharmony_ci struct sk_buff *skb); 41962306a36Sopenharmony_civoid xenvif_skb_zerocopy_complete(struct xenvif_queue *queue); 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci/* Multicast control */ 42262306a36Sopenharmony_cibool xenvif_mcast_match(struct xenvif *vif, const u8 *addr); 42362306a36Sopenharmony_civoid xenvif_mcast_addr_list_free(struct xenvif *vif); 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ci/* Hash */ 42662306a36Sopenharmony_civoid xenvif_init_hash(struct xenvif *vif); 42762306a36Sopenharmony_civoid xenvif_deinit_hash(struct xenvif *vif); 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ciu32 xenvif_set_hash_alg(struct xenvif *vif, u32 alg); 43062306a36Sopenharmony_ciu32 xenvif_get_hash_flags(struct xenvif *vif, u32 *flags); 43162306a36Sopenharmony_ciu32 xenvif_set_hash_flags(struct xenvif *vif, u32 flags); 43262306a36Sopenharmony_ciu32 xenvif_set_hash_key(struct xenvif *vif, u32 gref, u32 len); 43362306a36Sopenharmony_ciu32 xenvif_set_hash_mapping_size(struct xenvif *vif, u32 size); 43462306a36Sopenharmony_ciu32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, 43562306a36Sopenharmony_ci u32 off); 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_civoid xenvif_set_skb_hash(struct xenvif *vif, struct sk_buff *skb); 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 44062306a36Sopenharmony_civoid xenvif_dump_hash_info(struct xenvif *vif, struct seq_file *m); 44162306a36Sopenharmony_ci#endif 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_ci#endif /* __XEN_NETBACK__COMMON_H__ */ 444