net: add rte prefix to ether structures
[dpdk.git] / drivers / net / nfp / nfp_net.c
index a791e95..95c2be1 100644 (file)
@@ -119,7 +119,7 @@ static int nfp_net_rss_reta_write(struct rte_eth_dev *dev,
 static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
                        struct rte_eth_rss_conf *rss_conf);
 static int nfp_set_mac_addr(struct rte_eth_dev *dev,
-                            struct ether_addr *mac_addr);
+                            struct rte_ether_addr *mac_addr);
 
 /* The offset of the queue controller queues in the PCIe Target */
 #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
@@ -553,7 +553,7 @@ nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
 }
 
 int
-nfp_set_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
+nfp_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 {
        struct nfp_net_hw *hw;
        uint32_t update, ctrl;
@@ -575,7 +575,10 @@ nfp_set_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 
        /* Signal the NIC about the change */
        update = NFP_NET_CFG_UPDATE_MACADDR;
-       ctrl = hw->ctrl | NFP_NET_CFG_CTRL_LIVE_ADDR;
+       ctrl = hw->ctrl;
+       if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
+           (hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
+               ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
        if (nfp_net_reconfig(hw, ctrl, update) < 0) {
                PMD_INIT_LOG(INFO, "MAC address update failed");
                return -EIO;
@@ -767,7 +770,7 @@ nfp_net_start(struct rte_eth_dev *dev)
                return -EIO;
 
        /*
-        * Allocating rte mbuffs for configured rx queues.
+        * Allocating rte mbufs for configured rx queues.
         * This requires queues being enabled before
         */
        if (nfp_net_rx_freelist_setup(dev) < 0) {
@@ -841,6 +844,48 @@ nfp_net_stop(struct rte_eth_dev *dev)
        }
 }
 
+/* Set the link up. */
+static int
+nfp_net_set_link_up(struct rte_eth_dev *dev)
+{
+       struct nfp_net_hw *hw;
+
+       PMD_DRV_LOG(DEBUG, "Set link up");
+
+       hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       if (!hw->is_pf)
+               return -ENOTSUP;
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               /* Configure the physical port down */
+               return nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 1);
+       else
+               return nfp_eth_set_configured(dev->process_private,
+                                             hw->pf_port_idx, 1);
+}
+
+/* Set the link down. */
+static int
+nfp_net_set_link_down(struct rte_eth_dev *dev)
+{
+       struct nfp_net_hw *hw;
+
+       PMD_DRV_LOG(DEBUG, "Set link down");
+
+       hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+       if (!hw->is_pf)
+               return -ENOTSUP;
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               /* Configure the physical port down */
+               return nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 0);
+       else
+               return nfp_eth_set_configured(dev->process_private,
+                                             hw->pf_port_idx, 0);
+}
+
 /* Reset and stop device. The device can not be restarted. */
 static void
 nfp_net_close(struct rte_eth_dev *dev)
@@ -1506,7 +1551,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
        if (rxq == NULL)
                return -ENOMEM;
 
-       /* Hw queues mapping based on firmware confifguration */
+       /* Hw queues mapping based on firmware configuration */
        rxq->qidx = queue_idx;
        rxq->fl_qcidx = queue_idx * hw->stride_rx;
        rxq->rx_qcidx = rxq->fl_qcidx + (hw->stride_rx - 1);
@@ -1538,7 +1583,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
                                   socket_id);
 
        if (tz == NULL) {
-               PMD_DRV_LOG(ERR, "Error allocatig rx dma");
+               PMD_DRV_LOG(ERR, "Error allocating rx dma");
                nfp_net_rx_queue_release(rxq);
                return -ENOMEM;
        }
@@ -1925,7 +1970,7 @@ nfp_net_mbuf_alloc_failed(struct nfp_net_rxq *rxq)
 /*
  * RX path design:
  *
- * There are some decissions to take:
+ * There are some decisions to take:
  * 1) How to check DD RX descriptors bit
  * 2) How and when to allocate new mbufs
  *
@@ -1995,7 +2040,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                rte_rmb();
 
                /*
-                * We got a packet. Let's alloc a new mbuff for refilling the
+                * We got a packet. Let's alloc a new mbuf for refilling the
                 * free descriptor ring as soon as possible
                 */
                new_mb = rte_pktmbuf_alloc(rxq->mem_pool);
@@ -2010,8 +2055,8 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                nb_hold++;
 
                /*
-                * Grab the mbuff and refill the descriptor with the
-                * previously allocated mbuff
+                * Grab the mbuf and refill the descriptor with the
+                * previously allocated mbuf
                 */
                mb = rxb->mbuf;
                rxb->mbuf = new_mb;
@@ -2043,7 +2088,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                        return -EINVAL;
                }
 
-               /* Filling the received mbuff with packet info */
+               /* Filling the received mbuf with packet info */
                if (hw->rx_offset)
                        mb->data_off = RTE_PKTMBUF_HEADROOM + hw->rx_offset;
                else
@@ -2068,7 +2113,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                        mb->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
                }
 
-               /* Adding the mbuff to the mbuff array passed by the app */
+               /* Adding the mbuf to the mbuf array passed by the app */
                rx_pkts[avail++] = mb;
 
                /* Now resetting and updating the descriptor */
