cortina_ni.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2020 Cortina Access Inc.
  4. * Author: Aaron Tseng <aaron.tseng@cortina-access.com>
  5. *
  6. * Ethernet MAC Driver for all supported CAxxxx SoCs
  7. */
  8. #ifndef __CORTINA_NI_H
  9. #define __CORTINA_NI_H
  10. #include <asm/types.h>
  11. #include <asm/io.h>
  12. #include <config.h>
  13. #define GE_MAC_INTF_GMII 0x0
  14. #define GE_MAC_INTF_MII 0x1
  15. #define GE_MAC_INTF_RGMII_1000 0x2
  16. #define GE_MAC_INTF_RGMII_100 0x3
  17. /* Defines the base and top address in CPU XRA
  18. * for packets to cpu instance 0
  19. * 0x300 * 8-byte = 6K-byte
  20. */
  21. #define RX_TOP_ADDR 0x02FF
  22. #define RX_BASE_ADDR 0x0000
  23. /* Defines the base and top address in CPU XRAM
  24. * for packets from cpu instance 0.
  25. * 0x100 * 8-byte = 2K-byte
  26. */
  27. #define TX_TOP_ADDR 0x03FF
  28. #define TX_BASE_ADDR 0x0300
  29. struct port_map_s {
  30. u32 phy_addr;
  31. u32 port;
  32. };
  33. struct gphy_cal_s {
  34. u32 reg_off;
  35. u32 value;
  36. };
  37. #if !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
  38. struct cortina_ni_priv {
  39. u32 ni_xram_base;
  40. u32 rx_xram_base_adr;
  41. u32 rx_xram_end_adr;
  42. u16 rx_xram_start;
  43. u16 rx_xram_end;
  44. u32 tx_xram_base_adr;
  45. u32 tx_xram_end_adr;
  46. u16 tx_xram_start;
  47. u16 tx_xram_end;
  48. u32 valid_port_map;
  49. u32 valid_port_num;
  50. u32 init_rgmii;
  51. u32 gphy_num;
  52. struct port_map_s port_map[5];
  53. struct gphy_cal_s gphy_values[10];
  54. void __iomem *glb_base_addr;
  55. void __iomem *per_mdio_base_addr;
  56. void __iomem *ni_hv_base_addr;
  57. struct mii_dev *mdio_bus;
  58. struct phy_device *phydev;
  59. int phy_interface;
  60. int active_port;
  61. };
  62. struct NI_HEADER_X_T {
  63. u32 next_link : 10; /* bits 9: 0 */
  64. u32 bytes_valid : 4; /* bits 13:10 */
  65. u32 reserved : 16; /* bits 29:14 */
  66. u32 hdr_a : 1; /* bits 30:30 */
  67. u32 ownership : 1; /* bits 31:31 */
  68. };
  69. struct NI_PACKET_STATUS {
  70. u32 packet_size : 14; /* bits 13:0 */
  71. u32 byte_valid : 4; /* bits 17:14 */
  72. u32 pfc : 1; /* bits 18:18 */
  73. u32 valid : 1; /* bits 19:19 */
  74. u32 drop : 1; /* bits 20:20 */
  75. u32 runt : 1; /* bits 21:21 */
  76. u32 oversize : 1; /* bits 22:22 */
  77. u32 jumbo : 1; /* bits 23:23 */
  78. u32 link_status : 1; /* bits 24:24 */
  79. u32 jabber : 1; /* bits 25:25 */
  80. u32 crc_error : 1; /* bits 26:26 */
  81. u32 pause : 1; /* bits 27:27 */
  82. u32 oam : 1; /* bits 28:28 */
  83. u32 unknown_opcode : 1; /* bits 29:29 */
  84. u32 multicast : 1; /* bits 30:30 */
  85. u32 broadcast : 1; /* bits 31:31 */
  86. };
  87. struct NI_MDIO_OPER_T {
  88. u32 reserved : 2; /* bits 1:0 */
  89. u32 reg_off : 5; /* bits 6:2 */
  90. u32 phy_addr : 5; /* bits 11:7 */
  91. u32 reg_base : 20; /* bits 31:12 */
  92. };
  93. #define __MDIO_WR_FLAG (0)
  94. #define __MDIO_RD_FLAG (1)
  95. #define __MDIO_ACCESS_TIMEOUT (1000000)
  96. #define CA_MDIO_ADDR_MIN (1)
  97. #define CA_MDIO_ADDR_MAX (31)
  98. #endif /* !__ASSEMBLER__ */
  99. /* HW REG */
  100. struct NI_HV_GLB_MAC_ADDR_CFG0_t {
  101. u32 mac_addr0 : 32; /* bits 31:0 */
  102. };
  103. struct NI_HV_GLB_MAC_ADDR_CFG1_t {
  104. u32 mac_addr1 : 8; /* bits 7:0 */
  105. u32 rsrvd1 : 24;
  106. };
  107. struct NI_HV_PT_PORT_STATIC_CFG_t {
  108. u32 int_cfg : 4; /* bits 3:0 */
  109. u32 phy_mode : 1; /* bits 4:4 */
  110. u32 rmii_clksrc : 1; /* bits 5:5 */
  111. u32 inv_clk_in : 1; /* bits 6:6 */
  112. u32 inv_clk_out : 1; /* bits 7:7 */
  113. u32 inv_rxclk_out : 1; /* bits 8:8 */
  114. u32 tx_use_gefifo : 1; /* bits 9:9 */
  115. u32 smii_tx_stat : 1; /* bits 10:10 */
  116. u32 crs_polarity : 1; /* bits 11:11 */
  117. u32 lpbk_mode : 2; /* bits 13:12 */
  118. u32 gmii_like_half_duplex_en : 1; /* bits 14:14 */
  119. u32 sup_tx_to_rx_lpbk_data : 1; /* bits 15:15 */
  120. u32 rsrvd1 : 8;
  121. u32 mac_addr6 : 8; /* bits 31:24 */
  122. };
  123. struct NI_HV_XRAM_CPUXRAM_CFG_t {
  124. u32 rx_0_cpu_pkt_dis : 1; /* bits 0:0 */
  125. u32 rsrvd1 : 8;
  126. u32 tx_0_cpu_pkt_dis : 1; /* bits 9:9 */
  127. u32 rsrvd2 : 1;
  128. u32 rx_x_drop_err_pkt : 1; /* bits 11:11 */
  129. u32 xram_mgmt_dis_drop_ovsz_pkt : 1; /* bits 12:12 */
  130. u32 xram_mgmt_term_large_pkt : 1; /* bits 13:13 */
  131. u32 xram_mgmt_promisc_mode : 2; /* bits 15:14 */
  132. u32 xram_cntr_debug_mode : 1; /* bits 16:16 */
  133. u32 xram_cntr_op_code : 2; /* bits 18:17 */
  134. u32 rsrvd3 : 2;
  135. u32 xram_rx_mgmtfifo_srst : 1; /* bits 21:21 */
  136. u32 xram_dma_fifo_srst : 1; /* bits 22:22 */
  137. u32 rsrvd4 : 9;
  138. };
  139. struct NI_HV_PT_RXMAC_CFG_t {
  140. u32 rx_en : 1; /* bits 0:0 */
  141. u32 rsrvd1 : 7;
  142. u32 rx_flow_disable : 1; /* bits 8:8 */
  143. u32 rsrvd2 : 3;
  144. u32 rx_flow_to_tx_en : 1; /* bits 12:12 */
  145. u32 rx_pfc_disable : 1; /* bits 13:13 */
  146. u32 rsrvd3 : 15;
  147. u32 send_pg_data : 1; /* bits 29:29 */
  148. u32 rsrvd4 : 2;
  149. };
  150. struct NI_HV_PT_TXMAC_CFG_t {
  151. u32 tx_en : 1; /* bits 0:0 */
  152. u32 rsrvd1 : 7;
  153. u32 mac_crc_calc_en : 1; /* bits 8:8 */
  154. u32 tx_ipg_sel : 3; /* bits 11:9 */
  155. u32 tx_flow_disable : 1; /* bits 12:12 */
  156. u32 tx_drain : 1; /* bits 13:13 */
  157. u32 tx_pfc_disable : 1; /* bits 14:14 */
  158. u32 tx_pau_sel : 2; /* bits 16:15 */
  159. u32 rsrvd2 : 9;
  160. u32 tx_auto_xon : 1; /* bits 26:26 */
  161. u32 rsrvd3 : 1;
  162. u32 pass_thru_hdr : 1; /* bits 28:28 */
  163. u32 rsrvd4 : 3;
  164. };
  165. struct NI_HV_GLB_INTF_RST_CONFIG_t {
  166. u32 intf_rst_p0 : 1; /* bits 0:0 */
  167. u32 intf_rst_p1 : 1; /* bits 1:1 */
  168. u32 intf_rst_p2 : 1; /* bits 2:2 */
  169. u32 intf_rst_p3 : 1; /* bits 3:3 */
  170. u32 intf_rst_p4 : 1; /* bits 4:4 */
  171. u32 mac_rx_rst_p0 : 1; /* bits 5:5 */
  172. u32 mac_rx_rst_p1 : 1; /* bits 6:6 */
  173. u32 mac_rx_rst_p2 : 1; /* bits 7:7 */
  174. u32 mac_rx_rst_p3 : 1; /* bits 8:8 */
  175. u32 mac_rx_rst_p4 : 1; /* bits 9:9 */
  176. u32 mac_tx_rst_p0 : 1; /* bits 10:10 */
  177. u32 mac_tx_rst_p1 : 1; /* bits 11:11 */
  178. u32 mac_tx_rst_p2 : 1; /* bits 12:12 */
  179. u32 mac_tx_rst_p3 : 1; /* bits 13:13 */
  180. u32 mac_tx_rst_p4 : 1; /* bits 14:14 */
  181. u32 port_rst_p5 : 1; /* bits 15:15 */
  182. u32 pcs_rst_p6 : 1; /* bits 16:16 */
  183. u32 pcs_rst_p7 : 1; /* bits 17:17 */
  184. u32 mac_rst_p6 : 1; /* bits 18:18 */
  185. u32 mac_rst_p7 : 1; /* bits 19:19 */
  186. u32 rsrvd1 : 12;
  187. };
  188. struct NI_HV_GLB_STATIC_CFG_t {
  189. u32 port_to_cpu : 4; /* bits 3:0 */
  190. u32 mgmt_pt_to_fe_also : 1; /* bits 4:4 */
  191. u32 txcrc_chk_en : 1; /* bits 5:5 */
  192. u32 p4_rgmii_tx_clk_phase : 2; /* bits 7:6 */
  193. u32 p4_rgmii_tx_data_order : 1; /* bits 8:8 */
  194. u32 rsrvd1 : 7;
  195. u32 rxmib_mode : 1; /* bits 16:16 */
  196. u32 txmib_mode : 1; /* bits 17:17 */
  197. u32 eth_sch_rdy_pkt : 1; /* bits 18:18 */
  198. u32 rsrvd2 : 1;
  199. u32 rxaui_mode : 2; /* bits 21:20 */
  200. u32 rxaui_sigdet : 2; /* bits 23:22 */
  201. u32 cnt_op_mode : 3; /* bits 26:24 */
  202. u32 rsrvd3 : 5;
  203. };
  204. struct GLOBAL_BLOCK_RESET_t {
  205. u32 reset_ni : 1; /* bits 0:0 */
  206. u32 reset_l2fe : 1; /* bits 1:1 */
  207. u32 reset_l2tm : 1; /* bits 2:2 */
  208. u32 reset_l3fe : 1; /* bits 3:3 */
  209. u32 reset_sdram : 1; /* bits 4:4 */
  210. u32 reset_tqm : 1; /* bits 5:5 */
  211. u32 reset_pcie0 : 1; /* bits 6:6 */
  212. u32 reset_pcie1 : 1; /* bits 7:7 */
  213. u32 reset_pcie2 : 1; /* bits 8:8 */
  214. u32 reset_sata : 1; /* bits 9:9 */
  215. u32 reset_gic400 : 1; /* bits 10:10 */
  216. u32 rsrvd1 : 2;
  217. u32 reset_usb : 1; /* bits 13:13 */
  218. u32 reset_flash : 1; /* bits 14:14 */
  219. u32 reset_per : 1; /* bits 15:15 */
  220. u32 reset_dma : 1; /* bits 16:16 */
  221. u32 reset_rtc : 1; /* bits 17:17 */
  222. u32 reset_pe0 : 1; /* bits 18:18 */
  223. u32 reset_pe1 : 1; /* bits 19:19 */
  224. u32 reset_rcpu0 : 1; /* bits 20:20 */
  225. u32 reset_rcpu1 : 1; /* bits 21:21 */
  226. u32 reset_sadb : 1; /* bits 22:22 */
  227. u32 rsrvd2 : 1;
  228. u32 reset_rcrypto : 1; /* bits 24:24 */
  229. u32 reset_ldma : 1; /* bits 25:25 */
  230. u32 reset_fbm : 1; /* bits 26:26 */
  231. u32 reset_eaxi : 1; /* bits 27:27 */
  232. u32 reset_sd : 1; /* bits 28:28 */
  233. u32 reset_otprom : 1; /* bits 29:29 */
  234. u32 rsrvd3 : 2;
  235. };
  236. struct PER_MDIO_ADDR_t {
  237. u32 mdio_addr : 5; /* bits 4:0 */
  238. u32 rsrvd1 : 3;
  239. u32 mdio_offset : 5; /* bits 12:8 */
  240. u32 rsrvd2 : 2;
  241. u32 mdio_rd_wr : 1; /* bits 15:15 */
  242. u32 mdio_st : 1; /* bits 16:16 */
  243. u32 rsrvd3 : 1;
  244. u32 mdio_op : 2; /* bits 19:18 */
  245. u32 rsrvd4 : 12;
  246. };
  247. struct PER_MDIO_CTRL_t {
  248. u32 mdiodone : 1; /* bits 0:0 */
  249. u32 rsrvd1 : 6;
  250. u32 mdiostart : 1; /* bits 7:7 */
  251. u32 rsrvd2 : 24;
  252. };
  253. struct PER_MDIO_RDDATA_t {
  254. u32 mdio_rddata : 16; /* bits 15:0 */
  255. u32 rsrvd1 : 16;
  256. };
  257. /* XRAM */
  258. struct NI_HV_XRAM_CPUXRAM_ADRCFG_RX_t {
  259. u32 rx_base_addr : 10; /* bits 9:0 */
  260. u32 rsrvd1 : 6;
  261. u32 rx_top_addr : 10; /* bits 25:16 */
  262. u32 rsrvd2 : 6;
  263. };
  264. struct NI_HV_XRAM_CPUXRAM_ADRCFG_TX_0_t {
  265. u32 tx_base_addr : 10; /* bits 9:0 */
  266. u32 rsrvd1 : 6;
  267. u32 tx_top_addr : 10; /* bits 25:16 */
  268. u32 rsrvd2 : 6;
  269. };
  270. struct NI_HV_XRAM_CPUXRAM_CPU_STA_RX_0_t {
  271. u32 pkt_wr_ptr : 10; /* bits 9:0 */
  272. u32 rsrvd1 : 5;
  273. u32 int_colsc_thresh_reached : 1; /* bits 15:15 */
  274. u32 rsrvd2 : 16;
  275. };
  276. struct NI_HV_XRAM_CPUXRAM_CPU_CFG_RX_0_t {
  277. u32 pkt_rd_ptr : 10; /* bits 9:0 */
  278. u32 rsrvd1 : 22;
  279. };
  280. struct NI_HV_XRAM_CPUXRAM_CPU_CFG_TX_0_t {
  281. u32 pkt_wr_ptr : 10; /* bits 9:0 */
  282. u32 rsrvd1 : 22;
  283. };
  284. struct GLOBAL_GLOBAL_CONFIG_t {
  285. u32 rsrvd1 : 4;
  286. u32 wd_reset_subsys_enable : 1; /* bits 4:4 */
  287. u32 rsrvd2 : 1;
  288. u32 wd_reset_all_blocks : 1; /* bits 6:6 */
  289. u32 wd_reset_remap : 1; /* bits 7:7 */
  290. u32 wd_reset_ext_reset : 1; /* bits 8:8 */
  291. u32 ext_reset : 1; /* bits 9:9 */
  292. u32 cfg_pcie_0_clken : 1; /* bits 10:10 */
  293. u32 cfg_sata_clken : 1; /* bits 11:11 */
  294. u32 cfg_pcie_1_clken : 1; /* bits 12:12 */
  295. u32 rsrvd3 : 1;
  296. u32 cfg_pcie_2_clken : 1; /* bits 14:14 */
  297. u32 rsrvd4 : 2;
  298. u32 ext_eth_refclk : 1; /* bits 17:17 */
  299. u32 refclk_sel : 2; /* bits 19:18 */
  300. u32 rsrvd5 : 7;
  301. u32 l3fe_pd : 1; /* bits 27:27 */
  302. u32 offload0_pd : 1; /* bits 28:28 */
  303. u32 offload1_pd : 1; /* bits 29:29 */
  304. u32 crypto_pd : 1; /* bits 30:30 */
  305. u32 core_pd : 1; /* bits 31:31 */
  306. };
  307. struct GLOBAL_IO_DRIVE_CONTROL_t {
  308. u32 gmac_dp : 3; /* bits 2:0 */
  309. u32 gmac_dn : 3; /* bits 5:3 */
  310. u32 gmac_mode : 2; /* bits 7:6 */
  311. u32 gmac_ds : 1; /* bits 8:8 */
  312. u32 flash_ds : 1; /* bits 9:9 */
  313. u32 nu_ds : 1; /* bits 10:10 */
  314. u32 ssp_ds : 1; /* bits 11:11 */
  315. u32 spi_ds : 1; /* bits 12:12 */
  316. u32 gpio_ds : 1; /* bits 13:13 */
  317. u32 misc_ds : 1; /* bits 14:14 */
  318. u32 eaxi_ds : 1; /* bits 15:15 */
  319. u32 sd_ds : 8; /* bits 23:16 */
  320. u32 rsrvd1 : 8;
  321. };
  322. struct NI_HV_GLB_INIT_DONE_t {
  323. u32 rsrvd1 : 1;
  324. u32 ni_init_done : 1; /* bits 1:1 */
  325. u32 rsrvd2 : 30;
  326. };
  327. struct NI_HV_PT_PORT_GLB_CFG_t {
  328. u32 speed : 1; /* bits 0:0 */
  329. u32 duplex : 1; /* bits 1:1 */
  330. u32 link_status : 1; /* bits 2:2 */
  331. u32 link_stat_mask : 1; /* bits 3:3 */
  332. u32 rsrvd1 : 7;
  333. u32 power_dwn_rx : 1; /* bits 11:11 */
  334. u32 power_dwn_tx : 1; /* bits 12:12 */
  335. u32 tx_intf_lp_time : 1; /* bits 13:13 */
  336. u32 rsrvd2 : 18;
  337. };
  338. #define NI_HV_GLB_INIT_DONE_OFFSET 0x004
  339. #define NI_HV_GLB_INTF_RST_CONFIG_OFFSET 0x008
  340. #define NI_HV_GLB_STATIC_CFG_OFFSET 0x00c
  341. #define NI_HV_PT_PORT_STATIC_CFG_OFFSET NI_HV_PT_BASE
  342. #define NI_HV_PT_PORT_GLB_CFG_OFFSET (0x4 + NI_HV_PT_BASE)
  343. #define NI_HV_PT_RXMAC_CFG_OFFSET (0x8 + NI_HV_PT_BASE)
  344. #define NI_HV_PT_TXMAC_CFG_OFFSET (0x14 + NI_HV_PT_BASE)
  345. #define NI_HV_XRAM_CPUXRAM_ADRCFG_RX_OFFSET NI_HV_XRAM_BASE
  346. #define NI_HV_XRAM_CPUXRAM_ADRCFG_TX_0_OFFSET (0x4 + NI_HV_XRAM_BASE)
  347. #define NI_HV_XRAM_CPUXRAM_CFG_OFFSET (0x8 + NI_HV_XRAM_BASE)
  348. #define NI_HV_XRAM_CPUXRAM_CPU_CFG_RX_0_OFFSET (0xc + NI_HV_XRAM_BASE)
  349. #define NI_HV_XRAM_CPUXRAM_CPU_STA_RX_0_OFFSET (0x10 + NI_HV_XRAM_BASE)
  350. #define NI_HV_XRAM_CPUXRAM_CPU_CFG_TX_0_OFFSET (0x24 + NI_HV_XRAM_BASE)
  351. #define NI_HV_XRAM_CPUXRAM_CPU_STAT_TX_0_OFFSET (0x28 + NI_HV_XRAM_BASE)
  352. #define PER_MDIO_CFG_OFFSET 0x00
  353. #define PER_MDIO_ADDR_OFFSET 0x04
  354. #define PER_MDIO_WRDATA_OFFSET 0x08
  355. #define PER_MDIO_RDDATA_OFFSET 0x0C
  356. #define PER_MDIO_CTRL_OFFSET 0x10
  357. #define APB0_NI_HV_PT_STRIDE 160
  358. #endif /* __CORTINA_NI_H */