drivers/net/usb/catc.c

Source file repositories/reference/linux-study-clean/drivers/net/usb/catc.c

File Facts

System
Linux kernel
Corpus path
drivers/net/usb/catc.c
Extension
.c
Size
24516 bytes
Lines
1000
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct net_device_ops catc_netdev_ops = {
	.ndo_open		= catc_open,
	.ndo_stop		= catc_stop,
	.ndo_start_xmit		= catc_start_xmit,

	.ndo_tx_timeout		= catc_tx_timeout,
	.ndo_set_rx_mode	= catc_set_multicast_list,
	.ndo_set_mac_address 	= eth_mac_addr,
	.ndo_validate_addr	= eth_validate_addr,
};

/*
 * USB probe, disconnect.
 */

static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
	struct device *dev = &intf->dev;
	struct usb_device *usbdev = interface_to_usbdev(intf);
	struct net_device *netdev;
	struct catc *catc;
	u8 broadcast[ETH_ALEN];
	u8 *macbuf;
	int pktsz, ret = -ENOMEM;
	static const u8 bulk_ep_addr[] = {
		CATC_USB_EP_BULK | USB_DIR_OUT,
		CATC_USB_EP_BULK | USB_DIR_IN,
		0};
	static const u8 int_ep_addr[] = {
		CATC_USB_EP_INT_IN | USB_DIR_IN,
		0};

	macbuf = kmalloc(ETH_ALEN, GFP_KERNEL);
	if (!macbuf)
		goto error;

	if (usb_set_interface(usbdev,
			intf->altsetting->desc.bInterfaceNumber, 1)) {
		dev_err(dev, "Can't set altsetting 1.\n");
		ret = -EIO;
		goto fail_mem;
	}

	/* Verify that all required endpoints are present */
	if (!usb_check_bulk_endpoints(intf, bulk_ep_addr) ||
	    !usb_check_int_endpoints(intf, int_ep_addr)) {
		dev_err(dev, "Missing or invalid endpoints\n");
		ret = -ENODEV;
		goto fail_mem;
	}

	netdev = alloc_etherdev(sizeof(struct catc));
	if (!netdev)
		goto fail_mem;

	catc = netdev_priv(netdev);

	netdev->netdev_ops = &catc_netdev_ops;
	netdev->watchdog_timeo = TX_TIMEOUT;
	netdev->ethtool_ops = &ops;

	catc->usbdev = usbdev;
	catc->netdev = netdev;

	spin_lock_init(&catc->tx_lock);
	spin_lock_init(&catc->ctrl_lock);

	timer_setup(&catc->timer, catc_stats_timer, 0);

	catc->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
	catc->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
	catc->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
	catc->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
	if ((!catc->ctrl_urb) || (!catc->tx_urb) ||
	    (!catc->rx_urb) || (!catc->irq_urb)) {
		dev_err(&intf->dev, "No free urbs available.\n");
		ret = -ENOMEM;
		goto fail_free;
	}

	/* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
	if (le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
	    le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
	    le16_to_cpu(catc->usbdev->descriptor.bcdDevice) == 0x0130) {
		dev_dbg(dev, "Testing for f5u011\n");
		catc->is_f5u011 = 1;
		atomic_set(&catc->recq_sz, 0);
		pktsz = RX_PKT_SZ;
	} else {
		pktsz = RX_MAX_BURST * (PKT_SZ + 2);

Annotation

Implementation Notes