mmc: s3c6410: enable ADMA feature in 6410 sdhci controller
[safe/jmp/linux-2.6] / net / sched / sch_atm.c
index aaa32a2..fcbb86a 100644 (file)
@@ -3,6 +3,7 @@
 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/errno.h>
@@ -49,7 +50,7 @@ struct atm_flow_data {
        struct socket           *sock;          /* for closing */
        u32                     classid;        /* x:y type ID */
        int                     ref;            /* reference count */
-       struct gnet_stats_basic bstats;
+       struct gnet_stats_basic_packed  bstats;
        struct gnet_stats_queue qstats;
        struct atm_flow_data    *next;
        struct atm_flow_data    *excess;        /* flow for excess traffic;
@@ -62,7 +63,7 @@ struct atm_qdisc_data {
        struct atm_flow_data    link;           /* unclassified skbs go here */
        struct atm_flow_data    *flows;         /* NB: "link" is also on this
                                                   list */
-       struct tasklet_struct   task;           /* requeue tasklet */
+       struct tasklet_struct   task;           /* dequeue tasklet */
 };
 
 /* ------------------------- Class/flow operations ------------------------- */
@@ -102,7 +103,8 @@ static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
                return -EINVAL;
        if (!new)
                new = &noop_qdisc;
-       *old = xchg(&flow->q, new);
+       *old = flow->q;
+       flow->q = new;
        if (*old)
                qdisc_reset(*old);
        return 0;
@@ -160,9 +162,9 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
        *prev = flow->next;
        pr_debug("atm_tc_put: qdisc %p\n", flow->q);
        qdisc_destroy(flow->q);
-       tcf_destroy_chain(flow->filter_list);
+       tcf_destroy_chain(&flow->filter_list);
        if (flow->sock) {
-               pr_debug("atm_tc_put: f_count %d\n",
+               pr_debug("atm_tc_put: f_count %ld\n",
                        file_count(flow->sock->file));
                flow->vcc->pop = flow->old_pop;
                sockfd_put(flow->sock);
@@ -195,6 +197,11 @@ static const u8 llc_oui_ip[] = {
        0x08, 0x00
 };                             /* Ethertype IP (0800) */
 
+static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = {
+       [TCA_ATM_FD]            = { .type = NLA_U32 },
+       [TCA_ATM_EXCESS]        = { .type = NLA_U32 },
+};
+
 static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
                         struct nlattr **tca, unsigned long *arg)
 {
@@ -225,13 +232,14 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
                return -EBUSY;
        if (opt == NULL)
                return -EINVAL;
-       error = nla_parse_nested(tb, TCA_ATM_MAX, opt, NULL);
+
+       error = nla_parse_nested(tb, TCA_ATM_MAX, opt, atm_policy);
        if (error < 0)
                return error;
 
-       if (!tb[TCA_ATM_FD] || nla_len(tb[TCA_ATM_FD]) < sizeof(fd))
+       if (!tb[TCA_ATM_FD])
                return -EINVAL;
-       fd = *(int *)nla_data(tb[TCA_ATM_FD]);
+       fd = nla_get_u32(tb[TCA_ATM_FD]);
        pr_debug("atm_tc_change: fd %d\n", fd);
        if (tb[TCA_ATM_HDR]) {
                hdr_len = nla_len(tb[TCA_ATM_HDR]);
@@ -243,10 +251,8 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
        if (!tb[TCA_ATM_EXCESS])
                excess = NULL;
        else {
-               if (nla_len(tb[TCA_ATM_EXCESS]) != sizeof(u32))
-                       return -EINVAL;
                excess = (struct atm_flow_data *)
-                       atm_tc_get(sch, *(u32 *)nla_data(tb[TCA_ATM_EXCESS]));
+                       atm_tc_get(sch, nla_get_u32(tb[TCA_ATM_EXCESS]));
                if (!excess)
                        return -ENOENT;
        }
@@ -255,7 +261,7 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
        sock = sockfd_lookup(fd, &error);
        if (!sock)
                return error;   /* f_count++ */
-       pr_debug("atm_tc_change: f_count %d\n", file_count(sock->file));
+       pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file));
        if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
                error = -EPROTOTYPE;
                goto err_out;
@@ -292,7 +298,8 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
                goto err_out;
        }
        flow->filter_list = NULL;
-       flow->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid);
+       flow->q = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
+                                   &pfifo_qdisc_ops, classid);
        if (!flow->q)
                flow->q = &noop_qdisc;
        pr_debug("atm_tc_change: qdisc %p\n", flow->q);
@@ -410,7 +417,7 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
                case TC_ACT_QUEUED:
                case TC_ACT_STOLEN:
                        kfree_skb(skb);
-                       return NET_XMIT_SUCCESS;
+                       return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
                case TC_ACT_SHOT:
                        kfree_skb(skb);
                        goto drop;
@@ -424,17 +431,19 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 #endif
        }
 
-       ret = flow->q->enqueue(skb, flow->q);
+       ret = qdisc_enqueue(skb, flow->q);
        if (ret != 0) {
 drop: __maybe_unused
-               sch->qstats.drops++;
-               if (flow)
-                       flow->qstats.drops++;
+               if (net_xmit_drop_count(ret)) {
+                       sch->qstats.drops++;
+                       if (flow)
+                               flow->qstats.drops++;
+               }
                return ret;
        }
-       sch->bstats.bytes += skb->len;
+       sch->bstats.bytes += qdisc_pkt_len(skb);
        sch->bstats.packets++;
