iPXE
Functions | Variables
ncm.c File Reference

CDC-NCM USB Ethernet driver. More...

#include <string.h>
#include <errno.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/profile.h>
#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include "ecm.h"
#include "ncm.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ncm_intr_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete interrupt transfer.
static int ncm_in_prefill (struct ncm_device *ncm)
 Prefill bulk IN endpoint.
static void ncm_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer.
static int ncm_out_transmit (struct ncm_device *ncm, struct io_buffer *iobuf)
 Transmit packet.
static void ncm_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer.
static int ncm_open (struct net_device *netdev)
 Open network device.
static void ncm_close (struct net_device *netdev)
 Close network device.
static int ncm_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet.
static void ncm_poll (struct net_device *netdev)
 Poll for completed and received packets.
static int ncm_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device.
static void ncm_remove (struct usb_function *func)
 Remove device.

Variables

static struct profiler
ncm_intr_profiler 
__profiler
 Interrupt completion profiler.
static struct
usb_endpoint_driver_operations 
ncm_intr_operations
 Interrupt endpoint operations.
static struct
usb_endpoint_driver_operations 
ncm_in_operations
 Bulk IN endpoint operations.
static struct
usb_endpoint_driver_operations 
ncm_out_operations
 Bulk OUT endpoint operations.
static struct net_device_operations ncm_operations
 CDC-NCM network device operations.
static struct usb_device_id ncm_ids []
 CDC-NCM device IDs.
struct usb_driver ncm_driver __usb_driver
 CDC-NCM driver.

Detailed Description

CDC-NCM USB Ethernet driver.

Definition in file ncm.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void ncm_intr_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
) [static]

Complete interrupt transfer.

Parameters:
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 73 of file ncm.c.

References CDC_CONNECTION_SPEED_CHANGE, CDC_NETWORK_CONNECTION, container_of, cpu_to_le16, io_buffer::data, DBGC, DBGC_HDA, EINVAL, error, free_iob(), usbnet_device::intr, iob_disown, iob_len(), len, message, netdev, ncm_device::netdev, netdev_link_down(), netdev_link_up(), netdev_rx_err(), usb_endpoint::open, profile_start(), profile_stop(), usb_setup_packet::request, strerror(), ncm_device::usbnet, and usb_setup_packet::value.

                                                                  {
        struct ncm_device *ncm = container_of ( ep, struct ncm_device,
                                                usbnet.intr );
        struct net_device *netdev = ncm->netdev;
        struct usb_setup_packet *message;
        size_t len = iob_len ( iobuf );

        /* Profile completions */
        profile_start ( &ncm_intr_profiler );

        /* Ignore packets cancelled when the endpoint closes */
        if ( ! ep->open )
                goto ignore;

        /* Ignore packets with errors */
        if ( rc != 0 ) {
                DBGC ( ncm, "NCM %p interrupt failed: %s\n",
                       ncm, strerror ( rc ) );
                DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
                goto error;
        }

        /* Extract message header */
        if ( len < sizeof ( *message ) ) {
                DBGC ( ncm, "NCM %p underlength interrupt:\n", ncm );
                DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
                rc = -EINVAL;
                goto error;
        }
        message = iobuf->data;

        /* Parse message header */
        switch ( message->request ) {

        case cpu_to_le16 ( CDC_NETWORK_CONNECTION ) :
                if ( message->value ) {
                        DBGC ( ncm, "NCM %p link up\n", ncm );
                        netdev_link_up ( netdev );
                } else {
                        DBGC ( ncm, "NCM %p link down\n", ncm );
                        netdev_link_down ( netdev );
                }
                break;

        case cpu_to_le16 ( CDC_CONNECTION_SPEED_CHANGE ) :
                /* Ignore */
                break;

        default:
                DBGC ( ncm, "NCM %p unrecognised interrupt:\n", ncm );
                DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
                goto error;
        }

        /* Free I/O buffer */
        free_iob ( iobuf );
        profile_stop ( &ncm_intr_profiler );

        return;

 error:
        netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
 ignore:
        free_iob ( iobuf );
        return;
}
static int ncm_in_prefill ( struct ncm_device ncm) [static]

Prefill bulk IN endpoint.

Parameters:
ncmCDC-NCM device
Return values:
rcReturn status code

Definition at line 159 of file ncm.c.

