sunvnet_common.h 4.3 KB

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