]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/et131x/et1310_mac.c
connector: Delete buggy notification code.
[karo-tx-linux.git] / drivers / staging / et131x / et1310_mac.c
1 /*
2  * Agere Systems Inc.
3  * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4  *
5  * Copyright © 2005 Agere Systems Inc.
6  * 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  *
22  * Copyright © 2005 Agere Systems Inc.
23  * 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  *
43  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44  * 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"
59 #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>
68 #include <linux/slab.h>
69 #include <linux/ctype.h>
70 #include <linux/string.h>
71 #include <linux/timer.h>
72 #include <linux/interrupt.h>
73 #include <linux/in.h>
74 #include <linux/delay.h>
75 #include <linux/io.h>
76 #include <linux/bitops.h>
77 #include <linux/pci.h>
78 #include <asm/system.h>
79
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/if_arp.h>
84 #include <linux/ioport.h>
85 #include <linux/crc32.h>
86
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
90 #include "et1310_mac.h"
91
92 #include "et131x_adapter.h"
93 #include "et131x_initpci.h"
94
95 /**
96  * ConfigMacRegs1 - Initialize the first part of MAC regs
97  * @pAdpater: pointer to our adapter structure
98  */
99 void ConfigMACRegs1(struct et131x_adapter *etdev)
100 {
101         struct _MAC_t __iomem *pMac = &etdev->regs->mac;
102         MAC_STATION_ADDR1_t station1;
103         MAC_STATION_ADDR2_t station2;
104         MAC_IPG_t ipg;
105         MAC_HFDP_t hfdp;
106         MII_MGMT_CFG_t mii_mgmt_cfg;
107
108         /* First we need to reset everything.  Write to MAC configuration
109          * register 1 to perform reset.
110          */
111         writel(0xC00F0000, &pMac->cfg1.value);
112
113         /* Next lets configure the MAC Inter-packet gap register */
114         ipg.bits.non_B2B_ipg_1 = 0x38;          /* 58d */
115         ipg.bits.non_B2B_ipg_2 = 0x58;          /* 88d */
116         ipg.bits.min_ifg_enforce = 0x50;        /* 80d */
117         ipg.bits.B2B_ipg = 0x60;                /* 96d */
118         writel(ipg.value, &pMac->ipg.value);
119
120         /* Next lets configure the MAC Half Duplex register */
121         hfdp.bits.alt_beb_trunc = 0xA;
122         hfdp.bits.alt_beb_enable = 0x0;
123         hfdp.bits.bp_no_backoff = 0x0;
124         hfdp.bits.no_backoff = 0x0;
125         hfdp.bits.excess_defer = 0x1;
126         hfdp.bits.rexmit_max = 0xF;
127         hfdp.bits.coll_window = 0x37;           /* 55d */
128         writel(hfdp.value, &pMac->hfdp.value);
129
130         /* Next lets configure the MAC Interface Control register */
131         writel(0, &pMac->if_ctrl.value);
132
133         /* Let's move on to setting up the mii management configuration */
134         mii_mgmt_cfg.bits.reset_mii_mgmt = 0;
135         mii_mgmt_cfg.bits.scan_auto_incremt = 0;
136         mii_mgmt_cfg.bits.preamble_suppress = 0;
137         mii_mgmt_cfg.bits.mgmt_clk_reset = 0x7;
138         writel(mii_mgmt_cfg.value, &pMac->mii_mgmt_cfg.value);
139
140         /* Next lets configure the MAC Station Address register.  These
141          * values are read from the EEPROM during initialization and stored
142          * in the adapter structure.  We write what is stored in the adapter
143          * structure to the MAC Station Address registers high and low.  This
144          * station address is used for generating and checking pause control
145          * packets.
146          */
147         station2.bits.Octet1 = etdev->CurrentAddress[0];
148         station2.bits.Octet2 = etdev->CurrentAddress[1];
149         station1.bits.Octet3 = etdev->CurrentAddress[2];
150         station1.bits.Octet4 = etdev->CurrentAddress[3];
151         station1.bits.Octet5 = etdev->CurrentAddress[4];
152         station1.bits.Octet6 = etdev->CurrentAddress[5];
153         writel(station1.value, &pMac->station_addr_1.value);
154         writel(station2.value, &pMac->station_addr_2.value);
155
156         /* Max ethernet packet in bytes that will passed by the mac without
157          * being truncated.  Allow the MAC to pass 4 more than our max packet
158          * size.  This is 4 for the Ethernet CRC.
159          *
160          * Packets larger than (RegistryJumboPacket) that do not contain a
161          * VLAN ID will be dropped by the Rx function.
162          */
163         writel(etdev->RegistryJumboPacket + 4, &pMac->max_fm_len.value);
164
165         /* clear out MAC config reset */
166         writel(0, &pMac->cfg1.value);
167 }
168
169 /**
170  * ConfigMacRegs2 - Initialize the second part of MAC regs
171  * @pAdpater: pointer to our adapter structure
172  */
173 void ConfigMACRegs2(struct et131x_adapter *etdev)
174 {
175         int32_t delay = 0;
176         struct _MAC_t __iomem *pMac = &etdev->regs->mac;
177         MAC_CFG1_t cfg1;
178         MAC_CFG2_t cfg2;
179         MAC_IF_CTRL_t ifctrl;
180         TXMAC_CTL_t ctl;
181
182         ctl.value = readl(&etdev->regs->txmac.ctl.value);
183         cfg1.value = readl(&pMac->cfg1.value);
184         cfg2.value = readl(&pMac->cfg2.value);
185         ifctrl.value = readl(&pMac->if_ctrl.value);
186
187         if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) {
188                 cfg2.bits.if_mode = 0x2;
189                 ifctrl.bits.phy_mode = 0x0;
190         } else {
191                 cfg2.bits.if_mode = 0x1;
192                 ifctrl.bits.phy_mode = 0x1;
193         }
194
195         /* We need to enable Rx/Tx */
196         cfg1.bits.rx_enable = 0x1;
197         cfg1.bits.tx_enable = 0x1;
198
199         /* Set up flow control */
200         cfg1.bits.tx_flow = 0x1;
201
202         if ((etdev->FlowControl == RxOnly) ||
203             (etdev->FlowControl == Both)) {
204                 cfg1.bits.rx_flow = 0x1;
205         } else {
206                 cfg1.bits.rx_flow = 0x0;
207         }
208
209         /* Initialize loop back to off */
210         cfg1.bits.loop_back = 0;
211
212         writel(cfg1.value, &pMac->cfg1.value);
213
214         /* Now we need to initialize the MAC Configuration 2 register */
215         cfg2.bits.preamble_len = 0x7;
216         cfg2.bits.huge_frame = 0x0;
217         /* LENGTH FIELD CHECKING bit4: Set this bit to cause the MAC to check
218          * the frame's length field to ensure it matches the actual data
219          * field length. Clear this bit if no length field checking is
220          * desired. Its default is 0.
221          */
222         cfg2.bits.len_check = 0x1;
223
224         if (etdev->RegistryPhyLoopbk == false) {
225                 cfg2.bits.pad_crc = 0x1;
226                 cfg2.bits.crc_enable = 0x1;
227         } else {
228                 cfg2.bits.pad_crc = 0;
229                 cfg2.bits.crc_enable = 0;
230         }
231
232         /* 1 - full duplex, 0 - half-duplex */
233         cfg2.bits.full_duplex = etdev->duplex_mode;
234         ifctrl.bits.ghd_mode = !etdev->duplex_mode;
235
236         writel(ifctrl.value, &pMac->if_ctrl.value);
237         writel(cfg2.value, &pMac->cfg2.value);
238
239         do {
240                 udelay(10);
241                 delay++;
242                 cfg1.value = readl(&pMac->cfg1.value);
243         } while ((!cfg1.bits.syncd_rx_en || !cfg1.bits.syncd_tx_en) &&
244                                                                  delay < 100);
245
246         if (delay == 100) {
247                 dev_warn(&etdev->pdev->dev,
248                     "Syncd bits did not respond correctly cfg1 word 0x%08x\n",
249                         cfg1.value);
250         }
251
252         /* Enable TXMAC */
253         ctl.bits.txmac_en = 0x1;
254         ctl.bits.fc_disable = 0x1;
255         writel(ctl.value, &etdev->regs->txmac.ctl.value);
256
257         /* Ready to start the RXDMA/TXDMA engine */
258         if (etdev->Flags & fMP_ADAPTER_LOWER_POWER) {
259                 et131x_rx_dma_enable(etdev);
260                 et131x_tx_dma_enable(etdev);
261         }
262 }
263
264 void ConfigRxMacRegs(struct et131x_adapter *etdev)
265 {
266         struct _RXMAC_t __iomem *pRxMac = &etdev->regs->rxmac;
267         RXMAC_WOL_SA_LO_t sa_lo;
268         RXMAC_WOL_SA_HI_t sa_hi;
269         RXMAC_PF_CTRL_t pf_ctrl = { 0 };
270
271         /* Disable the MAC while it is being configured (also disable WOL) */
272         writel(0x8, &pRxMac->ctrl.value);
273
274         /* Initialize WOL to disabled. */
275         writel(0, &pRxMac->crc0.value);
276         writel(0, &pRxMac->crc12.value);
277         writel(0, &pRxMac->crc34.value);
278
279         /* We need to set the WOL mask0 - mask4 next.  We initialize it to
280          * its default Values of 0x00000000 because there are not WOL masks
281          * as of this time.
282          */
283         writel(0, &pRxMac->mask0_word0);
284         writel(0, &pRxMac->mask0_word1);
285         writel(0, &pRxMac->mask0_word2);
286         writel(0, &pRxMac->mask0_word3);
287
288         writel(0, &pRxMac->mask1_word0);
289         writel(0, &pRxMac->mask1_word1);
290         writel(0, &pRxMac->mask1_word2);
291         writel(0, &pRxMac->mask1_word3);
292
293         writel(0, &pRxMac->mask2_word0);
294         writel(0, &pRxMac->mask2_word1);
295         writel(0, &pRxMac->mask2_word2);
296         writel(0, &pRxMac->mask2_word3);
297
298         writel(0, &pRxMac->mask3_word0);
299         writel(0, &pRxMac->mask3_word1);
300         writel(0, &pRxMac->mask3_word2);
301         writel(0, &pRxMac->mask3_word3);
302
303         writel(0, &pRxMac->mask4_word0);
304         writel(0, &pRxMac->mask4_word1);
305         writel(0, &pRxMac->mask4_word2);
306         writel(0, &pRxMac->mask4_word3);
307
308         /* Lets setup the WOL Source Address */
309         sa_lo.bits.sa3 = etdev->CurrentAddress[2];
310         sa_lo.bits.sa4 = etdev->CurrentAddress[3];
311         sa_lo.bits.sa5 = etdev->CurrentAddress[4];
312         sa_lo.bits.sa6 = etdev->CurrentAddress[5];
313         writel(sa_lo.value, &pRxMac->sa_lo.value);
314
315         sa_hi.bits.sa1 = etdev->CurrentAddress[0];
316         sa_hi.bits.sa2 = etdev->CurrentAddress[1];
317         writel(sa_hi.value, &pRxMac->sa_hi.value);
318
319         /* Disable all Packet Filtering */
320         writel(0, &pRxMac->pf_ctrl.value);
321
322         /* Let's initialize the Unicast Packet filtering address */
323         if (etdev->PacketFilter & ET131X_PACKET_TYPE_DIRECTED) {
324                 SetupDeviceForUnicast(etdev);
325                 pf_ctrl.bits.filter_uni_en = 1;
326         } else {
327                 writel(0, &pRxMac->uni_pf_addr1.value);
328                 writel(0, &pRxMac->uni_pf_addr2.value);
329                 writel(0, &pRxMac->uni_pf_addr3.value);
330         }
331
332         /* Let's initialize the Multicast hash */
333         if (etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST) {
334                 pf_ctrl.bits.filter_multi_en = 0;
335         } else {
336                 pf_ctrl.bits.filter_multi_en = 1;
337                 SetupDeviceForMulticast(etdev);
338         }
339
340         /* Runt packet filtering.  Didn't work in version A silicon. */
341         pf_ctrl.bits.min_pkt_size = NIC_MIN_PACKET_SIZE + 4;
342         pf_ctrl.bits.filter_frag_en = 1;
343
344         if (etdev->RegistryJumboPacket > 8192) {
345                 RXMAC_MCIF_CTRL_MAX_SEG_t mcif_ctrl_max_seg;
346
347                 /* In order to transmit jumbo packets greater than 8k, the
348                  * FIFO between RxMAC and RxDMA needs to be reduced in size
349                  * to (16k - Jumbo packet size).  In order to implement this,
350                  * we must use "cut through" mode in the RxMAC, which chops
351                  * packets down into segments which are (max_size * 16).  In
352                  * this case we selected 256 bytes, since this is the size of
353                  * the PCI-Express TLP's that the 1310 uses.
354                  */
355                 mcif_ctrl_max_seg.bits.seg_en = 0x1;
356                 mcif_ctrl_max_seg.bits.fc_en = 0x0;
357                 mcif_ctrl_max_seg.bits.max_size = 0x10;
358
359                 writel(mcif_ctrl_max_seg.value,
360                        &pRxMac->mcif_ctrl_max_seg.value);
361         } else {
362                 writel(0, &pRxMac->mcif_ctrl_max_seg.value);
363         }
364
365         /* Initialize the MCIF water marks */
366         writel(0, &pRxMac->mcif_water_mark.value);
367
368         /*  Initialize the MIF control */
369         writel(0, &pRxMac->mif_ctrl.value);
370
371         /* Initialize the Space Available Register */
372         writel(0, &pRxMac->space_avail.value);
373
374         /* Initialize the the mif_ctrl register
375          * bit 3:  Receive code error. One or more nibbles were signaled as
376          *         errors  during the reception of the packet.  Clear this
377          *         bit in Gigabit, set it in 100Mbit.  This was derived
378          *         experimentally at UNH.
379          * bit 4:  Receive CRC error. The packet's CRC did not match the
380          *         internally generated CRC.
381          * bit 5:  Receive length check error. Indicates that frame length
382          *         field value in the packet does not match the actual data
383          *         byte length and is not a type field.
384          * bit 16: Receive frame truncated.
385          * bit 17: Drop packet enable
386          */
387         if (etdev->linkspeed == TRUEPHY_SPEED_100MBPS)
388                 writel(0x30038, &pRxMac->mif_ctrl.value);
389         else
390                 writel(0x30030, &pRxMac->mif_ctrl.value);
391
392         /* Finally we initialize RxMac to be enabled & WOL disabled.  Packet
393          * filter is always enabled since it is where the runt packets are
394          * supposed to be dropped.  For version A silicon, runt packet
395          * dropping doesn't work, so it is disabled in the pf_ctrl register,
396          * but we still leave the packet filter on.
397          */
398         writel(pf_ctrl.value, &pRxMac->pf_ctrl.value);
399         writel(0x9, &pRxMac->ctrl.value);
400 }
401
402 void ConfigTxMacRegs(struct et131x_adapter *etdev)
403 {
404         struct _TXMAC_t __iomem *pTxMac = &etdev->regs->txmac;
405         TXMAC_CF_PARAM_t Local;
406
407         /* We need to update the Control Frame Parameters
408          * cfpt - control frame pause timer set to 64 (0x40)
409          * cfep - control frame extended pause timer set to 0x0
410          */
411         if (etdev->FlowControl == None) {
412                 writel(0, &pTxMac->cf_param.value);
413         } else {
414                 Local.bits.cfpt = 0x40;
415                 Local.bits.cfep = 0x0;
416                 writel(Local.value, &pTxMac->cf_param.value);
417         }
418 }
419
420 void ConfigMacStatRegs(struct et131x_adapter *etdev)
421 {
422         struct _MAC_STAT_t __iomem *pDevMacStat =
423                 &etdev->regs->macStat;
424
425         /* Next we need to initialize all the MAC_STAT registers to zero on
426          * the device.
427          */
428         writel(0, &pDevMacStat->RFcs);
429         writel(0, &pDevMacStat->RAln);
430         writel(0, &pDevMacStat->RFlr);
431         writel(0, &pDevMacStat->RDrp);
432         writel(0, &pDevMacStat->RCde);
433         writel(0, &pDevMacStat->ROvr);
434         writel(0, &pDevMacStat->RFrg);
435
436         writel(0, &pDevMacStat->TScl);
437         writel(0, &pDevMacStat->TDfr);
438         writel(0, &pDevMacStat->TMcl);
439         writel(0, &pDevMacStat->TLcl);
440         writel(0, &pDevMacStat->TNcl);
441         writel(0, &pDevMacStat->TOvr);
442         writel(0, &pDevMacStat->TUnd);
443
444         /* Unmask any counters that we want to track the overflow of.
445          * Initially this will be all counters.  It may become clear later
446          * that we do not need to track all counters.
447          */
448         {
449                 MAC_STAT_REG_1_t Carry1M = { 0xffffffff };
450
451                 Carry1M.bits.rdrp = 0;
452                 Carry1M.bits.rjbr = 1;
453                 Carry1M.bits.rfrg = 0;
454                 Carry1M.bits.rovr = 0;
455                 Carry1M.bits.rund = 1;
456                 Carry1M.bits.rcse = 1;
457                 Carry1M.bits.rcde = 0;
458                 Carry1M.bits.rflr = 0;
459                 Carry1M.bits.raln = 0;
460                 Carry1M.bits.rxuo = 1;
461                 Carry1M.bits.rxpf = 1;
462                 Carry1M.bits.rxcf = 1;
463                 Carry1M.bits.rbca = 1;
464                 Carry1M.bits.rmca = 1;
465                 Carry1M.bits.rfcs = 0;
466                 Carry1M.bits.rpkt = 1;
467                 Carry1M.bits.rbyt = 1;
468                 Carry1M.bits.trmgv = 1;
469                 Carry1M.bits.trmax = 1;
470                 Carry1M.bits.tr1k = 1;
471                 Carry1M.bits.tr511 = 1;
472                 Carry1M.bits.tr255 = 1;
473                 Carry1M.bits.tr127 = 1;
474                 Carry1M.bits.tr64 = 1;
475
476                 writel(Carry1M.value, &pDevMacStat->Carry1M.value);
477         }
478
479         {
480                 MAC_STAT_REG_2_t Carry2M = { 0xffffffff };
481
482                 Carry2M.bits.tdrp = 1;
483                 Carry2M.bits.tpfh = 1;
484                 Carry2M.bits.tncl = 0;
485                 Carry2M.bits.txcl = 1;
486                 Carry2M.bits.tlcl = 0;
487                 Carry2M.bits.tmcl = 0;
488                 Carry2M.bits.tscl = 0;
489                 Carry2M.bits.tedf = 1;
490                 Carry2M.bits.tdfr = 0;
491                 Carry2M.bits.txpf = 1;
492                 Carry2M.bits.tbca = 1;
493                 Carry2M.bits.tmca = 1;
494                 Carry2M.bits.tpkt = 1;
495                 Carry2M.bits.tbyt = 1;
496                 Carry2M.bits.tfrg = 1;
497                 Carry2M.bits.tund = 0;
498                 Carry2M.bits.tovr = 0;
499                 Carry2M.bits.txcf = 1;
500                 Carry2M.bits.tfcs = 1;
501                 Carry2M.bits.tjbr = 1;
502
503                 writel(Carry2M.value, &pDevMacStat->Carry2M.value);
504         }
505 }
506
507 void ConfigFlowControl(struct et131x_adapter *etdev)
508 {
509         if (etdev->duplex_mode == 0) {
510                 etdev->FlowControl = None;
511         } else {
512                 char RemotePause, RemoteAsyncPause;
513
514                 ET1310_PhyAccessMiBit(etdev,
515                                       TRUEPHY_BIT_READ, 5, 10, &RemotePause);
516                 ET1310_PhyAccessMiBit(etdev,
517                                       TRUEPHY_BIT_READ, 5, 11,
518                                       &RemoteAsyncPause);
519
520                 if ((RemotePause == TRUEPHY_BIT_SET) &&
521                     (RemoteAsyncPause == TRUEPHY_BIT_SET)) {
522                         etdev->FlowControl = etdev->RegistryFlowControl;
523                 } else if ((RemotePause == TRUEPHY_BIT_SET) &&
524                            (RemoteAsyncPause == TRUEPHY_BIT_CLEAR)) {
525                         if (etdev->RegistryFlowControl == Both)
526                                 etdev->FlowControl = Both;
527                         else
528                                 etdev->FlowControl = None;
529                 } else if ((RemotePause == TRUEPHY_BIT_CLEAR) &&
530                            (RemoteAsyncPause == TRUEPHY_BIT_CLEAR)) {
531                         etdev->FlowControl = None;
532                 } else {/* if (RemotePause == TRUEPHY_CLEAR_BIT &&
533                                RemoteAsyncPause == TRUEPHY_SET_BIT) */
534                         if (etdev->RegistryFlowControl == Both)
535                                 etdev->FlowControl = RxOnly;
536                         else
537                                 etdev->FlowControl = None;
538                 }
539         }
540 }
541
542 /**
543  * UpdateMacStatHostCounters - Update the local copy of the statistics
544  * @etdev: pointer to the adapter structure
545  */
546 void UpdateMacStatHostCounters(struct et131x_adapter *etdev)
547 {
548         struct _ce_stats_t *stats = &etdev->Stats;
549         struct _MAC_STAT_t __iomem *pDevMacStat =
550                 &etdev->regs->macStat;
551
552         stats->collisions += readl(&pDevMacStat->TNcl);
553         stats->first_collision += readl(&pDevMacStat->TScl);
554         stats->tx_deferred += readl(&pDevMacStat->TDfr);
555         stats->excessive_collisions += readl(&pDevMacStat->TMcl);
556         stats->late_collisions += readl(&pDevMacStat->TLcl);
557         stats->tx_uflo += readl(&pDevMacStat->TUnd);
558         stats->max_pkt_error += readl(&pDevMacStat->TOvr);
559
560         stats->alignment_err += readl(&pDevMacStat->RAln);
561         stats->crc_err += readl(&pDevMacStat->RCde);
562         stats->norcvbuf += readl(&pDevMacStat->RDrp);
563         stats->rx_ov_flow += readl(&pDevMacStat->ROvr);
564         stats->code_violations += readl(&pDevMacStat->RFcs);
565         stats->length_err += readl(&pDevMacStat->RFlr);
566
567         stats->other_errors += readl(&pDevMacStat->RFrg);
568 }
569
570 /**
571  * HandleMacStatInterrupt
572  * @etdev: pointer to the adapter structure
573  *
574  * One of the MACSTAT counters has wrapped.  Update the local copy of
575  * the statistics held in the adapter structure, checking the "wrap"
576  * bit for each counter.
577  */
578 void HandleMacStatInterrupt(struct et131x_adapter *etdev)
579 {
580         MAC_STAT_REG_1_t Carry1;
581         MAC_STAT_REG_2_t Carry2;
582
583         /* Read the interrupt bits from the register(s).  These are Clear On
584          * Write.
585          */
586         Carry1.value = readl(&etdev->regs->macStat.Carry1.value);
587         Carry2.value = readl(&etdev->regs->macStat.Carry2.value);
588
589         writel(Carry1.value, &etdev->regs->macStat.Carry1.value);
590         writel(Carry2.value, &etdev->regs->macStat.Carry2.value);
591
592         /* We need to do update the host copy of all the MAC_STAT counters.
593          * For each counter, check it's overflow bit.  If the overflow bit is
594          * set, then increment the host version of the count by one complete
595          * revolution of the counter.  This routine is called when the counter
596          * block indicates that one of the counters has wrapped.
597          */
598         if (Carry1.bits.rfcs)
599                 etdev->Stats.code_violations += COUNTER_WRAP_16_BIT;
600         if (Carry1.bits.raln)
601                 etdev->Stats.alignment_err += COUNTER_WRAP_12_BIT;
602         if (Carry1.bits.rflr)
603                 etdev->Stats.length_err += COUNTER_WRAP_16_BIT;
604         if (Carry1.bits.rfrg)
605                 etdev->Stats.other_errors += COUNTER_WRAP_16_BIT;
606         if (Carry1.bits.rcde)
607                 etdev->Stats.crc_err += COUNTER_WRAP_16_BIT;
608         if (Carry1.bits.rovr)
609                 etdev->Stats.rx_ov_flow += COUNTER_WRAP_16_BIT;
610         if (Carry1.bits.rdrp)
611                 etdev->Stats.norcvbuf += COUNTER_WRAP_16_BIT;
612         if (Carry2.bits.tovr)
613                 etdev->Stats.max_pkt_error += COUNTER_WRAP_12_BIT;
614         if (Carry2.bits.tund)
615                 etdev->Stats.tx_uflo += COUNTER_WRAP_12_BIT;
616         if (Carry2.bits.tscl)
617                 etdev->Stats.first_collision += COUNTER_WRAP_12_BIT;
618         if (Carry2.bits.tdfr)
619                 etdev->Stats.tx_deferred += COUNTER_WRAP_12_BIT;
620         if (Carry2.bits.tmcl)
621                 etdev->Stats.excessive_collisions += COUNTER_WRAP_12_BIT;
622         if (Carry2.bits.tlcl)
623                 etdev->Stats.late_collisions += COUNTER_WRAP_12_BIT;
624         if (Carry2.bits.tncl)
625                 etdev->Stats.collisions += COUNTER_WRAP_12_BIT;
626 }
627
628 void SetupDeviceForMulticast(struct et131x_adapter *etdev)
629 {
630         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
631         uint32_t nIndex;
632         uint32_t result;
633         uint32_t hash1 = 0;
634         uint32_t hash2 = 0;
635         uint32_t hash3 = 0;
636         uint32_t hash4 = 0;
637         u32 pm_csr;
638
639         /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision
640          * the multi-cast LIST.  If it is NOT specified, (and "ALL" is not
641          * specified) then we should pass NO multi-cast addresses to the
642          * driver.
643          */
644         if (etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) {
645                 /* Loop through our multicast array and set up the device */
646                 for (nIndex = 0; nIndex < etdev->MCAddressCount; nIndex++) {
647                         result = ether_crc(6, etdev->MCList[nIndex]);
648
649                         result = (result & 0x3F800000) >> 23;
650
651                         if (result < 32) {
652                                 hash1 |= (1 << result);
653                         } else if ((31 < result) && (result < 64)) {
654                                 result -= 32;
655                                 hash2 |= (1 << result);
656                         } else if ((63 < result) && (result < 96)) {
657                                 result -= 64;
658                                 hash3 |= (1 << result);
659                         } else {
660                                 result -= 96;
661                                 hash4 |= (1 << result);
662                         }
663                 }
664         }
665
666         /* Write out the new hash to the device */
667         pm_csr = readl(&etdev->regs->global.pm_csr);
668         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
669                 writel(hash1, &rxmac->multi_hash1);
670                 writel(hash2, &rxmac->multi_hash2);
671                 writel(hash3, &rxmac->multi_hash3);
672                 writel(hash4, &rxmac->multi_hash4);
673         }
674 }
675
676 void SetupDeviceForUnicast(struct et131x_adapter *etdev)
677 {
678         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
679         RXMAC_UNI_PF_ADDR1_t uni_pf1;
680         RXMAC_UNI_PF_ADDR2_t uni_pf2;
681         RXMAC_UNI_PF_ADDR3_t uni_pf3;
682         u32 pm_csr;
683
684         /* Set up unicast packet filter reg 3 to be the first two octets of
685          * the MAC address for both address
686          *
687          * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the
688          * MAC address for second address
689          *
690          * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
691          * MAC address for first address
692          */
693         uni_pf3.bits.addr1_1 = etdev->CurrentAddress[0];
694         uni_pf3.bits.addr1_2 = etdev->CurrentAddress[1];
695         uni_pf3.bits.addr2_1 = etdev->CurrentAddress[0];
696         uni_pf3.bits.addr2_2 = etdev->CurrentAddress[1];
697
698         uni_pf2.bits.addr2_3 = etdev->CurrentAddress[2];
699         uni_pf2.bits.addr2_4 = etdev->CurrentAddress[3];
700         uni_pf2.bits.addr2_5 = etdev->CurrentAddress[4];
701         uni_pf2.bits.addr2_6 = etdev->CurrentAddress[5];
702
703         uni_pf1.bits.addr1_3 = etdev->CurrentAddress[2];
704         uni_pf1.bits.addr1_4 = etdev->CurrentAddress[3];
705         uni_pf1.bits.addr1_5 = etdev->CurrentAddress[4];
706         uni_pf1.bits.addr1_6 = etdev->CurrentAddress[5];
707
708         pm_csr = readl(&etdev->regs->global.pm_csr);
709         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
710                 writel(uni_pf1.value, &rxmac->uni_pf_addr1.value);
711                 writel(uni_pf2.value, &rxmac->uni_pf_addr2.value);
712                 writel(uni_pf3.value, &rxmac->uni_pf_addr3.value);
713         }
714 }