ethdev: add return value to stats get dev op
[dpdk.git] / drivers / net / mlx4 / mlx4.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2012 6WIND S.A.
5  *   Copyright 2012 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 #ifndef RTE_PMD_MLX4_H_
35 #define RTE_PMD_MLX4_H_
36
37 #include <net/if.h>
38 #include <stdint.h>
39
40 /* Verbs headers do not support -pedantic. */
41 #ifdef PEDANTIC
42 #pragma GCC diagnostic ignored "-Wpedantic"
43 #endif
44 #include <infiniband/verbs.h>
45 #ifdef PEDANTIC
46 #pragma GCC diagnostic error "-Wpedantic"
47 #endif
48
49 #include <rte_ethdev.h>
50 #include <rte_ether.h>
51 #include <rte_interrupts.h>
52 #include <rte_mempool.h>
53
54 /* Request send completion once in every 64 sends, might be less. */
55 #define MLX4_PMD_TX_PER_COMP_REQ 64
56
57 /* Maximum size for inline data. */
58 #define MLX4_PMD_MAX_INLINE 0
59
60 /*
61  * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP
62  * from which buffers are to be transmitted will have to be mapped by this
63  * driver to their own Memory Region (MR). This is a slow operation.
64  *
65  * This value is always 1 for RX queues.
66  */
67 #ifndef MLX4_PMD_TX_MP_CACHE
68 #define MLX4_PMD_TX_MP_CACHE 8
69 #endif
70
71 /* Interrupt alarm timeout value in microseconds. */
72 #define MLX4_INTR_ALARM_TIMEOUT 100000
73
74 /* Port parameter. */
75 #define MLX4_PMD_PORT_KVARG "port"
76
77 enum {
78         PCI_VENDOR_ID_MELLANOX = 0x15b3,
79 };
80
81 enum {
82         PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
83         PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
84         PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
85 };
86
87 #define MLX4_DRIVER_NAME "net_mlx4"
88
89 struct rxq;
90 struct txq;
91 struct rte_flow;
92
93 struct priv {
94         struct rte_eth_dev *dev; /* Ethernet device. */
95         struct ibv_context *ctx; /* Verbs context. */
96         struct ibv_device_attr device_attr; /* Device properties. */
97         struct ibv_pd *pd; /* Protection Domain. */
98         struct ether_addr mac; /* MAC address. */
99         struct ibv_flow *mac_flow; /* Flow associated with MAC address. */
100         /* Device properties. */
101         uint16_t mtu; /* Configured MTU. */
102         uint8_t port; /* Physical port number. */
103         unsigned int started:1; /* Device started, flows enabled. */
104         unsigned int vf:1; /* This is a VF device. */
105         unsigned int intr_alarm:1; /* An interrupt alarm is scheduled. */
106         unsigned int isolated:1; /* Toggle isolated mode. */
107         struct rte_intr_handle intr_handle; /* Port interrupt handle. */
108         struct rte_flow_drop *flow_drop_queue; /* Flow drop queue. */
109         LIST_HEAD(mlx4_flows, rte_flow) flows;
110 };
111
112 /* mlx4_ethdev.c */
113
114 int mlx4_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]);
115 int mlx4_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN]);
116 int mlx4_mtu_get(struct priv *priv, uint16_t *mtu);
117 int mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
118 int mlx4_dev_set_link_down(struct rte_eth_dev *dev);
119 int mlx4_dev_set_link_up(struct rte_eth_dev *dev);
120 int mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
121 void mlx4_stats_reset(struct rte_eth_dev *dev);
122 void mlx4_dev_infos_get(struct rte_eth_dev *dev,
123                         struct rte_eth_dev_info *info);
124 int mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete);
125 int mlx4_flow_ctrl_get(struct rte_eth_dev *dev,
126                        struct rte_eth_fc_conf *fc_conf);
127 int mlx4_flow_ctrl_set(struct rte_eth_dev *dev,
128                        struct rte_eth_fc_conf *fc_conf);
129
130 /* mlx4_intr.c */
131
132 int mlx4_intr_uninstall(struct priv *priv);
133 int mlx4_intr_install(struct priv *priv);
134 int mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx);
135 int mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx);
136
137 /* mlx4_mr.c */
138
139 struct ibv_mr *mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp);
140
141 #endif /* RTE_PMD_MLX4_H_ */