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

📄 wt_hotplug_pci.c

📁 mini-PCI driver for LHWT chipsets
💻 C
字号:
/* Copyright (C) 2005 LHWT Inc. */ #include "wtprecomp.h"/****************************************************************************/#ifdef WT4_DEBUG//int debug=0;int debug=L_FUNC;int wt4_debug_func_indent=0;#endif/*****************************************************************************/#define DRV_NAME	"wt4"#define DRV_VERSION	"1.0"MODULE_AUTHOR("LHWT");MODULE_DESCRIPTION("The WT 802.11 Wireless LAN adapter");MODULE_LICENSE("GPL");#if 0static int	init_pcitm = 0;module_param(init_pcitm, int, 0);#endif/* In this order: vendor, device, subvendor, subdevice, class, class_mask,driver_data */static const struct pci_device_id wt_id_tbl[] = {        /* WT4 hardware default r */	{	 0x6809, 0x8200,	 PCI_ANY_ID, PCI_ANY_ID,	 0, 0, 0	},	/* WT4 wireless adapter */	{	 0x1A45, 0x6104,	 PCI_ANY_ID, PCI_ANY_ID,	 0, 0, 0	},		/* End of list */	{0,0,0,0,0,0,0}};/* register the device with the Hotplug facilities of the kernel */MODULE_DEVICE_TABLE(pci, wt_id_tbl);static int  WtProbe(struct pci_dev *, const struct pci_device_id *);static void WtRemove(struct pci_dev *);static int  WtSuspend(struct pci_dev *, u32 state);static int  WtResume(struct pci_dev *);static struct pci_driver wt4_driver = {	.name = DRV_NAME,	.id_table = wt_id_tbl,	.probe    = WtProbe,	.remove   = WtRemove,	.suspend  = WtSuspend,	.resume   = WtResume,};/******************************************************************************    Module initialization functions******************************************************************************/int               //while insert pci cardWtProbe(struct pci_dev *pdev, const struct pci_device_id *id){	struct net_device *ndev;	u32 mem_addr;	u32 mem_addr0;	u32 mem_addr1;	u32 mem_addr2;	int rvalue;	WT_ADAPTER *Adapter;		FN_ENTER;        	/* Enable the pci device */	if (pci_enable_device(pdev)) {	   printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);           return -ENODEV;	}       printk(" LEVEL  pci_enable_device succeed (: !!!\n");        /****************************************************************/		/* enable PCI DMA */	if (pci_set_dma_mask(pdev, 0xffffffff)) {	   printk(KERN_ERR " LEVEL  %s: 32-bit PCI DMA not supported", DRV_NAME);	   goto do_pci_disable_device;        }       printk(" LEVEL  pci_set_dma_mask succeed (: !!!\n");	        /* request the pci device I/O regions */	rvalue = pci_request_regions(pdev, DRV_NAME);	if (rvalue) {		printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",		       DRV_NAME, rvalue);		goto do_pci_disable_device;	}       printk(" LEVEL  pci_request_regions succeed (: !!!\n");		/* check if the memory window is indeed set */	rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);	if (rvalue || !mem_addr) {		printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",DRV_NAME);		goto do_pci_disable_device;	}        printk(" LEVEL  PCI device memory region configured (:  !!!\n");	       pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr0);	printk("%s LEVEL   The value of mem_addr0 is %08x\r\n", __FUNCTION__,  mem_addr0);	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1, &mem_addr1);	printk("%s LEVEL   The value of mem_addr1 is %08x\r\n", __FUNCTION__,  mem_addr1);	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &mem_addr2);	printk("%s LEVEL   The value of mem_addr2 is %08x\r\n", __FUNCTION__,  mem_addr2);			printk("%s LEVEL    pci_resource_start(pdev, 0)= %08x\r\n", __FUNCTION__,  pci_resource_start(pdev, 0));	/* enable MWI */	//pci_set_mwi(pdev);        printk(" LEVEL  pci_set_mwi complete !!!\n");		/* setup the network device interface and its structure */	if (!(ndev = WtNdevSetup(pdev))) {		/* error configuring the driver as a network device */		printk(KERN_ERR "%s: could not configure network device\n",DRV_NAME);		goto do_pci_release_regions;	}	printk(" LEVEL  WtNdevSetup succeed (: !!!\n");	 	Adapter = netdev_priv(ndev); 	printk(" LEVEL  islpci_set_state complete !!!\n");	/* card is in unknown state yet, might have some interrupts pending */	WtDisableInterrupts(Adapter);        printk(" LEVEL  WtDisableInterrupts complete !!!\n");	/* request for the interrupt before uploading the firmware */	rvalue = request_irq(pdev->irq, &WtInterrupt,			     SA_SHIRQ, ndev->name, Adapter);     	if (rvalue) {		/* error, could not hook the handler to the irq */		printk("%s: could not install IRQ handler\n",		       ndev->name);		goto do_unregister_netdev;	}        printk(" LEVEL  request_irq complete !!!\n");	 	FN_EXIT(0,0);	return 0;        do_unregister_netdev:        unregister_netdev(ndev);	WtFreeMemory(Adapter);	pci_set_drvdata(pdev, NULL);	free_netdev(ndev);	Adapter = NULL;	        do_pci_release_regions:	pci_release_regions(pdev);	        do_pci_disable_device:	pci_disable_device(pdev);			FN_EXIT(0,0);	return -EIO;			 }/* set by cleanup_module */static volatile int __in_cleanup_module = 0;/* this one removes one(!!) instance only */voidWtRemove(struct pci_dev *pdev){	struct net_device *ndev = pci_get_drvdata(pdev);	WT_ADAPTER *Adapter = ndev ? netdev_priv(ndev) : NULL;	BUG_ON(!Adapter);		FN_ENTER;	//ndev->name is eth0	printk(" LEVEL  %s: removing device\n", ndev->name);        unregister_netdev(ndev);        WtDisableInterrupts(Adapter);//we moved it from the above if clause!!!		free_irq(pdev->irq, Adapter);	/* free the PCI memory and unmap the remapped page */	WtFreeMemory(Adapter);	pci_set_drvdata(pdev, NULL);	free_netdev(ndev);	Adapter = NULL;	pci_release_regions(pdev);	pci_disable_device(pdev);		FN_EXIT(0,0);	}intWtSuspend(struct pci_dev *pdev, u32 state){	return 0;}intWtResume(struct pci_dev *pdev){ 	return 0;}static int __initWtModuleInit(void)//while insmod executing{		FN_ENTER;	printk(" LEVEL  Loaded %s driver, version %s\n",	       DRV_NAME, DRV_VERSION);	__bug_on_wrong_struct_sizes ();		FN_EXIT(0,0);	return pci_module_init(&wt4_driver);			 } static void __exitWtModuleExit(void){        FN_ENTER;			__in_cleanup_module = 1;	pci_unregister_driver(&wt4_driver);	printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);	__in_cleanup_module = 0;		FN_EXIT(0,0);}/* register entry points */module_init(WtModuleInit);module_exit(WtModuleExit);/* EOF */

⌨️ 快捷键说明

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