bnx2x: Revising locking scheme for MAC configuration
authorYuval Mintz <yuvalmin@broadcom.com>
Thu, 1 Aug 2013 14:30:59 +0000 (17:30 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 1 Aug 2013 22:56:27 +0000 (15:56 -0700)
On very rare occasions, repeated load/unload stress test in the presence of
our storage driver (bnx2i/bnx2fc) causes a kernel panic in bnx2x code
(NULL pointer dereference). Stack traces indicate the issue happens during MAC
configuration; thorough code review showed that indeed several races exist
in which one thread can iterate over the list of configured MACs while another
deletes entries from the same list.

This patch adds a varient on the single-writer/Multiple-reader lock mechanism -
It utilizes an already exsiting bottom-half lock, using it so that Whenever
a writer is unable to continue due to the existence of another writer/reader,
it pends its request for future deliverance.
The writer / last readers will check for the existence of such requests and
perform them instead of the original initiator.
This prevents the writer from having to sleep while waiting for the lock
to be accessible, which might cause deadlocks given the locks already
held by the writer.

Another result of this patch is that setting of Rx Mode is now made in
sleepable context - Setting of Rx Mode is made under a bottom-half lock, which
was always nontrivial for the bnx2x driver, as the HW/FW configuration requires
wait for completions.
Since sleep was impossible (due to the sleepless-context), various mechanisms
were utilized to prevent the calling thread from sleep, but the truth was that
when the caller thread (i.e, the one calling ndo_set_rx_mode()) returned, the
Rx mode was still not set in HW/FW.

bnx2x_set_rx_mode() will now overtly schedule for the Rx changes to be
configured by the sp_rtnl_task which hold the RTNL lock and is sleepable
context.

Signed-off-by: Yuval Mintz <yuvalmin@broadcom.com>
Signed-off-by: Ariel Elior <ariele@broadcom.com>
Signed-off-by: Eilon Greenstein <eilong@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c

index dedbd76..439387b 100644 (file)
@@ -1331,7 +1331,7 @@ enum {
        BNX2X_SP_RTNL_ENABLE_SRIOV,
        BNX2X_SP_RTNL_VFPF_MCAST,
        BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
-       BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
+       BNX2X_SP_RTNL_RX_MODE,
        BNX2X_SP_RTNL_HYPERVISOR_VLAN,
 };
 
index ee350bd..11abdcc 100644 (file)
@@ -2060,7 +2060,11 @@ void bnx2x_squeeze_objects(struct bnx2x *bp)
        rparam.mcast_obj = &bp->mcast_obj;
        __set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
 
-       /* Add a DEL command... */
+       /* Add a DEL command... - Since we're doing a driver cleanup only,
+        * we take a lock surrounding both the initial send and the CONTs,
+        * as we don't want a true completion to disrupt us in the middle.
+        */
+       netif_addr_lock_bh(bp->dev);
        rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
        if (rc < 0)
                BNX2X_ERR("Failed to add a new DEL command to a multi-cast object: %d\n",
@@ -2072,11 +2076,13 @@ void bnx2x_squeeze_objects(struct bnx2x *bp)
                if (rc < 0) {
                        BNX2X_ERR("Failed to clean multi-cast object: %d\n",
                                  rc);
+                       netif_addr_unlock_bh(bp->dev);
                        return;
                }
 
                rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
        }
+       netif_addr_unlock_bh(bp->dev);
 }
 
 #ifndef BNX2X_STOP_ON_ERROR
@@ -2432,9 +2438,7 @@ int bnx2x_load_cnic(struct bnx2x *bp)
        }
 
        /* Initialize Rx filter. */
-       netif_addr_lock_bh(bp->dev);
-       bnx2x_set_rx_mode(bp->dev);
-       netif_addr_unlock_bh(bp->dev);
+       bnx2x_set_rx_mode_inner(bp);
 
        /* re-read iscsi info */
        bnx2x_get_iscsi_info(bp);
@@ -2704,9 +2708,7 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
        /* Start fast path */
 
        /* Initialize Rx filter. */
