BNX2X: spatch changes for BUG and WARN
[akaros.git] / kern / drivers / net / bnx2x / bnx2x_sp.c
index 0a38b61..83e1e20 100644 (file)
@@ -53,7 +53,7 @@ static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
        INIT_LIST_HEAD(&o->exe_queue);
        INIT_LIST_HEAD(&o->pending_comp);
 
-       spin_lock_init(&o->lock);
+       spinlock_init_irqsave(&o->lock);
 
        o->exe_chunk_len = exe_len;
        o->owner         = owner;
@@ -81,12 +81,12 @@ static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
        struct bnx2x_exeq_elem *elem;
        int cnt = 0;
 
-       spin_lock_bh(&o->lock);
+       spin_lock(&o->lock);
 
        list_for_each_entry(elem, &o->exe_queue, link)
                cnt++;
 
-       spin_unlock_bh(&o->lock);
+       spin_unlock(&o->lock);
 
        return cnt;
 }
@@ -108,7 +108,7 @@ static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
 {
        int rc;
 
-       spin_lock_bh(&o->lock);
+       spin_lock(&o->lock);
 
        if (!restore) {
                /* Try to cancel this element queue */
@@ -127,14 +127,14 @@ static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
        /* If so, add it to the execution queue */
        list_add_tail(&elem->link, &o->exe_queue);
 
-       spin_unlock_bh(&o->lock);
+       spin_unlock(&o->lock);
 
        return 0;
 
 free_and_exit:
        bnx2x_exe_queue_free_elem(bp, elem);
 
-       spin_unlock_bh(&o->lock);
+       spin_unlock(&o->lock);
 
        return rc;
 }
@@ -193,7 +193,7 @@ static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
        while (!list_empty(&o->exe_queue)) {
                elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
                                        link);
-               WARN_ON(!elem->cmd_len);
+               warn_on(!elem->cmd_len);
 
                if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
                        cur_len += elem->cmd_len;
@@ -242,7 +242,7 @@ static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
        struct bnx2x *bp)
 {
        DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
-       return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
+       return kzmalloc(sizeof(struct bnx2x_exeq_elem), 0);
 }
 
 /************************ raw_obj functions ***********************************/
@@ -253,16 +253,16 @@ static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
 
 static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
 {
-       smp_mb__before_atomic();
+       cmb();
        clear_bit(o->state, o->pstate);
-       smp_mb__after_atomic();
+       cmb();
 }
 
 static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
 {
-       smp_mb__before_atomic();
+       cmb();
        set_bit(o->state, o->pstate);
-       smp_mb__after_atomic();
+       cmb();
 }
 
 /**
@@ -293,7 +293,7 @@ static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
                        return 0;
                }
 
-               usleep_range(1000, 2000);
+               kthread_usleep(1000);
 
                if (bp->panic)
                        return -EIO;
@@ -319,7 +319,7 @@ static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
 {
        struct bnx2x_credit_pool_obj *mp = o->macs_pool;
 
-       WARN_ON(!mp);
+       warn_on(!mp);
 
        return mp->get_entry(mp, offset);
 }
@@ -328,7 +328,7 @@ static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
 {
        struct bnx2x_credit_pool_obj *mp = o->macs_pool;
 
-       WARN_ON(!mp);
+       warn_on(!mp);
 
        return mp->get(mp, 1);
 }
@@ -337,7 +337,7 @@ static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
 {
        struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
 
-       WARN_ON(!vp);
+       warn_on(!vp);
 
        return vp->get_entry(vp, offset);
 }
@@ -346,7 +346,7 @@ static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
 {
        struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
 
-       WARN_ON(!vp);
+       warn_on(!vp);
 
        return vp->get(vp, 1);
 }
@@ -503,9 +503,9 @@ int bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
 {
        int rc;
 
-       spin_lock_bh(&o->exe_queue.lock);
+       spin_lock(&o->exe_queue.lock);
        rc = __bnx2x_vlan_mac_h_read_lock(bp, o);
-       spin_unlock_bh(&o->exe_queue.lock);
+       spin_unlock(&o->exe_queue.lock);
 
        return rc;
 }
@@ -558,9 +558,9 @@ static void __bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
 void bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
                                  struct bnx2x_vlan_mac_obj *o)
 {
-       spin_lock_bh(&o->exe_queue.lock);
+       spin_lock(&o->exe_queue.lock);
        __bnx2x_vlan_mac_h_read_unlock(bp, o);
-       spin_unlock_bh(&o->exe_queue.lock);
+       spin_unlock(&o->exe_queue.lock);
 }
 
 static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
@@ -601,6 +601,8 @@ static int bnx2x_check_mac_add(struct bnx2x *bp,
                               struct bnx2x_vlan_mac_obj *o,
                               union bnx2x_classification_ramrod_data *data)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        struct bnx2x_vlan_mac_registry_elem *pos;
 
        DP(BNX2X_MSG_SP, "Checking MAC %pM for ADD command\n", data->mac.mac);
@@ -615,6 +617,7 @@ static int bnx2x_check_mac_add(struct bnx2x *bp,
                        return -EEXIST;
 
        return 0;
+#endif
 }
 
 static int bnx2x_check_vlan_add(struct bnx2x *bp,
@@ -638,6 +641,8 @@ static struct bnx2x_vlan_mac_registry_elem *
                            struct bnx2x_vlan_mac_obj *o,
                            union bnx2x_classification_ramrod_data *data)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        struct bnx2x_vlan_mac_registry_elem *pos;
 
        DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
@@ -648,6 +653,7 @@ static struct bnx2x_vlan_mac_registry_elem *
                        return pos;
 
        return NULL;
+#endif
 }
 
 static struct bnx2x_vlan_mac_registry_elem *
@@ -1381,7 +1387,7 @@ static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
 
                /* Wait until there are no pending commands */
                if (!bnx2x_exe_queue_empty(exeq))
