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