This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM3358: NDK API Reference guide - ioctl and NIMUioctl

Part Number: AM3358


Tool/software: TI-RTOS

Hi,

I want to get/set configuration parameters for a module and wanto to use ioctl. I am referring to NDK API Reference guide  On page 182, I see a function ioctl and again on page 184, I see a function NIMUIoctl. I would like to know what is the difference between these two functions. I am able to get and set pararmeters using NIMUIoctl but what does ioctl (Pg. 182) does?

Regards

Vishav . 

  • Hi,

    It is explained in document:

    NIMUIoctl Get/Set configuration from the NIMU Module and Drivers
    This function is used to get and set configuration parameters from either the NIMU
    module or to the NIMU network interface objects driver attached to the NIMU module.
    The NIMU_IF_REQ structure is defined as follows:

    ioctl Callback function registered by driver for the NDK stack to get/set configuration
    This API is used by the NDK core stack to be able to get/set configuration in the drivers.
    The interface can now be used to configure the multicast address list, change device
    MAC address, etc. Each NIMU network interface object can also identify its own custom
    IOCTL commands to do any device-specific configuration. This function is called from
    kernel mode.

    Regards, Eric
  • Hi,

    Thanks for the answer. As per the document, I see that ioctl is a callback function. I wish to know what event calls this function. As some experiments, I used NIMUIoctl functions to get/set configurations. I assumed that the ioctl function is called as callback to NIMUIoctl. It turned out it is partly true. When I use the commands like NIMU_GET_NUM_NIMU_OBJ, NIMU_GET_DEVICE_MTU, NIMU_SET_DEVICE_MTU and NIMU_GET_DEVICE_MAC, ioctl is not called. But if I use command NIMU_SET_DEVICE_MAC, then ioctl function is called.
    This confuses me a bit what is the difference between these two functions and how to use them. The aim of my work is to get/set configurations for a network interface. It would be a great help if someone can explain it using an example.

    Regards
    Vishav
  • Hi Vishav,

    The ioctl function you are seeing is one of the "NIMU Registered Functions." That is, it is one of several functions that a NIMU Ethernet driver must implement. This implementation in the driver is for defining functionality that is specific to the driver/hardware of the particular device. (Realize that the NDK stack (upper layers) is generic C code that is used across a plethora of devices. The Ethernet driver is the portion of the stack that is hardware dependent code, and is typically implemented on a per device basis).

    The other IOCTL function you see - NIMUIoctl - is the "high level" IOCTL that is part of the generic stack code. This IOCTL function is common among all devices and supports getting/setting of common features that are available in all cases, regardless of the underlying EMAC hardware.

    For example, the NIMUIoctl function implements the getting of the interface index, as all NIMU Ethernet drivers must have this set (it's common to all device cases). You can get this device ID by calling the NIMUIoctl() function with the macro NIMU_GET_DEVICE_INDEX.

    However, there are also some device specific settings which the generic stack code doesn't know how to get/set for all underlying hardware. This is where the ioctl registered function comes into play. For example, setting the MAC address is different for each device, as it will require writing to the proper register(s). As such, this is a feature that must be implemented in the driver and so NIMUIoctl() will pass this request down to the driver's ioctl function, which will "know" how to properly set the MAC address. In this case, the application would call NIMUIoctl() using the macro NIMU_SET_DEVICE_MAC, which would result in the ioctl registered function being called. You can see this at line 1037 of ti/ndk/stack/nimu/nimu.c.

    Another use case is for supporting IOCTL commands that are device specific. For example, one EMAC device might support a particular feature, such as enabling protocol checksum offload to the hardware. Since not all devices might support this, it should be defined in the driver for the hardware that does support it.

    In this case, the application would call NIMUIoctl() with the appropriate device specific macro to enable/disable h/w checksum offloads. Since NIMUIoctl() has no 'case' for such a macro, this would result in hitting the default switch case in the code, which just passes the request down to the driver (i.e. ioctl). The driver ioctl registered function would then handle the command.

    In summary, the user application should always call NIMUIoctl(). That function is able to handle a generic list of commands (e.g getting the device index). For anything it cannot handle (e.g. setting the MAC address) or doesn't recognize (e.g. enabling h/w checksum offload), it calls the driver specific implementation that's pointed to by ioctl.

    Steve

  • Hi Steve,

    Thank you very much. That was really helpful and solved a lot of confusion.

    Regards
    Vishav