nps_enet.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Copyright(c) 2015 EZchip Technologies.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. */
  16. #ifndef _NPS_ENET_H
  17. #define _NPS_ENET_H
  18. /* default values */
  19. #define NPS_ENET_NAPI_POLL_WEIGHT 0x2
  20. #define NPS_ENET_MAX_FRAME_LENGTH 0x3FFF
  21. #define NPS_ENET_GE_MAC_CFG_0_TX_FC_RETR 0x7
  22. #define NPS_ENET_GE_MAC_CFG_0_RX_IFG 0x5
  23. #define NPS_ENET_GE_MAC_CFG_0_TX_IFG 0xC
  24. #define NPS_ENET_GE_MAC_CFG_0_TX_PR_LEN 0x7
  25. #define NPS_ENET_GE_MAC_CFG_2_STAT_EN 0x3
  26. #define NPS_ENET_GE_MAC_CFG_3_RX_IFG_TH 0x14
  27. #define NPS_ENET_GE_MAC_CFG_3_MAX_LEN 0x3FFC
  28. #define NPS_ENET_ENABLE 1
  29. #define NPS_ENET_DISABLE 0
  30. /* register definitions */
  31. #define NPS_ENET_REG_TX_CTL 0x800
  32. #define NPS_ENET_REG_TX_BUF 0x808
  33. #define NPS_ENET_REG_RX_CTL 0x810
  34. #define NPS_ENET_REG_RX_BUF 0x818
  35. #define NPS_ENET_REG_BUF_INT_ENABLE 0x8C0
  36. #define NPS_ENET_REG_GE_MAC_CFG_0 0x1000
  37. #define NPS_ENET_REG_GE_MAC_CFG_1 0x1004
  38. #define NPS_ENET_REG_GE_MAC_CFG_2 0x1008
  39. #define NPS_ENET_REG_GE_MAC_CFG_3 0x100C
  40. #define NPS_ENET_REG_GE_RST 0x1400
  41. #define NPS_ENET_REG_PHASE_FIFO_CTL 0x1404
  42. /* Tx control register */
  43. struct nps_enet_tx_ctl {
  44. union {
  45. /* ct: SW sets to indicate frame ready in Tx buffer for
  46. * transmission. HW resets to when transmission done
  47. * et: Transmit error
  48. * nt: Length in bytes of Tx frame loaded to Tx buffer
  49. */
  50. struct {
  51. u32
  52. __reserved_1:16,
  53. ct:1,
  54. et:1,
  55. __reserved_2:3,
  56. nt:11;
  57. };
  58. u32 value;
  59. };
  60. };
  61. /* Rx control register */
  62. struct nps_enet_rx_ctl {
  63. union {
  64. /* cr: HW sets to indicate frame ready in Rx buffer.
  65. * SW resets to indicate host read received frame
  66. * and new frames can be written to Rx buffer
  67. * er: Rx error indication
  68. * crc: Rx CRC error indication
  69. * nr: Length in bytes of Rx frame loaded by MAC to Rx buffer
  70. */
  71. struct {
  72. u32
  73. __reserved_1:16,
  74. cr:1,
  75. er:1,
  76. crc:1,
  77. __reserved_2:2,
  78. nr:11;
  79. };
  80. u32 value;
  81. };
  82. };
  83. /* Interrupt enable for data buffer events register */
  84. struct nps_enet_buf_int_enable {
  85. union {
  86. /* tx_done: Interrupt generation in the case when new frame
  87. * is ready in Rx buffer
  88. * rx_rdy: Interrupt generation in the case when current frame
  89. * was read from TX buffer
  90. */
  91. struct {
  92. u32
  93. __reserved:30,
  94. tx_done:1,
  95. rx_rdy:1;
  96. };
  97. u32 value;
  98. };
  99. };
  100. /* Gbps Eth MAC Configuration 0 register */
  101. struct nps_enet_ge_mac_cfg_0 {
  102. union {
  103. /* tx_pr_len: Transmit preamble length in bytes
  104. * tx_ifg_nib: Tx idle pattern
  105. * nib_mode: Nibble (4-bit) Mode
  106. * rx_pr_check_en: Receive preamble Check Enable
  107. * tx_ifg: Transmit inter-Frame Gap
  108. * rx_ifg: Receive inter-Frame Gap
  109. * tx_fc_retr: Transmit Flow Control Retransmit Mode
  110. * rx_length_check_en: Receive Length Check Enable
  111. * rx_crc_ignore: Results of the CRC check are ignored
  112. * rx_crc_strip: MAC strips the CRC from received frames
  113. * rx_fc_en: Receive Flow Control Enable
  114. * tx_crc_en: Transmit CRC Enabled
  115. * tx_pad_en: Transmit Padding Enable
  116. * tx_cf_en: Transmit Flow Control Enable
  117. * tx_en: Transmit Enable
  118. * rx_en: Receive Enable
  119. */
  120. struct {
  121. u32
  122. tx_pr_len:4,
  123. tx_ifg_nib:4,
  124. nib_mode:1,
  125. rx_pr_check_en:1,
  126. tx_ifg:6,
  127. rx_ifg:4,
  128. tx_fc_retr:3,
  129. rx_length_check_en:1,
  130. rx_crc_ignore:1,
  131. rx_crc_strip:1,
  132. rx_fc_en:1,
  133. tx_crc_en:1,
  134. tx_pad_en:1,
  135. tx_fc_en:1,
  136. tx_en:1,
  137. rx_en:1;
  138. };
  139. u32 value;
  140. };
  141. };
  142. /* Gbps Eth MAC Configuration 1 register */
  143. struct nps_enet_ge_mac_cfg_1 {
  144. union {
  145. /* octet_3: MAC address octet 3
  146. * octet_2: MAC address octet 2
  147. * octet_1: MAC address octet 1
  148. * octet_0: MAC address octet 0
  149. */
  150. struct {
  151. u32
  152. octet_3:8,
  153. octet_2:8,
  154. octet_1:8,
  155. octet_0:8;
  156. };
  157. u32 value;
  158. };
  159. };
  160. /* Gbps Eth MAC Configuration 2 register */
  161. struct nps_enet_ge_mac_cfg_2 {
  162. union {
  163. /* transmit_flush_en: MAC flush enable
  164. * stat_en: RMON statistics interface enable
  165. * disc_da: Discard frames with DA different
  166. * from MAC address
  167. * disc_bc: Discard broadcast frames
  168. * disc_mc: Discard multicast frames
  169. * octet_5: MAC address octet 5
  170. * octet_4: MAC address octet 4
  171. */
  172. struct {
  173. u32
  174. transmit_flush_en:1,
  175. __reserved_1:5,
  176. stat_en:2,
  177. __reserved_2:1,
  178. disc_da:1,
  179. disc_bc:1,
  180. disc_mc:1,
  181. __reserved_3:4,
  182. octet_5:8,
  183. octet_4:8;
  184. };
  185. u32 value;
  186. };
  187. };
  188. /* Gbps Eth MAC Configuration 3 register */
  189. struct nps_enet_ge_mac_cfg_3 {
  190. union {
  191. /* ext_oob_cbfc_sel: Selects one of the 4 profiles for
  192. * extended OOB in-flow-control indication
  193. * max_len: Maximum receive frame length in bytes
  194. * tx_cbfc_en: Enable transmission of class-based
  195. * flow control packets
  196. * rx_ifg_th: Threshold for IFG status reporting via OOB
  197. * cf_timeout: Configurable time to decrement FC counters
  198. * cf_drop: Drop control frames
  199. * redirect_cbfc_sel: Selects one of CBFC redirect profiles
  200. * rx_cbfc_redir_en: Enable Rx class-based flow
  201. * control redirect
  202. * rx_cbfc_en: Enable Rx class-based flow control
  203. * tm_hd_mode: TM header mode
  204. */
  205. struct {
  206. u32
  207. ext_oob_cbfc_sel:2,
  208. max_len:14,
  209. tx_cbfc_en:1,
  210. rx_ifg_th:5,
  211. cf_timeout:4,
  212. cf_drop:1,
  213. redirect_cbfc_sel:2,
  214. rx_cbfc_redir_en:1,
  215. rx_cbfc_en:1,
  216. tm_hd_mode:1;
  217. };
  218. u32 value;
  219. };
  220. };
  221. /* GE MAC, PCS reset control register */
  222. struct nps_enet_ge_rst {
  223. union {
  224. /* gmac_0: GE MAC reset
  225. * spcs_0: SGMII PCS reset
  226. */
  227. struct {
  228. u32
  229. __reserved_1:23,
  230. gmac_0:1,
  231. __reserved_2:7,
  232. spcs_0:1;
  233. };
  234. u32 value;
  235. };
  236. };
  237. /* Tx phase sync FIFO control register */
  238. struct nps_enet_phase_fifo_ctl {
  239. union {
  240. /* init: initialize serdes TX phase sync FIFO pointers
  241. * rst: reset serdes TX phase sync FIFO
  242. */
  243. struct {
  244. u32
  245. __reserved:30,
  246. init:1,
  247. rst:1;
  248. };
  249. u32 value;
  250. };
  251. };
  252. /**
  253. * struct nps_enet_priv - Storage of ENET's private information.
  254. * @regs_base: Base address of ENET memory-mapped control registers.
  255. * @irq: For RX/TX IRQ number.
  256. * @tx_packet_sent: SW indication if frame is being sent.
  257. * @tx_skb: socket buffer of sent frame.
  258. * @napi: Structure for NAPI.
  259. */
  260. struct nps_enet_priv {
  261. void __iomem *regs_base;
  262. s32 irq;
  263. bool tx_packet_sent;
  264. struct sk_buff *tx_skb;
  265. struct napi_struct napi;
  266. struct nps_enet_ge_mac_cfg_2 ge_mac_cfg_2;
  267. struct nps_enet_ge_mac_cfg_3 ge_mac_cfg_3;
  268. };
  269. /**
  270. * nps_reg_set - Sets ENET register with provided value.
  271. * @priv: Pointer to EZchip ENET private data structure.
  272. * @reg: Register offset from base address.
  273. * @value: Value to set in register.
  274. */
  275. static inline void nps_enet_reg_set(struct nps_enet_priv *priv,
  276. s32 reg, s32 value)
  277. {
  278. iowrite32be(value, priv->regs_base + reg);
  279. }
  280. /**
  281. * nps_reg_get - Gets value of specified ENET register.
  282. * @priv: Pointer to EZchip ENET private data structure.
  283. * @reg: Register offset from base address.
  284. *
  285. * returns: Value of requested register.
  286. */
  287. static inline u32 nps_enet_reg_get(struct nps_enet_priv *priv, s32 reg)
  288. {
  289. return ioread32be(priv->regs_base + reg);
  290. }
  291. #endif /* _NPS_ENET_H */