Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Revision 5"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
(Created page with "= = Hook-based callback function extensions for SANA-II (SANA-IIR5) <br /> by [mailto:sana2feedback@amiga.com?subject=Re:%20SANA-IIR5%20proposal Olaf Barthel] and Heinz Wrob...")
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
= =
+
== Authors ==
   
 
Hook-based callback function extensions for SANA-II (SANA-IIR5) <br />
 
Hook-based callback function extensions for SANA-II (SANA-IIR5) <br />
by [mailto:sana2feedback@amiga.com?subject=Re:%20SANA-IIR5%20proposal Olaf Barthel] and Heinz Wrobel
+
by Olaf Barthel and Heinz Wrobel
   
== 1. Introduction ==
+
== Introduction ==
   
 
The last changes proposed for the SANA-II networking driver standard were intended to address the demands of dial-up networking. A new issue has come up which concerns the application and deployment of PowerPC native networking drivers. So far the SANA-II standard only caters well for the Motorola 68000 platform, and the only way to support it on the PowerPC involves a considerable overhead. This is what the following proposal intends to address.
 
The last changes proposed for the SANA-II networking driver standard were intended to address the demands of dial-up networking. A new issue has come up which concerns the application and deployment of PowerPC native networking drivers. So far the SANA-II standard only caters well for the Motorola 68000 platform, and the only way to support it on the PowerPC involves a considerable overhead. This is what the following proposal intends to address.
   
