xref: /onnv-gate/usr/src/uts/common/io/chxge/com/xpak.c (revision 3833:45d8d0ee8613)
1*3833Sxw161283 /*
2*3833Sxw161283  * CDDL HEADER START
3*3833Sxw161283  *
4*3833Sxw161283  * The contents of this file are subject to the terms of the
5*3833Sxw161283  * Common Development and Distribution License (the "License").
6*3833Sxw161283  * You may not use this file except in compliance with the License.
7*3833Sxw161283  *
8*3833Sxw161283  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3833Sxw161283  * or http://www.opensolaris.org/os/licensing.
10*3833Sxw161283  * See the License for the specific language governing permissions
11*3833Sxw161283  * and limitations under the License.
12*3833Sxw161283  *
13*3833Sxw161283  * When distributing Covered Code, include this CDDL HEADER in each
14*3833Sxw161283  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3833Sxw161283  * If applicable, add the following below this CDDL HEADER, with the
16*3833Sxw161283  * fields enclosed by brackets "[]" replaced with your own identifying
17*3833Sxw161283  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3833Sxw161283  *
19*3833Sxw161283  * CDDL HEADER END
20*3833Sxw161283  */
21*3833Sxw161283 
22*3833Sxw161283 /*
23*3833Sxw161283  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
24*3833Sxw161283  */
25*3833Sxw161283 
26*3833Sxw161283 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* xpak.c */
27*3833Sxw161283 
28*3833Sxw161283 #include "cphy.h"
29*3833Sxw161283 #include "elmer0.h"
30*3833Sxw161283 
31*3833Sxw161283 /* ARGSUSED */
xpak_reset(struct cphy * cphy,int wait)32*3833Sxw161283 static int xpak_reset(struct cphy *cphy, int wait)
33*3833Sxw161283 {
34*3833Sxw161283 	return 0;
35*3833Sxw161283 }
36*3833Sxw161283 
37*3833Sxw161283 /* ARGSUSED */
xpak_interrupt_enable(struct cphy * cphy)38*3833Sxw161283 static int xpak_interrupt_enable(struct cphy *cphy)
39*3833Sxw161283 {
40*3833Sxw161283 	return 0;
41*3833Sxw161283 }
42*3833Sxw161283 
43*3833Sxw161283 /* ARGSUSED */
xpak_interrupt_disable(struct cphy * cphy)44*3833Sxw161283 static int xpak_interrupt_disable(struct cphy *cphy)
45*3833Sxw161283 {
46*3833Sxw161283 	return 0;
47*3833Sxw161283 }
48*3833Sxw161283 
49*3833Sxw161283 /* ARGSUSED */
xpak_interrupt_clear(struct cphy * cphy)50*3833Sxw161283 static int xpak_interrupt_clear(struct cphy *cphy)
51*3833Sxw161283 {
52*3833Sxw161283 	return 0;
53*3833Sxw161283 }
54*3833Sxw161283 
55*3833Sxw161283 /* ARGSUSED */
xpak_set_loopback(struct cphy * cphy,int on)56*3833Sxw161283 static int xpak_set_loopback(struct cphy *cphy, int on)
57*3833Sxw161283 {
58*3833Sxw161283 	return 0;
59*3833Sxw161283 }
60*3833Sxw161283 
61*3833Sxw161283 /* ARGSUSED */
xpak_get_link_status(struct cphy * cphy,int * link_ok,int * speed,int * duplex,int * fc)62*3833Sxw161283 static int xpak_get_link_status(struct cphy *cphy, int *link_ok, int *speed,
63*3833Sxw161283 				int *duplex, int *fc)
64*3833Sxw161283 {
65*3833Sxw161283 	if (link_ok)
66*3833Sxw161283 		*link_ok = 1;
67*3833Sxw161283 	if (speed)
68*3833Sxw161283 		*speed = SPEED_10000;
69*3833Sxw161283 	if (duplex)
70*3833Sxw161283 		*duplex = DUPLEX_FULL;
71*3833Sxw161283 	if (fc)
72*3833Sxw161283 		*fc = PAUSE_RX | PAUSE_TX;
73*3833Sxw161283 	return 0;
74*3833Sxw161283 }
75*3833Sxw161283 
xpak_destroy(struct cphy * cphy)76*3833Sxw161283 static void xpak_destroy(struct cphy *cphy)
77*3833Sxw161283 {
78*3833Sxw161283 	t1_os_free((void *)cphy, sizeof(*cphy));
79*3833Sxw161283 }
80*3833Sxw161283 
81*3833Sxw161283 #ifdef C99_NOT_SUPPORTED
82*3833Sxw161283 static struct cphy_ops xpak_ops = {
83*3833Sxw161283 	 xpak_destroy,
84*3833Sxw161283          xpak_reset,
85*3833Sxw161283          xpak_interrupt_enable,
86*3833Sxw161283          xpak_interrupt_disable,
87*3833Sxw161283          xpak_interrupt_clear,
88*3833Sxw161283          NULL,
89*3833Sxw161283          NULL,
90*3833Sxw161283          NULL,
91*3833Sxw161283          NULL,
92*3833Sxw161283          NULL,
93*3833Sxw161283 	 xpak_set_loopback,
94*3833Sxw161283          NULL,
95*3833Sxw161283          xpak_get_link_status,
96*3833Sxw161283 };
97*3833Sxw161283 #else
98*3833Sxw161283 static struct cphy_ops xpak_ops = {
99*3833Sxw161283 	.destroy           = xpak_destroy,
100*3833Sxw161283 	.reset             = xpak_reset,
101*3833Sxw161283 	.interrupt_enable  = xpak_interrupt_enable,
102*3833Sxw161283 	.interrupt_disable = xpak_interrupt_disable,
103*3833Sxw161283 	.interrupt_clear   = xpak_interrupt_clear,
104*3833Sxw161283 	.get_link_status   = xpak_get_link_status,
105*3833Sxw161283 	.set_loopback      = xpak_set_loopback,
106*3833Sxw161283 };
107*3833Sxw161283 #endif
108*3833Sxw161283 
109*3833Sxw161283 /* ARGSUSED */
xpak_phy_create(adapter_t * adapter,int phy_addr,struct mdio_ops * mdio_ops)110*3833Sxw161283 static struct cphy *xpak_phy_create(adapter_t * adapter, int phy_addr,
111*3833Sxw161283 				    struct mdio_ops *mdio_ops)
112*3833Sxw161283 {
113*3833Sxw161283 	struct cphy *cphy = t1_os_malloc_wait_zero(sizeof(*cphy));
114*3833Sxw161283 
115*3833Sxw161283 	if (!cphy)
116*3833Sxw161283 		return NULL;
117*3833Sxw161283 
118*3833Sxw161283 	cphy->ops        = &xpak_ops;
119*3833Sxw161283 	cphy->adapter    = adapter;
120*3833Sxw161283 	cphy->mdio_read  = mdio_ops->read;
121*3833Sxw161283 	cphy->mdio_write = mdio_ops->write;
122*3833Sxw161283 	return cphy;
123*3833Sxw161283 }
124*3833Sxw161283 
xpak_phy_reset(adapter_t * adapter)125*3833Sxw161283 static int xpak_phy_reset(adapter_t *adapter)
126*3833Sxw161283 {
127*3833Sxw161283 	u32 val;
128*3833Sxw161283 
129*3833Sxw161283 	(void) t1_tpi_read(adapter, A_ELMER0_GPO, &val);
130*3833Sxw161283 	val &= ~4;
131*3833Sxw161283 	(void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
132*3833Sxw161283 	DELAY_MS(100);
133*3833Sxw161283 
134*3833Sxw161283 	/*
135*3833Sxw161283 	 * Errata #26 states to wait 5 seconds after reset before transceiver
136*3833Sxw161283 	 * becomes operational.
137*3833Sxw161283 	 */
138*3833Sxw161283 	(void) t1_tpi_write(adapter, A_ELMER0_GPO, val | 4);
139*3833Sxw161283 	DELAY_MS(5000);
140*3833Sxw161283 
141*3833Sxw161283 	/* Now lets enable the Laser. Delay 100us
142*3833Sxw161283 	 * as defined in XPAK errata.
143*3833Sxw161283 	 */
144*3833Sxw161283 	(void) t1_tpi_read(adapter, A_ELMER0_GPO, &val);
145*3833Sxw161283 	val |= 0x8000;
146*3833Sxw161283 	(void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
147*3833Sxw161283 	DELAY_US(100);
148*3833Sxw161283 	return 0;
149*3833Sxw161283 }
150*3833Sxw161283 
151*3833Sxw161283 struct gphy t1_xpak_ops = {
152*3833Sxw161283 	xpak_phy_create,
153*3833Sxw161283 	xpak_phy_reset
154*3833Sxw161283 };
155*3833Sxw161283 
156