cxgb4: add ethtool n-tuple filter deletion
[linux-2.6-microblaze.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_tc_flower.c
index 4a5fa9e..3ded4fe 100644 (file)
@@ -81,19 +81,9 @@ static struct ch_tc_flower_entry *ch_flower_lookup(struct adapter *adap,
 }
 
 static void cxgb4_process_flow_match(struct net_device *dev,
-                                    struct flow_cls_offload *cls,
+                                    struct flow_rule *rule,
                                     struct ch_filter_specification *fs)
 {
-       struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
-       u16 addr_type = 0;
-
-       if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
-               struct flow_match_control match;
-
-               flow_rule_match_control(rule, &match);
-               addr_type = match.key->addr_type;
-       }
-
        if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
                struct flow_match_basic match;
                u16 ethtype_key, ethtype_mask;
@@ -116,7 +106,7 @@ static void cxgb4_process_flow_match(struct net_device *dev,
                fs->mask.proto = match.mask->ip_proto;
        }
 
-       if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
+       if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
                struct flow_match_ipv4_addrs match;
 
                flow_rule_match_ipv4_addrs(rule, &match);
@@ -131,7 +121,7 @@ static void cxgb4_process_flow_match(struct net_device *dev,
                memcpy(&fs->nat_fip[0], &match.key->src, sizeof(match.key->src));
        }
 
-       if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
+       if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
                struct flow_match_ipv6_addrs match;
 
                flow_rule_match_ipv6_addrs(rule, &match);
@@ -224,9 +214,8 @@ static void cxgb4_process_flow_match(struct net_device *dev,
 }
 
 static int cxgb4_validate_flow_match(struct net_device *dev,
-                                    struct flow_cls_offload *cls)
+                                    struct flow_rule *rule)
 {
-       struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
        struct flow_dissector *dissector = rule->match.dissector;
        u16 ethtype_mask = 0;
        u16 ethtype_key = 0;
@@ -693,14 +682,11 @@ out_unlock:
        spin_unlock_bh(&t->ftid_lock);
 }
 
