#include <vlib/unix/unix.h>
#include <vlib/pci/pci.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/interface/rx_queue_funcs.h>
#include <avf/avf.h>
#define AVF_MBOX_LEN 64
-#define AVF_MBOX_BUF_SZ 512
+#define AVF_MBOX_BUF_SZ 4096
#define AVF_RXQ_SZ 512
#define AVF_TXQ_SZ 512
#define AVF_ITR_INT 250
#define PCI_DEVICE_ID_INTEL_X710_VF 0x154c
#define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd
+/* *INDENT-OFF* */
+VLIB_REGISTER_LOG_CLASS (avf_log) = {
+ .class_name = "avf",
+};
+/* *INDENT-ON* */
+
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},
done:
if (ad->flags & AVF_DEVICE_F_ELOG)
{
- /* *INDENT-OFF* */
ELOG_TYPE_DECLARE (el) =
{
.format = "avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x "
u16 datalen;
u16 retval;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
- ed->dev_instance = ad->dev_instance;
- ed->s_flags = dc.flags;
- ed->r_flags = d->flags;
- ed->opcode = dc.opcode;
- ed->datalen = dc.datalen;
- ed->retval = d->retval;
- /* *INDENT-ON* */
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+ ed->dev_instance = ad->dev_instance;
+ ed->s_flags = dc.flags;
+ ed->r_flags = d->flags;
+ ed->opcode = dc.opcode;
+ ed->datalen = dc.datalen;
+ ed->retval = d->retval;
}
return err;
if (ad->flags & AVF_DEVICE_F_ELOG)
{
- /* *INDENT-OFF* */
ELOG_TYPE_DECLARE (el) =
{
.format = "avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
u32 reg;
u32 val;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
- ed->dev_instance = ad->dev_instance;
- ed->reg = reg;
- ed->val = val;
- /* *INDENT-ON* */
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+ ed->dev_instance = ad->dev_instance;
+ ed->reg = reg;
+ ed->val = val;
}
return err;
}
{
clib_error_t *err;
avf_txq_t *txq;
+ u8 bpi = vlib_buffer_pool_get_default_for_numa (vm,
+ ad->numa_node);
if (qid >= ad->num_queue_pairs)
{
txq = vec_elt_at_index (ad->txqs, qid);
txq->size = txq_size;
txq->next = 0;
+
+ /* Prepare a placeholder buffer to maintain a 1-1
+ relationship between bufs and descs when a context
+ descriptor is added in descs */
+ if (!vlib_buffer_alloc_from_pool
+ (vm, &txq->ctx_desc_placeholder_bi, 1, bpi))
+ return clib_error_return (0, "buffer allocation error");
+
txq->descs = vlib_physmem_alloc_aligned_on_numa (vm, txq->size *
sizeof (avf_tx_desc_t),
2 * CLIB_CACHE_LINE_BYTES,
/* initialize ring of pending RS slots */
clib_ring_new_aligned (txq->rs_slots, 32, CLIB_CACHE_LINE_BYTES);
+ vec_validate_aligned (txq->tmp_descs, txq->size, CLIB_CACHE_LINE_BYTES);
+ vec_validate_aligned (txq->tmp_bufs, txq->size, CLIB_CACHE_LINE_BYTES);
+
ad->n_tx_queues = clib_min (ad->num_queue_pairs, qid + 1);
return 0;
}
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 */
if (d->v_opcode != op)
{
- err =
- clib_error_return (0,
- "unexpected message receiver [v_opcode = %u, "
- "expected %u, v_retval %d]", d->v_opcode, op,
- d->v_retval);
+ err = clib_error_return (0,
+ "unexpected message received [v_opcode = %u, "
+ "expected %u, v_retval %d]",
+ d->v_opcode, op, d->v_retval);
goto done;
}
goto done;
}
- if (d->flags & AVF_AQ_F_BUF)
+ if (out_len && d->flags & AVF_AQ_F_BUF)
{
void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
clib_memcpy_fast (out, buf, out_len);
if (ad->flags & AVF_DEVICE_F_ELOG)
{
- /* *INDENT-OFF* */
ELOG_TYPE_DECLARE (el) =
{
.format = "avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
u32 v_opcode_val;
u32 v_retval;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
- ed->dev_instance = ad->dev_instance;
- ed->v_opcode = op;
- ed->v_opcode_val = op;
- ed->v_retval = d->v_retval;
- /* *INDENT-ON* */
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+ ed->dev_instance = ad->dev_instance;
+ ed->v_opcode = op;
+ ed->v_opcode_val = op;
+ ed->v_retval = d->v_retval;
}
return err;
}
u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
VIRTCHNL_VF_OFFLOAD_RX_POLLING |
- VIRTCHNL_VF_CAP_ADV_LINK_SPEED);
+ VIRTCHNL_VF_CAP_ADV_LINK_SPEED | VIRTCHNL_VF_OFFLOAD_FDIR_PF |
+ VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF | VIRTCHNL_VF_OFFLOAD_VLAN_V2);
- avf_log_debug (ad, "get_vf_reqources: bitmap 0x%x", bitmap);
+ avf_log_debug (ad, "get_vf_resources: bitmap 0x%x (%U)", bitmap,
+ format_avf_vf_cap_flags, bitmap);
err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
sizeof (u32), res, sizeof (virtchnl_vf_resource_t));
if (err == 0)
{
int i;
- avf_log_debug (ad, "get_vf_reqources: num_vsis %u num_queue_pairs %u "
- "max_vectors %u max_mtu %u vf_offload_flags 0x%04x "
+ avf_log_debug (ad,
+ "get_vf_resources: num_vsis %u num_queue_pairs %u "
+ "max_vectors %u max_mtu %u vf_cap_flags 0x%x (%U) "
"rss_key_size %u rss_lut_size %u",
res->num_vsis, res->num_queue_pairs, res->max_vectors,
- res->max_mtu, res->vf_offload_flags, res->rss_key_size,
- res->rss_lut_size);
+ res->max_mtu, res->vf_cap_flags, format_avf_vf_cap_flags,
+ res->vf_cap_flags, res->rss_key_size, res->rss_lut_size);
for (i = 0; i < res->num_vsis; i++)
- avf_log_debug (ad, "get_vf_reqources_vsi[%u]: vsi_id %u "
- "num_queue_pairs %u vsi_type %u qset_handle %u "
- "default_mac_addr %U", i,
- res->vsi_res[i].vsi_id,
- res->vsi_res[i].num_queue_pairs,
- res->vsi_res[i].vsi_type,
- res->vsi_res[i].qset_handle,
- format_ethernet_address,
- res->vsi_res[i].default_mac_addr);
+ avf_log_debug (
+ ad,
+ "get_vf_resources_vsi[%u]: vsi_id %u num_queue_pairs %u vsi_type %u "
+ "qset_handle %u default_mac_addr %U",
+ i, res->vsi_res[i].vsi_id, res->vsi_res[i].num_queue_pairs,
+ res->vsi_res[i].vsi_type, res->vsi_res[i].qset_handle,
+ format_ethernet_address, res->vsi_res[i].default_mac_addr);
}
return err;
}
clib_error_t *
-avf_config_promisc_mode (vlib_main_t * vm, avf_device_t * ad, int is_enable)
+avf_op_config_promisc_mode (vlib_main_t * vm, avf_device_t * ad,
+ int is_enable)
{
virtchnl_promisc_info_t pi = { 0 };
}
clib_error_t *
-avf_op_add_eth_addr (vlib_main_t * vm, avf_device_t * ad, u8 count, u8 * macs)
+avf_op_add_del_eth_addr (vlib_main_t * vm, avf_device_t * ad, u8 count,
+ u8 * macs, int is_add)
{
int msg_len =
sizeof (virtchnl_ether_addr_list_t) +
al->vsi_id = ad->vsi_id;
al->num_elements = count;
- avf_log_debug (ad, "add_eth_addr: vsi_id %u num_elements %u",
- ad->vsi_id, al->num_elements);
+ avf_log_debug (ad, "add_del_eth_addr: vsi_id %u num_elements %u is_add %u",
+ ad->vsi_id, al->num_elements, is_add);
for (i = 0; i < count; i++)
{
clib_memcpy_fast (&al->list[i].addr, macs + i * 6, 6);
- avf_log_debug (ad, "add_eth_addr[%u]: %U", i,
+ avf_log_debug (ad, "add_del_eth_addr[%u]: %U", i,
format_ethernet_address, &al->list[i].addr);
}
- return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ADD_ETH_ADDR, msg, msg_len, 0,
- 0);
+ return avf_send_to_pf (vm, ad, is_add ? VIRTCHNL_OP_ADD_ETH_ADDR :
+ VIRTCHNL_OP_DEL_ETH_ADDR, msg, msg_len, 0, 0);
}
clib_error_t *
es, sizeof (virtchnl_eth_stats_t));
}
+clib_error_t *
+avf_op_get_offload_vlan_v2_caps (vlib_main_t *vm, avf_device_t *ad,
+ virtchnl_vlan_caps_t *vc)
+{
+ clib_error_t *err;
+
+ err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, 0, 0, vc,
+ sizeof (virtchnl_vlan_caps_t));
+
+ avf_log_debug (ad, "get_offload_vlan_v2_caps:\n%U%U", format_white_space, 16,
+ format_avf_vlan_caps, vc);
+
+ return err;
+}
+
+clib_error_t *
+avf_op_disable_vlan_stripping_v2 (vlib_main_t *vm, avf_device_t *ad, u32 outer,
+ u32 inner)
+{
+ virtchnl_vlan_setting_t vs = {
+ .outer_ethertype_setting = outer,
+ .inner_ethertype_setting = inner,
+ .vport_id = ad->vsi_id,
+ };
+
+ avf_log_debug (ad, "disable_vlan_stripping_v2: outer: %U, inner %U",
+ format_avf_vlan_support, outer, format_avf_vlan_support,
+ inner);
+
+ return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2, &vs,
+ sizeof (virtchnl_vlan_setting_t), 0, 0);
+}
+
clib_error_t *
avf_device_reset (vlib_main_t * vm, avf_device_t * ad)
{
return clib_error_return (0, "unexpected GET_VF_RESOURCE reply received");
ad->vsi_id = res.vsi_res[0].vsi_id;
- ad->feature_bitmap = res.vf_offload_flags;
+ ad->cap_flags = res.vf_cap_flags;
ad->num_queue_pairs = res.num_queue_pairs;
ad->max_vectors = res.max_vectors;
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;
+ wb_on_itr = (ad->cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) != 0;
clib_memcpy_fast (ad->hwaddr, res.vsi_res[0].default_mac_addr, 6);
/*
* Disable VLAN stripping
*/
- if ((error = avf_op_disable_vlan_stripping (vm, ad)))
+ if (ad->cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
+ {
+ virtchnl_vlan_caps_t vc = {};
+ u32 outer = VIRTCHNL_VLAN_UNSUPPORTED, inner = VIRTCHNL_VLAN_UNSUPPORTED;
+ u32 mask = VIRTCHNL_VLAN_ETHERTYPE_8100;
+
+ if ((error = avf_op_get_offload_vlan_v2_caps (vm, ad, &vc)))
+ return error;
+
+ outer = vc.offloads.stripping_support.outer & mask;
+ inner = vc.offloads.stripping_support.inner & mask;
+
+ if ((outer || inner) &&
+ (error = avf_op_disable_vlan_stripping_v2 (vm, ad, outer, inner)))
+ return error;
+ }
+ else if ((error = avf_op_disable_vlan_stripping (vm, ad)))
return error;
/*
else
ad->n_rx_irqs = 1;
-
- if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
+ if ((ad->cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
(error = avf_op_config_rss_lut (vm, ad)))
return error;
- if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
+ if ((ad->cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
(error = avf_op_config_rss_key (vm, ad)))
return error;
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)))
+ if ((error = avf_op_add_del_eth_addr (vm, ad, 1, ad->hwaddr, 1 /* add */ )))
return error;
if ((error = avf_op_enable_queues (vm, ad, pow2_mask (ad->n_rx_queues),
void
avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq)
{
- avf_main_t *am = &avf_main;
vnet_main_t *vnm = vnet_get_main ();
virtchnl_pf_event_t *e;
u32 r;
u32 flags = 0;
u32 mbps = 0;
- if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
+ if (ad->cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
link_up = e->event_data.link_event_adv.link_status;
else
link_up = e->event_data.link_event.link_status;
- if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
+ if (ad->cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
mbps = e->event_data.link_event_adv.link_speed;
if (speed == VIRTCHNL_LINK_SPEED_40GB)
mbps = 40000;
u8 link_status;
u32 link_speed;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
- ed->dev_instance = ad->dev_instance;
- ed->link_status = link_up;
- ed->link_speed = mbps;
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+ ed->dev_instance = ad->dev_instance;
+ ed->link_status = link_up;
+ ed->link_speed = mbps;
}
}
else
u32 event;
u32 severity;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
- ed->dev_instance = ad->dev_instance;
- ed->event = e->event;
- ed->severity = e->severity;
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+ ed->dev_instance = ad->dev_instance;
+ ed->event = e->event;
+ ed->severity = e->severity;
}
}
}
error:
ad->flags |= AVF_DEVICE_F_ERROR;
ASSERT (ad->error != 0);
- vlib_log_err (am->log_class, "%U", format_clib_error, ad->error);
+ vlib_log_err (avf_log.class, "%U", format_clib_error, ad->error);
+}
+
+clib_error_t *
+avf_op_program_flow (vlib_main_t *vm, avf_device_t *ad, int is_create,
+ u8 *rule, u32 rule_len, u8 *program_status,
+ u32 status_len)
+{
+ avf_log_debug (ad, "avf_op_program_flow: vsi_id %u is_create %u", ad->vsi_id,
+ is_create);
+
+ return avf_send_to_pf (vm, ad,
+ is_create ? VIRTCHNL_OP_ADD_FDIR_FILTER :
+ VIRTCHNL_OP_DEL_FDIR_FILTER,
+ rule, rule_len, program_status, status_len);
+}
+
+static void
+avf_process_handle_request (vlib_main_t * vm, avf_process_req_t * req)
+{
+ avf_device_t *ad = avf_get_device (req->dev_instance);
+
+ if (req->type == AVF_PROCESS_REQ_ADD_DEL_ETH_ADDR)
+ req->error = avf_op_add_del_eth_addr (vm, ad, 1, req->eth_addr,
+ req->is_add);
+ else if (req->type == AVF_PROCESS_REQ_CONFIG_PROMISC_MDDE)
+ req->error = avf_op_config_promisc_mode (vm, ad, req->is_enable);
+ else if (req->type == AVF_PROCESS_REQ_PROGRAM_FLOW)
+ req->error =
+ avf_op_program_flow (vm, ad, req->is_add, req->rule, req->rule_len,
+ req->program_status, req->status_len);
+ else
+ clib_panic ("BUG: unknown avf proceess request type");
+
+ if (req->calling_process_index != avf_process_node.index)
+ vlib_process_signal_event (vm, req->calling_process_index, 0, 0);
+}
+
+static clib_error_t *
+avf_process_request (vlib_main_t * vm, avf_process_req_t * req)
+{
+ uword *event_data = 0;
+ req->calling_process_index = vlib_get_current_process_node_index (vm);
+
+ if (req->calling_process_index != avf_process_node.index)
+ {
+ vlib_process_signal_event_pointer (vm, avf_process_node.index,
+ AVF_PROCESS_EVENT_REQ, req);
+
+ vlib_process_wait_for_event_or_clock (vm, 5.0);
+
+ if (vlib_process_get_events (vm, &event_data) != 0)
+ clib_panic ("avf process node failed to reply in 5 seconds");
+ vec_free (event_data);
+ }
+ else
+ avf_process_handle_request (vm, req);
+
+ return req->error;
}
static u32
avf_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
{
+ avf_process_req_t req;
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);
- clib_error_t *error;
- u8 promisc_enabled;
+ avf_device_t *ad = avf_get_device (hw->dev_instance);
+ clib_error_t *err;
switch (flags)
{
return ~0;
}
- promisc_enabled = ((ad->flags & AVF_DEVICE_F_PROMISC) != 0);
- if ((error = avf_config_promisc_mode (vm, ad, promisc_enabled)))
+ req.is_enable = ((ad->flags & AVF_DEVICE_F_PROMISC) != 0);
+ req.type = AVF_PROCESS_REQ_CONFIG_PROMISC_MDDE;
+ req.dev_instance = hw->dev_instance;
+
+ if ((err = avf_process_request (vm, &req)))
{
- avf_log_err (ad, "%s: %U", format_clib_error, error);
- clib_error_free (error);
+ avf_log_err (ad, "error: %U", format_clib_error, err);
+ clib_error_free (err);
return ~0;
}
-
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_REQ:
+ for (int i = 0; i < vec_len (event_data); i++)
+ avf_process_handle_request (vm, (void *) event_data[i]);
+ 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)
{
- avf_process_one_device (vm, ad, irq);
- });
+ vec_add1 (dev_pointers, avf_get_device (i));
+ }
+
+ vec_foreach_index (i, dev_pointers)
+ {
+ 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);
u32 icr0;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
ed->dev_instance = ad->dev_instance;
ed->icr0 = icr0;
}
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);
+ avf_device_t *ad = avf_get_device (pd);
+ avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, line - 1);
if (ad->flags & AVF_DEVICE_F_ELOG)
{
u16 line;
} *ed;
- ed = ELOG_DATA (&vm->elog_main, el);
+ ed = ELOG_DATA (&vlib_global_main.elog_main, el);
ed->dev_instance = ad->dev_instance;
ed->line = line;
}
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);
+ if (ad->flags & AVF_DEVICE_F_RX_INT && rxq->int_mode)
+ vnet_hw_if_rx_queue_set_int_pending (vnm, rxq->queue_index);
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;
+ u32 dev_instance;
+
+ 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);
vlib_buffer_free_from_ring (vm, txq->bufs, first, txq->size,
txq->n_enqueued);
}
+ /* Free the placeholder buffer */
+ vlib_buffer_free_one(vm, txq->ctx_desc_placeholder_bi);
vec_free (txq->bufs);
clib_ring_free (txq->rs_slots);
+ vec_free (txq->tmp_bufs);
+ vec_free (txq->tmp_descs);
}
/* *INDENT-ON* */
vec_free (ad->txqs);
vec_free (ad->name);
clib_error_free (ad->error);
+ dev_instance = ad->dev_instance;
clib_memset (ad, 0, sizeof (*ad));
- pool_put (am->devices, ad);
+ pool_put_index (am->devices, 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;
+
+ /* *INDENT-OFF* */
+ pool_foreach (adp, am->devices) {
+ if ((*adp)->pci_addr.as_u32 == args->addr.as_u32)
+ {
+ args->rv = VNET_API_ERROR_ADDRESS_IN_USE;
+ args->error =
+ clib_error_return (error, "%U: %s", format_vlib_pci_addr,
+ &args->addr, "pci address in use");
+ return;
+ }
+ }
+ /* *INDENT-ON* */
+
+ 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,
/* 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;
+ hi->caps |= VNET_HW_INTERFACE_CAP_SUPPORTS_MAC_FILTER |
+ VNET_HW_INTERFACE_CAP_SUPPORTS_L4_TX_CKSUM |
+ VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO;
ethernet_set_flags (vnm, ad->hw_if_index,
ETHERNET_INTERFACE_FLAG_DEFAULT_L3);
args->sw_if_index = ad->sw_if_index = sw->sw_if_index;
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, ad->hw_if_index);
- hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
- vnet_hw_interface_set_input_node (vnm, ad->hw_if_index,
- avf_input_node.index);
+ hw->caps |= VNET_HW_INTERFACE_CAP_SUPPORTS_INT_MODE;
+ vnet_hw_if_set_input_node (vnm, ad->hw_if_index, avf_input_node.index);
for (i = 0; i < ad->n_rx_queues; i++)
- vnet_hw_interface_assign_rx_thread (vnm, ad->hw_if_index, i, ~0);
+ {
+ u32 qi, fi;
+ qi = vnet_hw_if_register_rx_queue (vnm, ad->hw_if_index, i,
+ VNET_HW_IF_RXQ_THREAD_ANY);
+
+ if (ad->flags & AVF_DEVICE_F_RX_INT)
+ {
+ fi = vlib_pci_get_msix_file_index (vm, ad->pci_dev_handle, i + 1);
+ vnet_hw_if_set_rx_queue_file_index (vnm, qi, fi);
+ }
+ ad->rxqs[i].queue_index = qi;
+ }
+ vnet_hw_if_update_runtime_data (vnm, ad->hw_if_index);
if (pool_elts (am->devices) == 1)
vlib_process_signal_event (vm, avf_process_node.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)
static clib_error_t *
avf_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
- vnet_hw_interface_rx_mode mode)
+ vnet_hw_if_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)
+ if (mode == VNET_HW_IF_RX_MODE_POLLING)
{
if (rxq->int_mode == 0)
return 0;
- if (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
+ if (ad->cap_flags & 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);
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)
vlib_node_add_next (vlib_get_main (), avf_input_node.index, node_index);
}
+static clib_error_t *
+avf_add_del_mac_address (vnet_hw_interface_t * hw,
+ const u8 * address, u8 is_add)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ avf_process_req_t req;
+
+ req.dev_instance = hw->dev_instance;
+ req.type = AVF_PROCESS_REQ_ADD_DEL_ETH_ADDR;
+ req.is_add = is_add;
+ clib_memcpy (req.eth_addr, address, 6);
+
+ return avf_process_request (vm, &req);
+}
+
static char *avf_tx_func_error_strings[] = {
#define _(n,s) s,
foreach_avf_tx_func_error
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));
}
-/* *INDENT-OFF* */
-VNET_DEVICE_CLASS (avf_device_class,) =
+clib_error_t *
+avf_program_flow (u32 dev_instance, int is_add, u8 *rule, u32 rule_len,
+ u8 *program_status, u32 status_len)
{
+ vlib_main_t *vm = vlib_get_main ();
+ avf_process_req_t req;
+
+ req.dev_instance = dev_instance;
+ req.type = AVF_PROCESS_REQ_PROGRAM_FLOW;
+ req.is_add = is_add;
+ req.rule = rule;
+ req.rule_len = rule_len;
+ req.program_status = program_status;
+ req.status_len = status_len;
+
+ return avf_process_request (vm, &req);
+}
+
+/* *INDENT-OFF* */
+VNET_DEVICE_CLASS (avf_device_class, ) = {
.name = "Adaptive Virtual Function (AVF) interface",
.clear_counters = avf_clear_hw_interface_counters,
.format_device = format_avf_device,
.admin_up_down_function = avf_interface_admin_up_down,
.rx_mode_change_function = avf_interface_rx_mode_change,
.rx_redirect_to_node = avf_set_interface_next_node,
+ .mac_addr_add_del_function = avf_add_del_mac_address,
.tx_function_n_errors = AVF_TX_N_ERROR,
.tx_function_error_strings = avf_tx_func_error_strings,
+ .flow_ops_function = avf_flow_ops_fn,
};
/* *INDENT-ON* */
vec_validate_aligned (am->per_thread_data, tm->n_vlib_mains - 1,
CLIB_CACHE_LINE_BYTES);
- am->log_class = vlib_log_register_class ("avf", 0);
- vlib_log_debug (am->log_class, "initialized");
-
return 0;
}