1 /*- 2 * BSD LICENSE 3 * 4 * Copyright 2015 6WIND S.A. 5 * Copyright 2015 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 /* DPDK headers don't like -pedantic. */ 35 #ifdef PEDANTIC 36 #pragma GCC diagnostic ignored "-pedantic" 37 #endif 38 #include <rte_ether.h> 39 #include <rte_ethdev.h> 40 #ifdef PEDANTIC 41 #pragma GCC diagnostic error "-pedantic" 42 #endif 43 44 #include "mlx5.h" 45 #include "mlx5_rxtx.h" 46 #include "mlx5_utils.h" 47 48 /** 49 * DPDK callback to start the device. 50 * 51 * Simulate device start by attaching all configured flows. 52 * 53 * @param dev 54 * Pointer to Ethernet device structure. 55 * 56 * @return 57 * 0 on success, negative errno value on failure. 58 */ 59 int 60 mlx5_dev_start(struct rte_eth_dev *dev) 61 { 62 struct priv *priv = dev->data->dev_private; 63 int err; 64 65 priv_lock(priv); 66 if (priv->started) { 67 priv_unlock(priv); 68 return 0; 69 } 70 DEBUG("%p: allocating and configuring hash RX queues", (void *)dev); 71 err = priv_create_hash_rxqs(priv); 72 if (!err) 73 err = priv_mac_addrs_enable(priv); 74 if (!err && priv->promisc_req) 75 err = priv_promiscuous_enable(priv); 76 if (!err && priv->allmulti_req) 77 err = priv_allmulticast_enable(priv); 78 if (!err) 79 priv->started = 1; 80 else { 81 ERROR("%p: an error occurred while configuring hash RX queues:" 82 " %s", 83 (void *)priv, strerror(err)); 84 /* Rollback. */ 85 priv_allmulticast_disable(priv); 86 priv_promiscuous_disable(priv); 87 priv_mac_addrs_disable(priv); 88 priv_destroy_hash_rxqs(priv); 89 } 90 priv_unlock(priv); 91 return -err; 92 } 93 94 /** 95 * DPDK callback to stop the device. 96 * 97 * Simulate device stop by detaching all configured flows. 98 * 99 * @param dev 100 * Pointer to Ethernet device structure. 101 */ 102 void 103 mlx5_dev_stop(struct rte_eth_dev *dev) 104 { 105 struct priv *priv = dev->data->dev_private; 106 107 priv_lock(priv); 108 if (!priv->started) { 109 priv_unlock(priv); 110 return; 111 } 112 DEBUG("%p: cleaning up and destroying hash RX queues", (void *)dev); 113 priv_allmulticast_disable(priv); 114 priv_promiscuous_disable(priv); 115 priv_mac_addrs_disable(priv); 116 priv_destroy_hash_rxqs(priv); 117 priv->started = 0; 118 priv_unlock(priv); 119 } 120