1696fa399SGagandeep Singh /* SPDX-License-Identifier: BSD-3-Clause 27de1c06aSGagandeep Singh * Copyright 2018-2019 NXP 3696fa399SGagandeep Singh */ 4696fa399SGagandeep Singh 5696fa399SGagandeep Singh #ifndef _ENETC_H_ 6696fa399SGagandeep Singh #define _ENETC_H_ 7696fa399SGagandeep Singh 8696fa399SGagandeep Singh #include <rte_time.h> 9696fa399SGagandeep Singh 10696fa399SGagandeep Singh #include "base/enetc_hw.h" 11696fa399SGagandeep Singh 12696fa399SGagandeep Singh #define PCI_VENDOR_ID_FREESCALE 0x1957 13696fa399SGagandeep Singh 14696fa399SGagandeep Singh /* Max TX rings per ENETC. */ 15696fa399SGagandeep Singh #define MAX_TX_RINGS 2 16696fa399SGagandeep Singh 17696fa399SGagandeep Singh /* Max RX rings per ENTEC. */ 18696fa399SGagandeep Singh #define MAX_RX_RINGS 1 19696fa399SGagandeep Singh 20469c6111SGagandeep Singh /* Max BD counts per Ring. */ 21469c6111SGagandeep Singh #define MAX_BD_COUNT 64000 22469c6111SGagandeep Singh /* Min BD counts per Ring. */ 23469c6111SGagandeep Singh #define MIN_BD_COUNT 32 24469c6111SGagandeep Singh /* BD ALIGN */ 25469c6111SGagandeep Singh #define BD_ALIGN 8 26469c6111SGagandeep Singh 275d5589b0SGagandeep Singh /* minimum frame size supported */ 285d5589b0SGagandeep Singh #define ENETC_MAC_MINFRM_SIZE 68 295d5589b0SGagandeep Singh /* maximum frame size supported */ 305d5589b0SGagandeep Singh #define ENETC_MAC_MAXFRM_SIZE 9600 315d5589b0SGagandeep Singh 32*4d44217bSSteve Yang /* The max frame size with default MTU */ 33*4d44217bSSteve Yang #define ENETC_ETH_MAX_LEN (RTE_ETHER_MTU + \ 34*4d44217bSSteve Yang RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN) 35*4d44217bSSteve Yang 36696fa399SGagandeep Singh /* 37696fa399SGagandeep Singh * upper_32_bits - return bits 32-63 of a number 38696fa399SGagandeep Singh * @n: the number we're accessing 39696fa399SGagandeep Singh * 40696fa399SGagandeep Singh * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress 41696fa399SGagandeep Singh * the "right shift count >= width of type" warning when that quantity is 42696fa399SGagandeep Singh * 32-bits. 43696fa399SGagandeep Singh */ 44696fa399SGagandeep Singh #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16)) 45696fa399SGagandeep Singh 46696fa399SGagandeep Singh /* 47696fa399SGagandeep Singh * lower_32_bits - return bits 0-31 of a number 48696fa399SGagandeep Singh * @n: the number we're accessing 49696fa399SGagandeep Singh */ 50696fa399SGagandeep Singh #define lower_32_bits(n) ((uint32_t)(n)) 51696fa399SGagandeep Singh 52696fa399SGagandeep Singh #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i])) 53696fa399SGagandeep Singh #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i])) 54696fa399SGagandeep Singh 55696fa399SGagandeep Singh struct enetc_swbd { 56696fa399SGagandeep Singh struct rte_mbuf *buffer_addr; 57696fa399SGagandeep Singh }; 58696fa399SGagandeep Singh 59696fa399SGagandeep Singh struct enetc_bdr { 60696fa399SGagandeep Singh void *bd_base; /* points to Rx or Tx BD ring */ 6166894d98SAlex Marginean struct enetc_swbd *q_swbd; 62696fa399SGagandeep Singh union { 63696fa399SGagandeep Singh void *tcir; 64696fa399SGagandeep Singh void *rcir; 65696fa399SGagandeep Singh }; 66696fa399SGagandeep Singh int bd_count; /* # of BDs */ 67696fa399SGagandeep Singh int next_to_use; 68696fa399SGagandeep Singh int next_to_clean; 6966894d98SAlex Marginean uint16_t index; 7066894d98SAlex Marginean uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */ 71696fa399SGagandeep Singh union { 72696fa399SGagandeep Singh void *tcisr; /* Tx */ 73696fa399SGagandeep Singh int next_to_alloc; /* Rx */ 74696fa399SGagandeep Singh }; 7566894d98SAlex Marginean struct rte_mempool *mb_pool; /* mbuf pool to populate RX ring. */ 7666894d98SAlex Marginean struct rte_eth_dev *ndev; 77696fa399SGagandeep Singh }; 78696fa399SGagandeep Singh 79696fa399SGagandeep Singh /* 80696fa399SGagandeep Singh * Structure to store private data for each driver instance (for each port). 81696fa399SGagandeep Singh */ 82696fa399SGagandeep Singh struct enetc_eth_adapter { 83696fa399SGagandeep Singh struct rte_eth_dev *ndev; 84696fa399SGagandeep Singh struct enetc_eth_hw hw; 85696fa399SGagandeep Singh }; 86696fa399SGagandeep Singh 87696fa399SGagandeep Singh #define ENETC_DEV_PRIVATE(adapter) \ 88696fa399SGagandeep Singh ((struct enetc_eth_adapter *)adapter) 89696fa399SGagandeep Singh 90696fa399SGagandeep Singh #define ENETC_DEV_PRIVATE_TO_HW(adapter) \ 91696fa399SGagandeep Singh (&((struct enetc_eth_adapter *)adapter)->hw) 92696fa399SGagandeep Singh 93696fa399SGagandeep Singh #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \ 94696fa399SGagandeep Singh (&((struct enetc_eth_adapter *)adapter)->stats) 95696fa399SGagandeep Singh 96696fa399SGagandeep Singh #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \ 97696fa399SGagandeep Singh (&((struct enetc_eth_adapter *)adapter)->intr) 98696fa399SGagandeep Singh 99469c6111SGagandeep Singh /* 100469c6111SGagandeep Singh * RX/TX ENETC function prototypes 101469c6111SGagandeep Singh */ 102469c6111SGagandeep Singh uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts, 103469c6111SGagandeep Singh uint16_t nb_pkts); 104469c6111SGagandeep Singh uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, 105469c6111SGagandeep Singh uint16_t nb_pkts); 106469c6111SGagandeep Singh 107469c6111SGagandeep Singh 108469c6111SGagandeep Singh int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt); 109469c6111SGagandeep Singh 110469c6111SGagandeep Singh static inline int enetc_bd_unused(struct enetc_bdr * bdr)111469c6111SGagandeep Singhenetc_bd_unused(struct enetc_bdr *bdr) 112469c6111SGagandeep Singh { 113469c6111SGagandeep Singh if (bdr->next_to_clean > bdr->next_to_use) 114469c6111SGagandeep Singh return bdr->next_to_clean - bdr->next_to_use - 1; 115469c6111SGagandeep Singh 116469c6111SGagandeep Singh return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1; 117469c6111SGagandeep Singh } 118696fa399SGagandeep Singh #endif /* _ENETC_H_ */ 119