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