^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mii.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Version Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define IDR 0x0120
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define MAR 0x0126
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define CR 0x012e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define TCR 0x012f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define RCR 0x0130
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define TSR 0x0132
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define RSR 0x0133
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define CON0 0x0135
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define CON1 0x0136
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define MSR 0x0137
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define PHYADD 0x0138
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define PHYDAT 0x0139
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define PHYCNT 0x013b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define GPPC 0x013d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define BMCR 0x0140
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define BMSR 0x0142
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define ANAR 0x0144
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define ANLP 0x0146
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define AER 0x0148
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define CSCR 0x014C /* This one has the link status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define CSCR_LINK_STATUS (1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define IDR_EEPROM 0x1202
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define PHY_READ 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define PHY_WRITE 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define PHY_GO 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define MII_TIMEOUT 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define INTBUFSIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define RTL8150_REQT_READ 0xc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define RTL8150_REQT_WRITE 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define RTL8150_REQ_GET_REGS 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define RTL8150_REQ_SET_REGS 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Transmit status register errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define TSR_ECOL (1<<5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TSR_LCOL (1<<4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define TSR_LOSS_CRS (1<<3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define TSR_JBR (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Receive status register errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define RSR_CRC (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define RSR_FAE (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define RSR_ERRORS (RSR_CRC | RSR_FAE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Media status register definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define MSR_DUPLEX (1<<4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define MSR_SPEED (1<<3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define MSR_LINK (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Interrupt pipe data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define INT_TSR 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define INT_RSR 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define INT_MSR 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define INT_WAKSR 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define INT_TXOK_CNT 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define INT_RXLOST_CNT 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define INT_CRERR_CNT 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define INT_COL_CNT 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define RTL8150_MTU 1540
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define RTL8150_TX_TIMEOUT (HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define RX_SKB_POOL_SIZE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* rtl8150 flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define RTL8150_HW_CRC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define RX_REG_SET 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define RTL8150_UNPLUG 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define RX_URB_FAIL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Define these values to match your device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define VENDOR_ID_REALTEK 0x0bda
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define VENDOR_ID_MELCO 0x0411
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define VENDOR_ID_MICRONET 0x3980
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define VENDOR_ID_LONGSHINE 0x07b8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define VENDOR_ID_OQO 0x1557
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define VENDOR_ID_ZYXEL 0x0586
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define PRODUCT_ID_RTL8150 0x8150
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define PRODUCT_ID_LUAKTX 0x0012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define PRODUCT_ID_LCS8138TX 0x401a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define PRODUCT_ID_SP128AR 0x0003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define PRODUCT_ID_PRESTIGE 0x401a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #undef EEPROM_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* table of devices that work with this driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct usb_device_id rtl8150_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_DEVICE_TABLE(usb, rtl8150_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct rtl8150 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct tasklet_struct tl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct urb *rx_urb, *tx_urb, *intr_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct sk_buff *tx_skb, *rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) spinlock_t rx_pool_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct usb_ctrlrequest dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int intr_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u8 *intr_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u8 phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) typedef struct rtl8150 rtl8150_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct async_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct usb_ctrlrequest dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u16 rx_creg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static const char driver_name [] = "rtl8150";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ** device related part of the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) RTL8150_REQT_READ, indx, 0, data, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 1000, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) RTL8150_REQT_WRITE, indx, 0, data, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 1000, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static void async_set_reg_cb(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct async_req *req = (struct async_req *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int res = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct urb *async_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct async_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) req = kmalloc(sizeof(struct async_req), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (req == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) async_urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (async_urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) req->rx_creg = cpu_to_le16(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) req->dr.bRequestType = RTL8150_REQT_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) req->dr.bRequest = RTL8150_REQ_SET_REGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) req->dr.wIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) req->dr.wValue = cpu_to_le16(indx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) req->dr.wLength = cpu_to_le16(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) usb_fill_control_urb(async_urb, dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) &req->rx_creg, size, async_set_reg_cb, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) res = usb_submit_urb(async_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) u8 data[3], tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) data[0] = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) data[1] = data[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) tmp = indx | PHY_READ | PHY_GO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) set_registers(dev, PHYADD, sizeof(data), data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) set_registers(dev, PHYCNT, 1, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) get_registers(dev, PHYCNT, 1, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (i <= MII_TIMEOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) get_registers(dev, PHYDAT, 2, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *reg = data[0] | (data[1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u8 data[3], tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) data[0] = phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) data[1] = reg & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) data[2] = (reg >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) tmp = indx | PHY_WRITE | PHY_GO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) set_registers(dev, PHYADD, sizeof(data), data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) set_registers(dev, PHYCNT, 1, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) get_registers(dev, PHYCNT, 1, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (i <= MII_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void set_ethernet_addr(rtl8150_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u8 node_id[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ret = get_registers(dev, IDR, sizeof(node_id), node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ether_addr_copy(dev->netdev->dev_addr, node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) eth_hw_addr_random(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) dev->netdev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct sockaddr *addr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (netif_running(netdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /* Set the IDR registers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #ifdef EEPROM_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) u8 cr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Get the CR contents. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) get_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Set the WEPROM bit (eeprom write enable). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) cr |= 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) set_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) so we need to split them up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) for (i = 0; i * 2 < netdev->addr_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) set_registers(dev, IDR_EEPROM + (i * 2), 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) netdev->dev_addr + (i * 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Clear the WEPROM bit (preventing accidental eeprom writes). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) cr &= 0xdf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) set_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static int rtl8150_reset(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) u8 data = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int i = HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) set_registers(dev, CR, 1, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) get_registers(dev, CR, 1, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) } while ((data & 0x10) && --i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return (i > 0) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int alloc_all_urbs(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (!dev->rx_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (!dev->tx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) usb_free_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!dev->intr_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) usb_free_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) usb_free_urb(dev->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static void free_all_urbs(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) usb_free_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) usb_free_urb(dev->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) usb_free_urb(dev->intr_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void unlink_all_urbs(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) usb_kill_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) usb_kill_urb(dev->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) usb_kill_urb(dev->intr_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static inline struct sk_buff *pull_skb(rtl8150_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (dev->rx_skb_pool[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) skb = dev->rx_skb_pool[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) dev->rx_skb_pool[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static void read_bulk_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) rtl8150_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned pkt_len, res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (test_bit(RTL8150_UNPLUG, &dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) netdev = dev->netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!netif_device_present(netdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return; /* the urb is in unlink state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) dev_warn(&urb->dev->dev, "may be reset is needed?..\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) goto goon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dev_warn(&urb->dev->dev, "Rx status %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) goto goon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!dev->rx_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) goto resched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /* protect against short packets (tell me why we got some?!?) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (urb->actual_length < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) goto goon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) res = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) pkt_len = res - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) skb_put(dev->rx_skb, pkt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) netif_rx(dev->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) netdev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) netdev->stats.rx_bytes += pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) spin_lock_irqsave(&dev->rx_pool_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) skb = pull_skb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) goto resched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) dev->rx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) goon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (result == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) else if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) set_bit(RX_URB_FAIL, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) goto resched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) clear_bit(RX_URB_FAIL, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) resched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) tasklet_schedule(&dev->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void write_bulk_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) rtl8150_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) dev_kfree_skb_irq(dev->tx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (!netif_device_present(dev->netdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) dev_info(&urb->dev->dev, "%s: Tx status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) dev->netdev->name, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) netif_trans_update(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) netif_wake_queue(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static void intr_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) rtl8150_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) __u8 *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) case 0: /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) case -ECONNRESET: /* unlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* -EPIPE: should clear the halt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) dev_info(&urb->dev->dev, "%s: intr status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) dev->netdev->name, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) d = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (d[0] & TSR_ERRORS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) dev->netdev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) dev->netdev->stats.tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (d[INT_TSR] & TSR_LCOL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) dev->netdev->stats.tx_window_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (d[INT_TSR] & TSR_LOSS_CRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) dev->netdev->stats.tx_carrier_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* Report link status changes to the network stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if ((d[INT_MSR] & MSR_LINK) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (netif_carrier_ok(dev->netdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) netif_carrier_off(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (!netif_carrier_ok(dev->netdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) netif_carrier_on(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) res = usb_submit_urb (urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) else if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dev_err(&dev->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) "can't resubmit intr, %s-%s/input0, status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dev->udev->bus->bus_name, dev->udev->devpath, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) rtl8150_t *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (netif_running(dev->netdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) usb_kill_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) usb_kill_urb(dev->intr_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static int rtl8150_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) rtl8150_t *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) netif_device_attach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (netif_running(dev->netdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) dev->rx_urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) dev->rx_urb->actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) read_bulk_callback(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) dev->intr_urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) dev->intr_urb->actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) intr_callback(dev->intr_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) ** network related part of the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static void fill_skb_pool(rtl8150_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (dev->rx_skb_pool[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) skb = dev_alloc_skb(RTL8150_MTU + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) skb_reserve(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) dev->rx_skb_pool[i] = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static void free_skb_pool(rtl8150_t *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) for (i = 0; i < RX_SKB_POOL_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) dev_kfree_skb(dev->rx_skb_pool[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static void rx_fixup(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct rtl8150 *dev = (struct rtl8150 *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) spin_lock_irq(&dev->rx_pool_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) fill_skb_pool(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) spin_unlock_irq(&dev->rx_pool_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (test_bit(RX_URB_FAIL, &dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (dev->rx_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) goto try_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) spin_lock_irq(&dev->rx_pool_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) skb = pull_skb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) spin_unlock_irq(&dev->rx_pool_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) goto tlsched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) dev->rx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) try_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (status == -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) } else if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) set_bit(RX_URB_FAIL, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto tlsched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) clear_bit(RX_URB_FAIL, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) tlsched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) tasklet_schedule(&dev->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static int enable_net_traffic(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) u8 cr, tcr, rcr, msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (!rtl8150_reset(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) dev_warn(&dev->udev->dev, "device reset failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) rcr = 0x9e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) tcr = 0xd8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) cr = 0x0c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!(rcr & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) set_bit(RTL8150_HW_CRC, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) set_registers(dev, RCR, 1, &rcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) set_registers(dev, TCR, 1, &tcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) set_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) get_registers(dev, MSR, 1, &msr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static void disable_net_traffic(rtl8150_t * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) u8 cr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) get_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) cr &= 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) set_registers(dev, CR, 1, &cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static void rtl8150_tx_timeout(struct net_device *netdev, unsigned int txqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) dev_warn(&netdev->dev, "Tx timeout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) usb_unlink_urb(dev->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) netdev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static void rtl8150_set_multicast(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) u16 rx_creg = 0x9e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) netif_stop_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (netdev->flags & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) rx_creg |= 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) } else if (!netdev_mc_empty(netdev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) (netdev->flags & IFF_ALLMULTI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) rx_creg &= 0xfffe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) rx_creg |= 0x0002;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) dev_dbg(&netdev->dev, "%s: allmulti set\n", netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) rx_creg &= 0x00fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) async_set_registers(dev, RCR, sizeof(rx_creg), rx_creg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) netif_wake_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int count, res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) netif_stop_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) count = (skb->len < 60) ? 60 : skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) count = (count & 0x3f) ? count : count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) dev->tx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) skb->data, count, write_bulk_callback, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* Can we get/handle EPIPE here? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) netdev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) netif_start_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) netdev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) netdev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) netif_trans_update(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static void set_carrier(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) short tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) get_registers(dev, CSCR, 2, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (tmp & CSCR_LINK_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) netif_carrier_on(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) netif_carrier_off(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) static int rtl8150_open(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (dev->rx_skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) dev->rx_skb = pull_skb(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (!dev->rx_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) set_registers(dev, IDR, 6, netdev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) dev->intr_buff, INTBUFSIZE, intr_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) dev, dev->intr_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) netif_device_detach(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) usb_kill_urb(dev->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) enable_net_traffic(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) set_carrier(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) netif_start_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) static int rtl8150_close(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) netif_stop_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (!test_bit(RTL8150_UNPLUG, &dev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) disable_net_traffic(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) unlink_all_urbs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) strlcpy(info->driver, driver_name, sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) static int rtl8150_get_link_ksettings(struct net_device *netdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct ethtool_link_ksettings *ecmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) short lpa, bmcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) u32 supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) supported = (SUPPORTED_10baseT_Half |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) SUPPORTED_10baseT_Full |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) SUPPORTED_100baseT_Half |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) SUPPORTED_100baseT_Full |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) SUPPORTED_Autoneg |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) SUPPORTED_TP | SUPPORTED_MII);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) ecmd->base.port = PORT_TP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) ecmd->base.phy_address = dev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) get_registers(dev, BMCR, 2, &bmcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) get_registers(dev, ANLP, 2, &lpa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (bmcr & BMCR_ANENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) SPEED_100 : SPEED_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ecmd->base.speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) ecmd->base.autoneg = AUTONEG_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (speed == SPEED_100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) ecmd->base.duplex = (lpa & LPA_100FULL) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) DUPLEX_FULL : DUPLEX_HALF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ecmd->base.duplex = (lpa & LPA_10FULL) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) DUPLEX_FULL : DUPLEX_HALF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) ecmd->base.autoneg = AUTONEG_DISABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) ecmd->base.speed = ((bmcr & BMCR_SPEED100) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) SPEED_100 : SPEED_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) ecmd->base.duplex = (bmcr & BMCR_FULLDPLX) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) DUPLEX_FULL : DUPLEX_HALF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) supported);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) static const struct ethtool_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) .get_drvinfo = rtl8150_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) .get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) .get_link_ksettings = rtl8150_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) rtl8150_t *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) u16 *data = (u16 *) & rq->ifr_ifru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) case SIOCDEVPRIVATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) data[0] = dev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) case SIOCDEVPRIVATE + 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) case SIOCDEVPRIVATE + 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) res = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static const struct net_device_ops rtl8150_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) .ndo_open = rtl8150_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) .ndo_stop = rtl8150_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) .ndo_do_ioctl = rtl8150_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) .ndo_start_xmit = rtl8150_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) .ndo_tx_timeout = rtl8150_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) .ndo_set_rx_mode = rtl8150_set_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) .ndo_set_mac_address = rtl8150_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static int rtl8150_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) rtl8150_t *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) netdev = alloc_etherdev(sizeof(rtl8150_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (!netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (!dev->intr_buff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) free_netdev(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) spin_lock_init(&dev->rx_pool_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) dev->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) dev->netdev = netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) netdev->netdev_ops = &rtl8150_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) netdev->ethtool_ops = &ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) dev->intr_interval = 100; /* 100ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (!alloc_all_urbs(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) dev_err(&intf->dev, "out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (!rtl8150_reset(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) dev_err(&intf->dev, "couldn't reset the device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) fill_skb_pool(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) set_ethernet_addr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) usb_set_intfdata(intf, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) SET_NETDEV_DEV(netdev, &intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (register_netdev(netdev) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) dev_err(&intf->dev, "couldn't register the device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) free_skb_pool(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) free_all_urbs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) kfree(dev->intr_buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) free_netdev(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) static void rtl8150_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) rtl8150_t *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) set_bit(RTL8150_UNPLUG, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) tasklet_kill(&dev->tl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) unregister_netdev(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) unlink_all_urbs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) free_all_urbs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) free_skb_pool(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) dev_kfree_skb(dev->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) kfree(dev->intr_buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) free_netdev(dev->netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) static struct usb_driver rtl8150_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) .name = driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) .probe = rtl8150_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) .disconnect = rtl8150_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) .id_table = rtl8150_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) .suspend = rtl8150_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) .resume = rtl8150_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) module_usb_driver(rtl8150_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) MODULE_LICENSE("GPL");