net/bnx2x: restrict Rx mask flags sent to the PF
[dpdk.git] / drivers / net / bnx2x / bnx2x_vfpf.c
index 39fd59a..df145d3 100644 (file)
@@ -1,7 +1,11 @@
 /*
  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
  *
+ * Copyright (c) 2015 QLogic Corporation.
  * All rights reserved.
+ * www.qlogic.com
+ *
+ * See LICENSE.bnx2x_pmd for copyright and licensing details.
  */
 
 #include "bnx2x.h"
@@ -62,8 +66,8 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 
 /* add tlv to a buffer */
 #define BNX2X_TLV_APPEND(_tlvs, _offset, _type, _length) \
-       ((struct vf_first_tlv *)((uint64_t)_tlvs + _offset))->type   = _type; \
-       ((struct vf_first_tlv *)((uint64_t)_tlvs + _offset))->length = _length
+       ((struct vf_first_tlv *)((unsigned long)_tlvs + _offset))->type   = _type; \
+       ((struct vf_first_tlv *)((unsigned long)_tlvs + _offset))->length = _length
 
 /* Initiliaze header of the first tlv and clear mailbox*/
 static void
@@ -118,16 +122,10 @@ bnx2x_do_req4pf(struct bnx2x_softc *sc, phys_addr_t phys_addr)
                                break;
                }
 
-               if (i == BNX2X_VF_CHANNEL_TRIES) {
+               if (!*status) {
                        PMD_DRV_LOG(ERR, "Response from PF timed out");
                        return -EAGAIN;
                }
-
-               if (BNX2X_VF_STATUS_SUCCESS != *status) {
-                       PMD_DRV_LOG(ERR, "Bad reply from PF : %u",
-                                       *status);
-                       return -EINVAL;
-               }
        } else {
                PMD_DRV_LOG(ERR, "status should be zero before message"
                                "to pf was sent");
@@ -189,10 +187,10 @@ struct bnx2x_obtain_status bnx2x_loop_obtain_resources(struct bnx2x_softc *sc)
        do {
                PMD_DRV_LOG(DEBUG, "trying to get resources");
 
-               if ( bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr) ) {
+               if (bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr)) {
                        /* timeout */
                        status.success = 0;
-                       status.err_code = 0;
+                       status.err_code = -EAGAIN;
                        return status;
                }
 
@@ -284,6 +282,8 @@ int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_
        sc->igu_sb_cnt  = sc_resp.resc.num_sbs;
        sc->igu_base_sb = sc_resp.resc.hw_sbs[0] & 0xFF;
        sc->igu_dsb_id  = -1;
+       sc->max_tx_queues = sc_resp.resc.num_txqs;
+       sc->max_rx_queues = sc_resp.resc.num_rxqs;
 
        sc->link_params.chip_id = sc->devinfo.chip_id;
        sc->doorbell_size = sc_resp.db_size;
@@ -293,10 +293,11 @@ int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_
                sc->igu_sb_cnt, sc->igu_base_sb);
        strncpy(sc->fw_ver, sc_resp.fw_ver, sizeof(sc->fw_ver));
 
-       if (is_valid_ether_addr(sc_resp.resc.current_mac_addr))
-               (void)rte_memcpy(sc->link_params.mac_addr,
-                      sc_resp.resc.current_mac_addr,
-                      ETH_ALEN);
+       if (is_valid_assigned_ether_addr(&sc_resp.resc.current_mac_addr))
+               ether_addr_copy(&sc_resp.resc.current_mac_addr,
+                               (struct ether_addr *)sc->link_params.mac_addr);
+       else
+               eth_random_addr(sc->link_params.mac_addr);
 
        return 0;
 }
@@ -306,8 +307,8 @@ void
 bnx2x_vf_close(struct bnx2x_softc *sc)
 {
        struct vf_release_tlv *query;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
        int vf_id = bnx2x_read_vf_id(sc);
-       int ret;
 
        if (vf_id >= 0) {
                query = &sc->vf2pf_mbox->query[0].release;
@@ -318,11 +319,9 @@ bnx2x_vf_close(struct bnx2x_softc *sc)
                BNX2X_TLV_APPEND(query, query->first_tlv.length, BNX2X_VF_TLV_LIST_END,
                                sizeof(struct channel_list_end_tlv));
 
-               ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-
-               if (ret) {
+               bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+               if (reply->status != BNX2X_VF_STATUS_SUCCESS)
                        PMD_DRV_LOG(ERR, "Failed to release VF");
-               }
        }
 }
 