References bus, ncm_device::bus, count, DBGC, ENOMEM, usbnet_device::in, mtu, ncm_device::mtu, usb_bus::mtu, NCM_IN_MAX_SIZE, NCM_IN_MIN_COUNT, NCM_IN_MIN_SIZE, NCM_MAX_NTB_INPUT_SIZE, NCM_MIN_NTB_INPUT_SIZE, rc, usb_prefill(), usb_refill_init(), and ncm_device::usbnet.

Referenced by ncm_open().

                                                     {
        struct usb_bus *bus = ncm->bus;
        size_t mtu;
        unsigned int count;
        int rc;

        /* Some devices have a very small number of internal buffers,
         * and rely on being able to pack multiple packets into each
         * buffer.  We therefore want to use large buffers if
         * possible.  However, large allocations have a reasonable
         * chance of failure, especially if this is not the first or
         * only device to be opened.
         *
         * We therefore attempt to find a usable buffer size, starting
         * large and working downwards until allocation succeeds.
         * Smaller buffers will still work, albeit with a higher
         * chance of packet loss and so lower overall throughput.
         */
        for ( mtu = ncm->mtu ; mtu >= NCM_MIN_NTB_INPUT_SIZE ; mtu >>= 1 ) {

                /* Attempt allocation at this MTU */
                if ( mtu > NCM_MAX_NTB_INPUT_SIZE )
                        continue;
                if ( mtu > bus->mtu )
                        continue;
                count = ( NCM_IN_MIN_SIZE / mtu );
                if ( count < NCM_IN_MIN_COUNT )
                        count = NCM_IN_MIN_COUNT;
                if ( ( count * mtu ) > NCM_IN_MAX_SIZE )
                        continue;
                usb_refill_init ( &ncm->usbnet.in, 0, mtu, count );
                if ( ( rc = usb_prefill ( &ncm->usbnet.in ) ) != 0 ) {
                        DBGC ( ncm, "NCM %p could not prefill %dx %zd-byte "
                               "buffers for bulk IN\n", ncm, count, mtu );
                        continue;
                }

                DBGC ( ncm, "NCM %p using %dx %zd-byte buffers for bulk IN\n",
                       ncm, count, mtu );
                return 0;
        }

        DBGC ( ncm, "NCM %p could not prefill bulk IN endpoint\n", ncm );
        return -ENOMEM;
}
static void ncm_in_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
) [static]

Complete bulk IN transfer.

Parameters:
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 212 of file ncm.c.