-       netif_addr_lock_bh(bp->dev);
-       bnx2x_set_rx_mode(bp->dev);
-       netif_addr_unlock_bh(bp->dev);
+       bnx2x_set_rx_mode_inner(bp);
 
        /* Start the Tx */
        switch (load_mode) {
index c07a6d0..38be494 100644 (file)
@@ -418,6 +418,7 @@ int bnx2x_set_eth_mac(struct bnx2x *bp, bool set);
  * netif_addr_lock_bh()
  */
 void bnx2x_set_rx_mode(struct net_device *dev);
+void bnx2x_set_rx_mode_inner(struct bnx2x *bp);
 
 /**
  * bnx2x_set_storm_rx_mode - configure MAC filtering rules in a FW.
index e5da078..bd064c6 100644 (file)
@@ -9628,11 +9628,9 @@ sp_rtnl_not_reset:
                }
        }
 
-       if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
-                              &bp->sp_rtnl_state)) {
-               DP(BNX2X_MSG_SP,
-                  "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
-               bnx2x_vfpf_storm_rx_mode(bp);
+       if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
+               DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
+               bnx2x_set_rx_mode_inner(bp);
        }
 
        if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
@@ -11849,34 +11847,48 @@ static int bnx2x_set_mc_list(struct bnx2x *bp)
 void bnx2x_set_rx_mode(struct net_device *dev)
 {
        struct bnx2x *bp = netdev_priv(dev);
-       u32 rx_mode = BNX2X_RX_MODE_NORMAL;
 
        if (bp->state != BNX2X_STATE_OPEN) {
                DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
                return;
+       } else {
+               /* Schedule an SP task to handle rest of change */
+               DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
+               smp_mb__before_clear_bit();
+               set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
+               smp_mb__after_clear_bit();
+               schedule_delayed_work(&bp->sp_rtnl_task, 0);
        }
+}
+
+void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
+{
+       u32 rx_mode = BNX2X_RX_MODE_NORMAL;
 
        DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
 
-       if (dev->flags & IFF_PROMISC)
+       netif_addr_lock_bh(bp->dev);
+
+       if (bp->dev->flags & IFF_PROMISC) {
                rx_mode = BNX2X_RX_MODE_PROMISC;
-       else if ((dev->flags & IFF_ALLMULTI) ||
-                ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
-                 CHIP_IS_E1(bp)))
+       } else if ((bp->dev->flags & IFF_ALLMULTI) ||
+                  ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
+                   CHIP_IS_E1(bp))) {
                rx_mode = BNX2X_RX_MODE_ALLMULTI;
-       else {
+       else {
                if (IS_PF(bp)) {
                        /* some multicasts */
                        if (bnx2x_set_mc_list(bp) < 0)
                                rx_mode = BNX2X_RX_MODE_ALLMULTI;
 
+                       /* release bh lock, as bnx2x_set_uc_list might sleep */
+                       netif_addr_unlock_bh(bp->dev);
                        if (bnx2x_set_uc_list(bp) < 0)
                                rx_mode = BNX2X_RX_MODE_PROMISC;
+                       netif_addr_lock_bh(bp->dev);
                } else {
                        /* configuring mcast to a vf involves sleeping (when we
-                        * wait for the pf's response). Since this function is
-                        * called from non sleepable context we must schedule
-                        * a work item for this purpose
+                        * wait for the pf's response).
                         */
                        smp_mb__before_clear_bit();
                        set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
@@ -11894,22 +11906,20 @@ void bnx2x_set_rx_mode(struct net_device *dev)
        /* Schedule the rx_mode command */
        if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
                set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
+               netif_addr_unlock_bh(bp->dev);
                return;
        }
 
        if (IS_PF(bp)) {
                bnx2x_set_storm_rx_mode(bp);
+               netif_addr_unlock_bh(bp->dev);
        } else {
-               /* configuring rx mode to storms in a vf involves sleeping (when
-                * we wait for the pf's response). Since this function is
-                * called from non sleepable context we must schedule
-                * a work item for this purpose
+               /* VF will need to request the PF to make this change, and so
+                * the VF needs to release the bottom-half lock prior to the
+                * request (as it will likely require sleep on the VF side)
                 */
-               smp_mb__before_clear_bit();
-               set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
-                       &bp->sp_rtnl_state);
-               smp_mb__after_clear_bit();
-               schedule_delayed_work(&bp->sp_rtnl_task, 0);
+               netif_addr_unlock_bh(bp->dev);
+               bnx2x_vfpf_storm_rx_mode(bp);
        }
 }
 
index 8f03c98..1d46b68 100644 (file)
@@ -159,16 +159,6 @@ static inline void __bnx2x_exe_queue_reset_pending(
        }
 }
 
