1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
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
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. 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**************************************/
49 * Small helper utilities.
51 * <hr>$Revision: 70030 $<hr>
53 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
54 #include <linux/module.h>
55 #include <linux/slab.h> \
57 #include <asm/octeon/cvmx.h>
58 #include <asm/octeon/cvmx-config.h>
59 #include <asm/octeon/cvmx-pip.h>
60 #include <asm/octeon/cvmx-ipd.h>
61 #include <asm/octeon/cvmx-helper.h>
62 #include <asm/octeon/cvmx-gmxx-defs.h>
63 #include <asm/octeon/cvmx-pko-defs.h>
64 #include <asm/octeon/cvmx-pko.h>
65 #include <asm/octeon/cvmx-sli-defs.h>
66 #include <asm/octeon/cvmx-pexp-defs.h>
67 #include <asm/octeon/cvmx-helper-cfg.h>
69 #if !defined(__FreeBSD__) || !defined(_KERNEL)
70 #include "executive-config.h"
71 #include "cvmx-config.h"
74 #include "cvmx-bootmem.h"
82 #include "cvmx-sysinfo.h"
83 #include "cvmx-helper.h"
84 #include "cvmx-helper-util.h"
85 #include "cvmx-version.h"
86 #include "cvmx-helper-ilk.h"
87 #include "cvmx-helper-cfg.h"
90 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
94 int cvif_has_fcs; /* PKO fcs for this interface. */
95 enum cvmx_pko_padding cvif_padding;
96 cvmx_helper_link_info_t *cvif_ipd_port_link_info;
100 * This has to be static as u-boot expects to probe an interface and
101 * gets the number of its ports.
103 static CVMX_SHARED struct cvmx_iface cvmx_interfaces[CVMX_HELPER_MAX_IFACE];
105 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
107 * Get the version of the CVMX libraries.
109 * @return Version string. Note this buffer is allocated statically
110 * and will be shared by all callers.
112 const char *cvmx_helper_get_version(void)
114 return OCTEON_SDK_VERSION_STRING;
119 * Convert a interface mode into a human readable string
121 * @param mode Mode to convert
125 const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode)
129 case CVMX_HELPER_INTERFACE_MODE_DISABLED: return "DISABLED";
130 case CVMX_HELPER_INTERFACE_MODE_RGMII: return "RGMII";
131 case CVMX_HELPER_INTERFACE_MODE_GMII: return "GMII";
132 case CVMX_HELPER_INTERFACE_MODE_SPI: return "SPI";
133 case CVMX_HELPER_INTERFACE_MODE_PCIE: return "PCIE";
134 case CVMX_HELPER_INTERFACE_MODE_XAUI: return "XAUI";
135 case CVMX_HELPER_INTERFACE_MODE_RXAUI: return "RXAUI";
136 case CVMX_HELPER_INTERFACE_MODE_SGMII: return "SGMII";
137 case CVMX_HELPER_INTERFACE_MODE_PICMG: return "PICMG";
138 case CVMX_HELPER_INTERFACE_MODE_NPI: return "NPI";
139 case CVMX_HELPER_INTERFACE_MODE_LOOP: return "LOOP";
140 case CVMX_HELPER_INTERFACE_MODE_SRIO: return "SRIO";
141 case CVMX_HELPER_INTERFACE_MODE_ILK: return "ILK";
148 * Debug routine to dump the packet structure to the console
150 * @param work Work queue entry containing the packet to dump
153 int cvmx_helper_dump_packet(cvmx_wqe_t *work)
156 uint64_t remaining_bytes;
157 cvmx_buf_ptr_t buffer_ptr;
158 uint64_t start_of_buffer;
159 uint8_t * data_address;
160 uint8_t * end_of_data;
162 cvmx_dprintf("Packet Length: %u\n", cvmx_wqe_get_len(work));
163 cvmx_dprintf(" Input Port: %u\n", cvmx_wqe_get_port(work));
164 cvmx_dprintf(" QoS: %u\n", cvmx_wqe_get_qos(work));
165 cvmx_dprintf(" Buffers: %u\n", work->word2.s.bufs);
167 if (work->word2.s.bufs == 0)
169 cvmx_ipd_wqe_fpa_queue_t wqe_pool;
170 wqe_pool.u64 = cvmx_read_csr(CVMX_IPD_WQE_FPA_QUEUE);
172 buffer_ptr.s.pool = wqe_pool.s.wqe_pool;
173 buffer_ptr.s.size = 128;
174 buffer_ptr.s.addr = cvmx_ptr_to_phys(work->packet_data);
175 if (cvmx_likely(!work->word2.s.not_IP))
177 cvmx_pip_ip_offset_t pip_ip_offset;
178 pip_ip_offset.u64 = cvmx_read_csr(CVMX_PIP_IP_OFFSET);
179 buffer_ptr.s.addr += (pip_ip_offset.s.offset<<3) - work->word2.s.ip_offset;
180 buffer_ptr.s.addr += (work->word2.s.is_v6^1)<<2;
184 /* WARNING: This code assume that the packet is not RAW. If it was,
185 we would use PIP_GBL_CFG[RAW_SHF] instead of
186 PIP_GBL_CFG[NIP_SHF] */
187 cvmx_pip_gbl_cfg_t pip_gbl_cfg;
188 pip_gbl_cfg.u64 = cvmx_read_csr(CVMX_PIP_GBL_CFG);
189 buffer_ptr.s.addr += pip_gbl_cfg.s.nip_shf;
193 buffer_ptr = work->packet_ptr;
194 remaining_bytes = cvmx_wqe_get_len(work);
196 while (remaining_bytes)
198 start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
199 cvmx_dprintf(" Buffer Start:%llx\n", (unsigned long long)start_of_buffer);
200 cvmx_dprintf(" Buffer I : %u\n", buffer_ptr.s.i);
201 cvmx_dprintf(" Buffer Back: %u\n", buffer_ptr.s.back);
202 cvmx_dprintf(" Buffer Pool: %u\n", buffer_ptr.s.pool);
203 cvmx_dprintf(" Buffer Data: %llx\n", (unsigned long long)buffer_ptr.s.addr);
204 cvmx_dprintf(" Buffer Size: %u\n", buffer_ptr.s.size);
206 cvmx_dprintf("\t\t");
207 data_address = (uint8_t *)cvmx_phys_to_ptr(buffer_ptr.s.addr);
208 end_of_data = data_address + buffer_ptr.s.size;
210 while (data_address < end_of_data)
212 if (remaining_bytes == 0)
216 cvmx_dprintf("%02x", (unsigned int)*data_address);
218 if (remaining_bytes && (count == 7))
220 cvmx_dprintf("\n\t\t");
229 buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
236 * Setup Random Early Drop on a specific input queue
238 * @param queue Input queue to setup RED on (0-7)
240 * Packets will begin slowly dropping when there are less than
241 * this many packet buffers free in FPA 0.
243 * All incomming packets will be dropped when there are less
244 * than this many free packet buffers in FPA 0.
245 * @return Zero on success. Negative on failure
247 int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh)
249 cvmx_ipd_qosx_red_marks_t red_marks;
250 cvmx_ipd_red_quex_param_t red_param;
252 /* Set RED to begin dropping packets when there are pass_thresh buffers
253 left. It will linearly drop more packets until reaching drop_thresh
256 red_marks.s.drop = drop_thresh;
257 red_marks.s.pass = pass_thresh;
258 cvmx_write_csr(CVMX_IPD_QOSX_RED_MARKS(queue), red_marks.u64);
260 /* Use the actual queue 0 counter, not the average */
262 red_param.s.prb_con = (255ul<<24) / (red_marks.s.pass - red_marks.s.drop);
263 red_param.s.avg_con = 1;
264 red_param.s.new_con = 255;
265 red_param.s.use_pcnt = 1;
266 cvmx_write_csr(CVMX_IPD_RED_QUEX_PARAM(queue), red_param.u64);
272 * Setup Random Early Drop to automatically begin dropping packets.
275 * Packets will begin slowly dropping when there are less than
276 * this many packet buffers free in FPA 0.
278 * All incomming packets will be dropped when there are less
279 * than this many free packet buffers in FPA 0.
280 * @return Zero on success. Negative on failure
282 int cvmx_helper_setup_red(int pass_thresh, int drop_thresh)
289 * Disable backpressure based on queued buffers. It needs SW support
291 if (octeon_has_feature(OCTEON_FEATURE_PKND))
294 for (interface = 0; interface < CVMX_HELPER_MAX_GMX; interface++)
298 num_ports = cvmx_helper_ports_on_interface(interface);
299 for (port = 0; port < num_ports; port++) {
300 bpid = cvmx_helper_get_bpid(interface, port);
301 if (bpid == CVMX_INVALID_BPID)
303 "setup_red: cvmx_helper_get_bpid(%d, %d) = %d\n",
304 interface, port, cvmx_helper_get_bpid(interface, port));
306 cvmx_write_csr(CVMX_IPD_BPIDX_MBUF_TH(bpid), 0);
312 cvmx_ipd_portx_bp_page_cnt_t page_cnt;
315 page_cnt.s.bp_enb = 0;
316 page_cnt.s.page_cnt = 100;
317 for (interface = 0; interface < CVMX_HELPER_MAX_GMX; interface++)
319 for (port = cvmx_helper_get_first_ipd_port(interface);
320 port < cvmx_helper_get_last_ipd_port(interface); port++)
321 cvmx_write_csr(CVMX_IPD_PORTX_BP_PAGE_CNT(port), page_cnt.u64);
325 for (queue = 0; queue < 8; queue++)
326 cvmx_helper_setup_red_queue(queue, pass_thresh, drop_thresh);
329 * Shutoff the dropping based on the per port page count. SW isn't
330 * decrementing it right now
332 if (octeon_has_feature(OCTEON_FEATURE_PKND))
333 cvmx_write_csr(CVMX_IPD_ON_BP_DROP_PKTX(0), 0);
335 cvmx_write_csr(CVMX_IPD_BP_PRT_RED_END, 0);
337 #define IPD_RED_AVG_DLY 1000
338 #define IPD_RED_PRB_DLY 1000
340 * Setting up avg_dly and prb_dly, enable bits
342 if (octeon_has_feature(OCTEON_FEATURE_PKND))
344 cvmx_ipd_red_delay_t red_delay;
345 cvmx_ipd_red_bpid_enablex_t red_bpid_enable;
348 red_delay.s.avg_dly = IPD_RED_AVG_DLY;
349 red_delay.s.prb_dly = IPD_RED_PRB_DLY;
350 cvmx_write_csr(CVMX_IPD_RED_DELAY, red_delay.u64);
353 * Only enable the gmx ports
355 red_bpid_enable.u64 = 0;
356 for (interface = 0; interface < CVMX_HELPER_MAX_GMX; interface++)
358 int num_ports = cvmx_helper_ports_on_interface(interface);
359 for (port = 0; port < num_ports; port++)
360 red_bpid_enable.u64 |= (((uint64_t) 1) <<
361 cvmx_helper_get_bpid(interface, port));
363 cvmx_write_csr(CVMX_IPD_RED_BPID_ENABLEX(0), red_bpid_enable.u64);
367 cvmx_ipd_red_port_enable_t red_port_enable;
369 red_port_enable.u64 = 0;
370 red_port_enable.s.prt_enb = 0xfffffffffull;
371 red_port_enable.s.avg_dly = IPD_RED_AVG_DLY;
372 red_port_enable.s.prb_dly = IPD_RED_PRB_DLY;
373 cvmx_write_csr(CVMX_IPD_RED_PORT_ENABLE, red_port_enable.u64);
376 * Shutoff the dropping of packets based on RED for SRIO ports
378 if (octeon_has_feature(OCTEON_FEATURE_SRIO))
380 cvmx_ipd_red_port_enable2_t red_port_enable2;
381 red_port_enable2.u64 = 0;
382 red_port_enable2.s.prt_enb = 0xf0;
383 cvmx_write_csr(CVMX_IPD_RED_PORT_ENABLE2, red_port_enable2.u64);
389 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
390 EXPORT_SYMBOL(cvmx_helper_setup_red);
396 * Setup the common GMX settings that determine the number of
397 * ports. These setting apply to almost all configurations of all
400 * @param interface Interface to configure
401 * @param num_ports Number of ports on the interface
403 * @return Zero on success, negative on failure
405 int __cvmx_helper_setup_gmx(int interface, int num_ports)
407 cvmx_gmxx_tx_prts_t gmx_tx_prts;
408 cvmx_gmxx_rx_prts_t gmx_rx_prts;
409 cvmx_pko_reg_gmx_port_mode_t pko_mode;
410 cvmx_gmxx_txx_thresh_t gmx_tx_thresh;
414 * Tell GMX the number of TX ports on this interface
416 gmx_tx_prts.u64 = cvmx_read_csr(CVMX_GMXX_TX_PRTS(interface));
417 gmx_tx_prts.s.prts = num_ports;
418 cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), gmx_tx_prts.u64);
421 * Tell GMX the number of RX ports on this interface. This only applies
422 * to GMII and XAUI ports
424 if (cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_RGMII
425 || cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_SGMII
426 || cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_GMII
427 || cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_XAUI)
431 cvmx_dprintf("__cvmx_helper_setup_gmx: Illegal num_ports\n");
435 gmx_rx_prts.u64 = cvmx_read_csr(CVMX_GMXX_RX_PRTS(interface));
436 gmx_rx_prts.s.prts = num_ports;
437 cvmx_write_csr(CVMX_GMXX_RX_PRTS(interface), gmx_rx_prts.u64);
441 * Skip setting CVMX_PKO_REG_GMX_PORT_MODE on 30XX, 31XX, 50XX,
444 if (!OCTEON_IS_MODEL(OCTEON_CN30XX) && !OCTEON_IS_MODEL(OCTEON_CN31XX) &&
445 !OCTEON_IS_MODEL(OCTEON_CN50XX) && !OCTEON_IS_MODEL(OCTEON_CN68XX))
447 /* Tell PKO the number of ports on this interface */
448 pko_mode.u64 = cvmx_read_csr(CVMX_PKO_REG_GMX_PORT_MODE);
452 pko_mode.s.mode0 = 4;
453 else if (num_ports == 2)
454 pko_mode.s.mode0 = 3;
455 else if (num_ports <= 4)
456 pko_mode.s.mode0 = 2;
457 else if (num_ports <= 8)
458 pko_mode.s.mode0 = 1;
460 pko_mode.s.mode0 = 0;
465 pko_mode.s.mode1 = 4;
466 else if (num_ports == 2)
467 pko_mode.s.mode1 = 3;
468 else if (num_ports <= 4)
469 pko_mode.s.mode1 = 2;
470 else if (num_ports <= 8)
471 pko_mode.s.mode1 = 1;
473 pko_mode.s.mode1 = 0;
475 cvmx_write_csr(CVMX_PKO_REG_GMX_PORT_MODE, pko_mode.u64);
479 * Set GMX to buffer as much data as possible before starting
480 * transmit. This reduces the chances that we have a TX under run
481 * due to memory contention. Any packet that fits entirely in the
482 * GMX FIFO can never have an under run regardless of memory load.
484 gmx_tx_thresh.u64 = cvmx_read_csr(CVMX_GMXX_TXX_THRESH(0, interface));
485 if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN31XX) ||
486 OCTEON_IS_MODEL(OCTEON_CN50XX))
487 /* These chips have a fixed max threshold of 0x40 */
488 gmx_tx_thresh.s.cnt = 0x40;
491 /* ccn - common cnt numberator */
494 /* Choose the max value for the number of ports */
496 gmx_tx_thresh.s.cnt = ccn / 1;
497 else if (num_ports == 2)
498 gmx_tx_thresh.s.cnt = ccn / 2;
500 gmx_tx_thresh.s.cnt = ccn / 4;
504 * SPI and XAUI can have lots of ports but the GMX hardware only ever has
509 for (index = 0; index < num_ports; index++)
510 cvmx_write_csr(CVMX_GMXX_TXX_THRESH(index, interface),
514 * For o68, we need to setup the pipes
516 if (OCTEON_IS_MODEL(OCTEON_CN68XX) && interface < CVMX_HELPER_MAX_GMX)
518 cvmx_gmxx_txx_pipe_t config;
520 for (index = 0; index < num_ports; index++)
524 if (__cvmx_helper_cfg_pko_port_base(interface, index) >= 0)
526 config.u64 = cvmx_read_csr(
527 CVMX_GMXX_TXX_PIPE(index, interface));
528 config.s.nump = __cvmx_helper_cfg_pko_port_num(interface, index);
529 config.s.base = __cvmx_helper_cfg_pko_port_base(interface, index);
530 cvmx_write_csr(CVMX_GMXX_TXX_PIPE(index, interface),
539 int cvmx_helper_get_pko_port(int interface, int port)
541 return cvmx_pko_get_base_pko_port(interface, port);
543 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
544 EXPORT_SYMBOL(cvmx_helper_get_pko_port);
547 int cvmx_helper_get_ipd_port(int interface, int port)
549 if (octeon_has_feature(OCTEON_FEATURE_PKND))
551 if (interface >= 0 && interface <= 4)
553 cvmx_helper_interface_mode_t mode = cvmx_helper_interface_get_mode(interface);
554 if (mode == CVMX_HELPER_INTERFACE_MODE_XAUI || mode == CVMX_HELPER_INTERFACE_MODE_RXAUI)
555 return 0x840 + (interface * 0x100);
557 return 0x800 + (interface * 0x100) + (port * 16);
559 else if (interface == 5 || interface == 6)
560 return 0x400 + (interface - 5) * 0x100 + port;
561 else if (interface == 7)
563 else if (interface == 8)
571 case 1: return port + 16;
572 case 2: return port + 32;
573 case 3: return port + 36;
574 case 4: return port + 40;
575 case 5: return port + 42;
576 case 6: return port + 44;
580 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
581 EXPORT_SYMBOL(cvmx_helper_get_ipd_port);
584 int __cvmx_helper_get_num_ipd_ports(int interface)
586 struct cvmx_iface *piface;
588 if (interface >= cvmx_helper_get_number_of_interfaces())
591 piface = &cvmx_interfaces[interface];
592 return piface->cvif_ipd_nports;
595 enum cvmx_pko_padding __cvmx_helper_get_pko_padding(int interface)
597 struct cvmx_iface *piface;
599 if (interface >= cvmx_helper_get_number_of_interfaces())
600 return CVMX_PKO_PADDING_NONE;
602 piface = &cvmx_interfaces[interface];
603 return piface->cvif_padding;
606 int __cvmx_helper_init_interface(int interface, int num_ipd_ports, int has_fcs, enum cvmx_pko_padding pad)
608 struct cvmx_iface *piface;
611 if (interface >= cvmx_helper_get_number_of_interfaces())
614 piface = &cvmx_interfaces[interface];
615 piface->cvif_ipd_nports = num_ipd_ports;
616 piface->cvif_padding = pad;
618 piface->cvif_has_fcs = has_fcs;
621 * allocate the per-ipd_port link_info structure
623 sz = piface->cvif_ipd_nports * sizeof(cvmx_helper_link_info_t);
624 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
626 sz = sizeof(cvmx_helper_link_info_t);
627 piface->cvif_ipd_port_link_info = (cvmx_helper_link_info_t *)kmalloc(sz, GFP_KERNEL);
628 if (ZERO_OR_NULL_PTR(piface->cvif_ipd_port_link_info))
629 panic("Cannot allocate memory in __cvmx_helper_init_interface.");
631 piface->cvif_ipd_port_link_info = (cvmx_helper_link_info_t *)cvmx_bootmem_alloc(sz, sizeof(cvmx_helper_link_info_t));
633 if (!piface->cvif_ipd_port_link_info)
636 /* Initialize 'em */ {
638 cvmx_helper_link_info_t *p;
639 p = piface->cvif_ipd_port_link_info;
641 for (i = 0; i < piface->cvif_ipd_nports; i++)
652 * Shut down the interfaces; free the resources.
655 void __cvmx_helper_shutdown_interfaces(void)
658 int nifaces; /* number of interfaces */
659 struct cvmx_iface *piface;
661 nifaces = cvmx_helper_get_number_of_interfaces();
662 for (i = 0; i < nifaces; i++)
664 piface = cvmx_interfaces + i;
665 if (piface->cvif_ipd_port_link_info)
666 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
667 kfree(piface->cvif_ipd_port_link_info);
670 * For SE apps, bootmem was meant to be allocated and never
674 piface->cvif_ipd_port_link_info = 0;
678 int __cvmx_helper_set_link_info(int interface, int port,
679 cvmx_helper_link_info_t link_info)
681 struct cvmx_iface *piface;
683 if (interface >= cvmx_helper_get_number_of_interfaces())
686 piface = &cvmx_interfaces[interface];
688 if (piface->cvif_ipd_port_link_info)
690 piface->cvif_ipd_port_link_info[port] = link_info;
697 cvmx_helper_link_info_t __cvmx_helper_get_link_info(int interface, int port)
699 struct cvmx_iface *piface;
700 cvmx_helper_link_info_t err;
704 if (interface >= cvmx_helper_get_number_of_interfaces())
706 piface = &cvmx_interfaces[interface];
708 if (piface->cvif_ipd_port_link_info)
709 return piface->cvif_ipd_port_link_info[port];
714 int __cvmx_helper_get_has_fcs(int interface)
716 return cvmx_interfaces[interface].cvif_has_fcs;
719 int cvmx_helper_get_pknd(int interface, int port)
721 if (octeon_has_feature(OCTEON_FEATURE_PKND))
722 return __cvmx_helper_cfg_pknd(interface, port);
724 return CVMX_INVALID_PKND;
726 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
727 EXPORT_SYMBOL(cvmx_helper_get_pknd);
730 int cvmx_helper_get_bpid(int interface, int port)
732 if (octeon_has_feature(OCTEON_FEATURE_PKND))
733 return __cvmx_helper_cfg_bpid(interface, port);
735 return CVMX_INVALID_BPID;
737 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
738 EXPORT_SYMBOL(cvmx_helper_get_bpid);
742 * Display interface statistics.
744 * @param port IPD/PKO port number
748 void cvmx_helper_show_stats(int port)
750 cvmx_pip_port_status_t status;
751 cvmx_pko_port_status_t pko_status;
754 if (octeon_has_feature(OCTEON_FEATURE_ILK))
755 __cvmx_helper_ilk_show_stats();
758 cvmx_pip_get_port_status (port, 0, &status);
759 cvmx_dprintf ("port %d: the number of packets - ipd: %d\n", port, (int)status.packets);
762 cvmx_pko_get_port_status (port, 0, &pko_status);
763 cvmx_dprintf ("port %d: the number of packets - pko: %d\n", port, (int)pko_status.packets);
765 /* TODO: other stats */
767 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
770 * Returns the interface number for an IPD/PKO port number.
772 * @param ipd_port IPD/PKO port number
774 * @return Interface number
776 int cvmx_helper_get_interface_num(int ipd_port)
778 if (octeon_has_feature(OCTEON_FEATURE_PKND))
780 if (ipd_port >= 0x800 && ipd_port < 0x900)
782 else if (ipd_port >= 0x900 && ipd_port < 0xa00)
784 else if (ipd_port >= 0xa00 && ipd_port < 0xb00)
786 else if (ipd_port >= 0xb00 && ipd_port < 0xc00)
788 else if (ipd_port >= 0xc00 && ipd_port < 0xd00)
790 else if (ipd_port >= 0x400 && ipd_port < 0x500)
792 else if (ipd_port >= 0x500 && ipd_port < 0x600)
794 else if (ipd_port >= 0x100 && ipd_port < 0x120)
796 else if (ipd_port < 8)
801 else if (ipd_port < 32)
803 else if (ipd_port < 36)
805 else if (ipd_port < 40)
807 else if (ipd_port < 42)
809 else if (ipd_port < 44)
811 else if (ipd_port < 46)
814 cvmx_dprintf("cvmx_helper_get_interface_num: Illegal IPD port number %d\n", ipd_port);
817 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
818 EXPORT_SYMBOL(cvmx_helper_get_interface_num);
823 * Returns the interface index number for an IPD/PKO port
826 * @param ipd_port IPD/PKO port number
828 * @return Interface index number
830 int cvmx_helper_get_interface_index_num(int ipd_port)
832 if (octeon_has_feature(OCTEON_FEATURE_PKND))
834 if (ipd_port >= 0x800 && ipd_port < 0xd00)
836 int port = ((ipd_port & 0xff) >> 6);
837 return ((port) ? (port - 1) : ((ipd_port & 0xff) >> 4));
839 else if (ipd_port >= 0x400 && ipd_port < 0x600)
840 return (ipd_port & 0xff);
841 else if (ipd_port >= 0x100 && ipd_port < 0x120)
842 return (ipd_port & 0xff);
843 else if (ipd_port < 8)
846 cvmx_dprintf("cvmx_helper_get_interface_index_num: Illegal IPD port number %d\n", ipd_port);
850 return ipd_port & 15;
851 else if (ipd_port < 40)
853 else if (ipd_port < 44)
855 else if (ipd_port < 46)
858 cvmx_dprintf("cvmx_helper_get_interface_index_num: Illegal IPD port number\n");
862 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
863 EXPORT_SYMBOL(cvmx_helper_get_interface_index_num);