net/at91_ether: use pclk member instead of ether_clk
[firefly-linux-kernel-4.4.55.git] / drivers / net / ethernet / cadence / macb.h
index d3212f6db70325a53917b380e4f4ab05f8abd9b4..138311f9be9a1660d134edb304f6a7128540e381 100644 (file)
@@ -14,6 +14,8 @@
 #define MACB_NCR                               0x0000
 #define MACB_NCFGR                             0x0004
 #define MACB_NSR                               0x0008
+#define MACB_TAR                               0x000c /* AT91RM9200 only */
+#define MACB_TCR                               0x0010 /* AT91RM9200 only */
 #define MACB_TSR                               0x0014
 #define MACB_RBQP                              0x0018
 #define MACB_TBQP                              0x001c
 #define MACB_TPQ                               0x00bc
 #define MACB_USRIO                             0x00c0
 #define MACB_WOL                               0x00c4
+#define MACB_MID                               0x00fc
+
+/* GEM register offsets. */
+#define GEM_NCFGR                              0x0004
+#define GEM_USRIO                              0x000c
+#define GEM_DMACFG                             0x0010
+#define GEM_HRB                                        0x0080
+#define GEM_HRT                                        0x0084
+#define GEM_SA1B                               0x0088
+#define GEM_SA1T                               0x008C
+#define GEM_OTX                                        0x0100
+#define GEM_DCFG1                              0x0280
+#define GEM_DCFG2                              0x0284
+#define GEM_DCFG3                              0x0288
+#define GEM_DCFG4                              0x028c
+#define GEM_DCFG5                              0x0290
+#define GEM_DCFG6                              0x0294
+#define GEM_DCFG7                              0x0298
 
 /* Bitfields in NCR */
 #define MACB_LB_OFFSET                         0
 #define MACB_RTY_SIZE                          1
 #define MACB_PAE_OFFSET                                13
 #define MACB_PAE_SIZE                          1
+#define MACB_RM9200_RMII_OFFSET                        13 /* AT91RM9200 only */
+#define MACB_RM9200_RMII_SIZE                  1  /* AT91RM9200 only */
 #define MACB_RBOF_OFFSET                       14
 #define MACB_RBOF_SIZE                         2
 #define MACB_RLCE_OFFSET                       16
 #define MACB_IRXFCS_OFFSET                     19
 #define MACB_IRXFCS_SIZE                       1
 
+/* GEM specific NCFGR bitfields. */
+#define GEM_CLK_OFFSET                         18
+#define GEM_CLK_SIZE                           3
+#define GEM_DBW_OFFSET                         21
+#define GEM_DBW_SIZE                           2
+
+/* Constants for data bus width. */
+#define GEM_DBW32                              0
+#define GEM_DBW64                              1
+#define GEM_DBW128                             2
+
+/* Bitfields in DMACFG. */
+#define GEM_RXBS_OFFSET                                16
+#define GEM_RXBS_SIZE                          8
+
 /* Bitfields in NSR */
 #define MACB_NSR_LINK_OFFSET                   0
 #define MACB_NSR_LINK_SIZE                     1
 #define MACB_TGO_SIZE                          1
 #define MACB_BEX_OFFSET                                4
 #define MACB_BEX_SIZE                          1
+#define MACB_RM9200_BNQ_OFFSET                 4 /* AT91RM9200 only */
+#define MACB_RM9200_BNQ_SIZE                   1 /* AT91RM9200 only */
 #define MACB_COMP_OFFSET                       5
 #define MACB_COMP_SIZE                         1
 #define MACB_UND_OFFSET                                6
 #define MACB_WOL_MTI_OFFSET                    19
 #define MACB_WOL_MTI_SIZE                      1
 
+/* Bitfields in MID */
+#define MACB_IDNUM_OFFSET                      16
+#define MACB_IDNUM_SIZE                                16
+#define MACB_REV_OFFSET                                0
+#define MACB_REV_SIZE                          16
+
+/* Bitfields in DCFG1. */
+#define GEM_DBWDEF_OFFSET                      25
+#define GEM_DBWDEF_SIZE                                3
+
 /* Constants for CLK */
 #define MACB_CLK_DIV8                          0
 #define MACB_CLK_DIV16                         1
 #define MACB_CLK_DIV32                         2
 #define MACB_CLK_DIV64                         3
 
+/* GEM specific constants for CLK. */
+#define GEM_CLK_DIV8                           0
+#define GEM_CLK_DIV16                          1
+#define GEM_CLK_DIV32                          2
+#define GEM_CLK_DIV48                          3
+#define GEM_CLK_DIV64                          4
+#define GEM_CLK_DIV96                          5
+
 /* Constants for MAN register */
 #define MACB_MAN_SOF                           1
 #define MACB_MAN_WRITE                         1
                    << MACB_##name##_OFFSET))           \
         | MACB_BF(name,value))
 
