net/mlx4: support a device removal check operation
[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 #include <sys/queue.h>
40
41 /* Verbs headers do not support -pedantic. */
42 #ifdef PEDANTIC
43 #pragma GCC diagnostic ignored "-Wpedantic"
44 #endif
45 #include <infiniband/verbs.h>
46 #ifdef PEDANTIC
47 #pragma GCC diagnostic error "-Wpedantic"
48 #endif
49
50 #include <rte_ethdev.h>
51 #include <rte_ether.h>
52 #include <rte_interrupts.h>
53 #include <rte_mempool.h>
54 #include <rte_spinlock.h>
55
56 #ifndef IBV_RX_HASH_INNER
57 /** This is not necessarily defined by supported RDMA core versions. */
58 #define IBV_RX_HASH_INNER (1ull << 31)
59 #endif /* IBV_RX_HASH_INNER */
60
61 /** Maximum number of simultaneous MAC addresses. This value is arbitrary. */
62 #define MLX4_MAX_MAC_ADDRESSES 128
63
64 /** Request send completion once in every 64 sends, might be less. */
65 #define MLX4_PMD_TX_PER_COMP_REQ 64
66
67 /** Maximum size for inline data. */
68 #define MLX4_PMD_MAX_INLINE 0
69
70 /** Fixed RSS hash key size in bytes. Cannot be modified. */
71 #define MLX4_RSS_HASH_KEY_SIZE 40
72
73 /**
74  * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP
75  * from which buffers are to be transmitted will have to be mapped by this
76  * driver to their own Memory Region (MR). This is a slow operation.
77  *
78  * This value is always 1 for RX queues.
79  */
80 #ifndef MLX4_PMD_TX_MP_CACHE
81 #define MLX4_PMD_TX_MP_CACHE 8
82 #endif
83
84 /** Interrupt alarm timeout value in microseconds. */
85 #define MLX4_INTR_ALARM_TIMEOUT 100000
86
87 /** Port parameter. */
88 #define MLX4_PMD_PORT_KVARG "port"
89
90 enum {
91         PCI_VENDOR_ID_MELLANOX = 0x15b3,
92 };
93
94 enum {
95         PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
96         PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
97         PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
98 };
99
100 /** Driver name reported to lower layers and used in log output. */
101 #define MLX4_DRIVER_NAME "net_mlx4"
102
103 struct mlx4_drop;
104 struct mlx4_rss;
105 struct rxq;
106 struct txq;
107 struct rte_flow;
108
109 /** Memory region descriptor. */
110 struct mlx4_mr {
111         LIST_ENTRY(mlx4_mr) next; /**< Next entry in list. */
112         uintptr_t start; /**< Base address for memory region. */
113         uintptr_t end; /**< End address for memory region. */
114         uint32_t lkey; /**< L_Key extracted from @p mr. */
115         uint32_t refcnt; /**< Reference count for this object. */
116         struct priv *priv; /**< Back pointer to private data. */
117         struct ibv_mr *mr; /**< Memory region associated with @p mp. */
118         struct rte_mempool *mp; /**< Target memory pool (mempool). */
119 };
120
121 /** Private data structure. */
122 struct priv {
123         struct rte_eth_dev *dev; /**< Ethernet device. */
124         struct ibv_context *ctx; /**< Verbs context. */
125         struct ibv_device_attr device_attr; /**< Device properties. */
126         struct ibv_pd *pd; /**< Protection Domain. */
127         /* Device properties. */
128         uint16_t mtu; /**< Configured MTU. */
129         uint8_t port; /**< Physical port number. */
130         uint32_t started:1; /**< Device started, flows enabled. */
131         uint32_t vf:1; /**< This is a VF device. */
132         uint32_t intr_alarm:1; /**< An interrupt alarm is scheduled. */
133         uint32_t isolated:1; /**< Toggle isolated mode. */
134         uint32_t hw_csum:1; /**< Checksum offload is supported. */
135         uint32_t hw_csum_l2tun:1; /**< Checksum support for L2 tunnels. */
136         uint64_t hw_rss_sup; /**< Supported RSS hash fields (Verbs format). */
137         struct rte_intr_handle intr_handle; /**< Port interrupt handle. */
138         struct mlx4_drop *drop; /**< Shared resources for drop flow rules. */
139         LIST_HEAD(, mlx4_rss) rss; /**< Shared targets for Rx flow rules. */
140         LIST_HEAD(, rte_flow) flows; /**< Configured flow rule handles. */
141         LIST_HEAD(, mlx4_mr) mr; /**< Registered memory regions. */
142         rte_spinlock_t mr_lock; /**< Lock for @p mr access. */
143         struct ether_addr mac[MLX4_MAX_MAC_ADDRESSES];
144         /**< Configured MAC addresses. Unused entries are zeroed. */
145 };
146
147 /* mlx4_ethdev.c */
148
149 int mlx4_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]);
150 int mlx4_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN]);
151 int mlx4_mtu_get(struct priv *priv, uint16_t *mtu);
152 int mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
153 int mlx4_dev_set_link_down(struct rte_eth_dev *dev);
154 int mlx4_dev_set_link_up(struct rte_eth_dev *dev);
155 void mlx4_promiscuous_enable(struct rte_eth_dev *dev);
156 void mlx4_promiscuous_disable(struct rte_eth_dev *dev);
157 void mlx4_allmulticast_enable(struct rte_eth_dev *dev);
158 void mlx4_allmulticast_disable(struct rte_eth_dev *dev);
159 void mlx4_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
160 int mlx4_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
161                       uint32_t index, uint32_t vmdq);
162 void mlx4_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr);
163 int mlx4_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
164 int mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
165 void mlx4_stats_reset(struct rte_eth_dev *dev);
166 void mlx4_dev_infos_get(struct rte_eth_dev *dev,
167                         struct rte_eth_dev_info *info);
168 int mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete);
169 int mlx4_flow_ctrl_get(struct rte_eth_dev *dev,
170                        struct rte_eth_fc_conf *fc_conf);
171 int mlx4_flow_ctrl_set(struct rte_eth_dev *dev,
172                        struct rte_eth_fc_conf *fc_conf);
173 const uint32_t *mlx4_dev_supported_ptypes_get(struct rte_eth_dev *dev);
174 int mlx4_is_removed(struct rte_eth_dev *dev);
175
176 /* mlx4_intr.c */
177
178 int mlx4_intr_uninstall(struct priv *priv);
179 int mlx4_intr_install(struct priv *priv);
180 int mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx);
181 int mlx4_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx);
182
183 /* mlx4_mr.c */
184
185 struct mlx4_mr *mlx4_mr_get(struct priv *priv, struct rte_mempool *mp);
186 void mlx4_mr_put(struct mlx4_mr *mr);
187 uint32_t mlx4_txq_add_mr(struct txq *txq, struct rte_mempool *mp,
188                          uint32_t i);
189
190 #endif /* RTE_PMD_MLX4_H_ */