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

📄 kcompat.h

📁 网卡的驱动程序源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
#define netif_device_attach _kc_netif_device_attachextern void _kc_netif_device_attach(struct net_device *dev);#endif#ifndef netif_device_detach#define netif_device_detach _kc_netif_device_detachextern void _kc_netif_device_detach(struct net_device *dev);#endif#ifndef netif_carrier_on#define netif_carrier_on _kc_netif_carrier_onextern void _kc_netif_carrier_on(struct net_device *dev);#endif#ifndef netif_carrier_off#define netif_carrier_off _kc_netif_carrier_offextern void _kc_netif_carrier_off(struct net_device *dev);#endif#ifndef netif_carrier_ok#define netif_carrier_ok _kc_netif_carrier_okextern int _kc_netif_carrier_ok(struct net_device *dev);#endif/**************************************//* OTHER */#ifndef del_timer_sync	#define del_timer_sync del_timer#endif#ifndef BUG	#define BUG() printk(KERN_CRIT "BUG in %s at line %d\n", __FILE__, __LINE__)#endif#ifndef set_current_state	#define set_current_state(S) current->state = (S)#endif#ifndef list_for_each	#define list_for_each(pos, head) \		for(pos = (head)->next; pos != (head); pos = pos->next)#endif#ifndef list_add_tail	#define list_add_tail(new, head) __list_add(new, (head)->prev, (head))#endif#ifndef ARRARY_SIZE	#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))#endif#else /* remove 2.2.x only compatibility stuff */	#undef MOD_INC_USE_COUNT	#undef MOD_DEC_USE_COUNT	#define MOD_INC_USE_COUNT	#define MOD_DEC_USE_COUNT#endif /* 2.4.0 => 2.2.0 *//*****************************************************************************//* 2.4.3 => 2.4.0 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )/**************************************//* PCI DRIVER API */#ifndef pci_set_dma_mask#define pci_set_dma_mask _kc_pci_set_dma_maskextern int _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);#endif#ifndef pci_request_regions#define pci_request_regions _kc_pci_request_regionsextern int _kc_pci_request_regions(struct pci_dev *pdev, char *res_name);#endif#ifndef pci_release_regions#define pci_release_regions _kc_pci_release_regionsextern void _kc_pci_release_regions(struct pci_dev *pdev);#endif/**************************************//* NETWORK DRIVER API */#ifndef alloc_etherdev#define alloc_etherdev _kc_alloc_etherdevextern struct net_device * _kc_alloc_etherdev(int sizeof_priv);#endif#ifndef is_valid_ether_addr#define is_valid_ether_addr _kc_is_valid_ether_addrextern int _kc_is_valid_ether_addr(u8 *addr);#endif#endif /* 2.4.3 => 2.4.0 *//*****************************************************************************//* 2.4.6 => 2.4.3 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )#ifndef pci_set_power_state#define pci_set_power_state _kc_pci_set_power_stateextern int _kc_pci_set_power_state(struct pci_dev *dev, int state);#endif#ifndef pci_save_state#define pci_save_state _kc_pci_save_stateextern int _kc_pci_save_state(struct pci_dev *dev, u32 *buffer);#endif#ifndef pci_restore_state#define pci_restore_state _kc_pci_restore_stateextern int _kc_pci_restore_state(struct pci_dev *pdev, u32 *buffer);#endif#ifndef pci_enable_wake#define pci_enable_wake _kc_pci_enable_wakeextern int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable);#endif#ifndef pci_disable_device#define pci_disable_device _kc_pci_disable_deviceextern void _kc_pci_disable_device(struct pci_dev *pdev);#endif/* PCI PM entry point syntax changed, so don't support suspend/resume */#undef CONFIG_PM#endif /* 2.4.6 => 2.4.3 *//*****************************************************************************//* 2.4.10 => 2.4.6 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) )/**************************************//* MODULE API */#ifndef MODULE_LICENSE	#define MODULE_LICENSE(X)#endif/**************************************//* OTHER */#undef min#define min(x,y) ({ \	const typeof(x) _x = (x);	\	const typeof(y) _y = (y);	\	(void) (&_x == &_y);		\	_x < _y ? _x : _y; })#undef max#define max(x,y) ({ \	const typeof(x) _x = (x);	\	const typeof(y) _y = (y);	\	(void) (&_x == &_y);		\	_x > _y ? _x : _y; })#ifndef list_for_each_safe#define list_for_each_safe(pos, n, head) \	for (pos = (head)->next, n = pos->next; pos != (head); \		pos = n, n = pos->next)#endif#endif /* 2.4.10 -> 2.4.6 *//*****************************************************************************//* 2.4.13 => 2.4.10 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )/**************************************//* PCI DMA MAPPING */#ifndef virt_to_page	#define virt_to_page(v) (mem_map + (virt_to_phys(v) >> PAGE_SHIFT))#endif#ifndef pci_map_page#define pci_map_page _kc_pci_map_pageextern u64 _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset, size_t size, int direction);#endif#ifndef pci_unmap_page#define pci_unmap_page _kc_pci_unmap_pageextern void _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size, int direction);#endif/* pci_set_dma_mask takes dma_addr_t, which is only 32-bits prior to 2.4.13 */#undef PCI_DMA_32BIT#define PCI_DMA_32BIT	0xffffffff#undef PCI_DMA_64BIT#define PCI_DMA_64BIT	0xffffffff/**************************************//* OTHER */#ifndef cpu_relax#define cpu_relax()	rep_nop()#endif#endif /* 2.4.13 => 2.4.10 *//*****************************************************************************//* 2.4.19 => 2.4.12 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19) )#ifndef __devexit_p	#define __devexit_p(x) &(x)#endif#ifndef VLAN_HLEN#define VLAN_HLEN 4#endif#ifndef VLAN_ETH_HLEN#define VLAN_ETH_HLEN 18#endif#ifndef VLAN_ETH_FRAME_LEN#define VLAN_ETH_FRAME_LEN 1518#endif#endif /* 2.4.19 => 2.4.13 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \    ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \      LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )#define ETHTOOL_OPS_COMPAT#endif/*****************************************************************************//* 2.4.20 => 2.4.19 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20) )/* we won't support NAPI on less than 2.4.20 */#ifdef CONFIG_E100_NAPI#undef CONFIG_E100_NAPI#endif#ifndef HAVE_NETIF_MSG/* * Network interface message level settings */#define HAVE_NETIF_MSG 1enum {	NETIF_MSG_DRV		= 0x0001,	NETIF_MSG_PROBE		= 0x0002,	NETIF_MSG_LINK		= 0x0004,	NETIF_MSG_TIMER		= 0x0008,	NETIF_MSG_IFDOWN	= 0x0010,	NETIF_MSG_IFUP		= 0x0020,	NETIF_MSG_RX_ERR	= 0x0040,	NETIF_MSG_TX_ERR	= 0x0080,	NETIF_MSG_TX_QUEUED	= 0x0100,	NETIF_MSG_INTR		= 0x0200,	NETIF_MSG_TX_DONE	= 0x0400,	NETIF_MSG_RX_STATUS	= 0x0800,	NETIF_MSG_PKTDATA	= 0x1000,	NETIF_MSG_HW		= 0x2000,	NETIF_MSG_WOL		= 0x4000,};#else#define NETIF_MSG_HW	0x2000#define NETIF_MSG_WOL	0x4000#endif#ifndef MII_RESV1#define MII_RESV1		0x17		/* Reserved...		*/#endif#endif /* 2.4.20 => 2.4.18 */#ifndef ETHTOOL_BUSINFO_LEN#define ETHTOOL_BUSINFO_LEN	32#endif#define mii_if_info _kc_mii_if_infostruct _kc_mii_if_info {	int phy_id;	int advertising;	int phy_id_mask;	int reg_num_mask;	unsigned int full_duplex : 1;	/* is full duplex? */	unsigned int force_media : 1;	/* is autoneg. disabled? */	struct net_device *dev;	int (*mdio_read) (struct net_device *dev, int phy_id, int location);	void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val);};struct ethtool_cmd;struct mii_ioctl_data;#undef mii_link_ok#define mii_link_ok _kc_mii_link_ok#undef mii_nway_restart#define mii_nway_restart _kc_mii_nway_restart#undef mii_ethtool_gset#define mii_ethtool_gset _kc_mii_ethtool_gset#undef mii_ethtool_sset#define mii_ethtool_sset _kc_mii_ethtool_sset#undef mii_check_link#define mii_check_link _kc_mii_check_link#undef generic_mii_ioctl#define generic_mii_ioctl _kc_generic_mii_ioctlextern int _kc_mii_link_ok (struct mii_if_info *mii);extern int _kc_mii_nway_restart (struct mii_if_info *mii);extern int _kc_mii_ethtool_gset(struct mii_if_info *mii,		struct ethtool_cmd *ecmd);extern int _kc_mii_ethtool_sset(struct mii_if_info *mii,		struct ethtool_cmd *ecmd);extern void _kc_mii_check_link (struct mii_if_info *mii);extern int _kc_generic_mii_ioctl(struct mii_if_info *mii_if,                struct mii_ioctl_data *mii_data, int cmd,		unsigned int *duplex_changed);struct _kc_pci_dev_ext {	struct pci_dev *dev;	void *pci_drvdata;	struct pci_driver *driver;};struct _kc_net_dev_ext {	struct net_device *dev;	unsigned int carrier;};/**************************************//* mii support */int _kc_mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd){	struct net_device *dev = mii->dev;	u32 advert, bmcr, lpa, nego;	ecmd->supported =	    (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |	     SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |	     SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII);	/* only supports twisted-pair */	ecmd->port = PORT_MII;	/* only supports internal transceiver */	ecmd->transceiver = XCVR_INTERNAL;	/* this isn't fully supported at higher layers */	ecmd->phy_address = mii->phy_id;	ecmd->advertising = ADVERTISED_TP | ADVERTISED_MII;	advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);	if (advert & ADVERTISE_10HALF)		ecmd->advertising |= ADVERTISED_10baseT_Half;	if (advert & ADVERTISE_10FULL)		ecmd->advertising |= ADVERTISED_10baseT_Full;	if (advert & ADVERTISE_100HALF)		ecmd->advertising |= ADVERTISED_100baseT_Half;	if (advert & ADVERTISE_100FULL)		ecmd->advertising |= ADVERTISED_100baseT_Full;	bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);	lpa = mii->mdio_read(dev, mii->phy_id, MII_LPA);	if (bmcr & BMCR_ANENABLE) {		ecmd->advertising |= ADVERTISED_Autoneg;		ecmd->autoneg = AUTONEG_ENABLE;				nego = mii_nway_result(advert & lpa);		if (nego == LPA_100FULL || nego == LPA_100HALF)			ecmd->speed = SPEED_100;		else			ecmd->speed = SPEED_10;		if (nego == LPA_100FULL || nego == LPA_10FULL) {			ecmd->duplex = DUPLEX_FULL;			mii->full_duplex = 1;		} else {			ecmd->duplex = DUPLEX_HALF;			mii->full_duplex = 0;		}	} else {		ecmd->autoneg = AUTONEG_DISABLE;		ecmd->speed = (bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;		ecmd->duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;	}	/* ignore maxtxpkt, maxrxpkt for now */	return 0;}int _kc_mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd){	struct net_device *dev = mii->dev;	if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)		return -EINVAL;	if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)		return -EINVAL;	if (ecmd->port != PORT_MII)		return -EINVAL;	if (ecmd->transceiver != XCVR_INTERNAL)		return -EINVAL;	if (ecmd->phy_address != mii->phy_id)		return -EINVAL;	if (ecmd->autoneg != AUTONEG_DISABLE && ecmd->autoneg != AUTONEG_ENABLE)		return -EINVAL;				  	/* ignore supported, maxtxpkt, maxrxpkt */		if (ecmd->autoneg == AUTONEG_ENABLE) {		u32 bmcr, advert, tmp;		if ((ecmd->advertising & (ADVERTISED_10baseT_Half |					  ADVERTISED_10baseT_Full |					  ADVERTISED_100baseT_Half |					  ADVERTISED_100baseT_Full)) == 0)			return -EINVAL;		/* advertise only what has been requested */		advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);		tmp = advert & ~(ADVERTISE_ALL | ADVERTISE_100BASE4);		if (ADVERTISED_10baseT_Half)			tmp |= ADVERTISE_10HALF;		if (ADVERTISED_10baseT_Full)			tmp |= ADVERTISE_10FULL;		if (ADVERTISED_100baseT_Half)			tmp |= ADVERTISE_100HALF;		if (ADVERTISED_100baseT_Full)			tmp |= ADVERTISE_100FULL;		if (advert != tmp) {			mii->mdio_write(dev, mii->phy_id, MII_ADVERTISE, tmp);			mii->advertising = tmp;		}				/* turn on autonegotiation, and force a renegotiate */		bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);		bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);		mii->mdio_write(dev, mii->phy_id, MII_BMCR, bmcr);		mii->force_media = 0;	} else {		u32 bmcr, tmp;		/* turn off auto negotiation, set speed and duplexity */		bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);		tmp = bmcr & ~(BMCR_ANENABLE | BMCR_SPEED100 | BMCR_FULLDPLX);		if (ecmd->speed == SPEED_100)			tmp |= BMCR_SPEED100;		if (ecmd->duplex == DUPLEX_FULL) {			tmp |= BMCR_FULLDPLX;			mii->full_duplex = 1;		} else			mii->full_duplex = 0;		if (bmcr != tmp)			mii->mdio_write(dev, mii->phy_id, MII_BMCR, tmp);		mii->force_media = 1;	}	return 0;}int _kc_mii_link_ok (struct mii_if_info *mii){	/* first, a dummy read, needed to latch some MII phys */	mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);	if (mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR) & BMSR_LSTATUS)		return 1;	return 0;}int _kc_mii_nway_restart (struct mii_if_info *mii){	int bmcr;	int r = -EINVAL;	/* if autoneg is off, it's an error */	bmcr = mii->mdio_read(mii->dev, mii->phy_id, MII_BMCR);	if (bmcr & BMCR_ANENABLE) {		bmcr |= BMCR_ANRESTART;		mii->mdio_write(mii->dev, mii->phy_id, MII_BMCR, bmcr);		r = 0;	}	return r;}void _kc_mii_check_link (struct mii_if_info *mii){	int cur_link = mii_link_ok(mii);	int prev_link = netif_carrier_ok(mii->dev);	if (cur_link && !prev_link)		netif_carrier_on(mii->dev);	else if (prev_link && !cur_link)		netif_carrier_off(mii->dev);}int _kc_generic_mii_ioctl(struct mii_if_info *mii_if,		      struct mii_ioctl_data *mii_data, int cmd,		      unsigned int *duplex_chg_out){	int rc = 0;	unsigned int duplex_changed = 0;	if (duplex_chg_out)		*duplex_chg_out = 0;	mii_data->phy_id &= mii_if->phy_id_mask;	mii_data->reg_num &= mii_if->reg_num_mask;	switch(cmd) {	case SIOCDEVPRIVATE:	/* binary compat, remove in 2.5 */	case SIOCGMIIPHY:		mii_data->phy_id = mii_if->phy_id;		/* fall through */	case SIOCDEVPRIVATE + 1:/* binary compat, remove in 2.5 */	case SIOCGMIIREG:		mii_data->val_out =			mii_if->mdio_read(mii_if->dev, mii_data->phy_id,					  mii_data->reg_num);		break;	case SIOCDEVPRIVATE + 2:/* binary compat, remove in 2.5 */	case SIOCSMIIREG: {		u16 val = mii_data->val_in;		if (!capable(CAP_NET_ADMIN))			return -EPERM;		if (mii_data->phy_id == mii_if->phy_id) {			switch(mii_data->reg_num) {			case MII_BMCR: {				unsigned int new_duplex = 0;				if (val & (BMCR_RESET|BMCR_ANENABLE))					mii_if->force_media = 0;				else					mii_if->force_media = 1;				if (mii_if->force_media &&				    (val & BMCR_FULLDPLX))					new_duplex = 1;				if (mii_if->full_duplex != new_duplex) {					duplex_changed = 1;					mii_if->full_duplex = new_duplex;				}				break;			}			case MII_ADVERTISE:				mii_if->advertising = val;				break;			default:				/* do nothing */				break;			}		}		mii_if->mdio_write(mii_if->dev, mii_data->phy_id,				   mii_data->reg_num, val);

⌨️ 快捷键说明

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