-       flow->bstats.bytes += skb->len;
+       flow->bstats.bytes += qdisc_pkt_len(skb);
        flow->bstats.packets++;
        /*
         * Okay, this may seem weird. We pretend we've dropped the packet if
@@ -450,7 +459,7 @@ drop: __maybe_unused
                return 0;
        }
        tasklet_schedule(&p->task);
-       return NET_XMIT_BYPASS;
+       return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
 }
 
 /*
@@ -473,11 +482,14 @@ static void sch_atm_dequeue(unsigned long data)
                 * If traffic is properly shaped, this won't generate nasty
                 * little bursts. Otherwise, it may ... (but that's okay)
                 */
-               while ((skb = flow->q->dequeue(flow->q))) {
-                       if (!atm_may_send(flow->vcc, skb->truesize)) {
-                               (void)flow->q->ops->requeue(skb, flow->q);
+               while ((skb = flow->q->ops->peek(flow->q))) {
+                       if (!atm_may_send(flow->vcc, skb->truesize))
                                break;
-                       }
+
+                       skb = qdisc_dequeue_peeked(flow->q);
+                       if (unlikely(!skb))
+                               break;
+
                        pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
                        /* remove any LL header somebody else has attached */
                        skb_pull(skb, skb_network_offset(skb));
@@ -509,27 +521,19 @@ static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
 
        pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
        tasklet_schedule(&p->task);
-       skb = p->link.q->dequeue(p->link.q);
+       skb = qdisc_dequeue_peeked(p->link.q);
        if (skb)
                sch->q.qlen--;
        return skb;
 }
 
-static int atm_tc_requeue(struct sk_buff *skb, struct Qdisc *sch)
+static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
 {
        struct atm_qdisc_data *p = qdisc_priv(sch);
-       int ret;
 
-       pr_debug("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
-       ret = p->link.q->ops->requeue(skb, p->link.q);
-       if (!ret) {
-               sch->q.qlen++;
-               sch->qstats.requeues++;
-       } else {
-               sch->qstats.drops++;
-               p->link.qstats.drops++;
-       }
-       return ret;
+       pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
+
+       return p->link.q->ops->peek(p->link.q);
 }
 
 static unsigned int atm_tc_drop(struct Qdisc *sch)
@@ -551,7 +555,8 @@ static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt)
 
        pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
        p->flows = &p->link;
-       p->link.q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, sch->handle);
+       p->link.q = qdisc_create_dflt(qdisc_dev(sch), sch->dev_queue,
+                                     &pfifo_qdisc_ops, sch->handle);
        if (!p->link.q)
                p->link.q = &noop_qdisc;
        pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
@@ -582,10 +587,11 @@ static void atm_tc_destroy(struct Qdisc *sch)
        struct atm_flow_data *flow;
 
        pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
+       for (flow = p->flows; flow; flow = flow->next)
+               tcf_destroy_chain(&flow->filter_list);
+
        /* races ? */
        while ((flow = p->flows)) {
-               tcf_destroy_chain(flow->filter_list);
-               flow->filter_list = NULL;
                if (flow->ref > 1)
                        printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow,
                               flow->ref);
@@ -605,8 +611,7 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
 {
        struct atm_qdisc_data *p = qdisc_priv(sch);
        struct atm_flow_data *flow = (struct atm_flow_data *)cl;
-       unsigned char *b = skb_tail_pointer(skb);
-       struct nlattr *nla;
+       struct nlattr *nest;
 
        pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
                sch, p, flow, skb, tcm);
@@ -614,8 +619,11 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
                return -EINVAL;
        tcm->tcm_handle = flow->classid;
        tcm->tcm_info = flow->q->handle;
-       nla = (struct nlattr *)b;
-       NLA_PUT(skb, TCA_OPTIONS, 0, NULL);
+
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
+
        NLA_PUT(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr);
        if (flow->vcc) {
                struct sockaddr_atmpvc pvc;
@@ -627,20 +635,19 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
                pvc.sap_addr.vci = flow->vcc->vci;
                NLA_PUT(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc);
                state = ATM_VF2VS(flow->vcc->flags);
-               NLA_PUT(skb, TCA_ATM_STATE, sizeof(state), &state);
+               NLA_PUT_U32(skb, TCA_ATM_STATE, state);
        }
        if (flow->excess)
-               NLA_PUT(skb, TCA_ATM_EXCESS, sizeof(u32), &flow->classid);
+               NLA_PUT_U32(skb, TCA_ATM_EXCESS, flow->classid);
        else {
-               static u32 zero;
-
-               NLA_PUT(skb, TCA_ATM_EXCESS, sizeof(zero), &zero);
+               NLA_PUT_U32(skb, TCA_ATM_EXCESS, 0);
        }
-       nla->nla_len = skb_tail_pointer(skb) - b;
+
+       nla_nest_end(skb, nest);
        return skb->len;
 
 nla_put_failure:
-       nlmsg_trim(skb, b);
+       nla_nest_cancel(skb, nest);
        return -1;
 }
 static int
@@ -684,7 +691,7 @@ static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
        .priv_size      = sizeof(struct atm_qdisc_data),
        .enqueue        = atm_tc_enqueue,
        .dequeue        = atm_tc_dequeue,
-       .requeue        = atm_tc_requeue,
+       .peek           = atm_tc_peek,
        .drop           = atm_tc_drop,
        .init           = atm_tc_init,
        .reset          = atm_tc_reset,