New upstream version 17.11~rc4
[deb_dpdk.git] / drivers / net / liquidio / base / lio_mbox.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _LIO_MBOX_H_
35 #define _LIO_MBOX_H_
36
37 #include <stdint.h>
38
39 #include <rte_spinlock.h>
40
41 /* Macros for Mail Box Communication */
42
43 #define LIO_MBOX_DATA_MAX                       32
44
45 #define LIO_VF_ACTIVE                           0x1
46 #define LIO_VF_FLR_REQUEST                      0x2
47 #define LIO_CORES_CRASHED                       0x3
48
49 /* Macro for Read acknowledgment */
50 #define LIO_PFVFACK                             0xffffffffffffffff
51 #define LIO_PFVFSIG                             0x1122334455667788
52 #define LIO_PFVFERR                             0xDEADDEADDEADDEAD
53
54 enum lio_mbox_cmd_status {
55         LIO_MBOX_STATUS_SUCCESS         = 0,
56         LIO_MBOX_STATUS_FAILED          = 1,
57         LIO_MBOX_STATUS_BUSY            = 2
58 };
59
60 enum lio_mbox_message_type {
61         LIO_MBOX_REQUEST        = 0,
62         LIO_MBOX_RESPONSE       = 1
63 };
64
65 union lio_mbox_message {
66         uint64_t mbox_msg64;
67         struct {
68                 uint16_t type : 1;
69                 uint16_t resp_needed : 1;
70                 uint16_t cmd : 6;
71                 uint16_t len : 8;
72                 uint8_t params[6];
73         } s;
74 };
75
76 typedef void (*lio_mbox_callback)(void *, void *, void *);
77
78 struct lio_mbox_cmd {
79         union lio_mbox_message msg;
80         uint64_t data[LIO_MBOX_DATA_MAX];
81         uint32_t q_no;
82         uint32_t recv_len;
83         uint32_t recv_status;
84         lio_mbox_callback fn;
85         void *fn_arg;
86 };
87
88 enum lio_mbox_state {
89         LIO_MBOX_STATE_IDLE             = 1,
90         LIO_MBOX_STATE_REQ_RECEIVING    = 2,
91         LIO_MBOX_STATE_REQ_RECEIVED     = 4,
92         LIO_MBOX_STATE_RES_PENDING      = 8,
93         LIO_MBOX_STATE_RES_RECEIVING    = 16,
94         LIO_MBOX_STATE_RES_RECEIVED     = 16,
95         LIO_MBOX_STATE_ERROR            = 32
96 };
97
98 struct lio_mbox {
99         /* A spinlock to protect access to this q_mbox. */
100         rte_spinlock_t lock;
101
102         struct lio_device *lio_dev;
103
104         uint32_t q_no;
105
106         enum lio_mbox_state state;
107
108         /* SLI_MAC_PF_MBOX_INT for PF, SLI_PKT_MBOX_INT for VF. */
109         void *mbox_int_reg;
110
111         /* SLI_PKT_PF_VF_MBOX_SIG(0) for PF,
112          * SLI_PKT_PF_VF_MBOX_SIG(1) for VF.
113          */
114         void *mbox_write_reg;
115
116         /* SLI_PKT_PF_VF_MBOX_SIG(1) for PF,
117          * SLI_PKT_PF_VF_MBOX_SIG(0) for VF.
118          */
119         void *mbox_read_reg;
120
121         struct lio_mbox_cmd mbox_req;
122
123         struct lio_mbox_cmd mbox_resp;
124
125 };
126
127 int lio_mbox_read(struct lio_mbox *mbox);
128 int lio_mbox_write(struct lio_device *lio_dev,
129                    struct lio_mbox_cmd *mbox_cmd);
130 int lio_mbox_process_message(struct lio_mbox *mbox);
131 #endif  /* _LIO_MBOX_H_ */