@@ -331,7 +330,8 @@ int
 bnx2x_vf_init(struct bnx2x_softc *sc)
 {
        struct vf_init_tlv *query;
-       int i, ret;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
+       int i;
 
        query = &sc->vf2pf_mbox->query[0].init;
        bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_INIT,
@@ -348,11 +348,10 @@ bnx2x_vf_init(struct bnx2x_softc *sc)
        BNX2X_TLV_APPEND(query, query->first_tlv.length, BNX2X_VF_TLV_LIST_END,
                        sizeof(struct channel_list_end_tlv));
 
-       ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-
-       if (ret) {
+       bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+       if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
                PMD_DRV_LOG(ERR, "Failed to init VF");
-               return ret;
+               return -EINVAL;
        }
 
        PMD_DRV_LOG(DEBUG, "VF was initialized");
@@ -363,8 +362,9 @@ void
 bnx2x_vf_unload(struct bnx2x_softc *sc)
 {
        struct vf_close_tlv *query;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
        struct vf_q_op_tlv *query_op;
-       int i, vf_id, ret;
+       int i, vf_id;
 
        vf_id = bnx2x_read_vf_id(sc);
        if (vf_id > 0) {
@@ -380,10 +380,10 @@ bnx2x_vf_unload(struct bnx2x_softc *sc)
                                        BNX2X_VF_TLV_LIST_END,
                                        sizeof(struct channel_list_end_tlv));
 
-                       ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-                       if (ret)
+                       bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+                       if (reply->status != BNX2X_VF_STATUS_SUCCESS)
                                PMD_DRV_LOG(ERR,
-                                               "Bad reply for vf_q %d teardown", i);
+                                           "Bad reply for vf_q %d teardown", i);
                }
 
                bnx2x_vf_set_mac(sc, false);
@@ -398,11 +398,10 @@ bnx2x_vf_unload(struct bnx2x_softc *sc)
                                BNX2X_VF_TLV_LIST_END,
                                sizeof(struct channel_list_end_tlv));
 
-               ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-
-               if (ret)
+               bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+               if (reply->status != BNX2X_VF_STATUS_SUCCESS)
                        PMD_DRV_LOG(ERR,
-                               "Bad reply from PF for close message");
+                                   "Bad reply from PF for close message");
        }
 }
 
@@ -465,8 +464,8 @@ int
 bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, int leading)
 {
        struct vf_setup_q_tlv *query;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
        uint16_t flags = bnx2x_vf_q_flags(leading);
-       int ret;
 
        query = &sc->vf2pf_mbox->query[0].setup_q;
        bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SETUP_Q,
@@ -481,11 +480,10 @@ bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, int lead
        BNX2X_TLV_APPEND(query, query->first_tlv.length, BNX2X_VF_TLV_LIST_END,
                        sizeof(struct channel_list_end_tlv));
 
-       ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-
-       if (ret) {
+       bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+       if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
                PMD_DRV_LOG(ERR, "Failed to setup VF queue[%d]",
-                               fp->index);
+                                fp->index);
                return -EINVAL;
        }
 
@@ -544,7 +542,7 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc,
                          struct ecore_config_rss_params *params)
 {
        struct vf_rss_tlv *query;
-       int ret;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
 
        query = &sc->vf2pf_mbox->query[0].update_rss;
 
@@ -564,10 +562,10 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc,
        query->rss_result_mask = params->rss_result_mask;
        query->rss_flags = params->rss_flags;
 
-       ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-       if (ret) {
-               PMD_DRV_LOG(ERR, "Failed to send message to PF, rc %d", ret);
-               return ret;
+       bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+       if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
+               PMD_DRV_LOG(ERR, "Failed to configure RSS");
+               return -EINVAL;
        }
 
        return 0;
@@ -577,8 +575,7 @@ int
 bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc)
 {
        struct vf_set_q_filters_tlv *query;
-       unsigned long tx_mask;
-       int ret;
+       struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
 
        query = &sc->vf2pf_mbox->query[0].set_q_filters;
        bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS,
@@ -587,17 +584,37 @@ bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc)
        query->vf_qid = 0;
        query->flags = BNX2X_VF_RX_MASK_CHANGED;
 
-       if (bnx2x_fill_accept_flags(sc, sc->rx_mode, &query->rx_mask, &tx_mask)) {
+       switch (sc->rx_mode) {
+       case BNX2X_RX_MODE_NONE: /* no Rx */
+               query->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
+               break;
+       case BNX2X_RX_MODE_NORMAL:
+               query->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
+               break;
+       case BNX2X_RX_MODE_ALLMULTI:
+               query->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
+               break;
+       case BNX2X_RX_MODE_PROMISC:
+               query->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
+               query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
+               break;
+       default:
+               PMD_DRV_LOG(ERR, "BAD rx mode (%d)", sc->rx_mode);
                return -EINVAL;
        }
 
        BNX2X_TLV_APPEND(query, query->first_tlv.length, BNX2X_VF_TLV_LIST_END,
                        sizeof(struct channel_list_end_tlv));
 
-       ret = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
-       if (ret) {
-               PMD_DRV_LOG(ERR, "Failed to send message to PF, rc %d", ret);
-               return ret;
+       bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
+       if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
+               PMD_DRV_LOG(ERR, "Failed to set RX mode");
+               return -EINVAL;
        }
 
        return 0;