1*11453Sgdamore@opensolaris.org /*
2*11453Sgdamore@opensolaris.org * CDDL HEADER START
3*11453Sgdamore@opensolaris.org *
4*11453Sgdamore@opensolaris.org * The contents of this file are subject to the terms of the
5*11453Sgdamore@opensolaris.org * Common Development and Distribution License (the "License").
6*11453Sgdamore@opensolaris.org * You may not use this file except in compliance with the License.
7*11453Sgdamore@opensolaris.org *
8*11453Sgdamore@opensolaris.org * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*11453Sgdamore@opensolaris.org * or http://www.opensolaris.org/os/licensing.
10*11453Sgdamore@opensolaris.org * See the License for the specific language governing permissions
11*11453Sgdamore@opensolaris.org * and limitations under the License.
12*11453Sgdamore@opensolaris.org *
13*11453Sgdamore@opensolaris.org * When distributing Covered Code, include this CDDL HEADER in each
14*11453Sgdamore@opensolaris.org * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*11453Sgdamore@opensolaris.org * If applicable, add the following below this CDDL HEADER, with the
16*11453Sgdamore@opensolaris.org * fields enclosed by brackets "[]" replaced with your own identifying
17*11453Sgdamore@opensolaris.org * information: Portions Copyright [yyyy] [name of copyright owner]
18*11453Sgdamore@opensolaris.org *
19*11453Sgdamore@opensolaris.org * CDDL HEADER END
20*11453Sgdamore@opensolaris.org */
21*11453Sgdamore@opensolaris.org /*
22*11453Sgdamore@opensolaris.org * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23*11453Sgdamore@opensolaris.org * Use is subject to license terms.
24*11453Sgdamore@opensolaris.org */
25*11453Sgdamore@opensolaris.org
26*11453Sgdamore@opensolaris.org /*
27*11453Sgdamore@opensolaris.org * MII overrides for Cicada (now Vitesse) PHYs.
28*11453Sgdamore@opensolaris.org */
29*11453Sgdamore@opensolaris.org
30*11453Sgdamore@opensolaris.org #include <sys/types.h>
31*11453Sgdamore@opensolaris.org #include <sys/ddi.h>
32*11453Sgdamore@opensolaris.org #include <sys/sunddi.h>
33*11453Sgdamore@opensolaris.org #include <sys/mii.h>
34*11453Sgdamore@opensolaris.org #include <sys/miiregs.h>
35*11453Sgdamore@opensolaris.org #include "miipriv.h"
36*11453Sgdamore@opensolaris.org
37*11453Sgdamore@opensolaris.org
38*11453Sgdamore@opensolaris.org /*
39*11453Sgdamore@opensolaris.org * The Realtek 10/100 PHYs are mostly standard compliant, but they
40*11453Sgdamore@opensolaris.org * lack a true vendor/device ID for the integrated PHY, and they don't
41*11453Sgdamore@opensolaris.org * report the "detected" non-Nway link speed in the appropriate
42*11453Sgdamore@opensolaris.org * registers.
43*11453Sgdamore@opensolaris.org */
44*11453Sgdamore@opensolaris.org static int rtl8139_check(phy_handle_t *);
45*11453Sgdamore@opensolaris.org static int rtl8201_check(phy_handle_t *);
46*11453Sgdamore@opensolaris.org
47*11453Sgdamore@opensolaris.org boolean_t
phy_realtek_probe(phy_handle_t * ph)48*11453Sgdamore@opensolaris.org phy_realtek_probe(phy_handle_t *ph)
49*11453Sgdamore@opensolaris.org {
50*11453Sgdamore@opensolaris.org if ((ph->phy_id == 0) &&
51*11453Sgdamore@opensolaris.org (strcmp(phy_get_driver(ph), "rtls") == 0)) {
52*11453Sgdamore@opensolaris.org ph->phy_vendor = "Realtek";
53*11453Sgdamore@opensolaris.org ph->phy_model = "Internal RTL8139";
54*11453Sgdamore@opensolaris.org ph->phy_check = rtl8139_check;
55*11453Sgdamore@opensolaris.org return (B_TRUE);
56*11453Sgdamore@opensolaris.org } else if (ph->phy_id == 0x8201) {
57*11453Sgdamore@opensolaris.org ph->phy_vendor = "Realtek";
58*11453Sgdamore@opensolaris.org ph->phy_model = "RTL8201";
59*11453Sgdamore@opensolaris.org ph->phy_check = rtl8201_check;
60*11453Sgdamore@opensolaris.org return (B_TRUE);
61*11453Sgdamore@opensolaris.org } else {
62*11453Sgdamore@opensolaris.org return (B_FALSE);
63*11453Sgdamore@opensolaris.org }
64*11453Sgdamore@opensolaris.org }
65*11453Sgdamore@opensolaris.org
66*11453Sgdamore@opensolaris.org static int
rtl8139_check(phy_handle_t * ph)67*11453Sgdamore@opensolaris.org rtl8139_check(phy_handle_t *ph)
68*11453Sgdamore@opensolaris.org {
69*11453Sgdamore@opensolaris.org int rv;
70*11453Sgdamore@opensolaris.org uint16_t s;
71*11453Sgdamore@opensolaris.org
72*11453Sgdamore@opensolaris.org rv = phy_check(ph);
73*11453Sgdamore@opensolaris.org
74*11453Sgdamore@opensolaris.org /*
75*11453Sgdamore@opensolaris.org * We possibly override settings, so that we can use the PHYs
76*11453Sgdamore@opensolaris.org * autodetected link speed if the partner isn't doing NWay.
77*11453Sgdamore@opensolaris.org */
78*11453Sgdamore@opensolaris.org s = phy_read(ph, MII_VENDOR(0));
79*11453Sgdamore@opensolaris.org if (s & (1 << 2)) {
80*11453Sgdamore@opensolaris.org ph->phy_link = LINK_STATE_DOWN;
81*11453Sgdamore@opensolaris.org } else {
82*11453Sgdamore@opensolaris.org ph->phy_link = LINK_STATE_UP;
83*11453Sgdamore@opensolaris.org if (s & (1 << 3)) {
84*11453Sgdamore@opensolaris.org ph->phy_speed = 10;
85*11453Sgdamore@opensolaris.org } else {
86*11453Sgdamore@opensolaris.org ph->phy_speed = 100;
87*11453Sgdamore@opensolaris.org }
88*11453Sgdamore@opensolaris.org }
89*11453Sgdamore@opensolaris.org
90*11453Sgdamore@opensolaris.org return (rv);
91*11453Sgdamore@opensolaris.org }
92*11453Sgdamore@opensolaris.org
93*11453Sgdamore@opensolaris.org static int
rtl8201_check(phy_handle_t * ph)94*11453Sgdamore@opensolaris.org rtl8201_check(phy_handle_t *ph)
95*11453Sgdamore@opensolaris.org {
96*11453Sgdamore@opensolaris.org int rv;
97*11453Sgdamore@opensolaris.org uint16_t s;
98*11453Sgdamore@opensolaris.org
99*11453Sgdamore@opensolaris.org rv = phy_check(ph);
100*11453Sgdamore@opensolaris.org
101*11453Sgdamore@opensolaris.org /*
102*11453Sgdamore@opensolaris.org * We possibly override settings, so that we can use the PHYs
103*11453Sgdamore@opensolaris.org * autodetected link speed if the partner isn't doing NWay.
104*11453Sgdamore@opensolaris.org */
105*11453Sgdamore@opensolaris.org s = phy_read(ph, MII_VENDOR(9));
106*11453Sgdamore@opensolaris.org if (s & (1 << 0)) {
107*11453Sgdamore@opensolaris.org ph->phy_link = LINK_STATE_UP;
108*11453Sgdamore@opensolaris.org ph->phy_speed = 100;
109*11453Sgdamore@opensolaris.org } else if (s & (1 << 1)) {
110*11453Sgdamore@opensolaris.org ph->phy_link = LINK_STATE_UP;
111*11453Sgdamore@opensolaris.org ph->phy_speed = 10;
112*11453Sgdamore@opensolaris.org } else {
113*11453Sgdamore@opensolaris.org ph->phy_link = LINK_STATE_DOWN;
114*11453Sgdamore@opensolaris.org }
115*11453Sgdamore@opensolaris.org
116*11453Sgdamore@opensolaris.org return (rv);
117*11453Sgdamore@opensolaris.org }
118