xref: /openbmc/linux/drivers/scsi/snic/wq_enet_desc.h (revision 0da908c2)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
3 
4 #ifndef _WQ_ENET_DESC_H_
5 #define _WQ_ENET_DESC_H_
6 
7 /* Ethernet work queue descriptor: 16B */
8 struct wq_enet_desc {
9 	__le64 address;
10 	__le16 length;
11 	__le16 mss_loopback;
12 	__le16 header_length_flags;
13 	__le16 vlan_tag;
14 };
15 
16 #define WQ_ENET_ADDR_BITS		64
17 #define WQ_ENET_LEN_BITS		14
18 #define WQ_ENET_LEN_MASK		((1 << WQ_ENET_LEN_BITS) - 1)
19 #define WQ_ENET_MSS_BITS		14
20 #define WQ_ENET_MSS_MASK		((1 << WQ_ENET_MSS_BITS) - 1)
21 #define WQ_ENET_MSS_SHIFT		2
22 #define WQ_ENET_LOOPBACK_SHIFT		1
23 #define WQ_ENET_HDRLEN_BITS		10
24 #define WQ_ENET_HDRLEN_MASK		((1 << WQ_ENET_HDRLEN_BITS) - 1)
25 #define WQ_ENET_FLAGS_OM_BITS		2
26 #define WQ_ENET_FLAGS_OM_MASK		((1 << WQ_ENET_FLAGS_OM_BITS) - 1)
27 #define WQ_ENET_FLAGS_EOP_SHIFT		12
28 #define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT	13
29 #define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT	14
30 #define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT	15
31 
32 #define WQ_ENET_OFFLOAD_MODE_CSUM	0
33 #define WQ_ENET_OFFLOAD_MODE_RESERVED	1
34 #define WQ_ENET_OFFLOAD_MODE_CSUM_L4	2
35 #define WQ_ENET_OFFLOAD_MODE_TSO	3
36 
37 static inline void wq_enet_desc_enc(struct wq_enet_desc *desc,
38 	u64 address, u16 length, u16 mss, u16 header_length,
39 	u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap,
40 	u8 vlan_tag_insert, u16 vlan_tag, u8 loopback)
41 {
42 	desc->address = cpu_to_le64(address);
43 	desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK);
44 	desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) <<
45 		WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT);
46 	desc->header_length_flags = cpu_to_le16(
47 		(header_length & WQ_ENET_HDRLEN_MASK) |
48 		(offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS |
49 		(eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT |
50 		(cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT |
51 		(fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT |
52 		(vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT);
53 	desc->vlan_tag = cpu_to_le16(vlan_tag);
54 }
55 
56 static inline void wq_enet_desc_dec(struct wq_enet_desc *desc,
57 	u64 *address, u16 *length, u16 *mss, u16 *header_length,
58 	u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap,
59 	u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback)
60 {
61 	*address = le64_to_cpu(desc->address);
62 	*length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK;
63 	*mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) &
64 		WQ_ENET_MSS_MASK;
65 	*loopback = (u8)((le16_to_cpu(desc->mss_loopback) >>
66 		WQ_ENET_LOOPBACK_SHIFT) & 1);
67 	*header_length = le16_to_cpu(desc->header_length_flags) &
68 		WQ_ENET_HDRLEN_MASK;
69 	*offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >>
70 		WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK);
71 	*eop = (u8)((le16_to_cpu(desc->header_length_flags) >>
72 		WQ_ENET_FLAGS_EOP_SHIFT) & 1);
73 	*cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >>
74 		WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1);
75 	*fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >>
76 		WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1);
77 	*vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >>
78 		WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1);
79 	*vlan_tag = le16_to_cpu(desc->vlan_tag);
80 }
81 
82 #endif /* _WQ_ENET_DESC_H_ */
83