References alloc_iob(), container_of, cpu_to_le32, io_buffer::data, DBGC, DBGC_HDA, ncm_datagram_pointer::desc, EINVAL, ENOMEM, error, ETH_HLEN, ncm_datagram_pointer::header_len, usbnet_device::in, iob_len(), iob_put, iob_reserve, iob_unput, le16_to_cpu, ncm_datagram_descriptor::len, len, ncm_datagram_pointer::magic, memcpy(), NCM_DATAGRAM_POINTER_MAGIC_CRC, netdev, ncm_device::netdev, netdev_rx(), netdev_rx_err(), NULL, ncm_transfer_header::offset, ncm_datagram_descriptor::offset, offsetof, usb_endpoint::open, profile_start(), profile_stop(), strerror(), usb_recycle(), and ncm_device::usbnet.

                                       {
        struct ncm_device *ncm = container_of ( ep, struct ncm_device,
                                                usbnet.in );
        struct net_device *netdev = ncm->netdev;
        struct ncm_transfer_header *nth;
        struct ncm_datagram_pointer *ndp;
        struct ncm_datagram_descriptor *desc;
        struct io_buffer *pkt;
        unsigned int remaining;
        size_t ndp_offset;
        size_t ndp_len;
        size_t pkt_offset;
        size_t pkt_len;
        size_t headroom;
        size_t len;

        /* Profile overall bulk IN completion */
        profile_start ( &ncm_in_profiler );

        /* Ignore packets cancelled when the endpoint closes */
        if ( ! ep->open )
                goto ignore;

        /* Record USB errors against the network device */
        if ( rc != 0 ) {
                DBGC ( ncm, "NCM %p bulk IN failed: %s\n",
                       ncm, strerror ( rc ) );
                goto error;
        }

        /* Locate transfer header */
        len = iob_len ( iobuf );
        if ( sizeof ( *nth ) > len ) {
                DBGC ( ncm, "NCM %p packet too short for NTH:\n", ncm );
                rc = -EINVAL;
                goto error;
        }
        nth = iobuf->data;

        /* Locate datagram pointer */
        ndp_offset = le16_to_cpu ( nth->offset );
        if ( ( ndp_offset + sizeof ( *ndp ) ) > len ) {
                DBGC ( ncm, "NCM %p packet too short for NDP:\n", ncm );
                rc = -EINVAL;
                goto error;
        }
        ndp = ( iobuf->data + ndp_offset );
        ndp_len = le16_to_cpu ( ndp->header_len );
        if ( ndp_len < offsetof ( typeof ( *ndp ), desc ) ) {
                DBGC ( ncm, "NCM %p NDP header length too short:\n", ncm );
                rc = -EINVAL;
                goto error;
        }
        if ( ( ndp_offset + ndp_len ) > len ) {
                DBGC ( ncm, "NCM %p packet too short for NDP:\n", ncm );
                rc = -EINVAL;
                goto error;
        }

        /* Process datagrams */
        remaining = ( ( ndp_len - offsetof ( typeof ( *ndp ), desc ) ) /
                      sizeof ( ndp->desc[0] ) );
        for ( desc = ndp->desc ; remaining && desc->offset ; remaining-- ) {

                /* Profile individual datagrams */
                profile_start ( &ncm_in_datagram_profiler );

                /* Locate datagram */
                pkt_offset = le16_to_cpu ( desc->offset );
                pkt_len = le16_to_cpu ( desc->len );
                if ( pkt_len < ETH_HLEN ) {
                        DBGC ( ncm, "NCM %p underlength datagram:\n", ncm );
                        rc = -EINVAL;
                        goto error;
                }
                if ( ( pkt_offset + pkt_len ) > len ) {
                        DBGC ( ncm, "NCM %p datagram exceeds packet:\n", ncm );
                        rc = -EINVAL;
                        goto error;
                }

                /* Move to next descriptor */
                desc++;

                /* Copy data to a new I/O buffer.  Our USB buffers may
                 * be very large and so we choose to recycle the
                 * buffers directly rather than attempt reallocation
                 * while the device is running.  We therefore copy the
                 * data to a new I/O buffer even if this is the only
                 * (or last) packet within the buffer.
                 *
                 * We reserve enough space at the start of each buffer
                 * to allow for our own transmission header, to
                 * support protocols such as ARP which may modify the
                 * received packet and reuse the same I/O buffer for
                 * transmission.
                 */
                headroom = ( sizeof ( struct ncm_ntb_header ) + ncm->padding );
                pkt = alloc_iob ( headroom + pkt_len );
                if ( ! pkt ) {
                        /* Record error and continue */
                        netdev_rx_err ( netdev, NULL, -ENOMEM );
                        continue;
                }
                iob_reserve ( pkt, headroom );
                memcpy ( iob_put ( pkt, pkt_len ),
                         ( iobuf->data + pkt_offset ), pkt_len );

                /* Strip CRC, if present */
                if ( ndp->magic & cpu_to_le32 ( NCM_DATAGRAM_POINTER_MAGIC_CRC))
                        iob_unput ( pkt, 4 /* CRC32 */ );

                /* Hand off to network stack */
                netdev_rx ( netdev, pkt );
                profile_stop ( &ncm_in_datagram_profiler );
        }

        /* Recycle I/O buffer */
        usb_recycle ( &ncm->usbnet.in, iobuf );
        profile_stop ( &ncm_in_profiler );

        return;

 error:
        /* Record error against network device */
        DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
        netdev_rx_err ( netdev, NULL, rc );
 ignore:
        usb_recycle ( &ncm->usbnet.in, iobuf );
}
static int ncm_out_transmit ( struct ncm_device ncm,
struct io_buffer iobuf 
) [static]

Transmit packet.

Parameters:
ncmCDC-NCM device
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 356 of file ncm.c.

References cpu_to_le16, cpu_to_le32, ncm_ntb_header::desc, header, ncm_transfer_header::header_len, ncm_datagram_pointer::header_len, iob_ensure_headroom(), iob_len(), iob_push, ncm_transfer_header::len, ncm_datagram_descriptor::len, len, ncm_transfer_header::magic, ncm_datagram_pointer::magic, memset(), NCM_DATAGRAM_POINTER_MAGIC, NCM_TRANSFER_HEADER_MAGIC, ncm_ntb_header::ndp, ncm_ntb_header::nth, ncm_transfer_header::offset, ncm_datagram_descriptor::offset, ncm_datagram_pointer::offset, offsetof, usbnet_device::out, ncm_device::padding, profile_start(), profile_stop(), rc, ncm_transfer_header::sequence, ncm_device::sequence, usb_stream(), and ncm_device::usbnet.

