Skip to contentSkip to conversation

r8169: support dash

RFC PATCH In review Hayes Wang 5 participants 25 messages Nov 29, 2021 – Dec 9, 2021

Subsystems (3)
lore
Share & tools
lore

Hayes Wang

author
#0 lore raw

cover r8169: support dash

These patches are used to support dash for RTL8111EP and RTL8111FP(RTL81117).

Hayes Wang (4):
r8169: remove the relative code about dash
r8169: add type2 access functions
r8169: support CMAC
r8169: add sysfs for dash

 drivers/net/ethernet/realtek/Makefile     |   2 +-
 drivers/net/ethernet/realtek/r8169.h      |   5 +
 drivers/net/ethernet/realtek/r8169_dash.c | 887 ++++++++++++++++++++++
 drivers/net/ethernet/realtek/r8169_dash.h |  30 +
 drivers/net/ethernet/realtek/r8169_main.c | 349 +++++++--
 5 files changed, 1196 insertions(+), 77 deletions(-)
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.c
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.h
Signature · 1 line
2.31.1
author
#1 lore raw

RFC PATCH 1/4 r8169: remove the relative code about dash

Remove the relative code of dash, except for RTL8111DP.

The flow of initialization is different when considering supporting the dash, so remove the relative code first.

The RTL8111DP has the different design and is stopped to maintain, so keep the current behavior is enough.

---
 drivers/net/ethernet/realtek/r8169_main.c | 70 ++---------------------
 1 file changed, 5 insertions(+), 65 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +5 -65
index 3d6843332c77..fd295bcd125c 100644
@@ -245,10 +245,6 @@ enum rtl_registers {
 	FuncEvent	= 0xf0,
 	FuncEventMask	= 0xf4,
 	FuncPresetState	= 0xf8,
-	IBCR0           = 0xf8,
-	IBCR2           = 0xf9,
-	IBIMR0          = 0xfa,
-	IBISR0          = 0xfb,
 	FuncForceEvent	= 0xfc,
 };
 
@@ -1127,67 +1123,18 @@ DECLARE_RTL_COND(rtl_dp_ocp_read_cond)
 	return r8168dp_ocp_read(tp, reg) & 0x00000800;
 }
 
-DECLARE_RTL_COND(rtl_ep_ocp_read_cond)
-{
-	return r8168ep_ocp_read(tp, 0x124) & 0x00000001;
-}
-
-DECLARE_RTL_COND(rtl_ocp_tx_cond)
-{
-	return RTL_R8(tp, IBISR0) & 0x20;
-}
-
-static void rtl8168ep_stop_cmac(struct rtl8169_private *tp)
-{
-	RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01);
-	rtl_loop_wait_high(tp, &rtl_ocp_tx_cond, 50000, 2000);
-	RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20);
-	RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01);
-}
-
 static void rtl8168dp_driver_start(struct rtl8169_private *tp)
 {
 	r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START);
 	rtl_loop_wait_high(tp, &rtl_dp_ocp_read_cond, 10000, 10);
 }
 
-static void rtl8168ep_driver_start(struct rtl8169_private *tp)
-{
-	r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START);
-	r8168ep_ocp_write(tp, 0x01, 0x30, r8168ep_ocp_read(tp, 0x30) | 0x01);
-	rtl_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10000, 10);
-}
-
-static void rtl8168_driver_start(struct rtl8169_private *tp)
-{
-	if (tp->dash_type == RTL_DASH_DP)
-		rtl8168dp_driver_start(tp);
-	else
-		rtl8168ep_driver_start(tp);
-}
-
 static void rtl8168dp_driver_stop(struct rtl8169_private *tp)
 {
 	r8168dp_oob_notify(tp, OOB_CMD_DRIVER_STOP);
 	rtl_loop_wait_low(tp, &rtl_dp_ocp_read_cond, 10000, 10);
 }
 
-static void rtl8168ep_driver_stop(struct rtl8169_private *tp)
-{
-	rtl8168ep_stop_cmac(tp);
-	r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP);
-	r8168ep_ocp_write(tp, 0x01, 0x30, r8168ep_ocp_read(tp, 0x30) | 0x01);
-	rtl_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10000, 10);
-}
-
-static void rtl8168_driver_stop(struct rtl8169_private *tp)
-{
-	if (tp->dash_type == RTL_DASH_DP)
-		rtl8168dp_driver_stop(tp);
-	else
-		rtl8168ep_driver_stop(tp);
-}
-
 static bool r8168dp_check_dash(struct rtl8169_private *tp)
 {
 	u16 reg = rtl8168_get_ocp_reg(tp);
@@ -3227,8 +3174,6 @@ static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
 
 static void rtl_hw_start_8168ep(struct rtl8169_private *tp)
 {
-	rtl8168ep_stop_cmac(tp);
-
 	rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06);
 	rtl8168g_set_pause_thresholds(tp, 0x2f, 0x5f);
 
@@ -3324,8 +3269,6 @@ static void rtl_hw_start_8117(struct rtl8169_private *tp)
 	};
 	int rg_saw_cnt;
 
-	rtl8168ep_stop_cmac(tp);
-
 	/* disable aspm and clock request before access ephy */
 	rtl_hw_aspm_clkreq_enable(tp, false);
 	rtl_ephy_init(tp, e_info_8117);
@@ -4968,8 +4911,8 @@ static void rtl_remove_one(struct pci_dev *pdev)
 
 	unregister_netdev(tp->dev);
 
-	if (tp->dash_type != RTL_DASH_NONE)
-		rtl8168_driver_stop(tp);
+	if (tp->dash_type == RTL_DASH_DP)
+		rtl8168dp_driver_stop(tp);
 
 	rtl_release_firmware(tp);
 
@@ -5161,10 +5104,7 @@ static void rtl_hw_init_8125(struct rtl8169_private *tp)
 static void rtl_hw_initialize(struct rtl8169_private *tp)
 {
 	switch (tp->mac_version) {
-	case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_53:
-		rtl8168ep_stop_cmac(tp);
-		fallthrough;
-	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48:
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_53:
 		rtl_hw_init_8168g(tp);
 		break;
 	case RTL_GIGA_MAC_VER_60 ... RTL_GIGA_MAC_VER_63:
@@ -5443,9 +5383,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 			    jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ?
 			    "ok" : "ko");
 
-	if (tp->dash_type != RTL_DASH_NONE) {
+	if (tp->dash_type == RTL_DASH_DP) {
 		netdev_info(dev, "DASH enabled\n");
-		rtl8168_driver_start(tp);
+		rtl8168dp_driver_start(tp);
 	}
 
 	if (pci_dev_run_wake(pdev))
Signature · 1 line
2.31.1
author
#2 lore raw

RFC PATCH 2/4 r8169: add type2 access functions

In reply to Hayes Wang

The type2 functions are used to access the OOB registers of RTL8111EP and RTL8111FP(RTL8117). The OOB registers are used to control the settings about dash.

---
 drivers/net/ethernet/realtek/r8169.h      |  3 ++
 drivers/net/ethernet/realtek/r8169_main.c | 39 +++++++++++++++++++++++
 2 files changed, 42 insertions(+)
drivers/net/ethernet/realtek/r8169.h +3 -0
index 8da4b66b71b5..7db647b4796f 100644
@@ -77,3 +77,6 @@ u16 rtl8168h_2_get_adc_bias_ioffset(struct rtl8169_private *tp);
 u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr);
 void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
 			 enum mac_version ver);
