cregit-Linux how code gets into the kernel

Release 4.11 drivers/net/usb/pegasus.c

Directory: drivers/net/usb
/*
 *  Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *      ChangeLog:
 *              ....    Most of the time spent on reading sources & docs.
 *              v0.2.x  First official release for the Linux kernel.
 *              v0.3.0  Beutified and structured, some bugs fixed.
 *              v0.3.x  URBifying bulk requests and bugfixing. First relatively
 *                      stable release. Still can touch device's registers only
 *                      from top-halves.
 *              v0.4.0  Control messages remained unurbified are now URBs.
 *                      Now we can touch the HW at any time.
 *              v0.4.9  Control urbs again use process context to wait. Argh...
 *                      Some long standing bugs (enable_net_traffic) fixed.
 *                      Also nasty trick about resubmiting control urb from
 *                      interrupt context used. Please let me know how it
 *                      behaves. Pegasus II support added since this version.
 *                      TODO: suppressing HCD warnings spewage on disconnect.
 *              v0.4.13 Ethernet address is now set at probe(), not at open()
 *                      time as this seems to break dhcpd.
 *              v0.5.0  branch to 2.5.x kernels
 *              v0.5.1  ethtool support added
 *              v0.5.5  rx socket buffers are in a pool and the their allocation
 *                      is out of the interrupt routine.
 *              ...
 *              v0.9.3  simplified [get|set]_register(s), async update registers
 *                      logic revisited, receive skb_pool removed.
 */

#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/usb.h>
#include <linux/module.h>
#include <asm/byteorder.h>
#include <linux/uaccess.h>
#include "pegasus.h"

/*
 * Version Information
 */

#define DRIVER_VERSION "v0.9.3 (2013/04/25)"

#define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>"

#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"


static const char driver_name[] = "pegasus";


#undef	PEGASUS_WRITE_EEPROM

#define	BMSR_MEDIA	(BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
                        BMSR_100FULL | BMSR_ANEGCAPABLE)


static bool loopback;

static bool mii_mode;

static char *devid;


static struct usb_eth_dev usb_dev_id[] = {

#define	PEGASUS_DEV(pn, vid, pid, flags)	\
	{.name = pn, .vendor = vid, .device = pid, .private = flags},

#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
	PEGASUS_DEV(pn, vid, pid, flags)
#include "pegasus.h"

#undef	PEGASUS_DEV

#undef	PEGASUS_DEV_CLASS
	{NULL, 0, 0, 0},
	{NULL, 0, 0, 0}
};