-static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
-                                                struct bnx2x_exe_queue_obj *o)
-{
-       spin_lock_bh(&o->lock);
-
-       __bnx2x_exe_queue_reset_pending(bp, o);
-
-       spin_unlock_bh(&o->lock);
-}
-
 /**
  * bnx2x_exe_queue_step - execute one execution chunk atomically
  *
@@ -176,7 +166,7 @@ static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
  * @o:                 queue
  * @ramrod_flags:      flags
  *
- * (Atomicity is ensured using the exe_queue->lock).
+ * (Should be called while holding the exe_queue->lock).
  */
 static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
                                       struct bnx2x_exe_queue_obj *o,
@@ -187,8 +177,6 @@ static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
 
        memset(&spacer, 0, sizeof(spacer));
 
-       spin_lock_bh(&o->lock);
-
        /* Next step should not be performed until the current is finished,
         * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
         * properly clear object internals without sending any command to the FW
@@ -200,7 +188,6 @@ static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
                        DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
                        __bnx2x_exe_queue_reset_pending(bp, o);
                } else {
-                       spin_unlock_bh(&o->lock);
                        return 1;
                }
        }
@@ -228,10 +215,8 @@ static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
        }
 
        /* Sanity check */
-       if (!cur_len) {
-               spin_unlock_bh(&o->lock);
+       if (!cur_len)
                return 0;
-       }
 
        rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
        if (rc < 0)
@@ -245,7 +230,6 @@ static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
                 */
                __bnx2x_exe_queue_reset_pending(bp, o);
 
-       spin_unlock_bh(&o->lock);
        return rc;
 }
 
@@ -432,12 +416,219 @@ static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
        return true;
 }
 
