X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Favf%2Fdevice.c;h=62a18cc3c5c583306ace5eb6291947ea01e0d2f8;hb=2ee0098dee4e4130ae350ccfe526d88a826160c5;hp=039a8203edb605152462f70a632e0f784ade60bc;hpb=910d3694e8b22c9d14e5f2913d14ae149e184620;p=vpp.git diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c index 039a8203edb..62a18cc3c5c 100644 --- a/src/plugins/avf/device.c +++ b/src/plugins/avf/device.c @@ -27,7 +27,7 @@ #define AVF_MBOX_BUF_SZ 512 #define AVF_RXQ_SZ 512 #define AVF_TXQ_SZ 512 -#define AVF_ITR_INT 8160 +#define AVF_ITR_INT 250 #define PCI_VENDOR_ID_INTEL 0x8086 #define PCI_DEVICE_ID_INTEL_AVF 0x1889 @@ -35,6 +35,7 @@ #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}, @@ -43,8 +44,21 @@ static pci_device_id_t avf_pci_device_ids[] = { {0}, }; +const static char *virtchnl_event_names[] = { +#define _(v, n) [v] = #n, + foreach_virtchnl_event_code +#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; @@ -53,45 +67,52 @@ avf_irq_0_disable (avf_device_t * 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_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); } @@ -101,10 +122,9 @@ clib_error_t * avf_aq_desc_enq (vlib_main_t * vm, avf_device_t * ad, avf_aq_desc_t * dt, void *data, int len) { - avf_main_t *am = &avf_main; clib_error_t *err = 0; avf_aq_desc_t *d, dc; - int n_retry = 5; + f64 t0, suspend_time = AVF_AQ_ENQ_SUSPEND_TIME; d = &ad->atq[ad->atq_next_slot]; clib_memcpy_fast (d, dt, sizeof (avf_aq_desc_t)); @@ -126,22 +146,25 @@ avf_aq_desc_enq (vlib_main_t * vm, avf_device_t * ad, avf_aq_desc_t * dt, clib_memcpy_fast (&dc, d, sizeof (avf_aq_desc_t)); CLIB_MEMORY_BARRIER (); - vlib_log_debug (am->log_class, "%U", format_hexdump, data, len); ad->atq_next_slot = (ad->atq_next_slot + 1) % AVF_MBOX_LEN; avf_reg_write (ad, AVF_ATQT, ad->atq_next_slot); avf_reg_flush (ad); + t0 = vlib_time_now (vm); retry: - vlib_process_suspend (vm, 10e-6); + vlib_process_suspend (vm, suspend_time); if (((d->flags & AVF_AQ_F_DD) == 0) || ((d->flags & AVF_AQ_F_CMP) == 0)) { - if (--n_retry == 0) + f64 t = vlib_time_now (vm) - t0; + if (t > AVF_AQ_ENQ_MAX_WAIT_TIME) { + avf_log_err (ad, "aq_desc_enq failed (timeout %.3fs)", t); err = clib_error_return (0, "adminq enqueue timeout [opcode 0x%x]", d->opcode); goto done; } + suspend_time *= 2; goto retry; } @@ -374,10 +397,9 @@ avf_send_to_pf (vlib_main_t * vm, avf_device_t * ad, virtchnl_ops_t op, clib_error_t *err; avf_aq_desc_t *d, dt = {.opcode = 0x801,.v_opcode = op }; u32 head; - int n_retry = 5; - + f64 t0, suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME; - /* supppres interrupt in the next adminq receive slot + /* suppress interrupt in the next adminq receive slot as we are going to wait for response we only need interrupts when event is received */ d = &ad->arq[ad->arq_next_slot]; @@ -386,14 +408,20 @@ avf_send_to_pf (vlib_main_t * vm, avf_device_t * ad, virtchnl_ops_t op, if ((err = avf_aq_desc_enq (vm, ad, &dt, in, in_len))) return err; + t0 = vlib_time_now (vm); retry: head = avf_get_u32 (ad->bar0, AVF_ARQH); if (ad->arq_next_slot == head) { - if (--n_retry == 0) - return clib_error_return (0, "timeout"); - vlib_process_suspend (vm, 10e-3); + f64 t = vlib_time_now (vm) - t0; + if (t > AVF_SEND_TO_PF_MAX_WAIT_TIME) + { + avf_log_err (ad, "send_to_pf failed (timeout %.3fs)", t); + return clib_error_return (0, "timeout"); + } + vlib_process_suspend (vm, suspend_time); + suspend_time *= 2; goto retry; } @@ -412,7 +440,9 @@ retry: clib_memcpy_fast (e, buf, sizeof (virtchnl_pf_event_t)); avf_arq_slot_init (ad, ad->arq_next_slot); ad->arq_next_slot++; - n_retry = 5; + /* reset timer */ + t0 = vlib_time_now (vm); + suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME; goto retry; } @@ -487,6 +517,8 @@ avf_op_version (vlib_main_t * vm, avf_device_t * ad, .minor = VIRTCHNL_VERSION_MINOR, }; + avf_log_debug (ad, "version: major %u minor %u", myver.major, myver.minor); + err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_VERSION, &myver, sizeof (virtchnl_version_info_t), ver, sizeof (virtchnl_version_info_t)); @@ -501,12 +533,38 @@ clib_error_t * avf_op_get_vf_resources (vlib_main_t * vm, avf_device_t * ad, virtchnl_vf_resource_t * res) { + clib_error_t *err = 0; 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_OFFLOAD_RX_POLLING | + VIRTCHNL_VF_CAP_ADV_LINK_SPEED); + + avf_log_debug (ad, "get_vf_reqources: bitmap 0x%x", 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 " + "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); + 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); + } - return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap, - sizeof (u32), res, sizeof (virtchnl_vf_resource_t)); + return err; } clib_error_t * @@ -524,6 +582,10 @@ avf_op_config_rss_lut (vlib_main_t * vm, avf_device_t * ad) for (i = 0; i < ad->rss_lut_size; i++) rl->lut[i] = i % ad->n_rx_queues; + avf_log_debug (ad, "config_rss_lut: vsi_id %u rss_lut_size %u lut 0x%U", + rl->vsi_id, rl->lut_entries, format_hex_bytes_no_wrap, + rl->lut, rl->lut_entries); + return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_LUT, msg, msg_len, 0, 0); } @@ -544,6 +606,10 @@ avf_op_config_rss_key (vlib_main_t * vm, avf_device_t * ad) for (i = 0; i < ad->rss_key_size; i++) rk->key[i] = (u8) random_u32 (&seed); + avf_log_debug (ad, "config_rss_key: vsi_id %u rss_key_size %u key 0x%U", + rk->vsi_id, rk->key_len, format_hex_bytes_no_wrap, rk->key, + rk->key_len); + return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_KEY, msg, msg_len, 0, 0); } @@ -551,17 +617,26 @@ avf_op_config_rss_key (vlib_main_t * vm, avf_device_t * ad) clib_error_t * avf_op_disable_vlan_stripping (vlib_main_t * vm, avf_device_t * ad) { + avf_log_debug (ad, "disable_vlan_stripping"); + return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 0, 0, 0, 0); } clib_error_t * -avf_config_promisc_mode (vlib_main_t * vm, avf_device_t * ad) +avf_config_promisc_mode (vlib_main_t * vm, avf_device_t * ad, int is_enable) { virtchnl_promisc_info_t pi = { 0 }; pi.vsi_id = ad->vsi_id; - pi.flags = 1; + + if (is_enable) + pi.flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC; + + avf_log_debug (ad, "config_promisc_mode: unicast %s multicast %s", + pi.flags & FLAG_VF_UNICAST_PROMISC ? "on" : "off", + pi.flags & FLAG_VF_MULTICAST_PROMISC ? "on" : "off"); + return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, &pi, sizeof (virtchnl_promisc_info_t), 0, 0); } @@ -582,6 +657,9 @@ avf_op_config_vsi_queues (vlib_main_t * vm, avf_device_t * ad) ci->vsi_id = ad->vsi_id; ci->num_queue_pairs = n_qp; + avf_log_debug (ad, "config_vsi_queues: vsi_id %u num_queue_pairs %u", + ad->vsi_id, ci->num_queue_pairs); + for (i = 0; i < n_qp; i++) { virtchnl_txq_info_t *txq = &ci->qpair[i].txq; @@ -594,19 +672,26 @@ avf_op_config_vsi_queues (vlib_main_t * vm, avf_device_t * ad) { avf_rxq_t *q = vec_elt_at_index (ad->rxqs, i); rxq->ring_len = q->size; - rxq->databuffer_size = VLIB_BUFFER_DATA_SIZE; + rxq->databuffer_size = vlib_buffer_get_default_data_size (vm); rxq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs); avf_reg_write (ad, AVF_QRX_TAIL (i), q->size - 1); } + avf_log_debug (ad, "config_vsi_queues_rx[%u]: max_pkt_size %u " + "ring_len %u databuffer_size %u dma_ring_addr 0x%llx", + i, rxq->max_pkt_size, rxq->ring_len, + rxq->databuffer_size, rxq->dma_ring_addr); - avf_txq_t *q = vec_elt_at_index (ad->txqs, i); txq->vsi_id = ad->vsi_id; + txq->queue_id = i; if (i < vec_len (ad->txqs)) { - txq->queue_id = i; + avf_txq_t *q = vec_elt_at_index (ad->txqs, i); txq->ring_len = q->size; txq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs); } + avf_log_debug (ad, "config_vsi_queues_tx[%u]: ring_len %u " + "dma_ring_addr 0x%llx", i, txq->ring_len, + txq->dma_ring_addr); } return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_VSI_QUEUES, msg, msg_len, @@ -616,19 +701,30 @@ avf_op_config_vsi_queues (vlib_main_t * vm, avf_device_t * ad) 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);; + + 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); + } + - imi->vecmap[0].vector_id = 1; - imi->vecmap[0].vsi_id = ad->vsi_id; - imi->vecmap[0].rxq_map = 1; return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0, 0); } @@ -647,8 +743,16 @@ avf_op_add_eth_addr (vlib_main_t * vm, avf_device_t * ad, u8 count, u8 * macs) al = (virtchnl_ether_addr_list_t *) msg; 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); + for (i = 0; i < count; i++) - clib_memcpy_fast (&al->list[i].addr, macs + i * 6, 6); + { + clib_memcpy_fast (&al->list[i].addr, macs + i * 6, 6); + avf_log_debug (ad, "add_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); } @@ -661,6 +765,10 @@ avf_op_enable_queues (vlib_main_t * vm, avf_device_t * ad, u32 rx, u32 tx) qs.vsi_id = ad->vsi_id; qs.rx_queues = rx; qs.tx_queues = tx; + + avf_log_debug (ad, "enable_queues: vsi_id %u rx_queues %u tx_queues %u", + ad->vsi_id, qs.rx_queues, qs.tx_queues); + while (rx) { if (rx & (1 << i)) @@ -681,6 +789,9 @@ avf_op_get_stats (vlib_main_t * vm, avf_device_t * ad, { virtchnl_queue_select_t qs = { 0 }; qs.vsi_id = ad->vsi_id; + + avf_log_debug (ad, "get_stats: vsi_id %u", ad->vsi_id); + return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_STATS, &qs, sizeof (virtchnl_queue_select_t), es, sizeof (virtchnl_eth_stats_t)); @@ -692,23 +803,35 @@ avf_device_reset (vlib_main_t * vm, avf_device_t * ad) avf_aq_desc_t d = { 0 }; clib_error_t *error; u32 rstat; - int n_retry = 20; + f64 t0, t = 0, suspend_time = AVF_RESET_SUSPEND_TIME; + + avf_log_debug (ad, "reset"); d.opcode = 0x801; d.v_opcode = VIRTCHNL_OP_RESET_VF; if ((error = avf_aq_desc_enq (vm, ad, &d, 0, 0))) return error; + t0 = vlib_time_now (vm); retry: - vlib_process_suspend (vm, 10e-3); + vlib_process_suspend (vm, suspend_time); + rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT); if (rstat == 2 || rstat == 3) - return 0; + { + avf_log_debug (ad, "reset completed in %.3fs", t); + return 0; + } - if (--n_retry == 0) - return clib_error_return (0, "reset failed (timeout)"); + t = vlib_time_now (vm) - t0; + if (t > AVF_RESET_MAX_WAIT_TIME) + { + avf_log_err (ad, "reset failed (timeout %.3fs)", t); + return clib_error_return (0, "reset failed (timeout)"); + } + suspend_time *= 2; goto retry; } @@ -718,16 +841,18 @@ avf_request_queues (vlib_main_t * vm, avf_device_t * ad, u16 num_queue_pairs) virtchnl_vf_res_request_t res_req = { 0 }; clib_error_t *error; u32 rstat; - int n_retry = 20; + f64 t0, t, suspend_time = AVF_RESET_SUSPEND_TIME; res_req.num_queue_pairs = num_queue_pairs; + avf_log_debug (ad, "request_queues: num_queue_pairs %u", num_queue_pairs); + error = avf_send_to_pf (vm, ad, VIRTCHNL_OP_REQUEST_QUEUES, &res_req, sizeof (virtchnl_vf_res_request_t), &res_req, sizeof (virtchnl_vf_res_request_t)); /* - * if PF respondes, the request failed + * if PF responds, the request failed * else PF initializes restart and avf_send_to_pf returns an error */ if (!error) @@ -736,16 +861,23 @@ avf_request_queues (vlib_main_t * vm, avf_device_t * ad, u16 num_queue_pairs) res_req.num_queue_pairs); } + t0 = vlib_time_now (vm); retry: - vlib_process_suspend (vm, 10e-3); + vlib_process_suspend (vm, suspend_time); + t = vlib_time_now (vm) - t0; + rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT); if ((rstat == VIRTCHNL_VFR_COMPLETED) || (rstat == VIRTCHNL_VFR_VFACTIVE)) goto done; - if (--n_retry == 0) - return clib_error_return (0, "reset failed (timeout)"); + if (t > AVF_RESET_MAX_WAIT_TIME) + { + avf_log_err (ad, "request queues failed (timeout %.3f seconds)", t); + return clib_error_return (0, "request queues failed (timeout)"); + } + suspend_time *= 2; goto retry; done: @@ -760,12 +892,12 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, 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); - /* request more queues only if we need them */ - if ((error = avf_request_queues (vm, ad, tm->n_vlib_mains))) + if ((error = avf_request_queues (vm, ad, clib_max (tm->n_vlib_mains, + args->rxq_num)))) { /* we failed to get more queues, but still we want to proceed */ clib_error_free (error); @@ -788,7 +920,7 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, "(remote %d.%d)", ver.major, ver.minor); /* - * OP_GET_VF_RESOUCES + * OP_GET_VF_RESOURCES */ if ((error = avf_op_get_vf_resources (vm, ad, &res))) return error; @@ -803,6 +935,7 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * 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); @@ -812,9 +945,6 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, if ((error = avf_op_disable_vlan_stripping (vm, ad))) return error; - if ((error = avf_config_promisc_mode (vm, ad))) - return error; - /* * Init Queues */ @@ -825,9 +955,8 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, else if (args->rxq_num > ad->num_queue_pairs) { args->rxq_num = ad->num_queue_pairs; - vlib_log_warn (am->log_class, "Requested more rx queues than" - "queue pairs available. Using %u rx queues.", - args->rxq_num); + avf_log_warn (ad, "Requested more rx queues than queue pairs available." + "Using %u rx queues.", args->rxq_num); } for (i = 0; i < args->rxq_num; i++) @@ -838,6 +967,15 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, 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; @@ -852,9 +990,11 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad, 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; @@ -892,6 +1032,7 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) if ((r & 0xf0000000) != (1ULL << 31)) { ad->error = clib_error_return (0, "arq not enabled, arqlen = 0x%x", r); + avf_log_err (ad, "error: %U", format_clib_error, ad->error); goto error; } @@ -899,6 +1040,7 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) if ((r & 0xf0000000) != (1ULL << 31)) { ad->error = clib_error_return (0, "atq not enabled, atqlen = 0x%x", r); + avf_log_err (ad, "error: %U", format_clib_error, ad->error); goto error; } @@ -908,31 +1050,49 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) /* *INDENT-OFF* */ vec_foreach (e, ad->events) { + avf_log_debug (ad, "event: %s (%u) sev %d", + virtchnl_event_names[e->event], e->event, e->severity); if (e->event == VIRTCHNL_EVENT_LINK_CHANGE) { - int link_up = e->event_data.link_event.link_status; + int link_up; virtchnl_link_speed_t speed = e->event_data.link_event.link_speed; u32 flags = 0; - u32 kbps = 0; + u32 mbps = 0; + + if (ad->feature_bitmap & 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) + mbps = e->event_data.link_event_adv.link_speed; + if (speed == VIRTCHNL_LINK_SPEED_40GB) + mbps = 40000; + else if (speed == VIRTCHNL_LINK_SPEED_25GB) + mbps = 25000; + else if (speed == VIRTCHNL_LINK_SPEED_10GB) + mbps = 10000; + else if (speed == VIRTCHNL_LINK_SPEED_5GB) + mbps = 5000; + else if (speed == VIRTCHNL_LINK_SPEED_2_5GB) + mbps = 2500; + else if (speed == VIRTCHNL_LINK_SPEED_1GB) + mbps = 1000; + else if (speed == VIRTCHNL_LINK_SPEED_100MB) + mbps = 100; + + avf_log_debug (ad, "event_link_change: status %d speed %u mbps", + link_up, mbps); if (link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) == 0) { ad->flags |= AVF_DEVICE_F_LINK_UP; flags |= (VNET_HW_INTERFACE_FLAG_FULL_DUPLEX | VNET_HW_INTERFACE_FLAG_LINK_UP); - if (speed == VIRTCHNL_LINK_SPEED_40GB) - kbps = 40000000; - else if (speed == VIRTCHNL_LINK_SPEED_25GB) - kbps = 25000000; - else if (speed == VIRTCHNL_LINK_SPEED_10GB) - kbps = 10000000; - else if (speed == VIRTCHNL_LINK_SPEED_1GB) - kbps = 1000000; - else if (speed == VIRTCHNL_LINK_SPEED_100MB) - kbps = 100000; vnet_hw_interface_set_flags (vnm, ad->hw_if_index, flags); - vnet_hw_interface_set_link_speed (vnm, ad->hw_if_index, kbps); - ad->link_speed = speed; + vnet_hw_interface_set_link_speed (vnm, ad->hw_if_index, + mbps * 1000); + ad->link_speed = mbps; } else if (!link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) != 0) { @@ -945,19 +1105,19 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) ELOG_TYPE_DECLARE (el) = { .format = "avf[%d] link change: link_status %d " - "link_speed %d", - .format_args = "i4i1i1", + "link_speed %d mbps", + .format_args = "i4i1i4", }; struct { u32 dev_instance; u8 link_status; - u8 link_speed; + 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 = speed; + ed->link_speed = mbps; } } else @@ -996,8 +1156,32 @@ error: static u32 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; - vlib_log_warn (am->log_class, "TODO"); + avf_device_t *ad = vec_elt_at_index (am->devices, hw->dev_instance); + clib_error_t *error; + u8 promisc_enabled; + + 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; + } + + promisc_enabled = ((ad->flags & AVF_DEVICE_F_PROMISC) != 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; + } + return 0; } @@ -1019,7 +1203,6 @@ avf_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) 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) @@ -1030,9 +1213,15 @@ avf_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) 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++) + { + ad = pool_elt_at_index (am->devices, 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; @@ -1040,6 +1229,11 @@ avf_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) ASSERT (0); } + vec_reset_length (event_data); + + if (enabled == 0) + continue; + /* *INDENT-OFF* */ pool_foreach (ad, am->devices, { @@ -1052,7 +1246,7 @@ avf_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) } /* *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", @@ -1089,7 +1283,7 @@ avf_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line) 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)) @@ -1104,8 +1298,6 @@ avf_irq_n_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); - u16 qid; - int i; if (ad->flags & AVF_DEVICE_F_ELOG) { @@ -1127,25 +1319,31 @@ avf_irq_n_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line) 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); @@ -1233,6 +1431,7 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args) return; } ad->pci_dev_handle = h; + ad->pci_addr = args->addr; ad->numa_node = vlib_pci_get_numa_node (vm, h); vlib_pci_set_private_data (vm, h, ad->dev_instance); @@ -1243,17 +1442,6 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args) 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, @@ -1306,15 +1494,26 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args) 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, @@ -1323,6 +1522,13 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args) 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; @@ -1341,11 +1547,11 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args) 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); - vlib_log_err (am->log_class, "%U", format_clib_error, args->error); + avf_log_err (ad, "error: %U", format_clib_error, args->error); } static clib_error_t * @@ -1383,9 +1589,24 @@ avf_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid, 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; } @@ -1415,10 +1636,20 @@ static char *avf_tx_func_error_strings[] = { #undef _ }; +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); + clib_memcpy_fast (&ad->last_cleared_eth_stats, + &ad->eth_stats, sizeof (ad->eth_stats)); +} + /* *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, .format_device_name = format_avf_device_name, .admin_up_down_function = avf_interface_admin_up_down, @@ -1433,22 +1664,23 @@ clib_error_t * avf_init (vlib_main_t * vm) { avf_main_t *am = &avf_main; - clib_error_t *error; vlib_thread_main_t *tm = vlib_get_thread_main (); - if ((error = vlib_call_init_function (vm, pci_bus_init))) - return error; - vec_validate_aligned (am->per_thread_data, tm->n_vlib_mains - 1, CLIB_CACHE_LINE_BYTES); - am->log_class = vlib_log_register_class ("avf_plugin", 0); + am->log_class = vlib_log_register_class ("avf", 0); vlib_log_debug (am->log_class, "initialized"); return 0; } -VLIB_INIT_FUNCTION (avf_init); +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (avf_init) = +{ + .runs_after = VLIB_INITS ("pci_bus_init"), +}; +/* *INDENT-OFF* */ /* * fd.io coding-style-patch-verification: ON