Referenced by ncm_transmit().

                                                        {
        struct ncm_ntb_header *header;
        size_t len = iob_len ( iobuf );
        size_t header_len = ( sizeof ( *header ) + ncm->padding );
        int rc;

        /* Profile transmissions */
        profile_start ( &ncm_out_profiler );

        /* Prepend header */
        if ( ( rc = iob_ensure_headroom ( iobuf, header_len ) ) != 0 )
                return rc;
        header = iob_push ( iobuf, header_len );

        /* Populate header */
        header->nth.magic = cpu_to_le32 ( NCM_TRANSFER_HEADER_MAGIC );
        header->nth.header_len = cpu_to_le16 ( sizeof ( header->nth ) );
        header->nth.sequence = cpu_to_le16 ( ncm->sequence );
        header->nth.len = cpu_to_le16 ( iob_len ( iobuf ) );
        header->nth.offset =
                cpu_to_le16 ( offsetof ( typeof ( *header ), ndp ) );
        header->ndp.magic = cpu_to_le32 ( NCM_DATAGRAM_POINTER_MAGIC );
        header->ndp.header_len = cpu_to_le16 ( sizeof ( header->ndp ) +
                                               sizeof ( header->desc ) );
        header->ndp.offset = cpu_to_le16 ( 0 );
        header->desc[0].offset = cpu_to_le16 ( header_len );
        header->desc[0].len = cpu_to_le16 ( len );
        memset ( &header->desc[1], 0, sizeof ( header->desc[1] ) );

        /* Enqueue I/O buffer */
        if ( ( rc = usb_stream ( &ncm->usbnet.out, iobuf, 0 ) ) != 0 )
                return rc;

        /* Increment sequence number */
        ncm->sequence++;

        profile_stop ( &ncm_out_profiler );
        return 0;
}
static void ncm_out_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
) [static]

Complete bulk OUT transfer.

Parameters:
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 404 of file ncm.c.

References container_of, netdev, ncm_device::netdev, netdev_tx_complete_err(), usbnet_device::out, and ncm_device::usbnet.

                                        {
        struct ncm_device *ncm = container_of ( ep, struct ncm_device,
                                                usbnet.out );
        struct net_device *netdev = ncm->netdev;

        /* Report TX completion */
        netdev_tx_complete_err ( netdev, iobuf, rc );
}
static int ncm_open ( struct net_device netdev) [static]

Open network device.

Parameters:
netdevNetwork device
Return values:
rcReturn status code

Definition at line 432 of file ncm.c.

