Some technical information about NICs in Linux (1)

Source: Internet
Author: User
Tags kingston technology
Article Title: some technical information about NICs in Linux (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
For those who want to learn more about how NICs work, how to use existing drivers, and try to write their own drivers for NICs that are not currently supported, this information should be useful. If you do not have this idea, skip this section.
  
1 programmable I/O, shared memory and DMA
  
If you can send and receive back-to-back data packets, you cannot put more data on the network. Each modern Ethernet card can receive back-to-back packets. Linux DP8390 drivers (wd80x3, SMC-Ultra, 3c503, ne2000, etc.) can basically send back-to-back data packets (depending on the current interrupt latency ), the hardware of 3c509 and AT1500 has no problem in automatically sending back-to-back data packets.
  
The ISA bus can reach 5.3 MB/sec (42 Mb/sec), which is sufficient for 10 Mbps Ethernet. For Mbps NICs, it is clear that a faster bus is needed to make full use of the network bandwidth.
  
Programmable I/O (such as NE2000 and 3c509)
  
Advantage: no restricted system resources are used, only I/O registers are used, and there is no 16 m limit.
  
Disadvantage: generally, the transmission rate is slow, the CPU needs to wait, and it is almost impossible to access cross data packets.
  
Shared memory (such as WD80x3, SMC-Ultra, 3c503)
  
Advantage: simple, faster than programmable I/O, and allows random access to data packets. If possible, the Linux driver calculates the checksum when copying the received IP packet from the NIC, which further reduces the CPU usage than the corresponding PIO Nic.
  
Disadvantage: the use of high-end memory space (which is a big problem for DOS users and is no problem in Linux) still requires CPU usage.
  
Direct memory access from the slave (normal) (this is not the case in Linux !)
  
Advantage: the CPU is not used during actual data transmission.
  
Disadvantage: checking boundary conditions, allocating adjacent caches, and DMA register programming make this method the slowest technology. It also occupies a precious DMA channel and requires alignment of the low-end memory cache.
  
Direct memory access controlled by bus (such as LANCE and DEC 21040)
  
Advantage: the cache can be serialized without occupying the CPU during data transmission, and the CPU time is very small or not spent on the ISA bus. Most bus-controlled Linux drivers now use a "copybreak" scheme. large data packets are directly put into the kernel's network cache from the NIC, the CPU copies small data packets to the cache for further processing.
  
Disadvantages: (only applicable to ISA bus NICs) NICs require a low-end memory cache and a DMA channel. Any bus controller may have problems when working with other bus controllers, such as some old SCSI adapters. There are several poorly designed motherboard chipsets that are also troublesome to use with bus controllers. One reason not to use any type of DMA device is that a 386 processor plug-in designed to replace 486 is used: these processors must refresh the cache during each DMA cycle. (These include Cx486DLC, Ti486DLC, Cx486SLC, and Ti486SLC .)
  
  
2. write the driver
  
In Linux, only the corresponding driver is required to use the Ethernet card. Therefore, the key is that the manufacturer wants to publish the technical materials for programming to the public without any agreement you (or others) sign. About the possibility of getting information (maybe you don't write code, that is, the possibility of others writing the driver you actually need), a better guide is Crynwr (nee Clarkson) the availability of the package driver. Russ Nelson is doing this and is very helpful for developing Linux drivers. Online surfers can try to look at Russ's software.
  
Russ Nelson's Packet Drivers
  
With the information, you can write drivers for the NIC and use them in Linux (at least theoretically ). Remember, some old-fashioned hardware designed for the XT type does not work well in a multitasking environment like Linux. If the network traffic is high, using these NICs will cause great trouble.
  
Most NICs have drivers with MS-DOS interfaces such as NDIS and ODI, but they are useless for Linux. Many people suggest directly linking them or automatically translating them, but this is almost impossible. The MS-DOS driver needs to be in 16-bit mode and dependent on "software interrupt", which is incompatible with the Linux kernel. This incompatibility is actually a feature of Linux, and some Linux drivers are much better than their corresponding MS-DOS drivers. For example, the "8390" series drivers use the ping-pong transfer cache. this method has just been introduced to MS-DOS.
  
(Table tennis transfer cache means using at least two packages of the maximum size for transmitted packets. When the network adapter sends one of them, load the other. After the first package is sent, the second package is immediately sent, and so on. In this way, most NICs can send back-to-back packets to the line consecutively .)
  
Okay. You can write a driver for the Foobar Ethernet NIC because you have programming materials and no one has written this driver. (...) You can start with the network driver framework provided in the Linux kernel source code tree. This file/usr/src/linux/drivers/net/skeleton. c can be found in all recent kernels. You can also see the following URL's Kernel Hackers Guide: KHG
  
  
3. kernel driver interface
  
The following describes the functions required to write a new driver. It is clearer to read with the driver framework mentioned above.
  
  
Probe
  
It is called to check whether the Nic exists at startup. It is best to perform a check by unforced means such as reading the memory. It can also be read from the I/O port. It is difficult to write to the I/O port at the start of the probe, because this may damage another device. Some devices are usually initialized here (I/O space allocation, IRQ, fill dev-> ??? Domain ). You must understand which I/O ports/memory can be configured for the NIC, how to enable shared memory (if used), and how to select/enable interrupt generation.
  
Interrupt handling program
  
The program called by the kernel when the NIC is interrupted. He needs to determine the cause of the NIC interruption and perform corresponding operations. Generally, the interruption condition is that data is received, sent completely, and an error is reported. You need to know the relevant interrupt status bit for corresponding operations.
  
Transfer function
  
It is linked to dev-> hard_start_xmit () and called when the kernel wants to transmit data through a device. This function puts data into the network card and triggers transmission. You need to know how to package and pass the data to the NIC (shared memory copy, PIO transfer, DMA ?), And the correct location of the Eni. Then you need to know how to notify the NIC to send data to the line, and (possibly) initiate an interruption after sending. When the hardware cannot receive more data packets, you need to set the dev-> tbusy flag. When the NIC has space available, this usually occurs when the transfer is interrupted. The dev-> tbusy mark is cleared and the previous layer is notified with mark_bh (INET_BH.
  
Receiving function
  
When the Nic reports data, it is called by the kernel interrupt handler. It removes data from the NIC, puts it in a sk_buff, and tells the kernel where the data is located by executing netif_rx (sk_buff. You need to know how to enable interrupt generation when receiving data, how to check the relevant receipt status bits, and how to obtain data from the NIC (through shared memory copy, PIO, DMA, etc ).
  
Open a function
  
And dev-> open link. when ifconfig eth0 up is used, the network layer calls it-connects the device to the line and enables it to receive/send data. Any special initialization operations that are not completed during the probe process (enable IRQ generation, etc.) are carried out here.
  
Disable a function (optional)
  
When ifconfig eth0 is down, enable the NIC to enter a sober state. If the hardware permits, it releases the interrupt and DMA channels and completely closes them to save energy (like the transceiver ).
  
Other functions
  
Like a reset function, if something gets worse, the driver can try to reset the NIC as the final line of defense. This is generally done when the sending Times out or in a similar case. It is also a function for reading the Nic statistical registers. if so.
  
  
4 3Com technical information
  
If you are interested in the work of the 3Com NIC driver, you can obtain technical information from 3Com. Cameron kindly told us how to do it:
  
In our "technical references", we provide information that 3Com Ethernet adapter driver programmers need to know. These manuals describe the programmer interfaces on the board, but do not mention what end users see, such as diagnostics and installation programs.
  
The marketing department of the network adapter division provides technical reference materials for distribution. To make this plan more effective, we will centralize it into an automatic telephone system called "CardFacts. You can call and fax the materials to you. For technical reference, call 408-727-7021. Request the developer's order. the document number is 9070. Prepare your fax number before making a call. After filling out the order, fax it to 408-764-5004. The manual will be delivered by the federal express delivery service the next day.
  
Some people think that our manuals should not be free, and they are looking for evidence that the system is too expensive or takes up too much time and effort. So far, 3Com's customers have been very good and the requirements we have made are reasonable. We need your cooperation and maintain such services.
  
  
5 precautions for AMD PCnet/LANCE-based NICs
  
AMD's LANCE (Ethernet LAN controller) was first provided and has been replaced by the "PCnet-ISA" chip. Otherwise, it is also named 79C960. Note that there is something wrong with the name "LANCE", and some people will refer to the new chip as old names. Dave Roberts of AMD's network product division provides the following information about the chip:
  
"In terms of functionality, it is equivalent to NE1500. Its register Group is the same as the old LANCE with an additional 1500/2100 structure. PCnet-ISA can use an earlier 1500/2100 driver. The structure of NE1500 and NE2100 is basically the same. Novell first called it 2100, but later he wanted to distinguish the coaxial cable from the 10BASE-T Nic. If the value belongs to 10BASE-T, only the serial number in the range of 1500 is used. This is the only difference.
  
Many companies provide PCnet-ISA-based products, including HP, Racal-Datacom, Allied Telesis, Boca Research, and Kingston Technology. Except that some manufacturers have added the "No Jumper" feature to allow software to configure NICs, these NICs are basically the same. Most manufacturers do not add this feature. AMD provides a standard design package for NICs using PCnet-ISA, and many manufacturers directly use our design without any change. That is to say, if you want to write a majority of PCnet-ISA-based Nic drivers, you only need to obtain data from AMD. Call our data distribution center (800) 222-9323 to obtain the PCnet-ISA data Am79C960. This is free.
  
To quickly learn whether a network card is a "standard" network card, you only need to check it. If it is standard, there is only one large core on the NIC
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.