blob: 3ebf5e8aa91d61b1a2eafe54088106e7797c7c53 [file] [log] [blame]
Damjan Marion0f60ff82017-03-30 17:58:42 +02001diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
2index 879da5e..2b4345a 100644
3--- a/drivers/net/mlx5/mlx5.h
4+++ b/drivers/net/mlx5/mlx5.h
5@@ -197,6 +197,8 @@ struct mlx5_secondary_data {
6 int mlx5_is_secondary(void);
7 int priv_get_ifname(const struct priv *, char (*)[IF_NAMESIZE]);
8 int priv_ifreq(const struct priv *, int req, struct ifreq *);
9+int priv_is_ib_cntr(const char *);
10+int priv_get_cntr_sysfs(struct priv *, const char *, uint64_t *);
11 int priv_get_num_vfs(struct priv *, uint16_t *);
12 int priv_get_mtu(struct priv *, uint16_t *);
13 int priv_set_flags(struct priv *, unsigned int, unsigned int);
14diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
15index 2145965..6b64f44 100644
16--- a/drivers/net/mlx5/mlx5_ethdev.c
17+++ b/drivers/net/mlx5/mlx5_ethdev.c
18@@ -234,6 +234,23 @@ struct priv *
19 }
20
21 /**
22+ * Check if the counter is located on ib counters file.
23+ *
24+ * @param[in] cntr
25+ * Counter name.
26+ *
27+ * @return
28+ * 1 if counter is located on ib counters file , 0 otherwise.
29+ */
30+int
31+priv_is_ib_cntr(const char *cntr)
32+{
33+ if (!strcmp(cntr, "out_of_buffer"))
34+ return 1;
35+ return 0;
36+}
37+
38+/**
39 * Read from sysfs entry.
40 *
41 * @param[in] priv
42@@ -260,10 +277,15 @@ struct priv *
43 if (priv_get_ifname(priv, &ifname))
44 return -1;
45
46- MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path,
47- ifname, entry);
48-
49- file = fopen(path, "rb");
50+ if (priv_is_ib_cntr(entry)) {
51+ MKSTR(path, "%s/ports/1/hw_counters/%s",
52+ priv->ctx->device->ibdev_path, entry);
53+ file = fopen(path, "rb");
54+ } else {
55+ MKSTR(path, "%s/device/net/%s/%s",
56+ priv->ctx->device->ibdev_path, ifname, entry);
57+ file = fopen(path, "rb");
58+ }
59 if (file == NULL)
60 return -1;
61 ret = fread(buf, 1, size, file);
62@@ -469,6 +491,30 @@ struct priv *
63 }
64
65 /**
66+ * Read device counter from sysfs.
67+ *
68+ * @param priv
69+ * Pointer to private structure.
70+ * @param name
71+ * Counter name.
72+ * @param[out] cntr
73+ * Counter output buffer.
74+ *
75+ * @return
76+ * 0 on success, -1 on failure and errno is set.
77+ */
78+int
79+priv_get_cntr_sysfs(struct priv *priv, const char *name, uint64_t *cntr)
80+{
81+ unsigned long ulong_ctr;
82+
83+ if (priv_get_sysfs_ulong(priv, name, &ulong_ctr) == -1)
84+ return -1;
85+ *cntr = ulong_ctr;
86+ return 0;
87+}
88+
89+/**
90 * Set device MTU.
91 *
92 * @param priv
93diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
94index 20c957e..a48ebea 100644
95--- a/drivers/net/mlx5/mlx5_stats.c
96+++ b/drivers/net/mlx5/mlx5_stats.c
97@@ -125,6 +125,10 @@ struct mlx5_counter_ctrl {
98 .dpdk_name = "tx_errors_phy",
99 .ctr_name = "tx_errors_phy",
100 },
101+ {
102+ .dpdk_name = "rx_out_of_buffer",
103+ .ctr_name = "out_of_buffer",
104+ },
105 };
106
107 static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init);
108@@ -159,9 +163,15 @@ struct mlx5_counter_ctrl {
109 WARN("unable to read statistic values from device");
110 return -1;
111 }
112- for (i = 0; i != xstats_n; ++i)
113- stats[i] = (uint64_t)
114- et_stats->data[xstats_ctrl->dev_table_idx[i]];
115+ for (i = 0; i != xstats_n; ++i) {
116+ if (priv_is_ib_cntr(mlx5_counters_init[i].ctr_name))
117+ priv_get_cntr_sysfs(priv,
118+ mlx5_counters_init[i].ctr_name,
119+ &stats[i]);
120+ else
121+ stats[i] = (uint64_t)
122+ et_stats->data[xstats_ctrl->dev_table_idx[i]];
123+ }
124 return 0;
125 }
126
127@@ -233,6 +243,8 @@ struct mlx5_counter_ctrl {
128 }
129 }
130 for (j = 0; j != xstats_n; ++j) {
131+ if (priv_is_ib_cntr(mlx5_counters_init[i].ctr_name))
132+ continue;
133 if (xstats_ctrl->dev_table_idx[j] >= dev_stats_n) {
134 WARN("counter \"%s\" is not recognized",
135 mlx5_counters_init[j].dpdk_name);