ea92d4b6eb78e31d0ba4d64a22407f002ff19092
[dpdk.git] / drivers / net / ark / ark_udm.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2015-2018 Atomic Rules LLC
3  */
4
5 #ifndef _ARK_UDM_H_
6 #define _ARK_UDM_H_
7
8 #include <stdint.h>
9
10 #include <rte_memory.h>
11
12 /* The UDM or Upstream Data Mover is an internal Arkville hardware
13  * module for moving packet from the RX packet streams to host memory.
14  * This module is *not* intended for end-user manipulation, hence
15  * there is minimal documentation.
16  */
17
18 /* Meta data structure passed from FPGA, must match layout in FPGA
19  * -- 32 bytes
20  */
21 struct ark_rx_meta {
22         uint64_t timestamp;
23         uint64_t user_data;
24         uint8_t  reserved[14];
25         uint16_t pkt_len;
26 } __rte_packed;
27
28 /*
29  * UDM hardware structures
30  * These are overlay structures to a memory mapped FPGA device.  These
31  * structs will never be instantiated in ram memory
32  */
33
34 #define ARK_RX_WRITE_TIME_NS 2500
35 #define ARK_UDM_SETUP 0
36 #define ARK_UDM_CONST2 0xbACECACE
37 #define ARK_UDM_CONST3 0x334d4455
38 #define ARK_UDM_CONST ARK_UDM_CONST3
39 struct ark_udm_setup_t {
40         uint32_t r0;
41         uint32_t r4;
42         volatile uint32_t cycle_count;
43         uint32_t const0;
44 };
45
46 #define ARK_UDM_CFG 0x010
47 struct ark_udm_cfg_t {
48         volatile uint32_t stop_flushed; /* RO */
49         volatile uint32_t command;
50         uint32_t dataroom;
51         uint32_t headroom;
52 };
53
54 typedef enum {
55         ARK_UDM_START = 0x1,
56         ARK_UDM_STOP = 0x2,
57         ARK_UDM_RESET = 0x3
58 } ark_udm_commands;
59
60 #define ARK_UDM_STATS 0x020
61 struct ark_udm_stats_t {
62         volatile uint64_t rx_byte_count;
63         volatile uint64_t rx_packet_count;
64         volatile uint64_t rx_mbuf_count;
65         volatile uint64_t rx_sent_packets;
66 };
67
68 #define ARK_UDM_PQ 0x040
69 struct ark_udm_queue_stats_t {
70         volatile uint64_t q_byte_count;
71         volatile uint64_t q_packet_count;       /* includes drops */
72         volatile uint64_t q_mbuf_count;
73         volatile uint64_t q_ff_packet_count;
74         volatile uint64_t q_pkt_drop;
75         uint32_t q_enable;
76 };
77
78 #define ARK_UDM_TLP 0x0070
79 struct ark_udm_tlp_t {
80         volatile uint64_t pkt_drop;     /* global */
81         volatile uint32_t tlp_q1;
82         volatile uint32_t tlp_q2;
83         volatile uint32_t tlp_q3;
84         volatile uint32_t tlp_q4;
85         volatile uint32_t tlp_full;
86 };
87
88 #define ARK_UDM_PCIBP 0x00a0
89 struct ark_udm_pcibp_t {
90         volatile uint32_t pci_clear;
91         volatile uint32_t pci_empty;
92         volatile uint32_t pci_q1;
93         volatile uint32_t pci_q2;
94         volatile uint32_t pci_q3;
95         volatile uint32_t pci_q4;
96         volatile uint32_t pci_full;
97 };
98
99 #define ARK_UDM_TLP_PS 0x00bc
100 struct ark_udm_tlp_ps_t {
101         volatile uint32_t tlp_clear;
102         volatile uint32_t tlp_ps_min;
103         volatile uint32_t tlp_ps_max;
104         volatile uint32_t tlp_full_ps_min;
105         volatile uint32_t tlp_full_ps_max;
106         volatile uint32_t tlp_dw_ps_min;
107         volatile uint32_t tlp_dw_ps_max;
108         volatile uint32_t tlp_pldw_ps_min;
109         volatile uint32_t tlp_pldw_ps_max;
110 };
111
112 #define ARK_UDM_RT_CFG 0x00e0
113 struct ark_udm_rt_cfg_t {
114         rte_iova_t hw_prod_addr;
115         uint32_t write_interval;        /* 4ns cycles */
116         volatile uint32_t prod_idx;     /* RO */
117 };
118
119 /*  Consolidated structure */
120 #define ARK_UDM_EXPECT_SIZE (0x00fc + 4)
121 #define ARK_UDM_QOFFSET ARK_UDM_EXPECT_SIZE
122 struct ark_udm_t {
123         struct ark_udm_setup_t setup;
124         struct ark_udm_cfg_t cfg;
125         struct ark_udm_stats_t stats;
126         struct ark_udm_queue_stats_t qstats;
127         uint8_t reserved1[(ARK_UDM_TLP - ARK_UDM_PQ) -
128                           sizeof(struct ark_udm_queue_stats_t)];
129         struct ark_udm_tlp_t tlp;
130         uint8_t reserved2[(ARK_UDM_PCIBP - ARK_UDM_TLP) -
131                           sizeof(struct ark_udm_tlp_t)];
132         struct ark_udm_pcibp_t pcibp;
133         struct ark_udm_tlp_ps_t tlp_ps;
134         struct ark_udm_rt_cfg_t rt_cfg;
135         int8_t reserved3[(ARK_UDM_EXPECT_SIZE - ARK_UDM_RT_CFG) -
136                          sizeof(struct ark_udm_rt_cfg_t)];
137 };
138
139
140 int ark_udm_verify(struct ark_udm_t *udm);
141 int ark_udm_stop(struct ark_udm_t *udm, int wait);
142 void ark_udm_start(struct ark_udm_t *udm);
143 int ark_udm_reset(struct ark_udm_t *udm);
144 void ark_udm_configure(struct ark_udm_t *udm,
145                        uint32_t headroom,
146                        uint32_t dataroom,
147                        uint32_t write_interval_ns);
148 void ark_udm_write_addr(struct ark_udm_t *udm, rte_iova_t addr);
149 void ark_udm_stats_reset(struct ark_udm_t *udm);
150 void ark_udm_dump_stats(struct ark_udm_t *udm, const char *msg);
151 void ark_udm_dump_queue_stats(struct ark_udm_t *udm, const char *msg,
152                               uint16_t qid);
153 void ark_udm_dump(struct ark_udm_t *udm, const char *msg);
154 void ark_udm_dump_perf(struct ark_udm_t *udm, const char *msg);
155 void ark_udm_dump_setup(struct ark_udm_t *udm, uint16_t q_id);
156 int ark_udm_is_flushed(struct ark_udm_t *udm);
157
158 /* Per queue data */
159 uint64_t ark_udm_dropped(struct ark_udm_t *udm);
160 uint64_t ark_udm_bytes(struct ark_udm_t *udm);
161 uint64_t ark_udm_packets(struct ark_udm_t *udm);
162
163 void ark_udm_queue_stats_reset(struct ark_udm_t *udm);
164 void ark_udm_queue_enable(struct ark_udm_t *udm, int enable);
165
166 #endif