1 /***********************license start***************
2 * Author: Cavium Networks
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
7 * Copyright (c) 2003-2008 Cavium Networks
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
30 * Helper functions to abstract board specific data about
31 * network ports from the rest of the cvmx-helper files.
34 #include <linux/bug.h>
35 #include <asm/octeon/octeon.h>
36 #include <asm/octeon/cvmx-bootinfo.h>
38 #include <asm/octeon/cvmx-config.h>
40 #include <asm/octeon/cvmx-helper.h>
41 #include <asm/octeon/cvmx-helper-util.h>
42 #include <asm/octeon/cvmx-helper-board.h>
44 #include <asm/octeon/cvmx-gmxx-defs.h>
45 #include <asm/octeon/cvmx-asxx-defs.h>
48 * Return the MII PHY address associated with the given IPD
49 * port. A result of -1 means there isn't a MII capable PHY
50 * connected to this port. On chips supporting multiple MII
51 * busses the bus number is encoded in bits <15:8>.
53 * This function must be modified for every new Octeon board.
54 * Internally it uses switch statements based on the cvmx_sysinfo
55 * data to determine board types and revisions. It replies on the
56 * fact that every Octeon board receives a unique board type
57 * enumeration from the bootloader.
59 * @ipd_port: Octeon IPD port to get the MII address for.
61 * Returns MII PHY address and bus number or -1.
63 int cvmx_helper_board_get_mii_address(int ipd_port
)
65 switch (cvmx_sysinfo_get()->board_type
) {
66 case CVMX_BOARD_TYPE_SIM
:
67 /* Simulator doesn't have MII */
69 case CVMX_BOARD_TYPE_EBT3000
:
70 case CVMX_BOARD_TYPE_EBT5800
:
71 case CVMX_BOARD_TYPE_THUNDER
:
72 case CVMX_BOARD_TYPE_NICPRO2
:
73 /* Interface 0 is SPI4, interface 1 is RGMII */
74 if ((ipd_port
>= 16) && (ipd_port
< 20))
78 case CVMX_BOARD_TYPE_KODAMA
:
79 case CVMX_BOARD_TYPE_EBH3100
:
80 case CVMX_BOARD_TYPE_HIKARI
:
81 case CVMX_BOARD_TYPE_CN3010_EVB_HS5
:
82 case CVMX_BOARD_TYPE_CN3005_EVB_HS5
:
83 case CVMX_BOARD_TYPE_CN3020_EVB_HS5
:
85 * Port 0 is WAN connected to a PHY, Port 1 is GMII
86 * connected to a switch
90 else if (ipd_port
== 1)
94 case CVMX_BOARD_TYPE_NAC38
:
95 /* Board has 8 RGMII ports PHYs are 0-7 */
96 if ((ipd_port
>= 0) && (ipd_port
< 4))
98 else if ((ipd_port
>= 16) && (ipd_port
< 20))
99 return ipd_port
- 16 + 4;
102 case CVMX_BOARD_TYPE_EBH3000
:
103 /* Board has dual SPI4 and no PHYs */
105 case CVMX_BOARD_TYPE_EBH5200
:
106 case CVMX_BOARD_TYPE_EBH5201
:
107 case CVMX_BOARD_TYPE_EBT5200
:
108 /* Board has 2 management ports */
109 if ((ipd_port
>= CVMX_HELPER_BOARD_MGMT_IPD_PORT
) &&
110 (ipd_port
< (CVMX_HELPER_BOARD_MGMT_IPD_PORT
+ 2)))
111 return ipd_port
- CVMX_HELPER_BOARD_MGMT_IPD_PORT
;
113 * Board has 4 SGMII ports. The PHYs start right after the MII
114 * ports MII0 = 0, MII1 = 1, SGMII = 2-5.
116 if ((ipd_port
>= 0) && (ipd_port
< 4))
120 case CVMX_BOARD_TYPE_EBH5600
:
121 case CVMX_BOARD_TYPE_EBH5601
:
122 case CVMX_BOARD_TYPE_EBH5610
:
123 /* Board has 1 management port */
124 if (ipd_port
== CVMX_HELPER_BOARD_MGMT_IPD_PORT
)
127 * Board has 8 SGMII ports. 4 connect out, two connect
128 * to a switch, and 2 loop to each other
130 if ((ipd_port
>= 0) && (ipd_port
< 4))
134 case CVMX_BOARD_TYPE_CUST_NB5
:
139 case CVMX_BOARD_TYPE_NIC_XLE_4G
:
140 /* Board has 4 SGMII ports. connected QLM3(interface 1) */
141 if ((ipd_port
>= 16) && (ipd_port
< 20))
142 return ipd_port
- 16 + 1;
145 case CVMX_BOARD_TYPE_NIC_XLE_10G
:
146 case CVMX_BOARD_TYPE_NIC10E
:
148 case CVMX_BOARD_TYPE_NIC4E
:
149 if (ipd_port
>= 0 && ipd_port
<= 3)
150 return (ipd_port
+ 0x1f) & 0x1f;
153 case CVMX_BOARD_TYPE_NIC2E
:
154 if (ipd_port
>= 0 && ipd_port
<= 1)
158 case CVMX_BOARD_TYPE_BBGW_REF
:
160 * No PHYs are connected to Octeon, everything is
165 case CVMX_BOARD_TYPE_CUST_WSX16
:
166 if (ipd_port
>= 0 && ipd_port
<= 3)
168 else if (ipd_port
>= 16 && ipd_port
<= 19)
169 return ipd_port
- 16 + 4;
172 case CVMX_BOARD_TYPE_UBNT_E100
:
173 if (ipd_port
>= 0 && ipd_port
<= 2)
177 case CVMX_BOARD_TYPE_KONTRON_S1901
:
178 if (ipd_port
== CVMX_HELPER_BOARD_MGMT_IPD_PORT
)
185 /* Some unknown board. Somebody forgot to update this function... */
187 ("cvmx_helper_board_get_mii_address: Unknown board type %d\n",
188 cvmx_sysinfo_get()->board_type
);
193 * This function is the board specific method of determining an
194 * ethernet ports link speed. Most Octeon boards have Marvell PHYs
195 * and are handled by the fall through case. This function must be
196 * updated for boards that don't have the normal Marvell PHYs.
198 * This function must be modified for every new Octeon board.
199 * Internally it uses switch statements based on the cvmx_sysinfo
200 * data to determine board types and revisions. It relies on the
201 * fact that every Octeon board receives a unique board type
202 * enumeration from the bootloader.
204 * @ipd_port: IPD input port associated with the port we want to get link
207 * Returns The ports link status. If the link isn't fully resolved, this must
210 union cvmx_helper_link_info
__cvmx_helper_board_link_get(int ipd_port
)
212 union cvmx_helper_link_info result
;
214 WARN(!octeon_is_simulation(),
215 "Using deprecated link status - please update your DT");
217 /* Unless we fix it later, all links are defaulted to down */
220 if (octeon_is_simulation()) {
221 /* The simulator gives you a simulated 1Gbps full duplex link */
222 result
.s
.link_up
= 1;
223 result
.s
.full_duplex
= 1;
224 result
.s
.speed
= 1000;
228 if (OCTEON_IS_MODEL(OCTEON_CN3XXX
)
229 || OCTEON_IS_MODEL(OCTEON_CN58XX
)
230 || OCTEON_IS_MODEL(OCTEON_CN50XX
)) {
232 * We don't have a PHY address, so attempt to use
233 * in-band status. It is really important that boards
234 * not supporting in-band status never get
235 * here. Reading broken in-band status tends to do bad
238 union cvmx_gmxx_rxx_rx_inbnd inband_status
;
239 int interface
= cvmx_helper_get_interface_num(ipd_port
);
240 int index
= cvmx_helper_get_interface_index_num(ipd_port
);
242 cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index
, interface
));
244 result
.s
.link_up
= inband_status
.s
.status
;
245 result
.s
.full_duplex
= inband_status
.s
.duplex
;
246 switch (inband_status
.s
.speed
) {
247 case 0: /* 10 Mbps */
250 case 1: /* 100 Mbps */
251 result
.s
.speed
= 100;
254 result
.s
.speed
= 1000;
256 case 3: /* Illegal */
262 * We don't have a PHY address and we don't have
263 * in-band status. There is no way to determine the
264 * link speed. Return down assuming this port isn't
270 /* If link is down, return all fields as zero. */
271 if (!result
.s
.link_up
)
278 * This function is called by cvmx_helper_interface_probe() after it
279 * determines the number of ports Octeon can support on a specific
280 * interface. This function is the per board location to override
281 * this value. It is called with the number of ports Octeon might
282 * support and should return the number of actual ports on the
285 * This function must be modifed for every new Octeon board.
286 * Internally it uses switch statements based on the cvmx_sysinfo
287 * data to determine board types and revisions. It relys on the
288 * fact that every Octeon board receives a unique board type
289 * enumeration from the bootloader.
291 * @interface: Interface to probe
293 * Number of ports Octeon supports.
295 * Returns Number of ports the actual board supports. Many times this will
296 * simple be "support_ports".
298 int __cvmx_helper_board_interface_probe(int interface
, int supported_ports
)
300 switch (cvmx_sysinfo_get()->board_type
) {
301 case CVMX_BOARD_TYPE_CN3005_EVB_HS5
:
305 case CVMX_BOARD_TYPE_BBGW_REF
:
309 case CVMX_BOARD_TYPE_NIC_XLE_4G
:
313 /* The 2nd interface on the EBH5600 is connected to the Marvel switch,
314 which we don't support. Disable ports connected to it */
315 case CVMX_BOARD_TYPE_EBH5600
:
320 return supported_ports
;
324 * Get the clock type used for the USB block based on board type.
325 * Used by the USB code for auto configuration of clock type.
327 * Return USB clock type enumeration
329 enum cvmx_helper_board_usb_clock_types
__cvmx_helper_board_usb_get_clock_type(void)
331 switch (cvmx_sysinfo_get()->board_type
) {
332 case CVMX_BOARD_TYPE_BBGW_REF
:
333 case CVMX_BOARD_TYPE_LANAI2_A
:
334 case CVMX_BOARD_TYPE_LANAI2_U
:
335 case CVMX_BOARD_TYPE_LANAI2_G
:
336 case CVMX_BOARD_TYPE_NIC10E_66
:
337 case CVMX_BOARD_TYPE_UBNT_E100
:
338 return USB_CLOCK_TYPE_CRYSTAL_12
;
339 case CVMX_BOARD_TYPE_NIC10E
:
340 return USB_CLOCK_TYPE_REF_12
;
344 /* Most boards except NIC10e use a 12MHz crystal */
345 if (OCTEON_IS_OCTEON2())
346 return USB_CLOCK_TYPE_CRYSTAL_12
;
347 return USB_CLOCK_TYPE_REF_48
;