Skip to contentSkip to conversation

TX max rate limiting for Chelsio T4/T5 adapters

PATCH In review Rahul Lakkireddy 2 participants 5 messages Aug 22, 2016 – Aug 23, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover TX max rate limiting for Chelsio T4/T5 adapters

This series of patches implement tx max rate limiting per queue on Chelsio T4/T5 hardware. This is achieved by first creating a tx scheduling class with the specified max rate. The queue is then bound to the newly created class. If a scheduling class with similar max rate already exists, then the queue is bound to the matching class.

Patch 1 adds support for setting tx scheduling classes.
Patch 2 adds support to bind/unbind queues to/from the scheduling classes. Patch 3 implements the set_tx_maxrate NDO.

Rahul Lakkireddy (3):
cxgb4: add support for tx traffic scheduling classes
cxgb4: add support for per queue tx scheduling
cxgb4: add support for tx max rate limiting

 drivers/net/ethernet/chelsio/cxgb4/Makefile     |   2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h      |  56 ++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 102 ++++-
 drivers/net/ethernet/chelsio/cxgb4/sched.c      | 556 ++++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/sched.h      | 110 +++++
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c      |  31 +-
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h   |  38 +-
 7 files changed, 890 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/sched.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/sched.h
Signature · 1 line
2.5.3
#1 lore raw

PATCH 1/3 cxgb4: add support for tx traffic scheduling classes

Add support to create tx traffic scheduling classes with specified scheduling parameters. Return an existing class if a match is found with same scheduling parameters.

---
 drivers/net/ethernet/chelsio/cxgb4/Makefile     |   2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h      |  28 ++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |  20 +-
 drivers/net/ethernet/chelsio/cxgb4/sched.c      | 235 ++++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/sched.h      |  89 +++++++++
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c      |  31 +++-
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h   |  38 +++-
 7 files changed, 438 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/sched.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/sched.h
drivers/net/ethernet/chelsio/cxgb4/Makefile +1 -1
index fac2157..2461296 100644
@@ -4,7 +4,7 @@
 
 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
+cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o cxgb4_uld.o sched.o
 cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +27 -1
index 6b05289..17a6dd0 100644
@@ -1,7 +1,7 @@
 /*
  * This file is part of the Chelsio T4 Ethernet driver for Linux.
  *
- * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
+ * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -347,6 +347,7 @@ struct adapter_params {
 	unsigned int ofldq_wr_cred;
 	bool ulptx_memwrite_dsgl;          /* use of T5 DSGL allowed */
 
+	unsigned int nsched_cls;          /* number of traffic classes */
 	unsigned int max_ordird_qp;       /* Max read depth per RDMA QP */
 	unsigned int max_ird_adapter;     /* Max read depth per adapter */
 };
@@ -495,6 +496,7 @@ struct port_info {
 #endif /* CONFIG_CHELSIO_T4_FCOE */
 	bool rxtstamp;  /* Enable TS */
 	struct hwtstamp_config tstamp_config;
+	struct sched_table *sched_tbl;
 };
 
 struct dentry;
@@ -858,6 +860,27 @@ struct adapter {
 	spinlock_t win0_lock ____cacheline_aligned_in_smp;
 };
 
+/* Support for "sched-class" command to allow a TX Scheduling Class to be
+ * programmed with various parameters.
+ */
+struct ch_sched_params {
+	s8   type;                     /* packet or flow */
+	union {
+		struct {
+			s8   level;    /* scheduler hierarchy level */
+			s8   mode;     /* per-class or per-flow */
+			s8   rateunit; /* bit or packet rate */
+			s8   ratemode; /* %port relative or kbps absolute */
+			s8   channel;  /* scheduler channel [0..N] */
+			s8   class;    /* scheduler class [0..N] */
+			s32  minrate;  /* minimum rate */
+			s32  maxrate;  /* maximum rate */
+			s16  weight;   /* percent weight */
+			s16  pktsize;  /* average packet size */
+		} params;
+	} u;
+};
+
 /* Defined bit width of user definable filter tuples
  */
 #define ETHTYPE_BITWIDTH 16
@@ -1563,6 +1586,9 @@ void t4_get_trace_filter(struct adapter *adapter, struct trace_params *tp,
 			 int filter_index, int *enabled);
 int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
 			 u32 addr, u32 val);
