a5a8a2ad57dc114f6aa9c2103f51273afaafc81e
[vpp.git] / src / plugins / dpdk / device / 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   1024
17 #define DPDK_NB_TX_DESC_DEFAULT   1024
18 #define DPDK_NB_RX_DESC_VIRTIO    256
19 #define DPDK_NB_TX_DESC_VIRTIO    256
20
21 #define I40E_DEV_ID_SFP_XL710           0x1572
22 #define I40E_DEV_ID_QSFP_A              0x1583
23 #define I40E_DEV_ID_QSFP_B              0x1584
24 #define I40E_DEV_ID_QSFP_C              0x1585
25 #define I40E_DEV_ID_10G_BASE_T          0x1586
26 #define I40E_DEV_ID_VF                  0x154C
27
28 /* These args appear by themselves */
29 #define foreach_eal_double_hyphen_predicate_arg \
30 _(no-shconf)                                    \
31 _(no-hpet)                                      \
32 _(no-huge)                                      \
33 _(vmware-tsc-map)
34
35 #define foreach_eal_single_hyphen_mandatory_arg \
36 _(coremask, c)                                  \
37 _(nchannels, n)                                 \
38
39 #define foreach_eal_single_hyphen_arg           \
40 _(mem-alloc-request, m)                         \
41 _(force-ranks, r)
42
43 /* clang-format off */
44 /* These args are preceded by "--" and followed by a single string */
45 #define foreach_eal_double_hyphen_arg           \
46 _(huge-dir)                                     \
47 _(proc-type)                                    \
48 _(file-prefix)                                  \
49 _(vdev)                                         \
50 _(log-level)                                    \
51 _(iova-mode)                                    \
52 _(base-virtaddr)
53 /* clang-format on */
54
55 static inline void
56 dpdk_get_xstats (dpdk_device_t * xd)
57 {
58   int len, ret;
59
60   if (!(xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP))
61     return;
62
63   len = rte_eth_xstats_get (xd->port_id, NULL, 0);
64   if (len < 0)
65     return;
66
67   vec_validate (xd->xstats, len - 1);
68
69   ret = rte_eth_xstats_get (xd->port_id, xd->xstats, len);
70   if (ret < 0 || ret > len)
71     {
72       _vec_len (xd->xstats) = 0;
73       return;
74     }
75
76   _vec_len (xd->xstats) = len;
77 }
78
79 #define DPDK_UPDATE_COUNTER(vnm, tidx, xd, stat, cnt)                         \
80   do                                                                          \
81     {                                                                         \
82       u64 _v = (xd)->stats.stat;                                              \
83       u64 _lv = (xd)->last_stats.stat;                                        \
84       if (PREDICT_FALSE (_v != _lv))                                          \
85         {                                                                     \
86           if (PREDICT_FALSE (_v < _lv))                                       \
87             dpdk_log_warn ("%v: %s counter decreased (before %lu after %lu)", \
88                            xd->name, #stat, _lv, _v);                         \
89           else                                                                \
90             vlib_increment_simple_counter (                                   \
91                 vec_elt_at_index ((vnm)->interface_main.sw_if_counters, cnt), \
92                 (tidx), (xd)->sw_if_index, _v - _lv);                         \
93         }                                                                     \
94     }                                                                         \
95   while (0)
96
97 static inline void
98 dpdk_update_counters (dpdk_device_t * xd, f64 now)
99 {
100   vnet_main_t *vnm = vnet_get_main ();
101   u32 thread_index = vlib_get_thread_index ();
102
103   /* only update counters for PMD interfaces */
104   if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
105     return;
106
107   xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
108   clib_memcpy_fast (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
109   rte_eth_stats_get (xd->port_id, &xd->stats);
110
111   /* maybe bump interface rx no buffer counter */
112   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, rx_nombuf,
113                        VNET_INTERFACE_COUNTER_RX_NO_BUF);
114   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, imissed,
115                        VNET_INTERFACE_COUNTER_RX_MISS);
116   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, ierrors,
117                        VNET_INTERFACE_COUNTER_RX_ERROR);
118
119   dpdk_get_xstats (xd);
120 }
121
122 /*
123  * fd.io coding-style-patch-verification: ON
124  *
125  * Local Variables:
126  * eval: (c-set-style "gnu")
127  * End:
128  */