+#define GEM_BIT(name)                                  \
+       (1 << GEM_##name##_OFFSET)
+#define GEM_BF(name, value)                            \
+       (((value) & ((1 << GEM_##name##_SIZE) - 1))     \
+        << GEM_##name##_OFFSET)
+#define GEM_BFEXT(name, value)\
+       (((value) >> GEM_##name##_OFFSET)               \
+        & ((1 << GEM_##name##_SIZE) - 1))
+#define GEM_BFINS(name, value, old)                    \
+       (((old) & ~(((1 << GEM_##name##_SIZE) - 1)      \
+                   << GEM_##name##_OFFSET))            \
+        | GEM_BF(name, value))
+
 /* Register access macros */
 #define macb_readl(port,reg)                           \
        __raw_readl((port)->regs + MACB_##reg)
 #define macb_writel(port,reg,value)                    \
        __raw_writel((value), (port)->regs + MACB_##reg)
+#define gem_readl(port, reg)                           \
+       __raw_readl((port)->regs + GEM_##reg)
+#define gem_writel(port, reg, value)                   \
+       __raw_writel((value), (port)->regs + GEM_##reg)
+
+/*
+ * Conditional GEM/MACB macros.  These perform the operation to the correct
+ * register dependent on whether the device is a GEM or a MACB.  For registers
+ * and bitfields that are common across both devices, use macb_{read,write}l
+ * to avoid the cost of the conditional.
+ */
+#define macb_or_gem_writel(__bp, __reg, __value) \
+       ({ \
+               if (macb_is_gem((__bp))) \
+                       gem_writel((__bp), __reg, __value); \
+               else \
+                       macb_writel((__bp), __reg, __value); \
+       })
+
+#define macb_or_gem_readl(__bp, __reg) \
+       ({ \
+               u32 __v; \
+               if (macb_is_gem((__bp))) \
+                       __v = gem_readl((__bp), __reg); \
+               else \
+                       __v = macb_readl((__bp), __reg); \
+               __v; \
+       })
 
 struct dma_desc {
        u32     addr;
@@ -358,6 +456,67 @@ struct macb_stats {
        u32     tx_pause_frames;
 };
 
+struct gem_stats {
+       u32     tx_octets_31_0;
+       u32     tx_octets_47_32;
+       u32     tx_frames;
+       u32     tx_broadcast_frames;
+       u32     tx_multicast_frames;
+       u32     tx_pause_frames;
+       u32     tx_64_byte_frames;
+       u32     tx_65_127_byte_frames;
+       u32     tx_128_255_byte_frames;
+       u32     tx_256_511_byte_frames;
+       u32     tx_512_1023_byte_frames;
+       u32     tx_1024_1518_byte_frames;
+       u32     tx_greater_than_1518_byte_frames;
+       u32     tx_underrun;
+       u32     tx_single_collision_frames;
+       u32     tx_multiple_collision_frames;
+       u32     tx_excessive_collisions;
+       u32     tx_late_collisions;
+       u32     tx_deferred_frames;
+       u32     tx_carrier_sense_errors;
+       u32     rx_octets_31_0;
+       u32     rx_octets_47_32;
+       u32     rx_frames;
+       u32     rx_broadcast_frames;
+       u32     rx_multicast_frames;
+       u32     rx_pause_frames;
+       u32     rx_64_byte_frames;
+       u32     rx_65_127_byte_frames;
+       u32     rx_128_255_byte_frames;
+       u32     rx_256_511_byte_frames;
+       u32     rx_512_1023_byte_frames;
+       u32     rx_1024_1518_byte_frames;
+       u32     rx_greater_than_1518_byte_frames;
+       u32     rx_undersized_frames;
+       u32     rx_oversize_frames;
+       u32     rx_jabbers;
+       u32     rx_frame_check_sequence_errors;
+       u32     rx_length_field_frame_errors;
+       u32     rx_symbol_errors;
+       u32     rx_alignment_errors;
+       u32     rx_resource_errors;
+       u32     rx_overruns;
+       u32     rx_ip_header_checksum_errors;
+       u32     rx_tcp_checksum_errors;
+       u32     rx_udp_checksum_errors;
+};
+
+struct rbf_t {
+       unsigned int addr;
+       unsigned long size;
+};
+
+#define MAX_RBUFF_SZ   0x600           /* 1518 rounded up */
+#define MAX_RX_DESCR   9               /* max number of receive buffers */
+
+struct recv_desc_bufs {
+       struct rbf_t descriptors[MAX_RX_DESCR];         /* must be on sizeof (rbf_t) boundary */
+       char recv_buf[MAX_RX_DESCR][MAX_RBUFF_SZ];      /* must be on long boundary */
+};
+
 struct macb {
        void __iomem            *regs;
 
@@ -376,7 +535,10 @@ struct macb {
        struct net_device       *dev;
        struct napi_struct      napi;
        struct net_device_stats stats;
-       struct macb_stats       hw_stats;
+       union {
+               struct macb_stats       macb;
+               struct gem_stats        gem;
+       }                       hw_stats;
 
        dma_addr_t              rx_ring_dma;
        dma_addr_t              tx_ring_dma;
@@ -389,6 +551,35 @@ struct macb {
        unsigned int            link;
        unsigned int            speed;
        unsigned int            duplex;
+
+       phy_interface_t         phy_interface;
+
+       /* at91_private */
+       struct mii_if_info mii;                 /* ethtool support */
+       struct macb_platform_data board_data;   /* board-specific
+                                                * configuration (shared with
+                                                * macb for common data */
+
+       /* PHY */
+       unsigned long phy_type;                 /* type of PHY (PHY_ID) */
+       short phy_media;                        /* media interface type */
+       unsigned short phy_address;             /* 5-bit MDI address of PHY (0..31) */
+       struct timer_list check_timer;          /* Poll link status */
+
+       /* Transmit */
+       struct sk_buff *skb;                    /* holds skb until xmit interrupt completes */
+       dma_addr_t skb_physaddr;                /* phys addr from pci_map_single */
+       int skb_length;                         /* saved skb length for pci_unmap_single */
+
+       /* Receive */
+       int rxBuffIndex;                        /* index into receive descriptor list */
+       struct recv_desc_bufs *dlist;           /* descriptor list address */
+       struct recv_desc_bufs *dlist_phys;      /* descriptor list physical address */
 };
 
+static inline bool macb_is_gem(struct macb *bp)
+{
+       return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
+}
+
 #endif /* _MACB_H */