New upstream version 18.02
[deb_dpdk.git] / drivers / bus / fslmc / qbman / qbman_portal.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
4  *
5  */
6
7 #include "qbman_sys.h"
8 #include <fsl_qbman_portal.h>
9
10 uint32_t qman_version;
11 #define QMAN_REV_4000   0x04000000
12 #define QMAN_REV_4100   0x04010000
13 #define QMAN_REV_4101   0x04010001
14
15 /* All QBMan command and result structures use this "valid bit" encoding */
16 #define QB_VALID_BIT ((uint32_t)0x80)
17
18 /* Management command result codes */
19 #define QBMAN_MC_RSLT_OK      0xf0
20
21 /* QBMan DQRR size is set at runtime in qbman_portal.c */
22
23 #define QBMAN_EQCR_SIZE 8
24
25 static inline uint8_t qm_cyc_diff(uint8_t ringsize, uint8_t first,
26                                   uint8_t last)
27 {
28         /* 'first' is included, 'last' is excluded */
29         if (first <= last)
30                 return last - first;
31         return (2 * ringsize) + last - first;
32 }
33
34 /* --------------------- */
35 /* portal data structure */
36 /* --------------------- */
37
38 struct qbman_swp {
39         struct qbman_swp_desc desc;
40         /* The qbman_sys (ie. arch/OS-specific) support code can put anything it
41          * needs in here.
42          */
43         struct qbman_swp_sys sys;
44         /* Management commands */
45         struct {
46 #ifdef QBMAN_CHECKING
47                 enum swp_mc_check {
48                         swp_mc_can_start, /* call __qbman_swp_mc_start() */
49                         swp_mc_can_submit, /* call __qbman_swp_mc_submit() */
50                         swp_mc_can_poll, /* call __qbman_swp_mc_result() */
51                 } check;
52 #endif
53                 uint32_t valid_bit; /* 0x00 or 0x80 */
54         } mc;
55         /* Push dequeues */
56         uint32_t sdq;
57         /* Volatile dequeues */
58         struct {
59                 /* VDQCR supports a "1 deep pipeline", meaning that if you know
60                  * the last-submitted command is already executing in the
61                  * hardware (as evidenced by at least 1 valid dequeue result),
62                  * you can write another dequeue command to the register, the
63                  * hardware will start executing it as soon as the
64                  * already-executing command terminates. (This minimises latency
65                  * and stalls.) With that in mind, this "busy" variable refers
66                  * to whether or not a command can be submitted, not whether or
67                  * not a previously-submitted command is still executing. In
68                  * other words, once proof is seen that the previously-submitted
69                  * command is executing, "vdq" is no longer "busy".
70                  */
71                 atomic_t busy;
72                 uint32_t valid_bit; /* 0x00 or 0x80 */
73                 /* We need to determine when vdq is no longer busy. This depends
74                  * on whether the "busy" (last-submitted) dequeue command is
75                  * targeting DQRR or main-memory, and detected is based on the
76                  * presence of the dequeue command's "token" showing up in
77                  * dequeue entries in DQRR or main-memory (respectively).
78                  */
79                 struct qbman_result *storage; /* NULL if DQRR */
80         } vdq;
81         /* DQRR */
82         struct {
83                 uint32_t next_idx;
84                 uint32_t valid_bit;
85                 uint8_t dqrr_size;
86                 int reset_bug;
87         } dqrr;
88         struct {
89                 uint32_t pi;
90                 uint32_t pi_vb;
91                 uint32_t ci;
92                 int available;
93         } eqcr;
94 };
95
96 /* -------------------------- */
97 /* portal management commands */
98 /* -------------------------- */
99
100 /* Different management commands all use this common base layer of code to issue
101  * commands and poll for results. The first function returns a pointer to where
102  * the caller should fill in their MC command (though they should ignore the
103  * verb byte), the second function commits merges in the caller-supplied command
104  * verb (which should not include the valid-bit) and submits the command to
105  * hardware, and the third function checks for a completed response (returns
106  * non-NULL if only if the response is complete).
107  */
108 void *qbman_swp_mc_start(struct qbman_swp *p);
109 void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, uint8_t cmd_verb);
110 void *qbman_swp_mc_result(struct qbman_swp *p);
111
112 /* Wraps up submit + poll-for-result */
113 static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
114                                           uint8_t cmd_verb)
115 {
116         int loopvar = 1000;
117
118         qbman_swp_mc_submit(swp, cmd, cmd_verb);
119         do {
120                 cmd = qbman_swp_mc_result(swp);
121         } while (!cmd && loopvar--);
122         QBMAN_BUG_ON(!loopvar);
123
124         return cmd;
125 }
126
127 /* ---------------------- */
128 /* Descriptors/cachelines */
129 /* ---------------------- */
130
131 /* To avoid needless dynamic allocation, the driver API often gives the caller
132  * a "descriptor" type that the caller can instantiate however they like.
133  * Ultimately though, it is just a cacheline of binary storage (or something
134  * smaller when it is known that the descriptor doesn't need all 64 bytes) for
135  * holding pre-formatted pieces of hardware commands. The performance-critical
136  * code can then copy these descriptors directly into hardware command
137  * registers more efficiently than trying to construct/format commands
138  * on-the-fly. The API user sees the descriptor as an array of 32-bit words in
139  * order for the compiler to know its size, but the internal details are not
140  * exposed. The following macro is used within the driver for converting *any*
141  * descriptor pointer to a usable array pointer. The use of a macro (instead of
142  * an inline) is necessary to work with different descriptor types and to work
143  * correctly with const and non-const inputs (and similarly-qualified outputs).
144  */
145 #define qb_cl(d) (&(d)->donot_manipulate_directly[0])