xref: /openbmc/linux/drivers/net/ethernet/aeroflex/greth.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21fe003fdSJeff Kirsher #ifndef GRETH_H
31fe003fdSJeff Kirsher #define GRETH_H
41fe003fdSJeff Kirsher 
51fe003fdSJeff Kirsher #include <linux/phy.h>
61fe003fdSJeff Kirsher 
71fe003fdSJeff Kirsher /* Register bits and masks */
81fe003fdSJeff Kirsher #define GRETH_RESET 0x40
91fe003fdSJeff Kirsher #define GRETH_MII_BUSY 0x8
101fe003fdSJeff Kirsher #define GRETH_MII_NVALID 0x10
111fe003fdSJeff Kirsher 
121fe003fdSJeff Kirsher #define GRETH_CTRL_FD         0x10
131fe003fdSJeff Kirsher #define GRETH_CTRL_PR         0x20
141fe003fdSJeff Kirsher #define GRETH_CTRL_SP         0x80
151fe003fdSJeff Kirsher #define GRETH_CTRL_GB         0x100
161fe003fdSJeff Kirsher #define GRETH_CTRL_PSTATIEN   0x400
171fe003fdSJeff Kirsher #define GRETH_CTRL_MCEN       0x800
181fe003fdSJeff Kirsher #define GRETH_CTRL_DISDUPLEX  0x1000
191fe003fdSJeff Kirsher #define GRETH_STATUS_PHYSTAT  0x100
201fe003fdSJeff Kirsher 
211fe003fdSJeff Kirsher #define GRETH_BD_EN 0x800
221fe003fdSJeff Kirsher #define GRETH_BD_WR 0x1000
231fe003fdSJeff Kirsher #define GRETH_BD_IE 0x2000
241fe003fdSJeff Kirsher #define GRETH_BD_LEN 0x7FF
251fe003fdSJeff Kirsher 
261fe003fdSJeff Kirsher #define GRETH_TXEN 0x1
271fe003fdSJeff Kirsher #define GRETH_INT_TE 0x2
281fe003fdSJeff Kirsher #define GRETH_INT_TX 0x8
291fe003fdSJeff Kirsher #define GRETH_TXI 0x4
301fe003fdSJeff Kirsher #define GRETH_TXBD_STATUS 0x0001C000
311fe003fdSJeff Kirsher #define GRETH_TXBD_MORE 0x20000
321fe003fdSJeff Kirsher #define GRETH_TXBD_IPCS 0x40000
331fe003fdSJeff Kirsher #define GRETH_TXBD_TCPCS 0x80000
341fe003fdSJeff Kirsher #define GRETH_TXBD_UDPCS 0x100000
351fe003fdSJeff Kirsher #define GRETH_TXBD_CSALL (GRETH_TXBD_IPCS | GRETH_TXBD_TCPCS | GRETH_TXBD_UDPCS)
361fe003fdSJeff Kirsher #define GRETH_TXBD_ERR_LC 0x10000
371fe003fdSJeff Kirsher #define GRETH_TXBD_ERR_UE 0x4000
381fe003fdSJeff Kirsher #define GRETH_TXBD_ERR_AL 0x8000
391fe003fdSJeff Kirsher 
401fe003fdSJeff Kirsher #define GRETH_INT_RE         0x1
411fe003fdSJeff Kirsher #define GRETH_INT_RX         0x4
421fe003fdSJeff Kirsher #define GRETH_RXEN           0x2
431fe003fdSJeff Kirsher #define GRETH_RXI            0x8
441fe003fdSJeff Kirsher #define GRETH_RXBD_STATUS    0xFFFFC000
451fe003fdSJeff Kirsher #define GRETH_RXBD_ERR_AE    0x4000
461fe003fdSJeff Kirsher #define GRETH_RXBD_ERR_FT    0x8000
471fe003fdSJeff Kirsher #define GRETH_RXBD_ERR_CRC   0x10000
481fe003fdSJeff Kirsher #define GRETH_RXBD_ERR_OE    0x20000
491fe003fdSJeff Kirsher #define GRETH_RXBD_ERR_LE    0x40000
501fe003fdSJeff Kirsher #define GRETH_RXBD_IP        0x80000
511fe003fdSJeff Kirsher #define GRETH_RXBD_IP_CSERR  0x100000
521fe003fdSJeff Kirsher #define GRETH_RXBD_UDP       0x200000
531fe003fdSJeff Kirsher #define GRETH_RXBD_UDP_CSERR 0x400000
541fe003fdSJeff Kirsher #define GRETH_RXBD_TCP       0x800000
551fe003fdSJeff Kirsher #define GRETH_RXBD_TCP_CSERR 0x1000000
561fe003fdSJeff Kirsher #define GRETH_RXBD_IP_FRAG   0x2000000
571fe003fdSJeff Kirsher #define GRETH_RXBD_MCAST     0x4000000
581fe003fdSJeff Kirsher 
591fe003fdSJeff Kirsher /* Descriptor parameters */
601fe003fdSJeff Kirsher #define GRETH_TXBD_NUM 128
611fe003fdSJeff Kirsher #define GRETH_TXBD_NUM_MASK (GRETH_TXBD_NUM-1)
621fe003fdSJeff Kirsher #define GRETH_TX_BUF_SIZE 2048
631fe003fdSJeff Kirsher #define GRETH_RXBD_NUM 128
641fe003fdSJeff Kirsher #define GRETH_RXBD_NUM_MASK (GRETH_RXBD_NUM-1)
651fe003fdSJeff Kirsher #define GRETH_RX_BUF_SIZE 2048
661fe003fdSJeff Kirsher 
671fe003fdSJeff Kirsher /* Buffers per page */
681fe003fdSJeff Kirsher #define GRETH_RX_BUF_PPGAE	(PAGE_SIZE/GRETH_RX_BUF_SIZE)
691fe003fdSJeff Kirsher #define GRETH_TX_BUF_PPGAE	(PAGE_SIZE/GRETH_TX_BUF_SIZE)
701fe003fdSJeff Kirsher 
711fe003fdSJeff Kirsher /* How many pages are needed for buffers */
721fe003fdSJeff Kirsher #define GRETH_RX_BUF_PAGE_NUM	(GRETH_RXBD_NUM/GRETH_RX_BUF_PPGAE)
731fe003fdSJeff Kirsher #define GRETH_TX_BUF_PAGE_NUM	(GRETH_TXBD_NUM/GRETH_TX_BUF_PPGAE)
741fe003fdSJeff Kirsher 
751fe003fdSJeff Kirsher /* Buffer size.
761fe003fdSJeff Kirsher  * Gbit MAC uses tagged maximum frame size which is 1518 excluding CRC.
771fe003fdSJeff Kirsher  * Set to 1520 to make all buffers word aligned for non-gbit MAC.
781fe003fdSJeff Kirsher  */
791fe003fdSJeff Kirsher #define MAX_FRAME_SIZE		1520
801fe003fdSJeff Kirsher 
811fe003fdSJeff Kirsher /* GRETH APB registers */
821fe003fdSJeff Kirsher struct greth_regs {
831fe003fdSJeff Kirsher 	u32 control;
841fe003fdSJeff Kirsher 	u32 status;
851fe003fdSJeff Kirsher 	u32 esa_msb;
861fe003fdSJeff Kirsher 	u32 esa_lsb;
871fe003fdSJeff Kirsher 	u32 mdio;
881fe003fdSJeff Kirsher 	u32 tx_desc_p;
891fe003fdSJeff Kirsher 	u32 rx_desc_p;
901fe003fdSJeff Kirsher 	u32 edclip;
911fe003fdSJeff Kirsher 	u32 hash_msb;
921fe003fdSJeff Kirsher 	u32 hash_lsb;
931fe003fdSJeff Kirsher };
941fe003fdSJeff Kirsher 
951fe003fdSJeff Kirsher /* GRETH buffer descriptor */
961fe003fdSJeff Kirsher struct greth_bd {
971fe003fdSJeff Kirsher 	u32 stat;
981fe003fdSJeff Kirsher 	u32 addr;
991fe003fdSJeff Kirsher };
1001fe003fdSJeff Kirsher 
1011fe003fdSJeff Kirsher struct greth_private {
1021fe003fdSJeff Kirsher 	struct sk_buff *rx_skbuff[GRETH_RXBD_NUM];
1031fe003fdSJeff Kirsher 	struct sk_buff *tx_skbuff[GRETH_TXBD_NUM];
1041fe003fdSJeff Kirsher 
1051fe003fdSJeff Kirsher 	unsigned char *tx_bufs[GRETH_TXBD_NUM];
1061fe003fdSJeff Kirsher 	unsigned char *rx_bufs[GRETH_RXBD_NUM];
1078decf868SDavid S. Miller 	u16 tx_bufs_length[GRETH_TXBD_NUM];
1081fe003fdSJeff Kirsher 
1091fe003fdSJeff Kirsher 	u16 tx_next;
1101fe003fdSJeff Kirsher 	u16 tx_last;
111e1743a16SDaniel Hellstrom 	u16 tx_free; /* only used on 10/100Mbit */
1121fe003fdSJeff Kirsher 	u16 rx_cur;
1131fe003fdSJeff Kirsher 
1141fe003fdSJeff Kirsher 	struct greth_regs *regs;	/* Address of controller registers. */
1151fe003fdSJeff Kirsher 	struct greth_bd *rx_bd_base;	/* Address of Rx BDs. */
1161fe003fdSJeff Kirsher 	struct greth_bd *tx_bd_base;	/* Address of Tx BDs. */
1171fe003fdSJeff Kirsher 	dma_addr_t rx_bd_base_phys;
1181fe003fdSJeff Kirsher 	dma_addr_t tx_bd_base_phys;
1191fe003fdSJeff Kirsher 
1201fe003fdSJeff Kirsher 	int irq;
1211fe003fdSJeff Kirsher 
1221fe003fdSJeff Kirsher 	struct device *dev;	        /* Pointer to platform_device->dev */
1231fe003fdSJeff Kirsher 	struct net_device *netdev;
1241fe003fdSJeff Kirsher 	struct napi_struct napi;
1251fe003fdSJeff Kirsher 	spinlock_t devlock;
1261fe003fdSJeff Kirsher 
1271fe003fdSJeff Kirsher 	struct mii_bus *mdio;
1281fe003fdSJeff Kirsher 	unsigned int link;
1291fe003fdSJeff Kirsher 	unsigned int speed;
1301fe003fdSJeff Kirsher 	unsigned int duplex;
1311fe003fdSJeff Kirsher 
1321fe003fdSJeff Kirsher 	u32 msg_enable;
1331fe003fdSJeff Kirsher 
1341fe003fdSJeff Kirsher 	u8 phyaddr;
1351fe003fdSJeff Kirsher 	u8 multicast;
1361fe003fdSJeff Kirsher 	u8 gbit_mac;
1371fe003fdSJeff Kirsher 	u8 mdio_int_en;
1381fe003fdSJeff Kirsher 	u8 edcl;
1391fe003fdSJeff Kirsher };
1401fe003fdSJeff Kirsher 
1411fe003fdSJeff Kirsher #endif
142