Skip to content

Commit cddd952

Browse files
committed
Merge branch 'cxgb4-tc-flower'
Rahul Lakkireddy says: ==================== cxgb4: add support to offload tc flower This series of patches add support to offload tc flower onto Chelsio NICs. Patch 1 adds basic skeleton to prepare for offloading tc flower flows. Patch 2 adds support to add/remove flows for offload. Flows can have accompanying masks. Following match and action are currently supported for offload: Match: ether-protocol, IPv4/IPv6 addresses, L4 ports (TCP/UDP) Action: drop, redirect to another port on the device. Patch 3 adds support to offload tc-flower flows having vlan actions: pop, push, and modify. Patch 4 adds support to fetch stats for the offloaded tc flower flows from hardware. Support for offloading more match and action types are to be followed in subsequent series. v2: - Setting ftid to -1 not required after bitmap_find_free_region in cxgb4_get_free_ftid. - Direct return can be used as jumping to error path is not needed if flower entry allocation failed in cxgb4_tc_flower_replace. Same applies if flower entry not found in cxgb4_tc_flower_destroy. - Also, removed an extra return from cxgb4_tc_flower_destroy. - Avoid wrapping line for netdev_err message. Also, use consistent error message string. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 52a59bd + e0f911c commit cddd952

File tree

7 files changed

+653
-1
lines changed

7 files changed

+653
-1
lines changed

drivers/net/ethernet/chelsio/cxgb4/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
obj-$(CONFIG_CHELSIO_T4) += cxgb4.o
66

7-
cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o cxgb4_uld.o sched.o cxgb4_filter.o cxgb4_tc_u32.o cxgb4_ptp.o
7+
cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o \
8+
cxgb4_uld.o sched.o cxgb4_filter.o cxgb4_tc_u32.o \
9+
cxgb4_ptp.o cxgb4_tc_flower.o
810
cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o
911
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o
1012
cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ struct adapter {
905905
/* TC u32 offload */
906906
struct cxgb4_tc_u32_table *tc_u32;
907907
struct chcr_stats_debug chcr_stats;
908+
909+
/* TC flower offload */
910+
DECLARE_HASHTABLE(flower_anymatch_tbl, 9);
911+
struct timer_list flower_stats_timer;
908912
};
909913

910914
/* Support for "sched-class" command to allow a TX Scheduling Class to be

drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,106 @@ static int get_filter_steerq(struct net_device *dev,
148148
return iq;
149149
}
150150

151+
static int get_filter_count(struct adapter *adapter, unsigned int fidx,
152+
u64 *pkts, u64 *bytes)
153+
{
154+
unsigned int tcb_base, tcbaddr;
155+
unsigned int word_offset;
156+
struct filter_entry *f;
157+
__be64 be64_byte_count;
158+
int ret;
159+
160+
tcb_base = t4_read_reg(adapter, TP_CMM_TCB_BASE_A);
161+
if ((fidx != (adapter->tids.nftids + adapter->tids.nsftids - 1)) &&
162+
fidx >= adapter->tids.nftids)
163+
return -E2BIG;
164+
165+
f = &adapter->tids.ftid_tab[fidx];
166+
if (!f->valid)
167+
return -EINVAL;
168+
169+
tcbaddr = tcb_base + f->tid * TCB_SIZE;
170+
171+
spin_lock(&adapter->win0_lock);
172+
if (is_t4(adapter->params.chip)) {
173+
__be64 be64_count;
174+
175+
/* T4 doesn't maintain byte counts in hw */
176+
*bytes = 0;
177+
178+
/* Get pkts */
179+
word_offset = 4;
180+
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
181+
tcbaddr + (word_offset * sizeof(__be32)),
182+
sizeof(be64_count),
183+
(__be32 *)&be64_count,
184+
T4_MEMORY_READ);
185+
if (ret < 0)
186+
goto out;
187+
*pkts = be64_to_cpu(be64_count);
188+
} else {
189+
__be32 be32_count;
190+
191+
/* Get bytes */
192+
word_offset = 4;
193+
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
194+
tcbaddr + (word_offset * sizeof(__be32)),
195+
sizeof(be64_byte_count),
196+
&be64_byte_count,
197+
T4_MEMORY_READ);
198+
if (ret < 0)
199+
goto out;
200+
*bytes = be64_to_cpu(be64_byte_count);
201+
202+
/* Get pkts */
203+
word_offset = 6;
204+
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
205+
tcbaddr + (word_offset * sizeof(__be32)),
206+
sizeof(be32_count),
207+
&be32_count,
208+
T4_MEMORY_READ);
209+
if (ret < 0)
210+
goto out;
211+
*pkts = (u64)be32_to_cpu(be32_count);
212+
}
213+
214+
out:
215+
spin_unlock(&adapter->win0_lock);
216+
return ret;
217+
}
218+
219+
int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
220+
u64 *hitcnt, u64 *bytecnt)
221+
{
222+
struct adapter *adapter = netdev2adap(dev);
223+
224+
return get_filter_count(adapter, fidx, hitcnt, bytecnt);
225+
}
226+
227+
int cxgb4_get_free_ftid(struct net_device *dev, int family)
228+
{
229+
struct adapter *adap = netdev2adap(dev);
230+
struct tid_info *t = &adap->tids;
231+
int ftid;
232+
233+
spin_lock_bh(&t->ftid_lock);
234+
if (family == PF_INET) {
235+
ftid = find_first_zero_bit(t->ftid_bmap, t->nftids);
236+
if (ftid >= t->nftids)
237+
ftid = -1;
238+
} else {
239+
ftid = bitmap_find_free_region(t->ftid_bmap, t->nftids, 2);
240+
if (ftid < 0)
241+
goto out_unlock;
242+
243+
/* this is only a lookup, keep the found region unallocated */
244+
bitmap_release_region(t->ftid_bmap, ftid, 2);
245+
}
246+
out_unlock:
247+
spin_unlock_bh(&t->ftid_lock);
248+
return ftid;
249+
}
250+
151251
static int cxgb4_set_ftid(struct tid_info *t, int fidx, int family)
152252
{
153253
spin_lock_bh(&t->ftid_lock);

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include "l2t.h"
8080
#include "sched.h"
8181
#include "cxgb4_tc_u32.h"
82+
#include "cxgb4_tc_flower.h"
8283
#include "cxgb4_ptp.h"
8384

8485
char cxgb4_driver_name[] = KBUILD_MODNAME;
@@ -2873,6 +2874,25 @@ static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
28732874
return err;
28742875
}
28752876

