summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2012-10-11 16:33:58 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2012-10-11 16:33:58 +0000
commit1739abc58ad6a43d78926ce243c5e3c34a94fcc7 (patch)
treec965623dd78cf226caf151a4cecf9a4f73d47923 /sys/dev
parent395f7bac4b34266619d2abb3e96f40f59e430e66 (diff)
better integer log2 implementation, checked with what linux is doing
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_oce.c4
-rw-r--r--sys/dev/pci/oce.c16
-rw-r--r--sys/dev/pci/ocevar.h27
3 files changed, 17 insertions, 30 deletions
diff --git a/sys/dev/pci/if_oce.c b/sys/dev/pci/if_oce.c
index ac3b14ac91c..a100efd7d4b 100644
--- a/sys/dev/pci/if_oce.c
+++ b/sys/dev/pci/if_oce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_oce.c,v 1.14 2012/08/09 19:29:03 mikeb Exp $ */
+/* $OpenBSD: if_oce.c,v 1.15 2012/10/11 16:33:57 mikeb Exp $ */
/*
* Copyright (c) 2012 Mike Belopuhov
@@ -1844,7 +1844,7 @@ oce_rq_init(struct oce_softc *sc, uint32_t q_len, uint32_t frag_size,
struct oce_rq *rq;
int rc = 0, i;
- if (OCE_LOG2(frag_size) <= 0)
+ if (ilog2(frag_size) <= 0)
return NULL;
/* Hardware doesn't support any other value */
diff --git a/sys/dev/pci/oce.c b/sys/dev/pci/oce.c
index dec19f98d1e..c0e19e8daba 100644
--- a/sys/dev/pci/oce.c
+++ b/sys/dev/pci/oce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: oce.c,v 1.6 2012/08/10 16:24:56 mikeb Exp $ */
+/* $OpenBSD: oce.c,v 1.7 2012/10/11 16:33:57 mikeb Exp $ */
/*-
* Copyright (C) 2012 Emulex
@@ -1079,7 +1079,7 @@ oce_rss_itbl_init(struct oce_softc *sc, struct mbx_config_nic_rss *fwcmd)
/* fill log2 value indicating the size of the CPU table */
if (rc == 0)
- fwcmd->params.req.cpu_tbl_sz_log2 = htole16(OCE_LOG2(i));
+ fwcmd->params.req.cpu_tbl_sz_log2 = htole16(ilog2(i));
return rc;
}
@@ -1583,7 +1583,7 @@ oce_mbox_create_rq(struct oce_rq *rq)
fwcmd->params.req.frag_size = rq->cfg.frag_size / 2048;
fwcmd->params.req.page_size = 1;
} else
- fwcmd->params.req.frag_size = OCE_LOG2(rq->cfg.frag_size);
+ fwcmd->params.req.frag_size = ilog2(rq->cfg.frag_size);
fwcmd->params.req.num_pages = num_pages;
fwcmd->params.req.cq_id = rq->cq->cq_id;
fwcmd->params.req.if_id = htole32(sc->if_id);
@@ -1636,7 +1636,7 @@ oce_mbox_create_wq(struct oce_wq *wq)
fwcmd->params.req.nic_wq_type = wq->cfg.wq_type;
fwcmd->params.req.num_pages = num_pages;
- fwcmd->params.req.wq_size = OCE_LOG2(wq->cfg.q_len) + 1;
+ fwcmd->params.req.wq_size = ilog2(wq->cfg.q_len) + 1;
fwcmd->params.req.cq_id = htole16(wq->cq->cq_id);
fwcmd->params.req.ulp_num = 1;
@@ -1683,7 +1683,7 @@ oce_mbox_create_mq(struct oce_mq *mq)
ctx = &fwcmd->params.req.context;
ctx->v0.num_pages = num_pages;
ctx->v0.cq_id = mq->cq->cq_id;
- ctx->v0.ring_size = OCE_LOG2(mq->cfg.q_len) + 1;
+ ctx->v0.ring_size = ilog2(mq->cfg.q_len) + 1;
ctx->v0.valid = 1;
/* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
ctx->v0.async_evt_bitmap = 0xffffffff;
@@ -1731,7 +1731,7 @@ oce_mbox_create_eq(struct oce_eq *eq)
fwcmd->params.req.ctx.num_pages = htole16(num_pages);
fwcmd->params.req.ctx.valid = 1;
fwcmd->params.req.ctx.size = (eq->eq_cfg.item_size == 4) ? 0 : 1;
- fwcmd->params.req.ctx.count = OCE_LOG2(eq->eq_cfg.q_len / 256);
+ fwcmd->params.req.ctx.count = ilog2(eq->eq_cfg.q_len / 256);
fwcmd->params.req.ctx.armed = 0;
fwcmd->params.req.ctx.delay_mult = htole32(eq->eq_cfg.cur_eqd);
@@ -1793,7 +1793,7 @@ oce_mbox_create_cq(struct oce_cq *cq, uint32_t ncoalesce,
ctx->v2.page_size = page_size;
ctx->v2.eventable = is_eventable;
ctx->v2.valid = 1;
- ctx->v2.count = OCE_LOG2(cq->cq_cfg.q_len / 256);
+ ctx->v2.count = ilog2(cq->cq_cfg.q_len / 256);
ctx->v2.nodelay = cq->cq_cfg.nodelay;
ctx->v2.coalesce_wm = ncoalesce;
ctx->v2.armed = 0;
@@ -1808,7 +1808,7 @@ oce_mbox_create_cq(struct oce_cq *cq, uint32_t ncoalesce,
ctx->v0.num_pages = htole16(num_pages);
ctx->v0.eventable = is_eventable;
ctx->v0.valid = 1;
- ctx->v0.count = OCE_LOG2(cq->cq_cfg.q_len / 256);
+ ctx->v0.count = ilog2(cq->cq_cfg.q_len / 256);
ctx->v0.nodelay = cq->cq_cfg.nodelay;
ctx->v0.coalesce_wm = ncoalesce;
ctx->v0.armed = 0;
diff --git a/sys/dev/pci/ocevar.h b/sys/dev/pci/ocevar.h
index 3d143ae5146..1f4b6432710 100644
--- a/sys/dev/pci/ocevar.h
+++ b/sys/dev/pci/ocevar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ocevar.h,v 1.10 2012/08/09 19:23:35 mikeb Exp $ */
+/* $OpenBSD: ocevar.h,v 1.11 2012/10/11 16:33:57 mikeb Exp $ */
/*-
* Copyright (C) 2012 Emulex
@@ -857,25 +857,12 @@ int oce_stats_get(struct oce_softc *sc, u_int64_t *rxe, u_int64_t *txe);
#define IF_LSO_ENABLED(ifp) (((ifp)->if_capabilities & IFCAP_TSO4) ? 1:0)
#define IF_CSUM_ENABLED(ifp) (((ifp)->if_capabilities & IFCAP_HWCSUM) ? 1:0)
-#define OCE_LOG2(x) (oce_highbit(x))
-static inline uint32_t oce_highbit(uint32_t x)
+static inline int
+ilog2(unsigned int v)
{
- int i;
- int c;
- int b;
+ int r = 0;
- c = 0;
- b = 0;
-
- for (i = 0; i < 32; i++) {
- if ((1 << i) & x) {
- c++;
- b = i;
- }
- }
-
- if (c == 1)
- return b;
-
- return 0;
+ while (v >>= 1)
+ r++;
+ return (r);
}