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" /* ixf1010.c */
27*3833Sxw161283
28*3833Sxw161283 #include "gmac.h"
29*3833Sxw161283 #include "elmer0.h"
30*3833Sxw161283
31*3833Sxw161283 /* Update fast changing statistics every 15 seconds */
32*3833Sxw161283 #define STATS_TICK_SECS 15
33*3833Sxw161283 /* 30 minutes for full statistics update */
34*3833Sxw161283 #define MAJOR_UPDATE_TICKS (1800 / STATS_TICK_SECS)
35*3833Sxw161283
36*3833Sxw161283 /*
37*3833Sxw161283 * The IXF1010 can handle frames up to 16383 bytes but it's optimized for
38*3833Sxw161283 * frames up to 9831 (0x2667) bytes, so we limit jumbo frame size to this.
39*3833Sxw161283 * This length includes ethernet header and FCS.
40*3833Sxw161283 */
41*3833Sxw161283 #define MAX_FRAME_SIZE 0x2667
42*3833Sxw161283
43*3833Sxw161283 /* MAC registers */
44*3833Sxw161283 enum {
45*3833Sxw161283 /* Per-port registers */
46*3833Sxw161283 REG_MACADDR_LOW = 0,
47*3833Sxw161283 REG_MACADDR_HIGH = 0x4,
48*3833Sxw161283 REG_FDFC_TYPE = 0xC,
49*3833Sxw161283 REG_FC_TX_TIMER_VALUE = 0x1c,
50*3833Sxw161283 REG_IPG_RX_TIME1 = 0x28,
51*3833Sxw161283 REG_IPG_RX_TIME2 = 0x2c,
52*3833Sxw161283 REG_IPG_TX_TIME = 0x30,
53*3833Sxw161283 REG_PAUSE_THRES = 0x38,
54*3833Sxw161283 REG_MAX_FRAME_SIZE = 0x3c,
55*3833Sxw161283 REG_RGMII_SPEED = 0x40,
56*3833Sxw161283 REG_FC_ENABLE = 0x48,
57*3833Sxw161283 REG_DISCARD_CTRL_FRAMES = 0x54,
58*3833Sxw161283 REG_DIVERSE_CONFIG = 0x60,
59*3833Sxw161283 REG_RX_FILTER = 0x64,
60*3833Sxw161283 REG_MC_ADDR_LOW = 0x68,
61*3833Sxw161283 REG_MC_ADDR_HIGH = 0x6c,
62*3833Sxw161283
63*3833Sxw161283 REG_RX_OCTETS_OK = 0x80,
64*3833Sxw161283 REG_RX_OCTETS_BAD = 0x84,
65*3833Sxw161283 REG_RX_UC_PKTS = 0x88,
66*3833Sxw161283 REG_RX_MC_PKTS = 0x8c,
67*3833Sxw161283 REG_RX_BC_PKTS = 0x90,
68*3833Sxw161283 REG_RX_FCS_ERR = 0xb0,
69*3833Sxw161283 REG_RX_TAGGED = 0xb4,
70*3833Sxw161283 REG_RX_DATA_ERR = 0xb8,
71*3833Sxw161283 REG_RX_ALIGN_ERR = 0xbc,
72*3833Sxw161283 REG_RX_LONG_ERR = 0xc0,
73*3833Sxw161283 REG_RX_JABBER_ERR = 0xc4,
74*3833Sxw161283 REG_RX_PAUSE_FRAMES = 0xc8,
75*3833Sxw161283 REG_RX_UNKNOWN_CTRL_FRAMES = 0xcc,
76*3833Sxw161283 REG_RX_VERY_LONG_ERR = 0xd0,
77*3833Sxw161283 REG_RX_RUNT_ERR = 0xd4,
78*3833Sxw161283 REG_RX_SHORT_ERR = 0xd8,
79*3833Sxw161283 REG_RX_SYMBOL_ERR = 0xe4,
80*3833Sxw161283
81*3833Sxw161283 REG_TX_OCTETS_OK = 0x100,
82*3833Sxw161283 REG_TX_OCTETS_BAD = 0x104,
83*3833Sxw161283 REG_TX_UC_PKTS = 0x108,
84*3833Sxw161283 REG_TX_MC_PKTS = 0x10c,
85*3833Sxw161283 REG_TX_BC_PKTS = 0x110,
86*3833Sxw161283 REG_TX_EXCESSIVE_LEN_DROP = 0x14c,
87*3833Sxw161283 REG_TX_UNDERRUN = 0x150,
88*3833Sxw161283 REG_TX_TAGGED = 0x154,
89*3833Sxw161283 REG_TX_PAUSE_FRAMES = 0x15C,
90*3833Sxw161283
91*3833Sxw161283 /* Global registers */
92*3833Sxw161283 REG_PORT_ENABLE = 0x1400,
93*3833Sxw161283
94*3833Sxw161283 REG_JTAG_ID = 0x1430,
95*3833Sxw161283
96*3833Sxw161283 RX_FIFO_HIGH_WATERMARK_BASE = 0x1600,
97*3833Sxw161283 RX_FIFO_LOW_WATERMARK_BASE = 0x1628,
98*3833Sxw161283 RX_FIFO_FRAMES_REMOVED_BASE = 0x1650,
99*3833Sxw161283
100*3833Sxw161283 REG_RX_ERR_DROP = 0x167c,
101*3833Sxw161283 REG_RX_FIFO_OVERFLOW_EVENT = 0x1680,
102*3833Sxw161283
103*3833Sxw161283 TX_FIFO_HIGH_WATERMARK_BASE = 0x1800,
104*3833Sxw161283 TX_FIFO_LOW_WATERMARK_BASE = 0x1828,
105*3833Sxw161283 TX_FIFO_XFER_THRES_BASE = 0x1850,
106*3833Sxw161283
107*3833Sxw161283 REG_TX_FIFO_OVERFLOW_EVENT = 0x1878,
108*3833Sxw161283 REG_TX_FIFO_OOS_EVENT = 0x1884,
109*3833Sxw161283
110*3833Sxw161283 TX_FIFO_FRAMES_REMOVED_BASE = 0x1888,
111*3833Sxw161283
112*3833Sxw161283 REG_SPI_RX_BURST = 0x1c00,
113*3833Sxw161283 REG_SPI_RX_TRAINING = 0x1c04,
114*3833Sxw161283 REG_SPI_RX_CALENDAR = 0x1c08,
115*3833Sxw161283 REG_SPI_TX_SYNC = 0x1c0c
116*3833Sxw161283 };
117*3833Sxw161283
118*3833Sxw161283 enum { /* RMON registers */
119*3833Sxw161283 REG_RxOctetsTotalOK = 0x80,
120*3833Sxw161283 REG_RxOctetsBad = 0x84,
121*3833Sxw161283 REG_RxUCPkts = 0x88,
122*3833Sxw161283 REG_RxMCPkts = 0x8c,
123*3833Sxw161283 REG_RxBCPkts = 0x90,
124*3833Sxw161283 REG_RxJumboPkts = 0xac,
125*3833Sxw161283 REG_RxFCSErrors = 0xb0,
126*3833Sxw161283 REG_RxDataErrors = 0xb8,
127*3833Sxw161283 REG_RxAlignErrors = 0xbc,
128*3833Sxw161283 REG_RxLongErrors = 0xc0,
129*3833Sxw161283 REG_RxJabberErrors = 0xc4,
130*3833Sxw161283 REG_RxPauseMacControlCounter = 0xc8,
131*3833Sxw161283 REG_RxVeryLongErrors = 0xd0,
132*3833Sxw161283 REG_RxRuntErrors = 0xd4,
133*3833Sxw161283 REG_RxShortErrors = 0xd8,
134*3833Sxw161283 REG_RxSequenceErrors = 0xe0,
135*3833Sxw161283 REG_RxSymbolErrors = 0xe4,
136*3833Sxw161283
137*3833Sxw161283 REG_TxOctetsTotalOK = 0x100,
138*3833Sxw161283 REG_TxOctetsBad = 0x104,
139*3833Sxw161283 REG_TxUCPkts = 0x108,
140*3833Sxw161283 REG_TxMCPkts = 0x10c,
141*3833Sxw161283 REG_TxBCPkts = 0x110,
142*3833Sxw161283 REG_TxJumboPkts = 0x12C,
143*3833Sxw161283 REG_TxTotalCollisions = 0x134,
144*3833Sxw161283 REG_TxExcessiveLengthDrop = 0x14c,
145*3833Sxw161283 REG_TxUnderrun = 0x150,
146*3833Sxw161283 REG_TxCRCErrors = 0x158,
147*3833Sxw161283 REG_TxPauseFrames = 0x15c
148*3833Sxw161283 };
149*3833Sxw161283
150*3833Sxw161283 enum {
151*3833Sxw161283 DIVERSE_CONFIG_PAD_ENABLE = 0x80,
152*3833Sxw161283 DIVERSE_CONFIG_CRC_ADD = 0x40
153*3833Sxw161283 };
154*3833Sxw161283
155*3833Sxw161283 #define MACREG_BASE 0
156*3833Sxw161283 #define MACREG(mac, mac_reg) ((mac)->instance->mac_base + (mac_reg))
157*3833Sxw161283
158*3833Sxw161283 struct _cmac_instance {
159*3833Sxw161283 u32 mac_base;
160*3833Sxw161283 u32 index;
161*3833Sxw161283 u32 version;
162*3833Sxw161283 u32 ticks;
163*3833Sxw161283 };
164*3833Sxw161283
disable_port(struct cmac * mac)165*3833Sxw161283 static void disable_port(struct cmac *mac)
166*3833Sxw161283 {
167*3833Sxw161283 u32 val;
168*3833Sxw161283
169*3833Sxw161283 (void) t1_tpi_read(mac->adapter, REG_PORT_ENABLE, &val);
170*3833Sxw161283 val &= ~(1 << mac->instance->index);
171*3833Sxw161283 (void) t1_tpi_write(mac->adapter, REG_PORT_ENABLE, val);
172*3833Sxw161283 }
173*3833Sxw161283
174*3833Sxw161283 #define RMON_UPDATE(mac, name, stat_name) \
175*3833Sxw161283 (void) t1_tpi_read((mac)->adapter, MACREG(mac, REG_##name), &val); \
176*3833Sxw161283 (mac)->stats.stat_name += val;
177*3833Sxw161283
178*3833Sxw161283 /*
179*3833Sxw161283 * Read the current values of the RMON counters and add them to the cumulative
180*3833Sxw161283 * port statistics. The HW RMON counters are cleared by this operation.
181*3833Sxw161283 */
port_stats_update(struct cmac * mac)182*3833Sxw161283 static void port_stats_update(struct cmac *mac)
183*3833Sxw161283 {
184*3833Sxw161283 u32 val;
185*3833Sxw161283
186*3833Sxw161283 /* Rx stats */
187*3833Sxw161283 RMON_UPDATE(mac, RxOctetsTotalOK, RxOctetsOK);
188*3833Sxw161283 RMON_UPDATE(mac, RxOctetsBad, RxOctetsBad);
189*3833Sxw161283 RMON_UPDATE(mac, RxUCPkts, RxUnicastFramesOK);
190*3833Sxw161283 RMON_UPDATE(mac, RxMCPkts, RxMulticastFramesOK);
191*3833Sxw161283 RMON_UPDATE(mac, RxBCPkts, RxBroadcastFramesOK);
192*3833Sxw161283 RMON_UPDATE(mac, RxJumboPkts, RxJumboFramesOK);
193*3833Sxw161283 RMON_UPDATE(mac, RxFCSErrors, RxFCSErrors);
194*3833Sxw161283 RMON_UPDATE(mac, RxAlignErrors, RxAlignErrors);
195*3833Sxw161283 RMON_UPDATE(mac, RxLongErrors, RxFrameTooLongErrors);
196*3833Sxw161283 RMON_UPDATE(mac, RxVeryLongErrors, RxFrameTooLongErrors);
197*3833Sxw161283 RMON_UPDATE(mac, RxPauseMacControlCounter, RxPauseFrames);
198*3833Sxw161283 RMON_UPDATE(mac, RxDataErrors, RxDataErrors);
199*3833Sxw161283 RMON_UPDATE(mac, RxJabberErrors, RxJabberErrors);
200*3833Sxw161283 RMON_UPDATE(mac, RxRuntErrors, RxRuntErrors);
201*3833Sxw161283 RMON_UPDATE(mac, RxShortErrors, RxRuntErrors);
202*3833Sxw161283 RMON_UPDATE(mac, RxSequenceErrors, RxSequenceErrors);
203*3833Sxw161283 RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
204*3833Sxw161283
205*3833Sxw161283 /* Tx stats (skip collision stats as we are full-duplex only) */
206*3833Sxw161283 RMON_UPDATE(mac, TxOctetsTotalOK, TxOctetsOK);
207*3833Sxw161283 RMON_UPDATE(mac, TxOctetsBad, TxOctetsBad);
208*3833Sxw161283 RMON_UPDATE(mac, TxUCPkts, TxUnicastFramesOK);
209*3833Sxw161283 RMON_UPDATE(mac, TxMCPkts, TxMulticastFramesOK);
210*3833Sxw161283 RMON_UPDATE(mac, TxBCPkts, TxBroadcastFramesOK);
211*3833Sxw161283 RMON_UPDATE(mac, TxJumboPkts, TxJumboFramesOK);
212*3833Sxw161283 RMON_UPDATE(mac, TxPauseFrames, TxPauseFrames);
213*3833Sxw161283 RMON_UPDATE(mac, TxExcessiveLengthDrop, TxLengthErrors);
214*3833Sxw161283 RMON_UPDATE(mac, TxUnderrun, TxUnderrun);
215*3833Sxw161283 RMON_UPDATE(mac, TxCRCErrors, TxFCSErrors);
216*3833Sxw161283 }
217*3833Sxw161283
218*3833Sxw161283 /* No-op interrupt operation as this MAC does not support interrupts */
219*3833Sxw161283 /* ARGSUSED */
mac_intr_op(struct cmac * mac)220*3833Sxw161283 static int mac_intr_op(struct cmac *mac)
221*3833Sxw161283 {
222*3833Sxw161283 return 0;
223*3833Sxw161283 }
224*3833Sxw161283
225*3833Sxw161283 /* Expect MAC address to be in network byte order. */
mac_set_address(struct cmac * mac,u8 addr[6])226*3833Sxw161283 static int mac_set_address(struct cmac *mac, u8 addr[6])
227*3833Sxw161283 {
228*3833Sxw161283 u32 addr_lo, addr_hi;
229*3833Sxw161283
230*3833Sxw161283 addr_lo = addr[2];
231*3833Sxw161283 addr_lo = (addr_lo << 8) | addr[3];
232*3833Sxw161283 addr_lo = (addr_lo << 8) | addr[4];
233*3833Sxw161283 addr_lo = (addr_lo << 8) | addr[5];
234*3833Sxw161283
235*3833Sxw161283 addr_hi = addr[0];
236*3833Sxw161283 addr_hi = (addr_hi << 8) | addr[1];
237*3833Sxw161283
238*3833Sxw161283 (void) t1_tpi_write(mac->adapter, MACREG(mac, REG_MACADDR_LOW), addr_lo);
239*3833Sxw161283 (void) t1_tpi_write(mac->adapter, MACREG(mac, REG_MACADDR_HIGH), addr_hi);
240*3833Sxw161283 return 0;
241*3833Sxw161283 }
242*3833Sxw161283
mac_get_address(struct cmac * mac,u8 addr[6])243*3833Sxw161283 static int mac_get_address(struct cmac *mac, u8 addr[6])
244*3833Sxw161283 {
245*3833Sxw161283 u32 addr_lo, addr_hi;
246*3833Sxw161283
247*3833Sxw161283 (void) t1_tpi_read(mac->adapter, MACREG(mac, REG_MACADDR_LOW), &addr_lo);
248*3833Sxw161283 (void) t1_tpi_read(mac->adapter, MACREG(mac, REG_MACADDR_HIGH), &addr_hi);
249*3833Sxw161283
250*3833Sxw161283 addr[0] = (u8) (addr_hi >> 8);
251*3833Sxw161283 addr[1] = (u8) addr_hi;
252*3833Sxw161283 addr[2] = (u8) (addr_lo >> 24);
253*3833Sxw161283 addr[3] = (u8) (addr_lo >> 16);
254*3833Sxw161283 addr[4] = (u8) (addr_lo >> 8);
255*3833Sxw161283 addr[5] = (u8) addr_lo;
256*3833Sxw161283 return 0;
257*3833Sxw161283 }
258*3833Sxw161283
259*3833Sxw161283 /* This is intended to reset a port, not the whole MAC */
260*3833Sxw161283 /* ARGSUSED */
mac_reset(struct cmac * mac)261*3833Sxw161283 static int mac_reset(struct cmac *mac)
262*3833Sxw161283 {
263*3833Sxw161283 return 0;
264*3833Sxw161283 }
265*3833Sxw161283
mac_set_rx_mode(struct cmac * mac,struct t1_rx_mode * rm)266*3833Sxw161283 static int mac_set_rx_mode(struct cmac *mac, struct t1_rx_mode *rm)
267*3833Sxw161283 {
268*3833Sxw161283 u32 val, new_mode;
269*3833Sxw161283 adapter_t *adapter = mac->adapter;
270*3833Sxw161283 u32 addr_lo, addr_hi;
271*3833Sxw161283 u8 *addr;
272*3833Sxw161283
273*3833Sxw161283 (void) t1_tpi_read(adapter, MACREG(mac, REG_RX_FILTER), &val);
274*3833Sxw161283 new_mode = val & ~7;
275*3833Sxw161283 if (!t1_rx_mode_promisc(rm) && mac->instance->version > 0)
276*3833Sxw161283 new_mode |= 1; /* only set if version > 0 due to erratum */
277*3833Sxw161283 if (!t1_rx_mode_promisc(rm) && !t1_rx_mode_allmulti(rm)
278*3833Sxw161283 && t1_rx_mode_mc_cnt(rm) <= 1)
279*3833Sxw161283 new_mode |= 2;
280*3833Sxw161283 if (new_mode != val)
281*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_RX_FILTER), new_mode);
282*3833Sxw161283 switch (t1_rx_mode_mc_cnt(rm)) {
283*3833Sxw161283 case 0:
284*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_MC_ADDR_LOW), 0);
285*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_MC_ADDR_HIGH), 0);
286*3833Sxw161283 break;
287*3833Sxw161283 case 1:
288*3833Sxw161283 addr = t1_get_next_mcaddr(rm);
289*3833Sxw161283 addr_lo = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) |
290*3833Sxw161283 addr[5];
291*3833Sxw161283 addr_hi = (addr[0] << 8) | addr[1];
292*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_MC_ADDR_LOW), addr_lo);
293*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_MC_ADDR_HIGH), addr_hi);
294*3833Sxw161283 break;
295*3833Sxw161283 default:
296*3833Sxw161283 break;
297*3833Sxw161283 }
298*3833Sxw161283 return 0;
299*3833Sxw161283 }
300*3833Sxw161283
mac_set_mtu(struct cmac * mac,int mtu)301*3833Sxw161283 static int mac_set_mtu(struct cmac *mac, int mtu)
302*3833Sxw161283 {
303*3833Sxw161283 /* MAX_FRAME_SIZE inludes header + FCS, mtu doesn't */
304*3833Sxw161283 if (mtu > (MAX_FRAME_SIZE - 14 - 4)) return -EINVAL;
305*3833Sxw161283 (void) t1_tpi_write(mac->adapter, MACREG(mac, REG_MAX_FRAME_SIZE),
306*3833Sxw161283 mtu + 14 + 4);
307*3833Sxw161283 return 0;
308*3833Sxw161283 }
309*3833Sxw161283
mac_set_speed_duplex_fc(struct cmac * mac,int speed,int duplex,int fc)310*3833Sxw161283 static int mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex,
311*3833Sxw161283 int fc)
312*3833Sxw161283 {
313*3833Sxw161283 u32 val;
314*3833Sxw161283
315*3833Sxw161283 if (speed >= 0 && speed != SPEED_100 && speed != SPEED_1000)
316*3833Sxw161283 return -1;
317*3833Sxw161283 if (duplex >= 0 && duplex != DUPLEX_FULL)
318*3833Sxw161283 return -1;
319*3833Sxw161283
320*3833Sxw161283 if (speed >= 0) {
321*3833Sxw161283 val = speed == SPEED_100 ? 1 : 2;
322*3833Sxw161283 (void) t1_tpi_write(mac->adapter, MACREG(mac, REG_RGMII_SPEED), val);
323*3833Sxw161283 }
324*3833Sxw161283
325*3833Sxw161283 (void) t1_tpi_read(mac->adapter, MACREG(mac, REG_FC_ENABLE), &val);
326*3833Sxw161283 val &= ~3;
327*3833Sxw161283 if (fc & PAUSE_RX)
328*3833Sxw161283 val |= 1;
329*3833Sxw161283 if (fc & PAUSE_TX)
330*3833Sxw161283 val |= 2;
331*3833Sxw161283 (void) t1_tpi_write(mac->adapter, MACREG(mac, REG_FC_ENABLE), val);
332*3833Sxw161283 return 0;
333*3833Sxw161283 }
334*3833Sxw161283
mac_get_speed_duplex_fc(struct cmac * mac,int * speed,int * duplex,int * fc)335*3833Sxw161283 static int mac_get_speed_duplex_fc(struct cmac *mac, int *speed, int *duplex,
336*3833Sxw161283 int *fc)
337*3833Sxw161283 {
338*3833Sxw161283 u32 val;
339*3833Sxw161283
340*3833Sxw161283 if (duplex)
341*3833Sxw161283 *duplex = DUPLEX_FULL;
342*3833Sxw161283 if (speed) {
343*3833Sxw161283 (void) t1_tpi_read(mac->adapter, MACREG(mac, REG_RGMII_SPEED),
344*3833Sxw161283 &val);
345*3833Sxw161283 *speed = (val & 2) ? SPEED_1000 : SPEED_100;
346*3833Sxw161283 }
347*3833Sxw161283 if (fc) {
348*3833Sxw161283 (void) t1_tpi_read(mac->adapter, MACREG(mac, REG_FC_ENABLE), &val);
349*3833Sxw161283 *fc = 0;
350*3833Sxw161283 if (val & 1)
351*3833Sxw161283 *fc |= PAUSE_RX;
352*3833Sxw161283 if (val & 2)
353*3833Sxw161283 *fc |= PAUSE_TX;
354*3833Sxw161283 }
355*3833Sxw161283 return 0;
356*3833Sxw161283 }
357*3833Sxw161283
enable_port(struct cmac * mac)358*3833Sxw161283 static void enable_port(struct cmac *mac)
359*3833Sxw161283 {
360*3833Sxw161283 u32 val;
361*3833Sxw161283 u32 index = mac->instance->index;
362*3833Sxw161283 adapter_t *adapter = mac->adapter;
363*3833Sxw161283
364*3833Sxw161283 (void) t1_tpi_read(adapter, MACREG(mac, REG_DIVERSE_CONFIG), &val);
365*3833Sxw161283 val |= DIVERSE_CONFIG_CRC_ADD | DIVERSE_CONFIG_PAD_ENABLE;
366*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_DIVERSE_CONFIG), val);
367*3833Sxw161283 if (mac->instance->version > 0)
368*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_RX_FILTER), 3);
369*3833Sxw161283 else /* Don't enable unicast address filtering due to IXF1010 bug */
370*3833Sxw161283 (void) t1_tpi_write(adapter, MACREG(mac, REG_RX_FILTER), 2);
371*3833Sxw161283
372*3833Sxw161283 (void) t1_tpi_read(adapter, REG_RX_ERR_DROP, &val);
373*3833Sxw161283 val |= (1 << index);
374*3833Sxw161283 (void) t1_tpi_write(adapter, REG_RX_ERR_DROP, val);
375*3833Sxw161283
376*3833Sxw161283 /*
377*3833Sxw161283 * Clear the port RMON registers by adding their current values to the
378*3833Sxw161283 * cumulatice port stats and then clearing the stats. Really.
379*3833Sxw161283 */
380*3833Sxw161283 port_stats_update(mac);
381*3833Sxw161283 (void) memset(&mac->stats, 0, sizeof(struct cmac_statistics));
382*3833Sxw161283 mac->instance->ticks = 0;
383*3833Sxw161283
384*3833Sxw161283 (void) t1_tpi_read(adapter, REG_PORT_ENABLE, &val);
385*3833Sxw161283 val |= (1 << index);
386*3833Sxw161283 (void) t1_tpi_write(adapter, REG_PORT_ENABLE, val);
387*3833Sxw161283
388*3833Sxw161283 index <<= 2;
389*3833Sxw161283 if (is_T2(adapter)) {
390*3833Sxw161283 /* T204: set the Fifo water level & threshold */
391*3833Sxw161283 if (index) index <<= 2;
392*3833Sxw161283 (void) t1_tpi_write(adapter, RX_FIFO_HIGH_WATERMARK_BASE + index, 0x740);
393*3833Sxw161283 (void) t1_tpi_write(adapter, RX_FIFO_LOW_WATERMARK_BASE + index, 0x730);
394*3833Sxw161283 (void) t1_tpi_write(adapter, TX_FIFO_HIGH_WATERMARK_BASE + index, 0x600);
395*3833Sxw161283 (void) t1_tpi_write(adapter, TX_FIFO_LOW_WATERMARK_BASE + index, 0x1d0);
396*3833Sxw161283 (void) t1_tpi_write(adapter, TX_FIFO_XFER_THRES_BASE + index, 0x1100);
397*3833Sxw161283 } else {
398*3833Sxw161283 /*
399*3833Sxw161283 * Set the TX Fifo Threshold to 0x400 instead of 0x100 to work around
400*3833Sxw161283 * Underrun problem. Intel has blessed this solution.
401*3833Sxw161283 */
402*3833Sxw161283 (void) t1_tpi_write(adapter,
403*3833Sxw161283 TX_FIFO_XFER_THRES_BASE + mac->instance->index * 4, 0x400);
404*3833Sxw161283 }
405*3833Sxw161283 }
406*3833Sxw161283
407*3833Sxw161283 /* IXF1010 ports do not have separate enables for TX and RX */
mac_enable(struct cmac * mac,int which)408*3833Sxw161283 static int mac_enable(struct cmac *mac, int which)
409*3833Sxw161283 {
410*3833Sxw161283 if (which & (MAC_DIRECTION_RX | MAC_DIRECTION_TX))
411*3833Sxw161283 enable_port(mac);
412*3833Sxw161283 return 0;
413*3833Sxw161283 }
414*3833Sxw161283
mac_disable(struct cmac * mac,int which)415*3833Sxw161283 static int mac_disable(struct cmac *mac, int which)
416*3833Sxw161283 {
417*3833Sxw161283 if (which & (MAC_DIRECTION_RX | MAC_DIRECTION_TX))
418*3833Sxw161283 disable_port(mac);
419*3833Sxw161283 return 0;
420*3833Sxw161283 }
421*3833Sxw161283
422*3833Sxw161283 /*
423*3833Sxw161283 * This function is called periodically to accumulate the current values of the
424*3833Sxw161283 * RMON counters into the port statistics. Since the counters are only 32 bits
425*3833Sxw161283 * some of them can overflow in less than a minute at GigE speeds, so this
426*3833Sxw161283 * function should be called every 30 seconds or so.
427*3833Sxw161283 *
428*3833Sxw161283 * To cut down on reading costs we update only the octet counters at each tick
429*3833Sxw161283 * and do a full update at major ticks, which can be every 30 minutes or more.
430*3833Sxw161283 */
mac_update_statistics(struct cmac * mac,int flag)431*3833Sxw161283 static const struct cmac_statistics *mac_update_statistics(struct cmac *mac,
432*3833Sxw161283 int flag)
433*3833Sxw161283 {
434*3833Sxw161283 if (flag == MAC_STATS_UPDATE_FULL ||
435*3833Sxw161283 MAJOR_UPDATE_TICKS <= mac->instance->ticks) {
436*3833Sxw161283 port_stats_update(mac);
437*3833Sxw161283 mac->instance->ticks = 0;
438*3833Sxw161283 } else {
439*3833Sxw161283 u32 val;
440*3833Sxw161283
441*3833Sxw161283 RMON_UPDATE(mac, RxOctetsTotalOK, RxOctetsOK);
442*3833Sxw161283 RMON_UPDATE(mac, TxOctetsTotalOK, TxOctetsOK);
443*3833Sxw161283 mac->instance->ticks++;
444*3833Sxw161283 }
445*3833Sxw161283 return &mac->stats;
446*3833Sxw161283 }
447*3833Sxw161283
mac_destroy(struct cmac * mac)448*3833Sxw161283 static void mac_destroy(struct cmac *mac)
449*3833Sxw161283 {
450*3833Sxw161283 t1_os_free((void *)mac, sizeof(*mac) + sizeof(cmac_instance));
451*3833Sxw161283 }
452*3833Sxw161283
453*3833Sxw161283 #ifdef C99_NOT_SUPPORTED
454*3833Sxw161283 static struct cmac_ops ixf1010_ops = {
455*3833Sxw161283 mac_destroy,
456*3833Sxw161283 mac_reset,
457*3833Sxw161283 mac_intr_op,
458*3833Sxw161283 mac_intr_op,
459*3833Sxw161283 mac_intr_op,
460*3833Sxw161283 NULL,
461*3833Sxw161283 mac_enable,
462*3833Sxw161283 mac_disable,
463*3833Sxw161283 NULL,
464*3833Sxw161283 NULL,
465*3833Sxw161283 mac_set_mtu,
466*3833Sxw161283 mac_set_rx_mode,
467*3833Sxw161283 mac_set_speed_duplex_fc,
468*3833Sxw161283 mac_get_speed_duplex_fc,
469*3833Sxw161283 mac_update_statistics,
470*3833Sxw161283 mac_get_address,
471*3833Sxw161283 mac_set_address
472*3833Sxw161283 };
473*3833Sxw161283 #else
474*3833Sxw161283 static struct cmac_ops ixf1010_ops = {
475*3833Sxw161283 .destroy = mac_destroy,
476*3833Sxw161283 .reset = mac_reset,
477*3833Sxw161283 .interrupt_enable = mac_intr_op,
478*3833Sxw161283 .interrupt_disable = mac_intr_op,
479*3833Sxw161283 .interrupt_clear = mac_intr_op,
480*3833Sxw161283 .enable = mac_enable,
481*3833Sxw161283 .disable = mac_disable,
482*3833Sxw161283 .set_mtu = mac_set_mtu,
483*3833Sxw161283 .set_rx_mode = mac_set_rx_mode,
484*3833Sxw161283 .set_speed_duplex_fc = mac_set_speed_duplex_fc,
485*3833Sxw161283 .get_speed_duplex_fc = mac_get_speed_duplex_fc,
486*3833Sxw161283 .statistics_update = mac_update_statistics,
487*3833Sxw161283 .macaddress_get = mac_get_address,
488*3833Sxw161283 .macaddress_set = mac_set_address,
489*3833Sxw161283 };
490*3833Sxw161283 #endif
491*3833Sxw161283
ixf1010_mac_reset(adapter_t * adapter)492*3833Sxw161283 static int ixf1010_mac_reset(adapter_t *adapter)
493*3833Sxw161283 {
494*3833Sxw161283 u32 val;
495*3833Sxw161283
496*3833Sxw161283 (void) t1_tpi_read(adapter, A_ELMER0_GPO, &val);
497*3833Sxw161283 if ((val & 1) != 0) {
498*3833Sxw161283 val &= ~1;
499*3833Sxw161283 (void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
500*3833Sxw161283 DELAY_US(2);
501*3833Sxw161283 }
502*3833Sxw161283 val |= 1;
503*3833Sxw161283 (void) t1_tpi_write(adapter, A_ELMER0_GPO, val);
504*3833Sxw161283 DELAY_US(2);
505*3833Sxw161283
506*3833Sxw161283 (void) t1_tpi_write(adapter, REG_PORT_ENABLE, 0);
507*3833Sxw161283 return 0;
508*3833Sxw161283 }
509*3833Sxw161283
ixf1010_mac_create(adapter_t * adapter,int index)510*3833Sxw161283 static struct cmac *ixf1010_mac_create(adapter_t *adapter, int index)
511*3833Sxw161283 {
512*3833Sxw161283 struct cmac *mac;
513*3833Sxw161283 u32 val;
514*3833Sxw161283
515*3833Sxw161283 if (index > 9) return NULL;
516*3833Sxw161283
517*3833Sxw161283 mac = t1_os_malloc_wait_zero(sizeof(*mac) + sizeof(cmac_instance));
518*3833Sxw161283 if (!mac) return NULL;
519*3833Sxw161283
520*3833Sxw161283 mac->ops = &ixf1010_ops;
521*3833Sxw161283 mac->instance = (cmac_instance *)(mac + 1);
522*3833Sxw161283
523*3833Sxw161283 mac->instance->mac_base = MACREG_BASE + (index * 0x200);
524*3833Sxw161283 mac->instance->index = index;
525*3833Sxw161283 mac->adapter = adapter;
526*3833Sxw161283 mac->instance->ticks = 0;
527*3833Sxw161283
528*3833Sxw161283 (void) t1_tpi_read(adapter, REG_JTAG_ID, &val);
529*3833Sxw161283 mac->instance->version = val >> 28;
530*3833Sxw161283 return mac;
531*3833Sxw161283 }
532*3833Sxw161283
533*3833Sxw161283 struct gmac t1_ixf1010_ops = {
534*3833Sxw161283 STATS_TICK_SECS,
535*3833Sxw161283 ixf1010_mac_create,
536*3833Sxw161283 ixf1010_mac_reset
537*3833Sxw161283 };
538