static struct usb_device_id pegasus_ids[] = {

#define	PEGASUS_DEV(pn, vid, pid, flags) \
	{.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
/*
 * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
 * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
 * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
 * case anyway, seeing as the pegasus is for "Wired" adaptors.
 */

#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
	{.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
        .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
#include "pegasus.h"

#undef	PEGASUS_DEV

#undef	PEGASUS_DEV_CLASS
	{},
	{}
};


MODULE_AUTHOR(DRIVER_AUTHOR);

MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
module_param(loopback, bool, 0);
module_param(mii_mode, bool, 0);
module_param(devid, charp, 0);
MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");

/* use ethtool to change the level for any given device */

static int msg_level = -1;
module_param(msg_level, int, 0);
MODULE_PARM_DESC(msg_level, "Override default message level");

MODULE_DEVICE_TABLE(usb, pegasus_ids);

static const struct net_device_ops pegasus_netdev_ops;

/*****/


static void async_ctrl_callback(struct urb *urb) { struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; int status = urb->status; if (status < 0) dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status); kfree(req); usb_free_urb(urb); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2640.62%436.36%
Petko Manolov2335.94%19.09%
Oliver Neukum710.94%19.09%
David Brownell34.69%19.09%
Linus Torvalds34.69%218.18%
Greg Kroah-Hartman11.56%19.09%
Harvey Harrison11.56%19.09%
Total64100.00%11100.00%


static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data) { u8 *buf; int ret; buf = kmalloc(size, GFP_NOIO); if (!buf) return -ENOMEM; ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0), PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0, indx, buf, size, 1000); if (ret < 0) netif_dbg(pegasus, drv, pegasus->net, "%s returned %d\n", __func__, ret); else if (ret <= size) memcpy(data, buf, ret); kfree(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4939.52%428.57%
Ben Hutchings4435.48%17.14%
Petko Manolov129.68%17.14%
David Brownell86.45%214.29%
Joe Perches54.03%17.14%
Greg Kroah-Hartman21.61%214.29%
Oliver Neukum21.61%17.14%
Linus Torvalds10.81%17.14%
Harvey Harrison10.81%17.14%
Total124100.00%14100.00%


static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, const void *data) { u8 *buf; int ret; buf = kmemdup(data, size, GFP_NOIO); if (!buf) return -ENOMEM; ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0, indx, buf, size, 100); if (ret < 0) netif_dbg(pegasus, drv, pegasus->net, "%s returned %d\n", __func__, ret); kfree(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5145.95%218.18%
Ben Hutchings3127.93%19.09%
Petko Manolov1311.71%19.09%
David Brownell87.21%218.18%
Joe Perches43.60%19.09%
Greg Kroah-Hartman21.80%218.18%
Linus Torvalds10.90%19.09%
Harvey Harrison10.90%19.09%
Total111100.00%11100.00%


static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data) { u8 *buf; int ret; buf = kmemdup(&data, 1, GFP_NOIO); if (!buf) return -ENOMEM; ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data, indx, buf, 1, 1000); if (ret < 0) netif_dbg(pegasus, drv, pegasus->net, "%s returned %d\n", __func__, ret); kfree(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Hutchings3128.97%110.00%
Linus Torvalds (pre-git)3028.04%220.00%
Petko Manolov2624.30%110.00%
David Brownell1211.21%220.00%
Joe Perches54.67%110.00%
Greg Kroah-Hartman21.87%220.00%
Harvey Harrison10.93%110.00%
Total107100.00%10100.00%


static int update_eth_regs_async(pegasus_t *pegasus) { int ret = -ENOMEM; struct urb *async_urb; struct usb_ctrlrequest *req; req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); if (req == NULL) return ret; async_urb = usb_alloc_urb(0, GFP_ATOMIC); if (async_urb == NULL) { kfree(req); return ret; } req->bRequestType = PEGASUS_REQT_WRITE; req->bRequest = PEGASUS_REQ_SET_REGS; req->wValue = cpu_to_le16(0); req->wIndex = cpu_to_le16(EthCtrl0); req->wLength = cpu_to_le16(3); usb_fill_control_urb(async_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (void *)req, pegasus->eth_regs, 3, async_ctrl_callback, req); ret = usb_submit_urb(async_urb, GFP_ATOMIC); if (ret) { if (ret == -ENODEV) netif_device_detach(pegasus->net); netif_err(pegasus, drv, pegasus->net, "%s returned %d\n", __func__, ret); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov7638.97%16.67%
Linus Torvalds (pre-git)7236.92%426.67%
David Brownell2110.77%213.33%
Linus Torvalds136.67%213.33%
Joe Perches52.56%16.67%
Michael Büsch31.54%16.67%
Greg Kroah-Hartman31.54%213.33%
Harvey Harrison10.51%16.67%
Josh Myer10.51%16.67%
Total195100.00%15100.00%


static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd) { int i; __u8 data[4] = { phy, 0, 0, indx }; __le16 regdi; int ret = -ETIMEDOUT; if (cmd & PHY_WRITE) { __le16 *t = (__le16 *) & data[1]; *t = cpu_to_le16(*regd); } set_register(p, PhyCtrl, 0); set_registers(p, PhyAddr, sizeof(data), data); set_register(p, PhyCtrl, (indx | cmd)); for (i = 0; i < REG_TIMEOUT; i++) { ret = get_registers(p, PhyCtrl, 1, data); if (ret < 0) goto fail; if (data[0] & PHY_DONE) break; } if (i >= REG_TIMEOUT) goto fail; if (cmd & PHY_READ) { ret = get_registers(p, PhyData, 2, &regdi); *regd = le16_to_cpu(regdi); return ret; } return 0; fail: netif_dbg(p, drv, p->net, "%s failed\n", __func__); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)12654.78%216.67%
Petko Manolov6427.83%325.00%
David Brownell187.83%216.67%
Linus Torvalds114.78%18.33%
Joe Perches83.48%18.33%
Greg Kroah-Hartman10.43%18.33%
Harvey Harrison10.43%18.33%
Al Viro10.43%18.33%
Total230100.00%12100.00%

/* Returns non-negative int on success, error on failure */
static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd) { return __mii_op(pegasus, phy, indx, regd, PHY_READ); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov34100.00%2100.00%
Total34100.00%2100.00%

/* Returns zero on success, error on failure */
static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd) { return __mii_op(pegasus, phy, indx, regd, PHY_WRITE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2676.47%480.00%
Petko Manolov823.53%120.00%
Total34100.00%5100.00%


static int mdio_read(struct net_device *dev, int phy_id, int loc) { pegasus_t *pegasus = netdev_priv(dev); u16 res; read_mii_word(pegasus, phy_id, loc, &res); return (int)res; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov3472.34%116.67%
Linus Torvalds (pre-git)919.15%233.33%
David Brownell24.26%116.67%
Greg Kroah-Hartman12.13%116.67%
Joe Perches12.13%116.67%
Total47100.00%6100.00%


static void mdio_write(struct net_device *dev, int phy_id, int loc, int val) { pegasus_t *pegasus = netdev_priv(dev); u16 data = val; write_mii_word(pegasus, phy_id, loc, &data); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov3780.43%250.00%
Dan Carpenter613.04%125.00%
Al Viro36.52%125.00%
Total46100.00%4100.00%


static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata) { int i; __u8 tmp; __le16 retdatai; int ret; set_register(pegasus, EpromCtrl, 0); set_register(pegasus, EpromOffset, index); set_register(pegasus, EpromCtrl, EPROM_READ); for (i = 0; i < REG_TIMEOUT; i++) { ret = get_registers(pegasus, EpromCtrl, 1, &tmp); if (tmp & EPROM_DONE) break; if (ret == -ESHUTDOWN) goto fail; } if (i >= REG_TIMEOUT) goto fail; ret = get_registers(pegasus, EpromData, 2, &retdatai); *retdata = le16_to_cpu(retdatai); return ret; fail: netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__); return -ETIMEDOUT; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10667.52%430.77%
David Brownell2314.65%215.38%
Linus Torvalds138.28%17.69%
Joe Perches95.73%17.69%
Petko Manolov31.91%215.38%
Greg Kroah-Hartman10.64%17.69%
Harvey Harrison10.64%17.69%
Al Viro10.64%17.69%
Total157100.00%13100.00%

#ifdef PEGASUS_WRITE_EEPROM
static inline void enable_eprom_write(pegasus_t *pegasus) { __u8 tmp; get_registers(pegasus, EthCtrl2, 1, &tmp); set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)37100.00%1100.00%
Total37100.00%1100.00%


static inline void disable_eprom_write(pegasus_t *pegasus) { __u8 tmp; get_registers(pegasus, EthCtrl2, 1, &tmp); set_register(pegasus, EpromCtrl, 0); set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)47100.00%1100.00%
Total47100.00%1100.00%


static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data) { int i; __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE }; int ret; __le16 le_data = cpu_to_le16(data); set_registers(pegasus, EpromOffset, 4, d); enable_eprom_write(pegasus); set_register(pegasus, EpromOffset, index); set_registers(pegasus, EpromData, 2, &le_data); set_register(pegasus, EpromCtrl, EPROM_WRITE); for (i = 0; i < REG_TIMEOUT; i++) { ret = get_registers(pegasus, EpromCtrl, 1, &tmp); if (ret == -ESHUTDOWN) goto fail; if (tmp & EPROM_DONE) break; } disable_eprom_write(pegasus); if (i >= REG_TIMEOUT) goto fail; return ret; fail: netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__); return -ETIMEDOUT; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)13274.16%110.00%
David Brownell2111.80%220.00%
Joe Perches95.06%110.00%
Michael Büsch95.06%110.00%
Petko Manolov52.81%330.00%
Greg Kroah-Hartman10.56%110.00%
Harvey Harrison10.56%110.00%
Total178100.00%10100.00%

