bcmasp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __BCMASP_H
  3. #define __BCMASP_H
  4. #include <linux/netdevice.h>
  5. #include <linux/phy.h>
  6. #include <linux/io-64-nonatomic-hi-lo.h>
  7. #include <uapi/linux/ethtool.h>
  8. #define ASP_INTR2_OFFSET 0x1000
  9. #define ASP_INTR2_STATUS 0x0
  10. #define ASP_INTR2_SET 0x4
  11. #define ASP_INTR2_CLEAR 0x8
  12. #define ASP_INTR2_MASK_STATUS 0xc
  13. #define ASP_INTR2_MASK_SET 0x10
  14. #define ASP_INTR2_MASK_CLEAR 0x14
  15. #define ASP_INTR2_RX_ECH(intr) BIT(intr)
  16. #define ASP_INTR2_TX_DESC(intr) BIT((intr) + 14)
  17. #define ASP_INTR2_UMC0_WAKE BIT(22)
  18. #define ASP_INTR2_UMC1_WAKE BIT(28)
  19. #define ASP_INTR2_PHY_EVENT(intr) ((intr) ? BIT(30) | BIT(31) : \
  20. BIT(24) | BIT(25))
  21. #define ASP_WAKEUP_INTR2_OFFSET 0x1200
  22. #define ASP_WAKEUP_INTR2_STATUS 0x0
  23. #define ASP_WAKEUP_INTR2_SET 0x4
  24. #define ASP_WAKEUP_INTR2_CLEAR 0x8
  25. #define ASP_WAKEUP_INTR2_MASK_STATUS 0xc
  26. #define ASP_WAKEUP_INTR2_MASK_SET 0x10
  27. #define ASP_WAKEUP_INTR2_MASK_CLEAR 0x14
  28. #define ASP_WAKEUP_INTR2_MPD_0 BIT(0)
  29. #define ASP_WAKEUP_INTR2_MPD_1 BIT(1)
  30. #define ASP_WAKEUP_INTR2_FILT_0 BIT(2)
  31. #define ASP_WAKEUP_INTR2_FILT_1 BIT(3)
  32. #define ASP_WAKEUP_INTR2_FW BIT(4)
  33. #define ASP_CTRL2_OFFSET 0x2000
  34. #define ASP_CTRL2_CORE_CLOCK_SELECT 0x0
  35. #define ASP_CTRL2_CORE_CLOCK_SELECT_MAIN BIT(0)
  36. #define ASP_CTRL2_CPU_CLOCK_SELECT 0x4
  37. #define ASP_CTRL2_CPU_CLOCK_SELECT_MAIN BIT(0)
  38. #define ASP_TX_ANALYTICS_OFFSET 0x4c000
  39. #define ASP_TX_ANALYTICS_CTRL 0x0
  40. #define ASP_RX_ANALYTICS_OFFSET 0x98000
  41. #define ASP_RX_ANALYTICS_CTRL 0x0
  42. #define ASP_RX_CTRL_OFFSET 0x9f000
  43. #define ASP_RX_CTRL_UMAC_0_FRAME_COUNT 0x8
  44. #define ASP_RX_CTRL_UMAC_1_FRAME_COUNT 0xc
  45. #define ASP_RX_CTRL_FB_0_FRAME_COUNT 0x14
  46. #define ASP_RX_CTRL_FB_1_FRAME_COUNT 0x18
  47. #define ASP_RX_CTRL_FB_8_FRAME_COUNT 0x1c
  48. /* asp2.1 diverges offsets here */
  49. /* ASP2.0 */
  50. #define ASP_RX_CTRL_FB_OUT_FRAME_COUNT 0x20
  51. #define ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT 0x24
  52. #define ASP_RX_CTRL_FLUSH 0x28
  53. #define ASP_CTRL_UMAC0_FLUSH_MASK (BIT(0) | BIT(12))
  54. #define ASP_CTRL_UMAC1_FLUSH_MASK (BIT(1) | BIT(13))
  55. #define ASP_CTRL_SPB_FLUSH_MASK (BIT(8) | BIT(20))
  56. #define ASP_RX_CTRL_FB_RX_FIFO_DEPTH 0x30
  57. /* ASP2.1 */
  58. #define ASP_RX_CTRL_FB_9_FRAME_COUNT_2_1 0x20
  59. #define ASP_RX_CTRL_FB_10_FRAME_COUNT_2_1 0x24
  60. #define ASP_RX_CTRL_FB_OUT_FRAME_COUNT_2_1 0x28
  61. #define ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT_2_1 0x2c
  62. #define ASP_RX_CTRL_FLUSH_2_1 0x30
  63. #define ASP_RX_CTRL_FB_RX_FIFO_DEPTH_2_1 0x38
  64. #define ASP_RX_FILTER_OFFSET 0x80000
  65. #define ASP_RX_FILTER_BLK_CTRL 0x0
  66. #define ASP_RX_FILTER_OPUT_EN BIT(0)
  67. #define ASP_RX_FILTER_MDA_EN BIT(1)
  68. #define ASP_RX_FILTER_LNR_MD BIT(2)
  69. #define ASP_RX_FILTER_GEN_WK_EN BIT(3)
  70. #define ASP_RX_FILTER_GEN_WK_CLR BIT(4)
  71. #define ASP_RX_FILTER_NT_FLT_EN BIT(5)
  72. #define ASP_RX_FILTER_MDA_CFG(sel) (((sel) * 0x14) + 0x100)
  73. #define ASP_RX_FILTER_MDA_CFG_EN_SHIFT 8
  74. #define ASP_RX_FILTER_MDA_CFG_UMC_SEL(sel) ((sel) > 1 ? BIT(17) : \
  75. BIT((sel) + 9))
  76. #define ASP_RX_FILTER_MDA_PAT_H(sel) (((sel) * 0x14) + 0x104)
  77. #define ASP_RX_FILTER_MDA_PAT_L(sel) (((sel) * 0x14) + 0x108)
  78. #define ASP_RX_FILTER_MDA_MSK_H(sel) (((sel) * 0x14) + 0x10c)
  79. #define ASP_RX_FILTER_MDA_MSK_L(sel) (((sel) * 0x14) + 0x110)
  80. #define ASP_RX_FILTER_MDA_CFG(sel) (((sel) * 0x14) + 0x100)
  81. #define ASP_RX_FILTER_MDA_PAT_H(sel) (((sel) * 0x14) + 0x104)
  82. #define ASP_RX_FILTER_MDA_PAT_L(sel) (((sel) * 0x14) + 0x108)
  83. #define ASP_RX_FILTER_MDA_MSK_H(sel) (((sel) * 0x14) + 0x10c)
  84. #define ASP_RX_FILTER_MDA_MSK_L(sel) (((sel) * 0x14) + 0x110)
  85. #define ASP_RX_FILTER_NET_CFG(sel) (((sel) * 0xa04) + 0x400)
  86. #define ASP_RX_FILTER_NET_CFG_CH(sel) ((sel) << 0)
  87. #define ASP_RX_FILTER_NET_CFG_EN BIT(9)
  88. #define ASP_RX_FILTER_NET_CFG_L2_EN BIT(10)
  89. #define ASP_RX_FILTER_NET_CFG_L3_EN BIT(11)
  90. #define ASP_RX_FILTER_NET_CFG_L4_EN BIT(12)
  91. #define ASP_RX_FILTER_NET_CFG_L3_FRM(sel) ((sel) << 13)
  92. #define ASP_RX_FILTER_NET_CFG_L4_FRM(sel) ((sel) << 15)
  93. #define ASP_RX_FILTER_NET_CFG_UMC(sel) BIT((sel) + 19)
  94. #define ASP_RX_FILTER_NET_CFG_DMA_EN BIT(27)
  95. #define ASP_RX_FILTER_NET_OFFSET_MAX 32
  96. #define ASP_RX_FILTER_NET_PAT(sel, block, off) \
  97. (((sel) * 0xa04) + ((block) * 0x200) + (off) + 0x600)
  98. #define ASP_RX_FILTER_NET_MASK(sel, block, off) \
  99. (((sel) * 0xa04) + ((block) * 0x200) + (off) + 0x700)
  100. #define ASP_RX_FILTER_NET_OFFSET(sel) (((sel) * 0xa04) + 0xe00)
  101. #define ASP_RX_FILTER_NET_OFFSET_L2(val) ((val) << 0)
  102. #define ASP_RX_FILTER_NET_OFFSET_L3_0(val) ((val) << 8)
  103. #define ASP_RX_FILTER_NET_OFFSET_L3_1(val) ((val) << 16)
  104. #define ASP_RX_FILTER_NET_OFFSET_L4(val) ((val) << 24)
  105. enum asp_rx_net_filter_block {
  106. ASP_RX_FILTER_NET_L2 = 0,
  107. ASP_RX_FILTER_NET_L3_0,
  108. ASP_RX_FILTER_NET_L3_1,
  109. ASP_RX_FILTER_NET_L4,
  110. ASP_RX_FILTER_NET_BLOCK_MAX
  111. };
  112. #define ASP_EDPKT_OFFSET 0x9c000
  113. #define ASP_EDPKT_ENABLE 0x4
  114. #define ASP_EDPKT_ENABLE_EN BIT(0)
  115. #define ASP_EDPKT_HDR_CFG 0xc
  116. #define ASP_EDPKT_HDR_SZ_SHIFT 2
  117. #define ASP_EDPKT_HDR_SZ_32 0
  118. #define ASP_EDPKT_HDR_SZ_64 1
  119. #define ASP_EDPKT_HDR_SZ_96 2
  120. #define ASP_EDPKT_HDR_SZ_128 3
  121. #define ASP_EDPKT_BURST_BUF_PSCAL_TOUT 0x10
  122. #define ASP_EDPKT_BURST_BUF_WRITE_TOUT 0x14
  123. #define ASP_EDPKT_BURST_BUF_READ_TOUT 0x18
  124. #define ASP_EDPKT_RX_TS_COUNTER 0x38
  125. #define ASP_EDPKT_ENDI 0x48
  126. #define ASP_EDPKT_ENDI_DESC_SHIFT 8
  127. #define ASP_EDPKT_ENDI_NO_BT_SWP 0
  128. #define ASP_EDPKT_ENDI_BT_SWP_WD 1
  129. #define ASP_EDPKT_RX_PKT_CNT 0x138
  130. #define ASP_EDPKT_HDR_EXTR_CNT 0x13c
  131. #define ASP_EDPKT_HDR_OUT_CNT 0x140
  132. #define ASP_EDPKT_SPARE_REG 0x174
  133. #define ASP_EDPKT_SPARE_REG_EPHY_LPI BIT(4)
  134. #define ASP_EDPKT_SPARE_REG_GPHY_LPI BIT(3)
  135. #define ASP_CTRL_OFFSET 0x101000
  136. #define ASP_CTRL_ASP_SW_INIT 0x04
  137. #define ASP_CTRL_ASP_SW_INIT_ACPUSS_CORE BIT(0)
  138. #define ASP_CTRL_ASP_SW_INIT_ASP_TX BIT(1)
  139. #define ASP_CTRL_ASP_SW_INIT_AS_RX BIT(2)
  140. #define ASP_CTRL_ASP_SW_INIT_ASP_RGMII_UMAC0 BIT(3)
  141. #define ASP_CTRL_ASP_SW_INIT_ASP_RGMII_UMAC1 BIT(4)
  142. #define ASP_CTRL_ASP_SW_INIT_ASP_XMEMIF BIT(5)
  143. #define ASP_CTRL_CLOCK_CTRL 0x04
  144. #define ASP_CTRL_CLOCK_CTRL_ASP_TX_DISABLE BIT(0)
  145. #define ASP_CTRL_CLOCK_CTRL_ASP_RX_DISABLE BIT(1)
  146. #define ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT 2
  147. #define ASP_CTRL_CLOCK_CTRL_ASP_RGMII_MASK (0x7 << ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT)
  148. #define ASP_CTRL_CLOCK_CTRL_ASP_RGMII_DIS(x) BIT(ASP_CTRL_CLOCK_CTRL_ASP_RGMII_SHIFT + (x))
  149. #define ASP_CTRL_CLOCK_CTRL_ASP_ALL_DISABLE GENMASK(4, 0)
  150. #define ASP_CTRL_CORE_CLOCK_SELECT 0x08
  151. #define ASP_CTRL_CORE_CLOCK_SELECT_MAIN BIT(0)
  152. #define ASP_CTRL_SCRATCH_0 0x0c
  153. struct bcmasp_tx_cb {
  154. struct sk_buff *skb;
  155. unsigned int bytes_sent;
  156. bool last;
  157. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  158. DEFINE_DMA_UNMAP_LEN(dma_len);
  159. };
  160. struct bcmasp_res {
  161. /* Per interface resources */
  162. /* Port */
  163. void __iomem *umac;
  164. void __iomem *umac2fb;
  165. void __iomem *rgmii;
  166. /* TX slowpath/configuration */
  167. void __iomem *tx_spb_ctrl;
  168. void __iomem *tx_spb_top;
  169. void __iomem *tx_epkt_core;
  170. void __iomem *tx_pause_ctrl;
  171. };
  172. #define DESC_ADDR(x) ((x) & GENMASK_ULL(39, 0))
  173. #define DESC_FLAGS(x) ((x) & GENMASK_ULL(63, 40))
  174. struct bcmasp_desc {
  175. u64 buf;
  176. #define DESC_CHKSUM BIT_ULL(40)
  177. #define DESC_CRC_ERR BIT_ULL(41)
  178. #define DESC_RX_SYM_ERR BIT_ULL(42)
  179. #define DESC_NO_OCT_ALN BIT_ULL(43)
  180. #define DESC_PKT_TRUC BIT_ULL(44)
  181. /* 39:0 (TX/RX) bits 0-39 of buf addr
  182. * 40 (RX) checksum
  183. * 41 (RX) crc_error
  184. * 42 (RX) rx_symbol_error
  185. * 43 (RX) non_octet_aligned
  186. * 44 (RX) pkt_truncated
  187. * 45 Reserved
  188. * 56:46 (RX) mac_filter_id
  189. * 60:57 (RX) rx_port_num (0-unicmac0, 1-unimac1)
  190. * 61 Reserved
  191. * 63:62 (TX) forward CRC, overwrite CRC
  192. */
  193. u32 size;
  194. u32 flags;
  195. #define DESC_INT_EN BIT(0)
  196. #define DESC_SOF BIT(1)
  197. #define DESC_EOF BIT(2)
  198. #define DESC_EPKT_CMD BIT(3)
  199. #define DESC_SCRAM_ST BIT(8)
  200. #define DESC_SCRAM_END BIT(9)
  201. #define DESC_PCPP BIT(10)
  202. #define DESC_PPPP BIT(11)
  203. /* 0 (TX) tx_int_en
  204. * 1 (TX/RX) SOF
  205. * 2 (TX/RX) EOF
  206. * 3 (TX) epkt_command
  207. * 6:4 (TX) PA
  208. * 7 (TX) pause at desc end
  209. * 8 (TX) scram_start
  210. * 9 (TX) scram_end
  211. * 10 (TX) PCPP
  212. * 11 (TX) PPPP
  213. * 14:12 Reserved
  214. * 15 (TX) pid ch Valid
  215. * 19:16 (TX) data_pkt_type
  216. * 32:20 (TX) pid_channel (RX) nw_filter_id
  217. */
  218. };
  219. struct bcmasp_intf;
  220. struct bcmasp_intf_stats64 {
  221. /* Rx Stats */
  222. u64_stats_t rx_packets;
  223. u64_stats_t rx_bytes;
  224. u64_stats_t rx_errors;
  225. u64_stats_t rx_dropped;
  226. u64_stats_t rx_crc_errs;
  227. u64_stats_t rx_sym_errs;
  228. /* Tx Stats*/
  229. u64_stats_t tx_packets;
  230. u64_stats_t tx_bytes;
  231. struct u64_stats_sync syncp;
  232. };
  233. struct bcmasp_mib_counters {
  234. u32 edpkt_ts;
  235. u32 edpkt_rx_pkt_cnt;
  236. u32 edpkt_hdr_ext_cnt;
  237. u32 edpkt_hdr_out_cnt;
  238. u32 umac_frm_cnt;
  239. u32 fb_frm_cnt;
  240. u32 fb_rx_fifo_depth;
  241. u32 fb_out_frm_cnt;
  242. u32 fb_filt_out_frm_cnt;
  243. u32 alloc_rx_skb_failed;
  244. u32 tx_dma_failed;
  245. u32 mc_filters_full_cnt;
  246. u32 uc_filters_full_cnt;
  247. u32 filters_combine_cnt;
  248. u32 promisc_filters_cnt;
  249. u32 tx_realloc_offload_failed;
  250. u32 tx_timeout_cnt;
  251. };
  252. struct bcmasp_intf_ops {
  253. unsigned long (*rx_desc_read)(struct bcmasp_intf *intf);
  254. void (*rx_buffer_write)(struct bcmasp_intf *intf, dma_addr_t addr);
  255. void (*rx_desc_write)(struct bcmasp_intf *intf, dma_addr_t addr);
  256. unsigned long (*tx_read)(struct bcmasp_intf *intf);
  257. void (*tx_write)(struct bcmasp_intf *intf, dma_addr_t addr);
  258. };
  259. struct bcmasp_priv;
  260. struct bcmasp_intf {
  261. struct list_head list;
  262. struct net_device *ndev;
  263. struct bcmasp_priv *parent;
  264. /* ASP Ch */
  265. int channel;
  266. int port;
  267. const struct bcmasp_intf_ops *ops;
  268. /* Used for splitting shared resources */
  269. int index;
  270. struct napi_struct tx_napi;
  271. /* TX ring, starts on a new cacheline boundary */
  272. void __iomem *tx_spb_dma;
  273. int tx_spb_index;
  274. int tx_spb_clean_index;
  275. struct bcmasp_desc *tx_spb_cpu;
  276. dma_addr_t tx_spb_dma_addr;
  277. dma_addr_t tx_spb_dma_valid;
  278. dma_addr_t tx_spb_dma_read;
  279. struct bcmasp_tx_cb *tx_cbs;
  280. /* RX ring, starts on a new cacheline boundary */
  281. void __iomem *rx_edpkt_cfg;
  282. void __iomem *rx_edpkt_dma;
  283. int rx_edpkt_index;
  284. int rx_buf_order;
  285. struct bcmasp_desc *rx_edpkt_cpu;
  286. dma_addr_t rx_edpkt_dma_addr;
  287. dma_addr_t rx_edpkt_dma_read;
  288. dma_addr_t rx_edpkt_dma_valid;
  289. /* RX buffer prefetcher ring*/
  290. void *rx_ring_cpu;
  291. dma_addr_t rx_ring_dma;
  292. dma_addr_t rx_ring_dma_valid;
  293. struct napi_struct rx_napi;
  294. struct bcmasp_res res;
  295. unsigned int crc_fwd;
  296. /* PHY device */
  297. struct device_node *phy_dn;
  298. struct device_node *ndev_dn;
  299. phy_interface_t phy_interface;
  300. bool internal_phy;
  301. int old_pause;
  302. int old_link;
  303. int old_duplex;
  304. u32 msg_enable;
  305. /* Statistics */
  306. struct bcmasp_intf_stats64 stats64;
  307. struct bcmasp_mib_counters mib;
  308. u32 wolopts;
  309. u8 sopass[SOPASS_MAX];
  310. /* Used if per intf wol irq */
  311. int wol_irq;
  312. unsigned int wol_irq_enabled:1;
  313. struct ethtool_keee eee;
  314. };
  315. #define NUM_NET_FILTERS 32
  316. struct bcmasp_net_filter {
  317. struct ethtool_rx_flow_spec fs;
  318. bool claimed;
  319. bool wake_filter;
  320. int port;
  321. unsigned int hw_index;
  322. };
  323. #define NUM_MDA_FILTERS 32
  324. struct bcmasp_mda_filter {
  325. /* Current owner of this filter */
  326. int port;
  327. bool en;
  328. u8 addr[ETH_ALEN];
  329. u8 mask[ETH_ALEN];
  330. };
  331. struct bcmasp_hw_info {
  332. u32 rx_ctrl_flush;
  333. u32 umac2fb;
  334. u32 rx_ctrl_fb_out_frame_count;
  335. u32 rx_ctrl_fb_filt_out_frame_count;
  336. u32 rx_ctrl_fb_rx_fifo_depth;
  337. };
  338. struct bcmasp_plat_data {
  339. void (*init_wol)(struct bcmasp_priv *priv);
  340. void (*enable_wol)(struct bcmasp_intf *intf, bool en);
  341. void (*destroy_wol)(struct bcmasp_priv *priv);
  342. void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
  343. void (*eee_fixup)(struct bcmasp_intf *priv, bool en);
  344. struct bcmasp_hw_info *hw_info;
  345. };
  346. struct bcmasp_priv {
  347. struct platform_device *pdev;
  348. struct clk *clk;
  349. int irq;
  350. u32 irq_mask;
  351. /* Used if shared wol irq */
  352. struct mutex wol_lock;
  353. int wol_irq;
  354. unsigned long wol_irq_enabled_mask;
  355. void (*init_wol)(struct bcmasp_priv *priv);
  356. void (*enable_wol)(struct bcmasp_intf *intf, bool en);
  357. void (*destroy_wol)(struct bcmasp_priv *priv);
  358. void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
  359. void (*eee_fixup)(struct bcmasp_intf *intf, bool en);
  360. void __iomem *base;
  361. struct bcmasp_hw_info *hw_info;
  362. struct list_head intfs;
  363. struct bcmasp_mda_filter mda_filters[NUM_MDA_FILTERS];
  364. /* MAC destination address filters lock */
  365. spinlock_t mda_lock;
  366. /* Protects accesses to ASP_CTRL_CLOCK_CTRL */
  367. spinlock_t clk_lock;
  368. struct bcmasp_net_filter net_filters[NUM_NET_FILTERS];
  369. /* Network filter lock */
  370. struct mutex net_lock;
  371. };
  372. static inline unsigned long bcmasp_intf_rx_desc_read(struct bcmasp_intf *intf)
  373. {
  374. return intf->ops->rx_desc_read(intf);
  375. }
  376. static inline void bcmasp_intf_rx_buffer_write(struct bcmasp_intf *intf,
  377. dma_addr_t addr)
  378. {
  379. intf->ops->rx_buffer_write(intf, addr);
  380. }
  381. static inline void bcmasp_intf_rx_desc_write(struct bcmasp_intf *intf,
  382. dma_addr_t addr)
  383. {
  384. intf->ops->rx_desc_write(intf, addr);
  385. }
  386. static inline unsigned long bcmasp_intf_tx_read(struct bcmasp_intf *intf)
  387. {
  388. return intf->ops->tx_read(intf);
  389. }
  390. static inline void bcmasp_intf_tx_write(struct bcmasp_intf *intf,
  391. dma_addr_t addr)
  392. {
  393. intf->ops->tx_write(intf, addr);
  394. }
  395. #define __BCMASP_IO_MACRO(name, m) \
  396. static inline u32 name##_rl(struct bcmasp_intf *intf, u32 off) \
  397. { \
  398. u32 reg = readl_relaxed(intf->m + off); \
  399. return reg; \
  400. } \
  401. static inline void name##_wl(struct bcmasp_intf *intf, u32 val, u32 off)\
  402. { \
  403. writel_relaxed(val, intf->m + off); \
  404. }
  405. #define BCMASP_IO_MACRO(name) __BCMASP_IO_MACRO(name, res.name)
  406. #define BCMASP_FP_IO_MACRO(name) __BCMASP_IO_MACRO(name, name)
  407. BCMASP_IO_MACRO(umac);
  408. BCMASP_IO_MACRO(umac2fb);
  409. BCMASP_IO_MACRO(rgmii);
  410. BCMASP_FP_IO_MACRO(tx_spb_dma);
  411. BCMASP_IO_MACRO(tx_spb_ctrl);
  412. BCMASP_IO_MACRO(tx_spb_top);
  413. BCMASP_IO_MACRO(tx_epkt_core);
  414. BCMASP_IO_MACRO(tx_pause_ctrl);
  415. BCMASP_FP_IO_MACRO(rx_edpkt_dma);
  416. BCMASP_FP_IO_MACRO(rx_edpkt_cfg);
  417. #define __BCMASP_FP_IO_MACRO_Q(name, m) \
  418. static inline u64 name##_rq(struct bcmasp_intf *intf, u32 off) \
  419. { \
  420. u64 reg = readq_relaxed(intf->m + off); \
  421. return reg; \
  422. } \
  423. static inline void name##_wq(struct bcmasp_intf *intf, u64 val, u32 off)\
  424. { \
  425. writeq_relaxed(val, intf->m + off); \
  426. }
  427. #define BCMASP_FP_IO_MACRO_Q(name) __BCMASP_FP_IO_MACRO_Q(name, name)
  428. BCMASP_FP_IO_MACRO_Q(tx_spb_dma);
  429. BCMASP_FP_IO_MACRO_Q(rx_edpkt_dma);
  430. BCMASP_FP_IO_MACRO_Q(rx_edpkt_cfg);
  431. #define PKT_OFFLOAD_NOP (0 << 28)
  432. #define PKT_OFFLOAD_HDR_OP (1 << 28)
  433. #define PKT_OFFLOAD_HDR_WRBACK BIT(19)
  434. #define PKT_OFFLOAD_HDR_COUNT(x) ((x) << 16)
  435. #define PKT_OFFLOAD_HDR_SIZE_1(x) ((x) << 4)
  436. #define PKT_OFFLOAD_HDR_SIZE_2(x) (x)
  437. #define PKT_OFFLOAD_HDR2_SIZE_2(x) ((x) << 24)
  438. #define PKT_OFFLOAD_HDR2_SIZE_3(x) ((x) << 12)
  439. #define PKT_OFFLOAD_HDR2_SIZE_4(x) (x)
  440. #define PKT_OFFLOAD_EPKT_OP (2 << 28)
  441. #define PKT_OFFLOAD_EPKT_WRBACK BIT(23)
  442. #define PKT_OFFLOAD_EPKT_IP(x) ((x) << 21)
  443. #define PKT_OFFLOAD_EPKT_TP(x) ((x) << 19)
  444. #define PKT_OFFLOAD_EPKT_LEN(x) ((x) << 16)
  445. #define PKT_OFFLOAD_EPKT_CSUM_L3 BIT(15)
  446. #define PKT_OFFLOAD_EPKT_CSUM_L2 BIT(14)
  447. #define PKT_OFFLOAD_EPKT_ID(x) ((x) << 12)
  448. #define PKT_OFFLOAD_EPKT_SEQ(x) ((x) << 10)
  449. #define PKT_OFFLOAD_EPKT_TS(x) ((x) << 8)
  450. #define PKT_OFFLOAD_EPKT_BLOC(x) (x)
  451. #define PKT_OFFLOAD_END_OP (7 << 28)
  452. struct bcmasp_pkt_offload {
  453. __be32 nop;
  454. __be32 header;
  455. __be32 header2;
  456. __be32 epkt;
  457. __be32 end;
  458. };
  459. #define BCMASP_CORE_IO_MACRO(name, offset) \
  460. static inline u32 name##_core_rl(struct bcmasp_priv *priv, \
  461. u32 off) \
  462. { \
  463. u32 reg = readl_relaxed(priv->base + (offset) + off); \
  464. return reg; \
  465. } \
  466. static inline void name##_core_wl(struct bcmasp_priv *priv, \
  467. u32 val, u32 off) \
  468. { \
  469. writel_relaxed(val, priv->base + (offset) + off); \
  470. }
  471. BCMASP_CORE_IO_MACRO(intr2, ASP_INTR2_OFFSET);
  472. BCMASP_CORE_IO_MACRO(wakeup_intr2, ASP_WAKEUP_INTR2_OFFSET);
  473. BCMASP_CORE_IO_MACRO(tx_analytics, ASP_TX_ANALYTICS_OFFSET);
  474. BCMASP_CORE_IO_MACRO(rx_analytics, ASP_RX_ANALYTICS_OFFSET);
  475. BCMASP_CORE_IO_MACRO(rx_ctrl, ASP_RX_CTRL_OFFSET);
  476. BCMASP_CORE_IO_MACRO(rx_filter, ASP_RX_FILTER_OFFSET);
  477. BCMASP_CORE_IO_MACRO(rx_edpkt, ASP_EDPKT_OFFSET);
  478. BCMASP_CORE_IO_MACRO(ctrl, ASP_CTRL_OFFSET);
  479. BCMASP_CORE_IO_MACRO(ctrl2, ASP_CTRL2_OFFSET);
  480. struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
  481. struct device_node *ndev_dn, int i);
  482. void bcmasp_interface_destroy(struct bcmasp_intf *intf);
  483. void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en);
  484. void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en);
  485. void bcmasp_enable_phy_irq(struct bcmasp_intf *intf, int en);
  486. void bcmasp_flush_rx_port(struct bcmasp_intf *intf);
  487. extern const struct ethtool_ops bcmasp_ethtool_ops;
  488. int bcmasp_interface_suspend(struct bcmasp_intf *intf);
  489. int bcmasp_interface_resume(struct bcmasp_intf *intf);
  490. void bcmasp_set_promisc(struct bcmasp_intf *intf, bool en);
  491. void bcmasp_set_allmulti(struct bcmasp_intf *intf, bool en);
  492. void bcmasp_set_broad(struct bcmasp_intf *intf, bool en);
  493. void bcmasp_set_oaddr(struct bcmasp_intf *intf, const unsigned char *addr,
  494. bool en);
  495. int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr,
  496. unsigned char *mask);
  497. void bcmasp_disable_all_filters(struct bcmasp_intf *intf);
  498. void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, bool en);
  499. struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
  500. u32 loc, bool wake_filter,
  501. bool init);
  502. bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
  503. struct ethtool_rx_flow_spec *fs);
  504. void bcmasp_netfilt_release(struct bcmasp_intf *intf,
  505. struct bcmasp_net_filter *nfilt);
  506. int bcmasp_netfilt_get_active(struct bcmasp_intf *intf);
  507. int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
  508. u32 *rule_cnt);
  509. void bcmasp_netfilt_suspend(struct bcmasp_intf *intf);
  510. void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable);
  511. #endif