am65-cpsw-nuss.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. */
  5. #ifndef AM65_CPSW_NUSS_H_
  6. #define AM65_CPSW_NUSS_H_
  7. #include <linux/if_ether.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/phylink.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/soc/ti/k3-ringacc.h>
  14. #include <net/devlink.h>
  15. #include "am65-cpsw-qos.h"
  16. struct am65_cpts;
  17. #define HOST_PORT_NUM 0
  18. #define AM65_CPSW_MAX_TX_QUEUES 8
  19. #define AM65_CPSW_MAX_RX_QUEUES 1
  20. #define AM65_CPSW_MAX_RX_FLOWS 1
  21. #define AM65_CPSW_PORT_VLAN_REG_OFFSET 0x014
  22. struct am65_cpsw_slave_data {
  23. bool mac_only;
  24. struct cpsw_sl *mac_sl;
  25. struct device_node *phy_node;
  26. phy_interface_t phy_if;
  27. struct phy *ifphy;
  28. bool rx_pause;
  29. bool tx_pause;
  30. u8 mac_addr[ETH_ALEN];
  31. int port_vlan;
  32. struct phylink *phylink;
  33. struct phylink_config phylink_config;
  34. };
  35. struct am65_cpsw_port {
  36. struct am65_cpsw_common *common;
  37. struct net_device *ndev;
  38. const char *name;
  39. u32 port_id;
  40. void __iomem *port_base;
  41. void __iomem *sgmii_base;
  42. void __iomem *stat_base;
  43. void __iomem *fetch_ram_base;
  44. bool disabled;
  45. struct am65_cpsw_slave_data slave;
  46. bool tx_ts_enabled;
  47. bool rx_ts_enabled;
  48. struct am65_cpsw_qos qos;
  49. struct devlink_port devlink_port;
  50. };
  51. struct am65_cpsw_host {
  52. struct am65_cpsw_common *common;
  53. void __iomem *port_base;
  54. void __iomem *stat_base;
  55. };
  56. struct am65_cpsw_tx_chn {
  57. struct device *dma_dev;
  58. struct napi_struct napi_tx;
  59. struct am65_cpsw_common *common;
  60. struct k3_cppi_desc_pool *desc_pool;
  61. struct k3_udma_glue_tx_channel *tx_chn;
  62. spinlock_t lock; /* protect TX rings in multi-port mode */
  63. int irq;
  64. u32 id;
  65. u32 descs_num;
  66. char tx_chn_name[128];
  67. };
  68. struct am65_cpsw_rx_chn {
  69. struct device *dev;
  70. struct device *dma_dev;
  71. struct k3_cppi_desc_pool *desc_pool;
  72. struct k3_udma_glue_rx_channel *rx_chn;
  73. u32 descs_num;
  74. int irq;
  75. };
  76. #define AM65_CPSW_QUIRK_I2027_NO_TX_CSUM BIT(0)
  77. #define AM64_CPSW_QUIRK_DMA_RX_TDOWN_IRQ BIT(1)
  78. struct am65_cpsw_pdata {
  79. u32 quirks;
  80. u64 extra_modes;
  81. enum k3_ring_mode fdqring_mode;
  82. const char *ale_dev_id;
  83. };
  84. enum cpsw_devlink_param_id {
  85. AM65_CPSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
  86. AM65_CPSW_DL_PARAM_SWITCH_MODE,
  87. };
  88. struct am65_cpsw_devlink {
  89. struct am65_cpsw_common *common;
  90. };
  91. struct am65_cpsw_common {
  92. struct device *dev;
  93. struct device *mdio_dev;
  94. struct am65_cpsw_pdata pdata;
  95. void __iomem *ss_base;
  96. void __iomem *cpsw_base;
  97. u32 port_num;
  98. struct am65_cpsw_host host;
  99. struct am65_cpsw_port *ports;
  100. u32 disabled_ports_mask;
  101. struct net_device *dma_ndev;
  102. int usage_count; /* number of opened ports */
  103. struct cpsw_ale *ale;
  104. int tx_ch_num;
  105. u32 rx_flow_id_base;
  106. struct am65_cpsw_tx_chn tx_chns[AM65_CPSW_MAX_TX_QUEUES];
  107. struct completion tdown_complete;
  108. atomic_t tdown_cnt;
  109. struct am65_cpsw_rx_chn rx_chns;
  110. struct napi_struct napi_rx;
  111. bool rx_irq_disabled;
  112. u32 nuss_ver;
  113. u32 cpsw_ver;
  114. unsigned long bus_freq;
  115. bool pf_p0_rx_ptype_rrobin;
  116. struct am65_cpts *cpts;
  117. int est_enabled;
  118. bool is_emac_mode;
  119. u16 br_members;
  120. int default_vlan;
  121. struct devlink *devlink;
  122. struct net_device *hw_bridge_dev;
  123. struct notifier_block am65_cpsw_netdevice_nb;
  124. unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN];
  125. };
  126. struct am65_cpsw_ndev_stats {
  127. u64 tx_packets;
  128. u64 tx_bytes;
  129. u64 rx_packets;
  130. u64 rx_bytes;
  131. struct u64_stats_sync syncp;
  132. };
  133. struct am65_cpsw_ndev_priv {
  134. u32 msg_enable;
  135. struct am65_cpsw_port *port;
  136. struct am65_cpsw_ndev_stats __percpu *stats;
  137. bool offload_fwd_mark;
  138. };
  139. #define am65_ndev_to_priv(ndev) \
  140. ((struct am65_cpsw_ndev_priv *)netdev_priv(ndev))
  141. #define am65_ndev_to_port(ndev) (am65_ndev_to_priv(ndev)->port)
  142. #define am65_ndev_to_common(ndev) (am65_ndev_to_port(ndev)->common)
  143. #define am65_ndev_to_slave(ndev) (&am65_ndev_to_port(ndev)->slave)
  144. #define am65_common_get_host(common) (&(common)->host)
  145. #define am65_common_get_port(common, id) (&(common)->ports[(id) - 1])
  146. #define am65_cpsw_napi_to_common(pnapi) \
  147. container_of(pnapi, struct am65_cpsw_common, napi_rx)
  148. #define am65_cpsw_napi_to_tx_chn(pnapi) \
  149. container_of(pnapi, struct am65_cpsw_tx_chn, napi_tx)
  150. #define AM65_CPSW_DRV_NAME "am65-cpsw-nuss"
  151. #define AM65_CPSW_IS_CPSW2G(common) ((common)->port_num == 1)
  152. extern const struct ethtool_ops am65_cpsw_ethtool_ops_slave;
  153. void am65_cpsw_nuss_adjust_link(struct net_device *ndev);
  154. void am65_cpsw_nuss_set_p0_ptype(struct am65_cpsw_common *common);
  155. void am65_cpsw_nuss_remove_tx_chns(struct am65_cpsw_common *common);
  156. int am65_cpsw_nuss_update_tx_chns(struct am65_cpsw_common *common, int num_tx);
  157. bool am65_cpsw_port_dev_check(const struct net_device *dev);
  158. #endif /* AM65_CPSW_NUSS_H_ */