+
+u32 r8168_type2_read(struct rtl8169_private *tp, u32 addr);
+void r8168_type2_write(struct rtl8169_private *tp, u8 mask, u32 addr, u32 val);
drivers/net/ethernet/realtek/r8169_main.c +39 -0
index fd295bcd125c..eb56b91fe41b 100644
@@ -1071,6 +1071,45 @@ static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr)
 		RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0;
 }
 
+static u32 r8168_dash_adjust_addr(struct rtl8169_private *tp, u32 addr)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51:
+		return ((addr & 0xf000) << 8) | (addr & 0xfff);
+	case RTL_GIGA_MAC_VER_52 ... RTL_GIGA_MAC_VER_53:
+		return ((addr & 0xfff000) << 6) | (addr & 0xfff);
+	default:
+		WARN_ON_ONCE(1);
+		return (addr & 0xfff);
+	}
+}
+
+u32 r8168_type2_read(struct rtl8169_private *tp, u32 addr)
+{
+	u32 cmd = ERIAR_READ_CMD | ERIAR_OOB | ERIAR_MASK_1111;
+
+	cmd |= r8168_dash_adjust_addr(tp, addr);
+	RTL_W32(tp, ERIAR, cmd);
+
+	return rtl_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ?
+		RTL_R32(tp, ERIDR) : ~0;
+}
+
+void r8168_type2_write(struct rtl8169_private *tp, u8 mask, u32 addr, u32 val)
+{
+	u32 cmd = ERIAR_WRITE_CMD | ERIAR_OOB |
+		  ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT;
+
+	if (WARN(addr & 3 || !mask, "addr: 0x%x, mask: 0x%08x\n", addr, mask))
+		return;
+
+	RTL_W32(tp, ERIDR, val);
+	cmd |= r8168_dash_adjust_addr(tp, addr);
+	RTL_W32(tp, ERIAR, cmd);
+
+	rtl_loop_wait_low(tp, &rtl_eriar_cond, 100, 100);
+}
+
 static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u16 reg)
 {
 	RTL_W32(tp, OCPAR, 0x0fu << 12 | (reg & 0x0fff));
Signature · 1 line
2.31.1
author
#3 lore raw

RFC PATCH 3/4 r8169: support CMAC

In reply to Hayes Wang

Support CMAC for RTL8111EP and RTL8111FP.

CMAC is the major interface to configure the firmware when dash is enabled.

---
 drivers/net/ethernet/realtek/Makefile     |   2 +-
 drivers/net/ethernet/realtek/r8169.h      |   2 +
 drivers/net/ethernet/realtek/r8169_dash.c | 756 ++++++++++++++++++++++
 drivers/net/ethernet/realtek/r8169_dash.h |  22 +
 drivers/net/ethernet/realtek/r8169_main.c |  54 +-
 5 files changed, 824 insertions(+), 12 deletions(-)
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.c
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.h
drivers/net/ethernet/realtek/Makefile +1 -1
index 2e1d78b106b0..8f3372ee92ff 100644
@@ -6,5 +6,5 @@
 obj-$(CONFIG_8139CP) += 8139cp.o
 obj-$(CONFIG_8139TOO) += 8139too.o
 obj-$(CONFIG_ATP) += atp.o
-r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o
+r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o r8169_dash.o
 obj-$(CONFIG_R8169) += r8169.o
drivers/net/ethernet/realtek/r8169.h +2 -0
index 7db647b4796f..b75484a2a580 100644
@@ -78,5 +78,7 @@ u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr);
 void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
 			 enum mac_version ver);
 
+u32 r8168ep_ocp_read(struct rtl8169_private *tp, u16 reg);
 u32 r8168_type2_read(struct rtl8169_private *tp, u32 addr);
+void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data);
 void r8168_type2_write(struct rtl8169_private *tp, u8 mask, u32 addr, u32 val);
drivers/net/ethernet/realtek/r8169_dash.c new file +756 -0

756 lines not on this page · raw message

drivers/net/ethernet/realtek/r8169_dash.h new file +22 -0
new file mode 100644
index 000000000000..1e9a54a3df1b
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#define CMAC_BUF_SIZE		2048
+
+enum rtl_dash_type {
+	RTL_DASH_NONE,
+	RTL_DASH_DP,
+	RTL_DASH_EP,
+	RTL_DASH_FP,
+};
+
+struct rtl_dash;
+
+void rtl_release_dash(struct rtl_dash *dash);
+void rtl_dash_up(struct rtl_dash *dash);
+void rtl_dash_down(struct rtl_dash *dash);
+void rtl_dash_cmac_reset_indicate(struct rtl_dash *dash);
+void rtl_dash_interrupt(struct rtl_dash *dash);
+
+struct rtl_dash *rtl_request_dash(struct rtl8169_private *tp,
+				  struct pci_dev *pci_dev, enum mac_version ver,
+				  void __iomem *mmio_addr);
drivers/net/ethernet/realtek/r8169_main.c +43 -11

138 lines not on this page · raw message

Signature · 1 line
2.31.1
#4 lore raw

Re: [RFC PATCH 3/4] r8169: support CMAC

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Hayes,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on horms-ipvs/master]
[also build test WARNING on linus/master v5.16-rc3 next-20211129] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hayes-Wang/r8169-support-dash/20211129-181721
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20211129/202111292307.PquauVvv-lkp(a)intel.com/config)
compiler: powerpc-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/813fd268861808bfcf2eb07e84aca80e45c35d2f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Hayes-Wang/r8169-support-dash/20211129-181721
git checkout 813fd268861808bfcf2eb07e84aca80e45c35d2f
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/net/ethernet/realtek/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/net/ethernet/realtek/r8169_dash.c: In function 'rtl_cmac_enable':

>> drivers/net/ethernet/realtek/r8169_dash.c:459:45: warning: right shift count >= width of type [-Wshift-count-overflow]
     459 |                           dash->rx_desc_dma >> 32);
         |                                             ^~
   drivers/net/ethernet/realtek/r8169_dash.c:463:45: warning: right shift count >= width of type [-Wshift-count-overflow]
     463 |                           dash->tx_desc_dma >> 32);
         |                                             ^~

vim +459 drivers/net/ethernet/realtek/r8169_dash.c

