Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cvmx-pip.h
Go to the documentation of this file.
1 /***********************license start***************
2  * Author: Cavium Networks
3  *
4  * Contact: [email protected]
5  * This file is part of the OCTEON SDK
6  *
7  * Copyright (c) 2003-2008 Cavium Networks
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this file; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  * or visit http://www.gnu.org/licenses/.
23  *
24  * This file may also be available under a different license from Cavium.
25  * Contact Cavium Networks for more information
26  ***********************license end**************************************/
27 
28 /*
29  * Interface to the hardware Packet Input Processing unit.
30  *
31  */
32 
33 #ifndef __CVMX_PIP_H__
34 #define __CVMX_PIP_H__
35 
36 #include <asm/octeon/cvmx-wqe.h>
37 #include <asm/octeon/cvmx-fpa.h>
39 
40 #define CVMX_PIP_NUM_INPUT_PORTS 40
41 #define CVMX_PIP_NUM_WATCHERS 4
42 
43 /*
44  * Encodes the different error and exception codes
45  */
46 typedef enum {
48  /*
49  * 1 = TCP (UDP) packet not long enough to cover TCP (UDP)
50  * header
51  */
53  /* 2 = TCP/UDP checksum failure */
55  /*
56  * 3 = TCP/UDP length check (TCP/UDP length does not match IP
57  * length).
58  */
60  /* 4 = illegal TCP/UDP port (either source or dest port is zero) */
62  /* 8 = TCP flags = FIN only */
64  /* 9 = TCP flags = 0 */
66  /* 10 = TCP flags = FIN+RST+* */
68  /* 11 = TCP flags = SYN+URG+* */
70  /* 12 = TCP flags = SYN+RST+* */
72  /* 13 = TCP flags = SYN+FIN+* */
75 
76 typedef enum {
77 
79  /* 1 = not IPv4 or IPv6 */
81  /* 2 = IPv4 header checksum violation */
83  /* 3 = malformed (packet not long enough to cover IP hdr) */
85  /* 4 = malformed (packet not long enough to cover len in IP hdr) */
87  /* 5 = TTL / hop count equal zero */
89  /* 6 = IPv4 options / IPv6 early extension headers */
92 
100 typedef enum {
101  /* No error */
103  /* RGM+SPI 1 = partially received packet (buffering/bandwidth
104  * not adequate) */
106  /* RGM+SPI 2 = receive packet too large and truncated */
108  /*
109  * RGM 3 = max frame error (pkt len > max frame len) (with FCS
110  * error)
111  */
113  /* RGM+SPI 4 = max frame error (pkt len > max frame len) */
115  /*
116  * RGM 5 = nibble error (data not byte multiple - 100M and 10M
117  * only)
118  */
120  /*
121  * RGM 6 = min frame error (pkt len < min frame len) (with FCS
122  * error)
123  */
125  /* RGM 7 = FCS error */
127  /* RGM+SPI 8 = min frame error (pkt len < min frame len) */
129  /* RGM 9 = Frame carrier extend error */
131  /*
132  * RGM 10 = length mismatch (len did not match len in L2
133  * length/type)
134  */
136  /* RGM 11 = Frame error (some or all data bits marked err) */
138  /* SPI 11 = DIP4 error */
140  /*
141  * RGM 12 = packet was not large enough to pass the skipper -
142  * no inspection could occur.
143  */
145  /*
146  * RGM 13 = studder error (data not repeated - 100M and 10M
147  * only)
148  */
150  /* RGM+SPI 16 = FCS error */
152  /*
153  * RGM+SPI+PCI 17 = packet was not large enough to pass the
154  * skipper - no inspection could occur.
155  */
157  /*
158  * RGM+SPI+PCI 18 = malformed l2 (packet not long enough to
159  * cover L2 hdr).
160  */
162  /*
163  * NOTES: xx = late collision (data received before collision)
164  * late collisions cannot be detected by the receiver
165  * they would appear as JAM bits which would appear as
166  * bad FCS or carrier extend error which is
167  * CVMX_PIP_EXTEND_ERR
168  */
170 
174 typedef union {
179 
183 typedef struct {
184  /* Inbound octets marked to be dropped by the IPD */
186  /* Inbound packets marked to be dropped by the IPD */
188  /* RAW PCI Packets received by PIP per port */
190  /* Number of octets processed by PIP */
192  /* Number of packets processed by PIP */
194  /*
195  * Number of indentified L2 multicast packets. Does not
196  * include broadcast packets. Only includes packets whose
197  * parse mode is SKIP_TO_L2
198  */
200  /*
201  * Number of indentified L2 broadcast packets. Does not
202  * include multicast packets. Only includes packets whose
203  * parse mode is SKIP_TO_L2
204  */
206  /* Number of 64B packets */
208  /* Number of 65-127B packets */
210  /* Number of 128-255B packets */
212  /* Number of 256-511B packets */
214  /* Number of 512-1023B packets */
216  /* Number of 1024-1518B packets */
218  /* Number of 1519-max packets */
220  /* Number of packets with FCS or Align opcode errors */
222  /* Number of packets with length < min */
224  /* Number of packets with length < min and FCS error */
226  /* Number of packets with length > max */
228  /* Number of packets with length > max and FCS error */
230  /* Number of packets without GMX/SPX/PCI errors received by PIP */
232  /*
233  * Total number of octets from all packets received by PIP,
234  * including CRC
235  */
237  /* Number of packets with GMX/SPX/PCI errors received by PIP */
240 
245 typedef union {
247  struct {
248  /*
249  * Documented as R - Set if the Packet is RAWFULL. If
250  * set, this header must be the full 8 bytes.
251  */
252  uint64_t rawfull:1;
253  /* Must be zero */
255  /* PIP parse mode for this packet */
256  uint64_t parse_mode:2;
257  /* Must be zero */
259  /*
260  * Skip amount, including this header, to the
261  * beginning of the packet
262  */
263  uint64_t skip_len:7;
264  /* Must be zero */
266  /* POW input queue for this packet */
267  uint64_t qos:3;
268  /* POW input group for this packet */
269  uint64_t grp:4;
270  /*
271  * Flag to store this packet in the work queue entry,
272  * if possible
273  */
275  /* POW input tag type */
277  /* POW input tag */
279  } s;
281 
282 /* CSR typedefs have been moved to cvmx-csr-*.h */
283 
292 static inline void cvmx_pip_config_port(uint64_t port_num,
294  union cvmx_pip_prt_tagx port_tag_cfg)
295 {
296  cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
297  cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
298 }
299 #if 0
300 
316 static inline void cvmx_pip_config_watcher(uint64_t watcher,
317  cvmx_pip_qos_watch_types match_type,
318  uint64_t match_value, uint64_t qos)
319 {
320  cvmx_pip_port_watcher_cfg_t watcher_config;
321 
322  watcher_config.u64 = 0;
323  watcher_config.s.match_type = match_type;
324  watcher_config.s.match_value = match_value;
325  watcher_config.s.qos = qos;
326 
327  cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
328 }
329 #endif
330 
337 static inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority,
338  uint64_t qos)
339 {
340  union cvmx_pip_qos_vlanx pip_qos_vlanx;
341  pip_qos_vlanx.u64 = 0;
342  pip_qos_vlanx.s.qos = qos;
343  cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
344 }
345 
352 static inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
353 {
354  union cvmx_pip_qos_diffx pip_qos_diffx;
355  pip_qos_diffx.u64 = 0;
356  pip_qos_diffx.s.qos = qos;
357  cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
358 }
359 
367 static inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear,
369 {
370  union cvmx_pip_stat_ctl pip_stat_ctl;
371  union cvmx_pip_stat0_prtx stat0;
372  union cvmx_pip_stat1_prtx stat1;
373  union cvmx_pip_stat2_prtx stat2;
374  union cvmx_pip_stat3_prtx stat3;
375  union cvmx_pip_stat4_prtx stat4;
376  union cvmx_pip_stat5_prtx stat5;
377  union cvmx_pip_stat6_prtx stat6;
378  union cvmx_pip_stat7_prtx stat7;
379  union cvmx_pip_stat8_prtx stat8;
380  union cvmx_pip_stat9_prtx stat9;
381  union cvmx_pip_stat_inb_pktsx pip_stat_inb_pktsx;
382  union cvmx_pip_stat_inb_octsx pip_stat_inb_octsx;
383  union cvmx_pip_stat_inb_errsx pip_stat_inb_errsx;
384 
385  pip_stat_ctl.u64 = 0;
386  pip_stat_ctl.s.rdclr = clear;
387  cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
388 
389  stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
390  stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
391  stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
392  stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
393  stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
394  stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
395  stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
396  stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
397  stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
398  stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
399  pip_stat_inb_pktsx.u64 =
400  cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
401  pip_stat_inb_octsx.u64 =
402  cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
403  pip_stat_inb_errsx.u64 =
404  cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
405 
406  status->dropped_octets = stat0.s.drp_octs;
407  status->dropped_packets = stat0.s.drp_pkts;
408  status->octets = stat1.s.octs;
409  status->pci_raw_packets = stat2.s.raw;
410  status->packets = stat2.s.pkts;
411  status->multicast_packets = stat3.s.mcst;
412  status->broadcast_packets = stat3.s.bcst;
413  status->len_64_packets = stat4.s.h64;
414  status->len_65_127_packets = stat4.s.h65to127;
415  status->len_128_255_packets = stat5.s.h128to255;
416  status->len_256_511_packets = stat5.s.h256to511;
417  status->len_512_1023_packets = stat6.s.h512to1023;
418  status->len_1024_1518_packets = stat6.s.h1024to1518;
419  status->len_1519_max_packets = stat7.s.h1519;
420  status->fcs_align_err_packets = stat7.s.fcs;
421  status->runt_packets = stat8.s.undersz;
422  status->runt_crc_packets = stat8.s.frag;
423  status->oversize_packets = stat9.s.oversz;
424  status->oversize_crc_packets = stat9.s.jabber;
425  status->inb_packets = pip_stat_inb_pktsx.s.pkts;
426  status->inb_octets = pip_stat_inb_octsx.s.octs;
427  status->inb_errors = pip_stat_inb_errsx.s.errs;
428 
429  if (cvmx_octeon_is_pass1()) {
430  /*
431  * Kludge to fix Octeon Pass 1 errata - Drop counts
432  * don't work.
433  */
434  if (status->inb_packets > status->packets)
435  status->dropped_packets =
436  status->inb_packets - status->packets;
437  else
438  status->dropped_packets = 0;
439  if (status->inb_octets - status->inb_packets * 4 >
440  status->octets)
441  status->dropped_octets =
442  status->inb_octets - status->inb_packets * 4 -
443  status->octets;
444  else
445  status->dropped_octets = 0;
446  }
447 }
448 
459 static inline void cvmx_pip_config_crc(uint64_t interface,
460  uint64_t invert_result, uint64_t reflect,
461  uint32_t initialization_vector)
462 {
465  union cvmx_pip_crc_ivx pip_crc_ivx;
466 
467  config.u64 = 0;
468  config.s.invres = invert_result;
469  config.s.reflect = reflect;
470  cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
471 
472  pip_crc_ivx.u64 = 0;
473  pip_crc_ivx.s.iv = initialization_vector;
474  cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
475  }
476 }
477 
486 static inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
487 {
488  uint64_t index;
489  union cvmx_pip_tag_incx pip_tag_incx;
490  pip_tag_incx.u64 = 0;
491  pip_tag_incx.s.en = 0;
492  for (index = mask_index * 16; index < (mask_index + 1) * 16; index++)
493  cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
494 }
495 
511 static inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset,
512  uint64_t len)
513 {
514  while (len--) {
515  union cvmx_pip_tag_incx pip_tag_incx;
516  uint64_t index = mask_index * 16 + offset / 8;
517  pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
518  pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
519  cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
520  offset++;
521  }
522 }
523 
524 #endif /* __CVMX_PIP_H__ */