sys/dev/cxgbe/common/t4_hw.c
/**
 *	t4_set_sched_bps - set the bit rate for a HW traffic scheduler
 *	@adap: the adapter
 *	@kbps: target rate in Kbps
 *	@sched: the scheduler index
 *
 *	Configure a Tx HW scheduler for the target rate.
 */
set the bit rate for a HW traffic scheduler
@adap: the adapter
@kbps: target rate in Kbps
@sched: the scheduler index

Configure a Tx HW scheduler for the target rate.
set the bit rate for a HW traffic scheduler @adap : the adapter @kbps : target rate in Kbps @sched : the scheduler index Configure a Tx HW scheduler for the target rate .
int t4_set_sched_bps(struct adapter *adap, int sched, unsigned int kbps)
{
	unsigned int v, tps, cpt, bpt, delta, mindelta = ~0;
	unsigned int clk = adap->params.vpd.cclk * 1000;
	unsigned int selected_cpt = 0, selected_bpt = 0;
	if (kbps > 0) {
		kbps *= 125;     
		for (cpt = 1; cpt <= 255; cpt++) {
			tps = clk / cpt;
			bpt = (kbps + tps / 2) / tps;
			if (bpt > 0 && bpt <= 255) {
				v = bpt * tps;
				delta = v >= kbps ? v - kbps : kbps - v;
				if (delta < mindelta) {
					mindelta = delta;
					selected_cpt = cpt;
					selected_bpt = bpt;
				}
			} else if (selected_cpt)
				break;
		}
		if (!selected_cpt)
			return -EINVAL;
	}
	t4_write_reg(adap, A_TP_TM_PIO_ADDR,
		     A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2);
	v = t4_read_reg(adap, A_TP_TM_PIO_DATA);
	if (sched & 1)
		v = (v & 0xffff) | (selected_cpt << 16) | (selected_bpt << 24);
	else
		v = (v & 0xffff0000) | selected_cpt | (selected_bpt << 8);
	t4_write_reg(adap, A_TP_TM_PIO_DATA, v);
	return 0;
}
int t4_set_sched_bps ( struct adapter * adap , int sched , unsigned int kbps ) { unsigned int v , tps , cpt , bpt , delta , mindelta = ~ 0 ; unsigned int clk = adap -> params . vpd . cclk * 1000 ; unsigned int selected_cpt = 0 , selected_bpt = 0 ; if ( kbps > 0 ) { kbps *= 125 ; for ( cpt = 1 ; cpt <= 255 ; cpt ++ ) { tps = clk / cpt ; bpt = ( kbps + tps / 2 ) / tps ; if ( bpt > 0 && bpt <= 255 ) { v = bpt * tps ; delta = v >= kbps ? v - kbps : kbps - v ; if ( delta < mindelta ) { mindelta = delta ; selected_cpt = cpt ; selected_bpt = bpt ; } } else if ( selected_cpt ) break ; } if ( ! selected_cpt ) return - EINVAL ; } t4_write_reg ( adap , A_TP_TM_PIO_ADDR , A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2 ) ; v = t4_read_reg ( adap , A_TP_TM_PIO_DATA ) ; if ( sched & 1 ) v = ( v & 0xffff ) | ( selected_cpt << 16 ) | ( selected_bpt << 24 ) ; else v = ( v & 0xffff0000 ) | selected_cpt | ( selected_bpt << 8 ) ; t4_write_reg ( adap , A_TP_TM_PIO_DATA , v ) ; return 0 ; }
t4_set_sched_bps - set the bit rate for a HW traffic scheduler
      @adap: the adapter
      @kbps: target rate in Kbps
      @sched: the scheduler index
t4_set_sched_bps - set the bit rate for a HW traffic scheduler @adap : the adapter @kbps : target rate in Kbps @sched : the scheduler index
/* -> bytes */