[PASEMI_MAC]: remove unused function
[pandora-kernel.git] / drivers / net / pasemi_mac.c
1 /*
2  * Copyright (C) 2006-2007 PA Semi, Inc
3  *
4  * Driver for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  */
19
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
24 #include <linux/dmaengine.h>
25 #include <linux/delay.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <asm/dma-mapping.h>
29 #include <linux/in.h>
30 #include <linux/skbuff.h>
31
32 #include <linux/ip.h>
33 #include <linux/tcp.h>
34 #include <net/checksum.h>
35
36 #include <asm/irq.h>
37
38 #include "pasemi_mac.h"
39
40
41 /* TODO list
42  *
43  * - Get rid of pci_{read,write}_config(), map registers with ioremap
44  *   for performance
45  * - PHY support
46  * - Multicast support
47  * - Large MTU support
48  * - Other performance improvements
49  */
50
51
52 /* Must be a power of two */
53 #define RX_RING_SIZE 512
54 #define TX_RING_SIZE 512
55
56 #define DEFAULT_MSG_ENABLE        \
57         (NETIF_MSG_DRV          | \
58          NETIF_MSG_PROBE        | \
59          NETIF_MSG_LINK         | \
60          NETIF_MSG_TIMER        | \
61          NETIF_MSG_IFDOWN       | \
62          NETIF_MSG_IFUP         | \
63          NETIF_MSG_RX_ERR       | \
64          NETIF_MSG_TX_ERR)
65
66 #define TX_DESC(mac, num)       ((mac)->tx->desc[(num) & (TX_RING_SIZE-1)])
67 #define TX_DESC_INFO(mac, num)  ((mac)->tx->desc_info[(num) & (TX_RING_SIZE-1)])
68 #define RX_DESC(mac, num)       ((mac)->rx->desc[(num) & (RX_RING_SIZE-1)])
69 #define RX_DESC_INFO(mac, num)  ((mac)->rx->desc_info[(num) & (RX_RING_SIZE-1)])
70 #define RX_BUFF(mac, num)       ((mac)->rx->buffers[(num) & (RX_RING_SIZE-1)])
71
72 #define RING_USED(ring)         (((ring)->next_to_fill - (ring)->next_to_clean) \
73                                  & ((ring)->size - 1))
74 #define RING_AVAIL(ring)        ((ring->size) - RING_USED(ring))
75
76 #define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
77
78 MODULE_LICENSE("GPL");
79 MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
80 MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
81
82 static int debug = -1;  /* -1 == use DEFAULT_MSG_ENABLE as value */
83 module_param(debug, int, 0);
84 MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
85
86 static struct pasdma_status *dma_status;
87
88 static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
89                           unsigned int val)
90 {
91         out_le32(mac->iob_regs+reg, val);
92 }
93
94 static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
95 {
96         return in_le32(mac->regs+reg);
97 }
98
99 static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
100                           unsigned int val)
101 {
102         out_le32(mac->regs+reg, val);
103 }
104
105 static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
106 {
107         return in_le32(mac->dma_regs+reg);
108 }
109
110 static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
111                           unsigned int val)
112 {
113         out_le32(mac->dma_regs+reg, val);
114 }
115
116 static int pasemi_get_mac_addr(struct pasemi_mac *mac)
117 {
118         struct pci_dev *pdev = mac->pdev;
119         struct device_node *dn = pci_device_to_OF_node(pdev);
120         int len;
121         const u8 *maddr;
122         u8 addr[6];
123
124         if (!dn) {
125                 dev_dbg(&pdev->dev,
126                           "No device node for mac, not configuring\n");
127                 return -ENOENT;
128         }
129
130         maddr = of_get_property(dn, "local-mac-address", &len);
131
132         if (maddr && len == 6) {
133                 memcpy(mac->mac_addr, maddr, 6);
134                 return 0;
135         }
136
137         /* Some old versions of firmware mistakenly uses mac-address
138          * (and as a string) instead of a byte array in local-mac-address.
139          */
140
141         if (maddr == NULL)
142                 maddr = of_get_property(dn, "mac-address", NULL);
143
144         if (maddr == NULL) {
145                 dev_warn(&pdev->dev,
146                          "no mac address in device tree, not configuring\n");
147                 return -ENOENT;
148         }
149
150
151         if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
152                    &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
153                 dev_warn(&pdev->dev,
154                          "can't parse mac address, not configuring\n");
155                 return -EINVAL;
156         }
157
158         memcpy(mac->mac_addr, addr, 6);
159
160         return 0;
161 }
162
163 static int pasemi_mac_setup_rx_resources(struct net_device *dev)
164 {
165         struct pasemi_mac_rxring *ring;
166         struct pasemi_mac *mac = netdev_priv(dev);
167         int chan_id = mac->dma_rxch;
168
169         ring = kzalloc(sizeof(*ring), GFP_KERNEL);
170
171         if (!ring)
172                 goto out_ring;
173
174         spin_lock_init(&ring->lock);
175
176         ring->size = RX_RING_SIZE;
177         ring->desc_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
178                                   RX_RING_SIZE, GFP_KERNEL);
179
180         if (!ring->desc_info)
181                 goto out_desc_info;
182
183         /* Allocate descriptors */
184         ring->desc = dma_alloc_coherent(&mac->dma_pdev->dev,
185                                         RX_RING_SIZE *
186                                         sizeof(struct pas_dma_xct_descr),
187                                         &ring->dma, GFP_KERNEL);
188
189         if (!ring->desc)
190                 goto out_desc;
191
192         memset(ring->desc, 0, RX_RING_SIZE * sizeof(struct pas_dma_xct_descr));
193
194         ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev,
195                                            RX_RING_SIZE * sizeof(u64),
196                                            &ring->buf_dma, GFP_KERNEL);
197         if (!ring->buffers)
198                 goto out_buffers;
199
200         memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64));
201
202         write_dma_reg(mac, PAS_DMA_RXCHAN_BASEL(chan_id), PAS_DMA_RXCHAN_BASEL_BRBL(ring->dma));
203
204         write_dma_reg(mac, PAS_DMA_RXCHAN_BASEU(chan_id),
205                            PAS_DMA_RXCHAN_BASEU_BRBH(ring->dma >> 32) |
206                            PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 2));
207
208         write_dma_reg(mac, PAS_DMA_RXCHAN_CFG(chan_id),
209                            PAS_DMA_RXCHAN_CFG_HBU(2));
210
211         write_dma_reg(mac, PAS_DMA_RXINT_BASEL(mac->dma_if),
212                            PAS_DMA_RXINT_BASEL_BRBL(__pa(ring->buffers)));
213
214         write_dma_reg(mac, PAS_DMA_RXINT_BASEU(mac->dma_if),
215                            PAS_DMA_RXINT_BASEU_BRBH(__pa(ring->buffers) >> 32) |
216                            PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
217
218         write_dma_reg(mac, PAS_DMA_RXINT_CFG(mac->dma_if),
219                            PAS_DMA_RXINT_CFG_DHL(2));
220
221         ring->next_to_fill = 0;
222         ring->next_to_clean = 0;
223
224         snprintf(ring->irq_name, sizeof(ring->irq_name),
225                  "%s rx", dev->name);
226         mac->rx = ring;
227
228         return 0;
229
230 out_buffers:
231         dma_free_coherent(&mac->dma_pdev->dev,
232                           RX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
233                           mac->rx->desc, mac->rx->dma);
234 out_desc:
235         kfree(ring->desc_info);
236 out_desc_info:
237         kfree(ring);
238 out_ring:
239         return -ENOMEM;
240 }
241
242
243 static int pasemi_mac_setup_tx_resources(struct net_device *dev)
244 {
245         struct pasemi_mac *mac = netdev_priv(dev);
246         u32 val;
247         int chan_id = mac->dma_txch;
248         struct pasemi_mac_txring *ring;
249
250         ring = kzalloc(sizeof(*ring), GFP_KERNEL);
251         if (!ring)
252                 goto out_ring;
253
254         spin_lock_init(&ring->lock);
255
256         ring->size = TX_RING_SIZE;
257         ring->desc_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
258                                   TX_RING_SIZE, GFP_KERNEL);
259         if (!ring->desc_info)
260                 goto out_desc_info;
261
262         /* Allocate descriptors */
263         ring->desc = dma_alloc_coherent(&mac->dma_pdev->dev,
264                                         TX_RING_SIZE *
265                                         sizeof(struct pas_dma_xct_descr),
266                                         &ring->dma, GFP_KERNEL);
267         if (!ring->desc)
268                 goto out_desc;
269
270         memset(ring->desc, 0, TX_RING_SIZE * sizeof(struct pas_dma_xct_descr));
271
272         write_dma_reg(mac, PAS_DMA_TXCHAN_BASEL(chan_id),
273                            PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma));
274         val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32);
275         val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 2);
276
277         write_dma_reg(mac, PAS_DMA_TXCHAN_BASEU(chan_id), val);
278
279         write_dma_reg(mac, PAS_DMA_TXCHAN_CFG(chan_id),
280                            PAS_DMA_TXCHAN_CFG_TY_IFACE |
281                            PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
282                            PAS_DMA_TXCHAN_CFG_UP |
283                            PAS_DMA_TXCHAN_CFG_WT(2));
284
285         ring->next_to_fill = 0;
286         ring->next_to_clean = 0;
287
288         snprintf(ring->irq_name, sizeof(ring->irq_name),
289                  "%s tx", dev->name);
290         mac->tx = ring;
291
292         return 0;
293
294 out_desc:
295         kfree(ring->desc_info);
296 out_desc_info:
297         kfree(ring);
298 out_ring:
299         return -ENOMEM;
300 }
301
302 static void pasemi_mac_free_tx_resources(struct net_device *dev)
303 {
304         struct pasemi_mac *mac = netdev_priv(dev);
305         unsigned int i;
306         struct pasemi_mac_buffer *info;
307         struct pas_dma_xct_descr *dp;
308
309         for (i = 0; i < TX_RING_SIZE; i++) {
310                 info = &TX_DESC_INFO(mac, i);
311                 dp = &TX_DESC(mac, i);
312                 if (info->dma) {
313                         if (info->skb) {
314                                 pci_unmap_single(mac->dma_pdev,
315                                                  info->dma,
316                                                  info->skb->len,
317                                                  PCI_DMA_TODEVICE);
318                                 dev_kfree_skb_any(info->skb);
319                         }
320                         info->dma = 0;
321                         info->skb = NULL;
322                         dp->mactx = 0;
323                         dp->ptr = 0;
324                 }
325         }
326
327         dma_free_coherent(&mac->dma_pdev->dev,
328                           TX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
329                           mac->tx->desc, mac->tx->dma);
330
331         kfree(mac->tx->desc_info);
332         kfree(mac->tx);
333         mac->tx = NULL;
334 }
335
336 static void pasemi_mac_free_rx_resources(struct net_device *dev)
337 {
338         struct pasemi_mac *mac = netdev_priv(dev);
339         unsigned int i;
340         struct pasemi_mac_buffer *info;
341         struct pas_dma_xct_descr *dp;
342
343         for (i = 0; i < RX_RING_SIZE; i++) {
344                 info = &RX_DESC_INFO(mac, i);
345                 dp = &RX_DESC(mac, i);
346                 if (info->skb) {
347                         if (info->dma) {
348                                 pci_unmap_single(mac->dma_pdev,
349                                                  info->dma,
350                                                  info->skb->len,
351                                                  PCI_DMA_FROMDEVICE);
352                                 dev_kfree_skb_any(info->skb);
353                         }
354                         info->dma = 0;
355                         info->skb = NULL;
356                         dp->macrx = 0;
357                         dp->ptr = 0;
358                 }
359         }
360
361         dma_free_coherent(&mac->dma_pdev->dev,
362                           RX_RING_SIZE * sizeof(struct pas_dma_xct_descr),
363                           mac->rx->desc, mac->rx->dma);
364
365         dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
366                           mac->rx->buffers, mac->rx->buf_dma);
367
368         kfree(mac->rx->desc_info);
369         kfree(mac->rx);
370         mac->rx = NULL;
371 }
372
373 static void pasemi_mac_replenish_rx_ring(struct net_device *dev)
374 {
375         struct pasemi_mac *mac = netdev_priv(dev);
376         unsigned int i;
377         int start = mac->rx->next_to_fill;
378         unsigned int limit, count;
379
380         limit = RING_AVAIL(mac->rx);
381         /* Check to see if we're doing first-time setup */
382         if (unlikely(mac->rx->next_to_clean == 0 && mac->rx->next_to_fill == 0))
383                 limit = RX_RING_SIZE;
384
385         if (limit <= 0)
386                 return;
387
388         i = start;
389         for (count = limit; count; count--) {
390                 struct pasemi_mac_buffer *info = &RX_DESC_INFO(mac, i);
391                 u64 *buff = &RX_BUFF(mac, i);
392                 struct sk_buff *skb;
393                 dma_addr_t dma;
394
395                 /* skb might still be in there for recycle on short receives */
396                 if (info->skb)
397                         skb = info->skb;
398                 else
399                         skb = dev_alloc_skb(BUF_SIZE);
400
401                 if (unlikely(!skb))
402                         break;
403
404                 dma = pci_map_single(mac->dma_pdev, skb->data, skb->len,
405                                      PCI_DMA_FROMDEVICE);
406
407                 if (unlikely(dma_mapping_error(dma))) {
408                         dev_kfree_skb_irq(info->skb);
409                         break;
410                 }
411
412                 info->skb = skb;
413                 info->dma = dma;
414                 *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
415                 i++;
416         }
417
418         wmb();
419
420         write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), limit - count);
421         write_dma_reg(mac, PAS_DMA_RXINT_INCR(mac->dma_if), limit - count);
422
423         mac->rx->next_to_fill += limit - count;
424 }
425
426 static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
427 {
428         unsigned int reg, pcnt;
429         /* Re-enable packet count interrupts: finally
430          * ack the packet count interrupt we got in rx_intr.
431          */
432
433         pcnt = *mac->rx_status & PAS_STATUS_PCNT_M;
434
435         reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
436
437         write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
438 }
439
440 static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac)
441 {
442         unsigned int reg, pcnt;
443
444         /* Re-enable packet count interrupts */
445         pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
446
447         reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
448
449         write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
450 }
451
452
453 static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
454 {
455         unsigned int n;
456         int count;
457         struct pas_dma_xct_descr *dp;
458         struct pasemi_mac_buffer *info;
459         struct sk_buff *skb;
460         unsigned int i, len;
461         u64 macrx;
462         dma_addr_t dma;
463
464         spin_lock(&mac->rx->lock);
465
466         n = mac->rx->next_to_clean;
467
468         for (count = limit; count; count--) {
469
470                 rmb();
471
472                 dp = &RX_DESC(mac, n);
473                 prefetchw(dp);
474                 macrx = dp->macrx;
475
476                 if (!(macrx & XCT_MACRX_O))
477                         break;
478
479
480                 info = NULL;
481
482                 /* We have to scan for our skb since there's no way
483                  * to back-map them from the descriptor, and if we
484                  * have several receive channels then they might not
485                  * show up in the same order as they were put on the
486                  * interface ring.
487                  */
488
489                 dma = (dp->ptr & XCT_PTR_ADDR_M);
490                 for (i = n; i < (n + RX_RING_SIZE); i++) {
491                         info = &RX_DESC_INFO(mac, i);
492                         if (info->dma == dma)
493                                 break;
494                 }
495                 prefetchw(info);
496
497                 skb = info->skb;
498                 prefetchw(skb);
499                 info->dma = 0;
500
501                 pci_unmap_single(mac->dma_pdev, dma, skb->len,
502                                  PCI_DMA_FROMDEVICE);
503
504                 len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
505
506                 if (len < 256) {
507                         struct sk_buff *new_skb =
508                             netdev_alloc_skb(mac->netdev, len + NET_IP_ALIGN);
509                         if (new_skb) {
510                                 skb_reserve(new_skb, NET_IP_ALIGN);
511                                 memcpy(new_skb->data, skb->data, len);
512                                 /* save the skb in buffer_info as good */
513                                 skb = new_skb;
514                         }
515                         /* else just continue with the old one */
516                 } else
517                         info->skb = NULL;
518
519                 skb_put(skb, len);
520
521                 if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) {
522                         skb->ip_summed = CHECKSUM_UNNECESSARY;
523                         skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
524                                            XCT_MACRX_CSUM_S;
525                 } else
526                         skb->ip_summed = CHECKSUM_NONE;
527
528                 mac->netdev->stats.rx_bytes += len;
529                 mac->netdev->stats.rx_packets++;
530
531                 skb->protocol = eth_type_trans(skb, mac->netdev);
532                 netif_receive_skb(skb);
533
534                 dp->ptr = 0;
535                 dp->macrx = 0;
536
537                 n++;
538         }
539
540         mac->rx->next_to_clean += limit - count;
541         pasemi_mac_replenish_rx_ring(mac->netdev);
542
543         spin_unlock(&mac->rx->lock);
544
545         return count;
546 }
547
548 static int pasemi_mac_clean_tx(struct pasemi_mac *mac)
549 {
550         int i;
551         struct pasemi_mac_buffer *info;
552         struct pas_dma_xct_descr *dp;
553         unsigned int start, count, limit;
554         unsigned int total_count;
555         int flags;
556         struct sk_buff *skbs[32];
557         dma_addr_t dmas[32];
558
559         total_count = 0;
560 restart:
561         spin_lock_irqsave(&mac->tx->lock, flags);
562
563         start = mac->tx->next_to_clean;
564         limit = min(mac->tx->next_to_fill, start+32);
565
566         count = 0;
567
568         for (i = start; i < limit; i++) {
569                 dp = &TX_DESC(mac, i);
570
571                 if (unlikely(dp->mactx & XCT_MACTX_O))
572                         /* Not yet transmitted */
573                         break;
574
575                 info = &TX_DESC_INFO(mac, i);
576                 skbs[count] = info->skb;
577                 dmas[count] = info->dma;
578
579                 info->skb = NULL;
580                 info->dma = 0;
581                 dp->mactx = 0;
582                 dp->ptr = 0;
583
584                 count++;
585         }
586         mac->tx->next_to_clean += count;
587         spin_unlock_irqrestore(&mac->tx->lock, flags);
588         netif_wake_queue(mac->netdev);
589
590         for (i = 0; i < count; i++) {
591                 pci_unmap_single(mac->dma_pdev, dmas[i],
592                                  skbs[i]->len, PCI_DMA_TODEVICE);
593                 dev_kfree_skb_irq(skbs[i]);
594         }
595
596         total_count += count;
597
598         /* If the batch was full, try to clean more */
599         if (count == 32)
600                 goto restart;
601
602         return total_count;
603 }
604
605
606 static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
607 {
608         struct net_device *dev = data;
609         struct pasemi_mac *mac = netdev_priv(dev);
610         unsigned int reg;
611
612         if (!(*mac->rx_status & PAS_STATUS_CAUSE_M))
613                 return IRQ_NONE;
614
615         if (*mac->rx_status & PAS_STATUS_ERROR)
616                 printk("rx_status reported error\n");
617
618         /* Don't reset packet count so it won't fire again but clear
619          * all others.
620          */
621
622         reg = 0;
623         if (*mac->rx_status & PAS_STATUS_SOFT)
624                 reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
625         if (*mac->rx_status & PAS_STATUS_ERROR)
626                 reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
627         if (*mac->rx_status & PAS_STATUS_TIMER)
628                 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
629
630         netif_rx_schedule(dev, &mac->napi);
631
632         write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
633
634         return IRQ_HANDLED;
635 }
636
637 static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
638 {
639         struct net_device *dev = data;
640         struct pasemi_mac *mac = netdev_priv(dev);
641         unsigned int reg, pcnt;
642
643         if (!(*mac->tx_status & PAS_STATUS_CAUSE_M))
644                 return IRQ_NONE;
645
646         pasemi_mac_clean_tx(mac);
647
648         pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
649
650         reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
651
652         if (*mac->tx_status & PAS_STATUS_SOFT)
653                 reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
654         if (*mac->tx_status & PAS_STATUS_ERROR)
655                 reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
656
657         write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
658
659         return IRQ_HANDLED;
660 }
661
662 static void pasemi_adjust_link(struct net_device *dev)
663 {
664         struct pasemi_mac *mac = netdev_priv(dev);
665         int msg;
666         unsigned int flags;
667         unsigned int new_flags;
668
669         if (!mac->phydev->link) {
670                 /* If no link, MAC speed settings don't matter. Just report
671                  * link down and return.
672                  */
673                 if (mac->link && netif_msg_link(mac))
674                         printk(KERN_INFO "%s: Link is down.\n", dev->name);
675
676                 netif_carrier_off(dev);
677                 mac->link = 0;
678
679                 return;
680         } else
681                 netif_carrier_on(dev);
682
683         flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
684         new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
685                               PAS_MAC_CFG_PCFG_TSR_M);
686
687         if (!mac->phydev->duplex)
688                 new_flags |= PAS_MAC_CFG_PCFG_HD;
689
690         switch (mac->phydev->speed) {
691         case 1000:
692                 new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
693                              PAS_MAC_CFG_PCFG_TSR_1G;
694                 break;
695         case 100:
696                 new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
697                              PAS_MAC_CFG_PCFG_TSR_100M;
698                 break;
699         case 10:
700                 new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
701                              PAS_MAC_CFG_PCFG_TSR_10M;
702                 break;
703         default:
704                 printk("Unsupported speed %d\n", mac->phydev->speed);
705         }
706
707         /* Print on link or speed/duplex change */
708         msg = mac->link != mac->phydev->link || flags != new_flags;
709
710         mac->duplex = mac->phydev->duplex;
711         mac->speed = mac->phydev->speed;
712         mac->link = mac->phydev->link;
713
714         if (new_flags != flags)
715                 write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags);
716
717         if (msg && netif_msg_link(mac))
718                 printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
719                        dev->name, mac->speed, mac->duplex ? "full" : "half");
720 }
721
722 static int pasemi_mac_phy_init(struct net_device *dev)
723 {
724         struct pasemi_mac *mac = netdev_priv(dev);
725         struct device_node *dn, *phy_dn;
726         struct phy_device *phydev;
727         unsigned int phy_id;
728         const phandle *ph;
729         const unsigned int *prop;
730         struct resource r;
731         int ret;
732
733         dn = pci_device_to_OF_node(mac->pdev);
734         ph = of_get_property(dn, "phy-handle", NULL);
735         if (!ph)
736                 return -ENODEV;
737         phy_dn = of_find_node_by_phandle(*ph);
738
739         prop = of_get_property(phy_dn, "reg", NULL);
740         ret = of_address_to_resource(phy_dn->parent, 0, &r);
741         if (ret)
742                 goto err;
743
744         phy_id = *prop;
745         snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
746
747         of_node_put(phy_dn);
748
749         mac->link = 0;
750         mac->speed = 0;
751         mac->duplex = -1;
752
753         phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
754
755         if (IS_ERR(phydev)) {
756                 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
757                 return PTR_ERR(phydev);
758         }
759
760         mac->phydev = phydev;
761
762         return 0;
763
764 err:
765         of_node_put(phy_dn);
766         return -ENODEV;
767 }
768
769
770 static int pasemi_mac_open(struct net_device *dev)
771 {
772         struct pasemi_mac *mac = netdev_priv(dev);
773         int base_irq;
774         unsigned int flags;
775         int ret;
776
777         /* enable rx section */
778         write_dma_reg(mac, PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN);
779
780         /* enable tx section */
781         write_dma_reg(mac, PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN);
782
783         flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
784                 PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
785                 PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
786
787         write_mac_reg(mac, PAS_MAC_CFG_TXP, flags);
788
789         flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PE |
790                 PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
791
792         flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
793
794         write_iob_reg(mac, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch),
795                            PAS_IOB_DMA_RXCH_CFG_CNTTH(0));
796
797         write_iob_reg(mac, PAS_IOB_DMA_TXCH_CFG(mac->dma_txch),
798                            PAS_IOB_DMA_TXCH_CFG_CNTTH(128));
799
800         /* Clear out any residual packet count state from firmware */
801         pasemi_mac_restart_rx_intr(mac);
802         pasemi_mac_restart_tx_intr(mac);
803
804         /* 0xffffff is max value, about 16ms */
805         write_iob_reg(mac, PAS_IOB_DMA_COM_TIMEOUTCFG,
806                            PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0xffffff));
807
808         write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
809
810         ret = pasemi_mac_setup_rx_resources(dev);
811         if (ret)
812                 goto out_rx_resources;
813
814         ret = pasemi_mac_setup_tx_resources(dev);
815         if (ret)
816                 goto out_tx_resources;
817
818         write_mac_reg(mac, PAS_MAC_IPC_CHNL,
819                            PAS_MAC_IPC_CHNL_DCHNO(mac->dma_rxch) |
820                            PAS_MAC_IPC_CHNL_BCH(mac->dma_rxch));
821
822         /* enable rx if */
823         write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
824                            PAS_DMA_RXINT_RCMDSTA_EN);
825
826         /* enable rx channel */
827         write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
828                            PAS_DMA_RXCHAN_CCMDSTA_EN |
829                            PAS_DMA_RXCHAN_CCMDSTA_DU);
830
831         /* enable tx channel */
832         write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
833                            PAS_DMA_TXCHAN_TCMDSTA_EN);
834
835         pasemi_mac_replenish_rx_ring(dev);
836
837         ret = pasemi_mac_phy_init(dev);
838         /* Some configs don't have PHYs (XAUI etc), so don't complain about
839          * failed init due to -ENODEV.
840          */
841         if (ret && ret != -ENODEV)
842                 dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret);
843
844         netif_start_queue(dev);
845         napi_enable(&mac->napi);
846
847         /* Interrupts are a bit different for our DMA controller: While
848          * it's got one a regular PCI device header, the interrupt there
849          * is really the base of the range it's using. Each tx and rx
850          * channel has it's own interrupt source.
851          */
852
853         base_irq = virq_to_hw(mac->dma_pdev->irq);
854
855         mac->tx_irq = irq_create_mapping(NULL, base_irq + mac->dma_txch);
856         mac->rx_irq = irq_create_mapping(NULL, base_irq + 20 + mac->dma_txch);
857
858         ret = request_irq(mac->tx_irq, &pasemi_mac_tx_intr, IRQF_DISABLED,
859                           mac->tx->irq_name, dev);
860         if (ret) {
861                 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
862                         base_irq + mac->dma_txch, ret);
863                 goto out_tx_int;
864         }
865
866         ret = request_irq(mac->rx_irq, &pasemi_mac_rx_intr, IRQF_DISABLED,
867                           mac->rx->irq_name, dev);
868         if (ret) {
869                 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
870                         base_irq + 20 + mac->dma_rxch, ret);
871                 goto out_rx_int;
872         }
873
874         if (mac->phydev)
875                 phy_start(mac->phydev);
876
877         return 0;
878
879 out_rx_int:
880         free_irq(mac->tx_irq, dev);
881 out_tx_int:
882         napi_disable(&mac->napi);
883         netif_stop_queue(dev);
884         pasemi_mac_free_tx_resources(dev);
885 out_tx_resources:
886         pasemi_mac_free_rx_resources(dev);
887 out_rx_resources:
888
889         return ret;
890 }
891
892 #define MAX_RETRIES 5000
893
894 static int pasemi_mac_close(struct net_device *dev)
895 {
896         struct pasemi_mac *mac = netdev_priv(dev);
897         unsigned int stat;
898         int retries;
899
900         if (mac->phydev) {
901                 phy_stop(mac->phydev);
902                 phy_disconnect(mac->phydev);
903         }
904
905         netif_stop_queue(dev);
906         napi_disable(&mac->napi);
907
908         /* Clean out any pending buffers */
909         pasemi_mac_clean_tx(mac);
910         pasemi_mac_clean_rx(mac, RX_RING_SIZE);
911
912         /* Disable interface */
913         write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), PAS_DMA_TXCHAN_TCMDSTA_ST);
914         write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), PAS_DMA_RXINT_RCMDSTA_ST);
915         write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), PAS_DMA_RXCHAN_CCMDSTA_ST);
916
917         for (retries = 0; retries < MAX_RETRIES; retries++) {
918                 stat = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
919                 if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT))
920                         break;
921                 cond_resched();
922         }
923
924         if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)
925                 dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n");
926
927         for (retries = 0; retries < MAX_RETRIES; retries++) {
928                 stat = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
929                 if (!(stat & PAS_DMA_RXCHAN_CCMDSTA_ACT))
930                         break;
931                 cond_resched();
932         }
933
934         if (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)
935                 dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
936
937         for (retries = 0; retries < MAX_RETRIES; retries++) {
938                 stat = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
939                 if (!(stat & PAS_DMA_RXINT_RCMDSTA_ACT))
940                         break;
941                 cond_resched();
942         }
943
944         if (stat & PAS_DMA_RXINT_RCMDSTA_ACT)
945                 dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
946
947         /* Then, disable the channel. This must be done separately from
948          * stopping, since you can't disable when active.
949          */
950
951         write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 0);
952         write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 0);
953         write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
954
955         free_irq(mac->tx_irq, dev);
956         free_irq(mac->rx_irq, dev);
957
958         /* Free resources */
959         pasemi_mac_free_rx_resources(dev);
960         pasemi_mac_free_tx_resources(dev);
961
962         return 0;
963 }
964
965 static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
966 {
967         struct pasemi_mac *mac = netdev_priv(dev);
968         struct pasemi_mac_txring *txring;
969         struct pasemi_mac_buffer *info;
970         struct pas_dma_xct_descr *dp;
971         u64 dflags, mactx, ptr;
972         dma_addr_t map;
973         int flags;
974
975         dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD;
976
977         if (skb->ip_summed == CHECKSUM_PARTIAL) {
978                 const unsigned char *nh = skb_network_header(skb);
979
980                 switch (ip_hdr(skb)->protocol) {
981                 case IPPROTO_TCP:
982                         dflags |= XCT_MACTX_CSUM_TCP;
983                         dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
984                         dflags |= XCT_MACTX_IPO(nh - skb->data);
985                         break;
986                 case IPPROTO_UDP:
987                         dflags |= XCT_MACTX_CSUM_UDP;
988                         dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
989                         dflags |= XCT_MACTX_IPO(nh - skb->data);
990                         break;
991                 }
992         }
993
994         map = pci_map_single(mac->dma_pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
995
996         if (dma_mapping_error(map))
997                 return NETDEV_TX_BUSY;
998
999         mactx = dflags | XCT_MACTX_LLEN(skb->len);
1000         ptr   = XCT_PTR_LEN(skb->len) | XCT_PTR_ADDR(map);
1001
1002         txring = mac->tx;
1003
1004         spin_lock_irqsave(&txring->lock, flags);
1005
1006         if (RING_AVAIL(txring) <= 1) {
1007                 spin_unlock_irqrestore(&txring->lock, flags);
1008                 pasemi_mac_clean_tx(mac);
1009                 pasemi_mac_restart_tx_intr(mac);
1010                 spin_lock_irqsave(&txring->lock, flags);
1011
1012                 if (RING_AVAIL(txring) <= 1) {
1013                         /* Still no room -- stop the queue and wait for tx
1014                          * intr when there's room.
1015                          */
1016                         netif_stop_queue(dev);
1017                         goto out_err;
1018                 }
1019         }
1020
1021         dp = &TX_DESC(mac, txring->next_to_fill);
1022         info = &TX_DESC_INFO(mac, txring->next_to_fill);
1023
1024         dp->mactx = mactx;
1025         dp->ptr   = ptr;
1026         info->dma = map;
1027         info->skb = skb;
1028
1029         txring->next_to_fill++;
1030         dev->stats.tx_packets++;
1031         dev->stats.tx_bytes += skb->len;
1032
1033         spin_unlock_irqrestore(&txring->lock, flags);
1034
1035         write_dma_reg(mac, PAS_DMA_TXCHAN_INCR(mac->dma_txch), 1);
1036
1037         return NETDEV_TX_OK;
1038
1039 out_err:
1040         spin_unlock_irqrestore(&txring->lock, flags);
1041         pci_unmap_single(mac->dma_pdev, map, skb->len, PCI_DMA_TODEVICE);
1042         return NETDEV_TX_BUSY;
1043 }
1044
1045 static void pasemi_mac_set_rx_mode(struct net_device *dev)
1046 {
1047         struct pasemi_mac *mac = netdev_priv(dev);
1048         unsigned int flags;
1049
1050         flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
1051
1052         /* Set promiscuous */
1053         if (dev->flags & IFF_PROMISC)
1054                 flags |= PAS_MAC_CFG_PCFG_PR;
1055         else
1056                 flags &= ~PAS_MAC_CFG_PCFG_PR;
1057
1058         write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
1059 }
1060
1061
1062 static int pasemi_mac_poll(struct napi_struct *napi, int budget)
1063 {
1064         struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
1065         struct net_device *dev = mac->netdev;
1066         int pkts;
1067
1068         pasemi_mac_clean_tx(mac);
1069         pkts = pasemi_mac_clean_rx(mac, budget);
1070         if (pkts < budget) {
1071                 /* all done, no more packets present */
1072                 netif_rx_complete(dev, napi);
1073
1074                 pasemi_mac_restart_rx_intr(mac);
1075         }
1076         return pkts;
1077 }
1078
1079 static void __iomem * __devinit map_onedev(struct pci_dev *p, int index)
1080 {
1081         struct device_node *dn;
1082         void __iomem *ret;
1083
1084         dn = pci_device_to_OF_node(p);
1085         if (!dn)
1086                 goto fallback;
1087
1088         ret = of_iomap(dn, index);
1089         if (!ret)
1090                 goto fallback;
1091
1092         return ret;
1093 fallback:
1094         /* This is hardcoded and ugly, but we have some firmware versions
1095          * that don't provide the register space in the device tree. Luckily
1096          * they are at well-known locations so we can just do the math here.
1097          */
1098         return ioremap(0xe0000000 + (p->devfn << 12), 0x2000);
1099 }
1100
1101 static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac)
1102 {
1103         struct resource res;
1104         struct device_node *dn;
1105         int err;
1106
1107         mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
1108         if (!mac->dma_pdev) {
1109                 dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
1110                 return -ENODEV;
1111         }
1112
1113         mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
1114         if (!mac->iob_pdev) {
1115                 dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
1116                 return -ENODEV;
1117         }
1118
1119         mac->regs = map_onedev(mac->pdev, 0);
1120         mac->dma_regs = map_onedev(mac->dma_pdev, 0);
1121         mac->iob_regs = map_onedev(mac->iob_pdev, 0);
1122
1123         if (!mac->regs || !mac->dma_regs || !mac->iob_regs) {
1124                 dev_err(&mac->pdev->dev, "Can't map registers\n");
1125                 return -ENODEV;
1126         }
1127
1128         /* The dma status structure is located in the I/O bridge, and
1129          * is cache coherent.
1130          */
1131         if (!dma_status) {
1132                 dn = pci_device_to_OF_node(mac->iob_pdev);
1133                 if (dn)
1134                         err = of_address_to_resource(dn, 1, &res);
1135                 if (!dn || err) {
1136                         /* Fallback for old firmware */
1137                         res.start = 0xfd800000;
1138                         res.end = res.start + 0x1000;
1139                 }
1140                 dma_status = __ioremap(res.start, res.end-res.start, 0);
1141         }
1142
1143         return 0;
1144 }
1145
1146 static int __devinit
1147 pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1148 {
1149         static int index = 0;
1150         struct net_device *dev;
1151         struct pasemi_mac *mac;
1152         int err;
1153         DECLARE_MAC_BUF(mac_buf);
1154
1155         err = pci_enable_device(pdev);
1156         if (err)
1157                 return err;
1158
1159         dev = alloc_etherdev(sizeof(struct pasemi_mac));
1160         if (dev == NULL) {
1161                 dev_err(&pdev->dev,
1162                         "pasemi_mac: Could not allocate ethernet device.\n");
1163                 err = -ENOMEM;
1164                 goto out_disable_device;
1165         }
1166
1167         pci_set_drvdata(pdev, dev);
1168         SET_NETDEV_DEV(dev, &pdev->dev);
1169
1170         mac = netdev_priv(dev);
1171
1172         mac->pdev = pdev;
1173         mac->netdev = dev;
1174
1175         netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
1176
1177         dev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX;
1178
1179         /* These should come out of the device tree eventually */
1180         mac->dma_txch = index;
1181         mac->dma_rxch = index;
1182
1183         /* We probe GMAC before XAUI, but the DMA interfaces are
1184          * in XAUI, GMAC order.
1185          */
1186         if (index < 4)
1187                 mac->dma_if = index + 2;
1188         else
1189                 mac->dma_if = index - 4;
1190         index++;
1191
1192         switch (pdev->device) {
1193         case 0xa005:
1194                 mac->type = MAC_TYPE_GMAC;
1195                 break;
1196         case 0xa006:
1197                 mac->type = MAC_TYPE_XAUI;
1198                 break;
1199         default:
1200                 err = -ENODEV;
1201                 goto out;
1202         }
1203
1204         /* get mac addr from device tree */
1205         if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
1206                 err = -ENODEV;
1207                 goto out;
1208         }
1209         memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
1210
1211         dev->open = pasemi_mac_open;
1212         dev->stop = pasemi_mac_close;
1213         dev->hard_start_xmit = pasemi_mac_start_tx;
1214         dev->set_multicast_list = pasemi_mac_set_rx_mode;
1215
1216         err = pasemi_mac_map_regs(mac);
1217         if (err)
1218                 goto out;
1219
1220         mac->rx_status = &dma_status->rx_sta[mac->dma_rxch];
1221         mac->tx_status = &dma_status->tx_sta[mac->dma_txch];
1222
1223         mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1224
1225         /* Enable most messages by default */
1226         mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
1227
1228         err = register_netdev(dev);
1229
1230         if (err) {
1231                 dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
1232                         err);
1233                 goto out;
1234         } else
1235                 printk(KERN_INFO "%s: PA Semi %s: intf %d, txch %d, rxch %d, "
1236                        "hw addr %s\n",
1237                        dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
1238                        mac->dma_if, mac->dma_txch, mac->dma_rxch,
1239                        print_mac(mac_buf, dev->dev_addr));
1240
1241         return err;
1242
1243 out:
1244         if (mac->iob_pdev)
1245                 pci_dev_put(mac->iob_pdev);
1246         if (mac->dma_pdev)
1247                 pci_dev_put(mac->dma_pdev);
1248         if (mac->dma_regs)
1249                 iounmap(mac->dma_regs);
1250         if (mac->iob_regs)
1251                 iounmap(mac->iob_regs);
1252         if (mac->regs)
1253                 iounmap(mac->regs);
1254
1255         free_netdev(dev);
1256 out_disable_device:
1257         pci_disable_device(pdev);
1258         return err;
1259
1260 }
1261
1262 static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
1263 {
1264         struct net_device *netdev = pci_get_drvdata(pdev);
1265         struct pasemi_mac *mac;
1266
1267         if (!netdev)
1268                 return;
1269
1270         mac = netdev_priv(netdev);
1271
1272         unregister_netdev(netdev);
1273
1274         pci_disable_device(pdev);
1275         pci_dev_put(mac->dma_pdev);
1276         pci_dev_put(mac->iob_pdev);
1277
1278         iounmap(mac->regs);
1279         iounmap(mac->dma_regs);
1280         iounmap(mac->iob_regs);
1281
1282         pci_set_drvdata(pdev, NULL);
1283         free_netdev(netdev);
1284 }
1285
1286 static struct pci_device_id pasemi_mac_pci_tbl[] = {
1287         { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
1288         { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
1289         { },
1290 };
1291
1292 MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
1293
1294 static struct pci_driver pasemi_mac_driver = {
1295         .name           = "pasemi_mac",
1296         .id_table       = pasemi_mac_pci_tbl,
1297         .probe          = pasemi_mac_probe,
1298         .remove         = __devexit_p(pasemi_mac_remove),
1299 };
1300
1301 static void __exit pasemi_mac_cleanup_module(void)
1302 {
1303         pci_unregister_driver(&pasemi_mac_driver);
1304         __iounmap(dma_status);
1305         dma_status = NULL;
1306 }
1307
1308 int pasemi_mac_init_module(void)
1309 {
1310         return pci_register_driver(&pasemi_mac_driver);
1311 }
1312
1313 module_init(pasemi_mac_init_module);
1314 module_exit(pasemi_mac_cleanup_module);