197f17497SC.J. Collier/*-
297f17497SC.J. Collier *   BSD LICENSE
397f17497SC.J. Collier *
497f17497SC.J. Collier *   Copyright 2015 6WIND S.A.
597f17497SC.J. Collier *   Copyright 2015 Mellanox.
697f17497SC.J. Collier *
797f17497SC.J. Collier *   Redistribution and use in source and binary forms, with or without
897f17497SC.J. Collier *   modification, are permitted provided that the following conditions
997f17497SC.J. Collier *   are met:
1097f17497SC.J. Collier *
1197f17497SC.J. Collier *     * Redistributions of source code must retain the above copyright
1297f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer.
1397f17497SC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
1497f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer in
1597f17497SC.J. Collier *       the documentation and/or other materials provided with the
1697f17497SC.J. Collier *       distribution.
1797f17497SC.J. Collier *     * Neither the name of 6WIND S.A. nor the names of its
1897f17497SC.J. Collier *       contributors may be used to endorse or promote products derived
1997f17497SC.J. Collier *       from this software without specific prior written permission.
2097f17497SC.J. Collier *
2197f17497SC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2297f17497SC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2397f17497SC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2497f17497SC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2597f17497SC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2697f17497SC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2797f17497SC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2897f17497SC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2997f17497SC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3097f17497SC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3197f17497SC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3297f17497SC.J. Collier */
3397f17497SC.J. Collier
3497f17497SC.J. Collier#ifndef RTE_PMD_MLX5_H_
3597f17497SC.J. Collier#define RTE_PMD_MLX5_H_
3697f17497SC.J. Collier
3797f17497SC.J. Collier#include <stddef.h>
3897f17497SC.J. Collier#include <stdint.h>
3997f17497SC.J. Collier#include <limits.h>
4097f17497SC.J. Collier#include <net/if.h>
4197f17497SC.J. Collier#include <netinet/in.h>
4297f17497SC.J. Collier
4397f17497SC.J. Collier/* Verbs header. */
4497f17497SC.J. Collier/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
4597f17497SC.J. Collier#ifdef PEDANTIC
4632e04ea0SChristian Ehrhardt#pragma GCC diagnostic ignored "-Wpedantic"
4797f17497SC.J. Collier#endif
4897f17497SC.J. Collier#include <infiniband/verbs.h>
4997f17497SC.J. Collier#ifdef PEDANTIC
5032e04ea0SChristian Ehrhardt#pragma GCC diagnostic error "-Wpedantic"
5197f17497SC.J. Collier#endif
5297f17497SC.J. Collier
5397f17497SC.J. Collier/* DPDK headers don't like -pedantic. */
5497f17497SC.J. Collier#ifdef PEDANTIC
5532e04ea0SChristian Ehrhardt#pragma GCC diagnostic ignored "-Wpedantic"
5697f17497SC.J. Collier#endif
5797f17497SC.J. Collier#include <rte_ether.h>
5897f17497SC.J. Collier#include <rte_ethdev.h>
5997f17497SC.J. Collier#include <rte_spinlock.h>
6097f17497SC.J. Collier#include <rte_interrupts.h>
6197f17497SC.J. Collier#include <rte_errno.h>
6297f17497SC.J. Collier#ifdef PEDANTIC
6332e04ea0SChristian Ehrhardt#pragma GCC diagnostic error "-Wpedantic"
6497f17497SC.J. Collier#endif
6597f17497SC.J. Collier
6697f17497SC.J. Collier#include "mlx5_utils.h"
6797f17497SC.J. Collier#include "mlx5_rxtx.h"
6897f17497SC.J. Collier#include "mlx5_autoconf.h"
6997f17497SC.J. Collier#include "mlx5_defs.h"
7097f17497SC.J. Collier
718b25d1adSChristian Ehrhardt#if !defined(HAVE_VERBS_IBV_EXP_CQ_COMPRESSED_CQE) || \
728b25d1adSChristian Ehrhardt	!defined(HAVE_VERBS_MLX5_ETH_VLAN_INLINE_HEADER_SIZE)
738b25d1adSChristian Ehrhardt#error Mellanox OFED >= 3.3 is required, please refer to the documentation.
748b25d1adSChristian Ehrhardt#endif
758b25d1adSChristian Ehrhardt
7697f17497SC.J. Collierenum {
7797f17497SC.J. Collier	PCI_VENDOR_ID_MELLANOX = 0x15b3,
7897f17497SC.J. Collier};
7997f17497SC.J. Collier
8097f17497SC.J. Collierenum {
8197f17497SC.J. Collier	PCI_DEVICE_ID_MELLANOX_CONNECTX4 = 0x1013,
8297f17497SC.J. Collier	PCI_DEVICE_ID_MELLANOX_CONNECTX4VF = 0x1014,
8397f17497SC.J. Collier	PCI_DEVICE_ID_MELLANOX_CONNECTX4LX = 0x1015,
8497f17497SC.J. Collier	PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF = 0x1016,
8597f17497SC.J. Collier};
8697f17497SC.J. Collier
8797f17497SC.J. Collierstruct priv {
8897f17497SC.J. Collier	struct rte_eth_dev *dev; /* Ethernet device. */
8997f17497SC.J. Collier	struct ibv_context *ctx; /* Verbs context. */
9097f17497SC.J. Collier	struct ibv_device_attr device_attr; /* Device properties. */
9197f17497SC.J. Collier	struct ibv_pd *pd; /* Protection Domain. */
9297f17497SC.J. Collier	/*
9397f17497SC.J. Collier	 * MAC addresses array and configuration bit-field.
9497f17497SC.J. Collier	 * An extra entry that cannot be modified by the DPDK is reserved
9597f17497SC.J. Collier	 * for broadcast frames (destination MAC address ff:ff:ff:ff:ff:ff).
9697f17497SC.J. Collier	 */
9797f17497SC.J. Collier	struct ether_addr mac[MLX5_MAX_MAC_ADDRESSES];
9897f17497SC.J. Collier	BITFIELD_DECLARE(mac_configured, uint32_t, MLX5_MAX_MAC_ADDRESSES);
9997f17497SC.J. Collier	uint16_t vlan_filter[MLX5_MAX_VLAN_IDS]; /* VLAN filters table. */
10097f17497SC.J. Collier	unsigned int vlan_filter_n; /* Number of configured VLAN filters. */
10197f17497SC.J. Collier	/* Device properties. */
10297f17497SC.J. Collier	uint16_t mtu; /* Configured MTU. */
10397f17497SC.J. Collier	uint8_t port; /* Physical port number. */
10497f17497SC.J. Collier	unsigned int started:1; /* Device started, flows enabled. */
10597f17497SC.J. Collier	unsigned int promisc_req:1; /* Promiscuous mode requested. */
10697f17497SC.J. Collier	unsigned int allmulti_req:1; /* All multicast mode requested. */
10797f17497SC.J. Collier	unsigned int hw_csum:1; /* Checksum offload is supported. */
10897f17497SC.J. Collier	unsigned int hw_csum_l2tun:1; /* Same for L2 tunnels. */
10997f17497SC.J. Collier	unsigned int hw_vlan_strip:1; /* VLAN stripping is supported. */
11097f17497SC.J. Collier	unsigned int hw_fcs_strip:1; /* FCS stripping is supported. */
11197f17497SC.J. Collier	unsigned int hw_padding:1; /* End alignment padding is supported. */
1128b25d1adSChristian Ehrhardt	unsigned int sriov:1; /* This is a VF or PF with VF devices. */
11397f17497SC.J. Collier	unsigned int mps:1; /* Whether multi-packet send is supported. */
1148b25d1adSChristian Ehrhardt	unsigned int cqe_comp:1; /* Whether CQE compression is enabled. */
11597f17497SC.J. Collier	unsigned int pending_alarm:1; /* An alarm is pending. */
1168b25d1adSChristian Ehrhardt	unsigned int txq_inline; /* Maximum packet size for inlining. */
1178b25d1adSChristian Ehrhardt	unsigned int txqs_inline; /* Queue number threshold for inlining. */
11897f17497SC.J. Collier	/* RX/TX queues. */
11997f17497SC.J. Collier	unsigned int rxqs_n; /* RX queues array size. */
12097f17497SC.J. Collier	unsigned int txqs_n; /* TX queues array size. */
12197f17497SC.J. Collier	struct rxq *(*rxqs)[]; /* RX queues. */
12297f17497SC.J. Collier	struct txq *(*txqs)[]; /* TX queues. */
12397f17497SC.J. Collier	/* Indirection tables referencing all RX WQs. */
12497f17497SC.J. Collier	struct ibv_exp_rwq_ind_table *(*ind_tables)[];
12597f17497SC.J. Collier	unsigned int ind_tables_n; /* Number of indirection tables. */
12697f17497SC.J. Collier	unsigned int ind_table_max_size; /* Maximum indirection table size. */
12797f17497SC.J. Collier	/* Hash RX QPs feeding the indirection table. */
12897f17497SC.J. Collier	struct hash_rxq (*hash_rxqs)[];
12997f17497SC.J. Collier	unsigned int hash_rxqs_n; /* Hash RX QPs array size. */
13097f17497SC.J. Collier	/* RSS configuration array indexed by hash RX queue type. */
13197f17497SC.J. Collier	struct rte_eth_rss_conf *(*rss_conf)[];
13297f17497SC.J. Collier	uint64_t rss_hf; /* RSS DPDK bit field of active RSS. */
13397f17497SC.J. Collier	struct rte_intr_handle intr_handle; /* Interrupt handler. */
13497f17497SC.J. Collier	unsigned int (*reta_idx)[]; /* RETA index table. */
13597f17497SC.J. Collier	unsigned int reta_idx_n; /* RETA index size. */
13697f17497SC.J. Collier	struct fdir_filter_list *fdir_filter_list; /* Flow director rules. */
13732e04ea0SChristian Ehrhardt	struct fdir_queue *fdir_drop_queue; /* Flow director drop queue. */
13832e04ea0SChristian Ehrhardt	uint32_t link_speed_capa; /* Link speed capabilities. */
13997f17497SC.J. Collier	rte_spinlock_t lock; /* Lock for control functions. */
14097f17497SC.J. Collier};
14197f17497SC.J. Collier
14297f17497SC.J. Collier/* Local storage for secondary process data. */
14397f17497SC.J. Collierstruct mlx5_secondary_data {
14497f17497SC.J. Collier	struct rte_eth_dev_data data; /* Local device data. */
14597f17497SC.J. Collier	struct priv *primary_priv; /* Private structure from primary. */
14697f17497SC.J. Collier	struct rte_eth_dev_data *shared_dev_data; /* Shared device data. */
14797f17497SC.J. Collier	rte_spinlock_t lock; /* Port configuration lock. */
14897f17497SC.J. Collier} mlx5_secondary_data[RTE_MAX_ETHPORTS];
14997f17497SC.J. Collier
15097f17497SC.J. Collier/**
15197f17497SC.J. Collier * Lock private structure to protect it from concurrent access in the
15297f17497SC.J. Collier * control path.
15397f17497SC.J. Collier *
15497f17497SC.J. Collier * @param priv
15597f17497SC.J. Collier *   Pointer to private structure.
15697f17497SC.J. Collier */
15797f17497SC.J. Collierstatic inline void
15897f17497SC.J. Collierpriv_lock(struct priv *priv)
15997f17497SC.J. Collier{
16097f17497SC.J. Collier	rte_spinlock_lock(&priv->lock);
16197f17497SC.J. Collier}
16297f17497SC.J. Collier
16339157ec0SLuca Boccassi/**
16439157ec0SLuca Boccassi * Try to lock private structure to protect it from concurrent access in the
16539157ec0SLuca Boccassi * control path.
16639157ec0SLuca Boccassi *
16739157ec0SLuca Boccassi * @param priv
16839157ec0SLuca Boccassi *   Pointer to private structure.
16939157ec0SLuca Boccassi *
17039157ec0SLuca Boccassi * @return
17139157ec0SLuca Boccassi *   1 if the lock is successfully taken; 0 otherwise.
17239157ec0SLuca Boccassi */
17339157ec0SLuca Boccassistatic inline int
17439157ec0SLuca Boccassipriv_trylock(struct priv *priv)
17539157ec0SLuca Boccassi{
17639157ec0SLuca Boccassi	return rte_spinlock_trylock(&priv->lock);
17739157ec0SLuca Boccassi}
17839157ec0SLuca Boccassi
17997f17497SC.J. Collier/**
18097f17497SC.J. Collier * Unlock private structure.
18197f17497SC.J. Collier *
18297f17497SC.J. Collier * @param priv
18397f17497SC.J. Collier *   Pointer to private structure.
18497f17497SC.J. Collier */
18597f17497SC.J. Collierstatic inline void
18697f17497SC.J. Collierpriv_unlock(struct priv *priv)
18797f17497SC.J. Collier{
18897f17497SC.J. Collier	rte_spinlock_unlock(&priv->lock);
18997f17497SC.J. Collier}
19097f17497SC.J. Collier
19197f17497SC.J. Collier/* mlx5.c */
19297f17497SC.J. Collier
19397f17497SC.J. Collierint mlx5_getenv_int(const char *);
19497f17497SC.J. Collier
19597f17497SC.J. Collier/* mlx5_ethdev.c */
19697f17497SC.J. Collier
19797f17497SC.J. Collierstruct priv *mlx5_get_priv(struct rte_eth_dev *dev);
19897f17497SC.J. Collierint mlx5_is_secondary(void);
19997f17497SC.J. Collierint priv_get_ifname(const struct priv *, char (*)[IF_NAMESIZE]);
20097f17497SC.J. Collierint priv_ifreq(const struct priv *, int req, struct ifreq *);
2018b25d1adSChristian Ehrhardtint priv_get_num_vfs(struct priv *, uint16_t *);
20297f17497SC.J. Collierint priv_get_mtu(struct priv *, uint16_t *);
20397f17497SC.J. Collierint priv_set_flags(struct priv *, unsigned int, unsigned int);
20497f17497SC.J. Collierint mlx5_dev_configure(struct rte_eth_dev *);
20597f17497SC.J. Colliervoid mlx5_dev_infos_get(struct rte_eth_dev *, struct rte_eth_dev_info *);
20697f17497SC.J. Collierconst uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev);
20732e04ea0SChristian Ehrhardtint mlx5_link_update_unlocked(struct rte_eth_dev *, int);
20897f17497SC.J. Collierint mlx5_link_update(struct rte_eth_dev *, int);
20997f17497SC.J. Collierint mlx5_dev_set_mtu(struct rte_eth_dev *, uint16_t);
21097f17497SC.J. Collierint mlx5_dev_get_flow_ctrl(struct rte_eth_dev *, struct rte_eth_fc_conf *);
21197f17497SC.J. Collierint mlx5_dev_set_flow_ctrl(struct rte_eth_dev *, struct rte_eth_fc_conf *);
21297f17497SC.J. Collierint mlx5_ibv_device_to_pci_addr(const struct ibv_device *,
21397f17497SC.J. Collier				struct rte_pci_addr *);
21497f17497SC.J. Colliervoid mlx5_dev_link_status_handler(void *);
21597f17497SC.J. Colliervoid mlx5_dev_interrupt_handler(struct rte_intr_handle *, void *);
21697f17497SC.J. Colliervoid priv_dev_interrupt_handler_uninstall(struct priv *, struct rte_eth_dev *);
21797f17497SC.J. Colliervoid priv_dev_interrupt_handler_install(struct priv *, struct rte_eth_dev *);
21897f17497SC.J. Collierint mlx5_set_link_down(struct rte_eth_dev *dev);
21997f17497SC.J. Collierint mlx5_set_link_up(struct rte_eth_dev *dev);
22097f17497SC.J. Collierstruct priv *mlx5_secondary_data_setup(struct priv *priv);
2218b25d1adSChristian Ehrhardtvoid priv_select_tx_function(struct priv *);
2228b25d1adSChristian Ehrhardtvoid priv_select_rx_function(struct priv *);
22397f17497SC.J. Collier
22497f17497SC.J. Collier/* mlx5_mac.c */
22597f17497SC.J. Collier
22697f17497SC.J. Collierint priv_get_mac(struct priv *, uint8_t (*)[ETHER_ADDR_LEN]);
22797f17497SC.J. Colliervoid hash_rxq_mac_addrs_del(struct hash_rxq *);
22897f17497SC.J. Colliervoid priv_mac_addrs_disable(struct priv *);
22997f17497SC.J. Colliervoid mlx5_mac_addr_remove(struct rte_eth_dev *, uint32_t);
23097f17497SC.J. Collierint hash_rxq_mac_addrs_add(struct hash_rxq *);
23197f17497SC.J. Collierint priv_mac_addr_add(struct priv *, unsigned int,
23297f17497SC.J. Collier		      const uint8_t (*)[ETHER_ADDR_LEN]);
23397f17497SC.J. Collierint priv_mac_addrs_enable(struct priv *);
23497f17497SC.J. Colliervoid mlx5_mac_addr_add(struct rte_eth_dev *, struct ether_addr *, uint32_t,
23597f17497SC.J. Collier		       uint32_t);
23697f17497SC.J. Colliervoid mlx5_mac_addr_set(struct rte_eth_dev *, struct ether_addr *);
23797f17497SC.J. Collier
23897f17497SC.J. Collier/* mlx5_rss.c */
23997f17497SC.J. Collier
24097f17497SC.J. Collierint rss_hash_rss_conf_new_key(struct priv *, const uint8_t *, unsigned int,
24197f17497SC.J. Collier			      uint64_t);
24297f17497SC.J. Collierint mlx5_rss_hash_update(struct rte_eth_dev *, struct rte_eth_rss_conf *);
24397f17497SC.J. Collierint mlx5_rss_hash_conf_get(struct rte_eth_dev *, struct rte_eth_rss_conf *);
24497f17497SC.J. Collierint priv_rss_reta_index_resize(struct priv *, unsigned int);
24597f17497SC.J. Collierint mlx5_dev_rss_reta_query(struct rte_eth_dev *,
24697f17497SC.J. Collier			    struct rte_eth_rss_reta_entry64 *, uint16_t);
24797f17497SC.J. Collierint mlx5_dev_rss_reta_update(struct rte_eth_dev *,
24897f17497SC.J. Collier			     struct rte_eth_rss_reta_entry64 *, uint16_t);
24997f17497SC.J. Collier
25097f17497SC.J. Collier/* mlx5_rxmode.c */
25197f17497SC.J. Collier
25297f17497SC.J. Collierint priv_special_flow_enable(struct priv *, enum hash_rxq_flow_type);
25397f17497SC.J. Colliervoid priv_special_flow_disable(struct priv *, enum hash_rxq_flow_type);
25497f17497SC.J. Collierint priv_special_flow_enable_all(struct priv *);
25597f17497SC.J. Colliervoid priv_special_flow_disable_all(struct priv *);
25697f17497SC.J. Colliervoid mlx5_promiscuous_enable(struct rte_eth_dev *);
25797f17497SC.J. Colliervoid mlx5_promiscuous_disable(struct rte_eth_dev *);
25897f17497SC.J. Colliervoid mlx5_allmulticast_enable(struct rte_eth_dev *);
25997f17497SC.J. Colliervoid mlx5_allmulticast_disable(struct rte_eth_dev *);
26097f17497SC.J. Collier
26197f17497SC.J. Collier/* mlx5_stats.c */
26297f17497SC.J. Collier
26397f17497SC.J. Colliervoid mlx5_stats_get(struct rte_eth_dev *, struct rte_eth_stats *);
26497f17497SC.J. Colliervoid mlx5_stats_reset(struct rte_eth_dev *);
26597f17497SC.J. Collier
26697f17497SC.J. Collier/* mlx5_vlan.c */
26797f17497SC.J. Collier
26897f17497SC.J. Collierint mlx5_vlan_filter_set(struct rte_eth_dev *, uint16_t, int);
26997f17497SC.J. Colliervoid mlx5_vlan_offload_set(struct rte_eth_dev *, int);
27097f17497SC.J. Colliervoid mlx5_vlan_strip_queue_set(struct rte_eth_dev *, uint16_t, int);
27197f17497SC.J. Collier
27297f17497SC.J. Collier/* mlx5_trigger.c */
27397f17497SC.J. Collier
27497f17497SC.J. Collierint mlx5_dev_start(struct rte_eth_dev *);
27597f17497SC.J. Colliervoid mlx5_dev_stop(struct rte_eth_dev *);
27697f17497SC.J. Collier
27797f17497SC.J. Collier/* mlx5_fdir.c */
27897f17497SC.J. Collier
27932e04ea0SChristian Ehrhardtvoid priv_fdir_queue_destroy(struct priv *, struct fdir_queue *);
28097f17497SC.J. Collierint fdir_init_filters_list(struct priv *);
28197f17497SC.J. Colliervoid priv_fdir_delete_filters_list(struct priv *);
28297f17497SC.J. Colliervoid priv_fdir_disable(struct priv *);
28397f17497SC.J. Colliervoid priv_fdir_enable(struct priv *);
28497f17497SC.J. Collierint mlx5_dev_filter_ctrl(struct rte_eth_dev *, enum rte_filter_type,
28597f17497SC.J. Collier			 enum rte_filter_op, void *);
28697f17497SC.J. Collier
28797f17497SC.J. Collier#endif /* RTE_PMD_MLX5_H_ */
288