xref: /onnv-gate/usr/src/uts/common/io/chxge/com/vsc7321.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"	/* vsc7321.c */
27*3833Sxw161283 
28*3833Sxw161283 /* Driver for Vitesse VSC7321 (Meigs II) MAC */
29*3833Sxw161283 
30*3833Sxw161283 
31*3833Sxw161283 #if 0
32*3833Sxw161283 #ifndef INVARIANTS
33*3833Sxw161283 #define INVARIANTS
34*3833Sxw161283 #endif
35*3833Sxw161283 
36*3833Sxw161283 #include <sys/param.h>
37*3833Sxw161283 #include <sys/systm.h>
38*3833Sxw161283 #include <sys/malloc.h>
39*3833Sxw161283 #include <sys/kernel.h>
40*3833Sxw161283 #include <sys/conf.h>
41*3833Sxw161283 #include <pci/pcivar.h>
42*3833Sxw161283 #include <pci/pcireg.h>
43*3833Sxw161283 #endif
44*3833Sxw161283 
45*3833Sxw161283 #include "gmac.h"
46*3833Sxw161283 #include "elmer0.h"
47*3833Sxw161283 #include "vsc7321_reg.h"
48*3833Sxw161283 
49*3833Sxw161283 #define DEBUG 1
50*3833Sxw161283 
51*3833Sxw161283 struct init_table {
52*3833Sxw161283     u32 addr;
53*3833Sxw161283     u32 data;
54*3833Sxw161283 };
55*3833Sxw161283 
56*3833Sxw161283 static struct cmac_ops vsc7321_ops;
57*3833Sxw161283 
58*3833Sxw161283 struct _cmac_instance {
59*3833Sxw161283 	u32 mac_base;
60*3833Sxw161283 	u32 index;
61*3833Sxw161283 	u32 version;
62*3833Sxw161283 };
63*3833Sxw161283 
64*3833Sxw161283 #define INITBLOCK_SLEEP	0xffffffff
65*3833Sxw161283 
vsc_read(adapter_t * adapter,u32 addr,u32 * val)66*3833Sxw161283 static void vsc_read(adapter_t *adapter, u32 addr, u32 *val)
67*3833Sxw161283 {
68*3833Sxw161283     u32 status, vlo, vhi;
69*3833Sxw161283 
70*3833Sxw161283     (void) t1_tpi_read(adapter, (addr << 2) + 4, &vlo);
71*3833Sxw161283 
72*3833Sxw161283     do {
73*3833Sxw161283 	(void) t1_tpi_read(adapter, (REG_LOCAL_STATUS << 2) + 4, &vlo);
74*3833Sxw161283 	(void) t1_tpi_read(adapter, REG_LOCAL_STATUS << 2, &vhi);
75*3833Sxw161283 	status = (vhi << 16) | vlo;
76*3833Sxw161283     } while ((status & 1) == 0);
77*3833Sxw161283 
78*3833Sxw161283     (void) t1_tpi_read(adapter, (REG_LOCAL_DATA << 2) + 4, &vlo);
79*3833Sxw161283     (void) t1_tpi_read(adapter, REG_LOCAL_DATA << 2, &vhi);
80*3833Sxw161283 
81*3833Sxw161283     *val = (vhi << 16) | vlo;
82*3833Sxw161283 }
83*3833Sxw161283 
vsc_write(adapter_t * adapter,u32 addr,u32 data)84*3833Sxw161283 static void vsc_write(adapter_t *adapter, u32 addr, u32 data)
85*3833Sxw161283 {
86*3833Sxw161283     (void) t1_tpi_write(adapter, (addr << 2) + 4, data & 0xFFFF);
87*3833Sxw161283     (void) t1_tpi_write(adapter, addr << 2, (data >> 16) & 0xFFFF);
88*3833Sxw161283 }
89*3833Sxw161283 
90*3833Sxw161283 /* Hard reset the MAC.  This wipes out *all* configuration. */
vsc7321_full_reset(adapter_t * adapter)91*3833Sxw161283 static void vsc7321_full_reset(adapter_t* adapter)
92*3833Sxw161283 {
93*3833Sxw161283     u32 val;
94*3833Sxw161283 
95*3833Sxw161283     (void) t1_tpi_read(adapter, A_ELMER0_GPO, &val);
96*3833Sxw161283     val &= ~1;
97*3833Sxw161283     (void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
98*3833Sxw161283     DELAY_US(2);
99*3833Sxw161283     val |= 0x80001;	/* Turn on SPI4_EN, and the MAC itself */
100*3833Sxw161283     if (is_10G(adapter)) {
101*3833Sxw161283 	val |= 0x40000;	/* Enable 10G section */
102*3833Sxw161283     } else {
103*3833Sxw161283 	val |= 0x20000;	/* Enable 1G section */
104*3833Sxw161283     }
105*3833Sxw161283     val &= ~0x800;	/* Turn off the red LED */
106*3833Sxw161283     (void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
107*3833Sxw161283     DELAY_US(1000);
108*3833Sxw161283 }
109*3833Sxw161283 
110*3833Sxw161283 static struct init_table vsc7321_reset[] = {
111*3833Sxw161283     {        REG_SW_RESET, 0x80000001 },
112*3833Sxw161283     { INITBLOCK_SLEEP, 0x64 },
113*3833Sxw161283     {        REG_SW_RESET, 0x00000000 },
114*3833Sxw161283     {      REG_IFACE_MODE, 0x00000000 },
115*3833Sxw161283     {         REG_CRC_CFG, 0x00000020 },
116*3833Sxw161283     {   REG_PLL_CLK_SPEED, 0x00000000 },
117*3833Sxw161283     { INITBLOCK_SLEEP, 0x0a },
118*3833Sxw161283     {   REG_PLL_CLK_SPEED, 0x000000d4 },
119*3833Sxw161283     {       REG_SPI4_MISC, 0x00040009 },
120*3833Sxw161283     { REG_SPI4_ING_SETUP2, 0x04040004 },
121*3833Sxw161283     { REG_SPI4_ING_SETUP0, 0x0011100f },	/* FIXME: Multiport */
122*3833Sxw161283     { REG_SPI4_EGR_SETUP0, 0x0004100f },	/* FIXME: Multiport */
123*3833Sxw161283     { REG_SPI4_ING_SETUP1, 0x00100000 },
124*3833Sxw161283     {      REG_AGE_INC(0), 0x00000000 },
125*3833Sxw161283     {      REG_AGE_INC(1), 0x00000000 },
126*3833Sxw161283     {     REG_ING_CONTROL, 0x0a000014 },	/* FIXME: 1G vs 10G */
127*3833Sxw161283     {     REG_EGR_CONTROL, 0xa0010091 },	/* FIXME: 1G vs 10G */
128*3833Sxw161283 };
129*3833Sxw161283 
130*3833Sxw161283 static struct init_table vsc7321_portinit[4][20] = {
131*3833Sxw161283     {	/* Port 0 */
132*3833Sxw161283     		/* FIFO setup */
133*3833Sxw161283 	{        REG_TEST(0,0), 0x00000002 },
134*3833Sxw161283 	{        REG_TEST(1,0), 0x00000002 },
135*3833Sxw161283 	{  REG_TOP_BOTTOM(0,0), 0x00100000 },
136*3833Sxw161283 	{  REG_TOP_BOTTOM(1,0), 0x00100000 },
137*3833Sxw161283 	{ REG_HIGH_LOW_WM(0,0), 0x0fff0fff },
138*3833Sxw161283 	{ REG_HIGH_LOW_WM(1,0), 0x0fff0fff },
139*3833Sxw161283 	{   REG_CT_THRHLD(0,0), 0x00000000 },
140*3833Sxw161283 	{   REG_CT_THRHLD(1,0), 0x00000000 },
141*3833Sxw161283 	{        REG_TEST(0,0), 0x00000000 },
142*3833Sxw161283 	{        REG_TEST(1,0), 0x00000000 },
143*3833Sxw161283 		/* Port config */
144*3833Sxw161283 	{      REG_MODE_CFG(0), 0x0000054c },
145*3833Sxw161283 	{       REG_MAX_LEN(0), 0x000005ee },
146*3833Sxw161283 	{     REG_DEV_SETUP(0), 0x00000001 },
147*3833Sxw161283 	{    REG_TBI_CONFIG(0), 0x00000000 },
148*3833Sxw161283 	{     REG_DEV_SETUP(0), 0x00000046 },
149*3833Sxw161283 	{     REG_PAUSE_CFG(0), 0x00000000 },
150*3833Sxw161283 	{    REG_NORMALIZER(0), 0x00000064 },
151*3833Sxw161283 	{        REG_DENORM(0), 0x00000010 },
152*3833Sxw161283     },
153*3833Sxw161283     {	/* Port 1 */
154*3833Sxw161283     		/* FIFO setup */
155*3833Sxw161283 	{        REG_TEST(0,1), 0x00000002 },
156*3833Sxw161283 	{        REG_TEST(1,1), 0x00000002 },
157*3833Sxw161283 	{  REG_TOP_BOTTOM(0,1), 0x00100000 },
158*3833Sxw161283 	{  REG_TOP_BOTTOM(1,1), 0x00100000 },
159*3833Sxw161283 	{ REG_HIGH_LOW_WM(0,1), 0x0fff0fff },
160*3833Sxw161283 	{ REG_HIGH_LOW_WM(1,1), 0x0fff0fff },
161*3833Sxw161283 	{   REG_CT_THRHLD(0,1), 0x00000000 },
162*3833Sxw161283 	{   REG_CT_THRHLD(1,1), 0x00000000 },
163*3833Sxw161283 	{        REG_TEST(0,1), 0x00000000 },
164*3833Sxw161283 	{        REG_TEST(1,1), 0x00000000 },
165*3833Sxw161283 		/* Port config */
166*3833Sxw161283 	{      REG_MODE_CFG(1), 0x0000054c },
167*3833Sxw161283 	{       REG_MAX_LEN(1), 0x000005ee },
168*3833Sxw161283 	{     REG_DEV_SETUP(1), 0x00000001 },
169*3833Sxw161283 	{    REG_TBI_CONFIG(1), 0x00000000 },
170*3833Sxw161283 	{     REG_DEV_SETUP(1), 0x00000046 },
171*3833Sxw161283 	{     REG_PAUSE_CFG(1), 0x00000000 },
172*3833Sxw161283 	{    REG_NORMALIZER(1), 0x00000064 },
173*3833Sxw161283 	{        REG_DENORM(1), 0x00000010 },
174*3833Sxw161283     },
175*3833Sxw161283     {	/* Port 2 */
176*3833Sxw161283     		/* FIFO setup */
177*3833Sxw161283 	{        REG_TEST(0,2), 0x00000002 },
178*3833Sxw161283 	{        REG_TEST(1,2), 0x00000002 },
179*3833Sxw161283 	{  REG_TOP_BOTTOM(0,2), 0x00100000 },
180*3833Sxw161283 	{  REG_TOP_BOTTOM(1,2), 0x00100000 },
181*3833Sxw161283 	{ REG_HIGH_LOW_WM(0,2), 0x0fff0fff },
182*3833Sxw161283 	{ REG_HIGH_LOW_WM(1,2), 0x0fff0fff },
183*3833Sxw161283 	{   REG_CT_THRHLD(0,2), 0x00000000 },
184*3833Sxw161283 	{   REG_CT_THRHLD(1,2), 0x00000000 },
185*3833Sxw161283 	{        REG_TEST(0,2), 0x00000000 },
186*3833Sxw161283 	{        REG_TEST(1,2), 0x00000000 },
187*3833Sxw161283 		/* Port config */
188*3833Sxw161283 	{      REG_MODE_CFG(2), 0x0000054c },
189*3833Sxw161283 	{       REG_MAX_LEN(2), 0x000005ee },
190*3833Sxw161283 	{     REG_DEV_SETUP(2), 0x00000001 },
191*3833Sxw161283 	{    REG_TBI_CONFIG(2), 0x00000000 },
192*3833Sxw161283 	{     REG_DEV_SETUP(2), 0x00000046 },
193*3833Sxw161283 	{     REG_PAUSE_CFG(2), 0x00000000 },
194*3833Sxw161283 	{    REG_NORMALIZER(2), 0x00000064 },
195*3833Sxw161283 	{        REG_DENORM(2), 0x00000010 },
196*3833Sxw161283     },
197*3833Sxw161283     {	/* Port 3 */
198*3833Sxw161283     		/* FIFO setup */
199*3833Sxw161283 	{        REG_TEST(0,3), 0x00000002 },
200*3833Sxw161283 	{        REG_TEST(1,3), 0x00000002 },
201*3833Sxw161283 	{  REG_TOP_BOTTOM(0,3), 0x00100000 },
202*3833Sxw161283 	{  REG_TOP_BOTTOM(1,3), 0x00100000 },
203*3833Sxw161283 	{ REG_HIGH_LOW_WM(0,3), 0x0fff0fff },
204*3833Sxw161283 	{ REG_HIGH_LOW_WM(1,3), 0x0fff0fff },
205*3833Sxw161283 	{   REG_CT_THRHLD(0,3), 0x00000000 },
206*3833Sxw161283 	{   REG_CT_THRHLD(1,3), 0x00000000 },
207*3833Sxw161283 	{        REG_TEST(0,3), 0x00000000 },
208*3833Sxw161283 	{        REG_TEST(1,3), 0x00000000 },
209*3833Sxw161283 		/* Port config */
210*3833Sxw161283 	{      REG_MODE_CFG(3), 0x0000054c },
211*3833Sxw161283 	{       REG_MAX_LEN(3), 0x000005ee },
212*3833Sxw161283 	{     REG_DEV_SETUP(3), 0x00000001 },
213*3833Sxw161283 	{    REG_TBI_CONFIG(3), 0x00000000 },
214*3833Sxw161283 	{     REG_DEV_SETUP(3), 0x00000046 },
215*3833Sxw161283 	{     REG_PAUSE_CFG(3), 0x00000000 },
216*3833Sxw161283 	{    REG_NORMALIZER(3), 0x00000064 },
217*3833Sxw161283 	{        REG_DENORM(3), 0x00000010 },
218*3833Sxw161283     },
219*3833Sxw161283 };
220*3833Sxw161283 
run_table(adapter_t * adapter,struct init_table * ib,int len)221*3833Sxw161283 static void run_table(adapter_t *adapter, struct init_table *ib, int len)
222*3833Sxw161283 {
223*3833Sxw161283 	int i;
224*3833Sxw161283 
225*3833Sxw161283 	for (i = 0; i < len; i++) {
226*3833Sxw161283 		if (ib[i].addr == INITBLOCK_SLEEP) {
227*3833Sxw161283 			DELAY_US( ib[i].data );
228*3833Sxw161283 		} else {
229*3833Sxw161283 			vsc_write( adapter, ib[i].addr, ib[i].data );
230*3833Sxw161283 		}
231*3833Sxw161283 	}
232*3833Sxw161283 }
233*3833Sxw161283 
234*3833Sxw161283 /* ARGSUSED */
vsc7321_mac_reset(adapter_t * adapter)235*3833Sxw161283 static int vsc7321_mac_reset(adapter_t *adapter)
236*3833Sxw161283 {
237*3833Sxw161283 	return 0;
238*3833Sxw161283 }
239*3833Sxw161283 
vsc7321_mac_create(adapter_t * adapter,int index)240*3833Sxw161283 static struct cmac *vsc7321_mac_create(adapter_t *adapter, int index)
241*3833Sxw161283 {
242*3833Sxw161283 	struct cmac *mac;
243*3833Sxw161283 	u32 val;
244*3833Sxw161283 	int i;
245*3833Sxw161283 
246*3833Sxw161283 	mac = t1_os_malloc_wait_zero(sizeof(*mac) + sizeof(cmac_instance));
247*3833Sxw161283 	if (!mac) return NULL;
248*3833Sxw161283 
249*3833Sxw161283 	mac->ops = &vsc7321_ops;
250*3833Sxw161283 	mac->instance = (cmac_instance *)(mac + 1);
251*3833Sxw161283 
252*3833Sxw161283 	mac->adapter   = adapter;
253*3833Sxw161283 	mac->instance->index = index;
254*3833Sxw161283 
255*3833Sxw161283 
256*3833Sxw161283 	vsc7321_full_reset(adapter);
257*3833Sxw161283 
258*3833Sxw161283 	i = 0;
259*3833Sxw161283 	do {
260*3833Sxw161283 		u32 vhi, vlo;
261*3833Sxw161283 
262*3833Sxw161283 		vhi = vlo = 0;
263*3833Sxw161283 		(void) t1_tpi_read(adapter, (REG_LOCAL_STATUS << 2) + 4, &vlo);
264*3833Sxw161283 		DELAY_US(1);
265*3833Sxw161283 		(void) t1_tpi_read(adapter, REG_LOCAL_STATUS << 2, &vhi);
266*3833Sxw161283 		DELAY_US(5);
267*3833Sxw161283 		val = (vhi << 16) | vlo;
268*3833Sxw161283 	} while ((++i < 10000) && (val == 0xffffffff));
269*3833Sxw161283 
270*3833Sxw161283 
271*3833Sxw161283 	vsc_read(adapter, REG_CHIP_ID, &val);
272*3833Sxw161283 
273*3833Sxw161283 	if ((val & 0xfff0ffff) != 0x0F407321) {
274*3833Sxw161283 		CH_ERR("%s: Didn't find a VSC 7321.\n", adapter_name(adapter));
275*3833Sxw161283 		t1_os_free((void *)mac, sizeof(*mac) + sizeof(cmac_instance));
276*3833Sxw161283 		return NULL;
277*3833Sxw161283 	}
278*3833Sxw161283 
279*3833Sxw161283 	mac->instance->version = (val >> 16) & 0xf;
280*3833Sxw161283 
281*3833Sxw161283 	run_table(adapter, vsc7321_reset, DIMOF(vsc7321_reset));
282*3833Sxw161283 	return mac;
283*3833Sxw161283 }
284*3833Sxw161283 
285*3833Sxw161283 /* ARGSUSED */
mac_intr_handler(struct cmac * mac)286*3833Sxw161283 static int mac_intr_handler(struct cmac *mac)
287*3833Sxw161283 {
288*3833Sxw161283 	return 0;
289*3833Sxw161283 }
290*3833Sxw161283 
291*3833Sxw161283 /* ARGSUSED */
mac_intr_enable(struct cmac * mac)292*3833Sxw161283 static int mac_intr_enable(struct cmac *mac)
293*3833Sxw161283 {
294*3833Sxw161283 	return 0;
295*3833Sxw161283 }
296*3833Sxw161283 
297*3833Sxw161283 /* ARGSUSED */
mac_intr_disable(struct cmac * mac)298*3833Sxw161283 static int mac_intr_disable(struct cmac *mac)
299*3833Sxw161283 {
300*3833Sxw161283 	return 0;
301*3833Sxw161283 }
302*3833Sxw161283 
303*3833Sxw161283 /* ARGSUSED */
mac_intr_clear(struct cmac * mac)304*3833Sxw161283 static int mac_intr_clear(struct cmac *mac)
305*3833Sxw161283 {
306*3833Sxw161283     /* Nothing extra needed */
307*3833Sxw161283     return 0;
308*3833Sxw161283 }
309*3833Sxw161283 
310*3833Sxw161283 /* Expect MAC address to be in network byte order. */
mac_set_address(struct cmac * mac,u8 addr[6])311*3833Sxw161283 static int mac_set_address(struct cmac* mac, u8 addr[6])
312*3833Sxw161283 {
313*3833Sxw161283 	u32 addr_lo, addr_hi;
314*3833Sxw161283 	int port = mac->instance->index;
315*3833Sxw161283 
316*3833Sxw161283 	addr_lo = addr[3];
317*3833Sxw161283 	addr_lo = (addr_lo << 8) | addr[4];
318*3833Sxw161283 	addr_lo = (addr_lo << 8) | addr[5];
319*3833Sxw161283 
320*3833Sxw161283 	addr_hi = addr[0];
321*3833Sxw161283 	addr_hi = (addr_hi << 8) | addr[1];
322*3833Sxw161283 	addr_hi = (addr_hi << 8) | addr[2];
323*3833Sxw161283 
324*3833Sxw161283 	vsc_write(mac->adapter, REG_MAC_LOW_ADDR(port), addr_lo);
325*3833Sxw161283 	vsc_write(mac->adapter, REG_MAC_HIGH_ADDR(port), addr_hi);
326*3833Sxw161283 	return 0;
327*3833Sxw161283 }
328*3833Sxw161283 
mac_get_address(struct cmac * mac,u8 addr[6])329*3833Sxw161283 static int mac_get_address(struct cmac *mac, u8 addr[6])
330*3833Sxw161283 {
331*3833Sxw161283 	u32 addr_lo, addr_hi;
332*3833Sxw161283 	int port = mac->instance->index;
333*3833Sxw161283 
334*3833Sxw161283 	vsc_read(mac->adapter, REG_MAC_LOW_ADDR(port), &addr_lo);
335*3833Sxw161283 	vsc_read(mac->adapter, REG_MAC_HIGH_ADDR(port), &addr_hi);
336*3833Sxw161283 
337*3833Sxw161283 	addr[0] = (u8) (addr_hi >> 16);
338*3833Sxw161283 	addr[1] = (u8) (addr_hi >> 8);
339*3833Sxw161283 	addr[2] = (u8) addr_hi;
340*3833Sxw161283 	addr[3] = (u8) (addr_lo >> 16);
341*3833Sxw161283 	addr[4] = (u8) (addr_lo >> 8);
342*3833Sxw161283 	addr[5] = (u8) addr_lo;
343*3833Sxw161283 	return 0;
344*3833Sxw161283 }
345*3833Sxw161283 
346*3833Sxw161283 /* This is intended to reset a port, not the whole MAC */
mac_reset(struct cmac * mac)347*3833Sxw161283 static int mac_reset(struct cmac *mac)
348*3833Sxw161283 {
349*3833Sxw161283 	int index = mac->instance->index;
350*3833Sxw161283 
351*3833Sxw161283 	run_table(mac->adapter, vsc7321_portinit[index],
352*3833Sxw161283 		  DIMOF(vsc7321_portinit[index]));
353*3833Sxw161283 	return 0;
354*3833Sxw161283 }
355*3833Sxw161283 
356*3833Sxw161283 /* ARGSUSED */
mac_set_rx_mode(struct cmac * mac,struct t1_rx_mode * rm)357*3833Sxw161283 static int mac_set_rx_mode(struct cmac *mac, struct t1_rx_mode *rm)
358*3833Sxw161283 {
359*3833Sxw161283 	/* Meigs II is always promiscuous. */
360*3833Sxw161283 	return 0;
361*3833Sxw161283 }
362*3833Sxw161283 
363*3833Sxw161283 /* ARGSUSED */
mac_set_mtu(struct cmac * mac,int mtu)364*3833Sxw161283 static int mac_set_mtu(struct cmac *mac, int mtu)
365*3833Sxw161283 {
366*3833Sxw161283 	return 0;
367*3833Sxw161283 }
368*3833Sxw161283 
369*3833Sxw161283 /* ARGSUSED */
mac_set_speed_duplex_fc(struct cmac * mac,int speed,int duplex,int fc)370*3833Sxw161283 static int mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex,
371*3833Sxw161283 				   int fc)
372*3833Sxw161283 {
373*3833Sxw161283         /* XXX Fixme */
374*3833Sxw161283 	return 0;
375*3833Sxw161283 }
376*3833Sxw161283 
mac_enable(struct cmac * mac,int which)377*3833Sxw161283 static int mac_enable(struct cmac *mac, int which)
378*3833Sxw161283 {
379*3833Sxw161283 	u32 val;
380*3833Sxw161283 	int port = mac->instance->index;
381*3833Sxw161283 
382*3833Sxw161283 	vsc_read(mac->adapter, REG_MODE_CFG(port), &val);
383*3833Sxw161283 	if (which & MAC_DIRECTION_RX)
384*3833Sxw161283 		val |= 0x2;
385*3833Sxw161283 	if (which & MAC_DIRECTION_TX)
386*3833Sxw161283 		val |= 1;
387*3833Sxw161283 	vsc_write(mac->adapter, REG_MODE_CFG(port), val);
388*3833Sxw161283 	return 0;
389*3833Sxw161283 }
390*3833Sxw161283 
mac_disable(struct cmac * mac,int which)391*3833Sxw161283 static int mac_disable(struct cmac *mac, int which)
392*3833Sxw161283 {
393*3833Sxw161283 	u32 val;
394*3833Sxw161283 	int port = mac->instance->index;
395*3833Sxw161283 
396*3833Sxw161283 	vsc_read(mac->adapter, REG_MODE_CFG(port), &val);
397*3833Sxw161283 	if (which & MAC_DIRECTION_RX)
398*3833Sxw161283 		val &= ~0x2;
399*3833Sxw161283 	if (which & MAC_DIRECTION_TX)
400*3833Sxw161283 		val &= ~0x1;
401*3833Sxw161283 	vsc_write(mac->adapter, REG_MODE_CFG(port), val);
402*3833Sxw161283 	return 0;
403*3833Sxw161283 }
404*3833Sxw161283 
405*3833Sxw161283 #if 0
406*3833Sxw161283 /* TBD XXX cmac interface stats will need to assigned to Chelsio's
407*3833Sxw161283  *         mac stats.  cmac stats is now just usings Chelsio's
408*3833Sxw161283  *         so we don't need the conversion.
409*3833Sxw161283  */
410*3833Sxw161283 int mac_get_statistics(struct cmac* mac, struct cmac_statistics* ps)
411*3833Sxw161283 {
412*3833Sxw161283     port_stats_update(mac);
413*3833Sxw161283     return 0;
414*3833Sxw161283 }
415*3833Sxw161283 #endif
416*3833Sxw161283 
417*3833Sxw161283 /* ARGSUSED */
mac_update_statistics(struct cmac * mac,int flag)418*3833Sxw161283 static const struct cmac_statistics *mac_update_statistics(struct cmac *mac,
419*3833Sxw161283 							   int flag)
420*3833Sxw161283 {
421*3833Sxw161283 	return &mac->stats;
422*3833Sxw161283 }
423*3833Sxw161283 
mac_destroy(struct cmac * mac)424*3833Sxw161283 static void mac_destroy(struct cmac *mac)
425*3833Sxw161283 {
426*3833Sxw161283 	t1_os_free((void *)mac, sizeof(*mac) + sizeof(cmac_instance));
427*3833Sxw161283 }
428*3833Sxw161283 
429*3833Sxw161283 #ifdef C99_NOT_SUPPORTED
430*3833Sxw161283 static struct cmac_ops vsc7321_ops = {
431*3833Sxw161283 	mac_destroy,
432*3833Sxw161283 	mac_reset,
433*3833Sxw161283 	mac_intr_enable,
434*3833Sxw161283 	mac_intr_disable,
435*3833Sxw161283 	mac_intr_clear,
436*3833Sxw161283 	mac_intr_handler,
437*3833Sxw161283 	mac_enable,
438*3833Sxw161283 	mac_disable,
439*3833Sxw161283 	NULL,
440*3833Sxw161283 	NULL,
441*3833Sxw161283 	mac_set_mtu,
442*3833Sxw161283 	mac_set_rx_mode,
443*3833Sxw161283 	mac_set_speed_duplex_fc,
444*3833Sxw161283 	NULL,
445*3833Sxw161283 	mac_update_statistics,
446*3833Sxw161283 	mac_get_address,
447*3833Sxw161283 	mac_set_address
448*3833Sxw161283 };
449*3833Sxw161283 #else
450*3833Sxw161283 static struct cmac_ops vsc7321_ops = {
451*3833Sxw161283 	.destroy                  = mac_destroy,
452*3833Sxw161283 	.reset                    = mac_reset,
453*3833Sxw161283 	.interrupt_handler        = mac_intr_handler,
454*3833Sxw161283 	.interrupt_enable         = mac_intr_enable,
455*3833Sxw161283 	.interrupt_disable        = mac_intr_disable,
456*3833Sxw161283 	.interrupt_clear          = mac_intr_clear,
457*3833Sxw161283 	.enable                   = mac_enable,
458*3833Sxw161283 	.disable                  = mac_disable,
459*3833Sxw161283 	.set_mtu                  = mac_set_mtu,
460*3833Sxw161283 	.set_rx_mode              = mac_set_rx_mode,
461*3833Sxw161283 	.set_speed_duplex_fc      = mac_set_speed_duplex_fc,
462*3833Sxw161283 	.statistics_update        = mac_update_statistics,
463*3833Sxw161283 	.macaddress_get           = mac_get_address,
464*3833Sxw161283 	.macaddress_set           = mac_set_address,
465*3833Sxw161283 };
466*3833Sxw161283 #endif
467*3833Sxw161283 
468*3833Sxw161283 struct gmac t1_vsc7321_ops = {
469*3833Sxw161283 	0,
470*3833Sxw161283 	vsc7321_mac_create,
471*3833Sxw161283 	vsc7321_mac_reset
472*3833Sxw161283 };
473