395
396 static int rtl_cmac_enable(struct rtl_dash *dash)
397 {
398 u32 desc_addr;
399 int i;
400
401 for (i = 0; i < CMAC_DESC_NUM; i++) {
402 struct dash_tx_info *info = dash->tx_info + i;
403 struct cmac_desc *rx_desc = dash->rx_desc + i;
404 struct cmac_desc *tx_desc = dash->tx_desc + i;
405 struct device *d = &dash->pdev_cmac->dev;
406 dma_addr_t mapping;
407 u8 *addr;
408 u16 ops_rx, ops_tx;
409
410 info->buf = page_address(dash->tx_buf) + i * CMAC_BUF_SIZE;
411 info->len = 0;
412 info->ack = false;
413
414 addr = page_address(dash->rx_buf) + i * CMAC_BUF_SIZE;
415 mapping = dma_map_single(d, addr, CMAC_BUF_SIZE,
416 DMA_FROM_DEVICE);
417 if (unlikely(dma_mapping_error(d, mapping))) {
418 dev_err(d, "Failed to map RX DMA!\n");
419 rtl_dash_change_cmac_state(dash, OOB_CMD_CMAC_STOP);
420 return -ENOMEM;
421 }
422
423 rx_desc->dma_addr = cpu_to_le64(mapping);
424 rx_desc->length = CMAC_BUF_SIZE;
425 rx_desc->resv = 0;
426
427 if (i == (CMAC_DESC_NUM - 1)) {
428 ops_rx = RTXS_OWN | RTXS_EOR;
429 ops_tx = RTXS_FS | RTXS_LS | RTXS_EOR;
430 } else {
431 ops_rx = RTXS_OWN;
432 ops_tx = RTXS_FS | RTXS_LS;
433 }
434
435 rx_desc->status = cpu_to_le16(ops_rx);
436 tx_desc->status = cpu_to_le16(ops_tx);
437 }
438
439 dash->tx_free = 0;
440 dash->tx_used = 0;
441 dash->rx_cur = 0;
442
443 switch (dash->hw_dash_ver) {
444 case RTL_DASH_EP:
445 desc_addr = 0x890;
446 break;
447 case RTL_DASH_FP:
448 desc_addr = 0xf20090;
449 break;
450 default:
451 desc_addr = 0xf20090;
452 WARN_ON_ONCE(1);
453 break;
454 }
455
456 r8168_type2_write(dash->tp, 0xf, desc_addr,
457 dash->rx_desc_dma & DMA_BIT_MASK(32));
458 r8168_type2_write(dash->tp, 0xf, desc_addr + 4,

 > 459				  dash->rx_desc_dma >> 32);

460 r8168_type2_write(dash->tp, 0xf, desc_addr + 8,
461 dash->tx_desc_dma & DMA_BIT_MASK(32));
462 r8168_type2_write(dash->tp, 0xf, desc_addr + 12,
463 dash->tx_desc_dma >> 32);
464
465 RTL_CMAC_W8(dash, IBCR2, RTL_CMAC_R8(dash, IBCR2) | 0x01);
466 RTL_CMAC_W8(dash, IBCR0, RTL_CMAC_R8(dash, IBCR0) | 0x01);
467
468 tasklet_enable(&dash->tl);
469 dash->cmac_state = CMAC_STATE_RUNNING;
470
471 rtl_dash_intr_en(dash);
472
473 return 0;
474 }
475

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#5 lore raw

Re: [RFC PATCH 3/4] r8169: support CMAC

In reply to Hayes Wang
Quoted 116 lines · Hayes Wang

Support CMAC for RTL8111EP and RTL8111FP.

CMAC is the major interface to configure the firmware when dash is enabled.

---
 drivers/net/ethernet/realtek/Makefile     |   2 +-
 drivers/net/ethernet/realtek/r8169.h      |   2 +
 drivers/net/ethernet/realtek/r8169_dash.c | 756 ++++++++++++++++++++++
 drivers/net/ethernet/realtek/r8169_dash.h |  22 +
 drivers/net/ethernet/realtek/r8169_main.c |  54 +-
 5 files changed, 824 insertions(+), 12 deletions(-)
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.c
 create mode 100644 drivers/net/ethernet/realtek/r8169_dash.h
drivers/net/ethernet/realtek/Makefile +1 -1
index 2e1d78b106b0..8f3372ee92ff 100644
@@ -6,5 +6,5 @@
 obj-$(CONFIG_8139CP) += 8139cp.o
 obj-$(CONFIG_8139TOO) += 8139too.o
 obj-$(CONFIG_ATP) += atp.o
-r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o
+r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o r8169_dash.o
 obj-$(CONFIG_R8169) += r8169.o
drivers/net/ethernet/realtek/r8169.h +2 -0
index 7db647b4796f..b75484a2a580 100644
@@ -78,5 +78,7 @@ u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr);
 void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
 			 enum mac_version ver);
 
+u32 r8168ep_ocp_read(struct rtl8169_private *tp, u16 reg);
 u32 r8168_type2_read(struct rtl8169_private *tp, u32 addr);
+void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data);
 void r8168_type2_write(struct rtl8169_private *tp, u8 mask, u32 addr, u32 val);
