Path: blob/master/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
26481 views
/***********************license start***************1* Author: Cavium Networks2*3* Contact: [email protected]4* This file is part of the OCTEON SDK5*6* Copyright (c) 2003-2008 Cavium Networks7*8* This file is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License, Version 2, as10* published by the Free Software Foundation.11*12* This file is distributed in the hope that it will be useful, but13* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty14* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or15* NONINFRINGEMENT. See the GNU General Public License for more16* details.17*18* You should have received a copy of the GNU General Public License19* along with this file; if not, write to the Free Software20* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA21* or visit http://www.gnu.org/licenses/.22*23* This file may also be available under a different license from Cavium.24* Contact Cavium Networks for more information25***********************license end**************************************/2627/*28*29* Helper functions to abstract board specific data about30* network ports from the rest of the cvmx-helper files.31*/3233#include <linux/bug.h>34#include <asm/octeon/octeon.h>35#include <asm/octeon/cvmx-bootinfo.h>3637#include <asm/octeon/cvmx-config.h>3839#include <asm/octeon/cvmx-helper.h>40#include <asm/octeon/cvmx-helper-util.h>41#include <asm/octeon/cvmx-helper-board.h>4243#include <asm/octeon/cvmx-gmxx-defs.h>44#include <asm/octeon/cvmx-asxx-defs.h>4546/*47* Return the MII PHY address associated with the given IPD48* port. A result of -1 means there isn't a MII capable PHY49* connected to this port. On chips supporting multiple MII50* busses the bus number is encoded in bits <15:8>.51*52* This function must be modified for every new Octeon board.53* Internally it uses switch statements based on the cvmx_sysinfo54* data to determine board types and revisions. It replies on the55* fact that every Octeon board receives a unique board type56* enumeration from the bootloader.57*58* @ipd_port: Octeon IPD port to get the MII address for.59*60* Returns MII PHY address and bus number or -1.61*/62int cvmx_helper_board_get_mii_address(int ipd_port)63{64switch (cvmx_sysinfo_get()->board_type) {65case CVMX_BOARD_TYPE_SIM:66/* Simulator doesn't have MII */67return -1;68case CVMX_BOARD_TYPE_EBT3000:69case CVMX_BOARD_TYPE_EBT5800:70case CVMX_BOARD_TYPE_THUNDER:71case CVMX_BOARD_TYPE_NICPRO2:72/* Interface 0 is SPI4, interface 1 is RGMII */73if ((ipd_port >= 16) && (ipd_port < 20))74return ipd_port - 16;75else76return -1;77case CVMX_BOARD_TYPE_KODAMA:78case CVMX_BOARD_TYPE_EBH3100:79case CVMX_BOARD_TYPE_HIKARI:80case CVMX_BOARD_TYPE_CN3010_EVB_HS5:81case CVMX_BOARD_TYPE_CN3005_EVB_HS5:82case CVMX_BOARD_TYPE_CN3020_EVB_HS5:83/*84* Port 0 is WAN connected to a PHY, Port 1 is GMII85* connected to a switch86*/87if (ipd_port == 0)88return 4;89else if (ipd_port == 1)90return 9;91else92return -1;93case CVMX_BOARD_TYPE_NAC38:94/* Board has 8 RGMII ports PHYs are 0-7 */95if ((ipd_port >= 0) && (ipd_port < 4))96return ipd_port;97else if ((ipd_port >= 16) && (ipd_port < 20))98return ipd_port - 16 + 4;99else100return -1;101case CVMX_BOARD_TYPE_EBH3000:102/* Board has dual SPI4 and no PHYs */103return -1;104case CVMX_BOARD_TYPE_EBH5200:105case CVMX_BOARD_TYPE_EBH5201:106case CVMX_BOARD_TYPE_EBT5200:107/* Board has 2 management ports */108if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) &&109(ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))110return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT;111/*112* Board has 4 SGMII ports. The PHYs start right after the MII113* ports MII0 = 0, MII1 = 1, SGMII = 2-5.114*/115if ((ipd_port >= 0) && (ipd_port < 4))116return ipd_port + 2;117else118return -1;119case CVMX_BOARD_TYPE_EBH5600:120case CVMX_BOARD_TYPE_EBH5601:121case CVMX_BOARD_TYPE_EBH5610:122/* Board has 1 management port */123if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)124return 0;125/*126* Board has 8 SGMII ports. 4 connect out, two connect127* to a switch, and 2 loop to each other128*/129if ((ipd_port >= 0) && (ipd_port < 4))130return ipd_port + 1;131else132return -1;133case CVMX_BOARD_TYPE_CUST_NB5:134if (ipd_port == 2)135return 4;136else137return -1;138case CVMX_BOARD_TYPE_NIC_XLE_4G:139/* Board has 4 SGMII ports. connected QLM3(interface 1) */140if ((ipd_port >= 16) && (ipd_port < 20))141return ipd_port - 16 + 1;142else143return -1;144case CVMX_BOARD_TYPE_NIC_XLE_10G:145case CVMX_BOARD_TYPE_NIC10E:146return -1;147case CVMX_BOARD_TYPE_NIC4E:148if (ipd_port >= 0 && ipd_port <= 3)149return (ipd_port + 0x1f) & 0x1f;150else151return -1;152case CVMX_BOARD_TYPE_NIC2E:153if (ipd_port >= 0 && ipd_port <= 1)154return ipd_port + 1;155else156return -1;157case CVMX_BOARD_TYPE_BBGW_REF:158/*159* No PHYs are connected to Octeon, everything is160* through switch.161*/162return -1;163164case CVMX_BOARD_TYPE_CUST_WSX16:165if (ipd_port >= 0 && ipd_port <= 3)166return ipd_port;167else if (ipd_port >= 16 && ipd_port <= 19)168return ipd_port - 16 + 4;169else170return -1;171case CVMX_BOARD_TYPE_UBNT_E100:172if (ipd_port >= 0 && ipd_port <= 2)173return 7 - ipd_port;174else175return -1;176case CVMX_BOARD_TYPE_KONTRON_S1901:177if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)178return 1;179else180return -1;181182}183184/* Some unknown board. Somebody forgot to update this function... */185cvmx_dprintf186("cvmx_helper_board_get_mii_address: Unknown board type %d\n",187cvmx_sysinfo_get()->board_type);188return -1;189}190191/*192* This function is the board specific method of determining an193* ethernet ports link speed. Most Octeon boards have Marvell PHYs194* and are handled by the fall through case. This function must be195* updated for boards that don't have the normal Marvell PHYs.196*197* This function must be modified for every new Octeon board.198* Internally it uses switch statements based on the cvmx_sysinfo199* data to determine board types and revisions. It relies on the200* fact that every Octeon board receives a unique board type201* enumeration from the bootloader.202*203* @ipd_port: IPD input port associated with the port we want to get link204* status for.205*206* Returns The ports link status. If the link isn't fully resolved, this must207* return zero.208*/209union cvmx_helper_link_info __cvmx_helper_board_link_get(int ipd_port)210{211union cvmx_helper_link_info result;212213WARN_ONCE(!octeon_is_simulation(),214"Using deprecated link status - please update your DT");215216/* Unless we fix it later, all links are defaulted to down */217result.u64 = 0;218219if (octeon_is_simulation()) {220/* The simulator gives you a simulated 1Gbps full duplex link */221result.s.link_up = 1;222result.s.full_duplex = 1;223result.s.speed = 1000;224return result;225}226227if (OCTEON_IS_MODEL(OCTEON_CN3XXX)228|| OCTEON_IS_MODEL(OCTEON_CN58XX)229|| OCTEON_IS_MODEL(OCTEON_CN50XX)) {230/*231* We don't have a PHY address, so attempt to use232* in-band status. It is really important that boards233* not supporting in-band status never get234* here. Reading broken in-band status tends to do bad235* things236*/237union cvmx_gmxx_rxx_rx_inbnd inband_status;238int interface = cvmx_helper_get_interface_num(ipd_port);239int index = cvmx_helper_get_interface_index_num(ipd_port);240inband_status.u64 =241cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index, interface));242243result.s.link_up = inband_status.s.status;244result.s.full_duplex = inband_status.s.duplex;245switch (inband_status.s.speed) {246case 0: /* 10 Mbps */247result.s.speed = 10;248break;249case 1: /* 100 Mbps */250result.s.speed = 100;251break;252case 2: /* 1 Gbps */253result.s.speed = 1000;254break;255case 3: /* Illegal */256result.u64 = 0;257break;258}259} else {260/*261* We don't have a PHY address and we don't have262* in-band status. There is no way to determine the263* link speed. Return down assuming this port isn't264* wired265*/266result.u64 = 0;267}268269/* If link is down, return all fields as zero. */270if (!result.s.link_up)271result.u64 = 0;272273return result;274}275276/*277* This function is called by cvmx_helper_interface_probe() after it278* determines the number of ports Octeon can support on a specific279* interface. This function is the per board location to override280* this value. It is called with the number of ports Octeon might281* support and should return the number of actual ports on the282* board.283*284* This function must be modified for every new Octeon board.285* Internally it uses switch statements based on the cvmx_sysinfo286* data to determine board types and revisions. It relies on the287* fact that every Octeon board receives a unique board type288* enumeration from the bootloader.289*290* @interface: Interface to probe291* @supported_ports:292* Number of ports Octeon supports.293*294* Returns Number of ports the actual board supports. Many times this will295* simple be "support_ports".296*/297int __cvmx_helper_board_interface_probe(int interface, int supported_ports)298{299switch (cvmx_sysinfo_get()->board_type) {300case CVMX_BOARD_TYPE_CN3005_EVB_HS5:301if (interface == 0)302return 2;303break;304case CVMX_BOARD_TYPE_BBGW_REF:305if (interface == 0)306return 2;307break;308case CVMX_BOARD_TYPE_NIC_XLE_4G:309if (interface == 0)310return 0;311break;312/* The 2nd interface on the EBH5600 is connected to the Marvel switch,313which we don't support. Disable ports connected to it */314case CVMX_BOARD_TYPE_EBH5600:315if (interface == 1)316return 0;317break;318}319return supported_ports;320}321322/*323* Get the clock type used for the USB block based on board type.324* Used by the USB code for auto configuration of clock type.325*326* Return USB clock type enumeration327*/328enum cvmx_helper_board_usb_clock_types __cvmx_helper_board_usb_get_clock_type(void)329{330switch (cvmx_sysinfo_get()->board_type) {331case CVMX_BOARD_TYPE_BBGW_REF:332case CVMX_BOARD_TYPE_LANAI2_A:333case CVMX_BOARD_TYPE_LANAI2_U:334case CVMX_BOARD_TYPE_LANAI2_G:335case CVMX_BOARD_TYPE_NIC10E_66:336case CVMX_BOARD_TYPE_UBNT_E100:337return USB_CLOCK_TYPE_CRYSTAL_12;338case CVMX_BOARD_TYPE_NIC10E:339return USB_CLOCK_TYPE_REF_12;340default:341break;342}343/* Most boards except NIC10e use a 12MHz crystal */344if (OCTEON_IS_OCTEON2())345return USB_CLOCK_TYPE_CRYSTAL_12;346return USB_CLOCK_TYPE_REF_48;347}348349350