1 /* Intel(R) Ethernet Switch Host Interface Driver
2  * Copyright(c) 2013 - 2016 Intel Corporation.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * The full GNU General Public License is included in this distribution in
14  * the file called "COPYING".
15  *
16  * Contact Information:
17  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19  */
20 
21 #ifndef _FM10K_TLV_H_
22 #define _FM10K_TLV_H_
23 
24 /* forward declaration */
25 struct fm10k_msg_data;
26 
27 #include "fm10k_type.h"
28 
29 /* Message / Argument header format
30  *    3			  2		      1			  0
31  *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
32  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33  * |	     Length	   | Flags |	      Type / ID		   |
34  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35  *
36  * The message header format described here is used for messages that are
37  * passed between the PF and the VF.  To allow for messages larger then
38  * mailbox size we will provide a message with the above header and it
39  * will be segmented and transported to the mailbox to the other side where
40  * it is reassembled.  It contains the following fields:
41  * Length: Length of the message in bytes excluding the message header
42  * Flags: TBD
43  * Type/ID: These will be the message/argument types we pass
44  */
45 /* message data header */
46 #define FM10K_TLV_ID_SHIFT		0
47 #define FM10K_TLV_ID_SIZE		16
48 #define FM10K_TLV_ID_MASK		((1u << FM10K_TLV_ID_SIZE) - 1)
49 #define FM10K_TLV_FLAGS_SHIFT		16
50 #define FM10K_TLV_FLAGS_MSG		0x1
51 #define FM10K_TLV_FLAGS_SIZE		4
52 #define FM10K_TLV_LEN_SHIFT		20
53 #define FM10K_TLV_LEN_SIZE		12
54 
55 #define FM10K_TLV_HDR_LEN		4ul
56 #define FM10K_TLV_LEN_ALIGN_MASK \
57 	((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT)
58 #define FM10K_TLV_LEN_ALIGN(tlv) \
59 	(((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK)
60 #define FM10K_TLV_DWORD_LEN(tlv) \
61 	((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1)
62 
63 #define FM10K_TLV_RESULTS_MAX		32
64 
65 enum fm10k_tlv_type {
66 	FM10K_TLV_NULL_STRING,
67 	FM10K_TLV_MAC_ADDR,
68 	FM10K_TLV_BOOL,
69 	FM10K_TLV_UNSIGNED,
70 	FM10K_TLV_SIGNED,
71 	FM10K_TLV_LE_STRUCT,
72 	FM10K_TLV_NESTED,
73 	FM10K_TLV_MAX_TYPE
74 };
75 
76 #define FM10K_TLV_ERROR (~0u)
77 
78 struct fm10k_tlv_attr {
79 	unsigned int		id;
80 	enum fm10k_tlv_type	type;
81 	u16			len;
82 };
83 
84 #define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len }
85 #define FM10K_TLV_ATTR_MAC_ADDR(id)	    { id, FM10K_TLV_MAC_ADDR, 6 }
86 #define FM10K_TLV_ATTR_BOOL(id)		    { id, FM10K_TLV_BOOL, 0 }
87 #define FM10K_TLV_ATTR_U8(id)		    { id, FM10K_TLV_UNSIGNED, 1 }
88 #define FM10K_TLV_ATTR_U16(id)		    { id, FM10K_TLV_UNSIGNED, 2 }
89 #define FM10K_TLV_ATTR_U32(id)		    { id, FM10K_TLV_UNSIGNED, 4 }
90 #define FM10K_TLV_ATTR_U64(id)		    { id, FM10K_TLV_UNSIGNED, 8 }
91 #define FM10K_TLV_ATTR_S8(id)		    { id, FM10K_TLV_SIGNED, 1 }
92 #define FM10K_TLV_ATTR_S16(id)		    { id, FM10K_TLV_SIGNED, 2 }
93 #define FM10K_TLV_ATTR_S32(id)		    { id, FM10K_TLV_SIGNED, 4 }
94 #define FM10K_TLV_ATTR_S64(id)		    { id, FM10K_TLV_SIGNED, 8 }
95 #define FM10K_TLV_ATTR_LE_STRUCT(id, len)   { id, FM10K_TLV_LE_STRUCT, len }
96 #define FM10K_TLV_ATTR_NESTED(id)	    { id, FM10K_TLV_NESTED }
97 #define FM10K_TLV_ATTR_LAST		    { FM10K_TLV_ERROR }
98 
99 struct fm10k_msg_data {
100 	unsigned int		    id;
101 	const struct fm10k_tlv_attr *attr;
102 	s32			    (*func)(struct fm10k_hw *, u32 **,
103 					    struct fm10k_mbx_info *);
104 };
105 
106 #define FM10K_MSG_HANDLER(id, attr, func) { id, attr, func }
107 
108 s32 fm10k_tlv_msg_init(u32 *, u16);
109 s32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16);
110 s32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *);
111 s32 fm10k_tlv_attr_put_bool(u32 *, u16);
112 s32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32);
113 #define fm10k_tlv_attr_put_u8(msg, attr_id, val) \
114 		fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
115 #define fm10k_tlv_attr_put_u16(msg, attr_id, val) \
116 		fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
117 #define fm10k_tlv_attr_put_u32(msg, attr_id, val) \
118 		fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
119 #define fm10k_tlv_attr_put_u64(msg, attr_id, val) \
120 		fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
121 #define fm10k_tlv_attr_put_s8(msg, attr_id, val) \
122 		fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
123 #define fm10k_tlv_attr_put_s16(msg, attr_id, val) \
124 		fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
125 #define fm10k_tlv_attr_put_s32(msg, attr_id, val) \
126 		fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
127 #define fm10k_tlv_attr_put_s64(msg, attr_id, val) \
128 		fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
129 s32 fm10k_tlv_attr_get_value(u32 *, void *, u32);
130 #define fm10k_tlv_attr_get_u8(attr, ptr) \
131 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8))
132 #define fm10k_tlv_attr_get_u16(attr, ptr) \
133 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16))
134 #define fm10k_tlv_attr_get_u32(attr, ptr) \
135 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32))
136 #define fm10k_tlv_attr_get_u64(attr, ptr) \
137 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64))
138 #define fm10k_tlv_attr_get_s8(attr, ptr) \
139 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8))
140 #define fm10k_tlv_attr_get_s16(attr, ptr) \
141 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16))
142 #define fm10k_tlv_attr_get_s32(attr, ptr) \
143 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32))
144 #define fm10k_tlv_attr_get_s64(attr, ptr) \
145 		fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64))
146 s32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32);
147 s32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32);
148 s32 fm10k_tlv_msg_parse(struct fm10k_hw *, u32 *, struct fm10k_mbx_info *,
149 			const struct fm10k_msg_data *);
150 s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
151 			struct fm10k_mbx_info *);
152 
153 #define FM10K_TLV_MSG_ID_TEST	0
154 
155 enum fm10k_tlv_test_attr_id {
156 	FM10K_TEST_MSG_UNSET,
157 	FM10K_TEST_MSG_STRING,
158 	FM10K_TEST_MSG_MAC_ADDR,
159 	FM10K_TEST_MSG_U8,
160 	FM10K_TEST_MSG_U16,
161 	FM10K_TEST_MSG_U32,
162 	FM10K_TEST_MSG_U64,
163 	FM10K_TEST_MSG_S8,
164 	FM10K_TEST_MSG_S16,
165 	FM10K_TEST_MSG_S32,
166 	FM10K_TEST_MSG_S64,
167 	FM10K_TEST_MSG_LE_STRUCT,
168 	FM10K_TEST_MSG_NESTED,
169 	FM10K_TEST_MSG_RESULT,
170 	FM10K_TEST_MSG_MAX
171 };
172 
173 extern const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[];
174 void fm10k_tlv_msg_test_create(u32 *, u32);
175 s32 fm10k_tlv_msg_test(struct fm10k_hw *, u32 **, struct fm10k_mbx_info *);
176 
177 #define FM10K_TLV_MSG_TEST_HANDLER(func) \
178 	FM10K_MSG_HANDLER(FM10K_TLV_MSG_ID_TEST, fm10k_tlv_msg_test_attr, func)
179 #define FM10K_TLV_MSG_ERROR_HANDLER(func) \
180 	FM10K_MSG_HANDLER(FM10K_TLV_ERROR, NULL, func)
181 #endif /* _FM10K_MSG_H_ */
182