New upstream version 18.08
[deb_dpdk.git] / drivers / bus / fslmc / qbman / include / fsl_qbman_base.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (C) 2014 Freescale Semiconductor, Inc.
4  *
5  */
6 #ifndef _FSL_QBMAN_BASE_H
7 #define _FSL_QBMAN_BASE_H
8
9 /**
10  * DOC: QBMan basic structures
11  *
12  * The QBMan block descriptor, software portal descriptor and Frame descriptor
13  * are defined here.
14  *
15  */
16
17 /**
18  * struct qbman_block_desc - qbman block descriptor structure
19  * @ccsr_reg_bar: CCSR register map.
20  * @irq_rerr: Recoverable error interrupt line.
21  * @irq_nrerr: Non-recoverable error interrupt line
22  *
23  * Descriptor for a QBMan instance on the SoC. On partitions/targets that do not
24  * control this QBMan instance, these values may simply be place-holders. The
25  * idea is simply that we be able to distinguish between them, eg. so that SWP
26  * descriptors can identify which QBMan instance they belong to.
27  */
28 struct qbman_block_desc {
29         void *ccsr_reg_bar;
30         int irq_rerr;
31         int irq_nrerr;
32 };
33
34 enum qbman_eqcr_mode {
35         qman_eqcr_vb_ring = 2, /* Valid bit, with eqcr in ring mode */
36         qman_eqcr_vb_array, /* Valid bit, with eqcr in array mode */
37 };
38
39 /**
40  * struct qbman_swp_desc - qbman software portal descriptor structure
41  * @block: The QBMan instance.
42  * @cena_bar: Cache-enabled portal register map.
43  * @cinh_bar: Cache-inhibited portal register map.
44  * @irq: -1 if unused (or unassigned)
45  * @idx: SWPs within a QBMan are indexed. -1 if opaque to the user.
46  * @qman_version: the qman version.
47  * @eqcr_mode: Select the eqcr mode, currently only valid bit ring mode and
48  * valid bit array mode are supported.
49  *
50  * Descriptor for a QBMan software portal, expressed in terms that make sense to
51  * the user context. Ie. on MC, this information is likely to be true-physical,
52  * and instantiated statically at compile-time. On GPP, this information is
53  * likely to be obtained via "discovery" over a partition's "MC bus"
54  * (ie. in response to a MC portal command), and would take into account any
55  * virtualisation of the GPP user's address space and/or interrupt numbering.
56  */
57 struct qbman_swp_desc {
58         const struct qbman_block_desc *block;
59         uint8_t *cena_bar;
60         uint8_t *cinh_bar;
61         int irq;
62         int idx;
63         uint32_t qman_version;
64         enum qbman_eqcr_mode eqcr_mode;
65 };
66
67 /* Driver object for managing a QBMan portal */
68 struct qbman_swp;
69
70 /**
71  * struct qbman_fd - basci structure for qbman frame descriptor
72  * @words: for easier/faster copying the whole FD structure.
73  * @addr_lo: the lower 32 bits of the address in FD.
74  * @addr_hi: the upper 32 bits of the address in FD.
75  * @len: the length field in FD.
76  * @bpid_offset: represent the bpid and offset fields in FD. offset in
77  * the MS 16 bits, BPID in the LS 16 bits.
78  * @frc: frame context
79  * @ctrl: the 32bit control bits including dd, sc,... va, err.
80  * @flc_lo: the lower 32bit of flow context.
81  * @flc_hi: the upper 32bits of flow context.
82  *
83  * Place-holder for FDs, we represent it via the simplest form that we need for
84  * now. Different overlays may be needed to support different options, etc. (It
85  * is impractical to define One True Struct, because the resulting encoding
86  * routines (lots of read-modify-writes) would be worst-case performance whether
87  * or not circumstances required them.)
88  *
89  * Note, as with all data-structures exchanged between software and hardware (be
90  * they located in the portal register map or DMA'd to and from main-memory),
91  * the driver ensures that the caller of the driver API sees the data-structures
92  * in host-endianness. "struct qbman_fd" is no exception. The 32-bit words
93  * contained within this structure are represented in host-endianness, even if
94  * hardware always treats them as little-endian. As such, if any of these fields
95  * are interpreted in a binary (rather than numerical) fashion by hardware
96  * blocks (eg. accelerators), then the user should be careful. We illustrate
97  * with an example;
98  *
99  * Suppose the desired behaviour of an accelerator is controlled by the "frc"
100  * field of the FDs that are sent to it. Suppose also that the behaviour desired
101  * by the user corresponds to an "frc" value which is expressed as the literal
102  * sequence of bytes 0xfe, 0xed, 0xab, and 0xba. So "frc" should be the 32-bit
103  * value in which 0xfe is the first byte and 0xba is the last byte, and as
104  * hardware is little-endian, this amounts to a 32-bit "value" of 0xbaabedfe. If
105  * the software is little-endian also, this can simply be achieved by setting
106  * frc=0xbaabedfe. On the other hand, if software is big-endian, it should set
107  * frc=0xfeedabba! The best away of avoiding trouble with this sort of thing is
108  * to treat the 32-bit words as numerical values, in which the offset of a field
109  * from the beginning of the first byte (as required or generated by hardware)
110  * is numerically encoded by a left-shift (ie. by raising the field to a
111  * corresponding power of 2).  Ie. in the current example, software could set
112  * "frc" in the following way, and it would work correctly on both little-endian
113  * and big-endian operation;
114  *    fd.frc = (0xfe << 0) | (0xed << 8) | (0xab << 16) | (0xba << 24);
115  */
116 struct qbman_fd {
117         union {
118                 uint32_t words[8];
119                 struct qbman_fd_simple {
120                         uint32_t addr_lo;
121                         uint32_t addr_hi;
122                         uint32_t len;
123                         uint32_t bpid_offset;
124                         uint32_t frc;
125                         uint32_t ctrl;
126                         uint32_t flc_lo;
127                         uint32_t flc_hi;
128                 } simple;
129         };
130 };
131
132 #endif /* !_FSL_QBMAN_BASE_H */