嵌入式linux中文站在线图书

Previous Page Next Page

Chapter 14. Block Drivers

In This Chapter

416
421
422
423
426
434
436
437


Block devices are storage media capable of random access. Unlike character devices, block devices can hold filesystem data. In this chapter, let's find out how Linux supports storage buses and devices.


Storage Technologies

Let's start by taking a tour of the popular storage technologies found in today's computer systems. We'll also associate these technologies with the corresponding device driver subsystems in the kernel source tree.

Integrated Drive Electronics (IDE) is the common storage interface technology used in the PC environment. ATA (short for Advanced Technology Attachment) is the official name for the related specifications. The IDE/ATA standard began with ATA-1; the latest version is ATA-7 and supports bandwidths of up to 133MBps. Intervening versions of the specification are ATA-2, which introduced logical block addressing (LBA); ATA-3, which enabled SMART-capable disks (discussed later); ATA-4, which brought support for Ultra DMA and the associated 33MBps throughput; ATA-5, which increased maximum transfer speeds to 66MBps; and ATA-6, which provided for 100MBps data rates.

Storage devices such as CD-ROMs and tapes connect to the standard IDE cable using a special protocol called the ATA Packet Interface (ATAPI).[1]ATAPI was introduced along with ATA-4.

[1] The ATAPI protocol is closer to SCSI than to IDE.

The floppy disk controller in PC systems has traditionally been part of the Super I/O chipset about which we learned in Chapter 6, "Serial Drivers." These internal drives, however, have given way to faster external USB floppy drives in today's PC environment.

Figure 14.1 shows an ATA-7 disk drive connected to an IDE host adapter that's part of the South Bridge chipset on a PC system. Also shown connected are an ATAPI CD-ROM drive and a floppy drive.

Figure 14.1. Storage media in a PC system.


IDE/ATA is a parallel bus technology (sometimes called Parallel ATA or PATA) and cannot scale to high speeds, as you learned while discussing PCIe in Chapter 10, "Peripheral Component Interconnect." Serial ATA (SATA) is a modern serial bus evolution of PATA that supports transfer speeds in the realm of 300MBps and beyond. In addition to offering higher throughput than PATA, SATA brings capabilities such as hot swapping. SATA technology is steadily replacing PATA. See the sidebar "libATA" to learn about the new ATA subsystem in the kernel that supports both SATA and PATA.

libATA

libATA is the new ATA subsystem in the Linux kernel. It consists of a set of ATA library routines and a collection of low-level drivers that use them. libATA supports both SATA and PATA. SATA drivers in libATA have been around for some time under drivers/scsi/, but PATA drivers and the new drivers/ata/ directory that now houses all libATA sources were introduced with the 2.6.19 kernel release.

If your system is enabled with SATA storage, you need the services of libATA in tandem with the SCSI subsystem. libATA support for PATA is still experimental, and by default, PATA drivers continue to use the legacy IDE drivers that live in drivers/ide/.

Assume that your system is SATA-enabled via an Intel ICH7 South Bridge chipset. You need the following libATA components to access your disk:

  1. The libATA core鈥� To enable this, set CONFIG_ATA during kernel configuration. For a list of library functions offered by the core, grep for EXPORT_SYMBOL_GPL inside the drivers/ata/ directory.

  2. Advanced Host Controller Interface (AHCI) support鈥� AHCI specifies the register interface supported by SATA host adapters and is enabled by choosing CONFIG_AHCI at configuration time.

  3. The host controller adapter driver鈥� For the ICH7, enable CONFIG_ATA_PIIX.

Additionally, you need the mid-level and upper-level SCSI drivers (CONFIG_SCSI and friends). After you have loaded all these kernel components, your SATA disk partitions appear to the system as /dev/sd*, just like SCSI or USB mass storage partitions.

The home page of the libATA project is http://linux-ata.org/. A DocBook is available as part of the kernel source tree in Documentation/DocBook/libata.tmpl. A libATA developer's guide is available at www.kernel.org/pub/linux/kernel/people/jgarzik/libata.pdf.


Small Computer System Interface (SCSI) is the storage technology of choice in servers and high-end workstations. SCSI is somewhat faster than SATA and supports speeds of the order of 320MBps. SCSI has traditionally been a parallel interface standard, but, like ATA, has recently shifted to serial operation with the advent of a bus technology called Serial Attached SCSI (SAS).

The kernel's SCSI subsystem is architected into three layers: top-level drivers for media such as disks, CD-ROMs, and tapes; a middle-level layer that scans the SCSI bus and configures devices; and low-level host adapter drivers. We learned about these layers in the section "Mass Storage" in Chapter 11, "Universal Serial Bus." Refer back to Figure 11.4 in that chapter to see how the different components of the SCSI subsystem interact with each other.[2] USB mass storage drives use flash memory internally but communicate with host systems using the SCSI protocol.

