1

I was reading through the Linux Device Drivers, Third Edition book and in the "Putting It All Together" section in Chapter 14, they mention the interaction between "PCI core, driver core and the individual PCI drivers." And they used the word "driver core" multiple other times. Is the "driver core" different from the "character device driver"?

My question is arises from the intent of understanding the InfiniBand stack. The IB stack spans both the user-space and the kernel-space. So, if I am writing a simple ping-pong InfiniBand program to run on the Mellanox ConnectX-4 NIC, my binary will depend on 2 user-space libraries: libibverbs and libmlx5, AND 3 kernel-modules: ib_uverbs, mlx5_ib and mlx5_core. I know ib_uverbs is a character device driver. But can we consider the mlx5_ib and mlx5_core kernel modules as some category of driver? Or are their functions just globally exported in order to interface with them?

2 Answers2

2

The driver core is the generic code that manages drivers, devices, buses, classes, etc. It is not tied to a specific bus or device. I believe the chapter you refer to provides several examples to the division of labor between the PCI bus driver and the driver core, for example, see Figure 14-3 (Device-creation process).

Of the three kernel modules you mention, two participate in the device core: ib_uverbs registers its character devices to export RDMA functionality to user-space; mlx5_core registers a PCI driver to handle ConnectX NICs; mlx5_ib can also be considered a driver, but the RDMA subsystem doesn't use the device core to register drivers (it has its own API - ib_register_device).

haggai_e
  • 4,689
  • 1
  • 24
  • 37
0

what is driver core ??

Observe following flow of calls in Linux Source.
tps65086_regulator_probe---> devm_regulator_register--> regulator_register-->device_register(/drivers/regulator/tps65086-regulator.c--->/drivers/regulator/core.c---> drivers/base/core.c ).
tps65086 driver calls regulator core which in turn calls driver core. This driver is following standard driver model.

include/linux/device.h ----> driver model objects are defined here.
drivers/base/ --> All Functions that operate on driver model objects are defined here.
we can refer this as driver core and is base for any driver Frame work. All the registrations come here from Higher Layers. Any driver subsystem ..weather PCI/USB/Platform is based on this.
drivers/base/core.c -- is the core file of standard driver model.
A slight confusion in naming - However we can refer drivers/base/ - as driver core .

Any difference character driver vs other driver ??

/drivers/char/tlclk.c tlclk_init-->register_chrdev -->register_chrdev --> cdev_add --> kobj_map (fs/char_dev.c ---> /drivers/base/map.c ).
a character device registration is done with char_dev, a file system driver, which again uses infrastructure of driver model base.

whare as a non character driver like tps65086-regulator.c, may register with driver core as below. tps65086_regulator_probe---> devm_regulator_register--> regulator_register-->device_register-->device_add-->kobject_add (/drivers/regulator/tps65086-regulator.c--->/drivers/regulator/core.c---> drivers/base/core.c )

Also It's not just based on type of driver , but based on what kind of device it is and how device needs to be handled. Here is a pci-driver which register's a character device. tw_probe-->register_chrdev --> cdev_add --> kobj_map ( /drivers/scsi/3w-xxxx.c -->fs/char_dev.c ---> /drivers/base/map.c )

There is no standard rule wether a driver should call driver core or not.
Any stack / framework can have its own core to manage a device,which is the case with the driver mlx5_ib (drivers/infiniband/core/).
But Finally mostly it will use Kobject infrastructure and driver model objects,like struct device.
driver model infrastructure is introduced to eliminate redundant kernel code and data structures.
so most drivers are based on this and it is the effective way of writing a linux driver.

sudheer
  • 11
  • 4