From b82de0e28ccac15e1a0c3b4f6f20dfd230049041 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Wed, 22 Apr 2015 16:41:46 +0200 Subject: [PATCH 1/6] arcnet: move dev_free_skb to its only user The call for dev_free_skb is done only once. This patch moves its call to its only user and removes the obsolete condition variable. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/arcnet.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c index e41dd36fe832..542e2b46b9eb 100644 --- a/drivers/net/arcnet/arcnet.c +++ b/drivers/net/arcnet/arcnet.c @@ -515,7 +515,7 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, struct ArcProto *proto; int txbuf; unsigned long flags; - int freeskb, retval; + int retval; arc_printk(D_DURING, dev, "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n", @@ -554,15 +554,13 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, * the package later - forget about it now */ dev->stats.tx_bytes += skb->len; - freeskb = 1; + dev_kfree_skb(skb); } else { /* do it the 'split' way */ lp->outgoing.proto = proto; lp->outgoing.skb = skb; lp->outgoing.pkt = pkt; - freeskb = 0; - if (proto->continue_tx && proto->continue_tx(dev, txbuf)) { arc_printk(D_NORMAL, dev, @@ -574,7 +572,6 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, lp->next_tx = txbuf; } else { retval = NETDEV_TX_BUSY; - freeskb = 0; } arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n", @@ -589,9 +586,6 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, __FILE__, __LINE__, __func__, lp->hw.status(dev)); spin_unlock_irqrestore(&lp->lock, flags); - if (freeskb) - dev_kfree_skb(skb); - return retval; /* no need to try again */ } EXPORT_SYMBOL(arcnet_send_packet); From 27daf6ed5c1fbeca9029c59c7f4f70a5c7e13531 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Fri, 20 Mar 2015 15:20:59 +0100 Subject: [PATCH 2/6] arcnet: com20020: add enable and disable device on open/close This patch changes the driver to properly work with the linux netif interface. The controller gets enabled on open and disabled on close. Therefor it removes every bogus start of the xceiver. It only gets enabled on com20020_open and disabled on com20020_close. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/com20020.c | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c index c82f323a8c2b..13d9ad4b3f5c 100644 --- a/drivers/net/arcnet/com20020.c +++ b/drivers/net/arcnet/com20020.c @@ -118,7 +118,7 @@ int com20020_check(struct net_device *dev) arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND); } - lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; + lp->config = (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */ arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); arcnet_outb(0x42, ioaddr, COM20020_REG_W_XREG); @@ -131,11 +131,6 @@ int com20020_check(struct net_device *dev) } arc_printk(D_INIT_REASONS, dev, "status after reset: %X\n", status); - /* Enable TX */ - lp->config |= TXENcfg; - arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); - arcnet_outb(arcnet_inb(ioaddr, 8), ioaddr, COM20020_REG_W_XREG); - arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear, ioaddr, COM20020_REG_W_COMMAND); status = arcnet_inb(ioaddr, COM20020_REG_R_STATUS); @@ -169,9 +164,33 @@ static int com20020_set_hwaddr(struct net_device *dev, void *addr) return 0; } +static int com20020_netdev_open(struct net_device *dev) +{ + int ioaddr = dev->base_addr; + struct arcnet_local *lp = netdev_priv(dev); + + lp->config |= TXENcfg; + arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); + + return arcnet_open(dev); +} + +static int com20020_netdev_close(struct net_device *dev) +{ + int ioaddr = dev->base_addr; + struct arcnet_local *lp = netdev_priv(dev); + + arcnet_close(dev); + + /* disable transmitter */ + lp->config &= ~TXENcfg; + arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); + return 0; +} + const struct net_device_ops com20020_netdev_ops = { - .ndo_open = arcnet_open, - .ndo_stop = arcnet_close, + .ndo_open = com20020_netdev_open, + .ndo_stop = com20020_netdev_close, .ndo_start_xmit = arcnet_send_packet, .ndo_tx_timeout = arcnet_timeout, .ndo_set_mac_address = com20020_set_hwaddr, @@ -215,7 +234,7 @@ int com20020_found(struct net_device *dev, int shared) arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND); } - lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; + lp->config = (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; /* Default 0x38 + register: Node ID */ arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG); @@ -274,7 +293,7 @@ static int com20020_reset(struct net_device *dev, int really_reset) dev->name, arcnet_inb(ioaddr, COM20020_REG_R_STATUS)); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); - lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2); + lp->config |= (lp->timeout << 3) | (lp->backplane << 2); /* power-up defaults */ arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); From ae8ede6a0cdcf3b21596f44dff30bbd02265bb41 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Fri, 20 Mar 2015 15:22:24 +0100 Subject: [PATCH 3/6] arcnet: com20020-pci: set dev_port to the subdevice index This patch sets the dev_port according to the index of the card. This can be used by udev to name the ports in userspace. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/com20020-pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c index a12bf83be750..e3b7c14e619f 100644 --- a/drivers/net/arcnet/com20020-pci.c +++ b/drivers/net/arcnet/com20020-pci.c @@ -96,6 +96,7 @@ static int com20020pci_probe(struct pci_dev *pdev, ret = -ENOMEM; goto out_port; } + dev->dev_port = i; dev->netdev_ops = &com20020_netdev_ops; From 5ef216c1f84825c6942fdd6c24d12a08ac2df135 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Thu, 18 Sep 2014 00:12:50 +0200 Subject: [PATCH 4/6] arcnet: com20020-pci: add rotary index support The EAE PLX-PCI card has a special rotary encoder to configure the address of every card individually. We take this information for the initial setup of the cards dev_id. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/com20020-pci.c | 33 +++++++++++++++++++++++++++++++ drivers/net/arcnet/com20020.h | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c index e3b7c14e619f..637a6110cec6 100644 --- a/drivers/net/arcnet/com20020-pci.c +++ b/drivers/net/arcnet/com20020-pci.c @@ -68,6 +68,7 @@ static int com20020pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct com20020_pci_card_info *ci; + struct com20020_pci_channel_map *mm; struct net_device *dev; struct arcnet_local *lp; struct com20020_priv *priv; @@ -84,9 +85,22 @@ static int com20020pci_probe(struct pci_dev *pdev, ci = (struct com20020_pci_card_info *)id->driver_data; priv->ci = ci; + mm = &ci->misc_map; INIT_LIST_HEAD(&priv->list_dev); + if (mm->size) { + ioaddr = pci_resource_start(pdev, mm->bar) + mm->offset; + r = devm_request_region(&pdev->dev, ioaddr, mm->size, + "com20020-pci"); + if (!r) { + pr_err("IO region %xh-%xh already allocated.\n", + ioaddr, ioaddr + mm->size - 1); + return -EBUSY; + } + priv->misc = ioaddr; + } + for (i = 0; i < ci->devcount; i++) { struct com20020_pci_channel_map *cm = &ci->chan_map_tbl[i]; struct com20020_dev *card; @@ -132,6 +146,13 @@ static int com20020pci_probe(struct pci_dev *pdev, lp->timeout = timeout; lp->hw.owner = THIS_MODULE; + /* Get the dev_id from the PLX rotary coder */ + if (!strncmp(ci->name, "EAE PLX-PCI MA1", 15)) + dev->dev_id = 0xc; + dev->dev_id ^= inb(priv->misc + ci->rotary) >> 4; + + snprintf(dev->name, sizeof(dev->name), "arc%d-%d", dev->dev_id, i); + if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) { pr_err("IO address %Xh is empty!\n", ioaddr); ret = -EIO; @@ -235,6 +256,12 @@ static struct com20020_pci_card_info card_info_eae_arc1 = { .size = 0x08, }, }, + .misc_map = { + .bar = 2, + .offset = 0x10, + .size = 0x04, + }, + .rotary = 0x0, .flags = ARC_CAN_10MBIT, }; @@ -252,6 +279,12 @@ static struct com20020_pci_card_info card_info_eae_ma1 = { .size = 0x08, } }, + .misc_map = { + .bar = 2, + .offset = 0x10, + .size = 0x04, + }, + .rotary = 0x0, .flags = ARC_CAN_10MBIT, }; diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h index 22a460f39fb9..f2ed2eff3ae3 100644 --- a/drivers/net/arcnet/com20020.h +++ b/drivers/net/arcnet/com20020.h @@ -47,6 +47,9 @@ struct com20020_pci_card_info { int devcount; struct com20020_pci_channel_map chan_map_tbl[PLX_PCI_MAX_CARDS]; + struct com20020_pci_channel_map misc_map; + + int rotary; unsigned int flags; }; @@ -54,6 +57,7 @@ struct com20020_pci_card_info { struct com20020_priv { struct com20020_pci_card_info *ci; struct list_head list_dev; + resource_size_t misc; }; struct com20020_dev { From 8890624a4e8c2c7046d63bfd15d7331af9f55f10 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Thu, 18 Sep 2014 00:12:50 +0200 Subject: [PATCH 5/6] arcnet: com20020-pci: add led trigger support The EAE PLX-PCI card has special leds on the the main io pci resource bar. This patch adds support to trigger the conflict and data leds with the packages. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/arcdevice.h | 19 ++++++++ drivers/net/arcnet/arcnet.c | 72 ++++++++++++++++++++++++++++++ drivers/net/arcnet/com20020-pci.c | 73 +++++++++++++++++++++++++++++++ drivers/net/arcnet/com20020.h | 10 +++++ include/linux/leds.h | 7 +++ 5 files changed, 181 insertions(+) diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h index d7fdea11e694..2edc0c0ab7c7 100644 --- a/drivers/net/arcnet/arcdevice.h +++ b/drivers/net/arcnet/arcdevice.h @@ -237,6 +237,8 @@ struct Outgoing { numsegs; /* number of segments */ }; +#define ARCNET_LED_NAME_SZ (IFNAMSIZ + 6) + struct arcnet_local { uint8_t config, /* current value of CONFIG register */ timeout, /* Extended timeout for COM20020 */ @@ -260,6 +262,11 @@ struct arcnet_local { /* On preemtive and SMB a lock is needed */ spinlock_t lock; + struct led_trigger *tx_led_trig; + char tx_led_trig_name[ARCNET_LED_NAME_SZ]; + struct led_trigger *recon_led_trig; + char recon_led_trig_name[ARCNET_LED_NAME_SZ]; + /* * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of * which can be used for either sending or receiving. The new dynamic @@ -309,6 +316,8 @@ struct arcnet_local { int (*reset)(struct net_device *dev, int really_reset); void (*open)(struct net_device *dev); void (*close)(struct net_device *dev); + void (*datatrigger) (struct net_device * dev, int enable); + void (*recontrigger) (struct net_device * dev, int enable); void (*copy_to_card)(struct net_device *dev, int bufnum, int offset, void *buf, int count); @@ -319,6 +328,16 @@ struct arcnet_local { void __iomem *mem_start; /* pointer to ioremap'ed MMIO */ }; +enum arcnet_led_event { + ARCNET_LED_EVENT_RECON, + ARCNET_LED_EVENT_OPEN, + ARCNET_LED_EVENT_STOP, + ARCNET_LED_EVENT_TX, +}; + +void arcnet_led_event(struct net_device *netdev, enum arcnet_led_event event); +void devm_arcnet_led_init(struct net_device *netdev, int index, int subid); + #if ARCNET_DEBUG_MAX & D_SKB void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc); #else diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c index 542e2b46b9eb..4242522ae86b 100644 --- a/drivers/net/arcnet/arcnet.c +++ b/drivers/net/arcnet/arcnet.c @@ -52,6 +52,8 @@ #include #include +#include + #include "arcdevice.h" #include "com9026.h" @@ -189,6 +191,71 @@ static void arcnet_dump_packet(struct net_device *dev, int bufnum, #endif +/* Trigger a LED event in response to a ARCNET device event */ +void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event) +{ + struct arcnet_local *lp = netdev_priv(dev); + unsigned long led_delay = 350; + unsigned long tx_delay = 50; + + switch (event) { + case ARCNET_LED_EVENT_RECON: + led_trigger_blink_oneshot(lp->recon_led_trig, + &led_delay, &led_delay, 0); + break; + case ARCNET_LED_EVENT_OPEN: + led_trigger_event(lp->tx_led_trig, LED_OFF); + led_trigger_event(lp->recon_led_trig, LED_OFF); + break; + case ARCNET_LED_EVENT_STOP: + led_trigger_event(lp->tx_led_trig, LED_OFF); + led_trigger_event(lp->recon_led_trig, LED_OFF); + break; + case ARCNET_LED_EVENT_TX: + led_trigger_blink_oneshot(lp->tx_led_trig, + &tx_delay, &tx_delay, 0); + break; + } +} +EXPORT_SYMBOL_GPL(arcnet_led_event); + +static void arcnet_led_release(struct device *gendev, void *res) +{ + struct arcnet_local *lp = netdev_priv(to_net_dev(gendev)); + + led_trigger_unregister_simple(lp->tx_led_trig); + led_trigger_unregister_simple(lp->recon_led_trig); +} + +/* Register ARCNET LED triggers for a arcnet device + * + * This is normally called from a driver's probe function + */ +void devm_arcnet_led_init(struct net_device *netdev, int index, int subid) +{ + struct arcnet_local *lp = netdev_priv(netdev); + void *res; + + res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL); + if (!res) { + netdev_err(netdev, "cannot register LED triggers\n"); + return; + } + + snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name), + "arc%d-%d-tx", index, subid); + snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name), + "arc%d-%d-recon", index, subid); + + led_trigger_register_simple(lp->tx_led_trig_name, + &lp->tx_led_trig); + led_trigger_register_simple(lp->recon_led_trig_name, + &lp->recon_led_trig); + + devres_add(&netdev->dev, res); +} +EXPORT_SYMBOL_GPL(devm_arcnet_led_init); + /* Unregister a protocol driver from the arc_proto_map. Protocol drivers * are responsible for registering themselves, but the unregister routine * is pretty generic so we'll do it here. @@ -425,6 +492,7 @@ int arcnet_open(struct net_device *dev) netif_start_queue(dev); + arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN); return 0; out_module_put: @@ -438,6 +506,7 @@ int arcnet_close(struct net_device *dev) { struct arcnet_local *lp = netdev_priv(dev); + arcnet_led_event(dev, ARCNET_LED_EVENT_STOP); netif_stop_queue(dev); /* flush TX and disable RX */ @@ -585,6 +654,8 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb, arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n", __FILE__, __LINE__, __func__, lp->hw.status(dev)); + arcnet_led_event(dev, ARCNET_LED_EVENT_TX); + spin_unlock_irqrestore(&lp->lock, flags); return retval; /* no need to try again */ } @@ -837,6 +908,7 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n", status); + arcnet_led_event(dev, ARCNET_LED_EVENT_RECON); /* MYRECON bit is at bit 7 of diagstatus */ if (diagstatus & 0x80) arc_printk(D_RECON, dev, "Put out that recon myself\n"); diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c index 637a6110cec6..239de38fbd6a 100644 --- a/drivers/net/arcnet/com20020-pci.c +++ b/drivers/net/arcnet/com20020-pci.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "arcdevice.h" #include "com20020.h" @@ -62,6 +63,36 @@ module_param(clockp, int, 0); module_param(clockm, int, 0); MODULE_LICENSE("GPL"); +static void led_tx_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct com20020_dev *card; + struct com20020_priv *priv; + struct com20020_pci_card_info *ci; + + card = container_of(led_cdev, struct com20020_dev, tx_led); + + priv = card->pci_priv; + ci = priv->ci; + + outb(!!value, priv->misc + ci->leds[card->index].green); +} + +static void led_recon_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct com20020_dev *card; + struct com20020_priv *priv; + struct com20020_pci_card_info *ci; + + card = container_of(led_cdev, struct com20020_dev, recon_led); + + priv = card->pci_priv; + ci = priv->ci; + + outb(!!value, priv->misc + ci->leds[card->index].red); +} + static void com20020pci_remove(struct pci_dev *pdev); static int com20020pci_probe(struct pci_dev *pdev, @@ -170,14 +201,41 @@ static int com20020pci_probe(struct pci_dev *pdev, card->index = i; card->pci_priv = priv; + card->tx_led.brightness_set = led_tx_set; + card->tx_led.default_trigger = devm_kasprintf(&pdev->dev, + GFP_KERNEL, "arc%d-%d-tx", + dev->dev_id, i); + card->tx_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, + "pci:green:tx:%d-%d", + dev->dev_id, i); + + card->tx_led.dev = &dev->dev; + card->recon_led.brightness_set = led_recon_set; + card->recon_led.default_trigger = devm_kasprintf(&pdev->dev, + GFP_KERNEL, "arc%d-%d-recon", + dev->dev_id, i); + card->recon_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, + "pci:red:recon:%d-%d", + dev->dev_id, i); + card->recon_led.dev = &dev->dev; card->dev = dev; + ret = devm_led_classdev_register(&pdev->dev, &card->tx_led); + if (ret) + goto out_port; + + ret = devm_led_classdev_register(&pdev->dev, &card->recon_led); + if (ret) + goto out_port; + dev_set_drvdata(&dev->dev, card); ret = com20020_found(dev, IRQF_SHARED); if (ret) goto out_port; + devm_arcnet_led_init(dev, dev->dev_id, i); + list_add(&card->list, &priv->list_dev); } @@ -261,6 +319,12 @@ static struct com20020_pci_card_info card_info_eae_arc1 = { .offset = 0x10, .size = 0x04, }, + .leds = { + { + .green = 0x0, + .red = 0x1, + }, + }, .rotary = 0x0, .flags = ARC_CAN_10MBIT, }; @@ -284,6 +348,15 @@ static struct com20020_pci_card_info card_info_eae_ma1 = { .offset = 0x10, .size = 0x04, }, + .leds = { + { + .green = 0x0, + .red = 0x1, + }, { + .green = 0x2, + .red = 0x3, + }, + }, .rotary = 0x0, .flags = ARC_CAN_10MBIT, }; diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h index f2ed2eff3ae3..0bcc5d0a6903 100644 --- a/drivers/net/arcnet/com20020.h +++ b/drivers/net/arcnet/com20020.h @@ -26,6 +26,7 @@ */ #ifndef __COM20020_H #define __COM20020_H +#include int com20020_check(struct net_device *dev); int com20020_found(struct net_device *dev, int shared); @@ -36,6 +37,11 @@ extern const struct net_device_ops com20020_netdev_ops; #define PLX_PCI_MAX_CARDS 2 +struct ledoffsets { + int green; + int red; +}; + struct com20020_pci_channel_map { u32 bar; u32 offset; @@ -49,6 +55,7 @@ struct com20020_pci_card_info { struct com20020_pci_channel_map chan_map_tbl[PLX_PCI_MAX_CARDS]; struct com20020_pci_channel_map misc_map; + struct ledoffsets leds[PLX_PCI_MAX_CARDS]; int rotary; unsigned int flags; @@ -64,6 +71,9 @@ struct com20020_dev { struct list_head list; struct net_device *dev; + struct led_classdev tx_led; + struct led_classdev recon_led; + struct com20020_priv *pci_priv; int index; }; diff --git a/include/linux/leds.h b/include/linux/leds.h index b122eeafb5dc..fa359c79c825 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -283,6 +283,13 @@ static inline void led_trigger_register_simple(const char *name, static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {} static inline void led_trigger_event(struct led_trigger *trigger, enum led_brightness event) {} +static inline void led_trigger_blink(struct led_trigger *trigger, + unsigned long *delay_on, + unsigned long *delay_off) {} +static inline void led_trigger_blink_oneshot(struct led_trigger *trigger, + unsigned long *delay_on, + unsigned long *delay_off, + int invert) {} static inline void led_trigger_set_default(struct led_classdev *led_cdev) {} static inline void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) {} From 59fbcbc61e1f0fd9acdf3efb09faca0320049718 Mon Sep 17 00:00:00 2001 From: Michael Grzeschik Date: Wed, 16 Sep 2015 10:15:45 +0200 Subject: [PATCH 6/6] arcnet: add netif_carrier_on/off for reconnect The arcnet device has no interrupt to detect if the link has changed from disconnected to connected. This patch adds an timer to toggle the link detection. The timer will get retriggered as long as the reconnection interrupts accure. If the recon interrupts hold off for >1s we define the connection stable again. Signed-off-by: Michael Grzeschik --- drivers/net/arcnet/arcdevice.h | 2 ++ drivers/net/arcnet/arcnet.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h index 2edc0c0ab7c7..20bfb9ba83ea 100644 --- a/drivers/net/arcnet/arcdevice.h +++ b/drivers/net/arcnet/arcdevice.h @@ -267,6 +267,8 @@ struct arcnet_local { struct led_trigger *recon_led_trig; char recon_led_trig_name[ARCNET_LED_NAME_SZ]; + struct timer_list timer; + /* * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of * which can be used for either sending or receiving. The new dynamic diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c index 4242522ae86b..6ea963e3b89a 100644 --- a/drivers/net/arcnet/arcnet.c +++ b/drivers/net/arcnet/arcnet.c @@ -381,6 +381,16 @@ static void arcdev_setup(struct net_device *dev) dev->flags = IFF_BROADCAST; } +static void arcnet_timer(unsigned long data) +{ + struct net_device *dev = (struct net_device *)data; + + if (!netif_carrier_ok(dev)) { + netif_carrier_on(dev); + netdev_info(dev, "link up\n"); + } +} + struct net_device *alloc_arcdev(const char *name) { struct net_device *dev; @@ -392,6 +402,9 @@ struct net_device *alloc_arcdev(const char *name) struct arcnet_local *lp = netdev_priv(dev); spin_lock_init(&lp->lock); + init_timer(&lp->timer); + lp->timer.data = (unsigned long) dev; + lp->timer.function = arcnet_timer; } return dev; @@ -490,7 +503,9 @@ int arcnet_open(struct net_device *dev) lp->hw.intmask(dev, lp->intmask); arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); + netif_carrier_off(dev); netif_start_queue(dev); + mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000)); arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN); return 0; @@ -507,7 +522,10 @@ int arcnet_close(struct net_device *dev) struct arcnet_local *lp = netdev_priv(dev); arcnet_led_event(dev, ARCNET_LED_EVENT_STOP); + del_timer_sync(&lp->timer); + netif_stop_queue(dev); + netif_carrier_off(dev); /* flush TX and disable RX */ lp->hw.intmask(dev, 0); @@ -908,6 +926,12 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n", status); + if (netif_carrier_ok(dev)) { + netif_carrier_off(dev); + netdev_info(dev, "link down\n"); + } + mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000)); + arcnet_led_event(dev, ARCNET_LED_EVENT_RECON); /* MYRECON bit is at bit 7 of diagstatus */ if (diagstatus & 0x80) @@ -959,6 +983,7 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id) lp->num_recons = lp->network_down = 0; arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n"); + netif_carrier_on(dev); } if (didsomething)