]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
31762eaa AY |
2 | #ifndef _SUNVNETCOMMON_H |
3 | #define _SUNVNETCOMMON_H | |
4c521e42 | 4 | |
1d311ad2 SV |
5 | #include <linux/interrupt.h> |
6 | ||
8e845f4c DS |
7 | /* length of time (or less) we expect pending descriptors to be marked |
8 | * as VIO_DESC_DONE and skbs ready to be freed | |
9 | */ | |
31762eaa | 10 | #define VNET_CLEAN_TIMEOUT ((HZ / 100) + 1) |
8e845f4c | 11 | |
42db672d | 12 | #define VNET_MAXPACKET (65535ULL + ETH_HLEN + VLAN_HLEN) |
4c521e42 DM |
13 | #define VNET_TX_RING_SIZE 512 |
14 | #define VNET_TX_WAKEUP_THRESH(dr) ((dr)->pending / 4) | |
15 | ||
368e36ed DS |
16 | #define VNET_MINTSO 2048 /* VIO protocol's minimum TSO len */ |
17 | #define VNET_MAXTSO 65535 /* VIO protocol's maximum TSO len */ | |
18 | ||
540bfe30 JW |
19 | #define VNET_MAX_MTU 65535 |
20 | ||
4c521e42 DM |
21 | /* VNET packets are sent in buffers with the first 6 bytes skipped |
22 | * so that after the ethernet header the IPv4/IPv6 headers are aligned | |
23 | * properly. | |
24 | */ | |
25 | #define VNET_PACKET_SKIP 6 | |
26 | ||
31762eaa AY |
27 | #define VNET_MAXCOOKIES (VNET_MAXPACKET / PAGE_SIZE + 1) |
28 | ||
29 | #define VNET_MAX_TXQS 16 | |
42db672d | 30 | |
4c521e42 | 31 | struct vnet_tx_entry { |
8e845f4c | 32 | struct sk_buff *skb; |
4c521e42 | 33 | unsigned int ncookies; |
42db672d | 34 | struct ldc_trans_cookie cookies[VNET_MAXCOOKIES]; |
4c521e42 DM |
35 | }; |
36 | ||
37 | struct vnet; | |
67d0719f | 38 | |
0f512c84 SN |
39 | struct vnet_port_stats { |
40 | /* keep them all the same size */ | |
41 | u32 rx_bytes; | |
42 | u32 tx_bytes; | |
43 | u32 rx_packets; | |
44 | u32 tx_packets; | |
45 | u32 event_up; | |
46 | u32 event_reset; | |
47 | u32 q_placeholder; | |
48 | }; | |
49 | ||
50 | #define NUM_VNET_PORT_STATS (sizeof(struct vnet_port_stats) / sizeof(u32)) | |
51 | ||
67d0719f AY |
52 | /* Structure to describe a vnet-port or vsw-port in the MD. |
53 | * If the vsw bit is set, this structure represents a vswitch | |
54 | * port, and the net_device can be found from ->dev. If the | |
55 | * vsw bit is not set, the net_device is available from ->vp->dev. | |
56 | * See the VNET_PORT_TO_NET_DEVICE macro below. | |
57 | */ | |
4c521e42 DM |
58 | struct vnet_port { |
59 | struct vio_driver_state vio; | |
60 | ||
0f512c84 SN |
61 | struct vnet_port_stats stats; |
62 | ||
4c521e42 DM |
63 | struct hlist_node hash; |
64 | u8 raddr[ETH_ALEN]; | |
368e36ed DS |
65 | unsigned switch_port:1; |
66 | unsigned tso:1; | |
67d0719f AY |
67 | unsigned vsw:1; |
68 | unsigned __pad:13; | |
4c521e42 DM |
69 | |
70 | struct vnet *vp; | |
67d0719f | 71 | struct net_device *dev; |
4c521e42 DM |
72 | |
73 | struct vnet_tx_entry tx_bufs[VNET_TX_RING_SIZE]; | |
74 | ||
75 | struct list_head list; | |
d1015645 SV |
76 | |
77 | u32 stop_rx_idx; | |
78 | bool stop_rx; | |
79 | bool start_cons; | |
e4defc77 | 80 | |
8e845f4c DS |
81 | struct timer_list clean_timer; |
82 | ||
e4defc77 | 83 | u64 rmtu; |
368e36ed | 84 | u16 tsolen; |
69088822 SV |
85 | |
86 | struct napi_struct napi; | |
87 | u32 napi_stop_idx; | |
88 | bool napi_resume; | |
89 | int rx_event; | |
d51bffd1 | 90 | u16 q_index; |
4c521e42 DM |
91 | }; |
92 | ||
93 | static inline struct vnet_port *to_vnet_port(struct vio_driver_state *vio) | |
94 | { | |
95 | return container_of(vio, struct vnet_port, vio); | |
96 | } | |
97 | ||
98 | #define VNET_PORT_HASH_SIZE 16 | |
99 | #define VNET_PORT_HASH_MASK (VNET_PORT_HASH_SIZE - 1) | |
100 | ||
101 | static inline unsigned int vnet_hashfn(u8 *mac) | |
102 | { | |
103 | unsigned int val = mac[4] ^ mac[5]; | |
104 | ||
105 | return val & (VNET_PORT_HASH_MASK); | |
106 | } | |
107 | ||
028ebff2 DM |
108 | struct vnet_mcast_entry { |
109 | u8 addr[ETH_ALEN]; | |
110 | u8 sent; | |
111 | u8 hit; | |
112 | struct vnet_mcast_entry *next; | |
113 | }; | |
114 | ||
4c521e42 | 115 | struct vnet { |
e1f1e5f7 | 116 | spinlock_t lock; /* Protects port_list and port_hash. */ |
4c521e42 | 117 | struct net_device *dev; |
4c521e42 | 118 | u32 msg_enable; |
e1f1e5f7 | 119 | u8 q_used[VNET_MAX_TXQS]; |
4c521e42 | 120 | struct list_head port_list; |
4c521e42 | 121 | struct hlist_head port_hash[VNET_PORT_HASH_SIZE]; |
028ebff2 | 122 | struct vnet_mcast_entry *mcast_list; |
9184a046 DM |
123 | struct list_head list; |
124 | u64 local_mac; | |
d51bffd1 | 125 | int nports; |
4c521e42 DM |
126 | }; |
127 | ||
67d0719f AY |
128 | /* Def used by common code to get the net_device from the proper location */ |
129 | #define VNET_PORT_TO_NET_DEVICE(__port) \ | |
130 | ((__port)->vsw ? (__port)->dev : (__port)->vp->dev) | |
131 | ||
31762eaa | 132 | /* Common funcs */ |
0822c5d9 | 133 | void sunvnet_clean_timer_expire_common(struct timer_list *t); |
31762eaa AY |
134 | int sunvnet_open_common(struct net_device *dev); |
135 | int sunvnet_close_common(struct net_device *dev); | |
67d0719f | 136 | void sunvnet_set_rx_mode_common(struct net_device *dev, struct vnet *vp); |
31762eaa AY |
137 | int sunvnet_set_mac_addr_common(struct net_device *dev, void *p); |
138 | void sunvnet_tx_timeout_common(struct net_device *dev); | |
0e0cc31f Y |
139 | netdev_tx_t |
140 | sunvnet_start_xmit_common(struct sk_buff *skb, struct net_device *dev, | |
141 | struct vnet_port *(*vnet_tx_port) | |
142 | (struct sk_buff *, struct net_device *)); | |
31762eaa | 143 | #ifdef CONFIG_NET_POLL_CONTROLLER |
67d0719f | 144 | void sunvnet_poll_controller_common(struct net_device *dev, struct vnet *vp); |
31762eaa AY |
145 | #endif |
146 | void sunvnet_event_common(void *arg, int event); | |
147 | int sunvnet_send_attr_common(struct vio_driver_state *vio); | |
148 | int sunvnet_handle_attr_common(struct vio_driver_state *vio, void *arg); | |
149 | void sunvnet_handshake_complete_common(struct vio_driver_state *vio); | |
150 | int sunvnet_poll_common(struct napi_struct *napi, int budget); | |
151 | void sunvnet_port_free_tx_bufs_common(struct vnet_port *port); | |
867fa150 | 152 | void vnet_port_reset(struct vnet_port *port); |
67d0719f | 153 | bool sunvnet_port_is_up_common(struct vnet_port *vnet); |
31762eaa AY |
154 | void sunvnet_port_add_txq_common(struct vnet_port *port); |
155 | void sunvnet_port_rm_txq_common(struct vnet_port *port); | |
156 | ||
157 | #endif /* _SUNVNETCOMMON_H */ |