drivers/net/ethernet/realtek/r8169_dash.c new file +71 -0
new file mode 100644
index 000000000000..acee7519e9f1
@@ -0,0 +1,756 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/pci.h>
+#include <linux/workqueue.h>
+#include <linux/rtnetlink.h>
+#include <linux/string.h>
+#include "r8169.h"
+#include "r8169_dash.h"
+
+#define IBCR0				0xf8
+#define IBCR2				0xf9
+#define IBIMR0				0xfa
+#define IBISR0				0xfb
+
+#define RTXS_LS				BIT(12)
+#define RTXS_FS				BIT(13)
+#define RTXS_EOR			BIT(14)
+#define RTXS_OWN			BIT(15)
+
+#define DASH_ISR_ROK			BIT(0)
+#define DASH_ISR_RDU			BIT(1)
+#define DASH_ISR_TOK			BIT(2)
+#define DASH_ISR_TDU			BIT(3)
+#define DASH_ISR_TX_DISABLE_IDLE	BIT(5)
+#define DASH_ISR_RX_DISABLE_IDLE	BIT(6)
+
+#define CMAC_DESC_NUM		4
+#define CMAC_DESC_SIZE		(CMAC_DESC_NUM * sizeof(struct cmac_desc))
+#define CMAC_TIMEOUT		(HZ * 5)
+
+#define OOB_CMD_DRIVER_START		0x05
+#define OOB_CMD_DRIVER_STOP		0x06
+#define OOB_CMD_CMAC_STOP		0x25
+#define OOB_CMD_CMAC_INIT		0x26
+#define OOB_CMD_CMAC_RESET		0x2a
+
+enum dash_cmac_state {
+	CMAC_STATE_STOP = 0,
+	CMAC_STATE_READY,
+	CMAC_STATE_RUNNING,
+};
+
+enum dash_flag {
+	DASH_FLAG_CHECK_CMAC = 0,
+	DASH_FLAG_MAX
+};
+
+#pragma pack(push)
+#pragma pack(1)
+
+struct cmac_desc {
+	__le16 length;
+	__le16 status;
+	__le32 resv;
+	__le64 dma_addr;
+};
+
+struct oob_hdr {
+	__le32 len;
+	u8 type;
+	u8 flag;
+	u8 host_req;
+	u8 res;
+};
+
+#pragma pack(pop)
+
+struct dash_tx_info {
+	u8 *buf;
+	u32 len;
+	bool ack;

drivers/net/ethernet/realtek/r8169_dash.c line 81

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_dash.c new file +10 -0
+};
+
+struct rtl_dash {
+	struct rtl8169_private *tp;
+	struct pci_dev *pdev_cmac;
+	void __iomem *cmac_ioaddr;
+	struct cmac_desc *tx_desc, *rx_desc;
+	struct page *tx_buf, *rx_buf;
+	struct dash_tx_info tx_info[CMAC_DESC_NUM];
+	struct tasklet_struct tl;

Please see the following in include/linux/interrupt.h:

/* Tasklets --- multithreaded analogue of BHs.

This API is deprecated. Please consider using threaded IRQs instead:
https://lore.kernel.org/lkml/[email protected]

author
#6 lore raw

RE: [RFC PATCH 3/4] r8169: support CMAC

Heiner Kallweit <[email protected]>

Quoted 2 lines

Sent: Tuesday, November 30, 2021 4:47 AM
To: Hayes Wang <[email protected]>; Jakub Kicinski <[email protected]>;

[...]

Quoted 11 lines

drivers/net/ethernet/realtek/r8169_dash.c line 81

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_dash.c new file +8 -0
+struct rtl_dash {
+	struct rtl8169_private *tp;
+	struct pci_dev *pdev_cmac;
+	void __iomem *cmac_ioaddr;
+	struct cmac_desc *tx_desc, *rx_desc;
+	struct page *tx_buf, *rx_buf;
+	struct dash_tx_info tx_info[CMAC_DESC_NUM];
+	struct tasklet_struct tl;

Please see the following in include/linux/interrupt.h:

Quoted 3 lines

/* Tasklets --- multithreaded analogue of BHs.

This API is deprecated. Please consider using threaded IRQs instead:

How about replacing the tasklet with work?
It seems that the bottom half of threaded IRQ
is the work, too.

Best Regards,
Hayes

maintainer
#7 lore raw

Re: [RFC PATCH 3/4] r8169: support CMAC

Quoted 15 lines · Hayes Wang

Heiner Kallweit <[email protected]>

Quoted 2 lines

Sent: Tuesday, November 30, 2021 4:47 AM
To: Hayes Wang <[email protected]>; Jakub Kicinski <[email protected]>;

[...]

Quoted 11 lines

drivers/net/ethernet/realtek/r8169_dash.c line 81

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_dash.c new file +8 -0
+struct rtl_dash {
+	struct rtl8169_private *tp;
+	struct pci_dev *pdev_cmac;
+	void __iomem *cmac_ioaddr;
+	struct cmac_desc *tx_desc, *rx_desc;
+	struct page *tx_buf, *rx_buf;
+	struct dash_tx_info tx_info[CMAC_DESC_NUM];
+	struct tasklet_struct tl;

Please see the following in include/linux/interrupt.h:

Quoted 8 lines
Quoted 3 lines

/* Tasklets --- multithreaded analogue of BHs.

This API is deprecated. Please consider using threaded IRQs instead:

How about replacing the tasklet with work?
It seems that the bottom half of threaded IRQ
is the work, too.

Right, it's running in process context. It's to a certain extent comparable with the efforts to move NAPI processing from softirg context to threads.

Quoted 4 lines

Best Regards,
Hayes

author
#8 lore raw

RFC PATCH 4/4 r8169: add sysfs for dash

In reply to Hayes Wang

Add the sysfs for dash. Then the application could configure the firmware through them.

---
 drivers/net/ethernet/realtek/r8169_dash.c | 131 +++++++++++++++
 drivers/net/ethernet/realtek/r8169_dash.h |   8 +
 drivers/net/ethernet/realtek/r8169_main.c | 188 +++++++++++++++++++++-
 3 files changed, 326 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_dash.c +131 -0
index acee7519e9f1..197feb2c4a23 100644
@@ -754,3 +754,134 @@ void rtl_dash_interrupt(struct rtl_dash *dash)
 	tasklet_schedule(&dash->tl);
 }
 
+int rtl_dash_to_fw(struct rtl_dash *dash, u8 *src, int size)
+{
+	int ret;
+	long t;
+
+	if (dash->cmac_state != CMAC_STATE_RUNNING)
+		return -ENETDOWN;
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, NULL, 0);
+	spin_unlock_bh(&dash->cmac_lock);
+	if (ret < 0)
+		return -EUCLEAN;
+
+	reinit_completion(&dash->cmac_tx);
+	reinit_completion(&dash->fw_ack);
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = cmac_start_xmit(dash, src, size, false);
+	spin_unlock_bh(&dash->cmac_lock);
+
+	if (ret < 0)
+		goto err;
+
+	t = wait_for_completion_interruptible_timeout(&dash->cmac_tx,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		ret = -ETIMEDOUT;
+		dev_err(&dash->pdev_cmac->dev, "CMAC tx timeout\n");
+		goto err;
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "CMAC tx fail %ld\n", t);
+		goto err;
+	}
+
+	t = wait_for_completion_interruptible_timeout(&dash->fw_ack,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		ret = -ETIMEDOUT;
+		dev_err(&dash->pdev_cmac->dev, "FW ACK timeout\n");
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "FW ACK fail %ld\n", t);
+	}
+
+err:
+	return ret;
+}
+
+int rtl_dash_from_fw(struct rtl_dash *dash, u8 *src, int size)
+{
+	int ret;
+	long t;
+
+	if (dash->cmac_state != CMAC_STATE_RUNNING)
+		return -ENETDOWN;
+
+	reinit_completion(&dash->cmac_rx);
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, src, size);
+	spin_unlock_bh(&dash->cmac_lock);
+
+	if (ret)
+		goto out;
+
+	t = wait_for_completion_interruptible_timeout(&dash->cmac_rx,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		dev_warn(&dash->pdev_cmac->dev, "CMAC data timeout\n");
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "Wait CMAC data fail %ld\n", t);
+		goto out;
+	}
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, src, size);
+	spin_unlock_bh(&dash->cmac_lock);
+
+out:
+	return ret;
+}
+
+void rtl_dash_set_ap_ready(struct rtl_dash *dash, bool enable)
+{
+	struct rtl8169_private *tp = dash->tp;
+	u32 data;
+
+	data = r8168ep_ocp_read(tp, 0x124);
+	if (enable)
+		data |= BIT(1);
+	else
+		data &= ~BIT(1);
+	r8168ep_ocp_write(tp, 0x1, 0x124, data);
+}
+
+bool rtl_dash_get_ap_ready(struct rtl_dash *dash)
+{
+	struct rtl8169_private *tp = dash->tp;
+
+	if (r8168ep_ocp_read(tp, 0x124) & BIT(1))
+		return true;
+	else
+		return false;
+}
+
+ssize_t rtl_dash_info(struct rtl_dash *dash, char *buf)
+{
+	struct rtl8169_private *tp = dash->tp;
+	char *dest = buf;
+	int size;
+	u32 data;
+
+	data = r8168ep_ocp_read(tp, 0x120);
+	size = sprintf(dest, "FW_VERSION=0x%08X\n", data);
+	if (size > 0)
+		dest += size;
+	else
+		return size;
+
+	data = r8168ep_ocp_read(tp, 0x174);
+	size = sprintf(dest, "FW_BUILD=0x%08X\n", data);
+	if (size > 0)
+		dest += size;
+	else
+		return size;
+
+	return strlen(buf) + 1;
+}
drivers/net/ethernet/realtek/r8169_dash.h +8 -0
index 1e9a54a3df1b..b33f3adeef13 100644
@@ -16,6 +16,14 @@ void rtl_dash_up(struct rtl_dash *dash);
 void rtl_dash_down(struct rtl_dash *dash);
 void rtl_dash_cmac_reset_indicate(struct rtl_dash *dash);
 void rtl_dash_interrupt(struct rtl_dash *dash);
+void rtl_dash_set_ap_ready(struct rtl_dash *dash, bool enable);
+
+int rtl_dash_to_fw(struct rtl_dash *dash, u8 *src, int size);
+int rtl_dash_from_fw(struct rtl_dash *dash, u8 *src, int size);
+
+bool rtl_dash_get_ap_ready(struct rtl_dash *dash);
+
+ssize_t rtl_dash_info(struct rtl_dash *dash, char *buf);
 
 struct rtl_dash *rtl_request_dash(struct rtl8169_private *tp,
 				  struct pci_dev *pci_dev, enum mac_version ver,
drivers/net/ethernet/realtek/r8169_main.c +187 -1

218 lines not on this page · raw message

Signature · 1 line
2.31.1
maintainer
#9 lore raw

Re: [RFC PATCH 4/4] r8169: add sysfs for dash

Quoted 388 lines · Hayes Wang

Add the sysfs for dash. Then the application could configure the firmware through them.

---
 drivers/net/ethernet/realtek/r8169_dash.c | 131 +++++++++++++++
 drivers/net/ethernet/realtek/r8169_dash.h |   8 +
 drivers/net/ethernet/realtek/r8169_main.c | 188 +++++++++++++++++++++-
 3 files changed, 326 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_dash.c +131 -0
index acee7519e9f1..197feb2c4a23 100644
@@ -754,3 +754,134 @@ void rtl_dash_interrupt(struct rtl_dash *dash)
 	tasklet_schedule(&dash->tl);
 }
 
+int rtl_dash_to_fw(struct rtl_dash *dash, u8 *src, int size)
+{
+	int ret;
+	long t;
+
+	if (dash->cmac_state != CMAC_STATE_RUNNING)
+		return -ENETDOWN;
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, NULL, 0);
+	spin_unlock_bh(&dash->cmac_lock);
+	if (ret < 0)
+		return -EUCLEAN;
+
+	reinit_completion(&dash->cmac_tx);
+	reinit_completion(&dash->fw_ack);
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = cmac_start_xmit(dash, src, size, false);
+	spin_unlock_bh(&dash->cmac_lock);
+
+	if (ret < 0)
+		goto err;
+
+	t = wait_for_completion_interruptible_timeout(&dash->cmac_tx,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		ret = -ETIMEDOUT;
+		dev_err(&dash->pdev_cmac->dev, "CMAC tx timeout\n");
+		goto err;
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "CMAC tx fail %ld\n", t);
+		goto err;
+	}
+
+	t = wait_for_completion_interruptible_timeout(&dash->fw_ack,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		ret = -ETIMEDOUT;
+		dev_err(&dash->pdev_cmac->dev, "FW ACK timeout\n");
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "FW ACK fail %ld\n", t);
+	}
+
+err:
+	return ret;
+}
+
+int rtl_dash_from_fw(struct rtl_dash *dash, u8 *src, int size)
+{
+	int ret;
+	long t;
+
+	if (dash->cmac_state != CMAC_STATE_RUNNING)
+		return -ENETDOWN;
+
+	reinit_completion(&dash->cmac_rx);
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, src, size);
+	spin_unlock_bh(&dash->cmac_lock);
+
+	if (ret)
+		goto out;
+
+	t = wait_for_completion_interruptible_timeout(&dash->cmac_rx,
+						      CMAC_TIMEOUT);
+	if (!t) {
+		dev_warn(&dash->pdev_cmac->dev, "CMAC data timeout\n");
+	} else if (t < 0) {
+		ret = t;
+		dev_err(&dash->pdev_cmac->dev, "Wait CMAC data fail %ld\n", t);
+		goto out;
+	}
+
+	spin_lock_bh(&dash->cmac_lock);
+	ret = dash_rx_data(dash, src, size);
+	spin_unlock_bh(&dash->cmac_lock);
+
+out:
+	return ret;
+}
+
+void rtl_dash_set_ap_ready(struct rtl_dash *dash, bool enable)
+{
+	struct rtl8169_private *tp = dash->tp;
+	u32 data;
+
+	data = r8168ep_ocp_read(tp, 0x124);
+	if (enable)
+		data |= BIT(1);
+	else
+		data &= ~BIT(1);
+	r8168ep_ocp_write(tp, 0x1, 0x124, data);
+}
+
+bool rtl_dash_get_ap_ready(struct rtl_dash *dash)
+{
+	struct rtl8169_private *tp = dash->tp;
+
+	if (r8168ep_ocp_read(tp, 0x124) & BIT(1))
+		return true;
+	else
+		return false;
+}
+
+ssize_t rtl_dash_info(struct rtl_dash *dash, char *buf)
+{
+	struct rtl8169_private *tp = dash->tp;
+	char *dest = buf;
+	int size;
+	u32 data;
+
+	data = r8168ep_ocp_read(tp, 0x120);
+	size = sprintf(dest, "FW_VERSION=0x%08X\n", data);
+	if (size > 0)
+		dest += size;
+	else
+		return size;
+
+	data = r8168ep_ocp_read(tp, 0x174);
+	size = sprintf(dest, "FW_BUILD=0x%08X\n", data);
+	if (size > 0)
+		dest += size;
+	else
+		return size;
+
+	return strlen(buf) + 1;
+}
drivers/net/ethernet/realtek/r8169_dash.h +8 -0
index 1e9a54a3df1b..b33f3adeef13 100644
@@ -16,6 +16,14 @@ void rtl_dash_up(struct rtl_dash *dash);
 void rtl_dash_down(struct rtl_dash *dash);
 void rtl_dash_cmac_reset_indicate(struct rtl_dash *dash);
 void rtl_dash_interrupt(struct rtl_dash *dash);
+void rtl_dash_set_ap_ready(struct rtl_dash *dash, bool enable);
+
+int rtl_dash_to_fw(struct rtl_dash *dash, u8 *src, int size);
+int rtl_dash_from_fw(struct rtl_dash *dash, u8 *src, int size);
+
+bool rtl_dash_get_ap_ready(struct rtl_dash *dash);
+
+ssize_t rtl_dash_info(struct rtl_dash *dash, char *buf);
 
 struct rtl_dash *rtl_request_dash(struct rtl8169_private *tp,
 				  struct pci_dev *pci_dev, enum mac_version ver,
drivers/net/ethernet/realtek/r8169_main.c +185 -1
index 83da05e5769e..4c8439d3ae4d 100644
@@ -4654,6 +4654,184 @@ static int r8169_phy_connect(struct rtl8169_private *tp)
 	return 0;
 }
 
+static ssize_t
+information_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+	ssize_t ret;
+
+	if (rtnl_lock_killable())
+		return -EINTR;
+
+	ret = rtl_dash_info(tp->rtl_dash, buf);
+
+	rtnl_unlock();
+
+	return ret;
+}
+
+static DEVICE_ATTR_RO(information);
+
+static ssize_t
+ap_ready_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+	bool enable;
+
+	if (rtnl_lock_killable())
+		return -EINTR;
+
+	enable = rtl_dash_get_ap_ready(tp->rtl_dash);
+
+	rtnl_unlock();
+
+	if (enable)
+		strcat(buf, "enable\n");
+	else
+		strcat(buf, "disable\n");
+
+	return (strlen(buf) + 1);
+}
+
+static ssize_t ap_ready_store(struct device *dev, struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+	ssize_t len = strlen(buf);
+	bool enable;
+
+	if (buf[len - 1] <= ' ')
+		len--;
+
+	/* strlen("enable") = 6, and strlen("disable") = 7 */
+	if (len != 6 && len != 7)
+		return -EINVAL;
+
+	if (len == 6 && !strncmp(buf, "enable", 6))
+		enable = true;
+	else if (len == 7 && !strncmp(buf, "disable", 7))
+		enable = false;
+	else
+		return -EINVAL;
+
+	if (rtnl_lock_killable())
+		return -EINTR;
+
+	rtl_dash_set_ap_ready(tp->rtl_dash, enable);
+
+	rtnl_unlock();
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(ap_ready);
+
+static struct attribute *rtl_dash_attrs[] = {
+	&dev_attr_ap_ready.attr,
+	&dev_attr_information.attr,
+	NULL
+};
+
+static ssize_t cmac_data_write(struct file *fp, struct kobject *kobj,
+			       struct bin_attribute *attr, char *buf,
+			       loff_t offset, size_t size)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+	int ret;
+
+	if (IS_ERR_OR_NULL(tp->rtl_dash))
+		return -ENODEV;
+
+	if (size > CMAC_BUF_SIZE)
+		return -EFBIG;
+
+	if (offset)
+		return -EINVAL;
+
+	if (rtnl_lock_killable())
+		return -EINTR;
+
+	ret = rtl_dash_to_fw(tp->rtl_dash, buf, size);
+
+	rtnl_unlock();
+
+	return ret;
+}
+
+static ssize_t cmac_data_read(struct file *fp, struct kobject *kobj,
+			      struct bin_attribute *attr, char *buf,
+			      loff_t offset, size_t size)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+	int ret;
+
+	if (IS_ERR_OR_NULL(tp->rtl_dash))
+		return -ENODEV;
+
+	if (offset)
+		return -EINVAL;
+
+	if (rtnl_lock_killable())
+		return -EINTR;
+
+	ret = rtl_dash_from_fw(tp->rtl_dash, buf, size);
+
+	rtnl_unlock();
+
+	return ret;
+}
+
+static BIN_ATTR_RW(cmac_data, CMAC_BUF_SIZE);
+
+static struct bin_attribute *rtl_dash_bin_attrs[] = {
+	&bin_attr_cmac_data,
+	NULL
+};
+
+static umode_t is_dash_visible(struct kobject *kobj, struct attribute *attr,
+			       int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+
+	if (IS_ERR_OR_NULL(tp->rtl_dash))
+		return 0;
+
+	if (attr == &dev_attr_information.attr)
+		return 0440;
+
+	return 0660;
+}
+
+static umode_t is_dash_bin_visible(struct kobject *kobj,
+				   struct bin_attribute *attr, int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct net_device *net = to_net_dev(dev);
+	struct rtl8169_private *tp = netdev_priv(net);
+
+	if (IS_ERR_OR_NULL(tp->rtl_dash))
+		return 0;
+
+	return 0660;
+}
+
+static struct attribute_group rtl_dash_grp = {
+	.name = "dash",
+	.is_visible	= is_dash_visible,
+	.attrs		= rtl_dash_attrs,
+	.is_bin_visible = is_dash_bin_visible,
+	.bin_attrs = rtl_dash_bin_attrs,
+};
+
 static void rtl8169_dash_release(struct rtl8169_private *tp)
 {
 	if (tp->dash_type > RTL_DASH_DP) {
@@ -4717,6 +4895,8 @@ static int rtl8169_close(struct net_device *dev)
 
 	phy_disconnect(tp->phydev);
 
+	sysfs_remove_group(&dev->dev.kobj, &rtl_dash_grp);
+
 	dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
 			  tp->RxPhyAddr);
 	dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
@@ -4775,6 +4955,10 @@ static int rtl_open(struct net_device *dev)
 		if (retval)
 			goto err_release_fw_2;
 
+		retval = sysfs_create_group(&dev->dev.kobj, &rtl_dash_grp);
+		if (retval < 0)
+			goto err_release_dash;
+
 		tp->irq_mask |= DashCMAC | DashIntr;
 	}
 