+/**
+ * __bnx2x_vlan_mac_h_write_trylock - try getting the vlan mac writer lock
+ *
+ * @bp:                device handle
+ * @o:         vlan_mac object
+ *
+ * @details: Non-blocking implementation; should be called under execution
+ *           queue lock.
+ */
+static int __bnx2x_vlan_mac_h_write_trylock(struct bnx2x *bp,
+                                           struct bnx2x_vlan_mac_obj *o)
+{
+       if (o->head_reader) {
+               DP(BNX2X_MSG_SP, "vlan_mac_lock writer - There are readers; Busy\n");
+               return -EBUSY;
+       }
+
+       DP(BNX2X_MSG_SP, "vlan_mac_lock writer - Taken\n");
+       return 0;
+}
+
+/**
+ * __bnx2x_vlan_mac_h_exec_pending - execute step instead of a previous step
+ *
+ * @bp:                device handle
+ * @o:         vlan_mac object
+ *
+ * @details Should be called under execution queue lock; notice it might release
+ *          and reclaim it during its run.
+ */
+static void __bnx2x_vlan_mac_h_exec_pending(struct bnx2x *bp,
+                                           struct bnx2x_vlan_mac_obj *o)
+{
+       int rc;
+       unsigned long ramrod_flags = o->saved_ramrod_flags;
+
+       DP(BNX2X_MSG_SP, "vlan_mac_lock execute pending command with ramrod flags %lu\n",
+          ramrod_flags);
+       o->head_exe_request = false;
+       o->saved_ramrod_flags = 0;
+       rc = bnx2x_exe_queue_step(bp, &o->exe_queue, &ramrod_flags);
+       if (rc != 0) {
+               BNX2X_ERR("execution of pending commands failed with rc %d\n",
+                         rc);
+#ifdef BNX2X_STOP_ON_ERROR
+               bnx2x_panic();
+#endif
+       }
+}
+
+/**
+ * __bnx2x_vlan_mac_h_pend - Pend an execution step which couldn't run
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ * @ramrod_flags:      ramrod flags of missed execution
+ *
+ * @details Should be called under execution queue lock.
+ */
+static void __bnx2x_vlan_mac_h_pend(struct bnx2x *bp,
+                                   struct bnx2x_vlan_mac_obj *o,
+                                   unsigned long ramrod_flags)
+{
+       o->head_exe_request = true;
+       o->saved_ramrod_flags = ramrod_flags;
+       DP(BNX2X_MSG_SP, "Placing pending execution with ramrod flags %lu\n",
+          ramrod_flags);
+}
+
+/**
+ * __bnx2x_vlan_mac_h_write_unlock - unlock the vlan mac head list writer lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details Should be called under execution queue lock. Notice if a pending
+ *          execution exists, it would perform it - possibly releasing and
+ *          reclaiming the execution queue lock.
+ */
+static void __bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
+                                           struct bnx2x_vlan_mac_obj *o)
+{
+       /* It's possible a new pending execution was added since this writer
+        * executed. If so, execute again. [Ad infinitum]
+        */
+       while (o->head_exe_request) {
+               DP(BNX2X_MSG_SP, "vlan_mac_lock - writer release encountered a pending request\n");
+               __bnx2x_vlan_mac_h_exec_pending(bp, o);
+       }
+}
+
+/**
+ * bnx2x_vlan_mac_h_write_unlock - unlock the vlan mac head list writer lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details Notice if a pending execution exists, it would perform it -
+ *          possibly releasing and reclaiming the execution queue lock.
+ */
+void bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
+                                  struct bnx2x_vlan_mac_obj *o)
+{
+       spin_lock_bh(&o->exe_queue.lock);
+       __bnx2x_vlan_mac_h_write_unlock(bp, o);
+       spin_unlock_bh(&o->exe_queue.lock);
+}
+
+/**
+ * __bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details Should be called under the execution queue lock. May sleep. May
+ *          release and reclaim execution queue lock during its run.
+ */
+static int __bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
+                                       struct bnx2x_vlan_mac_obj *o)
+{
+       /* If we got here, we're holding lock --> no WRITER exists */
+       o->head_reader++;
+       DP(BNX2X_MSG_SP, "vlan_mac_lock - locked reader - number %d\n",
+          o->head_reader);
+
+       return 0;
+}
+
+/**
+ * bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details May sleep. Claims and releases execution queue lock during its run.
+ */
+int bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
+                              struct bnx2x_vlan_mac_obj *o)
+{
+       int rc;
+
+       spin_lock_bh(&o->exe_queue.lock);
+       rc = __bnx2x_vlan_mac_h_read_lock(bp, o);
+       spin_unlock_bh(&o->exe_queue.lock);
+
+       return rc;
+}
+
+/**
+ * __bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details Should be called under execution queue lock. Notice if a pending
+ *          execution exists, it would be performed if this was the last
+ *          reader. possibly releasing and reclaiming the execution queue lock.
+ */
+static void __bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
+                                         struct bnx2x_vlan_mac_obj *o)
+{
+       if (!o->head_reader) {
+               BNX2X_ERR("Need to release vlan mac reader lock, but lock isn't taken\n");
+#ifdef BNX2X_STOP_ON_ERROR
+               bnx2x_panic();
+#endif
+       } else {
+               o->head_reader--;
+               DP(BNX2X_MSG_SP, "vlan_mac_lock - decreased readers to %d\n",
+                  o->head_reader);
+       }
+
+       /* It's possible a new pending execution was added, and that this reader
+        * was last - if so we need to execute the command.
+        */
+       if (!o->head_reader && o->head_exe_request) {
+               DP(BNX2X_MSG_SP, "vlan_mac_lock - reader release encountered a pending request\n");
+
+               /* Writer release will do the trick */
+               __bnx2x_vlan_mac_h_write_unlock(bp, o);
+       }
+}
+
+/**
+ * bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
+ *
+ * @bp:                        device handle
+ * @o:                 vlan_mac object
+ *
+ * @details Notice if a pending execution exists, it would be performed if this
+ *          was the last reader. Claims and releases the execution queue lock
+ *          during its run.
+ */
+void bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
+                                 struct bnx2x_vlan_mac_obj *o)
+{
+       spin_lock_bh(&o->exe_queue.lock);
+       __bnx2x_vlan_mac_h_read_unlock(bp, o);
+       spin_unlock_bh(&o->exe_queue.lock);
+}
+
 static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
                                int n, u8 *base, u8 stride, u8 size)
 {
        struct bnx2x_vlan_mac_registry_elem *pos;
        u8 *next = base;
        int counter = 0;
+       int read_lock;
+
+       DP(BNX2X_MSG_SP, "get_n_elements - taking vlan_mac_lock (reader)\n");
+       read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
+       if (read_lock != 0)
+               BNX2X_ERR("get_n_elements failed to get vlan mac reader lock; Access without lock\n");
 
        /* traverse list */
        list_for_each_entry(pos, &o->head, link) {
@@ -449,6 +640,12 @@ static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
                        next += stride + size;
                }
        }
