enic: devcmd for adding IP 5 tuple hardware filters
[cascardo/linux.git] / drivers / net / ethernet / cisco / enic / enic_clsf.c
1 #include <linux/if.h>
2 #include <linux/if_ether.h>
3 #include <linux/if_link.h>
4 #include <linux/netdevice.h>
5 #include <linux/in.h>
6 #include <linux/types.h>
7 #include <linux/skbuff.h>
8 #include <net/flow_keys.h>
9 #include "enic_res.h"
10 #include "enic_clsf.h"
11
12 /* enic_addfltr_5t - Add ipv4 5tuple filter
13  *      @enic: enic struct of vnic
14  *      @keys: flow_keys of ipv4 5tuple
15  *      @rq: rq number to steer to
16  *
17  * This function returns filter_id(hardware_id) of the filter
18  * added. In case of error it returns an negative number.
19  */
20 int enic_addfltr_5t(struct enic *enic, struct flow_keys *keys, u16 rq)
21 {
22         int res;
23         struct filter data;
24
25         switch (keys->ip_proto) {
26         case IPPROTO_TCP:
27                 data.u.ipv4.protocol = PROTO_TCP;
28                 break;
29         case IPPROTO_UDP:
30                 data.u.ipv4.protocol = PROTO_UDP;
31                 break;
32         default:
33                 return -EPROTONOSUPPORT;
34         };
35         data.type = FILTER_IPV4_5TUPLE;
36         data.u.ipv4.src_addr = ntohl(keys->src);
37         data.u.ipv4.dst_addr = ntohl(keys->dst);
38         data.u.ipv4.src_port = ntohs(keys->port16[0]);
39         data.u.ipv4.dst_port = ntohs(keys->port16[1]);
40         data.u.ipv4.flags = FILTER_FIELDS_IPV4_5TUPLE;
41
42         spin_lock_bh(&enic->devcmd_lock);
43         res = vnic_dev_classifier(enic->vdev, CLSF_ADD, &rq, &data);
44         spin_unlock_bh(&enic->devcmd_lock);
45         res = (res == 0) ? rq : res;
46
47         return res;
48 }
49
50 /* enic_delfltr - Delete clsf filter
51  *      @enic: enic struct of vnic
52  *      @filter_id: filter_is(hardware_id) of filter to be deleted
53  *
54  * This function returns zero in case of success, negative number incase of
55  * error.
56  */
57 int enic_delfltr(struct enic *enic, u16 filter_id)
58 {
59         int ret;
60
61         spin_lock_bh(&enic->devcmd_lock);
62         ret = vnic_dev_classifier(enic->vdev, CLSF_DEL, &filter_id, NULL);
63         spin_unlock_bh(&enic->devcmd_lock);
64
65         return ret;
66 }