Run-Time Configuration

A user might occasionally want to change the interface configuration at run time. If, for example, the IRQ number can’t be probed for, the only way to have it properly configured is through a trial-and-error technique. A user-space program can retrieve the device’s current configuration or set a new configuration by invoking ioctl on an open socket. The ifconfig application, for instance, uses ioctl to set the I/O port for an interface.

We saw earlier how one of the methods defined for network interface is set_config. The method is used to set or change some interface features at run time.

When a program asks for the current configuration, the kernel extracts the information from struct device without notifying the driver; on the other hand, when a new configuration is passed to the interface, the set_config method is called so the driver can check the values being passed and take appropriate action. The driver method responds to the following prototype:

int (*set_config)(struct device *dev, struct ifmap *map);

The map argument points to a copy of the structure passed by the user program; the copy is already in kernel space, so the driver doesn’t need to call memcpy_from_fs.

The fields of struct ifmap are:

unsigned long mem_start; , unsigned long mem_end; , unsigned short base_addr; , unsigned char irq; , unsigned char dma;

These fields correspond to the fields in struct device.

unsigned char port;

This field corresponds to if_port, as found in dev. The ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.