Re: [PATCH net-next v4 0/3] Linn Ethernet Packet Sniffer driver
Hi Richard, On 06/03/15 15:22, Richard Cochran wrote: I don't really know what the problem here is. Yes, there is some networking configuration that you need to do when administering a network using PTP protocols. But these protocols (1588 aka PTP, and 802.1AS aka gPTP) do offer means for dealing with this. In particular, there is no danger mixing 1588 devices with audio devices, because the gPTP protocol uses a different transport flag. In any case, this has nothing at all to do with the kernel interface. Our feeling is that we will have to test and verify that a move to gPTP will fit with the use cases that we have to support and that will require a fair amount of effort and rewrite of application software. If the driver is not acceptable with the current interface we may need to maintain it as a private patch until we are ready to move to gPTP as you recommend. If you want to try and integrate your custom protocols into the networking stack, by all means please post them. I would certainly support expanding the time stamping interface to include your protocol's packet types (like adding them to hwtstamp_rx_filters). Maybe that would be enough for you? I was referring to the Songcast protocol we are using which is part of the OpenHome suite (www.openhome.org) and runs on top of UDP. It could be filtered by testing the first 5 bytes of the payload. In our implementation we also add the destination IP and port to the filter to make it more reliable, but hwtstamp_rx_filters cannot accept parameters. However, I will test that and maybe come back with a patch to expand the hwtstamp_rx_filter enum initially? Thanks, Richard Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH net-next v4 0/3] Linn Ethernet Packet Sniffer driver
Hi Richard, On 27/02/15 18:14, Richard Cochran wrote: >> The H/W does have the capability to do that. However, in order to >> implement it there will be some architectural changes needed >> in the kernel. This module cannot really pretend to be a PHY. >> In the real world it sits between the MAC and the PHY. > > Right. > > Here is one idea. Put a link to the TS device in the PHY's DT node. > Then, in phy_probe, check if the PHY's four methods, ts_info, > hwtstamp, rxtstamp, and txtstamp, are all null. If so, check for a DT > link from the PHY's node to a TS device driver. If found, then set > the four methods to call into the TS driver's callbacks. > > Just off of the top of my head. > Thank you for your help and suggestions. Although the PTP way appears to be the best from an architectural point of view, we have some questions as whether it is suitable for the audio use cases that this module is mainly intended for. To use the PTP terminology in a large installation we would have a potentially large number of clock domains. It is not clear how to easily manage the creation and allocation of domains. In addition the clock will be pulled according to the audio stream and it would be undesirable for other unrelated PTPv2 devices on the network to join the clock domain and have their clocks synchronized to it. The patch in its current form would allow a move to Linux using our existing synchronization protocols (which are open-source). A move to PTP is something to consider but will involve a fair amount of redesign including upgrade of legacy products. > Thanks, > Richard > Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH net-next v4 0/3] Linn Ethernet Packet Sniffer driver
Hi Richard, On 25/02/15 17:30, Richard Cochran wrote: I need some more time to study your other suggestions regarding the PHY timestamping framework. From my (limited) understanding of your HW device, I should think that it will work. The PHY time stamping subsystem is not the most obvious code in the world. Please feel free to ask if you have any questions. To summarize (and confirm my understanding) your suggestion is for the sniffer to be configured to match PTP packets and (similarly to the dp83640) return the Message Type and Sequence Id fields that will allow them to be matched to an sk_buf that has been passed from the stack. Then the sk_buf can be timestamped using the sniffer timestamp. The H/W does have the capability to do that. However, in order to implement it there will be some architectural changes needed in the kernel. This module cannot really pretend to be a PHY. In the real world it sits between the MAC and the PHY. Thanks, Richard Thanks, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH net-next v4 0/3] Linn Ethernet Packet Sniffer driver
Hi Richard, On 25/02/15 17:01, Richard Cochran wrote: On Wed, Feb 25, 2015 at 04:19:45PM +0100, Richard Cochran wrote: Let me suggest another approach that stays in line with the existing frame work. Based on the device's limitations and your own example, it seems clear that the intended use case is synchronization for AVB applications using gPTP. Also, forgot to say, expose your clock as a PTP Hardware Clock (PHC). Regarding this last point, the actual counter that generates the timestamps is not part of the sniffer H/W module. Timestamps are provided to the sniffer externally in H/W by a different module. Apart of that there is not eg. a sniffer register to read the current counter value. I wonder if it should be the driver for the module where the counter belongs (called Event Timer in the Pistachio Soc) that should register the PHC. I need some more time to study your other suggestions regarding the PHY timestamping framework. Thanks, Richard Regards, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 0/3] net: Linn Ethernet Packet Sniffer driver
Hi Richard, On 25/02/15 09:50, Richard Cochran wrote: The Linux kernel already fully supports this kind of application via the SIOCSHWTSTAMP, SO_TIMESTAMPING, and PHC mechanisms. We certainly don't need another another interface just for someone's warped hardware design. I suggest that you find a way to make your HW work within the existing frame work. The driver already uses that framework for returning timestamps to user space. It does not introduce any new interface. The interface needs to be public so that a user-space application can program a command string that will match packets that belong to the audio stream of interest, for this example. Let the user program simply use a BPF for that. In addition returning just a timestamp would not be enough in many cases. In the audio streaming use case mentioned above some additional bytes from the packet payload need to be returned (with Copy commands) in order to associate the timestamp with a certain point in the audio stream. The time stamp is *already* associated with a particular frame. Just tell your driver to program the hardware to: 1. time stamp every frame 2. deliver every frame Thats all you need. The H/W could not support that: We have a "Match/Stamp" command, so the packet byte needs to match the value following the command, in order for a timestamp to be generated, otherwise the packet is dropped. In addition, due to FIFO size limitations up to 128 bytes (including the timestamp) can be returned (through Copy commands) from each packet. The module was designed to be able to configure it to sniff packets belonging to a certain application level stream and from each matching packet return a timestamp and some bytes (from eg. the application layer protocol header) that would be useful to the application. BPF could accomplish that too, but timestamps will not be as accurate without H/W support. I understand that the device needs to be configured with a proprietary command stream, but all interfacing with user-space is done using existing frameworks (AF_PACKET, SIOCSHWTSTAMP, cmsg) Actually, that is how the H/W works. Each Match command is followed by a data value which must match the packet data byte at the corresponding location. If there is no match processing of the packet stops. And just what is the "corresponding location"? The command string is made up of a sequence of pairs. Take this for example: {0x00, 0x00, 0x01, 0x55, 0x02, 0x00, 0x04, 0x00}. First command is Don't Care (0x00), ie 1st byte of Ethernet frame is just skipped. Second command is Match (0x01), ie if the 2nd byte of the Ethernet frame is 0x55 processing continues otherwise packet is dropped. Third command is Copy (0x02), ie 3rd byte of the packet is copied to the H/W FIFO to be returned to the user Fourth command is Copy/Done (0x04), ie 4th packet byte is also copied to the FIFO and processing stops. Then an IRQ is generated, data (2 bytes) are read from the FIFO and delivered through an AF_PACKET socket. In v4 of the patch I tried to improve the documentation of some of these points. Thanks, Richard Thanks, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH net-next v4 1/3] Linn Ethernet packet sniffer: device tree binding and vendor prefix
Signed-off-by: Stathis Voukelatos --- .../bindings/net/linn-ether-packet-sniffer.txt | 39 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + 2 files changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt new file mode 100644 index 000..66bfc48 --- /dev/null +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt @@ -0,0 +1,39 @@ +* Linn Products Ethernet Packet Sniffer +The module allows Ethernet packets to be parsed, matched against +a user-defined pattern and timestamped. It sits between a 100M +Ethernet MAC and PHY and is completely passive with respect to +Ethernet frames. +Matched packet bytes and timestamp values are returned through a +FIFO. Timestamps are provided to the module through an externally +generated Gray-encoded counter. + +Required properties: +- compatible : must be "linn,eth-packet-sniffer" +- reg : a list of physical address and size pairs corresponding to + each entry in 'reg-names' +- reg-names : must contain: + "regs" : control registers + "tx-ram" : TX command string memory + "rx-ram" : RX command string memory +- interrupts : sniffer interrupt specifier +- clocks : list of clocks corresponding to each entry in 'clock-names' +- clock-names : must contain: + "sys": system clock for the peripheral + "tstamp" : timestamp counter clock +- fifo-block-words : number of words in one data FIFO entry +- tstamp-bits : width in bits of the timestamp counter + +Example: + +sniffer@1814a000 { + compatible = "linn,eth-sniffer"; + reg = <0x1814a000 0x100>, <0x1814a400 0x400>, + <0x1814a800 0x400>; + reg-names = "regs", "tx-ram", "rx-ram"; + interrupts = ; + clocks = <&cr_periph SYS_CLK_ENET>, +<&clk_core CLK_AUDIO>; + clock-names = "sys", "tstamp"; + fifo-block-words = <4>; + tstamp-bits = <30>; +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 389ca13..f685707 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -102,6 +102,7 @@ lacie LaCie lantiq Lantiq Semiconductor lenovo Lenovo Group Ltd. lg LG Corporation +linn Linn Products Ltd. linux Linux-specific binding lsiLSI Corp. (LSI Logic) lltc Linear Technology Corporation -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH net-next v4 2/3] Linn packet sniffer core framework
The framework registers each backend sniffer channel as a netdev, which can be accessed from user space through a raw packet socket. Packets received from user space are treated as a command string configuration. Each match event from the backend driver will generate a packet with the matching bytes plus an optional timestamp, if configured by the command string. Signed-off-by: Stathis Voukelatos --- MAINTAINERS| 6 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/linn/Kconfig | 25 ++ drivers/net/ethernet/linn/Makefile | 19 ++ .../net/ethernet/linn/pkt-sniffer/core/Makefile| 19 ++ .../net/ethernet/linn/pkt-sniffer/core/snf_core.c | 344 + .../net/ethernet/linn/pkt-sniffer/core/snf_core.h | 60 8 files changed, 475 insertions(+) create mode 100644 drivers/net/ethernet/linn/Kconfig create mode 100644 drivers/net/ethernet/linn/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.h diff --git a/MAINTAINERS b/MAINTAINERS index 0597c5b..6186c0c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5828,6 +5828,12 @@ M: Sasha Levin S: Maintained F: tools/lib/lockdep/ +LINN PACKET SNIFFER DRIVER +M: Stathis Voukelatos +S: Maintained +F: drivers/net/ethernet/linn/ +F: Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras W: http://www.ibm.com/linux/ltc/projects/ppc diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index eadcb05..ee4b3ed 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig @@ -103,6 +103,7 @@ config LANTIQ_ETOP ---help--- Support for the MII0 inside the Lantiq SoC +source "drivers/net/ethernet/linn/Kconfig" source "drivers/net/ethernet/marvell/Kconfig" source "drivers/net/ethernet/mellanox/Kconfig" source "drivers/net/ethernet/micrel/Kconfig" diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index 1367afc..f8071d3 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_NET_VENDOR_HP) += hp/ obj-$(CONFIG_NET_VENDOR_IBM) += ibm/ obj-$(CONFIG_NET_VENDOR_INTEL) += intel/ obj-$(CONFIG_NET_VENDOR_I825XX) += i825xx/ +obj-$(CONFIG_NET_VENDOR_LINN) += linn/ obj-$(CONFIG_NET_VENDOR_XSCALE) += xscale/ obj-$(CONFIG_IP1000) += icplus/ obj-$(CONFIG_JME) += jme.o diff --git a/drivers/net/ethernet/linn/Kconfig b/drivers/net/ethernet/linn/Kconfig new file mode 100644 index 000..6654f4e --- /dev/null +++ b/drivers/net/ethernet/linn/Kconfig @@ -0,0 +1,25 @@ +# +# Linn device configuration +# + +config NET_VENDOR_LINN + bool "Linn devices" + ---help--- + Say Y to add support for Linn Products devices. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Linn devices. If you say Y, you will be asked for + your specific device in the following questions. + +if NET_VENDOR_LINN + +menuconfig PKT_SNIFFER +tristate "Packet sniffer support" +---help--- +Say Y to add support for the packet sniffer driver framework. + +The core driver can also be built as a module. If so, the module +will be called snf_core. + +endif # NET_VENDOR_LINN diff --git a/drivers/net/ethernet/linn/Makefile b/drivers/net/ethernet/linn/Makefile new file mode 100644 index 000..f3338f3 --- /dev/null +++ b/drivers/net/ethernet/linn/Makefile @@ -0,0 +1,19 @@ +### +# Makefile for the Linn Products device drivers +# +# Copyright (C) 2015 Linn Products Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Written by: +# Stathis Voukelatos +### + +obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/core/ diff --git a/drivers/net/ethernet/linn/pkt-sniffer/core/Makefile b/drivers/net/ethernet/linn/pkt-sniffer/core/Makefile new file mode 100644 index 000..4dc8f11 --- /dev/null +++ b/
[PATCH net-next v4 3/3] Linn Ethernet packet sniffer driver
Driver for the Ethernet Mii packet sniffer H/W module found in the IMG Pistachio SoC. Signed-off-by: Stathis Voukelatos --- drivers/net/ethernet/linn/Kconfig | 11 + drivers/net/ethernet/linn/Makefile | 1 + .../linn/pkt-sniffer/backends/ether/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/channel.c | 444 + .../linn/pkt-sniffer/backends/ether/channel.h | 80 .../ethernet/linn/pkt-sniffer/backends/ether/hw.h | 46 +++ .../linn/pkt-sniffer/backends/ether/platform.c | 318 +++ 7 files changed, 920 insertions(+) create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/platform.c diff --git a/drivers/net/ethernet/linn/Kconfig b/drivers/net/ethernet/linn/Kconfig index 6654f4e..bbfd6a4 100644 --- a/drivers/net/ethernet/linn/Kconfig +++ b/drivers/net/ethernet/linn/Kconfig @@ -22,4 +22,15 @@ menuconfig PKT_SNIFFER The core driver can also be built as a module. If so, the module will be called snf_core. +config PKT_SNIFFER_ETHER +tristate "Ethernet packet sniffer" +depends on PKT_SNIFFER +help +Say Y here if you want to use the Ethernet packet sniffer +module by Linn Products Ltd. It can be found in the upcoming +Pistachio SoC by Imagination Technologies. + +The driver can also be built as a module. If so, the module +will be called snf_ether. + endif # NET_VENDOR_LINN diff --git a/drivers/net/ethernet/linn/Makefile b/drivers/net/ethernet/linn/Makefile index f3338f3..f51eb66 100644 --- a/drivers/net/ethernet/linn/Makefile +++ b/drivers/net/ethernet/linn/Makefile @@ -17,3 +17,4 @@ ### obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/core/ +obj-$(CONFIG_PKT_SNIFFER_ETHER) += pkt-sniffer/backends/ether/ diff --git a/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile new file mode 100644 index 000..1f97e51 --- /dev/null +++ b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile @@ -0,0 +1,20 @@ +### +# Makefile for the Linn ethernet packet sniffer driver +# +# Copyright (C) 2015 Linn Products Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Written by: +# Stathis Voukelatos +### + +obj-$(CONFIG_PKT_SNIFFER_ETHER) += snf_ether.o +snf_ether-objs := platform.o channel.o diff --git a/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c new file mode 100644 index 000..87ec790 --- /dev/null +++ b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c @@ -0,0 +1,444 @@ +/* + * Ethernet Mii packet sniffer driver + * - channel functions + * + * Copyright (C) 2015 Linn Products Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Written by: + * Stathis Voukelatos + */ +#include +#include +#include +#include "../../core/snf_core.h" +#include "hw.h" +#include "channel.h" + +#define to_ether_snf_chan(dev) container_of(dev, struct ether_snf_chan, chan) + +#define CMD_DONTCARE 0 +#define CMD_MATCH 1 +#define CMD_COPY 2 +#define CMD_MATCHSTAMP 3 +#define CMD_COPYDONE 4 + +/* Checks if the supplied command string is compatible with the + * capabilities of the H/W. + */ +static bool validate_pattern( + struct ether_snf_chan *ch, + const u8 *buf, + int count) +{ + int i, complete, max_copy_bytes; + int ts = 0; + int copy_before = 0; + int copy_after = 0; + + if (count >
[PATCH net-next v4 0/3] Linn Ethernet Packet Sniffer driver
This patch adds support for the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Selected packet bytes from matched packets and timestamp values are returned through a H/W FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command string for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides a common framework for managing backend packet sniffer implementations. Each backend channel is registered by the core as a netdev, which can be accessed from user space through AF_PACKET sockets. - Ethernet Packet Sniffer backend: provides the driver for the Linn Ethernet Packet Sniffer H/W modules. The split between a core and backend modules allows for other implementations to be added in the future apart of the Ethernet packet sniffer presented in this patch set. Changelog: v4: * More detailed documentation on driver usage (in snf_core.c) and H/W operation (in platform.c) * Some source file renaming in the core module. * Rebased against linux-net-next v3: * Code moved into vendor specific directory * Device tree binding updated and streamlined. Cyclecounter params are now calculated dynamically. v2: * Complete redesign of core framework to use netdev instead of the generic netlink framework * Updated device tree binding * A number of minor code improvements suggested by code review Stathis Voukelatos (3): Linn Ethernet packet sniffer: device tree binding and vendor prefix Linn packet sniffer core framework Linn Ethernet packet sniffer driver .../bindings/net/linn-ether-packet-sniffer.txt | 39 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + MAINTAINERS| 6 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/linn/Kconfig | 36 ++ drivers/net/ethernet/linn/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/channel.c | 444 + .../linn/pkt-sniffer/backends/ether/channel.h | 80 .../ethernet/linn/pkt-sniffer/backends/ether/hw.h | 46 +++ .../linn/pkt-sniffer/backends/ether/platform.c | 318 +++ .../net/ethernet/linn/pkt-sniffer/core/Makefile| 19 + .../net/ethernet/linn/pkt-sniffer/core/snf_core.c | 344 .../net/ethernet/linn/pkt-sniffer/core/snf_core.h | 60 +++ 15 files changed, 1435 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt create mode 100644 drivers/net/ethernet/linn/Kconfig create mode 100644 drivers/net/ethernet/linn/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/platform.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.h -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 3/3] Linn Ethernet packet sniffer driver
On 23/02/15 21:38, David Miller wrote: From: Stathis Voukelatos Date: Mon, 23 Feb 2015 14:26:22 + Driver for the Ethernet Mii packet sniffer H/W module found in the IMG Pistachio SoC. Signed-off-by: Stathis Voukelatos You really have to explain what this thing does, how it is used, what APIs are made use of to maniulate this device, etc. Nobody knows what the packet sniffer module by your company is. I tried to provide a description of the device in the cover letter. I will expand it and also include it in a suitable place in the actual source. I also anticipate that once you describe adequately how this thing behaves I won't like it, and I'll prefer that you integrate support for your device using an exising facility such as AF_PACKET, extending it if need be. The driver actually relies on AF_PACKET for accessing the device. I will add some documentation to make the usage and API clearer. I am very far away from applying this series at this point, it needs a lot more work and explanations. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 2/3] Packet sniffer core framework
On 23/02/15 21:37, David Miller wrote: From: Stathis Voukelatos Date: Mon, 23 Feb 2015 14:26:21 + + spin_lock_irqsave(&priv->lock, flags); + /* Stop the hardware */ + sch->stop(sch); + /* Set the new command pattern */ + ret = sch->set_pattern(sch, skb->data, skb->len / 2); + /* Restart the hardware */ + sch->start(sch); + spin_unlock_irqrestore(&priv->lock, flags); These comments are excessive. When someone calls ops->stop() what are they supposed to think the thing does? Open a can of tuna? Mow the lawn? Wash the dishes? No, it stops the thing. Everyone understands that and you don't have to explicitly say it. Saying "stop the hardware" does not add anything to the source code that is not already implicitly there. They just take up space and keep more useful information from being displayed at once on the screen. Please remove all of these things. Thanks. Will remove the comments in the next version of the patch set. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v3 2/3] Packet sniffer core framework
The framework registers each backend sniffer channel as a netdev, which can be accessed from user space through a raw packet socket. Packets received from user space are treated as a command string configuration. Each match event from the backend driver will generate a packet with the matching bytes plus an optional timestamp, if configured by the command string. Signed-off-by: Stathis Voukelatos --- MAINTAINERS| 6 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/linn/Kconfig | 25 ++ drivers/net/ethernet/linn/Makefile | 19 ++ .../net/ethernet/linn/pkt-sniffer/core/Makefile| 20 ++ .../net/ethernet/linn/pkt-sniffer/core/module.c| 37 +++ .../net/ethernet/linn/pkt-sniffer/core/netdev.c| 254 + .../net/ethernet/linn/pkt-sniffer/core/snf_core.h | 60 + 9 files changed, 423 insertions(+) create mode 100644 drivers/net/ethernet/linn/Kconfig create mode 100644 drivers/net/ethernet/linn/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/module.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/netdev.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.h diff --git a/MAINTAINERS b/MAINTAINERS index ddc5a8c..716b10c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5835,6 +5835,12 @@ M: Sasha Levin S: Maintained F: tools/lib/lockdep/ +LINN PACKET SNIFFER DRIVER +M: Stathis Voukelatos +S: Maintained +F: drivers/net/ethernet/linn/ +F: Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras W: http://www.ibm.com/linux/ltc/projects/ppc diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index eadcb05..ee4b3ed 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig @@ -103,6 +103,7 @@ config LANTIQ_ETOP ---help--- Support for the MII0 inside the Lantiq SoC +source "drivers/net/ethernet/linn/Kconfig" source "drivers/net/ethernet/marvell/Kconfig" source "drivers/net/ethernet/mellanox/Kconfig" source "drivers/net/ethernet/micrel/Kconfig" diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index 1367afc..f8071d3 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_NET_VENDOR_HP) += hp/ obj-$(CONFIG_NET_VENDOR_IBM) += ibm/ obj-$(CONFIG_NET_VENDOR_INTEL) += intel/ obj-$(CONFIG_NET_VENDOR_I825XX) += i825xx/ +obj-$(CONFIG_NET_VENDOR_LINN) += linn/ obj-$(CONFIG_NET_VENDOR_XSCALE) += xscale/ obj-$(CONFIG_IP1000) += icplus/ obj-$(CONFIG_JME) += jme.o diff --git a/drivers/net/ethernet/linn/Kconfig b/drivers/net/ethernet/linn/Kconfig new file mode 100644 index 000..6654f4e --- /dev/null +++ b/drivers/net/ethernet/linn/Kconfig @@ -0,0 +1,25 @@ +# +# Linn device configuration +# + +config NET_VENDOR_LINN + bool "Linn devices" + ---help--- + Say Y to add support for Linn Products devices. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Linn devices. If you say Y, you will be asked for + your specific device in the following questions. + +if NET_VENDOR_LINN + +menuconfig PKT_SNIFFER +tristate "Packet sniffer support" +---help--- +Say Y to add support for the packet sniffer driver framework. + +The core driver can also be built as a module. If so, the module +will be called snf_core. + +endif # NET_VENDOR_LINN diff --git a/drivers/net/ethernet/linn/Makefile b/drivers/net/ethernet/linn/Makefile new file mode 100644 index 000..f3338f3 --- /dev/null +++ b/drivers/net/ethernet/linn/Makefile @@ -0,0 +1,19 @@ +### +# Makefile for the Linn Products device drivers +# +# Copyright (C) 2015 Linn Products Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Written by: +# Stathis Voukelatos +### + +obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/core/ diff --git a/drivers/net/ethernet/linn/pkt-sniffer/core/Makefile b/drivers/net/ethernet/linn/pkt-sniffer/core/Makefile new file m
[PATCH v3 3/3] Linn Ethernet packet sniffer driver
Driver for the Ethernet Mii packet sniffer H/W module found in the IMG Pistachio SoC. Signed-off-by: Stathis Voukelatos --- drivers/net/ethernet/linn/Kconfig | 11 + drivers/net/ethernet/linn/Makefile | 1 + .../linn/pkt-sniffer/backends/ether/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/channel.c | 455 + .../linn/pkt-sniffer/backends/ether/channel.h | 80 .../ethernet/linn/pkt-sniffer/backends/ether/hw.h | 46 +++ .../linn/pkt-sniffer/backends/ether/platform.c | 286 + 7 files changed, 899 insertions(+) create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/platform.c diff --git a/drivers/net/ethernet/linn/Kconfig b/drivers/net/ethernet/linn/Kconfig index 6654f4e..bbfd6a4 100644 --- a/drivers/net/ethernet/linn/Kconfig +++ b/drivers/net/ethernet/linn/Kconfig @@ -22,4 +22,15 @@ menuconfig PKT_SNIFFER The core driver can also be built as a module. If so, the module will be called snf_core. +config PKT_SNIFFER_ETHER +tristate "Ethernet packet sniffer" +depends on PKT_SNIFFER +help +Say Y here if you want to use the Ethernet packet sniffer +module by Linn Products Ltd. It can be found in the upcoming +Pistachio SoC by Imagination Technologies. + +The driver can also be built as a module. If so, the module +will be called snf_ether. + endif # NET_VENDOR_LINN diff --git a/drivers/net/ethernet/linn/Makefile b/drivers/net/ethernet/linn/Makefile index f3338f3..f51eb66 100644 --- a/drivers/net/ethernet/linn/Makefile +++ b/drivers/net/ethernet/linn/Makefile @@ -17,3 +17,4 @@ ### obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/core/ +obj-$(CONFIG_PKT_SNIFFER_ETHER) += pkt-sniffer/backends/ether/ diff --git a/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile new file mode 100644 index 000..1f97e51 --- /dev/null +++ b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile @@ -0,0 +1,20 @@ +### +# Makefile for the Linn ethernet packet sniffer driver +# +# Copyright (C) 2015 Linn Products Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Written by: +# Stathis Voukelatos +### + +obj-$(CONFIG_PKT_SNIFFER_ETHER) += snf_ether.o +snf_ether-objs := platform.o channel.o diff --git a/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c new file mode 100644 index 000..2b502e8 --- /dev/null +++ b/drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c @@ -0,0 +1,455 @@ +/* + * Ethernet Mii packet sniffer driver + * - channel functions + * + * Copyright (C) 2015 Linn Products Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Written by: + * Stathis Voukelatos + */ +#include +#include +#include +#include "../../core/snf_core.h" +#include "hw.h" +#include "channel.h" + +#define to_ether_snf_chan(dev) container_of(dev, struct ether_snf_chan, chan) + +/* Checks if the supplied command string is compatible with the + * capabilities of the H/W. The command string consists of a series + * of bytes in the following format + * + * | CMD | DATA | CMD | DATA | + * + * Valid command IDs are the following: + * 0 - Don't care + * 1 - Match: packet data must match command string byte + * 2 - Copy: packet data will be copied to FIFO + * 3 - Match/Stamp: if packet data matches string byte, a timestamp + *
[PATCH v3 0/3] net: Linn Ethernet Packet Sniffer driver
This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Matched packet bytes and timestamp values are returned through a FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command string for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides a common framework for managing backend packet sniffer implementations. Each backend channel is registered by the core as a netdev, which can be accessed from user space through a raw packet socket. - Ethernet Packet Sniffer backend: provides the driver for the Linn Ethernet Packet Sniffer H/W modules. The split between a core and backend modules allows for other implementations to be added in the future apart of the Ethernet packet sniffer presented in this patch set. Changes for v3: * Code moved into vendor specific directory * Device tree binding updated and streamlined. Cyclecounter params are now calculated dynamically. Changes for v2: * Complete redesign of core framework to use netdev instead of the generic netlink framework * Updated device tree binding * A number of minor code improvements suggested by code review Stathis Voukelatos (3): Ethernet packet sniffer: device tree binding and vendor prefix Packet sniffer core framework Linn Ethernet packet sniffer driver .../bindings/net/linn-ether-packet-sniffer.txt | 39 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + MAINTAINERS| 6 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/linn/Kconfig | 36 ++ drivers/net/ethernet/linn/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/Makefile | 20 + .../linn/pkt-sniffer/backends/ether/channel.c | 455 + .../linn/pkt-sniffer/backends/ether/channel.h | 80 .../ethernet/linn/pkt-sniffer/backends/ether/hw.h | 46 +++ .../linn/pkt-sniffer/backends/ether/platform.c | 286 + .../net/ethernet/linn/pkt-sniffer/core/Makefile| 20 + .../net/ethernet/linn/pkt-sniffer/core/module.c| 37 ++ .../net/ethernet/linn/pkt-sniffer/core/netdev.c| 254 .../net/ethernet/linn/pkt-sniffer/core/snf_core.h | 60 +++ 16 files changed, 1362 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt create mode 100644 drivers/net/ethernet/linn/Kconfig create mode 100644 drivers/net/ethernet/linn/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/backends/ether/platform.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/Makefile create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/module.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/netdev.c create mode 100644 drivers/net/ethernet/linn/pkt-sniffer/core/snf_core.h -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v3 1/3] Ethernet packet sniffer: device tree binding and vendor prefix
Signed-off-by: Stathis Voukelatos --- .../bindings/net/linn-ether-packet-sniffer.txt | 39 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + 2 files changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt new file mode 100644 index 000..66bfc48 --- /dev/null +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt @@ -0,0 +1,39 @@ +* Linn Products Ethernet Packet Sniffer +The module allows Ethernet packets to be parsed, matched against +a user-defined pattern and timestamped. It sits between a 100M +Ethernet MAC and PHY and is completely passive with respect to +Ethernet frames. +Matched packet bytes and timestamp values are returned through a +FIFO. Timestamps are provided to the module through an externally +generated Gray-encoded counter. + +Required properties: +- compatible : must be "linn,eth-packet-sniffer" +- reg : a list of physical address and size pairs corresponding to + each entry in 'reg-names' +- reg-names : must contain: + "regs" : control registers + "tx-ram" : TX command string memory + "rx-ram" : RX command string memory +- interrupts : sniffer interrupt specifier +- clocks : list of clocks corresponding to each entry in 'clock-names' +- clock-names : must contain: + "sys": system clock for the peripheral + "tstamp" : timestamp counter clock +- fifo-block-words : number of words in one data FIFO entry +- tstamp-bits : width in bits of the timestamp counter + +Example: + +sniffer@1814a000 { + compatible = "linn,eth-sniffer"; + reg = <0x1814a000 0x100>, <0x1814a400 0x400>, + <0x1814a800 0x400>; + reg-names = "regs", "tx-ram", "rx-ram"; + interrupts = ; + clocks = <&cr_periph SYS_CLK_ENET>, +<&clk_core CLK_AUDIO>; + clock-names = "sys", "tstamp"; + fifo-block-words = <4>; + tstamp-bits = <30>; +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 389ca13..f685707 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -102,6 +102,7 @@ lacie LaCie lantiq Lantiq Semiconductor lenovo Lenovo Group Ltd. lg LG Corporation +linn Linn Products Ltd. linux Linux-specific binding lsiLSI Corp. (LSI Logic) lltc Linear Technology Corporation -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 0/3] net: Linn Ethernet Packet Sniffer driver
Hi Richard, On 18/02/15 21:08, Richard Cochran wrote: On Tue, Feb 17, 2015 at 02:03:30PM +, Stathis Voukelatos wrote: The command string for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. Why do you need to expose this interface to user space at all? Why not just time stamp every frame? To put this into context with an example, the use case this H/W module was originally developed for was to allow multiple audio receivers to synchronize with a single transmitter, eg. multi-room synchronised audio. The interface needs to be public so that a user-space application can program a command string that will match packets that belong to the audio stream of interest, for this example. In addition returning just a timestamp would not be enough in many cases. In the audio streaming use case mentioned above some additional bytes from the packet payload need to be returned (with Copy commands) in order to associate the timestamp with a certain point in the audio stream. How does the "Match" command work? The frame must have one particular byte? That can't be right. Please explain. Actually, that is how the H/W works. Each Match command is followed by a data value which must match the packet data byte at the corresponding location. If there is no match processing of the packet stops. Thanks, Richard Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 2/3] Packet sniffer core framework
Hi Daniel, On 18/02/15 15:42, Daniel Borkmann wrote: This whole framework really looks like only tailored to your specific driver, I have no idea who else should reuse that?! So, I don't think putting this under drivers/net/pkt-sniffer/ is a good idea. Yes, it is not necessarilly expected to be used by other 3rd party drivers. The reason of splitting out the framework code is to account of the fact the we may develop in the future othersimilar sniffer H/W for non-ethernet interfaces (eg. wifi). I can move the code under drivers/net/ethernet/linn as you mention below, although that may not account for non-ethernet backends in the future. Also it looks slightly confusing as if I understand you correctly, your module's purpose is to pass down some "packet pattern" to the hardware and match that in order to get a precise timestamp in return? Yes, this point can be slightly confusing. A write to a packet socket bound to the interface is done to supply the command string to the sniffer H/W, while reads would return matched packet bytes + timestamps (throuch cmsg). Is there any other way to supply the command string except of a proprietary ioctl? Might perhaps be better to have everything vendor-specific under something like drivers/net/ethernet/linn/ and have the framework squashed into the driver itself (if parts cannot be generalized in net/packet/). Answered above. It would be good if you can also avoid the extra uapi export. Perhaps it's possible to reuse at least some of the existing timestamping infrastructure? I can remove that. The header file only contains the list of commands. They can be documented. The driver does use the existing timestamping infrastructure to return timestamps to user space. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 1/3] Ethernet packet sniffer: Device tree binding and vendor prefix
Hi Mark, On 18/02/15 12:11, Mark Rutland wrote: Counters can often have a divider applied to their input clock and therefore run at a scaled down frequency. This is not the case in the first SoC where the sniffer is used, so for simplicity I can modify as you suggest and remove that field from the DT. The common clock bindings have fixed-factor-clock for handling dividers, so I believe you should be able to use that. You mentioned that the counter was a block external to the sniffer. Does it have any configuration interface (e.g. to reset the counter)? We may need to model it in the DT if so (and describe the clock as feeding into it rather than into the sniffer). The sniffer module is designed so that it receives a Gray encoded timestamp from another module of the SoC that it is integrated in. The first integration that we have is in the IMG Pistachio SoC. There the timestamp counter is part of the Event Timer module and its source is one of the system clocks of the chip (configurable) That module will eventually have it's own device-tree node when a driver becomes available for it. The 'tstamp' clock given in the sniffer DT node should be such that when it is enabled it will start the counter and its parent clock, so that it can start counting. Thanks, Mark. Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] Export clocks_calc_mult_shift() function
It is a useful utility function, that would allow cyclecounter users built as loadable modules to dynamically calculate the mult and shift values Signed-off-by: Stathis Voukelatos --- kernel/time/clocksource.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 4892352..de7708a 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -87,6 +87,7 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) *mult = tmp; *shift = sft; } +EXPORT_SYMBOL(clocks_calc_mult_shift); /*[Clocksource internal variables]- * curr_clocksource: -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 1/3] Ethernet packet sniffer: Device tree binding and vendor prefix
On 17/02/15 17:30, Mark Rutland wrote: It is the frequency of the timestamp values supplied to the sniffer module. It is used by the driver to convert to nanoseconds. I was trying to be somewhat generic here and not assume that it is necessarily the same as the 'tstamp' clock below, in which case we could indeed obtain it using the common clock framework. In what cases would it _not_ be the same? From your description this is that clock, no? Counters can often have a divider applied to their input clock and therefore run at a scaled down frequency. This is not the case in the first SoC where the sniffer is used, so for simplicity I can modify as you suggest and remove that field from the DT. Most networking driver use hard-coded values for that, but in my case I did not want to assume a certain fixed clock frequency. I will remove it from the DT and generate it dynamically. There is a kernel function clocks_calc_mult_shift() to do it but unfortunately it is not exported, so I guess I will need to replicate the code. Or submit a patch exporting it, along with the rationale for doing so? Will do that. Yes, but the sniffer module is hard-wired to a certain Ethernet Mii interface. We can add an entry to tie it to an Ethernet controller, but apart of a sanity check I am not sure what else the S/W can do. Fundamentally, the use-case for this is monitoring an ethernet interface. So regardless of which kernel framework this plumbs into, there needs to be a way to go from ethN to whatever this is exposed as. Exposing a completely separate interface makes no sense. Singleton stuff like that inevitably gets broken as someone later builds a board with multiple instances of some similar IP block. So I would imagine that either the link between interface and monitoring interface would be described somewhere in the filesystem, or there'd be a syscall/ioctl/whatever to go from an interface to the appropriate monitoring interface. That all depends on exactly how this gets exposed in the end, however. After the first version of the patch was submitted, the feedback from the netdev list was to expose it as a network interface as this would allow it to be accessed by standard user space monitoring tools. It definitely makes sense to link it to the associated ethernet netdev, but I am not sure if there is a framework in the kernel to do it at the driver level? Thanks, Mark. -- Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 1/3] Ethernet packet sniffer: Device tree binding and vendor prefix
Hi Mark, On 17/02/15 16:35, Mark Rutland wrote: +- tstamp-hz : frequency of the timestamp counter Is this the frequency the clock is running at, or a frequency that it should be programmed to in order to be used? The former can be queried from the common clock framework, and if you intended the latter the wording shuold be a little more explicit about that being the case. It is the frequency of the timestamp values supplied to the sniffer module. It is used by the driver to convert to nanoseconds. I was trying to be somewhat generic here and not assume that it is necessarily the same as the 'tstamp' clock below, in which case we could indeed obtain it using the common clock framework. See: include/linux/clocksource.h The driver uses a cyclecounter and timecounter to convert raw timestamps to nanoseconds. 'tstamp-shift' refers to the 'shift' field of the cyclecounter structure, that can be used to improve the precision of the conversion Sure, but the very concept of a cyclecounter is a Linux implementation detail. If we have the frequency of the timer we should be able to dynamically generate this, so there's no need for this to be in the DT. Most networking driver use hard-coded values for that, but in my case I did not want to assume a certain fixed clock frequency. I will remove it from the DT and generate it dynamically. There is a kernel function clocks_calc_mult_shift() to do it but unfortunately it is not exported, so I guess I will need to replicate the code. As mentioned previously, I think the relation between this unit and the MAC and/or PHY needs to be explicitly described in the DT. Do you suggest a field along the lines of: mac = <ð_controller_0>; The driver could check that it exists and is valid but does not need to make use of it. I would expect some level of the software stack to make use of it, or you have no idea which ethernet interface is related to this monitoring interface. Perhaps current systems only have one interface, but that shouldn't be relied upon. Yes, but the sniffer module is hard-wired to a certain Ethernet Mii interface. We can add an entry to tie it to an Ethernet controller, but apart of a sanity check I am not sure what else the S/W can do. Thanks, Mark. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 1/3] Ethernet packet sniffer: Device tree binding and vendor prefix
Hi Mark, On 17/02/15 14:51, Mark Rutland wrote: +Matched packet bytes and timestamp values are returned through a +FIFO. Timestamps are provided to the module through an externally +generated Gray-encoded counter. Does this counter unit need to be enabled (or have any input clocks enabled)? Yes it does, that is the purpose of the 'tstamp' entry in the 'clock-names' property below. + +Required properties: +- compatible : must be "linn,eth-sniffer" Is there not a more precise name for this IP block? It is generally called 'ethernet packet sniffer', maybe linn,eth-packet-sniffer would be a more descriptive name? +- reg : physical addresses and sizes of registers. Must contain 3 entries: + - registers memory space + - TX command string memory + - RX command string memory +- reg-names : must contain the following 3 entries: + "regs", "tx-ram", "rx-ram" It would be nicer to format this as: - reg: A list of physical address and size pairs corresponding to each entry in reg-names - reg-names: must contain: * "regs" for the control registers * "tx-ram" for the TX command string memory * "rx-ram" for the RX command string memory Which avoids redundancy. Will change formatting as suggested The phrase "command string" sounds a bit odd. What are these used for exactly? In these two memory areas we program a sequence of bytes in the format: [cmd][value][cmd][value] to configure the data patterns that the sniffer should match for Ethernet TX and RX packets respectively. Maybe 'command memory' would be clearer? +- interrupts : sniffer interrupt specifier +- clocks : specify the system clock for the peripheral and + the enable clock for the timestamp counter +- clock-names : must contain the "sys" and "tstamp" entries Similarly here clocks should just be defined in terms of clock-names. Will reformat similar to the 'regs' field +- fifo-block-words : number of words in one data FIFO entry I didn't see a data FIFO described. Is that dynamically allocated and handed to the sniffer, or does that correspond to one of the memory regions above? It is a H/W FIFO internal to the module and accessed through a register. It is divided in blocks and 'fifo-block-words' specify the number of words in each block. It is needed by the driver to make sure it reads an entire block, in order to clear the 'data available' interrupt. +- tstamp-hz : frequency of the timestamp counter +- tstamp-shift : shift value for the timestamp cyclecounter struct What exactly is this used for? Are there any docs? See: include/linux/clocksource.h The driver uses a cyclecounter and timecounter to convert raw timestamps to nanoseconds. 'tstamp-shift' refers to the 'shift' field of the cyclecounter structure, that can be used to improve the precision of the conversion +- tstamp-bits : width in bits of the timestamp counter + +Example: + +sniffer@1814a000 { + compatible = "linn,eth-sniffer"; + reg = <0x1814a000 0x100>, <0x1814a400 0x400>, + <0x1814a800 0x400>; + reg-names = "regs", "tx-ram", "rx-ram"; + interrupts = ; + clocks = <&clk_core CLK_AUDIO>, +<&cr_periph SYS_CLK_EVENT_TIMER>; + clock-names = "sys", "tstamp"; + fifo-block-words = <4>; + tstamp-hz = <5200>; + tstamp-shift = <27>; + tstamp-bits = <30>; This property wasn't documented. As mentioned previously, I think the relation between this unit and the MAC and/or PHY needs to be explicitly described in the DT. Do you suggest a field along the lines of: mac = <ð_controller_0>; The driver could check that it exists and is valid but does not need to make use of it. +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index d443279..891c224 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -90,6 +90,7 @@ lacie LaCie lantiqLantiq Semiconductor lenovoLenovo Group Ltd. lgLG Corporation +linnLinn Products Ltd. This addition looks fine to me. For some reason it seems to be padded with spaces instead of tabs though; is my mail server corrupting things or is that the case in the original patch? Sorry, it was spaces. Will be fixed Thanks, Mark. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v2 2/3] Packet sniffer core framework
The framework registers each backend sniffer channel as a netdev, which can be accessed from user space through a raw packet socket. Packets received from user space are treated as a command string configuration. Each match event from the backend driver will generate a packet with the matching bytes plus an optional timestamp, if configured by the command string. Signed-off-by: Stathis Voukelatos --- MAINTAINERS | 6 + drivers/net/Kconfig | 2 + drivers/net/Makefile| 2 + drivers/net/pkt-sniffer/Kconfig | 8 + drivers/net/pkt-sniffer/Makefile| 3 + drivers/net/pkt-sniffer/core/module.c | 37 + drivers/net/pkt-sniffer/core/netdev.c | 254 drivers/net/pkt-sniffer/core/snf_core.h | 60 include/uapi/linux/pkt_sniffer.h| 33 + 9 files changed, 405 insertions(+) create mode 100644 drivers/net/pkt-sniffer/Kconfig create mode 100644 drivers/net/pkt-sniffer/Makefile create mode 100644 drivers/net/pkt-sniffer/core/module.c create mode 100644 drivers/net/pkt-sniffer/core/netdev.c create mode 100644 drivers/net/pkt-sniffer/core/snf_core.h create mode 100644 include/uapi/linux/pkt_sniffer.h diff --git a/MAINTAINERS b/MAINTAINERS index aaa039d..7d882de 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5754,6 +5754,12 @@ M: Sasha Levin S: Maintained F: tools/lib/lockdep/ +LINN PACKET SNIFFER DRIVER +M: Stathis Voukelatos +S: Maintained +F: drivers/net/pkt-sniffer/ +F: Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras W: http://www.ibm.com/linux/ltc/projects/ppc diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index d6607ee..219c786 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -380,4 +380,6 @@ config VMXNET3 source "drivers/net/hyperv/Kconfig" +source "drivers/net/pkt-sniffer/Kconfig" + endif # NETDEVICES diff --git a/drivers/net/Makefile b/drivers/net/Makefile index e25fdd7..56ed84e 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -66,3 +66,5 @@ obj-$(CONFIG_USB_NET_DRIVERS) += usb/ obj-$(CONFIG_HYPERV_NET) += hyperv/ obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.o +obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/ + diff --git a/drivers/net/pkt-sniffer/Kconfig b/drivers/net/pkt-sniffer/Kconfig new file mode 100644 index 000..53ffcc1 --- /dev/null +++ b/drivers/net/pkt-sniffer/Kconfig @@ -0,0 +1,8 @@ +menuconfig PKT_SNIFFER +tristate "Packet sniffer support" +---help--- +Say Y to add support for the packet sniffer driver framework. + +The core driver can also be built as a module. If so, the module +will be called snf_core. + diff --git a/drivers/net/pkt-sniffer/Makefile b/drivers/net/pkt-sniffer/Makefile new file mode 100644 index 000..31dc396 --- /dev/null +++ b/drivers/net/pkt-sniffer/Makefile @@ -0,0 +1,3 @@ +snf_core-y += core/netdev.o +snf_core-y += core/module.o +obj-$(CONFIG_PKT_SNIFFER) += snf_core.o diff --git a/drivers/net/pkt-sniffer/core/module.c b/drivers/net/pkt-sniffer/core/module.c new file mode 100644 index 000..1dbed1f --- /dev/null +++ b/drivers/net/pkt-sniffer/core/module.c @@ -0,0 +1,37 @@ +/* + * Packet sniffer core driver: + * - backend channel management + * - interface to userland as a network I/F + * + * Copyright (C) 2015 Linn Products Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Written by: + * Stathis Voukelatos + */ +#include +#include + +static int __init snf_core_init(void) +{ + return 0; +} + +static void __exit snf_core_cleanup(void) +{ +} + +module_init(snf_core_init); +module_exit(snf_core_cleanup); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Core packet sniffer driver"); +MODULE_AUTHOR("Linn Products Ltd"); diff --git a/drivers/net/pkt-sniffer/core/netdev.c b/drivers/net/pkt-sniffer/core/netdev.c new file mode 100644 index 000..ba25cc0 --- /dev/null +++ b/drivers/net/pkt-sniffer/core/netdev.c @@ -0,0 +1,254 @@ +#include +#include +#include +#include +#include +#include +#include +#include "snf_core.h" + +struct snf_ndev_state { + struct snf_chan *chan; + bool rx_tstamp_enabled; + spinlock_t lock; +}; + +static int hw_timestamp_set(struct net_device *dev, struct ifreq *ifr) +{ + struct snf_ndev_state *priv = netdev_priv(dev); + struct hwtstamp_config tconf; + + if (copy_from_user(&tconf, ifr->ifr_data, si
[PATCH v2 3/3] Linn Ethernet packet sniffer driver
Driver for the Ethernet Mii packet sniffer H/W module found in the IMG Pistachio SoC. Signed-off-by: Stathis Voukelatos --- drivers/net/pkt-sniffer/Kconfig | 11 + drivers/net/pkt-sniffer/Makefile | 4 + drivers/net/pkt-sniffer/backends/ether/channel.c | 392 ++ drivers/net/pkt-sniffer/backends/ether/channel.h | 81 + drivers/net/pkt-sniffer/backends/ether/hw.h | 46 +++ drivers/net/pkt-sniffer/backends/ether/platform.c | 301 + 6 files changed, 835 insertions(+) create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/platform.c diff --git a/drivers/net/pkt-sniffer/Kconfig b/drivers/net/pkt-sniffer/Kconfig index 53ffcc1..b7c7f6b 100644 --- a/drivers/net/pkt-sniffer/Kconfig +++ b/drivers/net/pkt-sniffer/Kconfig @@ -6,3 +6,14 @@ menuconfig PKT_SNIFFER The core driver can also be built as a module. If so, the module will be called snf_core. +config PKT_SNIFFER_ETHER +tristate "Ethernet packet sniffer" +depends on PKT_SNIFFER +help +Say Y here if you want to use the Ethernet packet sniffer +module by Linn Products Ltd. It can be found in the upcoming +Pistachio SoC by Imagination Technologies. + +The driver can also be built as a module. If so, the module +will be called snf_ether. + diff --git a/drivers/net/pkt-sniffer/Makefile b/drivers/net/pkt-sniffer/Makefile index 31dc396..89a3c60 100644 --- a/drivers/net/pkt-sniffer/Makefile +++ b/drivers/net/pkt-sniffer/Makefile @@ -1,3 +1,7 @@ snf_core-y += core/netdev.o snf_core-y += core/module.o obj-$(CONFIG_PKT_SNIFFER) += snf_core.o + +snf_ether-y += backends/ether/platform.o +snf_ether-y += backends/ether/channel.o +obj-$(CONFIG_PKT_SNIFFER_ETHER) += snf_ether.o diff --git a/drivers/net/pkt-sniffer/backends/ether/channel.c b/drivers/net/pkt-sniffer/backends/ether/channel.c new file mode 100644 index 000..a7fed4e --- /dev/null +++ b/drivers/net/pkt-sniffer/backends/ether/channel.c @@ -0,0 +1,392 @@ +/* + * Ethernet Mii packet sniffer driver + * - channel functions + * + * Copyright (C) 2015 Linn Products Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Written by: + * Stathis Voukelatos + */ +#include +#include +#include +#include "../../core/snf_core.h" +#include "hw.h" +#include "channel.h" + +#define to_ether_snf_chan(dev) container_of(dev, struct ether_snf_chan, chan) + +/* Checks if the supplied command string is compatible with the + * capabilities of the H/W. The command string consists of a series + * of bytes in the following format + * + * | CMD | DATA | CMD | DATA | + * + */ +static bool validate_pattern( + struct ether_snf_chan *ch, + const u8 *buf, + int count) +{ + int i, complete, max_copy_bytes; + int ts = 0; + int copy_before = 0; + int copy_after = 0; + + if (count > ch->max_cmds) + return false; + + /* Iterate through the commands in the string */ + for (i = 0, complete = 0; (i < count) && !complete; i++) { + u8 cmd = buf[2*i]; + + switch (cmd) { + case PTN_CMD_DONTCARE: + case PTN_CMD_MATCH: + break; + + case PTN_CMD_MATCHSTAMP: + /* The timestamp needs to be word-aligned in the FIFO +* therefore, the number of 'copy' commands before it +* needs to be a multiple of 4 +*/ + if (copy_before & 3) + return false; + /* Signal that a timestamp will be present */ + ts = 1; + break; + + case PTN_CMD_COPY: + /* Increment count of bytes that will be returned */ + if (ts) + copy_after++; + else + copy_before++; + break; + + case PTN_CMD_COPYDONE: + /* Increment count of bytes that will be
[PATCH v2 1/3] Ethernet packet sniffer: Device tree binding and vendor prefix
Signed-off-by: Stathis Voukelatos --- .../bindings/net/linn-ether-packet-sniffer.txt | 42 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + 2 files changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt new file mode 100644 index 000..74bac5e --- /dev/null +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt @@ -0,0 +1,42 @@ +* Linn Products Ethernet Packet Sniffer +The module allows Ethernet packets to be parsed, matched against +a user-defined pattern and timestamped. It sits between a 100M +Ethernet MAC and PHY and is completely passive with respect to +Ethernet frames. +Matched packet bytes and timestamp values are returned through a +FIFO. Timestamps are provided to the module through an externally +generated Gray-encoded counter. + +Required properties: +- compatible : must be "linn,eth-sniffer" +- reg : physical addresses and sizes of registers. Must contain 3 entries: + - registers memory space + - TX command string memory + - RX command string memory +- reg-names : must contain the following 3 entries: + "regs", "tx-ram", "rx-ram" +- interrupts : sniffer interrupt specifier +- clocks : specify the system clock for the peripheral and + the enable clock for the timestamp counter +- clock-names : must contain the "sys" and "tstamp" entries +- fifo-block-words : number of words in one data FIFO entry +- tstamp-hz : frequency of the timestamp counter +- tstamp-shift : shift value for the timestamp cyclecounter struct +- tstamp-bits : width in bits of the timestamp counter + +Example: + +sniffer@1814a000 { + compatible = "linn,eth-sniffer"; + reg = <0x1814a000 0x100>, <0x1814a400 0x400>, + <0x1814a800 0x400>; + reg-names = "regs", "tx-ram", "rx-ram"; + interrupts = ; + clocks = <&clk_core CLK_AUDIO>, +<&cr_periph SYS_CLK_EVENT_TIMER>; + clock-names = "sys", "tstamp"; + fifo-block-words = <4>; + tstamp-hz = <5200>; + tstamp-shift = <27>; + tstamp-bits = <30>; +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index d443279..891c224 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -90,6 +90,7 @@ lacie LaCie lantiq Lantiq Semiconductor lenovo Lenovo Group Ltd. lg LG Corporation +linnLinn Products Ltd. linux Linux-specific binding lsiLSI Corp. (LSI Logic) lltc Linear Technology Corporation -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v2 0/3] net: Linn Ethernet Packet Sniffer driver
This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Matched packet bytes and timestamp values are returned through a FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command string for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides a common framework for managing backend packet sniffer implementations. Each backend channel is registered by the core as a netdev, which can be accessed from user space through a raw packet socket. - Ethernet Packet Sniffer backend: provides the driver for the Linn Ethernet Packet Sniffer H/W modules. The split between a core and backend modules allows for other implementations to be added in the future apart of the Ethernet packet sniffer presented in this patch set. Changes: v2: * Complete redesign of core framework to use netdev instead of the generic netlink framework * Updated device tree binding * A number of minor code improvements suggested by code review Stathis Voukelatos (3): Ethernet packet sniffer: Device tree binding and vendor prefix Packet sniffer core framework Linn Ethernet packet sniffer driver .../bindings/net/linn-ether-packet-sniffer.txt | 42 +++ .../devicetree/bindings/vendor-prefixes.txt| 1 + MAINTAINERS| 6 + drivers/net/Kconfig| 2 + drivers/net/Makefile | 2 + drivers/net/pkt-sniffer/Kconfig| 19 + drivers/net/pkt-sniffer/Makefile | 7 + drivers/net/pkt-sniffer/backends/ether/channel.c | 392 + drivers/net/pkt-sniffer/backends/ether/channel.h | 81 + drivers/net/pkt-sniffer/backends/ether/hw.h| 46 +++ drivers/net/pkt-sniffer/backends/ether/platform.c | 301 drivers/net/pkt-sniffer/core/module.c | 37 ++ drivers/net/pkt-sniffer/core/netdev.c | 254 + drivers/net/pkt-sniffer/core/snf_core.h| 60 include/uapi/linux/pkt_sniffer.h | 33 ++ 15 files changed, 1283 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt create mode 100644 drivers/net/pkt-sniffer/Kconfig create mode 100644 drivers/net/pkt-sniffer/Makefile create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/platform.c create mode 100644 drivers/net/pkt-sniffer/core/module.c create mode 100644 drivers/net/pkt-sniffer/core/netdev.c create mode 100644 drivers/net/pkt-sniffer/core/snf_core.h create mode 100644 include/uapi/linux/pkt_sniffer.h -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
Hi Daniel, On 27/01/15 14:46, Daniel Borkmann wrote: Just wanted to clarify some implementation details for your approach. - The driver would need to create and register two net_device instances. One for sniffing Ethernet TX packets and one for RX. Hm, I would represent the whole device as a single monitoring-only netdev. I'm somehow still missing the big advantage of all this as compared to using packet sockets on the normal netdev? I couldn't parse that from your commit message. This H/W module was developed to allow accurate timestamping of selected outgoing or incoming data packets. Timestamp values are provided by an external implementation-dependent clock or timer that is of suitable quality for the application. Example: multiple audio receivers synchronizing their clocks to a single transmitter, for synchronized playback. The TX and RX blocks of the sniffer can be operated (eg. started, stopped, configured) independently, that is why I believe two netdev instances would be a better match to the H/W architecture. - Would the control interface for the sniffer in that case need to be through private socket ioctls (ie SIOCDEVPRIVATE + x ioctl ids)? Nope, please have a look at Documentation/networking/packet_mmap.txt. Thanks for the link to the document. That is the way forward for retrieving data from sniffer match events from user space very efficiently. However, I am not sure about configuration, where we want to eg set the command string, or query device attributes such as the size of the command memory. That looks more suitable to an ioctl or a netlink message to me and better use the packet socket just for data from sniffer match events. Thanks, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
Hi Daniel, On 26/01/15 10:10, Daniel Borkmann wrote: Hello Daniel. Thank you for your feedback. Packet sockets could also be used for the driver interface to user space, however I think that both approaches would require the same amount of maintenance. We need to maintain a protocol consisting of a set of messages or commands that user space can use to communicate with the driver in order to configure the H/W and retrieve results. We could use packet sockets to send those messages too, but I thought netlink already provides a message exchange framework that we could make use of. When using packet sockets and your driver as a backend feeding them, users can see that there's an extra capturing/monitoring netdev present, all libpcap-based tools such as tcpdump et al would work out of the box w/o adapting any code, and as an admin you can also see what users/tools are making of use of the device through packet sockets. I couldn't parse the exact motivation from the commit message of why avoiding all this is better? Thanks, Daniel Just wanted to clarify some implementation details for your approach. - The driver would need to create and register two net_device instances. One for sniffing Ethernet TX packets and one for RX. - Would the control interface for the sniffer in that case need to be through private socket ioctls (ie SIOCDEVPRIVATE + x ioctl ids)? - For each ethernet packet that matches the command string the sniffer returns some data bytes and optionally a timestamp (depending on the command string). Would a new protocol need to be added in in order to deliver that data to user space through a packet socket? Thanks, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
Hi Florian, On 26/01/15 22:30, Florian Fainelli wrote: On 23/01/15 02:07, Stathis Voukelatos wrote: This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Is there any latency penalty involved in capturing (or not) packets as opposed to having this capture HW unused? There is no additional latency introduced by the sniffer at the H/W level, if that is what you mean. Only the S/W overhead for handling the sniffer interrupt for each match event. Matched packet bytes and timestamp values are returned through a FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command pattern for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides an API to user space using the Generic Netlink framework. Specific backend implementations, like the Ethernet Packet Sniffer, register one or more channels with the Core. For each channel a Genl family is created. User space can access a channel by sending Genl messages to the Genl family associated with the channel. Packet matching events are multicast. Instead of having this new generic netlink family to control sniffing, could we imagine registering a netdevice which does not nothing but still allows for tools like tcpdump, af_packet and other capture tools to work transparently and just leverage the HW capture? Thanks, I will work on that change. It has been suggested by a previous reviewer too and it makes sense to go down that route. Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 26/01/15 19:39, Joe Perches wrote: This header file is the public API for the driver. Should it not live under the 'include' directory? Several other drivers seem to follow that convention. It depends on how public is public. If it's _really_ public, it should be in uapi. If it's kinda public, then _maybe_ it should be in include/linux, but how likely is it another driver will use it? It is intended for user space code that needs to use the driver as it defines the netlink messages and attributes that the driver understands. So I guess uapi/linux would be the place for it. Thanks, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 23/01/15 10:21, Arnd Bergmann wrote: On Friday 23 January 2015 10:07:01 Stathis Voukelatos wrote: +- interrupts : sniffer interrupt specifier +- clocks : specify the system clock for the peripheral +- clock-names : must contain the "sys" entry +- fifo-block-words : number of words in one data FIFO entry + +Example: + +sniffer@1814a000 { +compatible = "linn,eth-sniffer"; +reg = <0x1814a000 0x100>, <0x1814a400 0x400>, <0x1814a800 0x400>; +reg-names = "regs", "tx-ram", "rx-ram"; +interrupts = ; +interrupt-names = "eth-sniffer-irq"; +clocks = <&system_clk>; +clock-names = "sys"; +fifo-block-words = <4>; The example contains an interrupt-names property that is not documented. If you want to name interrupts, the exact name strings need to be mandated by the binding. Alternatively just drop the name. I notice that the driver requests the first interrupt without giving a name anyway, and the description above suggests that there can only be one interrupt. Arnd Hi Arnd, Yes, we can probably just drop the interrupt name field. It will be done in the next version of the patch set. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 24/01/15 21:37, Joe Perches wrote: On Fri, 2015-01-23 at 10:07 +, Stathis Voukelatos wrote: This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. [] include/linux/pkt_sniffer.h| 89 + Why should this file be here? Why not in the drivers/net/pkt-sniffer directory? Hi Joe, Thank you for the feedback. This header file is the public API for the driver. Should it not live under the 'include' directory? Several other drivers seem to follow that convention. I will include your other suggestions in the next version of the patch set. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 23/01/15 18:12, James Hogan wrote: diff --git a/drivers/net/pkt-sniffer/Kconfig b/drivers/net/pkt-sniffer/Kconfig new file mode 100644 index 000..26b4f98 --- /dev/null +++ b/drivers/net/pkt-sniffer/Kconfig @@ -0,0 +1,23 @@ +menuconfig PKT_SNIFFER +tristate "Linn packet sniffer support" Should the kconfig symbol have linn in the name, or should the prompt not have lin in the name? No it should not actually, as this option enables the core (framework) driver. Anybody could add a backend using the framework. Will change the text. + +config PKT_SNIFFER_ETHER +tristate "Ethernet packet sniffer" +depends on MIPS worth adding || COMPILE_TEST to get compile coverage on x86 allmodconfig builds, or does it have hard dependencies on the MIPS arch? No hard dependencies on MIPS arch. Will change as you suggest. Will implement your other recommendations too in the next version of the patchset. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 23/01/15 10:51, Mark Rutland wrote: diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt new file mode 100644 index 000..6b6e105 --- /dev/null +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt @@ -0,0 +1,27 @@ +* Linn Products Ethernet Packet Sniffer + +Required properties: +- compatible : must be "linn,eth-sniffer" +- reg : physical addresses and sizes of registers. Must contain 3 entries: + first entry: registers memory space + second entry: TX command memory + third entry: RX command memory Just to check: are those memories are part of the packet sniffer device, or are carveouts from other memory? Yes, the 3 memory areas are part of the packet sniffer module. +- fifo-block-words : number of words in one data FIFO entry + +Example: + +sniffer@1814a000 { +compatible = "linn,eth-sniffer"; +reg = <0x1814a000 0x100>, <0x1814a400 0x400>, <0x1814a800 0x400>; +reg-names = "regs", "tx-ram", "rx-ram"; +interrupts = ; +interrupt-names = "eth-sniffer-irq"; +clocks = <&system_clk>; +clock-names = "sys"; +fifo-block-words = <4>; +}; Surely the relationship between the sniffer, MAC, and PHY should be described, so we know which interface the sniffer is related to? The packet sniffer sits between the MAC and the PHY and monitors TX or RX packets, or both. Will add a description in the binding doc. Your other suggestions too, will be incorporated in the next version of the patch set. Thank you, Stathis -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
On 23/01/15 11:20, Daniel Borkmann wrote: On 01/23/2015 11:07 AM, Stathis Voukelatos wrote: This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Matched packet bytes and timestamp values are returned through a FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command pattern for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides an API to user space using the Generic Netlink framework. Specific backend implementations, like the Ethernet Packet Sniffer, register one or more channels with the Core. For each channel a Genl family is created. User space can access a channel by sending Genl messages to the Genl family associated with the channel. Packet matching events are multicast. - Ethernet Packet Sniffer backend: provides the driver for the Linn Ethernet Packet Sniffer H/W modules. The split between a core and backend modules allows software-only implementations to be added for platforms where no H/W support is available. Based on 3.19-rc5 Signed-off-by: Stathis Voukelatos Please have a look at packet sockets, they offer already all the functionality (if not more) your driver interface to the user space resembles, are transparent to the underlying hardware, and easily can cope with 100Mbit. If I understand this correctly, you are effectively introducing a parallel API *next* to packet sockets to user space that we have to maintain forever ... Thanks ! Hello Daniel. Thank you for your feedback. Packet sockets could also be used for the driver interface to user space, however I think that both approaches would require the same amount of maintenance. We need to maintain a protocol consisting of a set of messages or commands that user space can use to communicate with the driver in order to configure the H/W and retrieve results. We could use packet sockets to send those messages too, but I thought netlink already provides a message exchange framework that we could make use of. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] net: Linn Ethernet Packet Sniffer driver
This patch adds support the Ethernet Packet Sniffer H/W module developed by Linn Products Ltd and found in the IMG Pistachio SoC. The module allows Ethernet packets to be parsed, matched against a user-defined pattern and timestamped. It sits between a 100M Ethernet MAC and PHY and is completely passive with respect to Ethernet frames. Matched packet bytes and timestamp values are returned through a FIFO. Timestamps are provided to the module through an externally generated Gray-encoded counter. The command pattern for packet matching is stored in module RAM and consists of a sequence of 16-bit entries. Each entry includes an 8-bit command code and and 8-bit data value. Valid command codes are: 0 - Don't care 1 - Match: packet data must match command string byte 2 - Copy: packet data will be copied to FIFO 3 - Match/Stamp: if packet data matches string byte, a timestamp is copied into the FIFO 4 - Copy/Done: packet data will be copied into the FIFO. This command terminates the command string. The driver consists of two modules: - Core: it provides an API to user space using the Generic Netlink framework. Specific backend implementations, like the Ethernet Packet Sniffer, register one or more channels with the Core. For each channel a Genl family is created. User space can access a channel by sending Genl messages to the Genl family associated with the channel. Packet matching events are multicast. - Ethernet Packet Sniffer backend: provides the driver for the Linn Ethernet Packet Sniffer H/W modules. The split between a core and backend modules allows software-only implementations to be added for platforms where no H/W support is available. Based on 3.19-rc5 Signed-off-by: Stathis Voukelatos --- .../bindings/net/linn-ether-packet-sniffer.txt | 27 ++ .../devicetree/bindings/vendor-prefixes.txt| 1 + MAINTAINERS| 7 + drivers/net/Kconfig| 2 + drivers/net/Makefile | 1 + drivers/net/pkt-sniffer/Kconfig| 23 ++ drivers/net/pkt-sniffer/Makefile | 8 + drivers/net/pkt-sniffer/backends/ether/channel.c | 366 ++ drivers/net/pkt-sniffer/backends/ether/channel.h | 76 drivers/net/pkt-sniffer/backends/ether/hw.h| 46 +++ drivers/net/pkt-sniffer/backends/ether/platform.c | 231 +++ drivers/net/pkt-sniffer/core/dev_table.c | 124 ++ drivers/net/pkt-sniffer/core/module.c | 37 ++ drivers/net/pkt-sniffer/core/nl.c | 427 + drivers/net/pkt-sniffer/core/nl.h | 34 ++ drivers/net/pkt-sniffer/core/snf_core.h| 64 +++ include/linux/pkt_sniffer.h| 89 + 17 files changed, 1563 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt create mode 100644 drivers/net/pkt-sniffer/Kconfig create mode 100644 drivers/net/pkt-sniffer/Makefile create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.c create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/hw.h create mode 100644 drivers/net/pkt-sniffer/backends/ether/platform.c create mode 100644 drivers/net/pkt-sniffer/core/dev_table.c create mode 100644 drivers/net/pkt-sniffer/core/module.c create mode 100644 drivers/net/pkt-sniffer/core/nl.c create mode 100644 drivers/net/pkt-sniffer/core/nl.h create mode 100644 drivers/net/pkt-sniffer/core/snf_core.h create mode 100644 include/linux/pkt_sniffer.h diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt new file mode 100644 index 000..6b6e105 --- /dev/null +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt @@ -0,0 +1,27 @@ +* Linn Products Ethernet Packet Sniffer + +Required properties: +- compatible : must be "linn,eth-sniffer" +- reg : physical addresses and sizes of registers. Must contain 3 entries: + first entry: registers memory space + second entry: TX command memory + third entry: RX command memory +- reg-names : must contain the following 3 entries: + "regs", "tx-ram", "rx-ram" +- interrupts : sniffer interrupt specifier +- clocks : specify the system clock for the peripheral +- clock-names : must contain the "sys" entry +- fifo-block-words : number of words in one data FIFO entry + +Example: + +sniffer@1814a000 { +compatible = "linn,eth-sniffer"; +reg = <0x1814a000 0x100>, <0x1814a400 0x400>, <0x1814a800 0x400>; +reg-names = "regs", "tx-ram", "rx-ram"; +i