Commit 47c0b580 authored by David S. Miller's avatar David S. Miller

Merge branch 'Introduce-a-flow-gate-control-action-and-apply-IEEE'

Po Liu says:

====================
Introduce a flow gate control action and apply IEEE

Changes from V4:
----------------
0001:
Fix and modify according to Vlid Buslov suggestions:
- Change spin_lock_bh() to spin_lock() since tcf_gate_act() already in
software irq.
- Remove spin lock protect in the ops->cleanup function.
- Enable the CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING checking,
then fix as kzalloc flag type and lock deadlock.
- Change kzalloc() flag type from GFP_KERNEL to GFP_ATOMIC since
function in the spin_lock protect.
- Change hrtimer type from HRTIMER_MODE_ABS to HRTIMER_MODE_ABS_SOFT
to avoid deadlock.

0002:
Fix and modify according to Vlid Buslov suggestions:
- Remove all rcu_read_lock protection since no rcu parameters.
- Enable the CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING checking,
then check kzalloc sleeping flag.
- Change kzalloc to kcalloc for array memory alloc and change GFP_KERNEL
flag to GFP_ATOMIC since function holding spin_lock protect.

0003:
- No changes.

0004:
- Commit comments rephrase act by Claudiu Manoil.

Changes from V3:
----------------
0001:

Fix and modify according to Vlid Buslov:
- Remove the struct gate_action and move the parameters to the
struct tcf_gate align with tc_action parameters. This would not need to
alloc rcu type memory with pointer.
- Remove the spin_lock type entry_lock which do not needed anymore, will
use the tcf_lock system provided.
- Provide lockep protect for the status parameters in the tcf_gate_act().
- Remove the cycletime 0 input warning, return error directly.

And:
- Remove Qci related description in the Kconfig for gate action.

0002:
- Fix rcu_read_lock protect range suggested by Vlid Buslov.

0003:
- No changes.

0004:
- Fix bug of gate maxoct wildcard condition not included.
- Fix the pass time basetime calculation report by Vladimir Otlean.

Changes from V2:
0001: No changes.
0002: No changes.
0003: No changes.
0004: Fix the vlan id filter parameter and add reject src mac
FF-FF-FF-FF-FF-FF filter in driver.

Changes from V1:
----------------
0000: Update description make it more clear
0001: Removed 'add update dropped stats' patch, will provide pull
request as standalone patches.
0001: Update commit description make it more clear ack by Jiri Pirko.
0002: No changes
0003: Fix some code style ack by Jiri Pirko.
0004: Fix enetc_psfp_enable/disable parameter type ack by test robot

iprout2 command patches:
  Not attach with these serial patches, will provide separate pull
request after kernel accept these patches.

Changes from RFC:
-----------------
0000: Reduce to 5 patches and remove the 4 max frame size offload and
flow metering in the policing offload action, Only keep gate action
offloading implementation.
0001: No changes.
0002:
 - fix kfree lead ack by Jakub Kicinski and Cong Wang
 - License fix from Jakub Kicinski and Stephen Hemminger
 - Update example in commit acked by Vinicius Costa Gomes
 - Fix the rcu protect in tcf_gate_act() acked by Vinicius

0003: No changes
0004: No changes
0005:
 Acked by Vinicius Costa Gomes
 - Use refcount kernel lib
 - Update stream gate check code position
 - Update reduce ref names more clear

iprout2 command patches:
0000: Update license expression and add gate id
0001: Add tc action gate man page

--------------------------------------------------------------------
These patches add stream gate action policing in IEEE802.1Qci (Per-Stream
Filtering and Policing) software support and hardware offload support in
tc flower, and implement the stream identify, stream filtering and
stream gate filtering action in the NXP ENETC ethernet driver.
Per-Stream Filtering and Policing (PSFP) specifies flow policing and
filtering for ingress flows, and has three main parts:
 1. The stream filter instance table consists of an ordered list of
stream filters that determine the filtering and policing actions that
are to be applied to frames received on a specific stream. The main
elements are stream gate id, flow metering id and maximum SDU size.
 2. The stream gate function setup a gate list to control ingress traffic
