xref: /openbmc/linux/drivers/net/usb/pegasus.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
25b2fc499SJeff Garzik /*
3bc65bacfSPetko Manolov  *  Copyright (c) 1999-2021 Petko Manolov (petkan@nucleusys.com)
45b2fc499SJeff Garzik  *
55b2fc499SJeff Garzik  */
65b2fc499SJeff Garzik 
75b2fc499SJeff Garzik #include <linux/sched.h>
85b2fc499SJeff Garzik #include <linux/slab.h>
95b2fc499SJeff Garzik #include <linux/init.h>
105b2fc499SJeff Garzik #include <linux/delay.h>
115b2fc499SJeff Garzik #include <linux/netdevice.h>
125b2fc499SJeff Garzik #include <linux/etherdevice.h>
135b2fc499SJeff Garzik #include <linux/ethtool.h>
145b2fc499SJeff Garzik #include <linux/mii.h>
155b2fc499SJeff Garzik #include <linux/usb.h>
165b2fc499SJeff Garzik #include <linux/module.h>
175b2fc499SJeff Garzik #include <asm/byteorder.h>
187c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
195b2fc499SJeff Garzik #include "pegasus.h"
205b2fc499SJeff Garzik 
215b2fc499SJeff Garzik /*
225b2fc499SJeff Garzik  * Version Information
235b2fc499SJeff Garzik  */
24323b3496SPetko Manolov #define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>"
255b2fc499SJeff Garzik #define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
265b2fc499SJeff Garzik 
275b2fc499SJeff Garzik static const char driver_name[] = "pegasus";
285b2fc499SJeff Garzik 
295b2fc499SJeff Garzik #undef	PEGASUS_WRITE_EEPROM
305b2fc499SJeff Garzik #define	BMSR_MEDIA	(BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
315b2fc499SJeff Garzik 			BMSR_100FULL | BMSR_ANEGCAPABLE)
322f5107c3SPetko Manolov #define CARRIER_CHECK_DELAY (2 * HZ)
335b2fc499SJeff Garzik 
34eb939922SRusty Russell static bool loopback;
35eb939922SRusty Russell static bool mii_mode;
365a9dbfe0SNicolas Kaiser static char *devid;
375b2fc499SJeff Garzik 
385b2fc499SJeff Garzik static struct usb_eth_dev usb_dev_id[] = {
395b2fc499SJeff Garzik #define	PEGASUS_DEV(pn, vid, pid, flags)	\
405b2fc499SJeff Garzik 	{.name = pn, .vendor = vid, .device = pid, .private = flags},
41ab854b24SChris Rankin #define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
42ab854b24SChris Rankin 	PEGASUS_DEV(pn, vid, pid, flags)
435b2fc499SJeff Garzik #include "pegasus.h"
445b2fc499SJeff Garzik #undef	PEGASUS_DEV
45ab854b24SChris Rankin #undef	PEGASUS_DEV_CLASS
465b2fc499SJeff Garzik 	{NULL, 0, 0, 0},
475b2fc499SJeff Garzik 	{NULL, 0, 0, 0}
485b2fc499SJeff Garzik };
495b2fc499SJeff Garzik 
505b2fc499SJeff Garzik static struct usb_device_id pegasus_ids[] = {
515b2fc499SJeff Garzik #define	PEGASUS_DEV(pn, vid, pid, flags) \
525b2fc499SJeff Garzik 	{.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
53ab854b24SChris Rankin /*
54ab854b24SChris Rankin  * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
55ab854b24SChris Rankin  * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
56ab854b24SChris Rankin  * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
57ab854b24SChris Rankin  * case anyway, seeing as the pegasus is for "Wired" adaptors.
58ab854b24SChris Rankin  */
59ab854b24SChris Rankin #define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
60ab854b24SChris Rankin 	{.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
61ab854b24SChris Rankin 	.idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
625b2fc499SJeff Garzik #include "pegasus.h"
635b2fc499SJeff Garzik #undef	PEGASUS_DEV
64ab854b24SChris Rankin #undef	PEGASUS_DEV_CLASS
655b2fc499SJeff Garzik 	{},
665b2fc499SJeff Garzik 	{}
675b2fc499SJeff Garzik };
685b2fc499SJeff Garzik 
695b2fc499SJeff Garzik MODULE_AUTHOR(DRIVER_AUTHOR);
705b2fc499SJeff Garzik MODULE_DESCRIPTION(DRIVER_DESC);
715b2fc499SJeff Garzik MODULE_LICENSE("GPL");
725b2fc499SJeff Garzik module_param(loopback, bool, 0);
735b2fc499SJeff Garzik module_param(mii_mode, bool, 0);
745b2fc499SJeff Garzik module_param(devid, charp, 0);
755b2fc499SJeff Garzik MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
765b2fc499SJeff Garzik MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
775b2fc499SJeff Garzik MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
785b2fc499SJeff Garzik 
795b2fc499SJeff Garzik /* use ethtool to change the level for any given device */
805b2fc499SJeff Garzik static int msg_level = -1;
815b2fc499SJeff Garzik module_param(msg_level, int, 0);
825b2fc499SJeff Garzik MODULE_PARM_DESC(msg_level, "Override default message level");
835b2fc499SJeff Garzik 
845b2fc499SJeff Garzik MODULE_DEVICE_TABLE(usb, pegasus_ids);
858cb89571SOliver Neukum static const struct net_device_ops pegasus_netdev_ops;
865b2fc499SJeff Garzik 
87323b3496SPetko Manolov /*****/
88323b3496SPetko Manolov 
async_ctrl_callback(struct urb * urb)89323b3496SPetko Manolov static void async_ctrl_callback(struct urb *urb)
905b2fc499SJeff Garzik {
91323b3496SPetko Manolov 	struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
92c94cb314SOliver Neukum 	int status = urb->status;
935b2fc499SJeff Garzik 
94323b3496SPetko Manolov 	if (status < 0)
95323b3496SPetko Manolov 		dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
96323b3496SPetko Manolov 	kfree(req);
97323b3496SPetko Manolov 	usb_free_urb(urb);
985b2fc499SJeff Garzik }
995b2fc499SJeff Garzik 
get_registers(pegasus_t * pegasus,__u16 indx,__u16 size,void * data)100323b3496SPetko Manolov static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
1015b2fc499SJeff Garzik {
102fb58cf4fSPetko Manolov 	return usb_control_msg_recv(pegasus->usb, 0, PEGASUS_REQ_GET_REGS,
103fb58cf4fSPetko Manolov 				   PEGASUS_REQT_READ, 0, indx, data, size,
104fb58cf4fSPetko Manolov 				   1000, GFP_NOIO);
1055b2fc499SJeff Garzik }
1065b2fc499SJeff Garzik 
set_registers(pegasus_t * pegasus,__u16 indx,__u16 size,const void * data)1075593523fSBen Hutchings static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size,
1085593523fSBen Hutchings 			 const void *data)
1095b2fc499SJeff Garzik {
1108a160e2eSPetko Manolov 	int ret;
1118a160e2eSPetko Manolov 
1128a160e2eSPetko Manolov 	ret = usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REGS,
113fb58cf4fSPetko Manolov 				    PEGASUS_REQT_WRITE, 0, indx, data, size,
114fb58cf4fSPetko Manolov 				    1000, GFP_NOIO);
1158a160e2eSPetko Manolov 	if (ret < 0)
1168a160e2eSPetko Manolov 		netif_dbg(pegasus, drv, pegasus->net, "%s failed with %d\n", __func__, ret);
1178a160e2eSPetko Manolov 
1188a160e2eSPetko Manolov 	return ret;
1195b2fc499SJeff Garzik }
1205b2fc499SJeff Garzik 
121fb58cf4fSPetko Manolov /*
122fb58cf4fSPetko Manolov  * There is only one way to write to a single ADM8511 register and this is via
123fb58cf4fSPetko Manolov  * specific control request.  'data' is ignored by the device, but it is here to
124fb58cf4fSPetko Manolov  * not break the API.
125fb58cf4fSPetko Manolov  */
set_register(pegasus_t * pegasus,__u16 indx,__u8 data)1265b2fc499SJeff Garzik static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
1275b2fc499SJeff Garzik {
128fb58cf4fSPetko Manolov 	void *buf = &data;
1298a160e2eSPetko Manolov 	int ret;
1305b2fc499SJeff Garzik 
1318a160e2eSPetko Manolov 	ret = usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REG,
132fb58cf4fSPetko Manolov 				    PEGASUS_REQT_WRITE, data, indx, buf, 1,
133fb58cf4fSPetko Manolov 				    1000, GFP_NOIO);
1348a160e2eSPetko Manolov 	if (ret < 0)
1358a160e2eSPetko Manolov 		netif_dbg(pegasus, drv, pegasus->net, "%s failed with %d\n", __func__, ret);
1368a160e2eSPetko Manolov 
1378a160e2eSPetko Manolov 	return ret;
1385b2fc499SJeff Garzik }
1395b2fc499SJeff Garzik 
update_eth_regs_async(pegasus_t * pegasus)1405b2fc499SJeff Garzik static int update_eth_regs_async(pegasus_t *pegasus)
1415b2fc499SJeff Garzik {
142323b3496SPetko Manolov 	int ret = -ENOMEM;
143323b3496SPetko Manolov 	struct urb *async_urb;
144323b3496SPetko Manolov 	struct usb_ctrlrequest *req;
1455b2fc499SJeff Garzik 
146323b3496SPetko Manolov 	req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
147323b3496SPetko Manolov 	if (req == NULL)
148323b3496SPetko Manolov 		return ret;
1495b2fc499SJeff Garzik 
150323b3496SPetko Manolov 	async_urb = usb_alloc_urb(0, GFP_ATOMIC);
151323b3496SPetko Manolov 	if (async_urb == NULL) {
152323b3496SPetko Manolov 		kfree(req);
153323b3496SPetko Manolov 		return ret;
154323b3496SPetko Manolov 	}
155323b3496SPetko Manolov 	req->bRequestType = PEGASUS_REQT_WRITE;
156323b3496SPetko Manolov 	req->bRequest = PEGASUS_REQ_SET_REGS;
157323b3496SPetko Manolov 	req->wValue = cpu_to_le16(0);
158323b3496SPetko Manolov 	req->wIndex = cpu_to_le16(EthCtrl0);
159323b3496SPetko Manolov 	req->wLength = cpu_to_le16(3);
1605b2fc499SJeff Garzik 
161323b3496SPetko Manolov 	usb_fill_control_urb(async_urb, pegasus->usb,
162323b3496SPetko Manolov 			     usb_sndctrlpipe(pegasus->usb, 0), (void *)req,
163323b3496SPetko Manolov 			     pegasus->eth_regs, 3, async_ctrl_callback, req);
164323b3496SPetko Manolov 
165323b3496SPetko Manolov 	ret = usb_submit_urb(async_urb, GFP_ATOMIC);
166323b3496SPetko Manolov 	if (ret) {
1675b2fc499SJeff Garzik 		if (ret == -ENODEV)
1685b2fc499SJeff Garzik 			netif_device_detach(pegasus->net);
169a475f603SJoe Perches 		netif_err(pegasus, drv, pegasus->net,
170323b3496SPetko Manolov 			  "%s returned %d\n", __func__, ret);
1715b2fc499SJeff Garzik 	}
1725b2fc499SJeff Garzik 	return ret;
1735b2fc499SJeff Garzik }
1745b2fc499SJeff Garzik 
__mii_op(pegasus_t * p,__u8 phy,__u8 indx,__u16 * regd,__u8 cmd)1752bd64701SPetko Manolov static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd)
1765b2fc499SJeff Garzik {
1778a160e2eSPetko Manolov 	int i, ret;
1785b2fc499SJeff Garzik 	__le16 regdi;
1798a160e2eSPetko Manolov 	__u8 data[4] = { phy, 0, 0, indx };
1805b2fc499SJeff Garzik 
1812bd64701SPetko Manolov 	if (cmd & PHY_WRITE) {
1822bd64701SPetko Manolov 		__le16 *t = (__le16 *) & data[1];
1832bd64701SPetko Manolov 		*t = cpu_to_le16(*regd);
1842bd64701SPetko Manolov 	}
1852bd64701SPetko Manolov 	set_register(p, PhyCtrl, 0);
1862bd64701SPetko Manolov 	set_registers(p, PhyAddr, sizeof(data), data);
1872bd64701SPetko Manolov 	set_register(p, PhyCtrl, (indx | cmd));
1885b2fc499SJeff Garzik 	for (i = 0; i < REG_TIMEOUT; i++) {
1892bd64701SPetko Manolov 		ret = get_registers(p, PhyCtrl, 1, data);
1902bd64701SPetko Manolov 		if (ret < 0)
1915b2fc499SJeff Garzik 			goto fail;
1925b2fc499SJeff Garzik 		if (data[0] & PHY_DONE)
1935b2fc499SJeff Garzik 			break;
1945b2fc499SJeff Garzik 	}
1958a160e2eSPetko Manolov 	if (i >= REG_TIMEOUT) {
1968a160e2eSPetko Manolov 		ret = -ETIMEDOUT;
197a475f603SJoe Perches 		goto fail;
1988a160e2eSPetko Manolov 	}
1992bd64701SPetko Manolov 	if (cmd & PHY_READ) {
2002bd64701SPetko Manolov 		ret = get_registers(p, PhyData, 2, &regdi);
2018a160e2eSPetko Manolov 		if (ret < 0)
2028a160e2eSPetko Manolov 			goto fail;
2035b2fc499SJeff Garzik 		*regd = le16_to_cpu(regdi);
2042bd64701SPetko Manolov 	}
2052bd64701SPetko Manolov 	return 0;
2065b2fc499SJeff Garzik fail:
2072bd64701SPetko Manolov 	netif_dbg(p, drv, p->net, "%s failed\n", __func__);
2085b2fc499SJeff Garzik 	return ret;
2095b2fc499SJeff Garzik }
2105b2fc499SJeff Garzik 
2112bd64701SPetko Manolov /* Returns non-negative int on success, error on failure */
read_mii_word(pegasus_t * pegasus,__u8 phy,__u8 indx,__u16 * regd)2122bd64701SPetko Manolov static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
2132bd64701SPetko Manolov {
2142bd64701SPetko Manolov 	return __mii_op(pegasus, phy, indx, regd, PHY_READ);
2152bd64701SPetko Manolov }
2162bd64701SPetko Manolov 
2172bd64701SPetko Manolov /* Returns zero on success, error on failure */
write_mii_word(pegasus_t * pegasus,__u8 phy,__u8 indx,__u16 * regd)2182bd64701SPetko Manolov static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
2192bd64701SPetko Manolov {
2202bd64701SPetko Manolov 	return __mii_op(pegasus, phy, indx, regd, PHY_WRITE);
2212bd64701SPetko Manolov }
2222bd64701SPetko Manolov 
mdio_read(struct net_device * dev,int phy_id,int loc)2235b2fc499SJeff Garzik static int mdio_read(struct net_device *dev, int phy_id, int loc)
2245b2fc499SJeff Garzik {
2258739cfefSJoe Perches 	pegasus_t *pegasus = netdev_priv(dev);
2268a160e2eSPetko Manolov 	int ret;
2275b2fc499SJeff Garzik 	u16 res;
2285b2fc499SJeff Garzik 
2298a160e2eSPetko Manolov 	ret = read_mii_word(pegasus, phy_id, loc, &res);
2308a160e2eSPetko Manolov 	if (ret < 0)
2318a160e2eSPetko Manolov 		return ret;
2328a160e2eSPetko Manolov 
2335b2fc499SJeff Garzik 	return (int)res;
2345b2fc499SJeff Garzik }
2355b2fc499SJeff Garzik 
mdio_write(struct net_device * dev,int phy_id,int loc,int val)2365b2fc499SJeff Garzik static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
2375b2fc499SJeff Garzik {
2388739cfefSJoe Perches 	pegasus_t *pegasus = netdev_priv(dev);
2393d64fc70SDan Carpenter 	u16 data = val;
2405b2fc499SJeff Garzik 
2413d64fc70SDan Carpenter 	write_mii_word(pegasus, phy_id, loc, &data);
2425b2fc499SJeff Garzik }
2435b2fc499SJeff Garzik 
read_eprom_word(pegasus_t * pegasus,__u8 index,__u16 * retdata)2445b2fc499SJeff Garzik static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata)
2455b2fc499SJeff Garzik {
2468a160e2eSPetko Manolov 	int ret, i;
2475b2fc499SJeff Garzik 	__le16 retdatai;
2488a160e2eSPetko Manolov 	__u8 tmp = 0;
2495b2fc499SJeff Garzik 
2505b2fc499SJeff Garzik 	set_register(pegasus, EpromCtrl, 0);
2515b2fc499SJeff Garzik 	set_register(pegasus, EpromOffset, index);
2525b2fc499SJeff Garzik 	set_register(pegasus, EpromCtrl, EPROM_READ);
2535b2fc499SJeff Garzik 
2545b2fc499SJeff Garzik 	for (i = 0; i < REG_TIMEOUT; i++) {
2555b2fc499SJeff Garzik 		ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
2568a160e2eSPetko Manolov 		if (ret < 0)
2578a160e2eSPetko Manolov 			goto fail;
2585b2fc499SJeff Garzik 		if (tmp & EPROM_DONE)
2595b2fc499SJeff Garzik 			break;
2608a160e2eSPetko Manolov 	}
2618a160e2eSPetko Manolov 	if (i >= REG_TIMEOUT) {
2628a160e2eSPetko Manolov 		ret = -ETIMEDOUT;
2635b2fc499SJeff Garzik 		goto fail;
2645b2fc499SJeff Garzik 	}
265a475f603SJoe Perches 
2665b2fc499SJeff Garzik 	ret = get_registers(pegasus, EpromData, 2, &retdatai);
2678a160e2eSPetko Manolov 	if (ret < 0)
2688a160e2eSPetko Manolov 		goto fail;
2695b2fc499SJeff Garzik 	*retdata = le16_to_cpu(retdatai);
2705b2fc499SJeff Garzik 	return ret;
2715b2fc499SJeff Garzik 
2725b2fc499SJeff Garzik fail:
2738a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__);
2748a160e2eSPetko Manolov 	return ret;
2755b2fc499SJeff Garzik }
2765b2fc499SJeff Garzik 
2775b2fc499SJeff Garzik #ifdef	PEGASUS_WRITE_EEPROM
enable_eprom_write(pegasus_t * pegasus)2785b2fc499SJeff Garzik static inline void enable_eprom_write(pegasus_t *pegasus)
2795b2fc499SJeff Garzik {
2805b2fc499SJeff Garzik 	__u8 tmp;
2815b2fc499SJeff Garzik 
2825b2fc499SJeff Garzik 	get_registers(pegasus, EthCtrl2, 1, &tmp);
2835b2fc499SJeff Garzik 	set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
2845b2fc499SJeff Garzik }
2855b2fc499SJeff Garzik 
disable_eprom_write(pegasus_t * pegasus)2865b2fc499SJeff Garzik static inline void disable_eprom_write(pegasus_t *pegasus)
2875b2fc499SJeff Garzik {
2885b2fc499SJeff Garzik 	__u8 tmp;
2895b2fc499SJeff Garzik 
2905b2fc499SJeff Garzik 	get_registers(pegasus, EthCtrl2, 1, &tmp);
2915b2fc499SJeff Garzik 	set_register(pegasus, EpromCtrl, 0);
2925b2fc499SJeff Garzik 	set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
2935b2fc499SJeff Garzik }
2945b2fc499SJeff Garzik 
write_eprom_word(pegasus_t * pegasus,__u8 index,__u16 data)2955b2fc499SJeff Garzik static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data)
2965b2fc499SJeff Garzik {
2975b2fc499SJeff Garzik 	int i;
2985b2fc499SJeff Garzik 	__u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
2995b2fc499SJeff Garzik 	int ret;
300e3453f63SMichael Buesch 	__le16 le_data = cpu_to_le16(data);
3015b2fc499SJeff Garzik 
3025b2fc499SJeff Garzik 	set_registers(pegasus, EpromOffset, 4, d);
3035b2fc499SJeff Garzik 	enable_eprom_write(pegasus);
3045b2fc499SJeff Garzik 	set_register(pegasus, EpromOffset, index);
305e3453f63SMichael Buesch 	set_registers(pegasus, EpromData, 2, &le_data);
3065b2fc499SJeff Garzik 	set_register(pegasus, EpromCtrl, EPROM_WRITE);
3075b2fc499SJeff Garzik 
3085b2fc499SJeff Garzik 	for (i = 0; i < REG_TIMEOUT; i++) {
3095b2fc499SJeff Garzik 		ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
3105b2fc499SJeff Garzik 		if (ret == -ESHUTDOWN)
3115b2fc499SJeff Garzik 			goto fail;
3125b2fc499SJeff Garzik 		if (tmp & EPROM_DONE)
3135b2fc499SJeff Garzik 			break;
3145b2fc499SJeff Garzik 	}
3155b2fc499SJeff Garzik 	disable_eprom_write(pegasus);
316a475f603SJoe Perches 	if (i >= REG_TIMEOUT)
317a475f603SJoe Perches 		goto fail;
318a475f603SJoe Perches 
3195b2fc499SJeff Garzik 	return ret;
320a475f603SJoe Perches 
3215b2fc499SJeff Garzik fail:
3228a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__);
3235b2fc499SJeff Garzik 	return -ETIMEDOUT;
3245b2fc499SJeff Garzik }
3255b2fc499SJeff Garzik #endif	/* PEGASUS_WRITE_EEPROM */
3265b2fc499SJeff Garzik 
get_node_id(pegasus_t * pegasus,u8 * id)327f30e25a9SPetko Manolov static inline int get_node_id(pegasus_t *pegasus, u8 *id)
3285b2fc499SJeff Garzik {
329f30e25a9SPetko Manolov 	int i, ret;
330f30e25a9SPetko Manolov 	u16 w16;
3315b2fc499SJeff Garzik 
3325b2fc499SJeff Garzik 	for (i = 0; i < 3; i++) {
333f30e25a9SPetko Manolov 		ret = read_eprom_word(pegasus, i, &w16);
334f30e25a9SPetko Manolov 		if (ret < 0)
335f30e25a9SPetko Manolov 			return ret;
336da2bbdccSHarvey Harrison 		((__le16 *) id)[i] = cpu_to_le16(w16);
3375b2fc499SJeff Garzik 	}
338f30e25a9SPetko Manolov 
339f30e25a9SPetko Manolov 	return 0;
3405b2fc499SJeff Garzik }
3415b2fc499SJeff Garzik 
set_ethernet_addr(pegasus_t * pegasus)3425b2fc499SJeff Garzik static void set_ethernet_addr(pegasus_t *pegasus)
3435b2fc499SJeff Garzik {
344f30e25a9SPetko Manolov 	int ret;
345f30e25a9SPetko Manolov 	u8 node_id[6];
3465b2fc499SJeff Garzik 
3475b2fc499SJeff Garzik 	if (pegasus->features & PEGASUS_II) {
348f30e25a9SPetko Manolov 		ret = get_registers(pegasus, 0x10, sizeof(node_id), node_id);
349f30e25a9SPetko Manolov 		if (ret < 0)
350f30e25a9SPetko Manolov 			goto err;
3515b2fc499SJeff Garzik 	} else {
352f30e25a9SPetko Manolov 		ret = get_node_id(pegasus, node_id);
353f30e25a9SPetko Manolov 		if (ret < 0)
354f30e25a9SPetko Manolov 			goto err;
355f30e25a9SPetko Manolov 		ret = set_registers(pegasus, EthID, sizeof(node_id), node_id);
356f30e25a9SPetko Manolov 		if (ret < 0)
357f30e25a9SPetko Manolov 			goto err;
3585b2fc499SJeff Garzik 	}
359f30e25a9SPetko Manolov 
360c51e5062SJakub Kicinski 	eth_hw_addr_set(pegasus->net, node_id);
361f30e25a9SPetko Manolov 
362f30e25a9SPetko Manolov 	return;
363f30e25a9SPetko Manolov err:
364f30e25a9SPetko Manolov 	eth_hw_addr_random(pegasus->net);
3658a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "software assigned MAC address.\n");
366f30e25a9SPetko Manolov 
367f30e25a9SPetko Manolov 	return;
3685b2fc499SJeff Garzik }
3695b2fc499SJeff Garzik 
reset_mac(pegasus_t * pegasus)3705b2fc499SJeff Garzik static inline int reset_mac(pegasus_t *pegasus)
3715b2fc499SJeff Garzik {
3728a160e2eSPetko Manolov 	int ret, i;
3735b2fc499SJeff Garzik 	__u8 data = 0x8;
3745b2fc499SJeff Garzik 
3755b2fc499SJeff Garzik 	set_register(pegasus, EthCtrl1, data);
3765b2fc499SJeff Garzik 	for (i = 0; i < REG_TIMEOUT; i++) {
3778a160e2eSPetko Manolov 		ret = get_registers(pegasus, EthCtrl1, 1, &data);
3788a160e2eSPetko Manolov 		if (ret < 0)
3798a160e2eSPetko Manolov 			goto fail;
3805b2fc499SJeff Garzik 		if (~data & 0x08) {
381681f1623SDan Carpenter 			if (loopback)
3825b2fc499SJeff Garzik 				break;
3835b2fc499SJeff Garzik 			if (mii_mode && (pegasus->features & HAS_HOME_PNA))
3845b2fc499SJeff Garzik 				set_register(pegasus, Gpio1, 0x34);
3855b2fc499SJeff Garzik 			else
3865b2fc499SJeff Garzik 				set_register(pegasus, Gpio1, 0x26);
3875b2fc499SJeff Garzik 			set_register(pegasus, Gpio0, pegasus->features);
3885b2fc499SJeff Garzik 			set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
3895b2fc499SJeff Garzik 			break;
3905b2fc499SJeff Garzik 		}
3915b2fc499SJeff Garzik 	}
3925b2fc499SJeff Garzik 	if (i == REG_TIMEOUT)
3935b2fc499SJeff Garzik 		return -ETIMEDOUT;
3945b2fc499SJeff Garzik 
3955b2fc499SJeff Garzik 	if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
3965b2fc499SJeff Garzik 	    usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
3975b2fc499SJeff Garzik 		set_register(pegasus, Gpio0, 0x24);
3985b2fc499SJeff Garzik 		set_register(pegasus, Gpio0, 0x26);
3995b2fc499SJeff Garzik 	}
4005b2fc499SJeff Garzik 	if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
4015b2fc499SJeff Garzik 		__u16 auxmode;
4028a160e2eSPetko Manolov 		ret = read_mii_word(pegasus, 3, 0x1b, &auxmode);
4038a160e2eSPetko Manolov 		if (ret < 0)
4048a160e2eSPetko Manolov 			goto fail;
4052bd64701SPetko Manolov 		auxmode |= 4;
4062bd64701SPetko Manolov 		write_mii_word(pegasus, 3, 0x1b, &auxmode);
4075b2fc499SJeff Garzik 	}
4085b2fc499SJeff Garzik 
4095b2fc499SJeff Garzik 	return 0;
4108a160e2eSPetko Manolov fail:
4118a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__);
4128a160e2eSPetko Manolov 	return ret;
4135b2fc499SJeff Garzik }
4145b2fc499SJeff Garzik 
enable_net_traffic(struct net_device * dev,struct usb_device * usb)4155b2fc499SJeff Garzik static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
4165b2fc499SJeff Garzik {
4175b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
4185b2fc499SJeff Garzik 	int ret;
4198a160e2eSPetko Manolov 	__u16 linkpart;
4208a160e2eSPetko Manolov 	__u8 data[4];
4215b2fc499SJeff Garzik 
4228a160e2eSPetko Manolov 	ret = read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
4238a160e2eSPetko Manolov 	if (ret < 0)
4248a160e2eSPetko Manolov 		goto fail;
4251a8deec0SPetko Manolov 	data[0] = 0xc8; /* TX & RX enable, append status, no CRC */
4265b2fc499SJeff Garzik 	data[1] = 0;
4275b2fc499SJeff Garzik 	if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
4285b2fc499SJeff Garzik 		data[1] |= 0x20;	/* set full duplex */
4295b2fc499SJeff Garzik 	if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
4305b2fc499SJeff Garzik 		data[1] |= 0x10;	/* set 100 Mbps */
4315b2fc499SJeff Garzik 	if (mii_mode)
4325b2fc499SJeff Garzik 		data[1] = 0;
433681f1623SDan Carpenter 	data[2] = loopback ? 0x09 : 0x01;
4345b2fc499SJeff Garzik 
4355b2fc499SJeff Garzik 	memcpy(pegasus->eth_regs, data, sizeof(data));
4365b2fc499SJeff Garzik 	ret = set_registers(pegasus, EthCtrl0, 3, data);
4375b2fc499SJeff Garzik 
4385b2fc499SJeff Garzik 	if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
4395b2fc499SJeff Garzik 	    usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
4405b2fc499SJeff Garzik 	    usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
4415b2fc499SJeff Garzik 		u16 auxmode;
4428a160e2eSPetko Manolov 		ret = read_mii_word(pegasus, 0, 0x1b, &auxmode);
4438a160e2eSPetko Manolov 		if (ret < 0)
4448a160e2eSPetko Manolov 			goto fail;
4452bd64701SPetko Manolov 		auxmode |= 4;
4462bd64701SPetko Manolov 		write_mii_word(pegasus, 0, 0x1b, &auxmode);
4475b2fc499SJeff Garzik 	}
4485b2fc499SJeff Garzik 
449ffc9c3ebSPetko Manolov 	return ret;
4508a160e2eSPetko Manolov fail:
4518a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__);
4525b2fc499SJeff Garzik 	return ret;
4535b2fc499SJeff Garzik }
4545b2fc499SJeff Garzik 
read_bulk_callback(struct urb * urb)4555b2fc499SJeff Garzik static void read_bulk_callback(struct urb *urb)
4565b2fc499SJeff Garzik {
4575b2fc499SJeff Garzik 	pegasus_t *pegasus = urb->context;
4585b2fc499SJeff Garzik 	struct net_device *net;
4598a160e2eSPetko Manolov 	u8 *buf = urb->transfer_buffer;
4605b2fc499SJeff Garzik 	int rx_status, count = urb->actual_length;
461c94cb314SOliver Neukum 	int status = urb->status;
4625b2fc499SJeff Garzik 	__u16 pkt_len;
4635b2fc499SJeff Garzik 
4645b2fc499SJeff Garzik 	if (!pegasus)
4655b2fc499SJeff Garzik 		return;
4665b2fc499SJeff Garzik 
4675b2fc499SJeff Garzik 	net = pegasus->net;
4685b2fc499SJeff Garzik 	if (!netif_device_present(net) || !netif_running(net))
4695b2fc499SJeff Garzik 		return;
4705b2fc499SJeff Garzik 
471c94cb314SOliver Neukum 	switch (status) {
4725b2fc499SJeff Garzik 	case 0:
4735b2fc499SJeff Garzik 		break;
4745b2fc499SJeff Garzik 	case -ETIME:
475a475f603SJoe Perches 		netif_dbg(pegasus, rx_err, net, "reset MAC\n");
4765b2fc499SJeff Garzik 		pegasus->flags &= ~PEGASUS_RX_BUSY;
4775b2fc499SJeff Garzik 		break;
4785b2fc499SJeff Garzik 	case -EPIPE:		/* stall, or disconnect from TT */
4795b2fc499SJeff Garzik 		/* FIXME schedule work to clear the halt */
480a475f603SJoe Perches 		netif_warn(pegasus, rx_err, net, "no rx stall recovery\n");
4815b2fc499SJeff Garzik 		return;
4825b2fc499SJeff Garzik 	case -ENOENT:
4835b2fc499SJeff Garzik 	case -ECONNRESET:
4845b2fc499SJeff Garzik 	case -ESHUTDOWN:
485a475f603SJoe Perches 		netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status);
4865b2fc499SJeff Garzik 		return;
4875b2fc499SJeff Garzik 	default:
488a475f603SJoe Perches 		netif_dbg(pegasus, rx_err, net, "RX status %d\n", status);
4895b2fc499SJeff Garzik 		goto goon;
4905b2fc499SJeff Garzik 	}
4915b2fc499SJeff Garzik 
492bbf178e0Sxypron.glpk@gmx.de 	if (count < 4)
4935b2fc499SJeff Garzik 		goto goon;
4945b2fc499SJeff Garzik 
4955b2fc499SJeff Garzik 	rx_status = buf[count - 2];
496ca506fcaSMatthias-Christian Ott 	if (rx_status & 0x1c) {
497a475f603SJoe Perches 		netif_dbg(pegasus, rx_err, net,
498a475f603SJoe Perches 			  "RX packet error %x\n", rx_status);
49982d82938STobias Klauser 		net->stats.rx_errors++;
500ca506fcaSMatthias-Christian Ott 		if (rx_status & 0x04)	/* runt	*/
50182d82938STobias Klauser 			net->stats.rx_length_errors++;
5025b2fc499SJeff Garzik 		if (rx_status & 0x08)
50382d82938STobias Klauser 			net->stats.rx_crc_errors++;
5045a9dbfe0SNicolas Kaiser 		if (rx_status & 0x10)	/* extra bits	*/
50582d82938STobias Klauser 			net->stats.rx_frame_errors++;
5065b2fc499SJeff Garzik 		goto goon;
5075b2fc499SJeff Garzik 	}
5085b2fc499SJeff Garzik 	if (pegasus->chip == 0x8513) {
5095b2fc499SJeff Garzik 		pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
5105b2fc499SJeff Garzik 		pkt_len &= 0x0fff;
5115b2fc499SJeff Garzik 		pegasus->rx_skb->data += 2;
5125b2fc499SJeff Garzik 	} else {
5135b2fc499SJeff Garzik 		pkt_len = buf[count - 3] << 8;
5145b2fc499SJeff Garzik 		pkt_len += buf[count - 4];
5155b2fc499SJeff Garzik 		pkt_len &= 0xfff;
5161a8deec0SPetko Manolov 		pkt_len -= 4;
5175b2fc499SJeff Garzik 	}
5185b2fc499SJeff Garzik 
5195b2fc499SJeff Garzik 	/*
5205b2fc499SJeff Garzik 	 * If the packet is unreasonably long, quietly drop it rather than
5215b2fc499SJeff Garzik 	 * kernel panicing by calling skb_put.
5225b2fc499SJeff Garzik 	 */
5235b2fc499SJeff Garzik 	if (pkt_len > PEGASUS_MTU)
5245b2fc499SJeff Garzik 		goto goon;
5255b2fc499SJeff Garzik 
5265b2fc499SJeff Garzik 	/*
5275b2fc499SJeff Garzik 	 * at this point we are sure pegasus->rx_skb != NULL
5285b2fc499SJeff Garzik 	 * so we go ahead and pass up the packet.
5295b2fc499SJeff Garzik 	 */
5305b2fc499SJeff Garzik 	skb_put(pegasus->rx_skb, pkt_len);
5315b2fc499SJeff Garzik 	pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
5325b2fc499SJeff Garzik 	netif_rx(pegasus->rx_skb);
53382d82938STobias Klauser 	net->stats.rx_packets++;
53482d82938STobias Klauser 	net->stats.rx_bytes += pkt_len;
5355b2fc499SJeff Garzik 
5365b2fc499SJeff Garzik 	if (pegasus->flags & PEGASUS_UNPLUG)
5375b2fc499SJeff Garzik 		return;
5385b2fc499SJeff Garzik 
539313a58e4SPetko Manolov 	pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU,
540313a58e4SPetko Manolov 						      GFP_ATOMIC);
5415b2fc499SJeff Garzik 
5425b2fc499SJeff Garzik 	if (pegasus->rx_skb == NULL)
5435b2fc499SJeff Garzik 		goto tl_sched;
5445b2fc499SJeff Garzik goon:
5455b2fc499SJeff Garzik 	usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
5465b2fc499SJeff Garzik 			  usb_rcvbulkpipe(pegasus->usb, 1),
547b7302ca0SPetko Manolov 			  pegasus->rx_skb->data, PEGASUS_MTU,
5485b2fc499SJeff Garzik 			  read_bulk_callback, pegasus);
5495b2fc499SJeff Garzik 	rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
5505b2fc499SJeff Garzik 	if (rx_status == -ENODEV)
5515b2fc499SJeff Garzik 		netif_device_detach(pegasus->net);
5525b2fc499SJeff Garzik 	else if (rx_status) {
5535b2fc499SJeff Garzik 		pegasus->flags |= PEGASUS_RX_URB_FAIL;
5545b2fc499SJeff Garzik 		goto tl_sched;
5555b2fc499SJeff Garzik 	} else {
5565b2fc499SJeff Garzik 		pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
5575b2fc499SJeff Garzik 	}
5585b2fc499SJeff Garzik 
5595b2fc499SJeff Garzik 	return;
5605b2fc499SJeff Garzik 
5615b2fc499SJeff Garzik tl_sched:
5625b2fc499SJeff Garzik 	tasklet_schedule(&pegasus->rx_tl);
5635b2fc499SJeff Garzik }
5645b2fc499SJeff Garzik 
rx_fixup(struct tasklet_struct * t)56523a64c51SEmil Renner Berthing static void rx_fixup(struct tasklet_struct *t)
5665b2fc499SJeff Garzik {
56723a64c51SEmil Renner Berthing 	pegasus_t *pegasus = from_tasklet(pegasus, t, rx_tl);
5685b2fc499SJeff Garzik 	int status;
5695b2fc499SJeff Garzik 
5705b2fc499SJeff Garzik 	if (pegasus->flags & PEGASUS_UNPLUG)
5715b2fc499SJeff Garzik 		return;
5725b2fc499SJeff Garzik 
5735b2fc499SJeff Garzik 	if (pegasus->flags & PEGASUS_RX_URB_FAIL)
5745b2fc499SJeff Garzik 		if (pegasus->rx_skb)
5755b2fc499SJeff Garzik 			goto try_again;
5765a9dbfe0SNicolas Kaiser 	if (pegasus->rx_skb == NULL)
577313a58e4SPetko Manolov 		pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
578313a58e4SPetko Manolov 							      PEGASUS_MTU,
579313a58e4SPetko Manolov 							      GFP_ATOMIC);
5805b2fc499SJeff Garzik 	if (pegasus->rx_skb == NULL) {
581a475f603SJoe Perches 		netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n");
5825b2fc499SJeff Garzik 		tasklet_schedule(&pegasus->rx_tl);
583313a58e4SPetko Manolov 		return;
5845b2fc499SJeff Garzik 	}
5855b2fc499SJeff Garzik 	usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
5865b2fc499SJeff Garzik 			  usb_rcvbulkpipe(pegasus->usb, 1),
587b7302ca0SPetko Manolov 			  pegasus->rx_skb->data, PEGASUS_MTU,
5885b2fc499SJeff Garzik 			  read_bulk_callback, pegasus);
5895b2fc499SJeff Garzik try_again:
5905b2fc499SJeff Garzik 	status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
5915b2fc499SJeff Garzik 	if (status == -ENODEV)
5925b2fc499SJeff Garzik 		netif_device_detach(pegasus->net);
5935b2fc499SJeff Garzik 	else if (status) {
5945b2fc499SJeff Garzik 		pegasus->flags |= PEGASUS_RX_URB_FAIL;
5955b2fc499SJeff Garzik 		tasklet_schedule(&pegasus->rx_tl);
5965b2fc499SJeff Garzik 	} else {
5975b2fc499SJeff Garzik 		pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
5985b2fc499SJeff Garzik 	}
5995b2fc499SJeff Garzik }
6005b2fc499SJeff Garzik 
write_bulk_callback(struct urb * urb)6015b2fc499SJeff Garzik static void write_bulk_callback(struct urb *urb)
6025b2fc499SJeff Garzik {
6035b2fc499SJeff Garzik 	pegasus_t *pegasus = urb->context;
6049351982bSMicah Gruber 	struct net_device *net;
605c94cb314SOliver Neukum 	int status = urb->status;
6065b2fc499SJeff Garzik 
6075b2fc499SJeff Garzik 	if (!pegasus)
6085b2fc499SJeff Garzik 		return;
6095b2fc499SJeff Garzik 
6109351982bSMicah Gruber 	net = pegasus->net;
6119351982bSMicah Gruber 
6125b2fc499SJeff Garzik 	if (!netif_device_present(net) || !netif_running(net))
6135b2fc499SJeff Garzik 		return;
6145b2fc499SJeff Garzik 
615c94cb314SOliver Neukum 	switch (status) {
6165b2fc499SJeff Garzik 	case -EPIPE:
6175b2fc499SJeff Garzik 		/* FIXME schedule_work() to clear the tx halt */
6185b2fc499SJeff Garzik 		netif_stop_queue(net);
619a475f603SJoe Perches 		netif_warn(pegasus, tx_err, net, "no tx stall recovery\n");
6205b2fc499SJeff Garzik 		return;
6215b2fc499SJeff Garzik 	case -ENOENT:
6225b2fc499SJeff Garzik 	case -ECONNRESET:
6235b2fc499SJeff Garzik 	case -ESHUTDOWN:
624a475f603SJoe Perches 		netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status);
6255b2fc499SJeff Garzik 		return;
6265b2fc499SJeff Garzik 	default:
627a475f603SJoe Perches 		netif_info(pegasus, tx_err, net, "TX status %d\n", status);
628df561f66SGustavo A. R. Silva 		fallthrough;
6295b2fc499SJeff Garzik 	case 0:
6305b2fc499SJeff Garzik 		break;
6315b2fc499SJeff Garzik 	}
6325b2fc499SJeff Garzik 
633860e9538SFlorian Westphal 	netif_trans_update(net); /* prevent tx timeout */
6345b2fc499SJeff Garzik 	netif_wake_queue(net);
6355b2fc499SJeff Garzik }
6365b2fc499SJeff Garzik 
intr_callback(struct urb * urb)6375b2fc499SJeff Garzik static void intr_callback(struct urb *urb)
6385b2fc499SJeff Garzik {
6395b2fc499SJeff Garzik 	pegasus_t *pegasus = urb->context;
6405b2fc499SJeff Garzik 	struct net_device *net;
641c94cb314SOliver Neukum 	int res, status = urb->status;
6425b2fc499SJeff Garzik 
6435b2fc499SJeff Garzik 	if (!pegasus)
6445b2fc499SJeff Garzik 		return;
6455b2fc499SJeff Garzik 	net = pegasus->net;
6465b2fc499SJeff Garzik 
647c94cb314SOliver Neukum 	switch (status) {
6485b2fc499SJeff Garzik 	case 0:
6495b2fc499SJeff Garzik 		break;
6505b2fc499SJeff Garzik 	case -ECONNRESET:	/* unlink */
6515b2fc499SJeff Garzik 	case -ENOENT:
6525b2fc499SJeff Garzik 	case -ESHUTDOWN:
6535b2fc499SJeff Garzik 		return;
6545b2fc499SJeff Garzik 	default:
6555b2fc499SJeff Garzik 		/* some Pegasus-I products report LOTS of data
6565b2fc499SJeff Garzik 		 * toggle errors... avoid log spamming
6575b2fc499SJeff Garzik 		 */
658a475f603SJoe Perches 		netif_dbg(pegasus, timer, net, "intr status %d\n", status);
6595b2fc499SJeff Garzik 	}
6605b2fc499SJeff Garzik 
6615b2fc499SJeff Garzik 	if (urb->actual_length >= 6) {
6625b2fc499SJeff Garzik 		u8 *d = urb->transfer_buffer;
6635b2fc499SJeff Garzik 
6645b2fc499SJeff Garzik 		/* byte 0 == tx_status1, reg 2B */
6655b2fc499SJeff Garzik 		if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
6665b2fc499SJeff Garzik 					|LATE_COL|JABBER_TIMEOUT)) {
66782d82938STobias Klauser 			net->stats.tx_errors++;
6685b2fc499SJeff Garzik 			if (d[0] & TX_UNDERRUN)
66982d82938STobias Klauser 				net->stats.tx_fifo_errors++;
6705b2fc499SJeff Garzik 			if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
67182d82938STobias Klauser 				net->stats.tx_aborted_errors++;
6725b2fc499SJeff Garzik 			if (d[0] & LATE_COL)
67382d82938STobias Klauser 				net->stats.tx_window_errors++;
6745b2fc499SJeff Garzik 		}
6755b2fc499SJeff Garzik 
6765b2fc499SJeff Garzik 		/* d[5].LINK_STATUS lies on some adapters.
6775b2fc499SJeff Garzik 		 * d[0].NO_CARRIER kicks in only with failed TX.
6785b2fc499SJeff Garzik 		 * ... so monitoring with MII may be safest.
6795b2fc499SJeff Garzik 		 */
6805b2fc499SJeff Garzik 
6815b2fc499SJeff Garzik 		/* bytes 3-4 == rx_lostpkt, reg 2E/2F */
68282d82938STobias Klauser 		net->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
6835b2fc499SJeff Garzik 	}
6845b2fc499SJeff Garzik 
685c94cb314SOliver Neukum 	res = usb_submit_urb(urb, GFP_ATOMIC);
686c94cb314SOliver Neukum 	if (res == -ENODEV)
6875b2fc499SJeff Garzik 		netif_device_detach(pegasus->net);
688a475f603SJoe Perches 	if (res)
689a475f603SJoe Perches 		netif_err(pegasus, timer, net,
690a475f603SJoe Perches 			  "can't resubmit interrupt urb, %d\n", res);
6915b2fc499SJeff Garzik }
6925b2fc499SJeff Garzik 
pegasus_tx_timeout(struct net_device * net,unsigned int txqueue)6930290bd29SMichael S. Tsirkin static void pegasus_tx_timeout(struct net_device *net, unsigned int txqueue)
6945b2fc499SJeff Garzik {
6955b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
696a475f603SJoe Perches 	netif_warn(pegasus, timer, net, "tx timeout\n");
6975b2fc499SJeff Garzik 	usb_unlink_urb(pegasus->tx_urb);
69882d82938STobias Klauser 	net->stats.tx_errors++;
6995b2fc499SJeff Garzik }
7005b2fc499SJeff Garzik 
pegasus_start_xmit(struct sk_buff * skb,struct net_device * net)70125a79c41SStephen Hemminger static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
70225a79c41SStephen Hemminger 					    struct net_device *net)
7035b2fc499SJeff Garzik {
7045b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
7055b2fc499SJeff Garzik 	int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
7065b2fc499SJeff Garzik 	int res;
7075b2fc499SJeff Garzik 	__u16 l16 = skb->len;
7085b2fc499SJeff Garzik 
7095b2fc499SJeff Garzik 	netif_stop_queue(net);
7105b2fc499SJeff Garzik 
7115b2fc499SJeff Garzik 	((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
7125b2fc499SJeff Garzik 	skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
7135b2fc499SJeff Garzik 	usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
7145b2fc499SJeff Garzik 			  usb_sndbulkpipe(pegasus->usb, 2),
7155b2fc499SJeff Garzik 			  pegasus->tx_buff, count,
7165b2fc499SJeff Garzik 			  write_bulk_callback, pegasus);
7175b2fc499SJeff Garzik 	if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
718a475f603SJoe Perches 		netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res);
7195b2fc499SJeff Garzik 		switch (res) {
7205b2fc499SJeff Garzik 		case -EPIPE:		/* stall, or disconnect from TT */
7215b2fc499SJeff Garzik 			/* cleanup should already have been scheduled */
7225b2fc499SJeff Garzik 			break;
7235b2fc499SJeff Garzik 		case -ENODEV:		/* disconnect() upcoming */
7249dd014ebSOliver Neukum 		case -EPERM:
7255b2fc499SJeff Garzik 			netif_device_detach(pegasus->net);
7265b2fc499SJeff Garzik 			break;
7275b2fc499SJeff Garzik 		default:
72882d82938STobias Klauser 			net->stats.tx_errors++;
7295b2fc499SJeff Garzik 			netif_start_queue(net);
7305b2fc499SJeff Garzik 		}
7315b2fc499SJeff Garzik 	} else {
73282d82938STobias Klauser 		net->stats.tx_packets++;
73382d82938STobias Klauser 		net->stats.tx_bytes += skb->len;
7345b2fc499SJeff Garzik 	}
7355b2fc499SJeff Garzik 	dev_kfree_skb(skb);
7365b2fc499SJeff Garzik 
7376ed10654SPatrick McHardy 	return NETDEV_TX_OK;
7385b2fc499SJeff Garzik }
7395b2fc499SJeff Garzik 
disable_net_traffic(pegasus_t * pegasus)7405b2fc499SJeff Garzik static inline void disable_net_traffic(pegasus_t *pegasus)
7415b2fc499SJeff Garzik {
742e3453f63SMichael Buesch 	__le16 tmp = cpu_to_le16(0);
7435b2fc499SJeff Garzik 
744e3453f63SMichael Buesch 	set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
7455b2fc499SJeff Garzik }
7465b2fc499SJeff Garzik 
get_interrupt_interval(pegasus_t * pegasus)747af35fc37SPavel Skripkin static inline int get_interrupt_interval(pegasus_t *pegasus)
7485b2fc499SJeff Garzik {
749e3453f63SMichael Buesch 	u16 data;
750e3453f63SMichael Buesch 	u8 interval;
751af35fc37SPavel Skripkin 	int ret;
7525b2fc499SJeff Garzik 
753af35fc37SPavel Skripkin 	ret = read_eprom_word(pegasus, 4, &data);
754af35fc37SPavel Skripkin 	if (ret < 0)
755af35fc37SPavel Skripkin 		return ret;
756af35fc37SPavel Skripkin 
757e3453f63SMichael Buesch 	interval = data >> 8;
7585b2fc499SJeff Garzik 	if (pegasus->usb->speed != USB_SPEED_HIGH) {
759e3453f63SMichael Buesch 		if (interval < 0x80) {
760a475f603SJoe Perches 			netif_info(pegasus, timer, pegasus->net,
761a475f603SJoe Perches 				   "intr interval changed from %ums to %ums\n",
762e3453f63SMichael Buesch 				   interval, 0x80);
763e3453f63SMichael Buesch 			interval = 0x80;
764e3453f63SMichael Buesch 			data = (data & 0x00FF) | ((u16)interval << 8);
7655b2fc499SJeff Garzik #ifdef PEGASUS_WRITE_EEPROM
766e3453f63SMichael Buesch 			write_eprom_word(pegasus, 4, data);
7675b2fc499SJeff Garzik #endif
7685b2fc499SJeff Garzik 		}
7695b2fc499SJeff Garzik 	}
770e3453f63SMichael Buesch 	pegasus->intr_interval = interval;
771af35fc37SPavel Skripkin 
772af35fc37SPavel Skripkin 	return 0;
7735b2fc499SJeff Garzik }
7745b2fc499SJeff Garzik 
set_carrier(struct net_device * net)7755b2fc499SJeff Garzik static void set_carrier(struct net_device *net)
7765b2fc499SJeff Garzik {
7775b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
7785b2fc499SJeff Garzik 	u16 tmp;
7795b2fc499SJeff Garzik 
7805b2fc499SJeff Garzik 	if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
7815b2fc499SJeff Garzik 		return;
7825b2fc499SJeff Garzik 
7835b2fc499SJeff Garzik 	if (tmp & BMSR_LSTATUS)
7845b2fc499SJeff Garzik 		netif_carrier_on(net);
7855b2fc499SJeff Garzik 	else
7865b2fc499SJeff Garzik 		netif_carrier_off(net);
7875b2fc499SJeff Garzik }
7885b2fc499SJeff Garzik 
free_all_urbs(pegasus_t * pegasus)7895b2fc499SJeff Garzik static void free_all_urbs(pegasus_t *pegasus)
7905b2fc499SJeff Garzik {
7915b2fc499SJeff Garzik 	usb_free_urb(pegasus->intr_urb);
7925b2fc499SJeff Garzik 	usb_free_urb(pegasus->tx_urb);
7935b2fc499SJeff Garzik 	usb_free_urb(pegasus->rx_urb);
7945b2fc499SJeff Garzik }
7955b2fc499SJeff Garzik 
unlink_all_urbs(pegasus_t * pegasus)7965b2fc499SJeff Garzik static void unlink_all_urbs(pegasus_t *pegasus)
7975b2fc499SJeff Garzik {
7985b2fc499SJeff Garzik 	usb_kill_urb(pegasus->intr_urb);
7995b2fc499SJeff Garzik 	usb_kill_urb(pegasus->tx_urb);
8005b2fc499SJeff Garzik 	usb_kill_urb(pegasus->rx_urb);
8015b2fc499SJeff Garzik }
8025b2fc499SJeff Garzik 
alloc_urbs(pegasus_t * pegasus)8035b2fc499SJeff Garzik static int alloc_urbs(pegasus_t *pegasus)
8045b2fc499SJeff Garzik {
805323b3496SPetko Manolov 	int res = -ENOMEM;
806323b3496SPetko Manolov 
8075b2fc499SJeff Garzik 	pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
8085b2fc499SJeff Garzik 	if (!pegasus->rx_urb) {
809323b3496SPetko Manolov 		return res;
8105b2fc499SJeff Garzik 	}
8115b2fc499SJeff Garzik 	pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
8125b2fc499SJeff Garzik 	if (!pegasus->tx_urb) {
8135b2fc499SJeff Garzik 		usb_free_urb(pegasus->rx_urb);
814323b3496SPetko Manolov 		return res;
8155b2fc499SJeff Garzik 	}
8165b2fc499SJeff Garzik 	pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
8175b2fc499SJeff Garzik 	if (!pegasus->intr_urb) {
8185b2fc499SJeff Garzik 		usb_free_urb(pegasus->tx_urb);
8195b2fc499SJeff Garzik 		usb_free_urb(pegasus->rx_urb);
820323b3496SPetko Manolov 		return res;
8215b2fc499SJeff Garzik 	}
8225b2fc499SJeff Garzik 
823323b3496SPetko Manolov 	return 0;
8245b2fc499SJeff Garzik }
8255b2fc499SJeff Garzik 
pegasus_open(struct net_device * net)8265b2fc499SJeff Garzik static int pegasus_open(struct net_device *net)
8275b2fc499SJeff Garzik {
8285b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
829323b3496SPetko Manolov 	int res=-ENOMEM;
8305b2fc499SJeff Garzik 
8315b2fc499SJeff Garzik 	if (pegasus->rx_skb == NULL)
832313a58e4SPetko Manolov 		pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
833313a58e4SPetko Manolov 							      PEGASUS_MTU,
834313a58e4SPetko Manolov 							      GFP_KERNEL);
8355b2fc499SJeff Garzik 	if (!pegasus->rx_skb)
836323b3496SPetko Manolov 		goto exit;
8375b2fc499SJeff Garzik 
838ffc9c3ebSPetko Manolov 	set_registers(pegasus, EthID, 6, net->dev_addr);
8395b2fc499SJeff Garzik 
8405b2fc499SJeff Garzik 	usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
8415b2fc499SJeff Garzik 			  usb_rcvbulkpipe(pegasus->usb, 1),
842b7302ca0SPetko Manolov 			  pegasus->rx_skb->data, PEGASUS_MTU,
8435b2fc499SJeff Garzik 			  read_bulk_callback, pegasus);
8445b2fc499SJeff Garzik 	if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
8455b2fc499SJeff Garzik 		if (res == -ENODEV)
8465b2fc499SJeff Garzik 			netif_device_detach(pegasus->net);
847a475f603SJoe Perches 		netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res);
8485b2fc499SJeff Garzik 		goto exit;
8495b2fc499SJeff Garzik 	}
8505b2fc499SJeff Garzik 
8515b2fc499SJeff Garzik 	usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
8525b2fc499SJeff Garzik 			 usb_rcvintpipe(pegasus->usb, 3),
8535b2fc499SJeff Garzik 			 pegasus->intr_buff, sizeof(pegasus->intr_buff),
8545b2fc499SJeff Garzik 			 intr_callback, pegasus, pegasus->intr_interval);
8555b2fc499SJeff Garzik 	if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
8565b2fc499SJeff Garzik 		if (res == -ENODEV)
8575b2fc499SJeff Garzik 			netif_device_detach(pegasus->net);
858a475f603SJoe Perches 		netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res);
8595b2fc499SJeff Garzik 		usb_kill_urb(pegasus->rx_urb);
8605b2fc499SJeff Garzik 		goto exit;
8615b2fc499SJeff Garzik 	}
862323b3496SPetko Manolov 	res = enable_net_traffic(net, pegasus->usb);
863323b3496SPetko Manolov 	if (res < 0) {
864a475f603SJoe Perches 		netif_dbg(pegasus, ifup, net,
865a475f603SJoe Perches 			  "can't enable_net_traffic() - %d\n", res);
8665b2fc499SJeff Garzik 		res = -EIO;
8675b2fc499SJeff Garzik 		usb_kill_urb(pegasus->rx_urb);
8685b2fc499SJeff Garzik 		usb_kill_urb(pegasus->intr_urb);
8695b2fc499SJeff Garzik 		goto exit;
8705b2fc499SJeff Garzik 	}
8715b2fc499SJeff Garzik 	set_carrier(net);
8725b2fc499SJeff Garzik 	netif_start_queue(net);
873a475f603SJoe Perches 	netif_dbg(pegasus, ifup, net, "open\n");
8745b2fc499SJeff Garzik 	res = 0;
8755b2fc499SJeff Garzik exit:
8765b2fc499SJeff Garzik 	return res;
8775b2fc499SJeff Garzik }
8785b2fc499SJeff Garzik 
pegasus_close(struct net_device * net)8795b2fc499SJeff Garzik static int pegasus_close(struct net_device *net)
8805b2fc499SJeff Garzik {
8815b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
8825b2fc499SJeff Garzik 
8835b2fc499SJeff Garzik 	netif_stop_queue(net);
8845b2fc499SJeff Garzik 	if (!(pegasus->flags & PEGASUS_UNPLUG))
8855b2fc499SJeff Garzik 		disable_net_traffic(pegasus);
8865b2fc499SJeff Garzik 	tasklet_kill(&pegasus->rx_tl);
8875b2fc499SJeff Garzik 	unlink_all_urbs(pegasus);
8885b2fc499SJeff Garzik 
8895b2fc499SJeff Garzik 	return 0;
8905b2fc499SJeff Garzik }
8915b2fc499SJeff Garzik 
pegasus_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)8925b2fc499SJeff Garzik static void pegasus_get_drvinfo(struct net_device *dev,
8935b2fc499SJeff Garzik 				struct ethtool_drvinfo *info)
8945b2fc499SJeff Garzik {
8955b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
8967826d43fSJiri Pirko 
897*fb3ceec1SWolfram Sang 	strscpy(info->driver, driver_name, sizeof(info->driver));
8985b2fc499SJeff Garzik 	usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info));
8995b2fc499SJeff Garzik }
9005b2fc499SJeff Garzik 
9015b2fc499SJeff Garzik /* also handles three patterns of some kind in hardware */
9025b2fc499SJeff Garzik #define	WOL_SUPPORTED	(WAKE_MAGIC|WAKE_PHY)
9035b2fc499SJeff Garzik 
9045b2fc499SJeff Garzik static void
pegasus_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)9055b2fc499SJeff Garzik pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9065b2fc499SJeff Garzik {
9075b2fc499SJeff Garzik 	pegasus_t	*pegasus = netdev_priv(dev);
9085b2fc499SJeff Garzik 
9095b2fc499SJeff Garzik 	wol->supported = WAKE_MAGIC | WAKE_PHY;
9105b2fc499SJeff Garzik 	wol->wolopts = pegasus->wolopts;
9115b2fc499SJeff Garzik }
9125b2fc499SJeff Garzik 
9135b2fc499SJeff Garzik static int
pegasus_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)9145b2fc499SJeff Garzik pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9155b2fc499SJeff Garzik {
9165b2fc499SJeff Garzik 	pegasus_t	*pegasus = netdev_priv(dev);
9175b2fc499SJeff Garzik 	u8		reg78 = 0x04;
9184fbc5b20SMing Lei 	int		ret;
9195b2fc499SJeff Garzik 
9205b2fc499SJeff Garzik 	if (wol->wolopts & ~WOL_SUPPORTED)
9215b2fc499SJeff Garzik 		return -EINVAL;
9225b2fc499SJeff Garzik 
9235b2fc499SJeff Garzik 	if (wol->wolopts & WAKE_MAGIC)
9245b2fc499SJeff Garzik 		reg78 |= 0x80;
9255b2fc499SJeff Garzik 	if (wol->wolopts & WAKE_PHY)
9265b2fc499SJeff Garzik 		reg78 |= 0x40;
9275b2fc499SJeff Garzik 	/* FIXME this 0x10 bit still needs to get set in the chip... */
9285b2fc499SJeff Garzik 	if (wol->wolopts)
9295b2fc499SJeff Garzik 		pegasus->eth_regs[0] |= 0x10;
9305b2fc499SJeff Garzik 	else
9315b2fc499SJeff Garzik 		pegasus->eth_regs[0] &= ~0x10;
9325b2fc499SJeff Garzik 	pegasus->wolopts = wol->wolopts;
9334fbc5b20SMing Lei 
9344fbc5b20SMing Lei 	ret = set_register(pegasus, WakeupControl, reg78);
9354fbc5b20SMing Lei 	if (!ret)
9364fbc5b20SMing Lei 		ret = device_set_wakeup_enable(&pegasus->usb->dev,
9374fbc5b20SMing Lei 						wol->wolopts);
9384fbc5b20SMing Lei 	return ret;
9395b2fc499SJeff Garzik }
9405b2fc499SJeff Garzik 
pegasus_reset_wol(struct net_device * dev)9415b2fc499SJeff Garzik static inline void pegasus_reset_wol(struct net_device *dev)
9425b2fc499SJeff Garzik {
9435b2fc499SJeff Garzik 	struct ethtool_wolinfo wol;
9445b2fc499SJeff Garzik 
9455b2fc499SJeff Garzik 	memset(&wol, 0, sizeof wol);
9465b2fc499SJeff Garzik 	(void) pegasus_set_wol(dev, &wol);
9475b2fc499SJeff Garzik }
9485b2fc499SJeff Garzik 
9495b2fc499SJeff Garzik static int
pegasus_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * ecmd)95071dbc341SPhilippe Reynes pegasus_get_link_ksettings(struct net_device *dev,
95171dbc341SPhilippe Reynes 			   struct ethtool_link_ksettings *ecmd)
9525b2fc499SJeff Garzik {
9535b2fc499SJeff Garzik 	pegasus_t *pegasus;
9545b2fc499SJeff Garzik 
9555b2fc499SJeff Garzik 	pegasus = netdev_priv(dev);
95671dbc341SPhilippe Reynes 	mii_ethtool_get_link_ksettings(&pegasus->mii, ecmd);
9575b2fc499SJeff Garzik 	return 0;
9585b2fc499SJeff Garzik }
9595b2fc499SJeff Garzik 
9605b2fc499SJeff Garzik static int
pegasus_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * ecmd)96171dbc341SPhilippe Reynes pegasus_set_link_ksettings(struct net_device *dev,
96271dbc341SPhilippe Reynes 			   const struct ethtool_link_ksettings *ecmd)
9635b2fc499SJeff Garzik {
9645b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
96571dbc341SPhilippe Reynes 	return mii_ethtool_set_link_ksettings(&pegasus->mii, ecmd);
9665b2fc499SJeff Garzik }
9675b2fc499SJeff Garzik 
pegasus_nway_reset(struct net_device * dev)9685b2fc499SJeff Garzik static int pegasus_nway_reset(struct net_device *dev)
9695b2fc499SJeff Garzik {
9705b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
9715b2fc499SJeff Garzik 	return mii_nway_restart(&pegasus->mii);
9725b2fc499SJeff Garzik }
9735b2fc499SJeff Garzik 
pegasus_get_link(struct net_device * dev)9745b2fc499SJeff Garzik static u32 pegasus_get_link(struct net_device *dev)
9755b2fc499SJeff Garzik {
9765b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
9775b2fc499SJeff Garzik 	return mii_link_ok(&pegasus->mii);
9785b2fc499SJeff Garzik }
9795b2fc499SJeff Garzik 
pegasus_get_msglevel(struct net_device * dev)9805b2fc499SJeff Garzik static u32 pegasus_get_msglevel(struct net_device *dev)
9815b2fc499SJeff Garzik {
9825b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
9835b2fc499SJeff Garzik 	return pegasus->msg_enable;
9845b2fc499SJeff Garzik }
9855b2fc499SJeff Garzik 
pegasus_set_msglevel(struct net_device * dev,u32 v)9865b2fc499SJeff Garzik static void pegasus_set_msglevel(struct net_device *dev, u32 v)
9875b2fc499SJeff Garzik {
9885b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(dev);
9895b2fc499SJeff Garzik 	pegasus->msg_enable = v;
9905b2fc499SJeff Garzik }
9915b2fc499SJeff Garzik 
9920fc0b732SStephen Hemminger static const struct ethtool_ops ops = {
9935b2fc499SJeff Garzik 	.get_drvinfo = pegasus_get_drvinfo,
9945b2fc499SJeff Garzik 	.nway_reset = pegasus_nway_reset,
9955b2fc499SJeff Garzik 	.get_link = pegasus_get_link,
9965b2fc499SJeff Garzik 	.get_msglevel = pegasus_get_msglevel,
9975b2fc499SJeff Garzik 	.set_msglevel = pegasus_set_msglevel,
9985b2fc499SJeff Garzik 	.get_wol = pegasus_get_wol,
9995b2fc499SJeff Garzik 	.set_wol = pegasus_set_wol,
100071dbc341SPhilippe Reynes 	.get_link_ksettings = pegasus_get_link_ksettings,
100171dbc341SPhilippe Reynes 	.set_link_ksettings = pegasus_set_link_ksettings,
10025b2fc499SJeff Garzik };
10035b2fc499SJeff Garzik 
pegasus_siocdevprivate(struct net_device * net,struct ifreq * rq,void __user * udata,int cmd)1004ef1b5b0cSArnd Bergmann static int pegasus_siocdevprivate(struct net_device *net, struct ifreq *rq,
1005ef1b5b0cSArnd Bergmann 				  void __user *udata, int cmd)
10065b2fc499SJeff Garzik {
10075b2fc499SJeff Garzik 	__u16 *data = (__u16 *) &rq->ifr_ifru;
10085b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
10095b2fc499SJeff Garzik 	int res;
10105b2fc499SJeff Garzik 
10115b2fc499SJeff Garzik 	switch (cmd) {
10125b2fc499SJeff Garzik 	case SIOCDEVPRIVATE:
10135b2fc499SJeff Garzik 		data[0] = pegasus->phy;
1014df561f66SGustavo A. R. Silva 		fallthrough;
10155b2fc499SJeff Garzik 	case SIOCDEVPRIVATE + 1:
10168a160e2eSPetko Manolov 		res = read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
10175b2fc499SJeff Garzik 		break;
10185b2fc499SJeff Garzik 	case SIOCDEVPRIVATE + 2:
10195b2fc499SJeff Garzik 		if (!capable(CAP_NET_ADMIN))
10205b2fc499SJeff Garzik 			return -EPERM;
10212bd64701SPetko Manolov 		write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]);
10225b2fc499SJeff Garzik 		res = 0;
10235b2fc499SJeff Garzik 		break;
10245b2fc499SJeff Garzik 	default:
10255b2fc499SJeff Garzik 		res = -EOPNOTSUPP;
10265b2fc499SJeff Garzik 	}
10275b2fc499SJeff Garzik 	return res;
10285b2fc499SJeff Garzik }
10295b2fc499SJeff Garzik 
pegasus_set_multicast(struct net_device * net)10305b2fc499SJeff Garzik static void pegasus_set_multicast(struct net_device *net)
10315b2fc499SJeff Garzik {
10325b2fc499SJeff Garzik 	pegasus_t *pegasus = netdev_priv(net);
10335b2fc499SJeff Garzik 
10345b2fc499SJeff Garzik 	if (net->flags & IFF_PROMISC) {
10355b2fc499SJeff Garzik 		pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
1036a475f603SJoe Perches 		netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
10374cd24eafSJiri Pirko 	} else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
10385b2fc499SJeff Garzik 		pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
10395b2fc499SJeff Garzik 		pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
1040a475f603SJoe Perches 		netif_dbg(pegasus, link, net, "set allmulti\n");
10415b2fc499SJeff Garzik 	} else {
10425b2fc499SJeff Garzik 		pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
10435b2fc499SJeff Garzik 		pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
10445b2fc499SJeff Garzik 	}
1045323b3496SPetko Manolov 	update_eth_regs_async(pegasus);
10465b2fc499SJeff Garzik }
10475b2fc499SJeff Garzik 
mii_phy_probe(pegasus_t * pegasus)10485b2fc499SJeff Garzik static __u8 mii_phy_probe(pegasus_t *pegasus)
10495b2fc499SJeff Garzik {
10508a160e2eSPetko Manolov 	int i, ret;
10515b2fc499SJeff Garzik 	__u16 tmp;
10525b2fc499SJeff Garzik 
10535b2fc499SJeff Garzik 	for (i = 0; i < 32; i++) {
10548a160e2eSPetko Manolov 		ret = read_mii_word(pegasus, i, MII_BMSR, &tmp);
10558a160e2eSPetko Manolov 		if (ret < 0)
10568a160e2eSPetko Manolov 			goto fail;
10575b2fc499SJeff Garzik 		if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
10585b2fc499SJeff Garzik 			continue;
10595b2fc499SJeff Garzik 		else
10605b2fc499SJeff Garzik 			return i;
10615b2fc499SJeff Garzik 	}
10628a160e2eSPetko Manolov fail:
10635b2fc499SJeff Garzik 	return 0xff;
10645b2fc499SJeff Garzik }
10655b2fc499SJeff Garzik 
setup_pegasus_II(pegasus_t * pegasus)10665b2fc499SJeff Garzik static inline void setup_pegasus_II(pegasus_t *pegasus)
10675b2fc499SJeff Garzik {
10688a160e2eSPetko Manolov 	int ret;
10695b2fc499SJeff Garzik 	__u8 data = 0xa5;
10705b2fc499SJeff Garzik 
10715b2fc499SJeff Garzik 	set_register(pegasus, Reg1d, 0);
10725b2fc499SJeff Garzik 	set_register(pegasus, Reg7b, 1);
10736dff5addSJia-Ju Bai 	msleep(100);
10745b2fc499SJeff Garzik 	if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
10755b2fc499SJeff Garzik 		set_register(pegasus, Reg7b, 0);
10765b2fc499SJeff Garzik 	else
10775b2fc499SJeff Garzik 		set_register(pegasus, Reg7b, 2);
10785b2fc499SJeff Garzik 
10795b2fc499SJeff Garzik 	set_register(pegasus, 0x83, data);
10808a160e2eSPetko Manolov 	ret = get_registers(pegasus, 0x83, 1, &data);
10818a160e2eSPetko Manolov 	if (ret < 0)
10828a160e2eSPetko Manolov 		goto fail;
10835b2fc499SJeff Garzik 
10845a9dbfe0SNicolas Kaiser 	if (data == 0xa5)
10855b2fc499SJeff Garzik 		pegasus->chip = 0x8513;
10865a9dbfe0SNicolas Kaiser 	else
10875b2fc499SJeff Garzik 		pegasus->chip = 0;
10885b2fc499SJeff Garzik 
10895b2fc499SJeff Garzik 	set_register(pegasus, 0x80, 0xc0);
10905b2fc499SJeff Garzik 	set_register(pegasus, 0x83, 0xff);
10915b2fc499SJeff Garzik 	set_register(pegasus, 0x84, 0x01);
10925b2fc499SJeff Garzik 
10935b2fc499SJeff Garzik 	if (pegasus->features & HAS_HOME_PNA && mii_mode)
10945b2fc499SJeff Garzik 		set_register(pegasus, Reg81, 6);
10955b2fc499SJeff Garzik 	else
10965b2fc499SJeff Garzik 		set_register(pegasus, Reg81, 2);
10978a160e2eSPetko Manolov 
10988a160e2eSPetko Manolov 	return;
10998a160e2eSPetko Manolov fail:
11008a160e2eSPetko Manolov 	netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__);
11015b2fc499SJeff Garzik }
11025b2fc499SJeff Garzik 
check_carrier(struct work_struct * work)11035b2fc499SJeff Garzik static void check_carrier(struct work_struct *work)
11045b2fc499SJeff Garzik {
11055b2fc499SJeff Garzik 	pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
11065b2fc499SJeff Garzik 	set_carrier(pegasus->net);
11075b2fc499SJeff Garzik 	if (!(pegasus->flags & PEGASUS_UNPLUG)) {
11082f5107c3SPetko Manolov 		queue_delayed_work(system_long_wq, &pegasus->carrier_check,
11095b2fc499SJeff Garzik 			CARRIER_CHECK_DELAY);
11105b2fc499SJeff Garzik 	}
11115b2fc499SJeff Garzik }
11125b2fc499SJeff Garzik 
pegasus_blacklisted(struct usb_device * udev)11134f63135eSBen Collins static int pegasus_blacklisted(struct usb_device *udev)
11144f63135eSBen Collins {
11154f63135eSBen Collins 	struct usb_device_descriptor *udd = &udev->descriptor;
11164f63135eSBen Collins 
11174f63135eSBen Collins 	/* Special quirk to keep the driver from handling the Belkin Bluetooth
11184f63135eSBen Collins 	 * dongle which happens to have the same ID.
11194f63135eSBen Collins 	 */
1120e3453f63SMichael Buesch 	if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
1121e3453f63SMichael Buesch 	    (udd->idProduct == cpu_to_le16(0x0121)) &&
11224f63135eSBen Collins 	    (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
11234f63135eSBen Collins 	    (udd->bDeviceProtocol == 1))
11244f63135eSBen Collins 		return 1;
11254f63135eSBen Collins 
11264f63135eSBen Collins 	return 0;
11274f63135eSBen Collins }
11284f63135eSBen Collins 
pegasus_probe(struct usb_interface * intf,const struct usb_device_id * id)11295b2fc499SJeff Garzik static int pegasus_probe(struct usb_interface *intf,
11305b2fc499SJeff Garzik 			 const struct usb_device_id *id)
11315b2fc499SJeff Garzik {
11325b2fc499SJeff Garzik 	struct usb_device *dev = interface_to_usbdev(intf);
11335b2fc499SJeff Garzik 	struct net_device *net;
11345b2fc499SJeff Garzik 	pegasus_t *pegasus;
11355b2fc499SJeff Garzik 	int dev_index = id - pegasus_ids;
11365b2fc499SJeff Garzik 	int res = -ENOMEM;
11375b2fc499SJeff Garzik 
1138cda2836dSDavid Brownell 	if (pegasus_blacklisted(dev))
1139cda2836dSDavid Brownell 		return -ENODEV;
11404f63135eSBen Collins 
11415b2fc499SJeff Garzik 	net = alloc_etherdev(sizeof(struct pegasus));
114241de8d4cSJoe Perches 	if (!net)
11435b2fc499SJeff Garzik 		goto out;
11445b2fc499SJeff Garzik 
11455b2fc499SJeff Garzik 	pegasus = netdev_priv(net);
11465b2fc499SJeff Garzik 	pegasus->dev_index = dev_index;
11475b2fc499SJeff Garzik 
1148323b3496SPetko Manolov 	res = alloc_urbs(pegasus);
1149323b3496SPetko Manolov 	if (res < 0) {
11505b2fc499SJeff Garzik 		dev_err(&intf->dev, "can't allocate %s\n", "urbs");
11515b2fc499SJeff Garzik 		goto out1;
11525b2fc499SJeff Garzik 	}
11535b2fc499SJeff Garzik 
115423a64c51SEmil Renner Berthing 	tasklet_setup(&pegasus->rx_tl, rx_fixup);
11555b2fc499SJeff Garzik 
11565b2fc499SJeff Garzik 	INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
11575b2fc499SJeff Garzik 
11585b2fc499SJeff Garzik 	pegasus->intf = intf;
11595b2fc499SJeff Garzik 	pegasus->usb = dev;
11605b2fc499SJeff Garzik 	pegasus->net = net;
11618cb89571SOliver Neukum 
11628cb89571SOliver Neukum 
11635b2fc499SJeff Garzik 	net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
11648cb89571SOliver Neukum 	net->netdev_ops = &pegasus_netdev_ops;
11657ad24ea4SWilfried Klaebe 	net->ethtool_ops = &ops;
11665b2fc499SJeff Garzik 	pegasus->mii.dev = net;
11675b2fc499SJeff Garzik 	pegasus->mii.mdio_read = mdio_read;
11685b2fc499SJeff Garzik 	pegasus->mii.mdio_write = mdio_write;
11695b2fc499SJeff Garzik 	pegasus->mii.phy_id_mask = 0x1f;
11705b2fc499SJeff Garzik 	pegasus->mii.reg_num_mask = 0x1f;
11715b2fc499SJeff Garzik 	pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV
11725b2fc499SJeff Garzik 				| NETIF_MSG_PROBE | NETIF_MSG_LINK);
11735b2fc499SJeff Garzik 
11745b2fc499SJeff Garzik 	pegasus->features = usb_dev_id[dev_index].private;
1175af35fc37SPavel Skripkin 	res = get_interrupt_interval(pegasus);
1176af35fc37SPavel Skripkin 	if (res)
1177af35fc37SPavel Skripkin 		goto out2;
11785b2fc499SJeff Garzik 	if (reset_mac(pegasus)) {
11795b2fc499SJeff Garzik 		dev_err(&intf->dev, "can't reset MAC\n");
11805b2fc499SJeff Garzik 		res = -EIO;
11815b2fc499SJeff Garzik 		goto out2;
11825b2fc499SJeff Garzik 	}
11835b2fc499SJeff Garzik 	set_ethernet_addr(pegasus);
11845b2fc499SJeff Garzik 	if (pegasus->features & PEGASUS_II) {
11855b2fc499SJeff Garzik 		dev_info(&intf->dev, "setup Pegasus II specific registers\n");
11865b2fc499SJeff Garzik 		setup_pegasus_II(pegasus);
11875b2fc499SJeff Garzik 	}
11885b2fc499SJeff Garzik 	pegasus->phy = mii_phy_probe(pegasus);
11895b2fc499SJeff Garzik 	if (pegasus->phy == 0xff) {
11905b2fc499SJeff Garzik 		dev_warn(&intf->dev, "can't locate MII phy, using default\n");
11915b2fc499SJeff Garzik 		pegasus->phy = 1;
11925b2fc499SJeff Garzik 	}
11935b2fc499SJeff Garzik 	pegasus->mii.phy_id = pegasus->phy;
11945b2fc499SJeff Garzik 	usb_set_intfdata(intf, pegasus);
11955b2fc499SJeff Garzik 	SET_NETDEV_DEV(net, &intf->dev);
11965b2fc499SJeff Garzik 	pegasus_reset_wol(net);
11975b2fc499SJeff Garzik 	res = register_netdev(net);
11985b2fc499SJeff Garzik 	if (res)
11995b2fc499SJeff Garzik 		goto out3;
12002f5107c3SPetko Manolov 	queue_delayed_work(system_long_wq, &pegasus->carrier_check,
12015b2fc499SJeff Garzik 			   CARRIER_CHECK_DELAY);
1202323b3496SPetko Manolov 	dev_info(&intf->dev, "%s, %s, %pM\n", net->name,
1203323b3496SPetko Manolov 		 usb_dev_id[dev_index].name, net->dev_addr);
12045b2fc499SJeff Garzik 	return 0;
12055b2fc499SJeff Garzik 
12065b2fc499SJeff Garzik out3:
12075b2fc499SJeff Garzik 	usb_set_intfdata(intf, NULL);
12085b2fc499SJeff Garzik out2:
12095b2fc499SJeff Garzik 	free_all_urbs(pegasus);
12105b2fc499SJeff Garzik out1:
12115b2fc499SJeff Garzik 	free_netdev(net);
12125b2fc499SJeff Garzik out:
12135b2fc499SJeff Garzik 	return res;
12145b2fc499SJeff Garzik }
12155b2fc499SJeff Garzik 
pegasus_disconnect(struct usb_interface * intf)12165b2fc499SJeff Garzik static void pegasus_disconnect(struct usb_interface *intf)
12175b2fc499SJeff Garzik {
12185b2fc499SJeff Garzik 	struct pegasus *pegasus = usb_get_intfdata(intf);
12195b2fc499SJeff Garzik 
12205b2fc499SJeff Garzik 	usb_set_intfdata(intf, NULL);
12215b2fc499SJeff Garzik 	if (!pegasus) {
12225b2fc499SJeff Garzik 		dev_dbg(&intf->dev, "unregistering non-bound device?\n");
12235b2fc499SJeff Garzik 		return;
12245b2fc499SJeff Garzik 	}
12255b2fc499SJeff Garzik 
12265b2fc499SJeff Garzik 	pegasus->flags |= PEGASUS_UNPLUG;
12272f5107c3SPetko Manolov 	cancel_delayed_work_sync(&pegasus->carrier_check);
12285b2fc499SJeff Garzik 	unregister_netdev(pegasus->net);
12295b2fc499SJeff Garzik 	unlink_all_urbs(pegasus);
12305b2fc499SJeff Garzik 	free_all_urbs(pegasus);
12315b2fc499SJeff Garzik 	if (pegasus->rx_skb != NULL) {
12325b2fc499SJeff Garzik 		dev_kfree_skb(pegasus->rx_skb);
12335b2fc499SJeff Garzik 		pegasus->rx_skb = NULL;
12345b2fc499SJeff Garzik 	}
12355b2fc499SJeff Garzik 	free_netdev(pegasus->net);
12365b2fc499SJeff Garzik }
12375b2fc499SJeff Garzik 
pegasus_suspend(struct usb_interface * intf,pm_message_t message)12385b2fc499SJeff Garzik static int pegasus_suspend(struct usb_interface *intf, pm_message_t message)
12395b2fc499SJeff Garzik {
12405b2fc499SJeff Garzik 	struct pegasus *pegasus = usb_get_intfdata(intf);
12415b2fc499SJeff Garzik 
12425b2fc499SJeff Garzik 	netif_device_detach(pegasus->net);
12432f5107c3SPetko Manolov 	cancel_delayed_work_sync(&pegasus->carrier_check);
12445b2fc499SJeff Garzik 	if (netif_running(pegasus->net)) {
12455b2fc499SJeff Garzik 		usb_kill_urb(pegasus->rx_urb);
12465b2fc499SJeff Garzik 		usb_kill_urb(pegasus->intr_urb);
12475b2fc499SJeff Garzik 	}
12485b2fc499SJeff Garzik 	return 0;
12495b2fc499SJeff Garzik }
12505b2fc499SJeff Garzik 
pegasus_resume(struct usb_interface * intf)12515b2fc499SJeff Garzik static int pegasus_resume(struct usb_interface *intf)
12525b2fc499SJeff Garzik {
12535b2fc499SJeff Garzik 	struct pegasus *pegasus = usb_get_intfdata(intf);
12545b2fc499SJeff Garzik 
12555b2fc499SJeff Garzik 	netif_device_attach(pegasus->net);
12565b2fc499SJeff Garzik 	if (netif_running(pegasus->net)) {
12575b2fc499SJeff Garzik 		pegasus->rx_urb->status = 0;
12585b2fc499SJeff Garzik 		pegasus->rx_urb->actual_length = 0;
12595b2fc499SJeff Garzik 		read_bulk_callback(pegasus->rx_urb);
12605b2fc499SJeff Garzik 
12615b2fc499SJeff Garzik 		pegasus->intr_urb->status = 0;
12625b2fc499SJeff Garzik 		pegasus->intr_urb->actual_length = 0;
12635b2fc499SJeff Garzik 		intr_callback(pegasus->intr_urb);
12645b2fc499SJeff Garzik 	}
12652f5107c3SPetko Manolov 	queue_delayed_work(system_long_wq, &pegasus->carrier_check,
12665b2fc499SJeff Garzik 				CARRIER_CHECK_DELAY);
12675b2fc499SJeff Garzik 	return 0;
12685b2fc499SJeff Garzik }
12695b2fc499SJeff Garzik 
12708cb89571SOliver Neukum static const struct net_device_ops pegasus_netdev_ops = {
12718cb89571SOliver Neukum 	.ndo_open =			pegasus_open,
12728cb89571SOliver Neukum 	.ndo_stop =			pegasus_close,
1273ef1b5b0cSArnd Bergmann 	.ndo_siocdevprivate =		pegasus_siocdevprivate,
12748cb89571SOliver Neukum 	.ndo_start_xmit =		pegasus_start_xmit,
1275afc4b13dSJiri Pirko 	.ndo_set_rx_mode =		pegasus_set_multicast,
12768cb89571SOliver Neukum 	.ndo_tx_timeout =		pegasus_tx_timeout,
1277240c102dSBen Hutchings 	.ndo_set_mac_address =		eth_mac_addr,
1278240c102dSBen Hutchings 	.ndo_validate_addr =		eth_validate_addr,
12798cb89571SOliver Neukum };
12808cb89571SOliver Neukum 
12815b2fc499SJeff Garzik static struct usb_driver pegasus_driver = {
12825b2fc499SJeff Garzik 	.name = driver_name,
12835b2fc499SJeff Garzik 	.probe = pegasus_probe,
12845b2fc499SJeff Garzik 	.disconnect = pegasus_disconnect,
12855b2fc499SJeff Garzik 	.id_table = pegasus_ids,
12865b2fc499SJeff Garzik 	.suspend = pegasus_suspend,
12875b2fc499SJeff Garzik 	.resume = pegasus_resume,
1288e1f12eb6SSarah Sharp 	.disable_hub_initiated_lpm = 1,
12895b2fc499SJeff Garzik };
12905b2fc499SJeff Garzik 
parse_id(char * id)1291cda2836dSDavid Brownell static void __init parse_id(char *id)
12925b2fc499SJeff Garzik {
12935b2fc499SJeff Garzik 	unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0;
12945b2fc499SJeff Garzik 	char *token, *name = NULL;
12955b2fc499SJeff Garzik 
12965b2fc499SJeff Garzik 	if ((token = strsep(&id, ":")) != NULL)
12975b2fc499SJeff Garzik 		name = token;
12985b2fc499SJeff Garzik 	/* name now points to a null terminated string*/
12995b2fc499SJeff Garzik 	if ((token = strsep(&id, ":")) != NULL)
13005b2fc499SJeff Garzik 		vendor_id = simple_strtoul(token, NULL, 16);
13015b2fc499SJeff Garzik 	if ((token = strsep(&id, ":")) != NULL)
13025b2fc499SJeff Garzik 		device_id = simple_strtoul(token, NULL, 16);
13035b2fc499SJeff Garzik 	flags = simple_strtoul(id, NULL, 16);
13045b2fc499SJeff Garzik 	pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
13055b2fc499SJeff Garzik 		driver_name, name, vendor_id, device_id, flags);
13065b2fc499SJeff Garzik 
13075b2fc499SJeff Garzik 	if (vendor_id > 0x10000 || vendor_id == 0)
13085b2fc499SJeff Garzik 		return;
13095b2fc499SJeff Garzik 	if (device_id > 0x10000 || device_id == 0)
13105b2fc499SJeff Garzik 		return;
13115b2fc499SJeff Garzik 
13125b2fc499SJeff Garzik 	for (i = 0; usb_dev_id[i].name; i++);
13135b2fc499SJeff Garzik 	usb_dev_id[i].name = name;
13145b2fc499SJeff Garzik 	usb_dev_id[i].vendor = vendor_id;
13155b2fc499SJeff Garzik 	usb_dev_id[i].device = device_id;
13165b2fc499SJeff Garzik 	usb_dev_id[i].private = flags;
13175b2fc499SJeff Garzik 	pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
13185b2fc499SJeff Garzik 	pegasus_ids[i].idVendor = vendor_id;
13195b2fc499SJeff Garzik 	pegasus_ids[i].idProduct = device_id;
13205b2fc499SJeff Garzik }
13215b2fc499SJeff Garzik 
pegasus_init(void)13225b2fc499SJeff Garzik static int __init pegasus_init(void)
13235b2fc499SJeff Garzik {
1324bc65bacfSPetko Manolov 	pr_info("%s: " DRIVER_DESC "\n", driver_name);
13255b2fc499SJeff Garzik 	if (devid)
13265b2fc499SJeff Garzik 		parse_id(devid);
13275b2fc499SJeff Garzik 	return usb_register(&pegasus_driver);
13285b2fc499SJeff Garzik }
13295b2fc499SJeff Garzik 
pegasus_exit(void)13305b2fc499SJeff Garzik static void __exit pegasus_exit(void)
13315b2fc499SJeff Garzik {
13325b2fc499SJeff Garzik 	usb_deregister(&pegasus_driver);
13335b2fc499SJeff Garzik }
13345b2fc499SJeff Garzik 
13355b2fc499SJeff Garzik module_init(pegasus_init);
13365b2fc499SJeff Garzik module_exit(pegasus_exit);
1337