2 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _WQ_ENET_DESC_H_
36 #define _WQ_ENET_DESC_H_
38 /* Ethernet work queue descriptor: 16B */
43 __le16 header_length_flags;
47 #define WQ_ENET_ADDR_BITS 64
48 #define WQ_ENET_LEN_BITS 14
49 #define WQ_ENET_LEN_MASK ((1 << WQ_ENET_LEN_BITS) - 1)
50 #define WQ_ENET_MSS_BITS 14
51 #define WQ_ENET_MSS_MASK ((1 << WQ_ENET_MSS_BITS) - 1)
52 #define WQ_ENET_MSS_SHIFT 2
53 #define WQ_ENET_LOOPBACK_SHIFT 1
54 #define WQ_ENET_HDRLEN_BITS 10
55 #define WQ_ENET_HDRLEN_MASK ((1 << WQ_ENET_HDRLEN_BITS) - 1)
56 #define WQ_ENET_FLAGS_OM_BITS 2
57 #define WQ_ENET_FLAGS_OM_MASK ((1 << WQ_ENET_FLAGS_OM_BITS) - 1)
58 #define WQ_ENET_FLAGS_EOP_SHIFT 12
59 #define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT 13
60 #define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT 14
61 #define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT 15
63 #define WQ_ENET_OFFLOAD_MODE_CSUM 0
64 #define WQ_ENET_OFFLOAD_MODE_RESERVED 1
65 #define WQ_ENET_OFFLOAD_MODE_CSUM_L4 2
66 #define WQ_ENET_OFFLOAD_MODE_TSO 3
68 static inline void wq_enet_desc_enc(struct wq_enet_desc *desc,
69 u64 address, u16 length, u16 mss, u16 header_length,
70 u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap,
71 u8 vlan_tag_insert, u16 vlan_tag, u8 loopback)
73 desc->address = cpu_to_le64(address);
74 desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK);
75 desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) <<
76 WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT);
77 desc->header_length_flags = cpu_to_le16(
78 (header_length & WQ_ENET_HDRLEN_MASK) |
79 (offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS |
80 (eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT |
81 (cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT |
82 (fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT |
83 (vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT);
84 desc->vlan_tag = cpu_to_le16(vlan_tag);
87 static inline void wq_enet_desc_dec(struct wq_enet_desc *desc,
88 u64 *address, u16 *length, u16 *mss, u16 *header_length,
89 u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap,
90 u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback)
92 *address = le64_to_cpu(desc->address);
93 *length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK;
94 *mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) &
96 *loopback = (u8)((le16_to_cpu(desc->mss_loopback) >>
97 WQ_ENET_LOOPBACK_SHIFT) & 1);
98 *header_length = le16_to_cpu(desc->header_length_flags) &
100 *offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >>
101 WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK);
102 *eop = (u8)((le16_to_cpu(desc->header_length_flags) >>
103 WQ_ENET_FLAGS_EOP_SHIFT) & 1);
104 *cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >>
105 WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1);
106 *fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >>
107 WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1);
108 *vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >>
109 WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1);
110 *vlan_tag = le16_to_cpu(desc->vlan_tag);
113 #endif /* _WQ_ENET_DESC_H_ */