1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /******************************************************************************* 3 STMMAC Common Header File 4 5 Copyright (C) 2007-2009 STMicroelectronics Ltd 6 7 8 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> 9 *******************************************************************************/ 10 11 #ifndef __COMMON_H__ 12 #define __COMMON_H__ 13 14 #include <linux/etherdevice.h> 15 #include <linux/netdevice.h> 16 #include <linux/stmmac.h> 17 #include <linux/phy.h> 18 #include <linux/module.h> 19 #if IS_ENABLED(CONFIG_VLAN_8021Q) 20 #define STMMAC_VLAN_TAG_USED 21 #include <linux/if_vlan.h> 22 #endif 23 24 #include "descs.h" 25 #include "hwif.h" 26 #include "mmc.h" 27 28 /* Synopsys Core versions */ 29 #define DWMAC_CORE_3_40 0x34 30 #define DWMAC_CORE_3_50 0x35 31 #define DWMAC_CORE_4_00 0x40 32 #define DWMAC_CORE_4_10 0x41 33 #define DWMAC_CORE_5_00 0x50 34 #define DWMAC_CORE_5_10 0x51 35 #define DWXGMAC_CORE_2_10 0x21 36 37 #define STMMAC_CHAN0 0 /* Always supported and default for all chips */ 38 39 /* These need to be power of two, and >= 4 */ 40 #define DMA_TX_SIZE 512 41 #define DMA_RX_SIZE 512 42 #define STMMAC_GET_ENTRY(x, size) ((x + 1) & (size - 1)) 43 44 #undef FRAME_FILTER_DEBUG 45 /* #define FRAME_FILTER_DEBUG */ 46 47 /* Extra statistic and debug information exposed by ethtool */ 48 struct stmmac_extra_stats { 49 /* Transmit errors */ 50 unsigned long tx_underflow ____cacheline_aligned; 51 unsigned long tx_carrier; 52 unsigned long tx_losscarrier; 53 unsigned long vlan_tag; 54 unsigned long tx_deferred; 55 unsigned long tx_vlan; 56 unsigned long tx_jabber; 57 unsigned long tx_frame_flushed; 58 unsigned long tx_payload_error; 59 unsigned long tx_ip_header_error; 60 /* Receive errors */ 61 unsigned long rx_desc; 62 unsigned long sa_filter_fail; 63 unsigned long overflow_error; 64 unsigned long ipc_csum_error; 65 unsigned long rx_collision; 66 unsigned long rx_crc_errors; 67 unsigned long dribbling_bit; 68 unsigned long rx_length; 69 unsigned long rx_mii; 70 unsigned long rx_multicast; 71 unsigned long rx_gmac_overflow; 72 unsigned long rx_watchdog; 73 unsigned long da_rx_filter_fail; 74 unsigned long sa_rx_filter_fail; 75 unsigned long rx_missed_cntr; 76 unsigned long rx_overflow_cntr; 77 unsigned long rx_vlan; 78 /* Tx/Rx IRQ error info */ 79 unsigned long tx_undeflow_irq; 80 unsigned long tx_process_stopped_irq; 81 unsigned long tx_jabber_irq; 82 unsigned long rx_overflow_irq; 83 unsigned long rx_buf_unav_irq; 84 unsigned long rx_process_stopped_irq; 85 unsigned long rx_watchdog_irq; 86 unsigned long tx_early_irq; 87 unsigned long fatal_bus_error_irq; 88 /* Tx/Rx IRQ Events */ 89 unsigned long rx_early_irq; 90 unsigned long threshold; 91 unsigned long tx_pkt_n; 92 unsigned long rx_pkt_n; 93 unsigned long normal_irq_n; 94 unsigned long rx_normal_irq_n; 95 unsigned long napi_poll; 96 unsigned long tx_normal_irq_n; 97 unsigned long tx_clean; 98 unsigned long tx_set_ic_bit; 99 unsigned long irq_receive_pmt_irq_n; 100 /* MMC info */ 101 unsigned long mmc_tx_irq_n; 102 unsigned long mmc_rx_irq_n; 103 unsigned long mmc_rx_csum_offload_irq_n; 104 /* EEE */ 105 unsigned long irq_tx_path_in_lpi_mode_n; 106 unsigned long irq_tx_path_exit_lpi_mode_n; 107 unsigned long irq_rx_path_in_lpi_mode_n; 108 unsigned long irq_rx_path_exit_lpi_mode_n; 109 unsigned long phy_eee_wakeup_error_n; 110 /* Extended RDES status */ 111 unsigned long ip_hdr_err; 112 unsigned long ip_payload_err; 113 unsigned long ip_csum_bypassed; 114 unsigned long ipv4_pkt_rcvd; 115 unsigned long ipv6_pkt_rcvd; 116 unsigned long no_ptp_rx_msg_type_ext; 117 unsigned long ptp_rx_msg_type_sync; 118 unsigned long ptp_rx_msg_type_follow_up; 119 unsigned long ptp_rx_msg_type_delay_req; 120 unsigned long ptp_rx_msg_type_delay_resp; 121 unsigned long ptp_rx_msg_type_pdelay_req; 122 unsigned long ptp_rx_msg_type_pdelay_resp; 123 unsigned long ptp_rx_msg_type_pdelay_follow_up; 124 unsigned long ptp_rx_msg_type_announce; 125 unsigned long ptp_rx_msg_type_management; 126 unsigned long ptp_rx_msg_pkt_reserved_type; 127 unsigned long ptp_frame_type; 128 unsigned long ptp_ver; 129 unsigned long timestamp_dropped; 130 unsigned long av_pkt_rcvd; 131 unsigned long av_tagged_pkt_rcvd; 132 unsigned long vlan_tag_priority_val; 133 unsigned long l3_filter_match; 134 unsigned long l4_filter_match; 135 unsigned long l3_l4_filter_no_match; 136 /* PCS */ 137 unsigned long irq_pcs_ane_n; 138 unsigned long irq_pcs_link_n; 139 unsigned long irq_rgmii_n; 140 unsigned long pcs_link; 141 unsigned long pcs_duplex; 142 unsigned long pcs_speed; 143 /* debug register */ 144 unsigned long mtl_tx_status_fifo_full; 145 unsigned long mtl_tx_fifo_not_empty; 146 unsigned long mmtl_fifo_ctrl; 147 unsigned long mtl_tx_fifo_read_ctrl_write; 148 unsigned long mtl_tx_fifo_read_ctrl_wait; 149 unsigned long mtl_tx_fifo_read_ctrl_read; 150 unsigned long mtl_tx_fifo_read_ctrl_idle; 151 unsigned long mac_tx_in_pause; 152 unsigned long mac_tx_frame_ctrl_xfer; 153 unsigned long mac_tx_frame_ctrl_idle; 154 unsigned long mac_tx_frame_ctrl_wait; 155 unsigned long mac_tx_frame_ctrl_pause; 156 unsigned long mac_gmii_tx_proto_engine; 157 unsigned long mtl_rx_fifo_fill_level_full; 158 unsigned long mtl_rx_fifo_fill_above_thresh; 159 unsigned long mtl_rx_fifo_fill_below_thresh; 160 unsigned long mtl_rx_fifo_fill_level_empty; 161 unsigned long mtl_rx_fifo_read_ctrl_flush; 162 unsigned long mtl_rx_fifo_read_ctrl_read_data; 163 unsigned long mtl_rx_fifo_read_ctrl_status; 164 unsigned long mtl_rx_fifo_read_ctrl_idle; 165 unsigned long mtl_rx_fifo_ctrl_active; 166 unsigned long mac_rx_frame_ctrl_fifo; 167 unsigned long mac_gmii_rx_proto_engine; 168 /* TSO */ 169 unsigned long tx_tso_frames; 170 unsigned long tx_tso_nfrags; 171 }; 172 173 /* Safety Feature statistics exposed by ethtool */ 174 struct stmmac_safety_stats { 175 unsigned long mac_errors[32]; 176 unsigned long mtl_errors[32]; 177 unsigned long dma_errors[32]; 178 }; 179 180 /* Number of fields in Safety Stats */ 181 #define STMMAC_SAFETY_FEAT_SIZE \ 182 (sizeof(struct stmmac_safety_stats) / sizeof(unsigned long)) 183 184 /* CSR Frequency Access Defines*/ 185 #define CSR_F_35M 35000000 186 #define CSR_F_60M 60000000 187 #define CSR_F_100M 100000000 188 #define CSR_F_150M 150000000 189 #define CSR_F_250M 250000000 190 #define CSR_F_300M 300000000 191 192 #define MAC_CSR_H_FRQ_MASK 0x20 193 194 #define HASH_TABLE_SIZE 64 195 #define PAUSE_TIME 0xffff 196 197 /* Flow Control defines */ 198 #define FLOW_OFF 0 199 #define FLOW_RX 1 200 #define FLOW_TX 2 201 #define FLOW_AUTO (FLOW_TX | FLOW_RX) 202 203 /* PCS defines */ 204 #define STMMAC_PCS_RGMII (1 << 0) 205 #define STMMAC_PCS_SGMII (1 << 1) 206 #define STMMAC_PCS_TBI (1 << 2) 207 #define STMMAC_PCS_RTBI (1 << 3) 208 209 #define SF_DMA_MODE 1 /* DMA STORE-AND-FORWARD Operation Mode */ 210 211 /* DAM HW feature register fields */ 212 #define DMA_HW_FEAT_MIISEL 0x00000001 /* 10/100 Mbps Support */ 213 #define DMA_HW_FEAT_GMIISEL 0x00000002 /* 1000 Mbps Support */ 214 #define DMA_HW_FEAT_HDSEL 0x00000004 /* Half-Duplex Support */ 215 #define DMA_HW_FEAT_EXTHASHEN 0x00000008 /* Expanded DA Hash Filter */ 216 #define DMA_HW_FEAT_HASHSEL 0x00000010 /* HASH Filter */ 217 #define DMA_HW_FEAT_ADDMAC 0x00000020 /* Multiple MAC Addr Reg */ 218 #define DMA_HW_FEAT_PCSSEL 0x00000040 /* PCS registers */ 219 #define DMA_HW_FEAT_L3L4FLTREN 0x00000080 /* Layer 3 & Layer 4 Feature */ 220 #define DMA_HW_FEAT_SMASEL 0x00000100 /* SMA(MDIO) Interface */ 221 #define DMA_HW_FEAT_RWKSEL 0x00000200 /* PMT Remote Wakeup */ 222 #define DMA_HW_FEAT_MGKSEL 0x00000400 /* PMT Magic Packet */ 223 #define DMA_HW_FEAT_MMCSEL 0x00000800 /* RMON Module */ 224 #define DMA_HW_FEAT_TSVER1SEL 0x00001000 /* Only IEEE 1588-2002 */ 225 #define DMA_HW_FEAT_TSVER2SEL 0x00002000 /* IEEE 1588-2008 PTPv2 */ 226 #define DMA_HW_FEAT_EEESEL 0x00004000 /* Energy Efficient Ethernet */ 227 #define DMA_HW_FEAT_AVSEL 0x00008000 /* AV Feature */ 228 #define DMA_HW_FEAT_TXCOESEL 0x00010000 /* Checksum Offload in Tx */ 229 #define DMA_HW_FEAT_RXTYP1COE 0x00020000 /* IP COE (Type 1) in Rx */ 230 #define DMA_HW_FEAT_RXTYP2COE 0x00040000 /* IP COE (Type 2) in Rx */ 231 #define DMA_HW_FEAT_RXFIFOSIZE 0x00080000 /* Rx FIFO > 2048 Bytes */ 232 #define DMA_HW_FEAT_RXCHCNT 0x00300000 /* No. additional Rx Channels */ 233 #define DMA_HW_FEAT_TXCHCNT 0x00c00000 /* No. additional Tx Channels */ 234 #define DMA_HW_FEAT_ENHDESSEL 0x01000000 /* Alternate Descriptor */ 235 /* Timestamping with Internal System Time */ 236 #define DMA_HW_FEAT_INTTSEN 0x02000000 237 #define DMA_HW_FEAT_FLEXIPPSEN 0x04000000 /* Flexible PPS Output */ 238 #define DMA_HW_FEAT_SAVLANINS 0x08000000 /* Source Addr or VLAN */ 239 #define DMA_HW_FEAT_ACTPHYIF 0x70000000 /* Active/selected PHY iface */ 240 #define DEFAULT_DMA_PBL 8 241 242 /* PCS status and mask defines */ 243 #define PCS_ANE_IRQ BIT(2) /* PCS Auto-Negotiation */ 244 #define PCS_LINK_IRQ BIT(1) /* PCS Link */ 245 #define PCS_RGSMIIIS_IRQ BIT(0) /* RGMII or SMII Interrupt */ 246 247 /* Max/Min RI Watchdog Timer count value */ 248 #define MAX_DMA_RIWT 0xff 249 #define MIN_DMA_RIWT 0x10 250 /* Tx coalesce parameters */ 251 #define STMMAC_COAL_TX_TIMER 1000 252 #define STMMAC_MAX_COAL_TX_TICK 100000 253 #define STMMAC_TX_MAX_FRAMES 256 254 #define STMMAC_TX_FRAMES 1 255 #define STMMAC_RX_FRAMES 25 256 257 /* Packets types */ 258 enum packets_types { 259 PACKET_AVCPQ = 0x1, /* AV Untagged Control packets */ 260 PACKET_PTPQ = 0x2, /* PTP Packets */ 261 PACKET_DCBCPQ = 0x3, /* DCB Control Packets */ 262 PACKET_UPQ = 0x4, /* Untagged Packets */ 263 PACKET_MCBCQ = 0x5, /* Multicast & Broadcast Packets */ 264 }; 265 266 /* Rx IPC status */ 267 enum rx_frame_status { 268 good_frame = 0x0, 269 discard_frame = 0x1, 270 csum_none = 0x2, 271 llc_snap = 0x4, 272 dma_own = 0x8, 273 rx_not_ls = 0x10, 274 }; 275 276 /* Tx status */ 277 enum tx_frame_status { 278 tx_done = 0x0, 279 tx_not_ls = 0x1, 280 tx_err = 0x2, 281 tx_dma_own = 0x4, 282 }; 283 284 enum dma_irq_status { 285 tx_hard_error = 0x1, 286 tx_hard_error_bump_tc = 0x2, 287 handle_rx = 0x4, 288 handle_tx = 0x8, 289 }; 290 291 /* EEE and LPI defines */ 292 #define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0) 293 #define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1) 294 #define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2) 295 #define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 3) 296 297 #define CORE_IRQ_MTL_RX_OVERFLOW BIT(8) 298 299 /* Physical Coding Sublayer */ 300 struct rgmii_adv { 301 unsigned int pause; 302 unsigned int duplex; 303 unsigned int lp_pause; 304 unsigned int lp_duplex; 305 }; 306 307 #define STMMAC_PCS_PAUSE 1 308 #define STMMAC_PCS_ASYM_PAUSE 2 309 310 /* DMA HW capabilities */ 311 struct dma_features { 312 unsigned int mbps_10_100; 313 unsigned int mbps_1000; 314 unsigned int half_duplex; 315 unsigned int hash_filter; 316 unsigned int multi_addr; 317 unsigned int pcs; 318 unsigned int sma_mdio; 319 unsigned int pmt_remote_wake_up; 320 unsigned int pmt_magic_frame; 321 unsigned int rmon; 322 /* IEEE 1588-2002 */ 323 unsigned int time_stamp; 324 /* IEEE 1588-2008 */ 325 unsigned int atime_stamp; 326 /* 802.3az - Energy-Efficient Ethernet (EEE) */ 327 unsigned int eee; 328 unsigned int av; 329 unsigned int hash_tb_sz; 330 unsigned int tsoen; 331 /* TX and RX csum */ 332 unsigned int tx_coe; 333 unsigned int rx_coe; 334 unsigned int rx_coe_type1; 335 unsigned int rx_coe_type2; 336 unsigned int rxfifo_over_2048; 337 /* TX and RX number of channels */ 338 unsigned int number_rx_channel; 339 unsigned int number_tx_channel; 340 /* TX and RX number of queues */ 341 unsigned int number_rx_queues; 342 unsigned int number_tx_queues; 343 /* PPS output */ 344 unsigned int pps_out_num; 345 /* Alternate (enhanced) DESC mode */ 346 unsigned int enh_desc; 347 /* TX and RX FIFO sizes */ 348 unsigned int tx_fifo_size; 349 unsigned int rx_fifo_size; 350 /* Automotive Safety Package */ 351 unsigned int asp; 352 /* RX Parser */ 353 unsigned int frpsel; 354 unsigned int frpbs; 355 unsigned int frpes; 356 unsigned int addr64; 357 }; 358 359 /* GMAC TX FIFO is 8K, Rx FIFO is 16K */ 360 #define BUF_SIZE_16KiB 16384 361 /* RX Buffer size must be < 8191 and multiple of 4/8/16 bytes */ 362 #define BUF_SIZE_8KiB 8188 363 #define BUF_SIZE_4KiB 4096 364 #define BUF_SIZE_2KiB 2048 365 366 /* Power Down and WOL */ 367 #define PMT_NOT_SUPPORTED 0 368 #define PMT_SUPPORTED 1 369 370 /* Common MAC defines */ 371 #define MAC_CTRL_REG 0x00000000 /* MAC Control */ 372 #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */ 373 #define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */ 374 375 /* Default LPI timers */ 376 #define STMMAC_DEFAULT_LIT_LS 0x3E8 377 #define STMMAC_DEFAULT_TWT_LS 0x1E 378 379 #define STMMAC_CHAIN_MODE 0x1 380 #define STMMAC_RING_MODE 0x2 381 382 #define JUMBO_LEN 9000 383 384 extern const struct stmmac_desc_ops enh_desc_ops; 385 extern const struct stmmac_desc_ops ndesc_ops; 386 387 struct mac_device_info; 388 389 extern const struct stmmac_hwtimestamp stmmac_ptp; 390 extern const struct stmmac_mode_ops dwmac4_ring_mode_ops; 391 392 struct mac_link { 393 u32 speed_mask; 394 u32 speed10; 395 u32 speed100; 396 u32 speed1000; 397 u32 speed2500; 398 u32 duplex; 399 struct { 400 u32 speed2500; 401 u32 speed5000; 402 u32 speed10000; 403 } xgmii; 404 }; 405 406 struct mii_regs { 407 unsigned int addr; /* MII Address */ 408 unsigned int data; /* MII Data */ 409 unsigned int addr_shift; /* MII address shift */ 410 unsigned int reg_shift; /* MII reg shift */ 411 unsigned int addr_mask; /* MII address mask */ 412 unsigned int reg_mask; /* MII reg mask */ 413 unsigned int clk_csr_shift; 414 unsigned int clk_csr_mask; 415 }; 416 417 struct mac_device_info { 418 const struct stmmac_ops *mac; 419 const struct stmmac_desc_ops *desc; 420 const struct stmmac_dma_ops *dma; 421 const struct stmmac_mode_ops *mode; 422 const struct stmmac_hwtimestamp *ptp; 423 const struct stmmac_tc_ops *tc; 424 const struct stmmac_mmc_ops *mmc; 425 struct mii_regs mii; /* MII register Addresses */ 426 struct mac_link link; 427 void __iomem *pcsr; /* vpointer to device CSRs */ 428 unsigned int multicast_filter_bins; 429 unsigned int unicast_filter_entries; 430 unsigned int mcast_bits_log2; 431 unsigned int rx_csum; 432 unsigned int pcs; 433 unsigned int pmt; 434 unsigned int ps; 435 }; 436 437 struct stmmac_rx_routing { 438 u32 reg_mask; 439 u32 reg_shift; 440 }; 441 442 int dwmac100_setup(struct stmmac_priv *priv); 443 int dwmac1000_setup(struct stmmac_priv *priv); 444 int dwmac4_setup(struct stmmac_priv *priv); 445 int dwxgmac2_setup(struct stmmac_priv *priv); 446 447 void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6], 448 unsigned int high, unsigned int low); 449 void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr, 450 unsigned int high, unsigned int low); 451 void stmmac_set_mac(void __iomem *ioaddr, bool enable); 452 453 void stmmac_dwmac4_set_mac_addr(void __iomem *ioaddr, u8 addr[6], 454 unsigned int high, unsigned int low); 455 void stmmac_dwmac4_get_mac_addr(void __iomem *ioaddr, unsigned char *addr, 456 unsigned int high, unsigned int low); 457 void stmmac_dwmac4_set_mac(void __iomem *ioaddr, bool enable); 458 459 void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 460 461 extern const struct stmmac_mode_ops ring_mode_ops; 462 extern const struct stmmac_mode_ops chain_mode_ops; 463 extern const struct stmmac_desc_ops dwmac4_desc_ops; 464 465 #endif /* __COMMON_H__ */ 466