-                       usleep_range(1000, 2000);
+                       kthread_usleep(1000);
                else
                        return 0;
        }
@@ -1395,7 +1401,7 @@ static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
 {
        int rc = 0;
 
-       spin_lock_bh(&o->exe_queue.lock);
+       spin_lock(&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);
@@ -1410,7 +1416,7 @@ static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
        } else {
                rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
        }
-       spin_unlock_bh(&o->exe_queue.lock);
+       spin_unlock(&o->exe_queue.lock);
 
        return rc;
 }
@@ -1435,7 +1441,7 @@ static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
        /* 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);
+       spin_lock(&o->exe_queue.lock);
 
        /* Reset pending list */
        __bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
@@ -1443,7 +1449,7 @@ static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
        /* Clear pending */
        r->clear_pending(r);
 
-       spin_unlock_bh(&o->exe_queue.lock);
+       spin_unlock(&o->exe_queue.lock);
 
        /* If ramrod failed this is most likely a SW bug */
        if (cqe->message.error)
@@ -1546,7 +1552,7 @@ static inline int bnx2x_vlan_mac_get_registry_elem(
        /* Allocate a new registry element if needed. */
        if (!restore &&
            ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
-               reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
+               reg_elem = kzmalloc(sizeof(*reg_elem), 0);
                if (!reg_elem)
                        return -ENOMEM;
 
@@ -1555,7 +1561,7 @@ static inline int bnx2x_vlan_mac_get_registry_elem(
                        /* This shall never happen, because we have checked the
                         * CAM availability in the 'validate'.
                         */
-                       WARN_ON(1);
+                       warn_on(1);
                        kfree(reg_elem);
                        return -EINVAL;
                }
@@ -1604,7 +1610,7 @@ static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
         * and exit. Otherwise send a ramrod to FW.
         */
        if (!drv_only) {
-               WARN_ON(r->check_pending(r));
+               warn_on(r->check_pending(r));
 
                /* Set pending */
                r->set_pending(r);
@@ -1626,7 +1632,7 @@ static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
                        if (rc)
                                goto error_exit;
 
-                       WARN_ON(!reg_elem);
+                       warn_on(!reg_elem);
 
                        /* Push a new entry into the registry */
                        if (!restore &&
@@ -1668,7 +1674,7 @@ static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
                        reg_elem = o->check_del(bp, o,
                                                &elem->cmd_data.vlan_mac.u);
 
-                       WARN_ON(!reg_elem);
+                       warn_on(!reg_elem);
 
                        o->put_cam_offset(o, reg_elem->cam_offset);
                        list_del(&reg_elem->link);
@@ -1842,7 +1848,7 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
 
        /* Clear pending commands first */
 
-       spin_lock_bh(&exeq->lock);
+       spin_lock(&exeq->lock);
 
        list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
                flags = exeq_pos->cmd_data.vlan_mac.vlan_mac_flags;
@@ -1851,7 +1857,7 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
                        rc = exeq->remove(bp, exeq->owner, exeq_pos);
                        if (rc) {
                                BNX2X_ERR("Failed to remove command\n");
-                               spin_unlock_bh(&exeq->lock);
+                               spin_unlock(&exeq->lock);
                                return rc;
                        }
                        list_del(&exeq_pos->link);
@@ -1859,7 +1865,7 @@ static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
                }
        }
 
-       spin_unlock_bh(&exeq->lock);
+       spin_unlock(&exeq->lock);
 
        /* Prepare a command request */
        memset(&p, 0, sizeof(p));
@@ -2024,7 +2030,7 @@ void bnx2x_init_vlan_obj(struct bnx2x *bp,
 
        if (CHIP_IS_E1x(bp)) {
                BNX2X_ERR("Do not support chips others than E2 and newer\n");
-               BUG();
+               panic("BUG");
        } else {
                vlan_obj->set_one_rule      = bnx2x_set_one_vlan_e2;
                vlan_obj->check_del         = bnx2x_check_vlan_del;
@@ -2134,7 +2140,7 @@ static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
 
        /* The operation is completed */
        clear_bit(p->state, p->pstate);
-       smp_mb__after_atomic();
+       cmb();
 
        return 0;
 }
@@ -2347,7 +2353,10 @@ void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
 /********************* Multicast verbs: SET, CLEAR ****************************/
 static inline uint8_t bnx2x_mcast_bin_from_mac(uint8_t *mac)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        return (crc32c_le(0, mac, Eaddrlen) >> 24) & 0xff;
+#endif
 }
 
 struct bnx2x_mcast_mac_elem {
@@ -2403,7 +2412,7 @@ static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
                macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
 
        /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
-       new_cmd = kzalloc(total_sz, GFP_ATOMIC);
+       new_cmd = kzmalloc(total_sz, 0);
 
        if (!new_cmd)
                return -ENOMEM;
@@ -2955,8 +2964,8 @@ static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
        o->total_pending_num -= cnt;
 
        /* send a ramrod */
-       WARN_ON(o->total_pending_num < 0);
-       WARN_ON(cnt > o->max_cmd_len);
+       warn_on(o->total_pending_num < 0);
+       warn_on(cnt > o->max_cmd_len);
 
        bnx2x_mcast_set_rdata_hdr_e2(bp, p, (uint8_t)cnt);
 
@@ -3382,7 +3391,7 @@ static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
                if (!list_empty(&o->registry.exact_match.macs))
                        return 0;
 
-               elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
+               elem = kzmalloc((len) * (sizeof(*elem)), 0);
                if (!elem) {
                        BNX2X_ERR("Failed to allocate registry memory\n");
                        return -ENOMEM;
@@ -3447,7 +3456,7 @@ static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
 
        /* send a ramrod */
 
-       WARN_ON(cnt > o->max_cmd_len);
+       warn_on(cnt > o->max_cmd_len);
 
        /* Set ramrod header (in particular, a number of entries to update) */
        bnx2x_mcast_set_rdata_hdr_e1(bp, p, (uint8_t)cnt);
@@ -3579,16 +3588,16 @@ error_exit1:
 
 static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
 {
-       smp_mb__before_atomic();
+       cmb();
        clear_bit(o->sched_state, o->raw.pstate);
-       smp_mb__after_atomic();
+       cmb();
 }
 
 static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
 {
-       smp_mb__before_atomic();
+       cmb();
        set_bit(o->sched_state, o->raw.pstate);
-       smp_mb__after_atomic();
+       cmb();
 }
 
 static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
@@ -3701,6 +3710,8 @@ void bnx2x_init_mcast_obj(struct bnx2x *bp,
  */
 static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        int c, old;
 
        c = atomic_read(v);
@@ -3715,6 +3726,7 @@ static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
        }
 
        return true;
+#endif
 }
 
 /**
@@ -3729,6 +3741,8 @@ static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
  */
 static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        int c, old;
 
        c = atomic_read(v);
@@ -3743,38 +3757,45 @@ static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
        }
 
        return true;
+#endif
 }
 
 static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        bool rc;
 
-       smp_mb();
+       mb();
        rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
-       smp_mb();
+       mb();
 
        return rc;
+#endif
 }
 
 static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        bool rc;
 
