e8410563a708e8c8bf7ec757b74aee56c3392c18
[deb_dpdk.git] / drivers / net / enic / base / cq_enet_desc.h
1 /*
2  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
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
18  * distribution.
19  *
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.
32  *
33  */
34
35 #ifndef _CQ_ENET_DESC_H_
36 #define _CQ_ENET_DESC_H_
37
38 #include "cq_desc.h"
39
40 /* Ethernet completion queue descriptor: 16B */
41 struct cq_enet_wq_desc {
42         __le16 completed_index;
43         __le16 q_number;
44         u8 reserved[11];
45         u8 type_color;
46 };
47
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)
50 {
51         cq_desc_enc((struct cq_desc *)desc, type,
52                 color, q_number, completed_index);
53 }
54
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)
57 {
58         cq_desc_dec((struct cq_desc *)desc, type,
59                 color, q_number, completed_index);
60 }
61
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;
66         __le32 rss_hash;
67         __le16 bytes_written_flags;
68         __le16 vlan;
69         __le16 checksum_fcoe;
70         u8 flags;
71         u8 type_color;
72 };
73
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;
78         __le16 filter_id;
79         __le16 lif;
80         __le16 bytes_written_flags;
81         __le16 vlan;
82         __le16 checksum_fcoe;
83         u8 flags;
84         u8 type_color;
85 };
86
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)
91
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
102
103 #define CQ_ENET_RQ_DESC_FLAGS_CSUM_NOT_CALC         (0x1 << 14)
104
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)
110
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
119
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
127
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)
138
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)
146 {
147         cq_desc_enc((struct cq_desc *)desc, type,
148                 color, q_number, completed_index);
149
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));
155
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));
160
161         desc->rss_hash = cpu_to_le32(rss_hash);
162
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));
167
168         desc->vlan = cpu_to_le16(vlan);
169
170         if (fcoe) {
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));
175         } else {
176                 desc->checksum_fcoe = cpu_to_le16(checksum);
177         }
178
179         desc->flags =
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);
190 }
191
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)
200 {
201         u16 completed_index_flags;
202         u16 q_number_rss_type_flags;
203         u16 bytes_written_flags;
204
205         cq_desc_dec((struct cq_desc *)desc, type,
206                 color, q_number, completed_index);
207
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);
212
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) ?
216                 1 : 0;
217         *eop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_EOP) ?
218                 1 : 0;
219         *sop = (completed_index_flags & CQ_ENET_RQ_DESC_FLAGS_SOP) ?
220                 1 : 0;
221
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;
226
227         *rss_hash = le32_to_cpu(desc->rss_hash);
228
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;
235
236         /*
237          * Tag Control Information(16) = user_priority(3) + cfi(1) + vlan(12)
238          */
239         *vlan_tci = le16_to_cpu(desc->vlan);
240
241         if (*fcoe) {
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);
251                 *checksum = 0;
252         } else {
253                 *fcoe_sof = 0;
254                 *fcoe_fc_crc_ok = 0;
255                 *fcoe_enc_error = 0;
256                 *fcoe_eof = 0;
257                 *checksum = le16_to_cpu(desc->checksum_fcoe);
258         }
259
260         *tcp_udp_csum_ok =
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;
264         *ipv4_csum_ok =
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;
268         *ipv4_fragment =
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;
271 }
272
273 #endif /* _CQ_ENET_DESC_H_ */