Before reading the code, I have been seriously thinking about this issue. Do I need to pay attention to more than 3000 lines of code under the drivers/usb/storage/directory? Is that how many files can make different USB flash drives work in Linux? Compare this directory...
Before reading the code, I have been seriously thinking about this issue. Do I need to pay attention to more than 3000 lines of code under the drivers/usb/storage/directory? Is that how many files can make different USB flash drives work in Linux? If we compare this directory to a small town in the beginning, maybe the moonlight in the city is very beautiful. she can shine her dream and warm her heart. But can we really stay in this city for the whole of our life?
Unfortunately, the problem is far from that simple. The outside world is wonderful. as a USB flash drive, she needs to deal with USB Core, SCSI Core, memory management unit, and many other modules in the kernel. The world outside is much bigger than we are.
What is USB Core? It is responsible for implementing some core functions and providing services for drivers of other devices, such as applying for memory, and implementing public functions required by all devices. In fact, in the world of USB, to make a common device work normally, in addition to the device itself, there must also be a Host Controller ), root Hub is connected to the controller.
The Hub on the Ethernet should not be unfamiliar. multiple computers can share one network port. In the world of USB, there is also a Hub. In fact, the principle is the same. any computer that supports USB does not mean that only one USB device can be used at a time. for example, if a USB flash drive is inserted, you can also insert a USB keyboard or a USB mouse, because you will find that your computer is not just a USB interface. These ports are actually so-called Hub ports. In reality, a USB controller is often bound with a Hub, that is, integration, which is also called the Root Hub. In other words, the Hub that is bound with the USB controller is the most fundamental Hub in the system. other hubs can be connected to her, and can be extended to external devices. of course, no other Hub is needed, connect the USB device directly to the Root Hub.
So what is the use of the USB host controller itself? The controller, as its name implies, is used to control the communication between all USB devices. Generally, a computer's CPU does not directly deal with a USB device, but with a controller. instead of sending commands directly to the device, it will tell the controller what it wants to do to the device, the controller is responsible for handling this issue and will direct the device to execute commands, while the CPU does not care about the remaining tasks. why should we do it? the controller completes the remaining tasks for him, after the task is completed, the CPU is notified.
Otherwise, it is unrealistic to let the CPU stare at every device and do everything. it is like letting the dean of a college stare at each of our undergraduates and manage our attendance, it is unrealistic. Therefore, we are divided into several departments. generally, if the president has any instructions to directly talk to the department leaders, if he wants to talk to the three department heads, even if he doesn't call all three people for a meeting, he can call each of them. after the call, he will be busy with his own affairs.
Therefore, Linux kernel developers specially wrote some code and named it USB Core. The times are always evolving. Yang Guifei was still fascinated by Tang Minghuang, and now people appreciate the devil's body like Lin Zhiling. Similarly, in the early Linux kernel, its structure was not as expressive as it is today, and it was far from being so messy as it is today. at that time, many files were stored under the drivers/usb/directory, the code of USB Core and drivers of various other devices is piled up here. later, how can this problem be solved.
Therefore, a core directory is displayed under the drivers/usb/directory, and some core code is put specifically, such as initializing the entire USB system, initializing the Root Hub, and initializing the host controller code, later, I even created a separate directory named host Directory for the host controller-related code. this is because the development of the USB host controller has also begun to provide several types, there is no more than one type as in the beginning. Therefore, designers leave some common host controller code in the core directory, some individual code of each host controller is moved to the host directory for maintenance by the person in charge of various host controllers. Common host controllers include EHCI, UHCI, and OHCI.
Therefore, there are three concepts: USB Core, USB host controller, and USB device. The reality is always helpless. However, if you know the direction of the soul, even if you cannot stay with us overnight? That's right. the soul of USB communication is the USB protocol. USB protocol will be the game rule that all USB devices and USB hosts must follow. Such rules are also naturally reflected in the code. So what we need to know is not only the files under the drivers/usb/storage/directory, but also the world outside, although we only need to know a little bit.
*****************************
From Linux, I am USB.