stmmac_pcs.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * stmmac_pcs.h: Physical Coding Sublayer Header File
  3. *
  4. * Copyright (C) 2016 STMicroelectronics (R&D) Limited
  5. * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #ifndef __STMMAC_PCS_H__
  13. #define __STMMAC_PCS_H__
  14. #include <linux/slab.h>
  15. #include <linux/io.h>
  16. #include "common.h"
  17. /* PCS registers (AN/TBI/SGMII/RGMII) offsets */
  18. #define GMAC_AN_CTRL(x) (x) /* AN control */
  19. #define GMAC_AN_STATUS(x) (x + 0x4) /* AN status */
  20. #define GMAC_ANE_ADV(x) (x + 0x8) /* ANE Advertisement */
  21. #define GMAC_ANE_LPA(x) (x + 0xc) /* ANE link partener ability */
  22. #define GMAC_ANE_EXP(x) (x + 0x10) /* ANE expansion */
  23. #define GMAC_TBI(x) (x + 0x14) /* TBI extend status */
  24. /* AN Configuration defines */
  25. #define GMAC_AN_CTRL_RAN BIT(9) /* Restart Auto-Negotiation */
  26. #define GMAC_AN_CTRL_ANE BIT(12) /* Auto-Negotiation Enable */
  27. #define GMAC_AN_CTRL_ELE BIT(14) /* External Loopback Enable */
  28. #define GMAC_AN_CTRL_ECD BIT(16) /* Enable Comma Detect */
  29. #define GMAC_AN_CTRL_LR BIT(17) /* Lock to Reference */
  30. #define GMAC_AN_CTRL_SGMRAL BIT(18) /* SGMII RAL Control */
  31. /* AN Status defines */
  32. #define GMAC_AN_STATUS_LS BIT(2) /* Link Status 0:down 1:up */
  33. #define GMAC_AN_STATUS_ANA BIT(3) /* Auto-Negotiation Ability */
  34. #define GMAC_AN_STATUS_ANC BIT(5) /* Auto-Negotiation Complete */
  35. #define GMAC_AN_STATUS_ES BIT(8) /* Extended Status */
  36. /* ADV and LPA defines */
  37. #define GMAC_ANE_FD BIT(5)
  38. #define GMAC_ANE_HD BIT(6)
  39. #define GMAC_ANE_PSE GENMASK(8, 7)
  40. #define GMAC_ANE_PSE_SHIFT 7
  41. #define GMAC_ANE_RFE GENMASK(13, 12)
  42. #define GMAC_ANE_RFE_SHIFT 12
  43. #define GMAC_ANE_ACK BIT(14)
  44. /**
  45. * dwmac_pcs_isr - TBI, RTBI, or SGMII PHY ISR
  46. * @ioaddr: IO registers pointer
  47. * @reg: Base address of the AN Control Register.
  48. * @intr_status: GMAC core interrupt status
  49. * @x: pointer to log these events as stats
  50. * Description: it is the ISR for PCS events: Auto-Negotiation Completed and
  51. * Link status.
  52. */
  53. static inline void dwmac_pcs_isr(void __iomem *ioaddr, u32 reg,
  54. unsigned int intr_status,
  55. struct stmmac_extra_stats *x)
  56. {
  57. u32 val = readl(ioaddr + GMAC_AN_STATUS(reg));
  58. if (intr_status & PCS_ANE_IRQ) {
  59. x->irq_pcs_ane_n++;
  60. if (val & GMAC_AN_STATUS_ANC)
  61. pr_info("stmmac_pcs: ANE process completed\n");
  62. }
  63. if (intr_status & PCS_LINK_IRQ) {
  64. x->irq_pcs_link_n++;
  65. if (val & GMAC_AN_STATUS_LS)
  66. pr_info("stmmac_pcs: Link Up\n");
  67. else
  68. pr_info("stmmac_pcs: Link Down\n");
  69. }
  70. }
  71. /**
  72. * dwmac_rane - To restart ANE
  73. * @ioaddr: IO registers pointer
  74. * @reg: Base address of the AN Control Register.
  75. * @restart: to restart ANE
  76. * Description: this is to just restart the Auto-Negotiation.
  77. */
  78. static inline void dwmac_rane(void __iomem *ioaddr, u32 reg, bool restart)
  79. {
  80. u32 value = readl(ioaddr + GMAC_AN_CTRL(reg));
  81. if (restart)
  82. value |= GMAC_AN_CTRL_RAN;
  83. writel(value, ioaddr + GMAC_AN_CTRL(reg));
  84. }
  85. /**
  86. * dwmac_ctrl_ane - To program the AN Control Register.
  87. * @ioaddr: IO registers pointer
  88. * @reg: Base address of the AN Control Register.
  89. * @ane: to enable the auto-negotiation
  90. * @srgmi_ral: to manage MAC-2-MAC SGMII connections.
  91. * @loopback: to cause the PHY to loopback tx data into rx path.
  92. * Description: this is the main function to configure the AN control register
  93. * and init the ANE, select loopback (usually for debugging purpose) and
  94. * configure SGMII RAL.
  95. */
  96. static inline void dwmac_ctrl_ane(void __iomem *ioaddr, u32 reg, bool ane,
  97. bool srgmi_ral, bool loopback)
  98. {
  99. u32 value = readl(ioaddr + GMAC_AN_CTRL(reg));
  100. /* Enable and restart the Auto-Negotiation */
  101. if (ane)
  102. value |= GMAC_AN_CTRL_ANE | GMAC_AN_CTRL_RAN;
  103. /* In case of MAC-2-MAC connection, block is configured to operate
  104. * according to MAC conf register.
  105. */
  106. if (srgmi_ral)
  107. value |= GMAC_AN_CTRL_SGMRAL;
  108. if (loopback)
  109. value |= GMAC_AN_CTRL_ELE;
  110. writel(value, ioaddr + GMAC_AN_CTRL(reg));
  111. }
  112. /**
  113. * dwmac_get_adv_lp - Get ADV and LP cap
  114. * @ioaddr: IO registers pointer
  115. * @reg: Base address of the AN Control Register.
  116. * @adv_lp: structure to store the adv,lp status
  117. * Description: this is to expose the ANE advertisement and Link partner ability
  118. * status to ethtool support.
  119. */
  120. static inline void dwmac_get_adv_lp(void __iomem *ioaddr, u32 reg,
  121. struct rgmii_adv *adv_lp)
  122. {
  123. u32 value = readl(ioaddr + GMAC_ANE_ADV(reg));
  124. if (value & GMAC_ANE_FD)
  125. adv_lp->duplex = DUPLEX_FULL;
  126. if (value & GMAC_ANE_HD)
  127. adv_lp->duplex |= DUPLEX_HALF;
  128. adv_lp->pause = (value & GMAC_ANE_PSE) >> GMAC_ANE_PSE_SHIFT;
  129. value = readl(ioaddr + GMAC_ANE_LPA(reg));
  130. if (value & GMAC_ANE_FD)
  131. adv_lp->lp_duplex = DUPLEX_FULL;
  132. if (value & GMAC_ANE_HD)
  133. adv_lp->lp_duplex = DUPLEX_HALF;
  134. adv_lp->lp_pause = (value & GMAC_ANE_PSE) >> GMAC_ANE_PSE_SHIFT;
  135. }
  136. #endif /* __STMMAC_PCS_H__ */