HAM_Scan_For_Devices (Function 0x01)

Mandatory function. Tells the HAM to scan (probe) for devices attached to a specified bus and build a list of detected devices on that bus.

Overview

For each device in its list, the HAM is expected to fill out an instance of a DeviceInfoStruct, which includes a HAM-generated, unique access handle (deviceHandle) to the device. The HAM will receive one scan request for each bus instance it registers using HAI_Activate_Bus.

The HACB indicating this function is received on a non-blocking thread. Because a bus scan could take milliseconds or even seconds to complete, the HAM should spawn (schedule) a separate, blocking thread to perform the physical scan. Blocking threads can be created using NPA_Spawn_Thread.

HAM_Scan_For_Devices must handle four different scan cases according to the parameters given in the HACB's host command block. NWPA classifies each scan case as either Case 0, Case 1, Case 2, or Case 3 corresponding to the value received in the parameter2 field of the host command block. Case 0 scans are issued by the OS, and Cases 1 - 3 scans are issued by CDMs.

These scan cases also tell the HAM whether to declare a device public or private. The Public vs. Private Devices section defines this concept in detail.

The objectives of each scan case are as follows:

Case

Description

Case 0:

This scan case tells the HAM to perform a typical “scan for new devices” by probing all public target locations. These locations include unit number 0 (and any other unit numbers as specified under Case 2) of all target IDs on the specified bus. This scan case is issued by the OS, and an object for each device is created and added to the Media Manager's device database.

The command “scan for new devices” is a NetWare command that can be issued from any .ncf file or at the command line by the user. The purpose of “scan for new devices” is to make storage devices attached to the server visible to the NetWare OS.)

The term unit number is a generic term that refers to device subaddresses if they are defined by the host architecture. For example, in the SCSI architecture this number refers to the Logical unit number, or LUN.

Case 1:

This scan case tells the HAM to probe a particular unit number on a particular target ID of the bus. If a device is detected, it is declared private, and information about the device is returned as defined by NWPA's DeviceInfoStruct. A device object is not created for the Media Manager's device database. This scan case is issued by a CDM allowing it to probe unit numbers other than zero of the specified target ID to detect additional devices that enhance the functionality of the unit number 0 device. An example would be a magazine, addressed at unit number 1, attached to a tape drive at unit number 0.

Case 2:

This scan case has the same function and purpose as the Case 1 scan except that the target device is declared public, and a device object is created and added to the Media Manager's device database.

Case 3:

This scan tells the HAM to discard the device object, associated with the specified unit number and target ID, from its device list. This scan case is issued by a CDM.

The remaining subsections provide more details by describing the following:

Public vs. Private Devices

The HAM does not decide the public/private attribute of a device. This decision is made either by the OS (Case 0) or a CDM (Cases 1 and 2) according to the scan case issued. The HAM declares a device public by clearing the Private_Public_Flag in the attributeFlags field of the device's DeviceInfoStruct. To declare a device private, the HAM sets the Private_Public_Flag. All devices detected by Case 0 and Case 2 scans should be declared public. All devices detected by a Case 1 scan should be declared private.

Following a Case 0 or Case 2 scan, the HAM's HAM_Return_Device_Info (Function 0x02) function gets called on the target bus, which reports the bus's device list to NWPA. For all public devices in the list, NWPA creates a corresponding device object and adds it into the Media Manager's device database. The Media Manager then makes these devices visible to the application layer. This is the criterion that defines a public device.

The criterion that defines a private device is that the device's Private_Public_Flag is set, and no corresponding object is added to the Media Manager's device database. Thus, the device is not visible to the application layer. NWPA makes private devices visible only to the CDM layer.

Scan Case Definitions and Descriptions

This subsection defines the HACB's host command block parameters associated with each scan case along with a paradigm description of the how the HAM should handle each case.

Case 0: Probe all Unit Number 0s and Make Detected Devices Public

INPUTS from HACB

Field Values in Host Command Block

function
1
parameter0
Unit Number Mask
parameter1
Target ID Mask (-1 will scan all target IDs)
parameter2
0

OUTPUTS to HACB

hacbCompletion
Appropriate scan completion code.

Remarks

A Case 0 scan request is issued by the NetWare OS following a “scan for new devices” command issued either in a .ncf file or at the command line by a user.