#endif /* PEGASUS_WRITE_EEPROM */
static inline void get_node_id(pegasus_t *pegasus, __u8 *id) { int i; __u16 w16; for (i = 0; i < 3; i++) { read_eprom_word(pegasus, i, &w16); ((__le16 *) id)[i] = cpu_to_le16(w16); } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4674.19%562.50%
Linus Torvalds1422.58%112.50%
Al Viro11.61%112.50%
Harvey Harrison11.61%112.50%
Total62100.00%8100.00%


static void set_ethernet_addr(pegasus_t *pegasus) { __u8 node_id[6]; if (pegasus->features & PEGASUS_II) { get_registers(pegasus, 0x10, sizeof(node_id), node_id); } else { get_node_id(pegasus, node_id); set_registers(pegasus, EthID, sizeof(node_id), node_id); } memcpy(pegasus->net->dev_addr, node_id, sizeof(node_id)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5366.25%375.00%
Petko Manolov2733.75%125.00%
Total80100.00%4100.00%


static inline int reset_mac(pegasus_t *pegasus) { __u8 data = 0x8; int i; set_register(pegasus, EthCtrl1, data); for (i = 0; i < REG_TIMEOUT; i++) { get_registers(pegasus, EthCtrl1, 1, &data); if (~data & 0x08) { if (loopback) break; if (mii_mode && (pegasus->features & HAS_HOME_PNA)) set_register(pegasus, Gpio1, 0x34); else set_register(pegasus, Gpio1, 0x26); set_register(pegasus, Gpio0, pegasus->features); set_register(pegasus, Gpio0, DEFAULT_GPIO_SET); break; } } if (i == REG_TIMEOUT) return -ETIMEDOUT; if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS || usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) { set_register(pegasus, Gpio0, 0x24); set_register(pegasus, Gpio0, 0x26); } if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) { __u16 auxmode; read_mii_word(pegasus, 3, 0x1b, &auxmode); auxmode |= 4; write_mii_word(pegasus, 3, 0x1b, &auxmode); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)16975.45%654.55%
Greg Kroah-Hartman4118.30%19.09%
Petko Manolov135.80%327.27%
Linus Torvalds10.45%19.09%
Total224100.00%11100.00%


static int enable_net_traffic(struct net_device *dev, struct usb_device *usb) { __u16 linkpart; __u8 data[4]; pegasus_t *pegasus = netdev_priv(dev); int ret; read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart); data[0] = 0xc8; /* TX & RX enable, append status, no CRC */ data[1] = 0; if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL)) data[1] |= 0x20; /* set full duplex */ if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF)) data[1] |= 0x10; /* set 100 Mbps */ if (mii_mode) data[1] = 0; data[2] = loopback ? 0x09 : 0x01; memcpy(pegasus->eth_regs, data, sizeof(data)); ret = set_registers(pegasus, EthCtrl0, 3, data); if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS || usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 || usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) { u16 auxmode; read_mii_word(pegasus, 0, 0x1b, &auxmode); auxmode |= 4; write_mii_word(pegasus, 0, 0x1b, &auxmode); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)13862.16%850.00%
Petko Manolov6529.28%531.25%
Malte Doersam114.95%16.25%
David Brownell52.25%16.25%
Al Viro31.35%16.25%
Total222100.00%16100.00%


static void read_bulk_callback(struct urb *urb) { pegasus_t *pegasus = urb->context; struct net_device *net; int rx_status, count = urb->actual_length; int status = urb->status; u8 *buf = urb->transfer_buffer; __u16 pkt_len; if (!pegasus) return; net = pegasus->net; if (!netif_device_present(net) || !netif_running(net)) return; switch (status) { case 0: break; case -ETIME: netif_dbg(pegasus, rx_err, net, "reset MAC\n"); pegasus->flags &= ~PEGASUS_RX_BUSY; break; case -EPIPE: /* stall, or disconnect from TT */ /* FIXME schedule work to clear the halt */ netif_warn(pegasus, rx_err, net, "no rx stall recovery\n"); return; case -ENOENT: case -ECONNRESET: case -ESHUTDOWN: netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status); return; default: netif_dbg(pegasus, rx_err, net, "RX status %d\n", status); goto goon; } if (count < 4) goto goon; rx_status = buf[count - 2]; if (rx_status & 0x1e) { netif_dbg(pegasus, rx_err, net, "RX packet error %x\n", rx_status); pegasus->stats.rx_errors++; if (rx_status & 0x06) /* long or runt */ pegasus->stats.rx_length_errors++; if (rx_status & 0x08) pegasus->stats.rx_crc_errors++; if (rx_status & 0x10) /* extra bits */ pegasus->stats.rx_frame_errors++; goto goon; } if (pegasus->chip == 0x8513) { pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer); pkt_len &= 0x0fff; pegasus->rx_skb->data += 2; } else { pkt_len = buf[count - 3] << 8; pkt_len += buf[count - 4]; pkt_len &= 0xfff; pkt_len -= 4; } /* * If the packet is unreasonably long, quietly drop it rather than * kernel panicing by calling skb_put. */ if (pkt_len > PEGASUS_MTU) goto goon; /* * at this point we are sure pegasus->rx_skb != NULL * so we go ahead and pass up the packet. */ skb_put(pegasus->rx_skb, pkt_len); pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net); netif_rx(pegasus->rx_skb); pegasus->stats.rx_packets++; pegasus->stats.rx_bytes += pkt_len; if (pegasus->flags & PEGASUS_UNPLUG) return; pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU, GFP_ATOMIC); if (pegasus->rx_skb == NULL) goto tl_sched; goon: usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, usb_rcvbulkpipe(pegasus->usb, 1), pegasus->rx_skb->data, PEGASUS_MTU, read_bulk_callback, pegasus); rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC); if (rx_status == -ENODEV) netif_device_detach(pegasus->net); else if (rx_status) { pegasus->flags |= PEGASUS_RX_URB_FAIL; goto tl_sched; } else { pegasus->flags &= ~PEGASUS_RX_URB_FAIL; } return; tl_sched: tasklet_schedule(&pegasus->rx_tl); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)20639.85%830.77%
Petko Manolov18435.59%726.92%
David Brownell7614.70%27.69%
Joe Perches254.84%13.85%
Kevin Vigor101.93%13.85%
Oliver Neukum71.35%13.85%
Nicolas Kaiser20.39%13.85%
Linus Torvalds20.39%13.85%
Greg Kroah-Hartman20.39%13.85%
Al Viro10.19%13.85%
Josh Myer10.19%13.85%
Pete Zaitcev10.19%13.85%
Total517100.00%26100.00%