Please feel free to comment; you can contact me through the e-mail address given in the headline of this document. Note that the issues discussed in this document are just a list of proposed changes.
+
Please feel free to comment; you can contact me through the [http://www.amigaos.net/contact AmigaOS contact form]. Note that the issues discussed in this document are just a list of proposed changes.
   
== 2. The problem: parameter passing to the copying functions ==
+
== The problem: parameter passing to the copying functions ==
   
 
The SANA-II driver interface is intended to transform data between the hardware layer and the link layer, to be used by networking software such as TCP/IP stacks. This transformation is performed by call-back functions which are supplied by the networking software at the time the device driver is opened. The device driver then invokes these functions later in order to transfer data received and data to be sent.
 
The SANA-II driver interface is intended to transform data between the hardware layer and the link layer, to be used by networking software such as TCP/IP stacks. This transformation is performed by call-back functions which are supplied by the networking software at the time the device driver is opened. The device driver then invokes these functions later in order to transfer data received and data to be sent.
Line 47: Line 47:
 
system memory functions (since those functions rely on Forbid() to
 
system memory functions (since those functions rely on Forbid() to
 
protect themselves) and that you must not compile this function
 
protect themselves) and that you must not compile this function
with stack checking enabled. See the RKM:Libraries Exec:Interupts
+
with stack checking enabled. See the Exec Interupts
 
chapter for more details on what is legal in a routine called from
 
chapter for more details on what is legal in a routine called from
 
an interupt handler.
 
an interupt handler.
Line 61: Line 61:
 
The following proposal therefore intends to wrap the copying functions into the standardized <tt>Hook</tt> interface.
 
The following proposal therefore intends to wrap the copying functions into the standardized <tt>Hook</tt> interface.
   
== 3. New data structures and commands ==
+
== New data structures and commands ==
   
=== 3.1 Data structures ===
+
=== Data structures ===
   
 
The SANA-IIR4 proposal lists ten copying functions, which can be grouped into two categories: data copying and direct memory access. These functions are:
 
The SANA-IIR4 proposal lists ten copying functions, which can be grouped into two categories: data copying and direct memory access. These functions are:
Line 80: Line 80:
 
** <tt>S2_DMACopyToBuff64</tt>
 
** <tt>S2_DMACopyToBuff64</tt>
 
** <tt>S2_DMACopyFromBuff64</tt>
 
** <tt>S2_DMACopyFromBuff64</tt>
 
   
 
There are three 'flavours' of the data copying functions. These cater for certain buffer memory alignment requirements which the underlying hardware requires or which can be used to boost transfer efficiency. For the direct memory access functions there are two variants which cater for certain memory alignment requirements in the same manner as the copying functions.
 
There are three 'flavours' of the data copying functions. These cater for certain buffer memory alignment requirements which the underlying hardware requires or which can be used to boost transfer efficiency. For the direct memory access functions there are two variants which cater for certain memory alignment requirements in the same manner as the copying functions.
Line 88: Line 87:
 
I propose the following hook messages to be used :
 
I propose the following hook messages to be used :
   
  +
<syntaxhighlight>
<pre> struct SANA2HookMsg
 
  +
struct SANA2HookMsg
{
 
  +
{
ULONG shm_Method;
 
ULONG shm_MsgSize;
+
ULONG shm_Method;
  +
ULONG shm_MsgSize;
};</pre>
 
  +
};
  +
</syntaxhighlight>
  +
 
In this data structure the <tt>shm_Method</tt> field would indicate the task to be performed. This can a be request to copy data or to store a log message. The <tt>shm_MsgSize</tt> field tells you how large the data structure is (for future enhancements which may cause the data structure to grow).
 
In this data structure the <tt>shm_Method</tt> field would indicate the task to be performed. This can a be request to copy data or to store a log message. The <tt>shm_MsgSize</tt> field tells you how large the data structure is (for future enhancements which may cause the data structure to grow).
   
 
For copying operations the message would look like this:
 
For copying operations the message would look like this:
   
  +
<syntaxhighlight>
<pre> struct SANA2CopyHookMsg
 
  +
struct SANA2CopyHookMsg
{
 
  +
{
ULONG schm_Method;
 
ULONG schm_MsgSize;
+
ULONG schm_Method;
  +
ULONG schm_MsgSize;
  +
  +
APTR schm_To;
  +
APTR schm_From;
  +
ULONG schm_Size;
  +
};
  +
</syntaxhighlight>
   
APTR schm_To;
 
APTR schm_From;
 
ULONG schm_Size;
 
};</pre>
 
 
The structure members would be used as follows:
 
The structure members would be used as follows:
   
Line 123: Line 128:
 
For logging operations the message would look like this:
 
For logging operations the message would look like this:
   
  +
<syntaxhighlight>
<pre> struct SANA2LogHookMsg
 
  +
struct SANA2LogHookMsg
{
 
  +
{
ULONG slhm_Method;
 
ULONG slhm_MsgSize;
+
ULONG slhm_Method;
  +
ULONG slhm_MsgSize;
  +
  +
ULONG slhm_Priority;
  +
STRPTR slhm_Name;
  +
STRPTR slhm_Message;
  +
};
  +
</syntaxhighlight>
   
ULONG slhm_Priority;
 
STRPTR slhm_Name;
 
STRPTR slhm_Message;
 
};</pre>
 
 
The structure members would be used as follows:
 
The structure members would be used as follows:
   
Line 169: Line 177:
 
The hook function itself would be invoked with the following parameters:
 
The hook function itself would be invoked with the following parameters:
   
  +
<syntaxhighlight>
<pre> result = hook_function(hook,sana2req,sana2hookmsg)
 
  +
result = hook_function(hook,sana2req,sana2hookmsg)
D0 A0 A2 A1
 
   
 
ULONG hook_function(struct Hook *hook,
 
ULONG hook_function(struct Hook *hook,
 
struct IOSana2Req *sana2req,
 
struct IOSana2Req *sana2req,
struct SANA2HookMsg *sana2hookmsg);</pre>
+
struct SANA2HookMsg *sana2hookmsg);
  +
</syntaxhighlight>
  +
 
Note that the result would not necessarily be of type <tt>ULONG</tt>. It would be a 32 bit value, which would either be a boolean result code (for <tt>CopyFromBuff</tt>, <tt>CopyToBuff</tt> and their like) or the pointer to a memory address (for <tt>DMACopyToBuff</tt>, <tt>DMACopyFromBuff</tt> and their like).
 
Note that the result would not necessarily be of type <tt>ULONG</tt>. It would be a 32 bit value, which would either be a boolean result code (for <tt>CopyFromBuff</tt>, <tt>CopyToBuff</tt> and their like) or the pointer to a memory address (for <tt>DMACopyToBuff</tt>, <tt>DMACopyFromBuff</tt> and their like).
   
=== 3.2 Commands ===
+
=== Commands ===
   
 
The 'traditional' copy call-back functions are installed at <tt>OpenDevice()</tt> time, and they are found in a <tt>TagItem</tt> list which is passed along with the <tt>IOSana2Req</tt>. For the new <tt>Hook</tt>-based call-back functionality, I propose to introduce a new command. This command would take care of installing one single <tt>Hook</tt> which will be invoked with the parameters described in section 3.1. The hook function can key off the <tt>SANA2HookMsg-&gt;schm_Method</tt> field to figure out which function should be performed. Once the <tt>Hook</tt> is installed via the command as follows, the driver shall ignore any and all tags passed to it during <tt>OpenDevice()</tt> time.
 
The 'traditional' copy call-back functions are installed at <tt>OpenDevice()</tt> time, and they are found in a <tt>TagItem</tt> list which is passed along with the <tt>IOSana2Req</tt>. For the new <tt>Hook</tt>-based call-back functionality, I propose to introduce a new command. This command would take care of installing one single <tt>Hook</tt> which will be invoked with the parameters described in section 3.1. The hook function can key off the <tt>SANA2HookMsg-&gt;schm_Method</tt> field to figure out which function should be performed. Once the <tt>Hook</tt> is installed via the command as follows, the driver shall ignore any and all tags passed to it during <tt>OpenDevice()</tt> time.
Line 183: Line 193:
 
The command is tentatively defined as follows:
 
The command is tentatively defined as follows:
   
  +
<pre>
<pre>sana2.device/S2_SANA2HOOK sana2.device/S2_SANA2HOOK
 
  +
sana2.device/S2_SANA2HOOK sana2.device/S2_SANA2HOOK
   
 
NAME
 
NAME
Line 281: Line 292:
 
This field is to be treated as private by a protocol stack.
 
This field is to be treated as private by a protocol stack.
 
IOSana2Req structures may be duplicated by copying
 
IOSana2Req structures may be duplicated by copying
ios2_BufferManagement, io_Device, and io_Unit.</pre>
+
ios2_BufferManagement, io_Device, and io_Unit.
  +
</pre>
  +
 
The new command value is defined as follows:
 
The new command value is defined as follows:
   
  +
<pre>
<pre> #define S2_SANA2HOOK 0xC008</pre>
 
  +
#define S2_SANA2HOOK 0xC008
  +
</pre>
  +
 
The new error code is defined as follows:
 
The new error code is defined as follows:
   
  +
<pre>
<pre> #define S2WERR_FUNCTIONS_MISSING 24 /* mandatory copy functions are missing */</pre>
 
  +
#define S2WERR_FUNCTIONS_MISSING 24 /* mandatory copy functions are missing */
== 4. Application and driver software use of the new functions ==
 
  +
</pre>
  +
  +
== Application and driver software use of the new functions ==
   
 
Since plenty of software exists which uses the 'traditional' <tt>TagItem</tt> list provided at <tt>OpenDevice()</tt> time it is recommend that drivers always examine these parameters and do not expect a <tt>S2_SANA2HOOK</tt> command to be sent later.
 
Since plenty of software exists which uses the 'traditional' <tt>TagItem</tt> list provided at <tt>OpenDevice()</tt> time it is recommend that drivers always examine these parameters and do not expect a <tt>S2_SANA2HOOK</tt> command to be sent later.
Line 294: Line 313:
 
If the new <tt>Hook</tt>-based callback functions are to be used, then the driver must invoke the Hooks via <tt>utility.library/CallHookPkt</tt>. It must not invoke the hook functions through local assembly language stubs or the <tt>amiga.lib/CallHook</tt> and <tt>amiga.lib/CallHookA</tt> functions.
 
If the new <tt>Hook</tt>-based callback functions are to be used, then the driver must invoke the Hooks via <tt>utility.library/CallHookPkt</tt>. It must not invoke the hook functions through local assembly language stubs or the <tt>amiga.lib/CallHook</tt> and <tt>amiga.lib/CallHookA</tt> functions.
   
== 5. Caveats ==
+
== Caveats ==
   
 
The functionality proposed above suggests that one could do entirely without the <tt>TagItem</tt> list passed in at <tt>OpenDevice()</tt> time. However, at this time it is hard to tell how existing driver software will react to empty <tt>TagItem</tt> lists or even a NULL pointer in the <tt>IOSana2Req-&gt;ios2_BufferManagement</tt> field. It is therefore recommend to always provide for a <tt>TagItem</tt> list which includes proper (i.e. they must point to working functions and may not be <tt>NULL</tt>) function pointers for the <tt>S2_CopyToBuff</tt> and <tt>S2_CopyFromBuff</tt> tags. Once the device has been opened successfully, the next step is to try and install the copy <tt>Hook</tt> through the proposed <tt>S2_SANA2HOOK</tt> command. If the command fails, the application can still expect that the <tt>S2_CopyToBuff</tt> and <tt>S2_CopyFromBuff</tt> tags supplied at <tt>OpenDevice()</tt> time will work.
 
The functionality proposed above suggests that one could do entirely without the <tt>TagItem</tt> list passed in at <tt>OpenDevice()</tt> time. However, at this time it is hard to tell how existing driver software will react to empty <tt>TagItem</tt> lists or even a NULL pointer in the <tt>IOSana2Req-&gt;ios2_BufferManagement</tt> field. It is therefore recommend to always provide for a <tt>TagItem</tt> list which includes proper (i.e. they must point to working functions and may not be <tt>NULL</tt>) function pointers for the <tt>S2_CopyToBuff</tt> and <tt>S2_CopyFromBuff</tt> tags. Once the device has been opened successfully, the next step is to try and install the copy <tt>Hook</tt> through the proposed <tt>S2_SANA2HOOK</tt> command. If the command fails, the application can still expect that the <tt>S2_CopyToBuff</tt> and <tt>S2_CopyFromBuff</tt> tags supplied at <tt>OpenDevice()</tt> time will work.
Line 300: Line 319:
 
Note that the <tt>ios2_BufferManagement</tt> field provided by the driver on <tt>OpenDevice()</tt> time in conjunction with <tt>io_Device</tt> and <tt>io_Unit</tt> is the unique identifier for all requests coming from this protocol stack until <tt>CloseDevice()</tt>. The driver must not ever change the <tt>ios2_BufferManagement</tt> field for a protocol stack at run time, even if <tt>S2_SANAHOOK</tt> is called to request extended features.
 
Note that the <tt>ios2_BufferManagement</tt> field provided by the driver on <tt>OpenDevice()</tt> time in conjunction with <tt>io_Device</tt> and <tt>io_Unit</tt> is the unique identifier for all requests coming from this protocol stack until <tt>CloseDevice()</tt>. The driver must not ever change the <tt>ios2_BufferManagement</tt> field for a protocol stack at run time, even if <tt>S2_SANAHOOK</tt> is called to request extended features.
   
== 6. Changes ==
+
== Changes ==
  +
  +
02-May-2012:
  +
  +
* Conversion to MediaWiki format.
   
 
22-Mar-2004:
 
22-Mar-2004:

Latest revision as of 21:55, 10 May 2012

Authors

Hook-based callback function extensions for SANA-II (SANA-IIR5)
by Olaf Barthel and Heinz Wrobel

Introduction

The last changes proposed for the SANA-II networking driver standard were intended to address the demands of dial-up networking. A new issue has come up which concerns the application and deployment of PowerPC native networking drivers. So far the SANA-II standard only caters well for the Motorola 68000 platform, and the only way to support it on the PowerPC involves a considerable overhead. This is what the following proposal intends to address.

Please feel free to comment; you can contact me through the AmigaOS contact form. Note that the issues discussed in this document are just a list of proposed changes.

The problem: parameter passing to the copying functions

The SANA-II driver interface is intended to transform data between the hardware layer and the link layer, to be used by networking software such as TCP/IP stacks. This transformation is performed by call-back functions which are supplied by the networking software at the time the device driver is opened. The device driver then invokes these functions later in order to transfer data received and data to be sent.

These copying functions are designed for low overhead. They use up to three parameters and are documented in the copybuff.doc file which comes with the SANA-II specification. Here is an excerpt which describes the CopyFromBuff function, which is associated with the S2_CopyFromBuff tag:

any_sana2_protocol/CopyFromBuff               any_sana2_protocol/CopyFromBuff

   NAME
        CopyFromBuff -- Copy n bytes from an abstract data structure.

   SYNOPSIS
        success = CopyFromBuff(to, from, n)
        d0                     a0  a1    d0

        BOOL CopyToBuff(VOID *, VOID *, ULONG);

   FUNCTION
        This function copies 'n' bytes of data in the abstract data structure
        pointed to by 'from' into the contigous memory pointed to by 'to'.
        'to' must contain at least 'n' bytes of usable memory or innocent
        memory will be overwritten.

   INPUTS
        to              - pointer to contiguous memory to copy to.
        from            - pointer to abstract structure to copy from.
        n               - number of bytes to copy.

   RESULT
        success         - TRUE if operation was successful, else FALSE.

   NOTES
        This function must be callable from interupts.  In particular, this
        means that this function may not directly or indirectly call any
        system memory functions (since those functions rely on Forbid() to
        protect themselves) and that  you must not compile this function
        with stack checking enabled.  See the Exec Interupts
        chapter for more details on what is legal in a routine called from
        an interupt handler.

        'C' programmers should not compile with stack checking (option '-v'
        in SAS) and should geta4() or __saveds.

As one can see, the function parameters are passed in 68000 registers. Compare this to the packet filter function, which is associated with the S2_PacketFilter tag: it is intended to be invoked as a hook function, as part of the Hook interface in utility.library/CallHookPkt.

The problem with 68000 register parameters is that on the PowerPC platform, this form of parameter passing may require the use of emulation code. This is costly and may incur a severe performance penalty. It is an even greater problem if PowerPC native networking software is calling PowerPC native networking driver software and the other way round. In both cases the runtime environment will have to enter emulation mode, return to to PowerPC native execution, dip into emulation mode and return to native PowerPC execution. It would be much better if the chain of execution would stay in PowerPC mode all the time.

However, if a hook function is used (such as for the packet filter), the operating system may be able to decide whether the function to be invoked needs emulating or could be called straight away. The Hook effectively works as an abstraction which makes the function invocation platform independent.

The following proposal therefore intends to wrap the copying functions into the standardized Hook interface.

New data structures and commands

Data structures

The SANA-IIR4 proposal lists ten copying functions, which can be grouped into two categories: data copying and direct memory access. These functions are:

  • Data copying:
    • S2_CopyToBuff
    • S2_CopyFromBuff
    • S2_CopyToBuff16
    • S2_CopyFromBuff16
    • S2_CopyToBuff32
    • S2_CopyFromBuff32
  • Direct memory access:
    • S2_DMACopyToBuff32
    • S2_DMACopyFromBuff32
    • S2_DMACopyToBuff64
    • S2_DMACopyFromBuff64

There are three 'flavours' of the data copying functions. These cater for certain buffer memory alignment requirements which the underlying hardware requires or which can be used to boost transfer efficiency. For the direct memory access functions there are two variants which cater for certain memory alignment requirements in the same manner as the copying functions.

All these functions are using basically the same set of parameters and 68000 registers. The parameters and result codes are used for different purposes, though. In order to translate the parameters for use with the Hook interface one needs to define a 'hook message' and a set of parameters the hook function is invoked with.

I propose the following hook messages to be used :

struct SANA2HookMsg
{
  ULONG shm_Method;
  ULONG shm_MsgSize;
};

In this data structure the shm_Method field would indicate the task to be performed. This can a be request to copy data or to store a log message. The shm_MsgSize field tells you how large the data structure is (for future enhancements which may cause the data structure to grow).

For copying operations the message would look like this:

struct SANA2CopyHookMsg
{
  ULONG schm_Method;
  ULONG schm_MsgSize;
 
  APTR  schm_To;
  APTR  schm_From;
  ULONG schm_Size;
};

The structure members would be used as follows:

  • schm_Method

    This must be one S2_CopyToBuff, S2_CopyFromBuff, S2_CopyToBuff16, S2_CopyFromBuff16, S2_CopyToBuff32, S2_CopyFromBuff32, S2_DMACopyToBuff32, S2_DMACopyFromBuff32, S2_DMACopyToBuff64 or S2_DMACopyFromBuff64 to identify the function to be performed.

  • schm_MsgSize

    Size of this message data structure in bytes. This must be >= 20 for this message type.

    The driver shall set schm_MsgSize always correctly to be compliant. The protocol stack shall use this field to validate the message and to reject/ignore bad messages via a FALSE hook function return value. For DMA related hooks, a FALSE return value is equivalent to a NULL pointer.

  • schm_To

    Equivalent to the to parameter of the CopyFromBuff, CopyToBuff and DMACopyToBuff functions.

  • schm_From

    Equivalent to the from parameter of the CopyFromBuff and CopyToBuff functions.

  • schm_Size

    Equivalent to the n parameter of the CopyFromBuff, CopyToBuff, functions.

For logging operations the message would look like this:

struct SANA2LogHookMsg
{
  ULONG  slhm_Method;
  ULONG  slhm_MsgSize;
 
  ULONG  slhm_Priority;
  STRPTR slhm_Name;
  STRPTR slhm_Message;
};

The structure members would be used as follows:

  • slhm_Method

    This must be S2_Log, as defined in the SANA-IIR4 specification.

  • slhm_MsgSize

    Size of this message data structure in bytes. This must be >= 20 for this message type.

    The driver shall set slhm_MsgSize always correctly to be compliant. The protocol stack shall use this field to validate the message and to reject/ignore bad messages via a FALSE hook function return value. For DMA related hooks, a FALSE return value is equivalent to a NULL pointer.

  • slhm_Priority

    The smaller this value, the more important the message to be logged or displayed. The following priority levels are defined (similar to the Unix syslog() mechanism):

    • #define S2LOG_Emergency 0

      A panic condition.

    • #define S2LOG_Alert 1

      A condition that should be corrected immediately.

    • #define S2LOG_Critical 2

      Critical conditions.

    • #define S2LOG_Error 3

      A plain error.

    • #define S2LOG_Warning 4

      A warning message.

    • #define S2LOG_Notice 5

      Conditions that are not error conditions, but should possibly be handled specially.

    • #define S2LOG_Information 6

      An informational message.

    • #define S2LOG_Debug 7

      Messages that contain information normally of use only when debugging.

    Only these priority values may be used by a driver. It is suggested that a driver is configurable to generate different types of messages or not, e.g., a driver may be configured to only emit S2LOG_Emergency and S2LOG_Debug messages.

  • slhm_Name

    Pointer to a NUL-terminated string which identifies the source of this message. This can be NULL in which case the OS device name of the driver shall be used by the protocol stack.

  • slhm_Message

    Pointer to a NUL-terminated string which contains the log message. The text should not contain any formatting characters such as line feeds or carriage returns. The slhm_Message member must never be NULL.

    All message texts shall preferrably be formatted in the current user's locale. If that is not possible, the english language shall be used. slhm_Name and slhm_Message shall only contain printable characters.

The hook function itself would be invoked with the following parameters:

   result = hook_function(hook,sana2req,sana2hookmsg)
 
   ULONG hook_function(struct Hook *hook,
                       struct IOSana2Req *sana2req,
                       struct SANA2HookMsg *sana2hookmsg);

Note that the result would not necessarily be of type ULONG. It would be a 32 bit value, which would either be a boolean result code (for CopyFromBuff, CopyToBuff and their like) or the pointer to a memory address (for DMACopyToBuff, DMACopyFromBuff and their like).

Commands

The 'traditional' copy call-back functions are installed at OpenDevice() time, and they are found in a TagItem list which is passed along with the IOSana2Req. For the new Hook-based call-back functionality, I propose to introduce a new command. This command would take care of installing one single Hook which will be invoked with the parameters described in section 3.1. The hook function can key off the SANA2HookMsg->schm_Method field to figure out which function should be performed. Once the Hook is installed via the command as follows, the driver shall ignore any and all tags passed to it during OpenDevice() time.

The command is tentatively defined as follows:

sana2.device/S2_SANA2HOOK                             sana2.device/S2_SANA2HOOK

   NAME
        S2_SANA2HOOK -- Install a Hook to perform operations such as copying,
                        overriding the call-back functions installed at
                        OpenDevice() time.

   FUNCTION
        The S2_SANA2HOOK command is to replace the 'traditional' call-back
        functions installed through the TagItem list found in the
        IOSana2Req->ios2_BufferManagement field. Instead of assigning a
        function pointer for each copying function, all operations are
        to be performed through a Hook. This is intended to make the
        interface more portable and less dependant on a certain hardware
        architecture.

        The hook message and the hook data structures allow for more than
        copying to be done.

   IO REQUEST
        ios2_Command    - S2_SANA2HOOK
        ios2_Data       - Points to a struct Sana2Hook, which looks
                          like this:

                             struct Sana2Hook
                             {
                                struct Hook s2h_Hook;
                                Tag *       s2h_Methods;
                             };

                          The structure fields have the following purposes:

                             s2h_Hook
                                A standard Hook structure, ready to be
                                called. Once installed, the complete Hook
                                structure including its Node structure is
                                off limits! The s2h_Hook remains installed
                                until CloseDevice().

                             s2h_Methods
                                Points to a table of Tag values, each
                                identifying a copy method supported
                                (S2_CopyToBuff, S2_CopyFromBuff,
                                S2_CopyToBuff16, S2_CopyFromBuff16,
                                S2_CopyToBuff32, S2_CopyFromBuff32,
                                S2_DMACopyToBuff32, S2_DMACopyFromBuff32,
                                S2_DMACopyToBuff64 or S2_DMACopyFromBuff64)
                                or the logging facility (S2_Log).
                                The table must be terminated by TAG_END.

                                The driver will check the table and
                                verify that the mandatory S2_CopyToBuff
                                and S2_CopyFromBuff commands are present.
                                Additional functionality is used as
                                available if the driver supports it.

        ios2_DataLength - Must be >= 20, which is the default length of
                          the Sana2Hook structure. This may grow in
                          the future, and larger values for ios2_DataLength
                          may indicate additional functionality associated
                          with the Sana2Hook.

   RESULTS
        ios2_Error      - IOERR_NOCMD if this command is not supported
                          by the driver.

                          IOERR_BADLENGTH if IOSana2Req->ios2_DataLength
                          is < 20.

                          IOERR_UNITBUSY if the Hook was already
                          installed or if any of the CMD_READ, CMD_WRITE,
                          S2_MULTICAST or S2_BROADCAST have already been
                          invoked.

                          S2WERR_FUNCTIONS_MISSING if the table pointed
                          to by Sana2Hook->s2h_Methods does not
                          include the S2_CopyToBuff and S2_CopyFromBuff
                          tags.

   NOTES
        The S2_SANA2HOOK command shall be invoked right after OpenDevice()
        as very first command.

        When the command has been executed, the driver must use the
        newly installed Hook for all its copying or logging and cease to
        use the call-back functions provided at OpenDevice() time.

        The contents of the Sana2Hook structure, as passed to the
        driver, must not be modified. This includes the MinNode
        at the beginning of the Hook structure which the driver may
        need to use for its own purposes.

        The table pointed to by Sana2Hook->s2h_Methods must
        include at least the S2_CopyToBuff and S2_CopyFromBuff tags.
        It must be valid until CloseDevice() is called.

        This field is to be treated as private by a protocol stack.
        IOSana2Req structures may be duplicated by copying
        ios2_BufferManagement, io_Device, and io_Unit.

The new command value is defined as follows:

   #define S2_SANA2HOOK 0xC008

The new error code is defined as follows:

   #define S2WERR_FUNCTIONS_MISSING 24 /* mandatory copy functions are missing */

Application and driver software use of the new functions

Since plenty of software exists which uses the 'traditional' TagItem list provided at OpenDevice() time it is recommend that drivers always examine these parameters and do not expect a S2_SANA2HOOK command to be sent later.

If the new Hook-based callback functions are to be used, then the driver must invoke the Hooks via utility.library/CallHookPkt. It must not invoke the hook functions through local assembly language stubs or the amiga.lib/CallHook and amiga.lib/CallHookA functions.

Caveats

The functionality proposed above suggests that one could do entirely without the TagItem list passed in at OpenDevice() time. However, at this time it is hard to tell how existing driver software will react to empty TagItem lists or even a NULL pointer in the IOSana2Req->ios2_BufferManagement field. It is therefore recommend to always provide for a TagItem list which includes proper (i.e. they must point to working functions and may not be NULL) function pointers for the S2_CopyToBuff and S2_CopyFromBuff tags. Once the device has been opened successfully, the next step is to try and install the copy Hook through the proposed S2_SANA2HOOK command. If the command fails, the application can still expect that the S2_CopyToBuff and S2_CopyFromBuff tags supplied at OpenDevice() time will work.

Note that the ios2_BufferManagement field provided by the driver on OpenDevice() time in conjunction with io_Device and io_Unit is the unique identifier for all requests coming from this protocol stack until CloseDevice(). The driver must not ever change the ios2_BufferManagement field for a protocol stack at run time, even if S2_SANAHOOK is called to request extended features.

Changes

02-May-2012:

  • Conversion to MediaWiki format.

22-Mar-2004:

  • Conversion to HTML

21-Jan-2004:

  • Added clarifications for schm_MsgSize, slhm_MsgSize, slhm_Priority, slhm_Name, slhm_Message and s2h_Hook.
  • Updated the S2_SANA2HOOK documentation.
  • Shortened section 4.
  • Updated section 5.

30-Nov-2003:

  • Extended the applicability of the Hook to logging.
  • Renamed S2_COPYHOOK to S2_SANA2HOOK, which matches the extended scope it should cover.
  • The message passed to the Hook now includes a size field which holds the size of the message, expressed in bytes.

06-Oct-2003:

  • Replaced the list of new tag items with a single Hook, which is installed through a new command.
  • Added "Caveats" and "Changes" sections
  • Removed the documentation for the originally proposed TagItem (sections 3.2.1 through 3.2.10)