bcm_sf2.h 3.6 KB

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