sys/dev: extend use of the howmany() macro when available.

We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
This commit is contained in:
Pedro F. Giffuni 2016-04-26 15:03:15 +00:00
parent 768f89e078
commit 057b4402bf
30 changed files with 47 additions and 52 deletions

View File

@ -2486,7 +2486,7 @@ age_rxintr(struct age_softc *sc, int rr_prod, int count)
* I'm not sure whether this check is really needed.
*/
pktlen = AGE_RX_BYTES(le32toh(rxrd->len));
if (nsegs != (pktlen + (AGE_RX_BUF_SIZE - 1)) / AGE_RX_BUF_SIZE)
if (nsegs != howmany(pktlen, AGE_RX_BUF_SIZE))
break;
/* Received a frame. */

View File

@ -1316,7 +1316,7 @@ amr_bio_command(struct amr_softc *sc, struct amr_command **acp)
}
amrd = (struct amrd_softc *)bio->bio_disk->d_drv1;
driveno = amrd->amrd_drive - sc->amr_drive;
blkcount = (bio->bio_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE;
blkcount = howmany(bio->bio_bcount, AMR_BLKSIZE);
ac->ac_mailbox.mb_command = cmd;
if (bio->bio_cmd == BIO_READ || bio->bio_cmd == BIO_WRITE) {

View File

@ -11166,7 +11166,7 @@ bwn_phy_lp_b2063_switch_channel(struct bwn_mac *mac, uint8_t chan)
tmp[2] = ((41 * (val[2] - 3000)) /1200) + 27;
tmp[3] = bwn_phy_lp_roundup(132000 * tmp[0], 8451, 16);
if ((tmp[3] + tmp[2] - 1) / tmp[2] > 60) {
if (howmany(tmp[3], tmp[2]) > 60) {
scale = 1;
tmp[4] = ((tmp[3] + tmp[2]) / (tmp[2] << 1)) - 8;
} else {

View File

@ -1347,7 +1347,7 @@ cyparam(struct tty *tp, struct termios *t)
/*
* Set receive time-out period, normally to max(one char time, 5 ms).
*/
itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
itimeout = howmany(1000 * bits, t->c_ispeed);
#ifdef SOFT_HOTCHAR
#define MIN_RTP 1
#else

View File

@ -1085,7 +1085,7 @@ fatm_supply_small_buffers(struct fatm_softc *sc)
nbufs = min(nbufs, SMALL_POOL_SIZE);
nbufs -= sc->small_cnt;
nblocks = (nbufs + SMALL_SUPPLY_BLKSIZE - 1) / SMALL_SUPPLY_BLKSIZE;
nblocks = howmany(nbufs, SMALL_SUPPLY_BLKSIZE);
for (cnt = 0; cnt < nblocks; cnt++) {
q = GET_QUEUE(sc->s1queue, struct supqueue, sc->s1queue.head);
@ -1174,7 +1174,7 @@ fatm_supply_large_buffers(struct fatm_softc *sc)
nbufs = min(nbufs, LARGE_POOL_SIZE);
nbufs -= sc->large_cnt;
nblocks = (nbufs + LARGE_SUPPLY_BLKSIZE - 1) / LARGE_SUPPLY_BLKSIZE;
nblocks = howmany(nbufs, LARGE_SUPPLY_BLKSIZE);
for (cnt = 0; cnt < nblocks; cnt++) {
q = GET_QUEUE(sc->l1queue, struct supqueue, sc->l1queue.head);

View File

@ -1247,8 +1247,8 @@ set_line_length(video_adapter_t *adp, int pixel)
switch (adp->va_info.vi_mem_model) {
case V_INFO_MM_PLANAR:
ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
count = (pixel + ppw - 1)/ppw/2;
bpl = ((pixel + ppw - 1)/ppw/2)*4;
count = howmany(pixel, ppw)/2;
bpl = (howmany(pixel, ppw)/2)*4;
break;
case V_INFO_MM_PACKED:
count = (pixel + 7)/8;

View File

@ -2664,7 +2664,7 @@ jme_rxintr(struct jme_softc *sc, int count)
* sure whether this check is needed.
*/
pktlen = JME_RX_BYTES(le32toh(desc->buflen));
if (nsegs != ((pktlen + (MCLBYTES - 1)) / MCLBYTES))
if (nsegs != howmany(pktlen, MCLBYTES))
break;
prog++;
/* Received a frame. */

View File

@ -922,7 +922,7 @@ mcd_doread(struct mcd_softc *sc, int state, struct mcd_mbx *mbxin)
RDELAY_WAITMODE-mbx->count);
modedone:
/* for first block */
mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz;
mbx->nblk = howmany(bp->bio_bcount, mbx->sz);
mbx->skip = 0;
nextblock:

View File

@ -2156,7 +2156,7 @@ mfi_build_syspdio(struct mfi_softc *sc, struct bio *bio)
}
/* Cheat with the sector length to avoid a non-constant division */
blkcount = (bio->bio_bcount + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
blkcount = howmany(bio->bio_bcount, MFI_SECTOR_LEN);
/* Fill the LBA and Transfer length in CDB */
cdb_len = mfi_build_cdb(readop, 0, bio->bio_pblkno, blkcount,
pass->cdb);
@ -2215,7 +2215,7 @@ mfi_build_ldio(struct mfi_softc *sc, struct bio *bio)
}
/* Cheat with the sector length to avoid a non-constant division */
blkcount = (bio->bio_bcount + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
blkcount = howmany(bio->bio_bcount, MFI_SECTOR_LEN);
io->header.target_id = (uintptr_t)bio->bio_driver1;
io->header.timeout = 0;
io->header.flags = 0;
@ -2622,7 +2622,7 @@ mfi_dump_blocks(struct mfi_softc *sc, int id, uint64_t lba, void *virt,
io->header.flags = 0;
io->header.scsi_status = 0;
io->header.sense_len = MFI_SENSE_LEN;
io->header.data_len = (len + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
io->header.data_len = howmany(len, MFI_SECTOR_LEN);
io->sense_addr_lo = (uint32_t)cm->cm_sense_busaddr;
io->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
io->lba_hi = (lba & 0xffffffff00000000) >> 32;
@ -2660,7 +2660,7 @@ mfi_dump_syspd_blocks(struct mfi_softc *sc, int id, uint64_t lba, void *virt,
pass->header.cmd = MFI_CMD_PD_SCSI_IO;
readop = 0;
blkcount = (len + MFI_SECTOR_LEN - 1) / MFI_SECTOR_LEN;
blkcount = howmany(len, MFI_SECTOR_LEN);
cdb_len = mfi_build_cdb(readop, 0, lba, blkcount, pass->cdb);
pass->header.target_id = id;
pass->header.timeout = 0;

View File

@ -1868,7 +1868,7 @@ mlx_startio_cb(void *arg, bus_dma_segment_t *segs, int nsegments, int error)
/* build a suitable I/O command (assumes 512-byte rounded transfers) */
mlxd = bp->bio_disk->d_drv1;
driveno = mlxd->mlxd_drive - sc->mlx_sysdrive;
blkcount = (bp->bio_bcount + MLX_BLKSIZE - 1) / MLX_BLKSIZE;
blkcount = howmany(bp->bio_bcount, MLX_BLKSIZE);
if ((bp->bio_pblkno + blkcount) > sc->mlx_sysdrive[driveno].ms_size)
device_printf(sc->mlx_dev,

View File

@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$");
#define WRITE4(_sc, _reg, _val) \
bus_write_4((_sc)->res[0], _reg, _val)
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define DIV_ROUND_UP(n, d) howmany(n, d)
#define DWMMC_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define DWMMC_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)

View File

@ -3468,11 +3468,11 @@ ncr_attach (device_t dev)
* Btw, 'period' is in tenths of nanoseconds.
*/
period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
period = howmany(4 * div_10M[0], np->clock_khz);
if (period <= 250) np->minsync = 10;
else if (period <= 303) np->minsync = 11;
else if (period <= 500) np->minsync = 12;
else np->minsync = (period + 40 - 1) / 40;
else np->minsync = howmany(period, 40);
/*
* Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).

View File

@ -119,8 +119,8 @@ cbr2slots(struct patm_softc *sc, struct patm_vcc *vcc)
{
/* compute the number of slots we need, make sure to get at least
* the specified PCR */
return ((u_int)(((uint64_t)(sc->mmap->tst_size - 1) *
vcc->vcc.tparam.pcr + IFP2IFATM(sc->ifp)->mib.pcr - 1) / IFP2IFATM(sc->ifp)->mib.pcr));
return ((u_int)howmany((uint64_t)(sc->mmap->tst_size - 1) *
vcc->vcc.tparam.pcr, IFP2IFATM(sc->ifp)->mib.pcr));
}
static __inline u_int

View File

@ -1425,7 +1425,7 @@ rt2560_setup_tx_desc(struct rt2560_softc *sc, struct rt2560_tx_desc *desc,
desc->plcp_length_hi = plcp_length >> 6;
desc->plcp_length_lo = plcp_length & 0x3f;
} else {
plcp_length = (16 * len + rate - 1) / rate;
plcp_length = howmany(16 * len, rate);
if (rate == 22) {
remainder = (16 * len) % 22;
if (remainder != 0 && remainder < 7)

View File

@ -1246,7 +1246,7 @@ rt2661_setup_tx_desc(struct rt2661_softc *sc, struct rt2661_tx_desc *desc,
desc->plcp_length_hi = plcp_length >> 6;
desc->plcp_length_lo = plcp_length & 0x3f;
} else {
plcp_length = (16 * len + rate - 1) / rate;
plcp_length = howmany(16 * len, rate);
if (rate == 22) {
remainder = (16 * len) % 22;
if (remainder != 0 && remainder < 7)

View File

@ -738,7 +738,7 @@ prepare_to_send(struct sbni_softc *sc)
len = SBNI_MIN_LEN;
sc->pktlen = len;
sc->tx_frameno = (len + sc->maxframe - 1) / sc->maxframe;
sc->tx_frameno = howmany(len, sc->maxframe);
sc->framelen = min(len, sc->maxframe);
sbni_outb(sc, CSR0, sbni_inb(sc, CSR0) | TR_REQ);

View File

@ -751,7 +751,7 @@ scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin)
mbx->sz = sc->data.blksize;
/* for first block */
mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz;
mbx->nblk = howmany(bp->bio_bcount, mbx->sz);
mbx->skip = 0;
nextblock:

View File

@ -906,7 +906,7 @@ static const struct tcphdr *tso_tcph(const struct sfxge_tso_state *tso)
#define TSOH_COUNT(_txq_entries) ((_txq_entries) / 2u)
#define TSOH_PER_PAGE (PAGE_SIZE / TSOH_STD_SIZE)
#define TSOH_PAGE_COUNT(_txq_entries) \
((TSOH_COUNT(_txq_entries) + TSOH_PER_PAGE - 1) / TSOH_PER_PAGE)
howmany(TSOH_COUNT(_txq_entries), TSOH_PER_PAGE)
static int tso_init(struct sfxge_txq *txq)
{

View File

@ -1058,8 +1058,8 @@ siba_cc_powerup_delay(struct siba_cc *scc)
min = siba_cc_clockfreq(scc, 0);
scc->scc_powerup_delay =
(((SIBA_CC_READ32(scc, SIBA_CC_PLLONDELAY) + 2) * 1000000) +
(min - 1)) / min;
howmany((SIBA_CC_READ32(scc, SIBA_CC_PLLONDELAY) + 2) * 1000000,
min);
}
static int

View File

@ -1173,8 +1173,8 @@ uaudio_get_buffer_size(struct uaudio_chan *ch, uint8_t alt)
{
struct uaudio_chan_alt *chan_alt = &ch->usb_alt[alt];
/* We use 2 times 8ms of buffer */
uint32_t buf_size = (((chan_alt->sample_rate * (UAUDIO_NFRAMES / 8)) +
1000 - 1) / 1000) * chan_alt->sample_size;
uint32_t buf_size = chan_alt->sample_size *
howmany(chan_alt->sample_rate * (UAUDIO_NFRAMES / 8), 1000);
return (buf_size);
}
@ -1292,8 +1292,8 @@ uaudio_configure_msg_sub(struct uaudio_softc *sc,
/* bytes per frame should not be zero */
chan->bytes_per_frame[0] =
((chan_alt->sample_rate / fps) * chan_alt->sample_size);
chan->bytes_per_frame[1] =
(((chan_alt->sample_rate + fps - 1) / fps) * chan_alt->sample_size);
chan->bytes_per_frame[1] = howmany(chan_alt->sample_rate, fps) *
chan_alt->sample_size;
/* setup data rate dithering, if any */
chan->frames_per_second = fps;

View File

@ -2526,11 +2526,11 @@ static int sym_prepare_setting(hcb_p np, struct sym_nvram *nvram)
* Minimum synchronous period factor supported by the chip.
* Btw, 'period' is in tenths of nanoseconds.
*/
period = (4 * div_10M[0] + np->clock_khz - 1) / np->clock_khz;
period = howmany(4 * div_10M[0], np->clock_khz);
if (period <= 250) np->minsync = 10;
else if (period <= 303) np->minsync = 11;
else if (period <= 500) np->minsync = 12;
else np->minsync = (period + 40 - 1) / 40;
else np->minsync = howmany(period, 40);
/*
* Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).

View File

@ -1659,8 +1659,7 @@ ehci_setup_standard_chain_sub(struct ehci_std_temp *temp)
/* update data toggle */
if (((average + temp->max_frame_size - 1) /
temp->max_frame_size) & 1) {
if (howmany(average, temp->max_frame_size) & 1) {
temp->qtd_status ^=
htohc32(temp->sc, EHCI_QTD_TOGGLE_MASK);
}

View File

@ -2437,7 +2437,7 @@ ohci_xfer_setup(struct usb_setup_params *parm)
usbd_transfer_setup_sub(parm);
nitd = ((xfer->max_data_length / OHCI_PAGE_SIZE) +
((xfer->nframes + OHCI_ITD_NOFFSET - 1) / OHCI_ITD_NOFFSET) +
howmany(xfer->nframes, OHCI_ITD_NOFFSET) +
1 /* EXTRA */ );
ntd = 0;
nqh = 1;

View File

@ -1830,8 +1830,8 @@ xhci_setup_generic_chain_sub(struct xhci_std_temp *temp)
}
/* set up npkt */
npkt = (len_old - npkt_off + temp->max_packet_size - 1) /
temp->max_packet_size;
npkt = howmany(len_old - npkt_off,
temp->max_packet_size);
if (npkt == 0)
npkt = 1;
@ -2185,10 +2185,9 @@ xhci_setup_generic_chain(struct usb_xfer *xfer)
temp.len = xfer->max_frame_size;
/* compute TD packet count */
tdpc = (temp.len + xfer->max_packet_size - 1) /
xfer->max_packet_size;
tdpc = howmany(temp.len, xfer->max_packet_size);
temp.tbc = ((tdpc + mult - 1) / mult) - 1;
temp.tbc = howmany(tdpc, mult) - 1;
temp.tlbpc = (tdpc % mult);
if (temp.tlbpc == 0)

View File

@ -246,7 +246,7 @@ usbd_transfer_setup_sub_malloc(struct usb_setup_params *parm,
* Compute number of DMA chunks, rounded up
* to nearest one:
*/
n_dma_pc = ((count + n_obj - 1) / n_obj);
n_dma_pc = howmany(count, n_obj);
n_dma_pg = 1;
}

View File

@ -1336,7 +1336,7 @@ rum_setup_tx_desc(struct rum_softc *sc, struct rum_tx_desc *desc,
} else {
if (rate == 0)
rate = 2; /* avoid division by zero */
plcp_length = (16 * len + rate - 1) / rate;
plcp_length = howmany(16 * len, rate);
if (rate == 22) {
remainder = (16 * len) % 22;
if (remainder != 0 && remainder < 7)

View File

@ -1002,7 +1002,7 @@ ural_setup_tx_desc(struct ural_softc *sc, struct ural_tx_desc *desc,
} else {
if (rate == 0)
rate = 2; /* avoid division by zero */
plcp_length = (16 * len + rate - 1) / rate;
plcp_length = howmany(16 * len, rate);
if (rate == 22) {
remainder = (16 * len) % 22;
if (remainder != 0 && remainder < 7)

View File

@ -815,9 +815,8 @@ vga_bitblt_text_gfxmode(struct vt_device *vd, const struct vt_window *vw,
col = area->tr_end.tp_col;
row = area->tr_end.tp_row;
x2 = (int)((col * vf->vf_width + vw->vw_draw_area.tr_begin.tp_col
+ VT_VGA_PIXELS_BLOCK - 1)
/ VT_VGA_PIXELS_BLOCK)
x2 = (int)howmany(col * vf->vf_width + vw->vw_draw_area.tr_begin.tp_col,
VT_VGA_PIXELS_BLOCK)
* VT_VGA_PIXELS_BLOCK;
y2 = row * vf->vf_height + vw->vw_draw_area.tr_begin.tp_row;
@ -916,8 +915,7 @@ vga_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw,
x1 = x / VT_VGA_PIXELS_BLOCK * VT_VGA_PIXELS_BLOCK;
y1 = y;
x2 = (x + width + VT_VGA_PIXELS_BLOCK - 1) /
VT_VGA_PIXELS_BLOCK * VT_VGA_PIXELS_BLOCK;
x2 = roundup(x + width, VT_VGA_PIXELS_BLOCK);
y2 = y + height;
x2 = min(x2, vd->vd_width - 1);
y2 = min(y2, vd->vd_height - 1);

View File

@ -573,8 +573,7 @@ gnttab_expand(unsigned int req_entries)
unsigned int cur, extra;
cur = nr_grant_frames;
extra = ((req_entries + (GREFS_PER_GRANT_FRAME-1)) /
GREFS_PER_GRANT_FRAME);
extra = howmany(req_entries, GREFS_PER_GRANT_FRAME);
if (cur + extra > max_nr_grant_frames())
return (ENOSPC);

View File

@ -1931,7 +1931,7 @@ xnb_mbufc2pkt(const struct mbuf *mbufc, struct xnb_pkt *pkt,
* into responses so that each response but the last uses all
* PAGE_SIZE bytes.
*/
pkt->list_len = (pkt->size + PAGE_SIZE - 1) / PAGE_SIZE;
pkt->list_len = howmany(pkt->size, PAGE_SIZE);
if (pkt->list_len > 1) {
pkt->flags |= NETRXF_more_data;