static void rx_fixup(unsigned long data) { pegasus_t *pegasus; int status; pegasus = (pegasus_t *) data; if (pegasus->flags & PEGASUS_UNPLUG) return; if (pegasus->flags & PEGASUS_RX_URB_FAIL) if (pegasus->rx_skb) goto try_again; if (pegasus->rx_skb == NULL) pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU, GFP_ATOMIC); if (pegasus->rx_skb == NULL) { netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n"); tasklet_schedule(&pegasus->rx_tl); return; } usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, usb_rcvbulkpipe(pegasus->usb, 1), pegasus->rx_skb->data, PEGASUS_MTU, read_bulk_callback, pegasus); try_again: status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC); if (status == -ENODEV) netif_device_detach(pegasus->net); else if (status) { pegasus->flags |= PEGASUS_RX_URB_FAIL; tasklet_schedule(&pegasus->rx_tl); } else { pegasus->flags &= ~PEGASUS_RX_URB_FAIL; } }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov14775.00%538.46%
David Brownell3015.31%215.38%
Linus Torvalds (pre-git)126.12%323.08%
Joe Perches52.55%17.69%
Greg Kroah-Hartman10.51%17.69%
Josh Myer10.51%17.69%
Total196100.00%13100.00%


static void write_bulk_callback(struct urb *urb) { pegasus_t *pegasus = urb->context; struct net_device *net; int status = urb->status; if (!pegasus) return; net = pegasus->net; if (!netif_device_present(net) || !netif_running(net)) return; switch (status) { case -EPIPE: /* FIXME schedule_work() to clear the tx halt */ netif_stop_queue(net); netif_warn(pegasus, tx_err, net, "no tx stall recovery\n"); return; case -ENOENT: case -ECONNRESET: case -ESHUTDOWN: netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status); return; default: netif_info(pegasus, tx_err, net, "TX status %d\n", status); /* FALL THROUGH */ case 0: break; } netif_trans_update(net); /* prevent tx timeout */ netif_wake_queue(net); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5135.92%750.00%
Petko Manolov4934.51%17.14%
Joe Perches1510.56%17.14%
David Brownell107.04%17.14%
Oliver Neukum74.93%17.14%
Micah Gruber64.23%17.14%
Florian Westphal32.11%17.14%
Eric Dumazet10.70%17.14%
Total142100.00%14100.00%


static void intr_callback(struct urb *urb) { pegasus_t *pegasus = urb->context; struct net_device *net; int res, status = urb->status; if (!pegasus) return; net = pegasus->net; switch (status) { case 0: break; case -ECONNRESET: /* unlink */ case -ENOENT: case -ESHUTDOWN: return; default: /* some Pegasus-I products report LOTS of data * toggle errors... avoid log spamming */ netif_dbg(pegasus, timer, net, "intr status %d\n", status); } if (urb->actual_length >= 6) { u8 *d = urb->transfer_buffer; /* byte 0 == tx_status1, reg 2B */ if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL |LATE_COL|JABBER_TIMEOUT)) { pegasus->stats.tx_errors++; if (d[0] & TX_UNDERRUN) pegasus->stats.tx_fifo_errors++; if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT)) pegasus->stats.tx_aborted_errors++; if (d[0] & LATE_COL) pegasus->stats.tx_window_errors++; } /* d[5].LINK_STATUS lies on some adapters. * d[0].NO_CARRIER kicks in only with failed TX. * ... so monitoring with MII may be safest. */ /* bytes 3-4 == rx_lostpkt, reg 2E/2F */ pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4]; } res = usb_submit_urb(urb, GFP_ATOMIC); if (res == -ENODEV) netif_device_detach(pegasus->net); if (res) netif_err(pegasus, timer, net, "can't resubmit interrupt urb, %d\n", res); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)12349.80%218.18%
Petko Manolov5622.67%218.18%
David Brownell4317.41%327.27%
Joe Perches114.45%19.09%
Oliver Neukum104.05%19.09%
Linus Torvalds31.21%19.09%
Christoph Lameter10.40%19.09%
Total247100.00%11100.00%


