Commit 9dbfec80 authored by Petko Manolov's avatar Petko Manolov Committed by Greg Kroah-Hartman

[PATCH] pegasus & rtl8150

I chose a little bit more restrictive license for my drivers.
Rx skb pool introduced in pegasus driver and the pool locking in rtl8150
is refined.
parent 6c9a20c9
This diff is collapsed.
...@@ -2,18 +2,8 @@ ...@@ -2,18 +2,8 @@
* Copyright (c) 1999-2002 Petko Manolov - Petkan (petkan@users.sourceforge.net) * Copyright (c) 1999-2002 Petko Manolov - Petkan (petkan@users.sourceforge.net)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License version 2 as published
* the Free Software Foundation; either version 2 of the License, or * by the Free Software Foundation.
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
...@@ -23,6 +13,7 @@ ...@@ -23,6 +13,7 @@
#define HAS_HOME_PNA 0x40000000 #define HAS_HOME_PNA 0x40000000
#define PEGASUS_MTU 1536 #define PEGASUS_MTU 1536
#define RX_SKBS 4
#define EPROM_WRITE 0x01 #define EPROM_WRITE 0x01
#define EPROM_READ 0x02 #define EPROM_READ 0x02
...@@ -100,10 +91,12 @@ typedef struct pegasus { ...@@ -100,10 +91,12 @@ typedef struct pegasus {
int intr_interval; int intr_interval;
struct tasklet_struct rx_tl; struct tasklet_struct rx_tl;
struct urb *ctrl_urb, *rx_urb, *tx_urb, *intr_urb; struct urb *ctrl_urb, *rx_urb, *tx_urb, *intr_urb;
struct sk_buff *rx_pool[RX_SKBS];
struct sk_buff *rx_skb; struct sk_buff *rx_skb;
struct usb_ctrlrequest dr; struct usb_ctrlrequest dr;
wait_queue_head_t ctrl_wait; wait_queue_head_t ctrl_wait;
struct semaphore sem; struct semaphore sem;
spinlock_t rx_pool_lock;
unsigned char intr_buff[8]; unsigned char intr_buff[8];
__u8 tx_buff[PEGASUS_MTU]; __u8 tx_buff[PEGASUS_MTU];
__u8 eth_regs[4]; __u8 eth_regs[4];
......
/* /*
* Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net) * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/init.h>
#include <linux/signal.h> #include <linux/signal.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -19,7 +18,6 @@ ...@@ -19,7 +18,6 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/init.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
/* Version Information */ /* Version Information */
...@@ -106,7 +104,7 @@ unsigned long multicast_filter_limit = 32; ...@@ -106,7 +104,7 @@ unsigned long multicast_filter_limit = 32;
static void fill_skb_pool(rtl8150_t *); static void fill_skb_pool(rtl8150_t *);
static void free_skb_pool(rtl8150_t *); static void free_skb_pool(rtl8150_t *);
static struct sk_buff *pull_skb(rtl8150_t *); static inline struct sk_buff *pull_skb(rtl8150_t *);
static void rtl8150_disconnect(struct usb_device *dev, void *ptr); static void rtl8150_disconnect(struct usb_device *dev, void *ptr);
static void *rtl8150_probe(struct usb_device *dev, unsigned int ifnum, static void *rtl8150_probe(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id); const struct usb_device_id *id);
...@@ -312,7 +310,7 @@ static void read_bulk_callback(struct urb *urb) ...@@ -312,7 +310,7 @@ static void read_bulk_callback(struct urb *urb)
case -ENOENT: case -ENOENT:
return; /* the urb is in unlink state */ return; /* the urb is in unlink state */
case -ETIMEDOUT: case -ETIMEDOUT:
warn("reset needed may be?.."); warn("may be reset is needed?..");
goto goon; goto goon;
default: default:
warn("Rx status %d", urb->status); warn("Rx status %d", urb->status);
...@@ -331,13 +329,13 @@ static void read_bulk_callback(struct urb *urb) ...@@ -331,13 +329,13 @@ static void read_bulk_callback(struct urb *urb)
netif_rx(dev->rx_skb); netif_rx(dev->rx_skb);
dev->stats.rx_packets++; dev->stats.rx_packets++;
dev->stats.rx_bytes += pkt_len; dev->stats.rx_bytes += pkt_len;
spin_lock(&dev->rx_pool_lock);
skb = pull_skb(dev); skb = pull_skb(dev);
spin_unlock(&dev->rx_pool_lock);
if (!skb) if (!skb)
goto resched; goto resched;
skb->dev = netdev;
skb_reserve(skb, 2);
dev->rx_skb = skb; dev->rx_skb = skb;
goon: goon:
FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
...@@ -361,11 +359,16 @@ static void rx_fixup(unsigned long data) ...@@ -361,11 +359,16 @@ static void rx_fixup(unsigned long data)
dev = (rtl8150_t *)data; dev = (rtl8150_t *)data;
spin_lock_irq(&dev->rx_pool_lock);
fill_skb_pool(dev); fill_skb_pool(dev);
spin_unlock_irq(&dev->rx_pool_lock);
if (test_bit(RX_URB_FAIL, &dev->flags)) if (test_bit(RX_URB_FAIL, &dev->flags))
if (dev->rx_skb) if (dev->rx_skb)
goto try_again; goto try_again;
if (!(skb = pull_skb(dev))) spin_lock_irq(&dev->rx_pool_lock);
skb = pull_skb(dev);
spin_unlock_irq(&dev->rx_pool_lock);
if (skb == NULL)
goto tlsched; goto tlsched;
dev->rx_skb = skb; dev->rx_skb = skb;
FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), FILL_BULK_URB(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
...@@ -426,51 +429,41 @@ static void fill_skb_pool(rtl8150_t *dev) ...@@ -426,51 +429,41 @@ static void fill_skb_pool(rtl8150_t *dev)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int i; int i;
unsigned long flags;
spin_lock_irqsave(&dev->rx_pool_lock, flags);
for (i = 0; i < RX_SKB_POOL_SIZE; i++) { for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
if (dev->rx_skb_pool[i]) if (dev->rx_skb_pool[i])
continue; continue;
skb = dev_alloc_skb(RTL8150_MTU + 2); skb = dev_alloc_skb(RTL8150_MTU + 2);
if (!skb) { if (!skb) {
spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
return; return;
} }
skb->dev = dev->netdev; skb->dev = dev->netdev;
skb_reserve(skb, 2); skb_reserve(skb, 2);
dev->rx_skb_pool[i] = skb; dev->rx_skb_pool[i] = skb;
} }
spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
} }
static void free_skb_pool(rtl8150_t *dev) static void free_skb_pool(rtl8150_t *dev)
{ {
int i; int i;
spin_lock_irq(&dev->rx_pool_lock);
for (i = 0; i < RX_SKB_POOL_SIZE; i++) for (i = 0; i < RX_SKB_POOL_SIZE; i++)
if (dev->rx_skb_pool[i]) if (dev->rx_skb_pool[i])
dev_kfree_skb(dev->rx_skb_pool[i]); dev_kfree_skb(dev->rx_skb_pool[i]);
spin_unlock_irq(&dev->rx_pool_lock);
} }
static struct sk_buff *pull_skb(rtl8150_t *dev) static inline struct sk_buff *pull_skb(rtl8150_t *dev)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int i; int i;
unsigned long flags;
spin_lock_irqsave(&dev->rx_pool_lock, flags);
for (i = 0; i < RX_SKB_POOL_SIZE; i++) { for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
if (dev->rx_skb_pool[i]) { if (dev->rx_skb_pool[i]) {
skb = dev->rx_skb_pool[i]; skb = dev->rx_skb_pool[i];
dev->rx_skb_pool[i] = NULL; dev->rx_skb_pool[i] = NULL;
spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
return skb; return skb;
} }
} }
spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
return NULL; return NULL;
} }
...@@ -578,8 +571,8 @@ static int rtl8150_open(struct net_device *netdev) ...@@ -578,8 +571,8 @@ static int rtl8150_open(struct net_device *netdev)
if (dev == NULL) { if (dev == NULL) {
return -ENODEV; return -ENODEV;
} }
if (dev->rx_skb == NULL)
dev->rx_skb = pull_skb(dev); dev->rx_skb = pull_skb(dev);
if (!dev->rx_skb) if (!dev->rx_skb)
return -ENOMEM; return -ENOMEM;
...@@ -816,13 +809,13 @@ static void rtl8150_disconnect(struct usb_device *udev, void *ptr) ...@@ -816,13 +809,13 @@ static void rtl8150_disconnect(struct usb_device *udev, void *ptr)
dev = NULL; dev = NULL;
} }
static int __init usb_rtl8150_init(void) int __init usb_rtl8150_init(void)
{ {
info(DRIVER_DESC " " DRIVER_VERSION); info(DRIVER_DESC " " DRIVER_VERSION);
return usb_register(&rtl8150_driver); return usb_register(&rtl8150_driver);
} }
static void __exit usb_rtl8150_exit(void) void __exit usb_rtl8150_exit(void)
{ {
usb_deregister(&rtl8150_driver); usb_deregister(&rtl8150_driver);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment