Imported Upstream version 16.11
[deb_dpdk.git] / drivers / net / thunderx / base / nicvf_mbox.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium networks Ltd. 2016.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef __THUNDERX_NICVF_MBOX__
34 #define __THUNDERX_NICVF_MBOX__
35
36 #include <stdint.h>
37
38 #include "nicvf_plat.h"
39 #include "../nicvf_struct.h"
40
41 /* PF <--> VF Mailbox communication
42  * Two 64bit registers are shared between PF and VF for each VF
43  * Writing into second register means end of message.
44  */
45
46 /* PF <--> VF mailbox communication */
47 #define NIC_PF_VF_MAILBOX_SIZE          2
48 #define NIC_MBOX_MSG_TIMEOUT            2000    /* ms */
49
50 /* Mailbox message types */
51 #define NIC_MBOX_MSG_INVALID            0x00    /* Invalid message */
52 #define NIC_MBOX_MSG_READY              0x01    /* Is PF ready to rcv msgs */
53 #define NIC_MBOX_MSG_ACK                0x02    /* ACK the message received */
54 #define NIC_MBOX_MSG_NACK               0x03    /* NACK the message received */
55 #define NIC_MBOX_MSG_QS_CFG             0x04    /* Configure Qset */
56 #define NIC_MBOX_MSG_RQ_CFG             0x05    /* Configure receive queue */
57 #define NIC_MBOX_MSG_SQ_CFG             0x06    /* Configure Send queue */
58 #define NIC_MBOX_MSG_RQ_DROP_CFG        0x07    /* Configure receive queue */
59 #define NIC_MBOX_MSG_SET_MAC            0x08    /* Add MAC ID to DMAC filter */
60 #define NIC_MBOX_MSG_SET_MAX_FRS        0x09    /* Set max frame size */
61 #define NIC_MBOX_MSG_CPI_CFG            0x0A    /* Config CPI, RSSI */
62 #define NIC_MBOX_MSG_RSS_SIZE           0x0B    /* Get RSS indir_tbl size */
63 #define NIC_MBOX_MSG_RSS_CFG            0x0C    /* Config RSS table */
64 #define NIC_MBOX_MSG_RSS_CFG_CONT       0x0D    /* RSS config continuation */
65 #define NIC_MBOX_MSG_RQ_BP_CFG          0x0E    /* RQ backpressure config */
66 #define NIC_MBOX_MSG_RQ_SW_SYNC         0x0F    /* Flush inflight pkts to RQ */
67 #define NIC_MBOX_MSG_BGX_LINK_CHANGE    0x11    /* BGX:LMAC link status */
68 #define NIC_MBOX_MSG_ALLOC_SQS          0x12    /* Allocate secondary Qset */
69 #define NIC_MBOX_MSG_LOOPBACK           0x16    /* Set interface in loopback */
70 #define NIC_MBOX_MSG_RESET_STAT_COUNTER 0x17    /* Reset statistics counters */
71 #define NIC_MBOX_MSG_CFG_DONE           0x7E    /* VF configuration done */
72 #define NIC_MBOX_MSG_SHUTDOWN           0x7F    /* VF is being shutdown */
73 #define NIC_MBOX_MSG_RES_BIT            0x80    /* Reset bit from PF */
74 #define NIC_MBOX_MSG_MAX                0x100   /* Maximum number of messages */
75
76 #define NIC_MBOX_MSG_RSS_SIZE_RES_BIT \
77         (NIC_MBOX_MSG_RSS_SIZE | NIC_MBOX_MSG_RES_BIT)
78 #define NIC_MBOX_MSG_ALLOC_SQS_RES_BIT \
79         (NIC_MBOX_MSG_ALLOC_SQS | NIC_MBOX_MSG_RES_BIT)
80
81 /* Get vNIC VF configuration */
82 struct nic_cfg_msg {
83         uint8_t    msg;
84         uint8_t    vf_id;
85         uint8_t    node_id;
86         bool       tns_mode:1;
87         bool       sqs_mode:1;
88         bool       loopback_supported:1;
89         uint8_t    mac_addr[NICVF_MAC_ADDR_SIZE];
90 };
91
92 /* Qset configuration */
93 struct qs_cfg_msg {
94         uint8_t    msg;
95         uint8_t    num;
96         uint8_t    sqs_count;
97         uint64_t   cfg;
98 };
99
100 /* Receive queue configuration */
101 struct rq_cfg_msg {
102         uint8_t    msg;
103         uint8_t    qs_num;
104         uint8_t    rq_num;
105         uint64_t   cfg;
106 };
107
108 /* Send queue configuration */
109 struct sq_cfg_msg {
110         uint8_t    msg;
111         uint8_t    qs_num;
112         uint8_t    sq_num;
113         bool       sqs_mode;
114         uint64_t   cfg;
115 };
116
117 /* Set VF's MAC address */
118 struct set_mac_msg {
119         uint8_t    msg;
120         uint8_t    vf_id;
121         uint8_t    mac_addr[NICVF_MAC_ADDR_SIZE];
122 };
123
124 /* Set Maximum frame size */
125 struct set_frs_msg {
126         uint8_t    msg;
127         uint8_t    vf_id;
128         uint16_t   max_frs;
129 };
130
131 /* Set CPI algorithm type */
132 struct cpi_cfg_msg {
133         uint8_t    msg;
134         uint8_t    vf_id;
135         uint8_t    rq_cnt;
136         uint8_t    cpi_alg;
137 };
138
139 /* Get RSS table size */
140 struct rss_sz_msg {
141         uint8_t    msg;
142         uint8_t    vf_id;
143         uint16_t   ind_tbl_size;
144 };
145
146 /* Set RSS configuration */
147 struct rss_cfg_msg {
148         uint8_t    msg;
149         uint8_t    vf_id;
150         uint8_t    hash_bits;
151         uint8_t    tbl_len;
152         uint8_t    tbl_offset;
153 #define RSS_IND_TBL_LEN_PER_MBX_MSG     8
154         uint8_t    ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG];
155 };
156
157 /* Physical interface link status */
158 struct bgx_link_status {
159         uint8_t    msg;
160         uint8_t    link_up;
161         uint8_t    duplex;
162         uint32_t   speed;
163 };
164
165 /* Allocate additional SQS to VF */
166 struct sqs_alloc {
167         uint8_t    msg;
168         uint8_t    spec;
169         uint8_t    qs_count;
170         uint8_t    svf[MAX_SQS_PER_VF];
171 };
172
173 /* Set interface in loopback mode */
174 struct set_loopback {
175         uint8_t    msg;
176         uint8_t    vf_id;
177         bool       enable;
178 };
179
180 /* Reset statistics counters */
181 struct reset_stat_cfg {
182         uint8_t    msg;
183         /* Bitmap to select NIC_PF_VNIC(vf_id)_RX_STAT(0..13) */
184         uint16_t   rx_stat_mask;
185         /* Bitmap to select NIC_PF_VNIC(vf_id)_TX_STAT(0..4) */
186         uint8_t    tx_stat_mask;
187         /* Bitmap to select NIC_PF_QS(0..127)_RQ(0..7)_STAT(0..1)
188          * bit14, bit15 NIC_PF_QS(vf_id)_RQ7_STAT(0..1)
189          * bit12, bit13 NIC_PF_QS(vf_id)_RQ6_STAT(0..1)
190          * ..
191          * bit2, bit3 NIC_PF_QS(vf_id)_RQ1_STAT(0..1)
192          * bit0, bit1 NIC_PF_QS(vf_id)_RQ0_STAT(0..1)
193          */
194         uint16_t   rq_stat_mask;
195         /* Bitmap to select NIC_PF_QS(0..127)_SQ(0..7)_STAT(0..1)
196          * bit14, bit15 NIC_PF_QS(vf_id)_SQ7_STAT(0..1)
197          * bit12, bit13 NIC_PF_QS(vf_id)_SQ6_STAT(0..1)
198          * ..
199          * bit2, bit3 NIC_PF_QS(vf_id)_SQ1_STAT(0..1)
200          * bit0, bit1 NIC_PF_QS(vf_id)_SQ0_STAT(0..1)
201          */
202         uint16_t   sq_stat_mask;
203 };
204
205 struct nic_mbx {
206 /* 128 bit shared memory between PF and each VF */
207 union {
208         struct { uint8_t msg; } msg;
209         struct nic_cfg_msg      nic_cfg;
210         struct qs_cfg_msg       qs;
211         struct rq_cfg_msg       rq;
212         struct sq_cfg_msg       sq;
213         struct set_mac_msg      mac;
214         struct set_frs_msg      frs;
215         struct cpi_cfg_msg      cpi_cfg;
216         struct rss_sz_msg       rss_size;
217         struct rss_cfg_msg      rss_cfg;
218         struct bgx_link_status  link_status;
219         struct sqs_alloc        sqs_alloc;
220         struct set_loopback     lbk;
221         struct reset_stat_cfg   reset_stat;
222 };
223 };
224
225 NICVF_STATIC_ASSERT(sizeof(struct nic_mbx) <= 16);
226
227 int nicvf_handle_mbx_intr(struct nicvf *nic);
228 int nicvf_mbox_check_pf_ready(struct nicvf *nic);
229 int nicvf_mbox_qset_config(struct nicvf *nic, struct pf_qs_cfg *qs_cfg);
230 int nicvf_mbox_request_sqs(struct nicvf *nic);
231 int nicvf_mbox_rq_config(struct nicvf *nic, uint16_t qidx,
232                          struct pf_rq_cfg *pf_rq_cfg);
233 int nicvf_mbox_sq_config(struct nicvf *nic, uint16_t qidx);
234 int nicvf_mbox_rq_drop_config(struct nicvf *nic, uint16_t qidx, bool enable);
235 int nicvf_mbox_rq_bp_config(struct nicvf *nic, uint16_t qidx, bool enable);
236 int nicvf_mbox_set_mac_addr(struct nicvf *nic,
237                             const uint8_t mac[NICVF_MAC_ADDR_SIZE]);
238 int nicvf_mbox_config_cpi(struct nicvf *nic, uint32_t qcnt);
239 int nicvf_mbox_get_rss_size(struct nicvf *nic);
240 int nicvf_mbox_config_rss(struct nicvf *nic);
241 int nicvf_mbox_update_hw_max_frs(struct nicvf *nic, uint16_t mtu);
242 int nicvf_mbox_rq_sync(struct nicvf *nic);
243 int nicvf_mbox_loopback_config(struct nicvf *nic, bool enable);
244 int nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask,
245         uint8_t tx_stat_mask, uint16_t rq_stat_mask, uint16_t sq_stat_mask);
246 void nicvf_mbox_shutdown(struct nicvf *nic);
247 void nicvf_mbox_cfg_done(struct nicvf *nic);
248
249 #endif /* __THUNDERX_NICVF_MBOX__ */