static void pegasus_tx_timeout(struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); netif_warn(pegasus, timer, net, "tx timeout\n"); usb_unlink_urb(pegasus->tx_urb); pegasus->stats.tx_errors++; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3577.78%457.14%
Joe Perches511.11%114.29%
Al Viro36.67%114.29%
David Brownell24.44%114.29%
Total45100.00%7100.00%


static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb, struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3; int res; __u16 l16 = skb->len; netif_stop_queue(net); ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16); skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len); usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb, usb_sndbulkpipe(pegasus->usb, 2), pegasus->tx_buff, count, write_bulk_callback, pegasus); if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) { netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res); switch (res) { case -EPIPE: /* stall, or disconnect from TT */ /* cleanup should already have been scheduled */ break; case -ENODEV: /* disconnect() upcoming */ case -EPERM: netif_device_detach(pegasus->net); break; default: pegasus->stats.tx_errors++; netif_start_queue(net); } } else { pegasus->stats.tx_packets++; pegasus->stats.tx_bytes += skb->len; } dev_kfree_skb(skb); return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)16772.29%422.22%
Petko Manolov219.09%211.11%
Linus Torvalds114.76%15.56%
David Brownell114.76%211.11%
Joe Perches52.16%15.56%
Al Viro41.73%211.11%
Oliver Neukum41.73%15.56%
Arnaldo Carvalho de Melo31.30%15.56%
Greg Kroah-Hartman20.87%15.56%
Patrick McHardy10.43%15.56%
Stephen Hemminger10.43%15.56%
Josh Myer10.43%15.56%
Total231100.00%18100.00%


static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev) { return &((pegasus_t *) netdev_priv(dev))->stats; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2589.29%375.00%
Al Viro310.71%125.00%
Total28100.00%4100.00%


static inline void disable_net_traffic(pegasus_t *pegasus) { __le16 tmp = cpu_to_le16(0); set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2676.47%375.00%
Michael Büsch823.53%125.00%
Total34100.00%4100.00%


static inline void get_interrupt_interval(pegasus_t *pegasus) { u16 data; u8 interval; read_eprom_word(pegasus, 4, &data); interval = data >> 8; if (pegasus->usb->speed != USB_SPEED_HIGH) { if (interval < 0x80) { netif_info(pegasus, timer, pegasus->net, "intr interval changed from %ums to %ums\n", interval, 0x80); interval = 0x80; data = (data & 0x00FF) | ((u16)interval << 8); #ifdef PEGASUS_WRITE_EEPROM write_eprom_word(pegasus, 4, data); #endif } } pegasus->intr_interval = interval; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5650.45%233.33%
Michael Büsch3228.83%116.67%
Kevin Vigor1210.81%116.67%
Joe Perches65.41%116.67%
David Brownell54.50%116.67%
Total111100.00%6100.00%


static void set_carrier(struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); u16 tmp; if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp)) return; if (tmp & BMSR_LSTATUS) netif_carrier_on(net); else netif_carrier_off(net); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov5189.47%250.00%
Al Viro58.77%125.00%
David Brownell11.75%125.00%
Total57100.00%4100.00%


static void free_all_urbs(pegasus_t *pegasus) { usb_free_urb(pegasus->intr_urb); usb_free_urb(pegasus->tx_urb); usb_free_urb(pegasus->rx_urb); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov31100.00%1100.00%
Total31100.00%1100.00%


static void unlink_all_urbs(pegasus_t *pegasus) { usb_kill_urb(pegasus->intr_urb); usb_kill_urb(pegasus->tx_urb); usb_kill_urb(pegasus->rx_urb); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov2890.32%150.00%
Borislav Petkov39.68%150.00%
Total31100.00%2100.00%


static int alloc_urbs(pegasus_t *pegasus) { int res = -ENOMEM; pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL); if (!pegasus->rx_urb) { return res; } pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL); if (!pegasus->tx_urb) { usb_free_urb(pegasus->rx_urb); return res; } pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL); if (!pegasus->intr_urb) { usb_free_urb(pegasus->tx_urb); usb_free_urb(pegasus->rx_urb); return res; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov109100.00%2100.00%
Total109100.00%2100.00%


static int pegasus_open(struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); int res=-ENOMEM; if (pegasus->rx_skb == NULL) pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU, GFP_KERNEL); if (!pegasus->rx_skb) goto exit; res = set_registers(pegasus, EthID, 6, net->dev_addr); usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, usb_rcvbulkpipe(pegasus->usb, 1), pegasus->rx_skb->data, PEGASUS_MTU, read_bulk_callback, pegasus); if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) { if (res == -ENODEV) netif_device_detach(pegasus->net); netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res); goto exit; } usb_fill_int_urb(pegasus->intr_urb, pegasus->usb, usb_rcvintpipe(pegasus->usb, 3), pegasus->intr_buff, sizeof(pegasus->intr_buff), intr_callback, pegasus, pegasus->intr_interval); if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) { if (res == -ENODEV) netif_device_detach(pegasus->net); netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res); usb_kill_urb(pegasus->rx_urb); goto exit; } res = enable_net_traffic(net, pegasus->usb); if (res < 0) { netif_dbg(pegasus, ifup, net, "can't enable_net_traffic() - %d\n", res); res = -EIO; usb_kill_urb(pegasus->rx_urb); usb_kill_urb(pegasus->intr_urb); goto exit; } set_carrier(net); netif_start_queue(net); netif_dbg(pegasus, ifup, net, "open\n"); res = 0; exit: return res; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)12537.88%731.82%
Petko Manolov10832.73%731.82%
David Brownell6419.39%29.09%
Joe Perches206.06%14.55%
Greg Kroah-Hartman61.82%29.09%
Al Viro30.91%14.55%
Josh Myer20.61%14.55%
Borislav Petkov20.61%14.55%
Total330100.00%22100.00%