+
+       if (read_lock == 0) {
+               DP(BNX2X_MSG_SP, "get_n_elements - releasing vlan_mac_lock (reader)\n");
+               bnx2x_vlan_mac_h_read_unlock(bp, o);
+       }
+
        return counter * ETH_ALEN;
 }
 
@@ -1397,6 +1594,32 @@ static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
        return -EBUSY;
 }
 
+static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
+                                        struct bnx2x_vlan_mac_obj *o,
+                                        unsigned long *ramrod_flags)
+{
+       int rc = 0;
+
+       spin_lock_bh(&o->exe_queue.lock);
+
+       DP(BNX2X_MSG_SP, "vlan_mac_execute_step - trying to take writer lock\n");
+       rc = __bnx2x_vlan_mac_h_write_trylock(bp, o);
+
+       if (rc != 0) {
+               __bnx2x_vlan_mac_h_pend(bp, o, *ramrod_flags);
+
+               /* Calling function should not diffrentiate between this case
+                * and the case in which there is already a pending ramrod
+                */
+               rc = 1;
+       } else {
+               rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
+       }
+       spin_unlock_bh(&o->exe_queue.lock);
+
+       return rc;
+}
+
 /**
  * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
  *
@@ -1414,19 +1637,27 @@ static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
        struct bnx2x_raw_obj *r = &o->raw;
        int rc;
 
+       /* Clearing the pending list & raw state should be made
+        * atomically (as execution flow assumes they represent the same).
+        */
+       spin_lock_bh(&o->exe_queue.lock);
+
        /* Reset pending list */
-       bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
+       __bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
 
        /* Clear pending */
        r->clear_pending(r);
 
+       spin_unlock_bh(&o->exe_queue.lock);
+
        /* If ramrod failed this is most likely a SW bug */
        if (cqe->message.error)
                return -EINVAL;
 
        /* Run the next bulk of pending commands if requested */
        if (test_bit(RAMROD_CONT, ramrod_flags)) {
-               rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
+               rc = __bnx2x_vlan_mac_execute_step(bp, o, ramrod_flags);
+
                if (rc < 0)
                        return rc;
        }
