cvmx-helper-board.c revision 216476
138032Speter/***********************license start*************** 2249729Sgshapiro * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 364562Sgshapiro * reserved. 438032Speter * 538032Speter * 638032Speter * Redistribution and use in source and binary forms, with or without 738032Speter * modification, are permitted provided that the following conditions are 838032Speter * met: 938032Speter * 1038032Speter * * Redistributions of source code must retain the above copyright 1138032Speter * notice, this list of conditions and the following disclaimer. 1238032Speter * 1338032Speter * * Redistributions in binary form must reproduce the above 1464562Sgshapiro * copyright notice, this list of conditions and the following 1538032Speter * disclaimer in the documentation and/or other materials provided 1638032Speter * with the distribution. 1764562Sgshapiro 1890792Sgshapiro * * Neither the name of Cavium Networks nor the names of 1964562Sgshapiro * its contributors may be used to endorse or promote products 20132943Sgshapiro * derived from this software without specific prior written 21132943Sgshapiro * permission. 22132943Sgshapiro 23132943Sgshapiro * This Software, including technical data, may be subject to U.S. export control 2464562Sgshapiro * laws, including the U.S. Export Administration Act and its associated 2538032Speter * regulations, and may be subject to export or import regulations in other 2664562Sgshapiro * countries. 2738032Speter 2864562Sgshapiro * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 2938032Speter * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR 3064562Sgshapiro * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 3164562Sgshapiro * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 3264562Sgshapiro * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 3364562Sgshapiro * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 3464562Sgshapiro * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 3590792Sgshapiro * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 3664562Sgshapiro * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 3764562Sgshapiro * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 3864562Sgshapiro ***********************license end**************************************/ 3964562Sgshapiro 4038032Speter 4138032Speter 4264562Sgshapiro 4338032Speter 4464562Sgshapiro 4590792Sgshapiro 4690792Sgshapiro/** 4790792Sgshapiro * @file 4890792Sgshapiro * 4990792Sgshapiro * Helper functions to abstract board specific data about 5090792Sgshapiro * network ports from the rest of the cvmx-helper files. 5190792Sgshapiro * 5290792Sgshapiro * <hr>$Revision: 49627 $<hr> 5390792Sgshapiro */ 5490792Sgshapiro#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 55249729Sgshapiro#include <linux/module.h> 5690792Sgshapiro#include <asm/octeon/cvmx.h> 5790792Sgshapiro#include <asm/octeon/cvmx-bootinfo.h> 5890792Sgshapiro#include <asm/octeon/cvmx-smix-defs.h> 5964562Sgshapiro#include <asm/octeon/cvmx-gmxx-defs.h> 6064562Sgshapiro#include <asm/octeon/cvmx-asxx-defs.h> 6190792Sgshapiro#include <asm/octeon/cvmx-mdio.h> 6290792Sgshapiro#include <asm/octeon/cvmx-helper.h> 6390792Sgshapiro#include <asm/octeon/cvmx-helper-util.h> 6490792Sgshapiro#include <asm/octeon/cvmx-helper-board.h> 6590792Sgshapiro#include <asm/octeon/cvmx-twsi.h> 6690792Sgshapiro#else 6790792Sgshapiro#include "cvmx.h" 6890792Sgshapiro#include "cvmx-app-init.h" 6990792Sgshapiro#include "cvmx-sysinfo.h" 7090792Sgshapiro#include "cvmx-twsi.h" 7190792Sgshapiro#include "cvmx-mdio.h" 7290792Sgshapiro#include "cvmx-helper.h" 73168515Sgshapiro#include "cvmx-helper-util.h" 7438032Speter#include "cvmx-helper-board.h" 7564562Sgshapiro#endif 7638032Speter 7764562Sgshapiro/** 7838032Speter * cvmx_override_board_link_get(int ipd_port) is a function 7964562Sgshapiro * pointer. It is meant to allow customization of the process of 8064562Sgshapiro * talking to a PHY to determine link speed. It is called every 8164562Sgshapiro * time a PHY must be polled for link status. Users should set 8264562Sgshapiro * this pointer to a function before calling any cvmx-helper 8364562Sgshapiro * operations. 8438032Speter */ 8564562SgshapiroCVMX_SHARED cvmx_helper_link_info_t (*cvmx_override_board_link_get)(int ipd_port) = NULL; 8664562Sgshapiro 8764562Sgshapiro/** 8864562Sgshapiro * Return the MII PHY address associated with the given IPD 8964562Sgshapiro * port. A result of -1 means there isn't a MII capable PHY 9064562Sgshapiro * connected to this port. On chips supporting multiple MII 9164562Sgshapiro * busses the bus number is encoded in bits <15:8>. 9264562Sgshapiro * 9364562Sgshapiro * This function must be modified for every new Octeon board. 9464562Sgshapiro * Internally it uses switch statements based on the cvmx_sysinfo 9564562Sgshapiro * data to determine board types and revisions. It replies on the 9638032Speter * fact that every Octeon board receives a unique board type 9764562Sgshapiro * enumeration from the bootloader. 9864562Sgshapiro * 9938032Speter * @param ipd_port Octeon IPD port to get the MII address for. 10064562Sgshapiro * 10164562Sgshapiro * @return MII PHY address and bus number or -1. 10238032Speter */ 10364562Sgshapiroint cvmx_helper_board_get_mii_address(int ipd_port) 10464562Sgshapiro{ 10538032Speter /* 10664562Sgshapiro * Board types we have to know at compile-time. 10764562Sgshapiro */ 10864562Sgshapiro#ifdef OCTEON_BOARD_CAPK_0100ND 10964562Sgshapiro switch (ipd_port) { 11064562Sgshapiro case 0: 11164562Sgshapiro return 2; 11290792Sgshapiro case 1: 11390792Sgshapiro return 3; 11490792Sgshapiro case 2: 11564562Sgshapiro /* XXX Switch PHY? */ 11638032Speter return -1; 11790792Sgshapiro default: 11864562Sgshapiro return -1; 11964562Sgshapiro } 12064562Sgshapiro#endif 12164562Sgshapiro 12264562Sgshapiro /* 12338032Speter * For board types we can determine at runtime. 12464562Sgshapiro */ 12564562Sgshapiro switch (cvmx_sysinfo_get()->board_type) 12690792Sgshapiro { 127249729Sgshapiro case CVMX_BOARD_TYPE_SIM: 128249729Sgshapiro /* Simulator doesn't have MII */ 129249729Sgshapiro return -1; 130249729Sgshapiro case CVMX_BOARD_TYPE_EBT3000: 131249729Sgshapiro case CVMX_BOARD_TYPE_EBT5800: 13290792Sgshapiro case CVMX_BOARD_TYPE_THUNDER: 13364562Sgshapiro case CVMX_BOARD_TYPE_NICPRO2: 13464562Sgshapiro /* Interface 0 is SPI4, interface 1 is RGMII */ 13564562Sgshapiro if ((ipd_port >= 16) && (ipd_port < 20)) 13698121Sgshapiro return ipd_port - 16; 13798121Sgshapiro else 13898121Sgshapiro return -1; 13998121Sgshapiro case CVMX_BOARD_TYPE_LANAI2_A: 140225906Sume if (ipd_port == 0) 14198121Sgshapiro return 0; 142225906Sume else 143225906Sume return -1; 144225906Sume case CVMX_BOARD_TYPE_LANAI2_U: 14598121Sgshapiro case CVMX_BOARD_TYPE_LANAI2_G: 14698121Sgshapiro if (ipd_port == 0) 14798121Sgshapiro return 0x1c; 148225906Sume else 14998121Sgshapiro return -1; 15064562Sgshapiro case CVMX_BOARD_TYPE_KODAMA: 15164562Sgshapiro case CVMX_BOARD_TYPE_EBH3100: 15298121Sgshapiro case CVMX_BOARD_TYPE_HIKARI: 15364562Sgshapiro case CVMX_BOARD_TYPE_CN3010_EVB_HS5: 15464562Sgshapiro case CVMX_BOARD_TYPE_CN3005_EVB_HS5: 15598121Sgshapiro case CVMX_BOARD_TYPE_CN3020_EVB_HS5: 15664562Sgshapiro /* Port 0 is WAN connected to a PHY, Port 1 is GMII connected to a 15764562Sgshapiro switch */ 15864562Sgshapiro if (ipd_port == 0) 15964562Sgshapiro return 4; 16098121Sgshapiro else if (ipd_port == 1) 16164562Sgshapiro return 9; 16264562Sgshapiro else 16364562Sgshapiro return -1; 16464562Sgshapiro case CVMX_BOARD_TYPE_NAC38: 16564562Sgshapiro /* Board has 8 RGMII ports PHYs are 0-7 */ 16664562Sgshapiro if ((ipd_port >= 0) && (ipd_port < 4)) 16764562Sgshapiro return ipd_port; 16864562Sgshapiro else if ((ipd_port >= 16) && (ipd_port < 20)) 16938032Speter return ipd_port - 16 + 4; 17038032Speter else 17138032Speter return -1; 17238032Speter case CVMX_BOARD_TYPE_EBH3000: 17338032Speter /* Board has dual SPI4 and no PHYs */ 17438032Speter return -1; 17538032Speter case CVMX_BOARD_TYPE_EBT5810: 17638032Speter /* Board has 10g PHYs hooked up to the MII controller on the 17738032Speter ** IXF18201 MAC. The 10G PHYS use clause 45 MDIO which the CN58XX 17838032Speter ** does not support. All MII accesses go through the IXF part. */ 17938032Speter return -1; 18064562Sgshapiro case CVMX_BOARD_TYPE_EBH5200: 18164562Sgshapiro case CVMX_BOARD_TYPE_EBH5201: 18264562Sgshapiro case CVMX_BOARD_TYPE_EBT5200: 18364562Sgshapiro /* Board has 2 management ports */ 18438032Speter if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2))) 18538032Speter return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT; 18664562Sgshapiro /* Board has 4 SGMII ports. The PHYs start right after the MII 18738032Speter ports MII0 = 0, MII1 = 1, SGMII = 2-5 */ 18838032Speter if ((ipd_port >= 0) && (ipd_port < 4)) 18964562Sgshapiro return ipd_port+2; 19073188Sgshapiro else 19173188Sgshapiro return -1; 19273188Sgshapiro case CVMX_BOARD_TYPE_EBH5600: 19338032Speter case CVMX_BOARD_TYPE_EBH5601: 19464562Sgshapiro case CVMX_BOARD_TYPE_EBH5610: 19564562Sgshapiro /* Board has 1 management port */ 19664562Sgshapiro if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT) 19738032Speter return 0; 19864562Sgshapiro /* Board has 8 SGMII ports. 4 connect out, two connect to a switch, 19964562Sgshapiro and 2 loop to each other */ 20064562Sgshapiro if ((ipd_port >= 0) && (ipd_port < 4)) 20138032Speter return ipd_port+1; 20264562Sgshapiro else 203120256Sgshapiro return -1; 204120256Sgshapiro case CVMX_BOARD_TYPE_EBB5600: 205120256Sgshapiro { 206120256Sgshapiro static unsigned char qlm_switch_addr = 0; 20790792Sgshapiro 20890792Sgshapiro /* Board has 1 management port */ 20990792Sgshapiro if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT) 21090792Sgshapiro return 0; 21190792Sgshapiro 21290792Sgshapiro /* Board has 8 SGMII ports. 4 connected QLM1, 4 connected QLM3 */ 21390792Sgshapiro if ((ipd_port >= 0) && (ipd_port < 4)) 21490792Sgshapiro { 21590792Sgshapiro if (qlm_switch_addr != 0x3) 21690792Sgshapiro { 21790792Sgshapiro qlm_switch_addr = 0x3; /* QLM1 */ 21890792Sgshapiro cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr); 21990792Sgshapiro cvmx_wait_usec(11000); /* Let the write complete */ 22090792Sgshapiro } 22190792Sgshapiro return ipd_port+1 + (1<<8); 22290792Sgshapiro } 22338032Speter else if ((ipd_port >= 16) && (ipd_port < 20)) 22438032Speter { 22538032Speter if (qlm_switch_addr != 0xC) 22690792Sgshapiro { 22738032Speter qlm_switch_addr = 0xC; /* QLM3 */ 22890792Sgshapiro cvmx_twsix_write_ia(0, 0x71, 0, 1, 1, qlm_switch_addr); 22938032Speter cvmx_wait_usec(11000); /* Let the write complete */ 23038032Speter } 23138032Speter return ipd_port-16+1 + (1<<8); 23238032Speter } 23338032Speter else 23438032Speter return -1; 23538032Speter } 23638032Speter case CVMX_BOARD_TYPE_EBB6300: 23738032Speter /* Board has 2 management ports */ 23838032Speter if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2))) 23938032Speter return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT + 4; 24090792Sgshapiro if ((ipd_port >= 0) && (ipd_port < 4)) 24138032Speter return ipd_port + 1 + (1<<8); 24238032Speter else 24338032Speter return -1; 24438032Speter case CVMX_BOARD_TYPE_CUST_NB5: 24538032Speter if (ipd_port == 2) 24638032Speter return 4; 24738032Speter else 24838032Speter return -1; 24990792Sgshapiro case CVMX_BOARD_TYPE_NIC_XLE_4G: 25090792Sgshapiro /* Board has 4 SGMII ports. connected QLM3(interface 1) */ 25190792Sgshapiro if ((ipd_port >= 16) && (ipd_port < 20)) 25290792Sgshapiro return ipd_port - 16 + 1; 25338032Speter else 25438032Speter return -1; 25538032Speter case CVMX_BOARD_TYPE_NIC_XLE_10G: 25638032Speter return -1; /* We don't use clause 45 MDIO for anything */ 25738032Speter case CVMX_BOARD_TYPE_BBGW_REF: 25864562Sgshapiro return -1; /* No PHYs are connected to Octeon, everything is through switch */ 25990792Sgshapiro case CVMX_BOARD_TYPE_CUST_WSX16: 26090792Sgshapiro if (ipd_port >= 0 && ipd_port <= 3) 26190792Sgshapiro return ipd_port; 26290792Sgshapiro else if (ipd_port >= 16 && ipd_port <= 19) 26338032Speter return ipd_port - 16 + 4; 26438032Speter else 26538032Speter return -1; 26638032Speter 26764562Sgshapiro /* Private vendor-defined boards. */ 26864562Sgshapiro#if defined(OCTEON_VENDOR_LANNER) 26964562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR955: 27064562Sgshapiro /* Interface 1 is 12 BCM5482S PHYs. */ 27164562Sgshapiro if ((ipd_port >= 16) && (ipd_port < 28)) 27264562Sgshapiro return ipd_port - 16; 27364562Sgshapiro return -1; 27464562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR730: 27564562Sgshapiro if ((ipd_port >= 0) && (ipd_port < 4)) 27664562Sgshapiro return ipd_port; 27790792Sgshapiro return -1; 27864562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR320: 27964562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR321X: 28064562Sgshapiro /* Port 0 is a Marvell 88E6161 switch, ports 1 and 2 are Marvell 28164562Sgshapiro 88E1111 interfaces. */ 28264562Sgshapiro switch (ipd_port) { 28390792Sgshapiro case 0: 28490792Sgshapiro return 16; 28590792Sgshapiro case 1: 28664562Sgshapiro return 1; 28764562Sgshapiro case 2: 28838032Speter return 2; 28964562Sgshapiro default: 29038032Speter return -1; 29164562Sgshapiro } 29264562Sgshapiro#endif 29364562Sgshapiro } 29464562Sgshapiro 29564562Sgshapiro /* Some unknown board. Somebody forgot to update this function... */ 29690792Sgshapiro cvmx_dprintf("%s: Unknown board type %d\n", 29790792Sgshapiro __FUNCTION__, cvmx_sysinfo_get()->board_type); 29838032Speter return -1; 29990792Sgshapiro} 30090792Sgshapiro#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 30190792SgshapiroEXPORT_SYMBOL(cvmx_helper_board_get_mii_address); 30290792Sgshapiro#endif 30390792Sgshapiro 30490792Sgshapiro 30590792Sgshapiro/** 30690792Sgshapiro * @INTERNAL 30790792Sgshapiro * This function is the board specific method of determining an 30890792Sgshapiro * ethernet ports link speed. Most Octeon boards have Marvell PHYs 30990792Sgshapiro * and are handled by the fall through case. This function must be 31090792Sgshapiro * updated for boards that don't have the normal Marvell PHYs. 31190792Sgshapiro * 31290792Sgshapiro * This function must be modified for every new Octeon board. 31390792Sgshapiro * Internally it uses switch statements based on the cvmx_sysinfo 314102528Sgshapiro * data to determine board types and revisions. It relies on the 31590792Sgshapiro * fact that every Octeon board receives a unique board type 31664562Sgshapiro * enumeration from the bootloader. 31764562Sgshapiro * 31864562Sgshapiro * @param ipd_port IPD input port associated with the port we want to get link 31964562Sgshapiro * status for. 32064562Sgshapiro * 32190792Sgshapiro * @return The ports link status. If the link isn't fully resolved, this must 32264562Sgshapiro * return zero. 32364562Sgshapiro */ 32464562Sgshapirocvmx_helper_link_info_t __cvmx_helper_board_link_get(int ipd_port) 32564562Sgshapiro{ 32664562Sgshapiro cvmx_helper_link_info_t result; 32790792Sgshapiro int phy_addr; 32864562Sgshapiro int is_broadcom_phy = 0; 32990792Sgshapiro 33090792Sgshapiro /* Give the user a chance to override the processing of this function */ 33164562Sgshapiro if (cvmx_override_board_link_get) 33290792Sgshapiro return cvmx_override_board_link_get(ipd_port); 33390792Sgshapiro 33464562Sgshapiro /* Unless we fix it later, all links are defaulted to down */ 33590792Sgshapiro result.u64 = 0; 336173340Sgshapiro 337173340Sgshapiro#if !defined(OCTEON_BOARD_CAPK_0100ND) 33890792Sgshapiro /* This switch statement should handle all ports that either don't use 339223067Sgshapiro Marvell PHYS, or don't support in-band status */ 34064562Sgshapiro switch (cvmx_sysinfo_get()->board_type) 34164562Sgshapiro { 34264562Sgshapiro case CVMX_BOARD_TYPE_SIM: 34364562Sgshapiro /* The simulator gives you a simulated 1Gbps full duplex link */ 34464562Sgshapiro result.s.link_up = 1; 34538032Speter result.s.full_duplex = 1; 346168515Sgshapiro result.s.speed = 1000; 347111823Sgshapiro return result; 34864562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_A: 34964562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_U: 35064562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_G: 35190792Sgshapiro break; 35290792Sgshapiro case CVMX_BOARD_TYPE_EBH3100: 35390792Sgshapiro case CVMX_BOARD_TYPE_CN3010_EVB_HS5: 354132943Sgshapiro case CVMX_BOARD_TYPE_CN3005_EVB_HS5: 355132943Sgshapiro case CVMX_BOARD_TYPE_CN3020_EVB_HS5: 35638032Speter /* Port 1 on these boards is always Gigabit */ 35764562Sgshapiro if (ipd_port == 1) 35890792Sgshapiro { 35938032Speter result.s.link_up = 1; 36038032Speter result.s.full_duplex = 1; 36190792Sgshapiro result.s.speed = 1000; 36264562Sgshapiro return result; 36390792Sgshapiro } 36464562Sgshapiro /* Fall through to the generic code below */ 365168515Sgshapiro break; 366168515Sgshapiro case CVMX_BOARD_TYPE_EBH5600: 367168515Sgshapiro case CVMX_BOARD_TYPE_EBH5601: 368168515Sgshapiro case CVMX_BOARD_TYPE_EBH5610: 369168515Sgshapiro /* Board has 1 management ports */ 370168515Sgshapiro if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT) 37164562Sgshapiro is_broadcom_phy = 1; 37290792Sgshapiro break; 37390792Sgshapiro case CVMX_BOARD_TYPE_EBH5200: 37490792Sgshapiro case CVMX_BOARD_TYPE_EBH5201: 37590792Sgshapiro case CVMX_BOARD_TYPE_EBT5200: 376168515Sgshapiro /* Board has 2 management ports */ 377168515Sgshapiro if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2))) 378168515Sgshapiro is_broadcom_phy = 1; 379168515Sgshapiro break; 380168515Sgshapiro case CVMX_BOARD_TYPE_EBB6300: /* Only for MII mode, with PHY addresses 0/1. Default is RGMII*/ 381168515Sgshapiro if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) && (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)) 382168515Sgshapiro && cvmx_helper_board_get_mii_address(ipd_port) >= 0 && cvmx_helper_board_get_mii_address(ipd_port) <= 1) 383168515Sgshapiro is_broadcom_phy = 1; 38438032Speter break; 38538032Speter case CVMX_BOARD_TYPE_CUST_NB5: 38638032Speter /* Port 1 on these boards is always Gigabit */ 38738032Speter if (ipd_port == 1) 38838032Speter { 38938032Speter result.s.link_up = 1; 39038032Speter result.s.full_duplex = 1; 39138032Speter result.s.speed = 1000; 39238032Speter return result; 39338032Speter } 39438032Speter else /* The other port uses a broadcom PHY */ 39538032Speter is_broadcom_phy = 1; 39638032Speter break; 39738032Speter case CVMX_BOARD_TYPE_BBGW_REF: 39838032Speter /* Port 1 on these boards is always Gigabit */ 39938032Speter if (ipd_port == 2) 40038032Speter { 40138032Speter /* Port 2 is not hooked up */ 40264562Sgshapiro result.u64 = 0; 40338032Speter return result; 40438032Speter } 40538032Speter else 40638032Speter { 40738032Speter /* Ports 0 and 1 connect to the switch */ 40838032Speter result.s.link_up = 1; 40938032Speter result.s.full_duplex = 1; 41038032Speter result.s.speed = 1000; 41138032Speter return result; 41238032Speter } 41364562Sgshapiro break; 41438032Speter /* Private vendor-defined boards. */ 41564562Sgshapiro#if defined(OCTEON_VENDOR_LANNER) 41638032Speter case CVMX_BOARD_TYPE_CUST_LANNER_MR730: 41738032Speter /* Ports are BCM5482S */ 41838032Speter is_broadcom_phy = 1; 41964562Sgshapiro break; 42064562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR320: 42190792Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR321X: 42238032Speter /* Port 0 connects to the switch */ 42338032Speter if (ipd_port == 0) 42438032Speter { 42590792Sgshapiro result.s.link_up = 1; 42664562Sgshapiro result.s.full_duplex = 1; 42764562Sgshapiro result.s.speed = 1000; 428141858Sgshapiro return result; 42964562Sgshapiro } 43064562Sgshapiro break; 43164562Sgshapiro#endif 43238032Speter } 43364562Sgshapiro#endif 43464562Sgshapiro 43564562Sgshapiro phy_addr = cvmx_helper_board_get_mii_address(ipd_port); 43638032Speter if (phy_addr != -1) 43764562Sgshapiro { 43864562Sgshapiro if (is_broadcom_phy) 43964562Sgshapiro { 44064562Sgshapiro /* Below we are going to read SMI/MDIO register 0x19 which works 44164562Sgshapiro on Broadcom parts */ 44264562Sgshapiro int phy_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0x19); 44364562Sgshapiro switch ((phy_status>>8) & 0x7) 44464562Sgshapiro { 44564562Sgshapiro case 0: 44664562Sgshapiro result.u64 = 0; 44764562Sgshapiro break; 44838032Speter case 1: 44964562Sgshapiro result.s.link_up = 1; 45064562Sgshapiro result.s.full_duplex = 0; 45164562Sgshapiro result.s.speed = 10; 45264562Sgshapiro break; 45338032Speter case 2: 45464562Sgshapiro result.s.link_up = 1; 45564562Sgshapiro result.s.full_duplex = 1; 45664562Sgshapiro result.s.speed = 10; 45764562Sgshapiro break; 45864562Sgshapiro case 3: 45964562Sgshapiro result.s.link_up = 1; 46064562Sgshapiro result.s.full_duplex = 0; 46164562Sgshapiro result.s.speed = 100; 46238032Speter break; 46364562Sgshapiro case 4: 464132943Sgshapiro result.s.link_up = 1; 46538032Speter result.s.full_duplex = 1; 46664562Sgshapiro result.s.speed = 100; 46764562Sgshapiro break; 46890792Sgshapiro case 5: 46964562Sgshapiro result.s.link_up = 1; 47064562Sgshapiro result.s.full_duplex = 1; 47190792Sgshapiro result.s.speed = 100; 47264562Sgshapiro break; 47364562Sgshapiro case 6: 47464562Sgshapiro result.s.link_up = 1; 47564562Sgshapiro result.s.full_duplex = 0; 47664562Sgshapiro result.s.speed = 1000; 47764562Sgshapiro break; 47864562Sgshapiro case 7: 47964562Sgshapiro result.s.link_up = 1; 48064562Sgshapiro result.s.full_duplex = 1; 48164562Sgshapiro result.s.speed = 1000; 48264562Sgshapiro break; 48364562Sgshapiro } 48464562Sgshapiro } 48564562Sgshapiro else 48638032Speter { 48764562Sgshapiro /* This code assumes we are using a Marvell Gigabit PHY. All the 48864562Sgshapiro speed information can be read from register 17 in one go. Somebody 48964562Sgshapiro using a different PHY will need to handle it above in the board 49090792Sgshapiro specific area */ 491141858Sgshapiro int phy_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 17); 49294334Sgshapiro 49394334Sgshapiro /* If the resolve bit 11 isn't set, see if autoneg is turned off 49494334Sgshapiro (bit 12, reg 0). The resolve bit doesn't get set properly when 49538032Speter autoneg is off, so force it */ 49690792Sgshapiro if ((phy_status & (1<<11)) == 0) 49790792Sgshapiro { 49890792Sgshapiro int auto_status = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0); 49990792Sgshapiro if ((auto_status & (1<<12)) == 0) 50090792Sgshapiro phy_status |= 1<<11; 50190792Sgshapiro } 50290792Sgshapiro 50390792Sgshapiro /* Only return a link if the PHY has finished auto negotiation 50490792Sgshapiro and set the resolved bit (bit 11) */ 50590792Sgshapiro if (phy_status & (1<<11)) 50690792Sgshapiro { 50790792Sgshapiro#if defined(OCTEON_BOARD_CAPK_0100ND) 50890792Sgshapiro result.s.link_up = (phy_status>>10)&1; 50990792Sgshapiro#else 51090792Sgshapiro result.s.link_up = 1; 51190792Sgshapiro#endif 51290792Sgshapiro result.s.full_duplex = ((phy_status>>13)&1); 51390792Sgshapiro switch ((phy_status>>14)&3) 51490792Sgshapiro { 51590792Sgshapiro case 0: /* 10 Mbps */ 51690792Sgshapiro result.s.speed = 10; 51790792Sgshapiro break; 51890792Sgshapiro case 1: /* 100 Mbps */ 51990792Sgshapiro result.s.speed = 100; 52090792Sgshapiro break; 52190792Sgshapiro case 2: /* 1 Gbps */ 52290792Sgshapiro result.s.speed = 1000; 52390792Sgshapiro break; 52490792Sgshapiro case 3: /* Illegal */ 52590792Sgshapiro result.u64 = 0; 52690792Sgshapiro break; 52790792Sgshapiro } 52890792Sgshapiro } 52990792Sgshapiro } 53090792Sgshapiro } 53190792Sgshapiro else if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) 53290792Sgshapiro { 53390792Sgshapiro /* We don't have a PHY address, so attempt to use in-band status. It is 53490792Sgshapiro really important that boards not supporting in-band status never get 53590792Sgshapiro here. Reading broken in-band status tends to do bad things */ 53690792Sgshapiro cvmx_gmxx_rxx_rx_inbnd_t inband_status; 53790792Sgshapiro int interface = cvmx_helper_get_interface_num(ipd_port); 53890792Sgshapiro int index = cvmx_helper_get_interface_index_num(ipd_port); 53990792Sgshapiro inband_status.u64 = cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index, interface)); 54090792Sgshapiro 54190792Sgshapiro result.s.link_up = inband_status.s.status; 54290792Sgshapiro result.s.full_duplex = inband_status.s.duplex; 54390792Sgshapiro switch (inband_status.s.speed) 54490792Sgshapiro { 54590792Sgshapiro case 0: /* 10 Mbps */ 54690792Sgshapiro result.s.speed = 10; 54790792Sgshapiro break; 54890792Sgshapiro case 1: /* 100 Mbps */ 54990792Sgshapiro result.s.speed = 100; 55094334Sgshapiro break; 55194334Sgshapiro case 2: /* 1 Gbps */ 55294334Sgshapiro result.s.speed = 1000; 55394334Sgshapiro break; 55490792Sgshapiro case 3: /* Illegal */ 55590792Sgshapiro result.u64 = 0; 55690792Sgshapiro break; 55790792Sgshapiro } 55890792Sgshapiro } 55990792Sgshapiro else 56090792Sgshapiro { 56190792Sgshapiro /* We don't have a PHY address and we don't have in-band status. There 56290792Sgshapiro is no way to determine the link speed. Return down assuming this 56390792Sgshapiro port isn't wired */ 56490792Sgshapiro result.u64 = 0; 56590792Sgshapiro } 56690792Sgshapiro 56790792Sgshapiro /* If link is down, return all fields as zero. */ 56890792Sgshapiro if (!result.s.link_up) 56990792Sgshapiro result.u64 = 0; 57090792Sgshapiro 57190792Sgshapiro return result; 57290792Sgshapiro} 57390792Sgshapiro 57490792Sgshapiro 57590792Sgshapiro/** 57690792Sgshapiro * This function as a board specific method of changing the PHY 57790792Sgshapiro * speed, duplex, and autonegotiation. This programs the PHY and 57890792Sgshapiro * not Octeon. This can be used to force Octeon's links to 57990792Sgshapiro * specific settings. 58090792Sgshapiro * 58190792Sgshapiro * @param phy_addr The address of the PHY to program 58290792Sgshapiro * @param link_flags 58390792Sgshapiro * Flags to control autonegotiation. Bit 0 is autonegotiation 58490792Sgshapiro * enable/disable to maintain backward compatibility. 58590792Sgshapiro * @param link_info Link speed to program. If the speed is zero and autonegotiation 58690792Sgshapiro * is enabled, all possible negotiation speeds are advertised. 58790792Sgshapiro * 58890792Sgshapiro * @return Zero on success, negative on failure 58990792Sgshapiro */ 59090792Sgshapiroint cvmx_helper_board_link_set_phy(int phy_addr, cvmx_helper_board_set_phy_link_flags_types_t link_flags, 59190792Sgshapiro cvmx_helper_link_info_t link_info) 59290792Sgshapiro{ 59390792Sgshapiro 59490792Sgshapiro /* Set the flow control settings based on link_flags */ 59590792Sgshapiro if ((link_flags & set_phy_link_flags_flow_control_mask) != set_phy_link_flags_flow_control_dont_touch) 59690792Sgshapiro { 59790792Sgshapiro cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver; 59890792Sgshapiro reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER); 59990792Sgshapiro reg_autoneg_adver.s.asymmetric_pause = (link_flags & set_phy_link_flags_flow_control_mask) == set_phy_link_flags_flow_control_enable; 60090792Sgshapiro reg_autoneg_adver.s.pause = (link_flags & set_phy_link_flags_flow_control_mask) == set_phy_link_flags_flow_control_enable; 60190792Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16); 60290792Sgshapiro } 60390792Sgshapiro 60490792Sgshapiro /* If speed isn't set and autoneg is on advertise all supported modes */ 60590792Sgshapiro if ((link_flags & set_phy_link_flags_autoneg) && (link_info.s.speed == 0)) 60698121Sgshapiro { 60798121Sgshapiro cvmx_mdio_phy_reg_control_t reg_control; 60898121Sgshapiro cvmx_mdio_phy_reg_status_t reg_status; 60998121Sgshapiro cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver; 61098121Sgshapiro cvmx_mdio_phy_reg_extended_status_t reg_extended_status; 61190792Sgshapiro cvmx_mdio_phy_reg_control_1000_t reg_control_1000; 61290792Sgshapiro 61390792Sgshapiro reg_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_STATUS); 61490792Sgshapiro reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER); 61590792Sgshapiro reg_autoneg_adver.s.advert_100base_t4 = reg_status.s.capable_100base_t4; 61690792Sgshapiro reg_autoneg_adver.s.advert_10base_tx_full = reg_status.s.capable_10_full; 61790792Sgshapiro reg_autoneg_adver.s.advert_10base_tx_half = reg_status.s.capable_10_half; 61898121Sgshapiro reg_autoneg_adver.s.advert_100base_tx_full = reg_status.s.capable_100base_x_full; 619203004Sgshapiro reg_autoneg_adver.s.advert_100base_tx_half = reg_status.s.capable_100base_x_half; 62090792Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16); 62190792Sgshapiro if (reg_status.s.capable_extended_status) 62290792Sgshapiro { 62390792Sgshapiro reg_extended_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_EXTENDED_STATUS); 62498121Sgshapiro reg_control_1000.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000); 62598121Sgshapiro reg_control_1000.s.advert_1000base_t_full = reg_extended_status.s.capable_1000base_t_full; 62698121Sgshapiro reg_control_1000.s.advert_1000base_t_half = reg_extended_status.s.capable_1000base_t_half; 62798121Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000, reg_control_1000.u16); 62890792Sgshapiro } 62998121Sgshapiro reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL); 63090792Sgshapiro reg_control.s.autoneg_enable = 1; 63198121Sgshapiro reg_control.s.restart_autoneg = 1; 63290792Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16); 63398121Sgshapiro } 63498121Sgshapiro else if ((link_flags & set_phy_link_flags_autoneg)) 63590792Sgshapiro { 63690792Sgshapiro cvmx_mdio_phy_reg_control_t reg_control; 63790792Sgshapiro cvmx_mdio_phy_reg_status_t reg_status; 63890792Sgshapiro cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver; 63990792Sgshapiro cvmx_mdio_phy_reg_extended_status_t reg_extended_status; 64090792Sgshapiro cvmx_mdio_phy_reg_control_1000_t reg_control_1000; 641132943Sgshapiro 64290792Sgshapiro reg_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_STATUS); 64390792Sgshapiro reg_autoneg_adver.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER); 64490792Sgshapiro reg_autoneg_adver.s.advert_100base_t4 = 0; 64590792Sgshapiro reg_autoneg_adver.s.advert_10base_tx_full = 0; 64690792Sgshapiro reg_autoneg_adver.s.advert_10base_tx_half = 0; 64790792Sgshapiro reg_autoneg_adver.s.advert_100base_tx_full = 0; 64890792Sgshapiro reg_autoneg_adver.s.advert_100base_tx_half = 0; 64990792Sgshapiro if (reg_status.s.capable_extended_status) 65090792Sgshapiro { 65190792Sgshapiro reg_extended_status.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_EXTENDED_STATUS); 65290792Sgshapiro reg_control_1000.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000); 65390792Sgshapiro reg_control_1000.s.advert_1000base_t_full = 0; 65490792Sgshapiro reg_control_1000.s.advert_1000base_t_half = 0; 65590792Sgshapiro } 65690792Sgshapiro switch (link_info.s.speed) 65790792Sgshapiro { 65890792Sgshapiro case 10: 65990792Sgshapiro reg_autoneg_adver.s.advert_10base_tx_full = link_info.s.full_duplex; 66038032Speter reg_autoneg_adver.s.advert_10base_tx_half = !link_info.s.full_duplex; 66138032Speter break; 66238032Speter case 100: 66338032Speter reg_autoneg_adver.s.advert_100base_tx_full = link_info.s.full_duplex; 66464562Sgshapiro reg_autoneg_adver.s.advert_100base_tx_half = !link_info.s.full_duplex; 66538032Speter break; 66638032Speter case 1000: 66738032Speter reg_control_1000.s.advert_1000base_t_full = link_info.s.full_duplex; 66890792Sgshapiro reg_control_1000.s.advert_1000base_t_half = !link_info.s.full_duplex; 66938032Speter break; 67038032Speter } 67138032Speter cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_AUTONEG_ADVER, reg_autoneg_adver.u16); 67238032Speter if (reg_status.s.capable_extended_status) 67364562Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL_1000, reg_control_1000.u16); 67438032Speter reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL); 67590792Sgshapiro reg_control.s.autoneg_enable = 1; 67690792Sgshapiro reg_control.s.restart_autoneg = 1; 67738032Speter cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16); 67838032Speter } 67938032Speter else 68038032Speter { 68138032Speter cvmx_mdio_phy_reg_control_t reg_control; 68238032Speter reg_control.u16 = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL); 68338032Speter reg_control.s.autoneg_enable = 0; 68490792Sgshapiro reg_control.s.restart_autoneg = 1; 68564562Sgshapiro reg_control.s.duplex = link_info.s.full_duplex; 68690792Sgshapiro if (link_info.s.speed == 1000) 68790792Sgshapiro { 68890792Sgshapiro reg_control.s.speed_msb = 1; 68990792Sgshapiro reg_control.s.speed_lsb = 0; 69090792Sgshapiro } 69190792Sgshapiro else if (link_info.s.speed == 100) 69290792Sgshapiro { 69390792Sgshapiro reg_control.s.speed_msb = 0; 69464562Sgshapiro reg_control.s.speed_lsb = 1; 69590792Sgshapiro } 69664562Sgshapiro else if (link_info.s.speed == 10) 69764562Sgshapiro { 69864562Sgshapiro reg_control.s.speed_msb = 0; 69964562Sgshapiro reg_control.s.speed_lsb = 0; 70064562Sgshapiro } 70164562Sgshapiro cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff, CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16); 70264562Sgshapiro } 70364562Sgshapiro return 0; 70464562Sgshapiro} 70590792Sgshapiro 70638032Speter 70738032Speter/** 70838032Speter * @INTERNAL 70938032Speter * This function is called by cvmx_helper_interface_probe() after it 71064562Sgshapiro * determines the number of ports Octeon can support on a specific 71190792Sgshapiro * interface. This function is the per board location to override 71264562Sgshapiro * this value. It is called with the number of ports Octeon might 71364562Sgshapiro * support and should return the number of actual ports on the 71464562Sgshapiro * board. 71564562Sgshapiro * 71664562Sgshapiro * This function must be modified for every new Octeon board. 71764562Sgshapiro * Internally it uses switch statements based on the cvmx_sysinfo 71894334Sgshapiro * data to determine board types and revisions. It relies on the 71964562Sgshapiro * fact that every Octeon board receives a unique board type 72064562Sgshapiro * enumeration from the bootloader. 72164562Sgshapiro * 72264562Sgshapiro * @param interface Interface to probe 72364562Sgshapiro * @param supported_ports 72464562Sgshapiro * Number of ports Octeon supports. 72564562Sgshapiro * 72664562Sgshapiro * @return Number of ports the actual board supports. Many times this will 72764562Sgshapiro * simple be "support_ports". 72890792Sgshapiro */ 729110560Sgshapiroint __cvmx_helper_board_interface_probe(int interface, int supported_ports) 73064562Sgshapiro{ 73164562Sgshapiro switch (cvmx_sysinfo_get()->board_type) 73264562Sgshapiro { 73364562Sgshapiro case CVMX_BOARD_TYPE_CN3005_EVB_HS5: 734223067Sgshapiro case CVMX_BOARD_TYPE_LANAI2_A: 735223067Sgshapiro case CVMX_BOARD_TYPE_LANAI2_U: 73664562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_G: 73790792Sgshapiro if (interface == 0) 73890792Sgshapiro return 2; 73990792Sgshapiro break; 74090792Sgshapiro case CVMX_BOARD_TYPE_BBGW_REF: 741173340Sgshapiro if (interface == 0) 742223067Sgshapiro return 2; 74371345Sgshapiro break; 74438032Speter case CVMX_BOARD_TYPE_NIC_XLE_4G: 745223067Sgshapiro if (interface == 0) 746223067Sgshapiro return 0; 74738032Speter break; 74838032Speter /* The 2nd interface on the EBH5600 is connected to the Marvel switch, 74938032Speter which we don't support. Disable ports connected to it */ 75038032Speter case CVMX_BOARD_TYPE_EBH5600: 75190792Sgshapiro if (interface == 1) 75290792Sgshapiro return 0; 75390792Sgshapiro break; 75490792Sgshapiro case CVMX_BOARD_TYPE_EBB5600: 75590792Sgshapiro#ifdef CVMX_ENABLE_PKO_FUNCTIONS 75690792Sgshapiro if (cvmx_helper_interface_get_mode(interface) == CVMX_HELPER_INTERFACE_MODE_PICMG) 75738032Speter return 0; 75838032Speter#endif 75938032Speter break; 760141867Sgshapiro case CVMX_BOARD_TYPE_EBT5810: 761132943Sgshapiro return 1; /* Two ports on each SPI: 1 hooked to MAC, 1 loopback 762132943Sgshapiro ** Loopback disabled by default. */ 76364562Sgshapiro#if defined(OCTEON_VENDOR_LANNER) 764223067Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR955: 76564562Sgshapiro if (interface == 1) 76664562Sgshapiro return 12; 76764562Sgshapiro break; 76838032Speter#endif 76938032Speter } 77064562Sgshapiro#ifdef CVMX_BUILD_FOR_UBOOT 77164562Sgshapiro if (CVMX_HELPER_INTERFACE_MODE_SPI == cvmx_helper_interface_get_mode(interface) && getenv("disable_spi")) 77264562Sgshapiro return 0; 773168515Sgshapiro#endif 77438032Speter return supported_ports; 77564562Sgshapiro} 77690792Sgshapiro 77790792Sgshapiro 77890792Sgshapiro/** 77990792Sgshapiro * @INTERNAL 78090792Sgshapiro * Enable packet input/output from the hardware. This function is 78138032Speter * called after by cvmx_helper_packet_hardware_enable() to 78238032Speter * perform board specific initialization. For most boards 78338032Speter * nothing is needed. 78438032Speter * 78538032Speter * @param interface Interface to enable 78638032Speter * 78738032Speter * @return Zero on success, negative on failure 78838032Speter */ 78938032Speterint __cvmx_helper_board_hardware_enable(int interface) 79090792Sgshapiro{ 79190792Sgshapiro if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3005_EVB_HS5) 79264562Sgshapiro { 79338032Speter if (interface == 0) 79438032Speter { 79538032Speter /* Different config for switch port */ 79638032Speter cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(1, interface), 0); 79738032Speter cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(1, interface), 0); 79838032Speter /* Boards with gigabit WAN ports need a different setting that is 79938032Speter compatible with 100 Mbit settings */ 80038032Speter cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 0xc); 80138032Speter cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 0xc); 80238032Speter } 80338032Speter } 80438032Speter else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_LANAI2_U) 80590792Sgshapiro { 80690792Sgshapiro if (interface == 0) 80790792Sgshapiro { 80838032Speter cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 16); 80938032Speter cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 16); 81038032Speter } 81138032Speter } 81238032Speter else if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3010_EVB_HS5) 81364562Sgshapiro { 81464562Sgshapiro /* Broadcom PHYs require different ASX clocks. Unfortunately 81564562Sgshapiro many customer don't define a new board Id and simply 81664562Sgshapiro mangle the CN3010_EVB_HS5 */ 81764562Sgshapiro if (interface == 0) 81864562Sgshapiro { 81964562Sgshapiro /* Some customers boards use a hacked up bootloader that identifies them as 82064562Sgshapiro ** CN3010_EVB_HS5 evaluation boards. This leads to all kinds of configuration 82164562Sgshapiro ** problems. Detect one case, and print warning, while trying to do the right thing. 82264562Sgshapiro */ 82364562Sgshapiro int phy_addr = cvmx_helper_board_get_mii_address(0); 82464562Sgshapiro if (phy_addr != -1) 82564562Sgshapiro { 82664562Sgshapiro int phy_identifier = cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 0x2); 82764562Sgshapiro /* Is it a Broadcom PHY? */ 82864562Sgshapiro if (phy_identifier == 0x0143) 82964562Sgshapiro { 83064562Sgshapiro cvmx_dprintf("\n"); 83164562Sgshapiro cvmx_dprintf("ERROR:\n"); 83238032Speter cvmx_dprintf("ERROR: Board type is CVMX_BOARD_TYPE_CN3010_EVB_HS5, but Broadcom PHY found.\n"); 83364562Sgshapiro cvmx_dprintf("ERROR: The board type is mis-configured, and software malfunctions are likely.\n"); 83464562Sgshapiro cvmx_dprintf("ERROR: All boards require a unique board type to identify them.\n"); 83564562Sgshapiro cvmx_dprintf("ERROR:\n"); 83664562Sgshapiro cvmx_dprintf("\n"); 83790792Sgshapiro cvmx_wait(1000000000); 83864562Sgshapiro cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface), 5); 83938032Speter cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface), 5); 840168515Sgshapiro } 84190792Sgshapiro } 842173340Sgshapiro } 84390792Sgshapiro } 84490792Sgshapiro return 0; 84564562Sgshapiro} 846168515Sgshapiro 84764562Sgshapiro 848157001Sgshapiro/** 84964562Sgshapiro * @INTERNAL 85064562Sgshapiro * Gets the clock type used for the USB block based on board type. 85190792Sgshapiro * Used by the USB code for auto configuration of clock type. 85264562Sgshapiro * 85364562Sgshapiro * @return USB clock type enumeration 85464562Sgshapiro */ 85564562Sgshapirocvmx_helper_board_usb_clock_types_t __cvmx_helper_board_usb_get_clock_type(void) 85664562Sgshapiro{ 85764562Sgshapiro switch (cvmx_sysinfo_get()->board_type) 85864562Sgshapiro { 85964562Sgshapiro case CVMX_BOARD_TYPE_BBGW_REF: 86064562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_A: 86164562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_U: 86264562Sgshapiro case CVMX_BOARD_TYPE_LANAI2_G: 86364562Sgshapiro#if defined(OCTEON_VENDOR_LANNER) 86464562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR320: 86564562Sgshapiro case CVMX_BOARD_TYPE_CUST_LANNER_MR321X: 86690792Sgshapiro#endif 86738032Speter return USB_CLOCK_TYPE_CRYSTAL_12; 86838032Speter } 86938032Speter return USB_CLOCK_TYPE_REF_48; 87038032Speter} 87138032Speter 87238032Speter 87338032Speter/** 87438032Speter * @INTERNAL 87538032Speter * Adjusts the number of available USB ports on Octeon based on board 87638032Speter * specifics. 87738032Speter * 87838032Speter * @param supported_ports expected number of ports based on chip type; 87938032Speter * 88090792Sgshapiro * 88138032Speter * @return number of available usb ports, based on board specifics. 88238032Speter * Return value is supported_ports if function does not 88338032Speter * override. 88438032Speter */ 88538032Speterint __cvmx_helper_board_usb_get_num_ports(int supported_ports) 88666494Sgshapiro{ 88766494Sgshapiro switch (cvmx_sysinfo_get()->board_type) 88866494Sgshapiro { 88966494Sgshapiro case CVMX_BOARD_TYPE_NIC_XLE_4G: 89066494Sgshapiro return 0; 89166494Sgshapiro } 89290792Sgshapiro 89338032Speter return supported_ports; 89490792Sgshapiro} 89590792Sgshapiro 89638032Speter 89738032Speter