bcm_sf2.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_priv {
  46. /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
  47. void __iomem *core;
  48. void __iomem *reg;
  49. void __iomem *intrl2_0;
  50. void __iomem *intrl2_1;
  51. void __iomem *fcb;
  52. void __iomem *acb;
  53. /* spinlock protecting access to the indirect registers */
  54. spinlock_t indir_lock;
  55. int irq0;
  56. int irq1;
  57. u32 irq0_stat;
  58. u32 irq0_mask;
  59. u32 irq1_stat;
  60. u32 irq1_mask;
  61. /* Backing b53_device */
  62. struct b53_device *dev;
  63. /* Mutex protecting access to the MIB counters */
  64. struct mutex stats_mutex;
  65. struct bcm_sf2_hw_params hw_params;
  66. struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS];
  67. /* Mask of ports enabled for Wake-on-LAN */
  68. u32 wol_ports_mask;
  69. /* MoCA port location */
  70. int moca_port;
  71. /* Bitmask of ports having an integrated PHY */
  72. unsigned int int_phy_mask;
  73. /* Master and slave MDIO bus controller */
  74. unsigned int indir_phy_mask;
  75. struct device_node *master_mii_dn;
  76. struct mii_bus *slave_mii_bus;
  77. struct mii_bus *master_mii_bus;
  78. };
  79. static inline struct bcm_sf2_priv *bcm_sf2_to_priv(struct dsa_switch *ds)
  80. {
  81. struct b53_device *dev = ds->priv;
  82. return dev->priv;
  83. }
  84. #define SF2_IO_MACRO(name) \
  85. static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
  86. { \
  87. return __raw_readl(priv->name + off); \
  88. } \
  89. static inline void name##_writel(struct bcm_sf2_priv *priv, \
  90. u32 val, u32 off) \
  91. { \
  92. __raw_writel(val, priv->name + off); \
  93. } \
  94. /* Accesses to 64-bits register requires us to latch the hi/lo pairs
  95. * using the REG_DIR_DATA_{READ,WRITE} ancillary registers. The 'indir_lock'
  96. * spinlock is automatically grabbed and released to provide relative
  97. * atomiticy with latched reads/writes.
  98. */
  99. #define SF2_IO64_MACRO(name) \
  100. static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
  101. { \
  102. u32 indir, dir; \
  103. spin_lock(&priv->indir_lock); \
  104. dir = __raw_readl(priv->name + off); \
  105. indir = reg_readl(priv, REG_DIR_DATA_READ); \
  106. spin_unlock(&priv->indir_lock); \
  107. return (u64)indir << 32 | dir; \
  108. } \
  109. static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \
  110. u32 off) \
  111. { \
  112. spin_lock(&priv->indir_lock); \
  113. reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
  114. __raw_writel(lower_32_bits(val), priv->name + off); \
  115. spin_unlock(&priv->indir_lock); \
  116. }
  117. #define SWITCH_INTR_L2(which) \
  118. static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
  119. u32 mask) \
  120. { \
  121. priv->irq##which##_mask &= ~(mask); \
  122. intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
  123. } \
  124. static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \
  125. u32 mask) \
  126. { \
  127. intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
  128. priv->irq##which##_mask |= (mask); \
  129. } \
  130. SF2_IO_MACRO(core);
  131. SF2_IO_MACRO(reg);
  132. SF2_IO64_MACRO(core);
  133. SF2_IO_MACRO(intrl2_0);
  134. SF2_IO_MACRO(intrl2_1);
  135. SF2_IO_MACRO(fcb);
  136. SF2_IO_MACRO(acb);
  137. SWITCH_INTR_L2(0);
  138. SWITCH_INTR_L2(1);
  139. #endif /* __BCM_SF2_H */