static int pegasus_close(struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); netif_stop_queue(net); if (!(pegasus->flags & PEGASUS_UNPLUG)) disable_net_traffic(pegasus); tasklet_kill(&pegasus->rx_tl); unlink_all_urbs(pegasus); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3764.91%562.50%
Petko Manolov1729.82%225.00%
Al Viro35.26%112.50%
Total57100.00%8100.00%


static void pegasus_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { pegasus_t *pegasus = netdev_priv(dev); strlcpy(info->driver, driver_name, sizeof(info->driver)); strlcpy(info->version, DRIVER_VERSION, sizeof(info->version)); usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info)); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov6080.00%233.33%
Al Viro1216.00%233.33%
Jiri Pirko22.67%116.67%
Adrian Bunk11.33%116.67%
Total75100.00%6100.00%

/* also handles three patterns of some kind in hardware */ #define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY)
static void pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { pegasus_t *pegasus = netdev_priv(dev); wol->supported = WAKE_MAGIC | WAKE_PHY; wol->wolopts = pegasus->wolopts; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov41100.00%1100.00%
Total41100.00%1100.00%


static int pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { pegasus_t *pegasus = netdev_priv(dev); u8 reg78 = 0x04; int ret; if (wol->wolopts & ~WOL_SUPPORTED) return -EINVAL; if (wol->wolopts & WAKE_MAGIC) reg78 |= 0x80; if (wol->wolopts & WAKE_PHY) reg78 |= 0x40; /* FIXME this 0x10 bit still needs to get set in the chip... */ if (wol->wolopts) pegasus->eth_regs[0] |= 0x10; else pegasus->eth_regs[0] &= ~0x10; pegasus->wolopts = wol->wolopts; ret = set_register(pegasus, WakeupControl, reg78); if (!ret) ret = device_set_wakeup_enable(&pegasus->usb->dev, wol->wolopts); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov11078.57%133.33%
Ming Lei2920.71%133.33%
David Brownell10.71%133.33%
Total140100.00%3100.00%


static inline void pegasus_reset_wol(struct net_device *dev) { struct ethtool_wolinfo wol; memset(&wol, 0, sizeof wol); (void) pegasus_set_wol(dev, &wol); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov38100.00%1100.00%
Total38100.00%1100.00%


static int pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) { pegasus_t *pegasus; pegasus = netdev_priv(dev); mii_ethtool_gset(&pegasus->mii, ecmd); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov2255.00%266.67%
Al Viro1845.00%133.33%
Total40100.00%3100.00%


static int pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) { pegasus_t *pegasus = netdev_priv(dev); return mii_ethtool_sset(&pegasus->mii, ecmd); }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro1850.00%150.00%
Petko Manolov1850.00%150.00%
Total36100.00%2100.00%


static int pegasus_nway_reset(struct net_device *dev) { pegasus_t *pegasus = netdev_priv(dev); return mii_nway_restart(&pegasus->mii); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov2379.31%250.00%
Al Viro620.69%250.00%
Total29100.00%4100.00%


static u32 pegasus_get_link(struct net_device *dev) { pegasus_t *pegasus = netdev_priv(dev); return mii_link_ok(&pegasus->mii); }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro1655.17%133.33%
Petko Manolov1344.83%266.67%
Total29100.00%3100.00%


static u32 pegasus_get_msglevel(struct net_device *dev) { pegasus_t *pegasus = netdev_priv(dev); return pegasus->msg_enable; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov1664.00%250.00%
Al Viro832.00%125.00%
David Brownell14.00%125.00%
Total25100.00%4100.00%


static void pegasus_set_msglevel(struct net_device *dev, u32 v) { pegasus_t *pegasus = netdev_priv(dev); pegasus->msg_enable = v; }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov1655.17%250.00%
Al Viro1241.38%125.00%
David Brownell13.45%125.00%
Total29100.00%4100.00%

static const struct ethtool_ops ops = { .get_drvinfo = pegasus_get_drvinfo, .get_settings = pegasus_get_settings, .set_settings = pegasus_set_settings, .nway_reset = pegasus_nway_reset, .get_link = pegasus_get_link, .get_msglevel = pegasus_get_msglevel, .set_msglevel = pegasus_set_msglevel, .get_wol = pegasus_get_wol, .set_wol = pegasus_set_wol, };
static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd) { __u16 *data = (__u16 *) &rq->ifr_ifru; pegasus_t *pegasus = netdev_priv(net); int res; switch (cmd) { case SIOCDEVPRIVATE: data[0] = pegasus->phy; case SIOCDEVPRIVATE + 1: read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]); res = 0; break; case SIOCDEVPRIVATE + 2: if (!capable(CAP_NET_ADMIN)) return -EPERM; write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]); res = 0; break; default: res = -EOPNOTSUPP; } return res; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)12685.14%450.00%
Petko Manolov1812.16%225.00%
Al Viro42.70%225.00%
Total148100.00%8100.00%


static void pegasus_set_multicast(struct net_device *net) { pegasus_t *pegasus = netdev_priv(net); if (net->flags & IFF_PROMISC) { pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS; netif_info(pegasus, link, net, "Promiscuous mode enabled\n"); } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) { pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST; pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; netif_dbg(pegasus, link, net, "set allmulti\n"); } else { pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST; pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; } update_eth_regs_async(pegasus); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10582.68%654.55%
Joe Perches107.87%19.09%
David Brownell43.15%19.09%
Jiri Pirko43.15%19.09%
Al Viro32.36%19.09%
Petko Manolov10.79%19.09%
Total127100.00%11100.00%


static __u8 mii_phy_probe(pegasus_t *pegasus) { int i; __u16 tmp; for (i = 0; i < 32; i++) { read_mii_word(pegasus, i, MII_BMSR, &tmp); if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0) continue; else return i; } return 0xff; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)69100.00%2100.00%
Total69100.00%2100.00%


