blob: c29c5269703d191aa63fcbc31dc6e37abc368ee5 [file] [log] [blame]
Aaron Young31762ea2016-03-15 11:35:37 -07001#ifndef _SUNVNETCOMMON_H
2#define _SUNVNETCOMMON_H
3
4#include <linux/interrupt.h>
5
6/* length of time (or less) we expect pending descriptors to be marked
7 * as VIO_DESC_DONE and skbs ready to be freed
8 */
9#define VNET_CLEAN_TIMEOUT ((HZ / 100) + 1)
10
11#define VNET_MAXPACKET (65535ULL + ETH_HLEN + VLAN_HLEN)
12#define VNET_TX_RING_SIZE 512
13#define VNET_TX_WAKEUP_THRESH(dr) ((dr)->pending / 4)
14
15#define VNET_MINTSO 2048 /* VIO protocol's minimum TSO len */
16#define VNET_MAXTSO 65535 /* VIO protocol's maximum TSO len */
17
18/* VNET packets are sent in buffers with the first 6 bytes skipped
19 * so that after the ethernet header the IPv4/IPv6 headers are aligned
20 * properly.
21 */
22#define VNET_PACKET_SKIP 6
23
24#define VNET_MAXCOOKIES (VNET_MAXPACKET / PAGE_SIZE + 1)
25
26#define VNET_MAX_TXQS 16
27
28struct vnet_tx_entry {
29 struct sk_buff *skb;
30 unsigned int ncookies;
31 struct ldc_trans_cookie cookies[VNET_MAXCOOKIES];
32};
33
34struct vnet;
35struct vnet_port {
36 struct vio_driver_state vio;
37
38 struct hlist_node hash;
39 u8 raddr[ETH_ALEN];
40 unsigned switch_port:1;
41 unsigned tso:1;
42 unsigned __pad:14;
43
44 struct vnet *vp;
45
46 struct vnet_tx_entry tx_bufs[VNET_TX_RING_SIZE];
47
48 struct list_head list;
49
50 u32 stop_rx_idx;
51 bool stop_rx;
52 bool start_cons;
53
54 struct timer_list clean_timer;
55
56 u64 rmtu;
57 u16 tsolen;
58
59 struct napi_struct napi;
60 u32 napi_stop_idx;
61 bool napi_resume;
62 int rx_event;
63 u16 q_index;
64};
65
66static inline struct vnet_port *to_vnet_port(struct vio_driver_state *vio)
67{
68 return container_of(vio, struct vnet_port, vio);
69}
70
71#define VNET_PORT_HASH_SIZE 16
72#define VNET_PORT_HASH_MASK (VNET_PORT_HASH_SIZE - 1)
73
74static inline unsigned int vnet_hashfn(u8 *mac)
75{
76 unsigned int val = mac[4] ^ mac[5];
77
78 return val & (VNET_PORT_HASH_MASK);
79}
80
81struct vnet_mcast_entry {
82 u8 addr[ETH_ALEN];
83 u8 sent;
84 u8 hit;
85 struct vnet_mcast_entry *next;
86};
87
88struct vnet {
89 /* Protects port_list and port_hash. */
90 spinlock_t lock;
91
92 struct net_device *dev;
93
94 u32 msg_enable;
95
96 struct list_head port_list;
97
98 struct hlist_head port_hash[VNET_PORT_HASH_SIZE];
99
100 struct vnet_mcast_entry *mcast_list;
101
102 struct list_head list;
103 u64 local_mac;
104
105 int nports;
106};
107
108/* Common funcs */
109void sunvnet_clean_timer_expire_common(unsigned long port0);
110int sunvnet_open_common(struct net_device *dev);
111int sunvnet_close_common(struct net_device *dev);
112void sunvnet_set_rx_mode_common(struct net_device *dev);
113int sunvnet_set_mac_addr_common(struct net_device *dev, void *p);
114void sunvnet_tx_timeout_common(struct net_device *dev);
115int sunvnet_change_mtu_common(struct net_device *dev, int new_mtu);
116int sunvnet_start_xmit_common(struct sk_buff *skb, struct net_device *dev);
117u16 sunvnet_select_queue_common(struct net_device *dev,
118 struct sk_buff *skb,
119 void *accel_priv,
120 select_queue_fallback_t fallback);
121#ifdef CONFIG_NET_POLL_CONTROLLER
122void sunvnet_poll_controller_common(struct net_device *dev);
123#endif
124void sunvnet_event_common(void *arg, int event);
125int sunvnet_send_attr_common(struct vio_driver_state *vio);
126int sunvnet_handle_attr_common(struct vio_driver_state *vio, void *arg);
127void sunvnet_handshake_complete_common(struct vio_driver_state *vio);
128int sunvnet_poll_common(struct napi_struct *napi, int budget);
129void sunvnet_port_free_tx_bufs_common(struct vnet_port *port);
130void sunvnet_port_add_txq_common(struct vnet_port *port);
131void sunvnet_port_rm_txq_common(struct vnet_port *port);
132
133#endif /* _SUNVNETCOMMON_H */