References usbnet_device::comms, cpu_to_le32, DBGC, usbnet_device::in, usb_endpoint::len, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memset(), ncm_set_ntb_input_size::mtu, ncm_in_prefill(), NCM_SET_NET_ADDRESS, NCM_SET_NTB_INPUT_SIZE, net_device::priv, rc, ncm_device::sequence, strerror(), ncm_device::usb, usb_control(), usb_flush(), ncm_device::usbnet, usbnet_close(), and usbnet_open().

                                                  {
        struct ncm_device *ncm = netdev->priv;
        struct usb_device *usb = ncm->usb;
        struct ncm_set_ntb_input_size size;
        int rc;

        /* Reset sequence number */
        ncm->sequence = 0;

        /* Prefill I/O buffers */
        if ( ( rc = ncm_in_prefill ( ncm ) ) != 0 )
                goto err_prefill;

        /* Set maximum input size */
        memset ( &size, 0, sizeof ( size ) );
        size.mtu = cpu_to_le32 ( ncm->usbnet.in.len );
        if ( ( rc = usb_control ( usb, NCM_SET_NTB_INPUT_SIZE, 0,
                                  ncm->usbnet.comms, &size,
                                  sizeof ( size ) ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not set input size to %zd: %s\n",
                       ncm, ncm->usbnet.in.len, strerror ( rc ) );
                goto err_set_ntb_input_size;
        }

        /* Set MAC address */
        if ( ( rc = usb_control ( usb, NCM_SET_NET_ADDRESS, 0,
                                  ncm->usbnet.comms, netdev->ll_addr,
                                  netdev->ll_protocol->ll_addr_len ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not set MAC address: %s\n",
                       ncm, strerror ( rc ) );
                /* Ignore error and continue */
        }

        /* Open USB network device */
        if ( ( rc = usbnet_open ( &ncm->usbnet ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not open: %s\n",
                       ncm, strerror ( rc ) );
                goto err_open;
        }

        return 0;

        usbnet_close ( &ncm->usbnet );
 err_open:
 err_set_ntb_input_size:
        usb_flush ( &ncm->usbnet.in );
 err_prefill:
        return rc;
}
static void ncm_close ( struct net_device netdev) [static]

Close network device.

Parameters:
netdevNetwork device

Definition at line 487 of file ncm.c.

References net_device::priv, ncm_device::usbnet, and usbnet_close().

                                                    {
        struct ncm_device *ncm = netdev->priv;

        /* Close USB network device */
        usbnet_close ( &ncm->usbnet );
}
static int ncm_transmit ( struct net_device netdev,
struct io_buffer iobuf 
) [static]

Transmit packet.

Parameters:
netdevNetwork device
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 501 of file ncm.c.

References ncm_out_transmit(), net_device::priv, and rc.

                                                    {
        struct ncm_device *ncm = netdev->priv;
        int rc;

        /* Transmit packet */
        if ( ( rc = ncm_out_transmit ( ncm, iobuf ) ) != 0 )
                return rc;

        return 0;
}
static void ncm_poll ( struct net_device netdev) [static]

Poll for completed and received packets.

Parameters:
netdevNetwork device

Definition at line 518 of file ncm.c.

References ncm_device::bus, netdev_rx_err(), NULL, net_device::priv, rc, usb_poll(), ncm_device::usbnet, and usbnet_refill().

                                                   {
        struct ncm_device *ncm = netdev->priv;
        int rc;

        /* Poll USB bus */
        usb_poll ( ncm->bus );

        /* Refill endpoints */
        if ( ( rc = usbnet_refill ( &ncm->usbnet ) ) != 0 )
                netdev_rx_err ( netdev, NULL, rc );

}
static int ncm_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
) [static]

Probe device.

Parameters:
funcUSB function
configConfiguration descriptor
Return values:
rcReturn status code

Definition at line 553 of file ncm.c.

References alloc_etherdev(), assert, ncm_device::bus, usb_hub::bus, usbnet_device::comms, DBGC, DBGC2, net_device::dev, usb_function::dev, ncm_ntb_datagram_parameters::divisor, ecm_ethernet_descriptor(), ecm_fetch_mac(), EINVAL, ENOMEM, usb_port::hub, net_device::hw_addr, ncm_ntb_parameters::in, usbnet_device::intr, le16_to_cpu, le32_to_cpu, memset(), ncm_ntb_datagram_parameters::mtu, ncm_device::mtu, usb_function::name, NCM_GET_NTB_PARAMETERS, NCM_INTR_COUNT, netdev, ncm_device::netdev, netdev_init(), netdev_nullify(), netdev_put(), NULL, ncm_ntb_parameters::out, ncm_device::padding, usb_device::port, net_device::priv, rc, register_netdev(), ncm_ntb_datagram_parameters::remainder, strerror(), unregister_netdev(), ncm_device::usb, usb_function::usb, usb_control(), usb_func_set_drvdata(), usb_interface_descriptor(), usb_refill_init(), ncm_device::usbnet, usbnet_describe(), and usbnet_init().

                                                                     {
        struct usb_device *usb = func->usb;
        struct net_device *netdev;
        struct ncm_device *ncm;
        struct usb_interface_descriptor *comms;
        struct ecm_ethernet_descriptor *ethernet;
        struct ncm_ntb_parameters params;
        int rc;

        /* Allocate and initialise structure */
        netdev = alloc_etherdev ( sizeof ( *ncm ) );
        if ( ! netdev ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        netdev_init ( netdev, &ncm_operations );
        netdev->dev = &func->dev;
        ncm = netdev->priv;
        memset ( ncm, 0, sizeof ( *ncm ) );
        ncm->usb = usb;
        ncm->bus = usb->port->hub->bus;
        ncm->netdev = netdev;
        usbnet_init ( &ncm->usbnet, func, &ncm_intr_operations,
                      &ncm_in_operations, &ncm_out_operations );
        usb_refill_init ( &ncm->usbnet.intr, 0, 0, NCM_INTR_COUNT );
        DBGC ( ncm, "NCM %p on %s\n", ncm, func->name );

        /* Describe USB network device */
        if ( ( rc = usbnet_describe ( &ncm->usbnet, config ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not describe: %s\n",
                       ncm, strerror ( rc ) );
                goto err_describe;
        }

        /* Locate Ethernet descriptor */
        comms = usb_interface_descriptor ( config, ncm->usbnet.comms, 0 );
        assert ( comms != NULL );
        ethernet = ecm_ethernet_descriptor ( config, comms );
        if ( ! ethernet ) {
                DBGC ( ncm, "NCM %p has no Ethernet descriptor\n", ncm );
                rc = -EINVAL;
                goto err_ethernet;
        }

        /* Fetch MAC address */
        if ( ( rc = ecm_fetch_mac ( usb, ethernet, netdev->hw_addr ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not fetch MAC address: %s\n",
                       ncm, strerror ( rc ) );
                goto err_fetch_mac;
        }

        /* Get NTB parameters */
        if ( ( rc = usb_control ( usb, NCM_GET_NTB_PARAMETERS, 0,
                                  ncm->usbnet.comms, &params,
                                  sizeof ( params ) ) ) != 0 ) {
                DBGC ( ncm, "NCM %p could not get NTB parameters: %s\n",
                       ncm, strerror ( rc ) );
                goto err_ntb_parameters;
        }

        /* Get maximum supported input size */
        ncm->mtu = le32_to_cpu ( params.in.mtu );
        DBGC2 ( ncm, "NCM %p maximum IN size is %zd bytes\n", ncm, ncm->mtu );

        /* Calculate transmit padding */
        ncm->padding = ( ( le16_to_cpu ( params.out.remainder ) -
                           sizeof ( struct ncm_ntb_header ) - ETH_HLEN ) &
                         ( le16_to_cpu ( params.out.divisor ) - 1 ) );
        DBGC2 ( ncm, "NCM %p using %zd-byte transmit padding\n",
                ncm, ncm->padding );
        assert ( ( ( sizeof ( struct ncm_ntb_header ) + ncm->padding +
                     ETH_HLEN ) % le16_to_cpu ( params.out.divisor ) ) ==
                 le16_to_cpu ( params.out.remainder ) );

        /* Register network device */
        if ( ( rc = register_netdev ( netdev ) ) != 0 )
                goto err_register;

        usb_func_set_drvdata ( func, ncm );
        return 0;

        unregister_netdev ( netdev );
 err_register:
 err_ntb_parameters:
 err_fetch_mac:
 err_ethernet:
 err_describe:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 err_alloc:
        return rc;
}
static void ncm_remove ( struct usb_function func) [static]

Remove device.

Parameters:
funcUSB function

Definition at line 652 of file ncm.c.

References netdev, ncm_device::netdev, netdev_nullify(), netdev_put(), unregister_netdev(), and usb_func_get_drvdata().

                                                     {
        struct ncm_device *ncm = usb_func_get_drvdata ( func );
        struct net_device *netdev = ncm->netdev;

        unregister_netdev ( netdev );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
}

Variable Documentation

struct profiler ncm_out_profiler __profiler [static]
Initial value:
        { .name = "ncm.intr" }

Interrupt completion profiler.

Bulk OUT profiler.

Bulk IN per-datagram profiler.

Bulk IN completion profiler.

Definition at line 44 of file ncm.c.

Initial value:
 {
        .complete = ncm_intr_complete,
}

Interrupt endpoint operations.

Definition at line 142 of file ncm.c.

Initial value:
 {
        .complete = ncm_in_complete,
}

Bulk IN endpoint operations.

Definition at line 345 of file ncm.c.

Initial value:
 {
        .complete = ncm_out_complete,
}

Bulk OUT endpoint operations.

Definition at line 415 of file ncm.c.

Initial value:
 {
        .open           = ncm_open,
        .close          = ncm_close,
        .transmit       = ncm_transmit,
        .poll           = ncm_poll,
}

CDC-NCM network device operations.

Definition at line 532 of file ncm.c.

struct usb_device_id ncm_ids[] [static]
Initial value:
 {
        {
                .name = "cdc-ncm",
                .vendor = USB_ANY_ID,
                .product = USB_ANY_ID,
        },
}

CDC-NCM device IDs.

Definition at line 662 of file ncm.c.

struct usb_driver ncm_driver __usb_driver
Initial value:
 {
        .ids = ncm_ids,
        .id_count = ( sizeof ( ncm_ids ) / sizeof ( ncm_ids[0] ) ),
        .class = USB_CLASS_ID ( USB_CLASS_CDC, USB_SUBCLASS_CDC_NCM, 0 ),
        .score = USB_SCORE_NORMAL,
        .probe = ncm_probe,
        .remove = ncm_remove,
}

CDC-NCM driver.

Definition at line 671 of file ncm.c.