fm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #ifndef __FM_H__
  20. #define __FM_H__
  21. #include <common.h>
  22. #include <fm_eth.h>
  23. #include <asm/fsl_enet.h>
  24. #include <asm/fsl_fman.h>
  25. /* Port ID */
  26. #define OH_PORT_ID_BASE 0x01
  27. #define MAX_NUM_OH_PORT 7
  28. #define RX_PORT_1G_BASE 0x08
  29. #define MAX_NUM_RX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
  30. #define RX_PORT_10G_BASE 0x10
  31. #define TX_PORT_1G_BASE 0x28
  32. #define MAX_NUM_TX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
  33. #define TX_PORT_10G_BASE 0x30
  34. struct fm_muram {
  35. u32 base;
  36. u32 top;
  37. u32 size;
  38. u32 alloc;
  39. };
  40. #define FM_MURAM_RES_SIZE 0x01000
  41. /* Rx/Tx buffer descriptor */
  42. struct fm_port_bd {
  43. u16 status;
  44. u16 len;
  45. u32 res0;
  46. u16 res1;
  47. u16 buf_ptr_hi;
  48. u32 buf_ptr_lo;
  49. };
  50. /* Common BD flags */
  51. #define BD_LAST 0x0800
  52. /* Rx BD status flags */
  53. #define RxBD_EMPTY 0x8000
  54. #define RxBD_LAST BD_LAST
  55. #define RxBD_FIRST 0x0400
  56. #define RxBD_PHYS_ERR 0x0008
  57. #define RxBD_SIZE_ERR 0x0004
  58. #define RxBD_ERROR (RxBD_PHYS_ERR | RxBD_SIZE_ERR)
  59. /* Tx BD status flags */
  60. #define TxBD_READY 0x8000
  61. #define TxBD_LAST BD_LAST
  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_P1017) || defined(CONFIG_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. u32 fm_muram_alloc(int fm_idx, u32 size, u32 align);
  96. u32 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. struct fsl_enet_mac {
  102. void *base; /* MAC controller registers base address */
  103. void *phyregs;
  104. int max_rx_len;
  105. void (*init_mac)(struct fsl_enet_mac *mac);
  106. void (*enable_mac)(struct fsl_enet_mac *mac);
  107. void (*disable_mac)(struct fsl_enet_mac *mac);
  108. void (*set_mac_addr)(struct fsl_enet_mac *mac, u8 *mac_addr);
  109. void (*set_if_mode)(struct fsl_enet_mac *mac, phy_interface_t type,
  110. int speed);
  111. };
  112. /* Fman ethernet private struct */
  113. struct fm_eth {
  114. int fm_index; /* Fman index */
  115. u32 num; /* 0..n-1 for give type */
  116. struct fm_bmi_tx_port *tx_port;
  117. struct fm_bmi_rx_port *rx_port;
  118. enum fm_eth_type type; /* 1G or 10G ethernet */
  119. phy_interface_t enet_if;
  120. struct fsl_enet_mac *mac; /* MAC controller */
  121. struct mii_dev *bus;
  122. struct phy_device *phydev;
  123. int phyaddr;
  124. struct eth_device *dev;
  125. int max_rx_len;
  126. struct fm_port_global_pram *rx_pram; /* Rx parameter table */
  127. struct fm_port_global_pram *tx_pram; /* Tx parameter table */
  128. void *rx_bd_ring; /* Rx BD ring base */
  129. void *cur_rxbd; /* current Rx BD */
  130. void *rx_buf; /* Rx buffer base */
  131. void *tx_bd_ring; /* Tx BD ring base */
  132. void *cur_txbd; /* current Tx BD */
  133. };
  134. #define RX_BD_RING_SIZE 8
  135. #define TX_BD_RING_SIZE 8
  136. #define MAX_RXBUF_LOG2 11
  137. #define MAX_RXBUF_LEN (1 << MAX_RXBUF_LOG2)
  138. #define PORT_IS_ENABLED(port) fm_info[fm_port_to_index(port)].enabled
  139. #endif /* __FM_H__ */