xref: /linux/drivers/net/ethernet/cisco/enic/enic_mbox.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2025 Cisco Systems, Inc.  All rights reserved. */
3 
4 #ifndef _ENIC_MBOX_H_
5 #define _ENIC_MBOX_H_
6 
7 #include <linux/bits.h>
8 #include <linux/types.h>
9 
10 /*
11  * Mailbox protocol for PF-VF communication over the admin channel.
12  *
13  * Even numbers are requests, odd numbers are replies/acks.
14  * The prefix indicates the initiator: VF_ = VF-initiated, PF_ = PF-initiated.
15  */
16 enum enic_mbox_msg_type {
17 	ENIC_MBOX_VF_CAPABILITY_REQUEST		= 0,
18 	ENIC_MBOX_VF_CAPABILITY_REPLY		= 1,
19 	ENIC_MBOX_VF_REGISTER_REQUEST		= 2,
20 	ENIC_MBOX_VF_REGISTER_REPLY		= 3,
21 	ENIC_MBOX_VF_UNREGISTER_REQUEST		= 4,
22 	ENIC_MBOX_VF_UNREGISTER_REPLY		= 5,
23 	ENIC_MBOX_PF_LINK_STATE_NOTIF		= 6,
24 	ENIC_MBOX_PF_LINK_STATE_ACK		= 7,
25 	ENIC_MBOX_MAX
26 };
27 
28 struct enic_mbox_hdr {
29 	__le16 src_vnic_id;
30 	__le16 dst_vnic_id;
31 	u8 msg_type;
32 	u8 flags;
33 	__le16 msg_len;
34 	__le64 msg_num;
35 };
36 
37 struct enic_mbox_generic_reply {
38 	__le16 ret_major;
39 	__le16 ret_minor;
40 };
41 
42 #define ENIC_MBOX_ERR_GENERIC		BIT(0)
43 #define ENIC_MBOX_ERR_VF_NOT_REGISTERED	BIT(1)
44 #define ENIC_MBOX_ERR_MSG_NOT_SUPPORTED	BIT(2)
45 
46 /* ENIC_MBOX_VF_CAPABILITY_REQUEST / _REPLY */
47 #define ENIC_MBOX_CAP_VERSION_0		0
48 #define ENIC_MBOX_CAP_VERSION_1		1
49 
50 struct enic_mbox_vf_capability_msg {
51 	__le32 version;
52 	__le32 reserved[32];
53 };
54 
55 /* The embedded enic_mbox_generic_reply has 2-byte alignment, but the
56  * __le32 members give this struct 4-byte natural alignment.  Receive
57  * buffers come from kmalloc (>= 8-byte aligned), so there is no
58  * misaligned access risk when casting from the receive buffer.
59  */
60 struct enic_mbox_vf_capability_reply_msg {
61 	struct enic_mbox_generic_reply reply;
62 	__le32 version;
63 	__le32 reserved[32];
64 };
65 
66 /* ENIC_MBOX_VF_REGISTER / _UNREGISTER */
67 struct enic_mbox_vf_register_reply_msg {
68 	struct enic_mbox_generic_reply reply;
69 };
70 
71 /* ENIC_MBOX_PF_LINK_STATE_NOTIF / _ACK */
72 #define ENIC_MBOX_LINK_STATE_DISABLE	0
73 #define ENIC_MBOX_LINK_STATE_ENABLE	1
74 
75 struct enic_mbox_pf_link_state_notif_msg {
76 	__le32 link_state;
77 };
78 
79 struct enic_mbox_pf_link_state_ack_msg {
80 	struct enic_mbox_generic_reply ack;
81 };
82 
83 #define ENIC_MBOX_DST_PF	0xFFFF
84 
85 struct enic;
86 
87 void enic_mbox_init(struct enic *enic);
88 int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
89 		       void *payload, u16 payload_len);
90 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state);
91 int enic_mbox_vf_capability_check(struct enic *enic);
92 int enic_mbox_vf_register(struct enic *enic);
93 int enic_mbox_vf_unregister(struct enic *enic);
94 
95 #endif /* _ENIC_MBOX_H_ */
96