net/enetc: add PMD with basic operations
[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 /*
21  * upper_32_bits - return bits 32-63 of a number
22  * @n: the number we're accessing
23  *
24  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
25  * the "right shift count >= width of type" warning when that quantity is
26  * 32-bits.
27  */
28 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
29
30 /*
31  * lower_32_bits - return bits 0-31 of a number
32  * @n: the number we're accessing
33  */
34 #define lower_32_bits(n) ((uint32_t)(n))
35
36 #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i]))
37 #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
38
39 struct enetc_swbd {
40         struct rte_mbuf *buffer_addr;
41 };
42
43 struct enetc_bdr {
44         struct rte_eth_dev *ndev;
45         struct rte_mempool *mb_pool;   /* mbuf pool to populate RX ring. */
46         void *bd_base;                  /* points to Rx or Tx BD ring */
47         union {
48                 void *tcir;
49                 void *rcir;
50         };
51         uint16_t index;
52         int bd_count; /* # of BDs */
53         int next_to_use;
54         int next_to_clean;
55         struct enetc_swbd *q_swbd;
56         union {
57                 void *tcisr; /* Tx */
58                 int next_to_alloc; /* Rx */
59         };
60 };
61
62 /*
63  * Structure to store private data for each driver instance (for each port).
64  */
65 struct enetc_eth_adapter {
66         struct rte_eth_dev *ndev;
67         struct enetc_eth_hw hw;
68 };
69
70 #define ENETC_DEV_PRIVATE(adapter) \
71         ((struct enetc_eth_adapter *)adapter)
72
73 #define ENETC_DEV_PRIVATE_TO_HW(adapter) \
74         (&((struct enetc_eth_adapter *)adapter)->hw)
75
76 #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \
77         (&((struct enetc_eth_adapter *)adapter)->stats)
78
79 #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \
80         (&((struct enetc_eth_adapter *)adapter)->intr)
81
82 #define ENETC_GET_HW_ADDR(reg, addr) ((void *)(((size_t)reg) + (addr)))
83 #define ENETC_REG_READ(addr) (*(uint32_t *)addr)
84 #define ENETC_REG_WRITE(addr, val) (*(uint32_t *)addr = val)
85 #define ENETC_REG_WRITE_RELAXED(addr, val) (*(uint32_t *)addr = val)
86
87 #endif /* _ENETC_H_ */