cvmx-pip.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  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. * Interface to the hardware Packet Input Processing unit.
  29. *
  30. */
  31. #ifndef __CVMX_PIP_H__
  32. #define __CVMX_PIP_H__
  33. #include "cvmx-wqe.h"
  34. #include "cvmx-fpa.h"
  35. #include "cvmx-pip-defs.h"
  36. #define CVMX_PIP_NUM_INPUT_PORTS 40
  37. #define CVMX_PIP_NUM_WATCHERS 4
  38. /*
  39. * Encodes the different error and exception codes
  40. */
  41. typedef enum {
  42. CVMX_PIP_L4_NO_ERR = 0ull,
  43. /*
  44. * 1 = TCP (UDP) packet not long enough to cover TCP (UDP)
  45. * header
  46. */
  47. CVMX_PIP_L4_MAL_ERR = 1ull,
  48. /* 2 = TCP/UDP checksum failure */
  49. CVMX_PIP_CHK_ERR = 2ull,
  50. /*
  51. * 3 = TCP/UDP length check (TCP/UDP length does not match IP
  52. * length).
  53. */
  54. CVMX_PIP_L4_LENGTH_ERR = 3ull,
  55. /* 4 = illegal TCP/UDP port (either source or dest port is zero) */
  56. CVMX_PIP_BAD_PRT_ERR = 4ull,
  57. /* 8 = TCP flags = FIN only */
  58. CVMX_PIP_TCP_FLG8_ERR = 8ull,
  59. /* 9 = TCP flags = 0 */
  60. CVMX_PIP_TCP_FLG9_ERR = 9ull,
  61. /* 10 = TCP flags = FIN+RST+* */
  62. CVMX_PIP_TCP_FLG10_ERR = 10ull,
  63. /* 11 = TCP flags = SYN+URG+* */
  64. CVMX_PIP_TCP_FLG11_ERR = 11ull,
  65. /* 12 = TCP flags = SYN+RST+* */
  66. CVMX_PIP_TCP_FLG12_ERR = 12ull,
  67. /* 13 = TCP flags = SYN+FIN+* */
  68. CVMX_PIP_TCP_FLG13_ERR = 13ull
  69. } cvmx_pip_l4_err_t;
  70. typedef enum {
  71. CVMX_PIP_IP_NO_ERR = 0ull,
  72. /* 1 = not IPv4 or IPv6 */
  73. CVMX_PIP_NOT_IP = 1ull,
  74. /* 2 = IPv4 header checksum violation */
  75. CVMX_PIP_IPV4_HDR_CHK = 2ull,
  76. /* 3 = malformed (packet not long enough to cover IP hdr) */
  77. CVMX_PIP_IP_MAL_HDR = 3ull,
  78. /* 4 = malformed (packet not long enough to cover len in IP hdr) */
  79. CVMX_PIP_IP_MAL_PKT = 4ull,
  80. /* 5 = TTL / hop count equal zero */
  81. CVMX_PIP_TTL_HOP = 5ull,
  82. /* 6 = IPv4 options / IPv6 early extension headers */
  83. CVMX_PIP_OPTS = 6ull
  84. } cvmx_pip_ip_exc_t;
  85. /**
  86. * NOTES
  87. * late collision (data received before collision)
  88. * late collisions cannot be detected by the receiver
  89. * they would appear as JAM bits which would appear as bad FCS
  90. * or carrier extend error which is CVMX_PIP_EXTEND_ERR
  91. */
  92. typedef enum {
  93. /* No error */
  94. CVMX_PIP_RX_NO_ERR = 0ull,
  95. /* RGM+SPI 1 = partially received packet (buffering/bandwidth
  96. * not adequate) */
  97. CVMX_PIP_PARTIAL_ERR = 1ull,
  98. /* RGM+SPI 2 = receive packet too large and truncated */
  99. CVMX_PIP_JABBER_ERR = 2ull,
  100. /*
  101. * RGM 3 = max frame error (pkt len > max frame len) (with FCS
  102. * error)
  103. */
  104. CVMX_PIP_OVER_FCS_ERR = 3ull,
  105. /* RGM+SPI 4 = max frame error (pkt len > max frame len) */
  106. CVMX_PIP_OVER_ERR = 4ull,
  107. /*
  108. * RGM 5 = nibble error (data not byte multiple - 100M and 10M
  109. * only)
  110. */
  111. CVMX_PIP_ALIGN_ERR = 5ull,
  112. /*
  113. * RGM 6 = min frame error (pkt len < min frame len) (with FCS
  114. * error)
  115. */
  116. CVMX_PIP_UNDER_FCS_ERR = 6ull,
  117. /* RGM 7 = FCS error */
  118. CVMX_PIP_GMX_FCS_ERR = 7ull,
  119. /* RGM+SPI 8 = min frame error (pkt len < min frame len) */
  120. CVMX_PIP_UNDER_ERR = 8ull,
  121. /* RGM 9 = Frame carrier extend error */
  122. CVMX_PIP_EXTEND_ERR = 9ull,
  123. /*
  124. * RGM 10 = length mismatch (len did not match len in L2
  125. * length/type)
  126. */
  127. CVMX_PIP_LENGTH_ERR = 10ull,
  128. /* RGM 11 = Frame error (some or all data bits marked err) */
  129. CVMX_PIP_DAT_ERR = 11ull,
  130. /* SPI 11 = DIP4 error */
  131. CVMX_PIP_DIP_ERR = 11ull,
  132. /*
  133. * RGM 12 = packet was not large enough to pass the skipper -
  134. * no inspection could occur.
  135. */
  136. CVMX_PIP_SKIP_ERR = 12ull,
  137. /*
  138. * RGM 13 = studder error (data not repeated - 100M and 10M
  139. * only)
  140. */
  141. CVMX_PIP_NIBBLE_ERR = 13ull,
  142. /* RGM+SPI 16 = FCS error */
  143. CVMX_PIP_PIP_FCS = 16L,
  144. /*
  145. * RGM+SPI+PCI 17 = packet was not large enough to pass the
  146. * skipper - no inspection could occur.
  147. */
  148. CVMX_PIP_PIP_SKIP_ERR = 17L,
  149. /*
  150. * RGM+SPI+PCI 18 = malformed l2 (packet not long enough to
  151. * cover L2 hdr).
  152. */
  153. CVMX_PIP_PIP_L2_MAL_HDR = 18L
  154. /*
  155. * NOTES: xx = late collision (data received before collision)
  156. * late collisions cannot be detected by the receiver
  157. * they would appear as JAM bits which would appear as
  158. * bad FCS or carrier extend error which is
  159. * CVMX_PIP_EXTEND_ERR
  160. */
  161. } cvmx_pip_rcv_err_t;
  162. /**
  163. * This defines the err_code field errors in the work Q entry
  164. */
  165. typedef union {
  166. cvmx_pip_l4_err_t l4_err;
  167. cvmx_pip_ip_exc_t ip_exc;
  168. cvmx_pip_rcv_err_t rcv_err;
  169. } cvmx_pip_err_t;
  170. /**
  171. * Status statistics for a port
  172. */
  173. typedef struct {
  174. /* Inbound octets marked to be dropped by the IPD */
  175. uint32_t dropped_octets;
  176. /* Inbound packets marked to be dropped by the IPD */
  177. uint32_t dropped_packets;
  178. /* RAW PCI Packets received by PIP per port */
  179. uint32_t pci_raw_packets;
  180. /* Number of octets processed by PIP */
  181. uint32_t octets;
  182. /* Number of packets processed by PIP */
  183. uint32_t packets;
  184. /*
  185. * Number of indentified L2 multicast packets. Does not
  186. * include broadcast packets. Only includes packets whose
  187. * parse mode is SKIP_TO_L2
  188. */
  189. uint32_t multicast_packets;
  190. /*
  191. * Number of indentified L2 broadcast packets. Does not
  192. * include multicast packets. Only includes packets whose
  193. * parse mode is SKIP_TO_L2
  194. */
  195. uint32_t broadcast_packets;
  196. /* Number of 64B packets */
  197. uint32_t len_64_packets;
  198. /* Number of 65-127B packets */
  199. uint32_t len_65_127_packets;
  200. /* Number of 128-255B packets */
  201. uint32_t len_128_255_packets;
  202. /* Number of 256-511B packets */
  203. uint32_t len_256_511_packets;
  204. /* Number of 512-1023B packets */
  205. uint32_t len_512_1023_packets;
  206. /* Number of 1024-1518B packets */
  207. uint32_t len_1024_1518_packets;
  208. /* Number of 1519-max packets */
  209. uint32_t len_1519_max_packets;
  210. /* Number of packets with FCS or Align opcode errors */
  211. uint32_t fcs_align_err_packets;
  212. /* Number of packets with length < min */
  213. uint32_t runt_packets;
  214. /* Number of packets with length < min and FCS error */
  215. uint32_t runt_crc_packets;
  216. /* Number of packets with length > max */
  217. uint32_t oversize_packets;
  218. /* Number of packets with length > max and FCS error */
  219. uint32_t oversize_crc_packets;
  220. /* Number of packets without GMX/SPX/PCI errors received by PIP */
  221. uint32_t inb_packets;
  222. /*
  223. * Total number of octets from all packets received by PIP,
  224. * including CRC
  225. */
  226. uint64_t inb_octets;
  227. /* Number of packets with GMX/SPX/PCI errors received by PIP */
  228. uint16_t inb_errors;
  229. } cvmx_pip_port_status_t;
  230. /**
  231. * Definition of the PIP custom header that can be prepended
  232. * to a packet by external hardware.
  233. */
  234. typedef union {
  235. uint64_t u64;
  236. struct {
  237. /*
  238. * Documented as R - Set if the Packet is RAWFULL. If
  239. * set, this header must be the full 8 bytes.
  240. */
  241. uint64_t rawfull:1;
  242. /* Must be zero */
  243. uint64_t reserved0:5;
  244. /* PIP parse mode for this packet */
  245. uint64_t parse_mode:2;
  246. /* Must be zero */
  247. uint64_t reserved1:1;
  248. /*
  249. * Skip amount, including this header, to the
  250. * beginning of the packet
  251. */
  252. uint64_t skip_len:7;
  253. /* Must be zero */
  254. uint64_t reserved2:6;
  255. /* POW input queue for this packet */
  256. uint64_t qos:3;
  257. /* POW input group for this packet */
  258. uint64_t grp:4;
  259. /*
  260. * Flag to store this packet in the work queue entry,
  261. * if possible
  262. */
  263. uint64_t rs:1;
  264. /* POW input tag type */
  265. uint64_t tag_type:2;
  266. /* POW input tag */
  267. uint64_t tag:32;
  268. } s;
  269. } cvmx_pip_pkt_inst_hdr_t;
  270. /* CSR typedefs have been moved to cvmx-csr-*.h */
  271. /**
  272. * Configure an ethernet input port
  273. *
  274. * @port_num: Port number to configure
  275. * @port_cfg: Port hardware configuration
  276. * @port_tag_cfg:
  277. * Port POW tagging configuration
  278. */
  279. static inline void cvmx_pip_config_port(uint64_t port_num,
  280. union cvmx_pip_prt_cfgx port_cfg,
  281. union cvmx_pip_prt_tagx port_tag_cfg)
  282. {
  283. cvmx_write_csr(CVMX_PIP_PRT_CFGX(port_num), port_cfg.u64);
  284. cvmx_write_csr(CVMX_PIP_PRT_TAGX(port_num), port_tag_cfg.u64);
  285. }
  286. #if 0
  287. /**
  288. * @deprecated This function is a thin wrapper around the Pass1 version
  289. * of the CVMX_PIP_QOS_WATCHX CSR; Pass2 has added a field for
  290. * setting the group that is incompatible with this function,
  291. * the preferred upgrade path is to use the CSR directly.
  292. *
  293. * Configure the global QoS packet watchers. Each watcher is
  294. * capable of matching a field in a packet to determine the
  295. * QoS queue for scheduling.
  296. *
  297. * @watcher: Watcher number to configure (0 - 3).
  298. * @match_type: Watcher match type
  299. * @match_value:
  300. * Value the watcher will match against
  301. * @qos: QoS queue for packets matching this watcher
  302. */
  303. static inline void cvmx_pip_config_watcher(uint64_t watcher,
  304. cvmx_pip_qos_watch_types match_type,
  305. uint64_t match_value, uint64_t qos)
  306. {
  307. cvmx_pip_port_watcher_cfg_t watcher_config;
  308. watcher_config.u64 = 0;
  309. watcher_config.s.match_type = match_type;
  310. watcher_config.s.match_value = match_value;
  311. watcher_config.s.qos = qos;
  312. cvmx_write_csr(CVMX_PIP_QOS_WATCHX(watcher), watcher_config.u64);
  313. }
  314. #endif
  315. /**
  316. * Configure the VLAN priority to QoS queue mapping.
  317. *
  318. * @vlan_priority:
  319. * VLAN priority (0-7)
  320. * @qos: QoS queue for packets matching this watcher
  321. */
  322. static inline void cvmx_pip_config_vlan_qos(uint64_t vlan_priority,
  323. uint64_t qos)
  324. {
  325. union cvmx_pip_qos_vlanx pip_qos_vlanx;
  326. pip_qos_vlanx.u64 = 0;
  327. pip_qos_vlanx.s.qos = qos;
  328. cvmx_write_csr(CVMX_PIP_QOS_VLANX(vlan_priority), pip_qos_vlanx.u64);
  329. }
  330. /**
  331. * Configure the Diffserv to QoS queue mapping.
  332. *
  333. * @diffserv: Diffserv field value (0-63)
  334. * @qos: QoS queue for packets matching this watcher
  335. */
  336. static inline void cvmx_pip_config_diffserv_qos(uint64_t diffserv, uint64_t qos)
  337. {
  338. union cvmx_pip_qos_diffx pip_qos_diffx;
  339. pip_qos_diffx.u64 = 0;
  340. pip_qos_diffx.s.qos = qos;
  341. cvmx_write_csr(CVMX_PIP_QOS_DIFFX(diffserv), pip_qos_diffx.u64);
  342. }
  343. /**
  344. * Get the status counters for a port.
  345. *
  346. * @port_num: Port number to get statistics for.
  347. * @clear: Set to 1 to clear the counters after they are read
  348. * @status: Where to put the results.
  349. */
  350. static inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear,
  351. cvmx_pip_port_status_t *status)
  352. {
  353. union cvmx_pip_stat_ctl pip_stat_ctl;
  354. union cvmx_pip_stat0_prtx stat0;
  355. union cvmx_pip_stat1_prtx stat1;
  356. union cvmx_pip_stat2_prtx stat2;
  357. union cvmx_pip_stat3_prtx stat3;
  358. union cvmx_pip_stat4_prtx stat4;
  359. union cvmx_pip_stat5_prtx stat5;
  360. union cvmx_pip_stat6_prtx stat6;
  361. union cvmx_pip_stat7_prtx stat7;
  362. union cvmx_pip_stat8_prtx stat8;
  363. union cvmx_pip_stat9_prtx stat9;
  364. union cvmx_pip_stat_inb_pktsx pip_stat_inb_pktsx;
  365. union cvmx_pip_stat_inb_octsx pip_stat_inb_octsx;
  366. union cvmx_pip_stat_inb_errsx pip_stat_inb_errsx;
  367. pip_stat_ctl.u64 = 0;
  368. pip_stat_ctl.s.rdclr = clear;
  369. cvmx_write_csr(CVMX_PIP_STAT_CTL, pip_stat_ctl.u64);
  370. stat0.u64 = cvmx_read_csr(CVMX_PIP_STAT0_PRTX(port_num));
  371. stat1.u64 = cvmx_read_csr(CVMX_PIP_STAT1_PRTX(port_num));
  372. stat2.u64 = cvmx_read_csr(CVMX_PIP_STAT2_PRTX(port_num));
  373. stat3.u64 = cvmx_read_csr(CVMX_PIP_STAT3_PRTX(port_num));
  374. stat4.u64 = cvmx_read_csr(CVMX_PIP_STAT4_PRTX(port_num));
  375. stat5.u64 = cvmx_read_csr(CVMX_PIP_STAT5_PRTX(port_num));
  376. stat6.u64 = cvmx_read_csr(CVMX_PIP_STAT6_PRTX(port_num));
  377. stat7.u64 = cvmx_read_csr(CVMX_PIP_STAT7_PRTX(port_num));
  378. stat8.u64 = cvmx_read_csr(CVMX_PIP_STAT8_PRTX(port_num));
  379. stat9.u64 = cvmx_read_csr(CVMX_PIP_STAT9_PRTX(port_num));
  380. pip_stat_inb_pktsx.u64 =
  381. cvmx_read_csr(CVMX_PIP_STAT_INB_PKTSX(port_num));
  382. pip_stat_inb_octsx.u64 =
  383. cvmx_read_csr(CVMX_PIP_STAT_INB_OCTSX(port_num));
  384. pip_stat_inb_errsx.u64 =
  385. cvmx_read_csr(CVMX_PIP_STAT_INB_ERRSX(port_num));
  386. status->dropped_octets = stat0.s.drp_octs;
  387. status->dropped_packets = stat0.s.drp_pkts;
  388. status->octets = stat1.s.octs;
  389. status->pci_raw_packets = stat2.s.raw;
  390. status->packets = stat2.s.pkts;
  391. status->multicast_packets = stat3.s.mcst;
  392. status->broadcast_packets = stat3.s.bcst;
  393. status->len_64_packets = stat4.s.h64;
  394. status->len_65_127_packets = stat4.s.h65to127;
  395. status->len_128_255_packets = stat5.s.h128to255;
  396. status->len_256_511_packets = stat5.s.h256to511;
  397. status->len_512_1023_packets = stat6.s.h512to1023;
  398. status->len_1024_1518_packets = stat6.s.h1024to1518;
  399. status->len_1519_max_packets = stat7.s.h1519;
  400. status->fcs_align_err_packets = stat7.s.fcs;
  401. status->runt_packets = stat8.s.undersz;
  402. status->runt_crc_packets = stat8.s.frag;
  403. status->oversize_packets = stat9.s.oversz;
  404. status->oversize_crc_packets = stat9.s.jabber;
  405. status->inb_packets = pip_stat_inb_pktsx.s.pkts;
  406. status->inb_octets = pip_stat_inb_octsx.s.octs;
  407. status->inb_errors = pip_stat_inb_errsx.s.errs;
  408. if (cvmx_octeon_is_pass1()) {
  409. /*
  410. * Kludge to fix Octeon Pass 1 errata - Drop counts
  411. * don't work.
  412. */
  413. if (status->inb_packets > status->packets)
  414. status->dropped_packets =
  415. status->inb_packets - status->packets;
  416. else
  417. status->dropped_packets = 0;
  418. if (status->inb_octets - status->inb_packets * 4 >
  419. status->octets)
  420. status->dropped_octets =
  421. status->inb_octets - status->inb_packets * 4 -
  422. status->octets;
  423. else
  424. status->dropped_octets = 0;
  425. }
  426. }
  427. /**
  428. * Configure the hardware CRC engine
  429. *
  430. * @interface: Interface to configure (0 or 1)
  431. * @invert_result:
  432. * Invert the result of the CRC
  433. * @reflect: Reflect
  434. * @initialization_vector:
  435. * CRC initialization vector
  436. */
  437. static inline void cvmx_pip_config_crc(uint64_t interface,
  438. uint64_t invert_result, uint64_t reflect,
  439. uint32_t initialization_vector)
  440. {
  441. if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
  442. union cvmx_pip_crc_ctlx config;
  443. union cvmx_pip_crc_ivx pip_crc_ivx;
  444. config.u64 = 0;
  445. config.s.invres = invert_result;
  446. config.s.reflect = reflect;
  447. cvmx_write_csr(CVMX_PIP_CRC_CTLX(interface), config.u64);
  448. pip_crc_ivx.u64 = 0;
  449. pip_crc_ivx.s.iv = initialization_vector;
  450. cvmx_write_csr(CVMX_PIP_CRC_IVX(interface), pip_crc_ivx.u64);
  451. }
  452. }
  453. /**
  454. * Clear all bits in a tag mask. This should be called on
  455. * startup before any calls to cvmx_pip_tag_mask_set. Each bit
  456. * set in the final mask represent a byte used in the packet for
  457. * tag generation.
  458. *
  459. * @mask_index: Which tag mask to clear (0..3)
  460. */
  461. static inline void cvmx_pip_tag_mask_clear(uint64_t mask_index)
  462. {
  463. uint64_t index;
  464. union cvmx_pip_tag_incx pip_tag_incx;
  465. pip_tag_incx.u64 = 0;
  466. pip_tag_incx.s.en = 0;
  467. for (index = mask_index * 16; index < (mask_index + 1) * 16; index++)
  468. cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
  469. }
  470. /**
  471. * Sets a range of bits in the tag mask. The tag mask is used
  472. * when the cvmx_pip_port_tag_cfg_t tag_mode is non zero.
  473. * There are four separate masks that can be configured.
  474. *
  475. * @mask_index: Which tag mask to modify (0..3)
  476. * @offset: Offset into the bitmask to set bits at. Use the GCC macro
  477. * offsetof() to determine the offsets into packet headers.
  478. * For example, offsetof(ethhdr, protocol) returns the offset
  479. * of the ethernet protocol field. The bitmask selects which
  480. * bytes to include the the tag, with bit offset X selecting
  481. * byte at offset X from the beginning of the packet data.
  482. * @len: Number of bytes to include. Usually this is the sizeof()
  483. * the field.
  484. */
  485. static inline void cvmx_pip_tag_mask_set(uint64_t mask_index, uint64_t offset,
  486. uint64_t len)
  487. {
  488. while (len--) {
  489. union cvmx_pip_tag_incx pip_tag_incx;
  490. uint64_t index = mask_index * 16 + offset / 8;
  491. pip_tag_incx.u64 = cvmx_read_csr(CVMX_PIP_TAG_INCX(index));
  492. pip_tag_incx.s.en |= 0x80 >> (offset & 0x7);
  493. cvmx_write_csr(CVMX_PIP_TAG_INCX(index), pip_tag_incx.u64);
  494. offset++;
  495. }
  496. }
  497. #endif /* __CVMX_PIP_H__ */