bcm_sf2.h 3.5 KB

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