@@ -4782,7 +4966,7 @@ static int rtl_open(struct net_device *dev)
 	retval = request_irq(pci_irq_vector(pdev, 0), rtl8169_interrupt,
 			     irqflags, dev->name, tp);
 	if (retval < 0)
-		goto err_release_dash;
+		goto err_remove_group;
 
 	retval = r8169_phy_connect(tp);
 	if (retval)

drivers/net/ethernet/realtek/r8169_main.c static int rtl_open(struct net_device *dev) · line 4989

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -0
@@ -4798,6 +4982,8 @@ static int rtl_open(struct net_device *dev)
 
 err_free_irq:
 	free_irq(pci_irq_vector(pdev, 0), tp);
+err_remove_group:
+	sysfs_remove_group(&dev->dev.kobj, &rtl_dash_grp);
 err_release_dash:
 	rtl8169_dash_release(tp);
 err_release_fw_2:

With regard to sysfs usage:
- attributes should be documented under /Documentation/ABI/testing
- attributes should be defined statically (driver.dev_groups instead of sysfs_create_group)
- for printing info there's sysfs_emit()
- is really RTNL needed? Or would a lighter mutex do?

author
#10 lore raw

RE: [RFC PATCH 4/4] r8169: add sysfs for dash

Heiner Kallweit <[email protected]>

