bcm_sf2.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 <net/dsa.h>
  23. #include "bcm_sf2_regs.h"
  24. struct bcm_sf2_hw_params {
  25. u16 top_rev;
  26. u16 core_rev;
  27. u16 gphy_rev;
  28. u32 num_gphy;
  29. u8 num_acb_queue;
  30. u8 num_rgmii;
  31. u8 num_ports;
  32. u8 fcb_pause_override:1;
  33. u8 acb_packets_inflight:1;
  34. };
  35. #define BCM_SF2_REGS_NAME {\
  36. "core", "reg", "intrl2_0", "intrl2_1", "fcb", "acb" \
  37. }
  38. #define BCM_SF2_REGS_NUM 6
  39. struct bcm_sf2_port_status {
  40. unsigned int link;
  41. struct ethtool_eee eee;
  42. u32 vlan_ctl_mask;
  43. };
  44. struct bcm_sf2_arl_entry {
  45. u8 port;
  46. u8 mac[ETH_ALEN];
  47. u16 vid;
  48. u8 is_valid:1;
  49. u8 is_age:1;
  50. u8 is_static:1;
  51. };
  52. static inline void bcm_sf2_mac_from_u64(u64 src, u8 *dst)
  53. {
  54. unsigned int i;
  55. for (i = 0; i < ETH_ALEN; i++)
  56. dst[ETH_ALEN - 1 - i] = (src >> (8 * i)) & 0xff;
  57. }
  58. static inline u64 bcm_sf2_mac_to_u64(const u8 *src)
  59. {
  60. unsigned int i;
  61. u64 dst = 0;
  62. for (i = 0; i < ETH_ALEN; i++)
  63. dst |= (u64)src[ETH_ALEN - 1 - i] << (8 * i);
  64. return dst;
  65. }
  66. static inline void bcm_sf2_arl_to_entry(struct bcm_sf2_arl_entry *ent,
  67. u64 mac_vid, u32 fwd_entry)
  68. {
  69. memset(ent, 0, sizeof(*ent));
  70. ent->port = fwd_entry & PORTID_MASK;
  71. ent->is_valid = !!(fwd_entry & ARL_VALID);
  72. ent->is_age = !!(fwd_entry & ARL_AGE);
  73. ent->is_static = !!(fwd_entry & ARL_STATIC);
  74. bcm_sf2_mac_from_u64(mac_vid, ent->mac);
  75. ent->vid = mac_vid >> VID_SHIFT;
  76. }
  77. static inline void bcm_sf2_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
  78. const struct bcm_sf2_arl_entry *ent)
  79. {
  80. *mac_vid = bcm_sf2_mac_to_u64(ent->mac);
  81. *mac_vid |= (u64)(ent->vid & VID_MASK) << VID_SHIFT;
  82. *fwd_entry = ent->port & PORTID_MASK;
  83. if (ent->is_valid)
  84. *fwd_entry |= ARL_VALID;
  85. if (ent->is_static)
  86. *fwd_entry |= ARL_STATIC;
  87. if (ent->is_age)
  88. *fwd_entry |= ARL_AGE;
  89. }
  90. struct bcm_sf2_priv {
  91. /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
  92. void __iomem *core;
  93. void __iomem *reg;
  94. void __iomem *intrl2_0;
  95. void __iomem *intrl2_1;
  96. void __iomem *fcb;
  97. void __iomem *acb;
  98. /* spinlock protecting access to the indirect registers */
  99. spinlock_t indir_lock;
  100. int irq0;
  101. int irq1;
  102. u32 irq0_stat;
  103. u32 irq0_mask;
  104. u32 irq1_stat;
  105. u32 irq1_mask;
  106. /* Mutex protecting access to the MIB counters */
  107. struct mutex stats_mutex;
  108. struct bcm_sf2_hw_params hw_params;
  109. struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS];
  110. /* Mask of ports enabled for Wake-on-LAN */
  111. u32 wol_ports_mask;
  112. /* MoCA port location */
  113. int moca_port;
  114. /* Bitmask of ports having an integrated PHY */
  115. unsigned int int_phy_mask;
  116. };
  117. struct bcm_sf2_hw_stats {
  118. const char *string;
  119. u16 reg;
  120. u8 sizeof_stat;
  121. };
  122. #define SF2_IO_MACRO(name) \
  123. static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
  124. { \
  125. return __raw_readl(priv->name + off); \
  126. } \
  127. static inline void name##_writel(struct bcm_sf2_priv *priv, \
  128. u32 val, u32 off) \
  129. { \
  130. __raw_writel(val, priv->name + off); \
  131. } \
  132. /* Accesses to 64-bits register requires us to latch the hi/lo pairs
  133. * using the REG_DIR_DATA_{READ,WRITE} ancillary registers. The 'indir_lock'
  134. * spinlock is automatically grabbed and released to provide relative
  135. * atomiticy with latched reads/writes.
  136. */
  137. #define SF2_IO64_MACRO(name) \
  138. static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
  139. { \
  140. u32 indir, dir; \
  141. spin_lock(&priv->indir_lock); \
  142. dir = __raw_readl(priv->name + off); \
  143. indir = reg_readl(priv, REG_DIR_DATA_READ); \
  144. spin_unlock(&priv->indir_lock); \
  145. return (u64)indir << 32 | dir; \
  146. } \
  147. static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \
  148. u32 off) \
  149. { \
  150. spin_lock(&priv->indir_lock); \
  151. reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
  152. __raw_writel(lower_32_bits(val), priv->name + off); \
  153. spin_unlock(&priv->indir_lock); \
  154. }
  155. #define SWITCH_INTR_L2(which) \
  156. static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
  157. u32 mask) \
  158. { \
  159. priv->irq##which##_mask &= ~(mask); \
  160. intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
  161. } \
  162. static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \
  163. u32 mask) \
  164. { \
  165. intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
  166. priv->irq##which##_mask |= (mask); \
  167. } \
  168. SF2_IO_MACRO(core);
  169. SF2_IO_MACRO(reg);
  170. SF2_IO64_MACRO(core);
  171. SF2_IO_MACRO(intrl2_0);
  172. SF2_IO_MACRO(intrl2_1);
  173. SF2_IO_MACRO(fcb);
  174. SF2_IO_MACRO(acb);
  175. SWITCH_INTR_L2(0);
  176. SWITCH_INTR_L2(1);
  177. #endif /* __BCM_SF2_H */