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 Units, and many other modules in the kernel. the world outside is much bigger than we think.
What is USB core? She 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, a common device needs to work normally. In addition to a device, it also needs a winter Controller called host controller. Foreigners call it host controller, another hacker who connects to the Controller is "root Hub". We should be familiar with the hub. In college, some dormitories have limited network ports, however, when our generation went to college, there was basically one computer for each person, so the network port was not enough, so some people would use the hub to allow multiple people to share one network port. This is the hub on Ethernet, 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 you can only use one USB device at a time. For example, if you have inserted a USB flash drive, you can also insert a USB keyboard and 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 and The Hub is also called the root hub. In other words, the hub associated 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, USB devices can be directly connected to the root Hub without using other hubs. what is the use of the hub? What is the use of the USB host controller? Controller, controller, as its name implies, is used to control, control, and control the communication between all USB devices. generally, the CPU of a computer does not directly deal with a USB device, but with a controller. If he wants to do something to the device, he will tell the controller instead of sending the command directly to the device, then the Controller is responsible for handling this matter. He will direct the device to execute commands, and the CPU will not care about the rest of the work. Why should he do it, the Controller completes the remaining tasks for him, and then notifies the CPU after the tasks are completed. 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, for example, he and his female masters will be filled with flowers and snow. the three department heads will arrange the following persons to execute specific tasks. After the completion, they will report like the president.
Therefore, Linux kernel developers have written some code specifically and named it USB core. the times are always evolving. Yang Guifei was still fascinated by Tang minghuang, and now people enjoy 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 for the host controller-related code, called the host directory. This is because the development of USB host controller has also begun to provide several types, there is no more than one type at the beginning, so designers Some common host controller code remains in the core directory, while some separate host controller code is moved to the host directory for maintenance by the person in charge of various host controllers, there are three common host controller types: EHCI, uhci, and OHCI. Therefore, we come up with three concepts: USB core, USB host, and USB device, which are originally a family, but it is actually divided into three places on both sides of the Taiwan Strait... indeed, the reality is always helpless. However, if you know the direction of the soul, Even if you cannot stay together on the eve of the day? Yes, 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. this kind of rule is naturally reflected in the Code. so what we need to know is not only about the winter in drivers/USB/storage/directory, but also about the world outside.