Quoted 1 line

Sent: Friday, December 3, 2021 11:15 PM

[...]

Quoted 6 lines

With regard to sysfs usage:
- attributes should be documented under /Documentation/ABI/testing
- attributes should be defined statically (driver.dev_groups instead of sysfs_create_group)
- for printing info there's sysfs_emit()
- is really RTNL needed? Or would a lighter mutex do?

In addition to protect the critical section, RTNL is used to avoid calling close() before CMAC is finished. The transfer of CMAC may contain several steps. And close() would disable CMAC. I don't wish the CMAC stays at strange state. It may influence the firmware or hardware. Besides, I find the original driver only use RTNL to protect critical section. Is there a better way for it?

Best Regards,
Hayes

maintainer
#11 lore raw

Re: [RFC PATCH 4/4] r8169: add sysfs for dash

Quoted 10 lines · Hayes Wang

Heiner Kallweit <[email protected]>

Quoted 1 line

Sent: Friday, December 3, 2021 11:15 PM

[...]

Quoted 6 lines

With regard to sysfs usage:
- attributes should be documented under /Documentation/ABI/testing
- attributes should be defined statically (driver.dev_groups instead of sysfs_create_group)
- for printing info there's sysfs_emit()
- is really RTNL needed? Or would a lighter mutex do?

Quoted 7 lines

In addition to protect the critical section, RTNL is used to avoid calling close() before CMAC is finished. The transfer of CMAC may contain several steps. And close() would disable CMAC. I don't wish the CMAC stays at strange state. It may influence the firmware or hardware. Besides, I find the original driver only use RTNL to protect critical section. Is there a better way for it?

The main issue I see is that you call rtl_dash_from_fw() under RTNL, and this function may sleep up to 5s. Holding a system-wide mutex for that long isn't too nice.

In rtl_dash_info() you just print FW version and build number. Wouldn't it be sufficient to print this info once to syslog instead of exporting it via sysfs?

Quoted 3 lines

Best Regards,
Hayes

author
#12 lore raw

RE: [RFC PATCH 4/4] r8169: add sysfs for dash

Heiner Kallweit <[email protected]>

Quoted 1 line

Sent: Tuesday, December 7, 2021 3:38 PM

[...]

Quoted 11 lines
Quoted 7 lines

