sb1250-mac.c

来自「linux 内核源代码」· C语言 代码 · 共 2,649 行 · 第 1/5 页

C
2,649 行
字号
#ifdef CONFIG_SBMAC_COALESCE	__raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |	((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),	sc->sbm_imr);#else	__raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | 	(M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);#endif}#endif/********************************************************************** *  SBDMA_RX_PROCESS(sc,d,work_to_do,poll) * *  Process "completed" receive buffers on the specified DMA channel. * *  Input parameters: *            sc - softc structure *  	       d - DMA channel context *    work_to_do - no. of packets to process before enabling interrupt *                 again (for NAPI) *          poll - 1: using polling (for NAPI) * *  Return value: *  	   nothing ********************************************************************* */static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d,			    int work_to_do, int poll){	struct net_device *dev = sc->sbm_dev;	int curidx;	int hwidx;	struct sbdmadscr *dsc;	struct sk_buff *sb;	int len;	int work_done = 0;	int dropped = 0;	prefetch(d);again:	/* Check if the HW dropped any frames */	dev->stats.rx_fifo_errors	    += __raw_readq(sc->sbm_rxdma.sbdma_oodpktlost) & 0xffff;	__raw_writeq(0, sc->sbm_rxdma.sbdma_oodpktlost);	while (work_to_do-- > 0) {		/*		 * figure out where we are (as an index) and where		 * the hardware is (also as an index)		 *		 * This could be done faster if (for example) the		 * descriptor table was page-aligned and contiguous in		 * both virtual and physical memory -- you could then		 * just compare the low-order bits of the virtual address		 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)		 */		dsc = d->sbdma_remptr;		curidx = dsc - d->sbdma_dscrtable;		prefetch(dsc);		prefetch(&d->sbdma_ctxtable[curidx]);		hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -			 d->sbdma_dscrtable_phys) /			sizeof(*d->sbdma_dscrtable);		/*		 * If they're the same, that means we've processed all		 * of the descriptors up to (but not including) the one that		 * the hardware is working on right now.		 */		if (curidx == hwidx)			goto done;		/*		 * Otherwise, get the packet's sk_buff ptr back		 */		sb = d->sbdma_ctxtable[curidx];		d->sbdma_ctxtable[curidx] = NULL;		len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;		/*		 * Check packet status.  If good, process it.		 * If not, silently drop it and put it back on the		 * receive ring.		 */		if (likely (!(dsc->dscr_a & M_DMA_ETHRX_BAD))) {			/*			 * Add a new buffer to replace the old one.  If we fail			 * to allocate a buffer, we're going to drop this			 * packet and put it right back on the receive ring.			 */			if (unlikely (sbdma_add_rcvbuffer(d,NULL) ==				      -ENOBUFS)) {				dev->stats.rx_dropped++;				sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */				/* No point in continuing at the moment */				printk(KERN_ERR "dropped packet (1)\n");				d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);				goto done;			} else {				/*				 * Set length into the packet				 */				skb_put(sb,len);				/*				 * Buffer has been replaced on the				 * receive ring.  Pass the buffer to				 * the kernel				 */				sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev);				/* Check hw IPv4/TCP checksum if supported */				if (sc->rx_hw_checksum == ENABLE) {					if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) &&					    !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) {						sb->ip_summed = CHECKSUM_UNNECESSARY;						/* don't need to set sb->csum */					} else {						sb->ip_summed = CHECKSUM_NONE;					}				}				prefetch(sb->data);				prefetch((const void *)(((char *)sb->data)+32));				if (poll)					dropped = netif_receive_skb(sb);				else					dropped = netif_rx(sb);				if (dropped == NET_RX_DROP) {					dev->stats.rx_dropped++;					d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);					goto done;				}				else {					dev->stats.rx_bytes += len;					dev->stats.rx_packets++;				}			}		} else {			/*			 * Packet was mangled somehow.  Just drop it and			 * put it back on the receive ring.			 */			dev->stats.rx_errors++;			sbdma_add_rcvbuffer(d,sb);		}		/*		 * .. and advance to the next buffer.		 */		d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);		work_done++;	}	if (!poll) {		work_to_do = 32;		goto again; /* collect fifo drop statistics again */	}done:	return work_done;}/********************************************************************** *  SBDMA_TX_PROCESS(sc,d) * *  Process "completed" transmit buffers on the specified DMA channel. *  This is normally called within the interrupt service routine. *  Note that this isn't really ideal for priority channels, since *  it processes all of the packets on a given channel before *  returning. * *  Input parameters: *      sc - softc structure *  	 d - DMA channel context *    poll - 1: using polling (for NAPI) * *  Return value: *  	   nothing ********************************************************************* */static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d,			     int poll){	struct net_device *dev = sc->sbm_dev;	int curidx;	int hwidx;	struct sbdmadscr *dsc;	struct sk_buff *sb;	unsigned long flags;	int packets_handled = 0;	spin_lock_irqsave(&(sc->sbm_lock), flags);	if (d->sbdma_remptr == d->sbdma_addptr)	  goto end_unlock;	hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -		 d->sbdma_dscrtable_phys) / sizeof(*d->sbdma_dscrtable);	for (;;) {		/*		 * figure out where we are (as an index) and where		 * the hardware is (also as an index)		 *		 * This could be done faster if (for example) the		 * descriptor table was page-aligned and contiguous in		 * both virtual and physical memory -- you could then		 * just compare the low-order bits of the virtual address		 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)		 */		curidx = d->sbdma_remptr - d->sbdma_dscrtable;		/*		 * If they're the same, that means we've processed all		 * of the descriptors up to (but not including) the one that		 * the hardware is working on right now.		 */		if (curidx == hwidx)			break;		/*		 * Otherwise, get the packet's sk_buff ptr back		 */		dsc = &(d->sbdma_dscrtable[curidx]);		sb = d->sbdma_ctxtable[curidx];		d->sbdma_ctxtable[curidx] = NULL;		/*		 * Stats		 */		dev->stats.tx_bytes += sb->len;		dev->stats.tx_packets++;		/*		 * for transmits, we just free buffers.		 */		dev_kfree_skb_irq(sb);		/*		 * .. and advance to the next buffer.		 */		d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);		packets_handled++;	}	/*	 * Decide if we should wake up the protocol or not.	 * Other drivers seem to do this when we reach a low	 * watermark on the transmit queue.	 */	if (packets_handled)		netif_wake_queue(d->sbdma_eth->sbm_dev);end_unlock:	spin_unlock_irqrestore(&(sc->sbm_lock), flags);}/********************************************************************** *  SBMAC_INITCTX(s) * *  Initialize an Ethernet context structure - this is called *  once per MAC on the 1250.  Memory is allocated here, so don't *  call it again from inside the ioctl routines that bring the *  interface up/down * *  Input parameters: *  	   s - sbmac context structure * *  Return value: *  	   0 ********************************************************************* */static int sbmac_initctx(struct sbmac_softc *s){	/*	 * figure out the addresses of some ports	 */	s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;	s->sbm_maccfg    = s->sbm_base + R_MAC_CFG;	s->sbm_fifocfg   = s->sbm_base + R_MAC_THRSH_CFG;	s->sbm_framecfg  = s->sbm_base + R_MAC_FRAMECFG;	s->sbm_rxfilter  = s->sbm_base + R_MAC_ADFILTER_CFG;	s->sbm_isr       = s->sbm_base + R_MAC_STATUS;	s->sbm_imr       = s->sbm_base + R_MAC_INT_MASK;	s->sbm_mdio      = s->sbm_base + R_MAC_MDIO;	/*	 * Initialize the DMA channels.  Right now, only one per MAC is used	 * Note: Only do this _once_, as it allocates memory from the kernel!	 */	sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);	sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);	/*	 * initial state is OFF	 */	s->sbm_state = sbmac_state_off;	return 0;}static void sbdma_uninitctx(struct sbmacdma *d){	if (d->sbdma_dscrtable_unaligned) {		kfree(d->sbdma_dscrtable_unaligned);		d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL;	}	if (d->sbdma_ctxtable) {		kfree(d->sbdma_ctxtable);		d->sbdma_ctxtable = NULL;	}}static void sbmac_uninitctx(struct sbmac_softc *sc){	sbdma_uninitctx(&(sc->sbm_txdma));	sbdma_uninitctx(&(sc->sbm_rxdma));}/********************************************************************** *  SBMAC_CHANNEL_START(s) * *  Start packet processing on this MAC. * *  Input parameters: *  	   s - sbmac structure * *  Return value: *  	   nothing ********************************************************************* */static void sbmac_channel_start(struct sbmac_softc *s){	uint64_t reg;	void __iomem *port;	uint64_t cfg,fifo,framecfg;	int idx, th_value;	/*	 * Don't do this if running	 */	if (s->sbm_state == sbmac_state_on)		return;	/*	 * Bring the controller out of reset, but leave it off.	 */	__raw_writeq(0, s->sbm_macenable);	/*	 * Ignore all received packets	 */	__raw_writeq(0, s->sbm_rxfilter);	/*	 * Calculate values for various control registers.	 */	cfg = M_MAC_RETRY_EN |		M_MAC_TX_HOLD_SOP_EN |		V_MAC_TX_PAUSE_CNT_16K |		M_MAC_AP_STAT_EN |		M_MAC_FAST_SYNC |		M_MAC_SS_EN |		0;	/*	 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars	 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above	 * Use a larger RD_THRSH for gigabit	 */	if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2)		th_value = 28;	else		th_value = 64;	fifo = V_MAC_TX_WR_THRSH(4) |	/* Must be '4' or '8' */		((s->sbm_speed == sbmac_speed_1000)		 ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) |		V_MAC_TX_RL_THRSH(4) |		V_MAC_RX_PL_THRSH(4) |		V_MAC_RX_RD_THRSH(4) |	/* Must be '4' */		V_MAC_RX_PL_THRSH(4) |		V_MAC_RX_RL_THRSH(8) |		0;	framecfg = V_MAC_MIN_FRAMESZ_DEFAULT |		V_MAC_MAX_FRAMESZ_DEFAULT |		V_MAC_BACKOFF_SEL(1);	/*	 * Clear out the hash address map	 */	port = s->sbm_base + R_MAC_HASH_BASE;	for (idx = 0; idx < MAC_HASH_COUNT; idx++) {		__raw_writeq(0, port);		port += sizeof(uint64_t);	}	/*	 * Clear out the exact-match table	 */	port = s->sbm_base + R_MAC_ADDR_BASE;	for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {		__raw_writeq(0, port);		port += sizeof(uint64_t);	}	/*	 * Clear out the DMA Channel mapping table registers	 */	port = s->sbm_base + R_MAC_CHUP0_BASE;	for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {		__raw_writeq(0, port);		port += sizeof(uint64_t);	}	port = s->sbm_base + R_MAC_CHLO0_BASE;	for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {		__raw_writeq(0, port);		port += sizeof(uint64_t);	}	/*	 * Program the hardware address.  It goes into the hardware-address	 * register as well as the first filter register.	 */	reg = sbmac_addr2reg(s->sbm_hwaddr);	port = s->sbm_base + R_MAC_ADDR_BASE;	__raw_writeq(reg, port);	port = s->sbm_base + R_MAC_ETHERNET_ADDR;#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS	/*	 * Pass1 SOCs do not receive packets addressed to the	 * destination address in the R_MAC_ETHERNET_ADDR register.	 * Set the value to zero.	 */	__raw_writeq(0, port);#else	__raw_writeq(reg, port);#endif	/*	 * Set the receive filter for no packets, and write values	 * to the various config registers	 */	__raw_writeq(0, s->sbm_rxfilter);	__raw_writeq(0, s->sbm_imr);	__raw_writeq(framecfg, s->sbm_framecfg);	__raw_writeq(fifo, s->sbm_fifocfg);	__raw_writeq(cfg, s->sbm_maccfg);	/*	 * Initialize DMA channels (rings should be ok now)	 */	sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);	sbdma_channel_start(&(s->sbm_txdma), DMA_TX);	/*	 * Configure the speed, duplex, and flow control	 */	sbmac_set_speed(s,s->sbm_speed);	sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);	/*	 * Fill the receive ring	 */	sbdma_fillring(&(s->sbm_rxdma));	/*	 * Turn on the rest of the bits in the enable register	 */#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)	__raw_writeq(M_MAC_RXDMA_EN0 |		       M_MAC_TXDMA_EN0, s->sbm_macenable);#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)	__raw_writeq(M_MAC_RXDMA_EN0 |		       M_MAC_TXDMA_EN0 |		       M_MAC_RX_ENABLE |		       M_MAC_TX_ENABLE, s->sbm_macenable);#else#error invalid SiByte MAC configuation#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?