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

📄 prism2_cs.c

📁 这是基于hfa3841、hfa3842的无线网卡linux驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#define WLAN_HOSTIF WLAN_PCMCIA#include "hfa384x.c"#include "prism2mgmt.c"#include "prism2mib.c"#include "prism2sta.c"#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,21) )#if (WLAN_CPU_FAMILY == WLAN_Ix86)#ifndef CONFIG_ISA#warning "You may need to enable ISA support in your kernel."#endif#endif#endifstatic u_int	irq_mask = 0xdeb8;		/* Interrupt mask */static int	irq_list[4] = { -1 };		/* Interrupt list */static u_int	prism2_ignorevcc=0;		/* Boolean, if set, we						 * ignore what the Vcc						 * is set to and what the CIS						 * says.						 */MODULE_PARM( irq_mask, "i");MODULE_PARM( irq_list, "1-4i");MODULE_PARM( prism2_ignorevcc, "i");static dev_link_t	*dev_list = NULL;	/* head of instance list */dev_link_t	*prism2sta_attach(void);static void	prism2sta_detach(dev_link_t *link);static void	prism2sta_config(dev_link_t *link);static void	prism2sta_release(UINT32 arg);static int 	prism2sta_event (event_t event, int priority, event_callback_args_t *args);#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68))/*----------------------------------------------------------------* cs_error** Utility function to print card services error messages.** Arguments:*	handle	client handle identifying this CS client*	func	CS function number that generated the error*	ret	CS function return code** Returns: *	nothing* Side effects:** Call context:*	process thread*	interrupt----------------------------------------------------------------*/static void cs_error(client_handle_t handle, int func, int ret){#if CS_RELEASE_CODE < 0x2911	CardServices(ReportError, dev_info, (void *)func, (void *)ret);#else	error_info_t err = { func, ret };	pcmcia_report_error(handle, &err);#endif}#else // kernel_versionstatic struct pcmcia_driver prism2_cs_driver = {	.drv = { 		.name = "prism2_cs",	},	.attach = prism2sta_attach,	.detach = prism2sta_detach,	.owner = THIS_MODULE,};#endif /* kernel_version *//*----------------------------------------------------------------* prism2sta_attach** Half of the attach/detach pair.  Creates and registers a device* instance with Card Services.  In this case, it also creates the* wlandev structure and device private structure.  These are * linked to the device instance via its priv member.** Arguments:*	none** Returns: *	A valid ptr to dev_link_t on success, NULL otherwise** Side effects:*	** Call context:*	process thread (insmod/init_module/register_pccard_driver)----------------------------------------------------------------*/dev_link_t *prism2sta_attach(void){	client_reg_t		client_reg;	int			result;	dev_link_t		*link = NULL;	wlandevice_t		*wlandev = NULL;	hfa384x_t		*hw = NULL;	DBFENTER;	/* Alloc our structures */	link =		kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);	if (!link || ((wlandev = create_wlan()) == NULL)) {		WLAN_LOG_ERROR("%s: Memory allocation failure.\n", dev_info);		result = -EIO;		goto failed;	}	hw = wlandev->priv;	/* Clear all the structs */	memset(link, 0, sizeof(struct dev_link_t));	if ( wlan_setup(wlandev) != 0 ) {		WLAN_LOG_ERROR("%s: wlan_setup() failed.\n", dev_info);		result = -EIO;		goto failed;	}	/* Initialize the hw struct for now */	hfa384x_create(hw, 0, 0, NULL);	hw->wlandev = wlandev;	/* Initialize the device private data stucture. */	hw->cs_link = link;	/* Initialize the PC card device object. */#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))	init_timer(&link->release);	link->release.function = &prism2sta_release;	link->release.data = (u_long)link;#endif	link->conf.IntType = INT_MEMORY_AND_IO;	link->priv = wlandev;#if CS_RELEASE_CODE > 0x2911	link->irq.Instance = wlandev;#endif	/* Link in to the list of devices managed by this driver */	link->next = dev_list;	dev_list = link;		/* Register with Card Services */	client_reg.dev_info = &dev_info;	client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;	client_reg.EventMask =		CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |		CS_EVENT_RESET_REQUEST |		CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |		CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;	client_reg.event_handler = &prism2sta_event;	client_reg.Version = 0x0210;	client_reg.event_callback_args.client_data = link;	result = pcmcia_register_client(&link->handle, &client_reg);	if (result != 0) {		cs_error(link->handle, RegisterClient, result);		prism2sta_detach(link);		return NULL;	}	goto done; failed:	if (link)	kfree(link);	if (wlandev)	kfree(wlandev);	if (hw)		kfree(hw);	link = NULL; done:	DBFEXIT;	return link;}/*----------------------------------------------------------------* prism2sta_detach** Remove one of the device instances managed by this driver.*   Search the list for the given instance, *   check our flags for a waiting timer'd release call*   call release*   Deregister the instance with Card Services*   (netdevice) unregister the network device.*   unlink the instance from the list*   free the link, priv, and priv->priv memory* Note: the dev_list variable is a driver scoped static used to*	maintain a list of device instances managed by this*	driver.** Arguments:*	link	ptr to the instance to detach** Returns: *	nothing** Side effects:*	the link structure is gone, the netdevice is gone** Call context:*	Might be interrupt, don't block.----------------------------------------------------------------*/void prism2sta_detach(dev_link_t *link){	dev_link_t		**linkp;	wlandevice_t		*wlandev;	hfa384x_t		*hw;	DBFENTER;	/* Locate prev device structure */	for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) {		if (*linkp == link) break;	}	if (*linkp != NULL) {#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))		unsigned long	flags;		/* Get rid of any timer'd release call */		save_flags(flags);		cli();#endif#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))		if (link->state & DEV_RELEASE_PENDING) {			del_timer_sync(&link->release);			link->state &= ~DEV_RELEASE_PENDING;		}#endif#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))		restore_flags(flags);#endif		/* If link says we're still config'd, call release */		if (link->state & DEV_CONFIG) {			prism2sta_release((u_long)link);			if (link->state & DEV_STALE_CONFIG) {				link->state |= DEV_STALE_LINK;				return;			}		}				/* Tell Card Services we're not around any more */		if (link->handle) {			pcmcia_deregister_client(link->handle);		}			/* Unlink device structure, free bits */		*linkp = link->next;		if ( link->priv != NULL ) {			wlandev = (wlandevice_t*)link->priv;			p80211netdev_hwremoved(wlandev);			if (link->dev != NULL) {				unregister_wlandev(wlandev);			}			wlan_unsetup(wlandev);			if (wlandev->priv) {				hw = wlandev->priv;				wlandev->priv = NULL;				if (hw) {					hfa384x_destroy(hw);					kfree(hw);				}			}			link->priv = NULL;			kfree(wlandev);		}		kfree(link);	}	DBFEXIT;	return;}/*----------------------------------------------------------------* prism2sta_config** Half of the config/release pair.  Usually called in response to* a card insertion event.  At this point, we _know_ there's some* physical device present.  That means we can start poking around* at the CIS and at any device specific config data we want.** Note the gotos and the macros.  I recoded this once without* them, and it got incredibly ugly.  It's actually simpler with* them.** Arguments:*	link	the dev_link_t structure created in attach that *		represents this device instance.** Returns: *	nothing** Side effects:*	Resources (irq, io, mem) are allocated*	The pcmcia dev_link->node->name is set*	(For netcards) The device structure is finished and,*	  most importantly, registered.  This means that there*	  is now a _named_ device that can be configured from*	  userland.** Call context:*	May be called from a timer.  Don't block!----------------------------------------------------------------*/#define CS_CHECK(fn, ret) \do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)#define CFG_CHECK(fn, retf) \do { int ret = (retf); \if (ret != 0) { \        WLAN_LOG_DEBUG(1, "CardServices(" #fn ") returned %d\n", ret); \        cs_error(link->handle, fn, ret); \        goto next_entry; \} \} while (0)void prism2sta_config(dev_link_t *link){	client_handle_t		handle;	wlandevice_t		*wlandev;	hfa384x_t               *hw;	int			last_fn;	int			last_ret;	tuple_t			tuple;	cisparse_t		parse;	config_info_t		socketconf;	UINT8			buf[64];	int			i;	int			minVcc = 0;	int			maxVcc = 0;	cistpl_cftable_entry_t	dflt = { 0 };	DBFENTER;	handle = link->handle;	wlandev = (wlandevice_t*)link->priv;	hw = wlandev->priv;	/* Collect the config register info */	tuple.DesiredTuple = CISTPL_CONFIG;	tuple.Attributes = 0;	tuple.TupleData = buf;	tuple.TupleDataMax = sizeof(buf);	tuple.TupleOffset = 0;	CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));	CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));	CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));	link->conf.ConfigBase = parse.config.base;	link->conf.Present = parse.config.rmask[0];		/* Configure card */	link->state |= DEV_CONFIG;	/* Acquire the current socket config (need Vcc setting) */	CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &socketconf));	/* Loop through the config table entries until we find one that works */	/* Assumes a complete and valid CIS */	tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;	CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));	while (1) {		cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);		CFG_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));		CFG_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));		if (cfg->index == 0) goto next_entry;		link->conf.ConfigIndex = cfg->index;		/* Lets print out the Vcc that the controller+pcmcia-cs set		 * for us, cause that's what we're going to use.		 */		WLAN_LOG_DEBUG(1,"Initial Vcc=%d/10v\n", socketconf.Vcc);		if (prism2_ignorevcc) {			link->conf.Vcc = socketconf.Vcc;			goto skipvcc;		}		/* Use power settings for Vcc and Vpp if present */		/* Note that the CIS values need to be rescaled */		if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {			WLAN_LOG_DEBUG(1, "Vcc obtained from curtupl.VNOM\n");			minVcc = maxVcc = 				cfg->vcc.param[CISTPL_POWER_VNOM]/10000;		} else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {			WLAN_LOG_DEBUG(1, "Vcc set from dflt.VNOM\n");			minVcc = maxVcc = 				dflt.vcc.param[CISTPL_POWER_VNOM]/10000;		} else if ((cfg->vcc.present & (1<<CISTPL_POWER_VMAX)) &&			   (cfg->vcc.present & (1<<CISTPL_POWER_VMIN)) ) {			WLAN_LOG_DEBUG(1, "Vcc set from curtupl(VMIN,VMAX)\n");			minVcc = cfg->vcc.param[CISTPL_POWER_VMIN]/10000;			maxVcc = cfg->vcc.param[CISTPL_POWER_VMAX]/10000;		} else if ((dflt.vcc.present & (1<<CISTPL_POWER_VMAX)) &&			   (dflt.vcc.present & (1<<CISTPL_POWER_VMIN)) ) {			WLAN_LOG_DEBUG(1, "Vcc set from dflt(VMIN,VMAX)\n");			minVcc = dflt.vcc.param[CISTPL_POWER_VMIN]/10000;			maxVcc = dflt.vcc.param[CISTPL_POWER_VMAX]/10000;		}		if ( socketconf.Vcc >= minVcc && socketconf.Vcc <= maxVcc) {			link->conf.Vcc = socketconf.Vcc;		} else {			/* [MSM]: Note that I've given up trying to change 			 * the Vcc if a change is indicated.  It seems the			 * system&socketcontroller&card vendors can't seem			 * to get it right, so I'm tired of trying to hack			 * my way around it.  pcmcia-cs does its best using 			 * the voltage sense pins but sometimes the controller			 * lies.  Then, even if we have a good read on the VS 			 * pins, some system designs will silently ignore our			 * requests to set the voltage.  Additionally, some 			 * vendors have 3.3v indicated on their sense pins, 			 * but 5v specified in the CIS or vice-versa.  I've			 * had it.  My only recommendation is "let the buyer			 * beware".  Your system might supply 5v to a 3v card			 * (possibly causing damage) or a 3v capable system 			 * might supply 5v to a 3v capable card (wasting 			 * precious battery life).			 * My only recommendation (if you care) is to get 			 * yourself an extender card (I don't know where, I 			 * have only one myself) and a meter and test it for			 * yourself.			 */			goto next_entry;		}skipvcc:					WLAN_LOG_DEBUG(1, "link->conf.Vcc=%d\n", link->conf.Vcc);		/* Do we need to allocate an interrupt? */		/* HACK: due to a bad CIS....we ALWAYS need an interrupt */		/* if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) */			link->conf.Attributes |= CONF_ENABLE_IRQ;		/* IO window settings */		link->io.NumPorts1 = link->io.NumPorts2 = 0;		if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {			cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;			link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;			if (!(io->flags & CISTPL_IO_8BIT))				link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;			if (!(io->flags & CISTPL_IO_16BIT))				link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;			link->io.BasePort1 = io->win[0].base;			if  ( link->io.BasePort1 != 0 ) {				WLAN_LOG_WARNING(				"Brain damaged CIS: hard coded iobase="				"0x%x, try letting pcmcia_cs decide...\n",

⌨️ 快捷键说明

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