1 #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 #define VNET_MAX_MTU 65535 19 20 /* VNET packets are sent in buffers with the first 6 bytes skipped 21 * so that after the ethernet header the IPv4/IPv6 headers are aligned 22 * properly. 23 */ 24 #define VNET_PACKET_SKIP 6 25 26 #define VNET_MAXCOOKIES (VNET_MAXPACKET / PAGE_SIZE + 1) 27 28 #define VNET_MAX_TXQS 16 29 30 struct vnet_tx_entry { 31 struct sk_buff *skb; 32 unsigned int ncookies; 33 struct ldc_trans_cookie cookies[VNET_MAXCOOKIES]; 34 }; 35 36 struct vnet; 37 38 struct vnet_port_stats { 39 /* keep them all the same size */ 40 u32 rx_bytes; 41 u32 tx_bytes; 42 u32 rx_packets; 43 u32 tx_packets; 44 u32 event_up; 45 u32 event_reset; 46 u32 q_placeholder; 47 }; 48 49 #define NUM_VNET_PORT_STATS (sizeof(struct vnet_port_stats) / sizeof(u32)) 50 51 /* Structure to describe a vnet-port or vsw-port in the MD. 52 * If the vsw bit is set, this structure represents a vswitch 53 * port, and the net_device can be found from ->dev. If the 54 * vsw bit is not set, the net_device is available from ->vp->dev. 55 * See the VNET_PORT_TO_NET_DEVICE macro below. 56 */ 57 struct vnet_port { 58 struct vio_driver_state vio; 59 60 struct vnet_port_stats stats; 61 62 struct hlist_node hash; 63 u8 raddr[ETH_ALEN]; 64 unsigned switch_port:1; 65 unsigned tso:1; 66 unsigned vsw:1; 67 unsigned __pad:13; 68 69 struct vnet *vp; 70 struct net_device *dev; 71 72 struct vnet_tx_entry tx_bufs[VNET_TX_RING_SIZE]; 73 74 struct list_head list; 75 76 u32 stop_rx_idx; 77 bool stop_rx; 78 bool start_cons; 79 80 struct timer_list clean_timer; 81 82 u64 rmtu; 83 u16 tsolen; 84 85 struct napi_struct napi; 86 u32 napi_stop_idx; 87 bool napi_resume; 88 int rx_event; 89 u16 q_index; 90 }; 91 92 static inline struct vnet_port *to_vnet_port(struct vio_driver_state *vio) 93 { 94 return container_of(vio, struct vnet_port, vio); 95 } 96 97 #define VNET_PORT_HASH_SIZE 16 98 #define VNET_PORT_HASH_MASK (VNET_PORT_HASH_SIZE - 1) 99 100 static inline unsigned int vnet_hashfn(u8 *mac) 101 { 102 unsigned int val = mac[4] ^ mac[5]; 103 104 return val & (VNET_PORT_HASH_MASK); 105 } 106 107 struct vnet_mcast_entry { 108 u8 addr[ETH_ALEN]; 109 u8 sent; 110 u8 hit; 111 struct vnet_mcast_entry *next; 112 }; 113 114 struct vnet { 115 spinlock_t lock; /* Protects port_list and port_hash. */ 116 struct net_device *dev; 117 u32 msg_enable; 118 u8 q_used[VNET_MAX_TXQS]; 119 struct list_head port_list; 120 struct hlist_head port_hash[VNET_PORT_HASH_SIZE]; 121 struct vnet_mcast_entry *mcast_list; 122 struct list_head list; 123 u64 local_mac; 124 int nports; 125 }; 126 127 /* Def used by common code to get the net_device from the proper location */ 128 #define VNET_PORT_TO_NET_DEVICE(__port) \ 129 ((__port)->vsw ? (__port)->dev : (__port)->vp->dev) 130 131 /* Common funcs */ 132 void sunvnet_clean_timer_expire_common(unsigned long port0); 133 int sunvnet_open_common(struct net_device *dev); 134 int sunvnet_close_common(struct net_device *dev); 135 void sunvnet_set_rx_mode_common(struct net_device *dev, struct vnet *vp); 136 int sunvnet_set_mac_addr_common(struct net_device *dev, void *p); 137 void sunvnet_tx_timeout_common(struct net_device *dev); 138 int sunvnet_start_xmit_common(struct sk_buff *skb, struct net_device *dev, 139 struct vnet_port *(*vnet_tx_port) 140 (struct sk_buff *, struct net_device *)); 141 #ifdef CONFIG_NET_POLL_CONTROLLER 142 void sunvnet_poll_controller_common(struct net_device *dev, struct vnet *vp); 143 #endif 144 void sunvnet_event_common(void *arg, int event); 145 int sunvnet_send_attr_common(struct vio_driver_state *vio); 146 int sunvnet_handle_attr_common(struct vio_driver_state *vio, void *arg); 147 void sunvnet_handshake_complete_common(struct vio_driver_state *vio); 148 int sunvnet_poll_common(struct napi_struct *napi, int budget); 149 void sunvnet_port_free_tx_bufs_common(struct vnet_port *port); 150 void vnet_port_reset(struct vnet_port *port); 151 bool sunvnet_port_is_up_common(struct vnet_port *vnet); 152 void sunvnet_port_add_txq_common(struct vnet_port *port); 153 void sunvnet_port_rm_txq_common(struct vnet_port *port); 154 155 #endif /* _SUNVNETCOMMON_H */ 156