blob: 16fa13d4821f56694ef861c4e47e07e0ba71f978 [file] [log] [blame]
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001/*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 *
Alan Cox64f93032009-06-10 17:30:41 +01005 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07006 * All rights reserved.
7 * http://www.agere.com
8 *
9 *------------------------------------------------------------------------------
10 *
11 * et1310_mac.c - All code and routines pertaining to the MAC
12 *
13 *------------------------------------------------------------------------------
14 *
15 * SOFTWARE LICENSE
16 *
17 * This software is provided subject to the following terms and conditions,
18 * which you should read carefully before using the software. Using this
19 * software indicates your acceptance of these terms and conditions. If you do
20 * not agree with these terms and conditions, do not use the software.
21 *
Alan Cox64f93032009-06-10 17:30:41 +010022 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070023 * All rights reserved.
24 *
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
27 *
28 * . Redistributions of source code must retain the above copyright notice, this
29 * list of conditions and the following Disclaimer as comments in the code as
30 * well as in the documentation and/or other materials provided with the
31 * distribution.
32 *
33 * . Redistributions in binary form must reproduce the above copyright notice,
34 * this list of conditions and the following Disclaimer in the documentation
35 * and/or other materials provided with the distribution.
36 *
37 * . Neither the name of Agere Systems Inc. nor the names of the contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
40 *
41 * Disclaimer
42 *
Alan Cox64f93032009-06-10 17:30:41 +010043 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070044 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
46 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
47 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
48 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
54 * DAMAGE.
55 *
56 */
57
58#include "et131x_version.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070059#include "et131x_defs.h"
60
61#include <linux/init.h>
62#include <linux/module.h>
63#include <linux/types.h>
64#include <linux/kernel.h>
65
66#include <linux/sched.h>
67#include <linux/ptrace.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070068#include <linux/ctype.h>
69#include <linux/string.h>
70#include <linux/timer.h>
71#include <linux/interrupt.h>
72#include <linux/in.h>
73#include <linux/delay.h>
Alan Cox64f93032009-06-10 17:30:41 +010074#include <linux/io.h>
75#include <linux/bitops.h>
Alan Cox15700032009-08-27 11:03:09 +010076#include <linux/pci.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070077#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070078
79#include <linux/netdevice.h>
80#include <linux/etherdevice.h>
81#include <linux/skbuff.h>
82#include <linux/if_arp.h>
83#include <linux/ioport.h>
84#include <linux/crc32.h>
85
86#include "et1310_phy.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070087#include "et131x_adapter.h"
Alan Cox69ea5fc2010-01-18 15:34:24 +000088#include "et131x.h"
89
90
91#define COUNTER_WRAP_28_BIT 0x10000000
92#define COUNTER_WRAP_22_BIT 0x400000
93#define COUNTER_WRAP_16_BIT 0x10000
94#define COUNTER_WRAP_12_BIT 0x1000
95
96#define COUNTER_MASK_28_BIT (COUNTER_WRAP_28_BIT - 1)
97#define COUNTER_MASK_22_BIT (COUNTER_WRAP_22_BIT - 1)
98#define COUNTER_MASK_16_BIT (COUNTER_WRAP_16_BIT - 1)
99#define COUNTER_MASK_12_BIT (COUNTER_WRAP_12_BIT - 1)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700100
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700101/**
102 * ConfigMacRegs1 - Initialize the first part of MAC regs
103 * @pAdpater: pointer to our adapter structure
104 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100105void ConfigMACRegs1(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700106{
Alan Coxf3f415a2009-08-27 10:59:30 +0100107 struct _MAC_t __iomem *pMac = &etdev->regs->mac;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700108 MAC_STATION_ADDR1_t station1;
109 MAC_STATION_ADDR2_t station2;
Alan Cox308e93e2009-10-06 15:50:26 +0100110 u32 ipg;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700111
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700112 /* First we need to reset everything. Write to MAC configuration
113 * register 1 to perform reset.
114 */
Alan Coxc9835d972009-10-06 15:50:45 +0100115 writel(0xC00F0000, &pMac->cfg1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700116
117 /* Next lets configure the MAC Inter-packet gap register */
Alan Cox308e93e2009-10-06 15:50:26 +0100118 ipg = 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */
119 ipg |= 0x50 << 8; /* ifg enforce 0x50 */
120 writel(ipg, &pMac->ipg);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700121
122 /* Next lets configure the MAC Half Duplex register */
Alan Coxc2f61182009-10-06 15:50:32 +0100123 /* BEB trunc 0xA, Ex Defer, Rexmit 0xF Coll 0x37 */
124 writel(0x00A1F037, &pMac->hfdp);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700125
126 /* Next lets configure the MAC Interface Control register */
Alan Coxb491f142009-11-18 14:06:50 +0000127 writel(0, &pMac->if_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700128
Uwe Kleine-König658ce9d2009-07-23 08:33:56 +0200129 /* Let's move on to setting up the mii management configuration */
Alan Coxeccdd882009-10-06 15:50:39 +0100130 writel(0x07, &pMac->mii_mgmt_cfg); /* Clock reset 0x7 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700131
132 /* Next lets configure the MAC Station Address register. These
133 * values are read from the EEPROM during initialization and stored
134 * in the adapter structure. We write what is stored in the adapter
135 * structure to the MAC Station Address registers high and low. This
136 * station address is used for generating and checking pause control
137 * packets.
138 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100139 station2.bits.Octet1 = etdev->CurrentAddress[0];
140 station2.bits.Octet2 = etdev->CurrentAddress[1];
141 station1.bits.Octet3 = etdev->CurrentAddress[2];
142 station1.bits.Octet4 = etdev->CurrentAddress[3];
143 station1.bits.Octet5 = etdev->CurrentAddress[4];
144 station1.bits.Octet6 = etdev->CurrentAddress[5];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700145 writel(station1.value, &pMac->station_addr_1.value);
146 writel(station2.value, &pMac->station_addr_2.value);
147
148 /* Max ethernet packet in bytes that will passed by the mac without
149 * being truncated. Allow the MAC to pass 4 more than our max packet
150 * size. This is 4 for the Ethernet CRC.
151 *
152 * Packets larger than (RegistryJumboPacket) that do not contain a
153 * VLAN ID will be dropped by the Rx function.
154 */
Alan Coxcc5dc292009-10-06 15:50:51 +0100155 writel(etdev->RegistryJumboPacket + 4, &pMac->max_fm_len);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700156
157 /* clear out MAC config reset */
Alan Coxc9835d972009-10-06 15:50:45 +0100158 writel(0, &pMac->cfg1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700159}
160
161/**
162 * ConfigMacRegs2 - Initialize the second part of MAC regs
163 * @pAdpater: pointer to our adapter structure
164 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100165void ConfigMACRegs2(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700166{
167 int32_t delay = 0;
Alan Coxf3f415a2009-08-27 10:59:30 +0100168 struct _MAC_t __iomem *pMac = &etdev->regs->mac;
Alan Coxc9835d972009-10-06 15:50:45 +0100169 u32 cfg1;
170 u32 cfg2;
Alan Coxb491f142009-11-18 14:06:50 +0000171 u32 ifctrl;
Alan Cox67209492010-01-18 15:34:29 +0000172 u32 ctl;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700173
Alan Cox67209492010-01-18 15:34:29 +0000174 ctl = readl(&etdev->regs->txmac.ctl);
Alan Coxc9835d972009-10-06 15:50:45 +0100175 cfg1 = readl(&pMac->cfg1);
176 cfg2 = readl(&pMac->cfg2);
Alan Coxb491f142009-11-18 14:06:50 +0000177 ifctrl = readl(&pMac->if_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700178
Alan Coxc9835d972009-10-06 15:50:45 +0100179 /* Set up the if mode bits */
180 cfg2 &= ~0x300;
Alan Cox9fa81092009-08-27 11:00:36 +0100181 if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) {
Alan Coxc9835d972009-10-06 15:50:45 +0100182 cfg2 |= 0x200;
Alan Coxb491f142009-11-18 14:06:50 +0000183 /* Phy mode bit */
184 ifctrl &= ~(1 << 24);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700185 } else {
Alan Coxc9835d972009-10-06 15:50:45 +0100186 cfg2 |= 0x100;
Alan Coxb491f142009-11-18 14:06:50 +0000187 ifctrl |= (1 << 24);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700188 }
189
190 /* We need to enable Rx/Tx */
Alan Coxc9835d972009-10-06 15:50:45 +0100191 cfg1 |= CFG1_RX_ENABLE|CFG1_TX_ENABLE|CFG1_TX_FLOW;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700192 /* Initialize loop back to off */
Alan Coxc9835d972009-10-06 15:50:45 +0100193 cfg1 &= ~(CFG1_LOOPBACK|CFG1_RX_FLOW);
194 if (etdev->FlowControl == RxOnly || etdev->FlowControl == Both)
195 cfg1 |= CFG1_RX_FLOW;
196 writel(cfg1, &pMac->cfg1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700197
198 /* Now we need to initialize the MAC Configuration 2 register */
Alan Coxc9835d972009-10-06 15:50:45 +0100199 /* preamble 7, check length, huge frame off, pad crc, crc enable
200 full duplex off */
201 cfg2 |= 0x7016;
202 cfg2 &= ~0x0021;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700203
Alan Coxc9835d972009-10-06 15:50:45 +0100204 /* Turn on duplex if needed */
205 if (etdev->duplex_mode)
206 cfg2 |= 0x01;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700207
Alan Coxb491f142009-11-18 14:06:50 +0000208 ifctrl &= ~(1 << 26);
209 if (!etdev->duplex_mode)
210 ifctrl |= (1<<26); /* Enable ghd */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700211
Alan Coxb491f142009-11-18 14:06:50 +0000212 writel(ifctrl, &pMac->if_ctrl);
Alan Coxc9835d972009-10-06 15:50:45 +0100213 writel(cfg2, &pMac->cfg2);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700214
215 do {
216 udelay(10);
217 delay++;
Alan Coxc9835d972009-10-06 15:50:45 +0100218 cfg1 = readl(&pMac->cfg1);
219 } while ((cfg1 & CFG1_WAIT) != CFG1_WAIT && delay < 100);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700220
221 if (delay == 100) {
Alan Cox15700032009-08-27 11:03:09 +0100222 dev_warn(&etdev->pdev->dev,
Alan Cox64f93032009-06-10 17:30:41 +0100223 "Syncd bits did not respond correctly cfg1 word 0x%08x\n",
Alan Coxc9835d972009-10-06 15:50:45 +0100224 cfg1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700225 }
226
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700227 /* Enable TXMAC */
Nick Bowler05ad62a2010-03-10 00:10:46 -0500228 ctl |= 0x09; /* TX mac enable, FC disable */
Alan Cox67209492010-01-18 15:34:29 +0000229 writel(ctl, &etdev->regs->txmac.ctl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700230
231 /* Ready to start the RXDMA/TXDMA engine */
Alan Coxf6b35d62009-08-27 11:02:05 +0100232 if (etdev->Flags & fMP_ADAPTER_LOWER_POWER) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100233 et131x_rx_dma_enable(etdev);
234 et131x_tx_dma_enable(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700235 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700236}
237
Alan Cox25ad00b2009-08-19 18:21:44 +0100238void ConfigRxMacRegs(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700239{
Alan Coxf3f415a2009-08-27 10:59:30 +0100240 struct _RXMAC_t __iomem *pRxMac = &etdev->regs->rxmac;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700241 RXMAC_WOL_SA_LO_t sa_lo;
242 RXMAC_WOL_SA_HI_t sa_hi;
Alan Coxb186f332010-01-18 15:34:57 +0000243 u32 pf_ctrl = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700244
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700245 /* Disable the MAC while it is being configured (also disable WOL) */
Alan Coxbd03d0d2010-01-18 15:35:30 +0000246 writel(0x8, &pRxMac->ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700247
248 /* Initialize WOL to disabled. */
Alan Cox70a29a22010-01-18 15:34:51 +0000249 writel(0, &pRxMac->crc0);
250 writel(0, &pRxMac->crc12);
251 writel(0, &pRxMac->crc34);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700252
253 /* We need to set the WOL mask0 - mask4 next. We initialize it to
254 * its default Values of 0x00000000 because there are not WOL masks
255 * as of this time.
256 */
257 writel(0, &pRxMac->mask0_word0);
258 writel(0, &pRxMac->mask0_word1);
259 writel(0, &pRxMac->mask0_word2);
260 writel(0, &pRxMac->mask0_word3);
261
262 writel(0, &pRxMac->mask1_word0);
263 writel(0, &pRxMac->mask1_word1);
264 writel(0, &pRxMac->mask1_word2);
265 writel(0, &pRxMac->mask1_word3);
266
267 writel(0, &pRxMac->mask2_word0);
268 writel(0, &pRxMac->mask2_word1);
269 writel(0, &pRxMac->mask2_word2);
270 writel(0, &pRxMac->mask2_word3);
271
272 writel(0, &pRxMac->mask3_word0);
273 writel(0, &pRxMac->mask3_word1);
274 writel(0, &pRxMac->mask3_word2);
275 writel(0, &pRxMac->mask3_word3);
276
277 writel(0, &pRxMac->mask4_word0);
278 writel(0, &pRxMac->mask4_word1);
279 writel(0, &pRxMac->mask4_word2);
280 writel(0, &pRxMac->mask4_word3);
281
282 /* Lets setup the WOL Source Address */
Alan Cox25ad00b2009-08-19 18:21:44 +0100283 sa_lo.bits.sa3 = etdev->CurrentAddress[2];
284 sa_lo.bits.sa4 = etdev->CurrentAddress[3];
285 sa_lo.bits.sa5 = etdev->CurrentAddress[4];
286 sa_lo.bits.sa6 = etdev->CurrentAddress[5];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700287 writel(sa_lo.value, &pRxMac->sa_lo.value);
288
Alan Cox25ad00b2009-08-19 18:21:44 +0100289 sa_hi.bits.sa1 = etdev->CurrentAddress[0];
290 sa_hi.bits.sa2 = etdev->CurrentAddress[1];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700291 writel(sa_hi.value, &pRxMac->sa_hi.value);
292
293 /* Disable all Packet Filtering */
Alan Coxb186f332010-01-18 15:34:57 +0000294 writel(0, &pRxMac->pf_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700295
296 /* Let's initialize the Unicast Packet filtering address */
Alan Cox25ad00b2009-08-19 18:21:44 +0100297 if (etdev->PacketFilter & ET131X_PACKET_TYPE_DIRECTED) {
298 SetupDeviceForUnicast(etdev);
Alan Coxb186f332010-01-18 15:34:57 +0000299 pf_ctrl |= 4; /* Unicast filter */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700300 } else {
301 writel(0, &pRxMac->uni_pf_addr1.value);
302 writel(0, &pRxMac->uni_pf_addr2.value);
303 writel(0, &pRxMac->uni_pf_addr3.value);
304 }
305
306 /* Let's initialize the Multicast hash */
Alan Coxb186f332010-01-18 15:34:57 +0000307 if (!(etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST)) {
308 pf_ctrl |= 2; /* Multicast filter */
Alan Cox25ad00b2009-08-19 18:21:44 +0100309 SetupDeviceForMulticast(etdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700310 }
311
312 /* Runt packet filtering. Didn't work in version A silicon. */
Alan Coxb186f332010-01-18 15:34:57 +0000313 pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << 16;
314 pf_ctrl |= 8; /* Fragment filter */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700315
Alan Cox287acb62010-01-18 15:35:02 +0000316 if (etdev->RegistryJumboPacket > 8192)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700317 /* In order to transmit jumbo packets greater than 8k, the
318 * FIFO between RxMAC and RxDMA needs to be reduced in size
319 * to (16k - Jumbo packet size). In order to implement this,
320 * we must use "cut through" mode in the RxMAC, which chops
321 * packets down into segments which are (max_size * 16). In
322 * this case we selected 256 bytes, since this is the size of
323 * the PCI-Express TLP's that the 1310 uses.
Alan Cox287acb62010-01-18 15:35:02 +0000324 *
325 * seg_en on, fc_en off, size 0x10
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700326 */
Alan Cox287acb62010-01-18 15:35:02 +0000327 writel(0x41, &pRxMac->mcif_ctrl_max_seg);
328 else
329 writel(0, &pRxMac->mcif_ctrl_max_seg);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700330
331 /* Initialize the MCIF water marks */
Alan Cox287acb62010-01-18 15:35:02 +0000332 writel(0, &pRxMac->mcif_water_mark);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700333
334 /* Initialize the MIF control */
Alan Coxdcb07892010-01-18 15:35:19 +0000335 writel(0, &pRxMac->mif_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700336
337 /* Initialize the Space Available Register */
Alan Cox370d52a2010-01-18 15:35:13 +0000338 writel(0, &pRxMac->space_avail);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700339
340 /* Initialize the the mif_ctrl register
341 * bit 3: Receive code error. One or more nibbles were signaled as
342 * errors during the reception of the packet. Clear this
343 * bit in Gigabit, set it in 100Mbit. This was derived
344 * experimentally at UNH.
345 * bit 4: Receive CRC error. The packet's CRC did not match the
346 * internally generated CRC.
347 * bit 5: Receive length check error. Indicates that frame length
348 * field value in the packet does not match the actual data
349 * byte length and is not a type field.
350 * bit 16: Receive frame truncated.
351 * bit 17: Drop packet enable
352 */
Alan Cox9fa81092009-08-27 11:00:36 +0100353 if (etdev->linkspeed == TRUEPHY_SPEED_100MBPS)
Alan Coxdcb07892010-01-18 15:35:19 +0000354 writel(0x30038, &pRxMac->mif_ctrl);
Alan Cox64f93032009-06-10 17:30:41 +0100355 else
Alan Coxdcb07892010-01-18 15:35:19 +0000356 writel(0x30030, &pRxMac->mif_ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700357
358 /* Finally we initialize RxMac to be enabled & WOL disabled. Packet
359 * filter is always enabled since it is where the runt packets are
360 * supposed to be dropped. For version A silicon, runt packet
361 * dropping doesn't work, so it is disabled in the pf_ctrl register,
362 * but we still leave the packet filter on.
363 */
Alan Coxb186f332010-01-18 15:34:57 +0000364 writel(pf_ctrl, &pRxMac->pf_ctrl);
Alan Coxbd03d0d2010-01-18 15:35:30 +0000365 writel(0x9, &pRxMac->ctrl);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700366}
367
Alan Cox25ad00b2009-08-19 18:21:44 +0100368void ConfigTxMacRegs(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700369{
Alan Coxafa7e5e2010-01-18 15:34:46 +0000370 struct txmac_regs *txmac = &etdev->regs->txmac;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700371
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700372 /* We need to update the Control Frame Parameters
373 * cfpt - control frame pause timer set to 64 (0x40)
374 * cfep - control frame extended pause timer set to 0x0
375 */
Alan Coxf838cab2009-11-18 14:07:09 +0000376 if (etdev->FlowControl == None)
Alan Coxafa7e5e2010-01-18 15:34:46 +0000377 writel(0, &txmac->cf_param);
Alan Coxf838cab2009-11-18 14:07:09 +0000378 else
Alan Coxafa7e5e2010-01-18 15:34:46 +0000379 writel(0x40, &txmac->cf_param);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700380}
381
Alan Cox25ad00b2009-08-19 18:21:44 +0100382void ConfigMacStatRegs(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700383{
Alan Coxdc26ffc2010-01-18 15:33:29 +0000384 struct macstat_regs __iomem *macstat =
385 &etdev->regs->macstat;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700386
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700387 /* Next we need to initialize all the MAC_STAT registers to zero on
388 * the device.
389 */
Alan Cox74f38632009-11-18 14:07:03 +0000390 writel(0, &macstat->RFcs);
391 writel(0, &macstat->RAln);
392 writel(0, &macstat->RFlr);
393 writel(0, &macstat->RDrp);
394 writel(0, &macstat->RCde);
395 writel(0, &macstat->ROvr);
396 writel(0, &macstat->RFrg);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700397
Alan Cox74f38632009-11-18 14:07:03 +0000398 writel(0, &macstat->TScl);
399 writel(0, &macstat->TDfr);
400 writel(0, &macstat->TMcl);
401 writel(0, &macstat->TLcl);
402 writel(0, &macstat->TNcl);
403 writel(0, &macstat->TOvr);
404 writel(0, &macstat->TUnd);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700405
406 /* Unmask any counters that we want to track the overflow of.
407 * Initially this will be all counters. It may become clear later
408 * that we do not need to track all counters.
409 */
Alan Cox74f38632009-11-18 14:07:03 +0000410 writel(0xFFFFBE32, &macstat->Carry1M);
411 writel(0xFFFE7E8B, &macstat->Carry2M);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700412}
413
Alan Cox25ad00b2009-08-19 18:21:44 +0100414void ConfigFlowControl(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700415{
Alan Cox9fa81092009-08-27 11:00:36 +0100416 if (etdev->duplex_mode == 0) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100417 etdev->FlowControl = None;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700418 } else {
Alan Cox74f38632009-11-18 14:07:03 +0000419 char remote_pause, remote_async_pause;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700420
Alan Cox25ad00b2009-08-19 18:21:44 +0100421 ET1310_PhyAccessMiBit(etdev,
Alan Cox74f38632009-11-18 14:07:03 +0000422 TRUEPHY_BIT_READ, 5, 10, &remote_pause);
Alan Cox25ad00b2009-08-19 18:21:44 +0100423 ET1310_PhyAccessMiBit(etdev,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700424 TRUEPHY_BIT_READ, 5, 11,
Alan Cox74f38632009-11-18 14:07:03 +0000425 &remote_async_pause);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700426
Alan Cox74f38632009-11-18 14:07:03 +0000427 if ((remote_pause == TRUEPHY_BIT_SET) &&
428 (remote_async_pause == TRUEPHY_BIT_SET)) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100429 etdev->FlowControl = etdev->RegistryFlowControl;
Alan Cox74f38632009-11-18 14:07:03 +0000430 } else if ((remote_pause == TRUEPHY_BIT_SET) &&
431 (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100432 if (etdev->RegistryFlowControl == Both)
433 etdev->FlowControl = Both;
Alan Cox64f93032009-06-10 17:30:41 +0100434 else
Alan Cox25ad00b2009-08-19 18:21:44 +0100435 etdev->FlowControl = None;
Alan Cox74f38632009-11-18 14:07:03 +0000436 } else if ((remote_pause == TRUEPHY_BIT_CLEAR) &&
437 (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100438 etdev->FlowControl = None;
Alan Cox74f38632009-11-18 14:07:03 +0000439 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT &&
440 remote_async_pause == TRUEPHY_SET_BIT) */
Alan Cox25ad00b2009-08-19 18:21:44 +0100441 if (etdev->RegistryFlowControl == Both)
442 etdev->FlowControl = RxOnly;
Alan Cox64f93032009-06-10 17:30:41 +0100443 else
Alan Cox25ad00b2009-08-19 18:21:44 +0100444 etdev->FlowControl = None;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700445 }
446 }
447}
448
449/**
450 * UpdateMacStatHostCounters - Update the local copy of the statistics
Alan Cox25ad00b2009-08-19 18:21:44 +0100451 * @etdev: pointer to the adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700452 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100453void UpdateMacStatHostCounters(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700454{
Alan Cox25ad00b2009-08-19 18:21:44 +0100455 struct _ce_stats_t *stats = &etdev->Stats;
Alan Coxdc26ffc2010-01-18 15:33:29 +0000456 struct macstat_regs __iomem *macstat =
457 &etdev->regs->macstat;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700458
Alan Cox74f38632009-11-18 14:07:03 +0000459 stats->collisions += readl(&macstat->TNcl);
460 stats->first_collision += readl(&macstat->TScl);
461 stats->tx_deferred += readl(&macstat->TDfr);
462 stats->excessive_collisions += readl(&macstat->TMcl);
463 stats->late_collisions += readl(&macstat->TLcl);
464 stats->tx_uflo += readl(&macstat->TUnd);
465 stats->max_pkt_error += readl(&macstat->TOvr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700466
Alan Cox74f38632009-11-18 14:07:03 +0000467 stats->alignment_err += readl(&macstat->RAln);
468 stats->crc_err += readl(&macstat->RCde);
469 stats->norcvbuf += readl(&macstat->RDrp);
470 stats->rx_ov_flow += readl(&macstat->ROvr);
471 stats->code_violations += readl(&macstat->RFcs);
472 stats->length_err += readl(&macstat->RFlr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700473
Alan Cox74f38632009-11-18 14:07:03 +0000474 stats->other_errors += readl(&macstat->RFrg);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700475}
476
477/**
478 * HandleMacStatInterrupt
Alan Cox25ad00b2009-08-19 18:21:44 +0100479 * @etdev: pointer to the adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700480 *
481 * One of the MACSTAT counters has wrapped. Update the local copy of
482 * the statistics held in the adapter structure, checking the "wrap"
483 * bit for each counter.
484 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100485void HandleMacStatInterrupt(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700486{
Alan Coxae8d9d82009-11-18 14:06:57 +0000487 u32 Carry1;
488 u32 Carry2;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700489
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700490 /* Read the interrupt bits from the register(s). These are Clear On
491 * Write.
492 */
Alan Coxdc26ffc2010-01-18 15:33:29 +0000493 Carry1 = readl(&etdev->regs->macstat.Carry1);
494 Carry2 = readl(&etdev->regs->macstat.Carry2);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700495
Alan Coxdc26ffc2010-01-18 15:33:29 +0000496 writel(Carry1, &etdev->regs->macstat.Carry1);
497 writel(Carry2, &etdev->regs->macstat.Carry2);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700498
499 /* We need to do update the host copy of all the MAC_STAT counters.
500 * For each counter, check it's overflow bit. If the overflow bit is
501 * set, then increment the host version of the count by one complete
502 * revolution of the counter. This routine is called when the counter
503 * block indicates that one of the counters has wrapped.
504 */
Alan Coxae8d9d82009-11-18 14:06:57 +0000505 if (Carry1 & (1 << 14))
Alan Cox25ad00b2009-08-19 18:21:44 +0100506 etdev->Stats.code_violations += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000507 if (Carry1 & (1 << 8))
Alan Cox25ad00b2009-08-19 18:21:44 +0100508 etdev->Stats.alignment_err += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000509 if (Carry1 & (1 << 7))
Alan Cox25ad00b2009-08-19 18:21:44 +0100510 etdev->Stats.length_err += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000511 if (Carry1 & (1 << 2))
Alan Cox25ad00b2009-08-19 18:21:44 +0100512 etdev->Stats.other_errors += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000513 if (Carry1 & (1 << 6))
Alan Cox25ad00b2009-08-19 18:21:44 +0100514 etdev->Stats.crc_err += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000515 if (Carry1 & (1 << 3))
Alan Cox25ad00b2009-08-19 18:21:44 +0100516 etdev->Stats.rx_ov_flow += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000517 if (Carry1 & (1 << 0))
Alan Cox25ad00b2009-08-19 18:21:44 +0100518 etdev->Stats.norcvbuf += COUNTER_WRAP_16_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000519 if (Carry2 & (1 << 16))
Alan Cox25ad00b2009-08-19 18:21:44 +0100520 etdev->Stats.max_pkt_error += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000521 if (Carry2 & (1 << 15))
Alan Cox25ad00b2009-08-19 18:21:44 +0100522 etdev->Stats.tx_uflo += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000523 if (Carry2 & (1 << 6))
Alan Cox25ad00b2009-08-19 18:21:44 +0100524 etdev->Stats.first_collision += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000525 if (Carry2 & (1 << 8))
Alan Cox25ad00b2009-08-19 18:21:44 +0100526 etdev->Stats.tx_deferred += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000527 if (Carry2 & (1 << 5))
Alan Cox25ad00b2009-08-19 18:21:44 +0100528 etdev->Stats.excessive_collisions += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000529 if (Carry2 & (1 << 4))
Alan Cox25ad00b2009-08-19 18:21:44 +0100530 etdev->Stats.late_collisions += COUNTER_WRAP_12_BIT;
Alan Coxae8d9d82009-11-18 14:06:57 +0000531 if (Carry2 & (1 << 2))
Alan Cox25ad00b2009-08-19 18:21:44 +0100532 etdev->Stats.collisions += COUNTER_WRAP_12_BIT;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700533}
534
Alan Cox25ad00b2009-08-19 18:21:44 +0100535void SetupDeviceForMulticast(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700536{
Alan Coxf3f415a2009-08-27 10:59:30 +0100537 struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700538 uint32_t nIndex;
539 uint32_t result;
540 uint32_t hash1 = 0;
541 uint32_t hash2 = 0;
542 uint32_t hash3 = 0;
543 uint32_t hash4 = 0;
Alan Coxf2c98d22009-08-27 11:01:49 +0100544 u32 pm_csr;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700545
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700546 /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision
547 * the multi-cast LIST. If it is NOT specified, (and "ALL" is not
548 * specified) then we should pass NO multi-cast addresses to the
549 * driver.
550 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100551 if (etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700552 /* Loop through our multicast array and set up the device */
Alan Cox25ad00b2009-08-19 18:21:44 +0100553 for (nIndex = 0; nIndex < etdev->MCAddressCount; nIndex++) {
Alan Cox25ad00b2009-08-19 18:21:44 +0100554 result = ether_crc(6, etdev->MCList[nIndex]);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700555
556 result = (result & 0x3F800000) >> 23;
557
558 if (result < 32) {
559 hash1 |= (1 << result);
560 } else if ((31 < result) && (result < 64)) {
561 result -= 32;
562 hash2 |= (1 << result);
563 } else if ((63 < result) && (result < 96)) {
564 result -= 64;
565 hash3 |= (1 << result);
566 } else {
567 result -= 96;
568 hash4 |= (1 << result);
569 }
570 }
571 }
572
573 /* Write out the new hash to the device */
Alan Coxf2c98d22009-08-27 11:01:49 +0100574 pm_csr = readl(&etdev->regs->global.pm_csr);
575 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700576 writel(hash1, &rxmac->multi_hash1);
577 writel(hash2, &rxmac->multi_hash2);
578 writel(hash3, &rxmac->multi_hash3);
579 writel(hash4, &rxmac->multi_hash4);
580 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700581}
582
Alan Cox25ad00b2009-08-19 18:21:44 +0100583void SetupDeviceForUnicast(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700584{
Alan Coxf3f415a2009-08-27 10:59:30 +0100585 struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700586 RXMAC_UNI_PF_ADDR1_t uni_pf1;
587 RXMAC_UNI_PF_ADDR2_t uni_pf2;
588 RXMAC_UNI_PF_ADDR3_t uni_pf3;
Alan Coxf2c98d22009-08-27 11:01:49 +0100589 u32 pm_csr;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700590
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700591 /* Set up unicast packet filter reg 3 to be the first two octets of
592 * the MAC address for both address
593 *
594 * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the
595 * MAC address for second address
596 *
597 * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
598 * MAC address for first address
599 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100600 uni_pf3.bits.addr1_1 = etdev->CurrentAddress[0];
601 uni_pf3.bits.addr1_2 = etdev->CurrentAddress[1];
602 uni_pf3.bits.addr2_1 = etdev->CurrentAddress[0];
603 uni_pf3.bits.addr2_2 = etdev->CurrentAddress[1];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700604
Alan Cox25ad00b2009-08-19 18:21:44 +0100605 uni_pf2.bits.addr2_3 = etdev->CurrentAddress[2];
606 uni_pf2.bits.addr2_4 = etdev->CurrentAddress[3];
607 uni_pf2.bits.addr2_5 = etdev->CurrentAddress[4];
608 uni_pf2.bits.addr2_6 = etdev->CurrentAddress[5];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700609
Alan Cox25ad00b2009-08-19 18:21:44 +0100610 uni_pf1.bits.addr1_3 = etdev->CurrentAddress[2];
611 uni_pf1.bits.addr1_4 = etdev->CurrentAddress[3];
612 uni_pf1.bits.addr1_5 = etdev->CurrentAddress[4];
613 uni_pf1.bits.addr1_6 = etdev->CurrentAddress[5];
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700614
Alan Coxf2c98d22009-08-27 11:01:49 +0100615 pm_csr = readl(&etdev->regs->global.pm_csr);
616 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700617 writel(uni_pf1.value, &rxmac->uni_pf_addr1.value);
618 writel(uni_pf2.value, &rxmac->uni_pf_addr2.value);
619 writel(uni_pf3.value, &rxmac->uni_pf_addr3.value);
620 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700621}