18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Tehuti Networks(R) Network Driver
48c2ecf20Sopenharmony_ci * Copyright (C) 2007 Tehuti Networks Ltd. All rights reserved
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _TEHUTI_H
88c2ecf20Sopenharmony_ci#define _TEHUTI_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/kernel.h>
128c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
138c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
148c2ecf20Sopenharmony_ci#include <linux/pci.h>
158c2ecf20Sopenharmony_ci#include <linux/delay.h>
168c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
178c2ecf20Sopenharmony_ci#include <linux/mii.h>
188c2ecf20Sopenharmony_ci#include <linux/crc32.h>
198c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
208c2ecf20Sopenharmony_ci#include <linux/in.h>
218c2ecf20Sopenharmony_ci#include <linux/ip.h>
228c2ecf20Sopenharmony_ci#include <linux/tcp.h>
238c2ecf20Sopenharmony_ci#include <linux/sched.h>
248c2ecf20Sopenharmony_ci#include <linux/tty.h>
258c2ecf20Sopenharmony_ci#include <linux/if_vlan.h>
268c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
278c2ecf20Sopenharmony_ci#include <linux/vmalloc.h>
288c2ecf20Sopenharmony_ci#include <linux/firmware.h>
298c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
308c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
318c2ecf20Sopenharmony_ci#include <linux/slab.h>
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* Compile Time Switches */
348c2ecf20Sopenharmony_ci/* start */
358c2ecf20Sopenharmony_ci#define BDX_TSO
368c2ecf20Sopenharmony_ci#define BDX_LLTX
378c2ecf20Sopenharmony_ci#define BDX_DELAY_WPTR
388c2ecf20Sopenharmony_ci/* #define BDX_MSI */
398c2ecf20Sopenharmony_ci/* end */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#if !defined CONFIG_PCI_MSI
428c2ecf20Sopenharmony_ci#   undef BDX_MSI
438c2ecf20Sopenharmony_ci#endif
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define BDX_DEF_MSG_ENABLE	(NETIF_MSG_DRV          | \
468c2ecf20Sopenharmony_ci				NETIF_MSG_PROBE        | \
478c2ecf20Sopenharmony_ci				NETIF_MSG_LINK)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* ioctl ops */
508c2ecf20Sopenharmony_ci#define BDX_OP_READ  1
518c2ecf20Sopenharmony_ci#define BDX_OP_WRITE 2
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* RX copy break size */
548c2ecf20Sopenharmony_ci#define BDX_COPYBREAK    257
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR     "Tehuti Networks(R)"
578c2ecf20Sopenharmony_ci#define BDX_DRV_DESC      "Tehuti Networks(R) Network Driver"
588c2ecf20Sopenharmony_ci#define BDX_DRV_NAME      "tehuti"
598c2ecf20Sopenharmony_ci#define BDX_NIC_NAME      "Tehuti 10 Giga TOE SmartNIC"
608c2ecf20Sopenharmony_ci#define BDX_NIC2PORT_NAME "Tehuti 2-Port 10 Giga TOE SmartNIC"
618c2ecf20Sopenharmony_ci#define BDX_DRV_VERSION   "7.29.3"
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#ifdef BDX_MSI
648c2ecf20Sopenharmony_ci#    define BDX_MSI_STRING "msi "
658c2ecf20Sopenharmony_ci#else
668c2ecf20Sopenharmony_ci#    define BDX_MSI_STRING ""
678c2ecf20Sopenharmony_ci#endif
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* netdev tx queue len for Luxor. default value is, btw, 1000
708c2ecf20Sopenharmony_ci * ifcontig eth1 txqueuelen 3000 - to change it at runtime */
718c2ecf20Sopenharmony_ci#define BDX_NDEV_TXQ_LEN 3000
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* Max MTU for Jumbo Frame mode, per tehutinetworks.net Features FAQ is 16k */
748c2ecf20Sopenharmony_ci#define BDX_MAX_MTU	(16 * 1024)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define FIFO_SIZE  4096
778c2ecf20Sopenharmony_ci#define FIFO_EXTRA_SPACE            1024
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 64
808c2ecf20Sopenharmony_ci#    define H32_64(x)  (u32) ((u64)(x) >> 32)
818c2ecf20Sopenharmony_ci#    define L32_64(x)  (u32) ((u64)(x) & 0xffffffff)
828c2ecf20Sopenharmony_ci#elif BITS_PER_LONG == 32
838c2ecf20Sopenharmony_ci#    define H32_64(x)  0
848c2ecf20Sopenharmony_ci#    define L32_64(x)  ((u32) (x))
858c2ecf20Sopenharmony_ci#else				/* BITS_PER_LONG == ?? */
868c2ecf20Sopenharmony_ci#    error BITS_PER_LONG is undefined. Must be 64 or 32
878c2ecf20Sopenharmony_ci#endif				/* BITS_PER_LONG */
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
908c2ecf20Sopenharmony_ci#   define CPU_CHIP_SWAP32(x) swab32(x)
918c2ecf20Sopenharmony_ci#   define CPU_CHIP_SWAP16(x) swab16(x)
928c2ecf20Sopenharmony_ci#else
938c2ecf20Sopenharmony_ci#   define CPU_CHIP_SWAP32(x) (x)
948c2ecf20Sopenharmony_ci#   define CPU_CHIP_SWAP16(x) (x)
958c2ecf20Sopenharmony_ci#endif
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define READ_REG(pp, reg)         readl(pp->pBdxRegs + reg)
988c2ecf20Sopenharmony_ci#define WRITE_REG(pp, reg, val)   writel(val, pp->pBdxRegs + reg)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#ifndef NET_IP_ALIGN
1018c2ecf20Sopenharmony_ci#   define NET_IP_ALIGN 2
1028c2ecf20Sopenharmony_ci#endif
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#ifndef NETDEV_TX_OK
1058c2ecf20Sopenharmony_ci#   define NETDEV_TX_OK 0
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define LUXOR_MAX_PORT     2
1098c2ecf20Sopenharmony_ci#define BDX_MAX_RX_DONE    150
1108c2ecf20Sopenharmony_ci#define BDX_TXF_DESC_SZ    16
1118c2ecf20Sopenharmony_ci#define BDX_MAX_TX_LEVEL   (priv->txd_fifo0.m.memsz - 16)
1128c2ecf20Sopenharmony_ci#define BDX_MIN_TX_LEVEL   256
1138c2ecf20Sopenharmony_ci#define BDX_NO_UPD_PACKETS 40
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistruct pci_nic {
1168c2ecf20Sopenharmony_ci	int port_num;
1178c2ecf20Sopenharmony_ci	void __iomem *regs;
1188c2ecf20Sopenharmony_ci	int irq_type;
1198c2ecf20Sopenharmony_ci	struct bdx_priv *priv[LUXOR_MAX_PORT];
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cienum { IRQ_INTX, IRQ_MSI, IRQ_MSIX };
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define PCK_TH_MULT   128
1258c2ecf20Sopenharmony_ci#define INT_COAL_MULT 2
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define BITS_MASK(nbits)			((1<<nbits)-1)
1288c2ecf20Sopenharmony_ci#define GET_BITS_SHIFT(x, nbits, nshift)	(((x)>>nshift)&BITS_MASK(nbits))
1298c2ecf20Sopenharmony_ci#define BITS_SHIFT_MASK(nbits, nshift)		(BITS_MASK(nbits)<<nshift)
1308c2ecf20Sopenharmony_ci#define BITS_SHIFT_VAL(x, nbits, nshift)	(((x)&BITS_MASK(nbits))<<nshift)
1318c2ecf20Sopenharmony_ci#define BITS_SHIFT_CLEAR(x, nbits, nshift)	\
1328c2ecf20Sopenharmony_ci	((x)&(~BITS_SHIFT_MASK(nbits, nshift)))
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define GET_INT_COAL(x)				GET_BITS_SHIFT(x, 15, 0)
1358c2ecf20Sopenharmony_ci#define GET_INT_COAL_RC(x)			GET_BITS_SHIFT(x, 1, 15)
1368c2ecf20Sopenharmony_ci#define GET_RXF_TH(x)				GET_BITS_SHIFT(x, 4, 16)
1378c2ecf20Sopenharmony_ci#define GET_PCK_TH(x)				GET_BITS_SHIFT(x, 4, 20)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define INT_REG_VAL(coal, coal_rc, rxf_th, pck_th)	\
1408c2ecf20Sopenharmony_ci	((coal)|((coal_rc)<<15)|((rxf_th)<<16)|((pck_th)<<20))
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistruct fifo {
1438c2ecf20Sopenharmony_ci	dma_addr_t da;		/* physical address of fifo (used by HW) */
1448c2ecf20Sopenharmony_ci	char *va;		/* virtual address of fifo (used by SW) */
1458c2ecf20Sopenharmony_ci	u32 rptr, wptr;		/* cached values of RPTR and WPTR registers,
1468c2ecf20Sopenharmony_ci				   they're 32 bits on both 32 and 64 archs */
1478c2ecf20Sopenharmony_ci	u16 reg_CFG0, reg_CFG1;
1488c2ecf20Sopenharmony_ci	u16 reg_RPTR, reg_WPTR;
1498c2ecf20Sopenharmony_ci	u16 memsz;		/* memory size allocated for fifo */
1508c2ecf20Sopenharmony_ci	u16 size_mask;
1518c2ecf20Sopenharmony_ci	u16 pktsz;		/* skb packet size to allocate */
1528c2ecf20Sopenharmony_ci	u16 rcvno;		/* number of buffers that come from this RXF */
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistruct txf_fifo {
1568c2ecf20Sopenharmony_ci	struct fifo m;		/* minimal set of variables used by all fifos */
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistruct txd_fifo {
1608c2ecf20Sopenharmony_ci	struct fifo m;		/* minimal set of variables used by all fifos */
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistruct rxf_fifo {
1648c2ecf20Sopenharmony_ci	struct fifo m;		/* minimal set of variables used by all fifos */
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistruct rxd_fifo {
1688c2ecf20Sopenharmony_ci	struct fifo m;		/* minimal set of variables used by all fifos */
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistruct rx_map {
1728c2ecf20Sopenharmony_ci	u64 dma;
1738c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1748c2ecf20Sopenharmony_ci};
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistruct rxdb {
1778c2ecf20Sopenharmony_ci	int *stack;
1788c2ecf20Sopenharmony_ci	struct rx_map *elems;
1798c2ecf20Sopenharmony_ci	int nelem;
1808c2ecf20Sopenharmony_ci	int top;
1818c2ecf20Sopenharmony_ci};
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ciunion bdx_dma_addr {
1848c2ecf20Sopenharmony_ci	dma_addr_t dma;
1858c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* Entry in the db.
1898c2ecf20Sopenharmony_ci * if len == 0 addr is dma
1908c2ecf20Sopenharmony_ci * if len != 0 addr is skb */
1918c2ecf20Sopenharmony_cistruct tx_map {
1928c2ecf20Sopenharmony_ci	union bdx_dma_addr addr;
1938c2ecf20Sopenharmony_ci	int len;
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/* tx database - implemented as circular fifo buffer*/
1978c2ecf20Sopenharmony_cistruct txdb {
1988c2ecf20Sopenharmony_ci	struct tx_map *start;	/* points to the first element */
1998c2ecf20Sopenharmony_ci	struct tx_map *end;	/* points just AFTER the last element */
2008c2ecf20Sopenharmony_ci	struct tx_map *rptr;	/* points to the next element to read */
2018c2ecf20Sopenharmony_ci	struct tx_map *wptr;	/* points to the next element to write */
2028c2ecf20Sopenharmony_ci	int size;		/* number of elements in the db */
2038c2ecf20Sopenharmony_ci};
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci/*Internal stats structure*/
2068c2ecf20Sopenharmony_cistruct bdx_stats {
2078c2ecf20Sopenharmony_ci	u64 InUCast;			/* 0x7200 */
2088c2ecf20Sopenharmony_ci	u64 InMCast;			/* 0x7210 */
2098c2ecf20Sopenharmony_ci	u64 InBCast;			/* 0x7220 */
2108c2ecf20Sopenharmony_ci	u64 InPkts;			/* 0x7230 */
2118c2ecf20Sopenharmony_ci	u64 InErrors;			/* 0x7240 */
2128c2ecf20Sopenharmony_ci	u64 InDropped;			/* 0x7250 */
2138c2ecf20Sopenharmony_ci	u64 FrameTooLong;		/* 0x7260 */
2148c2ecf20Sopenharmony_ci	u64 FrameSequenceErrors;	/* 0x7270 */
2158c2ecf20Sopenharmony_ci	u64 InVLAN;			/* 0x7280 */
2168c2ecf20Sopenharmony_ci	u64 InDroppedDFE;		/* 0x7290 */
2178c2ecf20Sopenharmony_ci	u64 InDroppedIntFull;		/* 0x72A0 */
2188c2ecf20Sopenharmony_ci	u64 InFrameAlignErrors;		/* 0x72B0 */
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* 0x72C0-0x72E0 RSRV */
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	u64 OutUCast;			/* 0x72F0 */
2238c2ecf20Sopenharmony_ci	u64 OutMCast;			/* 0x7300 */
2248c2ecf20Sopenharmony_ci	u64 OutBCast;			/* 0x7310 */
2258c2ecf20Sopenharmony_ci	u64 OutPkts;			/* 0x7320 */
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	/* 0x7330-0x7360 RSRV */
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	u64 OutVLAN;			/* 0x7370 */
2308c2ecf20Sopenharmony_ci	u64 InUCastOctects;		/* 0x7380 */
2318c2ecf20Sopenharmony_ci	u64 OutUCastOctects;		/* 0x7390 */
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	/* 0x73A0-0x73B0 RSRV */
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	u64 InBCastOctects;		/* 0x73C0 */
2368c2ecf20Sopenharmony_ci	u64 OutBCastOctects;		/* 0x73D0 */
2378c2ecf20Sopenharmony_ci	u64 InOctects;			/* 0x73E0 */
2388c2ecf20Sopenharmony_ci	u64 OutOctects;			/* 0x73F0 */
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistruct bdx_priv {
2428c2ecf20Sopenharmony_ci	void __iomem *pBdxRegs;
2438c2ecf20Sopenharmony_ci	struct net_device *ndev;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	struct napi_struct napi;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	/* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
2488c2ecf20Sopenharmony_ci	struct rxd_fifo rxd_fifo0;
2498c2ecf20Sopenharmony_ci	struct rxf_fifo rxf_fifo0;
2508c2ecf20Sopenharmony_ci	struct rxdb *rxdb;	/* rx dbs to store skb pointers */
2518c2ecf20Sopenharmony_ci	int napi_stop;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	/* Tx FIFOs: 1 for data desc, 1 for empty (acks) desc */
2548c2ecf20Sopenharmony_ci	struct txd_fifo txd_fifo0;
2558c2ecf20Sopenharmony_ci	struct txf_fifo txf_fifo0;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	struct txdb txdb;
2588c2ecf20Sopenharmony_ci	int tx_level;
2598c2ecf20Sopenharmony_ci#ifdef BDX_DELAY_WPTR
2608c2ecf20Sopenharmony_ci	int tx_update_mark;
2618c2ecf20Sopenharmony_ci	int tx_noupd;
2628c2ecf20Sopenharmony_ci#endif
2638c2ecf20Sopenharmony_ci	spinlock_t tx_lock;	/* NETIF_F_LLTX mode */
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/* rarely used */
2668c2ecf20Sopenharmony_ci	u8 port;
2678c2ecf20Sopenharmony_ci	u32 msg_enable;
2688c2ecf20Sopenharmony_ci	int stats_flag;
2698c2ecf20Sopenharmony_ci	struct bdx_stats hw_stats;
2708c2ecf20Sopenharmony_ci	struct pci_dev *pdev;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	struct pci_nic *nic;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	u8 txd_size;
2758c2ecf20Sopenharmony_ci	u8 txf_size;
2768c2ecf20Sopenharmony_ci	u8 rxd_size;
2778c2ecf20Sopenharmony_ci	u8 rxf_size;
2788c2ecf20Sopenharmony_ci	u32 rdintcm;
2798c2ecf20Sopenharmony_ci	u32 tdintcm;
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* RX FREE descriptor - 64bit*/
2838c2ecf20Sopenharmony_cistruct rxf_desc {
2848c2ecf20Sopenharmony_ci	u32 info;		/* Buffer Count + Info - described below */
2858c2ecf20Sopenharmony_ci	u32 va_lo;		/* VAdr[31:0] */
2868c2ecf20Sopenharmony_ci	u32 va_hi;		/* VAdr[63:32] */
2878c2ecf20Sopenharmony_ci	u32 pa_lo;		/* PAdr[31:0] */
2888c2ecf20Sopenharmony_ci	u32 pa_hi;		/* PAdr[63:32] */
2898c2ecf20Sopenharmony_ci	u32 len;		/* Buffer Length */
2908c2ecf20Sopenharmony_ci};
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#define GET_RXD_BC(x)			GET_BITS_SHIFT((x), 5, 0)
2938c2ecf20Sopenharmony_ci#define GET_RXD_RXFQ(x)			GET_BITS_SHIFT((x), 2, 8)
2948c2ecf20Sopenharmony_ci#define GET_RXD_TO(x)			GET_BITS_SHIFT((x), 1, 15)
2958c2ecf20Sopenharmony_ci#define GET_RXD_TYPE(x)			GET_BITS_SHIFT((x), 4, 16)
2968c2ecf20Sopenharmony_ci#define GET_RXD_ERR(x)			GET_BITS_SHIFT((x), 6, 21)
2978c2ecf20Sopenharmony_ci#define GET_RXD_RXP(x)			GET_BITS_SHIFT((x), 1, 27)
2988c2ecf20Sopenharmony_ci#define GET_RXD_PKT_ID(x)		GET_BITS_SHIFT((x), 3, 28)
2998c2ecf20Sopenharmony_ci#define GET_RXD_VTAG(x)			GET_BITS_SHIFT((x), 1, 31)
3008c2ecf20Sopenharmony_ci#define GET_RXD_VLAN_ID(x)		GET_BITS_SHIFT((x), 12, 0)
3018c2ecf20Sopenharmony_ci#define GET_RXD_VLAN_TCI(x)		GET_BITS_SHIFT((x), 16, 0)
3028c2ecf20Sopenharmony_ci#define GET_RXD_CFI(x)			GET_BITS_SHIFT((x), 1, 12)
3038c2ecf20Sopenharmony_ci#define GET_RXD_PRIO(x)			GET_BITS_SHIFT((x), 3, 13)
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistruct rxd_desc {
3068c2ecf20Sopenharmony_ci	u32 rxd_val1;
3078c2ecf20Sopenharmony_ci	u16 len;
3088c2ecf20Sopenharmony_ci	u16 rxd_vlan;
3098c2ecf20Sopenharmony_ci	u32 va_lo;
3108c2ecf20Sopenharmony_ci	u32 va_hi;
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci/* PBL describes each virtual buffer to be */
3148c2ecf20Sopenharmony_ci/* transmitted from the host.*/
3158c2ecf20Sopenharmony_cistruct pbl {
3168c2ecf20Sopenharmony_ci	u32 pa_lo;
3178c2ecf20Sopenharmony_ci	u32 pa_hi;
3188c2ecf20Sopenharmony_ci	u32 len;
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/* First word for TXD descriptor. It means: type = 3 for regular Tx packet,
3228c2ecf20Sopenharmony_ci * hw_csum = 7 for ip+udp+tcp hw checksums */
3238c2ecf20Sopenharmony_ci#define TXD_W1_VAL(bc, checksum, vtag, lgsnd, vlan_id)	\
3248c2ecf20Sopenharmony_ci	((bc) | ((checksum)<<5) | ((vtag)<<8) | \
3258c2ecf20Sopenharmony_ci	((lgsnd)<<9) | (0x30000) | ((vlan_id)<<20))
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistruct txd_desc {
3288c2ecf20Sopenharmony_ci	u32 txd_val1;
3298c2ecf20Sopenharmony_ci	u16 mss;
3308c2ecf20Sopenharmony_ci	u16 length;
3318c2ecf20Sopenharmony_ci	u32 va_lo;
3328c2ecf20Sopenharmony_ci	u32 va_hi;
3338c2ecf20Sopenharmony_ci	struct pbl pbl[];	/* Fragments */
3348c2ecf20Sopenharmony_ci} __packed;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/* Register region size */
3378c2ecf20Sopenharmony_ci#define BDX_REGS_SIZE	  0x1000
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci/* Registers from 0x0000-0x00fc were remapped to 0x4000-0x40fc */
3408c2ecf20Sopenharmony_ci#define regTXD_CFG1_0   0x4000
3418c2ecf20Sopenharmony_ci#define regRXF_CFG1_0   0x4010
3428c2ecf20Sopenharmony_ci#define regRXD_CFG1_0   0x4020
3438c2ecf20Sopenharmony_ci#define regTXF_CFG1_0   0x4030
3448c2ecf20Sopenharmony_ci#define regTXD_CFG0_0   0x4040
3458c2ecf20Sopenharmony_ci#define regRXF_CFG0_0   0x4050
3468c2ecf20Sopenharmony_ci#define regRXD_CFG0_0   0x4060
3478c2ecf20Sopenharmony_ci#define regTXF_CFG0_0   0x4070
3488c2ecf20Sopenharmony_ci#define regTXD_WPTR_0   0x4080
3498c2ecf20Sopenharmony_ci#define regRXF_WPTR_0   0x4090
3508c2ecf20Sopenharmony_ci#define regRXD_WPTR_0   0x40A0
3518c2ecf20Sopenharmony_ci#define regTXF_WPTR_0   0x40B0
3528c2ecf20Sopenharmony_ci#define regTXD_RPTR_0   0x40C0
3538c2ecf20Sopenharmony_ci#define regRXF_RPTR_0   0x40D0
3548c2ecf20Sopenharmony_ci#define regRXD_RPTR_0   0x40E0
3558c2ecf20Sopenharmony_ci#define regTXF_RPTR_0   0x40F0
3568c2ecf20Sopenharmony_ci#define regTXF_RPTR_3   0x40FC
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci/* hardware versioning */
3598c2ecf20Sopenharmony_ci#define  FW_VER         0x5010
3608c2ecf20Sopenharmony_ci#define  SROM_VER       0x5020
3618c2ecf20Sopenharmony_ci#define  FPGA_VER       0x5030
3628c2ecf20Sopenharmony_ci#define  FPGA_SEED      0x5040
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci/* Registers from 0x0100-0x0150 were remapped to 0x5100-0x5150 */
3658c2ecf20Sopenharmony_ci#define regISR regISR0
3668c2ecf20Sopenharmony_ci#define regISR0          0x5100
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci#define regIMR regIMR0
3698c2ecf20Sopenharmony_ci#define regIMR0          0x5110
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci#define regRDINTCM0      0x5120
3728c2ecf20Sopenharmony_ci#define regRDINTCM2      0x5128
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci#define regTDINTCM0      0x5130
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci#define regISR_MSK0      0x5140
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci#define regINIT_SEMAPHORE 0x5170
3798c2ecf20Sopenharmony_ci#define regINIT_STATUS    0x5180
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci#define regMAC_LNK_STAT  0x0200
3828c2ecf20Sopenharmony_ci#define MAC_LINK_STAT    0x4	/* Link state */
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci#define regGMAC_RXF_A   0x1240
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci#define regUNC_MAC0_A   0x1250
3878c2ecf20Sopenharmony_ci#define regUNC_MAC1_A   0x1260
3888c2ecf20Sopenharmony_ci#define regUNC_MAC2_A   0x1270
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define regVLAN_0       0x1800
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci#define regMAX_FRAME_A  0x12C0
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci#define regRX_MAC_MCST0    0x1A80
3958c2ecf20Sopenharmony_ci#define regRX_MAC_MCST1    0x1A84
3968c2ecf20Sopenharmony_ci#define MAC_MCST_NUM       15
3978c2ecf20Sopenharmony_ci#define regRX_MCST_HASH0   0x1A00
3988c2ecf20Sopenharmony_ci#define MAC_MCST_HASH_NUM  8
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci#define regVPC                  0x2300
4018c2ecf20Sopenharmony_ci#define regVIC                  0x2320
4028c2ecf20Sopenharmony_ci#define regVGLB                 0x2340
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci#define regCLKPLL               0x5000
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/*for 10G only*/
4078c2ecf20Sopenharmony_ci#define regREVISION        0x6000
4088c2ecf20Sopenharmony_ci#define regSCRATCH         0x6004
4098c2ecf20Sopenharmony_ci#define regCTRLST          0x6008
4108c2ecf20Sopenharmony_ci#define regMAC_ADDR_0      0x600C
4118c2ecf20Sopenharmony_ci#define regMAC_ADDR_1      0x6010
4128c2ecf20Sopenharmony_ci#define regFRM_LENGTH      0x6014
4138c2ecf20Sopenharmony_ci#define regPAUSE_QUANT     0x6018
4148c2ecf20Sopenharmony_ci#define regRX_FIFO_SECTION 0x601C
4158c2ecf20Sopenharmony_ci#define regTX_FIFO_SECTION 0x6020
4168c2ecf20Sopenharmony_ci#define regRX_FULLNESS     0x6024
4178c2ecf20Sopenharmony_ci#define regTX_FULLNESS     0x6028
4188c2ecf20Sopenharmony_ci#define regHASHTABLE       0x602C
4198c2ecf20Sopenharmony_ci#define regMDIO_ST         0x6030
4208c2ecf20Sopenharmony_ci#define regMDIO_CTL        0x6034
4218c2ecf20Sopenharmony_ci#define regMDIO_DATA       0x6038
4228c2ecf20Sopenharmony_ci#define regMDIO_ADDR       0x603C
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define regRST_PORT        0x7000
4258c2ecf20Sopenharmony_ci#define regDIS_PORT        0x7010
4268c2ecf20Sopenharmony_ci#define regRST_QU          0x7020
4278c2ecf20Sopenharmony_ci#define regDIS_QU          0x7030
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci#define regCTRLST_TX_ENA   0x0001
4308c2ecf20Sopenharmony_ci#define regCTRLST_RX_ENA   0x0002
4318c2ecf20Sopenharmony_ci#define regCTRLST_PRM_ENA  0x0010
4328c2ecf20Sopenharmony_ci#define regCTRLST_PAD_ENA  0x0020
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci#define regCTRLST_BASE     (regCTRLST_PAD_ENA|regCTRLST_PRM_ENA)
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci#define regRX_FLT   0x1400
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/* TXD TXF RXF RXD  CONFIG 0x0000 --- 0x007c*/
4398c2ecf20Sopenharmony_ci#define  TX_RX_CFG1_BASE          0xffffffff	/*0-31 */
4408c2ecf20Sopenharmony_ci#define  TX_RX_CFG0_BASE          0xfffff000	/*31:12 */
4418c2ecf20Sopenharmony_ci#define  TX_RX_CFG0_RSVD          0x0ffc	/*11:2 */
4428c2ecf20Sopenharmony_ci#define  TX_RX_CFG0_SIZE          0x0003	/*1:0 */
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci/*  TXD TXF RXF RXD  WRITE 0x0080 --- 0x00BC */
4458c2ecf20Sopenharmony_ci#define  TXF_WPTR_WR_PTR        0x7ff8	/*14:3 */
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/*  TXD TXF RXF RXD  READ  0x00CO --- 0x00FC */
4488c2ecf20Sopenharmony_ci#define  TXF_RPTR_RD_PTR        0x7ff8	/*14:3 */
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci#define TXF_WPTR_MASK 0x7ff0	/* last 4 bits are dropped
4518c2ecf20Sopenharmony_ci				 * size is rounded to 16 */
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/*  regISR 0x0100 */
4548c2ecf20Sopenharmony_ci/*  regIMR 0x0110 */
4558c2ecf20Sopenharmony_ci#define  IMR_INPROG   0x80000000	/*31 */
4568c2ecf20Sopenharmony_ci#define  IR_LNKCHG1   0x10000000	/*28 */
4578c2ecf20Sopenharmony_ci#define  IR_LNKCHG0   0x08000000	/*27 */
4588c2ecf20Sopenharmony_ci#define  IR_GPIO      0x04000000	/*26 */
4598c2ecf20Sopenharmony_ci#define  IR_RFRSH     0x02000000	/*25 */
4608c2ecf20Sopenharmony_ci#define  IR_RSVD      0x01000000	/*24 */
4618c2ecf20Sopenharmony_ci#define  IR_SWI       0x00800000	/*23 */
4628c2ecf20Sopenharmony_ci#define  IR_RX_FREE_3 0x00400000	/*22 */
4638c2ecf20Sopenharmony_ci#define  IR_RX_FREE_2 0x00200000	/*21 */
4648c2ecf20Sopenharmony_ci#define  IR_RX_FREE_1 0x00100000	/*20 */
4658c2ecf20Sopenharmony_ci#define  IR_RX_FREE_0 0x00080000	/*19 */
4668c2ecf20Sopenharmony_ci#define  IR_TX_FREE_3 0x00040000	/*18 */
4678c2ecf20Sopenharmony_ci#define  IR_TX_FREE_2 0x00020000	/*17 */
4688c2ecf20Sopenharmony_ci#define  IR_TX_FREE_1 0x00010000	/*16 */
4698c2ecf20Sopenharmony_ci#define  IR_TX_FREE_0 0x00008000	/*15 */
4708c2ecf20Sopenharmony_ci#define  IR_RX_DESC_3 0x00004000	/*14 */
4718c2ecf20Sopenharmony_ci#define  IR_RX_DESC_2 0x00002000	/*13 */
4728c2ecf20Sopenharmony_ci#define  IR_RX_DESC_1 0x00001000	/*12 */
4738c2ecf20Sopenharmony_ci#define  IR_RX_DESC_0 0x00000800	/*11 */
4748c2ecf20Sopenharmony_ci#define  IR_PSE       0x00000400	/*10 */
4758c2ecf20Sopenharmony_ci#define  IR_TMR3      0x00000200	/*9 */
4768c2ecf20Sopenharmony_ci#define  IR_TMR2      0x00000100	/*8 */
4778c2ecf20Sopenharmony_ci#define  IR_TMR1      0x00000080	/*7 */
4788c2ecf20Sopenharmony_ci#define  IR_TMR0      0x00000040	/*6 */
4798c2ecf20Sopenharmony_ci#define  IR_VNT       0x00000020	/*5 */
4808c2ecf20Sopenharmony_ci#define  IR_RxFL      0x00000010	/*4 */
4818c2ecf20Sopenharmony_ci#define  IR_SDPERR    0x00000008	/*3 */
4828c2ecf20Sopenharmony_ci#define  IR_TR        0x00000004	/*2 */
4838c2ecf20Sopenharmony_ci#define  IR_PCIE_LINK 0x00000002	/*1 */
4848c2ecf20Sopenharmony_ci#define  IR_PCIE_TOUT 0x00000001	/*0 */
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci#define  IR_EXTRA (IR_RX_FREE_0 | IR_LNKCHG0 | IR_PSE | \
4878c2ecf20Sopenharmony_ci    IR_TMR0 | IR_PCIE_LINK | IR_PCIE_TOUT)
4888c2ecf20Sopenharmony_ci#define  IR_RUN (IR_EXTRA | IR_RX_DESC_0 | IR_TX_FREE_0)
4898c2ecf20Sopenharmony_ci#define  IR_ALL 0xfdfffff7
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci#define  IR_LNKCHG0_ofst        27
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_OSEN  0x1000	/* shared OS enable */
4948c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_TXFC  0x0400	/* Tx flow control */
4958c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_RSV0  0x0200	/* reserved */
4968c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_FDA   0x0100	/* filter out direct address */
4978c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_AOF   0x0080	/* accept over run */
4988c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_ACF   0x0040	/* accept control frames */
4998c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_ARUNT 0x0020	/* accept under run */
5008c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_ACRC  0x0010	/* accept crc error */
5018c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_AM    0x0008	/* accept multicast */
5028c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_AB    0x0004	/* accept broadcast */
5038c2ecf20Sopenharmony_ci#define  GMAC_RX_FILTER_PRM   0x0001	/* [0:1] promiscuous mode */
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci#define  MAX_FRAME_AB_VAL       0x3fff	/* 13:0 */
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci#define  CLKPLL_PLLLKD          0x0200	/*9 */
5088c2ecf20Sopenharmony_ci#define  CLKPLL_RSTEND          0x0100	/*8 */
5098c2ecf20Sopenharmony_ci#define  CLKPLL_SFTRST          0x0001	/*0 */
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci#define  CLKPLL_LKD             (CLKPLL_PLLLKD|CLKPLL_RSTEND)
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci/*
5148c2ecf20Sopenharmony_ci * PCI-E Device Control Register (Offset 0x88)
5158c2ecf20Sopenharmony_ci * Source: Luxor Data Sheet, 7.1.3.3.3
5168c2ecf20Sopenharmony_ci */
5178c2ecf20Sopenharmony_ci#define PCI_DEV_CTRL_REG 0x88
5188c2ecf20Sopenharmony_ci#define GET_DEV_CTRL_MAXPL(x)           GET_BITS_SHIFT(x, 3, 5)
5198c2ecf20Sopenharmony_ci#define GET_DEV_CTRL_MRRS(x)            GET_BITS_SHIFT(x, 3, 12)
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/*
5228c2ecf20Sopenharmony_ci * PCI-E Link Status Register (Offset 0x92)
5238c2ecf20Sopenharmony_ci * Source: Luxor Data Sheet, 7.1.3.3.7
5248c2ecf20Sopenharmony_ci */
5258c2ecf20Sopenharmony_ci#define PCI_LINK_STATUS_REG 0x92
5268c2ecf20Sopenharmony_ci#define GET_LINK_STATUS_LANES(x)		GET_BITS_SHIFT(x, 6, 4)
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci/* Debugging Macros */
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci#define DBG2(fmt, args...)					\
5318c2ecf20Sopenharmony_ci	pr_err("%s:%-5d: " fmt, __func__, __LINE__, ## args)
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci#define BDX_ASSERT(x) BUG_ON(x)
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci#ifdef DEBUG
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci#define ENTER						\
5388c2ecf20Sopenharmony_cido {							\
5398c2ecf20Sopenharmony_ci	pr_err("%s:%-5d: ENTER\n", __func__, __LINE__); \
5408c2ecf20Sopenharmony_ci} while (0)
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci#define RET(args...)					 \
5438c2ecf20Sopenharmony_cido {							 \
5448c2ecf20Sopenharmony_ci	pr_err("%s:%-5d: RETURN\n", __func__, __LINE__); \
5458c2ecf20Sopenharmony_ci	return args;					 \
5468c2ecf20Sopenharmony_ci} while (0)
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci#define DBG(fmt, args...)					\
5498c2ecf20Sopenharmony_ci	pr_err("%s:%-5d: " fmt, __func__, __LINE__, ## args)
5508c2ecf20Sopenharmony_ci#else
5518c2ecf20Sopenharmony_ci#define ENTER do {  } while (0)
5528c2ecf20Sopenharmony_ci#define RET(args...)   return args
5538c2ecf20Sopenharmony_ci#define DBG(fmt, args...)			\
5548c2ecf20Sopenharmony_cido {						\
5558c2ecf20Sopenharmony_ci	if (0)					\
5568c2ecf20Sopenharmony_ci		pr_err(fmt, ##args);		\
5578c2ecf20Sopenharmony_ci} while (0)
5588c2ecf20Sopenharmony_ci#endif
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci#endif /* _BDX__H */
561