bcm_sf2.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Broadcom Starfighter2 private context
  3. *
  4. * Copyright (C) 2014, Broadcom Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef __BCM_SF2_H
  12. #define __BCM_SF2_H
  13. #include <linux/platform_device.h>
  14. #include <linux/kernel.h>
  15. #include <linux/io.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/mutex.h>
  18. #include <linux/mii.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/types.h>
  21. #include <linux/bitops.h>
  22. #include <linux/if_vlan.h>
  23. #include <net/dsa.h>
  24. #include "bcm_sf2_regs.h"
  25. #include "b53/b53_priv.h"
  26. struct bcm_sf2_hw_params {
  27. u16 top_rev;
  28. u16 core_rev;
  29. u16 gphy_rev;
  30. u32 num_gphy;
  31. u8 num_acb_queue;
  32. u8 num_rgmii;
  33. u8 num_ports;
  34. u8 fcb_pause_override:1;
  35. u8 acb_packets_inflight:1;
  36. };
  37. #define BCM_SF2_REGS_NAME {\
  38. "core", "reg", "intrl2_0", "intrl2_1", "fcb", "acb" \
  39. }
  40. #define BCM_SF2_REGS_NUM 6
  41. struct bcm_sf2_port_status {
  42. unsigned int link;
  43. struct ethtool_eee eee;
  44. };
  45. struct bcm_sf2_cfp_priv {
  46. /* Mutex protecting concurrent accesses to the CFP registers */
  47. struct mutex lock;
  48. DECLARE_BITMAP(used, CFP_NUM_RULES);
  49. unsigned int rules_cnt;
  50. };
  51. struct bcm_sf2_priv {
  52. /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
  53. void __iomem *core;
  54. void __iomem *reg;
  55. void __iomem *intrl2_0;
  56. void __iomem *intrl2_1;
  57. void __iomem *fcb;
  58. void __iomem *acb;
  59. /* Register offsets indirection tables */
  60. u32 type;
  61. const u16 *reg_offsets;
  62. unsigned int core_reg_align;
  63. /* spinlock protecting access to the indirect registers */
  64. spinlock_t indir_lock;
  65. int irq0;
  66. int irq1;
  67. u32 irq0_stat;
  68. u32 irq0_mask;
  69. u32 irq1_stat;
  70. u32 irq1_mask;
  71. /* Backing b53_device */
  72. struct b53_device *dev;
  73. /* Mutex protecting access to the MIB counters */
  74. struct mutex stats_mutex;
  75. struct bcm_sf2_hw_params hw_params;
  76. struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS];
  77. /* Mask of ports enabled for Wake-on-LAN */
  78. u32 wol_ports_mask;
  79. /* MoCA port location */
  80. int moca_port;
  81. /* Bitmask of ports having an integrated PHY */
  82. unsigned int int_phy_mask;
  83. /* Master and slave MDIO bus controller */
  84. unsigned int indir_phy_mask;
  85. struct device_node *master_mii_dn;
  86. struct mii_bus *slave_mii_bus;
  87. struct mii_bus *master_mii_bus;
  88. /* Bitmask of ports needing BRCM tags */
  89. unsigned int brcm_tag_mask;
  90. /* CFP rules context */
  91. struct bcm_sf2_cfp_priv cfp;
  92. };
  93. static inline struct bcm_sf2_priv *bcm_sf2_to_priv(struct dsa_switch *ds)
  94. {
  95. struct b53_device *dev = ds->priv;
  96. return dev->priv;
  97. }
  98. static inline u32 bcm_sf2_mangle_addr(struct bcm_sf2_priv *priv, u32 off)
  99. {
  100. return off << priv->core_reg_align;
  101. }
  102. #define SF2_IO_MACRO(name) \
  103. static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
  104. { \
  105. return __raw_readl(priv->name + off); \
  106. } \
  107. static inline void name##_writel(struct bcm_sf2_priv *priv, \
  108. u32 val, u32 off) \
  109. { \
  110. __raw_writel(val, priv->name + off); \
  111. } \
  112. /* Accesses to 64-bits register requires us to latch the hi/lo pairs
  113. * using the REG_DIR_DATA_{READ,WRITE} ancillary registers. The 'indir_lock'
  114. * spinlock is automatically grabbed and released to provide relative
  115. * atomiticy with latched reads/writes.
  116. */
  117. #define SF2_IO64_MACRO(name) \
  118. static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
  119. { \
  120. u32 indir, dir; \
  121. spin_lock(&priv->indir_lock); \
  122. dir = name##_readl(priv, off); \
  123. indir = reg_readl(priv, REG_DIR_DATA_READ); \
  124. spin_unlock(&priv->indir_lock); \
  125. return (u64)indir << 32 | dir; \
  126. } \
  127. static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \
  128. u32 off) \
  129. { \
  130. spin_lock(&priv->indir_lock); \
  131. reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
  132. name##_writel(priv, lower_32_bits(val), off); \
  133. spin_unlock(&priv->indir_lock); \
  134. }
  135. #define SWITCH_INTR_L2(which) \
  136. static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
  137. u32 mask) \
  138. { \
  139. priv->irq##which##_mask &= ~(mask); \
  140. intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
  141. } \
  142. static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \
  143. u32 mask) \
  144. { \
  145. intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
  146. priv->irq##which##_mask |= (mask); \
  147. } \
  148. static inline u32 core_readl(struct bcm_sf2_priv *priv, u32 off)
  149. {
  150. u32 tmp = bcm_sf2_mangle_addr(priv, off);
  151. return __raw_readl(priv->core + tmp);
  152. }
  153. static inline void core_writel(struct bcm_sf2_priv *priv, u32 val, u32 off)
  154. {
  155. u32 tmp = bcm_sf2_mangle_addr(priv, off);
  156. __raw_writel(val, priv->core + tmp);
  157. }
  158. static inline u32 reg_readl(struct bcm_sf2_priv *priv, u16 off)
  159. {
  160. return __raw_readl(priv->reg + priv->reg_offsets[off]);
  161. }
  162. static inline void reg_writel(struct bcm_sf2_priv *priv, u32 val, u16 off)
  163. {
  164. __raw_writel(val, priv->reg + priv->reg_offsets[off]);
  165. }
  166. SF2_IO64_MACRO(core);
  167. SF2_IO_MACRO(intrl2_0);
  168. SF2_IO_MACRO(intrl2_1);
  169. SF2_IO_MACRO(fcb);
  170. SF2_IO_MACRO(acb);
  171. SWITCH_INTR_L2(0);
  172. SWITCH_INTR_L2(1);
  173. /* RXNFC */
  174. int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
  175. struct ethtool_rxnfc *nfc, u32 *rule_locs);
  176. int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
  177. struct ethtool_rxnfc *nfc);
  178. int bcm_sf2_cfp_rst(struct bcm_sf2_priv *priv);
  179. #endif /* __BCM_SF2_H */