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