net/dpaa: support 2.5G
[dpdk.git] / drivers / bus / dpaa / include / fman.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2010-2012 Freescale Semiconductor, Inc.
4  * All rights reserved.
5  *
6  */
7
8 #ifndef __FMAN_H
9 #define __FMAN_H
10
11 #include <stdbool.h>
12 #include <net/if.h>
13
14 #include <rte_ethdev_driver.h>
15 #include <rte_ether.h>
16
17 #include <compat.h>
18 #include <dpaa_list.h>
19
20 #ifndef FMAN_DEVICE_PATH
21 #define FMAN_DEVICE_PATH "/dev/mem"
22 #endif
23
24 #define MEMAC_NUM_OF_PADDRS 7 /* Num of additional exact match MAC adr regs */
25
26 /* Control and Configuration Register (COMMAND_CONFIG) for MEMAC */
27 #define CMD_CFG_LOOPBACK_EN     0x00000400
28 /**< 21 XGMII/GMII loopback enable */
29 #define CMD_CFG_PROMIS_EN       0x00000010
30 /**< 27 Promiscuous operation enable */
31 #define CMD_CFG_PAUSE_IGNORE    0x00000100
32 /**< 23 Ignore Pause frame quanta */
33
34 /* Statistics Configuration Register (STATN_CONFIG) */
35 #define STATS_CFG_CLR           0x00000004
36 /**< 29 Reset all counters */
37 #define STATS_CFG_CLR_ON_RD     0x00000002
38 /**< 30 Clear on read */
39 #define STATS_CFG_SATURATE      0x00000001
40 /**< 31 Saturate at the maximum val */
41
42 /**< Max receive frame length mask */
43 #define MAXFRM_SIZE_MEMAC       0x00007fe0
44 #define MAXFRM_RX_MASK          0x0000ffff
45
46 /**< Interface Mode Register Register for MEMAC */
47 #define IF_MODE_RLP 0x00000820
48
49 /**< Pool Limits */
50 #define FMAN_PORT_MAX_EXT_POOLS_NUM     8
51 #define FMAN_PORT_OBS_EXT_POOLS_NUM     2
52
53 #define FMAN_PORT_CG_MAP_NUM            8
54 #define FMAN_PORT_PRS_RESULT_WORDS_NUM  8
55 #define FMAN_PORT_BMI_FIFO_UNITS        0x100
56 #define FMAN_PORT_IC_OFFSET_UNITS       0x10
57
58 #define FMAN_ENABLE_BPOOL_DEPLETION     0xF00000F0
59
60 #define HASH_CTRL_MCAST_EN      0x00000100
61 #define GROUP_ADDRESS           0x0000010000000000LL
62 #define HASH_CTRL_ADDR_MASK     0x0000003F
63
64 /* Pre definitions of FMAN interface and Bpool structures */
65 struct __fman_if;
66 struct fman_if_bpool;
67 /* Lists of fman interfaces and bpools */
68 TAILQ_HEAD(rte_fman_if_list, __fman_if);
69
70 /* Represents the different flavour of network interface */
71 enum fman_mac_type {
72         fman_offline = 0,
73         fman_mac_1g,
74         fman_mac_10g,
75         fman_mac_2_5g,
76 };
77
78 struct mac_addr {
79         uint32_t   mac_addr_l;  /**< Lower 32 bits of 48-bit MAC address */
80         uint32_t   mac_addr_u;  /**< Upper 16 bits of 48-bit MAC address */
81 };
82
83 struct memac_regs {
84         /* General Control and Status */
85         uint32_t res0000[2];
86         uint32_t command_config;        /**< 0x008 Ctrl and cfg */
87         struct mac_addr mac_addr0;      /**< 0x00C-0x010 MAC_ADDR_0...1 */
88         uint32_t maxfrm;                /**< 0x014 Max frame length */
89         uint32_t res0018[5];
90         uint32_t hashtable_ctrl;        /**< 0x02C Hash table control */
91         uint32_t res0030[4];
92         uint32_t ievent;                /**< 0x040 Interrupt event */
93         uint32_t tx_ipg_length;
94         /**< 0x044 Transmitter inter-packet-gap */
95         uint32_t res0048;
96         uint32_t imask;                 /**< 0x04C Interrupt mask */
97         uint32_t res0050;
98         uint32_t pause_quanta[4];       /**< 0x054 Pause quanta */
99         uint32_t pause_thresh[4];       /**< 0x064 Pause quanta threshold */
100         uint32_t rx_pause_status;       /**< 0x074 Receive pause status */
101         uint32_t res0078[2];
102         struct mac_addr mac_addr[MEMAC_NUM_OF_PADDRS];
103         /**< 0x80-0x0B4 mac padr */
104         uint32_t lpwake_timer;
105         /**< 0x0B8 Low Power Wakeup Timer */
106         uint32_t sleep_timer;
107         /**< 0x0BC Transmit EEE Low Power Timer */
108         uint32_t res00c0[8];
109         uint32_t statn_config;
110         /**< 0x0E0 Statistics configuration */
111         uint32_t res00e4[7];
112         /* Rx Statistics Counter */
113         uint32_t reoct_l;               /**<Rx Eth Octets Counter */
114         uint32_t reoct_u;
115         uint32_t roct_l;                /**<Rx Octet Counters */
116         uint32_t roct_u;
117         uint32_t raln_l;                /**<Rx Alignment Error Counter */
118         uint32_t raln_u;
119         uint32_t rxpf_l;                /**<Rx valid Pause Frame */
120         uint32_t rxpf_u;
121         uint32_t rfrm_l;                /**<Rx Frame counter */
122         uint32_t rfrm_u;
123         uint32_t rfcs_l;                /**<Rx frame check seq error */
124         uint32_t rfcs_u;
125         uint32_t rvlan_l;               /**<Rx Vlan Frame Counter */
126         uint32_t rvlan_u;
127         uint32_t rerr_l;                /**<Rx Frame error */
128         uint32_t rerr_u;
129         uint32_t ruca_l;                /**<Rx Unicast */
130         uint32_t ruca_u;
131         uint32_t rmca_l;                /**<Rx Multicast */
132         uint32_t rmca_u;
133         uint32_t rbca_l;                /**<Rx Broadcast */
134         uint32_t rbca_u;
135         uint32_t rdrp_l;                /**<Rx Dropper Packet */
136         uint32_t rdrp_u;
137         uint32_t rpkt_l;                /**<Rx packet */
138         uint32_t rpkt_u;
139         uint32_t rund_l;                /**<Rx undersized packets */
140         uint32_t rund_u;
141         uint32_t r64_l;                 /**<Rx 64 byte */
142         uint32_t r64_u;
143         uint32_t r127_l;
144         uint32_t r127_u;
145         uint32_t r255_l;
146         uint32_t r255_u;
147         uint32_t r511_l;
148         uint32_t r511_u;
149         uint32_t r1023_l;
150         uint32_t r1023_u;
151         uint32_t r1518_l;
152         uint32_t r1518_u;
153         uint32_t r1519x_l;
154         uint32_t r1519x_u;
155         uint32_t rovr_l;                /**<Rx oversized but good */
156         uint32_t rovr_u;
157         uint32_t rjbr_l;                /**<Rx oversized with bad csum */
158         uint32_t rjbr_u;
159         uint32_t rfrg_l;                /**<Rx fragment Packet */
160         uint32_t rfrg_u;
161         uint32_t rcnp_l;                /**<Rx control packets (0x8808 */
162         uint32_t rcnp_u;
163         uint32_t rdrntp_l;              /**<Rx dropped due to FIFO overflow */
164         uint32_t rdrntp_u;
165         uint32_t res01d0[12];
166         /* Tx Statistics Counter */
167         uint32_t teoct_l;               /**<Tx eth octets */
168         uint32_t teoct_u;
169         uint32_t toct_l;                /**<Tx Octets */
170         uint32_t toct_u;
171         uint32_t res0210[2];
172         uint32_t txpf_l;                /**<Tx valid pause frame */
173         uint32_t txpf_u;
174         uint32_t tfrm_l;                /**<Tx frame counter */
175         uint32_t tfrm_u;
176         uint32_t tfcs_l;                /**<Tx FCS error */
177         uint32_t tfcs_u;
178         uint32_t tvlan_l;               /**<Tx Vlan Frame */
179         uint32_t tvlan_u;
180         uint32_t terr_l;                /**<Tx frame error */
181         uint32_t terr_u;
182         uint32_t tuca_l;                /**<Tx Unicast */
183         uint32_t tuca_u;
184         uint32_t tmca_l;                /**<Tx Multicast */
185         uint32_t tmca_u;
186         uint32_t tbca_l;                /**<Tx Broadcast */
187         uint32_t tbca_u;
188         uint32_t res0258[2];
189         uint32_t tpkt_l;                /**<Tx Packet */
190         uint32_t tpkt_u;
191         uint32_t tund_l;                /**<Tx Undersized */
192         uint32_t tund_u;
193         uint32_t t64_l;
194         uint32_t t64_u;
195         uint32_t t127_l;
196         uint32_t t127_u;
197         uint32_t t255_l;
198         uint32_t t255_u;
199         uint32_t t511_l;
200         uint32_t t511_u;
201         uint32_t t1023_l;
202         uint32_t t1023_u;
203         uint32_t t1518_l;
204         uint32_t t1518_u;
205         uint32_t t1519x_l;
206         uint32_t t1519x_u;
207         uint32_t res02a8[6];
208         uint32_t tcnp_l;                /**<Tx Control Packet type - 0x8808 */
209         uint32_t tcnp_u;
210         uint32_t res02c8[14];
211         /* Line Interface Control */
212         uint32_t if_mode;               /**< 0x300 Interface Mode Control */
213         uint32_t if_status;             /**< 0x304 Interface Status */
214         uint32_t res0308[14];
215         /* HiGig/2 */
216         uint32_t hg_config;             /**< 0x340 Control and cfg */
217         uint32_t res0344[3];
218         uint32_t hg_pause_quanta;       /**< 0x350 Pause quanta */
219         uint32_t res0354[3];
220         uint32_t hg_pause_thresh;       /**< 0x360 Pause quanta threshold */
221         uint32_t res0364[3];
222         uint32_t hgrx_pause_status;     /**< 0x370 Receive pause status */
223         uint32_t hg_fifos_status;       /**< 0x374 fifos status */
224         uint32_t rhm;                   /**< 0x378 rx messages counter */
225         uint32_t thm;                   /**< 0x37C tx messages counter */
226 };
227
228 struct rx_bmi_regs {
229         uint32_t fmbm_rcfg;             /**< Rx Configuration */
230         uint32_t fmbm_rst;              /**< Rx Status */
231         uint32_t fmbm_rda;              /**< Rx DMA attributes*/
232         uint32_t fmbm_rfp;              /**< Rx FIFO Parameters*/
233         uint32_t fmbm_rfed;             /**< Rx Frame End Data*/
234         uint32_t fmbm_ricp;             /**< Rx Internal Context Parameters*/
235         uint32_t fmbm_rim;              /**< Rx Internal Buffer Margins*/
236         uint32_t fmbm_rebm;             /**< Rx External Buffer Margins*/
237         uint32_t fmbm_rfne;             /**< Rx Frame Next Engine*/
238         uint32_t fmbm_rfca;             /**< Rx Frame Command Attributes.*/
239         uint32_t fmbm_rfpne;            /**< Rx Frame Parser Next Engine*/
240         uint32_t fmbm_rpso;             /**< Rx Parse Start Offset*/
241         uint32_t fmbm_rpp;              /**< Rx Policer Profile  */
242         uint32_t fmbm_rccb;             /**< Rx Coarse Classification Base */
243         uint32_t fmbm_reth;             /**< Rx Excessive Threshold */
244         uint32_t reserved003c[1];       /**< (0x03C 0x03F) */
245         uint32_t fmbm_rprai[FMAN_PORT_PRS_RESULT_WORDS_NUM];
246                                         /**< Rx Parse Results Array Init*/
247         uint32_t fmbm_rfqid;            /**< Rx Frame Queue ID*/
248         uint32_t fmbm_refqid;           /**< Rx Error Frame Queue ID*/
249         uint32_t fmbm_rfsdm;            /**< Rx Frame Status Discard Mask*/
250         uint32_t fmbm_rfsem;            /**< Rx Frame Status Error Mask*/
251         uint32_t fmbm_rfene;            /**< Rx Frame Enqueue Next Engine */
252         uint32_t reserved0074[0x2];     /**< (0x074-0x07C)  */
253         uint32_t fmbm_rcmne;
254         /**< Rx Frame Continuous Mode Next Engine */
255         uint32_t reserved0080[0x20];/**< (0x080 0x0FF)  */
256         uint32_t fmbm_ebmpi[FMAN_PORT_MAX_EXT_POOLS_NUM];
257                                         /**< Buffer Manager pool Information-*/
258         uint32_t fmbm_acnt[FMAN_PORT_MAX_EXT_POOLS_NUM];
259                                         /**< Allocate Counter-*/
260         uint32_t reserved0130[8];
261                                         /**< 0x130/0x140 - 0x15F reserved -*/
262         uint32_t fmbm_rcgm[FMAN_PORT_CG_MAP_NUM];
263                                         /**< Congestion Group Map*/
264         uint32_t fmbm_mpd;              /**< BM Pool Depletion  */
265         uint32_t reserved0184[0x1F];    /**< (0x184 0x1FF) */
266         uint32_t fmbm_rstc;             /**< Rx Statistics Counters*/
267         uint32_t fmbm_rfrc;             /**< Rx Frame Counter*/
268         uint32_t fmbm_rfbc;             /**< Rx Bad Frames Counter*/
269         uint32_t fmbm_rlfc;             /**< Rx Large Frames Counter*/
270         uint32_t fmbm_rffc;             /**< Rx Filter Frames Counter*/
271         uint32_t fmbm_rfdc;             /**< Rx Frame Discard Counter*/
272         uint32_t fmbm_rfldec;           /**< Rx Frames List DMA Error Counter*/
273         uint32_t fmbm_rodc;             /**< Rx Out of Buffers Discard nntr*/
274         uint32_t fmbm_rbdc;             /**< Rx Buffers Deallocate Counter*/
275         uint32_t reserved0224[0x17];    /**< (0x224 0x27F) */
276         uint32_t fmbm_rpc;              /**< Rx Performance Counters*/
277         uint32_t fmbm_rpcp;             /**< Rx Performance Count Parameters*/
278         uint32_t fmbm_rccn;             /**< Rx Cycle Counter*/
279         uint32_t fmbm_rtuc;             /**< Rx Tasks Utilization Counter*/
280         uint32_t fmbm_rrquc;
281         /**< Rx Receive Queue Utilization cntr*/
282         uint32_t fmbm_rduc;             /**< Rx DMA Utilization Counter*/
283         uint32_t fmbm_rfuc;             /**< Rx FIFO Utilization Counter*/
284         uint32_t fmbm_rpac;             /**< Rx Pause Activation Counter*/
285         uint32_t reserved02a0[0x18];    /**< (0x2A0 0x2FF) */
286         uint32_t fmbm_rdbg;             /**< Rx Debug-*/
287 };
288
289 struct fman_port_qmi_regs {
290         uint32_t fmqm_pnc;              /**< PortID n Configuration Register */
291         uint32_t fmqm_pns;              /**< PortID n Status Register */
292         uint32_t fmqm_pnts;             /**< PortID n Task Status Register */
293         uint32_t reserved00c[4];        /**< 0xn00C - 0xn01B */
294         uint32_t fmqm_pnen;             /**< PortID n Enqueue NIA Register */
295         uint32_t fmqm_pnetfc;           /**< PortID n Enq Total Frame Counter */
296         uint32_t reserved024[2];        /**< 0xn024 - 0x02B */
297         uint32_t fmqm_pndn;             /**< PortID n Dequeue NIA Register */
298         uint32_t fmqm_pndc;             /**< PortID n Dequeue Config Register */
299         uint32_t fmqm_pndtfc;           /**< PortID n Dequeue tot Frame cntr */
300         uint32_t fmqm_pndfdc;           /**< PortID n Dequeue FQID Dflt Cntr */
301         uint32_t fmqm_pndcc;            /**< PortID n Dequeue Confirm Counter */
302 };
303
304 /* This struct exports parameters about an Fman network interface, determined
305  * from the device-tree.
306  */
307 struct fman_if {
308         /* Which Fman this interface belongs to */
309         uint8_t fman_idx;
310         /* The type/speed of the interface */
311         enum fman_mac_type mac_type;
312         /* Boolean, set when mac type is memac */
313         uint8_t is_memac;
314         /* Boolean, set when PHY is RGMII */
315         uint8_t is_rgmii;
316         /* The index of this MAC (within the Fman it belongs to) */
317         uint8_t mac_idx;
318         /* The MAC address */
319         struct rte_ether_addr mac_addr;
320         /* The Qman channel to schedule Tx FQs to */
321         u16 tx_channel_id;
322         /* The hard-coded FQIDs for this interface. Note: this doesn't cover
323          * the PCD nor the "Rx default" FQIDs, which are configured via FMC
324          * and its XML-based configuration.
325          */
326         uint32_t fqid_rx_def;
327         uint32_t fqid_rx_err;
328         uint32_t fqid_tx_err;
329         uint32_t fqid_tx_confirm;
330
331         struct list_head bpool_list;
332         /* The node for linking this interface into "fman_if_list" */
333         struct list_head node;
334 };
335
336 /* This struct exposes parameters for buffer pools, extracted from the network
337  * interface settings in the device tree.
338  */
339 struct fman_if_bpool {
340         uint32_t bpid;
341         uint64_t count;
342         uint64_t size;
343         uint64_t addr;
344         /* The node for linking this bpool into fman_if::bpool_list */
345         struct list_head node;
346 };
347
348 /* Internal Context transfer params - FMBM_RICP*/
349 struct fman_if_ic_params {
350         /*IC offset in the packet buffer */
351         uint16_t iceof;
352         /*IC internal offset */
353         uint16_t iciof;
354         /*IC size to copy */
355         uint16_t icsz;
356 };
357
358 /* The exported "struct fman_if" type contains the subset of fields we want
359  * exposed. This struct is embedded in a larger "struct __fman_if" which
360  * contains the extra bits we *don't* want exposed.
361  */
362 struct __fman_if {
363         struct fman_if __if;
364         char node_path[PATH_MAX];
365         uint64_t regs_size;
366         void *ccsr_map;
367         void *bmi_map;
368         void *qmi_map;
369         struct list_head node;
370 };
371
372 /* And this is the base list node that the interfaces are added to. (See
373  * fman_if_enable_all_rx() below for an example of its use.)
374  */
375 extern const struct list_head *fman_if_list;
376
377 extern int fman_ccsr_map_fd;
378
379 /* To iterate the "bpool_list" for an interface. Eg;
380  *        struct fman_if *p = get_ptr_to_some_interface();
381  *        struct fman_if_bpool *bp;
382  *        printf("Interface uses following BPIDs;\n");
383  *        fman_if_for_each_bpool(bp, p) {
384  *            printf("    %d\n", bp->bpid);
385  *            [...]
386  *        }
387  */
388 #define fman_if_for_each_bpool(bp, __if) \
389         list_for_each_entry(bp, &(__if)->bpool_list, node)
390
391 #define FMAN_ERR(rc, fmt, args...) \
392         do { \
393                 _errno = (rc); \
394                 DPAA_BUS_LOG(ERR, fmt "(%d)", ##args, errno); \
395         } while (0)
396
397 #define FMAN_IP_REV_1   0xC30C4
398 #define FMAN_IP_REV_1_MAJOR_MASK 0x0000FF00
399 #define FMAN_IP_REV_1_MAJOR_SHIFT 8
400 #define FMAN_V3 0x06
401 #define FMAN_V3_CONTEXTA_EN_A2V 0x10000000
402 #define FMAN_V3_CONTEXTA_EN_OVOM        0x02000000
403 #define FMAN_V3_CONTEXTA_EN_EBD 0x80000000
404 #define FMAN_CONTEXTA_DIS_CHECKSUM      0x7ull
405 #define FMAN_CONTEXTA_SET_OPCODE11 0x2000000b00000000
406 extern u16 fman_ip_rev;
407 extern u32 fman_dealloc_bufs_mask_hi;
408 extern u32 fman_dealloc_bufs_mask_lo;
409
410 /**
411  * Initialize the FMAN driver
412  *
413  * @args void
414  * @return
415  *      0 for success; error OTHERWISE
416  */
417 int fman_init(void);
418
419 /**
420  * Teardown the FMAN driver
421  *
422  * @args void
423  * @return void
424  */
425 void fman_finish(void);
426
427 #endif  /* __FMAN_H */