-       smp_mb();
+       mb();
 
        /* Don't let to refill if credit + cnt > pool_sz */
        rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
 
-       smp_mb();
+       mb();
 
        return rc;
+#endif
 }
 
 static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
 {
        int cur_credit;
 
-       smp_mb();
+       mb();
        cur_credit = atomic_read(&o->credit);
 
        return cur_credit;
@@ -3877,7 +3898,7 @@ static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
        p->base_pool_offset = base;
 
        /* Commit the change */
-       smp_mb();
+       mb();
 
        p->check = bnx2x_credit_pool_check;
 
@@ -4021,6 +4042,8 @@ static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
 static int bnx2x_setup_rss(struct bnx2x *bp,
                           struct bnx2x_config_rss_params *p)
 {
+panic("Not implemented");
+#if 0 // AKAROS_PORT
        struct bnx2x_rss_config_obj *o = p->rss_obj;
        struct bnx2x_raw_obj *r = &o->raw;
        struct eth_rss_update_ramrod_data *data =
@@ -4114,6 +4137,7 @@ static int bnx2x_setup_rss(struct bnx2x *bp,
                return rc;
 
        return 1;
+#endif
 }
 
 void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
@@ -4207,7 +4231,7 @@ int bnx2x_queue_state_change(struct bnx2x *bp,
                if (rc) {
                        o->next_state = BNX2X_Q_STATE_MAX;
                        clear_bit(pending_bit, pending);
-                       smp_mb__after_atomic();
+                       cmb();
                        return rc;
                }
 
@@ -4295,7 +4319,7 @@ static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
        wmb();
 
        clear_bit(cmd, &o->pending);
-       smp_mb__after_atomic();
+       cmb();
 
        return 0;
 }
@@ -4567,7 +4591,7 @@ static inline int bnx2x_q_init(struct bnx2x *bp,
        o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
 
        bus_wmb();
-       smp_mb();
+       mb();
 
        return 0;
 }
@@ -5193,7 +5217,7 @@ void bnx2x_init_queue_obj(struct bnx2x *bp,
        memset(obj, 0, sizeof(*obj));
 
        /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
-       BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
+       assert(!(BNX2X_MULTI_TX_COS < cid_cnt));
 
        memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
        obj->max_cos = cid_cnt;
@@ -5296,7 +5320,7 @@ static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
        wmb();
 
        clear_bit(cmd, &o->pending);
-       smp_mb__after_atomic();
+       cmb();
 
        return 0;
 }
@@ -5978,7 +6002,7 @@ void bnx2x_init_func_obj(struct bnx2x *bp,
 {
        memset(obj, 0, sizeof(*obj));
 
-       mutex_init(&obj->one_pending_mutex);
+       qlock_init(&obj->one_pending_mutex);
 
        obj->rdata = rdata;
        obj->rdata_mapping = rdata_mapping;
@@ -6021,7 +6045,7 @@ int bnx2x_func_state_change(struct bnx2x *bp,
            (test_bit(RAMROD_RETRY, &params->ramrod_flags))) {
                while ((rc == -EBUSY) && (--cnt > 0)) {
                        qunlock(&o->one_pending_mutex);
-                       msleep(10);
+                       kthread_usleep(1000 * 10);
                        qlock(&o->one_pending_mutex);
                        rc = o->check_transition(bp, o, params);
                }
@@ -6051,7 +6075,7 @@ int bnx2x_func_state_change(struct bnx2x *bp,
                if (rc) {
                        o->next_state = BNX2X_F_STATE_MAX;
                        clear_bit(cmd, pending);
-                       smp_mb__after_atomic();
+                       cmb();
                        return rc;
                }