Lines Matching refs:dev

110 static void rtl8150_disconnect(struct usb_device *dev, void *ptr);
111 static void *rtl8150_probe(struct usb_device *dev, unsigned int ifnum,
128 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data) in get_registers() argument
130 return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), in get_registers()
135 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data) in set_registers() argument
137 return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), in set_registers()
144 rtl8150_t *dev; in ctrl_callback() local
156 dev = urb->context; in ctrl_callback()
157 clear_bit(RX_REG_SET, &dev->flags); in ctrl_callback()
160 static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size) in async_set_registers() argument
164 if (test_bit(RX_REG_SET, &dev->flags)) in async_set_registers()
167 dev->dr.bRequestType = RTL8150_REQT_WRITE; in async_set_registers()
168 dev->dr.bRequest = RTL8150_REQ_SET_REGS; in async_set_registers()
169 dev->dr.wValue = cpu_to_le16(indx); in async_set_registers()
170 dev->dr.wIndex = 0; in async_set_registers()
171 dev->dr.wLength = cpu_to_le16(2); in async_set_registers()
172 dev->ctrl_urb->transfer_buffer_length = 2; in async_set_registers()
173 FILL_CONTROL_URB(dev->ctrl_urb, dev->udev, in async_set_registers()
174 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr, in async_set_registers()
175 &dev->rx_creg, 2, ctrl_callback, dev); in async_set_registers()
176 if ((ret = usb_submit_urb(dev->ctrl_urb))) in async_set_registers()
179 set_bit(RX_REG_SET, &dev->flags); in async_set_registers()
184 static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg) in read_mii_word() argument
194 set_registers(dev, PHYADD, sizeof(data), data); in read_mii_word()
195 set_registers(dev, PHYCNT, 1, &tmp); in read_mii_word()
197 get_registers(dev, PHYCNT, 1, data); in read_mii_word()
201 get_registers(dev, PHYDAT, 2, data); in read_mii_word()
208 static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg) in write_mii_word() argument
218 set_registers(dev, PHYADD, sizeof(data), data); in write_mii_word()
219 set_registers(dev, PHYCNT, 1, &tmp); in write_mii_word()
221 get_registers(dev, PHYCNT, 1, data); in write_mii_word()
230 static inline void set_ethernet_addr(rtl8150_t * dev) in set_ethernet_addr() argument
234 get_registers(dev, IDR, sizeof(node_id), node_id); in set_ethernet_addr()
235 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id)); in set_ethernet_addr()
241 rtl8150_t *dev; in rtl8150_set_mac_address() local
246 dev = netdev->priv; in rtl8150_set_mac_address()
247 if (dev == NULL) { in rtl8150_set_mac_address()
256 set_registers(dev, IDR, sizeof(netdev->dev_addr), netdev->dev_addr); in rtl8150_set_mac_address()
261 get_registers(dev, CR, 1, &cr); in rtl8150_set_mac_address()
264 set_registers(dev, CR, 1, &cr); in rtl8150_set_mac_address()
268 set_registers(dev, IDR_EEPROM + (i * 2), 2, in rtl8150_set_mac_address()
273 set_registers(dev, CR, 1, &cr); in rtl8150_set_mac_address()
279 static int rtl8150_reset(rtl8150_t * dev) in rtl8150_reset() argument
284 set_registers(dev, CR, 1, &data); in rtl8150_reset()
286 get_registers(dev, CR, 1, &data); in rtl8150_reset()
292 static int alloc_all_urbs(rtl8150_t * dev) in alloc_all_urbs() argument
294 dev->rx_urb = usb_alloc_urb(0); in alloc_all_urbs()
295 if (!dev->rx_urb) in alloc_all_urbs()
297 dev->tx_urb = usb_alloc_urb(0); in alloc_all_urbs()
298 if (!dev->tx_urb) { in alloc_all_urbs()
299 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
302 dev->intr_urb = usb_alloc_urb(0); in alloc_all_urbs()
303 if (!dev->intr_urb) { in alloc_all_urbs()
304 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
305 usb_free_urb(dev->tx_urb); in alloc_all_urbs()
308 dev->ctrl_urb = usb_alloc_urb(0); in alloc_all_urbs()
309 if (!dev->ctrl_urb) { in alloc_all_urbs()
310 usb_free_urb(dev->rx_urb); in alloc_all_urbs()
311 usb_free_urb(dev->tx_urb); in alloc_all_urbs()
312 usb_free_urb(dev->intr_urb); in alloc_all_urbs()
319 static void free_all_urbs(rtl8150_t * dev) in free_all_urbs() argument
321 usb_free_urb(dev->rx_urb); in free_all_urbs()
322 usb_free_urb(dev->tx_urb); in free_all_urbs()
323 usb_free_urb(dev->intr_urb); in free_all_urbs()
324 usb_free_urb(dev->ctrl_urb); in free_all_urbs()
327 static void unlink_all_urbs(rtl8150_t * dev) in unlink_all_urbs() argument
329 usb_unlink_urb(dev->rx_urb); in unlink_all_urbs()
330 usb_unlink_urb(dev->tx_urb); in unlink_all_urbs()
331 usb_unlink_urb(dev->intr_urb); in unlink_all_urbs()
332 usb_unlink_urb(dev->ctrl_urb); in unlink_all_urbs()
337 rtl8150_t *dev; in read_bulk_callback() local
343 dev = urb->context; in read_bulk_callback()
344 if (!dev) { in read_bulk_callback()
348 netdev = dev->netdev; in read_bulk_callback()
367 rx_stat = le16_to_cpu(*(u16 *) (dev->rx_buff + pkt_len)); in read_bulk_callback()
371 skb->dev = netdev; in read_bulk_callback()
373 eth_copy_and_sum(skb, dev->rx_buff, pkt_len, 0); in read_bulk_callback()
377 dev->stats.rx_packets++; in read_bulk_callback()
378 dev->stats.rx_bytes += pkt_len; in read_bulk_callback()
380 FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in read_bulk_callback()
381 dev->rx_buff, RTL8150_MAX_MTU, read_bulk_callback, dev); in read_bulk_callback()
382 if ((res = usb_submit_urb(dev->rx_urb))) in read_bulk_callback()
388 rtl8150_t *dev; in write_bulk_callback() local
390 dev = urb->context; in write_bulk_callback()
391 if (!dev) in write_bulk_callback()
393 if (!netif_device_present(dev->netdev)) in write_bulk_callback()
396 info("%s: Tx status %d", dev->netdev->name, urb->status); in write_bulk_callback()
397 dev->netdev->trans_start = jiffies; in write_bulk_callback()
398 netif_wake_queue(dev->netdev); in write_bulk_callback()
403 rtl8150_t *dev; in intr_callback() local
405 dev = urb->context; in intr_callback()
406 if (!dev) in intr_callback()
414 info("%s: intr status %d", dev->netdev->name, urb->status); in intr_callback()
424 static int enable_net_traffic(rtl8150_t * dev) in enable_net_traffic() argument
428 if (rtl8150_reset(dev)) { in enable_net_traffic()
432 dev->rx_creg = cpu_to_le16(rcr); in enable_net_traffic()
435 set_registers(dev, RCR, 1, &rcr); in enable_net_traffic()
436 set_registers(dev, TCR, 1, &tcr); in enable_net_traffic()
437 set_registers(dev, CR, 1, &cr); in enable_net_traffic()
438 get_registers(dev, MSR, 1, &msr); in enable_net_traffic()
443 static void disable_net_traffic(rtl8150_t * dev) in disable_net_traffic() argument
447 get_registers(dev, CR, 1, &cr); in disable_net_traffic()
449 set_registers(dev, CR, 1, &cr); in disable_net_traffic()
452 static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev) in rtl8150_netdev_stats() argument
454 return &((rtl8150_t *) dev->priv)->stats; in rtl8150_netdev_stats()
459 rtl8150_t *dev; in rtl8150_tx_timeout() local
461 dev = netdev->priv; in rtl8150_tx_timeout()
462 if (!dev) in rtl8150_tx_timeout()
465 dev->tx_urb->transfer_flags |= USB_ASYNC_UNLINK; in rtl8150_tx_timeout()
466 usb_unlink_urb(dev->tx_urb); in rtl8150_tx_timeout()
467 dev->stats.tx_errors++; in rtl8150_tx_timeout()
472 rtl8150_t *dev; in rtl8150_set_multicast() local
474 dev = netdev->priv; in rtl8150_set_multicast()
477 dev->rx_creg |= cpu_to_le16(0x0001); in rtl8150_set_multicast()
481 dev->rx_creg &= cpu_to_le16(0xfffe); in rtl8150_set_multicast()
482 dev->rx_creg |= cpu_to_le16(0x0002); in rtl8150_set_multicast()
486 dev->rx_creg &= cpu_to_le16(0x00fc); in rtl8150_set_multicast()
488 async_set_registers(dev, RCR, 2); in rtl8150_set_multicast()
494 rtl8150_t *dev; in rtl8150_start_xmit() local
498 dev = netdev->priv; in rtl8150_start_xmit()
501 memcpy(dev->tx_buff, skb->data, skb->len); in rtl8150_start_xmit()
502 FILL_BULK_URB(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), in rtl8150_start_xmit()
503 dev->tx_buff, count, write_bulk_callback, dev); in rtl8150_start_xmit()
504 dev->tx_urb->transfer_buffer_length = count; in rtl8150_start_xmit()
506 if ((res = usb_submit_urb(dev->tx_urb))) { in rtl8150_start_xmit()
508 dev->stats.tx_errors++; in rtl8150_start_xmit()
511 dev->stats.tx_packets++; in rtl8150_start_xmit()
512 dev->stats.tx_bytes += skb->len; in rtl8150_start_xmit()
522 rtl8150_t *dev; in rtl8150_open() local
525 dev = netdev->priv; in rtl8150_open()
526 if (dev == NULL) { in rtl8150_open()
530 down(&dev->sem); in rtl8150_open()
532 set_registers(dev, IDR, 6, netdev->dev_addr); in rtl8150_open()
534 FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in rtl8150_open()
535 dev->rx_buff, RTL8150_MAX_MTU, read_bulk_callback, dev); in rtl8150_open()
536 if ((res = usb_submit_urb(dev->rx_urb))) in rtl8150_open()
538 FILL_INT_URB(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3), in rtl8150_open()
539 dev->intr_buff, sizeof(dev->intr_buff), intr_callback, in rtl8150_open()
540 dev, dev->intr_interval); in rtl8150_open()
541 if ((res = usb_submit_urb(dev->intr_urb))) in rtl8150_open()
544 enable_net_traffic(dev); in rtl8150_open()
545 up(&dev->sem); in rtl8150_open()
552 rtl8150_t *dev; in rtl8150_close() local
555 dev = netdev->priv; in rtl8150_close()
556 if (!dev) in rtl8150_close()
559 down(&dev->sem); in rtl8150_close()
560 if (!test_bit(RTL8150_UNPLUG, &dev->flags)) in rtl8150_close()
561 disable_net_traffic(dev); in rtl8150_close()
562 unlink_all_urbs(dev); in rtl8150_close()
564 up(&dev->sem); in rtl8150_close()
571 rtl8150_t *dev; in rtl8150_ethtool_ioctl() local
575 dev = netdev->priv; in rtl8150_ethtool_ioctl()
586 sprintf(tmp, "usb%d:%d", dev->udev->bus->busnum, in rtl8150_ethtool_ioctl()
587 dev->udev->devnum); in rtl8150_ethtool_ioctl()
607 ecmd.phy_address = dev->phy; in rtl8150_ethtool_ioctl()
608 get_registers(dev, BMCR, 2, &bmcr); in rtl8150_ethtool_ioctl()
609 get_registers(dev, ANLP, 2, &lpa); in rtl8150_ethtool_ioctl()
649 rtl8150_t *dev; in rtl8150_ioctl() local
653 dev = netdev->priv; in rtl8150_ioctl()
657 down(&dev->sem); in rtl8150_ioctl()
663 data[0] = dev->phy; in rtl8150_ioctl()
665 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]); in rtl8150_ioctl()
669 up(&dev->sem); in rtl8150_ioctl()
672 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]); in rtl8150_ioctl()
677 up(&dev->sem); in rtl8150_ioctl()
685 rtl8150_t *dev; in rtl8150_probe() local
693 dev = kmalloc(sizeof(rtl8150_t), GFP_KERNEL); in rtl8150_probe()
694 if (!dev) { in rtl8150_probe()
698 memset(dev, 0, sizeof(rtl8150_t)); in rtl8150_probe()
702 kfree(dev); in rtl8150_probe()
704 dev = NULL; in rtl8150_probe()
708 init_MUTEX(&dev->sem); in rtl8150_probe()
709 dev->udev = udev; in rtl8150_probe()
710 dev->netdev = netdev; in rtl8150_probe()
712 netdev->priv = dev; in rtl8150_probe()
723 dev->intr_interval = 100; /* 100ms */ in rtl8150_probe()
725 if (rtl8150_reset(dev) || !alloc_all_urbs(dev)) { in rtl8150_probe()
727 free_all_urbs(dev); in rtl8150_probe()
728 unregister_netdev(dev->netdev); in rtl8150_probe()
730 kfree(dev); in rtl8150_probe()
731 dev = NULL; in rtl8150_probe()
735 set_ethernet_addr(dev); in rtl8150_probe()
739 return dev; in rtl8150_probe()
744 rtl8150_t *dev; in rtl8150_disconnect() local
746 dev = ptr; in rtl8150_disconnect()
747 set_bit(RTL8150_UNPLUG, &dev->flags); in rtl8150_disconnect()
748 unregister_netdev(dev->netdev); in rtl8150_disconnect()
749 unlink_all_urbs(dev); in rtl8150_disconnect()
750 free_all_urbs(dev); in rtl8150_disconnect()
751 kfree(dev->netdev); in rtl8150_disconnect()
752 kfree(dev); in rtl8150_disconnect()
753 dev->netdev = NULL; in rtl8150_disconnect()
754 dev = NULL; in rtl8150_disconnect()