net/qede: fix null pointer dereferences
[dpdk.git] / drivers / net / qede / qede_ethdev.c
index c228b06..8832145 100644 (file)
@@ -631,12 +631,20 @@ qede_vxlan_enable(struct rte_eth_dev *eth_dev, uint8_t clss,
 
        for_each_hwfn(edev, i) {
                p_hwfn = &edev->hwfns[i];
-               p_ptt = IS_PF(edev) ? ecore_ptt_acquire(p_hwfn) : NULL;
+               if (IS_PF(edev)) {
+                       p_ptt = ecore_ptt_acquire(p_hwfn);
+                       if (!p_ptt)
+                               return -EAGAIN;
+               } else {
+                       p_ptt = NULL;
+               }
                rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt,
                                &tunn, ECORE_SPQ_MODE_CB, NULL);
                if (rc != ECORE_SUCCESS) {
                        DP_ERR(edev, "Failed to update tunn_clss %u\n",
                                        tunn.vxlan.tun_cls);
+                       if (IS_PF(edev))
+                               ecore_ptt_release(p_hwfn, p_ptt);
                        break;
                }
        }
@@ -1159,6 +1167,9 @@ static int qede_dev_start(struct rte_eth_dev *eth_dev)
        /* Bring-up the link */
        qede_dev_set_link_state(eth_dev, true);
 
+       /* Update link status */
+       qede_link_update(eth_dev, 0);
+
        /* Start/resume traffic */
        qede_fastpath_start(edev);
 
@@ -1367,7 +1378,7 @@ qede_dev_info_get(struct rte_eth_dev *eth_dev,
 }
 
 /* return 0 means link status changed, -1 means not changed */
-static int
+int
 qede_link_update(struct rte_eth_dev *eth_dev, __rte_unused int wait_to_complete)
 {
        struct qede_dev *qdev = eth_dev->data->dev_private;
@@ -2253,7 +2264,13 @@ qede_conf_udp_dst_port(struct rte_eth_dev *eth_dev,
                tunn.vxlan_port.port = udp_port;
                for_each_hwfn(edev, i) {
                        p_hwfn = &edev->hwfns[i];
-                       p_ptt = IS_PF(edev) ? ecore_ptt_acquire(p_hwfn) : NULL;
+                       if (IS_PF(edev)) {
+                               p_ptt = ecore_ptt_acquire(p_hwfn);
+                               if (!p_ptt)
+                                       return -EAGAIN;
+                       } else {
+                               p_ptt = NULL;
+                       }
                        rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
                                                ECORE_SPQ_MODE_CB, NULL);
                        if (rc != ECORE_SUCCESS) {
@@ -2424,6 +2441,23 @@ static int qede_vxlan_tunn_config(struct rte_eth_dev *eth_dev,
                        return qede_vxlan_enable(eth_dev,
                                ECORE_TUNN_CLSS_MAC_VLAN, false, true);
 
+               filter_type = conf->filter_type;
+               /* Determine if the given filter classification is supported */
+               qede_get_ecore_tunn_params(filter_type, &type, &clss, str);
+               if (clss == MAX_ECORE_TUNN_CLSS) {
+                       DP_ERR(edev, "Unsupported filter type\n");
+                       return -EINVAL;
+               }
+               /* Init tunnel ucast params */
+               rc = qede_set_ucast_tunn_cmn_param(&ucast, conf, type);
+               if (rc != ECORE_SUCCESS) {
+                       DP_ERR(edev, "Unsupported VxLAN filter type 0x%x\n",
+                       conf->filter_type);
+                       return rc;
+               }
+               DP_INFO(edev, "Rule: \"%s\", op %d, type 0x%x\n",
+                       str, filter_op, ucast.type);
+
                ucast.opcode = ECORE_FILTER_REMOVE;
 
                if (!(filter_type & ETH_TUNNEL_FILTER_TENID)) {
@@ -2437,6 +2471,8 @@ static int qede_vxlan_tunn_config(struct rte_eth_dev *eth_dev,
                if (rc != ECORE_SUCCESS)
                        return rc;
 
+               qdev->vxlan.num_filters--;
+
                /* Disable VXLAN if VXLAN filters become 0 */
                if (qdev->vxlan.num_filters == 0)
                        return qede_vxlan_enable(eth_dev, clss, false, true);
@@ -2606,6 +2642,7 @@ static int qede_common_dev_init(struct rte_eth_dev *eth_dev, bool is_vf)
 
        /* Extract key data structures */
        adapter = eth_dev->data->dev_private;
+       adapter->ethdev = eth_dev;
        edev = &adapter->edev;
        pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        pci_addr = pci_dev->addr;