New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / enetc / base / enetc_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 NXP
3  */
4
5 #ifndef _ENETC_HW_H_
6 #define _ENETC_HW_H_
7 #include <rte_io.h>
8
9 #define BIT(x)          ((uint64_t)1 << ((x)))
10
11 /* ENETC device IDs */
12 #define ENETC_DEV_ID_VF         0xef00
13 #define ENETC_DEV_ID            0xe100
14
15 /* ENETC register block BAR */
16 #define ENETC_BAR_REGS                  0x0
17
18 /* SI regs, offset: 0h */
19 #define ENETC_SIMR                      0x0
20 #define ENETC_SIMR_EN                   BIT(31)
21
22 #define ENETC_SIPMAR0                   0x80
23 #define ENETC_SIPMAR1                   0x84
24
25 #define ENETC_SICAPR0                   0x900
26 #define ENETC_SICAPR1                   0x904
27
28 #define ENETC_SIMSITRV(n)               (0xB00 + (n) * 0x4)
29 #define ENETC_SIMSIRRV(n)               (0xB80 + (n) * 0x4)
30
31 #define ENETC_SICCAPR                   0x1200
32
33 /* enum for BD type */
34 enum enetc_bdr_type {TX, RX};
35
36 #define ENETC_BDR(type, n, off)         (0x8000 + (type) * 0x100 + (n) * 0x200 \
37                                                         + (off))
38 /* RX BDR reg offsets */
39 #define ENETC_RBMR              0x0 /* RX BDR mode register*/
40 #define ENETC_RBMR_EN           BIT(31)
41
42 #define ENETC_RBSR              0x4  /* Rx BDR status register*/
43 #define ENETC_RBBSR             0x8  /* Rx BDR buffer size register*/
44 #define ENETC_RBCIR             0xc  /* Rx BDR consumer index register*/
45 #define ENETC_RBBAR0            0x10 /* Rx BDR base address register 0 */
46 #define ENETC_RBBAR1            0x14 /* Rx BDR base address register 1*/
47 #define ENETC_RBPIR             0x18 /* Rx BDR producer index register*/
48 #define ENETC_RBLENR            0x20 /* Rx BDR length register*/
49 #define ENETC_RBIER             0xa0 /* Rx BDR interrupt enable register*/
50 #define ENETC_RBIER_RXTIE       BIT(0)
51 #define ENETC_RBIDR             0xa4 /* Rx BDR interrupt detect register*/
52 #define ENETC_RBICIR0           0xa8 /* Rx BDR inetrrupt coalescing register 0*/
53 #define ENETC_RBICIR0_ICEN      BIT(31)
54
55
56 #define ENETC_TBMR      0x0  /* Tx BDR mode register (TBMR) 32 RW */
57 #define ENETC_TBSR      0x4  /* x BDR status register (TBSR) 32 RO */
58 #define ENETC_TBBAR0    0x10 /* Tx BDR base address register 0 (TBBAR0) 32 RW */
59 #define ENETC_TBBAR1    0x14 /* Tx BDR base address register 1 (TBBAR1) 32 RW */
60 #define ENETC_TBCIR     0x18 /* Tx BDR consumer index register (TBCIR) 32 RW */
61 #define ENETC_TBCISR    0x1C /* Tx BDR consumer index shadow register 32 RW */
62 #define ENETC_TBIER     0xA0 /* Tx BDR interrupt enable register 32 RW */
63 #define ENETC_TBIDR     0xA4 /* Tx BDR interrupt detect register 32 RO */
64 #define ENETC_TBICR0    0xA8 /* Tx BDR interrupt coalescing register 0 32 RW */
65 #define ENETC_TBICR1    0xAC /* Tx BDR interrupt coalescing register 1 32 RW */
66 #define ENETC_TBLENR    0x20
67
68 #define ENETC_TBCISR_IDX_MASK           0xffff
69 #define ENETC_TBIER_TXFIE               BIT(1)
70
71 #define ENETC_RTBLENR_LEN(n)            ((n) & ~0x7)
72 #define ENETC_TBMR_EN                   BIT(31)
73
74 /* Port regs, offset: 1_0000h */
75 #define ENETC_PORT_BASE                 0x10000
76 #define ENETC_PMR                       0x00000
77 #define ENETC_PMR_EN                    (BIT(16) | BIT(17) | BIT(18))
78 #define ENETC_PSR                       0x00004 /* RO */
79 #define ENETC_PSIPMR                    0x00018
80 #define ENETC_PSIPMR_SET_UP(n)          (0x1 << (n)) /* n = SI index */
81 #define ENETC_PSIPMR_SET_MP(n)          (0x1 << ((n) + 8))
82 #define ENETC_PSIPMR_SET_VLAN_MP(n)     (0x1 << ((n) + 16))
83 #define ENETC_PSIPMAR0(n)               (0x00100 + (n) * 0x20)
84 #define ENETC_PSIPMAR1(n)               (0x00104 + (n) * 0x20)
85 #define ENETC_PCAPR0                    0x00900
86 #define ENETC_PCAPR1                    0x00904
87
88 #define ENETC_PV0CFGR(n)                (0x00920 + (n) * 0x10)
89 #define ENETC_PVCFGR_SET_TXBDR(val)     ((val) & 0xff)
90 #define ENETC_PVCFGR_SET_RXBDR(val)     (((val) & 0xff) << 16)
91
92 #define ENETC_PM0_CMD_CFG               0x08008
93 #define ENETC_PM0_TX_EN                 BIT(0)
94 #define ENETC_PM0_RX_EN                 BIT(1)
95
96 #define ENETC_PM0_MAXFRM                0x08014
97 #define ENETC_SET_MAXFRM(val)           ((val) << 16)
98
99 #define ENETC_PM0_STATUS                0x08304
100 #define ENETC_LINK_MODE                 0x0000000000080000ULL
101 #define ENETC_LINK_STATUS               0x0000000000010000ULL
102 #define ENETC_LINK_SPEED_MASK           0x0000000000060000ULL
103 #define ENETC_LINK_SPEED_10M            0x0ULL
104 #define ENETC_LINK_SPEED_100M           0x0000000000020000ULL
105 #define ENETC_LINK_SPEED_1G             0x0000000000040000ULL
106
107 /* Global regs, offset: 2_0000h */
108 #define ENETC_GLOBAL_BASE               0x20000
109 #define ENETC_G_EIPBRR0                 0x00bf8
110 #define ENETC_G_EIPBRR1                 0x00bfc
111
112 /* general register accessors */
113 #define enetc_rd_reg(reg)       rte_read32((void *)(reg))
114 #define enetc_wr_reg(reg, val)  rte_write32((val), (void *)(reg))
115 #define enetc_rd(hw, off)       enetc_rd_reg((size_t)(hw)->reg + (off))
116 #define enetc_wr(hw, off, val)  enetc_wr_reg((size_t)(hw)->reg + (off), val)
117 /* port register accessors - PF only */
118 #define enetc_port_rd(hw, off)  enetc_rd_reg((size_t)(hw)->port + (off))
119 #define enetc_port_wr(hw, off, val) \
120                                 enetc_wr_reg((size_t)(hw)->port + (off), val)
121 /* global register accessors - PF only */
122 #define enetc_global_rd(hw, off) \
123                                 enetc_rd_reg((size_t)(hw)->global + (off))
124 #define enetc_global_wr(hw, off, val) \
125                                 enetc_wr_reg((size_t)(hw)->global + (off), val)
126 /* BDR register accessors, see ENETC_BDR() */
127 #define enetc_bdr_rd(hw, t, n, off) \
128                                 enetc_rd(hw, ENETC_BDR(t, n, off))
129 #define enetc_bdr_wr(hw, t, n, off, val) \
130                                 enetc_wr(hw, ENETC_BDR(t, n, off), val)
131
132 #define enetc_txbdr_rd(hw, n, off) enetc_bdr_rd(hw, TX, n, off)
133 #define enetc_rxbdr_rd(hw, n, off) enetc_bdr_rd(hw, RX, n, off)
134 #define enetc_txbdr_wr(hw, n, off, val) \
135                                 enetc_bdr_wr(hw, TX, n, off, val)
136 #define enetc_rxbdr_wr(hw, n, off, val) \
137                                 enetc_bdr_wr(hw, RX, n, off, val)
138
139 #define ENETC_TX_ADDR(txq, addr) ((void *)((txq)->enetc_txbdr + (addr)))
140
141 #define ENETC_TXBD_FLAGS_IE             BIT(13)
142 #define ENETC_TXBD_FLAGS_F              BIT(15)
143
144 /* ENETC Parsed values (Little Endian) */
145 #define ENETC_PKT_TYPE_ETHER            0x0060
146 #define ENETC_PKT_TYPE_IPV4             0x0000
147 #define ENETC_PKT_TYPE_IPV6             0x0020
148 #define ENETC_PKT_TYPE_IPV4_TCP \
149                         (0x0010 | ENETC_PKT_TYPE_IPV4)
150 #define ENETC_PKT_TYPE_IPV6_TCP \
151                         (0x0010 | ENETC_PKT_TYPE_IPV6)
152 #define ENETC_PKT_TYPE_IPV4_UDP \
153                         (0x0011 | ENETC_PKT_TYPE_IPV4)
154 #define ENETC_PKT_TYPE_IPV6_UDP \
155                         (0x0011 | ENETC_PKT_TYPE_IPV6)
156 #define ENETC_PKT_TYPE_IPV4_SCTP \
157                         (0x0013 | ENETC_PKT_TYPE_IPV4)
158 #define ENETC_PKT_TYPE_IPV6_SCTP \
159                         (0x0013 | ENETC_PKT_TYPE_IPV6)
160 #define ENETC_PKT_TYPE_IPV4_ICMP \
161                         (0x0003 | ENETC_PKT_TYPE_IPV4)
162 #define ENETC_PKT_TYPE_IPV6_ICMP \
163                         (0x0003 | ENETC_PKT_TYPE_IPV6)
164
165 /* PCI device info */
166 struct enetc_hw {
167         void *reg;      /* SI registers, used by all PCI functions */
168         void *port;     /* Port registers, PF only */
169         void *global;   /* IP global registers, PF only */
170 };
171
172 struct enetc_eth_mac_info {
173         uint8_t addr[ETHER_ADDR_LEN];
174         uint8_t perm_addr[ETHER_ADDR_LEN];
175         uint8_t get_link_status;
176 };
177
178 struct enetc_eth_hw {
179         struct rte_eth_dev *ndev;
180         struct enetc_hw hw;
181         uint16_t device_id;
182         uint16_t vendor_id;
183         uint8_t revision_id;
184         struct enetc_eth_mac_info mac;
185 };
186
187 /* Transmit Descriptor */
188 struct enetc_tx_desc {
189         uint64_t addr;
190         uint16_t frm_len;
191         uint16_t buf_len;
192         uint32_t flags_errors;
193 };
194
195 /* TX Buffer Descriptors (BD) */
196 struct enetc_tx_bd {
197         uint64_t addr;
198         uint16_t buf_len;
199         uint16_t frm_len;
200         uint16_t err_csum;
201         uint16_t flags;
202 };
203
204 /* RX buffer descriptor */
205 union enetc_rx_bd {
206         struct {
207                 uint64_t addr;
208                 uint8_t reserved[8];
209         } w;
210         struct {
211                 uint16_t inet_csum;
212                 uint16_t parse_summary;
213                 uint32_t rss_hash;
214                 uint16_t buf_len;
215                 uint16_t vlan_opt;
216                 union {
217                         struct {
218                                 uint16_t flags;
219                                 uint16_t error;
220                         };
221                         uint32_t lstatus;
222                 };
223         } r;
224 };
225
226 #endif