[2] SCSI support is discussed in other parts of this book, too. The section "User Mode SCSI" in Chapter 19, "Drivers in User Space," discusses the SCSI Generic (sg) interface that lets you directly dispatch commands from user space to SCSI devices. The section "iSCSI" in Chapter 20, "More Devices and Drivers," briefly looks at the iSCSI protocol, which allows the transport of SCSI packets to a remote block device over a TCP/IP network.

Redundant array of inexpensive disks (RAID) is a technology built in to some SCSI and SATA controllers to achieve redundancy and reliability. Various RAID levels have been defined. RAID-1, for example, specifies disk mirroring, where data is duplicated on separate disks. Linux drivers are available for several RAID-capable disk drives. The kernel also offers a multidisk (md) driver that implements most RAID levels in software.

Miniature storage is the name of the game in the embedded consumer electronics space. Transfer speeds in this domain are much lower than that offered by the technologies discussed thus far. Secure Digital (SD) cards and their smaller form-factor derivatives (miniSD and microSD) are popular storage media[3] in devices such as cameras, cell phones, and music players. Cards complying with version 1.01 of the SD card specification support transfer speeds of up to 10MBps. SD storage has evolved from an older, slower, but compatible technology called MultiMediaCard (MMC) that supports data rates of 2.5MBps. The kernel contains an SD/MMC subsystem in drivers/mmc/.

[3] See the sidebar "WiFi over SDIO" in Chapter 16, "Linux Without Wires," to learn about nonstorage technologies available in SD form factor.

The section "PCMCIA Storage" in Chapter 9, "PCMCIA and Compact Flash," looked at different PCMCIA/CF flavors of storage cards and their corresponding kernel drivers. PCMCIA memory cards such as microdrives support true IDE operation, whereas those that internally use solid-state memory emulate IDE and export an IDE programming model to the kernel. In both these cases, the kernel's IDE subsystem can be used to enable the card.

Table 14.1 summarizes important storage technologies and the location of the associated device drivers in the kernel source tree.

Table 14.1. Storage Technologies and Associated Device Drivers
Storage TechnologyDescriptionSource File
IDE/ATAStorage interface technology in the PC environment. Supports data rates of 133MBps for ATA-7.drivers/ide/ide-disk.c, driver/ide/ide-io.c, drivers/ide/ide-probe.c

or

drivers/ata/ (Experimental)
ATAPIStorage devices such as CD-ROMs and tapes connect to the standard IDE cable using the ATAPI protocol.drivers/ide/ide-cd.c

or

drivers/ata/ (Experimental)
Floppy (internal)The floppy controller resides in the Super I/O chip on the LPC bus in PC-compatible systems. Supports transfer rates of the order of 150KBps.drivers/block/floppy.c
SATASerial evolution of IDE/ATA. Supports speeds of 300MBps and beyond.drivers/ata/, drivers/scsi/
SCSIStorage technology popular in the server environment. Supports transfer rates of 320MBps for Ultra320 SCSI.drivers/scsi/
USB Mass StorageThis refers to USB hard disks, pen drives, CD-ROMs, and floppy drives. Look at the section "Mass Storage" in Chapter 11. USB 2.0 devices can communicate at speeds of up to 60MBps.drivers/usb/storage/, drivers/scsi/
RAID:
Hardware RAIDThis is a capability built into high-end SCSI/SATA disk controllers to achieve redundancy and reliability.drivers/scsi/, drivers/ata/
Software RAIDOn Linux, the multidisk (md) driver implements several RAID levels in software.drivers/md/
SD/miniSD/microSDSmall form-factor storage media popular in consumer electronic devices such as cameras and cell phones. Supports transfer rates of up to 10MBps.drivers/mmc/
MMCOlder removable storage standard that's compatible with SD cards. Supports data rates of 2.5MBps.drivers/mmc/
PCMCIA/ CF storage cardsPCMCIA/CF form factor of miniature IDE drives, or solid-state memory cards that emulate IDE. See the section "PCMCIA Storage" in Chapter 9.drivers/ide/legacy/ide-cs.c

or

drivers/ata/pata_pcmcia.c (experimental)
Block device emulation over flash memoryEmulates a hard disk over flash memory. See the section "Block Device Emulation" in Chapter 17, "Memory Technology Devices."drivers/mtd/mtdblock.c, drivers/mtd/mtd_blkdevs.c
Virtual block devices on Linux:
RAM diskImplements support to use a RAM region as a block device.drivers/block/rd.c
Loopback deviceImplements support to use a regular file as a block device.drivers/block/loop.c


 

Previous Page Next Page