At the top of your driver code, after all other included header files, you need to write two lines of code:
where DEVICE_MAJOR is the major number of your device. drivers/block/blk.h requires the use of the MAJOR_NR define to set up many other defines and macros for your driver.
Now you need to edit blk.h. Under #ifdef MAJOR_NR, there is a section of defines that are conditionally included for certain major numbers, protected by #elif (MAJOR_NR == DEVICE_MAJOR). At the end of this list, you will add another section for your driver. In that section, the following lines are required:
DEVICE_NAME is simply the device name. See the other entries in blk.h for examples.
DEVICE_REQUEST is your strategy routine, which will do all the I/O on the device. See section for more details on the strategy routine.
DEVICE_ON and DEVICE_OFF are for devices that need to be turned on and off, like floppies. In fact, the floppy driver is currently the only device driver which uses these defines.
DEVICE_NR(device) is used to determine the number of the physical device from the minor device number. For instance, in the hd driver, since the second hard drive starts at minor 64, DEVICE_NR(device) is defined to be (MINOR(device)>>6).
If your driver is interrupt-driven, you will also set
which will become a variable automatically defined and used by the remainder of blk.h, specifically by the SET_INTR() and CLEAR_INTR macros.
You might also consider setting these defines:
where n is the number of jiffies (clock ticks; hundredths of a second on /386) to time out after if no interrupt is received. These are used if your device can become ``stuck'': a condition where the driver waits indefinitely for an interrupt that will never arrive. If you define these, they will automatically be used in SET_INTR to make your driver time out. Of course, your driver will have to be able to handle the possibility of being timed out by a timer. See section ?? for an explanation of how to do this.