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