⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net1080.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Net1080 based USB host-to-host cables * Copyright (C) 2000-2005 by David Brownell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */// #define	DEBUG			// error path messages, extra info// #define	VERBOSE			// more; success messages#include <linux/config.h>#include <linux/module.h>#include <linux/sched.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/ethtool.h>#include <linux/workqueue.h>#include <linux/mii.h>#include <linux/usb.h>#include <asm/unaligned.h>#include "usbnet.h"/* * Netchip 1080 driver ... http://www.netchip.com * (Sept 2004:  End-of-life announcement has been sent.) * Used in (some) LapLink cables */#define frame_errors	data[1]/* * NetChip framing of ethernet packets, supporting additional error * checks for links that may drop bulk packets from inside messages. * Odd USB length == always short read for last usb packet. *	- nc_header *	- Ethernet header (14 bytes) *	- payload *	- (optional padding byte, if needed so length becomes odd) *	- nc_trailer * * This framing is to be avoided for non-NetChip devices. */struct nc_header {		// packed:	__le16	hdr_len;		// sizeof nc_header (LE, all)	__le16	packet_len;		// payload size (including ethhdr)	__le16	packet_id;		// detects dropped packets#define MIN_HEADER	6	// all else is optional, and must start with:	// __le16	vendorId;	// from usb-if	// __le16	productId;} __attribute__((__packed__));#define	PAD_BYTE	((unsigned char)0xAC)struct nc_trailer {	__le16	packet_id;} __attribute__((__packed__));// packets may use FLAG_FRAMING_NC and optional pad#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \				+ sizeof (struct ethhdr) \				+ (mtu) \				+ 1 \				+ sizeof (struct nc_trailer))#define MIN_FRAMED	FRAMED_SIZE(0)/* packets _could_ be up to 64KB... */#define NC_MAX_PACKET	32767/* * Zero means no timeout; else, how long a 64 byte bulk packet may be queued * before the hardware drops it.  If that's done, the driver will need to * frame network packets to guard against the dropped USB packets.  The win32 * driver sets this for both sides of the link. */#define	NC_READ_TTL_MS	((u8)255)	// ms/* * We ignore most registers and EEPROM contents. */#define	REG_USBCTL	((u8)0x04)#define REG_TTL		((u8)0x10)#define REG_STATUS	((u8)0x11)/* * Vendor specific requests to read/write data */#define	REQUEST_REGISTER	((u8)0x10)#define	REQUEST_EEPROM		((u8)0x11)static intnc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr){	int status = usb_control_msg(dev->udev,		usb_rcvctrlpipe(dev->udev, 0),		req,		USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,		0, regnum,		retval_ptr, sizeof *retval_ptr,		USB_CTRL_GET_TIMEOUT);	if (status > 0)		status = 0;	if (!status)		le16_to_cpus(retval_ptr);	return status;}static inline intnc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr){	return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);}// no retval ... can become async, usable in_interrupt()static voidnc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value){	usb_control_msg(dev->udev,		usb_sndctrlpipe(dev->udev, 0),		req,		USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,		value, regnum,		NULL, 0,			// data is in setup packet		USB_CTRL_SET_TIMEOUT);}static inline voidnc_register_write(struct usbnet *dev, u8 regnum, u16 value){	nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);}#if 0static void nc_dump_registers(struct usbnet *dev){	u8	reg;	u16	*vp = kmalloc(sizeof (u16));	if (!vp) {		dbg("no memory?");		return;	}	dbg("%s registers:", dev->net->name);	for (reg = 0; reg < 0x20; reg++) {		int retval;		// reading some registers is trouble		if (reg >= 0x08 && reg <= 0xf)			continue;		if (reg >= 0x12 && reg <= 0x1e)			continue;		retval = nc_register_read(dev, reg, vp);		if (retval < 0)			dbg("%s reg [0x%x] ==> error %d",				dev->net->name, reg, retval);		else			dbg("%s reg [0x%x] = 0x%x",				dev->net->name, reg, *vp);	}	kfree(vp);}#endif/*-------------------------------------------------------------------------*//* * Control register */#define	USBCTL_WRITABLE_MASK	0x1f0f// bits 15-13 reserved, r/o#define	USBCTL_ENABLE_LANG	(1 << 12)#define	USBCTL_ENABLE_MFGR	(1 << 11)#define	USBCTL_ENABLE_PROD	(1 << 10)#define	USBCTL_ENABLE_SERIAL	(1 << 9)#define	USBCTL_ENABLE_DEFAULTS	(1 << 8)// bits 7-4 reserved, r/o#define	USBCTL_FLUSH_OTHER	(1 << 3)#define	USBCTL_FLUSH_THIS	(1 << 2)#define	USBCTL_DISCONN_OTHER	(1 << 1)#define	USBCTL_DISCONN_THIS	(1 << 0)static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl){	if (!netif_msg_link(dev))		return;	devdbg(dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"			" this%s%s;"			" other%s%s; r/o 0x%x",		dev->udev->bus->bus_name, dev->udev->devpath,		usbctl,		(usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",		(usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",		(usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",		(usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",		(usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",		(usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",		(usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",		(usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",		(usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",		usbctl & ~USBCTL_WRITABLE_MASK		);}/*-------------------------------------------------------------------------*//* * Status register */#define	STATUS_PORT_A		(1 << 15)#define	STATUS_CONN_OTHER	(1 << 14)#define	STATUS_SUSPEND_OTHER	(1 << 13)#define	STATUS_MAILBOX_OTHER	(1 << 12)#define	STATUS_PACKETS_OTHER(n)	(((n) >> 8) && 0x03)#define	STATUS_CONN_THIS	(1 << 6)#define	STATUS_SUSPEND_THIS	(1 << 5)#define	STATUS_MAILBOX_THIS	(1 << 4)#define	STATUS_PACKETS_THIS(n)	(((n) >> 0) && 0x03)#define	STATUS_UNSPEC_MASK	0x0c8c#define	STATUS_NOISE_MASK 	((u16)~(0x0303|STATUS_UNSPEC_MASK))static inline void nc_dump_status(struct usbnet *dev, u16 status){	if (!netif_msg_link(dev))		return;	devdbg(dev, "net1080 %s-%s status 0x%x:"			" this (%c) PKT=%d%s%s%s;"			" other PKT=%d%s%s%s; unspec 0x%x",		dev->udev->bus->bus_name, dev->udev->devpath,		status,		// XXX the packet counts don't seem right		// (1 at reset, not 0); maybe UNSPEC too		(status & STATUS_PORT_A) ? 'A' : 'B',		STATUS_PACKETS_THIS(status),		(status & STATUS_CONN_THIS) ? " CON" : "",		(status & STATUS_SUSPEND_THIS) ? " SUS" : "",		(status & STATUS_MAILBOX_THIS) ? " MBOX" : "",		STATUS_PACKETS_OTHER(status),		(status & STATUS_CONN_OTHER) ? " CON" : "",		(status & STATUS_SUSPEND_OTHER) ? " SUS" : "",		(status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",		status & STATUS_UNSPEC_MASK		);}/*-------------------------------------------------------------------------*//* * TTL register */#define	TTL_THIS(ttl)	(0x00ff & ttl)#define	TTL_OTHER(ttl)	(0x00ff & (ttl >> 8))#define MK_TTL(this,other)	((u16)(((other)<<8)|(0x00ff&(this))))static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl){	if (netif_msg_link(dev))		devdbg(dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",			dev->udev->bus->bus_name, dev->udev->devpath,			ttl, TTL_THIS(ttl), TTL_OTHER(ttl));}/*-------------------------------------------------------------------------*/static int net1080_reset(struct usbnet *dev){	u16		usbctl, status, ttl;	u16		*vp = kmalloc(sizeof (u16), GFP_KERNEL);	int		retval;	if (!vp)		return -ENOMEM;	// nc_dump_registers(dev);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -