svn commit: r240452 - in head/sys/dev/cxgbe: . tom

Navdeep Parhar np at FreeBSD.org
Thu Sep 13 09:10:10 UTC 2012


Author: np
Date: Thu Sep 13 09:10:10 2012
New Revision: 240452
URL: http://svn.freebsd.org/changeset/base/240452

Log:
  Use native FreeBSD facilities everywhere except the shared code in common/
  
  MFC after:	1 week

Modified:
  head/sys/dev/cxgbe/osdep.h
  head/sys/dev/cxgbe/t4_l2t.h
  head/sys/dev/cxgbe/t4_main.c
  head/sys/dev/cxgbe/tom/t4_ddp.c

Modified: head/sys/dev/cxgbe/osdep.h
==============================================================================
--- head/sys/dev/cxgbe/osdep.h	Thu Sep 13 09:01:52 2012	(r240451)
+++ head/sys/dev/cxgbe/osdep.h	Thu Sep 13 09:10:10 2012	(r240452)
@@ -83,7 +83,7 @@ typedef boolean_t bool;
 #define simple_strtoul strtoul
 #define DIV_ROUND_UP(x, y) howmany(x, y)
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define ARRAY_SIZE(x) nitems(x)
 #define container_of(p, s, f) ((s *)(((uint8_t *)(p)) - offsetof(s, f)))
 
 #define swab16(x) bswap16(x) 

