GNU Linux-libre 5.19-rc6-gnu
[releases.git] / drivers / net / ethernet / fungible / funcore / fun_hci.h
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2
3 #ifndef __FUN_HCI_H
4 #define __FUN_HCI_H
5
6 enum {
7         FUN_HCI_ID_INVALID = 0xffffffff,
8 };
9
10 enum fun_admin_op {
11         FUN_ADMIN_OP_BIND = 0x1,
12         FUN_ADMIN_OP_EPCQ = 0x11,
13         FUN_ADMIN_OP_EPSQ = 0x12,
14         FUN_ADMIN_OP_PORT = 0x13,
15         FUN_ADMIN_OP_ETH = 0x14,
16         FUN_ADMIN_OP_VI = 0x15,
17         FUN_ADMIN_OP_SWUPGRADE = 0x1f,
18         FUN_ADMIN_OP_RSS = 0x21,
19         FUN_ADMIN_OP_ADI = 0x25,
20         FUN_ADMIN_OP_KTLS = 0x26,
21 };
22
23 enum {
24         FUN_REQ_COMMON_FLAG_RSP = 0x1,
25         FUN_REQ_COMMON_FLAG_HEAD_WB = 0x2,
26         FUN_REQ_COMMON_FLAG_INT = 0x4,
27         FUN_REQ_COMMON_FLAG_CQE_IN_RQBUF = 0x8,
28 };
29
30 struct fun_admin_req_common {
31         __u8 op;
32         __u8 len8;
33         __be16 flags;
34         __u8 suboff8;
35         __u8 rsvd0;
36         __be16 cid;
37 };
38
39 #define FUN_ADMIN_REQ_COMMON_INIT(_op, _len8, _flags, _suboff8, _cid)       \
40         (struct fun_admin_req_common) {                                     \
41                 .op = (_op), .len8 = (_len8), .flags = cpu_to_be16(_flags), \
42                 .suboff8 = (_suboff8), .cid = cpu_to_be16(_cid),            \
43         }
44
45 #define FUN_ADMIN_REQ_COMMON_INIT2(_op, _len)    \
46         (struct fun_admin_req_common) {          \
47                 .op = (_op), .len8 = (_len) / 8, \
48         }
49
50 struct fun_admin_rsp_common {
51         __u8 op;
52         __u8 len8;
53         __be16 flags;
54         __u8 suboff8;
55         __u8 ret;
56         __be16 cid;
57 };
58
59 struct fun_admin_write48_req {
60         __be64 key_to_data;
61 };
62
63 #define FUN_ADMIN_WRITE48_REQ_KEY_S 56U
64 #define FUN_ADMIN_WRITE48_REQ_KEY_M 0xff
65 #define FUN_ADMIN_WRITE48_REQ_KEY_P_NOSWAP(x) \
66         (((__u64)x) << FUN_ADMIN_WRITE48_REQ_KEY_S)
67
68 #define FUN_ADMIN_WRITE48_REQ_DATA_S 0U
69 #define FUN_ADMIN_WRITE48_REQ_DATA_M 0xffffffffffff
70 #define FUN_ADMIN_WRITE48_REQ_DATA_P_NOSWAP(x) \
71         (((__u64)x) << FUN_ADMIN_WRITE48_REQ_DATA_S)
72
73 #define FUN_ADMIN_WRITE48_REQ_INIT(key, data)                       \
74         (struct fun_admin_write48_req) {                            \
75                 .key_to_data = cpu_to_be64(                         \
76                         FUN_ADMIN_WRITE48_REQ_KEY_P_NOSWAP(key) |   \
77                         FUN_ADMIN_WRITE48_REQ_DATA_P_NOSWAP(data)), \
78         }
79
80 struct fun_admin_write48_rsp {
81         __be64 key_to_data;
82 };
83
84 struct fun_admin_read48_req {
85         __be64 key_pack;
86 };
87
88 #define FUN_ADMIN_READ48_REQ_KEY_S 56U
89 #define FUN_ADMIN_READ48_REQ_KEY_M 0xff
90 #define FUN_ADMIN_READ48_REQ_KEY_P_NOSWAP(x) \
91         (((__u64)x) << FUN_ADMIN_READ48_REQ_KEY_S)
92
93 #define FUN_ADMIN_READ48_REQ_INIT(key)                                       \
94         (struct fun_admin_read48_req) {                                      \
95                 .key_pack =                                                  \
96                         cpu_to_be64(FUN_ADMIN_READ48_REQ_KEY_P_NOSWAP(key)), \
97         }
98
99 struct fun_admin_read48_rsp {
100         __be64 key_to_data;
101 };
102
103 #define FUN_ADMIN_READ48_RSP_KEY_S 56U
104 #define FUN_ADMIN_READ48_RSP_KEY_M 0xff
105 #define FUN_ADMIN_READ48_RSP_KEY_G(x)                     \
106         ((be64_to_cpu(x) >> FUN_ADMIN_READ48_RSP_KEY_S) & \
107          FUN_ADMIN_READ48_RSP_KEY_M)
108
109 #define FUN_ADMIN_READ48_RSP_RET_S 48U
110 #define FUN_ADMIN_READ48_RSP_RET_M 0xff
111 #define FUN_ADMIN_READ48_RSP_RET_G(x)                     \
112         ((be64_to_cpu(x) >> FUN_ADMIN_READ48_RSP_RET_S) & \
113          FUN_ADMIN_READ48_RSP_RET_M)
114
115 #define FUN_ADMIN_READ48_RSP_DATA_S 0U
116 #define FUN_ADMIN_READ48_RSP_DATA_M 0xffffffffffff
117 #define FUN_ADMIN_READ48_RSP_DATA_G(x)                     \
118         ((be64_to_cpu(x) >> FUN_ADMIN_READ48_RSP_DATA_S) & \
119          FUN_ADMIN_READ48_RSP_DATA_M)
120
121 enum fun_admin_bind_type {
122         FUN_ADMIN_BIND_TYPE_EPCQ = 0x1,
123         FUN_ADMIN_BIND_TYPE_EPSQ = 0x2,
124         FUN_ADMIN_BIND_TYPE_PORT = 0x3,
125         FUN_ADMIN_BIND_TYPE_RSS = 0x4,
126         FUN_ADMIN_BIND_TYPE_VI = 0x5,
127         FUN_ADMIN_BIND_TYPE_ETH = 0x6,
128 };
129
130 struct fun_admin_bind_entry {
131         __u8 type;
132         __u8 rsvd0[3];
133         __be32 id;
134 };
135
136 #define FUN_ADMIN_BIND_ENTRY_INIT(_type, _id)            \
137         (struct fun_admin_bind_entry) {                  \
138                 .type = (_type), .id = cpu_to_be32(_id), \
139         }
140
141 struct fun_admin_bind_req {
142         struct fun_admin_req_common common;
143         struct fun_admin_bind_entry entry[];
144 };
145
146 struct fun_admin_bind_rsp {
147         struct fun_admin_rsp_common bind_rsp_common;
148 };
149
150 struct fun_admin_simple_subop {
151         __u8 subop;
152         __u8 rsvd0;
153         __be16 flags;
154         __be32 data;
155 };
156
157 #define FUN_ADMIN_SIMPLE_SUBOP_INIT(_subop, _flags, _data)       \
158         (struct fun_admin_simple_subop) {                        \
159                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
160                 .data = cpu_to_be32(_data),                      \
161         }
162
163 enum fun_admin_subop {
164         FUN_ADMIN_SUBOP_CREATE = 0x10,
165         FUN_ADMIN_SUBOP_DESTROY = 0x11,
166         FUN_ADMIN_SUBOP_MODIFY = 0x12,
167         FUN_ADMIN_SUBOP_RES_COUNT = 0x14,
168         FUN_ADMIN_SUBOP_READ = 0x15,
169         FUN_ADMIN_SUBOP_WRITE = 0x16,
170         FUN_ADMIN_SUBOP_NOTIFY = 0x17,
171 };
172
173 enum {
174         FUN_ADMIN_RES_CREATE_FLAG_ALLOCATOR = 0x1,
175 };
176
177 struct fun_admin_generic_destroy_req {
178         struct fun_admin_req_common common;
179         struct fun_admin_simple_subop destroy;
180 };
181
182 struct fun_admin_generic_create_rsp {
183         struct fun_admin_rsp_common common;
184
185         __u8 subop;
186         __u8 rsvd0;
187         __be16 flags;
188         __be32 id;
189 };
190
191 struct fun_admin_res_count_req {
192         struct fun_admin_req_common common;
193         struct fun_admin_simple_subop count;
194 };
195
196 struct fun_admin_res_count_rsp {
197         struct fun_admin_rsp_common common;
198         struct fun_admin_simple_subop count;
199 };
200
201 enum {
202         FUN_ADMIN_EPCQ_CREATE_FLAG_INT_EPCQ = 0x2,
203         FUN_ADMIN_EPCQ_CREATE_FLAG_ENTRY_WR_TPH = 0x4,
204         FUN_ADMIN_EPCQ_CREATE_FLAG_SL_WR_TPH = 0x8,
205         FUN_ADMIN_EPCQ_CREATE_FLAG_RQ = 0x80,
206         FUN_ADMIN_EPCQ_CREATE_FLAG_INT_IQ = 0x100,
207         FUN_ADMIN_EPCQ_CREATE_FLAG_INT_NOARM = 0x200,
208         FUN_ADMIN_EPCQ_CREATE_FLAG_DROP_ON_OVERFLOW = 0x400,
209 };
210
211 struct fun_admin_epcq_req {
212         struct fun_admin_req_common common;
213         union epcq_req_subop {
214                 struct fun_admin_epcq_create_req {
215                         __u8 subop;
216                         __u8 rsvd0;
217                         __be16 flags;
218                         __be32 id;
219
220                         __be32 epsqid;
221                         __u8 rsvd1;
222                         __u8 entry_size_log2;
223                         __be16 nentries;
224
225                         __be64 address;
226
227                         __be16 tailroom; /* per packet tailroom in bytes */
228                         __u8 headroom; /* per packet headroom in 2B units */
229                         __u8 intcoal_kbytes;
230                         __u8 intcoal_holdoff_nentries;
231                         __u8 intcoal_holdoff_usecs;
232                         __be16 intid;
233
234                         __be32 scan_start_id;
235                         __be32 scan_end_id;
236
237                         __be16 tph_cpuid;
238                         __u8 rsvd3[6];
239                 } create;
240
241                 struct fun_admin_epcq_modify_req {
242                         __u8 subop;
243                         __u8 rsvd0;
244                         __be16 flags;
245                         __be32 id;
246
247                         __be16 headroom; /* headroom in bytes */
248                         __u8 rsvd1[6];
249                 } modify;
250         } u;
251 };
252
253 #define FUN_ADMIN_EPCQ_CREATE_REQ_INIT(                                      \
254         _subop, _flags, _id, _epsqid, _entry_size_log2, _nentries, _address, \
255         _tailroom, _headroom, _intcoal_kbytes, _intcoal_holdoff_nentries,    \
256         _intcoal_holdoff_usecs, _intid, _scan_start_id, _scan_end_id,        \
257         _tph_cpuid)                                                          \
258         (struct fun_admin_epcq_create_req) {                                 \
259                 .subop = (_subop), .flags = cpu_to_be16(_flags),             \
260                 .id = cpu_to_be32(_id), .epsqid = cpu_to_be32(_epsqid),      \
261                 .entry_size_log2 = _entry_size_log2,                         \
262                 .nentries = cpu_to_be16(_nentries),                          \
263                 .address = cpu_to_be64(_address),                            \
264                 .tailroom = cpu_to_be16(_tailroom), .headroom = _headroom,   \
265                 .intcoal_kbytes = _intcoal_kbytes,                           \
266                 .intcoal_holdoff_nentries = _intcoal_holdoff_nentries,       \
267                 .intcoal_holdoff_usecs = _intcoal_holdoff_usecs,             \
268                 .intid = cpu_to_be16(_intid),                                \
269                 .scan_start_id = cpu_to_be32(_scan_start_id),                \
270                 .scan_end_id = cpu_to_be32(_scan_end_id),                    \
271                 .tph_cpuid = cpu_to_be16(_tph_cpuid),                        \
272         }
273
274 #define FUN_ADMIN_EPCQ_MODIFY_REQ_INIT(_subop, _flags, _id, _headroom)      \
275         (struct fun_admin_epcq_modify_req) {                                \
276                 .subop = (_subop), .flags = cpu_to_be16(_flags),            \
277                 .id = cpu_to_be32(_id), .headroom = cpu_to_be16(_headroom), \
278         }
279
280 enum {
281         FUN_ADMIN_EPSQ_CREATE_FLAG_INT_EPSQ = 0x2,
282         FUN_ADMIN_EPSQ_CREATE_FLAG_ENTRY_RD_TPH = 0x4,
283         FUN_ADMIN_EPSQ_CREATE_FLAG_GL_RD_TPH = 0x8,
284         FUN_ADMIN_EPSQ_CREATE_FLAG_HEAD_WB_ADDRESS = 0x10,
285         FUN_ADMIN_EPSQ_CREATE_FLAG_HEAD_WB_ADDRESS_TPH = 0x20,
286         FUN_ADMIN_EPSQ_CREATE_FLAG_HEAD_WB_EPCQ = 0x40,
287         FUN_ADMIN_EPSQ_CREATE_FLAG_RQ = 0x80,
288         FUN_ADMIN_EPSQ_CREATE_FLAG_INT_IQ = 0x100,
289         FUN_ADMIN_EPSQ_CREATE_FLAG_NO_CMPL = 0x200,
290 };
291
292 struct fun_admin_epsq_req {
293         struct fun_admin_req_common common;
294
295         union epsq_req_subop {
296                 struct fun_admin_epsq_create_req {
297                         __u8 subop;
298                         __u8 rsvd0;
299                         __be16 flags;
300                         __be32 id;
301
302                         __be32 epcqid;
303                         __u8 rsvd1;
304                         __u8 entry_size_log2;
305                         __be16 nentries;
306
307                         __be64 address; /* DMA address of epsq */
308
309                         __u8 rsvd2[3];
310                         __u8 intcoal_kbytes;
311                         __u8 intcoal_holdoff_nentries;
312                         __u8 intcoal_holdoff_usecs;
313                         __be16 intid;
314
315                         __be32 scan_start_id;
316                         __be32 scan_end_id;
317
318                         __u8 rsvd3[4];
319                         __be16 tph_cpuid;
320                         __u8 buf_size_log2; /* log2 of RQ buffer size */
321                         __u8 head_wb_size_log2; /* log2 of head write back size */
322
323                         __be64 head_wb_address; /* DMA address for head writeback */
324                 } create;
325         } u;
326 };
327
328 #define FUN_ADMIN_EPSQ_CREATE_REQ_INIT(                                      \
329         _subop, _flags, _id, _epcqid, _entry_size_log2, _nentries, _address, \
330         _intcoal_kbytes, _intcoal_holdoff_nentries, _intcoal_holdoff_usecs,  \
331         _intid, _scan_start_id, _scan_end_id, _tph_cpuid, _buf_size_log2,    \
332         _head_wb_size_log2, _head_wb_address)                                \
333         (struct fun_admin_epsq_create_req) {                                 \
334                 .subop = (_subop), .flags = cpu_to_be16(_flags),             \
335                 .id = cpu_to_be32(_id), .epcqid = cpu_to_be32(_epcqid),      \
336                 .entry_size_log2 = _entry_size_log2,                         \
337                 .nentries = cpu_to_be16(_nentries),                          \
338                 .address = cpu_to_be64(_address),                            \
339                 .intcoal_kbytes = _intcoal_kbytes,                           \
340                 .intcoal_holdoff_nentries = _intcoal_holdoff_nentries,       \
341                 .intcoal_holdoff_usecs = _intcoal_holdoff_usecs,             \
342                 .intid = cpu_to_be16(_intid),                                \
343                 .scan_start_id = cpu_to_be32(_scan_start_id),                \
344                 .scan_end_id = cpu_to_be32(_scan_end_id),                    \
345                 .tph_cpuid = cpu_to_be16(_tph_cpuid),                        \
346                 .buf_size_log2 = _buf_size_log2,                             \
347                 .head_wb_size_log2 = _head_wb_size_log2,                     \
348                 .head_wb_address = cpu_to_be64(_head_wb_address),            \
349         }
350
351 enum {
352         FUN_PORT_CAP_OFFLOADS = 0x1,
353         FUN_PORT_CAP_STATS = 0x2,
354         FUN_PORT_CAP_LOOPBACK = 0x4,
355         FUN_PORT_CAP_VPORT = 0x8,
356         FUN_PORT_CAP_TX_PAUSE = 0x10,
357         FUN_PORT_CAP_RX_PAUSE = 0x20,
358         FUN_PORT_CAP_AUTONEG = 0x40,
359         FUN_PORT_CAP_RSS = 0x80,
360         FUN_PORT_CAP_VLAN_OFFLOADS = 0x100,
361         FUN_PORT_CAP_ENCAP_OFFLOADS = 0x200,
362         FUN_PORT_CAP_1000_X = 0x1000,
363         FUN_PORT_CAP_10G_R = 0x2000,
364         FUN_PORT_CAP_40G_R4 = 0x4000,
365         FUN_PORT_CAP_25G_R = 0x8000,
366         FUN_PORT_CAP_50G_R2 = 0x10000,
367         FUN_PORT_CAP_50G_R = 0x20000,
368         FUN_PORT_CAP_100G_R4 = 0x40000,
369         FUN_PORT_CAP_100G_R2 = 0x80000,
370         FUN_PORT_CAP_200G_R4 = 0x100000,
371         FUN_PORT_CAP_FEC_NONE = 0x10000000,
372         FUN_PORT_CAP_FEC_FC = 0x20000000,
373         FUN_PORT_CAP_FEC_RS = 0x40000000,
374 };
375
376 enum fun_port_brkout_mode {
377         FUN_PORT_BRKMODE_NA = 0x0,
378         FUN_PORT_BRKMODE_NONE = 0x1,
379         FUN_PORT_BRKMODE_2X = 0x2,
380         FUN_PORT_BRKMODE_4X = 0x3,
381 };
382
383 enum {
384         FUN_PORT_SPEED_AUTO = 0x0,
385         FUN_PORT_SPEED_10M = 0x1,
386         FUN_PORT_SPEED_100M = 0x2,
387         FUN_PORT_SPEED_1G = 0x4,
388         FUN_PORT_SPEED_10G = 0x8,
389         FUN_PORT_SPEED_25G = 0x10,
390         FUN_PORT_SPEED_40G = 0x20,
391         FUN_PORT_SPEED_50G = 0x40,
392         FUN_PORT_SPEED_100G = 0x80,
393         FUN_PORT_SPEED_200G = 0x100,
394 };
395
396 enum fun_port_duplex_mode {
397         FUN_PORT_FULL_DUPLEX = 0x0,
398         FUN_PORT_HALF_DUPLEX = 0x1,
399 };
400
401 enum {
402         FUN_PORT_FEC_NA = 0x0,
403         FUN_PORT_FEC_OFF = 0x1,
404         FUN_PORT_FEC_RS = 0x2,
405         FUN_PORT_FEC_FC = 0x4,
406         FUN_PORT_FEC_AUTO = 0x8,
407 };
408
409 enum fun_port_link_status {
410         FUN_PORT_LINK_UP = 0x0,
411         FUN_PORT_LINK_UP_WITH_ERR = 0x1,
412         FUN_PORT_LINK_DOWN = 0x2,
413 };
414
415 enum fun_port_led_type {
416         FUN_PORT_LED_OFF = 0x0,
417         FUN_PORT_LED_AMBER = 0x1,
418         FUN_PORT_LED_GREEN = 0x2,
419         FUN_PORT_LED_BEACON_ON = 0x3,
420         FUN_PORT_LED_BEACON_OFF = 0x4,
421 };
422
423 enum {
424         FUN_PORT_FLAG_MAC_DOWN = 0x1,
425         FUN_PORT_FLAG_MAC_UP = 0x2,
426         FUN_PORT_FLAG_NH_DOWN = 0x4,
427         FUN_PORT_FLAG_NH_UP = 0x8,
428 };
429
430 enum {
431         FUN_PORT_FLAG_ENABLE_NOTIFY = 0x1,
432 };
433
434 enum fun_port_lane_attr {
435         FUN_PORT_LANE_1 = 0x1,
436         FUN_PORT_LANE_2 = 0x2,
437         FUN_PORT_LANE_4 = 0x4,
438         FUN_PORT_LANE_SPEED_10G = 0x100,
439         FUN_PORT_LANE_SPEED_25G = 0x200,
440         FUN_PORT_LANE_SPEED_50G = 0x400,
441         FUN_PORT_LANE_SPLIT = 0x8000,
442 };
443
444 enum fun_admin_port_subop {
445         FUN_ADMIN_PORT_SUBOP_INETADDR_EVENT = 0x24,
446 };
447
448 enum fun_admin_port_key {
449         FUN_ADMIN_PORT_KEY_ILLEGAL = 0x0,
450         FUN_ADMIN_PORT_KEY_MTU = 0x1,
451         FUN_ADMIN_PORT_KEY_FEC = 0x2,
452         FUN_ADMIN_PORT_KEY_SPEED = 0x3,
453         FUN_ADMIN_PORT_KEY_DEBOUNCE = 0x4,
454         FUN_ADMIN_PORT_KEY_DUPLEX = 0x5,
455         FUN_ADMIN_PORT_KEY_MACADDR = 0x6,
456         FUN_ADMIN_PORT_KEY_LINKMODE = 0x7,
457         FUN_ADMIN_PORT_KEY_BREAKOUT = 0x8,
458         FUN_ADMIN_PORT_KEY_ENABLE = 0x9,
459         FUN_ADMIN_PORT_KEY_DISABLE = 0xa,
460         FUN_ADMIN_PORT_KEY_ERR_DISABLE = 0xb,
461         FUN_ADMIN_PORT_KEY_CAPABILITIES = 0xc,
462         FUN_ADMIN_PORT_KEY_LP_CAPABILITIES = 0xd,
463         FUN_ADMIN_PORT_KEY_STATS_DMA_LOW = 0xe,
464         FUN_ADMIN_PORT_KEY_STATS_DMA_HIGH = 0xf,
465         FUN_ADMIN_PORT_KEY_LANE_ATTRS = 0x10,
466         FUN_ADMIN_PORT_KEY_LED = 0x11,
467         FUN_ADMIN_PORT_KEY_ADVERT = 0x12,
468 };
469
470 struct fun_subop_imm {
471         __u8 subop; /* see fun_data_subop enum */
472         __u8 flags;
473         __u8 nsgl;
474         __u8 rsvd0;
475         __be32 len;
476
477         __u8 data[];
478 };
479
480 enum fun_subop_sgl_flags {
481         FUN_SUBOP_SGL_USE_OFF8 = 0x1,
482         FUN_SUBOP_FLAG_FREE_BUF = 0x2,
483         FUN_SUBOP_FLAG_IS_REFBUF = 0x4,
484         FUN_SUBOP_SGL_FLAG_LOCAL = 0x8,
485 };
486
487 enum fun_data_op {
488         FUN_DATAOP_INVALID = 0x0,
489         FUN_DATAOP_SL = 0x1, /* scatter */
490         FUN_DATAOP_GL = 0x2, /* gather */
491         FUN_DATAOP_SGL = 0x3, /* scatter-gather */
492         FUN_DATAOP_IMM = 0x4, /* immediate data */
493         FUN_DATAOP_RQBUF = 0x8, /* rq buffer */
494 };
495
496 struct fun_dataop_gl {
497         __u8 subop;
498         __u8 flags;
499         __be16 sgl_off;
500         __be32 sgl_len;
501
502         __be64 sgl_data;
503 };
504
505 static inline void fun_dataop_gl_init(struct fun_dataop_gl *s, u8 flags,
506                                       u16 sgl_off, u32 sgl_len, u64 sgl_data)
507 {
508         s->subop = FUN_DATAOP_GL;
509         s->flags = flags;
510         s->sgl_off = cpu_to_be16(sgl_off);
511         s->sgl_len = cpu_to_be32(sgl_len);
512         s->sgl_data = cpu_to_be64(sgl_data);
513 }
514
515 struct fun_dataop_imm {
516         __u8 subop;
517         __u8 flags;
518         __be16 rsvd0;
519         __be32 sgl_len;
520 };
521
522 struct fun_subop_sgl {
523         __u8 subop;
524         __u8 flags;
525         __u8 nsgl;
526         __u8 rsvd0;
527         __be32 sgl_len;
528
529         __be64 sgl_data;
530 };
531
532 #define FUN_SUBOP_SGL_INIT(_subop, _flags, _nsgl, _sgl_len, _sgl_data) \
533         (struct fun_subop_sgl) {                                       \
534                 .subop = (_subop), .flags = (_flags), .nsgl = (_nsgl), \
535                 .sgl_len = cpu_to_be32(_sgl_len),                      \
536                 .sgl_data = cpu_to_be64(_sgl_data),                    \
537         }
538
539 struct fun_dataop_rqbuf {
540         __u8 subop;
541         __u8 rsvd0;
542         __be16 cid;
543         __be32 bufoff;
544 };
545
546 struct fun_dataop_hdr {
547         __u8 nsgl;
548         __u8 flags;
549         __u8 ngather;
550         __u8 nscatter;
551         __be32 total_len;
552
553         struct fun_dataop_imm imm[];
554 };
555
556 #define FUN_DATAOP_HDR_INIT(_nsgl, _flags, _ngather, _nscatter, _total_len)  \
557         (struct fun_dataop_hdr) {                                            \
558                 .nsgl = _nsgl, .flags = _flags, .ngather = _ngather,         \
559                 .nscatter = _nscatter, .total_len = cpu_to_be32(_total_len), \
560         }
561
562 enum fun_port_inetaddr_event_type {
563         FUN_PORT_INETADDR_ADD = 0x1,
564         FUN_PORT_INETADDR_DEL = 0x2,
565 };
566
567 enum fun_port_inetaddr_addr_family {
568         FUN_PORT_INETADDR_IPV4 = 0x1,
569         FUN_PORT_INETADDR_IPV6 = 0x2,
570 };
571
572 struct fun_admin_port_req {
573         struct fun_admin_req_common common;
574
575         union port_req_subop {
576                 struct fun_admin_port_create_req {
577                         __u8 subop;
578                         __u8 rsvd0;
579                         __be16 flags;
580                         __be32 id;
581                 } create;
582                 struct fun_admin_port_write_req {
583                         __u8 subop;
584                         __u8 rsvd0;
585                         __be16 flags;
586                         __be32 id; /* portid */
587
588                         struct fun_admin_write48_req write48[];
589                 } write;
590                 struct fun_admin_port_read_req {
591                         __u8 subop;
592                         __u8 rsvd0;
593                         __be16 flags;
594                         __be32 id; /* portid */
595
596                         struct fun_admin_read48_req read48[];
597                 } read;
598                 struct fun_admin_port_inetaddr_event_req {
599                         __u8 subop;
600                         __u8 rsvd0;
601                         __u8 event_type;
602                         __u8 addr_family;
603                         __be32 id;
604
605                         __u8 addr[];
606                 } inetaddr_event;
607         } u;
608 };
609
610 #define FUN_ADMIN_PORT_CREATE_REQ_INIT(_subop, _flags, _id)      \
611         (struct fun_admin_port_create_req) {                     \
612                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
613                 .id = cpu_to_be32(_id),                          \
614         }
615
616 #define FUN_ADMIN_PORT_WRITE_REQ_INIT(_subop, _flags, _id)       \
617         (struct fun_admin_port_write_req) {                      \
618                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
619                 .id = cpu_to_be32(_id),                          \
620         }
621
622 #define FUN_ADMIN_PORT_READ_REQ_INIT(_subop, _flags, _id)        \
623         (struct fun_admin_port_read_req) {                       \
624                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
625                 .id = cpu_to_be32(_id),                          \
626         }
627
628 struct fun_admin_port_rsp {
629         struct fun_admin_rsp_common common;
630
631         union port_rsp_subop {
632                 struct fun_admin_port_create_rsp {
633                         __u8 subop;
634                         __u8 rsvd0[3];
635                         __be32 id;
636
637                         __be16 lport;
638                         __u8 rsvd1[6];
639                 } create;
640                 struct fun_admin_port_write_rsp {
641                         __u8 subop;
642                         __u8 rsvd0[3];
643                         __be32 id; /* portid */
644
645                         struct fun_admin_write48_rsp write48[];
646                 } write;
647                 struct fun_admin_port_read_rsp {
648                         __u8 subop;
649                         __u8 rsvd0[3];
650                         __be32 id; /* portid */
651
652                         struct fun_admin_read48_rsp read48[];
653                 } read;
654                 struct fun_admin_port_inetaddr_event_rsp {
655                         __u8 subop;
656                         __u8 rsvd0[3];
657                         __be32 id; /* portid */
658                 } inetaddr_event;
659         } u;
660 };
661
662 enum fun_xcvr_type {
663         FUN_XCVR_BASET = 0x0,
664         FUN_XCVR_CU = 0x1,
665         FUN_XCVR_SMF = 0x2,
666         FUN_XCVR_MMF = 0x3,
667         FUN_XCVR_AOC = 0x4,
668         FUN_XCVR_SFPP = 0x10, /* SFP+ or later */
669         FUN_XCVR_QSFPP = 0x11, /* QSFP+ or later */
670         FUN_XCVR_QSFPDD = 0x12, /* QSFP-DD */
671 };
672
673 struct fun_admin_port_notif {
674         struct fun_admin_rsp_common common;
675
676         __u8 subop;
677         __u8 rsvd0;
678         __be16 id;
679         __be32 speed; /* in 10 Mbps units */
680
681         __u8 link_state;
682         __u8 missed_events;
683         __u8 link_down_reason;
684         __u8 xcvr_type;
685         __u8 flow_ctrl;
686         __u8 fec;
687         __u8 active_lanes;
688         __u8 rsvd1;
689
690         __be64 advertising;
691
692         __be64 lp_advertising;
693 };
694
695 enum fun_eth_rss_const {
696         FUN_ETH_RSS_MAX_KEY_SIZE = 0x28,
697         FUN_ETH_RSS_MAX_INDIR_ENT = 0x40,
698 };
699
700 enum fun_eth_hash_alg {
701         FUN_ETH_RSS_ALG_INVALID = 0x0,
702         FUN_ETH_RSS_ALG_TOEPLITZ = 0x1,
703         FUN_ETH_RSS_ALG_CRC32 = 0x2,
704 };
705
706 struct fun_admin_rss_req {
707         struct fun_admin_req_common common;
708
709         union rss_req_subop {
710                 struct fun_admin_rss_create_req {
711                         __u8 subop;
712                         __u8 rsvd0;
713                         __be16 flags;
714                         __be32 id;
715
716                         __be32 rsvd1;
717                         __be32 viid; /* VI flow id */
718
719                         __be64 metadata[1];
720
721                         __u8 alg;
722                         __u8 keylen;
723                         __u8 indir_nent;
724                         __u8 rsvd2;
725                         __be16 key_off;
726                         __be16 indir_off;
727
728                         struct fun_dataop_hdr dataop;
729                 } create;
730         } u;
731 };
732
733 #define FUN_ADMIN_RSS_CREATE_REQ_INIT(_subop, _flags, _id, _viid, _alg,    \
734                                       _keylen, _indir_nent, _key_off,      \
735                                       _indir_off)                          \
736         (struct fun_admin_rss_create_req) {                                \
737                 .subop = (_subop), .flags = cpu_to_be16(_flags),           \
738                 .id = cpu_to_be32(_id), .viid = cpu_to_be32(_viid),        \
739                 .alg = _alg, .keylen = _keylen, .indir_nent = _indir_nent, \
740                 .key_off = cpu_to_be16(_key_off),                          \
741                 .indir_off = cpu_to_be16(_indir_off),                      \
742         }
743
744 struct fun_admin_vi_req {
745         struct fun_admin_req_common common;
746
747         union vi_req_subop {
748                 struct fun_admin_vi_create_req {
749                         __u8 subop;
750                         __u8 rsvd0;
751                         __be16 flags;
752                         __be32 id;
753
754                         __be32 rsvd1;
755                         __be32 portid; /* port flow id */
756                 } create;
757         } u;
758 };
759
760 #define FUN_ADMIN_VI_CREATE_REQ_INIT(_subop, _flags, _id, _portid)      \
761         (struct fun_admin_vi_create_req) {                              \
762                 .subop = (_subop), .flags = cpu_to_be16(_flags),        \
763                 .id = cpu_to_be32(_id), .portid = cpu_to_be32(_portid), \
764         }
765
766 struct fun_admin_eth_req {
767         struct fun_admin_req_common common;
768
769         union eth_req_subop {
770                 struct fun_admin_eth_create_req {
771                         __u8 subop;
772                         __u8 rsvd0;
773                         __be16 flags;
774                         __be32 id;
775
776                         __be32 rsvd1;
777                         __be32 portid; /* port flow id */
778                 } create;
779         } u;
780 };
781
782 #define FUN_ADMIN_ETH_CREATE_REQ_INIT(_subop, _flags, _id, _portid)     \
783         (struct fun_admin_eth_create_req) {                             \
784                 .subop = (_subop), .flags = cpu_to_be16(_flags),        \
785                 .id = cpu_to_be32(_id), .portid = cpu_to_be32(_portid), \
786         }
787
788 enum {
789         FUN_ADMIN_SWU_UPGRADE_FLAG_INIT = 0x10,
790         FUN_ADMIN_SWU_UPGRADE_FLAG_COMPLETE = 0x20,
791         FUN_ADMIN_SWU_UPGRADE_FLAG_DOWNGRADE = 0x40,
792         FUN_ADMIN_SWU_UPGRADE_FLAG_ACTIVE_IMAGE = 0x80,
793         FUN_ADMIN_SWU_UPGRADE_FLAG_ASYNC = 0x1,
794 };
795
796 enum fun_admin_swu_subop {
797         FUN_ADMIN_SWU_SUBOP_GET_VERSION = 0x20,
798         FUN_ADMIN_SWU_SUBOP_UPGRADE = 0x21,
799         FUN_ADMIN_SWU_SUBOP_UPGRADE_DATA = 0x22,
800         FUN_ADMIN_SWU_SUBOP_GET_ALL_VERSIONS = 0x23,
801 };
802
803 struct fun_admin_swu_req {
804         struct fun_admin_req_common common;
805
806         union swu_req_subop {
807                 struct fun_admin_swu_create_req {
808                         __u8 subop;
809                         __u8 rsvd0;
810                         __be16 flags;
811                         __be32 id;
812                 } create;
813                 struct fun_admin_swu_upgrade_req {
814                         __u8 subop;
815                         __u8 rsvd0;
816                         __be16 flags;
817                         __be32 id;
818
819                         __be32 fourcc;
820                         __be32 rsvd1;
821
822                         __be64 image_size; /* upgrade image length */
823                 } upgrade;
824                 struct fun_admin_swu_upgrade_data_req {
825                         __u8 subop;
826                         __u8 rsvd0;
827                         __be16 flags;
828                         __be32 id;
829
830                         __be32 offset; /* offset of data in this command */
831                         __be32 size; /* total size of data in this command */
832                 } upgrade_data;
833         } u;
834
835         struct fun_subop_sgl sgl[]; /* in, out buffers through sgl */
836 };
837
838 #define FUN_ADMIN_SWU_CREATE_REQ_INIT(_subop, _flags, _id)       \
839         (struct fun_admin_swu_create_req) {                      \
840                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
841                 .id = cpu_to_be32(_id),                          \
842         }
843
844 #define FUN_ADMIN_SWU_UPGRADE_REQ_INIT(_subop, _flags, _id, _fourcc,    \
845                                        _image_size)                     \
846         (struct fun_admin_swu_upgrade_req) {                            \
847                 .subop = (_subop), .flags = cpu_to_be16(_flags),        \
848                 .id = cpu_to_be32(_id), .fourcc = cpu_to_be32(_fourcc), \
849                 .image_size = cpu_to_be64(_image_size),                 \
850         }
851
852 #define FUN_ADMIN_SWU_UPGRADE_DATA_REQ_INIT(_subop, _flags, _id, _offset, \
853                                             _size)                        \
854         (struct fun_admin_swu_upgrade_data_req) {                         \
855                 .subop = (_subop), .flags = cpu_to_be16(_flags),          \
856                 .id = cpu_to_be32(_id), .offset = cpu_to_be32(_offset),   \
857                 .size = cpu_to_be32(_size),                               \
858         }
859
860 struct fun_admin_swu_rsp {
861         struct fun_admin_rsp_common common;
862
863         union swu_rsp_subop {
864                 struct fun_admin_swu_create_rsp {
865                         __u8 subop;
866                         __u8 rsvd0;
867                         __be16 flags;
868                         __be32 id;
869                 } create;
870                 struct fun_admin_swu_upgrade_rsp {
871                         __u8 subop;
872                         __u8 rsvd0[3];
873                         __be32 id;
874
875                         __be32 fourcc;
876                         __be32 status;
877
878                         __be32 progress;
879                         __be32 unused;
880                 } upgrade;
881                 struct fun_admin_swu_upgrade_data_rsp {
882                         __u8 subop;
883                         __u8 rsvd0;
884                         __be16 flags;
885                         __be32 id;
886
887                         __be32 offset;
888                         __be32 size;
889                 } upgrade_data;
890         } u;
891 };
892
893 enum fun_ktls_version {
894         FUN_KTLS_TLSV2 = 0x20,
895         FUN_KTLS_TLSV3 = 0x30,
896 };
897
898 enum fun_ktls_cipher {
899         FUN_KTLS_CIPHER_AES_GCM_128 = 0x33,
900         FUN_KTLS_CIPHER_AES_GCM_256 = 0x34,
901         FUN_KTLS_CIPHER_AES_CCM_128 = 0x35,
902         FUN_KTLS_CIPHER_CHACHA20_POLY1305 = 0x36,
903 };
904
905 enum fun_ktls_modify_flags {
906         FUN_KTLS_MODIFY_REMOVE = 0x1,
907 };
908
909 struct fun_admin_ktls_create_req {
910         struct fun_admin_req_common common;
911
912         __u8 subop;
913         __u8 rsvd0;
914         __be16 flags;
915         __be32 id;
916 };
917
918 #define FUN_ADMIN_KTLS_CREATE_REQ_INIT(_subop, _flags, _id)      \
919         (struct fun_admin_ktls_create_req) {                     \
920                 .subop = (_subop), .flags = cpu_to_be16(_flags), \
921                 .id = cpu_to_be32(_id),                          \
922         }
923
924 struct fun_admin_ktls_create_rsp {
925         struct fun_admin_rsp_common common;
926
927         __u8 subop;
928         __u8 rsvd0[3];
929         __be32 id;
930 };
931
932 struct fun_admin_ktls_modify_req {
933         struct fun_admin_req_common common;
934
935         __u8 subop;
936         __u8 rsvd0;
937         __be16 flags;
938         __be32 id;
939
940         __be64 tlsid;
941
942         __be32 tcp_seq;
943         __u8 version;
944         __u8 cipher;
945         __u8 rsvd1[2];
946
947         __u8 record_seq[8];
948
949         __u8 key[32];
950
951         __u8 iv[16];
952
953         __u8 salt[8];
954 };
955
956 #define FUN_ADMIN_KTLS_MODIFY_REQ_INIT(_subop, _flags, _id, _tlsid, _tcp_seq, \
957                                        _version, _cipher)                     \
958         (struct fun_admin_ktls_modify_req) {                                  \
959                 .subop = (_subop), .flags = cpu_to_be16(_flags),              \
960                 .id = cpu_to_be32(_id), .tlsid = cpu_to_be64(_tlsid),         \
961                 .tcp_seq = cpu_to_be32(_tcp_seq), .version = _version,        \
962                 .cipher = _cipher,                                            \
963         }
964
965 struct fun_admin_ktls_modify_rsp {
966         struct fun_admin_rsp_common common;
967
968         __u8 subop;
969         __u8 rsvd0[3];
970         __be32 id;
971
972         __be64 tlsid;
973 };
974
975 struct fun_req_common {
976         __u8 op;
977         __u8 len8;
978         __be16 flags;
979         __u8 suboff8;
980         __u8 rsvd0;
981         __be16 cid;
982 };
983
984 struct fun_rsp_common {
985         __u8 op;
986         __u8 len8;
987         __be16 flags;
988         __u8 suboff8;
989         __u8 ret;
990         __be16 cid;
991 };
992
993 struct fun_cqe_info {
994         __be16 sqhd;
995         __be16 sqid;
996         __be16 cid;
997         __be16 sf_p;
998 };
999
1000 enum fun_eprq_def {
1001         FUN_EPRQ_PKT_ALIGN = 0x80,
1002 };
1003
1004 struct fun_eprq_rqbuf {
1005         __be64 bufaddr;
1006 };
1007
1008 #define FUN_EPRQ_RQBUF_INIT(_bufaddr)             \
1009         (struct fun_eprq_rqbuf) {                 \
1010                 .bufaddr = cpu_to_be64(_bufaddr), \
1011         }
1012
1013 enum fun_eth_op {
1014         FUN_ETH_OP_TX = 0x1,
1015         FUN_ETH_OP_RX = 0x2,
1016 };
1017
1018 enum {
1019         FUN_ETH_OFFLOAD_EN = 0x8000,
1020         FUN_ETH_OUTER_EN = 0x4000,
1021         FUN_ETH_INNER_LSO = 0x2000,
1022         FUN_ETH_INNER_TSO = 0x1000,
1023         FUN_ETH_OUTER_IPV6 = 0x800,
1024         FUN_ETH_OUTER_UDP = 0x400,
1025         FUN_ETH_INNER_IPV6 = 0x200,
1026         FUN_ETH_INNER_UDP = 0x100,
1027         FUN_ETH_UPDATE_OUTER_L3_LEN = 0x80,
1028         FUN_ETH_UPDATE_OUTER_L3_CKSUM = 0x40,
1029         FUN_ETH_UPDATE_OUTER_L4_LEN = 0x20,
1030         FUN_ETH_UPDATE_OUTER_L4_CKSUM = 0x10,
1031         FUN_ETH_UPDATE_INNER_L3_LEN = 0x8,
1032         FUN_ETH_UPDATE_INNER_L3_CKSUM = 0x4,
1033         FUN_ETH_UPDATE_INNER_L4_LEN = 0x2,
1034         FUN_ETH_UPDATE_INNER_L4_CKSUM = 0x1,
1035 };
1036
1037 struct fun_eth_offload {
1038         __be16 flags; /* combination of above flags */
1039         __be16 mss; /* TSO max seg size */
1040         __be16 tcp_doff_flags; /* TCP data offset + flags 16b word */
1041         __be16 vlan;
1042
1043         __be16 inner_l3_off; /* Inner L3 header offset */
1044         __be16 inner_l4_off; /* Inner L4 header offset */
1045         __be16 outer_l3_off; /* Outer L3 header offset */
1046         __be16 outer_l4_off; /* Outer L4 header offset */
1047 };
1048
1049 static inline void fun_eth_offload_init(struct fun_eth_offload *s, u16 flags,
1050                                         u16 mss, __be16 tcp_doff_flags,
1051                                         __be16 vlan, u16 inner_l3_off,
1052                                         u16 inner_l4_off, u16 outer_l3_off,
1053                                         u16 outer_l4_off)
1054 {
1055         s->flags = cpu_to_be16(flags);
1056         s->mss = cpu_to_be16(mss);
1057         s->tcp_doff_flags = tcp_doff_flags;
1058         s->vlan = vlan;
1059         s->inner_l3_off = cpu_to_be16(inner_l3_off);
1060         s->inner_l4_off = cpu_to_be16(inner_l4_off);
1061         s->outer_l3_off = cpu_to_be16(outer_l3_off);
1062         s->outer_l4_off = cpu_to_be16(outer_l4_off);
1063 }
1064
1065 struct fun_eth_tls {
1066         __be64 tlsid;
1067 };
1068
1069 enum {
1070         FUN_ETH_TX_TLS = 0x8000,
1071 };
1072
1073 struct fun_eth_tx_req {
1074         __u8 op;
1075         __u8 len8;
1076         __be16 flags;
1077         __u8 suboff8;
1078         __u8 repr_idn;
1079         __be16 encap_proto;
1080
1081         struct fun_eth_offload offload;
1082
1083         struct fun_dataop_hdr dataop;
1084 };
1085
1086 struct fun_eth_rx_cv {
1087         __be16 il4_prot_to_l2_type;
1088 };
1089
1090 #define FUN_ETH_RX_CV_IL4_PROT_S 13U
1091 #define FUN_ETH_RX_CV_IL4_PROT_M 0x3
1092
1093 #define FUN_ETH_RX_CV_IL3_PROT_S 11U
1094 #define FUN_ETH_RX_CV_IL3_PROT_M 0x3
1095
1096 #define FUN_ETH_RX_CV_OL4_PROT_S 8U
1097 #define FUN_ETH_RX_CV_OL4_PROT_M 0x7
1098
1099 #define FUN_ETH_RX_CV_ENCAP_TYPE_S 6U
1100 #define FUN_ETH_RX_CV_ENCAP_TYPE_M 0x3
1101
1102 #define FUN_ETH_RX_CV_OL3_PROT_S 4U
1103 #define FUN_ETH_RX_CV_OL3_PROT_M 0x3
1104
1105 #define FUN_ETH_RX_CV_VLAN_TYPE_S 3U
1106 #define FUN_ETH_RX_CV_VLAN_TYPE_M 0x1
1107
1108 #define FUN_ETH_RX_CV_L2_TYPE_S 2U
1109 #define FUN_ETH_RX_CV_L2_TYPE_M 0x1
1110
1111 enum fun_rx_cv {
1112         FUN_RX_CV_NONE = 0x0,
1113         FUN_RX_CV_IP = 0x2,
1114         FUN_RX_CV_IP6 = 0x3,
1115         FUN_RX_CV_TCP = 0x2,
1116         FUN_RX_CV_UDP = 0x3,
1117         FUN_RX_CV_VXLAN = 0x2,
1118         FUN_RX_CV_MPLS = 0x3,
1119 };
1120
1121 struct fun_eth_cqe {
1122         __u8 op;
1123         __u8 len8;
1124         __u8 nsgl;
1125         __u8 repr_idn;
1126         __be32 pkt_len;
1127
1128         __be64 timestamp;
1129
1130         __be16 pkt_cv;
1131         __be16 rsvd0;
1132         __be32 hash;
1133
1134         __be16 encap_proto;
1135         __be16 vlan;
1136         __be32 rsvd1;
1137
1138         __be32 buf_offset;
1139         __be16 headroom;
1140         __be16 csum;
1141 };
1142
1143 enum fun_admin_adi_attr {
1144         FUN_ADMIN_ADI_ATTR_MACADDR = 0x1,
1145         FUN_ADMIN_ADI_ATTR_VLAN = 0x2,
1146         FUN_ADMIN_ADI_ATTR_RATE = 0x3,
1147 };
1148
1149 struct fun_adi_param {
1150         union adi_param {
1151                 struct fun_adi_mac {
1152                         __be64 addr;
1153                 } mac;
1154                 struct fun_adi_vlan {
1155                         __be32 rsvd;
1156                         __be16 eth_type;
1157                         __be16 tci;
1158                 } vlan;
1159                 struct fun_adi_rate {
1160                         __be32 rsvd;
1161                         __be32 tx_mbps;
1162                 } rate;
1163         } u;
1164 };
1165
1166 #define FUN_ADI_MAC_INIT(_addr)             \
1167         (struct fun_adi_mac) {              \
1168                 .addr = cpu_to_be64(_addr), \
1169         }
1170
1171 #define FUN_ADI_VLAN_INIT(_eth_type, _tci)                                    \
1172         (struct fun_adi_vlan) {                                               \
1173                 .eth_type = cpu_to_be16(_eth_type), .tci = cpu_to_be16(_tci), \
1174         }
1175
1176 #define FUN_ADI_RATE_INIT(_tx_mbps)               \
1177         (struct fun_adi_rate) {                   \
1178                 .tx_mbps = cpu_to_be32(_tx_mbps), \
1179         }
1180
1181 struct fun_admin_adi_req {
1182         struct fun_admin_req_common common;
1183
1184         union adi_req_subop {
1185                 struct fun_admin_adi_write_req {
1186                         __u8 subop;
1187                         __u8 attribute;
1188                         __be16 rsvd;
1189                         __be32 id;
1190
1191                         struct fun_adi_param param;
1192                 } write;
1193         } u;
1194 };
1195
1196 #define FUN_ADMIN_ADI_WRITE_REQ_INIT(_subop, _attribute, _id) \
1197         (struct fun_admin_adi_write_req) {                    \
1198                 .subop = (_subop), .attribute = (_attribute), \
1199                 .id = cpu_to_be32(_id),                       \
1200         }
1201
1202 #endif /* __FUN_HCI_H */