]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-pip.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-pip.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3  * reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *
13  *   * Redistributions in binary form must reproduce the above
14  *     copyright notice, this list of conditions and the following
15  *     disclaimer in the documentation and/or other materials provided
16  *     with the distribution.
17
18  *   * Neither the name of Cavium Networks nor the names of
19  *     its contributors may be used to endorse or promote products
20  *     derived from this software without specific prior written
21  *     permission.
22
23  * This Software, including technical data, may be subject to U.S. export  control
24  * laws, including the U.S. Export Administration Act and its  associated
25  * regulations, and may be subject to export or import  regulations in other
26  * countries.
27
28  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29  * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30  * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31  * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32  * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33  * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34  * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35  * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36  * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37  * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38  ***********************license end**************************************/
39
40
41 /**
42  * @file
43  *
44  * Interface to the hardware Packet Input Processing unit.
45  *
46  * <hr>$Revision: 49504 $<hr>
47  */
48
49
50 #ifndef __CVMX_PIP_H__
51 #define __CVMX_PIP_H__
52
53 #include "cvmx-wqe.h"
54 #include "cvmx-fpa.h"
55 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
56 #include "cvmx-pip-defs.h"
57 #else
58 #ifndef CVMX_DONT_INCLUDE_CONFIG
59 #include "executive-config.h"
60 #endif
61 #endif
62
63
64 #ifdef  __cplusplus
65 extern "C" {
66 #endif
67
68 #define CVMX_PIP_NUM_INPUT_PORTS                44
69
70 /*
71  * Encodes the different error and exception codes
72  */
73 typedef enum
74 {
75     CVMX_PIP_L4_NO_ERR       = 0ull,
76     /*        1  = TCP (UDP) packet not long enough to cover TCP (UDP) header */
77     CVMX_PIP_L4_MAL_ERR     = 1ull,
78     /*        2  = TCP/UDP checksum failure */
79     CVMX_PIP_CHK_ERR        = 2ull,
80     /*        3  = TCP/UDP length check (TCP/UDP length does not match IP length) */
81     CVMX_PIP_L4_LENGTH_ERR  = 3ull,
82     /*        4  = illegal TCP/UDP port (either source or dest port is zero) */
83     CVMX_PIP_BAD_PRT_ERR    = 4ull,
84     /*        8  = TCP flags = FIN only */
85     CVMX_PIP_TCP_FLG8_ERR   = 8ull,
86     /*        9  = TCP flags = 0 */
87     CVMX_PIP_TCP_FLG9_ERR   = 9ull,
88     /*        10 = TCP flags = FIN+RST+* */
89     CVMX_PIP_TCP_FLG10_ERR  = 10ull,
90     /*        11 = TCP flags = SYN+URG+* */
91     CVMX_PIP_TCP_FLG11_ERR  = 11ull,
92     /*        12 = TCP flags = SYN+RST+* */
93     CVMX_PIP_TCP_FLG12_ERR  = 12ull,
94     /*        13 = TCP flags = SYN+FIN+* */
95     CVMX_PIP_TCP_FLG13_ERR  = 13ull
96 } cvmx_pip_l4_err_t;
97
98 typedef enum
99 {
100
101     CVMX_PIP_IP_NO_ERR      = 0ull,
102     /*        1 = not IPv4 or IPv6 */
103     CVMX_PIP_NOT_IP        = 1ull,
104     /*        2 = IPv4 header checksum violation */
105     CVMX_PIP_IPV4_HDR_CHK  = 2ull,
106     /*        3 = malformed (packet not long enough to cover IP hdr) */
107     CVMX_PIP_IP_MAL_HDR    = 3ull,
108     /*        4 = malformed (packet not long enough to cover len in IP hdr) */
109     CVMX_PIP_IP_MAL_PKT    = 4ull,
110     /*        5 = TTL / hop count equal zero */
111     CVMX_PIP_TTL_HOP       = 5ull,
112     /*        6 = IPv4 options / IPv6 early extension headers */
113     CVMX_PIP_OPTS          = 6ull
114 } cvmx_pip_ip_exc_t;
115
116
117 /**
118  * NOTES
119  *       late collision (data received before collision)
120  *            late collisions cannot be detected by the receiver
121  *            they would appear as JAM bits which would appear as bad FCS
122  *            or carrier extend error which is CVMX_PIP_EXTEND_ERR
123  */
124 typedef enum
125 {
126     /**
127      * No error
128      */
129     CVMX_PIP_RX_NO_ERR      = 0ull,
130
131     CVMX_PIP_PARTIAL_ERR   = 1ull,  /* RGM+SPI            1 = partially received packet (buffering/bandwidth not adequate) */
132     CVMX_PIP_JABBER_ERR    = 2ull,  /* RGM+SPI            2 = receive packet too large and truncated */
133     CVMX_PIP_OVER_FCS_ERR  = 3ull,  /* RGM                3 = max frame error (pkt len > max frame len) (with FCS error) */
134     CVMX_PIP_OVER_ERR      = 4ull,  /* RGM+SPI            4 = max frame error (pkt len > max frame len) */
135     CVMX_PIP_ALIGN_ERR     = 5ull,  /* RGM                5 = nibble error (data not byte multiple - 100M and 10M only) */
136     CVMX_PIP_UNDER_FCS_ERR = 6ull,  /* RGM                6 = min frame error (pkt len < min frame len) (with FCS error) */
137     CVMX_PIP_GMX_FCS_ERR   = 7ull,  /* RGM                7 = FCS error */
138     CVMX_PIP_UNDER_ERR     = 8ull,  /* RGM+SPI            8 = min frame error (pkt len < min frame len) */
139     CVMX_PIP_EXTEND_ERR    = 9ull,  /* RGM                9 = Frame carrier extend error */
140     CVMX_PIP_TERMINATE_ERR = 9ull,  /* XAUI               9 = Packet was terminated with an idle cycle */
141     CVMX_PIP_LENGTH_ERR    = 10ull, /* RGM               10 = length mismatch (len did not match len in L2 length/type) */
142     CVMX_PIP_DAT_ERR       = 11ull, /* RGM               11 = Frame error (some or all data bits marked err) */
143     CVMX_PIP_DIP_ERR       = 11ull, /*     SPI           11 = DIP4 error */
144     CVMX_PIP_SKIP_ERR      = 12ull, /* RGM               12 = packet was not large enough to pass the skipper - no inspection could occur */
145     CVMX_PIP_NIBBLE_ERR    = 13ull, /* RGM               13 = studder error (data not repeated - 100M and 10M only) */
146     CVMX_PIP_PIP_FCS       = 16L, /* RGM+SPI           16 = FCS error */
147     CVMX_PIP_PIP_SKIP_ERR  = 17L, /* RGM+SPI+PCI       17 = packet was not large enough to pass the skipper - no inspection could occur */
148     CVMX_PIP_PIP_L2_MAL_HDR= 18L, /* RGM+SPI+PCI       18 = malformed l2 (packet not long enough to cover L2 hdr) */
149     CVMX_PIP_PUNY_ERR      = 47L  /* SGMII             47 = PUNY error (packet was 4B or less when FCS stripping is enabled) */
150     /* NOTES
151      *       xx = late collision (data received before collision)
152      *            late collisions cannot be detected by the receiver
153      *            they would appear as JAM bits which would appear as bad FCS
154      *            or carrier extend error which is CVMX_PIP_EXTEND_ERR
155      */
156 } cvmx_pip_rcv_err_t;
157
158 /**
159  * This defines the err_code field errors in the work Q entry
160  */
161 typedef union
162 {
163     cvmx_pip_l4_err_t  l4_err;
164     cvmx_pip_ip_exc_t  ip_exc;
165     cvmx_pip_rcv_err_t rcv_err;
166 } cvmx_pip_err_t;
167
168
169 /**
170  * Status statistics for a port
171  */
172 typedef struct
173 {
174     uint32_t    dropped_octets;         /**< Inbound octets marked to be dropped by the IPD */
175     uint32_t    dropped_packets;        /**< Inbound packets marked to be dropped by the IPD */
176     uint32_t    pci_raw_packets;        /**< RAW PCI Packets received by PIP per port */
177     uint32_t    octets;                 /**< Number of octets processed by PIP */
178     uint32_t    packets;                /**< Number of packets processed by PIP */
179     uint32_t    multicast_packets;      /**< Number of indentified L2 multicast packets.
180                                             Does not include broadcast packets.
181                                             Only includes packets whose parse mode is
182                                             SKIP_TO_L2 */
183     uint32_t    broadcast_packets;      /**< Number of indentified L2 broadcast packets.
184                                             Does not include multicast packets.
185                                             Only includes packets whose parse mode is
186                                             SKIP_TO_L2 */
187     uint32_t    len_64_packets;         /**< Number of 64B packets */
188     uint32_t    len_65_127_packets;     /**< Number of 65-127B packets */
189     uint32_t    len_128_255_packets;    /**< Number of 128-255B packets */
190     uint32_t    len_256_511_packets;    /**< Number of 256-511B packets */
191     uint32_t    len_512_1023_packets;   /**< Number of 512-1023B packets */
192     uint32_t    len_1024_1518_packets;  /**< Number of 1024-1518B packets */
193     uint32_t    len_1519_max_packets;   /**< Number of 1519-max packets */
194     uint32_t    fcs_align_err_packets;  /**< Number of packets with FCS or Align opcode errors */
195     uint32_t    runt_packets;           /**< Number of packets with length < min */
196     uint32_t    runt_crc_packets;       /**< Number of packets with length < min and FCS error */
197     uint32_t    oversize_packets;       /**< Number of packets with length > max */
198     uint32_t    oversize_crc_packets;   /**< Number of packets with length > max and FCS error */
199     uint32_t    inb_packets;            /**< Number of packets without GMX/SPX/PCI errors received by PIP */
200     uint64_t    inb_octets;             /**< Total number of octets from all packets received by PIP, including CRC */
201     uint16_t    inb_errors;             /**< Number of packets with GMX/SPX/PCI errors received by PIP */
202 } cvmx_pip_port_status_t;
203
204
205 /**
206  * Definition of the PIP custom header that can be prepended
207  * to a packet by external hardware.
208  */
209 typedef union
210 {
211     uint64_t    u64;
212     struct
213     {
214         uint64_t                    rawfull     : 1;    /**< Documented as R - Set if the Packet is RAWFULL. If set,
215                                                             this header must be the full 8 bytes */
216         uint64_t                    reserved0   : 5;    /**< Must be zero */
217         cvmx_pip_port_parse_mode_t  parse_mode  : 2;    /**< PIP parse mode for this packet */
218         uint64_t                    reserved1   : 1;    /**< Must be zero */
219         uint64_t                    skip_len    : 7;    /**< Skip amount, including this header, to the beginning of the packet */
220         uint64_t                    reserved2   : 2;    /**< Must be zero */
221         uint64_t                    nqos        : 1;    /**< Must be 0 when PKT_INST_HDR[R] = 0.
222                                                              When set to 1, NQOS prevents PIP from directly using
223                                                              PKT_INST_HDR[QOS] for the QOS value in WQE.
224                                                              When PIP_GBL_CTL[IHMSK_DIS] = 1, Octeon2 does not use NQOS */
225         uint64_t                    ngrp        : 1;    /**< Must be 0 when PKT_INST_HDR[R] = 0.
226                                                              When set to 1, NGPR prevents PIP from directly using
227                                                              PKT_INST_HDR[GPR] for the GPR value in WQE.
228                                                              When PIP_GBL_CTL[IHMSK_DIS] = 1, Octeon2 does not use NGRP */
229         uint64_t                    ntt         : 1;    /**< Must be 0 when PKT_INST_HDR[R] = 0.
230                                                              When set to 1, NTT prevents PIP from directly using
231                                                              PKT_INST_HDR[TT] for the TT value in WQE.
232                                                              When PIP_GBL_CTL[IHMSK_DIS] = 1, Octeon2 does not use NTT */
233         uint64_t                    ntag        : 1;    /**< Must be 0 when PKT_INST_HDR[R] = 0.
234                                                              When set to 1, NTAG prevents PIP from directly using
235                                                              PKT_INST_HDR[TAG] for the TAG value in WQE.
236                                                              When PIP_GBL_CTL[IHMSK_DIS] = 1, Octeon2 does not use NTAG */
237         uint64_t                    qos         : 3;    /**< POW input queue for this packet */
238         uint64_t                    grp         : 4;    /**< POW input group for this packet */
239         uint64_t                    rs          : 1;    /**< Flag to store this packet in the work queue entry, if possible */
240         cvmx_pow_tag_type_t         tag_type    : 2;    /**< POW input tag type */
241         uint64_t                    tag         : 32;   /**< POW input tag */
242     } s;
243 } cvmx_pip_pkt_inst_hdr_t;
244
245 /* CSR typedefs have been moved to cvmx-pip-defs.h */
246
247 /**
248  * Configure an ethernet input port
249  *
250  * @param port_num Port number to configure
251  * @param port_cfg Port hardware configuration
252  * @param port_tag_cfg
253  *                 Port POW tagging configuration
254  */
255 static inline void cvmx_pip_config_port(uint64_t port_num,
256                                         cvmx_pip_prt_cfgx_t port_cfg,
257                                         cvmx_pip_prt_tagx_t port_tag_cfg)
258 {
259     cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
260     cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
261 }
262
263
264 /**
265  * @deprecated      This function is a thin wrapper around the Pass1 version
266  *                  of the CVMX_PIP_QOS_WATCHX CSR; Pass2 has added a field for
267  *                  setting the group that is incompatible with this function,
268  *                  the preferred upgrade path is to use the CSR directly.
269  *
270  * Configure the global QoS packet watchers. Each watcher is
271  * capable of matching a field in a packet to determine the
272  * QoS queue for scheduling.
273  *
274  * @param watcher    Watcher number to configure (0 - 3).
275  * @param match_type Watcher match type
276  * @param match_value
277  *                   Value the watcher will match against
278  * @param qos        QoS queue for packets matching this watcher
279  */
280 static inline void cvmx_pip_config_watcher(uint64_t watcher,
281                                            cvmx_pip_qos_watch_types match_type,
282                                            uint64_t match_value, uint64_t qos)
283 {
284     cvmx_pip_qos_watchx_t watcher_config;
285
286     watcher_config.u64 = 0;
287     watcher_config.s.match_type = match_type;
288     watcher_config.s.match_value = match_value;
289     watcher_config.s.qos = qos;
290
291     cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
292 }
293
294
295 /**
296  * Configure the VLAN priority to QoS queue mapping.
297  *
298  * @param vlan_priority
299  *               VLAN priority (0-7)
300  * @param qos    QoS queue for packets matching this watcher
301  */
302 static inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority, uint64_t qos)
303 {
304     cvmx_pip_qos_vlanx_t pip_qos_vlanx;
305     pip_qos_vlanx.u64 = 0;
306     pip_qos_vlanx.s.qos = qos;
307     cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
308 }
309
310
311 /**
312  * Configure the Diffserv to QoS queue mapping.
313  *
314  * @param diffserv Diffserv field value (0-63)
315  * @param qos      QoS queue for packets matching this watcher
316  */
317 static inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
318 {
319     cvmx_pip_qos_diffx_t pip_qos_diffx;
320     pip_qos_diffx.u64 = 0;
321     pip_qos_diffx.s.qos = qos;
322     cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
323 }
324
325
326 /**
327  * Get the status counters for a port.
328  *
329  * @param port_num Port number to get statistics for.
330  * @param clear    Set to 1 to clear the counters after they are read
331  * @param status   Where to put the results.
332  */
333 static inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear, cvmx_pip_port_status_t *status)
334 {
335     cvmx_pip_stat_ctl_t pip_stat_ctl;
336     cvmx_pip_stat0_prtx_t stat0;
337     cvmx_pip_stat1_prtx_t stat1;
338     cvmx_pip_stat2_prtx_t stat2;
339     cvmx_pip_stat3_prtx_t stat3;
340     cvmx_pip_stat4_prtx_t stat4;
341     cvmx_pip_stat5_prtx_t stat5;
342     cvmx_pip_stat6_prtx_t stat6;
343     cvmx_pip_stat7_prtx_t stat7;
344     cvmx_pip_stat8_prtx_t stat8;
345     cvmx_pip_stat9_prtx_t stat9;
346     cvmx_pip_stat_inb_pktsx_t pip_stat_inb_pktsx;
347     cvmx_pip_stat_inb_octsx_t pip_stat_inb_octsx;
348     cvmx_pip_stat_inb_errsx_t pip_stat_inb_errsx;
349
350     pip_stat_ctl.u64 = 0;
351     pip_stat_ctl.s.rdclr = clear;
352     cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
353
354     if (port_num >= 40)
355     {
356         stat0.u64 = cvmx_read_csr(CVMX_PIP_XSTAT0_PRTX(port_num));
357         stat1.u64 = cvmx_read_csr(CVMX_PIP_XSTAT1_PRTX(port_num));
358         stat2.u64 = cvmx_read_csr(CVMX_PIP_XSTAT2_PRTX(port_num));
359         stat3.u64 = cvmx_read_csr(CVMX_PIP_XSTAT3_PRTX(port_num));
360         stat4.u64 = cvmx_read_csr(CVMX_PIP_XSTAT4_PRTX(port_num));
361         stat5.u64 = cvmx_read_csr(CVMX_PIP_XSTAT5_PRTX(port_num));
362         stat6.u64 = cvmx_read_csr(CVMX_PIP_XSTAT6_PRTX(port_num));
363         stat7.u64 = cvmx_read_csr(CVMX_PIP_XSTAT7_PRTX(port_num));
364         stat8.u64 = cvmx_read_csr(CVMX_PIP_XSTAT8_PRTX(port_num));
365         stat9.u64 = cvmx_read_csr(CVMX_PIP_XSTAT9_PRTX(port_num));
366     }
367     else
368     {
369         stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
370         stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
371         stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
372         stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
373         stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
374         stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
375         stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
376         stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
377         stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
378         stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
379     }
380     pip_stat_inb_pktsx.u64 = cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
381     pip_stat_inb_octsx.u64 = cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
382     pip_stat_inb_errsx.u64 = cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
383
384     status->dropped_octets          = stat0.s.drp_octs;
385     status->dropped_packets         = stat0.s.drp_pkts;
386     status->octets                  = stat1.s.octs;
387     status->pci_raw_packets         = stat2.s.raw;
388     status->packets                 = stat2.s.pkts;
389     status->multicast_packets       = stat3.s.mcst;
390     status->broadcast_packets       = stat3.s.bcst;
391     status->len_64_packets          = stat4.s.h64;
392     status->len_65_127_packets      = stat4.s.h65to127;
393     status->len_128_255_packets     = stat5.s.h128to255;
394     status->len_256_511_packets     = stat5.s.h256to511;
395     status->len_512_1023_packets    = stat6.s.h512to1023;
396     status->len_1024_1518_packets   = stat6.s.h1024to1518;
397     status->len_1519_max_packets    = stat7.s.h1519;
398     status->fcs_align_err_packets   = stat7.s.fcs;
399     status->runt_packets            = stat8.s.undersz;
400     status->runt_crc_packets        = stat8.s.frag;
401     status->oversize_packets        = stat9.s.oversz;
402     status->oversize_crc_packets    = stat9.s.jabber;
403     status->inb_packets             = pip_stat_inb_pktsx.s.pkts;
404     status->inb_octets              = pip_stat_inb_octsx.s.octs;
405     status->inb_errors              = pip_stat_inb_errsx.s.errs;
406
407 }
408
409
410 /**
411  * Configure the hardware CRC engine
412  *
413  * @param interface Interface to configure (0 or 1)
414  * @param invert_result
415  *                 Invert the result of the CRC
416  * @param reflect  Reflect
417  * @param initialization_vector
418  *                 CRC initialization vector
419  */
420 static inline void cvmx_pip_config_crc(uint64_t interface, uint64_t invert_result, uint64_t reflect, uint32_t initialization_vector)
421 {
422     if ((OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)))
423     {
424         cvmx_pip_crc_ctlx_t config;
425         cvmx_pip_crc_ivx_t pip_crc_ivx;
426
427         config.u64 = 0;
428         config.s.invres = invert_result;
429         config.s.reflect = reflect;
430         cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
431
432         pip_crc_ivx.u64 = 0;
433         pip_crc_ivx.s.iv = initialization_vector;
434         cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
435     }
436 }
437
438
439 /**
440  * Clear all bits in a tag mask. This should be called on
441  * startup before any calls to cvmx_pip_tag_mask_set. Each bit
442  * set in the final mask represent a byte used in the packet for
443  * tag generation.
444  *
445  * @param mask_index Which tag mask to clear (0..3)
446  */
447 static inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
448 {
449     uint64_t index;
450     cvmx_pip_tag_incx_t pip_tag_incx;
451     pip_tag_incx.u64 = 0;
452     pip_tag_incx.s.en = 0;
453     for (index=mask_index*16; index<(mask_index+1)*16; index++)
454         cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
455 }
456
457
458 /**
459  * Sets a range of bits in the tag mask. The tag mask is used
460  * when the cvmx_pip_port_tag_cfg_t tag_mode is non zero.
461  * There are four separate masks that can be configured.
462  *
463  * @param mask_index Which tag mask to modify (0..3)
464  * @param offset     Offset into the bitmask to set bits at. Use the GCC macro
465  *                   offsetof() to determine the offsets into packet headers.
466  *                   For example, offsetof(ethhdr, protocol) returns the offset
467  *                   of the ethernet protocol field.  The bitmask selects which bytes
468  *                   to include the the tag, with bit offset X selecting byte at offset X
469  *                   from the beginning of the packet data.
470  * @param len        Number of bytes to include. Usually this is the sizeof()
471  *                   the field.
472  */
473 static inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset, uint64_t len)
474 {
475     while (len--)
476     {
477         cvmx_pip_tag_incx_t pip_tag_incx;
478         uint64_t index = mask_index*16 + offset/8;
479         pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
480         pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
481         cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
482         offset++;
483     }
484 }
485
486 #ifdef  __cplusplus
487 }
488 #endif
489
490 #endif  /*  __CVMX_PIP_H__ */