static inline void setup_pegasus_II(pegasus_t *pegasus) { __u8 data = 0xa5; set_register(pegasus, Reg1d, 0); set_register(pegasus, Reg7b, 1); mdelay(100); if ((pegasus->features & HAS_HOME_PNA) && mii_mode) set_register(pegasus, Reg7b, 0); else set_register(pegasus, Reg7b, 2); set_register(pegasus, 0x83, data); get_registers(pegasus, 0x83, 1, &data); if (data == 0xa5) pegasus->chip = 0x8513; else pegasus->chip = 0; set_register(pegasus, 0x80, 0xc0); set_register(pegasus, 0x83, 0xff); set_register(pegasus, 0x84, 0x01); if (pegasus->features & HAS_HOME_PNA && mii_mode) set_register(pegasus, Reg81, 6); else set_register(pegasus, Reg81, 2); }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov10865.06%360.00%
Linus Torvalds (pre-git)5834.94%240.00%
Total166100.00%5100.00%

static int pegasus_count; static struct workqueue_struct *pegasus_workqueue; #define CARRIER_CHECK_DELAY (2 * HZ)
static void check_carrier(struct work_struct *work) { pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work); set_carrier(pegasus->net); if (!(pegasus->flags & PEGASUS_UNPLUG)) { queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check, CARRIER_CHECK_DELAY); } }

Contributors

PersonTokensPropCommitsCommitProp
Petko Manolov4475.86%133.33%
David Howells1322.41%133.33%
Adrian Bunk11.72%133.33%
Total58100.00%3100.00%


static int pegasus_blacklisted(struct usb_device *udev) { struct usb_device_descriptor *udd = &udev->descriptor; /* Special quirk to keep the driver from handling the Belkin Bluetooth * dongle which happens to have the same ID. */ if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) && (udd->idProduct == cpu_to_le16(0x0121)) && (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) && (udd->bDeviceProtocol == 1)) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Benjamin Collins6088.24%150.00%
Michael Büsch811.76%150.00%
Total68100.00%2100.00%

/* we rely on probe() and remove() being serialized so we * don't need extra locking on pegasus_count. */
static void pegasus_dec_workqueue(void) { pegasus_count--; if (pegasus_count == 0) { destroy_workqueue(pegasus_workqueue); pegasus_workqueue = NULL; } }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell28100.00%1100.00%
Total28100.00%1100.00%


static int pegasus_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *dev = interface_to_usbdev(intf); struct net_device *net; pegasus_t *pegasus; int dev_index = id - pegasus_ids; int res = -ENOMEM; if (pegasus_blacklisted(dev)) return -ENODEV; if (pegasus_count == 0) { pegasus_workqueue = alloc_workqueue("pegasus", WQ_MEM_RECLAIM, 0); if (!pegasus_workqueue) return -ENOMEM; } pegasus_count++; net = alloc_etherdev(sizeof(struct pegasus)); if (!net) goto out; pegasus = netdev_priv(net); pegasus->dev_index = dev_index; res = alloc_urbs(pegasus); if (res < 0) { dev_err(&intf->dev, "can't allocate %s\n", "urbs"); goto out1; } tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus); INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier); pegasus->intf = intf; pegasus->usb = dev; pegasus->net = net; net->watchdog_timeo = PEGASUS_TX_TIMEOUT; net->netdev_ops = &pegasus_netdev_ops; net->ethtool_ops = &ops; pegasus->mii.dev = net; pegasus->mii.mdio_read = mdio_read; pegasus->mii.mdio_write = mdio_write; pegasus->mii.phy_id_mask = 0x1f; pegasus->mii.reg_num_mask = 0x1f; pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK); pegasus->features = usb_dev_id[dev_index].private; get_interrupt_interval(pegasus); if (reset_mac(pegasus)) { dev_err(&intf->dev, "can't reset MAC\n"); res = -EIO; goto out2; } set_ethernet_addr(pegasus); if (pegasus->features & PEGASUS_II) { dev_info(&intf->dev, "setup Pegasus II specific registers\n"); setup_pegasus_II(pegasus); } pegasus->phy = mii_phy_probe(pegasus); if (pegasus->phy == 0xff) { dev_warn(&intf->dev, "can't locate MII phy, using default\n"); pegasus->phy = 1; } pegasus->mii.phy_id = pegasus->phy; usb_set_intfdata(intf, pegasus); SET_NETDEV_DEV(net, &intf->dev); pegasus_reset_wol(net); res = register_netdev(net); if (res) goto out3; queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check, CARRIER_CHECK_DELAY); dev_info(&intf->dev, "%s, %s, %pM\n", net->name, usb_dev_id[dev_index].name, net->dev_addr); return 0; out3: usb_set_intfdata(intf, NULL); out2: free_all_urbs(pegasus); out1: free_netdev(net); out: pegasus_dec_workqueue(); return res; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)14829.78%1029.41%
Petko Manolov13026.16%823.53%
David Brownell9719.52%38.82%
Al Viro7314.69%38.82%
Greg Kroah-Hartman214.23%25.88%
Benjamin Collins112.21%12.94%
Bhaktipriya Shridhar51.01%12.94%
Linus Torvalds30.60%12.94%
Wilfried Klaebe30.60%12.94%
Oliver Neukum30.60%12.94%
David Howells10.20%12.94%
Joe Perches10.20%12.94%
Johannes Berg10.20%12.94%
Total497100.00%34100.00%


