common.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*******************************************************************************
  3. STMMAC Common Header File
  4. Copyright (C) 2007-2009 STMicroelectronics Ltd
  5. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  6. *******************************************************************************/
  7. #ifndef __COMMON_H__
  8. #define __COMMON_H__
  9. #include <linux/etherdevice.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/stmmac.h>
  12. #include <linux/phy.h>
  13. #include <linux/pcs/pcs-xpcs.h>
  14. #include <linux/module.h>
  15. #if IS_ENABLED(CONFIG_VLAN_8021Q)
  16. #define STMMAC_VLAN_TAG_USED
  17. #include <linux/if_vlan.h>
  18. #endif
  19. #include "descs.h"
  20. #include "hwif.h"
  21. #include "mmc.h"
  22. #define DWMAC_SNPSVER GENMASK_U32(7, 0)
  23. #define DWMAC_USERVER GENMASK_U32(15, 8)
  24. /* Synopsys Core versions */
  25. #define DWMAC_CORE_3_40 0x34
  26. #define DWMAC_CORE_3_50 0x35
  27. #define DWMAC_CORE_3_70 0x37
  28. #define DWMAC_CORE_4_00 0x40
  29. #define DWMAC_CORE_4_10 0x41
  30. #define DWMAC_CORE_5_00 0x50
  31. #define DWMAC_CORE_5_10 0x51
  32. #define DWMAC_CORE_5_20 0x52
  33. #define DWXGMAC_CORE_2_10 0x21
  34. #define DWXGMAC_CORE_2_20 0x22
  35. #define DWXLGMAC_CORE_2_00 0x20
  36. /* Device ID */
  37. #define DWXGMAC_ID 0x76
  38. #define DWXLGMAC_ID 0x27
  39. static inline bool dwmac_is_xmac(enum dwmac_core_type core_type)
  40. {
  41. return core_type == DWMAC_CORE_GMAC4 || core_type == DWMAC_CORE_XGMAC;
  42. }
  43. #define STMMAC_CHAN0 0 /* Always supported and default for all chips */
  44. /* TX and RX Descriptor Length, these need to be power of two.
  45. * TX descriptor length less than 64 may cause transmit queue timed out error.
  46. * RX descriptor length less than 64 may cause inconsistent Rx chain error.
  47. */
  48. #define DMA_MIN_TX_SIZE 64
  49. #define DMA_MAX_TX_SIZE 1024
  50. #define DMA_DEFAULT_TX_SIZE 512
  51. #define DMA_MIN_RX_SIZE 64
  52. #define DMA_MAX_RX_SIZE 1024
  53. #define DMA_DEFAULT_RX_SIZE 512
  54. #define STMMAC_GET_ENTRY(x, size) ((x + 1) & (size - 1))
  55. #undef FRAME_FILTER_DEBUG
  56. /* #define FRAME_FILTER_DEBUG */
  57. struct stmmac_q_tx_stats {
  58. u64_stats_t tx_bytes;
  59. u64_stats_t tx_set_ic_bit;
  60. u64_stats_t tx_tso_frames;
  61. u64_stats_t tx_tso_nfrags;
  62. };
  63. struct stmmac_napi_tx_stats {
  64. u64_stats_t tx_packets;
  65. u64_stats_t tx_pkt_n;
  66. u64_stats_t poll;
  67. u64_stats_t tx_clean;
  68. u64_stats_t tx_set_ic_bit;
  69. };
  70. struct stmmac_txq_stats {
  71. /* Updates protected by tx queue lock. */
  72. struct u64_stats_sync q_syncp;
  73. struct stmmac_q_tx_stats q;
  74. /* Updates protected by NAPI poll logic. */
  75. struct u64_stats_sync napi_syncp;
  76. struct stmmac_napi_tx_stats napi;
  77. } ____cacheline_aligned_in_smp;
  78. struct stmmac_napi_rx_stats {
  79. u64_stats_t rx_bytes;
  80. u64_stats_t rx_packets;
  81. u64_stats_t rx_pkt_n;
  82. u64_stats_t poll;
  83. };
  84. struct stmmac_rxq_stats {
  85. /* Updates protected by NAPI poll logic. */
  86. struct u64_stats_sync napi_syncp;
  87. struct stmmac_napi_rx_stats napi;
  88. } ____cacheline_aligned_in_smp;
  89. /* Updates on each CPU protected by not allowing nested irqs. */
  90. struct stmmac_pcpu_stats {
  91. struct u64_stats_sync syncp;
  92. u64_stats_t rx_normal_irq_n[MTL_MAX_RX_QUEUES];
  93. u64_stats_t tx_normal_irq_n[MTL_MAX_TX_QUEUES];
  94. };
  95. /* Extra statistic and debug information exposed by ethtool */
  96. struct stmmac_extra_stats {
  97. /* Transmit errors */
  98. unsigned long tx_underflow ____cacheline_aligned;
  99. unsigned long tx_carrier;
  100. unsigned long tx_losscarrier;
  101. unsigned long vlan_tag;
  102. unsigned long tx_deferred;
  103. unsigned long tx_vlan;
  104. unsigned long tx_jabber;
  105. unsigned long tx_frame_flushed;
  106. unsigned long tx_payload_error;
  107. unsigned long tx_ip_header_error;
  108. unsigned long tx_collision;
  109. /* Receive errors */
  110. unsigned long rx_desc;
  111. unsigned long sa_filter_fail;
  112. unsigned long overflow_error;
  113. unsigned long ipc_csum_error;
  114. unsigned long rx_collision;
  115. unsigned long rx_crc_errors;
  116. unsigned long dribbling_bit;
  117. unsigned long rx_length;
  118. unsigned long rx_mii;
  119. unsigned long rx_multicast;
  120. unsigned long rx_gmac_overflow;
  121. unsigned long rx_watchdog;
  122. unsigned long da_rx_filter_fail;
  123. unsigned long sa_rx_filter_fail;
  124. unsigned long rx_missed_cntr;
  125. unsigned long rx_overflow_cntr;
  126. unsigned long rx_vlan;
  127. unsigned long rx_split_hdr_pkt_n;
  128. /* Tx/Rx IRQ error info */
  129. unsigned long tx_undeflow_irq;
  130. unsigned long tx_process_stopped_irq;
  131. unsigned long tx_jabber_irq;
  132. unsigned long rx_overflow_irq;
  133. unsigned long rx_buf_unav_irq;
  134. unsigned long rx_process_stopped_irq;
  135. unsigned long rx_watchdog_irq;
  136. unsigned long tx_early_irq;
  137. unsigned long fatal_bus_error_irq;
  138. /* Tx/Rx IRQ Events */
  139. unsigned long rx_early_irq;
  140. unsigned long threshold;
  141. unsigned long irq_receive_pmt_irq_n;
  142. /* MMC info */
  143. unsigned long mmc_tx_irq_n;
  144. unsigned long mmc_rx_irq_n;
  145. unsigned long mmc_rx_csum_offload_irq_n;
  146. /* EEE */
  147. unsigned long irq_tx_path_in_lpi_mode_n;
  148. unsigned long irq_tx_path_exit_lpi_mode_n;
  149. unsigned long irq_rx_path_in_lpi_mode_n;
  150. unsigned long irq_rx_path_exit_lpi_mode_n;
  151. unsigned long phy_eee_wakeup_error_n;
  152. /* Extended RDES status */
  153. unsigned long ip_hdr_err;
  154. unsigned long ip_payload_err;
  155. unsigned long ip_csum_bypassed;
  156. unsigned long ipv4_pkt_rcvd;
  157. unsigned long ipv6_pkt_rcvd;
  158. unsigned long no_ptp_rx_msg_type_ext;
  159. unsigned long ptp_rx_msg_type_sync;
  160. unsigned long ptp_rx_msg_type_follow_up;
  161. unsigned long ptp_rx_msg_type_delay_req;
  162. unsigned long ptp_rx_msg_type_delay_resp;
  163. unsigned long ptp_rx_msg_type_pdelay_req;
  164. unsigned long ptp_rx_msg_type_pdelay_resp;
  165. unsigned long ptp_rx_msg_type_pdelay_follow_up;
  166. unsigned long ptp_rx_msg_type_announce;
  167. unsigned long ptp_rx_msg_type_management;
  168. unsigned long ptp_rx_msg_pkt_reserved_type;
  169. unsigned long ptp_frame_type;
  170. unsigned long ptp_ver;
  171. unsigned long timestamp_dropped;
  172. unsigned long av_pkt_rcvd;
  173. unsigned long av_tagged_pkt_rcvd;
  174. unsigned long vlan_tag_priority_val;
  175. unsigned long l3_filter_match;
  176. unsigned long l4_filter_match;
  177. unsigned long l3_l4_filter_no_match;
  178. /* PCS */
  179. unsigned long irq_pcs_ane_n;
  180. unsigned long irq_pcs_link_n;
  181. unsigned long irq_rgmii_n;
  182. /* debug register */
  183. unsigned long mtl_tx_status_fifo_full;
  184. unsigned long mtl_tx_fifo_not_empty;
  185. unsigned long mmtl_fifo_ctrl;
  186. unsigned long mtl_tx_fifo_read_ctrl_write;
  187. unsigned long mtl_tx_fifo_read_ctrl_wait;
  188. unsigned long mtl_tx_fifo_read_ctrl_read;
  189. unsigned long mtl_tx_fifo_read_ctrl_idle;
  190. unsigned long mac_tx_in_pause;
  191. unsigned long mac_tx_frame_ctrl_xfer;
  192. unsigned long mac_tx_frame_ctrl_idle;
  193. unsigned long mac_tx_frame_ctrl_wait;
  194. unsigned long mac_tx_frame_ctrl_pause;
  195. unsigned long mac_gmii_tx_proto_engine;
  196. unsigned long mtl_rx_fifo_fill_level_full;
  197. unsigned long mtl_rx_fifo_fill_above_thresh;
  198. unsigned long mtl_rx_fifo_fill_below_thresh;
  199. unsigned long mtl_rx_fifo_fill_level_empty;
  200. unsigned long mtl_rx_fifo_read_ctrl_flush;
  201. unsigned long mtl_rx_fifo_read_ctrl_read_data;
  202. unsigned long mtl_rx_fifo_read_ctrl_status;
  203. unsigned long mtl_rx_fifo_read_ctrl_idle;
  204. unsigned long mtl_rx_fifo_ctrl_active;
  205. unsigned long mac_rx_frame_ctrl_fifo;
  206. unsigned long mac_gmii_rx_proto_engine;
  207. /* EST */
  208. unsigned long mtl_est_cgce;
  209. unsigned long mtl_est_hlbs;
  210. unsigned long mtl_est_hlbf;
  211. unsigned long mtl_est_btre;
  212. unsigned long mtl_est_btrlm;
  213. unsigned long max_sdu_txq_drop[MTL_MAX_TX_QUEUES];
  214. unsigned long mtl_est_txq_hlbf[MTL_MAX_TX_QUEUES];
  215. unsigned long mtl_est_txq_hlbs[MTL_MAX_TX_QUEUES];
  216. /* per queue statistics */
  217. struct stmmac_txq_stats txq_stats[MTL_MAX_TX_QUEUES];
  218. struct stmmac_rxq_stats rxq_stats[MTL_MAX_RX_QUEUES];
  219. struct stmmac_pcpu_stats __percpu *pcpu_stats;
  220. unsigned long rx_dropped;
  221. unsigned long rx_errors;
  222. unsigned long tx_dropped;
  223. unsigned long tx_errors;
  224. };
  225. /* Safety Feature statistics exposed by ethtool */
  226. struct stmmac_safety_stats {
  227. unsigned long mac_errors[32];
  228. unsigned long mtl_errors[32];
  229. unsigned long dma_errors[32];
  230. unsigned long dma_dpp_errors[32];
  231. };
  232. /* Number of fields in Safety Stats */
  233. #define STMMAC_SAFETY_FEAT_SIZE \
  234. (sizeof(struct stmmac_safety_stats) / sizeof(unsigned long))
  235. /* CSR Frequency Access Defines*/
  236. #define CSR_F_35M 35000000
  237. #define CSR_F_60M 60000000
  238. #define CSR_F_100M 100000000
  239. #define CSR_F_150M 150000000
  240. #define CSR_F_250M 250000000
  241. #define CSR_F_300M 300000000
  242. #define CSR_F_500M 500000000
  243. #define CSR_F_800M 800000000
  244. #define MAC_CSR_H_FRQ_MASK 0x20
  245. #define HASH_TABLE_SIZE 64
  246. #define PAUSE_TIME 0xffff
  247. /* Flow Control defines */
  248. #define FLOW_OFF 0
  249. #define FLOW_RX 1
  250. #define FLOW_TX 2
  251. #define FLOW_AUTO (FLOW_TX | FLOW_RX)
  252. /* PCS defines */
  253. #define STMMAC_PCS_SGMII (1 << 1)
  254. #define SF_DMA_MODE 1 /* DMA STORE-AND-FORWARD Operation Mode */
  255. /* DMA HW feature register fields */
  256. #define DMA_HW_FEAT_MIISEL 0x00000001 /* 10/100 Mbps Support */
  257. #define DMA_HW_FEAT_GMIISEL 0x00000002 /* 1000 Mbps Support */
  258. #define DMA_HW_FEAT_HDSEL 0x00000004 /* Half-Duplex Support */
  259. #define DMA_HW_FEAT_EXTHASHEN 0x00000008 /* Expanded DA Hash Filter */
  260. #define DMA_HW_FEAT_HASHSEL 0x00000010 /* HASH Filter */
  261. #define DMA_HW_FEAT_ADDMAC 0x00000020 /* Multiple MAC Addr Reg */
  262. #define DMA_HW_FEAT_PCSSEL 0x00000040 /* PCS registers */
  263. #define DMA_HW_FEAT_L3L4FLTREN 0x00000080 /* Layer 3 & Layer 4 Feature */
  264. #define DMA_HW_FEAT_SMASEL 0x00000100 /* SMA(MDIO) Interface */
  265. #define DMA_HW_FEAT_RWKSEL 0x00000200 /* PMT Remote Wakeup */
  266. #define DMA_HW_FEAT_MGKSEL 0x00000400 /* PMT Magic Packet */
  267. #define DMA_HW_FEAT_MMCSEL 0x00000800 /* RMON Module */
  268. #define DMA_HW_FEAT_TSVER1SEL 0x00001000 /* Only IEEE 1588-2002 */
  269. #define DMA_HW_FEAT_TSVER2SEL 0x00002000 /* IEEE 1588-2008 PTPv2 */
  270. #define DMA_HW_FEAT_EEESEL 0x00004000 /* Energy Efficient Ethernet */
  271. #define DMA_HW_FEAT_AVSEL 0x00008000 /* AV Feature */
  272. #define DMA_HW_FEAT_TXCOESEL 0x00010000 /* Checksum Offload in Tx */
  273. #define DMA_HW_FEAT_RXTYP1COE 0x00020000 /* IP COE (Type 1) in Rx */
  274. #define DMA_HW_FEAT_RXTYP2COE 0x00040000 /* IP COE (Type 2) in Rx */
  275. #define DMA_HW_FEAT_RXFIFOSIZE 0x00080000 /* Rx FIFO > 2048 Bytes */
  276. #define DMA_HW_FEAT_RXCHCNT 0x00300000 /* No. additional Rx Channels */
  277. #define DMA_HW_FEAT_TXCHCNT 0x00c00000 /* No. additional Tx Channels */
  278. #define DMA_HW_FEAT_ENHDESSEL 0x01000000 /* Alternate Descriptor */
  279. /* Timestamping with Internal System Time */
  280. #define DMA_HW_FEAT_INTTSEN 0x02000000
  281. #define DMA_HW_FEAT_FLEXIPPSEN 0x04000000 /* Flexible PPS Output */
  282. #define DMA_HW_FEAT_SAVLANINS 0x08000000 /* Source Addr or VLAN */
  283. #define DMA_HW_FEAT_ACTPHYIF 0x70000000 /* Active/selected PHY iface */
  284. #define DEFAULT_DMA_PBL 8
  285. /* phy_intf_sel_i and ACTPHYIF encodings */
  286. #define PHY_INTF_SEL_GMII_MII 0
  287. #define PHY_INTF_SEL_RGMII 1
  288. #define PHY_INTF_SEL_SGMII 2
  289. #define PHY_INTF_SEL_TBI 3
  290. #define PHY_INTF_SEL_RMII 4
  291. #define PHY_INTF_SEL_RTBI 5
  292. #define PHY_INTF_SEL_SMII 6
  293. #define PHY_INTF_SEL_REVMII 7
  294. /* XGMAC uses a different encoding - from the AgileX5 documentation */
  295. #define PHY_INTF_GMII 0
  296. #define PHY_INTF_RGMII 1
  297. /* MSI defines */
  298. #define STMMAC_MSI_VEC_MAX 32
  299. /* PCS status and mask defines */
  300. #define PCS_ANE_IRQ BIT(2) /* PCS Auto-Negotiation */
  301. #define PCS_LINK_IRQ BIT(1) /* PCS Link */
  302. #define PCS_RGSMIIIS_IRQ BIT(0) /* RGMII or SMII Interrupt */
  303. /* Max/Min RI Watchdog Timer count value */
  304. #define MAX_DMA_RIWT 0xff
  305. #define MIN_DMA_RIWT 0x10
  306. #define DEF_DMA_RIWT 0xa0
  307. /* Tx coalesce parameters */
  308. #define STMMAC_COAL_TX_TIMER 5000
  309. #define STMMAC_MAX_COAL_TX_TICK 100000
  310. #define STMMAC_TX_MAX_FRAMES 256
  311. #define STMMAC_TX_FRAMES 25
  312. #define STMMAC_RX_FRAMES 0
  313. /* Packets types */
  314. enum packets_types {
  315. PACKET_AVCPQ = 0x1, /* AV Untagged Control packets */
  316. PACKET_PTPQ = 0x2, /* PTP Packets */
  317. PACKET_DCBCPQ = 0x3, /* DCB Control Packets */
  318. PACKET_UPQ = 0x4, /* Untagged Packets */
  319. PACKET_MCBCQ = 0x5, /* Multicast & Broadcast Packets */
  320. };
  321. /* Rx IPC status */
  322. enum rx_frame_status {
  323. good_frame = 0x0,
  324. discard_frame = 0x1,
  325. csum_none = 0x2,
  326. llc_snap = 0x4,
  327. dma_own = 0x8,
  328. rx_not_ls = 0x10,
  329. };
  330. /* Tx status */
  331. enum tx_frame_status {
  332. tx_done = 0x0,
  333. tx_not_ls = 0x1,
  334. tx_err = 0x2,
  335. tx_dma_own = 0x4,
  336. tx_err_bump_tc = 0x8,
  337. };
  338. enum dma_irq_status {
  339. tx_hard_error = 0x1,
  340. tx_hard_error_bump_tc = 0x2,
  341. handle_rx = 0x4,
  342. handle_tx = 0x8,
  343. };
  344. enum dma_irq_dir {
  345. DMA_DIR_RX = 0x1,
  346. DMA_DIR_TX = 0x2,
  347. DMA_DIR_RXTX = 0x3,
  348. };
  349. enum request_irq_err {
  350. REQ_IRQ_ERR_ALL,
  351. REQ_IRQ_ERR_TX,
  352. REQ_IRQ_ERR_RX,
  353. REQ_IRQ_ERR_SFTY,
  354. REQ_IRQ_ERR_SFTY_UE,
  355. REQ_IRQ_ERR_SFTY_CE,
  356. REQ_IRQ_ERR_WOL,
  357. REQ_IRQ_ERR_MAC,
  358. REQ_IRQ_ERR_NO,
  359. };
  360. /* EEE and LPI defines */
  361. #define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0)
  362. #define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1)
  363. #define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2)
  364. #define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 3)
  365. /* FPE defines */
  366. #define FPE_EVENT_UNKNOWN 0
  367. #define FPE_EVENT_TRSP BIT(0)
  368. #define FPE_EVENT_TVER BIT(1)
  369. #define FPE_EVENT_RRSP BIT(2)
  370. #define FPE_EVENT_RVER BIT(3)
  371. #define CORE_IRQ_MTL_RX_OVERFLOW BIT(8)
  372. /* DMA HW capabilities */
  373. struct dma_features {
  374. unsigned int mbps_10_100;
  375. unsigned int mbps_1000;
  376. unsigned int half_duplex;
  377. unsigned int hash_filter;
  378. unsigned int multi_addr;
  379. unsigned int pcs;
  380. unsigned int sma_mdio;
  381. unsigned int pmt_remote_wake_up;
  382. unsigned int pmt_magic_frame;
  383. unsigned int rmon;
  384. /* IEEE 1588-2002 */
  385. unsigned int time_stamp;
  386. /* IEEE 1588-2008 */
  387. unsigned int atime_stamp;
  388. /* 802.3az - Energy-Efficient Ethernet (EEE) */
  389. unsigned int eee;
  390. unsigned int av;
  391. unsigned int hash_tb_sz;
  392. unsigned int tsoen;
  393. /* TX and RX csum */
  394. unsigned int tx_coe;
  395. unsigned int rx_coe;
  396. unsigned int rx_coe_type1;
  397. unsigned int rx_coe_type2;
  398. unsigned int rxfifo_over_2048;
  399. /* TX and RX number of channels */
  400. unsigned int number_rx_channel;
  401. unsigned int number_tx_channel;
  402. /* TX and RX number of queues */
  403. unsigned int number_rx_queues;
  404. unsigned int number_tx_queues;
  405. /* PPS output */
  406. unsigned int pps_out_num;
  407. /* Number of Traffic Classes */
  408. unsigned int numtc;
  409. /* DCB Feature Enable */
  410. unsigned int dcben;
  411. /* IEEE 1588 High Word Register Enable */
  412. unsigned int advthword;
  413. /* PTP Offload Enable */
  414. unsigned int ptoen;
  415. /* One-Step Timestamping Enable */
  416. unsigned int osten;
  417. /* Priority-Based Flow Control Enable */
  418. unsigned int pfcen;
  419. /* Alternate (enhanced) DESC mode */
  420. unsigned int enh_desc;
  421. /* TX and RX FIFO sizes */
  422. unsigned int tx_fifo_size;
  423. unsigned int rx_fifo_size;
  424. /* Automotive Safety Package */
  425. unsigned int asp;
  426. /* RX Parser */
  427. unsigned int frpsel;
  428. unsigned int frpbs;
  429. unsigned int frpes;
  430. unsigned int addr64;
  431. unsigned int host_dma_width;
  432. unsigned int rssen;
  433. unsigned int vlhash;
  434. unsigned int sphen;
  435. unsigned int vlins;
  436. unsigned int dvlan;
  437. unsigned int l3l4fnum;
  438. unsigned int arpoffsel;
  439. /* One Step for PTP over UDP/IP Feature Enable */
  440. unsigned int pou_ost_en;
  441. /* Tx Timestamp FIFO Depth */
  442. unsigned int ttsfd;
  443. /* Queue/Channel-Based VLAN tag insertion on Tx */
  444. unsigned int cbtisel;
  445. /* Supported Parallel Instruction Processor Engines */
  446. unsigned int frppipe_num;
  447. /* Number of Extended VLAN Tag Filters */
  448. unsigned int nrvf_num;
  449. /* TSN Features */
  450. unsigned int estwid;
  451. unsigned int estdep;
  452. unsigned int estsel;
  453. unsigned int fpesel;
  454. unsigned int tbssel;
  455. /* Number of DMA channels enabled for TBS */
  456. unsigned int tbs_ch_num;
  457. /* Per-Stream Filtering Enable */
  458. unsigned int sgfsel;
  459. /* Numbers of Auxiliary Snapshot Inputs */
  460. unsigned int aux_snapshot_n;
  461. /* Timestamp System Time Source */
  462. unsigned int tssrc;
  463. /* Enhanced DMA Enable */
  464. unsigned int edma;
  465. /* Different Descriptor Cache Enable */
  466. unsigned int ediffc;
  467. /* VxLAN/NVGRE Enable */
  468. unsigned int vxn;
  469. /* Debug Memory Interface Enable */
  470. unsigned int dbgmem;
  471. /* Number of Policing Counters */
  472. unsigned int pcsel;
  473. /* Active PHY interface, PHY_INTF_SEL_xxx */
  474. u8 actphyif;
  475. };
  476. /* RX Buffer size must be multiple of 4/8/16 bytes */
  477. #define BUF_SIZE_16KiB 16368
  478. #define BUF_SIZE_8KiB 8188
  479. #define BUF_SIZE_4KiB 4096
  480. #define BUF_SIZE_2KiB 2048
  481. /* Power Down and WOL */
  482. #define PMT_NOT_SUPPORTED 0
  483. #define PMT_SUPPORTED 1
  484. /* Common MAC defines */
  485. #define MAC_CTRL_REG 0x00000000 /* MAC Control */
  486. #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
  487. #define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */
  488. /* Default LPI timers */
  489. #define STMMAC_DEFAULT_LIT_LS 0x3E8
  490. #define STMMAC_DEFAULT_TWT_LS 0x1E
  491. #define STMMAC_ET_MAX 0xFFFFF
  492. /* Common LPI register bits */
  493. #define LPI_CTRL_STATUS_LPITCSE BIT(21) /* LPI Tx Clock Stop Enable, gmac4, xgmac2 only */
  494. #define LPI_CTRL_STATUS_LPIATE BIT(20) /* LPI Timer Enable, gmac4 only */
  495. #define LPI_CTRL_STATUS_LPITXA BIT(19) /* Enable LPI TX Automate */
  496. #define LPI_CTRL_STATUS_PLSEN BIT(18) /* Enable PHY Link Status */
  497. #define LPI_CTRL_STATUS_PLS BIT(17) /* PHY Link Status */
  498. #define LPI_CTRL_STATUS_LPIEN BIT(16) /* LPI Enable */
  499. #define LPI_CTRL_STATUS_RLPIST BIT(9) /* Receive LPI state, gmac1000 only? */
  500. #define LPI_CTRL_STATUS_TLPIST BIT(8) /* Transmit LPI state, gmac1000 only? */
  501. #define LPI_CTRL_STATUS_RLPIEX BIT(3) /* Receive LPI Exit */
  502. #define LPI_CTRL_STATUS_RLPIEN BIT(2) /* Receive LPI Entry */
  503. #define LPI_CTRL_STATUS_TLPIEX BIT(1) /* Transmit LPI Exit */
  504. #define LPI_CTRL_STATUS_TLPIEN BIT(0) /* Transmit LPI Entry */
  505. /* Common definitions for AXI Master Bus Mode */
  506. #define DMA_AXI_AAL BIT(12)
  507. #define DMA_AXI_BLEN256 BIT(7)
  508. #define DMA_AXI_BLEN128 BIT(6)
  509. #define DMA_AXI_BLEN64 BIT(5)
  510. #define DMA_AXI_BLEN32 BIT(4)
  511. #define DMA_AXI_BLEN16 BIT(3)
  512. #define DMA_AXI_BLEN8 BIT(2)
  513. #define DMA_AXI_BLEN4 BIT(1)
  514. #define DMA_AXI_BLEN_MASK GENMASK(7, 1)
  515. void stmmac_axi_blen_to_mask(u32 *regval, const u32 *blen, size_t len);
  516. #define STMMAC_CHAIN_MODE 0x1
  517. #define STMMAC_RING_MODE 0x2
  518. #define JUMBO_LEN 9000
  519. /* Receive Side Scaling */
  520. #define STMMAC_RSS_HASH_KEY_SIZE 40
  521. #define STMMAC_RSS_MAX_TABLE_SIZE 256
  522. /* VLAN */
  523. #define STMMAC_VLAN_NONE 0x0
  524. #define STMMAC_VLAN_REMOVE 0x1
  525. #define STMMAC_VLAN_INSERT 0x2
  526. #define STMMAC_VLAN_REPLACE 0x3
  527. struct mac_device_info;
  528. struct mac_link {
  529. u32 caps;
  530. u32 speed_mask;
  531. u32 speed10;
  532. u32 speed100;
  533. u32 speed1000;
  534. u32 speed2500;
  535. u32 duplex;
  536. struct {
  537. u32 speed2500;
  538. u32 speed5000;
  539. u32 speed10000;
  540. } xgmii;
  541. struct {
  542. u32 speed25000;
  543. u32 speed40000;
  544. u32 speed50000;
  545. u32 speed100000;
  546. } xlgmii;
  547. };
  548. struct mii_regs {
  549. unsigned int addr; /* MII Address */
  550. unsigned int data; /* MII Data */
  551. unsigned int addr_shift; /* MII address shift */
  552. unsigned int reg_shift; /* MII reg shift */
  553. unsigned int addr_mask; /* MII address mask */
  554. unsigned int reg_mask; /* MII reg mask */
  555. unsigned int clk_csr_shift;
  556. unsigned int clk_csr_mask;
  557. };
  558. struct mac_device_info {
  559. const struct stmmac_ops *mac;
  560. const struct stmmac_desc_ops *desc;
  561. const struct stmmac_dma_ops *dma;
  562. const struct stmmac_mode_ops *mode;
  563. const struct stmmac_hwtimestamp *ptp;
  564. const struct stmmac_tc_ops *tc;
  565. const struct stmmac_mmc_ops *mmc;
  566. const struct stmmac_est_ops *est;
  567. const struct stmmac_vlan_ops *vlan;
  568. struct dw_xpcs *xpcs;
  569. struct phylink_pcs *phylink_pcs;
  570. struct mii_regs mii; /* MII register Addresses */
  571. struct mac_link link;
  572. void __iomem *pcsr; /* vpointer to device CSRs */
  573. unsigned int multicast_filter_bins;
  574. unsigned int unicast_filter_entries;
  575. unsigned int mcast_bits_log2;
  576. unsigned int rx_csum;
  577. unsigned int pcs;
  578. unsigned int xlgmac;
  579. unsigned int num_vlan;
  580. u32 vlan_filter[32];
  581. bool vlan_fail_q_en;
  582. u8 vlan_fail_q;
  583. bool hw_vlan_en;
  584. bool reverse_sgmii_enable;
  585. /* This spinlock protects read-modify-write of the interrupt
  586. * mask/enable registers.
  587. */
  588. spinlock_t irq_ctrl_lock;
  589. };
  590. struct stmmac_rx_routing {
  591. u32 reg_mask;
  592. u32 reg_shift;
  593. };
  594. int dwmac100_setup(struct stmmac_priv *priv);
  595. int dwmac1000_setup(struct stmmac_priv *priv);
  596. int dwmac4_setup(struct stmmac_priv *priv);
  597. int dwxgmac2_setup(struct stmmac_priv *priv);
  598. int dwxlgmac2_setup(struct stmmac_priv *priv);
  599. void stmmac_set_mac_addr(void __iomem *ioaddr, const u8 addr[6],
  600. unsigned int high, unsigned int low);
  601. void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
  602. unsigned int high, unsigned int low);
  603. void stmmac_set_mac(void __iomem *ioaddr, bool enable);
  604. void stmmac_dwmac4_set_mac_addr(void __iomem *ioaddr, const u8 addr[6],
  605. unsigned int high, unsigned int low);
  606. void stmmac_dwmac4_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
  607. unsigned int high, unsigned int low);
  608. void stmmac_dwmac4_set_mac(void __iomem *ioaddr, bool enable);
  609. void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
  610. #endif /* __COMMON_H__ */