Device Dependent Functions - 0xffffffRabbit/NextBsd GitHub Wiki

IFLIB Library Functions - Device Dependent

#####These routines are registered with iflib by the driver.

Mandatory Queue Setup and Teardown

During iflib attach ifdi_tx_queues_alloc and ifdi_rx_queues_alloc are called to create the transmit and receive queues respectively. The driver is responsible for allocating these queues using:

 int ifdi_tx_queues_alloc(if_ctx_t ctx,  caddr_t *vaddrs, uint64_t *paddrs, 
     int nqs, int nqsets)
 int ifdi_rx_queues_alloc(if_ctx_t ctx,  caddr_t *vaddrs, uint64_t *paddrs, 
     int nqs, int nqsets) 

vaddrs and paddrs are arrays of virtual and physical addresses respectively of the hardware transmit and receive queues. If relevant, receiving queues may include any command completion queues, mailbox queues, and event queues. nqs is the number of queues/rings for transmit or receive. nqsets refers to the number of queue instances. For example a driver with 3 sets of transmit, receive, and mailbox queues, would have nqs of 1 for ifdi_tx_queues_alloc, nqs of 2 for ifdi_rx_queues_alloc and nqset of 3.

 void ifdi_queues_free(if_ctx_t ctx)

The driver is expected to free any memory that was allocated in ifdi_tx_queues_alloc and ifdi_rx_queues_alloc.

Optional

 int ifdi_txq_setup(if_ctx_t ctx, uint16_t qid)
 int ifdi_rxq_setup(if_ctx_t ctx, uint16_t qid)

If there is any setup configuration logic needed on a per queue basis, then place the code in their respective transmit and receive queue setup functions. Functions are called by iflib during queue initialization.

Device Setup and Teardown Functions

 int ifdi_attach_pre(if_ctx_t ctx)

Contains initialization logic done prior to iflib's creation of queues and interrupts. Troubleshooting: This code section should include initialization of the shared context descriptor's fields isc_softc_ctx.

 int ifdi_detach(if_ctx_t ctx)

Performs cleanup and notification functions. Frees any resources allocated by the driver in ifdi_attach_pre or ifdi_attach_post. If required, notifies the hardware that the driver is unloading. Troubleshooting: Function is called prior to the release of msi/msix memory, interrupts, and queues free.

Optional

 int _ifdi_attach_post(if_ctx_t ctx)

Function is called after queues and interrupts have been allocated and setup. Code that is dependent upon prior setup of queues, interrupts, and structure initialization should be placed here. Examples include hw initialization, interface setup, and notifying the hardware that the driver is loaded.

 void ifdi_vlan_register(if_ctx_t ctx, uint16_t vtag)

ifdi_vlan_register is called by the VLAN config eventhandler. vtag is the new VLAN tag.

void ifdi_vlan_unregister(if_ctx_t ctx, uint16_t vtag)

ifdi_vlan_register is called by the VLAN unconfig eventhandler. vtag is the VLAN tag.

int ifdi_suspend(if_ctx_t ctx)
int ifdi_resume(if_ctx_t ctx)

Device Configuration

Change of State Handlers

 void ifdi_init(if_ctx_t ctx) 

Initialization routine used in two ways. It is used by the stack as init entry point in the network interface structure. It is also used by the driver for hardware/software initialization to get a consistent state (reset the chip and enable the receiver unit).

 void ifdi_stop(if_ctx_t ctx)

ifdi_stop should disable all traffic on the interface. It should update the stack by setting the link_up to false and calling _if_update_admin_status.

 void ifdi_multi_set(if_ctx_t ctx)

ifdi_multi_set sets up the multicast table. The routine is called whenever the multicast address list is updated.

 int ifdi_mtu_set(if_ctx_t ctx, uint32_t mtu)

ifdi_mtu_set is the ioctl mtu entry point. It sets the interface mtu to mtu and returns 0 on success.

 void ifdi_media_status(if_ctx_t ctx, struct ifmediareq *ifr)

ifdi_media_status is called whenever the user queries the media status (i.e. link, speed, etc) of the interface using ifconfig. Troubleshooting: The driver is expected to set the link type and speed in ifmr->ifm_active.

 int ifdi_media_change(if_ctx_t ctx)

ifdi_media_change is called to change various media options (ie. link, speed/duplex, etc.) when the user uses media options with ifconfig.

 void ifdi_promisc_set(if_ctx_t ctx, int flags)

ifdi_promisc_set is called to set interface flags using flags which contains the interfaces' ifnet flags.

 uint64_t ifdi_get_counter(if_ctx_t ctx, ift_counter cnt)

ifdi_get_counter is essentially a wrapper around if_get_counter function.

 void ifdi_update_admin_status(if_ctx_t ctx)

ifdi_update_admin_status updates the OS on the link state. Note: The real check of the hardware only happens with a link interrupt.

####Optional

 void ifdi_media_set(if_ctx_t ctx) 

ifdi_media_set sets configuration values for physical media (ie. copper wire, optical fiber, etc).

Interupts

 int ifdi_msix_intr_assign(if_ctx_t, int msix)

ifdi_msix_intr_assign sets up the MSIX resources and handlers. The driver will commonly allocate 2 iflib_irq_alloc generic functions (IFLIB_INTR_RX and IFLIB_INTR_ADMIN) and iflib_irq_alloc_generic for IFLIB_INTR_TX. Troubleshooting: Allocate the ADMIN interrupt either with the first or last rid value depending upon the driver specifications.

 void ifdi_intr_enable(if_ctx_t ctx)
 void ifdi_intr_disable(if_ctx_t ctx) 

Routines enable and disable interrupts respectively at the hardware level by setting the appropriate bits in the driver.

 void ifdi_queue_intr_enable(if_ctx_t ctx, uint16_t qid)

ifdi_queue_intr_enable enables queues on queue id qid

IOV Support Routines

 int iov_init(if_ctx_t, uint16_t num_vfs, const nvlist_t *params)
 void iov_uninit(if_ctx_t)
 void ifdi_vflr_handle(if_ctx_t ctx)
 int ifdi_vf_add(if_ctx_t ctx, uint16_t vfnum, const nvlist_t *params)

####Optional void ifdi_link_intr_enable(if_ctx_t ctx) ifdi_link_intr_enable is called in response to a link interrupt and the routine implements link interrupts at the hardware level.

Optional Service Routines

void ifdi_timer(if_ctx_t ctx) Timer routine checks for link status and updates statistics. It runs every 500m.

 void ifdi_watchdog_reset(if_ctx_t ctx)

ifdi_watchdog_reset may be run when a transmit queue is hung.

 void ifdi_led_func(if_ctx_t ctx, int onoff)

ifdi_led_func is used to set the led at the hardware level on or off depending upon onoff value.

 int ifdi_sysctl_int_delay(if_ctx_t ctx, if_int_delay_info_t iidi)

 int ifdi_i2c_req(if_ctx_t ctx, struct ifi2creq *req)