static void pegasus_disconnect(struct usb_interface *intf) { struct pegasus *pegasus = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); if (!pegasus) { dev_dbg(&intf->dev, "unregistering non-bound device?\n"); return; } pegasus->flags |= PEGASUS_UNPLUG; cancel_delayed_work(&pegasus->carrier_check); unregister_netdev(pegasus->net); unlink_all_urbs(pegasus); free_all_urbs(pegasus); if (pegasus->rx_skb != NULL) { dev_kfree_skb(pegasus->rx_skb); pegasus->rx_skb = NULL; } free_netdev(pegasus->net); pegasus_dec_workqueue(); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3935.45%426.67%
Petko Manolov2220.00%320.00%
Greg Kroah-Hartman1311.82%213.33%
Arnaldo Carvalho de Melo109.09%16.67%
David Brownell109.09%213.33%
Linus Torvalds109.09%16.67%
Kevin Vigor54.55%16.67%
Stephen Hemminger10.91%16.67%
Total110100.00%15100.00%


static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) { struct pegasus *pegasus = usb_get_intfdata(intf); netif_device_detach(pegasus->net); cancel_delayed_work(&pegasus->carrier_check); if (netif_running(pegasus->net)) { usb_kill_urb(pegasus->rx_urb); usb_kill_urb(pegasus->intr_urb); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell3450.75%250.00%
Petko Manolov3349.25%250.00%
Total67100.00%4100.00%


static int pegasus_resume(struct usb_interface *intf) { struct pegasus *pegasus = usb_get_intfdata(intf); netif_device_attach(pegasus->net); if (netif_running(pegasus->net)) { pegasus->rx_urb->status = 0; pegasus->rx_urb->actual_length = 0; read_bulk_callback(pegasus->rx_urb); pegasus->intr_urb->status = 0; pegasus->intr_urb->actual_length = 0; intr_callback(pegasus->intr_urb); } queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check, CARRIER_CHECK_DELAY); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell6969.00%266.67%
Petko Manolov3131.00%133.33%
Total100100.00%3100.00%

static const struct net_device_ops pegasus_netdev_ops = { .ndo_open = pegasus_open, .ndo_stop = pegasus_close, .ndo_do_ioctl = pegasus_ioctl, .ndo_start_xmit = pegasus_start_xmit, .ndo_set_rx_mode = pegasus_set_multicast, .ndo_get_stats = pegasus_netdev_stats, .ndo_tx_timeout = pegasus_tx_timeout, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, }; static struct usb_driver pegasus_driver = { .name = driver_name, .probe = pegasus_probe, .disconnect = pegasus_disconnect, .id_table = pegasus_ids, .suspend = pegasus_suspend, .resume = pegasus_resume, .disable_hub_initiated_lpm = 1, };
static void __init parse_id(char *id) { unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0; char *token, *name = NULL; if ((token = strsep(&id, ":")) != NULL) name = token; /* name now points to a null terminated string*/ if ((token = strsep(&id, ":")) != NULL) vendor_id = simple_strtoul(token, NULL, 16); if ((token = strsep(&id, ":")) != NULL) device_id = simple_strtoul(token, NULL, 16); flags = simple_strtoul(id, NULL, 16); pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n", driver_name, name, vendor_id, device_id, flags); if (vendor_id > 0x10000 || vendor_id == 0) return; if (device_id > 0x10000 || device_id == 0) return; for (i = 0; usb_dev_id[i].name; i++); usb_dev_id[i].name = name; usb_dev_id[i].vendor = vendor_id; usb_dev_id[i].device = device_id; usb_dev_id[i].private = flags; pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE; pegasus_ids[i].idVendor = vendor_id; pegasus_ids[i].idProduct = device_id; }

Contributors

PersonTokensPropCommitsCommitProp
A.YOSHIYAMA24099.59%150.00%
David Brownell10.41%150.00%
Total241100.00%2100.00%


static int __init pegasus_init(void) { pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION); if (devid) parse_id(devid); return usb_register(&pegasus_driver); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1850.00%233.33%
A.YOSHIYAMA925.00%116.67%
Petko Manolov719.44%116.67%
Greg Kroah-Hartman12.78%116.67%
Linus Torvalds12.78%116.67%
Total36100.00%6100.00%


static void __exit pegasus_exit(void) { usb_deregister(&pegasus_driver); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1493.33%266.67%
Greg Kroah-Hartman16.67%133.33%
Total15100.00%3100.00%

module_init(pegasus_init); module_exit(pegasus_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)272839.74%1815.93%
Petko Manolov204229.75%1815.93%
David Brownell6479.43%87.08%
A.YOSHIYAMA2824.11%10.88%
Al Viro2483.61%54.42%
Joe Perches1492.17%21.77%
Ben Hutchings1161.69%21.77%
Greg Kroah-Hartman1101.60%76.19%
Linus Torvalds1071.56%119.73%
Oliver Neukum881.28%43.54%
Benjamin Collins711.03%10.88%
Michael Büsch600.87%10.88%
Chris Rankin390.57%10.88%
Ming Lei290.42%10.88%
Kevin Vigor270.39%10.88%
David Howells140.20%10.88%
Arnaldo Carvalho de Melo130.19%21.77%
Malte Doersam110.16%10.88%
Rusty Russell100.15%21.77%
Harvey Harrison90.13%32.65%
Jiri Pirko70.10%32.65%
Josh Myer60.09%10.88%
Micah Gruber60.09%10.88%
Dan Carpenter60.09%10.88%
Sarah Sharp50.07%10.88%
Bhaktipriya Shridhar50.07%10.88%
Borislav Petkov50.07%10.88%
Dave Jones30.04%10.88%
Adrian Bunk30.04%10.88%
Wilfried Klaebe30.04%10.88%
Florian Westphal30.04%10.88%
Stephen Hemminger30.04%32.65%
Art Haas20.03%10.88%
Nicolas Kaiser20.03%10.88%
Patrick McHardy10.01%10.88%
Christoph Lameter10.01%10.88%
Pete Zaitcev10.01%10.88%
Johannes Berg10.01%10.88%
Eric Dumazet10.01%10.88%
Total6864100.00%113100.00%
Directory: drivers/net/usb
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.