1 /***********************license start***************
2 * Copyright (c) 2003-2011 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 * Helper functions to abstract board specific data about
50 * network ports from the rest of the cvmx-helper files.
52 * <hr>$Revision: 70030 $<hr>
54 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
55 #include <linux/module.h>
56 #include <asm/octeon/cvmx.h>
57 #include <asm/octeon/cvmx-bootinfo.h>
58 #include <asm/octeon/cvmx-smix-defs.h>
59 #include <asm/octeon/cvmx-gmxx-defs.h>
60 #include <asm/octeon/cvmx-asxx-defs.h>
61 #include <asm/octeon/cvmx-mdio.h>
62 #include <asm/octeon/cvmx-helper.h>
63 #include <asm/octeon/cvmx-helper-util.h>
64 #include <asm/octeon/cvmx-helper-board.h>
65 #include <asm/octeon/cvmx-twsi.h>
68 #include "cvmx-app-init.h"
69 #include "cvmx-sysinfo.h"
70 #include "cvmx-twsi.h"
71 #include "cvmx-mdio.h"
72 #include "cvmx-helper.h"
73 #include "cvmx-helper-util.h"
74 #include "cvmx-helper-board.h"
75 #include "cvmx-gpio.h"
76 #if !defined(__FreeBSD__) || !defined(_KERNEL)
80 # include "libfdt/libfdt.h"
83 #include "cvmx-swap.h"
87 * cvmx_override_board_link_get(int ipd_port) is a function
88 * pointer. It is meant to allow customization of the process of
89 * talking to a PHY to determine link speed. It is called every
90 * time a PHY must be polled for link status. Users should set
91 * this pointer to a function before calling any cvmx-helper
94 CVMX_SHARED cvmx_helper_link_info_t (*cvmx_override_board_link_get)(int ipd_port) = NULL;
96 #if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && (!defined(__FreeBSD__) || !defined(_KERNEL))
98 static void cvmx_retry_i2c_write(int twsi_id, uint8_t dev_addr, uint16_t internal_addr, int num_bytes, int ia_width_bytes, uint64_t data)
103 r = cvmx_twsix_write_ia(twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, data);
104 } while (tries-- > 0 && r < 0);
107 static int __pip_eth_node(const void *fdt_addr, int aliases, int ipd_port)
109 char name_buffer[20];
112 int interface_num = cvmx_helper_get_interface_num(ipd_port);
113 int interface_index = cvmx_helper_get_interface_index_num(ipd_port);
115 pip_path = fdt_getprop(fdt_addr, aliases, "pip", NULL);
118 cvmx_dprintf("ERROR: pip path not found in device tree\n");
121 pip = fdt_path_offset(fdt_addr, pip_path);
124 cvmx_dprintf("ERROR: pip not found in device tree\n");
128 sprintf(name_buffer, "interface@%d", interface_num);
130 snprintf(name_buffer, sizeof(name_buffer), "interface@%d", interface_num);
132 iface = fdt_subnode_offset(fdt_addr, pip, name_buffer);
135 cvmx_dprintf("ERROR : pip intf %d not found in device tree \n",
140 sprintf(name_buffer, "ethernet@%x", interface_index);
142 snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", interface_index);
144 eth = fdt_subnode_offset(fdt_addr, iface, name_buffer);
147 cvmx_dprintf("ERROR : pip interface@%d ethernet@%d not found in device "
148 "tree\n", interface_num, interface_index);
154 static int __mix_eth_node(const void *fdt_addr, int aliases, int interface_index)
156 char name_buffer[20];
161 sprintf(name_buffer, "mix%d", interface_index);
163 snprintf(name_buffer, sizeof(name_buffer), "mix%d", interface_index);
165 mix_path = fdt_getprop(fdt_addr, aliases, name_buffer, NULL);
168 cvmx_dprintf("ERROR: mix%d path not found in device tree\n",interface_index);
170 mix = fdt_path_offset(fdt_addr, mix_path);
173 cvmx_dprintf("ERROR: %s not found in device tree\n", mix_path);
179 typedef struct cvmx_phy_info
183 cvmx_phy_type_t phy_type;
187 static int __mdiobus_addr_to_unit(uint32_t addr)
189 int unit = (addr >> 7) & 3;
190 if (!OCTEON_IS_MODEL(OCTEON_CN68XX))
195 * Return the MII PHY address associated with the given IPD
196 * port. The phy address is obtained from the device tree.
198 * @param ipd_port Octeon IPD port to get the MII address for.
200 * @return MII PHY address and bus number or -1.
203 static cvmx_phy_info_t __get_phy_info_from_dt(int ipd_port)
205 const void *fdt_addr = CASTPTR(const void *, cvmx_sysinfo_get()->fdt_addr);
206 uint32_t *phy_handle;
207 int aliases, eth, phy, phy_parent, phandle, ret;
208 cvmx_phy_info_t phy_info;
210 const char *phy_comaptible_str;
211 uint32_t *phy_addr_ptr;
213 phy_info.phy_addr = -1;
214 phy_info.direct_connect = -1;
215 phy_info.phy_type = (cvmx_phy_type_t) -1;
219 cvmx_dprintf("No device tree found.\n");
222 aliases = fdt_path_offset(fdt_addr, "/aliases");
224 cvmx_dprintf("Error: No /aliases node in device tree.\n");
229 int interface_index = ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT;
230 eth = __mix_eth_node(fdt_addr, aliases, interface_index) ;
234 eth = __pip_eth_node(fdt_addr, aliases, ipd_port);
238 cvmx_dprintf("ERROR : cannot find interface for ipd_port=%d\n", ipd_port);
241 /* Get handle to phy */
242 phy_handle = (uint32_t *) fdt_getprop(fdt_addr, eth, "phy-handle", NULL);
245 cvmx_dprintf("ERROR : phy handle not found in device tree ipd_port=%d"
249 phandle = cvmx_be32_to_cpu(*phy_handle);
250 phy = fdt_node_offset_by_phandle(fdt_addr, phandle);
253 cvmx_dprintf("ERROR : cannot find phy for ipd_port=%d ret=%d\n",
257 phy_comaptible_str = (const char *) fdt_getprop(fdt_addr, phy,
259 if (!phy_comaptible_str)
261 cvmx_dprintf("ERROR : no compatible prop in phy\n");
264 if (memcmp("marvell", phy_comaptible_str, strlen("marvell")) == 0)
266 phy_info.phy_type = MARVELL_GENERIC_PHY;
268 else if (memcmp("broadcom", phy_comaptible_str, strlen("broadcom")) == 0)
270 phy_info.phy_type = BROADCOM_GENERIC_PHY;
274 phy_info.phy_type = -1;
277 /* Check if PHY parent is the octeon MDIO bus. Some boards are connected
278 though a MUX and for them direct_connect_to_phy will be 0 */
279 phy_parent = fdt_parent_offset(fdt_addr, phy);
282 cvmx_dprintf("ERROR : cannot find phy parent for ipd_port=%d ret=%d\n",
283 ipd_port, phy_parent);
286 ret = fdt_node_check_compatible(fdt_addr, phy_parent,
287 "cavium,octeon-3860-mdio");
290 phy_info.direct_connect = 1 ;
291 uint32_t *mdio_reg_base = (uint32_t *) fdt_getprop(fdt_addr, phy_parent,"reg",0);
292 if (mdio_reg_base == 0)
294 cvmx_dprintf("ERROR : unable to get reg property in phy mdio\n");
297 mdio_unit = __mdiobus_addr_to_unit(mdio_reg_base[1]);
298 //cvmx_dprintf("phy parent=%s reg_base=%08x unit=%d \n",
299 // fdt_get_name(fdt_addr,phy_parent, NULL), mdio_reg_base[1], mdio_unit);
303 phy_info.direct_connect = 0;
304 /* The PHY is not directly connected to the Octeon MDIO bus.
305 SE doesn't have abstractions for MDIO MUX or MDIO MUX drivers and
306 hence for the non direct cases code will be needed which is
308 For now the the MDIO Unit is defaulted to 1.
313 phy_addr_ptr = (uint32_t *) fdt_getprop(fdt_addr, phy, "reg", NULL);
314 phy_info.phy_addr = cvmx_be32_to_cpu(*phy_addr_ptr) | mdio_unit << 8;
320 * Return the MII PHY address associated with the given IPD
321 * port. The phy address is obtained from the device tree.
323 * @param ipd_port Octeon IPD port to get the MII address for.
325 * @return MII PHY address and bus number or -1.
328 int cvmx_helper_board_get_mii_address_from_dt(int ipd_port)
330 cvmx_phy_info_t phy_info = __get_phy_info_from_dt(ipd_port);
331 return phy_info.phy_addr;
336 * Return the MII PHY address associated with the given IPD
337 * port. A result of -1 means there isn't a MII capable PHY
338 * connected to this port. On chips supporting multiple MII
339 * busses the bus number is encoded in bits <15:8>.
341 * This function must be modified for every new Octeon board.
342 * Internally it uses switch statements based on the cvmx_sysinfo
343 * data to determine board types and revisions. It replies on the
344 * fact that every Octeon board receives a unique board type
345 * enumeration from the bootloader.
347 * @param ipd_port Octeon IPD port to get the MII address for.
349 * @return MII PHY address and bus number or -1.
351 int cvmx_helper_board_get_mii_address(int ipd_port)
354 * Board types we have to know at compile-time.
356 #ifdef OCTEON_BOARD_CAPK_0100ND
363 /* XXX Switch PHY? */
371 * For board types we can determine at runtime.
373 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
375 #if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && (!defined(__FreeBSD__) || !defined(_KERNEL))
376 if (cvmx_sysinfo_get()->fdt_addr)
378 cvmx_phy_info_t phy_info = __get_phy_info_from_dt(ipd_port);
379 //cvmx_dprintf("ipd_port=%d phy_addr=%d\n", ipd_port, phy_info.phy_addr);
380 if (phy_info.phy_addr >= 0) return phy_info.phy_addr;
383 switch (cvmx_sysinfo_get()->board_type)
385 case CVMX_BOARD_TYPE_SIM:
386 /* Simulator doesn't have MII */
388 #if !defined(OCTEON_VENDOR_GEFES)
389 case CVMX_BOARD_TYPE_EBT5800:
390 case CVMX_BOARD_TYPE_NICPRO2:
392 case CVMX_BOARD_TYPE_EBT3000:
393 case CVMX_BOARD_TYPE_THUNDER:
394 /* Interface 0 is SPI4, interface 1 is RGMII */
395 if ((ipd_port >= 16) && (ipd_port < 20))
396 return ipd_port - 16;
399 case CVMX_BOARD_TYPE_LANAI2_A:
404 case CVMX_BOARD_TYPE_LANAI2_U:
405 case CVMX_BOARD_TYPE_LANAI2_G:
410 case CVMX_BOARD_TYPE_KODAMA:
411 case CVMX_BOARD_TYPE_EBH3100:
412 case CVMX_BOARD_TYPE_HIKARI:
413 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
414 case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
415 #if !defined(OCTEON_VENDOR_GEFES)
416 case CVMX_BOARD_TYPE_CN3020_EVB_HS5:
418 /* Port 0 is WAN connected to a PHY, Port 1 is GMII connected to a
422 else if (ipd_port == 1)
426 case CVMX_BOARD_TYPE_EBH3000:
427 /* Board has dual SPI4 and no PHYs */
429 case CVMX_BOARD_TYPE_EBT5810:
430 /* Board has 10g PHYs hooked up to the MII controller on the
431 ** IXF18201 MAC. The 10G PHYS use clause 45 MDIO which the CN58XX
432 ** does not support. All MII accesses go through the IXF part. */
434 case CVMX_BOARD_TYPE_EBH5200:
435 case CVMX_BOARD_TYPE_EBH5201:
436 case CVMX_BOARD_TYPE_EBT5200:
437 /* Board has 2 management ports */
438 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
439 return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT;
440 /* Board has 4 SGMII ports. The PHYs start right after the MII
441 ports MII0 = 0, MII1 = 1, SGMII = 2-5 */
442 if ((ipd_port >= 0) && (ipd_port < 4))
446 case CVMX_BOARD_TYPE_EBH5600:
447 case CVMX_BOARD_TYPE_EBH5601:
448 case CVMX_BOARD_TYPE_EBH5610:
449 /* Board has 1 management port */
450 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
452 /* Board has 8 SGMII ports. 4 connect out, two connect to a switch,
453 and 2 loop to each other */
454 if ((ipd_port >= 0) && (ipd_port < 4))
458 case CVMX_BOARD_TYPE_EBT5600:
459 /* Board has 1 management port */
460 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
462 /* Board has 1 XAUI port connected to a switch. */
464 case CVMX_BOARD_TYPE_EBB5600:
466 static unsigned char qlm_switch_addr = 0;
468 /* Board has 1 management port */
469 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
472 /* Board has 8 SGMII ports. 4 connected QLM1, 4 connected QLM3 */
473 if ((ipd_port >= 0) && (ipd_port < 4))
475 if (qlm_switch_addr != 0x3)
477 qlm_switch_addr = 0x3; /* QLM1 */
478 cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr);
479 cvmx_wait_usec(11000); /* Let the write complete */
481 return ipd_port+1 + (1<<8);
483 else if ((ipd_port >= 16) && (ipd_port < 20))
485 if (qlm_switch_addr != 0xC)
487 qlm_switch_addr = 0xC; /* QLM3 */
488 cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr);
489 cvmx_wait_usec(11000); /* Let the write complete */
491 return ipd_port-16+1 + (1<<8);
496 case CVMX_BOARD_TYPE_EBB6300:
497 /* Board has 2 management ports */
498 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
499 return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT + 4;
500 if ((ipd_port >= 0) && (ipd_port < 4))
501 return ipd_port + 1 + (1<<8);
504 case CVMX_BOARD_TYPE_EBB6800:
505 /* Board has 1 management ports */
506 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
508 if (ipd_port >= 0x800 && ipd_port < 0x900) /* QLM 0*/
509 return 0x101 + ((ipd_port >> 4) & 3); /* SMI 1*/
510 if (ipd_port >= 0xa00 && ipd_port < 0xb00) /* QLM 2*/
511 return 0x201 + ((ipd_port >> 4) & 3); /* SMI 2*/
512 if (ipd_port >= 0xb00 && ipd_port < 0xc00) /* QLM 3*/
513 return 0x301 + ((ipd_port >> 4) & 3); /* SMI 3*/
514 if (ipd_port >= 0xc00 && ipd_port < 0xd00) /* QLM 4*/
515 return 0x001 + ((ipd_port >> 4) & 3); /* SMI 0*/
517 case CVMX_BOARD_TYPE_EP6300C:
518 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
520 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT+1)
522 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
524 int interface = cvmx_helper_get_interface_num(ipd_port);
525 int mode = cvmx_helper_interface_get_mode(interface);
526 if (mode == CVMX_HELPER_INTERFACE_MODE_XAUI)
528 else if ((ipd_port >= 0) && (ipd_port < 4))
535 case CVMX_BOARD_TYPE_CUST_NB5:
540 case CVMX_BOARD_TYPE_NIC_XLE_4G:
541 /* Board has 4 SGMII ports. connected QLM3(interface 1) */
542 if ((ipd_port >= 16) && (ipd_port < 20))
543 return ipd_port - 16 + 1;
546 case CVMX_BOARD_TYPE_NIC_XLE_10G:
547 case CVMX_BOARD_TYPE_NIC10E:
548 return -1; /* We don't use clause 45 MDIO for anything */
549 case CVMX_BOARD_TYPE_NIC4E:
550 if (ipd_port >= 0 && ipd_port <= 3)
551 return (ipd_port + 0x1f) & 0x1f;
554 case CVMX_BOARD_TYPE_NIC2E:
555 if (ipd_port >= 0 && ipd_port <= 1)
556 return (ipd_port + 1);
559 case CVMX_BOARD_TYPE_REDWING:
560 return -1; /* No PHYs connected to Octeon */
561 case CVMX_BOARD_TYPE_BBGW_REF:
562 return -1; /* No PHYs are connected to Octeon, everything is through switch */
563 case CVMX_BOARD_TYPE_CUST_WSX16:
564 if (ipd_port >= 0 && ipd_port <= 3)
566 else if (ipd_port >= 16 && ipd_port <= 19)
567 return ipd_port - 16 + 4;
571 /* Private vendor-defined boards. */
572 #if defined(OCTEON_VENDOR_LANNER)
573 case CVMX_BOARD_TYPE_CUST_LANNER_MR955:
574 /* Interface 1 is 12 BCM5482S PHYs. */
575 if ((ipd_port >= 16) && (ipd_port < 28))
576 return ipd_port - 16;
578 case CVMX_BOARD_TYPE_CUST_LANNER_MR730:
579 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
580 return (ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT) + 0x81;
581 if ((ipd_port >= 0) && (ipd_port < 4))
584 case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
585 case CVMX_BOARD_TYPE_CUST_LANNER_MR321X:
586 /* Port 0 is a Marvell 88E6161 switch, ports 1 and 2 are Marvell
587 88E1111 interfaces. */
599 #if defined(OCTEON_VENDOR_UBIQUITI)
600 case CVMX_BOARD_TYPE_CUST_UBIQUITI_E100:
603 return (7 - ipd_port);
605 #if defined(OCTEON_VENDOR_RADISYS)
606 case CVMX_BOARD_TYPE_CUST_RADISYS_RSYS4GBE:
610 #if defined(OCTEON_VENDOR_GEFES)
611 case CVMX_BOARD_TYPE_AT5810:
613 case CVMX_BOARD_TYPE_TNPA3804:
614 case CVMX_BOARD_TYPE_CUST_TNPA5804:
615 case CVMX_BOARD_TYPE_CUST_W5800:
616 case CVMX_BOARD_TYPE_WNPA3850:
617 case CVMX_BOARD_TYPE_W3860:
618 return -1;// RGMII boards should use inbad status
619 case CVMX_BOARD_TYPE_CUST_W5651X:
620 case CVMX_BOARD_TYPE_CUST_W5650:
621 case CVMX_BOARD_TYPE_CUST_TNPA56X4:
622 case CVMX_BOARD_TYPE_CUST_TNPA5651X:
623 case CVMX_BOARD_TYPE_CUST_W63XX:
624 return -1; /* No PHYs are connected to Octeon, PHYs inside of SFPs which is accessed over TWSI */
625 case CVMX_BOARD_TYPE_CUST_W5434:
626 /* Board has 4 SGMII ports. 4 connect out
627 * must return the MII address of the PHY connected to each IPD port
629 if ((ipd_port >= 16) && (ipd_port < 20))
630 return ipd_port - 16 + 0x40;
636 /* Some unknown board. Somebody forgot to update this function... */
637 cvmx_dprintf("%s: Unknown board type %d\n",
638 __FUNCTION__, cvmx_sysinfo_get()->board_type);
641 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
642 EXPORT_SYMBOL(cvmx_helper_board_get_mii_address);
647 * Get link state of marvell PHY
649 static cvmx_helper_link_info_t __get_marvell_phy_link_state(int phy_addr)
651 cvmx_helper_link_info_t result;
655 /*All the speed information can be read from register 17 in one go.*/
656 phy_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 17);
658 /* If the resolve bit 11 isn't set, see if autoneg is turned off
659 (bit 12, reg 0). The resolve bit doesn't get set properly when
660 autoneg is off, so force it */
661 if ((phy_status & (1<<11)) == 0)
663 int auto_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0);
664 if ((auto_status & (1<<12)) == 0)
668 /* Only return a link if the PHY has finished auto negotiation
669 and set the resolved bit (bit 11) */
670 if (phy_status & (1<<11))
672 result.s.link_up = 1;
673 result.s.full_duplex = ((phy_status>>13)&1);
674 switch ((phy_status>>14)&3)
676 case 0: /* 10 Mbps */
679 case 1: /* 100 Mbps */
680 result.s.speed = 100;
683 result.s.speed = 1000;
685 case 3: /* Illegal */
695 * Get link state of broadcom PHY
697 static cvmx_helper_link_info_t __get_broadcom_phy_link_state(int phy_addr)
699 cvmx_helper_link_info_t result;
703 /* Below we are going to read SMI/MDIO register 0x19 which works
705 phy_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0x19);
706 switch ((phy_status>>8) & 0x7)
712 result.s.link_up = 1;
713 result.s.full_duplex = 0;
717 result.s.link_up = 1;
718 result.s.full_duplex = 1;
722 result.s.link_up = 1;
723 result.s.full_duplex = 0;
724 result.s.speed = 100;
727 result.s.link_up = 1;
728 result.s.full_duplex = 1;
729 result.s.speed = 100;
732 result.s.link_up = 1;
733 result.s.full_duplex = 1;
734 result.s.speed = 100;
737 result.s.link_up = 1;
738 result.s.full_duplex = 0;
739 result.s.speed = 1000;
742 result.s.link_up = 1;
743 result.s.full_duplex = 1;
744 result.s.speed = 1000;
753 * Get link state using inband status
755 static cvmx_helper_link_info_t __get_inband_link_state(int ipd_port)
757 cvmx_helper_link_info_t result;
758 cvmx_gmxx_rxx_rx_inbnd_t inband_status;
759 int interface = cvmx_helper_get_interface_num(ipd_port);
760 int index = cvmx_helper_get_interface_index_num(ipd_port);
763 inband_status.u64 = cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index, interface));
764 result.s.link_up = inband_status.s.status;
765 result.s.full_duplex = inband_status.s.duplex;
766 switch (inband_status.s.speed)
768 case 0: /* 10 Mbps */
771 case 1: /* 100 Mbps */
772 result.s.speed = 100;
775 result.s.speed = 1000;
777 case 3: /* Illegal */
784 #if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && (!defined(__FreeBSD__) || !defined(_KERNEL))
787 * Switch MDIO mux to the specified port.
789 static int __switch_mdio_mux(int ipd_port)
791 /* This method is board specific and doesn't use the device tree
792 information as SE doesn't implement MDIO MUX abstration */
793 switch (cvmx_sysinfo_get()->board_type)
795 case CVMX_BOARD_TYPE_EBB5600:
797 static unsigned char qlm_switch_addr = 0;
798 /* Board has 1 management port */
799 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
801 /* Board has 8 SGMII ports. 4 connected QLM1, 4 connected QLM3 */
802 if ((ipd_port >= 0) && (ipd_port < 4))
804 if (qlm_switch_addr != 0x3)
806 qlm_switch_addr = 0x3; /* QLM1 */
807 cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr);
808 cvmx_wait_usec(11000); /* Let the write complete */
810 return ipd_port+1 + (1<<8);
812 else if ((ipd_port >= 16) && (ipd_port < 20))
814 if (qlm_switch_addr != 0xC)
816 qlm_switch_addr = 0xC; /* QLM3 */
817 cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr);
818 cvmx_wait_usec(11000); /* Let the write complete */
820 return ipd_port-16+1 + (1<<8);
825 case CVMX_BOARD_TYPE_EBB6600:
827 static unsigned char qlm_switch_addr = 0;
828 int old_twsi_switch_reg;
829 /* Board has 2 management ports */
830 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) &&
831 (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
832 return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT + 4;
833 if ((ipd_port >= 0) && (ipd_port < 4)) /* QLM 2 */
835 if (qlm_switch_addr != 2)
841 old_twsi_switch_reg = cvmx_twsix_read8(0, 0x70, 0);
842 } while (tries-- > 0 && old_twsi_switch_reg < 0);
843 /* Set I2C MUX to enable port expander */
844 cvmx_retry_i2c_write(0, 0x70, 0, 1, 0, 8);
845 /* Set selecter to QLM 1 */
846 cvmx_retry_i2c_write(0, 0x38, 0, 1, 0, 0xff);
847 /* disable port expander */
848 cvmx_retry_i2c_write(0, 0x70, 0, 1, 0, old_twsi_switch_reg);
850 return 0x101 + ipd_port;
852 else if ((ipd_port >= 16) && (ipd_port < 20)) /* QLM 1 */
854 if (qlm_switch_addr != 1)
860 old_twsi_switch_reg = cvmx_twsix_read8(0, 0x70, 0);
861 } while (tries-- > 0 && old_twsi_switch_reg < 0);
862 /* Set I2C MUX to enable port expander */
863 cvmx_retry_i2c_write(0, 0x70, 0, 1, 0, 8);
864 /* Set selecter to QLM 2 */
865 cvmx_retry_i2c_write(0, 0x38, 0, 1, 0, 0xf7);
866 /* disable port expander */
867 cvmx_retry_i2c_write(0, 0x70, 0, 1, 0, old_twsi_switch_reg);
869 return 0x101 + (ipd_port - 16);
873 case CVMX_BOARD_TYPE_EBB6100:
875 static char gpio_configured = 0;
877 if (!gpio_configured)
882 /* Board has 2 management ports */
883 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) &&
884 (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
885 return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT + 4;
886 if ((ipd_port >= 0) && (ipd_port < 4)) /* QLM 2 */
888 cvmx_gpio_set(1ull << 3);
889 return 0x101 + ipd_port;
891 else if ((ipd_port >= 16) && (ipd_port < 20)) /* QLM 0 */
893 cvmx_gpio_clear(1ull << 3);
894 return 0x101 + (ipd_port - 16);
898 printf("%s: Unknown ipd port 0x%x\n", __func__, ipd_port);
904 cvmx_dprintf("ERROR : unexpected mdio switch for board=%08x\n",
905 cvmx_sysinfo_get()->board_type);
909 /* should never get here */
915 * This function is used ethernet ports link speed. This functions uses the
916 * device tree information to determine the phy address and type of PHY.
917 * The only supproted PHYs are Marvell and Broadcom.
919 * @param ipd_port IPD input port associated with the port we want to get link
922 * @return The ports link status. If the link isn't fully resolved, this must
926 cvmx_helper_link_info_t __cvmx_helper_board_link_get_from_dt(int ipd_port)
928 cvmx_helper_link_info_t result;
929 cvmx_phy_info_t phy_info;
932 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
934 /* The simulator gives you a simulated 1Gbps full duplex link */
935 result.s.link_up = 1;
936 result.s.full_duplex = 1;
937 result.s.speed = 1000;
940 phy_info = __get_phy_info_from_dt(ipd_port);
941 //cvmx_dprintf("ipd_port=%d phy_addr=%d dc=%d type=%d \n", ipd_port,
942 // phy_info.phy_addr, phy_info.direct_connect, phy_info.phy_type);
943 if (phy_info.phy_addr < 0) return result;
945 if (phy_info.direct_connect == 0)
946 __switch_mdio_mux(ipd_port);
947 switch(phy_info.phy_type)
949 case BROADCOM_GENERIC_PHY:
950 result = __get_broadcom_phy_link_state(phy_info.phy_addr);
952 case MARVELL_GENERIC_PHY:
953 result = __get_marvell_phy_link_state(phy_info.phy_addr);
956 result = __get_inband_link_state(ipd_port);
965 * This function invokes __cvmx_helper_board_link_get_from_dt when device tree
966 * info is available. When the device tree information is not available then
967 * this function is the board specific method of determining an
968 * ethernet ports link speed. Most Octeon boards have Marvell PHYs
969 * and are handled by the fall through case. This function must be
970 * updated for boards that don't have the normal Marvell PHYs.
972 * This function must be modified for every new Octeon board.
973 * Internally it uses switch statements based on the cvmx_sysinfo
974 * data to determine board types and revisions. It relies on the
975 * fact that every Octeon board receives a unique board type
976 * enumeration from the bootloader.
978 * @param ipd_port IPD input port associated with the port we want to get link
981 * @return The ports link status. If the link isn't fully resolved, this must
984 cvmx_helper_link_info_t __cvmx_helper_board_link_get(int ipd_port)
986 cvmx_helper_link_info_t result;
988 int is_broadcom_phy = 0;
990 #if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && (!defined(__FreeBSD__) || !defined(_KERNEL))
991 if (cvmx_sysinfo_get()->fdt_addr)
993 return __cvmx_helper_board_link_get_from_dt(ipd_port);
997 /* Give the user a chance to override the processing of this function */
998 if (cvmx_override_board_link_get)
999 return cvmx_override_board_link_get(ipd_port);
1001 /* Unless we fix it later, all links are defaulted to down */
1004 #if !defined(OCTEON_BOARD_CAPK_0100ND)
1005 /* This switch statement should handle all ports that either don't use
1006 Marvell PHYS, or don't support in-band status */
1007 switch (cvmx_sysinfo_get()->board_type)
1009 case CVMX_BOARD_TYPE_SIM:
1010 /* The simulator gives you a simulated 1Gbps full duplex link */
1011 result.s.link_up = 1;
1012 result.s.full_duplex = 1;
1013 result.s.speed = 1000;
1015 case CVMX_BOARD_TYPE_LANAI2_A:
1016 case CVMX_BOARD_TYPE_LANAI2_U:
1017 case CVMX_BOARD_TYPE_LANAI2_G:
1019 case CVMX_BOARD_TYPE_EBH3100:
1020 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
1021 case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
1022 #if !defined(OCTEON_VENDOR_GEFES)
1023 case CVMX_BOARD_TYPE_CN3020_EVB_HS5:
1025 /* Port 1 on these boards is always Gigabit */
1028 result.s.link_up = 1;
1029 result.s.full_duplex = 1;
1030 result.s.speed = 1000;
1033 /* Fall through to the generic code below */
1035 case CVMX_BOARD_TYPE_EBT5600:
1036 case CVMX_BOARD_TYPE_EBH5600:
1037 case CVMX_BOARD_TYPE_EBH5601:
1038 case CVMX_BOARD_TYPE_EBH5610:
1039 /* Board has 1 management ports */
1040 if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
1041 is_broadcom_phy = 1;
1043 case CVMX_BOARD_TYPE_EBH5200:
1044 case CVMX_BOARD_TYPE_EBH5201:
1045 case CVMX_BOARD_TYPE_EBT5200:
1046 /* Board has 2 management ports */
1047 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
1048 is_broadcom_phy = 1;
1050 case CVMX_BOARD_TYPE_EBB6100:
1051 case CVMX_BOARD_TYPE_EBB6300: /* Only for MII mode, with PHY addresses 0/1. Default is RGMII*/
1052 case CVMX_BOARD_TYPE_EBB6600: /* Only for MII mode, with PHY addresses 0/1. Default is RGMII*/
1053 if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2))
1054 && cvmx_helper_board_get_mii_address(ipd_port) >= 0 && cvmx_helper_board_get_mii_address(ipd_port) <= 1)
1055 is_broadcom_phy = 1;
1057 case CVMX_BOARD_TYPE_EP6300C:
1058 is_broadcom_phy = 1;
1060 case CVMX_BOARD_TYPE_CUST_NB5:
1061 /* Port 1 on these boards is always Gigabit */
1064 result.s.link_up = 1;
1065 result.s.full_duplex = 1;
1066 result.s.speed = 1000;
1069 else /* The other port uses a broadcom PHY */
1070 is_broadcom_phy = 1;
1072 case CVMX_BOARD_TYPE_BBGW_REF:
1073 /* Port 1 on these boards is always Gigabit */
1076 /* Port 2 is not hooked up */
1082 /* Ports 0 and 1 connect to the switch */
1083 result.s.link_up = 1;
1084 result.s.full_duplex = 1;
1085 result.s.speed = 1000;
1088 case CVMX_BOARD_TYPE_NIC4E:
1089 case CVMX_BOARD_TYPE_NIC2E:
1090 is_broadcom_phy = 1;
1092 /* Private vendor-defined boards. */
1093 #if defined(OCTEON_VENDOR_LANNER)
1094 case CVMX_BOARD_TYPE_CUST_LANNER_MR730:
1095 /* Ports are BCM5482S */
1096 is_broadcom_phy = 1;
1098 case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
1099 case CVMX_BOARD_TYPE_CUST_LANNER_MR321X:
1100 /* Port 0 connects to the switch */
1103 result.s.link_up = 1;
1104 result.s.full_duplex = 1;
1105 result.s.speed = 1000;
1110 #if defined(OCTEON_VENDOR_GEFES)
1111 case CVMX_BOARD_TYPE_CUST_TNPA5651X:
1112 /* Since we don't auto-negotiate... 1Gbps full duplex link */
1113 result.s.link_up = 1;
1114 result.s.full_duplex = 1;
1115 result.s.speed = 1000;
1122 phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
1123 //cvmx_dprintf("ipd_port=%d phy_addr=%d broadcom=%d\n",
1124 // ipd_port, phy_addr, is_broadcom_phy);
1127 if (is_broadcom_phy)
1129 result = __get_broadcom_phy_link_state(phy_addr);
1133 /* This code assumes we are using a Marvell Gigabit PHY. */
1134 result = __get_marvell_phy_link_state(phy_addr);
1137 else if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN58XX)
1138 || OCTEON_IS_MODEL(OCTEON_CN50XX))
1140 /* We don't have a PHY address, so attempt to use in-band status. It is
1141 really important that boards not supporting in-band status never get
1142 here. Reading broken in-band status tends to do bad things */
1143 result = __get_inband_link_state(ipd_port);
1145 #if defined(OCTEON_VENDOR_GEFES)
1146 else if( (OCTEON_IS_MODEL(OCTEON_CN56XX)) || (OCTEON_IS_MODEL(OCTEON_CN63XX)) )
1148 int interface = cvmx_helper_get_interface_num(ipd_port);
1149 int index = cvmx_helper_get_interface_index_num(ipd_port);
1150 cvmx_pcsx_miscx_ctl_reg_t mode_type;
1151 cvmx_pcsx_mrx_status_reg_t mrx_status;
1152 cvmx_pcsx_anx_adv_reg_t anxx_adv;
1153 cvmx_pcsx_sgmx_lp_adv_reg_t sgmii_inband_status;
1155 anxx_adv.u64 = cvmx_read_csr(CVMX_PCSX_ANX_ADV_REG(index, interface));
1156 mrx_status.u64 = cvmx_read_csr(CVMX_PCSX_MRX_STATUS_REG(index, interface));
1158 mode_type.u64 = cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
1160 /* Read Octeon's inband status */
1161 sgmii_inband_status.u64 = cvmx_read_csr(CVMX_PCSX_SGMX_LP_ADV_REG(index, interface));
1163 result.s.link_up = sgmii_inband_status.s.link;
1164 result.s.full_duplex = sgmii_inband_status.s.dup;
1165 switch (sgmii_inband_status.s.speed)
1167 case 0: /* 10 Mbps */
1168 result.s.speed = 10;
1170 case 1: /* 100 Mbps */
1171 result.s.speed = 100;
1173 case 2: /* 1 Gbps */
1174 result.s.speed = 1000;
1176 case 3: /* Illegal */
1178 result.s.link_up = 0;
1185 /* We don't have a PHY address and we don't have in-band status. There
1186 is no way to determine the link speed. Return down assuming this
1191 /* If link is down, return all fields as zero. */
1192 if (!result.s.link_up)
1200 * This function as a board specific method of changing the PHY
1201 * speed, duplex, and autonegotiation. This programs the PHY and
1202 * not Octeon. This can be used to force Octeon's links to
1203 * specific settings.
1205 * @param phy_addr The address of the PHY to program
1207 * Flags to control autonegotiation. Bit 0 is autonegotiation
1208 * enable/disable to maintain backward compatibility.
1209 * @param link_info Link speed to program. If the speed is zero and autonegotiation
1210 * is enabled, all possible negotiation speeds are advertised.
1212 * @return Zero on success, negative on failure
1214 int cvmx_helper_board_link_set_phy(int phy_addr, cvmx_helper_board_set_phy_link_flags_types_t link_flags,
1215 cvmx_helper_link_info_t link_info)
1218 /* Set the flow control settings based on link_flags */
1219 if ((link_flags & set_phy_link_flags_flow_control_mask) != set_phy_link_flags_flow_control_dont_touch)
1221 cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
1222 reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
1223 reg_autoneg_adver.s.asymmetric_pause = (link_flags & set_phy_link_flags_flow_control_mask) == set_phy_link_flags_flow_control_enable;
1224 reg_autoneg_adver.s.pause = (link_flags & set_phy_link_flags_flow_control_mask) == set_phy_link_flags_flow_control_enable;
1225 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16);
1228 /* If speed isn't set and autoneg is on advertise all supported modes */
1229 if ((link_flags & set_phy_link_flags_autoneg) && (link_info.s.speed == 0))
1231 cvmx_mdio_phy_reg_control_t reg_control;
1232 cvmx_mdio_phy_reg_status_t reg_status;
1233 cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
1234 cvmx_mdio_phy_reg_extended_status_t reg_extended_status;
1235 cvmx_mdio_phy_reg_control_1000_t reg_control_1000;
1237 reg_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_STATUS);
1238 reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
1239 reg_autoneg_adver.s.advert_100base_t4 = reg_status.s.capable_100base_t4;
1240 reg_autoneg_adver.s.advert_10base_tx_full = reg_status.s.capable_10_full;
1241 reg_autoneg_adver.s.advert_10base_tx_half = reg_status.s.capable_10_half;
1242 reg_autoneg_adver.s.advert_100base_tx_full = reg_status.s.capable_100base_x_full;
1243 reg_autoneg_adver.s.advert_100base_tx_half = reg_status.s.capable_100base_x_half;
1244 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16);
1245 if (reg_status.s.capable_extended_status)
1247 reg_extended_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_EXTENDED_STATUS);
1248 reg_control_1000.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000);
1249 reg_control_1000.s.advert_1000base_t_full = reg_extended_status.s.capable_1000base_t_full;
1250 reg_control_1000.s.advert_1000base_t_half = reg_extended_status.s.capable_1000base_t_half;
1251 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000, reg_control_1000.u16);
1253 reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL);
1254 reg_control.s.autoneg_enable = 1;
1255 reg_control.s.restart_autoneg = 1;
1256 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
1258 else if ((link_flags & set_phy_link_flags_autoneg))
1260 cvmx_mdio_phy_reg_control_t reg_control;
1261 cvmx_mdio_phy_reg_status_t reg_status;
1262 cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
1263 cvmx_mdio_phy_reg_control_1000_t reg_control_1000;
1265 reg_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_STATUS);
1266 reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
1267 reg_autoneg_adver.s.advert_100base_t4 = 0;
1268 reg_autoneg_adver.s.advert_10base_tx_full = 0;
1269 reg_autoneg_adver.s.advert_10base_tx_half = 0;
1270 reg_autoneg_adver.s.advert_100base_tx_full = 0;
1271 reg_autoneg_adver.s.advert_100base_tx_half = 0;
1272 if (reg_status.s.capable_extended_status)
1274 reg_control_1000.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000);
1275 reg_control_1000.s.advert_1000base_t_full = 0;
1276 reg_control_1000.s.advert_1000base_t_half = 0;
1278 switch (link_info.s.speed)
1281 reg_autoneg_adver.s.advert_10base_tx_full = link_info.s.full_duplex;
1282 reg_autoneg_adver.s.advert_10base_tx_half = !link_info.s.full_duplex;
1285 reg_autoneg_adver.s.advert_100base_tx_full = link_info.s.full_duplex;
1286 reg_autoneg_adver.s.advert_100base_tx_half = !link_info.s.full_duplex;
1289 reg_control_1000.s.advert_1000base_t_full = link_info.s.full_duplex;
1290 reg_control_1000.s.advert_1000base_t_half = !link_info.s.full_duplex;
1293 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16);
1294 if (reg_status.s.capable_extended_status)
1295 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000, reg_control_1000.u16);
1296 reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL);
1297 reg_control.s.autoneg_enable = 1;
1298 reg_control.s.restart_autoneg = 1;
1299 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
1303 cvmx_mdio_phy_reg_control_t reg_control;
1304 reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL);
1305 reg_control.s.autoneg_enable = 0;
1306 reg_control.s.restart_autoneg = 1;
1307 reg_control.s.duplex = link_info.s.full_duplex;
1308 if (link_info.s.speed == 1000)
1310 reg_control.s.speed_msb = 1;
1311 reg_control.s.speed_lsb = 0;
1313 else if (link_info.s.speed == 100)
1315 reg_control.s.speed_msb = 0;
1316 reg_control.s.speed_lsb = 1;
1318 else if (link_info.s.speed == 10)
1320 reg_control.s.speed_msb = 0;
1321 reg_control.s.speed_lsb = 0;
1323 cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
1331 * This function is called by cvmx_helper_interface_probe() after it
1332 * determines the number of ports Octeon can support on a specific
1333 * interface. This function is the per board location to override
1334 * this value. It is called with the number of ports Octeon might
1335 * support and should return the number of actual ports on the
1338 * This function must be modified for every new Octeon board.
1339 * Internally it uses switch statements based on the cvmx_sysinfo
1340 * data to determine board types and revisions. It relies on the
1341 * fact that every Octeon board receives a unique board type
1342 * enumeration from the bootloader.
1344 * @param interface Interface to probe
1345 * @param supported_ports
1346 * Number of ports Octeon supports.
1348 * @return Number of ports the actual board supports. Many times this will
1349 * simple be "support_ports".
1351 int __cvmx_helper_board_interface_probe(int interface, int supported_ports)
1353 switch (cvmx_sysinfo_get()->board_type)
1355 case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
1356 case CVMX_BOARD_TYPE_LANAI2_A:
1357 case CVMX_BOARD_TYPE_LANAI2_U:
1358 case CVMX_BOARD_TYPE_LANAI2_G:
1362 case CVMX_BOARD_TYPE_BBGW_REF:
1366 case CVMX_BOARD_TYPE_NIC_XLE_4G:
1370 /* The 2nd interface on the EBH5600 is connected to the Marvel switch,
1371 which we don't support. Disable ports connected to it */
1372 case CVMX_BOARD_TYPE_EBH5600:
1376 case CVMX_BOARD_TYPE_EBB5600:
1377 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
1378 if (cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_PICMG)
1382 case CVMX_BOARD_TYPE_EBT5600:
1383 /* Disable loopback. */
1387 case CVMX_BOARD_TYPE_EBT5810:
1388 return 1; /* Two ports on each SPI: 1 hooked to MAC, 1 loopback
1389 ** Loopback disabled by default. */
1390 case CVMX_BOARD_TYPE_NIC2E:
1393 #if defined(OCTEON_VENDOR_LANNER)
1394 case CVMX_BOARD_TYPE_CUST_LANNER_MR955:
1399 #if defined(OCTEON_VENDOR_GEFES)
1400 case CVMX_BOARD_TYPE_CUST_TNPA5651X:
1401 if (interface < 2) /* interface can be EITHER 0 or 1 */
1402 return 1;//always return 1 for XAUI and SGMII mode.
1404 case CVMX_BOARD_TYPE_CUST_TNPA56X4:
1405 if ((interface == 0) &&
1406 (cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_SGMII))
1408 cvmx_pcsx_miscx_ctl_reg_t pcsx_miscx_ctl_reg;
1410 /* For this port we need to set the mode to 1000BaseX */
1411 pcsx_miscx_ctl_reg.u64 =
1412 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(0, interface));
1413 pcsx_miscx_ctl_reg.cn56xx.mode = 1;
1414 cvmx_write_csr(CVMX_PCSX_MISCX_CTL_REG(0, interface),
1415 pcsx_miscx_ctl_reg.u64);
1416 pcsx_miscx_ctl_reg.u64 =
1417 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(1, interface));
1418 pcsx_miscx_ctl_reg.cn56xx.mode = 1;
1419 cvmx_write_csr(CVMX_PCSX_MISCX_CTL_REG(1, interface),
1420 pcsx_miscx_ctl_reg.u64);
1427 #ifdef CVMX_BUILD_FOR_UBOOT
1428 if (CVMX_HELPER_INTERFACE_MODE_SPI == cvmx_helper_interface_get_mode(interface) && getenv("disable_spi"))
1431 return supported_ports;
1437 * Enable packet input/output from the hardware. This function is
1438 * called after by cvmx_helper_packet_hardware_enable() to
1439 * perform board specific initialization. For most boards
1440 * nothing is needed.
1442 * @param interface Interface to enable
1444 * @return Zero on success, negative on failure
1446 int __cvmx_helper_board_hardware_enable(int interface)
1448 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3005_EVB_HS5)
1452 /* Different config for switch port */
1453 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(1, interface), 0);
1454 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(1, interface), 0);
1455 /* Boards with gigabit WAN ports need a different setting that is
1456 compatible with 100 Mbit settings */
1457 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 0xc);
1458 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 0xc);
1461 else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_LANAI2_U)
1465 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 16);
1466 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 16);
1469 else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3010_EVB_HS5)
1471 /* Broadcom PHYs require different ASX clocks. Unfortunately
1472 many customer don't define a new board Id and simply
1473 mangle the CN3010_EVB_HS5 */
1476 /* Some customers boards use a hacked up bootloader that identifies them as
1477 ** CN3010_EVB_HS5 evaluation boards. This leads to all kinds of configuration
1478 ** problems. Detect one case, and print warning, while trying to do the right thing.
1480 int phy_addr = cvmx_helper_board_get_mii_address(0);
1483 int phy_identifier = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0x2);
1484 /* Is it a Broadcom PHY? */
1485 if (phy_identifier == 0x0143)
1488 cvmx_dprintf("ERROR:\n");
1489 cvmx_dprintf("ERROR: Board type is CVMX_BOARD_TYPE_CN3010_EVB_HS5, but Broadcom PHY found.\n");
1490 cvmx_dprintf("ERROR: The board type is mis-configured, and software malfunctions are likely.\n");
1491 cvmx_dprintf("ERROR: All boards require a unique board type to identify them.\n");
1492 cvmx_dprintf("ERROR:\n");
1494 cvmx_wait(1000000000);
1495 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 5);
1496 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 5);
1501 #if defined(OCTEON_VENDOR_UBIQUITI)
1502 else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CUST_UBIQUITI_E100)
1504 /* Configure ASX cloks for all ports on interface 0. */
1509 for (port = 0; port < 3; port++) {
1510 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 16);
1511 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface), 0);
1522 * Gets the clock type used for the USB block based on board type.
1523 * Used by the USB code for auto configuration of clock type.
1525 * @return USB clock type enumeration
1527 cvmx_helper_board_usb_clock_types_t __cvmx_helper_board_usb_get_clock_type(void)
1529 #if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && (!defined(__FreeBSD__) || !defined(_KERNEL))
1530 const void *fdt_addr = CASTPTR(const void *, cvmx_sysinfo_get()->fdt_addr);
1535 const char *type = NULL;
1539 nodeoffset = fdt_path_offset(fdt_addr, "/soc/uctl");
1541 nodeoffset = fdt_path_offset(fdt_addr, "/soc/usbn");
1543 if (nodeoffset >= 0)
1545 nodep = fdt_getprop(fdt_addr, nodeoffset, "refclk-type", &len);
1546 if (nodep != NULL && len > 0)
1547 type = (const char *)nodep;
1550 nodep = fdt_getprop(fdt_addr, nodeoffset, "refclk-frequency", &len);
1551 if (nodep != NULL && len == sizeof(uint32_t))
1552 speed = fdt32_to_cpu(*(int *)nodep);
1555 if (!strcmp(type, "crystal"))
1557 if (speed == 0 || speed == 12000000)
1558 return USB_CLOCK_TYPE_CRYSTAL_12;
1560 printf("Warning: invalid crystal speed for USB clock type in FDT\n");
1562 else if (!strcmp(type, "external"))
1566 return USB_CLOCK_TYPE_REF_12;
1568 return USB_CLOCK_TYPE_REF_24;
1571 return USB_CLOCK_TYPE_REF_48;
1573 printf("Warning: invalid USB clock speed of %u hz in FDT\n", speed);
1577 printf("Warning: invalid USB reference clock type \"%s\" in FDT\n", type ? type : "NULL");
1581 switch (cvmx_sysinfo_get()->board_type)
1583 case CVMX_BOARD_TYPE_BBGW_REF:
1584 case CVMX_BOARD_TYPE_LANAI2_A:
1585 case CVMX_BOARD_TYPE_LANAI2_U:
1586 case CVMX_BOARD_TYPE_LANAI2_G:
1587 #if defined(OCTEON_VENDOR_LANNER)
1588 case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
1589 case CVMX_BOARD_TYPE_CUST_LANNER_MR321X:
1591 #if defined(OCTEON_VENDOR_UBIQUITI)
1592 case CVMX_BOARD_TYPE_CUST_UBIQUITI_E100:
1594 #if defined(OCTEON_BOARD_CAPK_0100ND)
1595 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
1597 #if defined(OCTEON_VENDOR_GEFES) /* All GEFES' boards use same xtal type */
1598 case CVMX_BOARD_TYPE_TNPA3804:
1599 case CVMX_BOARD_TYPE_AT5810:
1600 case CVMX_BOARD_TYPE_WNPA3850:
1601 case CVMX_BOARD_TYPE_W3860:
1602 case CVMX_BOARD_TYPE_CUST_TNPA5804:
1603 case CVMX_BOARD_TYPE_CUST_W5434:
1604 case CVMX_BOARD_TYPE_CUST_W5650:
1605 case CVMX_BOARD_TYPE_CUST_W5800:
1606 case CVMX_BOARD_TYPE_CUST_W5651X:
1607 case CVMX_BOARD_TYPE_CUST_TNPA5651X:
1608 case CVMX_BOARD_TYPE_CUST_TNPA56X4:
1609 case CVMX_BOARD_TYPE_CUST_W63XX:
1611 case CVMX_BOARD_TYPE_NIC10E_66:
1612 return USB_CLOCK_TYPE_CRYSTAL_12;
1613 case CVMX_BOARD_TYPE_NIC10E:
1614 return USB_CLOCK_TYPE_REF_12;
1618 if (OCTEON_IS_MODEL(OCTEON_CN6XXX) /* Most boards except NIC10e use a 12MHz crystal */
1619 || OCTEON_IS_MODEL(OCTEON_CNF7XXX))
1620 return USB_CLOCK_TYPE_CRYSTAL_12;
1621 return USB_CLOCK_TYPE_REF_48;
1627 * Adjusts the number of available USB ports on Octeon based on board
1630 * @param supported_ports expected number of ports based on chip type;
1633 * @return number of available usb ports, based on board specifics.
1634 * Return value is supported_ports if function does not
1637 int __cvmx_helper_board_usb_get_num_ports(int supported_ports)
1639 switch (cvmx_sysinfo_get()->board_type)
1641 case CVMX_BOARD_TYPE_NIC_XLE_4G:
1642 case CVMX_BOARD_TYPE_NIC2E:
1646 return supported_ports;