4ecb1b825024bfd2224757bd01bf076c67b9ced4
[vpp.git] / vnet / vnet / devices / dpdk / dpdk_priv.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #define DPDK_NB_RX_DESC_DEFAULT   512
17 #define DPDK_NB_TX_DESC_DEFAULT   512
18 #define DPDK_NB_RX_DESC_VIRTIO    256
19 #define DPDK_NB_TX_DESC_VIRTIO    256
20 #define DPDK_NB_RX_DESC_10GE    1024
21 #define DPDK_NB_TX_DESC_10GE    1024
22 #define DPDK_NB_RX_DESC_40GE    1024
23 #define DPDK_NB_TX_DESC_40GE    1024
24 #define DPDK_NB_RX_DESC_ENIC    1024
25
26 #if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
27 #define I40E_DEV_ID_SFP_XL710           0x1572
28 #define I40E_DEV_ID_QSFP_A              0x1583
29 #define I40E_DEV_ID_QSFP_B              0x1584
30 #define I40E_DEV_ID_QSFP_C              0x1585
31 #define I40E_DEV_ID_10G_BASE_T          0x1586
32 #define I40E_DEV_ID_VF                  0x154C
33 #endif
34
35 /* These args appear by themselves */
36 #define foreach_eal_double_hyphen_predicate_arg \
37 _(no-shconf)                                    \
38 _(no-hpet)                                      \
39 _(no-huge)                                      \
40 _(vmware-tsc-map)                               \
41 _(virtio-vhost)
42
43 #define foreach_eal_single_hyphen_mandatory_arg \
44 _(coremask, c)                                  \
45 _(nchannels, n)                                 \
46
47 #define foreach_eal_single_hyphen_arg           \
48 _(blacklist, b)                                 \
49 _(mem-alloc-request, m)                         \
50 _(force-ranks, r)
51
52 /* These args are preceeded by "--" and followed by a single string */
53 #define foreach_eal_double_hyphen_arg           \
54 _(huge-dir)                                     \
55 _(proc-type)                                    \
56 _(file-prefix)                                  \
57 _(vdev)
58
59 static inline void
60 dpdk_get_xstats (dpdk_device_t * xd)
61 {
62   int len;
63   if ((len = rte_eth_xstats_get (xd->device_index, NULL, 0)) > 0)
64     {
65       vec_validate (xd->xstats, len - 1);
66       vec_validate (xd->last_cleared_xstats, len - 1);
67
68       len =
69         rte_eth_xstats_get (xd->device_index, xd->xstats,
70                             vec_len (xd->xstats));
71
72       ASSERT (vec_len (xd->xstats) == len);
73       ASSERT (vec_len (xd->last_cleared_xstats) == len);
74
75       _vec_len (xd->xstats) = len;
76       _vec_len (xd->last_cleared_xstats) = len;
77
78     }
79 }
80
81
82 static inline void
83 dpdk_update_counters (dpdk_device_t * xd, f64 now)
84 {
85   vlib_simple_counter_main_t *cm;
86   vnet_main_t *vnm = vnet_get_main ();
87   u32 my_cpu = os_get_cpu_number ();
88   u64 rxerrors, last_rxerrors;
89
90   /* only update counters for PMD interfaces */
91   if (xd->dev_type != VNET_DPDK_DEV_ETH)
92     return;
93
94   /*
95    * DAW-FIXME: VMXNET3 device stop/start doesn't work,
96    * therefore fake the stop in the dpdk driver by
97    * silently dropping all of the incoming pkts instead of
98    * stopping the driver / hardware.
99    */
100   if (xd->admin_up != 0xff)
101     {
102       xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
103       clib_memcpy (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
104       rte_eth_stats_get (xd->device_index, &xd->stats);
105
106       /* maybe bump interface rx no buffer counter */
107       if (PREDICT_FALSE (xd->stats.rx_nombuf != xd->last_stats.rx_nombuf))
108         {
109           cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
110                                  VNET_INTERFACE_COUNTER_RX_NO_BUF);
111
112           vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
113                                          xd->stats.rx_nombuf -
114                                          xd->last_stats.rx_nombuf);
115         }
116
117       /* missed pkt counter */
118       if (PREDICT_FALSE (xd->stats.imissed != xd->last_stats.imissed))
119         {
120           cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
121                                  VNET_INTERFACE_COUNTER_RX_MISS);
122
123           vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
124                                          xd->stats.imissed -
125                                          xd->last_stats.imissed);
126         }
127       rxerrors = xd->stats.ierrors;
128       last_rxerrors = xd->last_stats.ierrors;
129
130       if (PREDICT_FALSE (rxerrors != last_rxerrors))
131         {
132           cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
133                                  VNET_INTERFACE_COUNTER_RX_ERROR);
134
135           vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
136                                          rxerrors - last_rxerrors);
137         }
138     }
139
140   dpdk_get_xstats (xd);
141 }
142
143 /*
144  * fd.io coding-style-patch-verification: ON
145  *
146  * Local Variables:
147  * eval: (c-set-style "gnu")
148  * End:
149  */