1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Marvell Octeon EP (EndPoint) Ethernet Driver
4 * Copyright (C) 2020 Marvell.
7 #ifndef __OCTEP_CTRL_MBOX_H__
8 #define __OCTEP_CTRL_MBOX_H__
11 * |===========================================|
12 * |Info (16 + 120 + 120 = 256 bytes) |
13 * |-------------------------------------------|
14 * |magic number (8 bytes) |
15 * |bar memory size (4 bytes) |
16 * |reserved (4 bytes) |
17 * |-------------------------------------------|
18 * |host version (8 bytes) |
20 * |host status (8 bytes) |
21 * |host reserved (104 bytes) |
22 * |-------------------------------------------|
23 * |fw version's (8 bytes) |
24 * | min=high 32 bits, max=low 32 bits |
25 * |fw status (8 bytes) |
26 * |fw reserved (104 bytes) |
27 * |===========================================|
28 * |Host to Fw Queue info (16 bytes) |
29 * |-------------------------------------------|
30 * |producer index (4 bytes) |
31 * |consumer index (4 bytes) |
32 * |max element size (4 bytes) |
33 * |reserved (4 bytes) |
34 * |===========================================|
35 * |Fw to Host Queue info (16 bytes) |
36 * |-------------------------------------------|
37 * |producer index (4 bytes) |
38 * |consumer index (4 bytes) |
39 * |max element size (4 bytes) |
40 * |reserved (4 bytes) |
41 * |===========================================|
42 * |Host to Fw Queue ((total size-288/2) bytes)|
43 * |-------------------------------------------|
45 * |===========================================|
46 * |===========================================|
47 * |Fw to Host Queue ((total size-288/2) bytes)|
48 * |-------------------------------------------|
50 * |===========================================|
53 #define OCTEP_CTRL_MBOX_MAGIC_NUMBER 0xdeaddeadbeefbeefull
55 /* Valid request message */
56 #define OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ BIT(0)
57 /* Valid response message */
58 #define OCTEP_CTRL_MBOX_MSG_HDR_FLAG_RESP BIT(1)
59 /* Valid notification, no response required */
60 #define OCTEP_CTRL_MBOX_MSG_HDR_FLAG_NOTIFY BIT(2)
61 /* Valid custom message */
62 #define OCTEP_CTRL_MBOX_MSG_HDR_FLAG_CUSTOM BIT(3)
64 #define OCTEP_CTRL_MBOX_MSG_DESC_MAX 4
66 enum octep_ctrl_mbox_status {
67 OCTEP_CTRL_MBOX_STATUS_INVALID = 0,
68 OCTEP_CTRL_MBOX_STATUS_INIT,
69 OCTEP_CTRL_MBOX_STATUS_READY,
70 OCTEP_CTRL_MBOX_STATUS_UNINIT
74 union octep_ctrl_mbox_msg_hdr {
79 /* vf_idx is valid if 1 */
81 /* sender vf index 0-(n-1), 0 if (is_vf==0) */
83 /* total size of message excluding header */
85 /* OCTEP_CTRL_MBOX_MSG_HDR_FLAG_* */
87 /* identifier to match responses */
93 /* mbox message buffer */
94 struct octep_ctrl_mbox_msg_buf {
99 /* pointer to message buffer */
104 struct octep_ctrl_mbox_msg {
105 /* mbox transaction header */
106 union octep_ctrl_mbox_msg_hdr hdr;
107 /* number of sg buffer's */
109 /* message buffer's */
110 struct octep_ctrl_mbox_msg_buf sg_list[OCTEP_CTRL_MBOX_MSG_DESC_MAX];
114 struct octep_ctrl_mbox_q {
115 /* size of queue buffer */
117 /* producer address in bar mem */
119 /* consumer address in bar mem */
121 /* q base address in bar mem */
125 struct octep_ctrl_mbox {
126 /* control plane version */
128 /* size of bar memory */
130 /* pointer to BAR memory */
132 /* host-to-fw queue */
133 struct octep_ctrl_mbox_q h2fq;
134 /* fw-to-host queue */
135 struct octep_ctrl_mbox_q f2hq;
137 struct mutex h2fq_lock;
139 struct mutex f2hq_lock;
140 /* Min control plane version supported by firmware */
142 /* Max control plane version supported by firmware */
146 /* Initialize control mbox.
148 * @param mbox: non-null pointer to struct octep_ctrl_mbox.
150 * return value: 0 on success, -errno on failure.
152 int octep_ctrl_mbox_init(struct octep_ctrl_mbox *mbox);
154 /* Send mbox message.
156 * @param mbox: non-null pointer to struct octep_ctrl_mbox.
157 * @param msg: non-null pointer to struct octep_ctrl_mbox_msg.
158 * Caller should fill msg.sz and msg.desc.sz for each message.
160 * return value: 0 on success, -errno on failure.
162 int octep_ctrl_mbox_send(struct octep_ctrl_mbox *mbox, struct octep_ctrl_mbox_msg *msg);
164 /* Retrieve mbox message.
166 * @param mbox: non-null pointer to struct octep_ctrl_mbox.
167 * @param msg: non-null pointer to struct octep_ctrl_mbox_msg.
168 * Caller should fill msg.sz and msg.desc.sz for each message.
170 * return value: 0 on success, -errno on failure.
172 int octep_ctrl_mbox_recv(struct octep_ctrl_mbox *mbox, struct octep_ctrl_mbox_msg *msg);
174 /* Uninitialize control mbox.
176 * @param mbox: non-null pointer to struct octep_ctrl_mbox.
178 * return value: 0 on success, -errno on failure.
180 int octep_ctrl_mbox_uninit(struct octep_ctrl_mbox *mbox);
182 #endif /* __OCTEP_CTRL_MBOX_H__ */