|
This paper provides the information device driver writers need to convert device drivers to be hotplug-capable. It is applicable to the Solaris 2.6 operating environment. IntroductionThe Solaris 2.6 environment currently supports Dynamic Reconfiguration (DR) (see "References"), which places similar requirements on device drivers. The information in this paper is being provided in advance of PCI hotplugging support in the Solaris product so that driver writers will have sufficient time to develop and test hotplug-capable PCI device drivers. The focus of this paper is on bus interfaces, such as the PCI hotplugging specification (see the PCI Special Internet Group Web Site, which provide a controlled environment for hot removal and insertion of cards. Before you can convert a driver to be hotplug-capable, you need to understand hotplug scenarios and how they affect device drivers. Section 2 describes controlled PCI hotplugging as outlined in the PCI hotplug specification. Section 3 describes the requirements on device drivers and the flow of control during hot removal and insertion. Section 4 outlines the steps required to make a device driver hotplug-capable. Section 5 provides guidelines for testing hotplug-capable device drivers in Solaris 2.6. For more information download Sample Solaris Drivers. This package contains a number of sample drivers that are hotplug-capable and provide greater insight into the process. The document Writing Device Drivers describes in detail how to write a Solaris device driver. This paper complements that document, which is a prerequisite to understanding this paper. (Note: On docs.sun.com, find the version of Writing Device Drivers that matches the release number you are working with.) Writing Device Drivers
does not describe the use of the Overview of PCI HotpluggingThis section summarizes the sequence of events in hot removal and hot insertion that are relevant to the device driver. For more details and terminology definitions, refer to the PCI hotplug specification. Hotplugging typically involves: 1. Preparation Indicate to the system that a hotplug operation will take place on particular hardware. 2. Isolation Specify that the hardware be isolated in preparation for a safe insertion or removal. 3. Removal, insertion, or both Insert and/or replace the hardware. 4. Verification Verify that the card is accessible and perform minimal sanity checks. 5. Integration Re-integrate the hardware back into the system. 6. Configuration Use kernel functions to configure the system, loading and attaching device drivers for newly installed hardware, and deconfiguring the system for removed hardware. Hot Removal With No ReplacementThis operation is used to remove a card. You may want to remove a card because, for example, its failure mode affects system operation. To perform a hotplug removal: 1. Indicate, using an administrative application, that a card needs to be removed or replaced. 2. Through the administrative application, use kernel functions to take the appropriate driver offline. If the driver instance is busy or open, this operation may fail and you will first have to terminate the processes that are accessing the device. 3. Through the administrative application, use kernel functions to turn off the appropriate slot; an optional slot-state indicator will show that the slot is off and it is now safe to remove the card. 4. Remove the card. 5. Inform the administrative application that the card has been removed. Hot InsertionThis procedure is used to insert a card in a previously unused slot. 1. Indicate, using an administrative application, that a card is to be inserted in a particular slot. 2. Through the administrative application, use kernel functions to turn off the appropriate slot (if it isn't off already). An optional slot-state indicator will show that the slot is off. 3. Insert the card. 4. Indicate to the administrative application that the card has been inserted. 5. Through the administrative application, use kernel functions to turn on the slot and the slot-state indicator. 6. Through the kernel, configure the system, and load and attach the device driver for the newly installed hardware. Hot Removal Followed by InsertionThis procedure is used to replace a card with either an identical or a different card. 1. Indicate, using an administrative application, that a card is to be removed or replaced in a given slot. 2. Through the administrative application, use kernel functions to place the appropriate driver offline. If the driver instance is busy or open, this operation may fail and you will first have to terminate any processes that are accessing the device. 3. Use the administrative application to disable the appropriate slot, and turn on an optional slot-state indicator to indicate the physical slot and verify that it is now safe to remove the card. 4. Remove the card. 5. Insert a replacement card. 6. Indicate to the administrative application that a card has been inserted. 7. Through the administrative application, use kernel functions to turn on the slot, and, optionally, turn off the slot-state indicator. 8. Through the kernel, configure the system, and load and attach the device driver for the newly installed hardware. Solaris Hotplugging Driver IssuesThis section describes the flow of control from a device driver perspective. Most device drivers can support hotplugging with minimal changes. Hot RemovalThe kernel checks the
driver state, and if the driver instance is not open, the kernel
can invoke the driver's detach(9E) entry point with the command Hot InsertionHot insertion uses the normal probe(9E) and attach(9E) entry points of a driver after the hardware has been inserted into the slot in a controlled manner. Hotplug-Capable Device Driver DevelopmentThis section briefly discusses how to make Solaris device drivers compliant with the new Solaris technologies of Dynamic Reconfiguration and future Solaris hotplug technologies. D_HOTPLUG FlagHotplug-capable drivers
should set Detach Entry PointThe driver's detach entry point can be called with these commands:
It is strongly recommended to fully implement support for all detach commands. Note the following uses are possible:
During Dynamic Reconfiguration, there are two possible detach scenarios. 1. All the devices on the
detaching system board receive a 2. All devices (other than
those on the detaching system board) receive a
DDI_DETACH Command The If the driver fails the The 1. Check whether The driver can assume that
the device has been closed before The driver should not block while waiting for callback completion or for the device to become idle. Devices that maintain some state after a close operation must be carefully analyzed. When a driver not currently in use is automatically unloaded (for example, because the system memory is low) and later automatically reloaded when the user opens the device, this might cause undesirable operation. For example, a tape driver that supports non-rewinding tape access might fail the detach operation when the tape head is not at the beginning of the tape. If the drive is powered down, the head position will be lost. 2. Shut down the device and disable interrupts. A device needs enough hardware information/support to be able to shut off and restart interrupts. This may already be coded in the driver as a function of the existing detach routines. 3. Remove any interrupts registered with the system. 4. Cancel any outstanding timeouts and callbacks. 5. Quiesce or remove any driver threads. 6. Deallocate memory resources. The driver should be unloadable without memory leaks. 7. Unmap any mapped device registers. 8. Execute 9. Free the softstate structure for this instance. When there is failure during detach, the driver must decide whether to continue the detach and return success or undo the detach actions completed to that point and return failure. Undoing might be risky and it is usually preferable to continue the detach operation.
Note the following when
using
The timeout routine should take the form of:
DDI_SUSPEND CommandSystem power management and
the Dynamic Reconfiguration framework pass the command To process the 1. Set a suspended flag to block new operations. 2. Wait until outstanding operations have completed, or abort them if they can be restarted. 3. Block further operations
from being initiated until the device is resumed (except for
dump(9E) requests). Refer to sample code in Writing Device Drivers and the 4. Cancel pending callouts such as timeout callbacks, and quiesce or destroy other driver threads. 5. Save any volatile hardware state in memory. This state includes the contents of device registers, and can also include downloaded firmware. Power Management in Writing Device Drivers describes in more detail some special power management considerations.
Attach Entry PointThe system calls attach(9E) to attach a device instance to the system or to resume operation after power has been suspended. The driver's attach(9E) entry point should handle these commands:
DDI_PM_RESUME CommandWhen power is restored to
the device that was suspended with The DDI_RESUME CommandWhen power is restored to
the system or the system is unquiesced, each device that was
suspended will be resumed using the If the device is still
suspended by The resume code should make no assumptions about the state of the hardware, which may or may not have lost power. Special Issues With Nexus DriversNexus drivers usually do
not have a
The Device Driver TestingThis section provides some hints for driver testing. UnloadingThe driver should be able to sustain heavy driver activity, followed by module unload, without errors or memory leaks. This can be loop tested as follows (using C shell):
Alternatively:
Suspend/Resume TestingStart up a test on your driver and simultaneously run:
in a loop to test Suspend/Resume. The driver test should check for data corruption or unexpected loss of state. You can also test Suspend/Resume by generating I/O to your device, and then pressing the top-right button on the keyboard to suspend the machine. Then resume the machine; there should be no panics, error messages, or data corruption. If you have access to a server system that supports Dynamic Reconfiguration, you may also want to test your driver on this configuration. ConclusionThe Solaris 2.6 driver
framework provides the necessary hooks to make drivers
hotplug-capable with minimal changes to the driver code. If a
driver already supports the detach commands ReferencesRefer to these materials for additional information on this topic.
| |||
|
| ||||||||||||