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