xref: /freebsd/sys/dev/bnxt/bnxt_re/qplib_tlv.h (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
1 /*
2  * Copyright (c) 2017 - 2024, Broadcom. All rights reserved.  The term
3  * Broadcom refers to Broadcom Limited and/or its subsidiaries.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __QPLIB_TLV_H__
31 #define __QPLIB_TLV_H__
32 
33 struct roce_tlv {
34 	struct tlv tlv;
35 	u8 total_size;
36 	u8 unused[7];
37 };
38 
39 #define CHUNK_SIZE 16
40 #define CHUNKS(x) (((x) + CHUNK_SIZE - 1) / CHUNK_SIZE)
41 
42 #define ROCE_1ST_TLV_PREP(rtlv, tot_chunks, content_bytes, more)     \
43     do {                                                             \
44 	(rtlv)->tlv.cmd_discr = CMD_DISCR_TLV_ENCAP;                 \
45 	(rtlv)->tlv.tlv_type = TLV_TYPE_ROCE_SP_COMMAND;             \
46 	(rtlv)->tlv.length = (content_bytes);                        \
47 	(rtlv)->tlv.flags = TLV_FLAGS_REQUIRED;                      \
48 	(rtlv)->tlv.flags |= (more) ? TLV_FLAGS_MORE : 0;            \
49 	(rtlv)->total_size = (tot_chunks);                           \
50     } while (0)
51 
52 #define ROCE_EXT_TLV_PREP(rtlv, ext_type, content_bytes, more, reqd) \
53     do {                                                             \
54 	(rtlv)->tlv.cmd_discr = CMD_DISCR_TLV_ENCAP;                 \
55 	(rtlv)->tlv.tlv_type = (ext_type);                           \
56 	(rtlv)->tlv.length = (content_bytes);                        \
57 	(rtlv)->tlv.flags |= (more) ? TLV_FLAGS_MORE : 0;            \
58 	(rtlv)->tlv.flags |= (reqd) ? TLV_FLAGS_REQUIRED : 0;        \
59     } while (0)
60 
61 /*
62  * TLV size in units of 16 byte chunks
63  */
64 #define TLV_SIZE ((sizeof(struct roce_tlv) + 15) / 16)
65 /*
66  * TLV length in bytes
67  */
68 #define TLV_BYTES (TLV_SIZE * 16)
69 
70 #define HAS_TLV_HEADER(msg) (((struct tlv *)(msg))->cmd_discr == CMD_DISCR_TLV_ENCAP)
71 #define GET_TLV_DATA(tlv)   ((void *)&((uint8_t *)(tlv))[TLV_BYTES])
72 
73 static inline u8 __get_cmdq_base_opcode(struct cmdq_base *req, u32 size)
74 {
75 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
76 		return ((struct cmdq_base *)GET_TLV_DATA(req))->opcode;
77 	else
78 		return req->opcode;
79 }
80 
81 static inline void __set_cmdq_base_opcode(struct cmdq_base *req,
82 					  u32 size, u8 val)
83 {
84 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
85 		((struct cmdq_base *)GET_TLV_DATA(req))->opcode = val;
86 	else
87 		req->opcode = val;
88 }
89 
90 static inline __le16 __get_cmdq_base_cookie(struct cmdq_base *req, u32 size)
91 {
92 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
93 		return ((struct cmdq_base *)GET_TLV_DATA(req))->cookie;
94 	else
95 		return req->cookie;
96 }
97 
98 static inline void __set_cmdq_base_cookie(struct cmdq_base *req,
99 					  u32 size, __le16 val)
100 {
101 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
102 		((struct cmdq_base *)GET_TLV_DATA(req))->cookie = val;
103 	else
104 		req->cookie = val;
105 }
106 
107 static inline __le64 __get_cmdq_base_resp_addr(struct cmdq_base *req, u32 size)
108 {
109 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
110 		return ((struct cmdq_base *)GET_TLV_DATA(req))->resp_addr;
111 	else
112 		return req->resp_addr;
113 }
114 
115 static inline void __set_cmdq_base_resp_addr(struct cmdq_base *req,
116 					     u32 size, __le64 val)
117 {
118 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
119 		((struct cmdq_base *)GET_TLV_DATA(req))->resp_addr = val;
120 	else
121 		req->resp_addr = val;
122 }
123 
124 static inline u8 __get_cmdq_base_resp_size(struct cmdq_base *req, u32 size)
125 {
126 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
127 		return ((struct cmdq_base *)GET_TLV_DATA(req))->resp_size;
128 	else
129 		return req->resp_size;
130 }
131 
132 static inline void __set_cmdq_base_resp_size(struct cmdq_base *req,
133 					     u32 size, u8 val)
134 {
135 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
136 		((struct cmdq_base *)GET_TLV_DATA(req))->resp_size = val;
137 	else
138 		req->resp_size = val;
139 }
140 
141 static inline u8 __get_cmdq_base_cmd_size(struct cmdq_base *req, u32 size)
142 {
143 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
144 		return ((struct roce_tlv *)(req))->total_size;
145 	else
146 		return req->cmd_size;
147 }
148 
149 static inline void __set_cmdq_base_cmd_size(struct cmdq_base *req,
150 					    u32 size, u8 val)
151 {
152 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
153 		((struct cmdq_base *)GET_TLV_DATA(req))->cmd_size = val;
154 	else
155 		req->cmd_size = val;
156 }
157 
158 static inline __le16 __get_cmdq_base_flags(struct cmdq_base *req, u32 size)
159 {
160 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
161 		return ((struct cmdq_base *)GET_TLV_DATA(req))->flags;
162 	else
163 		return req->flags;
164 }
165 
166 static inline void __set_cmdq_base_flags(struct cmdq_base *req,
167 					 u32 size, __le16 val)
168 {
169 	if (HAS_TLV_HEADER(req) && size > TLV_BYTES)
170 		((struct cmdq_base *)GET_TLV_DATA(req))->flags = val;
171 	else
172 		req->flags = val;
173 }
174 
175 struct bnxt_qplib_tlv_modify_cc_req {
176 	struct roce_tlv				tlv_hdr;
177 	struct cmdq_modify_roce_cc		base_req;
178 	__le64					tlvpad;
179 	struct cmdq_modify_roce_cc_gen1_tlv	ext_req;
180 };
181 
182 struct bnxt_qplib_tlv_query_rcc_sb {
183 	struct roce_tlv					tlv_hdr;
184 	struct creq_query_roce_cc_resp_sb		base_sb;
185 	struct creq_query_roce_cc_gen1_resp_sb_tlv	gen1_sb;
186 };
187 #endif
188