#define AVF_MBOX_BUF_SZ 512
#define AVF_RXQ_SZ 512
#define AVF_TXQ_SZ 512
-#define AVF_ITR_INT 32
+#define AVF_ITR_INT 250
#define PCI_VENDOR_ID_INTEL 0x8086
#define PCI_DEVICE_ID_INTEL_AVF 0x1889
#define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd
avf_main_t avf_main;
+void avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier);
static pci_device_id_t avf_pci_device_ids[] = {
{.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_AVF},
#undef _
};
+typedef enum
+{
+ AVF_IRQ_STATE_DISABLED,
+ AVF_IRQ_STATE_ENABLED,
+ AVF_IRQ_STATE_WB_ON_ITR,
+} avf_irq_state_t;
+
static inline void
-avf_irq_0_disable (avf_device_t * ad)
+avf_irq_0_set_state (avf_device_t * ad, avf_irq_state_t state)
{
u32 dyn_ctl0 = 0, icr0_ena = 0;
avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
avf_reg_flush (ad);
-}
-static inline void
-avf_irq_0_enable (avf_device_t * ad)
-{
- u32 dyn_ctl0 = 0, icr0_ena = 0;
+ if (state == AVF_IRQ_STATE_DISABLED)
+ return;
+
+ dyn_ctl0 = 0;
+ icr0_ena = 0;
icr0_ena |= (1 << 30); /* [30] Admin Queue Enable */
dyn_ctl0 |= (1 << 0); /* [0] Interrupt Enable */
dyn_ctl0 |= (1 << 1); /* [1] Clear PBA */
- //dyn_ctl0 |= (3 << 3); /* [4:3] ITR Index, 11b = No ITR update */
+ dyn_ctl0 |= (2 << 3); /* [4:3] ITR Index, 11b = No ITR update */
dyn_ctl0 |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
- avf_irq_0_disable (ad);
avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
avf_reg_flush (ad);
}
static inline void
-avf_irq_n_disable (avf_device_t * ad, u8 line)
+avf_irq_n_set_state (avf_device_t * ad, u8 line, avf_irq_state_t state)
{
u32 dyn_ctln = 0;
+ /* disable */
avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
avf_reg_flush (ad);
-}
-static inline void
-avf_irq_n_enable (avf_device_t * ad, u8 line)
-{
- u32 dyn_ctln = 0;
+ if (state == AVF_IRQ_STATE_DISABLED)
+ return;
- dyn_ctln |= (1 << 0); /* [0] Interrupt Enable */
dyn_ctln |= (1 << 1); /* [1] Clear PBA */
- dyn_ctln |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
+ if (state == AVF_IRQ_STATE_WB_ON_ITR)
+ {
+ /* minimal ITR interval, use ITR1 */
+ dyn_ctln |= (1 << 3); /* [4:3] ITR Index */
+ dyn_ctln |= ((32 / 2) << 5); /* [16:5] ITR Interval in 2us steps */
+ dyn_ctln |= (1 << 30); /* [30] Writeback on ITR */
+ }
+ else
+ {
+ /* configured ITR interval, use ITR0 */
+ dyn_ctln |= (1 << 0); /* [0] Interrupt Enable */
+ dyn_ctln |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
+ }
- avf_irq_n_disable (ad, line);
avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
avf_reg_flush (ad);
}
u32 head;
f64 t0, suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME;
+ /* adminq operations should be only done from process node after device
+ * is initialized */
+ ASSERT ((ad->flags & AVF_DEVICE_F_INITIALIZED) == 0 ||
+ vlib_get_current_process_node_index (vm) == avf_process_node.index);
+
/* suppress interrupt in the next adminq receive slot
as we are going to wait for response
we only need interrupts when event is received */
clib_error_t *
avf_op_config_irq_map (vlib_main_t * vm, avf_device_t * ad)
{
- int count = 1;
int msg_len = sizeof (virtchnl_irq_map_info_t) +
- count * sizeof (virtchnl_vector_map_t);
+ (ad->n_rx_irqs) * sizeof (virtchnl_vector_map_t);
u8 msg[msg_len];
virtchnl_irq_map_info_t *imi;
clib_memset (msg, 0, msg_len);
imi = (virtchnl_irq_map_info_t *) msg;
- imi->num_vectors = count;
+ imi->num_vectors = ad->n_rx_irqs;
+
+ for (int i = 0; i < ad->n_rx_irqs; i++)
+ {
+ imi->vecmap[i].vector_id = i + 1;
+ imi->vecmap[i].vsi_id = ad->vsi_id;
+ if (ad->n_rx_irqs == ad->n_rx_queues)
+ imi->vecmap[i].rxq_map = 1 << i;
+ else
+ imi->vecmap[i].rxq_map = pow2_mask (ad->n_rx_queues);;
- imi->vecmap[0].vector_id = 1;
- imi->vecmap[0].vsi_id = ad->vsi_id;
- imi->vecmap[0].rxq_map = (1 << ad->n_rx_queues) - 1;
- imi->vecmap[0].txq_map = (1 << ad->n_tx_queues) - 1;
+ avf_log_debug (ad, "config_irq_map[%u/%u]: vsi_id %u vector_id %u "
+ "rxq_map %u", i, ad->n_rx_irqs - 1, ad->vsi_id,
+ imi->vecmap[i].vector_id, imi->vecmap[i].rxq_map);
+ }
- avf_log_debug (ad, "config_irq_map: vsi_id %u vector_id %u rxq_map %u",
- ad->vsi_id, imi->vecmap[0].vector_id,
- imi->vecmap[0].rxq_map);
return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0,
0);
virtchnl_vf_resource_t res = { 0 };
clib_error_t *error;
vlib_thread_main_t *tm = vlib_get_thread_main ();
- int i;
+ int i, wb_on_itr;
avf_adminq_init (vm, ad);
ad->max_mtu = res.max_mtu;
ad->rss_key_size = res.rss_key_size;
ad->rss_lut_size = res.rss_lut_size;
+ wb_on_itr = (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) != 0;
clib_memcpy_fast (ad->hwaddr, res.vsi_res[0].default_mac_addr, 6);
if ((error = avf_txq_init (vm, ad, i, args->txq_size)))
return error;
+ if (ad->max_vectors > ad->n_rx_queues)
+ {
+ ad->flags |= AVF_DEVICE_F_RX_INT;
+ ad->n_rx_irqs = args->rxq_num;
+ }
+ else
+ ad->n_rx_irqs = 1;
+
+
if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
(error = avf_op_config_rss_lut (vm, ad)))
return error;
if ((error = avf_op_config_irq_map (vm, ad)))
return error;
- avf_irq_0_enable (ad);
- for (i = 0; i < ad->n_rx_queues; i++)
- avf_irq_n_enable (ad, i);
+ avf_irq_0_set_state (ad, AVF_IRQ_STATE_ENABLED);
+
+ for (i = 0; i < ad->n_rx_irqs; i++)
+ avf_irq_n_set_state (ad, i, wb_on_itr ? AVF_IRQ_STATE_WB_ON_ITR :
+ AVF_IRQ_STATE_ENABLED);
if ((error = avf_op_add_eth_addr (vm, ad, 1, ad->hwaddr)))
return error;
avf_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
{
vlib_main_t *vm = vlib_get_main ();
- avf_main_t *am = &avf_main;
- avf_device_t *ad = vec_elt_at_index (am->devices, hw->dev_instance);
- if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC (flags))
- {
- clib_error_t *error;
- int promisc_enabled = (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) != 0;
- u32 new_flags = promisc_enabled ?
- ad->flags | AVF_DEVICE_F_PROMISC : ad->flags & ~AVF_DEVICE_F_PROMISC;
+ avf_device_t *ad = avf_get_device (hw->dev_instance);
+ u8 promisc_enabled;
- if (new_flags == ad->flags)
- return flags;
+ switch (flags)
+ {
+ case ETHERNET_INTERFACE_FLAG_DEFAULT_L3:
+ ad->flags &= ~AVF_DEVICE_F_PROMISC;
+ break;
+ case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
+ ad->flags |= AVF_DEVICE_F_PROMISC;
+ break;
+ default:
+ return ~0;
+ }
- if ((error = avf_config_promisc_mode (vm, ad, promisc_enabled)))
- {
- avf_log_err (ad, "%s: %U", format_clib_error, error);
- clib_error_free (error);
- return 0;
- }
+ promisc_enabled = ((ad->flags & AVF_DEVICE_F_PROMISC) != 0);
- ad->flags = new_flags;
- }
+ vlib_process_signal_event (vm, avf_process_node.index,
+ promisc_enabled ?
+ AVF_PROCESS_EVENT_SET_PROMISC_ENABLE :
+ AVF_PROCESS_EVENT_SET_PROMISC_DISABLE,
+ hw->dev_instance);
return 0;
}
avf_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
avf_main_t *am = &avf_main;
- avf_device_t *ad;
uword *event_data = 0, event_type;
int enabled = 0, irq;
f64 last_run_duration = 0;
f64 last_periodic_time = 0;
+ avf_device_t **dev_pointers = 0;
+ u32 i;
while (1)
{
vlib_process_wait_for_event (vm);
event_type = vlib_process_get_events (vm, &event_data);
- vec_reset_length (event_data);
irq = 0;
switch (event_type)
case AVF_PROCESS_EVENT_START:
enabled = 1;
break;
- case AVF_PROCESS_EVENT_STOP:
- enabled = 0;
- continue;
+ case AVF_PROCESS_EVENT_DELETE_IF:
+ for (int i = 0; i < vec_len (event_data); i++)
+ {
+ avf_device_t *ad = avf_get_device (event_data[i]);
+ avf_delete_if (vm, ad, /* with_barrier */ 1);
+ }
+ if (pool_elts (am->devices) < 1)
+ enabled = 0;
+ break;
case AVF_PROCESS_EVENT_AQ_INT:
irq = 1;
break;
+ case AVF_PROCESS_EVENT_SET_PROMISC_ENABLE:
+ case AVF_PROCESS_EVENT_SET_PROMISC_DISABLE:
+ for (int i = 0; i < vec_len (event_data); i++)
+ {
+ avf_device_t *ad = avf_get_device (event_data[i]);
+ clib_error_t *err;
+ int is_enable = 0;
+
+ if (event_type == AVF_PROCESS_EVENT_SET_PROMISC_ENABLE)
+ is_enable = 1;
+
+ if ((err = avf_config_promisc_mode (vm, ad, is_enable)))
+ {
+ avf_log_err (ad, "error: %U", format_clib_error, err);
+ clib_error_free (err);
+ }
+ }
+ break;
+
default:
ASSERT (0);
}
+ vec_reset_length (event_data);
+
+ if (enabled == 0)
+ continue;
+
+ /* create local list of device pointers as device pool may grow
+ * during suspend */
+ vec_reset_length (dev_pointers);
/* *INDENT-OFF* */
- pool_foreach (ad, am->devices,
+ pool_foreach_index (i, am->devices,
+ {
+ vec_add1 (dev_pointers, avf_get_device (i));
+ });
+
+ vec_foreach_index (i, dev_pointers)
{
- avf_process_one_device (vm, ad, irq);
- });
+ avf_process_one_device (vm, dev_pointers[i], irq);
+ };
/* *INDENT-ON* */
last_run_duration = vlib_time_now (vm) - last_periodic_time;
}
}
/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (avf_process_node, static) = {
+VLIB_REGISTER_NODE (avf_process_node) = {
.function = avf_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "avf-process",
static void
avf_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
- avf_main_t *am = &avf_main;
uword pd = vlib_pci_get_private_data (vm, h);
- avf_device_t *ad = pool_elt_at_index (am->devices, pd);
+ avf_device_t *ad = avf_get_device (pd);
u32 icr0;
icr0 = avf_reg_read (ad, AVFINT_ICR0);
ed->icr0 = icr0;
}
- avf_irq_0_enable (ad);
+ avf_irq_0_set_state (ad, AVF_IRQ_STATE_ENABLED);
/* bit 30 - Send/Receive Admin queue interrupt indication */
if (icr0 & (1 << 30))
avf_irq_n_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
{
vnet_main_t *vnm = vnet_get_main ();
- avf_main_t *am = &avf_main;
uword pd = vlib_pci_get_private_data (vm, h);
- avf_device_t *ad = pool_elt_at_index (am->devices, pd);
- u16 qid;
- int i;
+ avf_device_t *ad = avf_get_device (pd);
if (ad->flags & AVF_DEVICE_F_ELOG)
{
ed->line = line;
}
- qid = line - 1;
- if (vec_len (ad->rxqs) > qid && ad->rxqs[qid].int_mode != 0)
- vnet_device_input_set_interrupt_pending (vnm, ad->hw_if_index, qid);
- for (i = 0; i < vec_len (ad->rxqs); i++)
- avf_irq_n_enable (ad, i);
+ line--;
+
+ if (ad->flags & AVF_DEVICE_F_RX_INT && ad->rxqs[line].int_mode)
+ vnet_device_input_set_interrupt_pending (vnm, ad->hw_if_index, line);
+ avf_irq_n_set_state (ad, line, AVF_IRQ_STATE_ENABLED);
}
void
-avf_delete_if (vlib_main_t * vm, avf_device_t * ad)
+avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier)
{
vnet_main_t *vnm = vnet_get_main ();
avf_main_t *am = &avf_main;
int i;
+ ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
+
if (ad->hw_if_index)
{
+ if (with_barrier)
+ vlib_worker_thread_barrier_sync (vm);
vnet_hw_interface_set_flags (vnm, ad->hw_if_index, 0);
vnet_hw_interface_unassign_rx_thread (vnm, ad->hw_if_index, 0);
ethernet_delete_interface (vnm, ad->hw_if_index);
+ if (with_barrier)
+ vlib_worker_thread_barrier_release (vm);
}
vlib_pci_device_close (vm, ad->pci_dev_handle);
clib_error_free (ad->error);
clib_memset (ad, 0, sizeof (*ad));
- pool_put (am->devices, ad);
+ pool_put_index (am->devices, ad->dev_instance);
+ clib_mem_free (ad);
}
-void
-avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
+static u8
+avf_validate_queue_size (avf_create_if_args_t * args)
{
- vnet_main_t *vnm = vnet_get_main ();
- avf_main_t *am = &avf_main;
- avf_device_t *ad;
- vlib_pci_dev_handle_t h;
clib_error_t *error = 0;
- int i;
- /* check input args */
args->rxq_size = (args->rxq_size == 0) ? AVF_RXQ_SZ : args->rxq_size;
args->txq_size = (args->txq_size == 0) ? AVF_TXQ_SZ : args->txq_size;
- if ((args->rxq_size & (args->rxq_size - 1))
- || (args->txq_size & (args->txq_size - 1)))
+ if ((args->rxq_size > AVF_QUEUE_SZ_MAX)
+ || (args->txq_size > AVF_QUEUE_SZ_MAX))
+ {
+ args->rv = VNET_API_ERROR_INVALID_VALUE;
+ args->error =
+ clib_error_return (error, "queue size must not be greater than %u",
+ AVF_QUEUE_SZ_MAX);
+ return 1;
+ }
+ if ((args->rxq_size < AVF_QUEUE_SZ_MIN)
+ || (args->txq_size < AVF_QUEUE_SZ_MIN))
+ {
+ args->rv = VNET_API_ERROR_INVALID_VALUE;
+ args->error =
+ clib_error_return (error, "queue size must not be smaller than %u",
+ AVF_QUEUE_SZ_MIN);
+ return 1;
+ }
+ if ((args->rxq_size & (args->rxq_size - 1)) ||
+ (args->txq_size & (args->txq_size - 1)))
{
args->rv = VNET_API_ERROR_INVALID_VALUE;
args->error =
clib_error_return (error, "queue size must be a power of two");
- return;
+ return 1;
}
+ return 0;
+}
- pool_get (am->devices, ad);
- ad->dev_instance = ad - am->devices;
+void
+avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ avf_main_t *am = &avf_main;
+ avf_device_t *ad, **adp;
+ vlib_pci_dev_handle_t h;
+ clib_error_t *error = 0;
+ int i;
+
+ /* check input args */
+ if (avf_validate_queue_size (args) != 0)
+ return;
+
+ pool_get (am->devices, adp);
+ adp[0] = ad = clib_mem_alloc_aligned (sizeof (avf_device_t),
+ CLIB_CACHE_LINE_BYTES);
+ clib_memset (ad, 0, sizeof (avf_device_t));
+ ad->dev_instance = adp - am->devices;
ad->per_interface_next_index = ~0;
ad->name = vec_dup (args->name);
if ((error = vlib_pci_device_open (vm, &args->addr, avf_pci_device_ids,
&h)))
{
- pool_put (am->devices, ad);
+ pool_put (am->devices, adp);
+ clib_mem_free (ad);
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error =
clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
if ((error = vlib_pci_map_region (vm, h, 0, &ad->bar0)))
goto error;
- if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
- &avf_irq_0_handler)))
- goto error;
-
- if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
- &avf_irq_n_handler)))
- goto error;
-
- if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
- goto error;
-
ad->atq = vlib_physmem_alloc_aligned_on_numa (vm, sizeof (avf_aq_desc_t) *
AVF_MBOX_LEN,
CLIB_CACHE_LINE_BYTES,
if ((error = vlib_pci_map_dma (vm, h, ad->arq_bufs)))
goto error;
- if ((error = vlib_pci_intr_enable (vm, h)))
- goto error;
-
if (vlib_pci_supports_virtual_addr_dma (vm, h))
ad->flags |= AVF_DEVICE_F_VA_DMA;
if ((error = avf_device_init (vm, am, ad, args)))
goto error;
+ if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
+ &avf_irq_0_handler)))
+ goto error;
+
+ if ((error = vlib_pci_register_msix_handler (vm, h, 1, ad->n_rx_irqs,
+ &avf_irq_n_handler)))
+ goto error;
+
+ if ((error = vlib_pci_enable_msix_irq (vm, h, 0, ad->n_rx_irqs + 1)))
+ goto error;
+
+ if ((error = vlib_pci_intr_enable (vm, h)))
+ goto error;
+
/* create interface */
error = ethernet_register_interface (vnm, avf_device_class.index,
ad->dev_instance, ad->hwaddr,
if (error)
goto error;
+ /* Indicate ability to support L3 DMAC filtering and
+ * initialize interface to L3 non-promisc mode */
+ vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, ad->hw_if_index);
+ hi->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_MAC_FILTER;
+ ethernet_set_flags (vnm, ad->hw_if_index,
+ ETHERNET_INTERFACE_FLAG_DEFAULT_L3);
+
vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, ad->hw_if_index);
args->sw_if_index = ad->sw_if_index = sw->sw_if_index;
return;
error:
- avf_delete_if (vm, ad);
+ avf_delete_if (vm, ad, /* with_barrier */ 0);
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error = clib_error_return (error, "pci-addr %U",
format_vlib_pci_addr, &args->addr);
avf_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
- avf_main_t *am = &avf_main;
- avf_device_t *ad = vec_elt_at_index (am->devices, hi->dev_instance);
+ avf_device_t *ad = avf_get_device (hi->dev_instance);
uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
if (ad->flags & AVF_DEVICE_F_ERROR)
avf_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
vnet_hw_interface_rx_mode mode)
{
- avf_main_t *am = &avf_main;
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
- avf_device_t *ad = pool_elt_at_index (am->devices, hw->dev_instance);
+ avf_device_t *ad = avf_get_device (hw->dev_instance);
avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, qid);
if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
- rxq->int_mode = 0;
+ {
+ if (rxq->int_mode == 0)
+ return 0;
+ if (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
+ avf_irq_n_set_state (ad, qid, AVF_IRQ_STATE_WB_ON_ITR);
+ else
+ avf_irq_n_set_state (ad, qid, AVF_IRQ_STATE_ENABLED);
+ rxq->int_mode = 0;
+ }
else
- rxq->int_mode = 1;
+ {
+ if (rxq->int_mode == 1)
+ return 0;
+ if (ad->n_rx_irqs != ad->n_rx_queues)
+ return clib_error_return (0, "not enough interrupt lines");
+ rxq->int_mode = 1;
+ avf_irq_n_set_state (ad, qid, AVF_IRQ_STATE_ENABLED);
+ }
return 0;
}
avf_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
u32 node_index)
{
- avf_main_t *am = &avf_main;
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
- avf_device_t *ad = pool_elt_at_index (am->devices, hw->dev_instance);
+ avf_device_t *ad = avf_get_device (hw->dev_instance);
/* Shut off redirection */
if (node_index == ~0)
static void
avf_clear_hw_interface_counters (u32 instance)
{
- avf_main_t *am = &avf_main;
- avf_device_t *ad = vec_elt_at_index (am->devices, instance);
+ avf_device_t *ad = avf_get_device (instance);
clib_memcpy_fast (&ad->last_cleared_eth_stats,
&ad->eth_stats, sizeof (ad->eth_stats));
}