⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gianfar_ethtool.c

📁 Powerpc网络处理器MPC85xx增强型三速以太控制器驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  drivers/net/gianfar_ethtool.c * *  Gianfar Ethernet Driver *  Ethtool support for Gianfar Enet *  Based on e1000 ethtool support * *  Author: Andy Fleming *  Maintainer: Kumar Gala * *  Copyright (C) 2003,2004, 2008 Freescale Semiconductor, Inc. All rights reserved. * *  ChangeLog: *  2007 Scott Wood <scottwood@freescale.com> *       Add power manangement support *  2008 Tanya Jiang <tanya.jiang@freescale.com> *       Enhanced pm support for waking up from phy interrupt * *  This software may be used and distributed according to *  the terms of the GNU Public License, Version 2, incorporated herein *  by reference. */#include <linux/kernel.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/spinlock.h>#include <linux/mm.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <linux/module.h>#include <linux/crc32.h>#include <asm/types.h>#include <asm/uaccess.h>#include <linux/ethtool.h>#include <linux/mii.h>#include <linux/phy.h>#include "gianfar.h"extern void gfar_start(struct net_device *dev);extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);#define GFAR_MAX_COAL_USECS 0xffff#define GFAR_MAX_COAL_FRAMES 0xffstatic void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,		     u64 * buf);static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);static char stat_gstrings[][ETH_GSTRING_LEN] = {	"rx-dropped-by-kernel",	"rx-large-frame-errors",	"rx-short-frame-errors",	"rx-non-octet-errors",	"rx-crc-errors",	"rx-overrun-errors",	"rx-busy-errors",	"rx-babbling-errors",	"rx-truncated-frames",#ifdef CONFIG_GFAR_SKBUFF_RECYCLING	"rx-skb-recycled-frames-new",	"rx-skb-recycled-frames-free",#endif	"ethernet-bus-error",	"tx-babbling-errors",	"tx-underrun-errors",	"rx-skb-missing-errors",	"tx-timeout-errors",	"tx-rx-64-frames",	"tx-rx-65-127-frames",	"tx-rx-128-255-frames",	"tx-rx-256-511-frames",	"tx-rx-512-1023-frames",	"tx-rx-1024-1518-frames",	"tx-rx-1519-1522-good-vlan",	"rx-bytes",	"rx-packets",	"rx-fcs-errors",	"receive-multicast-packet",	"receive-broadcast-packet",	"rx-control-frame-packets",	"rx-pause-frame-packets",	"rx-unknown-op-code",	"rx-alignment-error",	"rx-frame-length-error",	"rx-code-error",	"rx-carrier-sense-error",	"rx-undersize-packets",	"rx-oversize-packets",	"rx-fragmented-frames",	"rx-jabber-frames",	"rx-dropped-frames",	"tx-byte-counter",	"tx-packets",	"tx-multicast-packets",	"tx-broadcast-packets",	"tx-pause-control-frames",	"tx-deferral-packets",	"tx-excessive-deferral-packets",	"tx-single-collision-packets",	"tx-multiple-collision-packets",	"tx-late-collision-packets",	"tx-excessive-collision-packets",	"tx-total-collision",	"reserved",	"tx-dropped-frames",	"tx-jabber-frames",	"tx-fcs-errors",	"tx-control-frames",	"tx-oversize-frames",	"tx-undersize-frames",	"tx-fragmented-frames",};/* Fill in a buffer with the strings which correspond to the * stats */static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf){	struct gfar_private *priv = netdev_priv(dev);	if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)		memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);	else		memcpy(buf, stat_gstrings,				GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);}/* Fill in an array of 64-bit statistics from various sources. * This array will be appended to the end of the ethtool_stats * structure, and returned to user space */static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf){	int i;	struct gfar_private *priv = netdev_priv(dev);	u64 *extra = (u64 *) & priv->extra_stats;	if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {		u32 __iomem *rmon = (u32 __iomem *) & priv->regs->rmon;		struct gfar_stats *stats = (struct gfar_stats *) buf;		for (i = 0; i < GFAR_RMON_LEN; i++)			stats->rmon[i] = (u64) gfar_read(&rmon[i]);		for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)			stats->extra[i] = extra[i];	} else		for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)			buf[i] = extra[i];}/* Returns the number of stats (and their corresponding strings) */static int gfar_stats_count(struct net_device *dev){	struct gfar_private *priv = netdev_priv(dev);	if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)		return GFAR_STATS_LEN;	else		return GFAR_EXTRA_STATS_LEN;}/* Fills in the drvinfo structure with some basic info */static void gfar_gdrvinfo(struct net_device *dev, struct	      ethtool_drvinfo *drvinfo){	strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);	strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);	strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);	strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);	drvinfo->n_stats = GFAR_STATS_LEN;	drvinfo->testinfo_len = 0;	drvinfo->regdump_len = 0;	drvinfo->eedump_len = 0;}static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd){	struct gfar_private *priv = netdev_priv(dev);	struct phy_device *phydev = priv->phydev;	if (NULL == phydev)		return -ENODEV;	return phy_ethtool_sset(phydev, cmd);}/* Return the current settings in the ethtool_cmd structure */static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd){	struct gfar_private *priv = netdev_priv(dev);	struct phy_device *phydev = priv->phydev;	if (NULL == phydev)		return -ENODEV;	cmd->maxtxpkt = priv->txcount;	cmd->maxrxpkt = priv->rxcount;	return phy_ethtool_gset(phydev, cmd);}/* Return the length of the register structure */static int gfar_reglen(struct net_device *dev){	return sizeof (struct gfar);}/* Return a dump of the GFAR register space */static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf){	int i;	struct gfar_private *priv = netdev_priv(dev);	u32 __iomem *theregs = (u32 __iomem *) priv->regs;	u32 *buf = (u32 *) regbuf;	for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)		buf[i] = gfar_read(&theregs[i]);}/* Convert microseconds to ethernet clock ticks, which changes * depending on what speed the controller is running at */static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs){	unsigned int count;	/* The timer is different, depending on the interface speed */	switch (priv->phydev->speed) {	case SPEED_1000:		count = GFAR_GBIT_TIME;		break;	case SPEED_100:		count = GFAR_100_TIME;		break;	case SPEED_10:	default:		count = GFAR_10_TIME;		break;	}	/* Make sure we return a number greater than 0	 * if usecs > 0 */	return ((usecs * 1000 + count - 1) / count);}/* Convert ethernet clock ticks to microseconds */static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks){	unsigned int count;	/* The timer is different, depending on the interface speed */	switch (priv->phydev->speed) {	case SPEED_1000:		count = GFAR_GBIT_TIME;		break;	case SPEED_100:		count = GFAR_100_TIME;		break;	case SPEED_10:	default:		count = GFAR_10_TIME;		break;	}	/* Make sure we return a number greater than 0 */	/* if ticks is > 0 */	return ((ticks * count) / 1000);}/* Get the coalescing parameters, and put them in the cvals * structure.  */static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals){	struct gfar_private *priv = netdev_priv(dev);	if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))		return -EOPNOTSUPP;	if (NULL == priv->phydev)		return -ENODEV;	cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime);	cvals->rx_max_coalesced_frames = priv->rxcount;	cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, priv->txtime);	cvals->tx_max_coalesced_frames = priv->txcount;	cvals->use_adaptive_rx_coalesce = 0;	cvals->use_adaptive_tx_coalesce = 0;	cvals->pkt_rate_low = 0;	cvals->rx_coalesce_usecs_low = 0;	cvals->rx_max_coalesced_frames_low = 0;	cvals->tx_coalesce_usecs_low = 0;	cvals->tx_max_coalesced_frames_low = 0;	/* When the packet rate is below pkt_rate_high but above	 * pkt_rate_low (both measured in packets per second) the	 * normal {rx,tx}_* coalescing parameters are used.	 */	/* When the packet rate is (measured in packets per second)	 * is above pkt_rate_high, the {rx,tx}_*_high parameters are	 * used.	 */

⌨️ 快捷键说明

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