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