FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
device.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vppinfra/ring.h>
20 #include <vlib/unix/unix.h>
21 #include <vlib/pci/pci.h>
22 #include <vnet/ethernet/ethernet.h>
23 
24 #include <avf/avf.h>
25 
26 #define AVF_MBOX_LEN 64
27 #define AVF_MBOX_BUF_SZ 512
28 #define AVF_RXQ_SZ 512
29 #define AVF_TXQ_SZ 512
30 #define AVF_ITR_INT 32
31 
32 #define PCI_VENDOR_ID_INTEL 0x8086
33 #define PCI_DEVICE_ID_INTEL_AVF 0x1889
34 #define PCI_DEVICE_ID_INTEL_X710_VF 0x154c
35 #define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd
36 
38 
39 static pci_device_id_t avf_pci_device_ids[] = {
41  {.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_X710_VF},
42  {.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_X722_VF},
43  {0},
44 };
45 
46 const static char *virtchnl_event_names[] = {
47 #define _(v, n) [v] = #n,
49 #undef _
50 };
51 
52 const static char *virtchnl_link_speed_str[] = {
53 #define _(v, n, s) [v] = s,
55 #undef _
56 };
57 
58 static inline void
60 {
61  u32 dyn_ctl0 = 0, icr0_ena = 0;
62 
63  dyn_ctl0 |= (3 << 3); /* 11b = No ITR update */
64 
65  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
66  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
67  avf_reg_flush (ad);
68 }
69 
70 static inline void
72 {
73  u32 dyn_ctl0 = 0, icr0_ena = 0;
74 
75  icr0_ena |= (1 << 30); /* [30] Admin Queue Enable */
76 
77  dyn_ctl0 |= (1 << 0); /* [0] Interrupt Enable */
78  dyn_ctl0 |= (1 << 1); /* [1] Clear PBA */
79  //dyn_ctl0 |= (3 << 3); /* [4:3] ITR Index, 11b = No ITR update */
80  dyn_ctl0 |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
81 
82  avf_irq_0_disable (ad);
83  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
84  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
85  avf_reg_flush (ad);
86 }
87 
88 static inline void
90 {
91  u32 dyn_ctln = 0;
92 
93  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
94  avf_reg_flush (ad);
95 }
96 
97 static inline void
99 {
100  u32 dyn_ctln = 0;
101 
102  dyn_ctln |= (1 << 0); /* [0] Interrupt Enable */
103  dyn_ctln |= (1 << 1); /* [1] Clear PBA */
104  dyn_ctln |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
105 
106  avf_irq_n_disable (ad, line);
107  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
108  avf_reg_flush (ad);
109 }
110 
111 
112 clib_error_t *
114  void *data, int len)
115 {
116  clib_error_t *err = 0;
117  avf_aq_desc_t *d, dc;
118  f64 t0, suspend_time = AVF_AQ_ENQ_SUSPEND_TIME;
119 
120  d = &ad->atq[ad->atq_next_slot];
121  clib_memcpy_fast (d, dt, sizeof (avf_aq_desc_t));
122  d->flags |= AVF_AQ_F_RD | AVF_AQ_F_SI;
123  if (len)
124  d->datalen = len;
125  if (len)
126  {
127  u64 pa;
128  pa = ad->atq_bufs_pa + ad->atq_next_slot * AVF_MBOX_BUF_SZ;
129  d->addr_hi = (u32) (pa >> 32);
130  d->addr_lo = (u32) pa;
132  data, len);
133  d->flags |= AVF_AQ_F_BUF;
134  }
135 
136  if (ad->flags & AVF_DEVICE_F_ELOG)
137  clib_memcpy_fast (&dc, d, sizeof (avf_aq_desc_t));
138 
140  ad->atq_next_slot = (ad->atq_next_slot + 1) % AVF_MBOX_LEN;
142  avf_reg_flush (ad);
143 
144  t0 = vlib_time_now (vm);
145 retry:
146  vlib_process_suspend (vm, suspend_time);
147 
148  if (((d->flags & AVF_AQ_F_DD) == 0) || ((d->flags & AVF_AQ_F_CMP) == 0))
149  {
150  f64 t = vlib_time_now (vm) - t0;
151  if (t > AVF_AQ_ENQ_MAX_WAIT_TIME)
152  {
153  avf_log_err (ad, "aq_desc_enq failed (timeout %.3fs)", t);
154  err = clib_error_return (0, "adminq enqueue timeout [opcode 0x%x]",
155  d->opcode);
156  goto done;
157  }
158  suspend_time *= 2;
159  goto retry;
160  }
161 
162  clib_memcpy_fast (dt, d, sizeof (avf_aq_desc_t));
163  if (d->flags & AVF_AQ_F_ERR)
164  return clib_error_return (0, "adminq enqueue error [opcode 0x%x, retval "
165  "%d]", d->opcode, d->retval);
166 
167 done:
168  if (ad->flags & AVF_DEVICE_F_ELOG)
169  {
170  /* *INDENT-OFF* */
171  ELOG_TYPE_DECLARE (el) =
172  {
173  .format = "avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x "
174  "datalen %d retval %d",
175  .format_args = "i4i2i2i2i2i2",
176  };
177  struct
178  {
179  u32 dev_instance;
180  u16 s_flags;
181  u16 r_flags;
182  u16 opcode;
183  u16 datalen;
184  u16 retval;
185  } *ed;
186  ed = ELOG_DATA (&vm->elog_main, el);
187  ed->dev_instance = ad->dev_instance;
188  ed->s_flags = dc.flags;
189  ed->r_flags = d->flags;
190  ed->opcode = dc.opcode;
191  ed->datalen = dc.datalen;
192  ed->retval = d->retval;
193  /* *INDENT-ON* */
194  }
195 
196  return err;
197 }
198 
199 clib_error_t *
201  u32 val)
202 {
203  clib_error_t *err;
204  avf_aq_desc_t d = {.opcode = 0x207,.param1 = reg,.param3 = val };
205  err = avf_aq_desc_enq (vm, ad, &d, 0, 0);
206 
207  if (ad->flags & AVF_DEVICE_F_ELOG)
208  {
209  /* *INDENT-OFF* */
210  ELOG_TYPE_DECLARE (el) =
211  {
212  .format = "avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
213  .format_args = "i4i4i4",
214  };
215  struct
216  {
217  u32 dev_instance;
218  u32 reg;
219  u32 val;
220  } *ed;
221  ed = ELOG_DATA (&vm->elog_main, el);
222  ed->dev_instance = ad->dev_instance;
223  ed->reg = reg;
224  ed->val = val;
225  /* *INDENT-ON* */
226  }
227  return err;
228 }
229 
230 clib_error_t *
231 avf_rxq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 rxq_size)
232 {
233  clib_error_t *err;
234  avf_rxq_t *rxq;
235  u32 n_alloc, i;
236 
238  rxq = vec_elt_at_index (ad->rxqs, qid);
239  rxq->size = rxq_size;
240  rxq->next = 0;
242  sizeof (avf_rx_desc_t),
244  ad->numa_node);
245 
246  rxq->buffer_pool_index =
248 
249  if (rxq->descs == 0)
250  return vlib_physmem_last_error (vm);
251 
252  if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) rxq->descs)))
253  return err;
254 
255  clib_memset ((void *) rxq->descs, 0, rxq->size * sizeof (avf_rx_desc_t));
257  rxq->qrx_tail = ad->bar0 + AVF_QRX_TAIL (qid);
258 
259  n_alloc = vlib_buffer_alloc_from_pool (vm, rxq->bufs, rxq->size - 8,
260  rxq->buffer_pool_index);
261 
262  if (n_alloc == 0)
263  return clib_error_return (0, "buffer allocation error");
264 
265  rxq->n_enqueued = n_alloc;
266  avf_rx_desc_t *d = rxq->descs;
267  for (i = 0; i < n_alloc; i++)
268  {
269  vlib_buffer_t *b = vlib_get_buffer (vm, rxq->bufs[i]);
270  if (ad->flags & AVF_DEVICE_F_VA_DMA)
271  d->qword[0] = vlib_buffer_get_va (b);
272  else
273  d->qword[0] = vlib_buffer_get_pa (vm, b);
274  d++;
275  }
276 
277  ad->n_rx_queues = clib_min (ad->num_queue_pairs, qid + 1);
278  return 0;
279 }
280 
281 clib_error_t *
282 avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
283 {
284  clib_error_t *err;
285  avf_txq_t *txq;
286 
287  if (qid >= ad->num_queue_pairs)
288  {
289  qid = qid % ad->num_queue_pairs;
290  txq = vec_elt_at_index (ad->txqs, qid);
291  if (txq->lock == 0)
292  clib_spinlock_init (&txq->lock);
293  ad->flags |= AVF_DEVICE_F_SHARED_TXQ_LOCK;
294  return 0;
295  }
296 
298  txq = vec_elt_at_index (ad->txqs, qid);
299  txq->size = txq_size;
300  txq->next = 0;
302  sizeof (avf_tx_desc_t),
304  ad->numa_node);
305  if (txq->descs == 0)
306  return vlib_physmem_last_error (vm);
307 
308  if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) txq->descs)))
309  return err;
310 
312  txq->qtx_tail = ad->bar0 + AVF_QTX_TAIL (qid);
313 
314  /* initialize ring of pending RS slots */
316 
317  ad->n_tx_queues = clib_min (ad->num_queue_pairs, qid + 1);
318  return 0;
319 }
320 
321 typedef struct
322 {
326 
327 void
329 {
330  avf_aq_desc_t *d;
331  u64 pa = ad->arq_bufs_pa + slot * AVF_MBOX_BUF_SZ;
332  d = &ad->arq[slot];
333  clib_memset (d, 0, sizeof (avf_aq_desc_t));
334  d->flags = AVF_AQ_F_BUF;
336  d->addr_hi = (u32) (pa >> 32);
337  d->addr_lo = (u32) pa;
338 }
339 
340 static inline uword
342 {
343  return (ad->flags & AVF_DEVICE_F_VA_DMA) ?
345 }
346 
347 static void
349 {
350  u64 pa;
351  int i;
352 
353  /* VF MailBox Transmit */
354  clib_memset (ad->atq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
355  ad->atq_bufs_pa = avf_dma_addr (vm, ad, ad->atq_bufs);
356 
357  pa = avf_dma_addr (vm, ad, ad->atq);
358  avf_reg_write (ad, AVF_ATQT, 0); /* Tail */
359  avf_reg_write (ad, AVF_ATQH, 0); /* Head */
360  avf_reg_write (ad, AVF_ATQLEN, AVF_MBOX_LEN | (1ULL << 31)); /* len & ena */
361  avf_reg_write (ad, AVF_ATQBAL, (u32) pa); /* Base Address Low */
362  avf_reg_write (ad, AVF_ATQBAH, (u32) (pa >> 32)); /* Base Address High */
363 
364  /* VF MailBox Receive */
365  clib_memset (ad->arq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
366  ad->arq_bufs_pa = avf_dma_addr (vm, ad, ad->arq_bufs);
367 
368  for (i = 0; i < AVF_MBOX_LEN; i++)
369  avf_arq_slot_init (ad, i);
370 
371  pa = avf_dma_addr (vm, ad, ad->arq);
372 
373  avf_reg_write (ad, AVF_ARQH, 0); /* Head */
374  avf_reg_write (ad, AVF_ARQT, 0); /* Head */
375  avf_reg_write (ad, AVF_ARQLEN, AVF_MBOX_LEN | (1ULL << 31)); /* len & ena */
376  avf_reg_write (ad, AVF_ARQBAL, (u32) pa); /* Base Address Low */
377  avf_reg_write (ad, AVF_ARQBAH, (u32) (pa >> 32)); /* Base Address High */
378  avf_reg_write (ad, AVF_ARQT, AVF_MBOX_LEN - 1); /* Tail */
379 
380  ad->atq_next_slot = 0;
381  ad->arq_next_slot = 0;
382 }
383 
384 clib_error_t *
386  void *in, int in_len, void *out, int out_len)
387 {
388  clib_error_t *err;
389  avf_aq_desc_t *d, dt = {.opcode = 0x801,.v_opcode = op };
390  u32 head;
391  f64 t0, suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME;
392 
393  /* suppress interrupt in the next adminq receive slot
394  as we are going to wait for response
395  we only need interrupts when event is received */
396  d = &ad->arq[ad->arq_next_slot];
397  d->flags |= AVF_AQ_F_SI;
398 
399  if ((err = avf_aq_desc_enq (vm, ad, &dt, in, in_len)))
400  return err;
401 
402  t0 = vlib_time_now (vm);
403 retry:
404  head = avf_get_u32 (ad->bar0, AVF_ARQH);
405 
406  if (ad->arq_next_slot == head)
407  {
408  f64 t = vlib_time_now (vm) - t0;
410  {
411  avf_log_err (ad, "send_to_pf failed (timeout %.3fs)", t);
412  return clib_error_return (0, "timeout");
413  }
414  vlib_process_suspend (vm, suspend_time);
415  suspend_time *= 2;
416  goto retry;
417  }
418 
419  d = &ad->arq[ad->arq_next_slot];
420 
421  if (d->v_opcode == VIRTCHNL_OP_EVENT)
422  {
423  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
425 
426  if ((d->datalen != sizeof (virtchnl_pf_event_t)) ||
427  ((d->flags & AVF_AQ_F_BUF) == 0))
428  return clib_error_return (0, "event message error");
429 
430  vec_add2 (ad->events, e, 1);
431  clib_memcpy_fast (e, buf, sizeof (virtchnl_pf_event_t));
433  ad->arq_next_slot++;
434  /* reset timer */
435  t0 = vlib_time_now (vm);
436  suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME;
437  goto retry;
438  }
439 
440  if (d->v_opcode != op)
441  {
442  err =
444  "unexpected message receiver [v_opcode = %u, "
445  "expected %u, v_retval %d]", d->v_opcode, op,
446  d->v_retval);
447  goto done;
448  }
449 
450  if (d->v_retval)
451  {
452  err = clib_error_return (0, "error [v_opcode = %u, v_retval %d]",
453  d->v_opcode, d->v_retval);
454  goto done;
455  }
456 
457  if (d->flags & AVF_AQ_F_BUF)
458  {
459  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
460  clib_memcpy_fast (out, buf, out_len);
461  }
462 
465  avf_reg_flush (ad);
466  ad->arq_next_slot = (ad->arq_next_slot + 1) % AVF_MBOX_LEN;
467 
468 done:
469 
470  if (ad->flags & AVF_DEVICE_F_ELOG)
471  {
472  /* *INDENT-OFF* */
473  ELOG_TYPE_DECLARE (el) =
474  {
475  .format = "avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
476  .format_args = "i4t4i4i4",
477  .n_enum_strings = VIRTCHNL_N_OPS,
478  .enum_strings = {
479 #define _(v, n) [v] = #n,
481 #undef _
482  },
483  };
484  struct
485  {
486  u32 dev_instance;
487  u32 v_opcode;
488  u32 v_opcode_val;
489  u32 v_retval;
490  } *ed;
491  ed = ELOG_DATA (&vm->elog_main, el);
492  ed->dev_instance = ad->dev_instance;
493  ed->v_opcode = op;
494  ed->v_opcode_val = op;
495  ed->v_retval = d->v_retval;
496  /* *INDENT-ON* */
497  }
498  return err;
499 }
500 
501 clib_error_t *
504 {
505  clib_error_t *err = 0;
506  virtchnl_version_info_t myver = {
508  .minor = VIRTCHNL_VERSION_MINOR,
509  };
510 
511  avf_log_debug (ad, "version: major %u minor %u", myver.major, myver.minor);
512 
513  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_VERSION, &myver,
514  sizeof (virtchnl_version_info_t), ver,
515  sizeof (virtchnl_version_info_t));
516 
517  if (err)
518  return err;
519 
520  return err;
521 }
522 
523 clib_error_t *
526 {
527  clib_error_t *err = 0;
528  u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
529  VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
530  VIRTCHNL_VF_OFFLOAD_RX_POLLING);
531 
532  avf_log_debug (ad, "get_vf_reqources: bitmap 0x%x", bitmap);
533  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
534  sizeof (u32), res, sizeof (virtchnl_vf_resource_t));
535 
536  if (err == 0)
537  {
538  int i;
539  avf_log_debug (ad, "get_vf_reqources: num_vsis %u num_queue_pairs %u "
540  "max_vectors %u max_mtu %u vf_offload_flags 0x%04x "
541  "rss_key_size %u rss_lut_size %u",
542  res->num_vsis, res->num_queue_pairs, res->max_vectors,
543  res->max_mtu, res->vf_offload_flags, res->rss_key_size,
544  res->rss_lut_size);
545  for (i = 0; i < res->num_vsis; i++)
546  avf_log_debug (ad, "get_vf_reqources_vsi[%u]: vsi_id %u "
547  "num_queue_pairs %u vsi_type %u qset_handle %u "
548  "default_mac_addr %U", i,
549  res->vsi_res[i].vsi_id,
550  res->vsi_res[i].num_queue_pairs,
551  res->vsi_res[i].vsi_type,
552  res->vsi_res[i].qset_handle,
554  res->vsi_res[i].default_mac_addr);
555  }
556 
557  return err;
558 }
559 
560 clib_error_t *
562 {
563  int msg_len = sizeof (virtchnl_rss_lut_t) + ad->rss_lut_size - 1;
564  int i;
565  u8 msg[msg_len];
566  virtchnl_rss_lut_t *rl;
567 
568  clib_memset (msg, 0, msg_len);
569  rl = (virtchnl_rss_lut_t *) msg;
570  rl->vsi_id = ad->vsi_id;
571  rl->lut_entries = ad->rss_lut_size;
572  for (i = 0; i < ad->rss_lut_size; i++)
573  rl->lut[i] = i % ad->n_rx_queues;
574 
575  avf_log_debug (ad, "config_rss_lut: vsi_id %u rss_lut_size %u lut 0x%U",
576  rl->vsi_id, rl->lut_entries, format_hex_bytes_no_wrap,
577  rl->lut, rl->lut_entries);
578 
579  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_LUT, msg, msg_len, 0,
580  0);
581 }
582 
583 clib_error_t *
585 {
586  int msg_len = sizeof (virtchnl_rss_key_t) + ad->rss_key_size - 1;
587  int i;
588  u8 msg[msg_len];
589  virtchnl_rss_key_t *rk;
590 
591  clib_memset (msg, 0, msg_len);
592  rk = (virtchnl_rss_key_t *) msg;
593  rk->vsi_id = ad->vsi_id;
594  rk->key_len = ad->rss_key_size;
595  u32 seed = random_default_seed ();
596  for (i = 0; i < ad->rss_key_size; i++)
597  rk->key[i] = (u8) random_u32 (&seed);
598 
599  avf_log_debug (ad, "config_rss_key: vsi_id %u rss_key_size %u key 0x%U",
600  rk->vsi_id, rk->key_len, format_hex_bytes_no_wrap, rk->key,
601  rk->key_len);
602 
603  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_KEY, msg, msg_len, 0,
604  0);
605 }
606 
607 clib_error_t *
609 {
610  avf_log_debug (ad, "disable_vlan_stripping");
611 
612  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 0, 0, 0,
613  0);
614 }
615 
616 clib_error_t *
618 {
619  virtchnl_promisc_info_t pi = { 0 };
620 
621  pi.vsi_id = ad->vsi_id;
622 
623  if (is_enable)
624  pi.flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC;
625 
626  avf_log_debug (ad, "config_promisc_mode: unicast %s multicast %s",
627  pi.flags & FLAG_VF_UNICAST_PROMISC ? "on" : "off",
628  pi.flags & FLAG_VF_MULTICAST_PROMISC ? "on" : "off");
629 
630  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, &pi,
631  sizeof (virtchnl_promisc_info_t), 0, 0);
632 }
633 
634 
635 clib_error_t *
637 {
638  int i;
639  int n_qp = clib_max (vec_len (ad->rxqs), vec_len (ad->txqs));
640  int msg_len = sizeof (virtchnl_vsi_queue_config_info_t) + n_qp *
642  u8 msg[msg_len];
644 
645  clib_memset (msg, 0, msg_len);
647  ci->vsi_id = ad->vsi_id;
648  ci->num_queue_pairs = n_qp;
649 
650  avf_log_debug (ad, "config_vsi_queues: vsi_id %u num_queue_pairs %u",
651  ad->vsi_id, ci->num_queue_pairs);
652 
653  for (i = 0; i < n_qp; i++)
654  {
655  virtchnl_txq_info_t *txq = &ci->qpair[i].txq;
656  virtchnl_rxq_info_t *rxq = &ci->qpair[i].rxq;
657 
658  rxq->vsi_id = ad->vsi_id;
659  rxq->queue_id = i;
661  if (i < vec_len (ad->rxqs))
662  {
663  avf_rxq_t *q = vec_elt_at_index (ad->rxqs, i);
664  rxq->ring_len = q->size;
666  rxq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs);
667  avf_reg_write (ad, AVF_QRX_TAIL (i), q->size - 1);
668  }
669  avf_log_debug (ad, "config_vsi_queues_rx[%u]: max_pkt_size %u "
670  "ring_len %u databuffer_size %u dma_ring_addr 0x%llx",
671  i, rxq->max_pkt_size, rxq->ring_len,
672  rxq->databuffer_size, rxq->dma_ring_addr);
673 
674  txq->vsi_id = ad->vsi_id;
675  txq->queue_id = i;
676  if (i < vec_len (ad->txqs))
677  {
678  avf_txq_t *q = vec_elt_at_index (ad->txqs, i);
679  txq->ring_len = q->size;
680  txq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs);
681  }
682  avf_log_debug (ad, "config_vsi_queues_tx[%u]: ring_len %u "
683  "dma_ring_addr 0x%llx", i, txq->ring_len,
684  txq->dma_ring_addr);
685  }
686 
687  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_VSI_QUEUES, msg, msg_len,
688  0, 0);
689 }
690 
691 clib_error_t *
693 {
694  int count = 1;
695  int msg_len = sizeof (virtchnl_irq_map_info_t) +
696  count * sizeof (virtchnl_vector_map_t);
697  u8 msg[msg_len];
699 
700  clib_memset (msg, 0, msg_len);
701  imi = (virtchnl_irq_map_info_t *) msg;
702  imi->num_vectors = count;
703 
704  imi->vecmap[0].vector_id = 1;
705  imi->vecmap[0].vsi_id = ad->vsi_id;
706  imi->vecmap[0].rxq_map = (1 << ad->n_rx_queues) - 1;
707  imi->vecmap[0].txq_map = (1 << ad->n_tx_queues) - 1;
708 
709  avf_log_debug (ad, "config_irq_map: vsi_id %u vector_id %u rxq_map %u",
710  ad->vsi_id, imi->vecmap[0].vector_id,
711  imi->vecmap[0].rxq_map);
712 
713  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0,
714  0);
715 }
716 
717 clib_error_t *
719 {
720  int msg_len =
721  sizeof (virtchnl_ether_addr_list_t) +
722  count * sizeof (virtchnl_ether_addr_t);
723  u8 msg[msg_len];
725  int i;
726 
727  clib_memset (msg, 0, msg_len);
728  al = (virtchnl_ether_addr_list_t *) msg;
729  al->vsi_id = ad->vsi_id;
730  al->num_elements = count;
731 
732  avf_log_debug (ad, "add_eth_addr: vsi_id %u num_elements %u",
733  ad->vsi_id, al->num_elements);
734 
735  for (i = 0; i < count; i++)
736  {
737  clib_memcpy_fast (&al->list[i].addr, macs + i * 6, 6);
738  avf_log_debug (ad, "add_eth_addr[%u]: %U", i,
740  }
741  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ADD_ETH_ADDR, msg, msg_len, 0,
742  0);
743 }
744 
745 clib_error_t *
747 {
748  virtchnl_queue_select_t qs = { 0 };
749  int i = 0;
750  qs.vsi_id = ad->vsi_id;
751  qs.rx_queues = rx;
752  qs.tx_queues = tx;
753 
754  avf_log_debug (ad, "enable_queues: vsi_id %u rx_queues %u tx_queues %u",
755  ad->vsi_id, qs.rx_queues, qs.tx_queues);
756 
757  while (rx)
758  {
759  if (rx & (1 << i))
760  {
761  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
762  avf_reg_write (ad, AVF_QRX_TAIL (i), rxq->n_enqueued);
763  rx &= ~(1 << i);
764  }
765  i++;
766  }
767  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ENABLE_QUEUES, &qs,
768  sizeof (virtchnl_queue_select_t), 0, 0);
769 }
770 
771 clib_error_t *
774 {
775  virtchnl_queue_select_t qs = { 0 };
776  qs.vsi_id = ad->vsi_id;
777 
778  avf_log_debug (ad, "get_stats: vsi_id %u", ad->vsi_id);
779 
780  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_STATS,
781  &qs, sizeof (virtchnl_queue_select_t),
782  es, sizeof (virtchnl_eth_stats_t));
783 }
784 
785 clib_error_t *
787 {
788  avf_aq_desc_t d = { 0 };
789  clib_error_t *error;
790  u32 rstat;
791  f64 t0, t = 0, suspend_time = AVF_RESET_SUSPEND_TIME;
792 
793  avf_log_debug (ad, "reset");
794 
795  d.opcode = 0x801;
796  d.v_opcode = VIRTCHNL_OP_RESET_VF;
797  if ((error = avf_aq_desc_enq (vm, ad, &d, 0, 0)))
798  return error;
799 
800  t0 = vlib_time_now (vm);
801 retry:
802  vlib_process_suspend (vm, suspend_time);
803 
804  rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
805 
806  if (rstat == 2 || rstat == 3)
807  {
808  avf_log_debug (ad, "reset completed in %.3fs", t);
809  return 0;
810  }
811 
812  t = vlib_time_now (vm) - t0;
813  if (t > AVF_RESET_MAX_WAIT_TIME)
814  {
815  avf_log_err (ad, "reset failed (timeout %.3fs)", t);
816  return clib_error_return (0, "reset failed (timeout)");
817  }
818 
819  suspend_time *= 2;
820  goto retry;
821 }
822 
823 clib_error_t *
825 {
826  virtchnl_vf_res_request_t res_req = { 0 };
827  clib_error_t *error;
828  u32 rstat;
829  f64 t0, t, suspend_time = AVF_RESET_SUSPEND_TIME;
830 
831  res_req.num_queue_pairs = num_queue_pairs;
832 
833  avf_log_debug (ad, "request_queues: num_queue_pairs %u", num_queue_pairs);
834 
835  error = avf_send_to_pf (vm, ad, VIRTCHNL_OP_REQUEST_QUEUES, &res_req,
836  sizeof (virtchnl_vf_res_request_t), &res_req,
837  sizeof (virtchnl_vf_res_request_t));
838 
839  /*
840  * if PF responds, the request failed
841  * else PF initializes restart and avf_send_to_pf returns an error
842  */
843  if (!error)
844  {
845  return clib_error_return (0, "requested more than %u queue pairs",
846  res_req.num_queue_pairs);
847  }
848 
849  t0 = vlib_time_now (vm);
850 retry:
851  vlib_process_suspend (vm, suspend_time);
852  t = vlib_time_now (vm) - t0;
853 
854  rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
855 
856  if ((rstat == VIRTCHNL_VFR_COMPLETED) || (rstat == VIRTCHNL_VFR_VFACTIVE))
857  goto done;
858 
859  if (t > AVF_RESET_MAX_WAIT_TIME)
860  {
861  avf_log_err (ad, "request queues failed (timeout %.3f seconds)", t);
862  return clib_error_return (0, "request queues failed (timeout)");
863  }
864 
865  suspend_time *= 2;
866  goto retry;
867 
868 done:
869  return NULL;
870 }
871 
872 clib_error_t *
874  avf_create_if_args_t * args)
875 {
876  virtchnl_version_info_t ver = { 0 };
877  virtchnl_vf_resource_t res = { 0 };
878  clib_error_t *error;
880  int i;
881 
882  avf_adminq_init (vm, ad);
883 
884  if ((error = avf_request_queues (vm, ad, clib_max (tm->n_vlib_mains,
885  args->rxq_num))))
886  {
887  /* we failed to get more queues, but still we want to proceed */
888  clib_error_free (error);
889 
890  if ((error = avf_device_reset (vm, ad)))
891  return error;
892  }
893 
894  avf_adminq_init (vm, ad);
895 
896  /*
897  * OP_VERSION
898  */
899  if ((error = avf_op_version (vm, ad, &ver)))
900  return error;
901 
902  if (ver.major != VIRTCHNL_VERSION_MAJOR ||
904  return clib_error_return (0, "incompatible protocol version "
905  "(remote %d.%d)", ver.major, ver.minor);
906 
907  /*
908  * OP_GET_VF_RESOURCES
909  */
910  if ((error = avf_op_get_vf_resources (vm, ad, &res)))
911  return error;
912 
913  if (res.num_vsis != 1 || res.vsi_res[0].vsi_type != VIRTCHNL_VSI_SRIOV)
914  return clib_error_return (0, "unexpected GET_VF_RESOURCE reply received");
915 
916  ad->vsi_id = res.vsi_res[0].vsi_id;
919  ad->max_vectors = res.max_vectors;
920  ad->max_mtu = res.max_mtu;
921  ad->rss_key_size = res.rss_key_size;
922  ad->rss_lut_size = res.rss_lut_size;
923 
925 
926  /*
927  * Disable VLAN stripping
928  */
929  if ((error = avf_op_disable_vlan_stripping (vm, ad)))
930  return error;
931 
932  /*
933  * Init Queues
934  */
935  if (args->rxq_num == 0)
936  {
937  args->rxq_num = 1;
938  }
939  else if (args->rxq_num > ad->num_queue_pairs)
940  {
941  args->rxq_num = ad->num_queue_pairs;
942  avf_log_warn (ad, "Requested more rx queues than queue pairs available."
943  "Using %u rx queues.", args->rxq_num);
944  }
945 
946  for (i = 0; i < args->rxq_num; i++)
947  if ((error = avf_rxq_init (vm, ad, i, args->rxq_size)))
948  return error;
949 
950  for (i = 0; i < tm->n_vlib_mains; i++)
951  if ((error = avf_txq_init (vm, ad, i, args->txq_size)))
952  return error;
953 
954  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
955  (error = avf_op_config_rss_lut (vm, ad)))
956  return error;
957 
958  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
959  (error = avf_op_config_rss_key (vm, ad)))
960  return error;
961 
962  if ((error = avf_op_config_vsi_queues (vm, ad)))
963  return error;
964 
965  if ((error = avf_op_config_irq_map (vm, ad)))
966  return error;
967 
968  avf_irq_0_enable (ad);
969  for (i = 0; i < ad->n_rx_queues; i++)
970  avf_irq_n_enable (ad, i);
971 
972  if ((error = avf_op_add_eth_addr (vm, ad, 1, ad->hwaddr)))
973  return error;
974 
975  if ((error = avf_op_enable_queues (vm, ad, pow2_mask (ad->n_rx_queues),
976  pow2_mask (ad->n_tx_queues))))
977  return error;
978 
979  ad->flags |= AVF_DEVICE_F_INITIALIZED;
980  return error;
981 }
982 
983 void
985 {
986  avf_main_t *am = &avf_main;
987  vnet_main_t *vnm = vnet_get_main ();
989  u32 r;
990 
991  if (ad->flags & AVF_DEVICE_F_ERROR)
992  return;
993 
994  if ((ad->flags & AVF_DEVICE_F_INITIALIZED) == 0)
995  return;
996 
997  ASSERT (ad->error == 0);
998 
999  /* do not process device in reset state */
1000  r = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
1001  if (r != VIRTCHNL_VFR_VFACTIVE)
1002  return;
1003 
1004  r = avf_get_u32 (ad->bar0, AVF_ARQLEN);
1005  if ((r & 0xf0000000) != (1ULL << 31))
1006  {
1007  ad->error = clib_error_return (0, "arq not enabled, arqlen = 0x%x", r);
1008  avf_log_err (ad, "error: %U", format_clib_error, ad->error);
1009  goto error;
1010  }
1011 
1012  r = avf_get_u32 (ad->bar0, AVF_ATQLEN);
1013  if ((r & 0xf0000000) != (1ULL << 31))
1014  {
1015  ad->error = clib_error_return (0, "atq not enabled, atqlen = 0x%x", r);
1016  avf_log_err (ad, "error: %U", format_clib_error, ad->error);
1017  goto error;
1018  }
1019 
1020  if (is_irq == 0)
1021  avf_op_get_stats (vm, ad, &ad->eth_stats);
1022 
1023  /* *INDENT-OFF* */
1024  vec_foreach (e, ad->events)
1025  {
1026  avf_log_debug (ad, "event: %s (%u) sev %d",
1028  if (e->event == VIRTCHNL_EVENT_LINK_CHANGE)
1029  {
1030  int link_up = e->event_data.link_event.link_status;
1031  virtchnl_link_speed_t speed = e->event_data.link_event.link_speed;
1032  u32 flags = 0;
1033  u32 kbps = 0;
1034 
1035  avf_log_debug (ad, "event_link_change: status %d speed '%s' (%d)",
1036  link_up,
1038  virtchnl_link_speed_str[speed] : "unknown", speed);
1039 
1040  if (link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) == 0)
1041  {
1042  ad->flags |= AVF_DEVICE_F_LINK_UP;
1045  if (speed == VIRTCHNL_LINK_SPEED_40GB)
1046  kbps = 40000000;
1047  else if (speed == VIRTCHNL_LINK_SPEED_25GB)
1048  kbps = 25000000;
1049  else if (speed == VIRTCHNL_LINK_SPEED_10GB)
1050  kbps = 10000000;
1051  else if (speed == VIRTCHNL_LINK_SPEED_5GB)
1052  kbps = 5000000;
1053  else if (speed == VIRTCHNL_LINK_SPEED_2_5GB)
1054  kbps = 2500000;
1055  else if (speed == VIRTCHNL_LINK_SPEED_1GB)
1056  kbps = 1000000;
1057  else if (speed == VIRTCHNL_LINK_SPEED_100MB)
1058  kbps = 100000;
1059  vnet_hw_interface_set_flags (vnm, ad->hw_if_index, flags);
1061  ad->link_speed = speed;
1062  }
1063  else if (!link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) != 0)
1064  {
1065  ad->flags &= ~AVF_DEVICE_F_LINK_UP;
1066  ad->link_speed = 0;
1067  }
1068 
1069  if (ad->flags & AVF_DEVICE_F_ELOG)
1070  {
1071  ELOG_TYPE_DECLARE (el) =
1072  {
1073  .format = "avf[%d] link change: link_status %d "
1074  "link_speed %d",
1075  .format_args = "i4i1i1",
1076  };
1077  struct
1078  {
1079  u32 dev_instance;
1080  u8 link_status;
1081  u8 link_speed;
1082  } *ed;
1083  ed = ELOG_DATA (&vm->elog_main, el);
1084  ed->dev_instance = ad->dev_instance;
1085  ed->link_status = link_up;
1086  ed->link_speed = speed;
1087  }
1088  }
1089  else
1090  {
1091  if (ad->flags & AVF_DEVICE_F_ELOG)
1092  {
1093  ELOG_TYPE_DECLARE (el) =
1094  {
1095  .format = "avf[%d] unknown event: event %d severity %d",
1096  .format_args = "i4i4i1i1",
1097  };
1098  struct
1099  {
1100  u32 dev_instance;
1101  u32 event;
1102  u32 severity;
1103  } *ed;
1104  ed = ELOG_DATA (&vm->elog_main, el);
1105  ed->dev_instance = ad->dev_instance;
1106  ed->event = e->event;
1107  ed->severity = e->severity;
1108  }
1109  }
1110  }
1111  /* *INDENT-ON* */
1112  vec_reset_length (ad->events);
1113 
1114  return;
1115 
1116 error:
1117  ad->flags |= AVF_DEVICE_F_ERROR;
1118  ASSERT (ad->error != 0);
1119  vlib_log_err (am->log_class, "%U", format_clib_error, ad->error);
1120 }
1121 
1122 static u32
1124 {
1126  avf_main_t *am = &avf_main;
1128  clib_error_t *error;
1129  u8 promisc_enabled;
1130 
1131  switch (flags)
1132  {
1134  ad->flags &= ~AVF_DEVICE_F_PROMISC;
1135  break;
1137  ad->flags |= AVF_DEVICE_F_PROMISC;
1138  break;
1139  default:
1140  return ~0;
1141  }
1142 
1143  promisc_enabled = ((ad->flags & AVF_DEVICE_F_PROMISC) != 0);
1144  if ((error = avf_config_promisc_mode (vm, ad, promisc_enabled)))
1145  {
1146  avf_log_err (ad, "%s: %U", format_clib_error, error);
1147  clib_error_free (error);
1148  return ~0;
1149  }
1150 
1151  return 0;
1152 }
1153 
1154 static uword
1156 {
1157  avf_main_t *am = &avf_main;
1158  avf_device_t *ad;
1159  uword *event_data = 0, event_type;
1160  int enabled = 0, irq;
1161  f64 last_run_duration = 0;
1162  f64 last_periodic_time = 0;
1163 
1164  while (1)
1165  {
1166  if (enabled)
1167  vlib_process_wait_for_event_or_clock (vm, 5.0 - last_run_duration);
1168  else
1170 
1171  event_type = vlib_process_get_events (vm, &event_data);
1172  vec_reset_length (event_data);
1173  irq = 0;
1174 
1175  switch (event_type)
1176  {
1177  case ~0:
1178  last_periodic_time = vlib_time_now (vm);
1179  break;
1181  enabled = 1;
1182  break;
1184  enabled = 0;
1185  continue;
1187  irq = 1;
1188  break;
1189  default:
1190  ASSERT (0);
1191  }
1192 
1193  /* *INDENT-OFF* */
1194  pool_foreach (ad, am->devices,
1195  {
1196  avf_process_one_device (vm, ad, irq);
1197  });
1198  /* *INDENT-ON* */
1199  last_run_duration = vlib_time_now (vm) - last_periodic_time;
1200  }
1201  return 0;
1202 }
1203 
1204 /* *INDENT-OFF* */
1206  .function = avf_process,
1207  .type = VLIB_NODE_TYPE_PROCESS,
1208  .name = "avf-process",
1209 };
1210 /* *INDENT-ON* */
1211 
1212 static void
1214 {
1215  avf_main_t *am = &avf_main;
1216  uword pd = vlib_pci_get_private_data (vm, h);
1217  avf_device_t *ad = pool_elt_at_index (am->devices, pd);
1218  u32 icr0;
1219 
1220  icr0 = avf_reg_read (ad, AVFINT_ICR0);
1221 
1222  if (ad->flags & AVF_DEVICE_F_ELOG)
1223  {
1224  /* *INDENT-OFF* */
1225  ELOG_TYPE_DECLARE (el) =
1226  {
1227  .format = "avf[%d] irq 0: icr0 0x%x",
1228  .format_args = "i4i4",
1229  };
1230  /* *INDENT-ON* */
1231  struct
1232  {
1233  u32 dev_instance;
1234  u32 icr0;
1235  } *ed;
1236 
1237  ed = ELOG_DATA (&vm->elog_main, el);
1238  ed->dev_instance = ad->dev_instance;
1239  ed->icr0 = icr0;
1240  }
1241 
1242  avf_irq_0_enable (ad);
1243 
1244  /* bit 30 - Send/Receive Admin queue interrupt indication */
1245  if (icr0 & (1 << 30))
1248 }
1249 
1250 static void
1252 {
1253  vnet_main_t *vnm = vnet_get_main ();
1254  avf_main_t *am = &avf_main;
1255  uword pd = vlib_pci_get_private_data (vm, h);
1256  avf_device_t *ad = pool_elt_at_index (am->devices, pd);
1257  u16 qid;
1258  int i;
1259 
1260  if (ad->flags & AVF_DEVICE_F_ELOG)
1261  {
1262  /* *INDENT-OFF* */
1263  ELOG_TYPE_DECLARE (el) =
1264  {
1265  .format = "avf[%d] irq %d: received",
1266  .format_args = "i4i2",
1267  };
1268  /* *INDENT-ON* */
1269  struct
1270  {
1271  u32 dev_instance;
1272  u16 line;
1273  } *ed;
1274 
1275  ed = ELOG_DATA (&vm->elog_main, el);
1276  ed->dev_instance = ad->dev_instance;
1277  ed->line = line;
1278  }
1279 
1280  qid = line - 1;
1281  if (vec_len (ad->rxqs) > qid && ad->rxqs[qid].int_mode != 0)
1283  for (i = 0; i < vec_len (ad->rxqs); i++)
1284  avf_irq_n_enable (ad, i);
1285 }
1286 
1287 void
1289 {
1290  vnet_main_t *vnm = vnet_get_main ();
1291  avf_main_t *am = &avf_main;
1292  int i;
1293 
1294  if (ad->hw_if_index)
1295  {
1299  }
1300 
1302 
1303  vlib_physmem_free (vm, ad->atq);
1304  vlib_physmem_free (vm, ad->arq);
1305  vlib_physmem_free (vm, ad->atq_bufs);
1306  vlib_physmem_free (vm, ad->arq_bufs);
1307 
1308  /* *INDENT-OFF* */
1309  vec_foreach_index (i, ad->rxqs)
1310  {
1311  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
1312  vlib_physmem_free (vm, (void *) rxq->descs);
1313  if (rxq->n_enqueued)
1314  vlib_buffer_free_from_ring (vm, rxq->bufs, rxq->next, rxq->size,
1315  rxq->n_enqueued);
1316  vec_free (rxq->bufs);
1317  }
1318  /* *INDENT-ON* */
1319  vec_free (ad->rxqs);
1320 
1321  /* *INDENT-OFF* */
1322  vec_foreach_index (i, ad->txqs)
1323  {
1324  avf_txq_t *txq = vec_elt_at_index (ad->txqs, i);
1325  vlib_physmem_free (vm, (void *) txq->descs);
1326  if (txq->n_enqueued)
1327  {
1328  u16 first = (txq->next - txq->n_enqueued) & (txq->size -1);
1329  vlib_buffer_free_from_ring (vm, txq->bufs, first, txq->size,
1330  txq->n_enqueued);
1331  }
1332  vec_free (txq->bufs);
1333  clib_ring_free (txq->rs_slots);
1334  }
1335  /* *INDENT-ON* */
1336  vec_free (ad->txqs);
1337  vec_free (ad->name);
1338 
1339  clib_error_free (ad->error);
1340  clib_memset (ad, 0, sizeof (*ad));
1341  pool_put (am->devices, ad);
1342 }
1343 
1344 void
1346 {
1347  vnet_main_t *vnm = vnet_get_main ();
1348  avf_main_t *am = &avf_main;
1349  avf_device_t *ad;
1351  clib_error_t *error = 0;
1352  int i;
1353 
1354  /* check input args */
1355  args->rxq_size = (args->rxq_size == 0) ? AVF_RXQ_SZ : args->rxq_size;
1356  args->txq_size = (args->txq_size == 0) ? AVF_TXQ_SZ : args->txq_size;
1357 
1358  if ((args->rxq_size & (args->rxq_size - 1))
1359  || (args->txq_size & (args->txq_size - 1)))
1360  {
1361  args->rv = VNET_API_ERROR_INVALID_VALUE;
1362  args->error =
1363  clib_error_return (error, "queue size must be a power of two");
1364  return;
1365  }
1366 
1367  pool_get (am->devices, ad);
1368  ad->dev_instance = ad - am->devices;
1369  ad->per_interface_next_index = ~0;
1370  ad->name = vec_dup (args->name);
1371 
1372  if (args->enable_elog)
1373  ad->flags |= AVF_DEVICE_F_ELOG;
1374 
1375  if ((error = vlib_pci_device_open (vm, &args->addr, avf_pci_device_ids,
1376  &h)))
1377  {
1378  pool_put (am->devices, ad);
1379  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1380  args->error =
1381  clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
1382  &args->addr);
1383  return;
1384  }
1385  ad->pci_dev_handle = h;
1386  ad->pci_addr = args->addr;
1387  ad->numa_node = vlib_pci_get_numa_node (vm, h);
1388 
1390 
1391  if ((error = vlib_pci_bus_master_enable (vm, h)))
1392  goto error;
1393 
1394  if ((error = vlib_pci_map_region (vm, h, 0, &ad->bar0)))
1395  goto error;
1396 
1397  if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
1398  &avf_irq_0_handler)))
1399  goto error;
1400 
1401  if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
1402  &avf_irq_n_handler)))
1403  goto error;
1404 
1405  if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
1406  goto error;
1407 
1409  AVF_MBOX_LEN,
1411  ad->numa_node);
1412  if (ad->atq == 0)
1413  {
1414  error = vlib_physmem_last_error (vm);
1415  goto error;
1416  }
1417 
1418  if ((error = vlib_pci_map_dma (vm, h, ad->atq)))
1419  goto error;
1420 
1422  AVF_MBOX_LEN,
1424  ad->numa_node);
1425  if (ad->arq == 0)
1426  {
1427  error = vlib_physmem_last_error (vm);
1428  goto error;
1429  }
1430 
1431  if ((error = vlib_pci_map_dma (vm, h, ad->arq)))
1432  goto error;
1433 
1435  AVF_MBOX_LEN,
1437  ad->numa_node);
1438  if (ad->atq_bufs == 0)
1439  {
1440  error = vlib_physmem_last_error (vm);
1441  goto error;
1442  }
1443 
1444  if ((error = vlib_pci_map_dma (vm, h, ad->atq_bufs)))
1445  goto error;
1446 
1448  AVF_MBOX_LEN,
1450  ad->numa_node);
1451  if (ad->arq_bufs == 0)
1452  {
1453  error = vlib_physmem_last_error (vm);
1454  goto error;
1455  }
1456 
1457  if ((error = vlib_pci_map_dma (vm, h, ad->arq_bufs)))
1458  goto error;
1459 
1460  if ((error = vlib_pci_intr_enable (vm, h)))
1461  goto error;
1462 
1464  ad->flags |= AVF_DEVICE_F_VA_DMA;
1465 
1466  if ((error = avf_device_init (vm, am, ad, args)))
1467  goto error;
1468 
1469  /* create interface */
1470  error = ethernet_register_interface (vnm, avf_device_class.index,
1471  ad->dev_instance, ad->hwaddr,
1473 
1474  if (error)
1475  goto error;
1476 
1477  /* Indicate ability to support L3 DMAC filtering and
1478  * initialize interface to L3 non-promisc mode */
1481  ethernet_set_flags (vnm, ad->hw_if_index,
1483 
1485  args->sw_if_index = ad->sw_if_index = sw->sw_if_index;
1486 
1490  avf_input_node.index);
1491 
1492  for (i = 0; i < ad->n_rx_queues; i++)
1494 
1495  if (pool_elts (am->devices) == 1)
1498 
1499  return;
1500 
1501 error:
1502  avf_delete_if (vm, ad);
1503  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1504  args->error = clib_error_return (error, "pci-addr %U",
1505  format_vlib_pci_addr, &args->addr);
1506  avf_log_err (ad, "error: %U", format_clib_error, args->error);
1507 }
1508 
1509 static clib_error_t *
1511 {
1512  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1513  avf_main_t *am = &avf_main;
1515  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
1516 
1517  if (ad->flags & AVF_DEVICE_F_ERROR)
1518  return clib_error_return (0, "device is in error state");
1519 
1520  if (is_up)
1521  {
1524  ad->flags |= AVF_DEVICE_F_ADMIN_UP;
1525  }
1526  else
1527  {
1529  ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
1530  }
1531  return 0;
1532 }
1533 
1534 static clib_error_t *
1537 {
1538  avf_main_t *am = &avf_main;
1539  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1541  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, qid);
1542 
1544  rxq->int_mode = 0;
1545  else
1546  rxq->int_mode = 1;
1547 
1548  return 0;
1549 }
1550 
1551 static void
1553  u32 node_index)
1554 {
1555  avf_main_t *am = &avf_main;
1556  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1558 
1559  /* Shut off redirection */
1560  if (node_index == ~0)
1561  {
1562  ad->per_interface_next_index = node_index;
1563  return;
1564  }
1565 
1567  vlib_node_add_next (vlib_get_main (), avf_input_node.index, node_index);
1568 }
1569 
1570 static char *avf_tx_func_error_strings[] = {
1571 #define _(n,s) s,
1573 #undef _
1574 };
1575 
1576 static void
1578 {
1579  avf_main_t *am = &avf_main;
1580  avf_device_t *ad = vec_elt_at_index (am->devices, instance);
1582  &ad->eth_stats, sizeof (ad->eth_stats));
1583 }
1584 
1585 /* *INDENT-OFF* */
1587 {
1588  .name = "Adaptive Virtual Function (AVF) interface",
1589  .clear_counters = avf_clear_hw_interface_counters,
1590  .format_device = format_avf_device,
1591  .format_device_name = format_avf_device_name,
1592  .admin_up_down_function = avf_interface_admin_up_down,
1593  .rx_mode_change_function = avf_interface_rx_mode_change,
1594  .rx_redirect_to_node = avf_set_interface_next_node,
1595  .tx_function_n_errors = AVF_TX_N_ERROR,
1596  .tx_function_error_strings = avf_tx_func_error_strings,
1597 };
1598 /* *INDENT-ON* */
1599 
1600 clib_error_t *
1602 {
1603  avf_main_t *am = &avf_main;
1605 
1608 
1609  am->log_class = vlib_log_register_class ("avf", 0);
1610  vlib_log_debug (am->log_class, "initialized");
1611 
1612  return 0;
1613 }
1614 
1615 /* *INDENT-OFF* */
1617 {
1618  .runs_after = VLIB_INITS ("pci_bus_init"),
1619 };
1620 /* *INDENT-OFF* */
1621 
1622 /*
1623  * fd.io coding-style-patch-verification: ON
1624  *
1625  * Local Variables:
1626  * eval: (c-set-style "gnu")
1627  * End:
1628  */
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:209
#define AVF_TXQ_SZ
Definition: device.c:29
clib_error_t * avf_op_get_vf_resources(vlib_main_t *vm, avf_device_t *ad, virtchnl_vf_resource_t *res)
Definition: device.c:524
u8 count
Definition: dhcp.api:208
clib_error_t * avf_op_add_eth_addr(vlib_main_t *vm, avf_device_t *ad, u8 count, u8 *macs)
Definition: device.c:718
static vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
Definition: device.c:1205
u8 int_mode
Definition: avf.h:129
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define AVF_ARQLEN
Definition: virtchnl.h:47
virtchnl_queue_pair_info_t qpair[1]
Definition: virtchnl.h:311
u32 hw_if_index
Definition: avf.h:154
u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
static clib_error_t * vlib_pci_intr_enable(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.h:239
#define PCI_DEVICE_ID_INTEL_AVF
Definition: device.c:33
#define AVF_ATQH
Definition: virtchnl.h:40
#define clib_min(x, y)
Definition: clib.h:319
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)
Definition: random.h:91
static clib_error_t * vlib_pci_bus_master_enable(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.h:271
static void * vlib_physmem_alloc_aligned_on_numa(vlib_main_t *vm, uword n_bytes, uword alignment, u32 numa_node)
Definition: physmem_funcs.h:63
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...
Definition: node_funcs.h:673
void avf_arq_slot_init(avf_device_t *ad, u16 slot)
Definition: device.c:328
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)
Definition: device.c:385
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1345
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:593
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:378
#define AVF_ATQBAH
Definition: virtchnl.h:45
clib_error_t * avf_device_init(vlib_main_t *vm, avf_main_t *am, avf_device_t *ad, avf_create_if_args_t *args)
Definition: device.c:873
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
clib_error_t * error
Definition: avf.h:193
#define avf_log_warn(dev, f,...)
Definition: avf.h:55
#define AVF_AQ_ENQ_SUSPEND_TIME
Definition: avf.h:25
clib_error_t * avf_op_config_vsi_queues(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:636
clib_error_t * avf_op_version(vlib_main_t *vm, avf_device_t *ad, virtchnl_version_info_t *ver)
Definition: device.c:502
u64 atq_bufs_pa
Definition: avf.h:171
static uword vlib_buffer_get_pa(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:457
virtchnl_vsi_type_t vsi_type
Definition: virtchnl.h:165
#define AVF_SEND_TO_PF_SUSPEND_TIME
Definition: avf.h:31
unsigned long u64
Definition: types.h:89
void vlib_pci_device_close(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:1286
virtchnl_vector_map_t vecmap[1]
Definition: virtchnl.h:339
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:291
#define clib_ring_new_aligned(ring, size, align)
Definition: ring.h:53
virtchnl_link_speed_t link_speed
Definition: avf.h:185
#define AVF_ARQBAH
Definition: virtchnl.h:39
static uword avf_dma_addr(vlib_main_t *vm, avf_device_t *ad, void *p)
Definition: device.c:341
static clib_error_t * vlib_physmem_last_error(struct vlib_main_t *vm)
clib_error_t * avf_aq_desc_enq(vlib_main_t *vm, avf_device_t *ad, avf_aq_desc_t *dt, void *data, int len)
Definition: device.c:113
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define AVF_QRX_TAIL(q)
Definition: virtchnl.h:51
#define AVF_ARQT
Definition: virtchnl.h:43
format_function_t format_avf_device
Definition: avf.h:253
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:628
static void avf_irq_n_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:1251
vlib_pci_addr_t addr
Definition: avf.h:234
clib_error_t * avf_init(vlib_main_t *vm)
Definition: device.c:1601
#define AVF_AQ_F_SI
Definition: virtchnl.h:61
u32 dev_instance
Definition: avf.h:152
clib_error_t * vlib_pci_enable_msix_irq(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 start, u16 count)
Definition: pci.c:894
#define AVF_QTX_TAIL(q)
Definition: virtchnl.h:50
clib_error_t * avf_rxq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 rxq_size)
Definition: device.c:231
virtchnl_link_speed_t
Definition: virtchnl.h:205
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:518
avf_device_t * devices
Definition: avf.h:224
#define ETHERNET_INTERFACE_FLAG_DEFAULT_L3
Definition: ethernet.h:149
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
volatile u32 * qtx_tail
Definition: avf.h:136
#define AVF_ATQLEN
Definition: virtchnl.h:41
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
void avf_process_one_device(vlib_main_t *vm, avf_device_t *ad, int is_irq)
Definition: device.c:984
unsigned char u8
Definition: types.h:56
vnet_device_class_t avf_device_class
#define AVF_ARQH
Definition: virtchnl.h:44
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
virtchnl_ops_t
Definition: virtchnl.h:103
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
u8 buffer_pool_index
Definition: avf.h:130
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:422
#define AVF_AQ_F_DD
Definition: virtchnl.h:53
vnet_hw_interface_rx_mode
Definition: interface.h:53
#define AVF_RESET_SUSPEND_TIME
Definition: avf.h:28
u16 * rs_slots
Definition: avf.h:143
#define AVFINT_ICR0_ENA1
Definition: virtchnl.h:37
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
clib_error_t * vlib_pci_map_dma(vlib_main_t *vm, vlib_pci_dev_handle_t h, void *ptr)
Definition: pci.c:1207
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
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...
Definition: node_funcs.h:516
clib_spinlock_t lock
Definition: avf.h:139
#define AVF_SEND_TO_PF_MAX_WAIT_TIME
Definition: avf.h:32
static uword pow2_mask(uword x)
Definition: clib.h:235
static void avf_irq_0_disable(avf_device_t *ad)
Definition: device.c:59
static u32 avf_reg_read(avf_device_t *ad, u32 addr)
Definition: avf.h:304
static const char * virtchnl_link_speed_str[]
Definition: device.c:52
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:136
static void avf_irq_0_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:1213
vnet_hw_interface_flags_t flags
Definition: interface.h:526
volatile u32 * qrx_tail
Definition: avf.h:123
#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...)
Definition: error.h:99
static void avf_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: device.c:1552
static const char * virtchnl_event_names[]
Definition: device.c:46
unsigned int u32
Definition: types.h:88
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:155
clib_error_t * avf_op_config_rss_lut(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:561
#define vlib_log_debug(...)
Definition: log.h:109
virtchnl_ether_addr_t list[1]
Definition: virtchnl.h:354
void * arq_bufs
Definition: avf.h:170
avf_aq_desc_t * arq
Definition: avf.h:168
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
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.
Definition: buffer_funcs.h:984
static u32 avf_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 flags)
Definition: device.c:1123
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
u8 * name
Definition: avf.h:158
virtchnl_eth_stats_t last_cleared_eth_stats
Definition: avf.h:190
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
void vlib_pci_set_private_data(vlib_main_t *vm, vlib_pci_dev_handle_t h, uword private_data)
Definition: pci.c:155
static u32 avf_get_u32(void *start, int offset)
Definition: avf.h:258
virtchnl_txq_info_t txq
Definition: virtchnl.h:302
static void avf_irq_n_disable(avf_device_t *ad, u8 line)
Definition: device.c:89
#define AVF_ATQT
Definition: virtchnl.h:48
unsigned short u16
Definition: types.h:57
#define AVF_RESET_MAX_WAIT_TIME
Definition: avf.h:29
vec_header_t h
Definition: buffer.c:322
static void avf_clear_hw_interface_counters(u32 instance)
Definition: device.c:1577
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:427
static void avf_adminq_init(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:348
clib_error_t * vlib_pci_register_msix_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u32 start, u32 count, pci_msix_handler_function_t *msix_handler)
Definition: pci.c:837
u64 qword[4]
Definition: avf.h:98
#define ELOG_DATA(em, f)
Definition: elog.h:484
#define AVF_AQ_F_RD
Definition: virtchnl.h:58
#define VIRTCHNL_VERSION_MAJOR
Definition: virtchnl.h:21
uword vlib_pci_get_private_data(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:148
clib_error_t * avf_op_disable_vlan_stripping(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:608
static void avf_reg_flush(avf_device_t *ad)
Definition: avf.h:310
u32 vlib_pci_dev_handle_t
Definition: pci.h:97
#define AVFINT_ICR0
Definition: virtchnl.h:36
vlib_main_t * vm
Definition: in2out_ed.c:1599
vl_api_tunnel_mode_t mode
Definition: gre.api:48
clib_error_t * avf_device_reset(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:786
#define PCI_DEVICE_ID_INTEL_X710_VF
Definition: device.c:34
clib_error_t * avf_op_config_irq_map(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:692
#define PCI_VENDOR_ID_INTEL
Definition: device.c:32
u8 len
Definition: ip_types.api:92
clib_error_t * avf_request_queues(vlib_main_t *vm, avf_device_t *ad, u16 num_queue_pairs)
Definition: device.c:824
u16 n_rx_queues
Definition: avf.h:164
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
u8 slot
Definition: pci_types.api:22
u8 hwaddr[6]
Definition: avf.h:179
u16 atq_next_slot
Definition: avf.h:173
u32 vlib_pci_get_numa_node(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:170
#define AVF_AQ_F_BUF
Definition: virtchnl.h:60
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u32 numa_node
Definition: avf.h:156
u32 flags
Definition: vhost_user.h:248
static void vlib_physmem_free(vlib_main_t *vm, void *p)
Definition: physmem_funcs.h:89
vlib_node_registration_t avf_input_node
(constructor) VLIB_REGISTER_NODE (avf_input_node)
Definition: input.c:463
#define avf_log_debug(dev, f,...)
Definition: avf.h:60
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
Definition: avf.h:120
vlib_log_class_t log_class
Definition: avf.h:227
union virtchnl_pf_event_t::@32 event_data
elog_main_t elog_main
Definition: main.h:193
avf_tx_desc_t * descs
Definition: avf.h:140
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:152
#define ARRAY_LEN(x)
Definition: clib.h:66
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
virtchnl_ops_t v_opcode
Definition: virtchnl.h:249
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:38
u16 vsi_id
Definition: avf.h:177
u32 per_interface_next_index
Definition: avf.h:150
u32 feature_bitmap
Definition: avf.h:178
virtchnl_status_code_t v_retval
Definition: virtchnl.h:254
u32 * bufs
Definition: avf.h:141
#define AVF_ITR_INT
Definition: device.c:30
clib_error_t * avf_op_enable_queues(vlib_main_t *vm, avf_device_t *ad, u32 rx, u32 tx)
Definition: device.c:746
static u32 vlib_buffer_alloc_from_pool(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u8 buffer_pool_index)
Allocate buffers from specific pool into supplied array.
Definition: buffer_funcs.h:566
#define ASSERT(truth)
#define AVF_RXQ_SZ
Definition: device.c:28
avf_aq_desc_t * atq
Definition: avf.h:167
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:139
VNET_DEVICE_CLASS(avf_device_class,)
u32 flags
Definition: avf.h:149
u8 data[128]
Definition: ipsec_types.api:89
#define AVFINT_DYN_CTLN(x)
Definition: virtchnl.h:35
Definition: avf.h:133
u32 * bufs
Definition: avf.h:127
void * bar0
Definition: avf.h:157
#define AVF_MBOX_BUF_SZ
Definition: device.c:27
u16 n_enqueued
Definition: avf.h:142
clib_error_t * avf_txq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 txq_size)
Definition: device.c:282
u16 n_enqueued
Definition: avf.h:128
u8 * format_hex_bytes_no_wrap(u8 *s, va_list *va)
Definition: std-formats.c:112
virtchnl_pf_event_t * events
Definition: avf.h:175
virtchnl_event_codes_t event
Definition: virtchnl.h:215
#define AVF_AQ_ENQ_MAX_WAIT_TIME
Definition: avf.h:26
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:298
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static char * avf_tx_func_error_strings[]
Definition: device.c:1570
#define clib_max(x, y)
Definition: clib.h:312
virtchnl_eth_stats_t eth_stats
Definition: avf.h:189
void * atq_bufs
Definition: avf.h:169
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vl_api_ip4_address_t hi
Definition: arp.api:37
clib_error_t * avf_config_promisc_mode(vlib_main_t *vm, avf_device_t *ad, int is_enable)
Definition: device.c:617
#define AVFGEN_RSTAT
Definition: virtchnl.h:49
u16 num_queue_pairs
Definition: avf.h:180
u16 next
Definition: avf.h:137
#define PCI_DEVICE_ID_INTEL_X722_VF
Definition: device.c:35
clib_error_t * avf_op_config_rss_key(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:584
virtchnl_rxq_info_t rxq
Definition: virtchnl.h:303
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
#define AVF_ARQBAL
Definition: virtchnl.h:42
u32 rss_lut_size
Definition: avf.h:184
u16 n_tx_queues
Definition: avf.h:163
#define AVF_AQ_F_CMP
Definition: virtchnl.h:54
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, const u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:331
u32 instance
Definition: gre.api:51
clib_error_t * avf_cmd_rx_ctl_reg_write(vlib_main_t *vm, avf_device_t *ad, u32 reg, u32 val)
Definition: device.c:200
format_function_t format_avf_device_name
Definition: avf.h:254
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:498
avf_main_t avf_main
Definition: device.c:37
#define foreach_virtchnl_op
Definition: virtchnl.h:66
VLIB buffer representation.
Definition: buffer.h:102
#define foreach_avf_tx_func_error
Definition: avf.h:336
u64 uword
Definition: types.h:112
u16 size
Definition: avf.h:125
u16 arq_next_slot
Definition: avf.h:174
#define clib_error_free(e)
Definition: error.h:86
clib_error_t * vlib_pci_map_region(vlib_main_t *vm, vlib_pci_dev_handle_t h, u32 resource, void **result)
Definition: pci.c:1157
clib_error_t * avf_op_get_stats(vlib_main_t *vm, avf_device_t *ad, virtchnl_eth_stats_t *es)
Definition: device.c:772
avf_rxq_t * rxqs
Definition: avf.h:161
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1288
virtchnl_vsi_resource_t vsi_res[1]
Definition: virtchnl.h:179
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:188
static void avf_irq_n_enable(avf_device_t *ad, u8 line)
Definition: device.c:98
int vlib_pci_supports_virtual_addr_dma(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:1218
clib_error_t * error
Definition: avf.h:243
static uword avf_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: device.c:1155
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
avf_per_thread_data_t * per_thread_data
Definition: avf.h:225
static uword vlib_buffer_get_va(vlib_buffer_t *b)
Definition: buffer.h:217
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
u16 size
Definition: avf.h:138
vlib_pci_addr_t pci_addr
Definition: avf.h:186
u32 sw_if_index
Definition: avf.h:153
#define ETHERNET_MAX_PACKET_BYTES
Definition: ethernet.h:133
#define vec_foreach(var, vec)
Vector iterator.
#define vlib_log_err(...)
Definition: log.h:105
u64 arq_bufs_pa
Definition: avf.h:172
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:130
static clib_error_t * avf_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:1510
#define avf_log_err(dev, f,...)
Definition: avf.h:50
#define AVF_ATQBAL
Definition: virtchnl.h:46
struct virtchnl_pf_event_t::@32::@33 link_event
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
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)
Definition: device.c:1535
#define VIRTCHNL_VERSION_MINOR
Definition: virtchnl.h:22
static u8 vlib_buffer_pool_get_default_for_numa(vlib_main_t *vm, u32 numa_node)
Definition: buffer_funcs.h:199
#define clib_ring_free(f)
Definition: ring.h:59
#define AVF_MBOX_LEN
Definition: device.c:26
clib_error_t * vlib_pci_device_open(vlib_main_t *vm, vlib_pci_addr_t *addr, pci_device_id_t ids[], vlib_pci_dev_handle_t *handle)
Definition: pci.c:1226
u16 next
Definition: avf.h:124
#define VLIB_INITS(...)
Definition: init.h:344
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static void vnet_hw_interface_set_link_speed(vnet_main_t *vnm, u32 hw_if_index, u32 link_speed)
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
avf_txq_t * txqs
Definition: avf.h:162
avf_rx_desc_t * descs
Definition: avf.h:126
u16 vendor_id
Definition: pci.h:127
format_function_t format_vlib_pci_addr
Definition: pci.h:324
#define AVF_AQ_F_ERR
Definition: virtchnl.h:55
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:426
u16 max_vectors
Definition: avf.h:181
static void avf_irq_0_enable(avf_device_t *ad)
Definition: device.c:71
u32 rss_key_size
Definition: avf.h:183
u16 max_mtu
Definition: avf.h:182
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128