In addition to protect the critical section, RTNL is used to avoid calling close() before CMAC is finished. The transfer of CMAC may contain several steps. And close() would disable CMAC. I don't wish the CMAC stays at strange state. It may influence the firmware or hardware. Besides, I find the original driver only use RTNL to protect critical section. Is there a better way for it?

The main issue I see is that you call rtl_dash_from_fw() under RTNL, and this function may sleep up to 5s. Holding a system-wide mutex for that long isn't too nice.

I would think if there is a better way to replace current one. Thanks.

Quoted 3 lines

In rtl_dash_info() you just print FW version and build number. Wouldn't it be sufficient to print this info once to syslog instead of exporting it via sysfs?

It is the information which our user space tool need. I think it would be replaced with devlink param.

Best Regards,
Hayes

maintainer
#13 lore raw
In reply to Hayes Wang
Quoted 2 lines · On Mon, 29 Nov 2021 18:13:11 +0800 Hayes Wang wrote:

These patches are used to support dash for RTL8111EP and RTL8111FP(RTL81117).

If I understand correctly DASH is a DMTF standard for remote control.

Since it's a standard I think we should have a common way of configuring it across drivers. Is enable/disable the only configuration that we will need?

We don't use sysfs too much these days, can we move the knob to devlink, please? (If we only need an on/off switch generic devlink param should be fine).

author
#14 lore raw

Jakub Kicinski <[email protected]>

Quoted 11 lines

Sent: Tuesday, November 30, 2021 2:00 AM
Subject: Re: [RFC PATCH 0/4] r8169: support dash

Quoted 2 lines · On Mon, 29 Nov 2021 18:13:11 +0800 Hayes Wang wrote:

These patches are used to support dash for RTL8111EP and RTL8111FP(RTL81117).

If I understand correctly DASH is a DMTF standard for remote control.

Since it's a standard I think we should have a common way of configuring it across drivers.

Excuse me. I am not familiar with it.
What document or sample code could I start?

Quoted 2 lines

Is enable/disable the only configuration
that we will need?

I don't think I could answer it before I understand the above way you mentioned.

Quoted 3 lines

We don't use sysfs too much these days, can we move the knob to devlink, please? (If we only need an on/off switch generic devlink param should be fine).

Thanks. I would study devlink.

Best Regards,
Hayes

maintainer
#15 lore raw
Quoted 19 lines · On Wed, 1 Dec 2021 02:57:00 +0000 Hayes Wang wrote:

Jakub Kicinski <[email protected]>

Quoted 11 lines

Sent: Tuesday, November 30, 2021 2:00 AM
Subject: Re: [RFC PATCH 0/4] r8169: support dash

Quoted 2 lines · On Mon, 29 Nov 2021 18:13:11 +0800 Hayes Wang wrote:

These patches are used to support dash for RTL8111EP and RTL8111FP(RTL81117).

If I understand correctly DASH is a DMTF standard for remote control.

Since it's a standard I think we should have a common way of configuring it across drivers.

Excuse me. I am not familiar with it.
What document or sample code could I start?

Quoted 2 lines

Is enable/disable the only configuration
that we will need?

Quoted 8 lines

I don't think I could answer it before I understand the above way you mentioned.

Quoted 3 lines

We don't use sysfs too much these days, can we move the knob to devlink, please? (If we only need an on/off switch generic devlink param should be fine).

Thanks. I would study devlink.

I'm not sure how relevant it will be to you but this is the documentation we have:

https://www.kernel.org/doc/html/latest/networking/devlink/index.html
https://www.kernel.org/doc/html/latest/networking/devlink/devlink-params.html

You'll need to add a generic parameter (define + a short description) like 325e0d0aa683 ("devlink: Add 'enable_iwarp' generic device param")

In terms of driver changes I think the most relevant example to you will be:

drivers/net/ethernet/ti/cpsw_new.c

You need to call devlink_alloc(), devlink_register and devlink_params_register() (and the inverse functions).

author
#16 lore raw

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Wednesday, December 1, 2021 11:09 AM

[...]

Quoted 10 lines

I'm not sure how relevant it will be to you but this is the documentation we have:

https://www.kernel.org/doc/html/latest/networking/devlink/index.html
https://www.kernel.org/doc/html/latest/networking/devlink/devlink-params.ht
ml

You'll need to add a generic parameter (define + a short description) like 325e0d0aa683 ("devlink: Add 'enable_iwarp' generic device param")

Quoted 7 lines

In terms of driver changes I think the most relevant example to you will be:

drivers/net/ethernet/ti/cpsw_new.c

You need to call devlink_alloc(), devlink_register and devlink_params_register() (and the inverse functions).

I have studied the devlink briefly.

However, I find some problems. First, our settings are dependent on the design of both the hardware and firmware. That is, I don't think the others need to do the settings as the same as us. The devlink seems to let everyone could use the same command to do the same setting. However, most of our settings are useless for the other devices.

Second, according to the design of our CMAC, the application has to read and write data with variable length from/to the firmware. Each custom has his own requests. Therefore, our customs would get different firmware with different behavior. Only the application and the firmware know how to communicate with each other. The driver only passes the data between them. Like the Ethernet driver, it doesn't need to know the contend of the packet. I could implement the CMAC through sysfs, but I don't know how to do by devlink.

In brief, CMAC is our major method to configure the firmware and get response from the firmware. Except for certain information, the other settings are not standard and useless for the other vendors.

Is the devlink the only method I could use? Actually, we use IOCTL now. We wish to convert it to sysfs for upstream driver.

Best Regards,
Hayes

maintainer
#17 lore raw
Quoted 52 lines · On Fri, 3 Dec 2021 07:57:08 +0000 Hayes Wang wrote:

Jakub Kicinski <[email protected]>

Quoted 10 lines

I'm not sure how relevant it will be to you but this is the documentation we have:

https://www.kernel.org/doc/html/latest/networking/devlink/index.html
https://www.kernel.org/doc/html/latest/networking/devlink/devlink-params.ht
ml

You'll need to add a generic parameter (define + a short description) like 325e0d0aa683 ("devlink: Add 'enable_iwarp' generic device param")

Quoted 7 lines

In terms of driver changes I think the most relevant example to you will be:

drivers/net/ethernet/ti/cpsw_new.c

You need to call devlink_alloc(), devlink_register and devlink_params_register() (and the inverse functions).

I have studied the devlink briefly.

However, I find some problems. First, our settings are dependent on the design of both the hardware and firmware. That is, I don't think the others need to do the settings as the same as us. The devlink seems to let everyone could use the same command to do the same setting. However, most of our settings are useless for the other devices.

Second, according to the design of our CMAC, the application has to read and write data with variable length from/to the firmware. Each custom has his own requests. Therefore, our customs would get different firmware with different behavior. Only the application and the firmware know how to communicate with each other. The driver only passes the data between them. Like the Ethernet driver, it doesn't need to know the contend of the packet. I could implement the CMAC through sysfs, but I don't know how to do by devlink.

In brief, CMAC is our major method to configure the firmware and get response from the firmware. Except for certain information, the other settings are not standard and useless for the other vendors.

Quoted 3 lines

Is the devlink the only method I could use? Actually, we use IOCTL now. We wish to convert it to sysfs for upstream driver.

Ah, I've only spotted the enable/disable knob in the patch. If you're exchanging arbitrary binary data with the FW we can't help you. It's not going to fly upstream.

