fm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  4. */
  5. #ifndef __FM_H__
  6. #define __FM_H__
  7. #include <common.h>
  8. #include <phy.h>
  9. #include <fm_eth.h>
  10. #include <fsl_fman.h>
  11. /* Port ID */
  12. #define OH_PORT_ID_BASE 0x01
  13. #define MAX_NUM_OH_PORT 7
  14. #define RX_PORT_1G_BASE 0x08
  15. #define MAX_NUM_RX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
  16. #define RX_PORT_10G_BASE 0x10
  17. #define RX_PORT_10G_BASE2 0x08
  18. #define TX_PORT_1G_BASE 0x28
  19. #define MAX_NUM_TX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
  20. #define TX_PORT_10G_BASE 0x30
  21. #define TX_PORT_10G_BASE2 0x28
  22. #define MIIM_TIMEOUT 0xFFFF
  23. struct fm_muram {
  24. void *base;
  25. void *top;
  26. size_t size;
  27. void *alloc;
  28. };
  29. #define FM_MURAM_RES_SIZE 0x01000
  30. /* Rx/Tx buffer descriptor */
  31. struct fm_port_bd {
  32. u16 status;
  33. u16 len;
  34. u32 res0;
  35. u16 res1;
  36. u16 buf_ptr_hi;
  37. u32 buf_ptr_lo;
  38. };
  39. /* Common BD flags */
  40. #define BD_LAST 0x0800
  41. /* Rx BD status flags */
  42. #define RxBD_EMPTY 0x8000
  43. #define RxBD_LAST BD_LAST
  44. #define RxBD_FIRST 0x0400
  45. #define RxBD_PHYS_ERR 0x0008
  46. #define RxBD_SIZE_ERR 0x0004
  47. #define RxBD_ERROR (RxBD_PHYS_ERR | RxBD_SIZE_ERR)
  48. /* Tx BD status flags */
  49. #define TxBD_READY 0x8000
  50. #define TxBD_LAST BD_LAST
  51. #ifdef CONFIG_DM_ETH
  52. enum fm_mac_type {
  53. #ifdef CONFIG_SYS_FMAN_V3
  54. FM_MEMAC,
  55. #else
  56. FM_DTSEC,
  57. FM_TGEC,
  58. #endif
  59. };
  60. #endif
  61. /* Fman ethernet private struct */
  62. /* Rx/Tx queue descriptor */
  63. struct fm_port_qd {
  64. u16 gen;
  65. u16 bd_ring_base_hi;
  66. u32 bd_ring_base_lo;
  67. u16 bd_ring_size;
  68. u16 offset_in;
  69. u16 offset_out;
  70. u16 res0;
  71. u32 res1[0x4];
  72. };
  73. /* IM global parameter RAM */
  74. struct fm_port_global_pram {
  75. u32 mode; /* independent mode register */
  76. u32 rxqd_ptr; /* Rx queue descriptor pointer */
  77. u32 txqd_ptr; /* Tx queue descriptor pointer */
  78. u16 mrblr; /* max Rx buffer length */
  79. u16 rxqd_bsy_cnt; /* RxQD busy counter, should be cleared */
  80. u32 res0[0x4];
  81. struct fm_port_qd rxqd; /* Rx queue descriptor */
  82. struct fm_port_qd txqd; /* Tx queue descriptor */
  83. u32 res1[0x28];
  84. };
  85. #define FM_PRAM_SIZE sizeof(struct fm_port_global_pram)
  86. #define FM_PRAM_ALIGN 256
  87. #define PRAM_MODE_GLOBAL 0x20000000
  88. #define PRAM_MODE_GRACEFUL_STOP 0x00800000
  89. #if defined(CONFIG_ARCH_P1023)
  90. #define FM_FREE_POOL_SIZE 0x2000 /* 8K bytes */
  91. #else
  92. #define FM_FREE_POOL_SIZE 0x20000 /* 128K bytes */
  93. #endif
  94. #define FM_FREE_POOL_ALIGN 256
  95. void *fm_muram_alloc(int fm_idx, size_t size, ulong align);
  96. void *fm_muram_base(int fm_idx);
  97. int fm_init_common(int index, struct ccsr_fman *reg);
  98. int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info);
  99. phy_interface_t fman_port_enet_if(enum fm_port port);
  100. void fman_disable_port(enum fm_port port);
  101. void fman_enable_port(enum fm_port port);
  102. int fman_id(struct udevice *dev);
  103. void *fman_port(struct udevice *dev, int num);
  104. #ifdef CONFIG_DM_ETH
  105. void *fman_mdio(struct udevice *dev, enum fm_mac_type type, int num);
  106. #endif
  107. struct fsl_enet_mac {
  108. void *base; /* MAC controller registers base address */
  109. void *phyregs;
  110. int max_rx_len;
  111. void (*init_mac)(struct fsl_enet_mac *mac);
  112. void (*enable_mac)(struct fsl_enet_mac *mac);
  113. void (*disable_mac)(struct fsl_enet_mac *mac);
  114. void (*set_mac_addr)(struct fsl_enet_mac *mac, u8 *mac_addr);
  115. void (*set_if_mode)(struct fsl_enet_mac *mac, phy_interface_t type,
  116. int speed);
  117. };
  118. /* Fman ethernet private struct */
  119. struct fm_eth {
  120. int fm_index; /* Fman index */
  121. u32 num; /* 0..n-1 for give type */
  122. struct fm_bmi_tx_port *tx_port;
  123. struct fm_bmi_rx_port *rx_port;
  124. enum fm_eth_type type; /* 1G or 10G ethernet */
  125. phy_interface_t enet_if;
  126. struct fsl_enet_mac *mac; /* MAC controller */
  127. struct mii_dev *bus;
  128. struct phy_device *phydev;
  129. int phyaddr;
  130. #ifndef CONFIG_DM_ETH
  131. struct eth_device *dev;
  132. #else
  133. enum fm_mac_type mac_type;
  134. struct udevice *dev;
  135. struct udevice *pcs_mdio;
  136. #endif
  137. int max_rx_len;
  138. struct fm_port_global_pram *rx_pram; /* Rx parameter table */
  139. struct fm_port_global_pram *tx_pram; /* Tx parameter table */
  140. void *rx_bd_ring; /* Rx BD ring base */
  141. void *cur_rxbd; /* current Rx BD */
  142. void *rx_buf; /* Rx buffer base */
  143. void *tx_bd_ring; /* Tx BD ring base */
  144. void *cur_txbd; /* current Tx BD */
  145. };
  146. #define RX_BD_RING_SIZE 8
  147. #define TX_BD_RING_SIZE 8
  148. #define MAX_RXBUF_LOG2 11
  149. #define MAX_RXBUF_LEN (1 << MAX_RXBUF_LOG2)
  150. #define PORT_IS_ENABLED(port) (fm_port_to_index(port) == -1 ? \
  151. 0 : fm_info[fm_port_to_index(port)].enabled)
  152. #endif /* __FM_H__ */