Staging: et131x: Kill rxmac crc fields
[pandora-kernel.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 "et131x_adapter.h"
89 #include "et131x.h"
90
91
92 #define COUNTER_WRAP_28_BIT 0x10000000
93 #define COUNTER_WRAP_22_BIT 0x400000
94 #define COUNTER_WRAP_16_BIT 0x10000
95 #define COUNTER_WRAP_12_BIT 0x1000
96
97 #define COUNTER_MASK_28_BIT (COUNTER_WRAP_28_BIT - 1)
98 #define COUNTER_MASK_22_BIT (COUNTER_WRAP_22_BIT - 1)
99 #define COUNTER_MASK_16_BIT (COUNTER_WRAP_16_BIT - 1)
100 #define COUNTER_MASK_12_BIT (COUNTER_WRAP_12_BIT - 1)
101
102 /**
103  * ConfigMacRegs1 - Initialize the first part of MAC regs
104  * @pAdpater: pointer to our adapter structure
105  */
106 void ConfigMACRegs1(struct et131x_adapter *etdev)
107 {
108         struct _MAC_t __iomem *pMac = &etdev->regs->mac;
109         MAC_STATION_ADDR1_t station1;
110         MAC_STATION_ADDR2_t station2;
111         u32 ipg;
112
113         /* First we need to reset everything.  Write to MAC configuration
114          * register 1 to perform reset.
115          */
116         writel(0xC00F0000, &pMac->cfg1);
117
118         /* Next lets configure the MAC Inter-packet gap register */
119         ipg = 0x38005860;               /* IPG1 0x38 IPG2 0x58 B2B 0x60 */
120         ipg |= 0x50 << 8;               /* ifg enforce 0x50 */
121         writel(ipg, &pMac->ipg);
122
123         /* Next lets configure the MAC Half Duplex register */
124         /* BEB trunc 0xA, Ex Defer, Rexmit 0xF Coll 0x37 */
125         writel(0x00A1F037, &pMac->hfdp);
126
127         /* Next lets configure the MAC Interface Control register */
128         writel(0, &pMac->if_ctrl);
129
130         /* Let's move on to setting up the mii management configuration */
131         writel(0x07, &pMac->mii_mgmt_cfg);      /* Clock reset 0x7 */
132
133         /* Next lets configure the MAC Station Address register.  These
134          * values are read from the EEPROM during initialization and stored
135          * in the adapter structure.  We write what is stored in the adapter
136          * structure to the MAC Station Address registers high and low.  This
137          * station address is used for generating and checking pause control
138          * packets.
139          */
140         station2.bits.Octet1 = etdev->CurrentAddress[0];
141         station2.bits.Octet2 = etdev->CurrentAddress[1];
142         station1.bits.Octet3 = etdev->CurrentAddress[2];
143         station1.bits.Octet4 = etdev->CurrentAddress[3];
144         station1.bits.Octet5 = etdev->CurrentAddress[4];
145         station1.bits.Octet6 = etdev->CurrentAddress[5];
146         writel(station1.value, &pMac->station_addr_1.value);
147         writel(station2.value, &pMac->station_addr_2.value);
148
149         /* Max ethernet packet in bytes that will passed by the mac without
150          * being truncated.  Allow the MAC to pass 4 more than our max packet
151          * size.  This is 4 for the Ethernet CRC.
152          *
153          * Packets larger than (RegistryJumboPacket) that do not contain a
154          * VLAN ID will be dropped by the Rx function.
155          */
156         writel(etdev->RegistryJumboPacket + 4, &pMac->max_fm_len);
157
158         /* clear out MAC config reset */
159         writel(0, &pMac->cfg1);
160 }
161
162 /**
163  * ConfigMacRegs2 - Initialize the second part of MAC regs
164  * @pAdpater: pointer to our adapter structure
165  */
166 void ConfigMACRegs2(struct et131x_adapter *etdev)
167 {
168         int32_t delay = 0;
169         struct _MAC_t __iomem *pMac = &etdev->regs->mac;
170         u32 cfg1;
171         u32 cfg2;
172         u32 ifctrl;
173         u32 ctl;
174
175         ctl = readl(&etdev->regs->txmac.ctl);
176         cfg1 = readl(&pMac->cfg1);
177         cfg2 = readl(&pMac->cfg2);
178         ifctrl = readl(&pMac->if_ctrl);
179
180         /* Set up the if mode bits */
181         cfg2 &= ~0x300;
182         if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) {
183                 cfg2 |= 0x200;
184                 /* Phy mode bit */
185                 ifctrl &= ~(1 << 24);
186         } else {
187                 cfg2 |= 0x100;
188                 ifctrl |= (1 << 24);
189         }
190
191         /* We need to enable Rx/Tx */
192         cfg1 |= CFG1_RX_ENABLE|CFG1_TX_ENABLE|CFG1_TX_FLOW;
193         /* Initialize loop back to off */
194         cfg1 &= ~(CFG1_LOOPBACK|CFG1_RX_FLOW);
195         if (etdev->FlowControl == RxOnly || etdev->FlowControl == Both)
196                 cfg1 |= CFG1_RX_FLOW;
197         writel(cfg1, &pMac->cfg1);
198
199         /* Now we need to initialize the MAC Configuration 2 register */
200         /* preamble 7, check length, huge frame off, pad crc, crc enable
201            full duplex off */
202         cfg2 |= 0x7016;
203         cfg2 &= ~0x0021;
204
205         /* Turn on duplex if needed */
206         if (etdev->duplex_mode)
207                 cfg2 |= 0x01;
208
209         ifctrl &= ~(1 << 26);
210         if (!etdev->duplex_mode)
211                 ifctrl |= (1<<26);      /* Enable ghd */
212
213         writel(ifctrl, &pMac->if_ctrl);
214         writel(cfg2, &pMac->cfg2);
215
216         do {
217                 udelay(10);
218                 delay++;
219                 cfg1 = readl(&pMac->cfg1);
220         } while ((cfg1 & CFG1_WAIT) != CFG1_WAIT && delay < 100);
221
222         if (delay == 100) {
223                 dev_warn(&etdev->pdev->dev,
224                     "Syncd bits did not respond correctly cfg1 word 0x%08x\n",
225                         cfg1);
226         }
227
228         /* Enable TXMAC */
229         ctl |= 0x05;    /* TX mac enable, FC disable */
230         writel(ctl, &etdev->regs->txmac.ctl);
231
232         /* Ready to start the RXDMA/TXDMA engine */
233         if (etdev->Flags & fMP_ADAPTER_LOWER_POWER) {
234                 et131x_rx_dma_enable(etdev);
235                 et131x_tx_dma_enable(etdev);
236         }
237 }
238
239 void ConfigRxMacRegs(struct et131x_adapter *etdev)
240 {
241         struct _RXMAC_t __iomem *pRxMac = &etdev->regs->rxmac;
242         RXMAC_WOL_SA_LO_t sa_lo;
243         RXMAC_WOL_SA_HI_t sa_hi;
244         RXMAC_PF_CTRL_t pf_ctrl = { 0 };
245
246         /* Disable the MAC while it is being configured (also disable WOL) */
247         writel(0x8, &pRxMac->ctrl.value);
248
249         /* Initialize WOL to disabled. */
250         writel(0, &pRxMac->crc0);
251         writel(0, &pRxMac->crc12);
252         writel(0, &pRxMac->crc34);
253
254         /* We need to set the WOL mask0 - mask4 next.  We initialize it to
255          * its default Values of 0x00000000 because there are not WOL masks
256          * as of this time.
257          */
258         writel(0, &pRxMac->mask0_word0);
259         writel(0, &pRxMac->mask0_word1);
260         writel(0, &pRxMac->mask0_word2);
261         writel(0, &pRxMac->mask0_word3);
262
263         writel(0, &pRxMac->mask1_word0);
264         writel(0, &pRxMac->mask1_word1);
265         writel(0, &pRxMac->mask1_word2);
266         writel(0, &pRxMac->mask1_word3);
267
268         writel(0, &pRxMac->mask2_word0);
269         writel(0, &pRxMac->mask2_word1);
270         writel(0, &pRxMac->mask2_word2);
271         writel(0, &pRxMac->mask2_word3);
272
273         writel(0, &pRxMac->mask3_word0);
274         writel(0, &pRxMac->mask3_word1);
275         writel(0, &pRxMac->mask3_word2);
276         writel(0, &pRxMac->mask3_word3);
277
278         writel(0, &pRxMac->mask4_word0);
279         writel(0, &pRxMac->mask4_word1);
280         writel(0, &pRxMac->mask4_word2);
281         writel(0, &pRxMac->mask4_word3);
282
283         /* Lets setup the WOL Source Address */
284         sa_lo.bits.sa3 = etdev->CurrentAddress[2];
285         sa_lo.bits.sa4 = etdev->CurrentAddress[3];
286         sa_lo.bits.sa5 = etdev->CurrentAddress[4];
287         sa_lo.bits.sa6 = etdev->CurrentAddress[5];
288         writel(sa_lo.value, &pRxMac->sa_lo.value);
289
290         sa_hi.bits.sa1 = etdev->CurrentAddress[0];
291         sa_hi.bits.sa2 = etdev->CurrentAddress[1];
292         writel(sa_hi.value, &pRxMac->sa_hi.value);
293
294         /* Disable all Packet Filtering */
295         writel(0, &pRxMac->pf_ctrl.value);
296
297         /* Let's initialize the Unicast Packet filtering address */
298         if (etdev->PacketFilter & ET131X_PACKET_TYPE_DIRECTED) {
299                 SetupDeviceForUnicast(etdev);
300                 pf_ctrl.bits.filter_uni_en = 1;
301         } else {
302                 writel(0, &pRxMac->uni_pf_addr1.value);
303                 writel(0, &pRxMac->uni_pf_addr2.value);
304                 writel(0, &pRxMac->uni_pf_addr3.value);
305         }
306
307         /* Let's initialize the Multicast hash */
308         if (etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST) {
309                 pf_ctrl.bits.filter_multi_en = 0;
310         } else {
311                 pf_ctrl.bits.filter_multi_en = 1;
312                 SetupDeviceForMulticast(etdev);
313         }
314
315         /* Runt packet filtering.  Didn't work in version A silicon. */
316         pf_ctrl.bits.min_pkt_size = NIC_MIN_PACKET_SIZE + 4;
317         pf_ctrl.bits.filter_frag_en = 1;
318
319         if (etdev->RegistryJumboPacket > 8192) {
320                 RXMAC_MCIF_CTRL_MAX_SEG_t mcif_ctrl_max_seg;
321
322                 /* In order to transmit jumbo packets greater than 8k, the
323                  * FIFO between RxMAC and RxDMA needs to be reduced in size
324                  * to (16k - Jumbo packet size).  In order to implement this,
325                  * we must use "cut through" mode in the RxMAC, which chops
326                  * packets down into segments which are (max_size * 16).  In
327                  * this case we selected 256 bytes, since this is the size of
328                  * the PCI-Express TLP's that the 1310 uses.
329                  */
330                 mcif_ctrl_max_seg.bits.seg_en = 0x1;
331                 mcif_ctrl_max_seg.bits.fc_en = 0x0;
332                 mcif_ctrl_max_seg.bits.max_size = 0x10;
333
334                 writel(mcif_ctrl_max_seg.value,
335                        &pRxMac->mcif_ctrl_max_seg.value);
336         } else {
337                 writel(0, &pRxMac->mcif_ctrl_max_seg.value);
338         }
339
340         /* Initialize the MCIF water marks */
341         writel(0, &pRxMac->mcif_water_mark.value);
342
343         /*  Initialize the MIF control */
344         writel(0, &pRxMac->mif_ctrl.value);
345
346         /* Initialize the Space Available Register */
347         writel(0, &pRxMac->space_avail.value);
348
349         /* Initialize the the mif_ctrl register
350          * bit 3:  Receive code error. One or more nibbles were signaled as
351          *         errors  during the reception of the packet.  Clear this
352          *         bit in Gigabit, set it in 100Mbit.  This was derived
353          *         experimentally at UNH.
354          * bit 4:  Receive CRC error. The packet's CRC did not match the
355          *         internally generated CRC.
356          * bit 5:  Receive length check error. Indicates that frame length
357          *         field value in the packet does not match the actual data
358          *         byte length and is not a type field.
359          * bit 16: Receive frame truncated.
360          * bit 17: Drop packet enable
361          */
362         if (etdev->linkspeed == TRUEPHY_SPEED_100MBPS)
363                 writel(0x30038, &pRxMac->mif_ctrl.value);
364         else
365                 writel(0x30030, &pRxMac->mif_ctrl.value);
366
367         /* Finally we initialize RxMac to be enabled & WOL disabled.  Packet
368          * filter is always enabled since it is where the runt packets are
369          * supposed to be dropped.  For version A silicon, runt packet
370          * dropping doesn't work, so it is disabled in the pf_ctrl register,
371          * but we still leave the packet filter on.
372          */
373         writel(pf_ctrl.value, &pRxMac->pf_ctrl.value);
374         writel(0x9, &pRxMac->ctrl.value);
375 }
376
377 void ConfigTxMacRegs(struct et131x_adapter *etdev)
378 {
379         struct txmac_regs *txmac = &etdev->regs->txmac;
380
381         /* We need to update the Control Frame Parameters
382          * cfpt - control frame pause timer set to 64 (0x40)
383          * cfep - control frame extended pause timer set to 0x0
384          */
385         if (etdev->FlowControl == None)
386                 writel(0, &txmac->cf_param);
387         else
388                 writel(0x40, &txmac->cf_param);
389 }
390
391 void ConfigMacStatRegs(struct et131x_adapter *etdev)
392 {
393         struct macstat_regs __iomem *macstat =
394                 &etdev->regs->macstat;
395
396         /* Next we need to initialize all the MAC_STAT registers to zero on
397          * the device.
398          */
399         writel(0, &macstat->RFcs);
400         writel(0, &macstat->RAln);
401         writel(0, &macstat->RFlr);
402         writel(0, &macstat->RDrp);
403         writel(0, &macstat->RCde);
404         writel(0, &macstat->ROvr);
405         writel(0, &macstat->RFrg);
406
407         writel(0, &macstat->TScl);
408         writel(0, &macstat->TDfr);
409         writel(0, &macstat->TMcl);
410         writel(0, &macstat->TLcl);
411         writel(0, &macstat->TNcl);
412         writel(0, &macstat->TOvr);
413         writel(0, &macstat->TUnd);
414
415         /* Unmask any counters that we want to track the overflow of.
416          * Initially this will be all counters.  It may become clear later
417          * that we do not need to track all counters.
418          */
419         writel(0xFFFFBE32, &macstat->Carry1M);
420         writel(0xFFFE7E8B, &macstat->Carry2M);
421 }
422
423 void ConfigFlowControl(struct et131x_adapter *etdev)
424 {
425         if (etdev->duplex_mode == 0) {
426                 etdev->FlowControl = None;
427         } else {
428                 char remote_pause, remote_async_pause;
429
430                 ET1310_PhyAccessMiBit(etdev,
431                                       TRUEPHY_BIT_READ, 5, 10, &remote_pause);
432                 ET1310_PhyAccessMiBit(etdev,
433                                       TRUEPHY_BIT_READ, 5, 11,
434                                       &remote_async_pause);
435
436                 if ((remote_pause == TRUEPHY_BIT_SET) &&
437                     (remote_async_pause == TRUEPHY_BIT_SET)) {
438                         etdev->FlowControl = etdev->RegistryFlowControl;
439                 } else if ((remote_pause == TRUEPHY_BIT_SET) &&
440                            (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
441                         if (etdev->RegistryFlowControl == Both)
442                                 etdev->FlowControl = Both;
443                         else
444                                 etdev->FlowControl = None;
445                 } else if ((remote_pause == TRUEPHY_BIT_CLEAR) &&
446                            (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
447                         etdev->FlowControl = None;
448                 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT &&
449                                remote_async_pause == TRUEPHY_SET_BIT) */
450                         if (etdev->RegistryFlowControl == Both)
451                                 etdev->FlowControl = RxOnly;
452                         else
453                                 etdev->FlowControl = None;
454                 }
455         }
456 }
457
458 /**
459  * UpdateMacStatHostCounters - Update the local copy of the statistics
460  * @etdev: pointer to the adapter structure
461  */
462 void UpdateMacStatHostCounters(struct et131x_adapter *etdev)
463 {
464         struct _ce_stats_t *stats = &etdev->Stats;
465         struct macstat_regs __iomem *macstat =
466                 &etdev->regs->macstat;
467
468         stats->collisions += readl(&macstat->TNcl);
469         stats->first_collision += readl(&macstat->TScl);
470         stats->tx_deferred += readl(&macstat->TDfr);
471         stats->excessive_collisions += readl(&macstat->TMcl);
472         stats->late_collisions += readl(&macstat->TLcl);
473         stats->tx_uflo += readl(&macstat->TUnd);
474         stats->max_pkt_error += readl(&macstat->TOvr);
475
476         stats->alignment_err += readl(&macstat->RAln);
477         stats->crc_err += readl(&macstat->RCde);
478         stats->norcvbuf += readl(&macstat->RDrp);
479         stats->rx_ov_flow += readl(&macstat->ROvr);
480         stats->code_violations += readl(&macstat->RFcs);
481         stats->length_err += readl(&macstat->RFlr);
482
483         stats->other_errors += readl(&macstat->RFrg);
484 }
485
486 /**
487  * HandleMacStatInterrupt
488  * @etdev: pointer to the adapter structure
489  *
490  * One of the MACSTAT counters has wrapped.  Update the local copy of
491  * the statistics held in the adapter structure, checking the "wrap"
492  * bit for each counter.
493  */
494 void HandleMacStatInterrupt(struct et131x_adapter *etdev)
495 {
496         u32 Carry1;
497         u32 Carry2;
498
499         /* Read the interrupt bits from the register(s).  These are Clear On
500          * Write.
501          */
502         Carry1 = readl(&etdev->regs->macstat.Carry1);
503         Carry2 = readl(&etdev->regs->macstat.Carry2);
504
505         writel(Carry1, &etdev->regs->macstat.Carry1);
506         writel(Carry2, &etdev->regs->macstat.Carry2);
507
508         /* We need to do update the host copy of all the MAC_STAT counters.
509          * For each counter, check it's overflow bit.  If the overflow bit is
510          * set, then increment the host version of the count by one complete
511          * revolution of the counter.  This routine is called when the counter
512          * block indicates that one of the counters has wrapped.
513          */
514         if (Carry1 & (1 << 14))
515                 etdev->Stats.code_violations += COUNTER_WRAP_16_BIT;
516         if (Carry1 & (1 << 8))
517                 etdev->Stats.alignment_err += COUNTER_WRAP_12_BIT;
518         if (Carry1 & (1 << 7))
519                 etdev->Stats.length_err += COUNTER_WRAP_16_BIT;
520         if (Carry1 & (1 << 2))
521                 etdev->Stats.other_errors += COUNTER_WRAP_16_BIT;
522         if (Carry1 & (1 << 6))
523                 etdev->Stats.crc_err += COUNTER_WRAP_16_BIT;
524         if (Carry1 & (1 << 3))
525                 etdev->Stats.rx_ov_flow += COUNTER_WRAP_16_BIT;
526         if (Carry1 & (1 << 0))
527                 etdev->Stats.norcvbuf += COUNTER_WRAP_16_BIT;
528         if (Carry2 & (1 << 16))
529                 etdev->Stats.max_pkt_error += COUNTER_WRAP_12_BIT;
530         if (Carry2 & (1 << 15))
531                 etdev->Stats.tx_uflo += COUNTER_WRAP_12_BIT;
532         if (Carry2 & (1 << 6))
533                 etdev->Stats.first_collision += COUNTER_WRAP_12_BIT;
534         if (Carry2 & (1 << 8))
535                 etdev->Stats.tx_deferred += COUNTER_WRAP_12_BIT;
536         if (Carry2 & (1 << 5))
537                 etdev->Stats.excessive_collisions += COUNTER_WRAP_12_BIT;
538         if (Carry2 & (1 << 4))
539                 etdev->Stats.late_collisions += COUNTER_WRAP_12_BIT;
540         if (Carry2 & (1 << 2))
541                 etdev->Stats.collisions += COUNTER_WRAP_12_BIT;
542 }
543
544 void SetupDeviceForMulticast(struct et131x_adapter *etdev)
545 {
546         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
547         uint32_t nIndex;
548         uint32_t result;
549         uint32_t hash1 = 0;
550         uint32_t hash2 = 0;
551         uint32_t hash3 = 0;
552         uint32_t hash4 = 0;
553         u32 pm_csr;
554
555         /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision
556          * the multi-cast LIST.  If it is NOT specified, (and "ALL" is not
557          * specified) then we should pass NO multi-cast addresses to the
558          * driver.
559          */
560         if (etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) {
561                 /* Loop through our multicast array and set up the device */
562                 for (nIndex = 0; nIndex < etdev->MCAddressCount; nIndex++) {
563                         result = ether_crc(6, etdev->MCList[nIndex]);
564
565                         result = (result & 0x3F800000) >> 23;
566
567                         if (result < 32) {
568                                 hash1 |= (1 << result);
569                         } else if ((31 < result) && (result < 64)) {
570                                 result -= 32;
571                                 hash2 |= (1 << result);
572                         } else if ((63 < result) && (result < 96)) {
573                                 result -= 64;
574                                 hash3 |= (1 << result);
575                         } else {
576                                 result -= 96;
577                                 hash4 |= (1 << result);
578                         }
579                 }
580         }
581
582         /* Write out the new hash to the device */
583         pm_csr = readl(&etdev->regs->global.pm_csr);
584         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
585                 writel(hash1, &rxmac->multi_hash1);
586                 writel(hash2, &rxmac->multi_hash2);
587                 writel(hash3, &rxmac->multi_hash3);
588                 writel(hash4, &rxmac->multi_hash4);
589         }
590 }
591
592 void SetupDeviceForUnicast(struct et131x_adapter *etdev)
593 {
594         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
595         RXMAC_UNI_PF_ADDR1_t uni_pf1;
596         RXMAC_UNI_PF_ADDR2_t uni_pf2;
597         RXMAC_UNI_PF_ADDR3_t uni_pf3;
598         u32 pm_csr;
599
600         /* Set up unicast packet filter reg 3 to be the first two octets of
601          * the MAC address for both address
602          *
603          * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the
604          * MAC address for second address
605          *
606          * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
607          * MAC address for first address
608          */
609         uni_pf3.bits.addr1_1 = etdev->CurrentAddress[0];
610         uni_pf3.bits.addr1_2 = etdev->CurrentAddress[1];
611         uni_pf3.bits.addr2_1 = etdev->CurrentAddress[0];
612         uni_pf3.bits.addr2_2 = etdev->CurrentAddress[1];
613
614         uni_pf2.bits.addr2_3 = etdev->CurrentAddress[2];
615         uni_pf2.bits.addr2_4 = etdev->CurrentAddress[3];
616         uni_pf2.bits.addr2_5 = etdev->CurrentAddress[4];
617         uni_pf2.bits.addr2_6 = etdev->CurrentAddress[5];
618
619         uni_pf1.bits.addr1_3 = etdev->CurrentAddress[2];
620         uni_pf1.bits.addr1_4 = etdev->CurrentAddress[3];
621         uni_pf1.bits.addr1_5 = etdev->CurrentAddress[4];
622         uni_pf1.bits.addr1_6 = etdev->CurrentAddress[5];
623
624         pm_csr = readl(&etdev->regs->global.pm_csr);
625         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
626                 writel(uni_pf1.value, &rxmac->uni_pf_addr1.value);
627                 writel(uni_pf2.value, &rxmac->uni_pf_addr2.value);
628                 writel(uni_pf3.value, &rxmac->uni_pf_addr3.value);
629         }
630 }