1 /***********************license start***************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2008 Cavium Networks
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.
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
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/.
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
30 * Helper functions for common, but complicated tasks.
33 #include <asm/octeon/octeon.h>
35 #include <asm/octeon/cvmx-config.h>
37 #include <asm/octeon/cvmx-fpa.h>
38 #include <asm/octeon/cvmx-pip.h>
39 #include <asm/octeon/cvmx-pko.h>
40 #include <asm/octeon/cvmx-ipd.h>
41 #include <asm/octeon/cvmx-spi.h>
42 #include <asm/octeon/cvmx-helper.h>
43 #include <asm/octeon/cvmx-helper-board.h>
45 #include <asm/octeon/cvmx-pip-defs.h>
46 #include <asm/octeon/cvmx-smix-defs.h>
47 #include <asm/octeon/cvmx-asxx-defs.h>
50 * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
51 * priorities[16]) is a function pointer. It is meant to allow
52 * customization of the PKO queue priorities based on the port
53 * number. Users should set this pointer to a function before
54 * calling any cvmx-helper operations.
56 void (*cvmx_override_pko_queue_priority) (int pko_port,
57 uint64_t priorities[16]);
60 * cvmx_override_ipd_port_setup(int ipd_port) is a function
61 * pointer. It is meant to allow customization of the IPD port
62 * setup before packet input/output comes online. It is called
63 * after cvmx-helper does the default IPD configuration, but
64 * before IPD is enabled. Users should set this pointer to a
65 * function before calling any cvmx-helper operations.
67 void (*cvmx_override_ipd_port_setup) (int ipd_port);
69 /* Port count per interface */
70 static int interface_port_count[4] = { 0, 0, 0, 0 };
72 /* Port last configured link info index by IPD/PKO port */
73 static cvmx_helper_link_info_t
74 port_link_info[CVMX_PIP_NUM_INPUT_PORTS];
77 * Return the number of interfaces the chip has. Each interface
78 * may have multiple ports. Most chips support two interfaces,
79 * but the CNX0XX and CNX1XX are exceptions. These only support
82 * Returns Number of interfaces on chip
84 int cvmx_helper_get_number_of_interfaces(void)
86 if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
93 * Return the number of ports on an interface. Depending on the
94 * chip and configuration, this can be 1-16. A value of 0
95 * specifies that the interface doesn't exist or isn't usable.
97 * @interface: Interface to get the port count for
99 * Returns Number of ports on interface. Can be Zero.
101 int cvmx_helper_ports_on_interface(int interface)
103 return interface_port_count[interface];
107 * Get the operating mode of an interface. Depending on the Octeon
108 * chip and configuration, this function returns an enumeration
109 * of the type of packet I/O supported by an interface.
111 * @interface: Interface to probe
113 * Returns Mode of the interface. Unknown or unsupported interfaces return
116 cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface)
118 union cvmx_gmxx_inf_mode mode;
120 return CVMX_HELPER_INTERFACE_MODE_NPI;
122 if (interface == 3) {
123 if (OCTEON_IS_MODEL(OCTEON_CN56XX)
124 || OCTEON_IS_MODEL(OCTEON_CN52XX))
125 return CVMX_HELPER_INTERFACE_MODE_LOOP;
127 return CVMX_HELPER_INTERFACE_MODE_DISABLED;
131 && cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3005_EVB_HS5
132 && cvmx_sysinfo_get()->board_rev_major == 1) {
134 * Lie about interface type of CN3005 board. This
135 * board has a switch on port 1 like the other
136 * evaluation boards, but it is connected over RGMII
137 * instead of GMII. Report GMII mode so that the
138 * speed is forced to 1 Gbit full duplex. Other than
139 * some initial configuration (which does not use the
140 * output of this function) there is no difference in
141 * setup between GMII and RGMII modes.
143 return CVMX_HELPER_INTERFACE_MODE_GMII;
146 /* Interface 1 is always disabled on CN31XX and CN30XX */
148 && (OCTEON_IS_MODEL(OCTEON_CN31XX) || OCTEON_IS_MODEL(OCTEON_CN30XX)
149 || OCTEON_IS_MODEL(OCTEON_CN50XX)
150 || OCTEON_IS_MODEL(OCTEON_CN52XX)))
151 return CVMX_HELPER_INTERFACE_MODE_DISABLED;
153 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
155 if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX)) {
156 switch (mode.cn56xx.mode) {
158 return CVMX_HELPER_INTERFACE_MODE_DISABLED;
160 return CVMX_HELPER_INTERFACE_MODE_XAUI;
162 return CVMX_HELPER_INTERFACE_MODE_SGMII;
164 return CVMX_HELPER_INTERFACE_MODE_PICMG;
166 return CVMX_HELPER_INTERFACE_MODE_DISABLED;
170 return CVMX_HELPER_INTERFACE_MODE_DISABLED;
173 if (OCTEON_IS_MODEL(OCTEON_CN38XX)
174 || OCTEON_IS_MODEL(OCTEON_CN58XX))
175 return CVMX_HELPER_INTERFACE_MODE_SPI;
177 return CVMX_HELPER_INTERFACE_MODE_GMII;
179 return CVMX_HELPER_INTERFACE_MODE_RGMII;
184 * Configure the IPD/PIP tagging and QoS options for a specific
185 * port. This function determines the POW work queue entry
186 * contents for a port. The setup performed here is controlled by
187 * the defines in executive-config.h.
189 * @ipd_port: Port to configure. This follows the IPD numbering, not the
190 * per interface numbering
192 * Returns Zero on success, negative on failure
194 static int __cvmx_helper_port_setup_ipd(int ipd_port)
196 union cvmx_pip_prt_cfgx port_config;
197 union cvmx_pip_prt_tagx tag_config;
199 port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
200 tag_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_TAGX(ipd_port));
202 /* Have each port go to a different POW queue */
203 port_config.s.qos = ipd_port & 0x7;
205 /* Process the headers and place the IP header in the work queue */
206 port_config.s.mode = CVMX_HELPER_INPUT_PORT_SKIP_MODE;
208 tag_config.s.ip6_src_flag = CVMX_HELPER_INPUT_TAG_IPV6_SRC_IP;
209 tag_config.s.ip6_dst_flag = CVMX_HELPER_INPUT_TAG_IPV6_DST_IP;
210 tag_config.s.ip6_sprt_flag = CVMX_HELPER_INPUT_TAG_IPV6_SRC_PORT;
211 tag_config.s.ip6_dprt_flag = CVMX_HELPER_INPUT_TAG_IPV6_DST_PORT;
212 tag_config.s.ip6_nxth_flag = CVMX_HELPER_INPUT_TAG_IPV6_NEXT_HEADER;
213 tag_config.s.ip4_src_flag = CVMX_HELPER_INPUT_TAG_IPV4_SRC_IP;
214 tag_config.s.ip4_dst_flag = CVMX_HELPER_INPUT_TAG_IPV4_DST_IP;
215 tag_config.s.ip4_sprt_flag = CVMX_HELPER_INPUT_TAG_IPV4_SRC_PORT;
216 tag_config.s.ip4_dprt_flag = CVMX_HELPER_INPUT_TAG_IPV4_DST_PORT;
217 tag_config.s.ip4_pctl_flag = CVMX_HELPER_INPUT_TAG_IPV4_PROTOCOL;
218 tag_config.s.inc_prt_flag = CVMX_HELPER_INPUT_TAG_INPUT_PORT;
219 tag_config.s.tcp6_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
220 tag_config.s.tcp4_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
221 tag_config.s.ip6_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
222 tag_config.s.ip4_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
223 tag_config.s.non_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
224 /* Put all packets in group 0. Other groups can be used by the app */
225 tag_config.s.grp = 0;
227 cvmx_pip_config_port(ipd_port, port_config, tag_config);
229 /* Give the user a chance to override our setting for each port */
230 if (cvmx_override_ipd_port_setup)
231 cvmx_override_ipd_port_setup(ipd_port);
237 * This function sets the interface_port_count[interface] correctly,
238 * without modifying any hardware configuration. Hardware setup of
239 * the ports will be performed later.
241 * @interface: Interface to probe
243 * Returns Zero on success, negative on failure
245 int cvmx_helper_interface_enumerate(int interface)
247 switch (cvmx_helper_interface_get_mode(interface)) {
248 /* These types don't support ports to IPD/PKO */
249 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
250 case CVMX_HELPER_INTERFACE_MODE_PCIE:
251 interface_port_count[interface] = 0;
253 /* XAUI is a single high speed port */
254 case CVMX_HELPER_INTERFACE_MODE_XAUI:
255 interface_port_count[interface] =
256 __cvmx_helper_xaui_enumerate(interface);
259 * RGMII/GMII/MII are all treated about the same. Most
260 * functions refer to these ports as RGMII.
262 case CVMX_HELPER_INTERFACE_MODE_RGMII:
263 case CVMX_HELPER_INTERFACE_MODE_GMII:
264 interface_port_count[interface] =
265 __cvmx_helper_rgmii_enumerate(interface);
268 * SPI4 can have 1-16 ports depending on the device at
271 case CVMX_HELPER_INTERFACE_MODE_SPI:
272 interface_port_count[interface] =
273 __cvmx_helper_spi_enumerate(interface);
276 * SGMII can have 1-4 ports depending on how many are
279 case CVMX_HELPER_INTERFACE_MODE_SGMII:
280 case CVMX_HELPER_INTERFACE_MODE_PICMG:
281 interface_port_count[interface] =
282 __cvmx_helper_sgmii_enumerate(interface);
284 /* PCI target Network Packet Interface */
285 case CVMX_HELPER_INTERFACE_MODE_NPI:
286 interface_port_count[interface] =
287 __cvmx_helper_npi_enumerate(interface);
290 * Special loopback only ports. These are not the same
291 * as other ports in loopback mode.
293 case CVMX_HELPER_INTERFACE_MODE_LOOP:
294 interface_port_count[interface] =
295 __cvmx_helper_loop_enumerate(interface);
299 interface_port_count[interface] =
300 __cvmx_helper_board_interface_probe(interface,
304 /* Make sure all global variables propagate to other cores */
311 * This function probes an interface to determine the actual
312 * number of hardware ports connected to it. It doesn't setup the
313 * ports or enable them. The main goal here is to set the global
314 * interface_port_count[interface] correctly. Hardware setup of the
315 * ports will be performed later.
317 * @interface: Interface to probe
319 * Returns Zero on success, negative on failure
321 int cvmx_helper_interface_probe(int interface)
323 cvmx_helper_interface_enumerate(interface);
324 /* At this stage in the game we don't want packets to be moving yet.
325 The following probe calls should perform hardware setup
326 needed to determine port counts. Receive must still be disabled */
327 switch (cvmx_helper_interface_get_mode(interface)) {
328 /* These types don't support ports to IPD/PKO */
329 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
330 case CVMX_HELPER_INTERFACE_MODE_PCIE:
332 /* XAUI is a single high speed port */
333 case CVMX_HELPER_INTERFACE_MODE_XAUI:
334 __cvmx_helper_xaui_probe(interface);
337 * RGMII/GMII/MII are all treated about the same. Most
338 * functions refer to these ports as RGMII.
340 case CVMX_HELPER_INTERFACE_MODE_RGMII:
341 case CVMX_HELPER_INTERFACE_MODE_GMII:
342 __cvmx_helper_rgmii_probe(interface);
345 * SPI4 can have 1-16 ports depending on the device at
348 case CVMX_HELPER_INTERFACE_MODE_SPI:
349 __cvmx_helper_spi_probe(interface);
352 * SGMII can have 1-4 ports depending on how many are
355 case CVMX_HELPER_INTERFACE_MODE_SGMII:
356 case CVMX_HELPER_INTERFACE_MODE_PICMG:
357 __cvmx_helper_sgmii_probe(interface);
359 /* PCI target Network Packet Interface */
360 case CVMX_HELPER_INTERFACE_MODE_NPI:
361 __cvmx_helper_npi_probe(interface);
364 * Special loopback only ports. These are not the same
365 * as other ports in loopback mode.
367 case CVMX_HELPER_INTERFACE_MODE_LOOP:
368 __cvmx_helper_loop_probe(interface);
372 /* Make sure all global variables propagate to other cores */
379 * Setup the IPD/PIP for the ports on an interface. Packet
380 * classification and tagging are set for every port on the
381 * interface. The number of ports on the interface must already
384 * @interface: Interface to setup IPD/PIP for
386 * Returns Zero on success, negative on failure
388 static int __cvmx_helper_interface_setup_ipd(int interface)
390 int ipd_port = cvmx_helper_get_ipd_port(interface, 0);
391 int num_ports = interface_port_count[interface];
393 while (num_ports--) {
394 __cvmx_helper_port_setup_ipd(ipd_port);
401 * Setup global setting for IPD/PIP not related to a specific
402 * interface or port. This must be called before IPD is enabled.
404 * Returns Zero on success, negative on failure.
406 static int __cvmx_helper_global_setup_ipd(void)
408 /* Setup the global packet input options */
409 cvmx_ipd_config(CVMX_FPA_PACKET_POOL_SIZE / 8,
410 CVMX_HELPER_FIRST_MBUFF_SKIP / 8,
411 CVMX_HELPER_NOT_FIRST_MBUFF_SKIP / 8,
412 /* The +8 is to account for the next ptr */
413 (CVMX_HELPER_FIRST_MBUFF_SKIP + 8) / 128,
414 /* The +8 is to account for the next ptr */
415 (CVMX_HELPER_NOT_FIRST_MBUFF_SKIP + 8) / 128,
417 CVMX_IPD_OPC_MODE_STT,
418 CVMX_HELPER_ENABLE_BACK_PRESSURE);
423 * Setup the PKO for the ports on an interface. The number of
424 * queues per port and the priority of each PKO output queue
425 * is set here. PKO must be disabled when this function is called.
427 * @interface: Interface to setup PKO for
429 * Returns Zero on success, negative on failure
431 static int __cvmx_helper_interface_setup_pko(int interface)
434 * Each packet output queue has an associated priority. The
435 * higher the priority, the more often it can send a packet. A
436 * priority of 8 means it can send in all 8 rounds of
437 * contention. We're going to make each queue one less than
438 * the last. The vector of priorities has been extended to
439 * support CN5xxx CPUs, where up to 16 queues can be
440 * associated to a port. To keep backward compatibility we
441 * don't change the initial 8 priorities and replicate them in
442 * the second half. With per-core PKO queues (PKO lockless
443 * operation) all queues have the same priority.
445 uint64_t priorities[16] =
446 { 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1 };
449 * Setup the IPD/PIP and PKO for the ports discovered
450 * above. Here packet classification, tagging and output
451 * priorities are set.
453 int ipd_port = cvmx_helper_get_ipd_port(interface, 0);
454 int num_ports = interface_port_count[interface];
455 while (num_ports--) {
457 * Give the user a chance to override the per queue
460 if (cvmx_override_pko_queue_priority)
461 cvmx_override_pko_queue_priority(ipd_port, priorities);
463 cvmx_pko_config_port(ipd_port,
464 cvmx_pko_get_base_queue_per_core(ipd_port,
466 cvmx_pko_get_num_queues(ipd_port),
474 * Setup global setting for PKO not related to a specific
475 * interface or port. This must be called before PKO is enabled.
477 * Returns Zero on success, negative on failure.
479 static int __cvmx_helper_global_setup_pko(void)
482 * Disable tagwait FAU timeout. This needs to be done before
483 * anyone might start packet output using tags.
485 union cvmx_iob_fau_timeout fau_to;
487 fau_to.s.tout_val = 0xfff;
488 fau_to.s.tout_enb = 0;
489 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_to.u64);
494 * Setup global backpressure setting.
496 * Returns Zero on success, negative on failure
498 static int __cvmx_helper_global_setup_backpressure(void)
500 #if CVMX_HELPER_DISABLE_RGMII_BACKPRESSURE
501 /* Disable backpressure if configured to do so */
502 /* Disable backpressure (pause frame) generation */
503 int num_interfaces = cvmx_helper_get_number_of_interfaces();
505 for (interface = 0; interface < num_interfaces; interface++) {
506 switch (cvmx_helper_interface_get_mode(interface)) {
507 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
508 case CVMX_HELPER_INTERFACE_MODE_PCIE:
509 case CVMX_HELPER_INTERFACE_MODE_NPI:
510 case CVMX_HELPER_INTERFACE_MODE_LOOP:
511 case CVMX_HELPER_INTERFACE_MODE_XAUI:
513 case CVMX_HELPER_INTERFACE_MODE_RGMII:
514 case CVMX_HELPER_INTERFACE_MODE_GMII:
515 case CVMX_HELPER_INTERFACE_MODE_SPI:
516 case CVMX_HELPER_INTERFACE_MODE_SGMII:
517 case CVMX_HELPER_INTERFACE_MODE_PICMG:
518 cvmx_gmx_set_backpressure_override(interface, 0xf);
528 * Enable packet input/output from the hardware. This function is
529 * called after all internal setup is complete and IPD is enabled.
530 * After this function completes, packets will be accepted from the
531 * hardware ports. PKO should still be disabled to make sure packets
532 * aren't sent out partially setup hardware.
534 * @interface: Interface to enable
536 * Returns Zero on success, negative on failure
538 static int __cvmx_helper_packet_hardware_enable(int interface)
541 switch (cvmx_helper_interface_get_mode(interface)) {
542 /* These types don't support ports to IPD/PKO */
543 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
544 case CVMX_HELPER_INTERFACE_MODE_PCIE:
547 /* XAUI is a single high speed port */
548 case CVMX_HELPER_INTERFACE_MODE_XAUI:
549 result = __cvmx_helper_xaui_enable(interface);
552 * RGMII/GMII/MII are all treated about the same. Most
553 * functions refer to these ports as RGMII
555 case CVMX_HELPER_INTERFACE_MODE_RGMII:
556 case CVMX_HELPER_INTERFACE_MODE_GMII:
557 result = __cvmx_helper_rgmii_enable(interface);
560 * SPI4 can have 1-16 ports depending on the device at
563 case CVMX_HELPER_INTERFACE_MODE_SPI:
564 result = __cvmx_helper_spi_enable(interface);
567 * SGMII can have 1-4 ports depending on how many are
570 case CVMX_HELPER_INTERFACE_MODE_SGMII:
571 case CVMX_HELPER_INTERFACE_MODE_PICMG:
572 result = __cvmx_helper_sgmii_enable(interface);
574 /* PCI target Network Packet Interface */
575 case CVMX_HELPER_INTERFACE_MODE_NPI:
576 result = __cvmx_helper_npi_enable(interface);
579 * Special loopback only ports. These are not the same
580 * as other ports in loopback mode
582 case CVMX_HELPER_INTERFACE_MODE_LOOP:
583 result = __cvmx_helper_loop_enable(interface);
586 result |= __cvmx_helper_board_hardware_enable(interface);
591 * Function to adjust internal IPD pointer alignments
593 * Returns 0 on success
596 int __cvmx_helper_errata_fix_ipd_ptr_alignment(void)
598 #define FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES \
599 (CVMX_FPA_PACKET_POOL_SIZE-8-CVMX_HELPER_FIRST_MBUFF_SKIP)
600 #define FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES \
601 (CVMX_FPA_PACKET_POOL_SIZE-8-CVMX_HELPER_NOT_FIRST_MBUFF_SKIP)
602 #define FIX_IPD_OUTPORT 0
603 /* Ports 0-15 are interface 0, 16-31 are interface 1 */
604 #define INTERFACE(port) (port >> 4)
605 #define INDEX(port) (port & 0xf)
607 cvmx_pko_command_word0_t pko_command;
608 union cvmx_buf_ptr g_buffer, pkt_buffer;
610 int size, num_segs = 0, wqe_pcnt, pkt_pcnt;
611 union cvmx_gmxx_prtx_cfg gmx_cfg;
615 cvmx_helper_link_info_t link_info;
617 /* Save values for restore at end */
619 cvmx_read_csr(CVMX_GMXX_PRTX_CFG
620 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
622 cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
624 cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
625 uint64_t rxx_jabber =
626 cvmx_read_csr(CVMX_GMXX_RXX_JABBER
627 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
629 cvmx_read_csr(CVMX_GMXX_RXX_FRM_MAX
630 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
632 /* Configure port to gig FDX as required for loopback mode */
633 cvmx_helper_rgmii_internal_loopback(FIX_IPD_OUTPORT);
636 * Disable reception on all ports so if traffic is present it
637 * will not interfere.
639 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)), 0);
641 cvmx_wait(100000000ull);
643 for (retry_loop_cnt = 0; retry_loop_cnt < 10; retry_loop_cnt++) {
645 wqe_pcnt = cvmx_read_csr(CVMX_IPD_PTR_COUNT);
646 pkt_pcnt = (wqe_pcnt >> 7) & 0x7f;
649 num_segs = (2 + pkt_pcnt - wqe_pcnt) & 3;
657 FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES +
658 ((num_segs - 1) * FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES) -
659 (FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES / 2);
661 cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)),
662 1 << INDEX(FIX_IPD_OUTPORT));
667 cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_WQE_POOL));
668 if (g_buffer.s.addr == 0) {
669 cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
670 "buffer allocation failure.\n");
674 g_buffer.s.pool = CVMX_FPA_WQE_POOL;
675 g_buffer.s.size = num_segs;
679 cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_PACKET_POOL));
680 if (pkt_buffer.s.addr == 0) {
681 cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
682 "buffer allocation failure.\n");
686 pkt_buffer.s.pool = CVMX_FPA_PACKET_POOL;
687 pkt_buffer.s.size = FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES;
689 p64 = (uint64_t *) cvmx_phys_to_ptr(pkt_buffer.s.addr);
690 p64[0] = 0xffffffffffff0000ull;
691 p64[1] = 0x08004510ull;
692 p64[2] = ((uint64_t) (size - 14) << 48) | 0x5ae740004000ull;
693 p64[3] = 0x3a5fc0a81073c0a8ull;
695 for (i = 0; i < num_segs; i++) {
698 FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES;
700 if (i == (num_segs - 1))
703 *(uint64_t *) cvmx_phys_to_ptr(g_buffer.s.addr +
704 8 * i) = pkt_buffer.u64;
707 /* Build the PKO command */
709 pko_command.s.segs = num_segs;
710 pko_command.s.total_bytes = size;
711 pko_command.s.dontfree = 0;
712 pko_command.s.gather = 1;
715 cvmx_read_csr(CVMX_GMXX_PRTX_CFG
716 (INDEX(FIX_IPD_OUTPORT),
717 INTERFACE(FIX_IPD_OUTPORT)));
719 cvmx_write_csr(CVMX_GMXX_PRTX_CFG
720 (INDEX(FIX_IPD_OUTPORT),
721 INTERFACE(FIX_IPD_OUTPORT)), gmx_cfg.u64);
722 cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
723 1 << INDEX(FIX_IPD_OUTPORT));
724 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
725 1 << INDEX(FIX_IPD_OUTPORT));
727 cvmx_write_csr(CVMX_GMXX_RXX_JABBER
728 (INDEX(FIX_IPD_OUTPORT),
729 INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
730 cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
731 (INDEX(FIX_IPD_OUTPORT),
732 INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
734 cvmx_pko_send_packet_prepare(FIX_IPD_OUTPORT,
735 cvmx_pko_get_base_queue
737 CVMX_PKO_LOCK_CMD_QUEUE);
738 cvmx_pko_send_packet_finish(FIX_IPD_OUTPORT,
739 cvmx_pko_get_base_queue
740 (FIX_IPD_OUTPORT), pko_command,
741 g_buffer, CVMX_PKO_LOCK_CMD_QUEUE);
746 work = cvmx_pow_work_request_sync(CVMX_POW_WAIT);
748 } while ((work == NULL) && (retry_cnt > 0));
751 cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
752 "get_work() timeout occurred.\n");
756 cvmx_helper_free_packet_data(work);
761 /* Return CSR configs to saved values */
762 cvmx_write_csr(CVMX_GMXX_PRTX_CFG
763 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
765 cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
767 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
769 cvmx_write_csr(CVMX_GMXX_RXX_JABBER
770 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
772 cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
773 (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
775 cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)), 0);
776 /* Set link to down so autonegotiation will set it up again */
778 cvmx_helper_link_set(FIX_IPD_OUTPORT, link_info);
781 * Bring the link back up as autonegotiation is not done in
784 cvmx_helper_link_autoconf(FIX_IPD_OUTPORT);
788 cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT failed.\n");
795 * Called after all internal packet IO paths are setup. This
796 * function enables IPD/PIP and begins packet input and output.
798 * Returns Zero on success, negative on failure
800 int cvmx_helper_ipd_and_packet_input_enable(void)
809 * Time to enable hardware ports packet input and output. Note
810 * that at this point IPD/PIP must be fully functional and PKO
813 num_interfaces = cvmx_helper_get_number_of_interfaces();
814 for (interface = 0; interface < num_interfaces; interface++) {
815 if (cvmx_helper_ports_on_interface(interface) > 0)
816 __cvmx_helper_packet_hardware_enable(interface);
819 /* Finally enable PKO now that the entire path is up and running */
822 if ((OCTEON_IS_MODEL(OCTEON_CN31XX_PASS1)
823 || OCTEON_IS_MODEL(OCTEON_CN30XX_PASS1))
824 && (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM))
825 __cvmx_helper_errata_fix_ipd_ptr_alignment();
830 * Initialize the PIP, IPD, and PKO hardware to support
831 * simple priority based queues for the ethernet ports. Each
832 * port is configured with a number of priority queues based
833 * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
834 * priority than the previous.
836 * Returns Zero on success, non-zero on failure
838 int cvmx_helper_initialize_packet_io_global(void)
842 union cvmx_l2c_cfg l2c_cfg;
843 union cvmx_smix_en smix_en;
844 const int num_interfaces = cvmx_helper_get_number_of_interfaces();
847 * CN52XX pass 1: Due to a bug in 2nd order CDR, it needs to
850 if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_0))
851 __cvmx_helper_errata_qlm_disable_2nd_order_cdr(1);
854 * Tell L2 to give the IOB statically higher priority compared
855 * to the cores. This avoids conditions where IO blocks might
856 * be starved under very high L2 loads.
858 l2c_cfg.u64 = cvmx_read_csr(CVMX_L2C_CFG);
859 l2c_cfg.s.lrf_arb_mode = 0;
860 l2c_cfg.s.rfb_arb_mode = 0;
861 cvmx_write_csr(CVMX_L2C_CFG, l2c_cfg.u64);
863 /* Make sure SMI/MDIO is enabled so we can query PHYs */
864 smix_en.u64 = cvmx_read_csr(CVMX_SMIX_EN(0));
867 cvmx_write_csr(CVMX_SMIX_EN(0), smix_en.u64);
870 /* Newer chips actually have two SMI/MDIO interfaces */
871 if (!OCTEON_IS_MODEL(OCTEON_CN3XXX) &&
872 !OCTEON_IS_MODEL(OCTEON_CN58XX) &&
873 !OCTEON_IS_MODEL(OCTEON_CN50XX)) {
874 smix_en.u64 = cvmx_read_csr(CVMX_SMIX_EN(1));
877 cvmx_write_csr(CVMX_SMIX_EN(1), smix_en.u64);
881 cvmx_pko_initialize_global();
882 for (interface = 0; interface < num_interfaces; interface++) {
883 result |= cvmx_helper_interface_probe(interface);
884 if (cvmx_helper_ports_on_interface(interface) > 0)
885 cvmx_dprintf("Interface %d has %d ports (%s)\n",
887 cvmx_helper_ports_on_interface(interface),
888 cvmx_helper_interface_mode_to_string
889 (cvmx_helper_interface_get_mode
891 result |= __cvmx_helper_interface_setup_ipd(interface);
892 result |= __cvmx_helper_interface_setup_pko(interface);
895 result |= __cvmx_helper_global_setup_ipd();
896 result |= __cvmx_helper_global_setup_pko();
898 /* Enable any flow control and backpressure */
899 result |= __cvmx_helper_global_setup_backpressure();
901 #if CVMX_HELPER_ENABLE_IPD
902 result |= cvmx_helper_ipd_and_packet_input_enable();
908 * Does core local initialization for packet io
910 * Returns Zero on success, non-zero on failure
912 int cvmx_helper_initialize_packet_io_local(void)
914 return cvmx_pko_initialize_local();
918 * Auto configure an IPD/PKO port link state and speed. This
919 * function basically does the equivalent of:
920 * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
922 * @ipd_port: IPD/PKO port to auto configure
924 * Returns Link state after configure
926 cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port)
928 cvmx_helper_link_info_t link_info;
929 int interface = cvmx_helper_get_interface_num(ipd_port);
930 int index = cvmx_helper_get_interface_index_num(ipd_port);
932 if (index >= cvmx_helper_ports_on_interface(interface)) {
937 link_info = cvmx_helper_link_get(ipd_port);
938 if (link_info.u64 == port_link_info[ipd_port].u64)
941 /* If we fail to set the link speed, port_link_info will not change */
942 cvmx_helper_link_set(ipd_port, link_info);
945 * port_link_info should be the current value, which will be
946 * different than expect if cvmx_helper_link_set() failed.
948 return port_link_info[ipd_port];
952 * Return the link state of an IPD/PKO port as returned by
953 * auto negotiation. The result of this function may not match
954 * Octeon's link config if auto negotiation has changed since
955 * the last call to cvmx_helper_link_set().
957 * @ipd_port: IPD/PKO port to query
961 cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port)
963 cvmx_helper_link_info_t result;
964 int interface = cvmx_helper_get_interface_num(ipd_port);
965 int index = cvmx_helper_get_interface_index_num(ipd_port);
967 /* The default result will be a down link unless the code below
971 if (index >= cvmx_helper_ports_on_interface(interface))
974 switch (cvmx_helper_interface_get_mode(interface)) {
975 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
976 case CVMX_HELPER_INTERFACE_MODE_PCIE:
977 /* Network links are not supported */
979 case CVMX_HELPER_INTERFACE_MODE_XAUI:
980 result = __cvmx_helper_xaui_link_get(ipd_port);
982 case CVMX_HELPER_INTERFACE_MODE_GMII:
984 result = __cvmx_helper_rgmii_link_get(ipd_port);
986 result.s.full_duplex = 1;
987 result.s.link_up = 1;
988 result.s.speed = 1000;
991 case CVMX_HELPER_INTERFACE_MODE_RGMII:
992 result = __cvmx_helper_rgmii_link_get(ipd_port);
994 case CVMX_HELPER_INTERFACE_MODE_SPI:
995 result = __cvmx_helper_spi_link_get(ipd_port);
997 case CVMX_HELPER_INTERFACE_MODE_SGMII:
998 case CVMX_HELPER_INTERFACE_MODE_PICMG:
999 result = __cvmx_helper_sgmii_link_get(ipd_port);
1001 case CVMX_HELPER_INTERFACE_MODE_NPI:
1002 case CVMX_HELPER_INTERFACE_MODE_LOOP:
1003 /* Network links are not supported */
1010 * Configure an IPD/PKO port for the specified link state. This
1011 * function does not influence auto negotiation at the PHY level.
1012 * The passed link state must always match the link state returned
1013 * by cvmx_helper_link_get(). It is normally best to use
1014 * cvmx_helper_link_autoconf() instead.
1016 * @ipd_port: IPD/PKO port to configure
1017 * @link_info: The new link state
1019 * Returns Zero on success, negative on failure
1021 int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info)
1024 int interface = cvmx_helper_get_interface_num(ipd_port);
1025 int index = cvmx_helper_get_interface_index_num(ipd_port);
1027 if (index >= cvmx_helper_ports_on_interface(interface))
1030 switch (cvmx_helper_interface_get_mode(interface)) {
1031 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
1032 case CVMX_HELPER_INTERFACE_MODE_PCIE:
1034 case CVMX_HELPER_INTERFACE_MODE_XAUI:
1035 result = __cvmx_helper_xaui_link_set(ipd_port, link_info);
1038 * RGMII/GMII/MII are all treated about the same. Most
1039 * functions refer to these ports as RGMII.
1041 case CVMX_HELPER_INTERFACE_MODE_RGMII:
1042 case CVMX_HELPER_INTERFACE_MODE_GMII:
1043 result = __cvmx_helper_rgmii_link_set(ipd_port, link_info);
1045 case CVMX_HELPER_INTERFACE_MODE_SPI:
1046 result = __cvmx_helper_spi_link_set(ipd_port, link_info);
1048 case CVMX_HELPER_INTERFACE_MODE_SGMII:
1049 case CVMX_HELPER_INTERFACE_MODE_PICMG:
1050 result = __cvmx_helper_sgmii_link_set(ipd_port, link_info);
1052 case CVMX_HELPER_INTERFACE_MODE_NPI:
1053 case CVMX_HELPER_INTERFACE_MODE_LOOP:
1056 /* Set the port_link_info here so that the link status is updated
1057 no matter how cvmx_helper_link_set is called. We don't change
1058 the value if link_set failed */
1060 port_link_info[ipd_port].u64 = link_info.u64;
1065 * Configure a port for internal and/or external loopback. Internal loopback
1066 * causes packets sent by the port to be received by Octeon. External loopback
1067 * causes packets received from the wire to sent out again.
1069 * @ipd_port: IPD/PKO port to loopback.
1071 * Non zero if you want internal loopback
1073 * Non zero if you want external loopback
1075 * Returns Zero on success, negative on failure.
1077 int cvmx_helper_configure_loopback(int ipd_port, int enable_internal,
1078 int enable_external)
1081 int interface = cvmx_helper_get_interface_num(ipd_port);
1082 int index = cvmx_helper_get_interface_index_num(ipd_port);
1084 if (index >= cvmx_helper_ports_on_interface(interface))
1087 switch (cvmx_helper_interface_get_mode(interface)) {
1088 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
1089 case CVMX_HELPER_INTERFACE_MODE_PCIE:
1090 case CVMX_HELPER_INTERFACE_MODE_SPI:
1091 case CVMX_HELPER_INTERFACE_MODE_NPI:
1092 case CVMX_HELPER_INTERFACE_MODE_LOOP:
1094 case CVMX_HELPER_INTERFACE_MODE_XAUI:
1096 __cvmx_helper_xaui_configure_loopback(ipd_port,
1100 case CVMX_HELPER_INTERFACE_MODE_RGMII:
1101 case CVMX_HELPER_INTERFACE_MODE_GMII:
1103 __cvmx_helper_rgmii_configure_loopback(ipd_port,
1107 case CVMX_HELPER_INTERFACE_MODE_SGMII:
1108 case CVMX_HELPER_INTERFACE_MODE_PICMG:
1110 __cvmx_helper_sgmii_configure_loopback(ipd_port,