25 #define AVF_MBOX_LEN 64 26 #define AVF_MBOX_BUF_SZ 512 27 #define AVF_RXQ_SZ 512 28 #define AVF_TXQ_SZ 512 29 #define AVF_ITR_INT 8160 31 #define PCI_VENDOR_ID_INTEL 0x8086 32 #define PCI_DEVICE_ID_INTEL_AVF 0x1889 33 #define PCI_DEVICE_ID_INTEL_X710_VF 0x154c 34 #define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd 48 u32 dyn_ctl0 = 0, icr0_ena = 0;
60 u32 dyn_ctl0 = 0, icr0_ena = 0;
62 icr0_ena |= (1 << 30);
124 if (ad->
flags & AVF_DEVICE_F_ELOG)
153 if (ad->
flags & AVF_DEVICE_F_ELOG)
158 .format =
"avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x " 159 "datalen %d retval %d",
160 .format_args =
"i4i2i2i2i2i2",
173 ed->s_flags = dc.
flags;
174 ed->r_flags = d->
flags;
192 if (ad->
flags & AVF_DEVICE_F_ELOG)
197 .format =
"avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
198 .format_args =
"i4i4i4",
225 rxq->
size = rxq_size;
241 for (i = 0; i < n_alloc; i++)
243 if (ad->
flags & AVF_DEVICE_F_IOVA)
269 ad->
flags |= AVF_DEVICE_F_SHARED_TXQ_LOCK;
275 txq->
size = txq_size;
308 return (ad->
flags & AVF_DEVICE_F_IOVA) ?
352 void *in,
int in_len,
void *out,
int out_len)
382 if (d->
v_opcode == VIRTCHNL_OP_EVENT)
403 "unexpected message receiver [v_opcode = %u, " 404 "expected %u, v_retval %d]", d->
v_opcode, op,
429 if (ad->
flags & AVF_DEVICE_F_ELOG)
434 .format =
"avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
435 .format_args =
"i4t4i4i4",
438 #define _(v, n) [v] = #n, 453 ed->v_opcode_val = op;
484 u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
485 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
486 VIRTCHNL_VF_OFFLOAD_RX_POLLING);
488 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
499 memset (msg, 0, msg_len);
504 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_LUT, msg, msg_len, 0,
511 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 0, 0, 0,
522 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, &pi,
537 memset (msg, 0, msg_len);
542 for (i = 0; i < n_qp; i++)
569 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_VSI_QUEUES, msg, msg_len,
582 memset (msg, 0, msg_len);
589 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0,
603 memset (msg, 0, msg_len);
607 for (i = 0; i <
count; i++)
609 return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ADD_ETH_ADDR, msg, msg_len, 0,
654 if (rstat == 2 || rstat == 3)
751 ad->
flags |= AVF_DEVICE_F_INITIALIZED;
763 if (ad->
flags & AVF_DEVICE_F_ERROR)
766 if ((ad->
flags & AVF_DEVICE_F_INITIALIZED) == 0)
772 if ((r & 0xf0000000) != (1ULL << 31))
779 if ((r & 0xf0000000) != (1ULL << 31))
797 if (link_up && (ad->
flags & AVF_DEVICE_F_LINK_UP) == 0)
799 ad->
flags |= AVF_DEVICE_F_LINK_UP;
802 if (speed == VIRTCHNL_LINK_SPEED_40GB)
804 else if (speed == VIRTCHNL_LINK_SPEED_25GB)
806 else if (speed == VIRTCHNL_LINK_SPEED_10GB)
808 else if (speed == VIRTCHNL_LINK_SPEED_1GB)
810 else if (speed == VIRTCHNL_LINK_SPEED_100MB)
815 else if (!link_up && (ad->
flags & AVF_DEVICE_F_LINK_UP) != 0)
817 ad->
flags &= ~AVF_DEVICE_F_LINK_UP;
821 if (ad->
flags & AVF_DEVICE_F_ELOG)
825 .format =
"avf[%d] link change: link_status %d " 827 .format_args =
"i4i1i1",
837 ed->link_status = link_up;
838 ed->link_speed = speed;
843 if (ad->
flags & AVF_DEVICE_F_ELOG)
847 .format =
"avf[%d] unknown event: event %d severity %d",
848 .format_args =
"i4i4i1i1",
858 ed->event = e->
event;
869 ad->
flags |= AVF_DEVICE_F_ERROR;
887 uword *event_data = 0, event_type;
888 int enabled = 0, irq;
889 f64 last_run_duration = 0;
890 f64 last_periodic_time = 0;
924 avf_process_one_device (vm, ad, irq);
936 .name =
"avf-process",
951 if (ad->
flags & AVF_DEVICE_F_ELOG)
956 .format =
"avf[%d] irq 0: icr0 0x%x",
957 .format_args =
"i4i4",
974 if (icr0 & (1 << 30))
987 if (ad->
flags & AVF_DEVICE_F_ELOG)
992 .format =
"avf[%d] irq %d: received",
993 .format_args =
"i4i2",
1061 memset (ad, 0,
sizeof (*ad));
1081 args->
rv = VNET_API_ERROR_INVALID_VALUE;
1092 ad->
flags |= AVF_DEVICE_F_ELOG;
1097 args->
rv = VNET_API_ERROR_INVALID_INTERFACE;
1159 ad->
flags |= AVF_DEVICE_F_IOVA;
1186 args->
rv = VNET_API_ERROR_INVALID_INTERFACE;
1200 if (ad->
flags & AVF_DEVICE_F_ERROR)
1207 ad->
flags |= AVF_DEVICE_F_ADMIN_UP;
1213 ad->
flags &= ~AVF_DEVICE_F_ADMIN_UP;
1221 .name =
"Adaptive Virtual Function (AVF) interface",
1250 if ((i >= 22) && (i <= 87))
1253 p->
flags = VNET_BUFFER_F_IS_IP4;
1255 else if ((i >= 88) && (i <= 153))
1258 p->
flags = VNET_BUFFER_F_IS_IP6;
1263 p->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
format_function_t format_vlib_pci_addr
#define vec_foreach_index(var, v)
Iterate over vector indices.
virtchnl_queue_pair_info_t qpair[1]
u8 * format_clib_error(u8 *s, va_list *va)
#define vlib_log_warn(...)
#define VLIB_PHYSMEM_F_INIT_MHEAP
#define VNET_HW_INTERFACE_FLAG_SPEED_1G
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
clib_error_t * avf_init(vlib_main_t *vm)
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
clib_error_t * avf_send_to_pf(vlib_main_t *vm, avf_device_t *ad, virtchnl_ops_t op, void *in, int in_len, void *out, int out_len)
#define VLIB_PHYSMEM_F_HUGETLB
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
vnet_main_t * vnet_get_main(void)
void avf_arq_slot_init(avf_device_t *ad, u16 slot)
virtchnl_vsi_type_t vsi_type
virtchnl_vector_map_t vecmap[1]
static f64 vlib_time_now(vlib_main_t *vm)
virtchnl_link_speed_t link_speed
static void avf_adminq_init(vlib_main_t *vm, avf_device_t *ad)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static clib_error_t * vlib_physmem_region_alloc(vlib_main_t *vm, char *name, u32 size, u8 numa_node, u32 flags, vlib_physmem_region_index_t *idx)
format_function_t format_avf_device
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define VNET_HW_INTERFACE_FLAG_LINK_UP
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
static void * vlib_physmem_alloc_aligned(vlib_main_t *vm, vlib_physmem_region_index_t idx, clib_error_t **error, uword n_bytes, uword alignment)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static u64 vlib_get_buffer_data_physical_address(vlib_main_t *vm, u32 buffer_index)
clib_error_t * avf_op_config_irq_map(vlib_main_t *vm, avf_device_t *ad)
static vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
vnet_device_class_t avf_device_class
clib_error_t * avf_device_reset(vlib_main_t *vm, avf_device_t *ad)
clib_error_t * vlib_pci_register_msix_handler(vlib_pci_dev_handle_t h, u32 start, u32 count, pci_msix_handler_function_t *msix_handler)
clib_error_t * avf_op_disable_vlan_stripping(vlib_main_t *vm, avf_device_t *ad)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static uword avf_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
#define PCI_DEVICE_ID_INTEL_AVF
static u32 avf_reg_read(avf_device_t *ad, u32 addr)
clib_error_t * avf_txq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 txq_size)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
#define VNET_HW_INTERFACE_FLAG_SPEED_25G
union virtchnl_pf_event_t::@379 event_data
clib_error_t * vlib_pci_device_open(vlib_pci_addr_t *addr, pci_device_id_t ids[], vlib_pci_dev_handle_t *handle)
clib_error_t * avf_config_promisc_mode(vlib_main_t *vm, avf_device_t *ad)
#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES
vlib_pci_dev_handle_t pci_dev_handle
#define vlib_call_init_function(vm, x)
virtchnl_ether_addr_t list[1]
#define vlib_log_debug(...)
struct virtchnl_pf_event_t::@379::@380 link_event
static void clib_spinlock_init(clib_spinlock_t *p)
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
static heap_elt_t * first(heap_header_t *h)
void avf_process_one_device(vlib_main_t *vm, avf_device_t *ad, int is_irq)
static void avf_irq_n_handler(vlib_pci_dev_handle_t h, u16 line)
const u32 device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES/CLIB_CACHE_LINE_BYTES)+1)*CLIB_CACHE_LINE_BYTES]
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static u32 avf_get_u32(void *start, int offset)
u32 vlib_pci_dev_handle_t
#define pool_put(P, E)
Free an object E in pool P.
#define VIRTCHNL_VERSION_MAJOR
clib_error_t * avf_op_enable_queues(vlib_main_t *vm, avf_device_t *ad, u32 rx, u32 tx)
static void avf_reg_flush(avf_device_t *ad)
static clib_error_t * vlib_pci_bus_master_enable(vlib_pci_dev_handle_t h)
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
static u32 avf_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 flags)
static void avf_irq_0_enable(avf_device_t *ad)
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t avf_input_node
(constructor) VLIB_REGISTER_NODE (avf_input_node)
#define vec_free(V)
Free vector's memory (no header).
clib_error_t * pci_bus_init(vlib_main_t *vm)
static void avf_irq_0_disable(avf_device_t *ad)
clib_error_t * avf_op_get_stats(vlib_main_t *vm, avf_device_t *ad, virtchnl_eth_stats_t *es)
#define clib_memcpy(a, b, c)
vlib_log_class_t log_class
#define ELOG_TYPE_DECLARE(f)
clib_error_t * avf_aq_desc_enq(vlib_main_t *vm, avf_device_t *ad, avf_aq_desc_t *dt, void *data, int len)
#define VNET_HW_INTERFACE_FLAG_SPEED_10G
u32 per_interface_next_index
clib_error_t * avf_op_add_eth_addr(vlib_main_t *vm, avf_device_t *ad, u8 count, u8 *macs)
static clib_error_t * avf_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
virtchnl_status_code_t v_retval
#define VNET_HW_INTERFACE_FLAG_FULL_DUPLEX
void vlib_pci_device_close(vlib_pci_dev_handle_t h)
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
#define PCI_DEVICE_ID_INTEL_X722_VF
#define AVFINT_DYN_CTLN(x)
clib_error_t * avf_op_config_rss_lut(vlib_main_t *vm, avf_device_t *ad)
static void avf_irq_n_enable(avf_device_t *ad, u8 line)
#define PCI_DEVICE_ID_INTEL_X710_VF
static void vlib_physmem_free(vlib_main_t *vm, vlib_physmem_region_index_t idx, void *mem)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
VNET_DEVICE_CLASS(bond_dev_class)
virtchnl_pf_event_t * events
virtchnl_event_codes_t event
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
clib_error_t * avf_op_version(vlib_main_t *vm, avf_device_t *ad, virtchnl_version_info_t *ver)
static uword pointer_to_uword(const void *p)
static uword avf_dma_addr(vlib_main_t *vm, avf_device_t *ad, void *p)
virtchnl_eth_stats_t eth_stats
static vlib_main_t * vlib_get_main(void)
static void avf_irq_0_handler(vlib_pci_dev_handle_t h, u16 line)
#define VNET_HW_INTERFACE_FLAG_SPEED_100M
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
format_function_t format_avf_device_name
uword vlib_pci_get_private_data(vlib_pci_dev_handle_t h)
#define foreach_virtchnl_op
static u64 vlib_physmem_virtual_to_physical(vlib_main_t *vm, vlib_physmem_region_index_t idx, void *mem)
clib_error_t * avf_rxq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 rxq_size)
void vlib_pci_set_private_data(vlib_pci_dev_handle_t h, uword private_data)
clib_error_t * avf_device_init(vlib_main_t *vm, avf_device_t *ad, avf_create_if_args_t *args)
#define clib_error_free(e)
clib_error_t * vlib_pci_map_region(vlib_pci_dev_handle_t h, u32 resource, void **result)
virtchnl_vsi_resource_t vsi_res[1]
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
clib_error_t * vlib_pci_enable_msix_irq(vlib_pci_dev_handle_t h, u16 start, u16 count)
static clib_error_t * vlib_pci_intr_enable(vlib_pci_dev_handle_t h)
#define VNET_HW_INTERFACE_FLAG_SPEED_40G
avf_per_thread_data_t * per_thread_data
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
#define vlib_log_err(...)
#define CLIB_MEMORY_BARRIER()
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
#define CLIB_CACHE_LINE_BYTES
#define VIRTCHNL_VERSION_MINOR
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static void avf_irq_n_disable(avf_device_t *ad, u8 line)
#define PCI_VENDOR_ID_INTEL
clib_error_t * avf_cmd_rx_ctl_reg_write(vlib_main_t *vm, avf_device_t *ad, u32 reg, u32 val)
vlib_physmem_region_index_t physmem_region
uword avf_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
clib_error_t * avf_op_config_vsi_queues(vlib_main_t *vm, avf_device_t *ad)
clib_error_t * avf_op_get_vf_resources(vlib_main_t *vm, avf_device_t *ad, virtchnl_vf_resource_t *res)
static uword pool_elts(void *v)
Number of active elements in a pool.