dpdk: add buffer.h
[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 _(blacklist, b)                                 \
41 _(mem-alloc-request, m)                         \
42 _(force-ranks, r)
43
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
52 typedef struct
53 {
54   /* must be first */
55   struct rte_pktmbuf_pool_private mbp_priv;
56   u8 buffer_pool_index;
57 } dpdk_mempool_private_t;
58
59
60 static inline void
61 dpdk_get_xstats (dpdk_device_t * xd)
62 {
63   if (!(xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP))
64     return;
65   int len;
66   if ((len = rte_eth_xstats_get (xd->port_id, NULL, 0)) > 0)
67     {
68       vec_validate (xd->xstats, len - 1);
69       vec_validate (xd->last_cleared_xstats, len - 1);
70
71       len =
72         rte_eth_xstats_get (xd->port_id, xd->xstats, vec_len (xd->xstats));
73
74       ASSERT (vec_len (xd->xstats) == len);
75       ASSERT (vec_len (xd->last_cleared_xstats) == len);
76
77       _vec_len (xd->xstats) = len;
78       _vec_len (xd->last_cleared_xstats) = len;
79
80     }
81 }
82
83
84 static inline void
85 dpdk_update_counters (dpdk_device_t * xd, f64 now)
86 {
87   vlib_simple_counter_main_t *cm;
88   vnet_main_t *vnm = vnet_get_main ();
89   u32 thread_index = vlib_get_thread_index ();
90   u64 rxerrors, last_rxerrors;
91
92   /* only update counters for PMD interfaces */
93   if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
94     return;
95
96   xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
97   clib_memcpy_fast (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
98   rte_eth_stats_get (xd->port_id, &xd->stats);
99
100   /* maybe bump interface rx no buffer counter */
101   if (PREDICT_FALSE (xd->stats.rx_nombuf != xd->last_stats.rx_nombuf))
102     {
103       cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
104                              VNET_INTERFACE_COUNTER_RX_NO_BUF);
105
106       vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
107                                      xd->stats.rx_nombuf -
108                                      xd->last_stats.rx_nombuf);
109     }
110
111   /* missed pkt counter */
112   if (PREDICT_FALSE (xd->stats.imissed != xd->last_stats.imissed))
113     {
114       cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
115                              VNET_INTERFACE_COUNTER_RX_MISS);
116
117       vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
118                                      xd->stats.imissed -
119                                      xd->last_stats.imissed);
120     }
121   rxerrors = xd->stats.ierrors;
122   last_rxerrors = xd->last_stats.ierrors;
123
124   if (PREDICT_FALSE (rxerrors != last_rxerrors))
125     {
126       cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
127                              VNET_INTERFACE_COUNTER_RX_ERROR);
128
129       vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
130                                      rxerrors - last_rxerrors);
131     }
132
133   dpdk_get_xstats (xd);
134 }
135
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "gnu")
141  * End:
142  */