aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ks8842.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ks8842.c')
-rw-r--r--drivers/net/ks8842.c61
1 files changed, 46 insertions, 15 deletions
diff --git a/drivers/net/ks8842.c b/drivers/net/ks8842.c
index 5c45cb58d023..f852ab3ae9cf 100644
--- a/drivers/net/ks8842.c
+++ b/drivers/net/ks8842.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ks8842_main.c timberdale KS8842 ethernet driver 2 * ks8842.c timberdale KS8842 ethernet driver
3 * Copyright (c) 2009 Intel Corporation 3 * Copyright (c) 2009 Intel Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -20,12 +20,15 @@
20 * The Micrel KS8842 behind the timberdale FPGA 20 * The Micrel KS8842 behind the timberdale FPGA
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/kernel.h> 25#include <linux/kernel.h>
24#include <linux/module.h> 26#include <linux/module.h>
25#include <linux/platform_device.h> 27#include <linux/platform_device.h>
26#include <linux/netdevice.h> 28#include <linux/netdevice.h>
27#include <linux/etherdevice.h> 29#include <linux/etherdevice.h>
28#include <linux/ethtool.h> 30#include <linux/ethtool.h>
31#include <linux/ks8842.h>
29 32
30#define DRV_NAME "ks8842" 33#define DRV_NAME "ks8842"
31 34
@@ -302,6 +305,20 @@ static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest)
302 ks8842_write16(adapter, 39, mac, REG_MACAR3); 305 ks8842_write16(adapter, 39, mac, REG_MACAR3);
303} 306}
304 307
308static void ks8842_write_mac_addr(struct ks8842_adapter *adapter, u8 *mac)
309{
310 unsigned long flags;
311 unsigned i;
312
313 spin_lock_irqsave(&adapter->lock, flags);
314 for (i = 0; i < ETH_ALEN; i++) {
315 ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i);
316 ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1],
317 REG_MACAR1 + i);
318 }
319 spin_unlock_irqrestore(&adapter->lock, flags);
320}
321
305static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter) 322static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter)
306{ 323{
307 return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff; 324 return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff;
@@ -520,13 +537,14 @@ static int ks8842_open(struct net_device *netdev)
520 /* reset the HW */ 537 /* reset the HW */
521 ks8842_reset_hw(adapter); 538 ks8842_reset_hw(adapter);
522 539
540 ks8842_write_mac_addr(adapter, netdev->dev_addr);
541
523 ks8842_update_link_status(netdev, adapter); 542 ks8842_update_link_status(netdev, adapter);
524 543
525 err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME, 544 err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME,
526 adapter); 545 adapter);
527 if (err) { 546 if (err) {
528 printk(KERN_ERR "Failed to request IRQ: %d: %d\n", 547 pr_err("Failed to request IRQ: %d: %d\n", adapter->irq, err);
529 adapter->irq, err);
530 return err; 548 return err;
531 } 549 }
532 550
@@ -567,10 +585,8 @@ static netdev_tx_t ks8842_xmit_frame(struct sk_buff *skb,
567static int ks8842_set_mac(struct net_device *netdev, void *p) 585static int ks8842_set_mac(struct net_device *netdev, void *p)
568{ 586{
569 struct ks8842_adapter *adapter = netdev_priv(netdev); 587 struct ks8842_adapter *adapter = netdev_priv(netdev);
570 unsigned long flags;
571 struct sockaddr *addr = p; 588 struct sockaddr *addr = p;
572 char *mac = (u8 *)addr->sa_data; 589 char *mac = (u8 *)addr->sa_data;
573 int i;
574 590
575 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__); 591 dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__);
576 592
@@ -579,13 +595,7 @@ static int ks8842_set_mac(struct net_device *netdev, void *p)
579 595
580 memcpy(netdev->dev_addr, mac, netdev->addr_len); 596 memcpy(netdev->dev_addr, mac, netdev->addr_len);
581 597
582 spin_lock_irqsave(&adapter->lock, flags); 598 ks8842_write_mac_addr(adapter, mac);
583 for (i = 0; i < ETH_ALEN; i++) {
584 ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i);
585 ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1],
586 REG_MACAR1 + i);
587 }
588 spin_unlock_irqrestore(&adapter->lock, flags);
589 return 0; 599 return 0;
590} 600}
591 601
@@ -604,6 +614,8 @@ static void ks8842_tx_timeout(struct net_device *netdev)
604 614
605 ks8842_reset_hw(adapter); 615 ks8842_reset_hw(adapter);
606 616
617 ks8842_write_mac_addr(adapter, netdev->dev_addr);
618
607 ks8842_update_link_status(netdev, adapter); 619 ks8842_update_link_status(netdev, adapter);
608} 620}
609 621
@@ -626,7 +638,9 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
626 struct resource *iomem; 638 struct resource *iomem;
627 struct net_device *netdev; 639 struct net_device *netdev;
628 struct ks8842_adapter *adapter; 640 struct ks8842_adapter *adapter;
641 struct ks8842_platform_data *pdata = pdev->dev.platform_data;
629 u16 id; 642 u16 id;
643 unsigned i;
630 644
631 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 645 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
632 if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME)) 646 if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME))
@@ -657,7 +671,25 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
657 netdev->netdev_ops = &ks8842_netdev_ops; 671 netdev->netdev_ops = &ks8842_netdev_ops;
658 netdev->ethtool_ops = &ks8842_ethtool_ops; 672 netdev->ethtool_ops = &ks8842_ethtool_ops;
659 673
660 ks8842_read_mac_addr(adapter, netdev->dev_addr); 674 /* Check if a mac address was given */
675 i = netdev->addr_len;
676 if (pdata) {
677 for (i = 0; i < netdev->addr_len; i++)
678 if (pdata->macaddr[i] != 0)
679 break;
680
681 if (i < netdev->addr_len)
682 /* an address was passed, use it */
683 memcpy(netdev->dev_addr, pdata->macaddr,
684 netdev->addr_len);
685 }
686
687 if (i == netdev->addr_len) {
688 ks8842_read_mac_addr(adapter, netdev->dev_addr);
689
690 if (!is_valid_ether_addr(netdev->dev_addr))
691 random_ether_addr(netdev->dev_addr);
692 }
661 693
662 id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); 694 id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE);
663 695
@@ -668,8 +700,7 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
668 700
669 platform_set_drvdata(pdev, netdev); 701 platform_set_drvdata(pdev, netdev);
670 702
671 printk(KERN_INFO DRV_NAME 703 pr_info("Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n",
672 " Found chip, family: 0x%x, id: 0x%x, rev: 0x%x\n",
673 (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7); 704 (id >> 8) & 0xff, (id >> 4) & 0xf, (id >> 1) & 0x7);
674 705
675 return 0; 706 return 0;