adm6996.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * ADM6996 switch driver
  3. *
  4. * Copyright (c) 2008 Felix Fietkau <nbd@nbd.name>
  5. * Copyright (c) 2010,2011 Peter Lebbing <peter@digitalbrains.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License v2 as published by the
  9. * Free Software Foundation
  10. */
  11. #ifndef __ADM6996_H
  12. #define __ADM6996_H
  13. /*
  14. * ADM_PHY_PORTS: Number of ports with a PHY.
  15. * We only control ports 0 to 3, because if 4 is connected, it is most likely
  16. * not connected to the switch but to a separate MII and MAC for the WAN port.
  17. */
  18. #define ADM_PHY_PORTS 4
  19. #define ADM_NUM_PORTS 6
  20. #define ADM_CPU_PORT 5
  21. #define ADM_NUM_VLANS 16
  22. #define ADM_VLAN_MAX_ID 4094
  23. enum admreg {
  24. ADM_EEPROM_BASE = 0x0,
  25. ADM_P0_CFG = ADM_EEPROM_BASE + 1,
  26. ADM_P1_CFG = ADM_EEPROM_BASE + 3,
  27. ADM_P2_CFG = ADM_EEPROM_BASE + 5,
  28. ADM_P3_CFG = ADM_EEPROM_BASE + 7,
  29. ADM_P4_CFG = ADM_EEPROM_BASE + 8,
  30. ADM_P5_CFG = ADM_EEPROM_BASE + 9,
  31. ADM_SYSC0 = ADM_EEPROM_BASE + 0xa,
  32. ADM_VLAN_PRIOMAP = ADM_EEPROM_BASE + 0xe,
  33. ADM_SYSC3 = ADM_EEPROM_BASE + 0x11,
  34. /* Input Force No Tag Enable */
  35. ADM_IFNTE = ADM_EEPROM_BASE + 0x20,
  36. ADM_VID_CHECK = ADM_EEPROM_BASE + 0x26,
  37. ADM_P0_PVID = ADM_EEPROM_BASE + 0x28,
  38. ADM_P1_PVID = ADM_EEPROM_BASE + 0x29,
  39. /* Output Tag Bypass Enable and P2 PVID */
  40. ADM_OTBE_P2_PVID = ADM_EEPROM_BASE + 0x2a,
  41. ADM_P3_P4_PVID = ADM_EEPROM_BASE + 0x2b,
  42. ADM_P5_PVID = ADM_EEPROM_BASE + 0x2c,
  43. ADM_EEPROM_EXT_BASE = 0x40,
  44. #define ADM_VLAN_FILT_L(n) (ADM_EEPROM_EXT_BASE + 2 * (n))
  45. #define ADM_VLAN_FILT_H(n) (ADM_EEPROM_EXT_BASE + 1 + 2 * (n))
  46. #define ADM_VLAN_MAP(n) (ADM_EEPROM_BASE + 0x13 + n)
  47. ADM_COUNTER_BASE = 0xa0,
  48. ADM_SIG0 = ADM_COUNTER_BASE + 0,
  49. ADM_SIG1 = ADM_COUNTER_BASE + 1,
  50. ADM_PS0 = ADM_COUNTER_BASE + 2,
  51. ADM_PS1 = ADM_COUNTER_BASE + 3,
  52. ADM_PS2 = ADM_COUNTER_BASE + 4,
  53. ADM_CL0 = ADM_COUNTER_BASE + 8, /* RxPacket */
  54. ADM_CL6 = ADM_COUNTER_BASE + 0x1a, /* RxByte */
  55. ADM_CL12 = ADM_COUNTER_BASE + 0x2c, /* TxPacket */
  56. ADM_CL18 = ADM_COUNTER_BASE + 0x3e, /* TxByte */
  57. ADM_CL24 = ADM_COUNTER_BASE + 0x50, /* Coll */
  58. ADM_CL30 = ADM_COUNTER_BASE + 0x62, /* Err */
  59. #define ADM_OFFSET_PORT(n) ((n * 4) - (n / 4) * 2 - (n / 5) * 2)
  60. ADM_PHY_BASE = 0x200,
  61. #define ADM_PHY_PORT(n) (ADM_PHY_BASE + (0x20 * n))
  62. };
  63. /* Chip identification patterns */
  64. #define ADM_SIG0_MASK 0xffff
  65. #define ADM_SIG0_VAL 0x1023
  66. #define ADM_SIG1_MASK 0xffff
  67. #define ADM_SIG1_VAL 0x0007
  68. enum {
  69. ADM_PHYCFG_COLTST = (1 << 7), /* Enable collision test */
  70. ADM_PHYCFG_DPLX = (1 << 8), /* Enable full duplex */
  71. ADM_PHYCFG_ANEN_RST = (1 << 9), /* Restart auto negotiation (self clear) */
  72. ADM_PHYCFG_ISO = (1 << 10), /* Isolate PHY */
  73. ADM_PHYCFG_PDN = (1 << 11), /* Power down PHY */
  74. ADM_PHYCFG_ANEN = (1 << 12), /* Enable auto negotiation */
  75. ADM_PHYCFG_SPEED_100 = (1 << 13), /* Enable 100 Mbit/s */
  76. ADM_PHYCFG_LPBK = (1 << 14), /* Enable loopback operation */
  77. ADM_PHYCFG_RST = (1 << 15), /* Reset the port (self clear) */
  78. ADM_PHYCFG_INIT = (
  79. ADM_PHYCFG_RST |
  80. ADM_PHYCFG_SPEED_100 |
  81. ADM_PHYCFG_ANEN |
  82. ADM_PHYCFG_ANEN_RST
  83. )
  84. };
  85. enum {
  86. ADM_PORTCFG_FC = (1 << 0), /* Enable 802.x flow control */
  87. ADM_PORTCFG_AN = (1 << 1), /* Enable auto-negotiation */
  88. ADM_PORTCFG_SPEED_100 = (1 << 2), /* Enable 100 Mbit/s */
  89. ADM_PORTCFG_DPLX = (1 << 3), /* Enable full duplex */
  90. ADM_PORTCFG_OT = (1 << 4), /* Output tagged packets */
  91. ADM_PORTCFG_PD = (1 << 5), /* Port disable */
  92. ADM_PORTCFG_TV_PRIO = (1 << 6), /* 0 = VLAN based priority
  93. * 1 = TOS based priority */
  94. ADM_PORTCFG_PPE = (1 << 7), /* Port based priority enable */
  95. ADM_PORTCFG_PP_S = (1 << 8), /* Port based priority, 2 bits */
  96. ADM_PORTCFG_PVID_BASE = (1 << 10), /* Primary VLAN id, 4 bits */
  97. ADM_PORTCFG_FSE = (1 << 14), /* Fx select enable */
  98. ADM_PORTCFG_CAM = (1 << 15), /* Crossover Auto MDIX */
  99. ADM_PORTCFG_INIT = (
  100. ADM_PORTCFG_FC |
  101. ADM_PORTCFG_AN |
  102. ADM_PORTCFG_SPEED_100 |
  103. ADM_PORTCFG_DPLX |
  104. ADM_PORTCFG_CAM
  105. ),
  106. ADM_PORTCFG_CPU = (
  107. ADM_PORTCFG_FC |
  108. ADM_PORTCFG_SPEED_100 |
  109. ADM_PORTCFG_OT |
  110. ADM_PORTCFG_DPLX
  111. ),
  112. };
  113. #define ADM_PORTCFG_PPID(n) ((n & 0x3) << 8)
  114. #define ADM_PORTCFG_PVID(n) ((n & 0xf) << 10)
  115. #define ADM_PORTCFG_PVID_MASK (0xf << 10)
  116. #define ADM_IFNTE_MASK (0x3f << 9)
  117. #define ADM_VID_CHECK_MASK (0x3f << 6)
  118. #define ADM_P0_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  119. #define ADM_P1_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  120. #define ADM_P2_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  121. #define ADM_P3_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  122. #define ADM_P4_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 8)
  123. #define ADM_P5_PVID_VAL(n) ((((n) & 0xff0) >> 4) << 0)
  124. #define ADM_P2_PVID_MASK 0xff
  125. #define ADM_OTBE(n) (((n) & 0x3f) << 8)
  126. #define ADM_OTBE_MASK (0x3f << 8)
  127. /* ADM_SYSC0 */
  128. enum {
  129. ADM_NTTE = (1 << 2), /* New Tag Transmit Enable */
  130. ADM_RVID1 = (1 << 8) /* Replace VLAN ID 1 */
  131. };
  132. /* Tag Based VLAN in ADM_SYSC3 */
  133. #define ADM_MAC_CLONE BIT(4)
  134. #define ADM_TBV BIT(5)
  135. static const u8 adm_portcfg[] = {
  136. [0] = ADM_P0_CFG,
  137. [1] = ADM_P1_CFG,
  138. [2] = ADM_P2_CFG,
  139. [3] = ADM_P3_CFG,
  140. [4] = ADM_P4_CFG,
  141. [5] = ADM_P5_CFG,
  142. };
  143. /* Fields in ADM_VLAN_FILT_L(x) */
  144. #define ADM_VLAN_FILT_FID(n) (((n) & 0xf) << 12)
  145. #define ADM_VLAN_FILT_TAGGED(n) (((n) & 0x3f) << 6)
  146. #define ADM_VLAN_FILT_MEMBER(n) (((n) & 0x3f) << 0)
  147. #define ADM_VLAN_FILT_MEMBER_MASK 0x3f
  148. /* Fields in ADM_VLAN_FILT_H(x) */
  149. #define ADM_VLAN_FILT_VALID (1 << 15)
  150. #define ADM_VLAN_FILT_VID(n) (((n) & 0xfff) << 0)
  151. /* Convert ports to a form for ADM6996L VLAN map */
  152. #define ADM_VLAN_FILT(ports) ((ports & 0x01) | ((ports & 0x02) << 1) | \
  153. ((ports & 0x04) << 2) | ((ports & 0x08) << 3) | \
  154. ((ports & 0x10) << 3) | ((ports & 0x20) << 3))
  155. /* Port status register */
  156. enum {
  157. ADM_PS_LS = (1 << 0), /* Link status */
  158. ADM_PS_SS = (1 << 1), /* Speed status */
  159. ADM_PS_DS = (1 << 2), /* Duplex status */
  160. ADM_PS_FCS = (1 << 3) /* Flow control status */
  161. };
  162. /*
  163. * Split the register address in phy id and register
  164. * it will get combined again by the mdio bus op
  165. */
  166. #define PHYADDR(_reg) ((_reg >> 5) & 0xff), (_reg & 0x1f)
  167. #endif