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 _CQ_ENET_DESC_H_
36 #define _CQ_ENET_DESC_H_
40 /* Ethernet completion queue descriptor: 16B */
41 struct cq_enet_wq_desc {
42 __le16 completed_index;
48 static inline void cq_enet_wq_desc_enc(struct cq_enet_wq_desc *desc,
49 u8 type, u8 color, u16 q_number, u16 completed_index)
51 cq_desc_enc((struct cq_desc *)desc, type,
52 color, q_number, completed_index);
55 static inline void cq_enet_wq_desc_dec(struct cq_enet_wq_desc *desc,
56 u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
58 cq_desc_dec((struct cq_desc *)desc, type,
59 color, q_number, completed_index);
62 /* Completion queue descriptor: Ethernet receive queue, 16B */
63 struct cq_enet_rq_desc {
64 __le16 completed_index_flags;
65 __le16 q_number_rss_type_flags;
67 __le16 bytes_written_flags;
74 /* Completion queue descriptor: Ethernet receive queue, 16B */
75 struct cq_enet_rq_clsf_desc {
76 __le16 completed_index_flags;
77 __le16 q_number_rss_type_flags;
80 __le16 bytes_written_flags;
87 #define CQ_ENET_RQ_DESC_FLAGS_INGRESS_PORT (0x1 << 12)
88 #define CQ_ENET_RQ_DESC_FLAGS_FCOE (0x1 << 13)
89 #define CQ_ENET_RQ_DESC_FLAGS_EOP (0x1 << 14)
90 #define CQ_ENET_RQ_DESC_FLAGS_SOP (0x1 << 15)
92 #define CQ_ENET_RQ_DESC_RSS_TYPE_BITS 4
93 #define CQ_ENET_RQ_DESC_RSS_TYPE_MASK \
94 ((1 << CQ_ENET_RQ_DESC_RSS_TYPE_BITS) - 1)
95 #define CQ_ENET_RQ_DESC_RSS_TYPE_NONE 0
96 #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv4 1
97 #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv4 2
98 #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv6 3
99 #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv6 4
100 #define CQ_ENET_RQ_DESC_RSS_TYPE_IPv6_EX 5
101 #define CQ_ENET_RQ_DESC_RSS_TYPE_TCP_IPv6_EX 6
103 #define CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC (0x1 << 14)
105 #define CQ_ENET_RQ_DESC_BYTES_WRITTEN_BITS 14
106 #define CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK \
107 ((1 << CQ_ENET_RQ_DESC_BYTES_WRITTEN_BITS) - 1)
108 #define CQ_ENET_RQ_DESC_FLAGS_TRUNCATED (0x1 << 14)
109 #define CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED (0x1 << 15)
111 #define CQ_ENET_RQ_DESC_VLAN_TCI_VLAN_BITS 12
112 #define CQ_ENET_RQ_DESC_VLAN_TCI_VLAN_MASK \
113 ((1 << CQ_ENET_RQ_DESC_VLAN_TCI_VLAN_BITS) - 1)
114 #define CQ_ENET_RQ_DESC_VLAN_TCI_CFI_MASK (0x1 << 12)
115 #define CQ_ENET_RQ_DESC_VLAN_TCI_USER_PRIO_BITS 3
116 #define CQ_ENET_RQ_DESC_VLAN_TCI_USER_PRIO_MASK \
117 ((1 << CQ_ENET_RQ_DESC_VLAN_TCI_USER_PRIO_BITS) - 1)
118 #define CQ_ENET_RQ_DESC_VLAN_TCI_USER_PRIO_SHIFT 13
120 #define CQ_ENET_RQ_DESC_FCOE_SOF_BITS 8
121 #define CQ_ENET_RQ_DESC_FCOE_SOF_MASK \
122 ((1 << CQ_ENET_RQ_DESC_FCOE_SOF_BITS) - 1)
123 #define CQ_ENET_RQ_DESC_FCOE_EOF_BITS 8
124 #define CQ_ENET_RQ_DESC_FCOE_EOF_MASK \
125 ((1 << CQ_ENET_RQ_DESC_FCOE_EOF_BITS) - 1)
126 #define CQ_ENET_RQ_DESC_FCOE_EOF_SHIFT 8
128 #define CQ_ENET_RQ_DESC_FLAGS_TCP_UDP_CSUM_OK (0x1 << 0)
129 #define CQ_ENET_RQ_DESC_FCOE_FC_CRC_OK (0x1 << 0)
130 #define CQ_ENET_RQ_DESC_FLAGS_UDP (0x1 << 1)
131 #define CQ_ENET_RQ_DESC_FCOE_ENC_ERROR (0x1 << 1)
132 #define CQ_ENET_RQ_DESC_FLAGS_TCP (0x1 << 2)
133 #define CQ_ENET_RQ_DESC_FLAGS_IPV4_CSUM_OK (0x1 << 3)
134 #define CQ_ENET_RQ_DESC_FLAGS_IPV6 (0x1 << 4)
135 #define CQ_ENET_RQ_DESC_FLAGS_IPV4 (0x1 << 5)
136 #define CQ_ENET_RQ_DESC_FLAGS_IPV4_FRAGMENT (0x1 << 6)
137 #define CQ_ENET_RQ_DESC_FLAGS_FCS_OK (0x1 << 7)
139 static inline void cq_enet_rq_desc_enc(struct cq_enet_rq_desc *desc,
140 u8 type, u8 color, u16 q_number, u16 completed_index,
141 u8 ingress_port, u8 fcoe, u8 eop, u8 sop, u8 rss_type, u8 csum_not_calc,
142 u32 rss_hash, u16 bytes_written, u8 packet_error, u8 vlan_stripped,
143 u16 vlan, u16 checksum, u8 fcoe_sof, u8 fcoe_fc_crc_ok,
144 u8 fcoe_enc_error, u8 fcoe_eof, u8 tcp_udp_csum_ok, u8 udp, u8 tcp,
145 u8 ipv4_csum_ok, u8 ipv6, u8 ipv4, u8 ipv4_fragment, u8 fcs_ok)
147 cq_desc_enc((struct cq_desc *)desc, type,
148 color, q_number, completed_index);
150 desc->completed_index_flags |= cpu_to_le16(
151 (ingress_port ? CQ_ENET_RQ_DESC_FLAGS_INGRESS_PORT : 0) |
152 (fcoe ? CQ_ENET_RQ_DESC_FLAGS_FCOE : 0) |
153 (eop ? CQ_ENET_RQ_DESC_FLAGS_EOP : 0) |
154 (sop ? CQ_ENET_RQ_DESC_FLAGS_SOP : 0));
156 desc->q_number_rss_type_flags |= cpu_to_le16(
157 ((rss_type & CQ_ENET_RQ_DESC_RSS_TYPE_MASK) <<
158 CQ_DESC_Q_NUM_BITS) |
159 (csum_not_calc ? CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC : 0));
161 desc->rss_hash = cpu_to_le32(rss_hash);
163 desc->bytes_written_flags = cpu_to_le16(
164 (bytes_written & CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK) |
165 (packet_error ? CQ_ENET_RQ_DESC_FLAGS_TRUNCATED : 0) |
166 (vlan_stripped ? CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED : 0));
168 desc->vlan = cpu_to_le16(vlan);
171 desc->checksum_fcoe = cpu_to_le16(
172 (fcoe_sof & CQ_ENET_RQ_DESC_FCOE_SOF_MASK) |
173 ((fcoe_eof & CQ_ENET_RQ_DESC_FCOE_EOF_MASK) <<
174 CQ_ENET_RQ_DESC_FCOE_EOF_SHIFT));
176 desc->checksum_fcoe = cpu_to_le16(checksum);
180 (tcp_udp_csum_ok ? CQ_ENET_RQ_DESC_FLAGS_TCP_UDP_CSUM_OK : 0) |
181 (udp ? CQ_ENET_RQ_DESC_FLAGS_UDP : 0) |
182 (tcp ? CQ_ENET_RQ_DESC_FLAGS_TCP : 0) |
183 (ipv4_csum_ok ? CQ_ENET_RQ_DESC_FLAGS_IPV4_CSUM_OK : 0) |
184 (ipv6 ? CQ_ENET_RQ_DESC_FLAGS_IPV6 : 0) |
185 (ipv4 ? CQ_ENET_RQ_DESC_FLAGS_IPV4 : 0) |
186 (ipv4_fragment ? CQ_ENET_RQ_DESC_FLAGS_IPV4_FRAGMENT : 0) |
187 (fcs_ok ? CQ_ENET_RQ_DESC_FLAGS_FCS_OK : 0) |
188 (fcoe_fc_crc_ok ? CQ_ENET_RQ_DESC_FCOE_FC_CRC_OK : 0) |
189 (fcoe_enc_error ? CQ_ENET_RQ_DESC_FCOE_ENC_ERROR : 0);
192 static inline void cq_enet_rq_desc_dec(struct cq_enet_rq_desc *desc,
193 u8 *type, u8 *color, u16 *q_number, u16 *completed_index,
194 u8 *ingress_port, u8 *fcoe, u8 *eop, u8 *sop, u8 *rss_type,
195 u8 *csum_not_calc, u32 *rss_hash, u16 *bytes_written, u8 *packet_error,
196 u8 *vlan_stripped, u16 *vlan_tci, u16 *checksum, u8 *fcoe_sof,
197 u8 *fcoe_fc_crc_ok, u8 *fcoe_enc_error, u8 *fcoe_eof,
198 u8 *tcp_udp_csum_ok, u8 *udp, u8 *tcp, u8 *ipv4_csum_ok,
199 u8 *ipv6, u8 *ipv4, u8 *ipv4_fragment, u8 *fcs_ok)
201 u16 completed_index_flags;
202 u16 q_number_rss_type_flags;
203 u16 bytes_written_flags;
205 cq_desc_dec((struct cq_desc *)desc, type,
206 color, q_number, completed_index);
208 completed_index_flags = le16_to_cpu(desc->completed_index_flags);
209 q_number_rss_type_flags =
210 le16_to_cpu(desc->q_number_rss_type_flags);
211 bytes_written_flags = le16_to_cpu(desc->bytes_written_flags);
213 *ingress_port = (completed_index_flags &
214 CQ_ENET_RQ_DESC_FLAGS_INGRESS_PORT) ? 1 : 0;
215 *fcoe = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_FCOE) ?
217 *eop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_EOP) ?
219 *sop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_SOP) ?
222 *rss_type = (u8)((q_number_rss_type_flags >> CQ_DESC_Q_NUM_BITS) &
223 CQ_ENET_RQ_DESC_RSS_TYPE_MASK);
224 *csum_not_calc = (q_number_rss_type_flags &
225 CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC) ? 1 : 0;
227 *rss_hash = le32_to_cpu(desc->rss_hash);
229 *bytes_written = bytes_written_flags &
230 CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK;
231 *packet_error = (bytes_written_flags &
232 CQ_ENET_RQ_DESC_FLAGS_TRUNCATED) ? 1 : 0;
233 *vlan_stripped = (bytes_written_flags &
234 CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED) ? 1 : 0;
237 * Tag Control Information(16) = user_priority(3) + cfi(1) + vlan(12)
239 *vlan_tci = le16_to_cpu(desc->vlan);
242 *fcoe_sof = (u8)(le16_to_cpu(desc->checksum_fcoe) &
243 CQ_ENET_RQ_DESC_FCOE_SOF_MASK);
244 *fcoe_fc_crc_ok = (desc->flags &
245 CQ_ENET_RQ_DESC_FCOE_FC_CRC_OK) ? 1 : 0;
246 *fcoe_enc_error = (desc->flags &
247 CQ_ENET_RQ_DESC_FCOE_ENC_ERROR) ? 1 : 0;
248 *fcoe_eof = (u8)((le16_to_cpu(desc->checksum_fcoe) >>
249 CQ_ENET_RQ_DESC_FCOE_EOF_SHIFT) &
250 CQ_ENET_RQ_DESC_FCOE_EOF_MASK);
257 *checksum = le16_to_cpu(desc->checksum_fcoe);
261 (desc->flags & CQ_ENET_RQ_DESC_FLAGS_TCP_UDP_CSUM_OK) ? 1 : 0;
262 *udp = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_UDP) ? 1 : 0;
263 *tcp = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_TCP) ? 1 : 0;
265 (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4_CSUM_OK) ? 1 : 0;
266 *ipv6 = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV6) ? 1 : 0;
267 *ipv4 = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4) ? 1 : 0;
269 (desc->flags & CQ_ENET_RQ_DESC_FLAGS_IPV4_FRAGMENT) ? 1 : 0;
270 *fcs_ok = (desc->flags & CQ_ENET_RQ_DESC_FLAGS_FCS_OK) ? 1 : 0;
273 #endif /* _CQ_ENET_DESC_H_ */