// SPDX-License-Identifier: GPL-2.0-or-later /**************************************************************** * * kaweth.c - driver for KL5KUSB101 based USB->Ethernet * * (c) 2000 Interlan Communications * (c) 2000 Stephane Alnet * (C) 2001 Brad Hards * (C) 2002 Oliver Neukum * * Original author: The Zapman <[email protected]> * Inspired by, and much credit goes to Michael Rothwell * <[email protected]> for the test equipment, help, and patience * Based off of (and with thanks to) Petko Manolov's pegaus.c driver. * Also many thanks to Joel Silverman and Ed Surprenant at Kawasaki * for providing the firmware and driver resources. * ****************************************************************/ /* TODO: * Develop test procedures for USB net interfaces * Run test procedures * Fix bugs from previous two steps * Snoop other OSs for any tricks we're not doing * Reduce arbitrary timeouts * Smart multicast support * Temporary MAC change support * Tunable SOFs parameter - ioctl()? * Ethernet stats collection * Code formatting improvements */ #include <linux/module.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/delay.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/usb.h> #include <linux/types.h> #include <linux/ethtool.h> #include <linux/dma-mapping.h> #include <linux/wait.h> #include <linux/firmware.h> #include <linux/uaccess.h> #include <asm/byteorder.h> #undef DEBUG #define KAWETH_MTU … #define KAWETH_BUF_SIZE … #define KAWETH_TX_TIMEOUT … #define KAWETH_SCRATCH_SIZE … #define KAWETH_FIRMWARE_BUF_SIZE … #define KAWETH_CONTROL_TIMEOUT … #define KAWETH_STATUS_BROKEN … #define KAWETH_STATUS_CLOSING … #define KAWETH_STATUS_SUSPENDING … #define KAWETH_STATUS_BLOCKED … #define KAWETH_PACKET_FILTER_PROMISCUOUS … #define KAWETH_PACKET_FILTER_ALL_MULTICAST … #define KAWETH_PACKET_FILTER_DIRECTED … #define KAWETH_PACKET_FILTER_BROADCAST … #define KAWETH_PACKET_FILTER_MULTICAST … /* Table 7 */ #define KAWETH_COMMAND_GET_ETHERNET_DESC … #define KAWETH_COMMAND_MULTICAST_FILTERS … #define KAWETH_COMMAND_SET_PACKET_FILTER … #define KAWETH_COMMAND_STATISTICS … #define KAWETH_COMMAND_SET_TEMP_MAC … #define KAWETH_COMMAND_GET_TEMP_MAC … #define KAWETH_COMMAND_SET_URB_SIZE … #define KAWETH_COMMAND_SET_SOFS_WAIT … #define KAWETH_COMMAND_SCAN … #define KAWETH_SOFS_TO_WAIT … #define INTBUFFERSIZE … #define STATE_OFFSET … #define STATE_MASK … #define STATE_SHIFT … #define IS_BLOCKED(s) … MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_FIRMWARE(…) …; MODULE_FIRMWARE(…) …; MODULE_FIRMWARE(…) …; MODULE_FIRMWARE(…) …; static const char driver_name[] = …; static int kaweth_probe( struct usb_interface *intf, const struct usb_device_id *id /* from id_table */ ); static void kaweth_disconnect(struct usb_interface *intf); static int kaweth_suspend(struct usb_interface *intf, pm_message_t message); static int kaweth_resume(struct usb_interface *intf); /**************************************************************** * usb_device_id ****************************************************************/ static const struct usb_device_id usb_klsi_table[] = …; MODULE_DEVICE_TABLE (usb, usb_klsi_table); /**************************************************************** * kaweth_driver ****************************************************************/ static struct usb_driver kaweth_driver = …; eth_addr_t; /**************************************************************** * usb_eth_dev ****************************************************************/ struct usb_eth_dev { … }; /**************************************************************** * kaweth_ethernet_configuration * Refer Table 8 ****************************************************************/ struct kaweth_ethernet_configuration { … } __packed; /**************************************************************** * kaweth_device ****************************************************************/ struct kaweth_device { … }; /**************************************************************** * kaweth_read_configuration ****************************************************************/ static int kaweth_read_configuration(struct kaweth_device *kaweth) { … } /**************************************************************** * kaweth_set_urb_size ****************************************************************/ static int kaweth_set_urb_size(struct kaweth_device *kaweth, __u16 urb_size) { … } /**************************************************************** * kaweth_set_sofs_wait ****************************************************************/ static int kaweth_set_sofs_wait(struct kaweth_device *kaweth, __u16 sofs_wait) { … } /**************************************************************** * kaweth_set_receive_filter ****************************************************************/ static int kaweth_set_receive_filter(struct kaweth_device *kaweth, __u16 receive_filter) { … } /**************************************************************** * kaweth_download_firmware ****************************************************************/ static int kaweth_download_firmware(struct kaweth_device *kaweth, const char *fwname, __u8 interrupt, __u8 type) { … } /**************************************************************** * kaweth_trigger_firmware ****************************************************************/ static int kaweth_trigger_firmware(struct kaweth_device *kaweth, __u8 interrupt) { … } /**************************************************************** * kaweth_reset ****************************************************************/ static int kaweth_reset(struct kaweth_device *kaweth) { … } static void kaweth_usb_receive(struct urb *); static int kaweth_resubmit_rx_urb(struct kaweth_device *, gfp_t); /**************************************************************** int_callback *****************************************************************/ static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, gfp_t mf) { … } static void int_callback(struct urb *u) { … } static void kaweth_resubmit_tl(struct work_struct *work) { … } /**************************************************************** * kaweth_resubmit_rx_urb ****************************************************************/ static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth, gfp_t mem_flags) { … } static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth, bool may_sleep); /**************************************************************** * kaweth_usb_receive ****************************************************************/ static void kaweth_usb_receive(struct urb *urb) { … } /**************************************************************** * kaweth_open ****************************************************************/ static int kaweth_open(struct net_device *net) { … } /**************************************************************** * kaweth_kill_urbs ****************************************************************/ static void kaweth_kill_urbs(struct kaweth_device *kaweth) { … } /**************************************************************** * kaweth_close ****************************************************************/ static int kaweth_close(struct net_device *net) { … } static u32 kaweth_get_link(struct net_device *dev) { … } static const struct ethtool_ops ops = …; /**************************************************************** * kaweth_usb_transmit_complete ****************************************************************/ static void kaweth_usb_transmit_complete(struct urb *urb) { … } /**************************************************************** * kaweth_start_xmit ****************************************************************/ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb, struct net_device *net) { … } /**************************************************************** * kaweth_set_rx_mode ****************************************************************/ static void kaweth_set_rx_mode(struct net_device *net) { … } /**************************************************************** * kaweth_async_set_rx_mode ****************************************************************/ static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth, bool may_sleep) { … } /**************************************************************** * kaweth_tx_timeout ****************************************************************/ static void kaweth_tx_timeout(struct net_device *net, unsigned int txqueue) { … } /**************************************************************** * kaweth_suspend ****************************************************************/ static int kaweth_suspend(struct usb_interface *intf, pm_message_t message) { … } /**************************************************************** * kaweth_resume ****************************************************************/ static int kaweth_resume(struct usb_interface *intf) { … } /**************************************************************** * kaweth_probe ****************************************************************/ static const struct net_device_ops kaweth_netdev_ops = …; static int kaweth_probe( struct usb_interface *intf, const struct usb_device_id *id /* from id_table */ ) { … } /**************************************************************** * kaweth_disconnect ****************************************************************/ static void kaweth_disconnect(struct usb_interface *intf) { … } module_usb_driver(…) …;