sunvnet_common.h 3.9 KB

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