ssb_driver_gige.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef LINUX_SSB_DRIVER_GIGE_H_
  3. #define LINUX_SSB_DRIVER_GIGE_H_
  4. #include <linux/ssb/ssb.h>
  5. #include <linux/bug.h>
  6. #include <linux/pci.h>
  7. #include <linux/spinlock.h>
  8. #ifdef CONFIG_SSB_DRIVER_GIGE
  9. #define SSB_GIGE_PCIIO 0x0000 /* PCI I/O Registers (1024 bytes) */
  10. #define SSB_GIGE_RESERVED 0x0400 /* Reserved (1024 bytes) */
  11. #define SSB_GIGE_PCICFG 0x0800 /* PCI config space (256 bytes) */
  12. #define SSB_GIGE_SHIM_FLUSHSTAT 0x0C00 /* PCI to OCP: Flush status control (32bit) */
  13. #define SSB_GIGE_SHIM_FLUSHRDA 0x0C04 /* PCI to OCP: Flush read address (32bit) */
  14. #define SSB_GIGE_SHIM_FLUSHTO 0x0C08 /* PCI to OCP: Flush timeout counter (32bit) */
  15. #define SSB_GIGE_SHIM_BARRIER 0x0C0C /* PCI to OCP: Barrier register (32bit) */
  16. #define SSB_GIGE_SHIM_MAOCPSI 0x0C10 /* PCI to OCP: MaocpSI Control (32bit) */
  17. #define SSB_GIGE_SHIM_SIOCPMA 0x0C14 /* PCI to OCP: SiocpMa Control (32bit) */
  18. /* TM Status High flags */
  19. #define SSB_GIGE_TMSHIGH_RGMII 0x00010000 /* Have an RGMII PHY-bus */
  20. /* TM Status Low flags */
  21. #define SSB_GIGE_TMSLOW_TXBYPASS 0x00080000 /* TX bypass (no delay) */
  22. #define SSB_GIGE_TMSLOW_RXBYPASS 0x00100000 /* RX bypass (no delay) */
  23. #define SSB_GIGE_TMSLOW_DLLEN 0x01000000 /* Enable DLL controls */
  24. /* Boardflags (low) */
  25. #define SSB_GIGE_BFL_ROBOSWITCH 0x0010
  26. #define SSB_GIGE_MEM_RES_NAME "SSB Broadcom 47xx GigE memory"
  27. #define SSB_GIGE_IO_RES_NAME "SSB Broadcom 47xx GigE I/O"
  28. struct ssb_gige {
  29. struct ssb_device *dev;
  30. spinlock_t lock;
  31. /* True, if the device has an RGMII bus.
  32. * False, if the device has a GMII bus. */
  33. bool has_rgmii;
  34. /* The PCI controller device. */
  35. struct pci_controller pci_controller;
  36. struct pci_ops pci_ops;
  37. struct resource mem_resource;
  38. struct resource io_resource;
  39. };
  40. /* Check whether a PCI device is a SSB Gigabit Ethernet core. */
  41. extern bool pdev_is_ssb_gige_core(struct pci_dev *pdev);
  42. /* Convert a pci_dev pointer to a ssb_gige pointer. */
  43. static inline struct ssb_gige * pdev_to_ssb_gige(struct pci_dev *pdev)
  44. {
  45. if (!pdev_is_ssb_gige_core(pdev))
  46. return NULL;
  47. return container_of(pdev->bus->ops, struct ssb_gige, pci_ops);
  48. }
  49. /* Returns whether the PHY is connected by an RGMII bus. */
  50. static inline bool ssb_gige_is_rgmii(struct pci_dev *pdev)
  51. {
  52. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  53. return (dev ? dev->has_rgmii : 0);
  54. }
  55. /* Returns whether we have a Roboswitch. */
  56. static inline bool ssb_gige_have_roboswitch(struct pci_dev *pdev)
  57. {
  58. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  59. if (dev)
  60. return !!(dev->dev->bus->sprom.boardflags_lo &
  61. SSB_GIGE_BFL_ROBOSWITCH);
  62. return false;
  63. }
  64. /* Returns whether we can only do one DMA at once. */
  65. static inline bool ssb_gige_one_dma_at_once(struct pci_dev *pdev)
  66. {
  67. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  68. if (dev)
  69. return ((dev->dev->bus->chip_id == 0x4785) &&
  70. (dev->dev->bus->chip_rev < 2));
  71. return false;
  72. }
  73. /* Returns whether we must flush posted writes. */
  74. static inline bool ssb_gige_must_flush_posted_writes(struct pci_dev *pdev)
  75. {
  76. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  77. if (dev)
  78. return (dev->dev->bus->chip_id == 0x4785);
  79. return false;
  80. }
  81. /* Get the device MAC address */
  82. static inline int ssb_gige_get_macaddr(struct pci_dev *pdev, u8 *macaddr)
  83. {
  84. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  85. if (!dev)
  86. return -ENODEV;
  87. memcpy(macaddr, dev->dev->bus->sprom.et0mac, 6);
  88. return 0;
  89. }
  90. /* Get the device phy address */
  91. static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
  92. {
  93. struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
  94. if (!dev)
  95. return -ENODEV;
  96. return dev->dev->bus->sprom.et0phyaddr;
  97. }
  98. extern int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev,
  99. struct pci_dev *pdev);
  100. extern int ssb_gige_map_irq(struct ssb_device *sdev,
  101. const struct pci_dev *pdev);
  102. /* The GigE driver is not a standalone module, because we don't have support
  103. * for unregistering the driver. So we could not unload the module anyway. */
  104. extern int ssb_gige_init(void);
  105. static inline void ssb_gige_exit(void)
  106. {
  107. /* Currently we can not unregister the GigE driver,
  108. * because we can not unregister the PCI bridge. */
  109. BUG();
  110. }
  111. #else /* CONFIG_SSB_DRIVER_GIGE */
  112. /* Gigabit Ethernet driver disabled */
  113. static inline int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev,
  114. struct pci_dev *pdev)
  115. {
  116. return -ENOSYS;
  117. }
  118. static inline int ssb_gige_map_irq(struct ssb_device *sdev,
  119. const struct pci_dev *pdev)
  120. {
  121. return -ENOSYS;
  122. }
  123. static inline int ssb_gige_init(void)
  124. {
  125. return 0;
  126. }
  127. static inline void ssb_gige_exit(void)
  128. {
  129. }
  130. static inline bool pdev_is_ssb_gige_core(struct pci_dev *pdev)
  131. {
  132. return false;
  133. }
  134. static inline struct ssb_gige * pdev_to_ssb_gige(struct pci_dev *pdev)
  135. {
  136. return NULL;
  137. }
  138. static inline bool ssb_gige_is_rgmii(struct pci_dev *pdev)
  139. {
  140. return false;
  141. }
  142. static inline bool ssb_gige_have_roboswitch(struct pci_dev *pdev)
  143. {
  144. return false;
  145. }
  146. static inline bool ssb_gige_one_dma_at_once(struct pci_dev *pdev)
  147. {
  148. return false;
  149. }
  150. static inline bool ssb_gige_must_flush_posted_writes(struct pci_dev *pdev)
  151. {
  152. return false;
  153. }
  154. static inline int ssb_gige_get_macaddr(struct pci_dev *pdev, u8 *macaddr)
  155. {
  156. return -ENODEV;
  157. }
  158. static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
  159. {
  160. return -ENODEV;
  161. }
  162. #endif /* CONFIG_SSB_DRIVER_GIGE */
  163. #endif /* LINUX_SSB_DRIVER_GIGE_H_ */