class open/close state. When the gate is running at open state, the flow
could pass but dropped when gate state is running to close. User setup a
bastime to tell gate when start running the entry list, then the hardware
would periodiclly. There is no compare qdisc action support.
 3. Flow metering is two rates two buckets and three-color marker to
policing the frames. Flow metering instance are as specified in the
algorithm in MEF10.3. The most likely qdisc action is policing action.

The first patch introduces an ingress frame flow control gate action,
for the point 2. The tc gate action maintains the open/close state gate
list, allowing flows to pass when the gate is open. Each gate action
may policing one or more qdisc filters. When the start time arrived, The
driver would repeat the gate list periodiclly. User can assign a passed
time, the driver would calculate a new future time by the cycletime of
the gate list.

The 0002 patch introduces the gate flow hardware offloading.

The 0003 patch adds support control the on/off for the tc flower
offloading by ethtool.

The 0004 patch implement the stream identify and stream filtering and
stream gate filtering action in the NXP ENETC ethernet driver. Tc filter
command provide filtering keys with MAC address and VLAN id. These keys
would be set to stream identify instance entry. Stream gate instance
entry would refer the gate action parameters. Stream filter instance
entry would refer the stream gate index and assign a stream handle value
matches to the stream identify instance.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents eb236c29 888ae5a3
...@@ -756,6 +756,9 @@ void enetc_get_si_caps(struct enetc_si *si) ...@@ -756,6 +756,9 @@ void enetc_get_si_caps(struct enetc_si *si)
if (val & ENETC_SIPCAPR0_QBV) if (val & ENETC_SIPCAPR0_QBV)
si->hw_features |= ENETC_SI_F_QBV; si->hw_features |= ENETC_SI_F_QBV;
if (val & ENETC_SIPCAPR0_PSFP)
si->hw_features |= ENETC_SI_F_PSFP;
} }
static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size) static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size)
...@@ -1518,6 +1521,8 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type, ...@@ -1518,6 +1521,8 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type,
return enetc_setup_tc_cbs(ndev, type_data); return enetc_setup_tc_cbs(ndev, type_data);
case TC_SETUP_QDISC_ETF: case TC_SETUP_QDISC_ETF:
return enetc_setup_tc_txtime(ndev, type_data); return enetc_setup_tc_txtime(ndev, type_data);
case TC_SETUP_BLOCK:
return enetc_setup_tc_psfp(ndev, type_data);
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1567,15 +1572,42 @@ static int enetc_set_rss(struct net_device *ndev, int en) ...@@ -1567,15 +1572,42 @@ static int enetc_set_rss(struct net_device *ndev, int en)
return 0; return 0;
} }
static int enetc_set_psfp(struct net_device *ndev, int en)
{
struct enetc_ndev_priv *priv = netdev_priv(ndev);
int err;
if (en) {
err = enetc_psfp_enable(priv);
if (err)
return err;
priv->active_offloads |= ENETC_F_QCI;
return 0;
}
err = enetc_psfp_disable(priv);
if (err)
return err;
priv->active_offloads &= ~ENETC_F_QCI;
return 0;
}
int enetc_set_features(struct net_device *ndev, int enetc_set_features(struct net_device *ndev,
netdev_features_t features) netdev_features_t features)
{ {
netdev_features_t changed = ndev->features ^ features; netdev_features_t changed = ndev->features ^ features;
int err = 0;
if (changed & NETIF_F_RXHASH) if (changed & NETIF_F_RXHASH)
enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH)); enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
return 0; if (changed & NETIF_F_HW_TC)
err = enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
return err;
} }
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK #ifdef CONFIG_FSL_ENETC_PTP_CLOCK
......
...@@ -151,6 +151,7 @@ enum enetc_errata { ...@@ -151,6 +151,7 @@ enum enetc_errata {
}; };
#define ENETC_SI_F_QBV BIT(0) #define ENETC_SI_F_QBV BIT(0)
#define ENETC_SI_F_PSFP BIT(1)
/* PCI IEP device data */ /* PCI IEP device data */
struct enetc_si { struct enetc_si {
...@@ -203,12 +204,20 @@ struct enetc_cls_rule { ...@@ -203,12 +204,20 @@ struct enetc_cls_rule {
}; };
#define ENETC_MAX_BDR_INT 2 /* fixed to max # of available cpus */ #define ENETC_MAX_BDR_INT 2 /* fixed to max # of available cpus */
struct psfp_cap {
u32 max_streamid;
u32 max_psfp_filter;
u32 max_psfp_gate;
u32 max_psfp_gatelist;
u32 max_psfp_meter;
};
/* TODO: more hardware offloads */ /* TODO: more hardware offloads */
enum enetc_active_offloads { enum enetc_active_offloads {
ENETC_F_RX_TSTAMP = BIT(0), ENETC_F_RX_TSTAMP = BIT(0),
ENETC_F_TX_TSTAMP = BIT(1), ENETC_F_TX_TSTAMP = BIT(1),
ENETC_F_QBV = BIT(2), ENETC_F_QBV = BIT(2),
ENETC_F_QCI = BIT(3),
}; };
struct enetc_ndev_priv { struct enetc_ndev_priv {
...@@ -231,6 +240,8 @@ struct enetc_ndev_priv { ...@@ -231,6 +240,8 @@ struct enetc_ndev_priv {
struct enetc_cls_rule *cls_rules; struct enetc_cls_rule *cls_rules;
struct psfp_cap psfp_cap;
struct device_node *phy_node; struct device_node *phy_node;
phy_interface_t if_mode; phy_interface_t if_mode;
}; };
...@@ -289,9 +300,84 @@ int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data); ...@@ -289,9 +300,84 @@ int enetc_setup_tc_taprio(struct net_device *ndev, void *type_data);
void enetc_sched_speed_set(struct net_device *ndev); void enetc_sched_speed_set(struct net_device *ndev);
int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data); int enetc_setup_tc_cbs(struct net_device *ndev, void *type_data);
int enetc_setup_tc_txtime(struct net_device *ndev, void *type_data); int enetc_setup_tc_txtime(struct net_device *ndev, void *type_data);
int enetc_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
void *cb_priv);
int enetc_setup_tc_psfp(struct net_device *ndev, void *type_data);
int enetc_psfp_init(struct enetc_ndev_priv *priv);
int enetc_psfp_clean(struct enetc_ndev_priv *priv);
static inline void enetc_get_max_cap(struct enetc_ndev_priv *priv)
{
u32 reg;
reg = enetc_port_rd(&priv->si->hw, ENETC_PSIDCAPR);
priv->psfp_cap.max_streamid = reg & ENETC_PSIDCAPR_MSK;
/* Port stream filter capability */
reg = enetc_port_rd(&priv->si->hw, ENETC_PSFCAPR);
priv->psfp_cap.max_psfp_filter = reg & ENETC_PSFCAPR_MSK;
/* Port stream gate capability */
reg = enetc_port_rd(&priv->si->hw, ENETC_PSGCAPR);
priv->psfp_cap.max_psfp_gate = (reg & ENETC_PSGCAPR_SGIT_MSK);
priv->psfp_cap.max_psfp_gatelist = (reg & ENETC_PSGCAPR_GCL_MSK) >> 16;
/* Port flow meter capability */
reg = enetc_port_rd(&priv->si->hw, ENETC_PFMCAPR);
priv->psfp_cap.max_psfp_meter = reg & ENETC_PFMCAPR_MSK;
}
static inline int enetc_psfp_enable(struct enetc_ndev_priv *priv)
{
struct enetc_hw *hw = &priv->si->hw;
int err;
enetc_get_max_cap(priv);
err = enetc_psfp_init(priv);
if (err)
return err;
enetc_wr(hw, ENETC_PPSFPMR, enetc_rd(hw, ENETC_PPSFPMR) |
ENETC_PPSFPMR_PSFPEN | ENETC_PPSFPMR_VS |
ENETC_PPSFPMR_PVC | ENETC_PPSFPMR_PVZC);
return 0;
}
static inline int enetc_psfp_disable(struct enetc_ndev_priv *priv)
{
struct enetc_hw *hw = &priv->si->hw;
int err;
err = enetc_psfp_clean(priv);
if (err)
return err;
enetc_wr(hw, ENETC_PPSFPMR, enetc_rd(hw, ENETC_PPSFPMR) &
~ENETC_PPSFPMR_PSFPEN & ~ENETC_PPSFPMR_VS &
~ENETC_PPSFPMR_PVC & ~ENETC_PPSFPMR_PVZC);
memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
return 0;
}
#else #else
#define enetc_setup_tc_taprio(ndev, type_data) -EOPNOTSUPP #define enetc_setup_tc_taprio(ndev, type_data) -EOPNOTSUPP
#define enetc_sched_speed_set(ndev) (void)0 #define enetc_sched_speed_set(ndev) (void)0
#define enetc_setup_tc_cbs(ndev, type_data) -EOPNOTSUPP #define enetc_setup_tc_cbs(ndev, type_data) -EOPNOTSUPP
#define enetc_setup_tc_txtime(ndev, type_data) -EOPNOTSUPP #define enetc_setup_tc_txtime(ndev, type_data) -EOPNOTSUPP
#define enetc_setup_tc_psfp(ndev, type_data) -EOPNOTSUPP
#define enetc_setup_tc_block_cb NULL
#define enetc_get_max_cap(p) \
memset(&((p)->psfp_cap), 0, sizeof(struct psfp_cap))
static inline int enetc_psfp_enable(struct enetc_ndev_priv *priv)
{
return 0;
}
static inline int enetc_psfp_disable(struct enetc_ndev_priv *priv)
{
return 0;
}
#endif #endif
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define ENETC_SICTR1 0x1c #define ENETC_SICTR1 0x1c
#define ENETC_SIPCAPR0 0x20 #define ENETC_SIPCAPR0 0x20
#define ENETC_SIPCAPR0_QBV BIT(4) #define ENETC_SIPCAPR0_QBV BIT(4)
#define ENETC_SIPCAPR0_PSFP BIT(9)
#define ENETC_SIPCAPR0_RSS BIT(8) #define ENETC_SIPCAPR0_RSS BIT(8)
#define ENETC_SIPCAPR1 0x24 #define ENETC_SIPCAPR1 0x24
#define ENETC_SITGTGR 0x30 #define ENETC_SITGTGR 0x30
...@@ -228,6 +229,15 @@ enum enetc_bdr_type {TX, RX}; ...@@ -228,6 +229,15 @@ enum enetc_bdr_type {TX, RX};
#define ENETC_PM0_IFM_RLP (BIT(5) | BIT(11)) #define ENETC_PM0_IFM_RLP (BIT(5) | BIT(11))
#define ENETC_PM0_IFM_RGAUTO (BIT(15) | ENETC_PMO_IFM_RG | BIT(1)) #define ENETC_PM0_IFM_RGAUTO (BIT(15) | ENETC_PMO_IFM_RG | BIT(1))
#define ENETC_PM0_IFM_XGMII BIT(12) #define ENETC_PM0_IFM_XGMII BIT(12)
#define ENETC_PSIDCAPR 0x1b08
#define ENETC_PSIDCAPR_MSK GENMASK(15, 0)
#define ENETC_PSFCAPR 0x1b18
#define ENETC_PSFCAPR_MSK GENMASK(15, 0)
#define ENETC_PSGCAPR 0x1b28
#define ENETC_PSGCAPR_GCL_MSK GENMASK(18, 16)
#define ENETC_PSGCAPR_SGIT_MSK GENMASK(15, 0)
#define ENETC_PFMCAPR 0x1b38
#define ENETC_PFMCAPR_MSK GENMASK(15, 0)
/* MAC counters */ /* MAC counters */
#define ENETC_PM0_REOCT 0x8100 #define ENETC_PM0_REOCT 0x8100
...@@ -557,6 +567,9 @@ enum bdcr_cmd_class { ...@@ -557,6 +567,9 @@ enum bdcr_cmd_class {
BDCR_CMD_RFS, BDCR_CMD_RFS,
BDCR_CMD_PORT_GCL, BDCR_CMD_PORT_GCL,
BDCR_CMD_RECV_CLASSIFIER, BDCR_CMD_RECV_CLASSIFIER,
BDCR_CMD_STREAM_IDENTIFY,
BDCR_CMD_STREAM_FILTER,
BDCR_CMD_STREAM_GCL,
__BDCR_CMD_MAX_LEN, __BDCR_CMD_MAX_LEN,
BDCR_CMD_MAX_LEN = __BDCR_CMD_MAX_LEN - 1, BDCR_CMD_MAX_LEN = __BDCR_CMD_MAX_LEN - 1,
}; };
...@@ -588,13 +601,152 @@ struct tgs_gcl_data { ...@@ -588,13 +601,152 @@ struct tgs_gcl_data {
struct gce entry[]; struct gce entry[];
}; };
/* class 7, command 0, Stream Identity Entry Configuration */
struct streamid_conf {
__le32 stream_handle; /* init gate value */
__le32 iports;
u8 id_type;
u8 oui[3];
u8 res[3];
u8 en;
};
#define ENETC_CBDR_SID_VID_MASK 0xfff
#define ENETC_CBDR_SID_VIDM BIT(12)
#define ENETC_CBDR_SID_TG_MASK 0xc000
/* streamid_conf address point to this data space */
struct streamid_data {
union {
u8 dmac[6];
u8 smac[6];
};
u16 vid_vidm_tg;
};
#define ENETC_CBDR_SFI_PRI_MASK 0x7
#define ENETC_CBDR_SFI_PRIM BIT(3)
#define ENETC_CBDR_SFI_BLOV BIT(4)
#define ENETC_CBDR_SFI_BLEN BIT(5)
#define ENETC_CBDR_SFI_MSDUEN BIT(6)
#define ENETC_CBDR_SFI_FMITEN BIT(7)
#define ENETC_CBDR_SFI_ENABLE BIT(7)
/* class 8, command 0, Stream Filter Instance, Short Format */
struct sfi_conf {
__le32 stream_handle;
u8 multi;
u8 res[2];
u8 sthm;
/* Max Service Data Unit or Flow Meter Instance Table index.
* Depending on the value of FLT this represents either Max
* Service Data Unit (max frame size) allowed by the filter
* entry or is an index into the Flow Meter Instance table
* index identifying the policer which will be used to police
* it.
*/
__le16 fm_inst_table_index;
__le16 msdu;
__le16 sg_inst_table_index;
u8 res1[2];
__le32 input_ports;
u8 res2[3];
u8 en;
};
/* class 8, command 2 stream Filter Instance status query short format
* command no need structure define
* Stream Filter Instance Query Statistics Response data
*/
struct sfi_counter_data {
u32 matchl;
u32 matchh;
u32 msdu_dropl;
u32 msdu_droph;
u32 stream_gate_dropl;
u32 stream_gate_droph;
u32 flow_meter_dropl;
u32 flow_meter_droph;
};
#define ENETC_CBDR_SGI_OIPV_MASK 0x7
#define ENETC_CBDR_SGI_OIPV_EN BIT(3)
#define ENETC_CBDR_SGI_CGTST BIT(6)
#define ENETC_CBDR_SGI_OGTST BIT(7)
#define ENETC_CBDR_SGI_CFG_CHG BIT(1)
#define ENETC_CBDR_SGI_CFG_PND BIT(2)
#define ENETC_CBDR_SGI_OEX BIT(4)
#define ENETC_CBDR_SGI_OEXEN BIT(5)
#define ENETC_CBDR_SGI_IRX BIT(6)
#define ENETC_CBDR_SGI_IRXEN BIT(7)
#define ENETC_CBDR_SGI_ACLLEN_MASK 0x3
#define ENETC_CBDR_SGI_OCLLEN_MASK 0xc
#define ENETC_CBDR_SGI_EN BIT(7)
/* class 9, command 0, Stream Gate Instance Table, Short Format
* class 9, command 2, Stream Gate Instance Table entry query write back
* Short Format
*/
struct sgi_table {
u8 res[8];
u8 oipv;
u8 res0[2];
u8 ocgtst;
u8 res1[7];
u8 gset;
u8 oacl_len;
u8 res2[2];
u8 en;
};
#define ENETC_CBDR_SGI_AIPV_MASK 0x7
#define ENETC_CBDR_SGI_AIPV_EN BIT(3)
#define ENETC_CBDR_SGI_AGTST BIT(7)
/* class 9, command 1, Stream Gate Control List, Long Format */
struct sgcl_conf {
u8 aipv;
u8 res[2];
u8 agtst;
u8 res1[4];
union {
struct {
u8 res2[4];
u8 acl_len;
u8 res3[3];
};
u8 cct[8]; /* Config change time */
};
};
#define ENETC_CBDR_SGL_IOMEN BIT(0)
#define ENETC_CBDR_SGL_IPVEN BIT(3)
#define ENETC_CBDR_SGL_GTST BIT(4)
#define ENETC_CBDR_SGL_IPV_MASK 0xe
/* Stream Gate Control List Entry */
struct sgce {
u32 interval;
u8 msdu[3];
u8 multi;
};
/* stream control list class 9 , cmd 1 data buffer */
struct sgcl_data {
u32 btl;
u32 bth;
u32 ct;
u32 cte;
struct sgce sgcl[0];
};
struct enetc_cbd { struct enetc_cbd {
union{ union{
struct sfi_conf sfi_conf;
struct sgi_table sgi_table;
struct { struct {
__le32 addr[2]; __le32 addr[2];
union { union {
__le32 opt[4]; __le32 opt[4];
struct tgs_gcl_conf gcl_conf; struct tgs_gcl_conf gcl_conf;
struct streamid_conf sid_set;
struct sgcl_conf sgcl_conf;
}; };
}; /* Long format */ }; /* Long format */
__le32 data[6]; __le32 data[6];
...@@ -621,3 +773,10 @@ struct enetc_cbd { ...@@ -621,3 +773,10 @@ struct enetc_cbd {
/* Port time specific departure */ /* Port time specific departure */
#define ENETC_PTCTSDR(n) (0x1210 + 4 * (n)) #define ENETC_PTCTSDR(n) (0x1210 + 4 * (n))
#define ENETC_TSDE BIT(31) #define ENETC_TSDE BIT(31)
/* PSFP setting */
#define ENETC_PPSFPMR 0x11b00
#define ENETC_PPSFPMR_PSFPEN BIT(0)
#define ENETC_PPSFPMR_VS BIT(1)
#define ENETC_PPSFPMR_PVC BIT(2)
#define ENETC_PPSFPMR_PVZC BIT(3)
...@@ -727,6 +727,12 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ...@@ -727,6 +727,12 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
if (si->hw_features & ENETC_SI_F_QBV) if (si->hw_features & ENETC_SI_F_QBV)
priv->active_offloads |= ENETC_F_QBV; priv->active_offloads |= ENETC_F_QBV;
if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
priv->active_offloads |= ENETC_F_QCI;
ndev->features |= NETIF_F_HW_TC;
ndev->hw_features |= NETIF_F_HW_TC;
}
/* pick up primary MAC address from SI */ /* pick up primary MAC address from SI */
enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr); enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
} }
......
...@@ -147,6 +147,7 @@ enum flow_action_id { ...@@ -147,6 +147,7 @@ enum flow_action_id {
FLOW_ACTION_MPLS_PUSH, FLOW_ACTION_MPLS_PUSH,
FLOW_ACTION_MPLS_POP, FLOW_ACTION_MPLS_POP,
FLOW_ACTION_MPLS_MANGLE, FLOW_ACTION_MPLS_MANGLE,
FLOW_ACTION_GATE,
NUM_FLOW_ACTIONS, NUM_FLOW_ACTIONS,
}; };
...@@ -255,6 +256,15 @@ struct flow_action_entry { ...@@ -255,6 +256,15 @@ struct flow_action_entry {
u8 bos; u8 bos;
u8 ttl; u8 ttl;
} mpls_mangle; } mpls_mangle;
struct {
u32 index;
s32 prio;
u64 basetime;
u64 cycletime;
u64 cycletimeext;
u32 num_entries;
struct action_gate_entry *entries;
} gate;
}; };
struct flow_action_cookie *cookie; /* user defined action cookie */ struct flow_action_cookie *cookie; /* user defined action cookie */
}; };
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Copyright 2020 NXP */
#ifndef __NET_TC_GATE_H
#define __NET_TC_GATE_H
#include <net/act_api.h>
#include <linux/tc_act/tc_gate.h>
struct action_gate_entry {
u8 gate_state;
u32 interval;
s32 ipv;
s32 maxoctets;
};
struct tcfg_gate_entry {
int index;
u8 gate_state;
u32 interval;
s32 ipv;
s32 maxoctets;
struct list_head list;
};
struct tcf_gate_params {
s32 tcfg_priority;
u64 tcfg_basetime;
u64 tcfg_cycletime;
u64 tcfg_cycletime_ext;
u32 tcfg_flags;
s32 tcfg_clockid;
size_t num_entries;
struct list_head entries;
};
#define GATE_ACT_GATE_OPEN BIT(0)
#define GATE_ACT_PENDING BIT(1)
struct tcf_gate {
struct tc_action common;
struct tcf_gate_params param;
u8 current_gate_status;
ktime_t current_close_time;
u32 current_entry_octets;
s32 current_max_octets;
struct tcfg_gate_entry *next_entry;
struct hrtimer hitimer;
enum tk_offsets tk_offset;
};
#define to_gate(a) ((struct tcf_gate *)a)
static inline bool is_tcf_gate(const struct tc_action *a)
{
#ifdef CONFIG_NET_CLS_ACT
if (a->ops && a->ops->id == TCA_ID_GATE)
return true;
#endif
return false;
}
static inline u32 tcf_gate_index(const struct tc_action *a)
{
return a->tcfa_index;
}
static inline s32 tcf_gate_prio(const struct tc_action *a)
{
s32 tcfg_prio;
tcfg_prio = to_gate(a)->param.tcfg_priority;
return tcfg_prio;
}
static inline u64 tcf_gate_basetime(const struct tc_action *a)
{
u64 tcfg_basetime;
tcfg_basetime = to_gate(a)->param.tcfg_basetime;
return tcfg_basetime;
}
static inline u64 tcf_gate_cycletime(const struct tc_action *a)
{
u64 tcfg_cycletime;
tcfg_cycletime = to_gate(a)->param.tcfg_cycletime;
return tcfg_cycletime;
}
static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
{
u64 tcfg_cycletimeext;
tcfg_cycletimeext = to_gate(a)->param.tcfg_cycletime_ext;
return tcfg_cycletimeext;
}
static inline u32 tcf_gate_num_entries(const struct tc_action *a)
{
u32 num_entries;
num_entries = to_gate(a)->param.num_entries;
return num_entries;
}
static inline struct action_gate_entry
*tcf_gate_get_list(const struct tc_action *a)
{
struct action_gate_entry *oe;
struct tcf_gate_params *p;
struct tcfg_gate_entry *entry;
u32 num_entries;
int i = 0;
p = &to_gate(a)->param;
num_entries = p->num_entries;
list_for_each_entry(entry, &p->entries, list)
i++;
if (i != num_entries)
return NULL;
oe = kcalloc(num_entries, sizeof(*oe), GFP_ATOMIC);
if (!oe)
return NULL;
i = 0;
list_for_each_entry(entry, &p->entries, list) {
oe[i].gate_state = entry->gate_state;
oe[i].interval = entry->interval;
oe[i].ipv = entry->ipv;
oe[i].maxoctets = entry->maxoctets;
i++;
}
return oe;
}
#endif
...@@ -134,6 +134,7 @@ enum tca_id { ...@@ -134,6 +134,7 @@ enum tca_id {
TCA_ID_CTINFO, TCA_ID_CTINFO,
TCA_ID_MPLS, TCA_ID_MPLS,
TCA_ID_CT, TCA_ID_CT,
TCA_ID_GATE,
/* other actions go here */ /* other actions go here */
__TCA_ID_MAX = 255 __TCA_ID_MAX = 255
}; };
......
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
/* Copyright 2020 NXP */
#ifndef __LINUX_TC_GATE_H
#define __LINUX_TC_GATE_H
#include <linux/pkt_cls.h>
struct tc_gate {
tc_gen;
};
enum {
TCA_GATE_ENTRY_UNSPEC,
TCA_GATE_ENTRY_INDEX,
TCA_GATE_ENTRY_GATE,
TCA_GATE_ENTRY_INTERVAL,
TCA_GATE_ENTRY_IPV,
TCA_GATE_ENTRY_MAX_OCTETS,
__TCA_GATE_ENTRY_MAX,
};
#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
enum {
TCA_GATE_ONE_ENTRY_UNSPEC,
TCA_GATE_ONE_ENTRY,
__TCA_GATE_ONE_ENTRY_MAX,
};
#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX - 1)
enum {
TCA_GATE_UNSPEC,
TCA_GATE_TM,
TCA_GATE_PARMS,
TCA_GATE_PAD,
TCA_GATE_PRIORITY,
TCA_GATE_ENTRY_LIST,
TCA_GATE_BASE_TIME,
TCA_GATE_CYCLE_TIME,
TCA_GATE_CYCLE_TIME_EXT,
TCA_GATE_FLAGS,
TCA_GATE_CLOCKID,
__TCA_GATE_MAX,
};
#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
#endif
...@@ -981,6 +981,18 @@ config NET_ACT_CT ...@@ -981,6 +981,18 @@ config NET_ACT_CT
To compile this code as a module, choose M here: the To compile this code as a module, choose M here: the
module will be called act_ct. module will be called act_ct.
config NET_ACT_GATE
tristate "Frame gate entry list control tc action"
depends on NET_CLS_ACT
help
Say Y here to allow to control the ingress flow to be passed at
specific time slot and be dropped at other specific time slot by
the gate entry list.
If unsure, say N.
To compile this code as a module, choose M here: the
module will be called act_gate.
config NET_IFE_SKBMARK config NET_IFE_SKBMARK
tristate "Support to encoding decoding skb mark on IFE action" tristate "Support to encoding decoding skb mark on IFE action"
depends on NET_ACT_IFE depends on NET_ACT_IFE
......
...@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO) += act_meta_skbprio.o ...@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO) += act_meta_skbprio.o
obj-$(CONFIG_NET_IFE_SKBTCINDEX) += act_meta_skbtcindex.o obj-$(CONFIG_NET_IFE_SKBTCINDEX) += act_meta_skbtcindex.o
obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
obj-$(CONFIG_NET_ACT_CT) += act_ct.o obj-$(CONFIG_NET_ACT_CT) += act_ct.o
obj-$(CONFIG_NET_ACT_GATE) += act_gate.o
obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o
obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o
obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o
......
This diff is collapsed.
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <net/tc_act/tc_skbedit.h> #include <net/tc_act/tc_skbedit.h>
#include <net/tc_act/tc_ct.h> #include <net/tc_act/tc_ct.h>
#include <net/tc_act/tc_mpls.h> #include <net/tc_act/tc_mpls.h>
#include <net/tc_act/tc_gate.h>
#include <net/flow_offload.h> #include <net/flow_offload.h>
extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1]; extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
...@@ -3526,6 +3527,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry, ...@@ -3526,6 +3527,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
#endif #endif
} }
static void tcf_gate_entry_destructor(void *priv)
{
struct action_gate_entry *oe = priv;
kfree(oe);
}
static int tcf_gate_get_entries(struct flow_action_entry *entry,
const struct tc_action *act)
{
entry->gate.entries = tcf_gate_get_list(act);
if (!entry->gate.entries)
return -EINVAL;
entry->destructor = tcf_gate_entry_destructor;
entry->destructor_priv = entry->gate.entries;
return 0;
}
int tc_setup_flow_action(struct flow_action *flow_action, int tc_setup_flow_action(struct flow_action *flow_action,
const struct tcf_exts *exts) const struct tcf_exts *exts)
{ {
...@@ -3672,6 +3694,17 @@ int tc_setup_flow_action(struct flow_action *flow_action, ...@@ -3672,6 +3694,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
} else if (is_tcf_skbedit_priority(act)) { } else if (is_tcf_skbedit_priority(act)) {
entry->id = FLOW_ACTION_PRIORITY; entry->id = FLOW_ACTION_PRIORITY;
entry->priority = tcf_skbedit_priority(act); entry->priority = tcf_skbedit_priority(act);
} else if (is_tcf_gate(act)) {
entry->id = FLOW_ACTION_GATE;
entry->gate.index = tcf_gate_index(act);
entry->gate.prio = tcf_gate_prio(act);
entry->gate.basetime = tcf_gate_basetime(act);
entry->gate.cycletime = tcf_gate_cycletime(act);
entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
entry->gate.num_entries = tcf_gate_num_entries(act);
err = tcf_gate_get_entries(entry, act);
if (err)
goto err_out;
} else { } else {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto err_out_locked; goto err_out_locked;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment