Skip to content

Commit

Permalink
Merge branch 'cxgb4-tc-flower'
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
davem330 committed Sep 23, 2017
2 parents 52a59bd + e0f911c commit cddd952
Show file tree
Hide file tree
Showing 7 changed files with 653 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/net/ethernet/chelsio/cxgb4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

obj-$(CONFIG_CHELSIO_T4) += cxgb4.o

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
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 cxgb4_tc_flower.o
cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o
cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
4 changes: 4 additions & 0 deletions drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ struct adapter {
/* TC u32 offload */
struct cxgb4_tc_u32_table *tc_u32;
struct chcr_stats_debug chcr_stats;

/* TC flower offload */
DECLARE_HASHTABLE(flower_anymatch_tbl, 9);
struct timer_list flower_stats_timer;
};

/* Support for "sched-class" command to allow a TX Scheduling Class to be
Expand Down
100 changes: 100 additions & 0 deletions drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,106 @@ static int get_filter_steerq(struct net_device *dev,
return iq;
}

static int get_filter_count(struct adapter *adapter, unsigned int fidx,
u64 *pkts, u64 *bytes)
{
unsigned int tcb_base, tcbaddr;
unsigned int word_offset;
struct filter_entry *f;
__be64 be64_byte_count;
int ret;

tcb_base = t4_read_reg(adapter, TP_CMM_TCB_BASE_A);
if ((fidx != (adapter->tids.nftids + adapter->tids.nsftids - 1)) &&
fidx >= adapter->tids.nftids)
return -E2BIG;

f = &adapter->tids.ftid_tab[fidx];
if (!f->valid)
return -EINVAL;

tcbaddr = tcb_base + f->tid * TCB_SIZE;

spin_lock(&adapter->win0_lock);
if (is_t4(adapter->params.chip)) {
__be64 be64_count;

/* T4 doesn't maintain byte counts in hw */
*bytes = 0;

/* Get pkts */
word_offset = 4;
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
tcbaddr + (word_offset * sizeof(__be32)),
sizeof(be64_count),
(__be32 *)&be64_count,
T4_MEMORY_READ);
if (ret < 0)
goto out;
*pkts = be64_to_cpu(be64_count);
} else {
__be32 be32_count;

/* Get bytes */
word_offset = 4;
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
tcbaddr + (word_offset * sizeof(__be32)),
sizeof(be64_byte_count),
&be64_byte_count,
T4_MEMORY_READ);
if (ret < 0)
goto out;
*bytes = be64_to_cpu(be64_byte_count);

/* Get pkts */
word_offset = 6;
ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
tcbaddr + (word_offset * sizeof(__be32)),
sizeof(be32_count),
&be32_count,
T4_MEMORY_READ);
if (ret < 0)
goto out;
*pkts = (u64)be32_to_cpu(be32_count);
}

out:
spin_unlock(&adapter->win0_lock);
return ret;
}

int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
u64 *hitcnt, u64 *bytecnt)
{
struct adapter *adapter = netdev2adap(dev);

return get_filter_count(adapter, fidx, hitcnt, bytecnt);
}

int cxgb4_get_free_ftid(struct net_device *dev, int family)
{
struct adapter *adap = netdev2adap(dev);
struct tid_info *t = &adap->tids;
int ftid;

spin_lock_bh(&t->ftid_lock);
if (family == PF_INET) {
ftid = find_first_zero_bit(t->ftid_bmap, t->nftids);
if (ftid >= t->nftids)
ftid = -1;
} else {
ftid = bitmap_find_free_region(t->ftid_bmap, t->nftids, 2);
if (ftid < 0)
goto out_unlock;

/* this is only a lookup, keep the found region unallocated */
bitmap_release_region(t->ftid_bmap, ftid, 2);
}
out_unlock:
spin_unlock_bh(&t->ftid_lock);
return ftid;
}

static int cxgb4_set_ftid(struct tid_info *t, int fidx, int family)
{
spin_lock_bh(&t->ftid_lock);
Expand Down
25 changes: 25 additions & 0 deletions drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "l2t.h"
#include "sched.h"
#include "cxgb4_tc_u32.h"
#include "cxgb4_tc_flower.h"
#include "cxgb4_ptp.h"

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

static int cxgb_setup_tc_flower(struct net_device *dev,
struct tc_cls_flower_offload *cls_flower)
{
if (!is_classid_clsact_ingress(cls_flower->common.classid) ||
cls_flower->common.chain_index)
return -EOPNOTSUPP;

switch (cls_flower->command) {
case TC_CLSFLOWER_REPLACE:
return cxgb4_tc_flower_replace(dev, cls_flower);
case TC_CLSFLOWER_DESTROY:
return cxgb4_tc_flower_destroy(dev, cls_flower);
case TC_CLSFLOWER_STATS:
return cxgb4_tc_flower_stats(dev, cls_flower);
default:
return -EOPNOTSUPP;
}
}

static int cxgb_setup_tc_cls_u32(struct net_device *dev,
struct tc_cls_u32_offload *cls_u32)
{
Expand Down Expand Up @@ -2907,6 +2927,8 @@ static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
switch (type) {
case TC_SETUP_CLSU32:
return cxgb_setup_tc_cls_u32(dev, type_data);
case TC_SETUP_CLSFLOWER:
return cxgb_setup_tc_flower(dev, type_data);
default:
return -EOPNOTSUPP;
}
Expand Down Expand Up @@ -4615,6 +4637,7 @@ static void free_some_resources(struct adapter *adapter)
kvfree(adapter->l2t);
t4_cleanup_sched(adapter);
kvfree(adapter->tids.tid_tab);
cxgb4_cleanup_tc_flower(adapter);
cxgb4_cleanup_tc_u32(adapter);
kfree(adapter->sge.egr_map);
kfree(adapter->sge.ingr_map);
Expand Down Expand Up @@ -5083,6 +5106,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
if (!adapter->tc_u32)
dev_warn(&pdev->dev,
"could not offload tc u32, continuing\n");

cxgb4_init_tc_flower(adapter);
}

if (is_offload(adapter)) {
Expand Down
Loading

0 comments on commit cddd952

Please sign in to comment.