#18 lore raw

From: Jakub Kicinski <[email protected]>
Date: Fri, 3 Dec 2021 07:04:10 -0800

Quoted 53 lines · On Fri, 3 Dec 2021 07:57:08 +0000 Hayes Wang wrote:
Quoted 52 lines

Jakub Kicinski <[email protected]>

Quoted 10 lines

I'm not sure how relevant it will be to you but this is the documentation we have:

https://www.kernel.org/doc/html/latest/networking/devlink/index.html
https://www.kernel.org/doc/html/latest/networking/devlink/devlink-params.ht
ml

You'll need to add a generic parameter (define + a short description) like 325e0d0aa683 ("devlink: Add 'enable_iwarp' generic device param")

Quoted 7 lines

In terms of driver changes I think the most relevant example to you will be:

drivers/net/ethernet/ti/cpsw_new.c

You need to call devlink_alloc(), devlink_register and devlink_params_register() (and the inverse functions).

I have studied the devlink briefly.

However, I find some problems. First, our settings are dependent on the design of both the hardware and firmware. That is, I don't think the others need to do the settings as the same as us. The devlink seems to let everyone could use the same command to do the same setting. However, most of our settings are useless for the other devices.

Second, according to the design of our CMAC, the application has to read and write data with variable length from/to the firmware. Each custom has his own requests. Therefore, our customs would get different firmware with different behavior. Only the application and the firmware know how to communicate with each other. The driver only passes the data between them. Like the Ethernet driver, it doesn't need to know the contend of the packet. I could implement the CMAC through sysfs, but I don't know how to do by devlink.

In brief, CMAC is our major method to configure the firmware and get response from the firmware. Except for certain information, the other settings are not standard and useless for the other vendors.

Quoted 7 lines
Quoted 3 lines

Is the devlink the only method I could use? Actually, we use IOCTL now. We wish to convert it to sysfs for upstream driver.

Ah, I've only spotted the enable/disable knob in the patch. If you're exchanging arbitrary binary data with the FW we can't help you. It's not going to fly upstream.

Uhm. I'm not saying sysfs is a proper way to do that, not at all, buuut...
We have a ton of different subsystems providing a communication channel between userspace and HW/FW. Chardevices all over the tree, highly used rpmsg for remoteproc, uio. We have register dump in Ethtool, as well as get/set for EEPROM, I'd count them as well.
So it probably isn't a bad idea to provide some standard API for network drivers to talk to HW/FW from userspace, like get/set or rx/tx (when having enough caps for sure)? It could be Devlink ops or Ethtool ops, the latter fits more to me.

Al

maintainer
#19 lore raw
Quoted 9 lines · On Sat, 4 Dec 2021 02:08:29 +0100 Alexander Lobakin wrote:
Quoted 3 lines

Ah, I've only spotted the enable/disable knob in the patch. If you're exchanging arbitrary binary data with the FW we can't help you. It's not going to fly upstream.

Uhm. I'm not saying sysfs is a proper way to do that, not at all, buuut...
We have a ton of different subsystems providing a communication channel between userspace and HW/FW. Chardevices all over the tree, highly used rpmsg for remoteproc, uio.

Not in Ethernet.

Quoted 1 line

We have register dump in Ethtool,

Read only.

Quoted 1 line

as well as get/set for EEPROM, I'd count them as well.

EEPROM writes are supposed to update FW images, not send random messages.

Quoted 4 lines

So it probably isn't a bad idea to provide some standard API for network drivers to talk to HW/FW from userspace, like get/set or rx/tx (when having enough caps for sure)? It could be Devlink ops or Ethtool ops, the latter fits more to me.

I'm not saying it's wrong to merge shim drivers into the kernel and let the user space talk to device FW. I'm saying it's counter to what netdev's policy has always been and counter to my personal interests.

What is a standard API for custom, proprietary FW message interface? We want standards at a functional level. Once you open up a raw FW write interface there is no policing of what goes thru it.

I CCed Intel since you also have the (infamous) ME, but I never heard of the need to communicate from the OS to the ME via the netdev driver... Not sure why things are different for Realtek.

author
#20 lore raw
In reply to Jakub Kicinski

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Friday, December 3, 2021 11:04 PM

[...]

Quoted 3 lines

Ah, I've only spotted the enable/disable knob in the patch. If you're exchanging arbitrary binary data with the FW we can't help you. It's not going to fly upstream.

How is it that we only provide certain basic settings, such as IPv4 address, IPv6 address, and so on? Then, they are not the arbitrary binary data.

Could devlink param be used for more than 4 bytes settings? At least the IPv6 address is longer.

Besides, we need the information of SMBIOS which could be 4K ~ 8K bytes data. Is there any way we could transmit it to firmware?

Best Regards,
Hayes

maintainer
#21 lore raw
Quoted 11 lines · On Tue, 7 Dec 2021 07:28:02 +0000 Hayes Wang wrote:

Jakub Kicinski <[email protected]>

Quoted 3 lines

Ah, I've only spotted the enable/disable knob in the patch. If you're exchanging arbitrary binary data with the FW we can't help you. It's not going to fly upstream.

How is it that we only provide certain basic settings, such as IPv4 address, IPv6 address, and so on? Then, they are not the arbitrary binary data.

Could devlink param be used for more than 4 bytes settings? At least the IPv6 address is longer.

We can add a new devlink sub-command and driver callback in that case.

Quoted 3 lines

Besides, we need the information of SMBIOS which could be 4K ~ 8K bytes data. Is there any way we could transmit it to firmware?

Is structure of that data defined by some DMTF standard?

author
#22 lore raw

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Wednesday, December 8, 2021 12:21 PM

[...]

Quoted 4 lines
Quoted 2 lines

Could devlink param be used for more than 4 bytes settings? At least the IPv6 address is longer.

We can add a new devlink sub-command and driver callback in that case.

Excuse me. Do you mean someone will add it? Then, I could use it. Or, I have to add it.

Quoted 5 lines
Quoted 3 lines

Besides, we need the information of SMBIOS which could be 4K ~ 8K bytes data. Is there any way we could transmit it to firmware?

Is structure of that data defined by some DMTF standard?

Yes.

Best Regards,
Hayes

maintainer
#23 lore raw
Quoted 9 lines · On Wed, 8 Dec 2021 07:53:28 +0000 Hayes Wang wrote:

Jakub Kicinski <[email protected]>

Quoted 5 lines

Sent: Wednesday, December 8, 2021 12:21 PM

Quoted 2 lines

Could devlink param be used for more than 4 bytes settings? At least the IPv6 address is longer.

We can add a new devlink sub-command and driver callback in that case.

Excuse me. Do you mean someone will add it? Then, I could use it. Or, I have to add it.

You'd need to write all the code.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Besides, we need the information of SMBIOS which could be 4K ~ 8K bytes data. Is there any way we could transmit it to firmware?

Is structure of that data defined by some DMTF standard?

Yes.

That's good, as long as the kernel parses and validates the messages the exact interface to user space does not matter that much.

author
#24 lore raw

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Thursday, December 9, 2021 5:38 AM

[...]

Quoted 4 lines
Quoted 2 lines

Excuse me. Do you mean someone will add it? Then, I could use it. Or, I have to add it.

You'd need to write all the code.

I need more time to think how to do.
Thanks.

Best Regards,
Hayes