@@ -2462,7 +2507,7 @@ nfp_net_reta_query(struct rte_eth_dev *dev,
                for (j = 0; j < 4; j++) {
                        if (!(mask & (0x1 << j)))
                                continue;
-                       reta_conf->reta[shift + j] =
+                       reta_conf[idx].reta[shift + j] =
                                (uint8_t)((reta >> (8 * j)) & 0xF);
                }
        }
@@ -2649,6 +2694,8 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = {
        .dev_configure          = nfp_net_configure,
        .dev_start              = nfp_net_start,
        .dev_stop               = nfp_net_stop,
+       .dev_set_link_up        = nfp_net_set_link_up,
+       .dev_set_link_down      = nfp_net_set_link_down,
        .dev_close              = nfp_net_close,
        .promiscuous_enable     = nfp_net_promisc_enable,
        .promiscuous_disable    = nfp_net_promisc_disable,
@@ -2808,9 +2855,9 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
        case PCI_DEVICE_ID_NFP6000_PF_NIC:
        case PCI_DEVICE_ID_NFP6000_VF_NIC:
                start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
-               tx_bar_off = start_q * NFP_QCP_QUEUE_ADDR_SZ;
+               tx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
                start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
-               rx_bar_off = start_q * NFP_QCP_QUEUE_ADDR_SZ;
+               rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
                break;
        default:
                PMD_DRV_LOG(ERR, "nfp_net: no device ID matching");
@@ -2915,7 +2962,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
                nfp_net_vf_read_mac(hw);
        }
 
-       if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr)) {
+       if (!is_valid_assigned_ether_addr(
+                   (struct rte_ether_addr *)&hw->mac_addr)) {
                PMD_INIT_LOG(INFO, "Using random mac address for port %d",
                                   port);
                /* Using random mac addresses for VFs */
@@ -2924,7 +2972,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
        }
 
        /* Copying mac address to DPDK eth_dev struct */
-       ether_addr_copy((struct ether_addr *)hw->mac_addr,
+       ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
                        &eth_dev->data->mac_addrs[0]);
 
        if (!(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
@@ -3254,6 +3302,7 @@ nfp_cpp_bridge_service_func(void *args)
        if (ret < 0) {
                RTE_LOG(ERR, PMD, "%s: bind error (%d). Service failed\n",
                                  __func__, errno);
+               close(sockfd);
                return ret;
        }
 
@@ -3261,6 +3310,7 @@ nfp_cpp_bridge_service_func(void *args)
        if (ret < 0) {
                RTE_LOG(ERR, PMD, "%s: listen error(%d). Service failed\n",
                                  __func__, errno);
+               close(sockfd);
                return ret;
        }
 
@@ -3270,6 +3320,7 @@ nfp_cpp_bridge_service_func(void *args)
                        RTE_LOG(ERR, PMD, "%s: accept call error (%d)\n",
                                          __func__, errno);
                        RTE_LOG(ERR, PMD, "%s: service failed\n", __func__);
+                       close(sockfd);
                        return -EIO;
                }
 
@@ -3318,9 +3369,9 @@ nfp_pf_create_dev(struct rte_pci_device *dev, int port, int ports,
                return -ENOMEM;
 
        if (ports > 1)
-               sprintf(port_name, "%s_port%d", dev->device.name, port);
+               snprintf(port_name, 100, "%s_port%d", dev->device.name, port);
        else
-               sprintf(port_name, "%s", dev->device.name);
+               strlcat(port_name, dev->device.name, 100);
 
 
        if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
@@ -3433,28 +3484,31 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card)
        /* Looking for firmware file in order of priority */
 
        /* First try to find a firmware image specific for this device */
-       sprintf(serial, "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
+       snprintf(serial, sizeof(serial),
+                       "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
                cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3],
                cpp->serial[4], cpp->serial[5], cpp->interface >> 8,
                cpp->interface & 0xff);
 
-       sprintf(fw_name, "%s/%s.nffw", DEFAULT_FW_PATH, serial);
+       snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH,
+                       serial);
 
        PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
        fw_f = open(fw_name, O_RDONLY);
-       if (fw_f > 0)
+       if (fw_f >= 0)
                goto read_fw;
 
        /* Then try the PCI name */
-       sprintf(fw_name, "%s/pci-%s.nffw", DEFAULT_FW_PATH, dev->device.name);
+       snprintf(fw_name, sizeof(fw_name), "%s/pci-%s.nffw", DEFAULT_FW_PATH,
+                       dev->device.name);
 
        PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
        fw_f = open(fw_name, O_RDONLY);
-       if (fw_f > 0)
+       if (fw_f >= 0)
                goto read_fw;
 
        /* Finally try the card type and media */
-       sprintf(fw_name, "%s/%s", DEFAULT_FW_PATH, card);
+       snprintf(fw_name, sizeof(fw_name), "%s/%s", DEFAULT_FW_PATH, card);
        PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
        fw_f = open(fw_name, O_RDONLY);
        if (fw_f < 0) {
@@ -3530,8 +3584,9 @@ nfp_fw_setup(struct rte_pci_device *dev, struct nfp_cpp *cpp,
 
        PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
 
-       sprintf(card_desc, "nic_%s_%dx%d.nffw", nfp_fw_model,
-               nfp_eth_table->count, nfp_eth_table->ports[0].speed / 1000);
+       snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
+                       nfp_fw_model, nfp_eth_table->count,
+                       nfp_eth_table->ports[0].speed / 1000);
 
        nsp = nfp_nsp_open(cpp);
        if (!nsp) {