FILE
pegasus.c
File preview with syntax highlighting.
linux-6.19.14/drivers/net/usb/pegasus.c
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (c) 1999-2021 Petko Manolov (petkan@nucleusys.com) 4 * 5 */ 6 7#include <linux/sched.h> 8#include <linux/slab.h> 9#include <linux/init.h> 10#include <linux/delay.h> 11#include <linux/netdevice.h> 12#include <linux/etherdevice.h> 13#include <linux/ethtool.h> 14#include <linux/mii.h> 15#include <linux/usb.h> 16#include <linux/module.h> 17#include <asm/byteorder.h> 18#include <linux/uaccess.h> 19#include "pegasus.h" 20 21/* 22 * Version Information 23 */ 24#define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>" 25#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver" 26 27static const char driver_name[] = "pegasus"; 28 29#undef PEGASUS_WRITE_EEPROM 30#define BMSR_MEDIA (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \ 31 BMSR_100FULL | BMSR_ANEGCAPABLE) 32#define CARRIER_CHECK_DELAY (2 * HZ) 33 34/* 35 * USB endpoints. 36 */ 37 38enum pegasus_usb_ep { 39 PEGASUS_USB_EP_CONTROL = 0, 40 PEGASUS_USB_EP_BULK_IN = 1, 41 PEGASUS_USB_EP_BULK_OUT = 2, 42 PEGASUS_USB_EP_INT_IN = 3, 43}; 44 45static bool loopback; 46static bool mii_mode; 47static char *devid; 48 49static struct usb_eth_dev usb_dev_id[] = { 50#define PEGASUS_DEV(pn, vid, pid, flags) \ 51 {.name = pn, .vendor = vid, .device = pid, .private = flags}, 52#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \ 53 PEGASUS_DEV(pn, vid, pid, flags) 54#include "pegasus.h" 55#undef PEGASUS_DEV 56#undef PEGASUS_DEV_CLASS 57 {NULL, 0, 0, 0}, 58 {NULL, 0, 0, 0} 59}; 60 61static struct usb_device_id pegasus_ids[] = { 62#define PEGASUS_DEV(pn, vid, pid, flags) \ 63 {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid}, 64/* 65 * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product 66 * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to 67 * ignore adaptors belonging to the "Wireless" class 0xE0. For this one 68 * case anyway, seeing as the pegasus is for "Wired" adaptors. 69 */ 70#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \ 71 {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \ 72 .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass}, 73#include "pegasus.h" 74#undef PEGASUS_DEV 75#undef PEGASUS_DEV_CLASS 76 {}, 77 {} 78}; 79 80MODULE_AUTHOR(DRIVER_AUTHOR); 81MODULE_DESCRIPTION(DRIVER_DESC); 82MODULE_LICENSE("GPL"); 83module_param(loopback, bool, 0); 84module_param(mii_mode, bool, 0); 85module_param(devid, charp, 0); 86MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)"); 87MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0"); 88MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'"); 89 90/* use ethtool to change the level for any given device */ 91static int msg_level = -1; 92module_param(msg_level, int, 0); 93MODULE_PARM_DESC(msg_level, "Override default message level"); 94 95MODULE_DEVICE_TABLE(usb, pegasus_ids); 96static const struct net_device_ops pegasus_netdev_ops; 97 98/*****/ 99 100static void async_ctrl_callback(struct urb *urb) 101{ 102 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; 103 int status = urb->status; 104 105 if (status < 0) 106 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status); 107 kfree(req); 108 usb_free_urb(urb); 109} 110 111static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data) 112{ 113 return usb_control_msg_recv(pegasus->usb, 0, PEGASUS_REQ_GET_REGS, 114 PEGASUS_REQT_READ, 0, indx, data, size, 115 1000, GFP_NOIO); 116} 117 118static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, 119 const void *data) 120{ 121 int ret; 122 123 ret = usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REGS, 124 PEGASUS_REQT_WRITE, 0, indx, data, size, 125 1000, GFP_NOIO); 126 if (ret < 0) 127 netif_dbg(pegasus, drv, pegasus->net, "%s failed with %d\n", __func__, ret); 128 129 return ret; 130} 131 132/* 133 * There is only one way to write to a single ADM8511 register and this is via 134 * specific control request. 'data' is ignored by the device, but it is here to 135 * not break the API. 136 */ 137static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data) 138{ 139 void *buf = &data; 140 int ret; 141 142 ret = usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REG, 143 PEGASUS_REQT_WRITE, data, indx, buf, 1, 144 1000, GFP_NOIO); 145 if (ret < 0) 146 netif_dbg(pegasus, drv, pegasus->net, "%s failed with %d\n", __func__, ret); 147 148 return ret; 149} 150 151static int update_eth_regs_async(pegasus_t *pegasus) 152{ 153 int ret = -ENOMEM; 154 struct urb *async_urb; 155 struct usb_ctrlrequest *req; 156 157 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); 158 if (req == NULL) 159 return ret; 160 161 async_urb = usb_alloc_urb(0, GFP_ATOMIC); 162 if (async_urb == NULL) { 163 kfree(req); 164 return ret; 165 } 166 req->bRequestType = PEGASUS_REQT_WRITE; 167 req->bRequest = PEGASUS_REQ_SET_REGS; 168 req->wValue = cpu_to_le16(0); 169 req->wIndex = cpu_to_le16(EthCtrl0); 170 req->wLength = cpu_to_le16(3); 171 172 usb_fill_control_urb(async_urb, pegasus->usb, 173 usb_sndctrlpipe(pegasus->usb, 0), (void *)req, 174 pegasus->eth_regs, 3, async_ctrl_callback, req); 175 176 ret = usb_submit_urb(async_urb, GFP_ATOMIC); 177 if (ret) { 178 if (ret == -ENODEV) 179 netif_device_detach(pegasus->net); 180 netif_err(pegasus, drv, pegasus->net, 181 "%s returned %d\n", __func__, ret); 182 usb_free_urb(async_urb); 183 kfree(req); 184 } 185 return ret; 186} 187 188static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd) 189{ 190 int i, ret; 191 __le16 regdi; 192 __u8 data[4] = { phy, 0, 0, indx }; 193 194 if (cmd & PHY_WRITE) { 195 __le16 *t = (__le16 *) & data[1]; 196 *t = cpu_to_le16(*regd); 197 } 198 set_register(p, PhyCtrl, 0); 199 set_registers(p, PhyAddr, sizeof(data), data); 200 set_register(p, PhyCtrl, (indx | cmd)); 201 for (i = 0; i < REG_TIMEOUT; i++) { 202 ret = get_registers(p, PhyCtrl, 1, data); 203 if (ret < 0) 204 goto fail; 205 if (data[0] & PHY_DONE) 206 break; 207 } 208 if (i >= REG_TIMEOUT) { 209 ret = -ETIMEDOUT; 210 goto fail; 211 } 212 if (cmd & PHY_READ) { 213 ret = get_registers(p, PhyData, 2, ®di); 214 if (ret < 0) 215 goto fail; 216 *regd = le16_to_cpu(regdi); 217 } 218 return 0; 219fail: 220 netif_dbg(p, drv, p->net, "%s failed\n", __func__); 221 return ret; 222} 223 224/* Returns non-negative int on success, error on failure */ 225static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd) 226{ 227 return __mii_op(pegasus, phy, indx, regd, PHY_READ); 228} 229 230/* Returns zero on success, error on failure */ 231static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd) 232{ 233 return __mii_op(pegasus, phy, indx, regd, PHY_WRITE); 234} 235 236static int mdio_read(struct net_device *dev, int phy_id, int loc) 237{ 238 pegasus_t *pegasus = netdev_priv(dev); 239 int ret; 240 u16 res; 241 242 ret = read_mii_word(pegasus, phy_id, loc, &res); 243 if (ret < 0) 244 return ret; 245 246 return (int)res; 247} 248 249static void mdio_write(struct net_device *dev, int phy_id, int loc, int val) 250{ 251 pegasus_t *pegasus = netdev_priv(dev); 252 u16 data = val; 253 254 write_mii_word(pegasus, phy_id, loc, &data); 255} 256 257static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata) 258{ 259 int ret, i; 260 __le16 retdatai; 261 __u8 tmp = 0; 262 263 set_register(pegasus, EpromCtrl, 0); 264 set_register(pegasus, EpromOffset, index); 265 set_register(pegasus, EpromCtrl, EPROM_READ); 266 267 for (i = 0; i < REG_TIMEOUT; i++) { 268 ret = get_registers(pegasus, EpromCtrl, 1, &tmp); 269 if (ret < 0) 270 goto fail; 271 if (tmp & EPROM_DONE) 272 break; 273 } 274 if (i >= REG_TIMEOUT) { 275 ret = -ETIMEDOUT; 276 goto fail; 277 } 278 279 ret = get_registers(pegasus, EpromData, 2, &retdatai); 280 if (ret < 0) 281 goto fail; 282 *retdata = le16_to_cpu(retdatai); 283 return ret; 284 285fail: 286 netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__); 287 return ret; 288} 289 290#ifdef PEGASUS_WRITE_EEPROM 291static inline void enable_eprom_write(pegasus_t *pegasus) 292{ 293 __u8 tmp; 294 295 get_registers(pegasus, EthCtrl2, 1, &tmp); 296 set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE); 297} 298 299static inline void disable_eprom_write(pegasus_t *pegasus) 300{ 301 __u8 tmp; 302 303 get_registers(pegasus, EthCtrl2, 1, &tmp); 304 set_register(pegasus, EpromCtrl, 0); 305 set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE); 306} 307 308static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data) 309{ 310 int i; 311 __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE }; 312 int ret; 313 __le16 le_data = cpu_to_le16(data); 314 315 set_registers(pegasus, EpromOffset, 4, d); 316 enable_eprom_write(pegasus); 317 set_register(pegasus, EpromOffset, index); 318 set_registers(pegasus, EpromData, 2, &le_data); 319 set_register(pegasus, EpromCtrl, EPROM_WRITE); 320 321 for (i = 0; i < REG_TIMEOUT; i++) { 322 ret = get_registers(pegasus, EpromCtrl, 1, &tmp); 323 if (ret == -ESHUTDOWN) 324 goto fail; 325 if (tmp & EPROM_DONE) 326 break; 327 } 328 disable_eprom_write(pegasus); 329 if (i >= REG_TIMEOUT) 330 goto fail; 331 332 return ret; 333 334fail: 335 netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__); 336 return -ETIMEDOUT; 337} 338#endif /* PEGASUS_WRITE_EEPROM */ 339 340static inline int get_node_id(pegasus_t *pegasus, u8 *id) 341{ 342 int i, ret; 343 u16 w16; 344 345 for (i = 0; i < 3; i++) { 346 ret = read_eprom_word(pegasus, i, &w16); 347 if (ret < 0) 348 return ret; 349 ((__le16 *) id)[i] = cpu_to_le16(w16); 350 } 351 352 return 0; 353} 354 355static void set_ethernet_addr(pegasus_t *pegasus) 356{ 357 int ret; 358 u8 node_id[6]; 359 360 if (pegasus->features & PEGASUS_II) { 361 ret = get_registers(pegasus, 0x10, sizeof(node_id), node_id); 362 if (ret < 0) 363 goto err; 364 } else { 365 ret = get_node_id(pegasus, node_id); 366 if (ret < 0) 367 goto err; 368 ret = set_registers(pegasus, EthID, sizeof(node_id), node_id); 369 if (ret < 0) 370 goto err; 371 } 372 373 eth_hw_addr_set(pegasus->net, node_id); 374 375 return; 376err: 377 eth_hw_addr_random(pegasus->net); 378 netif_dbg(pegasus, drv, pegasus->net, "software assigned MAC address.\n"); 379 380 return; 381} 382 383static inline int reset_mac(pegasus_t *pegasus) 384{ 385 int ret, i; 386 __u8 data = 0x8; 387 388 set_register(pegasus, EthCtrl1, data); 389 for (i = 0; i < REG_TIMEOUT; i++) { 390 ret = get_registers(pegasus, EthCtrl1, 1, &data); 391 if (ret < 0) 392 goto fail; 393 if (~data & 0x08) { 394 if (loopback) 395 break; 396 if (mii_mode && (pegasus->features & HAS_HOME_PNA)) 397 set_register(pegasus, Gpio1, 0x34); 398 else 399 set_register(pegasus, Gpio1, 0x26); 400 set_register(pegasus, Gpio0, pegasus->features); 401 set_register(pegasus, Gpio0, DEFAULT_GPIO_SET); 402 break; 403 } 404 } 405 if (i == REG_TIMEOUT) 406 return -ETIMEDOUT; 407 408 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS || 409 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) { 410 set_register(pegasus, Gpio0, 0x24); 411 set_register(pegasus, Gpio0, 0x26); 412 } 413 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) { 414 __u16 auxmode; 415 ret = read_mii_word(pegasus, 3, 0x1b, &auxmode); 416 if (ret < 0) 417 goto fail; 418 auxmode |= 4; 419 write_mii_word(pegasus, 3, 0x1b, &auxmode); 420 } 421 422 return 0; 423fail: 424 netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__); 425 return ret; 426} 427 428static int enable_net_traffic(struct net_device *dev, struct usb_device *usb) 429{ 430 pegasus_t *pegasus = netdev_priv(dev); 431 int ret; 432 __u16 linkpart; 433 __u8 data[4]; 434 435 ret = read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart); 436 if (ret < 0) 437 goto fail; 438 data[0] = 0xc8; /* TX & RX enable, append status, no CRC */ 439 data[1] = 0; 440 if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL)) 441 data[1] |= 0x20; /* set full duplex */ 442 if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF)) 443 data[1] |= 0x10; /* set 100 Mbps */ 444 if (mii_mode) 445 data[1] = 0; 446 data[2] = loopback ? 0x09 : 0x01; 447 448 memcpy(pegasus->eth_regs, data, sizeof(data)); 449 ret = set_registers(pegasus, EthCtrl0, 3, data); 450 451 if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS || 452 usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 || 453 usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) { 454 u16 auxmode; 455 ret = read_mii_word(pegasus, 0, 0x1b, &auxmode); 456 if (ret < 0) 457 goto fail; 458 auxmode |= 4; 459 write_mii_word(pegasus, 0, 0x1b, &auxmode); 460 } 461 462 return ret; 463fail: 464 netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__); 465 return ret; 466} 467 468static void read_bulk_callback(struct urb *urb) 469{ 470 pegasus_t *pegasus = urb->context; 471 struct net_device *net; 472 u8 *buf = urb->transfer_buffer; 473 int rx_status, count = urb->actual_length; 474 int status = urb->status; 475 __u16 pkt_len; 476 477 if (!pegasus) 478 return; 479 480 net = pegasus->net; 481 if (!netif_device_present(net) || !netif_running(net)) 482 return; 483 484 switch (status) { 485 case 0: 486 break; 487 case -ETIME: 488 netif_dbg(pegasus, rx_err, net, "reset MAC\n"); 489 pegasus->flags &= ~PEGASUS_RX_BUSY; 490 break; 491 case -EPIPE: /* stall, or disconnect from TT */ 492 /* FIXME schedule work to clear the halt */ 493 netif_warn(pegasus, rx_err, net, "no rx stall recovery\n"); 494 return; 495 case -ENOENT: 496 case -ECONNRESET: 497 case -ESHUTDOWN: 498 netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status); 499 return; 500 default: 501 netif_dbg(pegasus, rx_err, net, "RX status %d\n", status); 502 goto goon; 503 } 504 505 if (count < 4) 506 goto goon; 507 508 rx_status = buf[count - 2]; 509 if (rx_status & 0x1c) { 510 netif_dbg(pegasus, rx_err, net, 511 "RX packet error %x\n", rx_status); 512 net->stats.rx_errors++; 513 if (rx_status & 0x04) /* runt */ 514 net->stats.rx_length_errors++; 515 if (rx_status & 0x08) 516 net->stats.rx_crc_errors++; 517 if (rx_status & 0x10) /* extra bits */ 518 net->stats.rx_frame_errors++; 519 goto goon; 520 } 521 if (pegasus->chip == 0x8513) { 522 pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer); 523 pkt_len &= 0x0fff; 524 pegasus->rx_skb->data += 2; 525 } else { 526 pkt_len = buf[count - 3] << 8; 527 pkt_len += buf[count - 4]; 528 pkt_len &= 0xfff; 529 pkt_len -= 4; 530 } 531 532 /* 533 * If the packet is unreasonably long, quietly drop it rather than 534 * kernel panicing by calling skb_put. 535 */ 536 if (pkt_len > PEGASUS_MTU) 537 goto goon; 538 539 /* 540 * at this point we are sure pegasus->rx_skb != NULL 541 * so we go ahead and pass up the packet. 542 */ 543 skb_put(pegasus->rx_skb, pkt_len); 544 pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net); 545 netif_rx(pegasus->rx_skb); 546 net->stats.rx_packets++; 547 net->stats.rx_bytes += pkt_len; 548 549 if (pegasus->flags & PEGASUS_UNPLUG) 550 return; 551 552 pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU, 553 GFP_ATOMIC); 554 555 if (pegasus->rx_skb == NULL) 556 goto tl_sched; 557goon: 558 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, 559 usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN), 560 pegasus->rx_skb->data, PEGASUS_MTU, 561 read_bulk_callback, pegasus); 562 rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC); 563 if (rx_status == -ENODEV) 564 netif_device_detach(pegasus->net); 565 else if (rx_status) { 566 pegasus->flags |= PEGASUS_RX_URB_FAIL; 567 goto tl_sched; 568 } else { 569 pegasus->flags &= ~PEGASUS_RX_URB_FAIL; 570 } 571 572 return; 573 574tl_sched: 575 tasklet_schedule(&pegasus->rx_tl); 576} 577 578static void rx_fixup(struct tasklet_struct *t) 579{ 580 pegasus_t *pegasus = from_tasklet(pegasus, t, rx_tl); 581 int status; 582 583 if (pegasus->flags & PEGASUS_UNPLUG) 584 return; 585 586 if (pegasus->flags & PEGASUS_RX_URB_FAIL) 587 if (pegasus->rx_skb) 588 goto try_again; 589 if (pegasus->rx_skb == NULL) 590 pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, 591 PEGASUS_MTU, 592 GFP_ATOMIC); 593 if (pegasus->rx_skb == NULL) { 594 netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n"); 595 tasklet_schedule(&pegasus->rx_tl); 596 return; 597 } 598 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, 599 usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN), 600 pegasus->rx_skb->data, PEGASUS_MTU, 601 read_bulk_callback, pegasus); 602try_again: 603 status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC); 604 if (status == -ENODEV) 605 netif_device_detach(pegasus->net); 606 else if (status) { 607 pegasus->flags |= PEGASUS_RX_URB_FAIL; 608 tasklet_schedule(&pegasus->rx_tl); 609 } else { 610 pegasus->flags &= ~PEGASUS_RX_URB_FAIL; 611 } 612} 613 614static void write_bulk_callback(struct urb *urb) 615{ 616 pegasus_t *pegasus = urb->context; 617 struct net_device *net; 618 int status = urb->status; 619 620 if (!pegasus) 621 return; 622 623 net = pegasus->net; 624 625 if (!netif_device_present(net) || !netif_running(net)) 626 return; 627 628 switch (status) { 629 case -EPIPE: 630 /* FIXME schedule_work() to clear the tx halt */ 631 netif_stop_queue(net); 632 netif_warn(pegasus, tx_err, net, "no tx stall recovery\n"); 633 return; 634 case -ENOENT: 635 case -ECONNRESET: 636 case -ESHUTDOWN: 637 netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status); 638 return; 639 default: 640 netif_info(pegasus, tx_err, net, "TX status %d\n", status); 641 fallthrough; 642 case 0: 643 break; 644 } 645 646 netif_trans_update(net); /* prevent tx timeout */ 647 netif_wake_queue(net); 648} 649 650static void intr_callback(struct urb *urb) 651{ 652 pegasus_t *pegasus = urb->context; 653 struct net_device *net; 654 int res, status = urb->status; 655 656 if (!pegasus) 657 return; 658 net = pegasus->net; 659 660 switch (status) { 661 case 0: 662 break; 663 case -ECONNRESET: /* unlink */ 664 case -ENOENT: 665 case -ESHUTDOWN: 666 return; 667 default: 668 /* some Pegasus-I products report LOTS of data 669 * toggle errors... avoid log spamming 670 */ 671 netif_dbg(pegasus, timer, net, "intr status %d\n", status); 672 } 673 674 if (urb->actual_length >= 6) { 675 u8 *d = urb->transfer_buffer; 676 677 /* byte 0 == tx_status1, reg 2B */ 678 if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL 679 |LATE_COL|JABBER_TIMEOUT)) { 680 net->stats.tx_errors++; 681 if (d[0] & TX_UNDERRUN) 682 net->stats.tx_fifo_errors++; 683 if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT)) 684 net->stats.tx_aborted_errors++; 685 if (d[0] & LATE_COL) 686 net->stats.tx_window_errors++; 687 } 688 689 /* d[5].LINK_STATUS lies on some adapters. 690 * d[0].NO_CARRIER kicks in only with failed TX. 691 * ... so monitoring with MII may be safest. 692 */ 693 694 /* bytes 3-4 == rx_lostpkt, reg 2E/2F */ 695 net->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4]; 696 } 697 698 res = usb_submit_urb(urb, GFP_ATOMIC); 699 if (res == -ENODEV) 700 netif_device_detach(pegasus->net); 701 if (res) 702 netif_err(pegasus, timer, net, 703 "can't resubmit interrupt urb, %d\n", res); 704} 705 706static void pegasus_tx_timeout(struct net_device *net, unsigned int txqueue) 707{ 708 pegasus_t *pegasus = netdev_priv(net); 709 netif_warn(pegasus, timer, net, "tx timeout\n"); 710 usb_unlink_urb(pegasus->tx_urb); 711 net->stats.tx_errors++; 712} 713 714static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb, 715 struct net_device *net) 716{ 717 pegasus_t *pegasus = netdev_priv(net); 718 int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3; 719 int res; 720 __u16 l16 = skb->len; 721 722 netif_stop_queue(net); 723 724 ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16); 725 skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len); 726 usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb, 727 usb_sndbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_OUT), 728 pegasus->tx_buff, count, 729 write_bulk_callback, pegasus); 730 if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) { 731 netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res); 732 switch (res) { 733 case -EPIPE: /* stall, or disconnect from TT */ 734 /* cleanup should already have been scheduled */ 735 break; 736 case -ENODEV: /* disconnect() upcoming */ 737 case -EPERM: 738 netif_device_detach(pegasus->net); 739 break; 740 default: 741 net->stats.tx_errors++; 742 netif_start_queue(net); 743 } 744 } else { 745 net->stats.tx_packets++; 746 net->stats.tx_bytes += skb->len; 747 } 748 dev_kfree_skb(skb); 749 750 return NETDEV_TX_OK; 751} 752 753static inline void disable_net_traffic(pegasus_t *pegasus) 754{ 755 __le16 tmp = cpu_to_le16(0); 756 757 set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp); 758} 759 760static inline int get_interrupt_interval(pegasus_t *pegasus) 761{ 762 u16 data; 763 u8 interval; 764 int ret; 765 766 ret = read_eprom_word(pegasus, 4, &data); 767 if (ret < 0) 768 return ret; 769 770 interval = data >> 8; 771 if (pegasus->usb->speed != USB_SPEED_HIGH) { 772 if (interval < 0x80) { 773 netif_info(pegasus, timer, pegasus->net, 774 "intr interval changed from %ums to %ums\n", 775 interval, 0x80); 776 interval = 0x80; 777 data = (data & 0x00FF) | ((u16)interval << 8); 778#ifdef PEGASUS_WRITE_EEPROM 779 write_eprom_word(pegasus, 4, data); 780#endif 781 } 782 } 783 pegasus->intr_interval = interval; 784 785 return 0; 786} 787 788static void set_carrier(struct net_device *net) 789{ 790 pegasus_t *pegasus = netdev_priv(net); 791 u16 tmp; 792 793 if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp)) 794 return; 795 796 if (tmp & BMSR_LSTATUS) 797 netif_carrier_on(net); 798 else 799 netif_carrier_off(net); 800} 801 802static void free_all_urbs(pegasus_t *pegasus) 803{ 804 usb_free_urb(pegasus->intr_urb); 805 usb_free_urb(pegasus->tx_urb); 806 usb_free_urb(pegasus->rx_urb); 807} 808 809static void unlink_all_urbs(pegasus_t *pegasus) 810{ 811 usb_kill_urb(pegasus->intr_urb); 812 usb_kill_urb(pegasus->tx_urb); 813 usb_kill_urb(pegasus->rx_urb); 814} 815 816static int alloc_urbs(pegasus_t *pegasus) 817{ 818 static const u8 bulk_ep_addr[] = { 819 1 | USB_DIR_IN, 820 2 | USB_DIR_OUT, 821 0}; 822 static const u8 int_ep_addr[] = { 823 3 | USB_DIR_IN, 824 0}; 825 int res = -ENOMEM; 826 827 if (!usb_check_bulk_endpoints(pegasus->intf, bulk_ep_addr) || 828 !usb_check_int_endpoints(pegasus->intf, int_ep_addr)) 829 return -ENODEV; 830 831 pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL); 832 if (!pegasus->rx_urb) { 833 return res; 834 } 835 pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL); 836 if (!pegasus->tx_urb) { 837 usb_free_urb(pegasus->rx_urb); 838 return res; 839 } 840 pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL); 841 if (!pegasus->intr_urb) { 842 usb_free_urb(pegasus->tx_urb); 843 usb_free_urb(pegasus->rx_urb); 844 return res; 845 } 846 847 return 0; 848} 849 850static int pegasus_open(struct net_device *net) 851{ 852 pegasus_t *pegasus = netdev_priv(net); 853 int res=-ENOMEM; 854 855 if (pegasus->rx_skb == NULL) 856 pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, 857 PEGASUS_MTU, 858 GFP_KERNEL); 859 if (!pegasus->rx_skb) 860 goto exit; 861 862 set_registers(pegasus, EthID, 6, net->dev_addr); 863 864 usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb, 865 usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN), 866 pegasus->rx_skb->data, PEGASUS_MTU, 867 read_bulk_callback, pegasus); 868 if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) { 869 if (res == -ENODEV) 870 netif_device_detach(pegasus->net); 871 netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res); 872 goto exit; 873 } 874 875 usb_fill_int_urb(pegasus->intr_urb, pegasus->usb, 876 usb_rcvintpipe(pegasus->usb, PEGASUS_USB_EP_INT_IN), 877 pegasus->intr_buff, sizeof(pegasus->intr_buff), 878 intr_callback, pegasus, pegasus->intr_interval); 879 if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) { 880 if (res == -ENODEV) 881 netif_device_detach(pegasus->net); 882 netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res); 883 usb_kill_urb(pegasus->rx_urb); 884 goto exit; 885 } 886 res = enable_net_traffic(net, pegasus->usb); 887 if (res < 0) { 888 netif_dbg(pegasus, ifup, net, 889 "can't enable_net_traffic() - %d\n", res); 890 res = -EIO; 891 usb_kill_urb(pegasus->rx_urb); 892 usb_kill_urb(pegasus->intr_urb); 893 goto exit; 894 } 895 set_carrier(net); 896 netif_start_queue(net); 897 netif_dbg(pegasus, ifup, net, "open\n"); 898 res = 0; 899exit: 900 return res; 901} 902 903static int pegasus_close(struct net_device *net) 904{ 905 pegasus_t *pegasus = netdev_priv(net); 906 907 netif_stop_queue(net); 908 if (!(pegasus->flags & PEGASUS_UNPLUG)) 909 disable_net_traffic(pegasus); 910 tasklet_kill(&pegasus->rx_tl); 911 unlink_all_urbs(pegasus); 912 913 return 0; 914} 915 916static void pegasus_get_drvinfo(struct net_device *dev, 917 struct ethtool_drvinfo *info) 918{ 919 pegasus_t *pegasus = netdev_priv(dev); 920 921 strscpy(info->driver, driver_name, sizeof(info->driver)); 922 usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info)); 923} 924 925/* also handles three patterns of some kind in hardware */ 926#define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY) 927 928static void 929pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 930{ 931 pegasus_t *pegasus = netdev_priv(dev); 932 933 wol->supported = WAKE_MAGIC | WAKE_PHY; 934 wol->wolopts = pegasus->wolopts; 935} 936 937static int 938pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 939{ 940 pegasus_t *pegasus = netdev_priv(dev); 941 u8 reg78 = 0x04; 942 int ret; 943 944 if (wol->wolopts & ~WOL_SUPPORTED) 945 return -EINVAL; 946 947 if (wol->wolopts & WAKE_MAGIC) 948 reg78 |= 0x80; 949 if (wol->wolopts & WAKE_PHY) 950 reg78 |= 0x40; 951 /* FIXME this 0x10 bit still needs to get set in the chip... */ 952 if (wol->wolopts) 953 pegasus->eth_regs[0] |= 0x10; 954 else 955 pegasus->eth_regs[0] &= ~0x10; 956 pegasus->wolopts = wol->wolopts; 957 958 ret = set_register(pegasus, WakeupControl, reg78); 959 if (!ret) 960 ret = device_set_wakeup_enable(&pegasus->usb->dev, 961 wol->wolopts); 962 return ret; 963} 964 965static inline void pegasus_reset_wol(struct net_device *dev) 966{ 967 struct ethtool_wolinfo wol; 968 969 memset(&wol, 0, sizeof wol); 970 (void) pegasus_set_wol(dev, &wol); 971} 972 973static int 974pegasus_get_link_ksettings(struct net_device *dev, 975 struct ethtool_link_ksettings *ecmd) 976{ 977 pegasus_t *pegasus; 978 979 pegasus = netdev_priv(dev); 980 mii_ethtool_get_link_ksettings(&pegasus->mii, ecmd); 981 return 0; 982} 983 984static int 985pegasus_set_link_ksettings(struct net_device *dev, 986 const struct ethtool_link_ksettings *ecmd) 987{ 988 pegasus_t *pegasus = netdev_priv(dev); 989 return mii_ethtool_set_link_ksettings(&pegasus->mii, ecmd); 990} 991 992static int pegasus_nway_reset(struct net_device *dev) 993{ 994 pegasus_t *pegasus = netdev_priv(dev); 995 return mii_nway_restart(&pegasus->mii); 996} 997 998static u32 pegasus_get_link(struct net_device *dev) 999{ 1000 pegasus_t *pegasus = netdev_priv(dev); 1001 return mii_link_ok(&pegasus->mii); 1002} 1003 1004static u32 pegasus_get_msglevel(struct net_device *dev) 1005{ 1006 pegasus_t *pegasus = netdev_priv(dev); 1007 return pegasus->msg_enable; 1008} 1009 1010static void pegasus_set_msglevel(struct net_device *dev, u32 v) 1011{ 1012 pegasus_t *pegasus = netdev_priv(dev); 1013 pegasus->msg_enable = v; 1014} 1015 1016static const struct ethtool_ops ops = { 1017 .get_drvinfo = pegasus_get_drvinfo, 1018 .nway_reset = pegasus_nway_reset, 1019 .get_link = pegasus_get_link, 1020 .get_msglevel = pegasus_get_msglevel, 1021 .set_msglevel = pegasus_set_msglevel, 1022 .get_wol = pegasus_get_wol, 1023 .set_wol = pegasus_set_wol, 1024 .get_link_ksettings = pegasus_get_link_ksettings, 1025 .set_link_ksettings = pegasus_set_link_ksettings, 1026}; 1027 1028static int pegasus_siocdevprivate(struct net_device *net, struct ifreq *rq, 1029 void __user *udata, int cmd) 1030{ 1031 __u16 *data = (__u16 *) &rq->ifr_ifru; 1032 pegasus_t *pegasus = netdev_priv(net); 1033 int res; 1034 1035 switch (cmd) { 1036 case SIOCDEVPRIVATE: 1037 data[0] = pegasus->phy; 1038 fallthrough; 1039 case SIOCDEVPRIVATE + 1: 1040 res = read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]); 1041 break; 1042 case SIOCDEVPRIVATE + 2: 1043 if (!capable(CAP_NET_ADMIN)) 1044 return -EPERM; 1045 write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]); 1046 res = 0; 1047 break; 1048 default: 1049 res = -EOPNOTSUPP; 1050 } 1051 return res; 1052} 1053 1054static void pegasus_set_multicast(struct net_device *net) 1055{ 1056 pegasus_t *pegasus = netdev_priv(net); 1057 1058 if (net->flags & IFF_PROMISC) { 1059 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS; 1060 netif_info(pegasus, link, net, "Promiscuous mode enabled\n"); 1061 } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) { 1062 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST; 1063 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; 1064 netif_dbg(pegasus, link, net, "set allmulti\n"); 1065 } else { 1066 pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST; 1067 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; 1068 } 1069 update_eth_regs_async(pegasus); 1070} 1071 1072static __u8 mii_phy_probe(pegasus_t *pegasus) 1073{ 1074 int i, ret; 1075 __u16 tmp; 1076 1077 for (i = 0; i < 32; i++) { 1078 ret = read_mii_word(pegasus, i, MII_BMSR, &tmp); 1079 if (ret < 0) 1080 goto fail; 1081 if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0) 1082 continue; 1083 else 1084 return i; 1085 } 1086fail: 1087 return 0xff; 1088} 1089 1090static inline void setup_pegasus_II(pegasus_t *pegasus) 1091{ 1092 int ret; 1093 __u8 data = 0xa5; 1094 1095 set_register(pegasus, Reg1d, 0); 1096 set_register(pegasus, Reg7b, 1); 1097 msleep(100); 1098 if ((pegasus->features & HAS_HOME_PNA) && mii_mode) 1099 set_register(pegasus, Reg7b, 0); 1100 else 1101 set_register(pegasus, Reg7b, 2); 1102 1103 set_register(pegasus, 0x83, data); 1104 ret = get_registers(pegasus, 0x83, 1, &data); 1105 if (ret < 0) 1106 goto fail; 1107 1108 if (data == 0xa5) 1109 pegasus->chip = 0x8513; 1110 else 1111 pegasus->chip = 0; 1112 1113 set_register(pegasus, 0x80, 0xc0); 1114 set_register(pegasus, 0x83, 0xff); 1115 set_register(pegasus, 0x84, 0x01); 1116 1117 if (pegasus->features & HAS_HOME_PNA && mii_mode) 1118 set_register(pegasus, Reg81, 6); 1119 else 1120 set_register(pegasus, Reg81, 2); 1121 1122 return; 1123fail: 1124 netif_dbg(pegasus, drv, pegasus->net, "%s failed\n", __func__); 1125} 1126 1127static void check_carrier(struct work_struct *work) 1128{ 1129 pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work); 1130 set_carrier(pegasus->net); 1131 if (!(pegasus->flags & PEGASUS_UNPLUG)) { 1132 queue_delayed_work(system_long_wq, &pegasus->carrier_check, 1133 CARRIER_CHECK_DELAY); 1134 } 1135} 1136 1137static int pegasus_blacklisted(struct usb_device *udev) 1138{ 1139 struct usb_device_descriptor *udd = &udev->descriptor; 1140 1141 /* Special quirk to keep the driver from handling the Belkin Bluetooth 1142 * dongle which happens to have the same ID. 1143 */ 1144 if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) && 1145 (udd->idProduct == cpu_to_le16(0x0121)) && 1146 (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) && 1147 (udd->bDeviceProtocol == 1)) 1148 return 1; 1149 1150 return 0; 1151} 1152 1153static int pegasus_probe(struct usb_interface *intf, 1154 const struct usb_device_id *id) 1155{ 1156 struct usb_device *dev = interface_to_usbdev(intf); 1157 struct net_device *net; 1158 pegasus_t *pegasus; 1159 int dev_index = id - pegasus_ids; 1160 int res = -ENOMEM; 1161 static const u8 bulk_ep_addr[] = { 1162 PEGASUS_USB_EP_BULK_IN | USB_DIR_IN, 1163 PEGASUS_USB_EP_BULK_OUT | USB_DIR_OUT, 1164 0}; 1165 static const u8 int_ep_addr[] = { 1166 PEGASUS_USB_EP_INT_IN | USB_DIR_IN, 1167 0}; 1168 1169 if (pegasus_blacklisted(dev)) 1170 return -ENODEV; 1171 1172 /* Verify that all required endpoints are present */ 1173 if (!usb_check_bulk_endpoints(intf, bulk_ep_addr) || 1174 !usb_check_int_endpoints(intf, int_ep_addr)) { 1175 dev_err(&intf->dev, "Missing or invalid endpoints\n"); 1176 return -ENODEV; 1177 } 1178 1179 net = alloc_etherdev(sizeof(struct pegasus)); 1180 if (!net) 1181 goto out; 1182 1183 pegasus = netdev_priv(net); 1184 pegasus->dev_index = dev_index; 1185 pegasus->intf = intf; 1186 1187 res = alloc_urbs(pegasus); 1188 if (res < 0) { 1189 dev_err(&intf->dev, "can't allocate %s\n", "urbs"); 1190 goto out1; 1191 } 1192 1193 tasklet_setup(&pegasus->rx_tl, rx_fixup); 1194 1195 INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier); 1196 1197 pegasus->usb = dev; 1198 pegasus->net = net; 1199 1200 1201 net->watchdog_timeo = PEGASUS_TX_TIMEOUT; 1202 net->netdev_ops = &pegasus_netdev_ops; 1203 net->ethtool_ops = &ops; 1204 pegasus->mii.dev = net; 1205 pegasus->mii.mdio_read = mdio_read; 1206 pegasus->mii.mdio_write = mdio_write; 1207 pegasus->mii.phy_id_mask = 0x1f; 1208 pegasus->mii.reg_num_mask = 0x1f; 1209 pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV 1210 | NETIF_MSG_PROBE | NETIF_MSG_LINK); 1211 1212 pegasus->features = usb_dev_id[dev_index].private; 1213 res = get_interrupt_interval(pegasus); 1214 if (res) 1215 goto out2; 1216 if (reset_mac(pegasus)) { 1217 dev_err(&intf->dev, "can't reset MAC\n"); 1218 res = -EIO; 1219 goto out2; 1220 } 1221 set_ethernet_addr(pegasus); 1222 if (pegasus->features & PEGASUS_II) { 1223 dev_info(&intf->dev, "setup Pegasus II specific registers\n"); 1224 setup_pegasus_II(pegasus); 1225 } 1226 pegasus->phy = mii_phy_probe(pegasus); 1227 if (pegasus->phy == 0xff) { 1228 dev_warn(&intf->dev, "can't locate MII phy, using default\n"); 1229 pegasus->phy = 1; 1230 } 1231 pegasus->mii.phy_id = pegasus->phy; 1232 usb_set_intfdata(intf, pegasus); 1233 SET_NETDEV_DEV(net, &intf->dev); 1234 pegasus_reset_wol(net); 1235 res = register_netdev(net); 1236 if (res) 1237 goto out3; 1238 queue_delayed_work(system_long_wq, &pegasus->carrier_check, 1239 CARRIER_CHECK_DELAY); 1240 dev_info(&intf->dev, "%s, %s, %pM\n", net->name, 1241 usb_dev_id[dev_index].name, net->dev_addr); 1242 return 0; 1243 1244out3: 1245 usb_set_intfdata(intf, NULL); 1246out2: 1247 free_all_urbs(pegasus); 1248out1: 1249 free_netdev(net); 1250out: 1251 return res; 1252} 1253 1254static void pegasus_disconnect(struct usb_interface *intf) 1255{ 1256 struct pegasus *pegasus = usb_get_intfdata(intf); 1257 1258 usb_set_intfdata(intf, NULL); 1259 if (!pegasus) { 1260 dev_dbg(&intf->dev, "unregistering non-bound device?\n"); 1261 return; 1262 } 1263 1264 pegasus->flags |= PEGASUS_UNPLUG; 1265 cancel_delayed_work_sync(&pegasus->carrier_check); 1266 unregister_netdev(pegasus->net); 1267 unlink_all_urbs(pegasus); 1268 free_all_urbs(pegasus); 1269 if (pegasus->rx_skb != NULL) { 1270 dev_kfree_skb(pegasus->rx_skb); 1271 pegasus->rx_skb = NULL; 1272 } 1273 free_netdev(pegasus->net); 1274} 1275 1276static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) 1277{ 1278 struct pegasus *pegasus = usb_get_intfdata(intf); 1279 1280 netif_device_detach(pegasus->net); 1281 cancel_delayed_work_sync(&pegasus->carrier_check); 1282 if (netif_running(pegasus->net)) { 1283 usb_kill_urb(pegasus->rx_urb); 1284 usb_kill_urb(pegasus->intr_urb); 1285 } 1286 return 0; 1287} 1288 1289static int pegasus_resume(struct usb_interface *intf) 1290{ 1291 struct pegasus *pegasus = usb_get_intfdata(intf); 1292 1293 netif_device_attach(pegasus->net); 1294 if (netif_running(pegasus->net)) { 1295 pegasus->rx_urb->status = 0; 1296 pegasus->rx_urb->actual_length = 0; 1297 read_bulk_callback(pegasus->rx_urb); 1298 1299 pegasus->intr_urb->status = 0; 1300 pegasus->intr_urb->actual_length = 0; 1301 intr_callback(pegasus->intr_urb); 1302 } 1303 queue_delayed_work(system_long_wq, &pegasus->carrier_check, 1304 CARRIER_CHECK_DELAY); 1305 return 0; 1306} 1307 1308static const struct net_device_ops pegasus_netdev_ops = { 1309 .ndo_open = pegasus_open, 1310 .ndo_stop = pegasus_close, 1311 .ndo_siocdevprivate = pegasus_siocdevprivate, 1312 .ndo_start_xmit = pegasus_start_xmit, 1313 .ndo_set_rx_mode = pegasus_set_multicast, 1314 .ndo_tx_timeout = pegasus_tx_timeout, 1315 .ndo_set_mac_address = eth_mac_addr, 1316 .ndo_validate_addr = eth_validate_addr, 1317}; 1318 1319static struct usb_driver pegasus_driver = { 1320 .name = driver_name, 1321 .probe = pegasus_probe, 1322 .disconnect = pegasus_disconnect, 1323 .id_table = pegasus_ids, 1324 .suspend = pegasus_suspend, 1325 .resume = pegasus_resume, 1326 .disable_hub_initiated_lpm = 1, 1327}; 1328 1329static void __init parse_id(char *id) 1330{ 1331 unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0; 1332 char *token, *name = NULL; 1333 1334 if ((token = strsep(&id, ":")) != NULL) 1335 name = token; 1336 /* name now points to a null terminated string*/ 1337 if ((token = strsep(&id, ":")) != NULL) 1338 vendor_id = simple_strtoul(token, NULL, 16); 1339 if ((token = strsep(&id, ":")) != NULL) 1340 device_id = simple_strtoul(token, NULL, 16); 1341 flags = simple_strtoul(id, NULL, 16); 1342 pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n", 1343 driver_name, name, vendor_id, device_id, flags); 1344 1345 if (vendor_id > 0x10000 || vendor_id == 0) 1346 return; 1347 if (device_id > 0x10000 || device_id == 0) 1348 return; 1349 1350 for (i = 0; usb_dev_id[i].name; i++); 1351 usb_dev_id[i].name = name; 1352 usb_dev_id[i].vendor = vendor_id; 1353 usb_dev_id[i].device = device_id; 1354 usb_dev_id[i].private = flags; 1355 pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 1356 pegasus_ids[i].idVendor = vendor_id; 1357 pegasus_ids[i].idProduct = device_id; 1358} 1359 1360static int __init pegasus_init(void) 1361{ 1362 pr_info("%s: " DRIVER_DESC "\n", driver_name); 1363 if (devid) 1364 parse_id(devid); 1365 return usb_register(&pegasus_driver); 1366} 1367 1368static void __exit pegasus_exit(void) 1369{ 1370 usb_deregister(&pegasus_driver); 1371} 1372 1373module_init(pegasus_init); 1374module_exit(pegasus_exit);
~/
Read-only file preview.