When the HAM receives a Case 0 scan request, it is expected to do the following:

  1. Probe unit number 0 of all target IDs selected by the Target ID mask (and any other target IDs and unit numbers specified under Case 2) on the target bus to detect devices.

    Any device object added to the device list through a Case 2 scan should also be probed and updated in any subsequent Case 0 scans.

  2. For each device detected, create an object describing the device, including information defined by NWPA's DeviceInfoStruct, and place it in a device list for that bus.

    An essential data member of the DeviceInfoStruct is the unique deviceHandle the HAM assigns to the device. This deviceHandle is the token that NWPA and CDMs will use to route HACB I/O requests, through the HAM, to a device.

  3. Make the device public by clearing the Private_Public_Flag in the attributeFlag field of the device's DeviceInfoStruct.
  4. After finishing the scan on the target bus, set the HACB's hacbCompletion field to SUCCESSFUL_COMPLETION (0x00000000), complete the HACB using HAI_Complete_HACB, and then return.

Case 1: Probe Specified Target ID and Unit Number, Return Info and Make Detected Device Private

INPUTS from HACB

Field Values in Host Command Block

function
1
parameter0
Unit Number
parameter1
Target ID
parameter2
1

Field Values in Main HACB

deviceHandle
-1 indicating a request for a first-time peek at the target ID and unit number. The calling CDM does not have ownership of the private device; therefore, execution restrictions apply to this request.

OUTPUTS to HACB

controlInfo
Size of (struct DeviceInfoStruct)
vDataBufferPtr
Pointer to the buffer where the HAM will copy the device’s DeviceInfoStruct information.
hacbCompletion
Appropriate scan completion code.

Remarks

A Case 1 scan request is issued by a CDM, allowing it to inquire about the existence of a device on a specific target ID and unit number (other than unit number 0). The purpose of this scan case is to grant a CDM private access to a device attached to the target ID and unit number by providing the CDM with a deviceHandle.

When the HAM receives a Case 1 scan request it is expected to do the following:

  1. Probe the specified target ID (parameter1) and unit number (parameter0):

    If the HAM detects a device at this location and there is no corresponding object for this device already existing in the HAM's device list:

    1. Create an object describing the device, including information defined by NWPA's DeviceInfoStruct, and place it in a device list for that bus.

      NOTE:An essential data member of theDeviceInfoStruct is the unique deviceHandle the HAM assigns to the device. This deviceHandle is the token that the CDM uses to route HACB I/O requests, through the HAM, to a device.

    2. Make the device private by setting the Private_Public_Flag in the attributeFlag field of the device's DeviceInfoStruct.
    3. Copy the device’s DeviceInfoStruct information into the buffer pointed at by the HACB's vDataBufferPtr field.
    4. Place the size, in bytes, of the return buffer in Step 3 in the HACB's controlInfo field.
    5. Set the HACB's hacbCompletion field to SUCCESSFUL_COMPLETION (0x00000000).
    6. Complete the HACB using HAI_Complete_HACB.

    If the HAM detects a device at this location and a corresponding object for this device already exists in the HAM's device list and the value in the HACB's deviceHandle field matches a device handle assigned to an object in the HAM's device list:

    1. Do Steps b through e above.
    2. Complete the HACB using HAI_Complete_HACB.

    If the HAM detects a device at this location and a corresponding object for this device already exists in the HAM's device list and the value in the HACB's deviceHandle field is equal to -1:

    1. Set the HACB's hacbCompletion field to TARGET_IN_USE (0x000A0003).
    2. Complete the HACB using HAI_Complete_HACB.

    If the HAM does not detect a device at this location:

    1. Set the HACB's hacbCompletion field to DEVICE_NOT_FOUND (0x000A0001).
    2. If a device object exists in the HAM's device list, meaning that at one time a device did exist at the target ID and unit number but has now gone away, the HAM should remove the object from the list and free the memory using NPA_Return_Memory.
    3. Complete the HACB using HAI_Complete_HACB.
  2. Return 0.

Case 2: Probe Specified Target ID and Unit Number, Return Info, and Make Detected Device Public

INPUTS from HACB

Field Values in Host Command Block

function
1
parameter0
Unit Number
parameter1
TargetID
parameter2
2

Field Values in Main HACB

deviceHandle
-1 indicating a request for a first-time peek at the target ID and unit number. The calling CDM does not have ownership of the device if it is private; therefore, execution restrictions apply to this request.

A handle that maps to a private device already existing in the HAM's device list. The HAM returned this device handle to the calling CDM in a previous Case 1 scan request, thereby giving the CDM exclusive ownership of the private device. Because of device ownership, no execution restrictions apply to this request.

OUTPUTS to HACB

controlInfo
Size of (struct DeviceInfoStruct)
vDataBufferPtr
Pointer to the buffer where the HAM will copy the device's DeviceInfoStruct information.
hacbCompletion
Appropriate scan completion code.

Remarks

A Case 2 scan request is issued by a CDM, allowing it to inquire about the existence of a device on a specific target ID and unit number (other than unit number 0) and make the device public.

