Multi-platform universal method for accessing mdio bus in user mode
By registering the mixed device mdio_xspeed in the operating system kernel, a unified mdio interface is provided for the application layer, which solves the problem of low versatility of mdio interfaces on different CPUs, and realizes unified control of mdio buses of different CPUs, reducing switching chips The adapted number of tasks has accelerated the R&D progress and performance optimization debugging speed.
Patent Information
- Application Number
- CN202411493400.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, the mdio interface has low versatility when facing different CPUs, resulting in large amount of adaptation tasks for switching chips and affecting R&D progress.
By registering a mixed device mdio_xspeed in the operating system kernel, the application layer provides a unified control interface for different CPU mdio buses, and the network chip is initialized directly through this interface to reduce the amount of tasks adapted by switching chips.
It realizes unified control of the mdio bus of different CPUs, reduces the amount of tasks for switching chip adaptation, accelerates the research and development progress of new products, and improves the debugging speed of product performance optimization.
Smart Images

Figure CN119441085A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of MDIO bus control, and in particular relates to a user mode access MDIO bus method universal to multiple platforms. Background Art
[0002] In the network communication equipment industry, MII (Media Independent Interface) is a standard interface used to connect MAC (Media Access Control) and PHY (Physical). MII is an Ethernet standard defined by IEEE-802.3. The MII interface can control multiple PHYs at the same time. mdio (Management Data Input / Output) is also commonly referred to as MIIM (Media Independent Interface Management) or SMI (Serial Management Interface), which is used to implement MAC management and control of PHY chips, such as network port rate setting, network port duplex mode setting, auto-negotiation enable control, etc.
[0003] A Chinese invention patent with announcement number "CN111090509B" discloses a method for accessing mdio resources, including the following steps: receiving mdio resource access requests initiated simultaneously by a first CPU and a second CPU; obtaining the status of the mdio resource, and the access priority level of the first CPU and the access priority level of the second CPU; when the mdio resource is in a non-occupied state, comparing the access priority level of the first CPU with the access priority level of the second CPU; if the access priority level of the first CPU and the access priority level of the second CPU are different, allocating the right to access the mdio resource to the CPU with a higher access priority level among the first CPU and the second CPU.
[0004] Firewalls, SD-WAN (Software-Defined Wide Area Network) and other devices are used as traffic monitoring and forwarding devices, and their performance requirements are also strict. In the actual design and application of equipment manufacturers, the cost of equipment chips is also strictly controlled, and the performance of network cards and CPUs is often further explored. The use of the DPDK (Data Plane Development Kit) framework can greatly improve data processing performance and throughput, so that the hardware can perform better. At present, the DPDK framework is isolated from the kernel. The switch chip and PHY chip mounted under the mdio bus need to be initialized in user mode and provide a control interface for the DPDK program. In devices with different CPUs, since the CPU mdio controller information is different, they all face the need to adapt the mdio interface configured for the switch chip and PHY chip to access, which greatly affects the workload of equipment manufacturers during development. Summary of the invention
[0005] The present invention provides a user-mode method for accessing an mdio bus universally on multiple platforms, aiming to provide a universal mdio interface to solve the problem that the mdio interface in the prior art has low universality when facing different CPUs, thereby resulting in a large amount of switching chip adaptation tasks during the research and development process.
[0006] To solve the above technical problems, the method for accessing the mdio bus proposed by the present invention comprises the following steps: S1: The driver module calls the interface provided by the kernel to register during the initialization process; S2: The driver module traverses the device tree and obtains description information of the matching CPU mdio or network card device from the device tree; S3: Judge the obtained description information. If the network card node in the device tree has been matched with the relevant network card driver and the mdio bus interface has been registered, directly call the relevant interface; if it is not registered, obtain the described mdio controller information and register the relevant interface according to the protocol used; S4: Create an operation interface for use by the application layer, where operations of the operation interface include read and write; S5: Generate an mdio_xspeed device in the system, wherein the mdio_xspeed device is used to provide an mdio unified interface for the network chip driver of the DPDK, and the mdio unified interface is used to implement access configuration to the network chip; S6: The user layer accesses the underlying mdio device by reading and writing the mdio_xspeed device.
[0007] Preferably, the step S5 is specifically: Create a promiscuous device, the device name of the promiscuous device is mdio_xspeed, and register it as a promiscuous driver device; Add read and write operation function interfaces on the hybrid device; In the read and write operation functions, the read and write protocols are specified.
[0008] Preferably, the interface provided by the kernel is a module_init macro, which is used to specify an initialization function called by the kernel when loading a driver module, and the initialization function includes the startup logic of the driver module.
[0009] Preferably, the description information includes the address, interrupt information, and register configuration of the device.
[0010] Preferably, the read operation interface is used by a user program to read status information of a device, and the write operation interface is used by a user program to send configuration commands to a device.
[0011] Preferably, the unified interface is also used for the user layer to call and read and write the mdio_xspeed device.
[0012] Preferably, in step S6, the user-mode program on the user layer performs read and write operations on the mdio_xspeed device according to the operation function interface provided by the mdio_xspeed device, and passes in the data information array defined by the read and write protocol to complete an access.
[0013] Preferably, the data information array includes a device address, a bus number, a register, a data size, and register data to be written or read.
[0014] Compared with the prior art, the present invention has the following technical effects: 1. The mdio bus access method proposed in the present invention provides a unified control interface for different CPU mdio buses for the application layer by registering a promiscuous device mdio_xspeed in the operating system kernel. In the process of adapting the DPDK driver, the network chip can be initialized directly through the interface. The mdio-related information of the CPU only needs to be described in the device tree, and the mdio_xspeed device can be processed, thereby providing a unified mdio control interface for the DPDK network card driver to use. It can greatly reduce the workload of switching chip adaptation and speed up the research and development progress of new products.
[0015] 2. The mdio bus access method proposed in the present invention is directly applied to the use environment using DPDK because the mdio_xspeed device therein provides a unified control interface for the network chip driver of DPDK, thereby accelerating the debugging speed of product performance optimization. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a flow chart of the method of the present invention; Figure 2 is a block diagram of the interface usage architecture used in an embodiment of the present invention; Figure 3 This is a user mode access flow chart of an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the objectives, technical solutions and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in combination with specific embodiments of the present application and with reference to the accompanying drawings.
[0018] like Figure 1 As shown, a multi-platform universal user mode method for accessing the mdio bus includes the following steps: S1: The driver module calls the interface provided by the kernel to register during the initialization process.
[0019] The kernel provides some interfaces for the driver to register its own functions with the kernel at runtime. When the module is initialized, the driver registers itself by calling the interface provided by the kernel so that it can be loaded when the system is running. The interface provided by the kernel is the module_init macro, which is used to specify the initialization function called by the kernel when loading the driver module. The initialization function includes the startup logic of the driver module.
[0020] S2: The driver module traverses the device tree and obtains description information of the matching CPU mdio or network card device from the device tree.
[0021] The device tree is a data structure that describes the embedded system hardware and its connection relationships. The driver module needs to check each node of the device tree and obtain the description information of the hardware devices such as CPU, MDIO controller or network card from the device tree. The description information may include address, interrupt information, register configuration, etc. This process is to obtain detailed configuration information of the system hardware so that the driver module can correctly initialize and interact with the hardware.
[0022] S3: The obtained description information is judged. If the network card node in the device tree has been matched with a related network card driver and the mdio bus interface has been registered, the related interface is directly called; if it is not registered, the described mdio controller information is obtained, and the related interface is registered according to the protocol used.
[0023] In this step, the driver module obtains the description information in the device tree, including information about the network card node and the related network card driver and MDIO controller. The driver module first checks whether there are other network card drivers in the device tree that match the currently described network card node, and these network card drivers have registered the MDIO bus interface. If there is a match and it has been registered, it means that other drivers have already processed the current network card. In order to avoid conflicts and repeated initialization, the relevant interface can be called directly.
[0024] If the network card node in the device tree does not have a related registered driver, it means that the current driver module may need to process the network card. The driver module obtains the specific information of the MDIO controller contained in the description information. And registers the MDIO bus interface according to the described MDIO controller information and possible protocols. This includes initializing and configuring the MDIO controller to ensure the correctness of communication with the network card. The registered interface includes functions such as reading and writing registers and initiating MDIO transactions.
[0025] S4: Create an operation interface for use by the application layer, where operations of the operation interface include read and write.
[0026] The read operation interface is used for the user program to read the status information of the device, and the write operation interface is used for the user program to send configuration commands to the device. After the driver module is initialized, in order to allow the user space application to interact with the driver module, a set of operation interfaces need to be created, and the operation interface includes functions that can be called by the application to perform specific operations. Among them, read is used to read the data in the register to obtain the status, configuration and other relevant information of PHY, such as information about the current link status, rate, duplex mode, etc. can be read from the status register, and the manufacturer ID, device ID and other information of PHY can be obtained by reading the identification register, which is used to uniquely identify the PHY device. Write can configure various parameters and modes of PHY, such as writing the control register of PHY can configure the working mode, rate, duplex mode, etc. of PHY. Writing the auto-negotiation register of PHY can manually configure the parameters related to auto-negotiation, such as whether you want PHY to run in full-duplex or half-duplex mode.
[0027] S5: Generate an mdio_xspeed device in the system. The mdio_xspeed device is used to provide an mdio unified interface for the DPDK network chip driver. The mdio unified interface is used to implement access configuration to the network chip, specifically: Create a promiscuous device, the device name of the promiscuous device is mdio_xspeed, and register it as a promiscuous driver device; Add read and write operation function interfaces on the hybrid device; In the read and write operation functions, the read and write protocols are specified.
[0028] Specifically, in the Linux kernel, promiscuous devices are usually created and registered through the Misc device interface, including the necessary header files such as linux / miscdevice.h and<linux / fs.h> ; Then define the operation functions of the promiscuous device in the block code, including open, release, read, write, etc., and implement them selectively according to the needs; define the struct miscdevice structure for the promiscuous device; then call the misc_register function in the module initialization function to register the promiscuous device.
[0029] Furthermore, firstly, MDIO related information is saved in the private data structure of the promiscuous device, and a field is added to the private data structure of the promiscuous device to store related information of the MDIO controller, such as bus number, device address, etc.; then, MDIO related information is set when the promiscuous device is initialized, and the related information can be the description information obtained in step S2; then, the API provided by DPDK or the MDIO API of the Linux kernel is used to perform read and write operations as needed. The user layer realizes the multiplexing of multiple buses and multiple devices by calling the device read and write interface and providing the bus number and device address of the corresponding mdio device.
[0030] S6: The user layer accesses the underlying mdio device by reading and writing the mdio_xspeed device. In step S6, the user state program on the user layer reads and writes the mdio_xspeed device according to the operation function interface provided by the mdio_xspeed device, and passes in the data information array defined by the read and write protocol to complete an access.
[0031] Figure 2The interface usage architecture block diagram used in this embodiment includes a DPDK layer and a system kernel layer. The DPDK layer includes a network chip, which communicates with the outside world through the mdio interface of the DPDK layer. Before the network chip runs, it needs to be initialized to meet the usage scenario; the system kernel layer includes a device tree and an mdio interface driver, and the device tree contains the CPU network card information described in this embodiment. The mdio interface is provided to the network chip (also called PHY / switching chip) driver for use, and the hardware register is modified through it. In this embodiment, a hybrid driver device named "mdio_xspeed" is registered in the system kernel. The hybrid driver device provides a unified mdio interface to communicate with the outside world. The kernel also unifies the hybrid device driver for the mdio controllers of different CPUs and provides a unified mdio unified interface. Specifically, in this embodiment, the mdio interface of the DPDK layer communicates with the mdio unified interface of the system kernel layer.
[0032] Furthermore, the device tree contains description information of mdio or network card devices of multiple different types of CPUs used.
[0033] Furthermore, the mdio unified interface is also used for the user layer to call and read and write the mdio_xspeed device.
[0034] Figure 3 is a user-mode access flow chart of this embodiment. In the user layer of this embodiment, the user-mode program (i.e. Figure 3 The application program in the system) performs read and write operations on the mdio_xspeed device according to the operation function interface provided by the mdio_xspeed device, and passes in the data information array (communication data array) defined by the read and write protocol to complete an access. The data information array includes the device address, bus number, register, data size, and register data written or read. The data information array encapsulated by the user layer reads and writes the mdio_xspeed device (mixed device) registered by the system kernel through the mdio unified interface, parses the read and write operations of the mdio interface driver on the mixed device in the system kernel, and reads and writes the underlying mdio related devices through the driver.
[0035] The above is only a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several modifications and improvements without departing from the inventive concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A user-mode method for accessing the mdio bus in a multi-platform manner, characterized in that: The following steps are involved: S1: The driver module calls the interface provided by the kernel to register during the initialization process; S2: The driver module traverses the device tree and obtains description information of the matching CPU mdio or network card device from the device tree; S3: judging the obtained description information, if the network card node in the device tree has been matched with the relevant network card driver and the mdio bus interface has been registered, directly calling the relevant interface; If not registered, obtain the described mdio controller information and register the related interfaces according to the protocol used; S4: Create an operation interface for use by the application layer, where operations of the operation interface include read and write; S5: Generate an mdio_xspeed device in the system, wherein the mdio_xspeed device is used to provide an mdio unified interface for the network chip driver of the DPDK, and the mdio unified interface is used to implement access configuration to the network chip; S6: The user layer accesses the underlying mdio device by reading and writing the mdio_xspeed device.
2. According to a multi-platform universal user mode access mdio bus method according to claim 1, it is characterized in that: The step S5 is specifically as follows: Create a promiscuous device, the device name of the promiscuous device is mdio_xspeed, and register it as a promiscuous driver device; Add read and write operation function interfaces on the hybrid device; In the read and write operation functions, the read and write protocols are specified.
3. A multi-platform universal user mode method for accessing mdio bus according to claim 1, characterized in that: The interface provided by the kernel is the module_init macro, which is used to specify an initialization function called by the kernel when loading a driver module. The initialization function includes the startup logic of the driver module.
4. A multi-platform universal user mode method for accessing mdio bus according to claim 1, characterized in that: The description information includes the address, interrupt information, and register configuration of the device.
5. The multi-platform universal user mode method for accessing the mdio bus according to claim 1, characterized in that: The read operation interface is used by the user program to read the status information of the device, and the write operation interface is used by the user program to send configuration commands to the device.
6. A multi-platform universal user mode method for accessing mdio bus according to claim 1, characterized in that: The unified interface is also used for the user layer to call and read and write the mdio_xspeed device.
7. A multi-platform universal user mode method for accessing mdio bus according to claim 2, characterized in that: In step S6, the user state program on the user layer performs read and write operations on the mdio_xspeed device according to the operation function interface provided by the mdio_xspeed device, and passes in the data information array defined by the read and write protocol to complete an access.
8. A multi-platform universal user mode method for accessing mdio bus according to claim 7, characterized in that: The data information array includes a device address, a bus number, a register, a data size, and register data to be written or read.
Citation Information
Patent Citations
A method for accessing MDIO resources, a storage medium, and a smart terminal
CN111090509B