dwmac-qcom-ethqos.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.*/
  3. #ifndef _DWMAC_QCOM_ETHQOS_H
  4. #define _DWMAC_QCOM_ETHQOS_H
  5. #include <linux/ipc_logging.h>
  6. extern void *ipc_emac_log_ctxt;
  7. #define IPCLOG_STATE_PAGES 50
  8. #define __FILENAME__ (strrchr(__FILE__, '/') ? \
  9. strrchr(__FILE__, '/') + 1 : __FILE__)
  10. #include <linux/inetdevice.h>
  11. #include <linux/inet.h>
  12. #include <net/addrconf.h>
  13. #include <net/ipv6.h>
  14. #include <net/inet_common.h>
  15. #include <linux/uaccess.h>
  16. #define QCOM_ETH_QOS_MAC_ADDR_LEN 6
  17. #define QCOM_ETH_QOS_MAC_ADDR_STR_LEN 18
  18. #define DRV_NAME "qcom-ethqos"
  19. #define ETHQOSDBG(fmt, args...) \
  20. pr_debug(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args)
  21. #define ETHQOSERR(fmt, args...) \
  22. do {\
  23. pr_err(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args);\
  24. if (ipc_emac_log_ctxt) { \
  25. ipc_log_string(ipc_emac_log_ctxt, \
  26. "%s: %s[%u]:[emac] ERROR:" fmt, __FILENAME__,\
  27. __func__, __LINE__, ## args); \
  28. } \
  29. } while (0)
  30. #define ETHQOSINFO(fmt, args...) \
  31. pr_info(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args)
  32. #define PM_WAKEUP_MS 5000
  33. #define RGMII_IO_MACRO_CONFIG 0x0
  34. #define SDCC_HC_REG_DLL_CONFIG 0x4
  35. #define SDCC_TEST_CTL 0x8
  36. #define SDCC_HC_REG_DDR_CONFIG 0xC
  37. #define SDCC_HC_REG_DLL_CONFIG2 0x10
  38. #define SDC4_STATUS 0x14
  39. #define SDCC_USR_CTL 0x18
  40. #define RGMII_IO_MACRO_CONFIG2 0x1C
  41. #define EMAC_WRAPPER_SGMII_PHY_CNTRL0_v3 0xF0
  42. #define EMAC_WRAPPER_SGMII_PHY_CNTRL1_v3 0xF4
  43. #define EMAC_WRAPPER_SGMII_PHY_CNTRL0 0x170
  44. #define EMAC_WRAPPER_SGMII_PHY_CNTRL1 0x174
  45. #define EMAC_WRAPPER_USXGMII_MUX_SEL 0x1D0
  46. #define RGMII_IO_MACRO_SCRATCH_2 0x44
  47. #define RGMII_IO_MACRO_BYPASS 0x16C
  48. #define EMAC_HW_NONE 0
  49. #define EMAC_HW_v2_1_1 0x20010001
  50. #define EMAC_HW_v2_1_2 0x20010002
  51. #define EMAC_HW_v2_3_0 0x20030000
  52. #define EMAC_HW_v2_3_1 0x20030001
  53. #define EMAC_HW_v3_0_0_RG 0x30000000
  54. #define EMAC_HW_v3_1_0 0x30010000
  55. #define EMAC_HW_v4_0_0 0x40000000
  56. #define EMAC_HW_vMAX 9
  57. #define EMAC_GDSC_EMAC_NAME "gdsc_emac"
  58. #define ETHQOS_CONFIG_PPSOUT_CMD 44
  59. #define ETHQOS_AVB_ALGORITHM 27
  60. #define MAC_PPS_CONTROL 0x00000b70
  61. #define PPS_MAXIDX(x) ((((x) + 1) * 8) - 1)
  62. #define PPS_MINIDX(x) ((x) * 8)
  63. #define MCGRENX(x) BIT(PPS_MAXIDX(x))
  64. #define PPSEN0 BIT(4)
  65. #define MAC_PPSX_TARGET_TIME_SEC(x) (0x00000b80 + ((x) * 0x10))
  66. #define MAC_PPSX_TARGET_TIME_NSEC(x) (0x00000b84 + ((x) * 0x10))
  67. #define TRGTBUSY0 BIT(31)
  68. #define TTSL0 GENMASK(30, 0)
  69. #define MAC_PPSX_INTERVAL(x) (0x00000b88 + ((x) * 0x10))
  70. #define MAC_PPSX_WIDTH(x) (0x00000b8c + ((x) * 0x10))
  71. #define DWC_ETH_QOS_PPS_CH_2 2
  72. #define DWC_ETH_QOS_PPS_CH_3 3
  73. #define AVB_CLASS_A_POLL_DEV_NODE "avb_class_a_intr"
  74. #define AVB_CLASS_B_POLL_DEV_NODE "avb_class_b_intr"
  75. #define AVB_CLASS_A_CHANNEL_NUM 2
  76. #define AVB_CLASS_B_CHANNEL_NUM 3
  77. static inline u32 PPSCMDX(u32 x, u32 val)
  78. {
  79. return (GENMASK(PPS_MINIDX(x) + 3, PPS_MINIDX(x)) &
  80. ((val) << PPS_MINIDX(x)));
  81. }
  82. static inline u32 TRGTMODSELX(u32 x, u32 val)
  83. {
  84. return (GENMASK(PPS_MAXIDX(x) - 1, PPS_MAXIDX(x) - 2) &
  85. ((val) << (PPS_MAXIDX(x) - 2)));
  86. }
  87. static inline u32 PPSX_MASK(u32 x)
  88. {
  89. return GENMASK(PPS_MAXIDX(x), PPS_MINIDX(x));
  90. }
  91. struct ethqos_emac_por {
  92. unsigned int offset;
  93. unsigned int value;
  94. };
  95. struct ethqos_emac_driver_data {
  96. struct ethqos_emac_por *por;
  97. unsigned int num_por;
  98. };
  99. struct qcom_ethqos {
  100. struct platform_device *pdev;
  101. void __iomem *rgmii_base;
  102. void __iomem *sgmii_base;
  103. void __iomem *ioaddr;
  104. unsigned int rgmii_clk_rate;
  105. struct clk *rgmii_clk;
  106. struct clk *phyaux_clk;
  107. struct clk *sgmiref_clk;
  108. unsigned int speed;
  109. int gpio_phy_intr_redirect;
  110. u32 phy_intr;
  111. /* Work struct for handling phy interrupt */
  112. struct work_struct emac_phy_work;
  113. const struct ethqos_emac_por *por;
  114. unsigned int num_por;
  115. unsigned int emac_ver;
  116. struct regulator *gdsc_emac;
  117. struct regulator *reg_rgmii;
  118. struct regulator *reg_emac_phy;
  119. struct regulator *reg_rgmii_io_pads;
  120. int pps_class_a_irq;
  121. int pps_class_b_irq;
  122. struct pinctrl_state *emac_pps_0;
  123. /* state of enabled wol options in PHY*/
  124. u32 phy_wol_wolopts;
  125. /* state of supported wol options in PHY*/
  126. u32 phy_wol_supported;
  127. /* avb_class_a dev node variables*/
  128. dev_t avb_class_a_dev_t;
  129. struct cdev *avb_class_a_cdev;
  130. struct class *avb_class_a_class;
  131. /* avb_class_b dev node variables*/
  132. dev_t avb_class_b_dev_t;
  133. struct cdev *avb_class_b_cdev;
  134. struct class *avb_class_b_class;
  135. unsigned long avb_class_a_intr_cnt;
  136. unsigned long avb_class_b_intr_cnt;
  137. int curr_serdes_speed;
  138. /* Boolean to check if clock is suspended*/
  139. int clks_suspended;
  140. struct completion clk_enable_done;
  141. /* Boolean flag for turning off GDSC during suspend */
  142. bool gdsc_off_on_suspend;
  143. /* early ethernet parameters */
  144. struct work_struct early_eth;
  145. struct delayed_work ipv4_addr_assign_wq;
  146. struct delayed_work ipv6_addr_assign_wq;
  147. bool early_eth_enabled;
  148. /* Key Performance Indicators */
  149. bool print_kpi;
  150. struct dentry *debugfs_dir;
  151. };
  152. struct ip_params {
  153. unsigned char mac_addr[QCOM_ETH_QOS_MAC_ADDR_LEN];
  154. bool is_valid_mac_addr;
  155. char link_speed[32];
  156. bool is_valid_link_speed;
  157. char ipv4_addr_str[32];
  158. struct in_addr ipv4_addr;
  159. bool is_valid_ipv4_addr;
  160. char ipv6_addr_str[48];
  161. struct in6_ifreq ipv6_addr;
  162. bool is_valid_ipv6_addr;
  163. };
  164. struct pps_cfg {
  165. unsigned int ptpclk_freq;
  166. unsigned int ppsout_freq;
  167. unsigned int ppsout_ch;
  168. unsigned int ppsout_duty;
  169. unsigned int ppsout_start;
  170. };
  171. struct ifr_data_struct {
  172. unsigned int flags;
  173. unsigned int qinx; /* dma channel no to be configured */
  174. unsigned int cmd;
  175. unsigned int context_setup;
  176. unsigned int connected_speed;
  177. unsigned int rwk_filter_values[8];
  178. unsigned int rwk_filter_length;
  179. int command_error;
  180. int test_done;
  181. void *ptr;
  182. };
  183. struct pps_info {
  184. int channel_no;
  185. };
  186. int ethqos_init_regulators(struct qcom_ethqos *ethqos);
  187. void ethqos_disable_regulators(struct qcom_ethqos *ethqos);
  188. int ethqos_init_gpio(struct qcom_ethqos *ethqos);
  189. void ethqos_free_gpios(struct qcom_ethqos *ethqos);
  190. void *qcom_ethqos_get_priv(struct qcom_ethqos *ethqos);
  191. int create_pps_interrupt_device_node(dev_t *pps_dev_t,
  192. struct cdev **pps_cdev,
  193. struct class **pps_class,
  194. char *pps_dev_node_name);
  195. int ppsout_config(struct stmmac_priv *priv, struct ifr_data_struct *req);
  196. u16 dwmac_qcom_select_queue(struct net_device *dev,
  197. struct sk_buff *skb,
  198. struct net_device *sb_dev);
  199. #define QTAG_VLAN_ETH_TYPE_OFFSET 16
  200. #define QTAG_UCP_FIELD_OFFSET 14
  201. #define QTAG_ETH_TYPE_OFFSET 12
  202. #define PTP_UDP_EV_PORT 0x013F
  203. #define PTP_UDP_GEN_PORT 0x0140
  204. #define IPA_DMA_TX_CH 0
  205. #define IPA_DMA_RX_CH 0
  206. #define VLAN_TAG_UCP_SHIFT 13
  207. #define CLASS_A_TRAFFIC_UCP 3
  208. #define CLASS_A_TRAFFIC_TX_CHANNEL 3
  209. #define CLASS_B_TRAFFIC_UCP 2
  210. #define CLASS_B_TRAFFIC_TX_CHANNEL 2
  211. #define NON_TAGGED_IP_TRAFFIC_TX_CHANNEL 1
  212. #define ALL_OTHER_TRAFFIC_TX_CHANNEL 1
  213. #define ALL_OTHER_TX_TRAFFIC_IPA_DISABLED 0
  214. #define DEFAULT_INT_MOD 1
  215. #define AVB_INT_MOD 8
  216. #define IP_PKT_INT_MOD 32
  217. #define PTP_INT_MOD 1
  218. enum dwmac_qcom_queue_operating_mode {
  219. DWMAC_QCOM_QDISABLED = 0X0,
  220. DWMAC_QCOM_QAVB,
  221. DWMAC_QCOM_QDCB,
  222. DWMAC_QCOM_QGENERIC
  223. };
  224. struct dwmac_qcom_avb_algorithm_params {
  225. unsigned int idle_slope;
  226. unsigned int send_slope;
  227. unsigned int hi_credit;
  228. unsigned int low_credit;
  229. };
  230. struct dwmac_qcom_avb_algorithm {
  231. unsigned int qinx;
  232. unsigned int algorithm;
  233. unsigned int cc;
  234. struct dwmac_qcom_avb_algorithm_params speed100params;
  235. struct dwmac_qcom_avb_algorithm_params speed1000params;
  236. enum dwmac_qcom_queue_operating_mode op_mode;
  237. };
  238. void dwmac_qcom_program_avb_algorithm(struct stmmac_priv *priv,
  239. struct ifr_data_struct *req);
  240. unsigned int dwmac_qcom_get_plat_tx_coal_frames(struct sk_buff *skb);
  241. int ethqos_init_pps(void *priv);
  242. #endif