fman_mac.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright 2008-2015 Freescale Semiconductor Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of Freescale Semiconductor nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. *
  16. * ALTERNATIVELY, this software may be distributed under the terms of the
  17. * GNU General Public License ("GPL") as published by the Free Software
  18. * Foundation, either version 2 of that License or (at your option) any
  19. * later version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  22. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  25. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  28. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /* FM MAC ... */
  33. #ifndef __FM_MAC_H
  34. #define __FM_MAC_H
  35. #include "fman.h"
  36. #include <linux/slab.h>
  37. #include <linux/phy.h>
  38. #include <linux/if_ether.h>
  39. struct fman_mac;
  40. /* Ethernet Address */
  41. typedef u8 enet_addr_t[ETH_ALEN];
  42. #define ENET_ADDR_TO_UINT64(_enet_addr) \
  43. (u64)(((u64)(_enet_addr)[0] << 40) | \
  44. ((u64)(_enet_addr)[1] << 32) | \
  45. ((u64)(_enet_addr)[2] << 24) | \
  46. ((u64)(_enet_addr)[3] << 16) | \
  47. ((u64)(_enet_addr)[4] << 8) | \
  48. ((u64)(_enet_addr)[5]))
  49. #define MAKE_ENET_ADDR_FROM_UINT64(_addr64, _enet_addr) \
  50. do { \
  51. int i; \
  52. for (i = 0; i < ETH_ALEN; i++) \
  53. (_enet_addr)[i] = \
  54. (u8)((_addr64) >> ((5 - i) * 8)); \
  55. } while (0)
  56. /* defaults */
  57. #define DEFAULT_RESET_ON_INIT false
  58. /* PFC defines */
  59. #define FSL_FM_PAUSE_TIME_ENABLE 0xf000
  60. #define FSL_FM_PAUSE_TIME_DISABLE 0
  61. #define FSL_FM_PAUSE_THRESH_DEFAULT 0
  62. #define FM_MAC_NO_PFC 0xff
  63. /* HASH defines */
  64. #define ETH_HASH_ENTRY_OBJ(ptr) \
  65. hlist_entry_safe(ptr, struct eth_hash_entry, node)
  66. /* Enumeration (bit flags) of communication modes (Transmit,
  67. * receive or both).
  68. */
  69. enum comm_mode {
  70. COMM_MODE_NONE = 0, /* No transmit/receive communication */
  71. COMM_MODE_RX = 1, /* Only receive communication */
  72. COMM_MODE_TX = 2, /* Only transmit communication */
  73. COMM_MODE_RX_AND_TX = 3 /* Both transmit and receive communication */
  74. };
  75. /* FM MAC Exceptions */
  76. enum fman_mac_exceptions {
  77. FM_MAC_EX_10G_MDIO_SCAN_EVENT = 0
  78. /* 10GEC MDIO scan event interrupt */
  79. , FM_MAC_EX_10G_MDIO_CMD_CMPL
  80. /* 10GEC MDIO command completion interrupt */
  81. , FM_MAC_EX_10G_REM_FAULT
  82. /* 10GEC, mEMAC Remote fault interrupt */
  83. , FM_MAC_EX_10G_LOC_FAULT
  84. /* 10GEC, mEMAC Local fault interrupt */
  85. , FM_MAC_EX_10G_TX_ECC_ER
  86. /* 10GEC, mEMAC Transmit frame ECC error interrupt */
  87. , FM_MAC_EX_10G_TX_FIFO_UNFL
  88. /* 10GEC, mEMAC Transmit FIFO underflow interrupt */
  89. , FM_MAC_EX_10G_TX_FIFO_OVFL
  90. /* 10GEC, mEMAC Transmit FIFO overflow interrupt */
  91. , FM_MAC_EX_10G_TX_ER
  92. /* 10GEC Transmit frame error interrupt */
  93. , FM_MAC_EX_10G_RX_FIFO_OVFL
  94. /* 10GEC, mEMAC Receive FIFO overflow interrupt */
  95. , FM_MAC_EX_10G_RX_ECC_ER
  96. /* 10GEC, mEMAC Receive frame ECC error interrupt */
  97. , FM_MAC_EX_10G_RX_JAB_FRM
  98. /* 10GEC Receive jabber frame interrupt */
  99. , FM_MAC_EX_10G_RX_OVRSZ_FRM
  100. /* 10GEC Receive oversized frame interrupt */
  101. , FM_MAC_EX_10G_RX_RUNT_FRM
  102. /* 10GEC Receive runt frame interrupt */
  103. , FM_MAC_EX_10G_RX_FRAG_FRM
  104. /* 10GEC Receive fragment frame interrupt */
  105. , FM_MAC_EX_10G_RX_LEN_ER
  106. /* 10GEC Receive payload length error interrupt */
  107. , FM_MAC_EX_10G_RX_CRC_ER
  108. /* 10GEC Receive CRC error interrupt */
  109. , FM_MAC_EX_10G_RX_ALIGN_ER
  110. /* 10GEC Receive alignment error interrupt */
  111. , FM_MAC_EX_1G_BAB_RX
  112. /* dTSEC Babbling receive error */
  113. , FM_MAC_EX_1G_RX_CTL
  114. /* dTSEC Receive control (pause frame) interrupt */
  115. , FM_MAC_EX_1G_GRATEFUL_TX_STP_COMPLET
  116. /* dTSEC Graceful transmit stop complete */
  117. , FM_MAC_EX_1G_BAB_TX
  118. /* dTSEC Babbling transmit error */
  119. , FM_MAC_EX_1G_TX_CTL
  120. /* dTSEC Transmit control (pause frame) interrupt */
  121. , FM_MAC_EX_1G_TX_ERR
  122. /* dTSEC Transmit error */
  123. , FM_MAC_EX_1G_LATE_COL
  124. /* dTSEC Late collision */
  125. , FM_MAC_EX_1G_COL_RET_LMT
  126. /* dTSEC Collision retry limit */
  127. , FM_MAC_EX_1G_TX_FIFO_UNDRN
  128. /* dTSEC Transmit FIFO underrun */
  129. , FM_MAC_EX_1G_MAG_PCKT
  130. /* dTSEC Magic Packet detection */
  131. , FM_MAC_EX_1G_MII_MNG_RD_COMPLET
  132. /* dTSEC MII management read completion */
  133. , FM_MAC_EX_1G_MII_MNG_WR_COMPLET
  134. /* dTSEC MII management write completion */
  135. , FM_MAC_EX_1G_GRATEFUL_RX_STP_COMPLET
  136. /* dTSEC Graceful receive stop complete */
  137. , FM_MAC_EX_1G_DATA_ERR
  138. /* dTSEC Internal data error on transmit */
  139. , FM_MAC_1G_RX_DATA_ERR
  140. /* dTSEC Internal data error on receive */
  141. , FM_MAC_EX_1G_1588_TS_RX_ERR
  142. /* dTSEC Time-Stamp Receive Error */
  143. , FM_MAC_EX_1G_RX_MIB_CNT_OVFL
  144. /* dTSEC MIB counter overflow */
  145. , FM_MAC_EX_TS_FIFO_ECC_ERR
  146. /* mEMAC Time-stamp FIFO ECC error interrupt;
  147. * not supported on T4240/B4860 rev1 chips
  148. */
  149. , FM_MAC_EX_MAGIC_PACKET_INDICATION = FM_MAC_EX_1G_MAG_PCKT
  150. /* mEMAC Magic Packet Indication Interrupt */
  151. };
  152. struct eth_hash_entry {
  153. u64 addr; /* Ethernet Address */
  154. struct list_head node;
  155. };
  156. typedef void (fman_mac_exception_cb)(void *dev_id,
  157. enum fman_mac_exceptions exceptions);
  158. /* FMan MAC config input */
  159. struct fman_mac_params {
  160. /* Base of memory mapped FM MAC registers */
  161. void __iomem *base_addr;
  162. /* MAC address of device; First octet is sent first */
  163. enet_addr_t addr;
  164. /* MAC ID; numbering of dTSEC and 1G-mEMAC:
  165. * 0 - FM_MAX_NUM_OF_1G_MACS;
  166. * numbering of 10G-MAC (TGEC) and 10G-mEMAC:
  167. * 0 - FM_MAX_NUM_OF_10G_MACS
  168. */
  169. u8 mac_id;
  170. /* PHY interface */
  171. phy_interface_t phy_if;
  172. /* Note that the speed should indicate the maximum rate that
  173. * this MAC should support rather than the actual speed;
  174. */
  175. u16 max_speed;
  176. /* A handle to the FM object this port related to */
  177. void *fm;
  178. void *dev_id; /* device cookie used by the exception cbs */
  179. fman_mac_exception_cb *event_cb; /* MDIO Events Callback Routine */
  180. fman_mac_exception_cb *exception_cb;/* Exception Callback Routine */
  181. /* SGMII/QSGII interface with 1000BaseX auto-negotiation between MAC
  182. * and phy or backplane; Note: 1000BaseX auto-negotiation relates only
  183. * to interface between MAC and phy/backplane, SGMII phy can still
  184. * synchronize with far-end phy at 10Mbps, 100Mbps or 1000Mbps
  185. */
  186. bool basex_if;
  187. /* Pointer to TBI/PCS PHY node, used for TBI/PCS PHY access */
  188. struct device_node *internal_phy_node;
  189. };
  190. struct eth_hash_t {
  191. u16 size;
  192. struct list_head *lsts;
  193. };
  194. static inline struct eth_hash_entry
  195. *dequeue_addr_from_hash_entry(struct list_head *addr_lst)
  196. {
  197. struct eth_hash_entry *hash_entry = NULL;
  198. if (!list_empty(addr_lst)) {
  199. hash_entry = ETH_HASH_ENTRY_OBJ(addr_lst->next);
  200. list_del_init(&hash_entry->node);
  201. }
  202. return hash_entry;
  203. }
  204. static inline void free_hash_table(struct eth_hash_t *hash)
  205. {
  206. struct eth_hash_entry *hash_entry;
  207. int i = 0;
  208. if (hash) {
  209. if (hash->lsts) {
  210. for (i = 0; i < hash->size; i++) {
  211. hash_entry =
  212. dequeue_addr_from_hash_entry(&hash->lsts[i]);
  213. while (hash_entry) {
  214. kfree(hash_entry);
  215. hash_entry =
  216. dequeue_addr_from_hash_entry(&hash->
  217. lsts[i]);
  218. }
  219. }
  220. kfree(hash->lsts);
  221. }
  222. kfree(hash);
  223. }
  224. }
  225. static inline struct eth_hash_t *alloc_hash_table(u16 size)
  226. {
  227. u32 i;
  228. struct eth_hash_t *hash;
  229. /* Allocate address hash table */
  230. hash = kmalloc_array(size, sizeof(struct eth_hash_t *), GFP_KERNEL);
  231. if (!hash)
  232. return NULL;
  233. hash->size = size;
  234. hash->lsts = kmalloc_array(hash->size, sizeof(struct list_head),
  235. GFP_KERNEL);
  236. if (!hash->lsts) {
  237. kfree(hash);
  238. return NULL;
  239. }
  240. for (i = 0; i < hash->size; i++)
  241. INIT_LIST_HEAD(&hash->lsts[i]);
  242. return hash;
  243. }
  244. #endif /* __FM_MAC_H */