18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2006 PA Semi, Inc 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Driver for the PA6T-1682M onchip 1G/10G Ethernet MACs, soft state and 68c2ecf20Sopenharmony_ci * hardware register layouts. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef PASEMI_MAC_H 108c2ecf20Sopenharmony_ci#define PASEMI_MAC_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 138c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 148c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 158c2ecf20Sopenharmony_ci#include <linux/phy.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Must be a power of two */ 188c2ecf20Sopenharmony_ci#define RX_RING_SIZE 2048 198c2ecf20Sopenharmony_ci#define TX_RING_SIZE 4096 208c2ecf20Sopenharmony_ci#define CS_RING_SIZE (TX_RING_SIZE*2) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define MAX_CS 2 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct pasemi_mac_txring { 268c2ecf20Sopenharmony_ci struct pasemi_dmachan chan; /* Must be first */ 278c2ecf20Sopenharmony_ci spinlock_t lock; 288c2ecf20Sopenharmony_ci unsigned int size; 298c2ecf20Sopenharmony_ci unsigned int next_to_fill; 308c2ecf20Sopenharmony_ci unsigned int next_to_clean; 318c2ecf20Sopenharmony_ci struct pasemi_mac_buffer *ring_info; 328c2ecf20Sopenharmony_ci struct pasemi_mac *mac; /* Needed in intr handler */ 338c2ecf20Sopenharmony_ci struct timer_list clean_timer; 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct pasemi_mac_rxring { 378c2ecf20Sopenharmony_ci struct pasemi_dmachan chan; /* Must be first */ 388c2ecf20Sopenharmony_ci spinlock_t lock; 398c2ecf20Sopenharmony_ci u64 *buffers; /* RX interface buffer ring */ 408c2ecf20Sopenharmony_ci dma_addr_t buf_dma; 418c2ecf20Sopenharmony_ci unsigned int size; 428c2ecf20Sopenharmony_ci unsigned int next_to_fill; 438c2ecf20Sopenharmony_ci unsigned int next_to_clean; 448c2ecf20Sopenharmony_ci struct pasemi_mac_buffer *ring_info; 458c2ecf20Sopenharmony_ci struct pasemi_mac *mac; /* Needed in intr handler */ 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistruct pasemi_mac_csring { 498c2ecf20Sopenharmony_ci struct pasemi_dmachan chan; 508c2ecf20Sopenharmony_ci unsigned int size; 518c2ecf20Sopenharmony_ci unsigned int next_to_fill; 528c2ecf20Sopenharmony_ci int events[2]; 538c2ecf20Sopenharmony_ci int last_event; 548c2ecf20Sopenharmony_ci int fun; 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistruct pasemi_mac { 588c2ecf20Sopenharmony_ci struct net_device *netdev; 598c2ecf20Sopenharmony_ci struct pci_dev *pdev; 608c2ecf20Sopenharmony_ci struct pci_dev *dma_pdev; 618c2ecf20Sopenharmony_ci struct pci_dev *iob_pdev; 628c2ecf20Sopenharmony_ci struct napi_struct napi; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci int bufsz; /* RX ring buffer size */ 658c2ecf20Sopenharmony_ci int last_cs; 668c2ecf20Sopenharmony_ci int num_cs; 678c2ecf20Sopenharmony_ci u32 dma_if; 688c2ecf20Sopenharmony_ci u8 type; 698c2ecf20Sopenharmony_ci#define MAC_TYPE_GMAC 1 708c2ecf20Sopenharmony_ci#define MAC_TYPE_XAUI 2 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci struct timer_list rxtimer; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci struct pasemi_mac_txring *tx; 778c2ecf20Sopenharmony_ci struct pasemi_mac_rxring *rx; 788c2ecf20Sopenharmony_ci struct pasemi_mac_csring *cs[MAX_CS]; 798c2ecf20Sopenharmony_ci char tx_irq_name[10]; /* "eth%d tx" */ 808c2ecf20Sopenharmony_ci char rx_irq_name[10]; /* "eth%d rx" */ 818c2ecf20Sopenharmony_ci int link; 828c2ecf20Sopenharmony_ci int speed; 838c2ecf20Sopenharmony_ci int duplex; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci unsigned int msg_enable; 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Software status descriptor (ring_info) */ 898c2ecf20Sopenharmony_cistruct pasemi_mac_buffer { 908c2ecf20Sopenharmony_ci struct sk_buff *skb; 918c2ecf20Sopenharmony_ci dma_addr_t dma; 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define TX_DESC(tx, num) ((tx)->chan.ring_virt[(num) & (TX_RING_SIZE-1)]) 958c2ecf20Sopenharmony_ci#define TX_DESC_INFO(tx, num) ((tx)->ring_info[(num) & (TX_RING_SIZE-1)]) 968c2ecf20Sopenharmony_ci#define RX_DESC(rx, num) ((rx)->chan.ring_virt[(num) & (RX_RING_SIZE-1)]) 978c2ecf20Sopenharmony_ci#define RX_DESC_INFO(rx, num) ((rx)->ring_info[(num) & (RX_RING_SIZE-1)]) 988c2ecf20Sopenharmony_ci#define RX_BUFF(rx, num) ((rx)->buffers[(num) & (RX_RING_SIZE-1)]) 998c2ecf20Sopenharmony_ci#define CS_DESC(cs, num) ((cs)->chan.ring_virt[(num) & (CS_RING_SIZE-1)]) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define RING_USED(ring) (((ring)->next_to_fill - (ring)->next_to_clean) \ 1028c2ecf20Sopenharmony_ci & ((ring)->size - 1)) 1038c2ecf20Sopenharmony_ci#define RING_AVAIL(ring) ((ring->size) - RING_USED(ring)) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* PCI register offsets and formats */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* MAC CFG register offsets */ 1098c2ecf20Sopenharmony_cienum { 1108c2ecf20Sopenharmony_ci PAS_MAC_CFG_PCFG = 0x80, 1118c2ecf20Sopenharmony_ci PAS_MAC_CFG_MACCFG = 0x84, 1128c2ecf20Sopenharmony_ci PAS_MAC_CFG_ADR0 = 0x8c, 1138c2ecf20Sopenharmony_ci PAS_MAC_CFG_ADR1 = 0x90, 1148c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP = 0x98, 1158c2ecf20Sopenharmony_ci PAS_MAC_CFG_RMON = 0x100, 1168c2ecf20Sopenharmony_ci PAS_MAC_IPC_CHNL = 0x208, 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* MAC CFG register fields */ 1208c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_PE 0x80000000 1218c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CE 0x40000000 1228c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_BU 0x20000000 1238c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TT 0x10000000 1248c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_M 0x0c000000 1258c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_10M 0x00000000 1268c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_100M 0x04000000 1278c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_1G 0x08000000 1288c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TSR_10G 0x0c000000 1298c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_T24 0x02000000 1308c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_PR 0x01000000 1318c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CRO_M 0x00ff0000 1328c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_CRO_S 16 1338c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IPO_M 0x0000ff00 1348c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IPO_S 8 1358c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_S1 0x00000080 1368c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_M 0x00000060 1378c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_MAC 0x00000000 1388c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_OFF 0x00000020 1398c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_IND_ETH 0x00000040 1408c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_IO_IND_IP 0x00000060 1418c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_LP 0x00000010 1428c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_TS 0x00000008 1438c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_HD 0x00000004 1448c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_M 0x00000003 1458c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_10M 0x00000000 1468c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_100M 0x00000001 1478c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_1G 0x00000002 1488c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_PCFG_SPD_10G 0x00000003 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_TXT_M 0x70000000 1518c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_TXT_S 28 1528c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_PRES_M 0x0f000000 1538c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_PRES_S 24 1548c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF_M 0x00ffff00 1558c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF_S 8 1568c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MAXF(x) (((x) << PAS_MAC_CFG_MACCFG_MAXF_S) & \ 1578c2ecf20Sopenharmony_ci PAS_MAC_CFG_MACCFG_MAXF_M) 1588c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MINF_M 0x000000ff 1598c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_MACCFG_MINF_S 0 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FCF 0x01000000 1628c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FCE 0x00800000 1638c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FC 0x00400000 1648c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC_M 0x00300000 1658c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC_S 20 1668c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_FPC(x) (((x) << PAS_MAC_CFG_TXP_FPC_S) & \ 1678c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP_FPC_M) 1688c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_RT 0x00080000 1698c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_BL 0x00040000 1708c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL_M 0x00030000 1718c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL_S 16 1728c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_SL(x) (((x) << PAS_MAC_CFG_TXP_SL_S) & \ 1738c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP_SL_M) 1748c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB_M 0x0000f000 1758c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB_S 12 1768c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_COB(x) (((x) << PAS_MAC_CFG_TXP_COB_S) & \ 1778c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP_COB_M) 1788c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT_M 0x00000f00 1798c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT_S 8 1808c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFT(x) (((x) << PAS_MAC_CFG_TXP_TIFT_S) & \ 1818c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP_TIFT_M) 1828c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG_M 0x000000ff 1838c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG_S 0 1848c2ecf20Sopenharmony_ci#define PAS_MAC_CFG_TXP_TIFG(x) (((x) << PAS_MAC_CFG_TXP_TIFG_S) & \ 1858c2ecf20Sopenharmony_ci PAS_MAC_CFG_TXP_TIFG_M) 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define PAS_MAC_RMON(r) (0x100+(r)*4) 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO_M 0x003f0000 1908c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO_S 16 1918c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_DCHNO(x) (((x) << PAS_MAC_IPC_CHNL_DCHNO_S) & \ 1928c2ecf20Sopenharmony_ci PAS_MAC_IPC_CHNL_DCHNO_M) 1938c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH_M 0x0000003f 1948c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH_S 0 1958c2ecf20Sopenharmony_ci#define PAS_MAC_IPC_CHNL_BCH(x) (((x) << PAS_MAC_IPC_CHNL_BCH_S) & \ 1968c2ecf20Sopenharmony_ci PAS_MAC_IPC_CHNL_BCH_M) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci#endif /* PASEMI_MAC_H */ 200