tsnep.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2021 Gerhard Engleder <[email protected]> */
  3. #ifndef _TSNEP_H
  4. #define _TSNEP_H
  5. #include "tsnep_hw.h"
  6. #include <linux/platform_device.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/etherdevice.h>
  9. #include <linux/phy.h>
  10. #include <linux/ethtool.h>
  11. #include <linux/net_tstamp.h>
  12. #include <linux/ptp_clock_kernel.h>
  13. #include <linux/miscdevice.h>
  14. #define TSNEP "tsnep"
  15. #define TSNEP_RING_SIZE 256
  16. #define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
  17. #define TSNEP_RING_PAGE_COUNT (TSNEP_RING_SIZE / TSNEP_RING_ENTRIES_PER_PAGE)
  18. struct tsnep_gcl {
  19. void __iomem *addr;
  20. u64 base_time;
  21. u64 cycle_time;
  22. u64 cycle_time_extension;
  23. struct tsnep_gcl_operation operation[TSNEP_GCL_COUNT];
  24. int count;
  25. u64 change_limit;
  26. u64 start_time;
  27. bool change;
  28. };
  29. enum tsnep_rxnfc_filter_type {
  30. TSNEP_RXNFC_ETHER_TYPE,
  31. };
  32. struct tsnep_rxnfc_filter {
  33. enum tsnep_rxnfc_filter_type type;
  34. union {
  35. u16 ether_type;
  36. };
  37. };
  38. struct tsnep_rxnfc_rule {
  39. struct list_head list;
  40. struct tsnep_rxnfc_filter filter;
  41. int queue_index;
  42. int location;
  43. };
  44. struct tsnep_tx_entry {
  45. struct tsnep_tx_desc *desc;
  46. struct tsnep_tx_desc_wb *desc_wb;
  47. dma_addr_t desc_dma;
  48. bool owner_user_flag;
  49. u32 properties;
  50. struct sk_buff *skb;
  51. size_t len;
  52. DEFINE_DMA_UNMAP_ADDR(dma);
  53. };
  54. struct tsnep_tx {
  55. struct tsnep_adapter *adapter;
  56. void __iomem *addr;
  57. int queue_index;
  58. void *page[TSNEP_RING_PAGE_COUNT];
  59. dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
  60. /* TX ring lock */
  61. spinlock_t lock;
  62. struct tsnep_tx_entry entry[TSNEP_RING_SIZE];
  63. int write;
  64. int read;
  65. u32 owner_counter;
  66. int increment_owner_counter;
  67. u32 packets;
  68. u32 bytes;
  69. u32 dropped;
  70. };
  71. struct tsnep_rx_entry {
  72. struct tsnep_rx_desc *desc;
  73. struct tsnep_rx_desc_wb *desc_wb;
  74. dma_addr_t desc_dma;
  75. u32 properties;
  76. struct page *page;
  77. size_t len;
  78. dma_addr_t dma;
  79. };
  80. struct tsnep_rx {
  81. struct tsnep_adapter *adapter;
  82. void __iomem *addr;
  83. int queue_index;
  84. void *page[TSNEP_RING_PAGE_COUNT];
  85. dma_addr_t page_dma[TSNEP_RING_PAGE_COUNT];
  86. struct tsnep_rx_entry entry[TSNEP_RING_SIZE];
  87. int read;
  88. u32 owner_counter;
  89. int increment_owner_counter;
  90. struct page_pool *page_pool;
  91. u32 packets;
  92. u32 bytes;
  93. u32 dropped;
  94. u32 multicast;
  95. };
  96. struct tsnep_queue {
  97. struct tsnep_adapter *adapter;
  98. char name[IFNAMSIZ + 16];
  99. struct tsnep_tx *tx;
  100. struct tsnep_rx *rx;
  101. struct napi_struct napi;
  102. int irq;
  103. u32 irq_mask;
  104. };
  105. struct tsnep_adapter {
  106. struct net_device *netdev;
  107. u8 mac_address[ETH_ALEN];
  108. struct mii_bus *mdiobus;
  109. bool suppress_preamble;
  110. phy_interface_t phy_mode;
  111. struct phy_device *phydev;
  112. int msg_enable;
  113. struct platform_device *pdev;
  114. struct device *dmadev;
  115. void __iomem *addr;
  116. bool gate_control;
  117. /* gate control lock */
  118. struct mutex gate_control_lock;
  119. bool gate_control_active;
  120. struct tsnep_gcl gcl[2];
  121. int next_gcl;
  122. struct hwtstamp_config hwtstamp_config;
  123. struct ptp_clock *ptp_clock;
  124. struct ptp_clock_info ptp_clock_info;
  125. /* ptp clock lock */
  126. spinlock_t ptp_lock;
  127. /* RX flow classification rules lock */
  128. struct mutex rxnfc_lock;
  129. struct list_head rxnfc_rules;
  130. int rxnfc_count;
  131. int rxnfc_max;
  132. int num_tx_queues;
  133. struct tsnep_tx tx[TSNEP_MAX_QUEUES];
  134. int num_rx_queues;
  135. struct tsnep_rx rx[TSNEP_MAX_QUEUES];
  136. int num_queues;
  137. struct tsnep_queue queue[TSNEP_MAX_QUEUES];
  138. };
  139. extern const struct ethtool_ops tsnep_ethtool_ops;
  140. int tsnep_ptp_init(struct tsnep_adapter *adapter);
  141. void tsnep_ptp_cleanup(struct tsnep_adapter *adapter);
  142. int tsnep_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  143. int tsnep_tc_init(struct tsnep_adapter *adapter);
  144. void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
  145. int tsnep_tc_setup(struct net_device *netdev, enum tc_setup_type type,
  146. void *type_data);
  147. int tsnep_rxnfc_init(struct tsnep_adapter *adapter);
  148. void tsnep_rxnfc_cleanup(struct tsnep_adapter *adapter);
  149. int tsnep_rxnfc_get_rule(struct tsnep_adapter *adapter,
  150. struct ethtool_rxnfc *cmd);
  151. int tsnep_rxnfc_get_all(struct tsnep_adapter *adapter,
  152. struct ethtool_rxnfc *cmd,
  153. u32 *rule_locs);
  154. int tsnep_rxnfc_add_rule(struct tsnep_adapter *adapter,
  155. struct ethtool_rxnfc *cmd);
  156. int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,
  157. struct ethtool_rxnfc *cmd);
  158. #if IS_ENABLED(CONFIG_TSNEP_SELFTESTS)
  159. int tsnep_ethtool_get_test_count(void);
  160. void tsnep_ethtool_get_test_strings(u8 *data);
  161. void tsnep_ethtool_self_test(struct net_device *netdev,
  162. struct ethtool_test *eth_test, u64 *data);
  163. #else
  164. static inline int tsnep_ethtool_get_test_count(void)
  165. {
  166. return -EOPNOTSUPP;
  167. }
  168. static inline void tsnep_ethtool_get_test_strings(u8 *data)
  169. {
  170. /* not enabled */
  171. }
  172. static inline void tsnep_ethtool_self_test(struct net_device *dev,
  173. struct ethtool_test *eth_test,
  174. u64 *data)
  175. {
  176. /* not enabled */
  177. }
  178. #endif /* CONFIG_TSNEP_SELFTESTS */
  179. void tsnep_get_system_time(struct tsnep_adapter *adapter, u64 *time);
  180. #endif /* _TSNEP_H */