blob: 6d22db63d048a4d9a3df4986c82ca61405ddedcd [file] [log] [blame]
Alexander Duyckae17db0ee2014-09-20 19:46:30 -04001/* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 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#include "fm10k_type.h"
25
26/* Message / Argument header format
27 * 3 2 1 0
28 * 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
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 * | Length | Flags | Type / ID |
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 *
33 * The message header format described here is used for messages that are
34 * passed between the PF and the VF. To allow for messages larger then
35 * mailbox size we will provide a message with the above header and it
36 * will be segmented and transported to the mailbox to the other side where
37 * it is reassembled. It contains the following fields:
38 * Len: Length of the message in bytes excluding the message header
39 * Flags: TBD
40 * Rule: These will be the message/argument types we pass
41 */
42/* message data header */
43#define FM10K_TLV_ID_SHIFT 0
44#define FM10K_TLV_ID_SIZE 16
45#define FM10K_TLV_ID_MASK ((1u << FM10K_TLV_ID_SIZE) - 1)
46#define FM10K_TLV_FLAGS_SHIFT 16
47#define FM10K_TLV_FLAGS_MSG 0x1
48#define FM10K_TLV_FLAGS_SIZE 4
49#define FM10K_TLV_LEN_SHIFT 20
50#define FM10K_TLV_LEN_SIZE 12
51
52#define FM10K_TLV_HDR_LEN 4ul
53#define FM10K_TLV_LEN_ALIGN_MASK \
54 ((FM10K_TLV_HDR_LEN - 1) << FM10K_TLV_LEN_SHIFT)
55#define FM10K_TLV_LEN_ALIGN(tlv) \
56 (((tlv) + FM10K_TLV_LEN_ALIGN_MASK) & ~FM10K_TLV_LEN_ALIGN_MASK)
57#define FM10K_TLV_DWORD_LEN(tlv) \
58 ((u16)((FM10K_TLV_LEN_ALIGN(tlv)) >> (FM10K_TLV_LEN_SHIFT + 2)) + 1)
59
60#define FM10K_TLV_RESULTS_MAX 32
61
62enum fm10k_tlv_type {
63 FM10K_TLV_NULL_STRING,
64 FM10K_TLV_MAC_ADDR,
65 FM10K_TLV_BOOL,
66 FM10K_TLV_UNSIGNED,
67 FM10K_TLV_SIGNED,
68 FM10K_TLV_LE_STRUCT,
69 FM10K_TLV_NESTED,
70 FM10K_TLV_MAX_TYPE
71};
72
73#define FM10K_TLV_ERROR (~0u)
74
75struct fm10k_tlv_attr {
76 unsigned int id;
77 enum fm10k_tlv_type type;
78 u16 len;
79};
80
81#define FM10K_TLV_ATTR_NULL_STRING(id, len) { id, FM10K_TLV_NULL_STRING, len }
82#define FM10K_TLV_ATTR_MAC_ADDR(id) { id, FM10K_TLV_MAC_ADDR, 6 }
83#define FM10K_TLV_ATTR_BOOL(id) { id, FM10K_TLV_BOOL, 0 }
84#define FM10K_TLV_ATTR_U8(id) { id, FM10K_TLV_UNSIGNED, 1 }
85#define FM10K_TLV_ATTR_U16(id) { id, FM10K_TLV_UNSIGNED, 2 }
86#define FM10K_TLV_ATTR_U32(id) { id, FM10K_TLV_UNSIGNED, 4 }
87#define FM10K_TLV_ATTR_U64(id) { id, FM10K_TLV_UNSIGNED, 8 }
88#define FM10K_TLV_ATTR_S8(id) { id, FM10K_TLV_SIGNED, 1 }
89#define FM10K_TLV_ATTR_S16(id) { id, FM10K_TLV_SIGNED, 2 }
90#define FM10K_TLV_ATTR_S32(id) { id, FM10K_TLV_SIGNED, 4 }
91#define FM10K_TLV_ATTR_S64(id) { id, FM10K_TLV_SIGNED, 8 }
92#define FM10K_TLV_ATTR_LE_STRUCT(id, len) { id, FM10K_TLV_LE_STRUCT, len }
93#define FM10K_TLV_ATTR_NESTED(id) { id, FM10K_TLV_NESTED }
94#define FM10K_TLV_ATTR_LAST { FM10K_TLV_ERROR }
95
96s32 fm10k_tlv_msg_init(u32 *, u16);
97s32 fm10k_tlv_attr_put_null_string(u32 *, u16, const unsigned char *);
98s32 fm10k_tlv_attr_get_null_string(u32 *, unsigned char *);
99s32 fm10k_tlv_attr_put_mac_vlan(u32 *, u16, const u8 *, u16);
100s32 fm10k_tlv_attr_get_mac_vlan(u32 *, u8 *, u16 *);
101s32 fm10k_tlv_attr_put_bool(u32 *, u16);
102s32 fm10k_tlv_attr_put_value(u32 *, u16, s64, u32);
103#define fm10k_tlv_attr_put_u8(msg, attr_id, val) \
104 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
105#define fm10k_tlv_attr_put_u16(msg, attr_id, val) \
106 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
107#define fm10k_tlv_attr_put_u32(msg, attr_id, val) \
108 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
109#define fm10k_tlv_attr_put_u64(msg, attr_id, val) \
110 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
111#define fm10k_tlv_attr_put_s8(msg, attr_id, val) \
112 fm10k_tlv_attr_put_value(msg, attr_id, val, 1)
113#define fm10k_tlv_attr_put_s16(msg, attr_id, val) \
114 fm10k_tlv_attr_put_value(msg, attr_id, val, 2)
115#define fm10k_tlv_attr_put_s32(msg, attr_id, val) \
116 fm10k_tlv_attr_put_value(msg, attr_id, val, 4)
117#define fm10k_tlv_attr_put_s64(msg, attr_id, val) \
118 fm10k_tlv_attr_put_value(msg, attr_id, val, 8)
119s32 fm10k_tlv_attr_get_value(u32 *, void *, u32);
120#define fm10k_tlv_attr_get_u8(attr, ptr) \
121 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u8))
122#define fm10k_tlv_attr_get_u16(attr, ptr) \
123 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u16))
124#define fm10k_tlv_attr_get_u32(attr, ptr) \
125 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u32))
126#define fm10k_tlv_attr_get_u64(attr, ptr) \
127 fm10k_tlv_attr_get_value(attr, ptr, sizeof(u64))
128#define fm10k_tlv_attr_get_s8(attr, ptr) \
129 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s8))
130#define fm10k_tlv_attr_get_s16(attr, ptr) \
131 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s16))
132#define fm10k_tlv_attr_get_s32(attr, ptr) \
133 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s32))
134#define fm10k_tlv_attr_get_s64(attr, ptr) \
135 fm10k_tlv_attr_get_value(attr, ptr, sizeof(s64))
136s32 fm10k_tlv_attr_put_le_struct(u32 *, u16, const void *, u32);
137s32 fm10k_tlv_attr_get_le_struct(u32 *, void *, u32);
138u32 *fm10k_tlv_attr_nest_start(u32 *, u16);
139s32 fm10k_tlv_attr_nest_stop(u32 *);
140s32 fm10k_tlv_attr_parse(u32 *, u32 **, const struct fm10k_tlv_attr *);
141#endif /* _FM10K_MSG_H_ */