@@ -1719,9 +1950,8 @@ static inline int bnx2x_vlan_mac_push_new_cmd(
  * @p:
  *
  */
-int bnx2x_config_vlan_mac(
-       struct bnx2x *bp,
-       struct bnx2x_vlan_mac_ramrod_params *p)
+int bnx2x_config_vlan_mac(struct bnx2x *bp,
+                          struct bnx2x_vlan_mac_ramrod_params *p)
 {
        int rc = 0;
        struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
@@ -1752,7 +1982,8 @@ int bnx2x_config_vlan_mac(
        /* Execute commands if required */
        if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
            test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
-               rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
+               rc = __bnx2x_vlan_mac_execute_step(bp, p->vlan_mac_obj,
+                                                  &p->ramrod_flags);
                if (rc < 0)
                        return rc;
        }
@@ -1775,8 +2006,9 @@ int bnx2x_config_vlan_mac(
                                return rc;
 
                        /* Make a next step */
-                       rc = bnx2x_exe_queue_step(bp, &o->exe_queue,
-                                                 ramrod_flags);
+                       rc = __bnx2x_vlan_mac_execute_step(bp,
+                                                          p->vlan_mac_obj,
+                                                          &p->ramrod_flags);
                        if (rc < 0)
                                return rc;
                }
@@ -1806,10 +2038,11 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
                                  unsigned long *ramrod_flags)
 {
        struct bnx2x_vlan_mac_registry_elem *pos = NULL;
-       int rc = 0;
        struct bnx2x_vlan_mac_ramrod_params p;
        struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
        struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
+       int read_lock;
+       int rc = 0;
 
        /* Clear pending commands first */
 
@@ -1844,6 +2077,11 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
        __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
        __clear_bit(RAMROD_CONT, &p.ramrod_flags);
 
+       DP(BNX2X_MSG_SP, "vlan_mac_del_all -- taking vlan_mac_lock (reader)\n");
+       read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
+       if (read_lock != 0)
+               return read_lock;
+
        list_for_each_entry(pos, &o->head, link) {
                if (pos->vlan_mac_flags == *vlan_mac_flags) {
                        p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
@@ -1851,11 +2089,15 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
                        rc = bnx2x_config_vlan_mac(bp, &p);
                        if (rc < 0) {
                                BNX2X_ERR("Failed to add a new DEL command\n");
+                               bnx2x_vlan_mac_h_read_unlock(bp, o);
                                return rc;
                        }
                }
        }
 
+       DP(BNX2X_MSG_SP, "vlan_mac_del_all -- releasing vlan_mac_lock (reader)\n");
+       bnx2x_vlan_mac_h_read_unlock(bp, o);
+
        p.ramrod_flags = *ramrod_flags;
        __set_bit(RAMROD_CONT, &p.ramrod_flags);
 
@@ -1887,6 +2129,9 @@ static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
        struct bnx2x_credit_pool_obj *vlans_pool)
 {
        INIT_LIST_HEAD(&o->head);
+       o->head_reader = 0;
+       o->head_exe_request = false;
+       o->saved_ramrod_flags = 0;
 
        o->macs_pool = macs_pool;
        o->vlans_pool = vlans_pool;
index 798dfe9..533a3ab 100644 (file)
@@ -285,6 +285,12 @@ struct bnx2x_vlan_mac_obj {
         * entries.
         */
        struct list_head                head;
+       /* Implement a simple reader/writer lock on the head list.
+        * all these fields should only be accessed under the exe_queue lock
+        */
+       u8              head_reader; /* Num. of readers accessing head list */
+       bool            head_exe_request; /* Pending execution request. */
+       unsigned long   saved_ramrod_flags; /* Ramrods of pending execution */
 
        /* TODO: Add it's initialization in the init functions */
        struct bnx2x_exe_queue_obj      exe_queue;
@@ -1302,8 +1308,16 @@ void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
                             struct bnx2x_credit_pool_obj *macs_pool,
                             struct bnx2x_credit_pool_obj *vlans_pool);
 
+int bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
+                                       struct bnx2x_vlan_mac_obj *o);
+void bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
+                                 struct bnx2x_vlan_mac_obj *o);
+int bnx2x_vlan_mac_h_write_lock(struct bnx2x *bp,
+                               struct bnx2x_vlan_mac_obj *o);
+void bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
+                                         struct bnx2x_vlan_mac_obj *o);
 int bnx2x_config_vlan_mac(struct bnx2x *bp,
-                         struct bnx2x_vlan_mac_ramrod_params *p);
+                          struct bnx2x_vlan_mac_ramrod_params *p);
 
 int bnx2x_vlan_mac_move(struct bnx2x *bp,
                        struct bnx2x_vlan_mac_ramrod_params *p,
index 95861ef..6291324 100644 (file)
@@ -491,12 +491,20 @@ static inline void bnx2x_vfop_credit(struct bnx2x *bp,
         * and a valid credit counter
         */
        if (!vfop->rc && args->credit) {
-               int cnt = 0;
                struct list_head *pos;
+               int read_lock;
+               int cnt = 0;
+
+               read_lock = bnx2x_vlan_mac_h_read_lock(bp, obj);
+               if (read_lock)
+                       DP(BNX2X_MSG_SP, "Failed to take vlan mac read head; continuing anyway\n");
 
                list_for_each(pos, &obj->head)
                        cnt++;
 
+               if (!read_lock)
+                       bnx2x_vlan_mac_h_read_unlock(bp, obj);
+
                atomic_set(args->credit, cnt);
        }
 }