bcm_sf2.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 <net/dsa.h>
  21. #include "bcm_sf2_regs.h"
  22. struct bcm_sf2_hw_params {
  23. u16 top_rev;
  24. u16 core_rev;
  25. u16 gphy_rev;
  26. u32 num_gphy;
  27. u8 num_acb_queue;
  28. u8 num_rgmii;
  29. u8 num_ports;
  30. u8 fcb_pause_override:1;
  31. u8 acb_packets_inflight:1;
  32. };
  33. #define BCM_SF2_REGS_NAME {\
  34. "core", "reg", "intrl2_0", "intrl2_1", "fcb", "acb" \
  35. }
  36. #define BCM_SF2_REGS_NUM 6
  37. struct bcm_sf2_port_status {
  38. unsigned int link;
  39. struct ethtool_eee eee;
  40. };
  41. struct bcm_sf2_priv {
  42. /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
  43. void __iomem *core;
  44. void __iomem *reg;
  45. void __iomem *intrl2_0;
  46. void __iomem *intrl2_1;
  47. void __iomem *fcb;
  48. void __iomem *acb;
  49. /* spinlock protecting access to the indirect registers */
  50. spinlock_t indir_lock;
  51. int irq0;
  52. int irq1;
  53. u32 irq0_stat;
  54. u32 irq0_mask;
  55. u32 irq1_stat;
  56. u32 irq1_mask;
  57. /* Mutex protecting access to the MIB counters */
  58. struct mutex stats_mutex;
  59. struct bcm_sf2_hw_params hw_params;
  60. struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS];
  61. /* Mask of ports enabled for Wake-on-LAN */
  62. u32 wol_ports_mask;
  63. };
  64. struct bcm_sf2_hw_stats {
  65. const char *string;
  66. u16 reg;
  67. u8 sizeof_stat;
  68. };
  69. #define SF2_IO_MACRO(name) \
  70. static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
  71. { \
  72. return __raw_readl(priv->name + off); \
  73. } \
  74. static inline void name##_writel(struct bcm_sf2_priv *priv, \
  75. u32 val, u32 off) \
  76. { \
  77. __raw_writel(val, priv->name + off); \
  78. } \
  79. /* Accesses to 64-bits register requires us to latch the hi/lo pairs
  80. * using the REG_DIR_DATA_{READ,WRITE} ancillary registers. The 'indir_lock'
  81. * spinlock is automatically grabbed and released to provide relative
  82. * atomiticy with latched reads/writes.
  83. */
  84. #define SF2_IO64_MACRO(name) \
  85. static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
  86. { \
  87. u32 indir, dir; \
  88. spin_lock(&priv->indir_lock); \
  89. indir = reg_readl(priv, REG_DIR_DATA_READ); \
  90. dir = __raw_readl(priv->name + off); \
  91. spin_unlock(&priv->indir_lock); \
  92. return (u64)indir << 32 | dir; \
  93. } \
  94. static inline void name##_writeq(struct bcm_sf2_priv *priv, u32 off, \
  95. u64 val) \
  96. { \
  97. spin_lock(&priv->indir_lock); \
  98. reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
  99. __raw_writel(lower_32_bits(val), priv->name + off); \
  100. spin_unlock(&priv->indir_lock); \
  101. }
  102. #define SWITCH_INTR_L2(which) \
  103. static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
  104. u32 mask) \
  105. { \
  106. intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
  107. priv->irq##which##_mask &= ~(mask); \
  108. } \
  109. static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \
  110. u32 mask) \
  111. { \
  112. intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
  113. priv->irq##which##_mask |= (mask); \
  114. } \
  115. SF2_IO_MACRO(core);
  116. SF2_IO_MACRO(reg);
  117. SF2_IO64_MACRO(core);
  118. SF2_IO_MACRO(intrl2_0);
  119. SF2_IO_MACRO(intrl2_1);
  120. SF2_IO_MACRO(fcb);
  121. SF2_IO_MACRO(acb);
  122. SWITCH_INTR_L2(0);
  123. SWITCH_INTR_L2(1);
  124. #endif /* __BCM_SF2_H */