Modified: head/sys/dev/cxgbe/t4_l2t.h
==============================================================================
--- head/sys/dev/cxgbe/t4_l2t.h	Thu Sep 13 09:01:52 2012	(r240451)
+++ head/sys/dev/cxgbe/t4_l2t.h	Thu Sep 13 09:10:10 2012	(r240452)
@@ -94,7 +94,7 @@ int do_l2t_write_rpl(struct sge_iq *, co
 static inline void
 t4_l2t_release(struct l2t_entry *e)
 {
-	struct l2t_data *d = container_of(e, struct l2t_data, l2tab[e->idx]);
+	struct l2t_data *d = member2struct(l2t_data, l2tab[e->idx], e);
 
 	if (atomic_fetchadd_int(&e->refcnt, -1) == 1)
 		atomic_add_int(&d->nfree, 1);

Modified: head/sys/dev/cxgbe/t4_main.c
==============================================================================
--- head/sys/dev/cxgbe/t4_main.c	Thu Sep 13 09:01:52 2012	(r240451)
+++ head/sys/dev/cxgbe/t4_main.c	Thu Sep 13 09:10:10 2012	(r240452)
@@ -381,8 +381,8 @@ CTASSERT(offsetof(struct sge_ofld_rxq, f
 #endif
 
 /* No easy way to include t4_msg.h before adapter.h so we check this way */
-CTASSERT(ARRAY_SIZE(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
-CTASSERT(ARRAY_SIZE(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
+CTASSERT(nitems(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
+CTASSERT(nitems(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
 
 static int
 t4_probe(device_t dev)
@@ -399,7 +399,7 @@ t4_probe(device_t dev)
 	if (d == 0xa000 && f != 0)
 		return (ENXIO);
 
-	for (i = 0; i < ARRAY_SIZE(t4_pciids); i++) {
+	for (i = 0; i < nitems(t4_pciids); i++) {
 		if (d == t4_pciids[i].device) {
 			device_set_desc(dev, t4_pciids[i].desc);
 			return (BUS_PROBE_DEFAULT);
@@ -459,9 +459,9 @@ t4_attach(device_t dev)
 
 	memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
 	sc->an_handler = an_not_handled;
-	for (i = 0; i < ARRAY_SIZE(sc->cpl_handler); i++)
+	for (i = 0; i < nitems(sc->cpl_handler); i++)
 		sc->cpl_handler[i] = cpl_not_handled;
-	for (i = 0; i < ARRAY_SIZE(sc->fw_msg_handler); i++)
+	for (i = 0; i < nitems(sc->fw_msg_handler); i++)
 		sc->fw_msg_handler[i] = fw_msg_not_handled;
 	t4_register_cpl_handler(sc, CPL_SET_TCB_RPL, t4_filter_rpl);
 
@@ -1839,12 +1839,7 @@ get_params__pre_init(struct adapter *sc)
 	}
 
 	sc->params.portvec = val[0];
-	sc->params.nports = 0;
-	while (val[0]) {
-		sc->params.nports++;
-		val[0] &= val[0] - 1;
-	}
-
+	sc->params.nports = bitcount32(val[0]);
 	sc->params.vpd.cclk = val[1];
 
 	/* Read device log parameters. */
@@ -2394,7 +2389,7 @@ adapter_full_init(struct adapter *sc)
 	if (rc != 0)
 		goto done;
 
-	for (i = 0; i < ARRAY_SIZE(sc->tq); i++) {
+	for (i = 0; i < nitems(sc->tq); i++) {
 		sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
 		    taskqueue_thread_enqueue, &sc->tq[i]);
 		if (sc->tq[i] == NULL) {
@@ -2501,7 +2496,7 @@ adapter_full_uninit(struct adapter *sc)
 	for (i = 0; i < sc->intr_count; i++)
 		t4_free_irq(sc, &sc->irq[i]);
 
-	for (i = 0; i < ARRAY_SIZE(sc->tq) && sc->tq[i]; i++) {
+	for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
 		taskqueue_free(sc->tq[i]);
 		sc->tq[i] = NULL;
 	}
@@ -2925,7 +2920,7 @@ t4_get_regs(struct adapter *sc, struct t
 	};
 
 	regs->version = 4 | (sc->params.rev << 10);
-	for (i = 0; i < ARRAY_SIZE(reg_ranges); i += 2)
+	for (i = 0; i < nitems(reg_ranges); i += 2)
 		reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
 }
 
@@ -3001,7 +2996,7 @@ t4_register_cpl_handler(struct adapter *
 {
 	uintptr_t *loc, new;
 
-	if (opcode >= ARRAY_SIZE(sc->cpl_handler))
+	if (opcode >= nitems(sc->cpl_handler))
 		return (EINVAL);
 
 	new = h ? (uintptr_t)h : (uintptr_t)cpl_not_handled;
@@ -3055,7 +3050,7 @@ t4_register_fw_msg_handler(struct adapte
 {
 	uintptr_t *loc, new;
 
-	if (type >= ARRAY_SIZE(sc->fw_msg_handler))
+	if (type >= nitems(sc->fw_msg_handler))
 		return (EINVAL);
 
 	new = h ? (uintptr_t)h : (uintptr_t)fw_msg_not_handled;
@@ -3829,9 +3824,9 @@ sysctl_devlog(SYSCTL_HANDLER_ARGS)
 
 		sbuf_printf(sb, "%10d  %15ju  %8s  %8s  ",
 		    e->seqno, e->timestamp,
-		    (e->level < ARRAY_SIZE(devlog_level_strings) ?
+		    (e->level < nitems(devlog_level_strings) ?
 			devlog_level_strings[e->level] : "UNKNOWN"),
-		    (e->facility < ARRAY_SIZE(devlog_facility_strings) ?
+		    (e->facility < nitems(devlog_facility_strings) ?
 			devlog_facility_strings[e->facility] : "UNKNOWN"));
 		sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
 		    e->params[2], e->params[3], e->params[4],
@@ -3973,7 +3968,7 @@ sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
 		sbuf_printf(sb, "%s                       Loopback %u"
 		    "           Loopback %u", i == 0 ? "" : "\n", i, i + 1);
 
-		for (j = 0; j < ARRAY_SIZE(stat_name); j++)
+		for (j = 0; j < nitems(stat_name); j++)
 			sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
 				   *p0++, *p1++);
 	}
@@ -4028,7 +4023,7 @@ sysctl_meminfo(SYSCTL_HANDLER_ARGS)
 		"ULPTX state:", "On-chip queues:"
 	};
 	struct mem_desc avail[3];
-	struct mem_desc mem[ARRAY_SIZE(region) + 3];	/* up to 3 holes */
+	struct mem_desc mem[nitems(region) + 3];	/* up to 3 holes */
 	struct mem_desc *md = mem;
 
 	rc = sysctl_wire_old_buffer(req, 0);
@@ -4039,7 +4034,7 @@ sysctl_meminfo(SYSCTL_HANDLER_ARGS)
 	if (sb == NULL)
 		return (ENOMEM);
 
-	for (i = 0; i < ARRAY_SIZE(mem); i++) {
+	for (i = 0; i < nitems(mem); i++) {
 		mem[i].limit = 0;
 		mem[i].idx = i;
 	}
@@ -4101,7 +4096,7 @@ sysctl_meminfo(SYSCTL_HANDLER_ARGS)
 		md->limit = (sc->tids.ntids - hi) * 16 + md->base - 1;
 	} else {
 		md->base = 0;
-		md->idx = ARRAY_SIZE(region);  /* hide it */
+		md->idx = nitems(region);  /* hide it */
 	}
 	md++;
 
@@ -4130,7 +4125,7 @@ sysctl_meminfo(SYSCTL_HANDLER_ARGS)
 	if (sc->vres.ocq.size)
 		md->limit = md->base + sc->vres.ocq.size - 1;
 	else
-		md->idx = ARRAY_SIZE(region);  /* hide it */
+		md->idx = nitems(region);  /* hide it */
 	md++;
 
 	/* add any address-space holes, there can be up to 3 */
@@ -4149,7 +4144,7 @@ sysctl_meminfo(SYSCTL_HANDLER_ARGS)
 
 	sbuf_printf(sb, "\n");
 	for (i = 0; i < n; i++) {
-		if (mem[i].idx >= ARRAY_SIZE(region))
+		if (mem[i].idx >= nitems(region))
 			continue;                        /* skip holes */
 		if (!mem[i].limit)
 			mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
@@ -5197,7 +5192,7 @@ t4_os_portmod_changed(const struct adapt
 		if_printf(pi->ifp, "unknown transceiver inserted.\n");
 	else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
 		if_printf(pi->ifp, "unsupported transceiver inserted.\n");
-	else if (pi->mod_type > 0 && pi->mod_type < ARRAY_SIZE(mod_str)) {
+	else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
 		if_printf(pi->ifp, "%s transceiver inserted.\n",
 		    mod_str[pi->mod_type]);
 	} else {

Modified: head/sys/dev/cxgbe/tom/t4_ddp.c
==============================================================================
--- head/sys/dev/cxgbe/tom/t4_ddp.c	Thu Sep 13 09:01:52 2012	(r240451)
+++ head/sys/dev/cxgbe/tom/t4_ddp.c	Thu Sep 13 09:10:10 2012	(r240452)
@@ -197,7 +197,7 @@ release_ddp_resources(struct toepcb *toe
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(toep->db); i++) {
+	for (i = 0; i < nitems(toep->db); i++) {
 		if (toep->db[i] != NULL) {
 			free_ddp_buffer(toep->td, toep->db[i]);
 			toep->db[i] = NULL;
@@ -662,7 +662,7 @@ alloc_ddp_buffer(struct tom_data *td, vm
 		return (NULL);
 	}
 
-	for (idx = ARRAY_SIZE(t4_ddp_pgsz) - 1; idx > 0; idx--) {
+	for (idx = nitems(t4_ddp_pgsz) - 1; idx > 0; idx--) {
 		if (hcf % t4_ddp_pgsz[idx] == 0)
 			break;
 	}
@@ -745,7 +745,7 @@ write_page_pods(struct adapter *sc, stru
 			    V_PPOD_OFST(db->offset));
 			ppod->rsvd = 0;
 			idx = i * PPOD_PAGES * (ddp_pgsz / PAGE_SIZE);
-			for (k = 0; k < ARRAY_SIZE(ppod->addr); k++) {
+			for (k = 0; k < nitems(ppod->addr); k++) {
 				if (idx < db->npages) {
 					ppod->addr[k] =
 					    htobe64(db->pages[idx]->phys_addr);
@@ -782,7 +782,7 @@ select_ddp_buffer(struct adapter *sc, st
 	int i, empty_slot = -1;
 
 	/* Try to reuse */
-	for (i = 0; i < ARRAY_SIZE(toep->db); i++) {
+	for (i = 0; i < nitems(toep->db); i++) {
 		if (bufcmp(toep->db[i], pages, npages, db_off, db_len) == 0) {
 			free(pages, M_CXGBE);
 			return (i);	/* pages still held */
@@ -805,7 +805,7 @@ select_ddp_buffer(struct adapter *sc, st
 
 	i = empty_slot;
 	if (i < 0) {
-		i = arc4random() % ARRAY_SIZE(toep->db);
+		i = arc4random() % nitems(toep->db);
 		free_ddp_buffer(td, toep->db[i]);
 	}
 	toep->db[i] = db;


More information about the svn-src-all mailing list