BNX2X: Spatch min, min_t, etc
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 6 Feb 2015 16:24:34 +0000 (11:24 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 2 Mar 2015 16:59:08 +0000 (11:59 -0500)
Keeping the _t versions around, since they might be needed later on.  Though
they are just the regular MIN/MAX for now.

Also, the spatch didn't like bnx2x.h (again), and also something in sriov.c.

kern/drivers/net/bnx2x/akaros_compat.h
kern/drivers/net/bnx2x/bnx2x.h
kern/drivers/net/bnx2x/bnx2x_cmn.c
kern/drivers/net/bnx2x/bnx2x_dcb.c
kern/drivers/net/bnx2x/bnx2x_ethtool.c
kern/drivers/net/bnx2x/bnx2x_init_ops.h
kern/drivers/net/bnx2x/bnx2x_main.c
kern/drivers/net/bnx2x/bnx2x_sriov.c
kern/drivers/net/bnx2x/bnx2x_vfpf.c
scripts/spatch/linux/funcs.cocci

index 9c13b43..096f5e1 100644 (file)
 #define __rcu
 #define unlikely(x) (x)
 
+/* Wanted to keep the _t variants in the code, in case that's useful in the
+ * future */
+#define MIN_T(t, a, b) MIN(a, b)
+#define MAX_T(t, a, b) MAX(a, b)
+#define CLAMP(val, lo, hi) MIN((typeof(val))MAX(val, lo), hi)
+#define CLAMP_T(t, val, lo, hi) CLAMP(val, lo, hi)
+
 typedef unsigned long dma_addr_t;
 /* these dma funcs are empty in linux with !CONFIG_NEED_DMA_MAP_STATE */
 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
@@ -86,16 +93,23 @@ typedef int pci_power_t;
 #define pr_cont(fmt, ...) \
        printk(KERN_CONT fmt, ##__VA_ARGS__)
 
-/* pr_devel() should produce zero code unless DEBUG is defined */
+
 #ifdef DEBUG
+
+#define might_sleep() assert(can_block(&per_cpu_info[core_id()]))
 #define pr_devel(fmt, ...) \
        printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+
 #else
+
+#define might_sleep()
 #define pr_devel(fmt, ...) \
        printd(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+
 #endif
 #define pr_debug pr_devel
 
+
 enum {
        NETIF_MSG_DRV           = 0x0001,
        NETIF_MSG_PROBE         = 0x0002,
index 9f699b1..8e18b27 100644 (file)
@@ -373,7 +373,7 @@ union db_prod {
 #define SGE_PAGE_SHIFT         PAGE_SHIFT
 #define SGE_PAGE_ALIGN(addr)   PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
 #define SGE_PAGES              (SGE_PAGE_SIZE * PAGES_PER_SGE)
-#define TPA_AGG_SIZE           min_t(uint32_t, (min_t(uint32_t, 8, MAX_SKB_FRAGS) * \
+#define TPA_AGG_SIZE           MIN_T(uint32_t, (MIN_T(uint32_t, 8, MAX_SKB_FRAGS) * \
                                            SGE_PAGES), 0xffff)
 
 /* SGE ring related macros */
@@ -822,8 +822,8 @@ static inline bool bnx2x_fp_ll_disable(struct bnx2x_fastpath *fp)
                                        ETH_MIN_RX_CQES_WITH_TPA_E1 : \
                                        ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
 #define MIN_RX_SIZE_NONTPA_HW   ETH_MIN_RX_CQES_WITHOUT_TPA
-#define MIN_RX_SIZE_TPA                (max_t(uint32_t, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
-#define MIN_RX_SIZE_NONTPA     (max_t(uint32_t, MIN_RX_SIZE_NONTPA_HW,\
+#define MIN_RX_SIZE_TPA                (MAX_T(uint32_t, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
+#define MIN_RX_SIZE_NONTPA     (MAX_T(uint32_t, MIN_RX_SIZE_NONTPA_HW,\
                                                                MIN_RX_AVAIL))
 
 #define NEXT_RX_IDX(x)         ((((x) & RX_DESC_MASK) == \
@@ -1511,7 +1511,7 @@ struct bnx2x {
        /* Max supported alignment is 256 (8 shift)
         * minimal alignment shift 6 is optimal for 57xxx HW performance
         */
-#define BNX2X_RX_ALIGN_SHIFT           max(6, min(8, L1_CACHE_SHIFT))
+#define BNX2X_RX_ALIGN_SHIFT           MAX(6, MIN(8, L1_CACHE_SHIFT))
 
        /* FW uses 2 Cache lines Alignment for start packet and size
         *
@@ -1522,7 +1522,7 @@ struct bnx2x {
 #define BNX2X_FW_RX_ALIGN_START        (1UL << BNX2X_RX_ALIGN_SHIFT)
 
 #define BNX2X_FW_RX_ALIGN_END                                  \
-       max_t(uint64_t, 1UL << BNX2X_RX_ALIGN_SHIFT,                    \
+       MAX_T(uint64_t, 1UL << BNX2X_RX_ALIGN_SHIFT,                    \
            SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
 
 #define BNX2X_PXP_DRAM_ALIGN           (BNX2X_RX_ALIGN_SHIFT - 5)
index 05360f1..7b08a3f 100644 (file)
@@ -58,7 +58,7 @@ static int bnx2x_calc_num_queues(struct bnx2x *bp)
        if (is_kdump_kernel())
                nq = 1;
 
-       nq = clamp(nq, 1, BNX2X_MAX_QUEUES(bp));
+       nq = CLAMP(nq, 1, BNX2X_MAX_QUEUES(bp));
        return nq;
 }
 
@@ -588,7 +588,7 @@ static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
                                     le16_to_cpu(cqe->num_of_coalesced_segs));
 
 #ifdef BNX2X_STOP_ON_ERROR
-       if (pages > min_t(uint32_t, 8, MAX_SKB_FRAGS) * SGE_PAGES) {
+       if (pages > MIN_T(uint32_t, 8, MAX_SKB_FRAGS) * SGE_PAGES) {
                BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
                          pages, cqe_idx);
                BNX2X_ERR("cqe->pkt_len = %d\n", cqe->pkt_len);
@@ -604,10 +604,10 @@ static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
                /* FW gives the indices of the SGE as if the ring is an array
                   (meaning that "next" element will consume 2 indices) */
                if (fp->mode == TPA_MODE_GRO)
-                       frag_len = min_t(uint32_t, frag_size,
+                       frag_len = MIN_T(uint32_t, frag_size,
                                         (uint32_t)full_page);
                else /* LRO */
-                       frag_len = min_t(uint32_t, frag_size,
+                       frag_len = MIN_T(uint32_t, frag_size,
                                         (uint32_t)SGE_PAGES);
 
                rx_pg = &fp->rx_page_ring[sge_idx];
@@ -4376,8 +4376,8 @@ static int bnx2x_alloc_rx_bds(struct bnx2x_fastpath *fp,
 
        fp->rx_bd_prod = ring_prod;
        /* Limit the CQE producer by the CQE ring size */
-       fp->rx_comp_prod = min_t(uint16_t, NUM_RCQ_RINGS*RCQ_DESC_CNT,
-                              cqe_ring_prod);
+       fp->rx_comp_prod = MIN_T(uint16_t, NUM_RCQ_RINGS * RCQ_DESC_CNT,
+                                cqe_ring_prod);
        fp->rx_pkt = fp->rx_calls = 0;
 
        bnx2x_fp_stats(bp, fp)->eth_q_stats.rx_skb_alloc_failed += failure_cnt;
@@ -4429,8 +4429,9 @@ static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
                }
 
                /* allocate at least number of buffers required by FW */
-               rx_ring_size = max_t(int, bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
-                                    MIN_RX_SIZE_TPA, rx_ring_size);
+               rx_ring_size = MAX_T(int,
+                                    bp->disable_tpa ? MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA,
+                                    rx_ring_size);
 
                bp->rx_ring_size = rx_ring_size;
        } else /* if rx_ring_size specified - use it */
index 8ca60c9..7fe2e24 100644 (file)
@@ -179,7 +179,7 @@ static void bnx2x_dcbx_get_ap_priority(struct bnx2x *bp,
        }
 
        if (pri < MAX_PFC_PRIORITIES)
-               ttp[llfc_traf_type] = max_t(uint32_t, ttp[llfc_traf_type],
+               ttp[llfc_traf_type] = MAX_T(uint32_t, ttp[llfc_traf_type],
                                            pri);
 }
 
@@ -1698,10 +1698,9 @@ static void bnx2x_dcbx_cee_fill_cos_params(struct bnx2x *bp,
 
                        entry++;
                } else {
-                       need_num_of_entries =  min_t(uint8_t,
-                               (uint8_t)pg->num_of_dif_pri,
-                               (uint8_t)DCBX_COS_MAX_NUM_E3B0 -
-                                                help_data->num_of_pg + 1);
+                       need_num_of_entries =  MIN_T(uint8_t,
+                                                    (uint8_t)pg->num_of_dif_pri,
+                                                    (uint8_t)DCBX_COS_MAX_NUM_E3B0 - help_data->num_of_pg + 1);
                        /*
                         * If there are still VOQ-s which have no associated PG,
                         * then associate these VOQ-s to PG15. These PG-s will
index 6abf12c..4242cdf 100644 (file)
@@ -2682,7 +2682,7 @@ static int bnx2x_nvram_crc(struct bnx2x *bp,
           "NVRAM CRC from 0x%08x to 0x%08x\n", offset, offset + size);
 
        while (done < size) {
-               int count = min_t(int, size - done, CRC_BUFF_SIZE);
+               int count = MIN_T(int, size - done, CRC_BUFF_SIZE);
 
                rc = bnx2x_nvram_read(bp, offset + done, buff, count);
 
index 30d03db..e9d850b 100644 (file)
@@ -90,7 +90,7 @@ static void bnx2x_init_fill(struct bnx2x *bp, uint32_t addr, int fill,
        memset(GUNZIP_BUF(bp), (uint8_t)fill, buf_len);
 
        for (i = 0; i < len; i += buf_len32) {
-               uint32_t cur_len = min(buf_len32, len - i);
+               uint32_t cur_len = MIN(buf_len32, len - i);
 
                bnx2x_write_big_buf(bp, addr + i*4, cur_len, wb);
        }
@@ -122,7 +122,7 @@ static void bnx2x_init_wr_64(struct bnx2x *bp, uint32_t addr,
        /* 64 bit value is in a blob: first low DWORD, then high DWORD */
        data64 = HILO_U64((*(data + 1)), (*data));
 
-       len64 = min((uint32_t)(FW_BUF_SIZE/8), len64);
+       len64 = MIN((uint32_t)(FW_BUF_SIZE / 8), len64);
        for (i = 0; i < len64; i++) {
                uint64_t *pdata = ((uint64_t *)(GUNZIP_BUF(bp))) + i;
 
@@ -130,7 +130,7 @@ static void bnx2x_init_wr_64(struct bnx2x *bp, uint32_t addr,
        }
 
        for (i = 0; i < len; i += buf_len32) {
-               uint32_t cur_len = min(buf_len32, len - i);
+               uint32_t cur_len = MIN(buf_len32, len - i);
 
                bnx2x_write_big_buf_wb(bp, addr + i*4, cur_len);
        }
index 9d20672..426124f 100644 (file)
@@ -3155,7 +3155,7 @@ static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
                        SGE_PAGE_SHIFT;
                max_sge = ((max_sge + PAGES_PER_SGE - 1) &
                          (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
-               sge_sz = (uint16_t)min_t(uint32_t, SGE_PAGES, 0xffff);
+               sge_sz = (uint16_t)MIN_T(uint32_t, SGE_PAGES, 0xffff);
        }
 
        /* pause - not for e1 */
@@ -6063,7 +6063,7 @@ static void bnx2x_init_eq_ring(struct bnx2x *bp)
        bp->eq_cons_sb = BNX2X_EQ_INDEX;
        /* we want a warning message before it gets wrought... */
        atomic_set(&bp->eq_spq_left,
-               min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
+               MIN_T(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
 }
 
 /* called with netif_addr_lock_bh() */
@@ -8273,7 +8273,7 @@ int bnx2x_alloc_mem(struct bnx2x *bp)
        context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
 
        for (i = 0, allocated = 0; allocated < context_size; i++) {
-               bp->context[i].size = min(CDU_ILT_PAGE_SZ,
+               bp->context[i].size = MIN(CDU_ILT_PAGE_SZ,
                                          (context_size - allocated));
                bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
                                                      bp->context[i].size);
@@ -10879,7 +10879,7 @@ static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
         * Driver should use the minimal value of both as the actual status
         * block count
         */
-       bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
+       bp->igu_sb_cnt = MIN_T(int, bp->igu_sb_cnt, igu_sb_cnt);
 #endif
 
        if (igu_sb_cnt == 0) {
@@ -11851,7 +11851,7 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
 
        /* adjust igu_sb_cnt to MF for E1H */
        if (CHIP_IS_E1H(bp) && IS_MF(bp))
-               bp->igu_sb_cnt = min_t(uint8_t, bp->igu_sb_cnt,
+               bp->igu_sb_cnt = MIN_T(uint8_t, bp->igu_sb_cnt,
                                       E1H_MAX_MF_SB_COUNT);
 
        /* port info */
index 9ab0da4..f739068 100644 (file)
@@ -1293,7 +1293,7 @@ int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
        if (iov->total == 0)
                goto failed;
 
-       iov->nr_virtfn = min_t(uint16_t, iov->total, num_vfs_param);
+       iov->nr_virtfn = MIN_T(uint16_t, iov->total, num_vfs_param);
 
        DP(BNX2X_MSG_IOV, "num_vfs_param was %d, nr_virtfn was %d\n",
           num_vfs_param, iov->nr_virtfn);
@@ -1412,7 +1412,7 @@ int bnx2x_iov_alloc_mem(struct bnx2x *bp)
 
        for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
                struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
-               cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
+               cxt->size = MIN_T(size_t, tot_size, CDU_ILT_PAGE_SZ);
 
                if (cxt->size) {
                        cxt->addr = BNX2X_PCI_ALLOC(&cxt->mapping, cxt->size);
@@ -2023,8 +2023,8 @@ static void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf)
 
 uint8_t bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
 {
-       return min_t(uint8_t,
-                    min_t(uint8_t, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
+       return MIN_T(uint8_t,
+                    MIN_T(uint8_t, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
                     BNX2X_VF_MAX_QUEUES);
 }
 
@@ -2507,7 +2507,7 @@ int bnx2x_enable_sriov(struct bnx2x *bp)
        first_vf = bp->vfdb->sriov.first_vf_in_pf;
 
        /* statically distribute vf sb pool between VFs */
-       num_vf_queues = min_t(uint16_t, BNX2X_VF_MAX_QUEUES,
+       num_vf_queues = MIN_T(uint16_t, BNX2X_VF_MAX_QUEUES,
                              BP_VFDB(bp)->vf_sbs_pool / req_vfs);
 
        /* zero previous values learned from igu cam */
index ae3b1f4..3398f5e 100644 (file)
@@ -298,22 +298,22 @@ int bnx2x_vfpf_acquire(struct bnx2x *bp, uint8_t tx_count, uint8_t rx_count)
 
                        /* humble our request */
                        req->resc_request.num_txqs =
-                               min(req->resc_request.num_txqs,
+                               MIN(req->resc_request.num_txqs,
                                    bp->acquire_resp.resc.num_txqs);
                        req->resc_request.num_rxqs =
-                               min(req->resc_request.num_rxqs,
+                               MIN(req->resc_request.num_rxqs,
                                    bp->acquire_resp.resc.num_rxqs);
                        req->resc_request.num_sbs =
-                               min(req->resc_request.num_sbs,
+                               MIN(req->resc_request.num_sbs,
                                    bp->acquire_resp.resc.num_sbs);
                        req->resc_request.num_mac_filters =
-                               min(req->resc_request.num_mac_filters,
+                               MIN(req->resc_request.num_mac_filters,
                                    bp->acquire_resp.resc.num_mac_filters);
                        req->resc_request.num_vlan_filters =
-                               min(req->resc_request.num_vlan_filters,
+                               MIN(req->resc_request.num_vlan_filters,
                                    bp->acquire_resp.resc.num_vlan_filters);
                        req->resc_request.num_mc_filters =
-                               min(req->resc_request.num_mc_filters,
+                               MIN(req->resc_request.num_mc_filters,
                                    bp->acquire_resp.resc.num_mc_filters);
 
                        /* Clear response buffer */
@@ -1350,7 +1350,7 @@ static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
        if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
                vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
        else
-               vf->fp_hsi = max_t(uint8_t, acquire->vfdev_info.fp_hsi_ver,
+               vf->fp_hsi = MAX_T(uint8_t, acquire->vfdev_info.fp_hsi_ver,
                                   ETH_FP_HSI_VER_2);
        if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
                DP(BNX2X_MSG_IOV,
index 27a1ca7..e502079 100644 (file)
@@ -43,3 +43,50 @@ expression TMAX;
 @@
 -smp_wmb();
 +wmb();
+
+@@
+expression A0;
+expression A1;
+@@
+-min(A0, A1)
++MIN(A0, A1)
+
+@@
+expression A0;
+expression A1;
+@@
+-max(A0, A1)
++MAX(A0, A1)
+
+@@
+expression LO;
+expression HI;
+expression V;
+@@
+-clamp(V, LO, HI)
++CLAMP(V, LO, HI)
+
+@@
+expression A0;
+expression A1;
+type T;
+@@
+-min_t(T, A0, A1)
++MIN_T(T, A0, A1)
+
+@@
+expression A0;
+expression A1;
+type T;
+@@
+-max_t(T, A0, A1)
++MAX_T(T, A0, A1)
+
+@@
+expression LO;
+expression HI;
+expression V;
+type T;
+@@
+-clamp_t(T, V, LO, HI)
++CLAMP_T(T, V, LO, HI)