-int cxgb4_tc_flower_replace(struct net_device *dev,
-                           struct flow_cls_offload *cls)
+int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,
+                           u32 tc_prio, struct netlink_ext_ack *extack,
+                           struct ch_filter_specification *fs, u32 *tid)
 {
-       struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
-       struct netlink_ext_ack *extack = cls->common.extack;
        struct adapter *adap = netdev2adap(dev);
-       struct ch_tc_flower_entry *ch_flower;
-       struct ch_filter_specification *fs;
        struct filter_ctx ctx;
        u8 inet_family;
        int fidx, ret;
@@ -708,18 +694,10 @@ int cxgb4_tc_flower_replace(struct net_device *dev,
        if (cxgb4_validate_flow_actions(dev, &rule->action, extack))
                return -EOPNOTSUPP;
 
-       if (cxgb4_validate_flow_match(dev, cls))
+       if (cxgb4_validate_flow_match(dev, rule))
                return -EOPNOTSUPP;
 
-       ch_flower = allocate_flower_entry();
-       if (!ch_flower) {
-               netdev_err(dev, "%s: ch_flower alloc failed.\n", __func__);
-               return -ENOMEM;
-       }
-
-       fs = &ch_flower->fs;
-       fs->hitcnts = 1;
-       cxgb4_process_flow_match(dev, cls, fs);
+       cxgb4_process_flow_match(dev, rule, fs);
        cxgb4_process_flow_actions(dev, &rule->action, fs);
 
        fs->hash = is_filter_exact_match(adap, fs);
@@ -730,12 +708,11 @@ int cxgb4_tc_flower_replace(struct net_device *dev,
         * existing rules.
         */
        fidx = cxgb4_get_free_ftid(dev, inet_family, fs->hash,
-                                  cls->common.prio);
+                                  tc_prio);
        if (fidx < 0) {
                NL_SET_ERR_MSG_MOD(extack,
                                   "No free LETCAM index available");
-               ret = -ENOMEM;
-               goto free_entry;
+               return -ENOMEM;
        }
 
        if (fidx < adap->tids.nhpftids) {
@@ -749,42 +726,70 @@ int cxgb4_tc_flower_replace(struct net_device *dev,
        if (fs->hash)
                fidx = 0;
 
-       fs->tc_prio = cls->common.prio;
-       fs->tc_cookie = cls->cookie;
+       fs->tc_prio = tc_prio;
 
        init_completion(&ctx.completion);
        ret = __cxgb4_set_filter(dev, fidx, fs, &ctx);
        if (ret) {
                netdev_err(dev, "%s: filter creation err %d\n",
                           __func__, ret);
-               goto free_entry;
+               return ret;
        }
 
        /* Wait for reply */
        ret = wait_for_completion_timeout(&ctx.completion, 10 * HZ);
-       if (!ret) {
-               ret = -ETIMEDOUT;
-               goto free_entry;
-       }
+       if (!ret)
+               return -ETIMEDOUT;
 
-       ret = ctx.result;
        /* Check if hw returned error for filter creation */
+       if (ctx.result)
+               return ctx.result;
+
+       *tid = ctx.tid;
+
+       if (fs->hash)
+               cxgb4_tc_flower_hash_prio_add(adap, tc_prio);
+
+       return 0;
+}
+
+int cxgb4_tc_flower_replace(struct net_device *dev,
+                           struct flow_cls_offload *cls)
+{
+       struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
+       struct netlink_ext_ack *extack = cls->common.extack;
+       struct adapter *adap = netdev2adap(dev);
+       struct ch_tc_flower_entry *ch_flower;
+       struct ch_filter_specification *fs;
+       int ret;
+
+       ch_flower = allocate_flower_entry();
+       if (!ch_flower) {
+               netdev_err(dev, "%s: ch_flower alloc failed.\n", __func__);
+               return -ENOMEM;
+       }
+
+       fs = &ch_flower->fs;
+       fs->hitcnts = 1;
+       fs->tc_cookie = cls->cookie;
+
+       ret = cxgb4_flow_rule_replace(dev, rule, cls->common.prio, extack, fs,
+                                     &ch_flower->filter_id);
        if (ret)
                goto free_entry;
 
        ch_flower->tc_flower_cookie = cls->cookie;
-       ch_flower->filter_id = ctx.tid;
        ret = rhashtable_insert_fast(&adap->flower_tbl, &ch_flower->node,
                                     adap->flower_ht_params);
        if (ret)
                goto del_filter;
 
-       if (fs->hash)
-               cxgb4_tc_flower_hash_prio_add(adap, cls->common.prio);
-
        return 0;
 
 del_filter:
+       if (fs->hash)
+               cxgb4_tc_flower_hash_prio_del(adap, cls->common.prio);
+
        cxgb4_del_filter(dev, ch_flower->filter_id, &ch_flower->fs);
 
 free_entry:
@@ -792,23 +797,38 @@ free_entry:
        return ret;
 }
 
+int cxgb4_flow_rule_destroy(struct net_device *dev, u32 tc_prio,
+                           struct ch_filter_specification *fs, int tid)
+{
+       struct adapter *adap = netdev2adap(dev);
+       u8 hash;
+       int ret;
+
+       hash = fs->hash;
+
+       ret = cxgb4_del_filter(dev, tid, fs);
+       if (ret)
+               return ret;
+
+       if (hash)
+               cxgb4_tc_flower_hash_prio_del(adap, tc_prio);
+
+       return ret;
+}
+
 int cxgb4_tc_flower_destroy(struct net_device *dev,
                            struct flow_cls_offload *cls)
 {
        struct adapter *adap = netdev2adap(dev);
        struct ch_tc_flower_entry *ch_flower;
-       u32 tc_prio;
-       bool hash;
        int ret;
 
        ch_flower = ch_flower_lookup(adap, cls->cookie);
        if (!ch_flower)
                return -ENOENT;
 
-       hash = ch_flower->fs.hash;
-       tc_prio = ch_flower->fs.tc_prio;
-
-       ret = cxgb4_del_filter(dev, ch_flower->filter_id, &ch_flower->fs);
+       ret = cxgb4_flow_rule_destroy(dev, ch_flower->fs.tc_prio,
+                                     &ch_flower->fs, ch_flower->filter_id);
        if (ret)
                goto err;
 
@@ -820,9 +840,6 @@ int cxgb4_tc_flower_destroy(struct net_device *dev,
        }
        kfree_rcu(ch_flower, rcu);
 
-       if (hash)
-               cxgb4_tc_flower_hash_prio_del(adap, tc_prio);
-
 err:
        return ret;
 }
@@ -902,7 +919,7 @@ int cxgb4_tc_flower_stats(struct net_device *dev,
                if (ofld_stats->prev_packet_count != packets)
                        ofld_stats->last_used = jiffies;
                flow_stats_update(&cls->stats, bytes - ofld_stats->byte_count,
-                                 packets - ofld_stats->packet_count,
+                                 packets - ofld_stats->packet_count, 0,
                                  ofld_stats->last_used,
                                  FLOW_ACTION_HW_STATS_IMMEDIATE);