linux/drivers/net/ethernet/xilinx/xilinx_axienet.h
<<
>>
Prefs
   1/*
   2 * Definitions for Xilinx Axi Ethernet device driver.
   3 *
   4 * Copyright (c) 2009 Secret Lab Technologies, Ltd.
   5 * Copyright (c) 2010 - 2012 Xilinx, Inc. All rights reserved.
   6 */
   7
   8#ifndef XILINX_AXIENET_H
   9#define XILINX_AXIENET_H
  10
  11#include <linux/netdevice.h>
  12#include <linux/spinlock.h>
  13#include <linux/interrupt.h>
  14#include <linux/if_vlan.h>
  15#include <linux/net_tstamp.h>
  16
  17/* Packet size info */
  18#define XAE_HDR_SIZE                    14 /* Size of Ethernet header */
  19#define XAE_TRL_SIZE                     4 /* Size of Ethernet trailer (FCS) */
  20#define XAE_MTU                       1500 /* Max MTU of an Ethernet frame */
  21#define XAE_JUMBO_MTU                 9000 /* Max MTU of a jumbo Eth. frame */
  22
  23#define XAE_MAX_FRAME_SIZE       (XAE_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
  24#define XAE_MAX_VLAN_FRAME_SIZE  (XAE_MTU + VLAN_ETH_HLEN + XAE_TRL_SIZE)
  25#define XAE_MAX_JUMBO_FRAME_SIZE (XAE_JUMBO_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
  26
  27/* Configuration options */
  28
  29/* Accept all incoming packets. Default: disabled (cleared) */
  30#define XAE_OPTION_PROMISC                      BIT(0)
  31
  32/* Jumbo frame support for Tx & Rx. Default: disabled (cleared) */
  33#define XAE_OPTION_JUMBO                        BIT(1)
  34
  35/* VLAN Rx & Tx frame support. Default: disabled (cleared) */
  36#define XAE_OPTION_VLAN                         BIT(2)
  37
  38/* Enable recognition of flow control frames on Rx. Default: enabled (set) */
  39#define XAE_OPTION_FLOW_CONTROL                 BIT(4)
  40
  41/* Strip FCS and PAD from incoming frames. Note: PAD from VLAN frames is not
  42 * stripped. Default: disabled (set)
  43 */
  44#define XAE_OPTION_FCS_STRIP                    BIT(5)
  45
  46/* Generate FCS field and add PAD automatically for outgoing frames.
  47 * Default: enabled (set)
  48 */
  49#define XAE_OPTION_FCS_INSERT                   BIT(6)
  50
  51/* Enable Length/Type error checking for incoming frames. When this option is
  52 * set, the MAC will filter frames that have a mismatched type/length field
  53 * and if XAE_OPTION_REPORT_RXERR is set, the user is notified when these
  54 * types of frames are encountered. When this option is cleared, the MAC will
  55 * allow these types of frames to be received. Default: enabled (set)
  56 */
  57#define XAE_OPTION_LENTYPE_ERR                  BIT(7)
  58
  59/* Enable the transmitter. Default: enabled (set) */
  60#define XAE_OPTION_TXEN                         BIT(11)
  61
  62/*  Enable the receiver. Default: enabled (set) */
  63#define XAE_OPTION_RXEN                         BIT(12)
  64
  65/*  Default options set when device is initialized or reset */
  66#define XAE_OPTION_DEFAULTS                                \
  67                                (XAE_OPTION_TXEN |         \
  68                                 XAE_OPTION_FLOW_CONTROL | \
  69                                 XAE_OPTION_RXEN)
  70
  71/* Axi DMA Register definitions */
  72
  73#define XAXIDMA_TX_CR_OFFSET    0x00000000 /* Channel control */
  74#define XAXIDMA_TX_SR_OFFSET    0x00000004 /* Status */
  75#define XAXIDMA_TX_CDESC_OFFSET 0x00000008 /* Current descriptor pointer */
  76#define XAXIDMA_TX_TDESC_OFFSET 0x00000010 /* Tail descriptor pointer */
  77
  78#define XAXIDMA_RX_CR_OFFSET    0x00000030 /* Channel control */
  79#define XAXIDMA_RX_SR_OFFSET    0x00000034 /* Status */
  80#define XAXIDMA_RX_CDESC_OFFSET 0x00000038 /* Current descriptor pointer */
  81#define XAXIDMA_RX_TDESC_OFFSET 0x00000040 /* Tail descriptor pointer */
  82
  83#define XAXIDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA channel */
  84#define XAXIDMA_CR_RESET_MASK   0x00000004 /* Reset DMA engine */
  85
  86#define XAXIDMA_BD_NDESC_OFFSET         0x00 /* Next descriptor pointer */
  87#define XAXIDMA_BD_BUFA_OFFSET          0x08 /* Buffer address */
  88#define XAXIDMA_BD_CTRL_LEN_OFFSET      0x18 /* Control/buffer length */
  89#define XAXIDMA_BD_STS_OFFSET           0x1C /* Status */
  90#define XAXIDMA_BD_USR0_OFFSET          0x20 /* User IP specific word0 */
  91#define XAXIDMA_BD_USR1_OFFSET          0x24 /* User IP specific word1 */
  92#define XAXIDMA_BD_USR2_OFFSET          0x28 /* User IP specific word2 */
  93#define XAXIDMA_BD_USR3_OFFSET          0x2C /* User IP specific word3 */
  94#define XAXIDMA_BD_USR4_OFFSET          0x30 /* User IP specific word4 */
  95#define XAXIDMA_BD_ID_OFFSET            0x34 /* Sw ID */
  96#define XAXIDMA_BD_HAS_STSCNTRL_OFFSET  0x38 /* Whether has stscntrl strm */
  97#define XAXIDMA_BD_HAS_DRE_OFFSET       0x3C /* Whether has DRE */
  98
  99#define XAXIDMA_BD_HAS_DRE_SHIFT        8 /* Whether has DRE shift */
 100#define XAXIDMA_BD_HAS_DRE_MASK         0xF00 /* Whether has DRE mask */
 101#define XAXIDMA_BD_WORDLEN_MASK         0xFF /* Whether has DRE mask */
 102
 103#define XAXIDMA_BD_CTRL_LENGTH_MASK     0x007FFFFF /* Requested len */
 104#define XAXIDMA_BD_CTRL_TXSOF_MASK      0x08000000 /* First tx packet */
 105#define XAXIDMA_BD_CTRL_TXEOF_MASK      0x04000000 /* Last tx packet */
 106#define XAXIDMA_BD_CTRL_ALL_MASK        0x0C000000 /* All control bits */
 107
 108#define XAXIDMA_DELAY_MASK              0xFF000000 /* Delay timeout counter */
 109#define XAXIDMA_COALESCE_MASK           0x00FF0000 /* Coalesce counter */
 110
 111#define XAXIDMA_DELAY_SHIFT             24
 112#define XAXIDMA_COALESCE_SHIFT          16
 113
 114#define XAXIDMA_IRQ_IOC_MASK            0x00001000 /* Completion intr */
 115#define XAXIDMA_IRQ_DELAY_MASK          0x00002000 /* Delay interrupt */
 116#define XAXIDMA_IRQ_ERROR_MASK          0x00004000 /* Error interrupt */
 117#define XAXIDMA_IRQ_ALL_MASK            0x00007000 /* All interrupts */
 118
 119/* Default TX/RX Threshold and waitbound values for SGDMA mode */
 120#define XAXIDMA_DFT_TX_THRESHOLD        24
 121#define XAXIDMA_DFT_TX_WAITBOUND        254
 122#define XAXIDMA_DFT_RX_THRESHOLD        1
 123#define XAXIDMA_DFT_RX_WAITBOUND        254
 124
 125#define XAXIDMA_BD_CTRL_TXSOF_MASK      0x08000000 /* First tx packet */
 126#define XAXIDMA_BD_CTRL_TXEOF_MASK      0x04000000 /* Last tx packet */
 127#define XAXIDMA_BD_CTRL_ALL_MASK        0x0C000000 /* All control bits */
 128
 129#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK  0x007FFFFF /* Actual len */
 130#define XAXIDMA_BD_STS_COMPLETE_MASK    0x80000000 /* Completed */
 131#define XAXIDMA_BD_STS_DEC_ERR_MASK     0x40000000 /* Decode error */
 132#define XAXIDMA_BD_STS_SLV_ERR_MASK     0x20000000 /* Slave error */
 133#define XAXIDMA_BD_STS_INT_ERR_MASK     0x10000000 /* Internal err */
 134#define XAXIDMA_BD_STS_ALL_ERR_MASK     0x70000000 /* All errors */
 135#define XAXIDMA_BD_STS_RXSOF_MASK       0x08000000 /* First rx pkt */
 136#define XAXIDMA_BD_STS_RXEOF_MASK       0x04000000 /* Last rx pkt */
 137#define XAXIDMA_BD_STS_ALL_MASK         0xFC000000 /* All status bits */
 138
 139#define XAXIDMA_BD_MINIMUM_ALIGNMENT    0x40
 140
 141/* AXI Tx Timestamp Stream FIFO Register Definitions */
 142#define XAXIFIFO_TXTS_ISR       0x00000000 /* Interrupt Status Register */
 143#define XAXIFIFO_TXTS_TXFD      0x00000010 /* Tx Data Write Port */
 144#define XAXIFIFO_TXTS_TLR       0x00000014 /* Transmit Length Register */
 145#define XAXIFIFO_TXTS_RFO       0x0000001C /* Rx Fifo Occupancy */
 146#define XAXIFIFO_TXTS_RDFR      0x00000018 /* Rx Fifo reset */
 147#define XAXIFIFO_TXTS_RXFD      0x00000020 /* Rx Data Read Port */
 148#define XAXIFIFO_TXTS_RLR       0x00000024 /* Receive Length Register */
 149#define XAXIFIFO_TXTS_SRR       0x00000028 /* AXI4-Stream Reset */
 150
 151#define XAXIFIFO_TXTS_INT_RC_MASK       0x04000000
 152#define XAXIFIFO_TXTS_RXFD_MASK         0x7FFFFFFF
 153#define XAXIFIFO_TXTS_RESET_MASK        0x000000A5
 154#define XAXIFIFO_TXTS_TAG_MASK          0xFFFF0000
 155#define XAXIFIFO_TXTS_TAG_SHIFT         16
 156
 157/* Axi Ethernet registers definition */
 158#define XAE_RAF_OFFSET          0x00000000 /* Reset and Address filter */
 159#define XAE_TPF_OFFSET          0x00000004 /* Tx Pause Frame */
 160#define XAE_IFGP_OFFSET         0x00000008 /* Tx Inter-frame gap adjustment*/
 161#define XAE_IS_OFFSET           0x0000000C /* Interrupt status */
 162#define XAE_IP_OFFSET           0x00000010 /* Interrupt pending */
 163#define XAE_IE_OFFSET           0x00000014 /* Interrupt enable */
 164#define XAE_TTAG_OFFSET         0x00000018 /* Tx VLAN TAG */
 165#define XAE_RTAG_OFFSET         0x0000001C /* Rx VLAN TAG */
 166#define XAE_UAWL_OFFSET         0x00000020 /* Unicast address word lower */
 167#define XAE_UAWU_OFFSET         0x00000024 /* Unicast address word upper */
 168#define XAE_TPID0_OFFSET        0x00000028 /* VLAN TPID0 register */
 169#define XAE_TPID1_OFFSET        0x0000002C /* VLAN TPID1 register */
 170#define XAE_PPST_OFFSET         0x00000030 /* PCS PMA Soft Temac Status Reg */
 171#define XAE_RCW0_OFFSET         0x00000400 /* Rx Configuration Word 0 */
 172#define XAE_RCW1_OFFSET         0x00000404 /* Rx Configuration Word 1 */
 173#define XAE_TC_OFFSET           0x00000408 /* Tx Configuration */
 174#define XAE_FCC_OFFSET          0x0000040C /* Flow Control Configuration */
 175#define XAE_EMMC_OFFSET         0x00000410 /* EMAC mode configuration */
 176#define XAE_PHYC_OFFSET         0x00000414 /* RGMII/SGMII configuration */
 177#define XAE_MDIO_MC_OFFSET      0x00000500 /* MII Management Config */
 178#define XAE_MDIO_MCR_OFFSET     0x00000504 /* MII Management Control */
 179#define XAE_MDIO_MWD_OFFSET     0x00000508 /* MII Management Write Data */
 180#define XAE_MDIO_MRD_OFFSET     0x0000050C /* MII Management Read Data */
 181#define XAE_MDIO_MIS_OFFSET     0x00000600 /* MII Management Interrupt Status */
 182/* MII Mgmt Interrupt Pending register offset */
 183#define XAE_MDIO_MIP_OFFSET     0x00000620
 184/* MII Management Interrupt Enable register offset */
 185#define XAE_MDIO_MIE_OFFSET     0x00000640
 186/* MII Management Interrupt Clear register offset. */
 187#define XAE_MDIO_MIC_OFFSET     0x00000660
 188#define XAE_UAW0_OFFSET         0x00000700 /* Unicast address word 0 */
 189#define XAE_UAW1_OFFSET         0x00000704 /* Unicast address word 1 */
 190#define XAE_FMI_OFFSET          0x00000708 /* Filter Mask Index */
 191#define XAE_AF0_OFFSET          0x00000710 /* Address Filter 0 */
 192#define XAE_AF1_OFFSET          0x00000714 /* Address Filter 1 */
 193
 194#define XAE_TX_VLAN_DATA_OFFSET 0x00004000 /* TX VLAN data table address */
 195#define XAE_RX_VLAN_DATA_OFFSET 0x00008000 /* RX VLAN data table address */
 196#define XAE_MCAST_TABLE_OFFSET  0x00020000 /* Multicast table address */
 197
 198/* Bit Masks for Axi Ethernet RAF register */
 199/* Reject receive multicast destination address */
 200#define XAE_RAF_MCSTREJ_MASK            0x00000002
 201/* Reject receive broadcast destination address */
 202#define XAE_RAF_BCSTREJ_MASK            0x00000004
 203#define XAE_RAF_TXVTAGMODE_MASK         0x00000018 /* Tx VLAN TAG mode */
 204#define XAE_RAF_RXVTAGMODE_MASK         0x00000060 /* Rx VLAN TAG mode */
 205#define XAE_RAF_TXVSTRPMODE_MASK        0x00000180 /* Tx VLAN STRIP mode */
 206#define XAE_RAF_RXVSTRPMODE_MASK        0x00000600 /* Rx VLAN STRIP mode */
 207#define XAE_RAF_NEWFNCENBL_MASK         0x00000800 /* New function mode */
 208/* Exteneded Multicast Filtering mode */
 209#define XAE_RAF_EMULTIFLTRENBL_MASK     0x00001000
 210#define XAE_RAF_STATSRST_MASK           0x00002000 /* Stats. Counter Reset */
 211#define XAE_RAF_RXBADFRMEN_MASK         0x00004000 /* Recv Bad Frame Enable */
 212#define XAE_RAF_TXVTAGMODE_SHIFT        3 /* Tx Tag mode shift bits */
 213#define XAE_RAF_RXVTAGMODE_SHIFT        5 /* Rx Tag mode shift bits */
 214#define XAE_RAF_TXVSTRPMODE_SHIFT       7 /* Tx strip mode shift bits*/
 215#define XAE_RAF_RXVSTRPMODE_SHIFT       9 /* Rx Strip mode shift bits*/
 216
 217/* Bit Masks for Axi Ethernet TPF and IFGP registers */
 218#define XAE_TPF_TPFV_MASK               0x0000FFFF /* Tx pause frame value */
 219/* Transmit inter-frame gap adjustment value */
 220#define XAE_IFGP0_IFGP_MASK             0x0000007F
 221
 222/* Bit Masks for Axi Ethernet IS, IE and IP registers, Same masks apply
 223 * for all 3 registers.
 224 */
 225/* Hard register access complete */
 226#define XAE_INT_HARDACSCMPLT_MASK       0x00000001
 227/* Auto negotiation complete */
 228#define XAE_INT_AUTONEG_MASK            0x00000002
 229#define XAE_INT_RXCMPIT_MASK            0x00000004 /* Rx complete */
 230#define XAE_INT_RXRJECT_MASK            0x00000008 /* Rx frame rejected */
 231#define XAE_INT_RXFIFOOVR_MASK          0x00000010 /* Rx fifo overrun */
 232#define XAE_INT_TXCMPIT_MASK            0x00000020 /* Tx complete */
 233#define XAE_INT_RXDCMLOCK_MASK          0x00000040 /* Rx Dcm Lock */
 234#define XAE_INT_MGTRDY_MASK             0x00000080 /* MGT clock Lock */
 235#define XAE_INT_PHYRSTCMPLT_MASK        0x00000100 /* Phy Reset complete */
 236#define XAE_INT_ALL_MASK                0x0000003F /* All the ints */
 237
 238/* INT bits that indicate receive errors */
 239#define XAE_INT_RECV_ERROR_MASK                         \
 240        (XAE_INT_RXRJECT_MASK | XAE_INT_RXFIFOOVR_MASK)
 241
 242/* Bit masks for Axi Ethernet VLAN TPID Word 0 register */
 243#define XAE_TPID_0_MASK         0x0000FFFF /* TPID 0 */
 244#define XAE_TPID_1_MASK         0xFFFF0000 /* TPID 1 */
 245
 246/* Bit masks for Axi Ethernet VLAN TPID Word 1 register */
 247#define XAE_TPID_2_MASK         0x0000FFFF /* TPID 0 */
 248#define XAE_TPID_3_MASK         0xFFFF0000 /* TPID 1 */
 249
 250/* Bit masks for Axi Ethernet RCW1 register */
 251#define XAE_RCW1_INBAND1588_MASK 0x00400000 /* Inband 1588 Enable */
 252#define XAE_RCW1_RST_MASK       0x80000000 /* Reset */
 253#define XAE_RCW1_JUM_MASK       0x40000000 /* Jumbo frame enable */
 254/* In-Band FCS enable (FCS not stripped) */
 255#define XAE_RCW1_FCS_MASK       0x20000000
 256#define XAE_RCW1_RX_MASK        0x10000000 /* Receiver enable */
 257#define XAE_RCW1_VLAN_MASK      0x08000000 /* VLAN frame enable */
 258/* Length/type field valid check disable */
 259#define XAE_RCW1_LT_DIS_MASK    0x02000000
 260/* Control frame Length check disable */
 261#define XAE_RCW1_CL_DIS_MASK    0x01000000
 262/* Pause frame source address bits [47:32]. Bits [31:0] are
 263 * stored in register RCW0
 264 */
 265#define XAE_RCW1_PAUSEADDR_MASK 0x0000FFFF
 266
 267/* Bit masks for Axi Ethernet TC register */
 268#define XAE_TC_INBAND1588_MASK 0x00400000 /* Inband 1588 Enable */
 269#define XAE_TC_RST_MASK         0x80000000 /* Reset */
 270#define XAE_TC_JUM_MASK         0x40000000 /* Jumbo frame enable */
 271/* In-Band FCS enable (FCS not generated) */
 272#define XAE_TC_FCS_MASK         0x20000000
 273#define XAE_TC_TX_MASK          0x10000000 /* Transmitter enable */
 274#define XAE_TC_VLAN_MASK        0x08000000 /* VLAN frame enable */
 275/* Inter-frame gap adjustment enable */
 276#define XAE_TC_IFG_MASK         0x02000000
 277
 278/* Bit masks for Axi Ethernet FCC register */
 279#define XAE_FCC_FCRX_MASK       0x20000000 /* Rx flow control enable */
 280#define XAE_FCC_FCTX_MASK       0x40000000 /* Tx flow control enable */
 281
 282/* Bit masks for Axi Ethernet EMMC register */
 283#define XAE_EMMC_LINKSPEED_MASK 0xC0000000 /* Link speed */
 284#define XAE_EMMC_RGMII_MASK     0x20000000 /* RGMII mode enable */
 285#define XAE_EMMC_SGMII_MASK     0x10000000 /* SGMII mode enable */
 286#define XAE_EMMC_GPCS_MASK      0x08000000 /* 1000BaseX mode enable */
 287#define XAE_EMMC_HOST_MASK      0x04000000 /* Host interface enable */
 288#define XAE_EMMC_TX16BIT        0x02000000 /* 16 bit Tx client enable */
 289#define XAE_EMMC_RX16BIT        0x01000000 /* 16 bit Rx client enable */
 290#define XAE_EMMC_LINKSPD_10     0x00000000 /* Link Speed mask for 10 Mbit */
 291#define XAE_EMMC_LINKSPD_100    0x40000000 /* Link Speed mask for 100 Mbit */
 292#define XAE_EMMC_LINKSPD_1000   0x80000000 /* Link Speed mask for 1000 Mbit */
 293#define XAE_EMMC_LINKSPD_2500   0x80000000 /* Link Speed mask for 2500 Mbit */
 294
 295/* Bit masks for Axi Ethernet PHYC register */
 296#define XAE_PHYC_SGMIILINKSPEED_MASK    0xC0000000 /* SGMII link speed mask*/
 297#define XAE_PHYC_RGMIILINKSPEED_MASK    0x0000000C /* RGMII link speed */
 298#define XAE_PHYC_RGMIIHD_MASK           0x00000002 /* RGMII Half-duplex */
 299#define XAE_PHYC_RGMIILINK_MASK         0x00000001 /* RGMII link status */
 300#define XAE_PHYC_RGLINKSPD_10           0x00000000 /* RGMII link 10 Mbit */
 301#define XAE_PHYC_RGLINKSPD_100          0x00000004 /* RGMII link 100 Mbit */
 302#define XAE_PHYC_RGLINKSPD_1000         0x00000008 /* RGMII link 1000 Mbit */
 303#define XAE_PHYC_SGLINKSPD_10           0x00000000 /* SGMII link 10 Mbit */
 304#define XAE_PHYC_SGLINKSPD_100          0x40000000 /* SGMII link 100 Mbit */
 305#define XAE_PHYC_SGLINKSPD_1000         0x80000000 /* SGMII link 1000 Mbit */
 306
 307/* Bit masks for Axi Ethernet MDIO interface MC register */
 308#define XAE_MDIO_MC_MDIOEN_MASK         0x00000040 /* MII management enable */
 309#define XAE_MDIO_MC_CLOCK_DIVIDE_MAX    0x3F       /* Maximum MDIO divisor */
 310
 311/* Bit masks for Axi Ethernet MDIO interface MCR register */
 312#define XAE_MDIO_MCR_PHYAD_MASK         0x1F000000 /* Phy Address Mask */
 313#define XAE_MDIO_MCR_PHYAD_SHIFT        24         /* Phy Address Shift */
 314#define XAE_MDIO_MCR_REGAD_MASK         0x001F0000 /* Reg Address Mask */
 315#define XAE_MDIO_MCR_REGAD_SHIFT        16         /* Reg Address Shift */
 316#define XAE_MDIO_MCR_OP_MASK            0x0000C000 /* Operation Code Mask */
 317#define XAE_MDIO_MCR_OP_SHIFT           13         /* Operation Code Shift */
 318#define XAE_MDIO_MCR_OP_READ_MASK       0x00008000 /* Op Code Read Mask */
 319#define XAE_MDIO_MCR_OP_WRITE_MASK      0x00004000 /* Op Code Write Mask */
 320#define XAE_MDIO_MCR_INITIATE_MASK      0x00000800 /* Ready Mask */
 321#define XAE_MDIO_MCR_READY_MASK         0x00000080 /* Ready Mask */
 322
 323/* Bit masks for Axi Ethernet MDIO interface MIS, MIP, MIE, MIC registers */
 324#define XAE_MDIO_INT_MIIM_RDY_MASK      0x00000001 /* MIIM Interrupt */
 325
 326/* Bit masks for Axi Ethernet UAW1 register */
 327/* Station address bits [47:32]; Station address
 328 * bits [31:0] are stored in register UAW0
 329 */
 330#define XAE_UAW1_UNICASTADDR_MASK       0x0000FFFF
 331
 332/* Bit masks for Axi Ethernet FMI register */
 333#define XAE_FMI_PM_MASK                 0x80000000 /* Promis. mode enable */
 334#define XAE_FMI_IND_MASK                0x00000003 /* Index Mask */
 335
 336#define XAE_MDIO_DIV_DFT                29 /* Default MDIO clock divisor */
 337
 338/* Total number of entries in the hardware multicast table. */
 339#define XAE_MULTICAST_CAM_TABLE_NUM     4
 340
 341/* Axi Ethernet Synthesis features */
 342#define XAE_FEATURE_PARTIAL_RX_CSUM     BIT(0)
 343#define XAE_FEATURE_PARTIAL_TX_CSUM     BIT(1)
 344#define XAE_FEATURE_FULL_RX_CSUM        BIT(2)
 345#define XAE_FEATURE_FULL_TX_CSUM        BIT(3)
 346
 347#define XAE_NO_CSUM_OFFLOAD             0
 348
 349#define XAE_FULL_CSUM_STATUS_MASK       0x00000038
 350#define XAE_IP_UDP_CSUM_VALIDATED       0x00000003
 351#define XAE_IP_TCP_CSUM_VALIDATED       0x00000002
 352
 353#define DELAY_OF_ONE_MILLISEC           1000
 354
 355#define XAXIENET_NAPI_WEIGHT            64
 356
 357/* Definitions of 1588 PTP in Axi Ethernet IP */
 358#define TX_TS_OP_NOOP           0x0
 359#define TX_TS_OP_ONESTEP        0x1
 360#define TX_TS_OP_TWOSTEP        0x2
 361#define TX_TS_CSUM_UPDATE       0x1
 362#define TX_PTP_CSUM_OFFSET      0x28
 363#define TX_PTP_TS_OFFSET        0x4C
 364
 365/* Read/Write access to the registers */
 366#ifndef out_be32
 367#if defined(CONFIG_ARCH_ZYNQ) || defined(CONFIG_ARCH_ZYNQMP)
 368#define in_be32(offset)         __raw_readl(offset)
 369#define out_be32(offset, val)   __raw_writel(val, offset)
 370#endif
 371#endif
 372
 373/* XXV MAC Register Definitions */
 374#define XXV_TC_OFFSET                   0x0000000C
 375#define XXV_RCW1_OFFSET                 0x00000014
 376#define XXV_JUM_OFFSET                  0x00000018
 377#define XXV_TICKREG_OFFSET              0x00000020
 378#define XXV_STATRX_BLKLCK_OFFSET        0x0000040C
 379
 380/* XXV MAC Register Mask Definitions */
 381#define XXV_TC_TX_MASK          BIT(0)
 382#define XXV_RCW1_RX_MASK        BIT(0)
 383#define XXV_RCW1_FCS_MASK       BIT(1)
 384#define XXV_TC_FCS_MASK         BIT(1)
 385#define XXV_MIN_JUM_MASK        GENMASK(7, 0)
 386#define XXV_MAX_JUM_MASK        GENMASK(10, 8)
 387#define XXV_RX_BLKLCK_MASK      BIT(0)
 388#define XXV_TICKREG_STATEN_MASK BIT(0)
 389#define XXV_MAC_MIN_PKT_LEN     64
 390
 391/* PTP Packet length */
 392#define XAE_TX_PTP_LEN          16
 393#define XXV_TX_PTP_LEN          12
 394
 395/* Macros used when AXI DMA h/w is configured without DRE */
 396#define XAE_TX_BUFFERS          64
 397#define XAE_MAX_PKT_LEN         8192
 398
 399/**
 400 * struct axidma_bd - Axi Dma buffer descriptor layout
 401 * @next:         MM2S/S2MM Next Descriptor Pointer
 402 * @reserved1:    Reserved and not used
 403 * @phys:         MM2S/S2MM Buffer Address
 404 * @reserved2:    Reserved and not used
 405 * @reserved3:    Reserved and not used
 406 * @reserved4:    Reserved and not used
 407 * @cntrl:        MM2S/S2MM Control value
 408 * @status:       MM2S/S2MM Status value
 409 * @app0:         MM2S/S2MM User Application Field 0.
 410 * @app1:         MM2S/S2MM User Application Field 1.
 411 * @app2:         MM2S/S2MM User Application Field 2.
 412 * @app3:         MM2S/S2MM User Application Field 3.
 413 * @app4:         MM2S/S2MM User Application Field 4.
 414 * @sw_id_offset: MM2S/S2MM Sw ID
 415 * @ptp_tx_skb:   If timestamping is enabled used for timestamping skb
 416 *                Otherwise reserved.
 417 * @ptp_tx_ts_tag: Tag value of 2 step timestamping if timestamping is enabled
 418 *                 Otherwise reserved.
 419 * @tx_skb:       Transmit skb address
 420 */
 421struct axidma_bd {
 422        u32 next;       /* Physical address of next buffer descriptor */
 423        u32 reserved1;
 424        u32 phys;
 425        u32 reserved2;
 426        u32 reserved3;
 427        u32 reserved4;
 428        u32 cntrl;
 429        u32 status;
 430        u32 app0;
 431        u32 app1;       /* TX start << 16 | insert */
 432        u32 app2;       /* TX csum seed */
 433        u32 app3;
 434        u32 app4;
 435        phys_addr_t sw_id_offset; /* first unused field by h/w */
 436        phys_addr_t ptp_tx_skb;
 437        u32 ptp_tx_ts_tag;
 438        phys_addr_t tx_skb;
 439        u32 tx_desc_mapping;
 440} __aligned(128);
 441
 442#define DESC_DMA_MAP_SINGLE 0
 443#define DESC_DMA_MAP_PAGE 1
 444
 445#ifdef CONFIG_XILINX_TSN
 446enum XAE_QUEUE {
 447        XAE_BE = 0, /* best effort */
 448        XAE_RE,    /* reserved(cbs) */
 449        XAE_ST,    /* Scheduled */
 450        XAE_MAX_QUEUES,
 451};
 452#else
 453#define XAE_MAX_QUEUES   1
 454#endif
 455
 456#ifdef CONFIG_XILINX_TSN_PTP
 457#define SIOCCHIOCTL SIOCDEVPRIVATE
 458#endif
 459/**
 460 * struct axienet_local - axienet private per device data
 461 * @ndev:       Pointer for net_device to which it will be attached.
 462 * @dev:        Pointer to device structure
 463 * @phy_node:   Pointer to device node structure
 464 * @mii_bus:    Pointer to MII bus structure
 465 * @regs:       Base address for the axienet_local device address space
 466 * @napi:       Napi Structure array for all dma queues
 467 * @num_queues: Total number of DMA queues
 468 * @dq:         DMA queues data
 469 * @is_tsn:     Denotes a tsn port
 470 * @temac_no:   Denotes the port number in TSN IP
 471 * @timer_priv: PTP timer private data pointer
 472 * @ptp_tx_irq: PTP tx irq
 473 * @ptp_rx_irq: PTP rx irq
 474 * @rtc_irq:    PTP RTC irq
 475 * @qbv_irq:    QBV shed irq
 476 * @ptp_rx_hw_pointer: ptp rx hw pointer
 477 * @ptp_rx_sw_pointer: ptp rx sw pointer
 478 * @ptp_txq:    PTP tx queue header
 479 * @tx_tstamp_work: PTP timestamping work queue
 480 * @ptp_tx_lock: PTP tx lock
 481 * @dma_err_tasklet: Tasklet structure to process Axi DMA errors
 482 * @eth_irq:    Axi Ethernet IRQ number
 483 * @phy_type:   Phy type to identify between MII/GMII/RGMII/SGMII/1000 Base-X
 484 * @options:    AxiEthernet option word
 485 * @last_link:  Phy link state in which the PHY was negotiated earlier
 486 * @features:   Stores the extended features supported by the axienet hw
 487 * @max_frm_size: Stores the maximum size of the frame that can be that
 488 *                Txed/Rxed in the existing hardware. If jumbo option is
 489 *                supported, the maximum frame size would be 9k. Else it is
 490 *                1522 bytes (assuming support for basic VLAN)
 491 * @rxmem:      Stores rx memory size for jumbo frame handling.
 492 * @csum_offload_on_tx_path:    Stores the checksum selection on TX side.
 493 * @csum_offload_on_rx_path:    Stores the checksum selection on RX side.
 494 * @coalesce_count_rx:  Store the irq coalesce on RX side.
 495 * @coalesce_count_tx:  Store the irq coalesce on TX side.
 496 * @phy_interface: Phy interface type.
 497 * @phy_flags:  Phy interface flags.
 498 * @eth_hasnobuf: Ethernet is configured in Non buf mode.
 499 * @axienet_config: Ethernet config structure
 500 * @tx_ts_regs:   Base address for the axififo device address space.
 501 * @rx_ts_regs:   Base address for the rx axififo device address space.
 502 * @tstamp_config: Hardware timestamp config structure.
 503 * @tx_ptpheader: Stores the tx ptp header.
 504 * @eth_clk: Clock resource for etherent mac.
 505 * @dma_clk: Clock resource for dma controller.
 506 */
 507struct axienet_local {
 508        struct net_device *ndev;
 509        struct device *dev;
 510
 511        /* Connection to PHY device */
 512        struct device_node *phy_node;
 513
 514        /* MDIO bus data */
 515        struct mii_bus *mii_bus;        /* MII bus reference */
 516
 517        /* IO registers, dma functions and IRQs */
 518        void __iomem *regs;
 519
 520        struct tasklet_struct dma_err_tasklet[XAE_MAX_QUEUES];
 521        struct napi_struct napi[XAE_MAX_QUEUES];        /* NAPI Structure */
 522
 523        #define XAE_TEMAC1 0
 524        #define XAE_TEMAC2 1
 525        u8     temac_no;
 526        u16    num_queues;      /* Number of DMA queues */
 527        struct axienet_dma_q *dq[XAE_MAX_QUEUES];       /* DAM queue data*/
 528        bool is_tsn;
 529#ifdef CONFIG_XILINX_TSN_PTP
 530        void *timer_priv;
 531        int ptp_tx_irq;
 532        int ptp_rx_irq;
 533        int rtc_irq;
 534        int qbv_irq;
 535        u8  ptp_rx_hw_pointer;
 536        u8  ptp_rx_sw_pointer;
 537        struct sk_buff_head ptp_txq;
 538        struct work_struct tx_tstamp_work;
 539        spinlock_t ptp_tx_lock;         /* TSN PTP tx lock*/
 540#endif
 541        int eth_irq;
 542        u32 phy_type;
 543
 544        u32 options;                    /* Current options word */
 545        u32 last_link;
 546        u32 features;
 547
 548        u32 max_frm_size;
 549        u32 rxmem;
 550
 551        int csum_offload_on_tx_path;
 552        int csum_offload_on_rx_path;
 553
 554        u32 coalesce_count_rx;
 555        u32 coalesce_count_tx;
 556        u32 phy_interface;
 557        u32 phy_flags;
 558        bool eth_hasnobuf;
 559        const struct axienet_config *axienet_config;
 560
 561#ifdef CONFIG_XILINX_AXI_EMAC_HWTSTAMP
 562        void __iomem *tx_ts_regs;
 563        void __iomem *rx_ts_regs;
 564        struct hwtstamp_config tstamp_config;
 565        u8 *tx_ptpheader;
 566#endif
 567        struct clk *eth_clk;
 568        struct clk *dma_clk;
 569};
 570
 571/**
 572 * struct axienet_dma_q - axienet private per dma queue data
 573 * @lp:         Parent pointer
 574 * @dma_regs:   Base address for the axidma device address space
 575 * @tx_irq:     Axidma TX IRQ number
 576 * @rx_irq:     Axidma RX IRQ number
 577 * @tx_lock:    Spin lock for tx path
 578 * @rx_lock:    Spin lock for tx path
 579 * @tx_bd_v:    Virtual address of the TX buffer descriptor ring
 580 * @tx_bd_p:    Physical address(start address) of the TX buffer descr. ring
 581 * @rx_bd_v:    Virtual address of the RX buffer descriptor ring
 582 * @rx_bd_p:    Physical address(start address) of the RX buffer descr. ring
 583 * @tx_buf:     Virtual address of the Tx buffer pool used by the driver when
 584 *              DMA h/w is configured without DRE.
 585 * @tx_bufs:    Virutal address of the Tx buffer address.
 586 * @tx_bufs_dma: Physical address of the Tx buffer address used by the driver
 587 *               when DMA h/w is configured without DRE.
 588 * @eth_hasdre: Tells whether DMA h/w is configured with dre or not.
 589 * @tx_bd_ci:   Stores the index of the Tx buffer descriptor in the ring being
 590 *              accessed currently. Used while alloc. BDs before a TX starts
 591 * @tx_bd_tail: Stores the index of the Tx buffer descriptor in the ring being
 592 *              accessed currently. Used while processing BDs after the TX
 593 *              completed.
 594 * @rx_bd_ci:   Stores the index of the Rx buffer descriptor in the ring being
 595 *              accessed currently.
 596 */
 597struct axienet_dma_q {
 598        struct axienet_local    *lp; /* parent */
 599        void __iomem *dma_regs;
 600
 601        int tx_irq;
 602        int rx_irq;
 603
 604        spinlock_t tx_lock;             /* tx lock */
 605        spinlock_t rx_lock;             /* rx lock */
 606
 607        /* Buffer descriptors */
 608        struct axidma_bd *tx_bd_v;
 609        struct axidma_bd *rx_bd_v;
 610        dma_addr_t rx_bd_p;
 611        dma_addr_t tx_bd_p;
 612
 613        unsigned char *tx_buf[XAE_TX_BUFFERS];
 614        unsigned char *tx_bufs;
 615        dma_addr_t tx_bufs_dma;
 616        bool eth_hasdre;
 617
 618        u32 tx_bd_ci;
 619        u32 rx_bd_ci;
 620        u32 tx_bd_tail;
 621
 622};
 623
 624/**
 625 * enum axienet_ip_type - AXIENET IP/MAC type.
 626 *
 627 * @XAXIENET_1G:         IP is 1G MAC
 628 * @XAXIENET_2_5G:       IP type is 2.5G MAC.
 629 * @XAXIENET_LEGACY_10G: IP type is legacy 10G MAC.
 630 * @XAXIENET_10G_25G:    IP type is 10G/25G MAC(XXV MAC).
 631 *
 632 */
 633enum axienet_ip_type {
 634        XAXIENET_1G = 0,
 635        XAXIENET_2_5G,
 636        XAXIENET_LEGACY_10G,
 637        XAXIENET_10G_25G,
 638};
 639
 640struct axienet_config {
 641        enum axienet_ip_type mactype;
 642        void (*setoptions)(struct net_device *ndev, u32 options);
 643        u32 tx_ptplen;
 644};
 645
 646/**
 647 * struct axiethernet_option - Used to set axi ethernet hardware options
 648 * @opt:        Option to be set.
 649 * @reg:        Register offset to be written for setting the option
 650 * @m_or:       Mask to be ORed for setting the option in the register
 651 */
 652struct axienet_option {
 653        u32 opt;
 654        u32 reg;
 655        u32 m_or;
 656};
 657
 658struct xxvenet_option {
 659        u32 opt;
 660        u32 reg;
 661        u32 m_or;
 662};
 663
 664/**
 665 * axienet_ior - Memory mapped Axi Ethernet register read
 666 * @lp:         Pointer to axienet local structure
 667 * @offset:     Address offset from the base address of Axi Ethernet core
 668 *
 669 * Return: The contents of the Axi Ethernet register
 670 *
 671 * This function returns the contents of the corresponding register.
 672 */
 673static inline u32 axienet_ior(struct axienet_local *lp, off_t offset)
 674{
 675        return in_be32(lp->regs + offset);
 676}
 677
 678/**
 679 * axienet_iow - Memory mapped Axi Ethernet register write
 680 * @lp:         Pointer to axienet local structure
 681 * @offset:     Address offset from the base address of Axi Ethernet core
 682 * @value:      Value to be written into the Axi Ethernet register
 683 *
 684 * This function writes the desired value into the corresponding Axi Ethernet
 685 * register.
 686 */
 687static inline void axienet_iow(struct axienet_local *lp, off_t offset,
 688                               u32 value)
 689{
 690        out_be32((lp->regs + offset), value);
 691}
 692
 693#ifdef CONFIG_XILINX_AXI_EMAC_HWTSTAMP
 694/**
 695 * axienet_txts_ior - Memory mapped AXI FIFO MM S register read
 696 * @lp:         Pointer to axienet_local structure
 697 * @reg:     Address offset from the base address of AXI FIFO MM S
 698 *              core
 699 *
 700 * Return: the contents of the AXI FIFO MM S register
 701 */
 702
 703static inline u32 axienet_txts_ior(struct axienet_local *lp, off_t reg)
 704{
 705        return in_be32(lp->tx_ts_regs + reg);
 706}
 707
 708/**
 709 * axienet_txts_iow - Memory mapper AXI FIFO MM S register write
 710 * @lp:         Pointer to axienet_local structure
 711 * @reg:     Address offset from the base address of AXI FIFO MM S
 712 *              core.
 713 * @value:      Value to be written into the AXI FIFO MM S register
 714 */
 715static inline void axienet_txts_iow(struct  axienet_local *lp, off_t reg,
 716                                    u32 value)
 717{
 718        out_be32((lp->tx_ts_regs + reg), value);
 719}
 720
 721/**
 722 * axienet_rxts_ior - Memory mapped AXI FIFO MM S register read
 723 * @lp:         Pointer to axienet_local structure
 724 * @reg:     Address offset from the base address of AXI FIFO MM S
 725 *              core
 726 *
 727 * Return: the contents of the AXI FIFO MM S register
 728 */
 729
 730static inline u32 axienet_rxts_ior(struct axienet_local *lp, off_t reg)
 731{
 732        return in_be32(lp->rx_ts_regs + reg);
 733}
 734
 735/**
 736 * axienet_rxts_iow - Memory mapper AXI FIFO MM S register write
 737 * @lp:         Pointer to axienet_local structure
 738 * @reg:     Address offset from the base address of AXI FIFO MM S
 739 *              core.
 740 * @value:      Value to be written into the AXI FIFO MM S register
 741 */
 742static inline void axienet_rxts_iow(struct  axienet_local *lp, off_t reg,
 743                                    u32 value)
 744{
 745        out_be32((lp->rx_ts_regs + reg), value);
 746}
 747#endif
 748
 749/* Function prototypes visible in xilinx_axienet_mdio.c for other files */
 750int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np);
 751int axienet_mdio_wait_until_ready(struct axienet_local *lp);
 752void axienet_mdio_teardown(struct axienet_local *lp);
 753#ifdef CONFIG_XILINX_TSN_PTP
 754void axienet_tx_tstamp(struct work_struct *work);
 755#endif
 756#ifdef CONFIG_XILINX_TSN_QBV
 757int axienet_qbv_init(struct net_device *ndev);
 758void axienet_qbv_remove(struct net_device *ndev);
 759int axienet_set_schedule(struct net_device *ndev, void __user *useraddr);
 760#endif
 761
 762#endif /* XILINX_AXI_ENET_H */
 763