What is knet interface and what is it used for? - linux

Can some expert please throw some light on what is knet interface and what is it used for.
One of my container images show knet2 as an interface for output of 'ifconfig'
I have no idea what it is, can someone please explain or point me to documents / web where I can find more about it.

knet is kernel network interface for efficient of packet exchange between switch and the kernel (linux operating system) network protocol stack.
There could be other methods which could used, such as implementing a software connector module over the Open NSL Rx/TX APIs.

The intent of theknet interface is to provide a network interface that
then delivers packets to the NetIO framework from the kernel.
this is nicely explained in user-networking.pdf.
I hope this is what you were expecting. feel free to comment for any clarification.

this is about knet reference
This module implements a Linux network driver for Broadcom
XGS switch devices. The driver simultaneously serves a
number of vitual Linux network devices and a Tx/Rx API
implemented in user space.
Packets received from the switch device are sent to either
a virtual Linux network device or the user mode Rx API
based on a set of packet filters.susp
Packets from the virtual Linux network devices and the user
mode Tx API are multiplexed with priority given to the Tx API

Related

How does the Linux Operating System understand the underlying hardware?

I want to learn how Linux OS understands the underlying hardware.Can anyone suggest me where to start for getting this understanding,As of now i just know the '/dev' sub-directory plays a vital role in that.
It has the device special files which are like a portal to the device driver which then takes it to the physical device.
I read somewhere that Udev daemon listens to the netlink socket to collect this information and Udev device manager detects addition and removal of devices as they occur.
But with these i am just not satisfied with the thought of how Linux reads the hardware.
Please let me know where to start to understand this, i am so thankful to anyone trying to help.
I think at first you need to find out how the memory mapping works. What is the address space and how it relates to physical memory. Then you could read about how the hardware is mapped in address space and how to access it. It is a big amount of docs to read.
Some of those information are in Linux Documentation Project.
Additionally some knowledge about electronic would be helpful.
In general - Linux for communication with devices needs some "channel" of communication. This channel may be for example ISA, PCI, USB, etc bus. For example PCI devices are memory mapped devices and Linux kernel communicates with them via memory accesses. So first Linux needs to see given device in some memory area and then it is able to configure this device and do some communication with it.
In case of USB devices it is a little bit complicated because USB devices are not memory mapped. You need to configure USB host first to be able to communicate with USB devices. Every communication with USB device is achieved via USB host.
There are also devices which are not connected via ISA, PCI or USB. They are connected directly to the processor and visible under some memory address. This solution is usually implemented in embedded devices. For example ARM processors use this approach.
Regarding udev - it is user-space application which listens for events from Linux kernel and helps other applications with recognizing device addition and configuration.

How do I write a network device driver using SPI?

I have implemented a device driver for the NRF24L01+ transceiver in userspace using rust. The userspace driver makes use of the kernel spi interface driver. Writing the driver as kernel module seems incredibly hard, as the documentation for linux/netdevice.h as found in linux device drivers seems outdated (or I'm just not smart enough to understand the intricate details).
A new project from the TU Munich proposes the use of vfio. From my understanding this type of driver implementation uses the iommu to manage isolation to protected memory areas for the devices. "Project Ixy" uses the network device as block device, hence it can be mapped. SPI is different as insofar it is a streaming protocol.
My question is, if it is possible to integrate the user space spi network device driver into the linux network stack, e.g. having all protocols etc handled by the network stack. Is it possible to use a similar approach as Project Ixy, like having a small component in kernel space, which is isolated for security, that builds a "bridge" to userland?
I think it is possible in two ways:
using TAP interface
writing your own "bridging" interface like TAP between user space and kernel space
If ethernet-like interface is enough for you - then use TAP. I mean TAP provides functionality where physical layer is moved to user space. In your case it could work like this: data received by SPI can be pushed to TAP interface to linux network stack. The data received from TAP interface (from Linux network stack) you can push via SPI. Is that what you wanted?
If ethernet-like interace (as TAP is) is not enough for you - you can write your own interface in kernel space basing on TAP sources.

Are RFCOMM packets guarnteed to be whole?

I'm writing an application that interfaces with Bluetooth devices using Headset Profile. These devices primarily communicate via AT commands send over a Serial Port Profile (SPP) connection. SPP is directly on top of RFCOMM.
My concern is whether or not I am guaranteed to receive "whole" packets (AT commands), or if there is a possibility that I will need to be able to handle an AT command split across multiple packets.
Furthermore, if the RFCOMM protocol does not guarantee this, does the protocol stack do any processing to guarantee receiving "whole" AT commands? I am using BlueZ 5.46 on a Linux 4.12 kernel.
If possible, please reference the standard or an external source that details how RFCOMM guarantees this so I can learn a bit more about it.

How to learn network Ethernet device driver programming?

I am looking what piece of hardware should i buy (NIC Or FPGA Or ASIC etc) which i could connect to my system, and write device driver to implement and learn Ethernet device driver typical functions like - packet trapping/ receiving and sending packet/ reprogramming the hardware etc ? How can i learn all this stuff at home ?
I think that if your "system" is a computer, it should have a NIC (or you can buy one). Anyway, you need a computer to write a driver... so download the kernel sources and look at the driver source for the NIC you are using.

Ethernet driver for ethercat modules

I have EK1101, EL6002, EL2034 modules which is based on network devices. These modules are connected PC Ethernet port via ethernet cable. I have tested these modules with some application program, its working fine on my PC.
EK1101 working as a Coupler. It connects PC Ethernet Port and Other slave modules( EL6002, EL2034,..)
EL6002 working as a RS232 communication. EL2034 working as digital I/O. Similarly we have more than 10 different devices. These modules interfaced with EK1101 coupler at same time.
How can i implement as Linux driver? and start?Do I modify the existing network driver or start new driver from scratch? what type of i need to write, character or network driver? If its character driver how can i transfer data through Ethernet port?
Using the serial slice (EL6002) you can only send 22 bytes (each direction) per exchange for each port. At full serial bandwidth (115k) updating at 1kHz, you won't be able to miss an update without starving the transmitter and/or dropping data on the receiver. If that's a concern you will probably need to claim exclusive control over the Ethernet port being used to master the EtherCAT loop. This requires some form of root permissions, otherwise someone can always try to send packets over the port, affecting your timings. You haven't given much detail about your application or timing requirements, so maybe that's not critical for you.
I've been using the Etherlab IgH open source stack, which requires root permissions to load its kernel module which implements the underlying stack. Once that's done you can set everything else up to run from user space without root permissions.
Once your application acquires access to the master stack, you setup a data exchange domain (what TwinCat calls a task) and you will have a region of shared memory that can be used to monitor the EtherCAT frame data. Your application is responsible for deciding when to send and receive domain updates.

Resources