mirror of
https://github.com/Ysurac/openmptcprouter.git
synced 2025-03-09 15:40:20 +00:00
Add a directory by kernel instead of a common root, add qnap-301w and rpi4 kernel 6.1 suppport
This commit is contained in:
parent
e910436a7a
commit
46837ec4c0
9459 changed files with 362648 additions and 116345 deletions
|
@ -0,0 +1,50 @@
|
|||
Index: linux-5.4.124/drivers/mtd/spi-nor/spi-nor.c
|
||||
===================================================================
|
||||
--- linux-5.4.124.orig/drivers/mtd/spi-nor/spi-nor.c
|
||||
+++ linux-5.4.124/drivers/mtd/spi-nor/spi-nor.c
|
||||
@@ -2241,6 +2241,9 @@ static const struct flash_info spi_nor_i
|
||||
.fixups = &gd25q256_fixups,
|
||||
},
|
||||
|
||||
+ /* Zbit */
|
||||
+ { "zb25vq128", INFO(0xC84018, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
|
||||
+
|
||||
/* Intel/Numonyx -- xxxs33b */
|
||||
{ "160s33b", INFO(0x898911, 0, 64 * 1024, 32, 0) },
|
||||
{ "320s33b", INFO(0x898912, 0, 64 * 1024, 64, 0) },
|
||||
@@ -2405,6 +2408,7 @@ static const struct flash_info spi_nor_i
|
||||
{ "m25p32", INFO(0x202016, 0, 64 * 1024, 64, 0) },
|
||||
{ "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) },
|
||||
{ "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) },
|
||||
+ { "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, 0) },
|
||||
|
||||
{ "m25p05-nonjedec", INFO(0, 0, 32 * 1024, 2, 0) },
|
||||
{ "m25p10-nonjedec", INFO(0, 0, 32 * 1024, 4, 0) },
|
||||
@@ -2508,10 +2512,14 @@ static const struct flash_info spi_nor_i
|
||||
{ "XM25QH128A", INFO(0x207018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
|
||||
|
||||
/* XTX Technology (Shenzhen) Limited */
|
||||
+ { "XT25F128A", INFO(0x207018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
|
||||
{ "xt25f128b", INFO(0x0B4018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
|
||||
{ },
|
||||
};
|
||||
|
||||
+static const struct flash_info spi_nor_unknown_id =
|
||||
+ { "undefined", INFO(0x0, 0, 64 * 1024, 256, SECT_4K) };
|
||||
+
|
||||
static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
|
||||
{
|
||||
int tmp;
|
||||
@@ -2542,9 +2550,12 @@ static const struct flash_info *spi_nor_
|
||||
return &spi_nor_ids[tmp];
|
||||
}
|
||||
}
|
||||
+ return &spi_nor_unknown_id; // for Teltonikia RUT devices
|
||||
+ /*
|
||||
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
|
||||
SPI_NOR_MAX_ID_LEN, id);
|
||||
return ERR_PTR(-ENODEV);
|
||||
+ */
|
||||
}
|
||||
|
||||
static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
|
|
@ -0,0 +1,198 @@
|
|||
From a07e31adf2753cad2fd9790db5bfc047c81e8152 Mon Sep 17 00:00:00 2001
|
||||
From: Felix Matouschek <felix@matouschek.org>
|
||||
Date: Fri, 2 Jul 2021 20:31:23 +0200
|
||||
Subject: [PATCH] mtd: spinand: Add support for XTX XT26G0xA
|
||||
|
||||
Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and
|
||||
XTX26G04AXXXXX SPI NAND.
|
||||
|
||||
These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC
|
||||
(8bit strength per 512bytes).
|
||||
|
||||
Tested on Teltonika RUTX10 flashed with OpenWrt.
|
||||
|
||||
Datasheets available at
|
||||
http://www.xtxtech.com/download/?AId=225
|
||||
https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf
|
||||
|
||||
Signed-off-by: Felix Matouschek <felix@matouschek.org>
|
||||
---
|
||||
drivers/mtd/nand/spi/Makefile | 2 +-
|
||||
drivers/mtd/nand/spi/core.c | 1 +
|
||||
drivers/mtd/nand/spi/xtx.c | 122 ++++++++++++++++++++++++++++++++++
|
||||
include/linux/mtd/spinand.h | 1 +
|
||||
4 files changed, 125 insertions(+), 1 deletion(-)
|
||||
create mode 100644 drivers/mtd/nand/spi/xtx.c
|
||||
|
||||
Index: linux-5.4.132/drivers/mtd/nand/spi/Makefile
|
||||
===================================================================
|
||||
--- linux-5.4.132.orig/drivers/mtd/nand/spi/Makefile
|
||||
+++ linux-5.4.132/drivers/mtd/nand/spi/Makefile
|
||||
@@ -1,3 +1,3 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
-spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
|
||||
+spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
|
||||
obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
|
||||
Index: linux-5.4.132/drivers/mtd/nand/spi/core.c
|
||||
===================================================================
|
||||
--- linux-5.4.132.orig/drivers/mtd/nand/spi/core.c
|
||||
+++ linux-5.4.132/drivers/mtd/nand/spi/core.c
|
||||
@@ -758,6 +758,7 @@ static const struct spinand_manufacturer
|
||||
¶gon_spinand_manufacturer,
|
||||
&toshiba_spinand_manufacturer,
|
||||
&winbond_spinand_manufacturer,
|
||||
+ &xtx_spinand_manufacturer,
|
||||
};
|
||||
|
||||
static int spinand_manufacturer_detect(struct spinand_device *spinand)
|
||||
Index: linux-5.4.132/drivers/mtd/nand/spi/xtx.c
|
||||
===================================================================
|
||||
--- /dev/null
|
||||
+++ linux-5.4.132/drivers/mtd/nand/spi/xtx.c
|
||||
@@ -0,0 +1,134 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0
|
||||
+/*
|
||||
+ * Author:
|
||||
+ * Felix Matouschek <felix@matouschek.org>
|
||||
+ */
|
||||
+
|
||||
+#include <linux/device.h>
|
||||
+#include <linux/kernel.h>
|
||||
+#include <linux/mtd/spinand.h>
|
||||
+
|
||||
+#define SPINAND_MFR_XTX 0x0B
|
||||
+
|
||||
+#define XT26G0XA_STATUS_ECC_MASK GENMASK(5, 2)
|
||||
+#define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2)
|
||||
+#define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
|
||||
+#define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4)
|
||||
+
|
||||
+static SPINAND_OP_VARIANTS(read_cache_variants,
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
|
||||
+ SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
|
||||
+
|
||||
+static SPINAND_OP_VARIANTS(write_cache_variants,
|
||||
+ SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
|
||||
+ SPINAND_PROG_LOAD(true, 0, NULL, 0));
|
||||
+
|
||||
+static SPINAND_OP_VARIANTS(update_cache_variants,
|
||||
+ SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
|
||||
+ SPINAND_PROG_LOAD(false, 0, NULL, 0));
|
||||
+
|
||||
+static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
|
||||
+ struct mtd_oob_region *region)
|
||||
+{
|
||||
+ if (section)
|
||||
+ return -ERANGE;
|
||||
+
|
||||
+ region->offset = 8;
|
||||
+ region->length = 40;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
|
||||
+ struct mtd_oob_region *region)
|
||||
+{
|
||||
+ if (section)
|
||||
+ return -ERANGE;
|
||||
+
|
||||
+ region->offset = 1;
|
||||
+ region->length = 7;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
|
||||
+ .ecc = xt26g0xa_ooblayout_ecc,
|
||||
+ .free = xt26g0xa_ooblayout_free,
|
||||
+};
|
||||
+
|
||||
+static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
|
||||
+ u8 status)
|
||||
+{
|
||||
+ switch (status & XT26G0XA_STATUS_ECC_MASK) {
|
||||
+ case XT26G0XA_STATUS_ECC_NO_DETECTED:
|
||||
+ return 0;
|
||||
+ case XT26G0XA_STATUS_ECC_8_CORRECTED:
|
||||
+ return 8;
|
||||
+ case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
|
||||
+ return -EBADMSG;
|
||||
+ default: /* (1 << 2) through (7 << 2) are 1-7 corrected errors */
|
||||
+ return (status & XT26G0XA_STATUS_ECC_MASK) >> 2;
|
||||
+ }
|
||||
+
|
||||
+ return -EINVAL;
|
||||
+}
|
||||
+
|
||||
+static const struct spinand_info xtx_spinand_table[] = {
|
||||
+ SPINAND_INFO("XT26G01A", 0xE1,
|
||||
+ NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
|
||||
+ NAND_ECCREQ(8, 512),
|
||||
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
|
||||
+ &write_cache_variants,
|
||||
+ &update_cache_variants),
|
||||
+ SPINAND_HAS_QE_BIT,
|
||||
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
|
||||
+ xt26g0xa_ecc_get_status)),
|
||||
+ SPINAND_INFO("XT26G02A", 0xE2,
|
||||
+ NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
|
||||
+ NAND_ECCREQ(8, 512),
|
||||
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
|
||||
+ &write_cache_variants,
|
||||
+ &update_cache_variants),
|
||||
+ SPINAND_HAS_QE_BIT,
|
||||
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
|
||||
+ xt26g0xa_ecc_get_status)),
|
||||
+ SPINAND_INFO("XT26G04A", 0xE3,
|
||||
+ NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
|
||||
+ NAND_ECCREQ(8, 512),
|
||||
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
|
||||
+ &write_cache_variants,
|
||||
+ &update_cache_variants),
|
||||
+ SPINAND_HAS_QE_BIT,
|
||||
+ SPINAND_ECCINFO(&xt26g0xa_ooblayout,
|
||||
+ xt26g0xa_ecc_get_status)),
|
||||
+};
|
||||
+
|
||||
+static int xtx_spinand_detect(struct spinand_device *spinand)
|
||||
+{
|
||||
+ u8 *id = spinand->id.data;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (id[1] != SPINAND_MFR_XTX)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = spinand_match_and_init(spinand, xtx_spinand_table,
|
||||
+ ARRAY_SIZE(xtx_spinand_table), id[2]);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
+static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
|
||||
+ .detect = xtx_spinand_detect,
|
||||
+};
|
||||
+
|
||||
+const struct spinand_manufacturer xtx_spinand_manufacturer = {
|
||||
+ .id = SPINAND_MFR_XTX,
|
||||
+ .name = "XTX",
|
||||
+ .ops = &xtx_spinand_manuf_ops,
|
||||
+};
|
||||
Index: linux-5.4.132/include/linux/mtd/spinand.h
|
||||
===================================================================
|
||||
--- linux-5.4.132.orig/include/linux/mtd/spinand.h
|
||||
+++ linux-5.4.132/include/linux/mtd/spinand.h
|
||||
@@ -230,6 +230,7 @@ extern const struct spinand_manufacturer
|
||||
extern const struct spinand_manufacturer paragon_spinand_manufacturer;
|
||||
extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
|
||||
extern const struct spinand_manufacturer winbond_spinand_manufacturer;
|
||||
+extern const struct spinand_manufacturer xtx_spinand_manufacturer;
|
||||
|
||||
/**
|
||||
* struct spinand_op_variants - SPI NAND operation variants
|
|
@ -0,0 +1,554 @@
|
|||
From: Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
Date: Thu, 11 Jan 2018 16:32:00 +0100
|
||||
Subject: [PATCH] netfilter: nf_flow_table: add hardware offload support
|
||||
|
||||
This patch adds the infrastructure to offload flows to hardware, in case
|
||||
the nic/switch comes with built-in flow tables capabilities.
|
||||
|
||||
If the hardware comes with no hardware flow tables or they have
|
||||
limitations in terms of features, the existing infrastructure falls back
|
||||
to the software flow table implementation.
|
||||
|
||||
The software flow table garbage collector skips entries that resides in
|
||||
the hardware, so the hardware will be responsible for releasing this
|
||||
flow table entry too via flow_offload_dead().
|
||||
|
||||
Hardware configuration, either to add or to delete entries, is done from
|
||||
the hardware offload workqueue, to ensure this is done from user context
|
||||
given that we may sleep when grabbing the mdio mutex.
|
||||
|
||||
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
---
|
||||
create mode 100644 net/netfilter/nf_flow_table_hw.c
|
||||
|
||||
--- a/include/linux/netdevice.h
|
||||
+++ b/include/linux/netdevice.h
|
||||
@@ -922,6 +922,13 @@ struct devlink;
|
||||
struct tlsdev_ops;
|
||||
|
||||
|
||||
+struct flow_offload;
|
||||
+
|
||||
+enum flow_offload_type {
|
||||
+ FLOW_OFFLOAD_ADD = 0,
|
||||
+ FLOW_OFFLOAD_DEL,
|
||||
+};
|
||||
+
|
||||
/*
|
||||
* This structure defines the management hooks for network devices.
|
||||
* The following hooks can be defined; unless noted otherwise, they are
|
||||
@@ -1154,6 +1161,10 @@ struct tlsdev_ops;
|
||||
* int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
|
||||
* u16 flags);
|
||||
*
|
||||
+ * int (*ndo_flow_offload)(enum flow_offload_type type,
|
||||
+ * struct flow_offload *flow);
|
||||
+ * Adds/deletes flow entry to/from net device flowtable.
|
||||
+ *
|
||||
* int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
|
||||
* Called to change device carrier. Soft-devices (like dummy, team, etc)
|
||||
* which do not represent real hardware may define this to allow their
|
||||
@@ -1401,6 +1412,8 @@ struct net_device_ops {
|
||||
int (*ndo_bridge_dellink)(struct net_device *dev,
|
||||
struct nlmsghdr *nlh,
|
||||
u16 flags);
|
||||
+ int (*ndo_flow_offload)(enum flow_offload_type type,
|
||||
+ struct flow_offload *flow);
|
||||
int (*ndo_change_carrier)(struct net_device *dev,
|
||||
bool new_carrier);
|
||||
int (*ndo_get_phys_port_id)(struct net_device *dev,
|
||||
--- a/include/net/netfilter/nf_flow_table.h
|
||||
+++ b/include/net/netfilter/nf_flow_table.h
|
||||
@@ -21,11 +21,17 @@ struct nf_flowtable_type {
|
||||
struct module *owner;
|
||||
};
|
||||
|
||||
+enum nf_flowtable_flags {
|
||||
+ NF_FLOWTABLE_F_HW = 0x1,
|
||||
+};
|
||||
+
|
||||
struct nf_flowtable {
|
||||
struct list_head list;
|
||||
struct rhashtable rhashtable;
|
||||
const struct nf_flowtable_type *type;
|
||||
+ u32 flags;
|
||||
struct delayed_work gc_work;
|
||||
+ possible_net_t ft_net;
|
||||
};
|
||||
|
||||
enum flow_offload_tuple_dir {
|
||||
@@ -68,6 +74,7 @@ struct flow_offload_tuple_rhash {
|
||||
#define FLOW_OFFLOAD_DNAT 0x2
|
||||
#define FLOW_OFFLOAD_DYING 0x4
|
||||
#define FLOW_OFFLOAD_TEARDOWN 0x8
|
||||
+#define FLOW_OFFLOAD_HW 0x10
|
||||
|
||||
struct flow_offload {
|
||||
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
|
||||
@@ -120,6 +127,22 @@ unsigned int nf_flow_offload_ip_hook(voi
|
||||
unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
|
||||
const struct nf_hook_state *state);
|
||||
|
||||
+void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
|
||||
+ struct nf_conn *ct);
|
||||
+void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow);
|
||||
+
|
||||
+struct nf_flow_table_hw {
|
||||
+ struct module *owner;
|
||||
+ void (*add)(struct net *net, struct flow_offload *flow,
|
||||
+ struct nf_conn *ct);
|
||||
+ void (*del)(struct net *net, struct flow_offload *flow);
|
||||
+};
|
||||
+
|
||||
+int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload);
|
||||
+void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload);
|
||||
+
|
||||
+extern struct work_struct nf_flow_offload_hw_work;
|
||||
+
|
||||
#define MODULE_ALIAS_NF_FLOWTABLE(family) \
|
||||
MODULE_ALIAS("nf-flowtable-" __stringify(family))
|
||||
|
||||
--- a/include/uapi/linux/netfilter/nf_tables.h
|
||||
+++ b/include/uapi/linux/netfilter/nf_tables.h
|
||||
@@ -1516,6 +1516,7 @@ enum nft_object_attributes {
|
||||
* @NFTA_FLOWTABLE_HOOK: netfilter hook configuration(NLA_U32)
|
||||
* @NFTA_FLOWTABLE_USE: number of references to this flow table (NLA_U32)
|
||||
* @NFTA_FLOWTABLE_HANDLE: object handle (NLA_U64)
|
||||
+ * @NFTA_FLOWTABLE_FLAGS: flags (NLA_U32)
|
||||
*/
|
||||
enum nft_flowtable_attributes {
|
||||
NFTA_FLOWTABLE_UNSPEC,
|
||||
@@ -1525,6 +1526,7 @@ enum nft_flowtable_attributes {
|
||||
NFTA_FLOWTABLE_USE,
|
||||
NFTA_FLOWTABLE_HANDLE,
|
||||
NFTA_FLOWTABLE_PAD,
|
||||
+ NFTA_FLOWTABLE_FLAGS,
|
||||
__NFTA_FLOWTABLE_MAX
|
||||
};
|
||||
#define NFTA_FLOWTABLE_MAX (__NFTA_FLOWTABLE_MAX - 1)
|
||||
--- a/net/netfilter/Kconfig
|
||||
+++ b/net/netfilter/Kconfig
|
||||
@@ -711,6 +711,15 @@ config NF_FLOW_TABLE
|
||||
|
||||
To compile it as a module, choose M here.
|
||||
|
||||
+config NF_FLOW_TABLE_HW
|
||||
+ tristate "Netfilter flow table hardware offload module"
|
||||
+ depends on NF_FLOW_TABLE
|
||||
+ help
|
||||
+ This option adds hardware offload support for the flow table core
|
||||
+ infrastructure.
|
||||
+
|
||||
+ To compile it as a module, choose M here.
|
||||
+
|
||||
config NETFILTER_XTABLES
|
||||
tristate "Netfilter Xtables support (required for ip_tables)"
|
||||
default m if NETFILTER_ADVANCED=n
|
||||
--- a/net/netfilter/Makefile
|
||||
+++ b/net/netfilter/Makefile
|
||||
@@ -123,6 +123,7 @@ obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_t
|
||||
nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o
|
||||
|
||||
obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
|
||||
+obj-$(CONFIG_NF_FLOW_TABLE_HW) += nf_flow_table_hw.o
|
||||
|
||||
# generic X tables
|
||||
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
|
||||
--- a/net/netfilter/nf_flow_table_core.c
|
||||
+++ b/net/netfilter/nf_flow_table_core.c
|
||||
@@ -248,10 +248,16 @@ static inline bool nf_flow_has_expired(c
|
||||
return nf_flow_timeout_delta(flow->timeout) <= 0;
|
||||
}
|
||||
|
||||
+static inline bool nf_flow_in_hw(const struct flow_offload *flow)
|
||||
+{
|
||||
+ return flow->flags & FLOW_OFFLOAD_HW;
|
||||
+}
|
||||
+
|
||||
static void flow_offload_del(struct nf_flowtable *flow_table,
|
||||
struct flow_offload *flow)
|
||||
{
|
||||
struct flow_offload_entry *e;
|
||||
+ struct net *net = read_pnet(&flow_table->ft_net);
|
||||
|
||||
rhashtable_remove_fast(&flow_table->rhashtable,
|
||||
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
|
||||
@@ -271,6 +277,9 @@ static void flow_offload_del(struct nf_f
|
||||
if (!(flow->flags & FLOW_OFFLOAD_TEARDOWN))
|
||||
flow_offload_fixup_ct_state(e->ct);
|
||||
|
||||
+ if (nf_flow_in_hw(flow))
|
||||
+ nf_flow_offload_hw_del(net, flow);
|
||||
+
|
||||
flow_offload_free(flow);
|
||||
}
|
||||
|
||||
@@ -490,10 +502,43 @@ int nf_flow_dnat_port(const struct flow_
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nf_flow_dnat_port);
|
||||
|
||||
+static const struct nf_flow_table_hw __rcu *nf_flow_table_hw_hook __read_mostly;
|
||||
+
|
||||
+static int nf_flow_offload_hw_init(struct nf_flowtable *flow_table)
|
||||
+{
|
||||
+ const struct nf_flow_table_hw *offload;
|
||||
+
|
||||
+ if (!rcu_access_pointer(nf_flow_table_hw_hook))
|
||||
+ request_module("nf-flow-table-hw");
|
||||
+
|
||||
+ rcu_read_lock();
|
||||
+ offload = rcu_dereference(nf_flow_table_hw_hook);
|
||||
+ if (!offload)
|
||||
+ goto err_no_hw_offload;
|
||||
+
|
||||
+ if (!try_module_get(offload->owner))
|
||||
+ goto err_no_hw_offload;
|
||||
+
|
||||
+ rcu_read_unlock();
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+err_no_hw_offload:
|
||||
+ rcu_read_unlock();
|
||||
+
|
||||
+ return -EOPNOTSUPP;
|
||||
+}
|
||||
+
|
||||
int nf_flow_table_init(struct nf_flowtable *flowtable)
|
||||
{
|
||||
int err;
|
||||
|
||||
+ if (flowtable->flags & NF_FLOWTABLE_F_HW) {
|
||||
+ err = nf_flow_offload_hw_init(flowtable);
|
||||
+ if (err)
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
INIT_DEFERRABLE_WORK(&flowtable->gc_work, nf_flow_offload_work_gc);
|
||||
|
||||
err = rhashtable_init(&flowtable->rhashtable,
|
||||
@@ -534,6 +579,8 @@ static void nf_flow_table_iterate_cleanu
|
||||
{
|
||||
nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup, dev);
|
||||
flush_delayed_work(&flowtable->gc_work);
|
||||
+ if (flowtable->flags & NF_FLOWTABLE_F_HW)
|
||||
+ flush_work(&nf_flow_offload_hw_work);
|
||||
}
|
||||
|
||||
void nf_flow_table_cleanup(struct net_device *dev)
|
||||
@@ -547,6 +594,26 @@ void nf_flow_table_cleanup(struct net_de
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
|
||||
|
||||
+struct work_struct nf_flow_offload_hw_work;
|
||||
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_work);
|
||||
+
|
||||
+/* Give the hardware workqueue the chance to remove entries from hardware.*/
|
||||
+static void nf_flow_offload_hw_free(struct nf_flowtable *flowtable)
|
||||
+{
|
||||
+ const struct nf_flow_table_hw *offload;
|
||||
+
|
||||
+ flush_work(&nf_flow_offload_hw_work);
|
||||
+
|
||||
+ rcu_read_lock();
|
||||
+ offload = rcu_dereference(nf_flow_table_hw_hook);
|
||||
+ if (!offload) {
|
||||
+ rcu_read_unlock();
|
||||
+ return;
|
||||
+ }
|
||||
+ module_put(offload->owner);
|
||||
+ rcu_read_unlock();
|
||||
+}
|
||||
+
|
||||
void nf_flow_table_free(struct nf_flowtable *flow_table)
|
||||
{
|
||||
mutex_lock(&flowtable_lock);
|
||||
@@ -556,9 +623,58 @@ void nf_flow_table_free(struct nf_flowta
|
||||
nf_flow_table_iterate(flow_table, nf_flow_table_do_cleanup, NULL);
|
||||
nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, flow_table);
|
||||
rhashtable_destroy(&flow_table->rhashtable);
|
||||
+ if (flow_table->flags & NF_FLOWTABLE_F_HW)
|
||||
+ nf_flow_offload_hw_free(flow_table);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nf_flow_table_free);
|
||||
|
||||
+/* Must be called from user context. */
|
||||
+void nf_flow_offload_hw_add(struct net *net, struct flow_offload *flow,
|
||||
+ struct nf_conn *ct)
|
||||
+{
|
||||
+ const struct nf_flow_table_hw *offload;
|
||||
+
|
||||
+ rcu_read_lock();
|
||||
+ offload = rcu_dereference(nf_flow_table_hw_hook);
|
||||
+ if (offload)
|
||||
+ offload->add(net, flow, ct);
|
||||
+ rcu_read_unlock();
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_add);
|
||||
+
|
||||
+/* Must be called from user context. */
|
||||
+void nf_flow_offload_hw_del(struct net *net, struct flow_offload *flow)
|
||||
+{
|
||||
+ const struct nf_flow_table_hw *offload;
|
||||
+
|
||||
+ rcu_read_lock();
|
||||
+ offload = rcu_dereference(nf_flow_table_hw_hook);
|
||||
+ if (offload)
|
||||
+ offload->del(net, flow);
|
||||
+ rcu_read_unlock();
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(nf_flow_offload_hw_del);
|
||||
+
|
||||
+int nf_flow_table_hw_register(const struct nf_flow_table_hw *offload)
|
||||
+{
|
||||
+ if (rcu_access_pointer(nf_flow_table_hw_hook))
|
||||
+ return -EBUSY;
|
||||
+
|
||||
+ rcu_assign_pointer(nf_flow_table_hw_hook, offload);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(nf_flow_table_hw_register);
|
||||
+
|
||||
+void nf_flow_table_hw_unregister(const struct nf_flow_table_hw *offload)
|
||||
+{
|
||||
+ WARN_ON(rcu_access_pointer(nf_flow_table_hw_hook) != offload);
|
||||
+ rcu_assign_pointer(nf_flow_table_hw_hook, NULL);
|
||||
+
|
||||
+ synchronize_rcu();
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(nf_flow_table_hw_unregister);
|
||||
+
|
||||
static int nf_flow_table_netdev_event(struct notifier_block *this,
|
||||
unsigned long event, void *ptr)
|
||||
{
|
||||
--- /dev/null
|
||||
+++ b/net/netfilter/nf_flow_table_hw.c
|
||||
@@ -0,0 +1,169 @@
|
||||
+#include <linux/kernel.h>
|
||||
+#include <linux/init.h>
|
||||
+#include <linux/module.h>
|
||||
+#include <linux/netfilter.h>
|
||||
+#include <linux/rhashtable.h>
|
||||
+#include <linux/netdevice.h>
|
||||
+#include <net/netfilter/nf_flow_table.h>
|
||||
+#include <net/netfilter/nf_conntrack.h>
|
||||
+#include <net/netfilter/nf_conntrack_core.h>
|
||||
+#include <net/netfilter/nf_conntrack_tuple.h>
|
||||
+
|
||||
+static DEFINE_SPINLOCK(flow_offload_hw_pending_list_lock);
|
||||
+static LIST_HEAD(flow_offload_hw_pending_list);
|
||||
+
|
||||
+static DEFINE_MUTEX(nf_flow_offload_hw_mutex);
|
||||
+
|
||||
+struct flow_offload_hw {
|
||||
+ struct list_head list;
|
||||
+ enum flow_offload_type type;
|
||||
+ struct flow_offload *flow;
|
||||
+ struct nf_conn *ct;
|
||||
+ possible_net_t flow_hw_net;
|
||||
+};
|
||||
+
|
||||
+static int do_flow_offload_hw(struct net *net, struct flow_offload *flow,
|
||||
+ int type)
|
||||
+{
|
||||
+ struct net_device *indev;
|
||||
+ int ret, ifindex;
|
||||
+
|
||||
+ ifindex = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.iifidx;
|
||||
+ indev = dev_get_by_index(net, ifindex);
|
||||
+ if (WARN_ON(!indev))
|
||||
+ return 0;
|
||||
+
|
||||
+ mutex_lock(&nf_flow_offload_hw_mutex);
|
||||
+ ret = indev->netdev_ops->ndo_flow_offload(type, flow);
|
||||
+ mutex_unlock(&nf_flow_offload_hw_mutex);
|
||||
+
|
||||
+ dev_put(indev);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_hw_work_add(struct flow_offload_hw *offload)
|
||||
+{
|
||||
+ struct net *net;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (nf_ct_is_dying(offload->ct))
|
||||
+ return;
|
||||
+
|
||||
+ net = read_pnet(&offload->flow_hw_net);
|
||||
+ ret = do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_ADD);
|
||||
+ if (ret >= 0)
|
||||
+ offload->flow->flags |= FLOW_OFFLOAD_HW;
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_hw_work_del(struct flow_offload_hw *offload)
|
||||
+{
|
||||
+ struct net *net = read_pnet(&offload->flow_hw_net);
|
||||
+
|
||||
+ do_flow_offload_hw(net, offload->flow, FLOW_OFFLOAD_DEL);
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_hw_work(struct work_struct *work)
|
||||
+{
|
||||
+ struct flow_offload_hw *offload, *next;
|
||||
+ LIST_HEAD(hw_offload_pending);
|
||||
+
|
||||
+ spin_lock_bh(&flow_offload_hw_pending_list_lock);
|
||||
+ list_replace_init(&flow_offload_hw_pending_list, &hw_offload_pending);
|
||||
+ spin_unlock_bh(&flow_offload_hw_pending_list_lock);
|
||||
+
|
||||
+ list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
|
||||
+ switch (offload->type) {
|
||||
+ case FLOW_OFFLOAD_ADD:
|
||||
+ flow_offload_hw_work_add(offload);
|
||||
+ break;
|
||||
+ case FLOW_OFFLOAD_DEL:
|
||||
+ flow_offload_hw_work_del(offload);
|
||||
+ break;
|
||||
+ }
|
||||
+ if (offload->ct)
|
||||
+ nf_conntrack_put(&offload->ct->ct_general);
|
||||
+ list_del(&offload->list);
|
||||
+ kfree(offload);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_queue_work(struct flow_offload_hw *offload)
|
||||
+{
|
||||
+ spin_lock_bh(&flow_offload_hw_pending_list_lock);
|
||||
+ list_add_tail(&offload->list, &flow_offload_hw_pending_list);
|
||||
+ spin_unlock_bh(&flow_offload_hw_pending_list_lock);
|
||||
+
|
||||
+ schedule_work(&nf_flow_offload_hw_work);
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_hw_add(struct net *net, struct flow_offload *flow,
|
||||
+ struct nf_conn *ct)
|
||||
+{
|
||||
+ struct flow_offload_hw *offload;
|
||||
+
|
||||
+ offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
|
||||
+ if (!offload)
|
||||
+ return;
|
||||
+
|
||||
+ nf_conntrack_get(&ct->ct_general);
|
||||
+ offload->type = FLOW_OFFLOAD_ADD;
|
||||
+ offload->ct = ct;
|
||||
+ offload->flow = flow;
|
||||
+ write_pnet(&offload->flow_hw_net, net);
|
||||
+
|
||||
+ flow_offload_queue_work(offload);
|
||||
+}
|
||||
+
|
||||
+static void flow_offload_hw_del(struct net *net, struct flow_offload *flow)
|
||||
+{
|
||||
+ struct flow_offload_hw *offload;
|
||||
+
|
||||
+ offload = kmalloc(sizeof(struct flow_offload_hw), GFP_ATOMIC);
|
||||
+ if (!offload)
|
||||
+ return;
|
||||
+
|
||||
+ offload->type = FLOW_OFFLOAD_DEL;
|
||||
+ offload->ct = NULL;
|
||||
+ offload->flow = flow;
|
||||
+ write_pnet(&offload->flow_hw_net, net);
|
||||
+
|
||||
+ flow_offload_queue_work(offload);
|
||||
+}
|
||||
+
|
||||
+static const struct nf_flow_table_hw flow_offload_hw = {
|
||||
+ .add = flow_offload_hw_add,
|
||||
+ .del = flow_offload_hw_del,
|
||||
+ .owner = THIS_MODULE,
|
||||
+};
|
||||
+
|
||||
+static int __init nf_flow_table_hw_module_init(void)
|
||||
+{
|
||||
+ INIT_WORK(&nf_flow_offload_hw_work, flow_offload_hw_work);
|
||||
+ nf_flow_table_hw_register(&flow_offload_hw);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void __exit nf_flow_table_hw_module_exit(void)
|
||||
+{
|
||||
+ struct flow_offload_hw *offload, *next;
|
||||
+ LIST_HEAD(hw_offload_pending);
|
||||
+
|
||||
+ nf_flow_table_hw_unregister(&flow_offload_hw);
|
||||
+ cancel_work_sync(&nf_flow_offload_hw_work);
|
||||
+
|
||||
+ list_for_each_entry_safe(offload, next, &hw_offload_pending, list) {
|
||||
+ if (offload->ct)
|
||||
+ nf_conntrack_put(&offload->ct->ct_general);
|
||||
+ list_del(&offload->list);
|
||||
+ kfree(offload);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+module_init(nf_flow_table_hw_module_init);
|
||||
+module_exit(nf_flow_table_hw_module_exit);
|
||||
+
|
||||
+MODULE_LICENSE("GPL");
|
||||
+MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
|
||||
+MODULE_ALIAS("nf-flow-table-hw");
|
||||
--- a/net/netfilter/nf_tables_api.c
|
||||
+++ b/net/netfilter/nf_tables_api.c
|
||||
@@ -5743,6 +5743,13 @@ static int nf_tables_flowtable_parse_hoo
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
+ for (i = 0; i < n; i++) {
|
||||
+ if (flowtable->data.flags & NF_FLOWTABLE_F_HW &&
|
||||
+ !dev_array[i]->netdev_ops->ndo_flow_offload) {
|
||||
+ return -EOPNOTSUPP;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
ops = kcalloc(n, sizeof(struct nf_hook_ops), GFP_KERNEL);
|
||||
if (!ops)
|
||||
return -ENOMEM;
|
||||
@@ -5873,10 +5880,19 @@ static int nf_tables_newflowtable(struct
|
||||
}
|
||||
|
||||
flowtable->data.type = type;
|
||||
+ write_pnet(&flowtable->data.ft_net, net);
|
||||
+
|
||||
err = type->init(&flowtable->data);
|
||||
if (err < 0)
|
||||
goto err3;
|
||||
|
||||
+ if (nla[NFTA_FLOWTABLE_FLAGS]) {
|
||||
+ flowtable->data.flags =
|
||||
+ ntohl(nla_get_be32(nla[NFTA_FLOWTABLE_FLAGS]));
|
||||
+ if (flowtable->data.flags & ~NF_FLOWTABLE_F_HW)
|
||||
+ goto err4;
|
||||
+ }
|
||||
+
|
||||
err = nf_tables_flowtable_parse_hook(&ctx, nla[NFTA_FLOWTABLE_HOOK],
|
||||
flowtable);
|
||||
if (err < 0)
|
||||
@@ -6002,7 +6018,8 @@ static int nf_tables_fill_flowtable_info
|
||||
nla_put_string(skb, NFTA_FLOWTABLE_NAME, flowtable->name) ||
|
||||
nla_put_be32(skb, NFTA_FLOWTABLE_USE, htonl(flowtable->use)) ||
|
||||
nla_put_be64(skb, NFTA_FLOWTABLE_HANDLE, cpu_to_be64(flowtable->handle),
|
||||
- NFTA_FLOWTABLE_PAD))
|
||||
+ NFTA_FLOWTABLE_PAD) ||
|
||||
+ nla_put_be32(skb, NFTA_FLOWTABLE_FLAGS, htonl(flowtable->data.flags)))
|
||||
goto nla_put_failure;
|
||||
|
||||
nest = nla_nest_start_noflag(skb, NFTA_FLOWTABLE_HOOK);
|
||||
--- a/net/netfilter/nft_flow_offload.c
|
||||
+++ b/net/netfilter/nft_flow_offload.c
|
||||
@@ -128,6 +128,9 @@ static void nft_flow_offload_eval(const
|
||||
if (ret < 0)
|
||||
goto err_flow_add;
|
||||
|
||||
+ if (flowtable->flags & NF_FLOWTABLE_F_HW)
|
||||
+ nf_flow_offload_hw_add(nft_net(pkt), flow, ct);
|
||||
+
|
||||
dst_release(route.tuple[!dir].dst);
|
||||
return;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
From: Felix Fietkau <nbd@nbd.name>
|
||||
Date: Sun, 25 Mar 2018 21:10:55 +0200
|
||||
Subject: [PATCH] netfilter: nf_flow_table: rework hardware offload timeout
|
||||
handling
|
||||
|
||||
Some offload implementations send keepalive packets + explicit
|
||||
notifications of TCP FIN/RST packets. In this case it is more convenient
|
||||
to simply let the driver update flow->timeout handling and use the
|
||||
regular flow offload gc step.
|
||||
|
||||
For drivers that manage their own lifetime, a separate flag can be set
|
||||
to avoid gc timeouts.
|
||||
|
||||
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
---
|
||||
|
||||
--- a/include/net/netfilter/nf_flow_table.h
|
||||
+++ b/include/net/netfilter/nf_flow_table.h
|
||||
@@ -75,6 +75,7 @@ struct flow_offload_tuple_rhash {
|
||||
#define FLOW_OFFLOAD_DYING 0x4
|
||||
#define FLOW_OFFLOAD_TEARDOWN 0x8
|
||||
#define FLOW_OFFLOAD_HW 0x10
|
||||
+#define FLOW_OFFLOAD_KEEP 0x20
|
||||
|
||||
struct flow_offload {
|
||||
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
|
Loading…
Add table
Add a link
Reference in a new issue