ethdev: add return value to stats get dev op
[dpdk.git] / drivers / net / mlx4 / mlx4_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 6WIND S.A.
5  *   Copyright 2017 Mellanox
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND S.A. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 /**
35  * @file
36  * Miscellaneous control operations for mlx4 driver.
37  */
38
39 #include <assert.h>
40 #include <dirent.h>
41 #include <errno.h>
42 #include <linux/ethtool.h>
43 #include <linux/sockios.h>
44 #include <net/if.h>
45 #include <netinet/ip.h>
46 #include <stddef.h>
47 #include <stdint.h>
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <sys/ioctl.h>
52 #include <sys/socket.h>
53 #include <unistd.h>
54
55 /* Verbs headers do not support -pedantic. */
56 #ifdef PEDANTIC
57 #pragma GCC diagnostic ignored "-Wpedantic"
58 #endif
59 #include <infiniband/verbs.h>
60 #ifdef PEDANTIC
61 #pragma GCC diagnostic error "-Wpedantic"
62 #endif
63
64 #include <rte_errno.h>
65 #include <rte_ethdev.h>
66 #include <rte_ether.h>
67 #include <rte_pci.h>
68
69 #include "mlx4.h"
70 #include "mlx4_rxtx.h"
71 #include "mlx4_utils.h"
72
73 /**
74  * Get interface name from private structure.
75  *
76  * @param[in] priv
77  *   Pointer to private structure.
78  * @param[out] ifname
79  *   Interface name output buffer.
80  *
81  * @return
82  *   0 on success, negative errno value otherwise and rte_errno is set.
83  */
84 int
85 mlx4_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE])
86 {
87         DIR *dir;
88         struct dirent *dent;
89         unsigned int dev_type = 0;
90         unsigned int dev_port_prev = ~0u;
91         char match[IF_NAMESIZE] = "";
92
93         {
94                 MKSTR(path, "%s/device/net", priv->ctx->device->ibdev_path);
95
96                 dir = opendir(path);
97                 if (dir == NULL) {
98                         rte_errno = errno;
99                         return -rte_errno;
100                 }
101         }
102         while ((dent = readdir(dir)) != NULL) {
103                 char *name = dent->d_name;
104                 FILE *file;
105                 unsigned int dev_port;
106                 int r;
107
108                 if ((name[0] == '.') &&
109                     ((name[1] == '\0') ||
110                      ((name[1] == '.') && (name[2] == '\0'))))
111                         continue;
112
113                 MKSTR(path, "%s/device/net/%s/%s",
114                       priv->ctx->device->ibdev_path, name,
115                       (dev_type ? "dev_id" : "dev_port"));
116
117                 file = fopen(path, "rb");
118                 if (file == NULL) {
119                         if (errno != ENOENT)
120                                 continue;
121                         /*
122                          * Switch to dev_id when dev_port does not exist as
123                          * is the case with Linux kernel versions < 3.15.
124                          */
125 try_dev_id:
126                         match[0] = '\0';
127                         if (dev_type)
128                                 break;
129                         dev_type = 1;
130                         dev_port_prev = ~0u;
131                         rewinddir(dir);
132                         continue;
133                 }
134                 r = fscanf(file, (dev_type ? "%x" : "%u"), &dev_port);
135                 fclose(file);
136                 if (r != 1)
137                         continue;
138                 /*
139                  * Switch to dev_id when dev_port returns the same value for
140                  * all ports. May happen when using a MOFED release older than
141                  * 3.0 with a Linux kernel >= 3.15.
142                  */
143                 if (dev_port == dev_port_prev)
144                         goto try_dev_id;
145                 dev_port_prev = dev_port;
146                 if (dev_port == (priv->port - 1u))
147                         snprintf(match, sizeof(match), "%s", name);
148         }
149         closedir(dir);
150         if (match[0] == '\0') {
151                 rte_errno = ENODEV;
152                 return -rte_errno;
153         }
154         strncpy(*ifname, match, sizeof(*ifname));
155         return 0;
156 }
157
158 /**
159  * Read from sysfs entry.
160  *
161  * @param[in] priv
162  *   Pointer to private structure.
163  * @param[in] entry
164  *   Entry name relative to sysfs path.
165  * @param[out] buf
166  *   Data output buffer.
167  * @param size
168  *   Buffer size.
169  *
170  * @return
171  *   Number of bytes read on success, negative errno value otherwise and
172  *   rte_errno is set.
173  */
174 static int
175 mlx4_sysfs_read(const struct priv *priv, const char *entry,
176                 char *buf, size_t size)
177 {
178         char ifname[IF_NAMESIZE];
179         FILE *file;
180         int ret;
181
182         ret = mlx4_get_ifname(priv, &ifname);
183         if (ret)
184                 return ret;
185
186         MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path,
187               ifname, entry);
188
189         file = fopen(path, "rb");
190         if (file == NULL) {
191                 rte_errno = errno;
192                 return -rte_errno;
193         }
194         ret = fread(buf, 1, size, file);
195         if ((size_t)ret < size && ferror(file)) {
196                 rte_errno = EIO;
197                 ret = -rte_errno;
198         } else {
199                 ret = size;
200         }
201         fclose(file);
202         return ret;
203 }
204
205 /**
206  * Write to sysfs entry.
207  *
208  * @param[in] priv
209  *   Pointer to private structure.
210  * @param[in] entry
211  *   Entry name relative to sysfs path.
212  * @param[in] buf
213  *   Data buffer.
214  * @param size
215  *   Buffer size.
216  *
217  * @return
218  *   Number of bytes written on success, negative errno value otherwise and
219  *   rte_errno is set.
220  */
221 static int
222 mlx4_sysfs_write(const struct priv *priv, const char *entry,
223                  char *buf, size_t size)
224 {
225         char ifname[IF_NAMESIZE];
226         FILE *file;
227         int ret;
228
229         ret = mlx4_get_ifname(priv, &ifname);
230         if (ret)
231                 return ret;
232
233         MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device->ibdev_path,
234               ifname, entry);
235
236         file = fopen(path, "wb");
237         if (file == NULL) {
238                 rte_errno = errno;
239                 return -rte_errno;
240         }
241         ret = fwrite(buf, 1, size, file);
242         if ((size_t)ret < size || ferror(file)) {
243                 rte_errno = EIO;
244                 ret = -rte_errno;
245         } else {
246                 ret = size;
247         }
248         fclose(file);
249         return ret;
250 }
251
252 /**
253  * Get unsigned long sysfs property.
254  *
255  * @param priv
256  *   Pointer to private structure.
257  * @param[in] name
258  *   Entry name relative to sysfs path.
259  * @param[out] value
260  *   Value output buffer.
261  *
262  * @return
263  *   0 on success, negative errno value otherwise and rte_errno is set.
264  */
265 static int
266 mlx4_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value)
267 {
268         int ret;
269         unsigned long value_ret;
270         char value_str[32];
271
272         ret = mlx4_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1));
273         if (ret < 0) {
274                 DEBUG("cannot read %s value from sysfs: %s",
275                       name, strerror(rte_errno));
276                 return ret;
277         }
278         value_str[ret] = '\0';
279         errno = 0;
280         value_ret = strtoul(value_str, NULL, 0);
281         if (errno) {
282                 rte_errno = errno;
283                 DEBUG("invalid %s value `%s': %s", name, value_str,
284                       strerror(rte_errno));
285                 return -rte_errno;
286         }
287         *value = value_ret;
288         return 0;
289 }
290
291 /**
292  * Set unsigned long sysfs property.
293  *
294  * @param priv
295  *   Pointer to private structure.
296  * @param[in] name
297  *   Entry name relative to sysfs path.
298  * @param value
299  *   Value to set.
300  *
301  * @return
302  *   0 on success, negative errno value otherwise and rte_errno is set.
303  */
304 static int
305 mlx4_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value)
306 {
307         int ret;
308         MKSTR(value_str, "%lu", value);
309
310         ret = mlx4_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1));
311         if (ret < 0) {
312                 DEBUG("cannot write %s `%s' (%lu) to sysfs: %s",
313                       name, value_str, value, strerror(rte_errno));
314                 return ret;
315         }
316         return 0;
317 }
318
319 /**
320  * Perform ifreq ioctl() on associated Ethernet device.
321  *
322  * @param[in] priv
323  *   Pointer to private structure.
324  * @param req
325  *   Request number to pass to ioctl().
326  * @param[out] ifr
327  *   Interface request structure output buffer.
328  *
329  * @return
330  *   0 on success, negative errno value otherwise and rte_errno is set.
331  */
332 static int
333 mlx4_ifreq(const struct priv *priv, int req, struct ifreq *ifr)
334 {
335         int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
336         int ret;
337
338         if (sock == -1) {
339                 rte_errno = errno;
340                 return -rte_errno;
341         }
342         ret = mlx4_get_ifname(priv, &ifr->ifr_name);
343         if (!ret && ioctl(sock, req, ifr) == -1) {
344                 rte_errno = errno;
345                 ret = -rte_errno;
346         }
347         close(sock);
348         return ret;
349 }
350
351 /**
352  * Get MAC address by querying netdevice.
353  *
354  * @param[in] priv
355  *   Pointer to private structure.
356  * @param[out] mac
357  *   MAC address output buffer.
358  *
359  * @return
360  *   0 on success, negative errno value otherwise and rte_errno is set.
361  */
362 int
363 mlx4_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN])
364 {
365         struct ifreq request;
366         int ret = mlx4_ifreq(priv, SIOCGIFHWADDR, &request);
367
368         if (ret)
369                 return ret;
370         memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
371         return 0;
372 }
373
374 /**
375  * Get device MTU.
376  *
377  * @param priv
378  *   Pointer to private structure.
379  * @param[out] mtu
380  *   MTU value output buffer.
381  *
382  * @return
383  *   0 on success, negative errno value otherwise and rte_errno is set.
384  */
385 int
386 mlx4_mtu_get(struct priv *priv, uint16_t *mtu)
387 {
388         unsigned long ulong_mtu = 0;
389         int ret = mlx4_get_sysfs_ulong(priv, "mtu", &ulong_mtu);
390
391         if (ret)
392                 return ret;
393         *mtu = ulong_mtu;
394         return 0;
395 }
396
397 /**
398  * DPDK callback to change the MTU.
399  *
400  * @param priv
401  *   Pointer to Ethernet device structure.
402  * @param mtu
403  *   MTU value to set.
404  *
405  * @return
406  *   0 on success, negative errno value otherwise and rte_errno is set.
407  */
408 int
409 mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
410 {
411         struct priv *priv = dev->data->dev_private;
412         uint16_t new_mtu;
413         int ret = mlx4_set_sysfs_ulong(priv, "mtu", mtu);
414
415         if (ret)
416                 return ret;
417         ret = mlx4_mtu_get(priv, &new_mtu);
418         if (ret)
419                 return ret;
420         if (new_mtu == mtu) {
421                 priv->mtu = mtu;
422                 return 0;
423         }
424         rte_errno = EINVAL;
425         return -rte_errno;
426 }
427
428 /**
429  * Set device flags.
430  *
431  * @param priv
432  *   Pointer to private structure.
433  * @param keep
434  *   Bitmask for flags that must remain untouched.
435  * @param flags
436  *   Bitmask for flags to modify.
437  *
438  * @return
439  *   0 on success, negative errno value otherwise and rte_errno is set.
440  */
441 static int
442 mlx4_set_flags(struct priv *priv, unsigned int keep, unsigned int flags)
443 {
444         unsigned long tmp = 0;
445         int ret = mlx4_get_sysfs_ulong(priv, "flags", &tmp);
446
447         if (ret)
448                 return ret;
449         tmp &= keep;
450         tmp |= (flags & (~keep));
451         return mlx4_set_sysfs_ulong(priv, "flags", tmp);
452 }
453
454 /**
455  * Change the link state (UP / DOWN).
456  *
457  * @param priv
458  *   Pointer to Ethernet device private data.
459  * @param up
460  *   Nonzero for link up, otherwise link down.
461  *
462  * @return
463  *   0 on success, negative errno value otherwise and rte_errno is set.
464  */
465 static int
466 mlx4_dev_set_link(struct priv *priv, int up)
467 {
468         struct rte_eth_dev *dev = priv->dev;
469         int err;
470
471         if (up) {
472                 err = mlx4_set_flags(priv, ~IFF_UP, IFF_UP);
473                 if (err)
474                         return err;
475                 dev->rx_pkt_burst = mlx4_rx_burst;
476         } else {
477                 err = mlx4_set_flags(priv, ~IFF_UP, ~IFF_UP);
478                 if (err)
479                         return err;
480                 dev->rx_pkt_burst = mlx4_rx_burst_removed;
481                 dev->tx_pkt_burst = mlx4_tx_burst_removed;
482         }
483         return 0;
484 }
485
486 /**
487  * DPDK callback to bring the link DOWN.
488  *
489  * @param dev
490  *   Pointer to Ethernet device structure.
491  *
492  * @return
493  *   0 on success, negative errno value otherwise and rte_errno is set.
494  */
495 int
496 mlx4_dev_set_link_down(struct rte_eth_dev *dev)
497 {
498         struct priv *priv = dev->data->dev_private;
499
500         return mlx4_dev_set_link(priv, 0);
501 }
502
503 /**
504  * DPDK callback to bring the link UP.
505  *
506  * @param dev
507  *   Pointer to Ethernet device structure.
508  *
509  * @return
510  *   0 on success, negative errno value otherwise and rte_errno is set.
511  */
512 int
513 mlx4_dev_set_link_up(struct rte_eth_dev *dev)
514 {
515         struct priv *priv = dev->data->dev_private;
516
517         return mlx4_dev_set_link(priv, 1);
518 }
519
520 /**
521  * DPDK callback to get information about the device.
522  *
523  * @param dev
524  *   Pointer to Ethernet device structure.
525  * @param[out] info
526  *   Info structure output buffer.
527  */
528 void
529 mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
530 {
531         struct priv *priv = dev->data->dev_private;
532         unsigned int max;
533         char ifname[IF_NAMESIZE];
534
535         info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
536         if (priv == NULL)
537                 return;
538         /* FIXME: we should ask the device for these values. */
539         info->min_rx_bufsize = 32;
540         info->max_rx_pktlen = 65536;
541         /*
542          * Since we need one CQ per QP, the limit is the minimum number
543          * between the two values.
544          */
545         max = ((priv->device_attr.max_cq > priv->device_attr.max_qp) ?
546                priv->device_attr.max_qp : priv->device_attr.max_cq);
547         /* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
548         if (max >= 65535)
549                 max = 65535;
550         info->max_rx_queues = max;
551         info->max_tx_queues = max;
552         /* Last array entry is reserved for broadcast. */
553         info->max_mac_addrs = 1;
554         info->rx_offload_capa = 0;
555         info->tx_offload_capa = 0;
556         if (mlx4_get_ifname(priv, &ifname) == 0)
557                 info->if_index = if_nametoindex(ifname);
558         info->speed_capa =
559                         ETH_LINK_SPEED_1G |
560                         ETH_LINK_SPEED_10G |
561                         ETH_LINK_SPEED_20G |
562                         ETH_LINK_SPEED_40G |
563                         ETH_LINK_SPEED_56G;
564 }
565
566 /**
567  * DPDK callback to get device statistics.
568  *
569  * @param dev
570  *   Pointer to Ethernet device structure.
571  * @param[out] stats
572  *   Stats structure output buffer.
573  */
574 int
575 mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
576 {
577         struct rte_eth_stats tmp;
578         unsigned int i;
579         unsigned int idx;
580
581         memset(&tmp, 0, sizeof(tmp));
582         /* Add software counters. */
583         for (i = 0; i != dev->data->nb_rx_queues; ++i) {
584                 struct rxq *rxq = dev->data->rx_queues[i];
585
586                 if (rxq == NULL)
587                         continue;
588                 idx = rxq->stats.idx;
589                 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
590                         tmp.q_ipackets[idx] += rxq->stats.ipackets;
591                         tmp.q_ibytes[idx] += rxq->stats.ibytes;
592                         tmp.q_errors[idx] += (rxq->stats.idropped +
593                                               rxq->stats.rx_nombuf);
594                 }
595                 tmp.ipackets += rxq->stats.ipackets;
596                 tmp.ibytes += rxq->stats.ibytes;
597                 tmp.ierrors += rxq->stats.idropped;
598                 tmp.rx_nombuf += rxq->stats.rx_nombuf;
599         }
600         for (i = 0; i != dev->data->nb_tx_queues; ++i) {
601                 struct txq *txq = dev->data->tx_queues[i];
602
603                 if (txq == NULL)
604                         continue;
605                 idx = txq->stats.idx;
606                 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
607                         tmp.q_opackets[idx] += txq->stats.opackets;
608                         tmp.q_obytes[idx] += txq->stats.obytes;
609                         tmp.q_errors[idx] += txq->stats.odropped;
610                 }
611                 tmp.opackets += txq->stats.opackets;
612                 tmp.obytes += txq->stats.obytes;
613                 tmp.oerrors += txq->stats.odropped;
614         }
615         *stats = tmp;
616         return 0;
617 }
618
619 /**
620  * DPDK callback to clear device statistics.
621  *
622  * @param dev
623  *   Pointer to Ethernet device structure.
624  */
625 void
626 mlx4_stats_reset(struct rte_eth_dev *dev)
627 {
628         unsigned int i;
629
630         for (i = 0; i != dev->data->nb_rx_queues; ++i) {
631                 struct rxq *rxq = dev->data->rx_queues[i];
632
633                 if (rxq)
634                         rxq->stats = (struct mlx4_rxq_stats){
635                                 .idx = rxq->stats.idx,
636                         };
637         }
638         for (i = 0; i != dev->data->nb_tx_queues; ++i) {
639                 struct txq *txq = dev->data->tx_queues[i];
640
641                 if (txq)
642                         txq->stats = (struct mlx4_txq_stats){
643                                 .idx = txq->stats.idx,
644                         };
645         }
646 }
647
648 /**
649  * DPDK callback to retrieve physical link information.
650  *
651  * @param dev
652  *   Pointer to Ethernet device structure.
653  * @param wait_to_complete
654  *   Wait for request completion (ignored).
655  *
656  * @return
657  *   0 on success, negative errno value otherwise and rte_errno is set.
658  */
659 int
660 mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete)
661 {
662         const struct priv *priv = dev->data->dev_private;
663         struct ethtool_cmd edata = {
664                 .cmd = ETHTOOL_GSET,
665         };
666         struct ifreq ifr;
667         struct rte_eth_link dev_link;
668         int link_speed = 0;
669
670         if (priv == NULL) {
671                 rte_errno = EINVAL;
672                 return -rte_errno;
673         }
674         (void)wait_to_complete;
675         if (mlx4_ifreq(priv, SIOCGIFFLAGS, &ifr)) {
676                 WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(rte_errno));
677                 return -rte_errno;
678         }
679         memset(&dev_link, 0, sizeof(dev_link));
680         dev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&
681                                 (ifr.ifr_flags & IFF_RUNNING));
682         ifr.ifr_data = (void *)&edata;
683         if (mlx4_ifreq(priv, SIOCETHTOOL, &ifr)) {
684                 WARN("ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s",
685                      strerror(rte_errno));
686                 return -rte_errno;
687         }
688         link_speed = ethtool_cmd_speed(&edata);
689         if (link_speed == -1)
690                 dev_link.link_speed = 0;
691         else
692                 dev_link.link_speed = link_speed;
693         dev_link.link_duplex = ((edata.duplex == DUPLEX_HALF) ?
694                                 ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
695         dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
696                                   ETH_LINK_SPEED_FIXED);
697         dev->data->dev_link = dev_link;
698         return 0;
699 }
700
701 /**
702  * DPDK callback to get flow control status.
703  *
704  * @param dev
705  *   Pointer to Ethernet device structure.
706  * @param[out] fc_conf
707  *   Flow control output buffer.
708  *
709  * @return
710  *   0 on success, negative errno value otherwise and rte_errno is set.
711  */
712 int
713 mlx4_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
714 {
715         struct priv *priv = dev->data->dev_private;
716         struct ifreq ifr;
717         struct ethtool_pauseparam ethpause = {
718                 .cmd = ETHTOOL_GPAUSEPARAM,
719         };
720         int ret;
721
722         ifr.ifr_data = (void *)&ethpause;
723         if (mlx4_ifreq(priv, SIOCETHTOOL, &ifr)) {
724                 ret = rte_errno;
725                 WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
726                      " failed: %s",
727                      strerror(rte_errno));
728                 goto out;
729         }
730         fc_conf->autoneg = ethpause.autoneg;
731         if (ethpause.rx_pause && ethpause.tx_pause)
732                 fc_conf->mode = RTE_FC_FULL;
733         else if (ethpause.rx_pause)
734                 fc_conf->mode = RTE_FC_RX_PAUSE;
735         else if (ethpause.tx_pause)
736                 fc_conf->mode = RTE_FC_TX_PAUSE;
737         else
738                 fc_conf->mode = RTE_FC_NONE;
739         ret = 0;
740 out:
741         assert(ret >= 0);
742         return -ret;
743 }
744
745 /**
746  * DPDK callback to modify flow control parameters.
747  *
748  * @param dev
749  *   Pointer to Ethernet device structure.
750  * @param[in] fc_conf
751  *   Flow control parameters.
752  *
753  * @return
754  *   0 on success, negative errno value otherwise and rte_errno is set.
755  */
756 int
757 mlx4_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
758 {
759         struct priv *priv = dev->data->dev_private;
760         struct ifreq ifr;
761         struct ethtool_pauseparam ethpause = {
762                 .cmd = ETHTOOL_SPAUSEPARAM,
763         };
764         int ret;
765
766         ifr.ifr_data = (void *)&ethpause;
767         ethpause.autoneg = fc_conf->autoneg;
768         if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
769             (fc_conf->mode & RTE_FC_RX_PAUSE))
770                 ethpause.rx_pause = 1;
771         else
772                 ethpause.rx_pause = 0;
773         if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
774             (fc_conf->mode & RTE_FC_TX_PAUSE))
775                 ethpause.tx_pause = 1;
776         else
777                 ethpause.tx_pause = 0;
778         if (mlx4_ifreq(priv, SIOCETHTOOL, &ifr)) {
779                 ret = rte_errno;
780                 WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
781                      " failed: %s",
782                      strerror(rte_errno));
783                 goto out;
784         }
785         ret = 0;
786 out:
787         assert(ret >= 0);
788         return -ret;
789 }