162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2006 PA Semi, Inc 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Driver for the PA6T-1682M onchip 1G/10G Ethernet MACs, soft state and 662306a36Sopenharmony_ci * hardware register layouts. 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef PASEMI_MAC_H 1062306a36Sopenharmony_ci#define PASEMI_MAC_H 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/ethtool.h> 1362306a36Sopenharmony_ci#include <linux/netdevice.h> 1462306a36Sopenharmony_ci#include <linux/spinlock.h> 1562306a36Sopenharmony_ci#include <linux/phy.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* Must be a power of two */ 1862306a36Sopenharmony_ci#define RX_RING_SIZE 2048 1962306a36Sopenharmony_ci#define TX_RING_SIZE 4096 2062306a36Sopenharmony_ci#define CS_RING_SIZE (TX_RING_SIZE*2) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define MAX_CS 2 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistruct pasemi_mac_txring { 2662306a36Sopenharmony_ci struct pasemi_dmachan chan; /* Must be first */ 2762306a36Sopenharmony_ci spinlock_t lock; 2862306a36Sopenharmony_ci unsigned int size; 2962306a36Sopenharmony_ci unsigned int next_to_fill; 3062306a36Sopenharmony_ci unsigned int next_to_clean; 3162306a36Sopenharmony_ci struct pasemi_mac_buffer *ring_info; 3262306a36Sopenharmony_ci struct pasemi_mac *mac; /* Needed in intr handler */ 3362306a36Sopenharmony_ci struct timer_list clean_timer; 3462306a36Sopenharmony_ci}; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistruct pasemi_mac_rxring { 3762306a36Sopenharmony_ci struct pasemi_dmachan chan; /* Must be first */ 3862306a36Sopenharmony_ci spinlock_t lock; 3962306a36Sopenharmony_ci u64 *buffers; /* RX interface buffer ring */ 4062306a36Sopenharmony_ci dma_addr_t buf_dma; 4162306a36Sopenharmony_ci unsigned int size; 4262306a36Sopenharmony_ci unsigned int next_to_fill; 4362306a36Sopenharmony_ci unsigned int next_to_clean; 4462306a36Sopenharmony_ci struct pasemi_mac_buffer *ring_info; 4562306a36Sopenharmony_ci struct pasemi_mac *mac; /* Needed in intr handler */ 4662306a36Sopenharmony_ci}; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cistruct pasemi_mac_csring { 4962306a36Sopenharmony_ci struct pasemi_dmachan chan; 5062306a36Sopenharmony_ci unsigned int size; 5162306a36Sopenharmony_ci unsigned int next_to_fill; 5262306a36Sopenharmony_ci int events[2]; 5362306a36Sopenharmony_ci int last_event; 5462306a36Sopenharmony_ci int fun; 5562306a36Sopenharmony_ci}; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_cistruct pasemi_mac { 5862306a36Sopenharmony_ci struct net_device *netdev; 5962306a36Sopenharmony_ci struct pci_dev *pdev; 6062306a36Sopenharmony_ci struct pci_dev *dma_pdev; 6162306a36Sopenharmony_ci struct pci_dev *iob_pdev; 6262306a36Sopenharmony_ci struct napi_struct napi; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci int bufsz; /* RX ring buffer size */ 6562306a36Sopenharmony_ci int last_cs; 6662306a36Sopenharmony_ci int num_cs; 6762306a36Sopenharmony_ci u32 dma_if; 6862306a36Sopenharmony_ci u8 type; 6962306a36Sopenharmony_ci#define MAC_TYPE_GMAC 1 7062306a36Sopenharmony_ci#define MAC_TYPE_XAUI 2 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci struct timer_list rxtimer; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci struct pasemi_mac_txring *tx; 7762306a36Sopenharmony_ci struct pasemi_mac_rxring *rx; 7862306a36Sopenharmony_ci struct pasemi_mac_csring *cs[MAX_CS]; 7962306a36Sopenharmony_ci char tx_irq_name[10]; /* "eth%d tx" */ 8062306a36Sopenharmony_ci char rx_irq_name[10]; /* "eth%d rx" */ 8162306a36Sopenharmony_ci int link; 8262306a36Sopenharmony_ci int speed; 8362306a36Sopenharmony_ci int duplex; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci unsigned int msg_enable; 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* Software status descriptor (ring_info) */ 8962306a36Sopenharmony_cistruct pasemi_mac_buffer { 9062306a36Sopenharmony_ci struct sk_buff *skb; 9162306a36Sopenharmony_ci dma_addr_t dma; 9262306a36Sopenharmony_ci}; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci#define TX_DESC(tx, num) ((tx)->chan.ring_virt[(num) & (TX_RING_SIZE-1)]) 9562306a36Sopenharmony_ci#define TX_DESC_INFO(tx, num) ((tx)->ring_info[(num) & (TX_RING_SIZE-1)]) 9662306a36Sopenharmony_ci#define RX_DESC(rx, num) ((rx)->chan.ring_virt[(num) & (RX_RING_SIZE-1)]) 9762306a36Sopenharmony_ci#define RX_DESC_INFO(rx, num) ((rx)->ring_info[(num) & (RX_RING_SIZE-1)]) 9862306a36Sopenharmony_ci#define RX_BUFF(rx, num) ((rx)->buffers[(num) & (RX_RING_SIZE-1)]) 9962306a36Sopenharmony_ci#define CS_DESC(cs, num) ((cs)->chan.ring_virt[(num) & (CS_RING_SIZE-1)]) 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define RING_USED(ring) (((ring)->next_to_fill - (ring)->next_to_clean) \ 10262306a36Sopenharmony_ci & ((ring)->size - 1)) 10362306a36Sopenharmony_ci#define RING_AVAIL(ring) ((ring->size) - RING_USED(ring)) 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* PCI register offsets and formats */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci/* MAC CFG register offsets */ 10962306a36Sopenharmony_cienum { 11062306a36Sopenharmony_ci PAS_MAC_CFG_PCFG = 0x80, 11162306a36Sopenharmony_ci PAS_MAC_CFG_MACCFG = 0x84, 11262306a36Sopenharmony_ci PAS_MAC_CFG_ADR0 = 0x8c, 11362306a36Sopenharmony_ci PAS_MAC_CFG_ADR1 = 0x90, 11462306a36Sopenharmony_ci PAS_MAC_CFG_TXP = 0x98, 11562306a36Sopenharmony_ci PAS_MAC_CFG_RMON = 0x100, 11662306a36Sopenharmony_ci PAS_MAC_IPC_CHNL = 0x208, 11762306a36Sopenharmony_ci}; 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* MAC CFG register fields */ 12062306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_PE 0x80000000 12162306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CE 0x40000000 12262306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_BU 0x20000000 12362306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TT 0x10000000 12462306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_M 0x0c000000 12562306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_10M 0x00000000 12662306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_100M 0x04000000 12762306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_1G 0x08000000 12862306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_10G 0x0c000000 12962306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_T24 0x02000000 13062306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_PR 0x01000000 13162306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CRO_M 0x00ff0000 13262306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CRO_S 16 13362306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IPO_M 0x0000ff00 13462306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IPO_S 8 13562306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_S1 0x00000080 13662306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_M 0x00000060 13762306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_MAC 0x00000000 13862306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_OFF 0x00000020 13962306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_IND_ETH 0x00000040 14062306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_IND_IP 0x00000060 14162306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_LP 0x00000010 14262306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TS 0x00000008 14362306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_HD 0x00000004 14462306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_M 0x00000003 14562306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_10M 0x00000000 14662306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_100M 0x00000001 14762306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_1G 0x00000002 14862306a36Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_10G 0x00000003 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_TXT_M 0x70000000 15162306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_TXT_S 28 15262306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_PRES_M 0x0f000000 15362306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_PRES_S 24 15462306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF_M 0x00ffff00 15562306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF_S 8 15662306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF(x) (((x) << PAS_MAC_CFG_MACCFG_MAXF_S) & \ 15762306a36Sopenharmony_ci PAS_MAC_CFG_MACCFG_MAXF_M) 15862306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MINF_M 0x000000ff 15962306a36Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MINF_S 0 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FCF 0x01000000 16262306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FCE 0x00800000 16362306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FC 0x00400000 16462306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC_M 0x00300000 16562306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC_S 20 16662306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC(x) (((x) << PAS_MAC_CFG_TXP_FPC_S) & \ 16762306a36Sopenharmony_ci PAS_MAC_CFG_TXP_FPC_M) 16862306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_RT 0x00080000 16962306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_BL 0x00040000 17062306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL_M 0x00030000 17162306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL_S 16 17262306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL(x) (((x) << PAS_MAC_CFG_TXP_SL_S) & \ 17362306a36Sopenharmony_ci PAS_MAC_CFG_TXP_SL_M) 17462306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB_M 0x0000f000 17562306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB_S 12 17662306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB(x) (((x) << PAS_MAC_CFG_TXP_COB_S) & \ 17762306a36Sopenharmony_ci PAS_MAC_CFG_TXP_COB_M) 17862306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT_M 0x00000f00 17962306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT_S 8 18062306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT(x) (((x) << PAS_MAC_CFG_TXP_TIFT_S) & \ 18162306a36Sopenharmony_ci PAS_MAC_CFG_TXP_TIFT_M) 18262306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG_M 0x000000ff 18362306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG_S 0 18462306a36Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG(x) (((x) << PAS_MAC_CFG_TXP_TIFG_S) & \ 18562306a36Sopenharmony_ci PAS_MAC_CFG_TXP_TIFG_M) 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#define PAS_MAC_RMON(r) (0x100+(r)*4) 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO_M 0x003f0000 19062306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO_S 16 19162306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO(x) (((x) << PAS_MAC_IPC_CHNL_DCHNO_S) & \ 19262306a36Sopenharmony_ci PAS_MAC_IPC_CHNL_DCHNO_M) 19362306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH_M 0x0000003f 19462306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH_S 0 19562306a36Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH(x) (((x) << PAS_MAC_IPC_CHNL_BCH_S) & \ 19662306a36Sopenharmony_ci PAS_MAC_IPC_CHNL_BCH_M) 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#endif /* PASEMI_MAC_H */ 200