From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932760AbdGXPp0 (ORCPT ); Mon, 24 Jul 2017 11:45:26 -0400 Received: from mail1.bemta5.messagelabs.com ([195.245.231.146]:35133 "EHLO mail1.bemta5.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756691AbdGXPpP (ORCPT ); Mon, 24 Jul 2017 11:45:15 -0400 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRWlGSWpSXmKPExsVyeL7SP11OsbJ Igzsv2CzO3z3EbPHkQDujxZzzLSwWv94dYbdYNXUni8XCtiUsFpd3zWGzOLZAzGLWkf1MDpwe W1beZPLYOesuu8fOHZ+ZPBb3TWb16P9r4HFl41wmj8+b5ALYo1gz85LyKxJYMyb9cS2YL12x/ lV8A+NDsS5GLg4hgbWMEr3vj7F1MXICOQsYJbpnuIDYbALGErumb2YCsVkEVCXa+qcydjFycA gLBEj8mWIK0isi8J5R4sPsXWA1zAKKEquen2cGsXkFBCVOznzCAhGXkDj44gVU3E3i0JNWJoh dMhKTl0xmApkpISAvce5AEUhYQiBOYtPaF8wTGHlnIZk0C8mkBYxMqxg1ilOLylKLdA0N9ZKK MtMzSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAsOXAQh2MK5sdz7EKMnBpCTKK8RUFinEl 5SfUpmRWJwRX1Sak1p8iFGGg0NJgveTCFBOsCg1PbUiLTMHGEkwaQkOHiUR3n0gad7igsTc4s x0iNQpRl2OKf/XfGESYsnLz0uVEuetBSkSACnKKM2DGwGL6kuMslLCvIxARwnxFKQW5WaWoMq /YhTnYFQCqhAFmsKTmVcCt+kV0BFMQEfMmVEKckRJIkJKqoFxuSB7vYLuNdUTn6ZONj7C4/cl zue24hff2E9Fzz3fKNT2nK9++GLN04DSgp7G4psqH81ciw9oznFu81mtPeGzr2b40+6lN5dL3 NsoKXHgzI83OQVTayRPuMTeff853LPCx98noIDdqXy946dnhSYzbiS/nng/XnPTpZ93RV/t2h nDVal8d80VJZbijERDLeai4kQACBNMdeUCAAA= X-Env-Sender: Egil.Hjelmeland@zenitel.com X-Msg-Ref: server-9.tower-178.messagelabs.com!1500911112!107758192!1 X-Originating-IP: [195.159.34.254] X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=zenitel.com,-,- X-VirusChecked: Checked From: Egil Hjelmeland Date: Thu, 20 Jul 2017 10:49:40 +0200 Subject: [PATCH 11/13] net: dsa: lan9303: Added "alr_dump" sysfs port attribute To: , , , , , , , , CC: MIME-Version: 1.0 Content-Type: text/plain Message-ID: X-Originating-IP: [10.5.202.90] X-ClientProxiedBy: nooslMX1.zenitelcss.com (10.5.2.91) To nooslMX1.zenitelcss.com (10.5.2.91) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Added read only file /sys/class/net//lan9303/alr_dump, that output 168 first ALR entires. Currently "bridge fdb show" does not include the CPU port, while "alr_dump" list all three ports per entry. Example output: 9c:57:ad:79:d0:84 1 l 01:80:c2:00:00:00 0 s 00:13:cb:0d:01:95 0 s 10:f3:11:f5:6f:cf 2 l 48:4d:7e:f4:59:a8 2 l 01:00:5e:00:01:0a 0 2 s ec:f4:bb:0f:e2:fd 2 l Signed-off-by: Egil Hjelmeland --- Documentation/networking/dsa/lan9303.txt | 3 ++ drivers/net/dsa/lan9303-core.c | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Documentation/networking/dsa/lan9303.txt b/Documentation/networking/dsa/lan9303.txt index 1fd72ff4b492..ace91c821ce7 100644 --- a/Documentation/networking/dsa/lan9303.txt +++ b/Documentation/networking/dsa/lan9303.txt @@ -37,6 +37,9 @@ Sysfs nodes When a user port is enabled, the driver creates sysfs directory /sys/class/net/xxx/lan9303 with the following files: + - alr_dump (RO): List the 168 first entries of the ALR table. + Including port 0 entires. This file is identical for both ports. + Format: MAC; list of ports; (l)earned / (s)tatic - swe_bcst_throt (RW): Set/get 6.4.7 Broadcast Storm Control Throttle Level for the port. Accesses the corresponding bits of the SWE_BCST_THROT register (13.4.3.23). diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index ad7a4c72e1fb..b682aa4f1fca 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -642,6 +642,47 @@ static void alr_loop_cb_fdb_port_dump( dump_ctx->cb(&fdb->obj); } +/* /sys/class/net/xxx/lan9303/alr_dump: display 168 first ALR entires, + * including cpu port + */ +struct port_sysfs_dump_ctx { + char *buf; + int pos; +}; + +static void alr_loop_cb_sysfs_dump( + struct lan9303 *chip, u32 dat0, u32 dat1, int portmap, void *ctx) +{ +# define LINE_LEN 24 + struct port_sysfs_dump_ctx *dump_ctx = ctx; + char *buf = dump_ctx->buf; + int pos = dump_ctx->pos; + + u8 mac[ETH_ALEN]; + int p; + char ports[LAN9303_NUM_PORTS + 1]; + const char trunc_txt[] = "Truncated!\n"; + + if (pos >= PAGE_SIZE - LINE_LEN - (sizeof(trunc_txt) - 1)) { + if (pos < PAGE_SIZE - LINE_LEN) + pos += sprintf(buf + pos, trunc_txt); + dump_ctx->pos = pos; + return; + } + + _alr_reg_to_mac(dat0, dat1, mac); + + /* print ports as list of port numbers: */ + for (p = 0; p < LAN9303_NUM_PORTS; p++) + ports[p] = (portmap & BIT(p)) ? '0' + p : ' '; + ports[LAN9303_NUM_PORTS] = 0; + + pos += sprintf(buf + pos, "%pM %s %s\n", + mac, ports, + (dat1 & ALR_DAT1_STATIC) ? "s" : "l"); + dump_ctx->pos = pos; +} + /* ALR: Add/modify/delete ALR entries */ /* Set a static ALR entry. Delete entry if port_map is zero */ @@ -931,8 +972,25 @@ swe_bcst_throt_store(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RW(swe_bcst_throt); +static ssize_t +alr_dump_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct dsa_port *dp = dsa_net_device_to_dsa_port(to_net_dev(dev)); + struct lan9303 *chip = dp->ds->priv; + struct port_sysfs_dump_ctx dump_ctx = { + .buf = buf, + .pos = 0, + }; + + lan9303_alr_loop(chip, alr_loop_cb_sysfs_dump, &dump_ctx); + return dump_ctx.pos; +} +static DEVICE_ATTR_RO(alr_dump); + static struct attribute *lan9303_attrs[] = { &dev_attr_swe_bcst_throt.attr, + &dev_attr_alr_dump.attr, NULL }; -- 2.11.0 DISCLAIMER: This e-mail may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply e-mail and delete all copies of this message.