drm/radeon/kms: enable use of unmappable VRAM V2
[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         u32 pf_ctrl = 0;
245
246         /* Disable the MAC while it is being configured (also disable WOL) */
247         writel(0x8, &pRxMac->ctrl);
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);
296
297         /* Let's initialize the Unicast Packet filtering address */
298         if (etdev->PacketFilter & ET131X_PACKET_TYPE_DIRECTED) {
299                 SetupDeviceForUnicast(etdev);
300                 pf_ctrl |= 4;   /* Unicast filter */
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 |= 2;   /* Multicast filter */
310                 SetupDeviceForMulticast(etdev);
311         }
312
313         /* Runt packet filtering.  Didn't work in version A silicon. */
314         pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << 16;
315         pf_ctrl |= 8;   /* Fragment filter */
316
317         if (etdev->RegistryJumboPacket > 8192)
318                 /* In order to transmit jumbo packets greater than 8k, the
319                  * FIFO between RxMAC and RxDMA needs to be reduced in size
320                  * to (16k - Jumbo packet size).  In order to implement this,
321                  * we must use "cut through" mode in the RxMAC, which chops
322                  * packets down into segments which are (max_size * 16).  In
323                  * this case we selected 256 bytes, since this is the size of
324                  * the PCI-Express TLP's that the 1310 uses.
325                  *
326                  * seg_en on, fc_en off, size 0x10
327                  */
328                 writel(0x41, &pRxMac->mcif_ctrl_max_seg);
329         else
330                 writel(0, &pRxMac->mcif_ctrl_max_seg);
331
332         /* Initialize the MCIF water marks */
333         writel(0, &pRxMac->mcif_water_mark);
334
335         /*  Initialize the MIF control */
336         writel(0, &pRxMac->mif_ctrl);
337
338         /* Initialize the Space Available Register */
339         writel(0, &pRxMac->space_avail);
340
341         /* Initialize the the mif_ctrl register
342          * bit 3:  Receive code error. One or more nibbles were signaled as
343          *         errors  during the reception of the packet.  Clear this
344          *         bit in Gigabit, set it in 100Mbit.  This was derived
345          *         experimentally at UNH.
346          * bit 4:  Receive CRC error. The packet's CRC did not match the
347          *         internally generated CRC.
348          * bit 5:  Receive length check error. Indicates that frame length
349          *         field value in the packet does not match the actual data
350          *         byte length and is not a type field.
351          * bit 16: Receive frame truncated.
352          * bit 17: Drop packet enable
353          */
354         if (etdev->linkspeed == TRUEPHY_SPEED_100MBPS)
355                 writel(0x30038, &pRxMac->mif_ctrl);
356         else
357                 writel(0x30030, &pRxMac->mif_ctrl);
358
359         /* Finally we initialize RxMac to be enabled & WOL disabled.  Packet
360          * filter is always enabled since it is where the runt packets are
361          * supposed to be dropped.  For version A silicon, runt packet
362          * dropping doesn't work, so it is disabled in the pf_ctrl register,
363          * but we still leave the packet filter on.
364          */
365         writel(pf_ctrl, &pRxMac->pf_ctrl);
366         writel(0x9, &pRxMac->ctrl);
367 }
368
369 void ConfigTxMacRegs(struct et131x_adapter *etdev)
370 {
371         struct txmac_regs *txmac = &etdev->regs->txmac;
372
373         /* We need to update the Control Frame Parameters
374          * cfpt - control frame pause timer set to 64 (0x40)
375          * cfep - control frame extended pause timer set to 0x0
376          */
377         if (etdev->FlowControl == None)
378                 writel(0, &txmac->cf_param);
379         else
380                 writel(0x40, &txmac->cf_param);
381 }
382
383 void ConfigMacStatRegs(struct et131x_adapter *etdev)
384 {
385         struct macstat_regs __iomem *macstat =
386                 &etdev->regs->macstat;
387
388         /* Next we need to initialize all the MAC_STAT registers to zero on
389          * the device.
390          */
391         writel(0, &macstat->RFcs);
392         writel(0, &macstat->RAln);
393         writel(0, &macstat->RFlr);
394         writel(0, &macstat->RDrp);
395         writel(0, &macstat->RCde);
396         writel(0, &macstat->ROvr);
397         writel(0, &macstat->RFrg);
398
399         writel(0, &macstat->TScl);
400         writel(0, &macstat->TDfr);
401         writel(0, &macstat->TMcl);
402         writel(0, &macstat->TLcl);
403         writel(0, &macstat->TNcl);
404         writel(0, &macstat->TOvr);
405         writel(0, &macstat->TUnd);
406
407         /* Unmask any counters that we want to track the overflow of.
408          * Initially this will be all counters.  It may become clear later
409          * that we do not need to track all counters.
410          */
411         writel(0xFFFFBE32, &macstat->Carry1M);
412         writel(0xFFFE7E8B, &macstat->Carry2M);
413 }
414
415 void ConfigFlowControl(struct et131x_adapter *etdev)
416 {
417         if (etdev->duplex_mode == 0) {
418                 etdev->FlowControl = None;
419         } else {
420                 char remote_pause, remote_async_pause;
421
422                 ET1310_PhyAccessMiBit(etdev,
423                                       TRUEPHY_BIT_READ, 5, 10, &remote_pause);
424                 ET1310_PhyAccessMiBit(etdev,
425                                       TRUEPHY_BIT_READ, 5, 11,
426                                       &remote_async_pause);
427
428                 if ((remote_pause == TRUEPHY_BIT_SET) &&
429                     (remote_async_pause == TRUEPHY_BIT_SET)) {
430                         etdev->FlowControl = etdev->RegistryFlowControl;
431                 } else if ((remote_pause == TRUEPHY_BIT_SET) &&
432                            (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
433                         if (etdev->RegistryFlowControl == Both)
434                                 etdev->FlowControl = Both;
435                         else
436                                 etdev->FlowControl = None;
437                 } else if ((remote_pause == TRUEPHY_BIT_CLEAR) &&
438                            (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
439                         etdev->FlowControl = None;
440                 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT &&
441                                remote_async_pause == TRUEPHY_SET_BIT) */
442                         if (etdev->RegistryFlowControl == Both)
443                                 etdev->FlowControl = RxOnly;
444                         else
445                                 etdev->FlowControl = None;
446                 }
447         }
448 }
449
450 /**
451  * UpdateMacStatHostCounters - Update the local copy of the statistics
452  * @etdev: pointer to the adapter structure
453  */
454 void UpdateMacStatHostCounters(struct et131x_adapter *etdev)
455 {
456         struct _ce_stats_t *stats = &etdev->Stats;
457         struct macstat_regs __iomem *macstat =
458                 &etdev->regs->macstat;
459
460         stats->collisions += readl(&macstat->TNcl);
461         stats->first_collision += readl(&macstat->TScl);
462         stats->tx_deferred += readl(&macstat->TDfr);
463         stats->excessive_collisions += readl(&macstat->TMcl);
464         stats->late_collisions += readl(&macstat->TLcl);
465         stats->tx_uflo += readl(&macstat->TUnd);
466         stats->max_pkt_error += readl(&macstat->TOvr);
467
468         stats->alignment_err += readl(&macstat->RAln);
469         stats->crc_err += readl(&macstat->RCde);
470         stats->norcvbuf += readl(&macstat->RDrp);
471         stats->rx_ov_flow += readl(&macstat->ROvr);
472         stats->code_violations += readl(&macstat->RFcs);
473         stats->length_err += readl(&macstat->RFlr);
474
475         stats->other_errors += readl(&macstat->RFrg);
476 }
477
478 /**
479  * HandleMacStatInterrupt
480  * @etdev: pointer to the adapter structure
481  *
482  * One of the MACSTAT counters has wrapped.  Update the local copy of
483  * the statistics held in the adapter structure, checking the "wrap"
484  * bit for each counter.
485  */
486 void HandleMacStatInterrupt(struct et131x_adapter *etdev)
487 {
488         u32 Carry1;
489         u32 Carry2;
490
491         /* Read the interrupt bits from the register(s).  These are Clear On
492          * Write.
493          */
494         Carry1 = readl(&etdev->regs->macstat.Carry1);
495         Carry2 = readl(&etdev->regs->macstat.Carry2);
496
497         writel(Carry1, &etdev->regs->macstat.Carry1);
498         writel(Carry2, &etdev->regs->macstat.Carry2);
499
500         /* We need to do update the host copy of all the MAC_STAT counters.
501          * For each counter, check it's overflow bit.  If the overflow bit is
502          * set, then increment the host version of the count by one complete
503          * revolution of the counter.  This routine is called when the counter
504          * block indicates that one of the counters has wrapped.
505          */
506         if (Carry1 & (1 << 14))
507                 etdev->Stats.code_violations += COUNTER_WRAP_16_BIT;
508         if (Carry1 & (1 << 8))
509                 etdev->Stats.alignment_err += COUNTER_WRAP_12_BIT;
510         if (Carry1 & (1 << 7))
511                 etdev->Stats.length_err += COUNTER_WRAP_16_BIT;
512         if (Carry1 & (1 << 2))
513                 etdev->Stats.other_errors += COUNTER_WRAP_16_BIT;
514         if (Carry1 & (1 << 6))
515                 etdev->Stats.crc_err += COUNTER_WRAP_16_BIT;
516         if (Carry1 & (1 << 3))
517                 etdev->Stats.rx_ov_flow += COUNTER_WRAP_16_BIT;
518         if (Carry1 & (1 << 0))
519                 etdev->Stats.norcvbuf += COUNTER_WRAP_16_BIT;
520         if (Carry2 & (1 << 16))
521                 etdev->Stats.max_pkt_error += COUNTER_WRAP_12_BIT;
522         if (Carry2 & (1 << 15))
523                 etdev->Stats.tx_uflo += COUNTER_WRAP_12_BIT;
524         if (Carry2 & (1 << 6))
525                 etdev->Stats.first_collision += COUNTER_WRAP_12_BIT;
526         if (Carry2 & (1 << 8))
527                 etdev->Stats.tx_deferred += COUNTER_WRAP_12_BIT;
528         if (Carry2 & (1 << 5))
529                 etdev->Stats.excessive_collisions += COUNTER_WRAP_12_BIT;
530         if (Carry2 & (1 << 4))
531                 etdev->Stats.late_collisions += COUNTER_WRAP_12_BIT;
532         if (Carry2 & (1 << 2))
533                 etdev->Stats.collisions += COUNTER_WRAP_12_BIT;
534 }
535
536 void SetupDeviceForMulticast(struct et131x_adapter *etdev)
537 {
538         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
539         uint32_t nIndex;
540         uint32_t result;
541         uint32_t hash1 = 0;
542         uint32_t hash2 = 0;
543         uint32_t hash3 = 0;
544         uint32_t hash4 = 0;
545         u32 pm_csr;
546
547         /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision
548          * the multi-cast LIST.  If it is NOT specified, (and "ALL" is not
549          * specified) then we should pass NO multi-cast addresses to the
550          * driver.
551          */
552         if (etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) {
553                 /* Loop through our multicast array and set up the device */
554                 for (nIndex = 0; nIndex < etdev->MCAddressCount; nIndex++) {
555                         result = ether_crc(6, etdev->MCList[nIndex]);
556
557                         result = (result & 0x3F800000) >> 23;
558
559                         if (result < 32) {
560                                 hash1 |= (1 << result);
561                         } else if ((31 < result) && (result < 64)) {
562                                 result -= 32;
563                                 hash2 |= (1 << result);
564                         } else if ((63 < result) && (result < 96)) {
565                                 result -= 64;
566                                 hash3 |= (1 << result);
567                         } else {
568                                 result -= 96;
569                                 hash4 |= (1 << result);
570                         }
571                 }
572         }
573
574         /* Write out the new hash to the device */
575         pm_csr = readl(&etdev->regs->global.pm_csr);
576         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
577                 writel(hash1, &rxmac->multi_hash1);
578                 writel(hash2, &rxmac->multi_hash2);
579                 writel(hash3, &rxmac->multi_hash3);
580                 writel(hash4, &rxmac->multi_hash4);
581         }
582 }
583
584 void SetupDeviceForUnicast(struct et131x_adapter *etdev)
585 {
586         struct _RXMAC_t __iomem *rxmac = &etdev->regs->rxmac;
587         RXMAC_UNI_PF_ADDR1_t uni_pf1;
588         RXMAC_UNI_PF_ADDR2_t uni_pf2;
589         RXMAC_UNI_PF_ADDR3_t uni_pf3;
590         u32 pm_csr;
591
592         /* Set up unicast packet filter reg 3 to be the first two octets of
593          * the MAC address for both address
594          *
595          * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the
596          * MAC address for second address
597          *
598          * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
599          * MAC address for first address
600          */
601         uni_pf3.bits.addr1_1 = etdev->CurrentAddress[0];
602         uni_pf3.bits.addr1_2 = etdev->CurrentAddress[1];
603         uni_pf3.bits.addr2_1 = etdev->CurrentAddress[0];
604         uni_pf3.bits.addr2_2 = etdev->CurrentAddress[1];
605
606         uni_pf2.bits.addr2_3 = etdev->CurrentAddress[2];
607         uni_pf2.bits.addr2_4 = etdev->CurrentAddress[3];
608         uni_pf2.bits.addr2_5 = etdev->CurrentAddress[4];
609         uni_pf2.bits.addr2_6 = etdev->CurrentAddress[5];
610
611         uni_pf1.bits.addr1_3 = etdev->CurrentAddress[2];
612         uni_pf1.bits.addr1_4 = etdev->CurrentAddress[3];
613         uni_pf1.bits.addr1_5 = etdev->CurrentAddress[4];
614         uni_pf1.bits.addr1_6 = etdev->CurrentAddress[5];
615
616         pm_csr = readl(&etdev->regs->global.pm_csr);
617         if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
618                 writel(uni_pf1.value, &rxmac->uni_pf_addr1.value);
619                 writel(uni_pf2.value, &rxmac->uni_pf_addr2.value);
620                 writel(uni_pf3.value, &rxmac->uni_pf_addr3.value);
621         }
622 }