New upstream version 17.11-rc3
[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_CORES_CRASHED                       0x3
47
48 /* Macro for Read acknowledgment */
49 #define LIO_PFVFACK                             0xffffffffffffffff
50 #define LIO_PFVFSIG                             0x1122334455667788
51 #define LIO_PFVFERR                             0xDEADDEADDEADDEAD
52
53 enum lio_mbox_cmd_status {
54         LIO_MBOX_STATUS_SUCCESS         = 0,
55         LIO_MBOX_STATUS_FAILED          = 1,
56         LIO_MBOX_STATUS_BUSY            = 2
57 };
58
59 enum lio_mbox_message_type {
60         LIO_MBOX_REQUEST        = 0,
61         LIO_MBOX_RESPONSE       = 1
62 };
63
64 union lio_mbox_message {
65         uint64_t mbox_msg64;
66         struct {
67                 uint16_t type : 1;
68                 uint16_t resp_needed : 1;
69                 uint16_t cmd : 6;
70                 uint16_t len : 8;
71                 uint8_t params[6];
72         } s;
73 };
74
75 typedef void (*lio_mbox_callback)(void *, void *, void *);
76
77 struct lio_mbox_cmd {
78         union lio_mbox_message msg;
79         uint64_t data[LIO_MBOX_DATA_MAX];
80         uint32_t q_no;
81         uint32_t recv_len;
82         uint32_t recv_status;
83         lio_mbox_callback fn;
84         void *fn_arg;
85 };
86
87 enum lio_mbox_state {
88         LIO_MBOX_STATE_IDLE             = 1,
89         LIO_MBOX_STATE_REQ_RECEIVING    = 2,
90         LIO_MBOX_STATE_REQ_RECEIVED     = 4,
91         LIO_MBOX_STATE_RES_PENDING      = 8,
92         LIO_MBOX_STATE_RES_RECEIVING    = 16,
93         LIO_MBOX_STATE_RES_RECEIVED     = 16,
94         LIO_MBOX_STATE_ERROR            = 32
95 };
96
97 struct lio_mbox {
98         /* A spinlock to protect access to this q_mbox. */
99         rte_spinlock_t lock;
100
101         struct lio_device *lio_dev;
102
103         uint32_t q_no;
104
105         enum lio_mbox_state state;
106
107         /* SLI_MAC_PF_MBOX_INT for PF, SLI_PKT_MBOX_INT for VF. */
108         void *mbox_int_reg;
109
110         /* SLI_PKT_PF_VF_MBOX_SIG(0) for PF,
111          * SLI_PKT_PF_VF_MBOX_SIG(1) for VF.
112          */
113         void *mbox_write_reg;
114
115         /* SLI_PKT_PF_VF_MBOX_SIG(1) for PF,
116          * SLI_PKT_PF_VF_MBOX_SIG(0) for VF.
117          */
118         void *mbox_read_reg;
119
120         struct lio_mbox_cmd mbox_req;
121
122         struct lio_mbox_cmd mbox_resp;
123
124 };
125
126 int lio_mbox_read(struct lio_mbox *mbox);
127 int lio_mbox_write(struct lio_device *lio_dev,
128                    struct lio_mbox_cmd *mbox_cmd);
129 int lio_mbox_process_message(struct lio_mbox *mbox);
130 #endif  /* _LIO_MBOX_H_ */