e100_kcompat.c

来自「linux intel 网卡驱动,利用他可以让inel的pro 100 网卡进行」· C语言 代码 · 共 211 行

C
211
字号
/*******************************************************************************    Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.    This program is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the Free   Software Foundation; either version 2 of the License, or (at your option)   any later version.    This program is distributed in the hope that it will be useful, but WITHOUT   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   more details.    You should have received a copy of the GNU General Public License along with  this program; if not, write to the Free Software Foundation, Inc., 59   Temple Place - Suite 330, Boston, MA  02111-1307, USA.    The full GNU General Public License is included in this distribution in the  file called LICENSE.    Contact Information:  Linux NICS <linux.nics@intel.com>  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497*******************************************************************************/#include "e100_kcompat.h"/****************************************************************** *################################################################# *# *# Kernels before 2.4.0 *# *################################################################# ******************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)struct _kc_pci_dev_ext {	struct pci_dev *dev;	void *pci_drvdata;	struct pci_driver *driver;};static int board_count = 0;static struct _kc_pci_dev_ext my_pci_devices[PCI_MAX_NUM_NICS];int __initpci_module_init(struct pci_driver *drv){	struct pci_dev *pdev;	struct pci_device_id *pciid;	uint16_t subvendor, subdevice;	/* walk the global pci device list looking for matches */	for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS);	     pdev = pdev->next) {		pciid = &drv->id_table[0];		pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);		pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);		while (pciid->vendor != 0) {			if (((pciid->vendor == pdev->vendor) ||			     (pciid->vendor == PCI_ANY_ID)) &&			    ((pciid->device == pdev->device) ||			     (pciid->device == PCI_ANY_ID)) &&			    ((pciid->subvendor == subvendor) ||			     (pciid->subvendor == PCI_ANY_ID)) &&			    ((pciid->subdevice == subdevice) ||			     (pciid->subdevice == PCI_ANY_ID))) {				if (drv->probe(pdev, pciid) == 0) {					drv->pcimap[board_count] = pdev;				        my_pci_devices[board_count].dev = pdev;				        my_pci_devices[board_count].driver = drv;					board_count++;				}				break;			}			pciid++;		}	}	if (board_count < PCI_MAX_NUM_NICS) {		drv->pcimap[board_count] = NULL;	}	return (board_count > 0) ? 0 : -ENODEV;}void __exitpci_unregister_driver(struct pci_driver *drv){	int i;	for (i = 0; i < PCI_MAX_NUM_NICS; i++) {		if (!drv->pcimap[i])			break;		drv->remove(drv->pcimap[i]);	}}unsigned longe100_pci_resource_len(struct pci_dev *dev, int bar){	u32 old, len;	int bar_reg = PCI_BASE_ADDRESS_0 + (bar << 2);	pci_read_config_dword(dev, bar_reg, &old);	pci_write_config_dword(dev, bar_reg, ~0);	pci_read_config_dword(dev, bar_reg, &len);	pci_write_config_dword(dev, bar_reg, old);	if ((len & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY)		len = ~(len & PCI_BASE_ADDRESS_MEM_MASK);	else		len = ~(len & PCI_BASE_ADDRESS_IO_MASK) & 0xffff;	return (len + 1);}struct pci_driver *_kc_pci_dev_driver(struct pci_dev *dev){	int i;	for(i = 0; i < board_count; i++) {		if(my_pci_devices[i].dev == dev) {			return my_pci_devices[i].driver;		}	}	return NULL;}#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) *//****************************************************************** *################################################################# *# *# Kernels before 2.4.3 *# *################################################################# ******************************************************************/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3)voide100_pci_release_regions(struct pci_dev *pdev){	release_region(pci_resource_start(pdev, 1), pci_resource_len(pdev, 1));#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)	release_mem_region(pci_resource_start(pdev, 0),			   pci_resource_len(pdev, 0));#endif}int __devinite100_pci_request_regions(struct pci_dev *pdev, char *res_name){	unsigned long io_len = pci_resource_len(pdev, 1);	unsigned long base_addr;	base_addr = pci_resource_start(pdev, 1);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)	if (check_region(base_addr, io_len)) {		printk(KERN_ERR "%s: Failed to reserve I/O region\n", res_name);		goto err;	}	request_region(base_addr, io_len, res_name);	return 0;#else	if (!request_region(base_addr, io_len, res_name)) {		printk(KERN_ERR "%s: Failed to reserve I/O region\n", res_name);		goto err;	}	if (!request_mem_region(pci_resource_start(pdev, 0),				pci_resource_len(pdev, 0), res_name)) {		printk(KERN_ERR		       "%s: Failed to reserve memory region\n", res_name);		goto err_io;	}	return 0;err_io:	release_region(base_addr, io_len);#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */err:	return -EBUSY;}#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) *//*****************************************************************************//* 2.4.6 => 2.4.3 */#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )int _kc_pci_set_power_state(struct pci_dev *dev, int state){ return 0; }int _kc_pci_save_state(struct pci_dev *dev, u32 *buffer){ return 0; }int _kc_pci_restore_state(struct pci_dev *pdev, u32 *buffer){ return 0; }int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable){ return 0; }#endif

⌨️ 快捷键说明

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