aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ksz884x.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ksz884x.c')
-rw-r--r--drivers/net/ksz884x.c86
1 files changed, 35 insertions, 51 deletions
diff --git a/drivers/net/ksz884x.c b/drivers/net/ksz884x.c
index 0606a1f359fb..c80ca64277b2 100644
--- a/drivers/net/ksz884x.c
+++ b/drivers/net/ksz884x.c
@@ -14,10 +14,11 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16 16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
17#include <linux/init.h> 19#include <linux/init.h>
18#include <linux/kernel.h> 20#include <linux/kernel.h>
19#include <linux/module.h> 21#include <linux/module.h>
20#include <linux/version.h>
21#include <linux/ioport.h> 22#include <linux/ioport.h>
22#include <linux/pci.h> 23#include <linux/pci.h>
23#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
@@ -1484,11 +1485,6 @@ struct dev_priv {
1484 int promiscuous; 1485 int promiscuous;
1485}; 1486};
1486 1487
1487#define ks_info(_ks, _msg...) dev_info(&(_ks)->pdev->dev, _msg)
1488#define ks_warn(_ks, _msg...) dev_warn(&(_ks)->pdev->dev, _msg)
1489#define ks_dbg(_ks, _msg...) dev_dbg(&(_ks)->pdev->dev, _msg)
1490#define ks_err(_ks, _msg...) dev_err(&(_ks)->pdev->dev, _msg)
1491
1492#define DRV_NAME "KSZ884X PCI" 1488#define DRV_NAME "KSZ884X PCI"
1493#define DEVICE_NAME "KSZ884x PCI" 1489#define DEVICE_NAME "KSZ884x PCI"
1494#define DRV_VERSION "1.0.0" 1490#define DRV_VERSION "1.0.0"
@@ -3835,7 +3831,7 @@ static void ksz_check_desc_num(struct ksz_desc_info *info)
3835 alloc >>= 1; 3831 alloc >>= 1;
3836 } 3832 }
3837 if (alloc != 1 || shift < MIN_DESC_SHIFT) { 3833 if (alloc != 1 || shift < MIN_DESC_SHIFT) {
3838 printk(KERN_ALERT "Hardware descriptor numbers not right!\n"); 3834 pr_alert("Hardware descriptor numbers not right!\n");
3839 while (alloc) { 3835 while (alloc) {
3840 shift++; 3836 shift++;
3841 alloc >>= 1; 3837 alloc >>= 1;
@@ -4546,8 +4542,7 @@ static int ksz_alloc_mem(struct dev_info *adapter)
4546 (((sizeof(struct ksz_hw_desc) + DESC_ALIGNMENT - 1) / 4542 (((sizeof(struct ksz_hw_desc) + DESC_ALIGNMENT - 1) /
4547 DESC_ALIGNMENT) * DESC_ALIGNMENT); 4543 DESC_ALIGNMENT) * DESC_ALIGNMENT);
4548 if (hw->rx_desc_info.size != sizeof(struct ksz_hw_desc)) 4544 if (hw->rx_desc_info.size != sizeof(struct ksz_hw_desc))
4549 printk(KERN_ALERT 4545 pr_alert("Hardware descriptor size not right!\n");
4550 "Hardware descriptor size not right!\n");
4551 ksz_check_desc_num(&hw->rx_desc_info); 4546 ksz_check_desc_num(&hw->rx_desc_info);
4552 ksz_check_desc_num(&hw->tx_desc_info); 4547 ksz_check_desc_num(&hw->tx_desc_info);
4553 4548
@@ -4689,7 +4684,7 @@ static void send_packet(struct sk_buff *skb, struct net_device *dev)
4689 int frag; 4684 int frag;
4690 skb_frag_t *this_frag; 4685 skb_frag_t *this_frag;
4691 4686
4692 dma_buf->len = skb->len - skb->data_len; 4687 dma_buf->len = skb_headlen(skb);
4693 4688
4694 dma_buf->dma = pci_map_single( 4689 dma_buf->dma = pci_map_single(
4695 hw_priv->pdev, skb->data, dma_buf->len, 4690 hw_priv->pdev, skb->data, dma_buf->len,
@@ -5049,8 +5044,6 @@ static inline int rx_proc(struct net_device *dev, struct ksz_hw* hw,
5049 dma_buf->skb->data, packet_len); 5044 dma_buf->skb->data, packet_len);
5050 } while (0); 5045 } while (0);
5051 5046
5052 skb->dev = dev;
5053
5054 skb->protocol = eth_type_trans(skb, dev); 5047 skb->protocol = eth_type_trans(skb, dev);
5055 5048
5056 if (hw->rx_cfg & (DMA_RX_CSUM_UDP | DMA_RX_CSUM_TCP)) 5049 if (hw->rx_cfg & (DMA_RX_CSUM_UDP | DMA_RX_CSUM_TCP))
@@ -5061,8 +5054,6 @@ static inline int rx_proc(struct net_device *dev, struct ksz_hw* hw,
5061 priv->stats.rx_bytes += packet_len; 5054 priv->stats.rx_bytes += packet_len;
5062 5055
5063 /* Notify upper layer for received packet. */ 5056 /* Notify upper layer for received packet. */
5064 dev->last_rx = jiffies;
5065
5066 rx_status = netif_rx(skb); 5057 rx_status = netif_rx(skb);
5067 5058
5068 return 0; 5059 return 0;
@@ -5320,10 +5311,10 @@ static irqreturn_t netdev_intr(int irq, void *dev_id)
5320 u32 data; 5311 u32 data;
5321 5312
5322 hw->intr_mask &= ~KS884X_INT_TX_STOPPED; 5313 hw->intr_mask &= ~KS884X_INT_TX_STOPPED;
5323 printk(KERN_INFO "Tx stopped\n"); 5314 pr_info("Tx stopped\n");
5324 data = readl(hw->io + KS_DMA_TX_CTRL); 5315 data = readl(hw->io + KS_DMA_TX_CTRL);
5325 if (!(data & DMA_TX_ENABLE)) 5316 if (!(data & DMA_TX_ENABLE))
5326 printk(KERN_INFO "Tx disabled\n"); 5317 pr_info("Tx disabled\n");
5327 break; 5318 break;
5328 } 5319 }
5329 } while (0); 5320 } while (0);
@@ -5496,6 +5487,18 @@ static int prepare_hardware(struct net_device *dev)
5496 return 0; 5487 return 0;
5497} 5488}
5498 5489
5490static void set_media_state(struct net_device *dev, int media_state)
5491{
5492 struct dev_priv *priv = netdev_priv(dev);
5493
5494 if (media_state == priv->media_state)
5495 netif_carrier_on(dev);
5496 else
5497 netif_carrier_off(dev);
5498 netif_info(priv, link, dev, "link %s\n",
5499 media_state == priv->media_state ? "on" : "off");
5500}
5501
5499/** 5502/**
5500 * netdev_open - open network device 5503 * netdev_open - open network device
5501 * @dev: Network device. 5504 * @dev: Network device.
@@ -5585,15 +5588,7 @@ static int netdev_open(struct net_device *dev)
5585 5588
5586 priv->media_state = port->linked->state; 5589 priv->media_state = port->linked->state;
5587 5590
5588 if (media_connected == priv->media_state) 5591 set_media_state(dev, media_connected);
5589 netif_carrier_on(dev);
5590 else
5591 netif_carrier_off(dev);
5592 if (netif_msg_link(priv))
5593 printk(KERN_INFO "%s link %s\n", dev->name,
5594 (media_connected == priv->media_state ?
5595 "on" : "off"));
5596
5597 netif_start_queue(dev); 5592 netif_start_queue(dev);
5598 5593
5599 return 0; 5594 return 0;
@@ -5767,7 +5762,7 @@ static void netdev_set_rx_mode(struct net_device *dev)
5767 struct dev_priv *priv = netdev_priv(dev); 5762 struct dev_priv *priv = netdev_priv(dev);
5768 struct dev_info *hw_priv = priv->adapter; 5763 struct dev_info *hw_priv = priv->adapter;
5769 struct ksz_hw *hw = &hw_priv->hw; 5764 struct ksz_hw *hw = &hw_priv->hw;
5770 struct dev_mc_list *mc_ptr; 5765 struct netdev_hw_addr *ha;
5771 int multicast = (dev->flags & IFF_ALLMULTI); 5766 int multicast = (dev->flags & IFF_ALLMULTI);
5772 5767
5773 dev_set_promiscuous(dev, priv, hw, (dev->flags & IFF_PROMISC)); 5768 dev_set_promiscuous(dev, priv, hw, (dev->flags & IFF_PROMISC));
@@ -5784,7 +5779,7 @@ static void netdev_set_rx_mode(struct net_device *dev)
5784 int i = 0; 5779 int i = 0;
5785 5780
5786 /* List too big to support so turn on all multicast mode. */ 5781 /* List too big to support so turn on all multicast mode. */
5787 if (dev->mc_count > MAX_MULTICAST_LIST) { 5782 if (netdev_mc_count(dev) > MAX_MULTICAST_LIST) {
5788 if (MAX_MULTICAST_LIST != hw->multi_list_size) { 5783 if (MAX_MULTICAST_LIST != hw->multi_list_size) {
5789 hw->multi_list_size = MAX_MULTICAST_LIST; 5784 hw->multi_list_size = MAX_MULTICAST_LIST;
5790 ++hw->all_multi; 5785 ++hw->all_multi;
@@ -5793,13 +5788,12 @@ static void netdev_set_rx_mode(struct net_device *dev)
5793 return; 5788 return;
5794 } 5789 }
5795 5790
5796 netdev_for_each_mc_addr(mc_ptr, dev) { 5791 netdev_for_each_mc_addr(ha, dev) {
5797 if (!(*mc_ptr->dmi_addr & 1)) 5792 if (!(*ha->addr & 1))
5798 continue; 5793 continue;
5799 if (i >= MAX_MULTICAST_LIST) 5794 if (i >= MAX_MULTICAST_LIST)
5800 break; 5795 break;
5801 memcpy(hw->multi_list[i++], mc_ptr->dmi_addr, 5796 memcpy(hw->multi_list[i++], ha->addr, MAC_ADDR_LEN);
5802 MAC_ADDR_LEN);
5803 } 5797 }
5804 hw->multi_list_size = (u8) i; 5798 hw->multi_list_size = (u8) i;
5805 hw_set_grp_addr(hw); 5799 hw_set_grp_addr(hw);
@@ -6683,16 +6677,8 @@ static void update_link(struct net_device *dev, struct dev_priv *priv,
6683{ 6677{
6684 if (priv->media_state != port->linked->state) { 6678 if (priv->media_state != port->linked->state) {
6685 priv->media_state = port->linked->state; 6679 priv->media_state = port->linked->state;
6686 if (netif_running(dev)) { 6680 if (netif_running(dev))
6687 if (media_connected == priv->media_state) 6681 set_media_state(dev, media_connected);
6688 netif_carrier_on(dev);
6689 else
6690 netif_carrier_off(dev);
6691 if (netif_msg_link(priv))
6692 printk(KERN_INFO "%s link %s\n", dev->name,
6693 (media_connected == priv->media_state ?
6694 "on" : "off"));
6695 }
6696 } 6682 }
6697} 6683}
6698 6684
@@ -6986,7 +6972,7 @@ static int __init pcidev_init(struct pci_dev *pdev,
6986 int pi; 6972 int pi;
6987 int port_count; 6973 int port_count;
6988 int result; 6974 int result;
6989 char banner[80]; 6975 char banner[sizeof(version)];
6990 struct ksz_switch *sw = NULL; 6976 struct ksz_switch *sw = NULL;
6991 6977
6992 result = pci_enable_device(pdev); 6978 result = pci_enable_device(pdev);
@@ -7010,10 +6996,9 @@ static int __init pcidev_init(struct pci_dev *pdev,
7010 6996
7011 result = -ENOMEM; 6997 result = -ENOMEM;
7012 6998
7013 info = kmalloc(sizeof(struct platform_info), GFP_KERNEL); 6999 info = kzalloc(sizeof(struct platform_info), GFP_KERNEL);
7014 if (!info) 7000 if (!info)
7015 goto pcidev_init_dev_err; 7001 goto pcidev_init_dev_err;
7016 memset(info, 0, sizeof(struct platform_info));
7017 7002
7018 hw_priv = &info->dev_info; 7003 hw_priv = &info->dev_info;
7019 hw_priv->pdev = pdev; 7004 hw_priv->pdev = pdev;
@@ -7027,15 +7012,15 @@ static int __init pcidev_init(struct pci_dev *pdev,
7027 cnt = hw_init(hw); 7012 cnt = hw_init(hw);
7028 if (!cnt) { 7013 if (!cnt) {
7029 if (msg_enable & NETIF_MSG_PROBE) 7014 if (msg_enable & NETIF_MSG_PROBE)
7030 printk(KERN_ALERT "chip not detected\n"); 7015 pr_alert("chip not detected\n");
7031 result = -ENODEV; 7016 result = -ENODEV;
7032 goto pcidev_init_alloc_err; 7017 goto pcidev_init_alloc_err;
7033 } 7018 }
7034 7019
7035 sprintf(banner, "%s\n", version); 7020 snprintf(banner, sizeof(banner), "%s", version);
7036 banner[13] = cnt + '0'; 7021 banner[13] = cnt + '0'; /* Replace x in "Micrel KSZ884x" */
7037 ks_info(hw_priv, "%s", banner); 7022 dev_info(&hw_priv->pdev->dev, "%s\n", banner);
7038 ks_dbg(hw_priv, "Mem = %p; IRQ = %d\n", hw->io, pdev->irq); 7023 dev_dbg(&hw_priv->pdev->dev, "Mem = %p; IRQ = %d\n", hw->io, pdev->irq);
7039 7024
7040 /* Assume device is KSZ8841. */ 7025 /* Assume device is KSZ8841. */
7041 hw->dev_count = 1; 7026 hw->dev_count = 1;
@@ -7064,10 +7049,9 @@ static int __init pcidev_init(struct pci_dev *pdev,
7064 mib_port_count = SWITCH_PORT_NUM; 7049 mib_port_count = SWITCH_PORT_NUM;
7065 } 7050 }
7066 hw->mib_port_cnt = TOTAL_PORT_NUM; 7051 hw->mib_port_cnt = TOTAL_PORT_NUM;
7067 hw->ksz_switch = kmalloc(sizeof(struct ksz_switch), GFP_KERNEL); 7052 hw->ksz_switch = kzalloc(sizeof(struct ksz_switch), GFP_KERNEL);
7068 if (!hw->ksz_switch) 7053 if (!hw->ksz_switch)
7069 goto pcidev_init_alloc_err; 7054 goto pcidev_init_alloc_err;
7070 memset(hw->ksz_switch, 0, sizeof(struct ksz_switch));
7071 7055
7072 sw = hw->ksz_switch; 7056 sw = hw->ksz_switch;
7073 } 7057 }