2877+
static int cxgb_setup_tc_flower(struct net_device *dev,
2878+
struct tc_cls_flower_offload *cls_flower)
2879+
{
2880+
if (!is_classid_clsact_ingress(cls_flower->common.classid) ||
2881+
cls_flower->common.chain_index)
2882+
return -EOPNOTSUPP;
2883+
2884+
switch (cls_flower->command) {
2885+
case TC_CLSFLOWER_REPLACE:
2886+
return cxgb4_tc_flower_replace(dev, cls_flower);
2887+
case TC_CLSFLOWER_DESTROY:
2888+
return cxgb4_tc_flower_destroy(dev, cls_flower);
2889+
case TC_CLSFLOWER_STATS:
2890+
return cxgb4_tc_flower_stats(dev, cls_flower);
2891+
default:
2892+
return -EOPNOTSUPP;
2893+
}
2894+
}
2895+
28762896
static int cxgb_setup_tc_cls_u32(struct net_device *dev,
28772897
struct tc_cls_u32_offload *cls_u32)
28782898
{
@@ -2907,6 +2927,8 @@ static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
29072927
switch (type) {
29082928
case TC_SETUP_CLSU32:
29092929
return cxgb_setup_tc_cls_u32(dev, type_data);
2930+
case TC_SETUP_CLSFLOWER:
2931+
return cxgb_setup_tc_flower(dev, type_data);
29102932
default:
29112933
return -EOPNOTSUPP;
29122934
}
@@ -4615,6 +4637,7 @@ static void free_some_resources(struct adapter *adapter)
46154637
kvfree(adapter->l2t);
46164638
t4_cleanup_sched(adapter);
46174639
kvfree(adapter->tids.tid_tab);
4640+
cxgb4_cleanup_tc_flower(adapter);
46184641
cxgb4_cleanup_tc_u32(adapter);
46194642
kfree(adapter->sge.egr_map);
46204643
kfree(adapter->sge.ingr_map);
@@ -5083,6 +5106,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
50835106
if (!adapter->tc_u32)
50845107
dev_warn(&pdev->dev,
50855108
"could not offload tc u32, continuing\n");
5109+
5110+
cxgb4_init_tc_flower(adapter);
50865111
}
50875112

50885113
if (is_offload(adapter)) {

0 commit comments

Comments
 (0)