New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / enetc / enetc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 NXP
3  */
4
5 #ifndef _ENETC_H_
6 #define _ENETC_H_
7
8 #include <rte_time.h>
9
10 #include "base/enetc_hw.h"
11
12 #define PCI_VENDOR_ID_FREESCALE 0x1957
13
14 /* Max TX rings per ENETC. */
15 #define MAX_TX_RINGS    2
16
17 /* Max RX rings per ENTEC. */
18 #define MAX_RX_RINGS    1
19
20 /* Max BD counts per Ring. */
21 #define MAX_BD_COUNT   64000
22 /* Min BD counts per Ring. */
23 #define MIN_BD_COUNT   32
24 /* BD ALIGN */
25 #define BD_ALIGN       8
26
27 /*
28  * upper_32_bits - return bits 32-63 of a number
29  * @n: the number we're accessing
30  *
31  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
32  * the "right shift count >= width of type" warning when that quantity is
33  * 32-bits.
34  */
35 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
36
37 /*
38  * lower_32_bits - return bits 0-31 of a number
39  * @n: the number we're accessing
40  */
41 #define lower_32_bits(n) ((uint32_t)(n))
42
43 #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i]))
44 #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
45
46 struct enetc_swbd {
47         struct rte_mbuf *buffer_addr;
48 };
49
50 struct enetc_bdr {
51         struct rte_eth_dev *ndev;
52         struct rte_mempool *mb_pool;   /* mbuf pool to populate RX ring. */
53         void *bd_base;                  /* points to Rx or Tx BD ring */
54         union {
55                 void *tcir;
56                 void *rcir;
57         };
58         uint16_t index;
59         int bd_count; /* # of BDs */
60         int next_to_use;
61         int next_to_clean;
62         struct enetc_swbd *q_swbd;
63         union {
64                 void *tcisr; /* Tx */
65                 int next_to_alloc; /* Rx */
66         };
67 };
68
69 /*
70  * Structure to store private data for each driver instance (for each port).
71  */
72 struct enetc_eth_adapter {
73         struct rte_eth_dev *ndev;
74         struct enetc_eth_hw hw;
75 };
76
77 #define ENETC_DEV_PRIVATE(adapter) \
78         ((struct enetc_eth_adapter *)adapter)
79
80 #define ENETC_DEV_PRIVATE_TO_HW(adapter) \
81         (&((struct enetc_eth_adapter *)adapter)->hw)
82
83 #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \
84         (&((struct enetc_eth_adapter *)adapter)->stats)
85
86 #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \
87         (&((struct enetc_eth_adapter *)adapter)->intr)
88
89 #define ENETC_GET_HW_ADDR(reg, addr) ((void *)(((size_t)reg) + (addr)))
90 #define ENETC_REG_READ(addr) (*(uint32_t *)addr)
91 #define ENETC_REG_WRITE(addr, val) (*(uint32_t *)addr = val)
92 #define ENETC_REG_WRITE_RELAXED(addr, val) (*(uint32_t *)addr = val)
93
94 /*
95  * RX/TX ENETC function prototypes
96  */
97 uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts,
98                 uint16_t nb_pkts);
99 uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts,
100                 uint16_t nb_pkts);
101
102
103 int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt);
104
105 static inline int
106 enetc_bd_unused(struct enetc_bdr *bdr)
107 {
108         if (bdr->next_to_clean > bdr->next_to_use)
109                 return bdr->next_to_clean - bdr->next_to_use - 1;
110
111         return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1;
112 }
113 #endif /* _ENETC_H_ */