15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright 2015 6WIND S.A.
55129044dSC.J. Collier *   Copyright 2015 Mellanox.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of 6WIND S.A. nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier/* DPDK headers don't like -pedantic. */
355129044dSC.J. Collier#ifdef PEDANTIC
36c300e355SChristian Ehrhardt#pragma GCC diagnostic ignored "-Wpedantic"
375129044dSC.J. Collier#endif
385129044dSC.J. Collier#include <rte_ether.h>
395129044dSC.J. Collier#include <rte_ethdev.h>
405129044dSC.J. Collier#include <rte_interrupts.h>
415129044dSC.J. Collier#include <rte_alarm.h>
425129044dSC.J. Collier#ifdef PEDANTIC
43c300e355SChristian Ehrhardt#pragma GCC diagnostic error "-Wpedantic"
445129044dSC.J. Collier#endif
455129044dSC.J. Collier
465129044dSC.J. Collier#include "mlx5.h"
475129044dSC.J. Collier#include "mlx5_rxtx.h"
485129044dSC.J. Collier#include "mlx5_utils.h"
495129044dSC.J. Collier
505129044dSC.J. Collier/**
515129044dSC.J. Collier * DPDK callback to start the device.
525129044dSC.J. Collier *
535129044dSC.J. Collier * Simulate device start by attaching all configured flows.
545129044dSC.J. Collier *
555129044dSC.J. Collier * @param dev
565129044dSC.J. Collier *   Pointer to Ethernet device structure.
575129044dSC.J. Collier *
585129044dSC.J. Collier * @return
595129044dSC.J. Collier *   0 on success, negative errno value on failure.
605129044dSC.J. Collier */
615129044dSC.J. Collierint
625129044dSC.J. Colliermlx5_dev_start(struct rte_eth_dev *dev)
635129044dSC.J. Collier{
645129044dSC.J. Collier	struct priv *priv = dev->data->dev_private;
655129044dSC.J. Collier	int err;
665129044dSC.J. Collier
675129044dSC.J. Collier	if (mlx5_is_secondary())
685129044dSC.J. Collier		return -E_RTE_SECONDARY;
695129044dSC.J. Collier
705129044dSC.J. Collier	priv_lock(priv);
715129044dSC.J. Collier	if (priv->started) {
725129044dSC.J. Collier		priv_unlock(priv);
735129044dSC.J. Collier		return 0;
745129044dSC.J. Collier	}
755129044dSC.J. Collier	DEBUG("%p: allocating and configuring hash RX queues", (void *)dev);
765129044dSC.J. Collier	err = priv_create_hash_rxqs(priv);
775129044dSC.J. Collier	if (!err)
785129044dSC.J. Collier		err = priv_rehash_flows(priv);
795129044dSC.J. Collier	if (!err)
805129044dSC.J. Collier		priv->started = 1;
815129044dSC.J. Collier	else {
825129044dSC.J. Collier		ERROR("%p: an error occurred while configuring hash RX queues:"
835129044dSC.J. Collier		      " %s",
845129044dSC.J. Collier		      (void *)priv, strerror(err));
855129044dSC.J. Collier		/* Rollback. */
865129044dSC.J. Collier		priv_special_flow_disable_all(priv);
875129044dSC.J. Collier		priv_mac_addrs_disable(priv);
885129044dSC.J. Collier		priv_destroy_hash_rxqs(priv);
895129044dSC.J. Collier	}
905129044dSC.J. Collier	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE)
915129044dSC.J. Collier		priv_fdir_enable(priv);
925129044dSC.J. Collier	priv_dev_interrupt_handler_install(priv, dev);
935129044dSC.J. Collier	priv_unlock(priv);
945129044dSC.J. Collier	return -err;
955129044dSC.J. Collier}
965129044dSC.J. Collier
975129044dSC.J. Collier/**
985129044dSC.J. Collier * DPDK callback to stop the device.
995129044dSC.J. Collier *
1005129044dSC.J. Collier * Simulate device stop by detaching all configured flows.
1015129044dSC.J. Collier *
1025129044dSC.J. Collier * @param dev
1035129044dSC.J. Collier *   Pointer to Ethernet device structure.
1045129044dSC.J. Collier */
1055129044dSC.J. Colliervoid
1065129044dSC.J. Colliermlx5_dev_stop(struct rte_eth_dev *dev)
1075129044dSC.J. Collier{
1085129044dSC.J. Collier	struct priv *priv = dev->data->dev_private;
1095129044dSC.J. Collier
1105129044dSC.J. Collier	if (mlx5_is_secondary())
1115129044dSC.J. Collier		return;
1125129044dSC.J. Collier
1135129044dSC.J. Collier	priv_lock(priv);
1145129044dSC.J. Collier	if (!priv->started) {
1155129044dSC.J. Collier		priv_unlock(priv);
1165129044dSC.J. Collier		return;
1175129044dSC.J. Collier	}
1185129044dSC.J. Collier	DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev);
1195129044dSC.J. Collier	priv_special_flow_disable_all(priv);
1205129044dSC.J. Collier	priv_mac_addrs_disable(priv);
1215129044dSC.J. Collier	priv_destroy_hash_rxqs(priv);
1225129044dSC.J. Collier	priv_fdir_disable(priv);
1235129044dSC.J. Collier	priv_dev_interrupt_handler_uninstall(priv, dev);
1245129044dSC.J. Collier	priv->started = 0;
1255129044dSC.J. Collier	priv_unlock(priv);
1265129044dSC.J. Collier}
127