+int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
+		    int rateunit, int ratemode, int channel, int class,
+		    int minrate, int maxrate, int weight, int pktsize);
 void t4_sge_decode_idma_state(struct adapter *adapter, int state);
 void t4_free_mem(void *addr);
 void t4_idma_monitor_init(struct adapter *adapter,
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +19 -1
index 0099a0c..2e341bf 100644
@@ -1,7 +1,7 @@
 /*
  * This file is part of the Chelsio T4 Ethernet driver for Linux.
  *
- * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
+ * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -76,6 +76,7 @@
 #include "cxgb4_debugfs.h"
 #include "clip_tbl.h"
 #include "l2t.h"
+#include "sched.h"
 
 char cxgb4_driver_name[] = KBUILD_MODNAME;
 
@@ -4024,6 +4025,12 @@ static int adap_init0(struct adapter *adap)
 	adap->clipt_start = val[0];
 	adap->clipt_end = val[1];
 
+	/* We don't yet have a PARAMs calls to retrieve the number of Traffic
+	 * Classes supported by the hardware/firmware so we hard code it here
+	 * for now.
+	 */
+	adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
+
 	/* query params related to active filter region */
 	params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
 	params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
@@ -4882,6 +4889,7 @@ static void free_some_resources(struct adapter *adapter)
 	unsigned int i;
 
 	t4_free_mem(adapter->l2t);
+	t4_cleanup_sched(adapter);
 	t4_free_mem(adapter->tids.tid_tab);
 	kfree(adapter->sge.egr_map);
 	kfree(adapter->sge.ingr_map);
@@ -5249,6 +5257,16 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		}
 	}
 #endif
+
+	for_each_port(adapter, i) {
+		pi = adap2pinfo(adapter, i);
+		pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
+		if (!pi->sched_tbl)
+			dev_warn(&pdev->dev,
+				 "could not activate scheduling on port %d\n",
+				 i);
+	}
+
 	if (is_offload(adapter) && tid_init(&adapter->tids) < 0) {
 		dev_warn(&pdev->dev, "could not allocate TID table, "
 			 "continuing\n");
drivers/net/ethernet/chelsio/cxgb4/sched.c new file +235 -0

235 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/sched.h new file +89 -0

89 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +30 -1
index 2a476cc..de451ee 100644
@@ -1,7 +1,7 @@
 /*
  * This file is part of the Chelsio T4 Ethernet driver for Linux.
  *
- * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
+ * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -8305,3 +8305,32 @@ int t4_set_vf_mac_acl(struct adapter *adapter, unsigned int vf,
 
 	return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
 }
+
+int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
+		    int rateunit, int ratemode, int channel, int class,
+		    int minrate, int maxrate, int weight, int pktsize)
+{
+	struct fw_sched_cmd cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_SCHED_CMD) |
+				      FW_CMD_REQUEST_F |
+				      FW_CMD_WRITE_F);
+	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
+
+	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
+	cmd.u.params.type = type;
+	cmd.u.params.level = level;
+	cmd.u.params.mode = mode;
+	cmd.u.params.ch = channel;
+	cmd.u.params.cl = class;
+	cmd.u.params.unit = rateunit;
+	cmd.u.params.rate = ratemode;
+	cmd.u.params.min = cpu_to_be32(minrate);
+	cmd.u.params.max = cpu_to_be32(maxrate);
+	cmd.u.params.weight = cpu_to_be16(weight);
+	cmd.u.params.pktsize = cpu_to_be16(pktsize);
+
+	return t4_wr_mbox_meat(adapter, adapter->mbox, &cmd, sizeof(cmd),
+			       NULL, 1);
+}
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h +37 -1
index d8f4adb..ffe4bf4 100644
@@ -1,7 +1,7 @@
 /*
  * This file is part of the Chelsio T4 Ethernet driver for Linux.
  *
- * Copyright (c) 2009-2014 Chelsio Communications, Inc. All rights reserved.
+ * Copyright (c) 2009-2016 Chelsio Communications, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -681,6 +681,7 @@ enum fw_cmd_opcodes {
 	FW_RSS_IND_TBL_CMD             = 0x20,
 	FW_RSS_GLB_CONFIG_CMD          = 0x22,
 	FW_RSS_VI_CONFIG_CMD           = 0x23,
+	FW_SCHED_CMD                   = 0x24,
 	FW_DEVLOG_CMD                  = 0x25,
 	FW_CLIP_CMD                    = 0x28,
 	FW_LASTC2E_CMD                 = 0x40,
@@ -2962,6 +2963,41 @@ struct fw_rss_vi_config_cmd {
 #define FW_RSS_VI_CONFIG_CMD_UDPEN_V(x)	((x) << FW_RSS_VI_CONFIG_CMD_UDPEN_S)
 #define FW_RSS_VI_CONFIG_CMD_UDPEN_F	FW_RSS_VI_CONFIG_CMD_UDPEN_V(1U)
 
+enum fw_sched_sc {
+	FW_SCHED_SC_PARAMS		= 1,
+};
+
+struct fw_sched_cmd {
+	__be32 op_to_write;
+	__be32 retval_len16;
+	union fw_sched {
+		struct fw_sched_config {
+			__u8   sc;
+			__u8   type;
+			__u8   minmaxen;
+			__u8   r3[5];
+			__u8   nclasses[4];
+			__be32 r4;
+		} config;
+		struct fw_sched_params {
+			__u8   sc;
+			__u8   type;
+			__u8   level;
+			__u8   mode;
+			__u8   unit;
+			__u8   rate;
+			__u8   ch;
+			__u8   cl;
+			__be32 min;
+			__be32 max;
+			__be16 weight;
+			__be16 pktsize;
+			__be16 burstsize;
+			__be16 r4;
+		} params;
+	} u;
+};
+
 struct fw_clip_cmd {
 	__be32 op_to_write;
 	__be32 alloc_to_len16;
Signature · 1 line
2.5.3
#2 lore raw

PATCH 2/3 cxgb4: add support for per queue tx scheduling

In reply to Rahul Lakkireddy

Add support to bind/unbind specified tx queues to/from scheduling classes. If a queue is already bound to a scheduling class, it is unbound first and then bound to a new specified class.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h |   8 +
 drivers/net/ethernet/chelsio/cxgb4/sched.c | 321 +++++++++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/sched.h |  18 ++
 3 files changed, 347 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +8 -0
index 17a6dd0..eb30612 100644
@@ -881,6 +881,14 @@ struct ch_sched_params {
 	} u;
 };
 
+/* Support for "sched_queue" command to allow one or more NIC TX Queues
+ * to be bound to a TX Scheduling Class.
+ */
+struct ch_sched_queue {
+	s8   queue;    /* queue index */
+	s8   class;    /* class index */
+};
+
 /* Defined bit width of user definable filter tuples
  */
 #define ETHTYPE_BITWIDTH 16
drivers/net/ethernet/chelsio/cxgb4/sched.c +321 -0

345 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/sched.h +18 -0
index 60b09e9..ac415eb 100644
@@ -40,6 +40,8 @@
 
 #define SCHED_CLS_NONE 0xff
 
+#define FW_SCHED_CLS_NONE 0xffffffff
+
 enum {
 	SCHED_STATE_ACTIVE,
 	SCHED_STATE_UNUSED,
@@ -49,10 +51,21 @@ enum sched_fw_ops {
 	SCHED_FW_OP_ADD,
 };
 
+enum sched_bind_type {
+	SCHED_QUEUE,
+};
+
+struct sched_queue_entry {
+	struct list_head list;
+	unsigned int cntxt_id;
+	struct ch_sched_queue param;
+};
+
 struct sched_class {
 	u8 state;
 	u8 idx;
 	struct ch_sched_params info;
+	struct list_head queue_list;
 	spinlock_t lock; /* Per class lock */
 	atomic_t refcnt;
 };
@@ -81,6 +94,11 @@ static inline bool valid_class_id(struct net_device *dev, u8 class_id)
 	return true;
 }
 
+int cxgb4_sched_class_bind(struct net_device *dev, void *arg,
+			   enum sched_bind_type type);
+int cxgb4_sched_class_unbind(struct net_device *dev, void *arg,
+			     enum sched_bind_type type);
+
 struct sched_class *cxgb4_sched_class_alloc(struct net_device *dev,
 					    struct ch_sched_params *p);
 
Signature · 1 line
2.5.3
#3 lore raw

PATCH 3/3 cxgb4: add support for tx max rate limiting

In reply to Rahul Lakkireddy

Implement set_tx_maxrate NDO to perform per queue tx rate limiting.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h      | 20 ++++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 82 +++++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/sched.h      |  3 +
 3 files changed, 105 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +20 -0
index eb30612..f988c60 100644
@@ -881,6 +881,26 @@ struct ch_sched_params {
 	} u;
 };
 
