18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Applied Micro X-Gene SoC Ethernet v2 Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2017, Applied Micro Circuits Corporation 68c2ecf20Sopenharmony_ci * Author(s): Iyappan Subramanian <isubramanian@apm.com> 78c2ecf20Sopenharmony_ci * Keyur Chudgar <kchudgar@apm.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef __XGENE_ENET_V2_RING_H__ 118c2ecf20Sopenharmony_ci#define __XGENE_ENET_V2_RING_H__ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define XGENE_ENET_DESC_SIZE 64 148c2ecf20Sopenharmony_ci#define XGENE_ENET_NUM_DESC 256 158c2ecf20Sopenharmony_ci#define NUM_BUFS 8 168c2ecf20Sopenharmony_ci#define SLOT_EMPTY 0xfff 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define DMATXCTRL 0xa180 198c2ecf20Sopenharmony_ci#define DMATXDESCL 0xa184 208c2ecf20Sopenharmony_ci#define DMATXDESCH 0xa1a0 218c2ecf20Sopenharmony_ci#define DMATXSTATUS 0xa188 228c2ecf20Sopenharmony_ci#define DMARXCTRL 0xa18c 238c2ecf20Sopenharmony_ci#define DMARXDESCL 0xa190 248c2ecf20Sopenharmony_ci#define DMARXDESCH 0xa1a4 258c2ecf20Sopenharmony_ci#define DMARXSTATUS 0xa194 268c2ecf20Sopenharmony_ci#define DMAINTRMASK 0xa198 278c2ecf20Sopenharmony_ci#define DMAINTERRUPT 0xa19c 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define D_POS 62 308c2ecf20Sopenharmony_ci#define D_LEN 2 318c2ecf20Sopenharmony_ci#define E_POS 63 328c2ecf20Sopenharmony_ci#define E_LEN 1 338c2ecf20Sopenharmony_ci#define PKT_ADDRL_POS 0 348c2ecf20Sopenharmony_ci#define PKT_ADDRL_LEN 32 358c2ecf20Sopenharmony_ci#define PKT_ADDRH_POS 32 368c2ecf20Sopenharmony_ci#define PKT_ADDRH_LEN 10 378c2ecf20Sopenharmony_ci#define PKT_SIZE_POS 32 388c2ecf20Sopenharmony_ci#define PKT_SIZE_LEN 12 398c2ecf20Sopenharmony_ci#define NEXT_DESC_ADDRL_POS 0 408c2ecf20Sopenharmony_ci#define NEXT_DESC_ADDRL_LEN 32 418c2ecf20Sopenharmony_ci#define NEXT_DESC_ADDRH_POS 48 428c2ecf20Sopenharmony_ci#define NEXT_DESC_ADDRH_LEN 10 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define TXPKTCOUNT_POS 16 458c2ecf20Sopenharmony_ci#define TXPKTCOUNT_LEN 8 468c2ecf20Sopenharmony_ci#define RXPKTCOUNT_POS 16 478c2ecf20Sopenharmony_ci#define RXPKTCOUNT_LEN 8 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define TX_PKT_SENT BIT(0) 508c2ecf20Sopenharmony_ci#define TX_BUS_ERROR BIT(3) 518c2ecf20Sopenharmony_ci#define RX_PKT_RCVD BIT(4) 528c2ecf20Sopenharmony_ci#define RX_BUS_ERROR BIT(7) 538c2ecf20Sopenharmony_ci#define RXSTATUS_RXPKTRCVD BIT(0) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistruct xge_raw_desc { 568c2ecf20Sopenharmony_ci __le64 m0; 578c2ecf20Sopenharmony_ci __le64 m1; 588c2ecf20Sopenharmony_ci __le64 m2; 598c2ecf20Sopenharmony_ci __le64 m3; 608c2ecf20Sopenharmony_ci __le64 m4; 618c2ecf20Sopenharmony_ci __le64 m5; 628c2ecf20Sopenharmony_ci __le64 m6; 638c2ecf20Sopenharmony_ci __le64 m7; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistruct pkt_info { 678c2ecf20Sopenharmony_ci struct sk_buff *skb; 688c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 698c2ecf20Sopenharmony_ci void *pkt_buf; 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* software context of a descriptor ring */ 738c2ecf20Sopenharmony_cistruct xge_desc_ring { 748c2ecf20Sopenharmony_ci struct net_device *ndev; 758c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 768c2ecf20Sopenharmony_ci u8 head; 778c2ecf20Sopenharmony_ci u8 tail; 788c2ecf20Sopenharmony_ci union { 798c2ecf20Sopenharmony_ci void *desc_addr; 808c2ecf20Sopenharmony_ci struct xge_raw_desc *raw_desc; 818c2ecf20Sopenharmony_ci }; 828c2ecf20Sopenharmony_ci struct pkt_info (*pkt_info); 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic inline u64 xge_set_desc_bits(int pos, int len, u64 val) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci return (val & ((1ULL << len) - 1)) << pos; 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic inline u64 xge_get_desc_bits(int pos, int len, u64 src) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci return (src >> pos) & ((1ULL << len) - 1); 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define SET_BITS(field, val) \ 968c2ecf20Sopenharmony_ci xge_set_desc_bits(field ## _POS, field ## _LEN, val) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define GET_BITS(field, src) \ 998c2ecf20Sopenharmony_ci xge_get_desc_bits(field ## _POS, field ## _LEN, src) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_civoid xge_setup_desc(struct xge_desc_ring *ring); 1028c2ecf20Sopenharmony_civoid xge_update_tx_desc_addr(struct xge_pdata *pdata); 1038c2ecf20Sopenharmony_civoid xge_update_rx_desc_addr(struct xge_pdata *pdata); 1048c2ecf20Sopenharmony_civoid xge_intr_enable(struct xge_pdata *pdata); 1058c2ecf20Sopenharmony_civoid xge_intr_disable(struct xge_pdata *pdata); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#endif /* __XGENE_ENET_V2_RING_H__ */ 108