Any device object added to the device list through a Case 2 scan should also be probed and updated in any subsequent Case 0 scans.

IMPORTANT:This function is required to support user scan commands or the /LUN command line option. See LUNs.

When the HAM receives a Case 2 scan request it is expected to do the following:

  1. Probe the specified target ID (parameter1) and unit Number (parameter0):

    If the HAM detects a device at this location and there is no corresponding object for this device already existing in the HAM's device list:

    1. Create an object describing the device, including information defined by NWPA's DeviceInfoStruct, and place it in a device list for that bus.

      An essential data member of the DeviceInfoStruct is the unique deviceHandle the HAM assigns to the device. This deviceHandle is the token that the CDM uses to route HACB I/O requests, through the HAM, to a device.

    2. Make the device public by clearing the Private_Public_Flag in the attributeFlag field of the device's DeviceInfoStruct.
    3. Copy the device's DeviceInfoStruct information into the buffer pointed at by the HACB's vDataBufferPtr field.
    4. Place the size, in bytes, of the return buffer in Step 3 in the HACB's controlInfo field.
    5. Set the HACB's hacbCompletion field to SUCCESSFUL_COMPLETION (0x00000000).
    6. Complete the HACB using HAI_Complete_HACB.

    If the HAM detects a device at this location and a corresponding object for this device already exists in the HAM's device list and the value in the HACB's deviceHandle field matches a device handle assigned to an object in the HAM's device list:

    1. Do Steps b through e above.
    2. Complete the HACB using HAI_Complete_HACB.

    If the HAM detects a device at this location and a corresponding object for this device already exists in the HAM's device list and the value in the HACB's deviceHandle field is equal to -1:

    1. Set the HACB's hacbCompletion field to TARGET_IN_USE (0x000A0003).
    2. Complete the HACB using HAI_Complete_HACB.

    If the HAM does not detect a device at this location:

    1. Set the HACB's hacbCompletion field to DEVICE_NOT_FOUND (0x000A0001).

      IMPORTANT:If a device object exists in the HAM's device list, meaning that at one time a device did exist at the target ID and unit number but has now gone away, the HAM should remove the object from the list and free the memory using NPA_Return_Memory.

    2. Complete the HACB using HAI_Complete_HACB.

    If the HAM does not detect a device at this location and it determines there are no more devices attached to the current target ID (parameter1):

    1. Set the HACB's hacbCompletion field to NO_MORE_LUNS (0x000A0000).
    2. Complete the HACB using HAI_Complete_HACB.
  2. Return 0.

Case 3: Remove Device Object from Device List

INPUTS from HACB

Field Values in Host Command Block

function
1
parameter0
Unit Number
parameter1
Target ID
parameter2
3

Field Values in Main HACB

deviceHandle
-1 indicating a request for a first-time peek at the target ID and unit number. The calling CDM does not have ownership of the device if it is private; therefore, execution restrictions apply to this request.

A handle that maps to a private device already existing in the HAM's device list. The HAM returned this device handle to the calling CDM in a previous Case 1 or Case 2 scan request, thereby giving the CDM exclusive ownership of the private device. Because of device ownership, no execution restrictions apply to this request.

OUTPUTS to HACB

hacbCompletion
Appropriate scan completion code.

Remarks

A Case 3 scan request is issued by a CDM after it determines that a device object (found from a previous Case 1 or Case 2 scan request) is a phantom, or in other words, a reflection of the device at unit number 0. Its main purpose is to have the HAM remove the target object from its device list.

When the HAM receives a Case 3 scan request, it is expected to do the following:

If the target object does not exist, meaning a previous Case 1 or Case 2 scan request was never received for the target ID and unit number:

  1. Set the HACB's hacbCompletion field to OBJECT_NOT_FOUND (0x000A0004).
  2. Complete the HACB using HAI_Complete_HACB.
  3. Return 0.

If the target object exists, but the value in the HACB's deviceHandle field is equal to -1:

  1. Set the HACB's hacbCompletion field to TARGET_IN_USE (0x000A0003).
  2. Complete the HACB using HAI_Complete_HACB.
  3. Return 0.

If the target object exists and the value in the HACB's deviceHandle field matches the target object's device handle:

  1. Remove the device object associated with the specified target ID (parameter1) and unit number (parameter0) from the device list and free the memory using NPA_Return_Memory.
  2. Set the HACB's hacbCompletion field to SUCCESSFUL_COMPLETION (0x00000000).
  3. Complete the HACB using HAI_Complete_HACB.
  4. Return 0.

Scan Completion Codes

Scan Completion Codes summarizes the scan completion codes described in the specific cases above. The table also includes additional error-completion codes common to all scan cases. These completion codes are posted to the HACB's hacbCompletion field.