+enum {
+	SCHED_CLASS_TYPE_PACKET = 0,    /* class type */
+};
+
+enum {
+	SCHED_CLASS_LEVEL_CL_RL = 0,    /* class rate limiter */
+};
+
+enum {
+	SCHED_CLASS_MODE_CLASS = 0,     /* per-class scheduling */
+};
+
+enum {
+	SCHED_CLASS_RATEUNIT_BITS = 0,  /* bit rate scheduling */
+};
+
+enum {
+	SCHED_CLASS_RATEMODE_ABS = 1,   /* Kb/s */
+};
+
 /* Support for "sched_queue" command to allow one or more NIC TX Queues
  * to be bound to a TX Scheduling Class.
  */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +82 -0

94 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/sched.h +3 -0
index ac415eb..77b2b3f 100644
@@ -42,6 +42,9 @@
 
 #define FW_SCHED_CLS_NONE 0xffffffff
 
+/* Max rate that can be set to a scheduling class is 10 Gbps */
+#define SCHED_MAX_RATE_KBPS 10000000U
+
 enum {
 	SCHED_STATE_ACTIVE,
 	SCHED_STATE_UNUSED,
Signature · 1 line
2.5.3
maintainer
#4 lore raw
In reply to Rahul Lakkireddy

From: Rahul Lakkireddy <[email protected]>
Date: Mon, 22 Aug 2016 16:29:05 +0530

Quoted 9 lines

This series of patches implement tx max rate limiting per queue on Chelsio T4/T5 hardware. This is achieved by first creating a tx scheduling class with the specified max rate. The queue is then bound to the newly created class. If a scheduling class with similar max rate already exists, then the queue is bound to the matching class.

Patch 1 adds support for setting tx scheduling classes.
Patch 2 adds support to bind/unbind queues to/from the scheduling classes. Patch 3 implements the set_tx_maxrate NDO.

Series applied, thanks.