]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wan/hdlc_fr.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6-omap-h63xx.git] / drivers / net / wan / hdlc_fr.c
index 071a64cacd5c29cdedfc959c922bea885a7a7cc2..62e93dac6b13b0ec91ebd72ea5d748faf7473fb3 100644 (file)
@@ -42,7 +42,6 @@
 #include <linux/init.h>
 #include <linux/skbuff.h>
 #include <linux/pkt_sched.h>
-#include <linux/random.h>
 #include <linux/inetdevice.h>
 #include <linux/lapb.h>
 #include <linux/rtnetlink.h>
@@ -136,7 +135,6 @@ typedef struct pvc_device_struct {
        }state;
 }pvc_device;
 
-
 struct frad_state {
        fr_proto settings;
        pvc_device *first_pvc;
@@ -171,18 +169,12 @@ static inline void dlci_to_q922(u8 *hdr, u16 dlci)
 }
 
 
-static inline struct frad_state * state(hdlc_device *hdlc)
+static inline struct frad_state* state(hdlc_device *hdlc)
 {
        return(struct frad_state *)(hdlc->state);
 }
 
 
-static __inline__ pvc_device* dev_to_pvc(struct net_device *dev)
-{
-       return dev->priv;
-}
-
-
 static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
 {
        pvc_device *pvc = state(hdlc)->first_pvc;
@@ -351,7 +343,7 @@ static int fr_hard_header(struct sk_buff **skb_p, u16 dlci)
 
 static int pvc_open(struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = dev->priv;
 
        if ((pvc->frad->flags & IFF_UP) == 0)
                return -EIO;  /* Frad must be UP in order to activate PVC */
@@ -371,7 +363,7 @@ static int pvc_open(struct net_device *dev)
 
 static int pvc_close(struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = dev->priv;
 
        if (--pvc->open_count == 0) {
                hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
@@ -390,7 +382,7 @@ static int pvc_close(struct net_device *dev)
 
 static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
+       pvc_device *pvc = dev->priv;
        fr_proto_pvc_info info;
 
        if (ifr->ifr_settings.type == IF_GET_PROTO) {
@@ -416,18 +408,9 @@ static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        return -EINVAL;
 }
 
-
-static inline struct net_device_stats *pvc_get_stats(struct net_device *dev)
-{
-       return &dev_to_desc(dev)->stats;
-}
-
-
-
 static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       pvc_device *pvc = dev_to_pvc(dev);
-       struct net_device_stats *stats = pvc_get_stats(dev);
+       pvc_device *pvc = dev->priv;
 
        if (pvc->state.active) {
                if (dev->type == ARPHRD_ETHER) {
@@ -437,7 +420,7 @@ static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
                                if (skb_tailroom(skb) < pad)
                                        if (pskb_expand_head(skb, 0, pad,
                                                             GFP_ATOMIC)) {
-                                               stats->tx_dropped++;
+                                               dev->stats.tx_dropped++;
                                                dev_kfree_skb(skb);
                                                return 0;
                                        }
@@ -447,17 +430,17 @@ static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
                        skb->protocol = __constant_htons(ETH_P_802_3);
                }
                if (!fr_hard_header(&skb, pvc->dlci)) {
-                       stats->tx_bytes += skb->len;
-                       stats->tx_packets++;
+                       dev->stats.tx_bytes += skb->len;
+                       dev->stats.tx_packets++;
                        if (pvc->state.fecn) /* TX Congestion counter */
-                               stats->tx_compressed++;
+                               dev->stats.tx_compressed++;
                        skb->dev = pvc->frad;
                        dev_queue_xmit(skb);
                        return 0;
                }
        }
 
-       stats->tx_dropped++;
+       dev->stats.tx_dropped++;
        dev_kfree_skb(skb);
        return 0;
 }
@@ -957,7 +940,7 @@ static int fr_rx(struct sk_buff *skb)
 
 
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
-               dev_to_desc(frad)->stats.rx_dropped++;
+               frad->stats.rx_dropped++;
                return NET_RX_DROP;
        }
 
@@ -1005,11 +988,11 @@ static int fr_rx(struct sk_buff *skb)
        }
 
        if (dev) {
-               struct net_device_stats *stats = pvc_get_stats(dev);
-               stats->rx_packets++; /* PVC traffic */
-               stats->rx_bytes += skb->len;
+               dev->stats.rx_packets++; /* PVC traffic */
+               dev->stats.rx_bytes += skb->len;
                if (pvc->state.becn)
-                       stats->rx_compressed++;
+                       dev->stats.rx_compressed++;
+               skb->dev = dev;
                netif_rx(skb);
                return NET_RX_SUCCESS;
        } else {
@@ -1018,7 +1001,7 @@ static int fr_rx(struct sk_buff *skb)
        }
 
  rx_error:
-       dev_to_desc(frad)->stats.rx_errors++; /* Mark error */
+       frad->stats.rx_errors++; /* Mark error */
        dev_kfree_skb_any(skb);
        return NET_RX_DROP;
 }
@@ -1089,13 +1072,9 @@ static void pvc_setup(struct net_device *dev)
 static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
 {
        hdlc_device *hdlc = dev_to_hdlc(frad);
-       pvc_device *pvc = NULL;
+       pvc_device *pvc;
        struct net_device *dev;
        int result, used;
-       char * prefix = "pvc%d";
-
-       if (type == ARPHRD_ETHER)
-               prefix = "pvceth%d";
 
        if ((pvc = add_pvc(frad, dlci)) == NULL) {
                printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
@@ -1109,11 +1088,9 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
        used = pvc_is_used(pvc);
 
        if (type == ARPHRD_ETHER)
-               dev = alloc_netdev(sizeof(struct net_device_stats),
-                                  "pvceth%d", ether_setup);
+               dev = alloc_netdev(0, "pvceth%d", ether_setup);
        else
-               dev = alloc_netdev(sizeof(struct net_device_stats),
-                                  "pvc%d", pvc_setup);
+               dev = alloc_netdev(0, "pvc%d", pvc_setup);
 
        if (!dev) {
                printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
@@ -1122,15 +1099,13 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
                return -ENOBUFS;
        }
 
-       if (type == ARPHRD_ETHER) {
-               memcpy(dev->dev_addr, "\x00\x01", 2);
-                get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2);
-       } else {
+       if (type == ARPHRD_ETHER)
+               random_ether_addr(dev->dev_addr);
+       else {
                *(__be16*)dev->dev_addr = htons(dlci);
                dlci_to_q922(dev->broadcast, dlci);
        }
        dev->hard_start_xmit = pvc_xmit;
-       dev->get_stats = pvc_get_stats;
        dev->open = pvc_open;
        dev->stop = pvc_close;
        dev->do_ioctl = pvc_ioctl;
@@ -1219,6 +1194,7 @@ static struct hdlc_proto proto = {
        .stop           = fr_stop,
        .detach         = fr_destroy,
        .ioctl          = fr_ioctl,
+       .netif_rx       = fr_rx,
        .module         = THIS_MODULE,
 };
 
@@ -1277,7 +1253,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
                        return result;
 
                if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
-                       result = attach_hdlc_protocol(dev, &proto, fr_rx,
+                       result = attach_hdlc_protocol(dev, &proto,
                                                      sizeof(struct frad_state));
                        if (result)
                                return result;