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

📄 hfa384x_usb.c

📁 这是基于hfa3841、hfa3842的无线网卡linux驱动程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* APs may also disable macports 1-6.  Only ports that have been* previously enabled may be disabled.** Arguments:*	hw		device structure*	macport		MAC port number (host order)** Returns: *	0		success*	>0		f/w reported failure - f/w status code*	<0		driver reported error (timeout|bad arg)** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_disable(hfa384x_t *hw, UINT16 macport){	int	result = 0;	DBFENTER;	if ((!hw->isap && macport != 0) || 	    (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||	    !(hw->port_enabled[macport]) ){		result = -EINVAL;	} else {		result = hfa384x_cmd_disable(hw, macport);		if ( result == 0 ) {			hw->port_enabled[macport] = 0;		}	}	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_enable** Issues the enable command to enable communications on one of * the MACs 'ports'.  Only macport 0 is valid  for stations.* APs may also enable macports 1-6.  Only ports that are currently* disabled may be enabled.** Arguments:*	hw		device structure*	macport		MAC port number** Returns: *	0		success*	>0		f/w reported failure - f/w status code*	<0		driver reported error (timeout|bad arg)** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_enable(hfa384x_t *hw, UINT16 macport){	int	result = 0;	DBFENTER;	if ((!hw->isap && macport != 0) || 	    (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||	    (hw->port_enabled[macport]) ){		result = -EINVAL;	} else {		result = hfa384x_cmd_enable(hw, macport);		if ( result == 0 ) {			hw->port_enabled[macport] = 1;		}	}	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_flashdl_enable** Begins the flash download state.  Checks to see that we're not* already in a download state and that a port isn't enabled.* Sets the download state and retrieves the flash download* buffer location, buffer size, and timeout length.** Arguments:*	hw		device structure** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_flashdl_enable(hfa384x_t *hw){	int		result = 0;	int		i;	DBFENTER;	/* Check that a port isn't active */	for ( i = 0; i < HFA384x_PORTID_MAX; i++) {		if ( hw->port_enabled[i] ) {			WLAN_LOG_DEBUG(1,"called when port enabled.\n");			return -EINVAL; 		}	}	/* Check that we're not already in a download state */	if ( hw->dlstate != HFA384x_DLSTATE_DISABLED ) {		return -EINVAL;	}	/* Retrieve the buffer loc&size and timeout */	if ( (result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER, 				&(hw->bufinfo), sizeof(hw->bufinfo))) ) {		return result;	}	hw->bufinfo.page = hfa384x2host_16(hw->bufinfo.page);	hw->bufinfo.offset = hfa384x2host_16(hw->bufinfo.offset);	hw->bufinfo.len = hfa384x2host_16(hw->bufinfo.len);	if ( (result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME, 				&(hw->dltimeout))) ) {		return result;	}	hw->dltimeout = hfa384x2host_16(hw->dltimeout);	WLAN_LOG_DEBUG(1,"flashdl_enable\n");	hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_flashdl_disable** Ends the flash download state.  Note that this will cause the MAC* firmware to restart.** Arguments:*	hw		device structure** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_flashdl_disable(hfa384x_t *hw){	DBFENTER;	/* Check that we're already in the download state */	if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {		return -EINVAL;	}	WLAN_LOG_DEBUG(1,"flashdl_enable\n");	/* There isn't much we can do at this point, so I don't */	/*  bother  w/ the return value */	hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0 , 0);	hw->dlstate = HFA384x_DLSTATE_DISABLED;	DBFEXIT;	return 0;}/*----------------------------------------------------------------* hfa384x_drvr_flashdl_write** Performs a FLASH download of a chunk of data. First checks to see* that we're in the FLASH download state, then sets the download* mode, uses the aux functions to 1) copy the data to the flash* buffer, 2) sets the download 'write flash' mode, 3) readback and * compare.  Lather rinse, repeat as many times an necessary to get* all the given data into flash.  * When all data has been written using this function (possibly * repeatedly), call drvr_flashdl_disable() to end the download state* and restart the MAC.** Arguments:*	hw		device structure*	daddr		Card address to write to. (host order)*	buf		Ptr to data to write.*	len		Length of data (host order).** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error** Side effects:** Call context:*	process ----------------------------------------------------------------*/inthfa384x_drvr_flashdl_write(	hfa384x_t	*hw, 	UINT32		daddr, 	void		*buf, 	UINT32		len){	int		result = 0;	UINT8		*verbuf;	UINT32		dlbufaddr;	int		nburns;	UINT32		burnlen;	UINT32		burndaddr;	UINT16		burnlo;	UINT16		burnhi;	int		nwrites;	UINT8		*writebuf;	UINT16		writepage;	UINT16		writeoffset;	UINT32		writelen;	int		i;	int		j;	DBFENTER;	WLAN_LOG_DEBUG(5,"daddr=0x%08lx len=%ld\n", daddr, len);	/* Check that we're in the flash download state */	if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {		return -EINVAL;	}	WLAN_LOG_INFO("Download %ld bytes to flash @0x%06lx\n", len, daddr);	/* Convert to flat address for arithmetic */	/* NOTE: dlbuffer RID stores the address in AUX format */	dlbufaddr = HFA384x_ADDR_AUX_MKFLAT(			hw->bufinfo.page, hw->bufinfo.offset);	WLAN_LOG_DEBUG(5,		"dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08lx\n",		hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);	verbuf = kmalloc(hw->bufinfo.len, GFP_ATOMIC);	if ( verbuf == NULL ) {		WLAN_LOG_ERROR("Failed to allocate flash verify buffer\n");		return 1;	}#if 0WLAN_LOG_WARNING("dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr, hw->bufinfo.len, hw->dltimeout);#endif	/* Calculations to determine how many fills of the dlbuffer to do	 * and how many USB wmemreq's to do for each fill.  At this point	 * in time, the dlbuffer size and the wmemreq size are the same.	 * Therefore, nwrites should always be 1.  The extra complexity	 * here is a hedge against future changes.	 */	/* Figure out how many times to do the flash programming */	nburns = len / hw->bufinfo.len;	nburns += (len % hw->bufinfo.len) ? 1 : 0;	/* For each flash program cycle, how many USB wmemreq's are needed? */	nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;	nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;	/* For each burn */	for ( i = 0; i < nburns; i++) {		/* Get the dest address and len */		burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?				hw->bufinfo.len : 				(len - (hw->bufinfo.len * i));		burndaddr = daddr + (hw->bufinfo.len * i);		burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);		burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);		WLAN_LOG_INFO("Writing %ld bytes to flash @0x%06lx\n", 			burnlen, burndaddr);		/* Set the download mode */		result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV, 				burnlo, burnhi, burnlen);		if ( result ) {			WLAN_LOG_ERROR("download(NV,lo=%x,hi=%x,len=%lx) "				"cmd failed, result=%d. Aborting d/l\n",				burnlo, burnhi, burnlen, result);			goto exit_proc;		}		/* copy the data to the flash download buffer */		for ( j=0; j < nwrites; j++) {			writebuf = buf + 				(i*hw->bufinfo.len) + 				(j*HFA384x_USB_RWMEM_MAXLEN);						writepage = HFA384x_ADDR_CMD_MKPAGE(					dlbufaddr + 					(j*HFA384x_USB_RWMEM_MAXLEN));			writeoffset = HFA384x_ADDR_CMD_MKOFF(					dlbufaddr + 					(j*HFA384x_USB_RWMEM_MAXLEN));			writelen = burnlen-(j*HFA384x_USB_RWMEM_MAXLEN);			writelen = writelen  > HFA384x_USB_RWMEM_MAXLEN ?					HFA384x_USB_RWMEM_MAXLEN :					writelen;			result = hfa384x_dowmem( hw, DOWAIT,					writepage, 					writeoffset, 					writebuf, 					writelen, 					NULL, NULL);#if 0Comment out for debugging, assume the write was successful.			if (result) {				WLAN_LOG_ERROR(					"Write to dl buffer failed, "					"result=0x%04x. Aborting.\n", 					result);				goto exit_proc;			}#endif		}		/* set the download 'write flash' mode */		result = hfa384x_cmd_download(hw, 				HFA384x_PROGMODE_NVWRITE, 				0,0,0);		if ( result ) {			WLAN_LOG_ERROR(				"download(NVWRITE,lo=%x,hi=%x,len=%lx) "				"cmd failed, result=%d. Aborting d/l\n",				burnlo, burnhi, burnlen, result);			goto exit_proc;		}		/* TODO: We really should do a readback and compare. */	}exit_proc:	/* Leave the firmware in the 'post-prog' mode.  flashdl_disable will */	/*  actually disable programming mode.  Remember, that will cause the */	/*  the firmware to effectively reset itself. */		DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_getconfig** Performs the sequence necessary to read a config/info item.** Arguments:*	hw		device structure*	rid		config/info record id (host order)*	buf		host side record buffer.  Upon return it will*			contain the body portion of the record (minus the *			RID and len).*	len		buffer length (in bytes, should match record length)** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error*	-ENODATA 	length mismatch between argument and retrieved*			record.** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_getconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len){	int 			result;	DBFENTER;	result = hfa384x_dorrid(hw, DOWAIT, rid, buf, len, NULL, NULL);	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_getconfig16** Performs the sequence necessary to read a 16 bit config/info item* and convert it to host order.** Arguments:*	hw		device structure*	rid		config/info record id (in host order)*	val		ptr to 16 bit buffer to receive value (in host order)** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_getconfig16(hfa384x_t *hw, UINT16 rid, void *val){	int		result;	DBFENTER;	result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT16));	if ( result == 0 ) {		*((UINT16*)val) = hfa384x2host_16(*((UINT16*)val));	}	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_getconfig32** Performs the sequence necessary to read a 32 bit config/info item* and convert it to host order.** Arguments:*	hw		device structure*	rid		config/info record id (in host order)*	val		ptr to 32 bit buffer to receive value (in host order)** Returns: *	0		success*	>0		f/w reported error - f/w status code*	<0		driver reported error** Side effects:** Call context:*	process ----------------------------------------------------------------*/int hfa384x_drvr_getconfig32(hfa384x_t *hw, UINT16 rid, void *val){	int		result;	DBFENTER;	result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT32));	if ( result == 0 ) {		*((UINT32*)val) = hfa384x2host_32(*((UINT32*)val));	}	DBFEXIT;	return result;}/*----------------------------------------------------------------* hfa384x_drvr_getconfig_async** Performs the sequence necessary to perform an async read of* of a config/info item.** Arguments:*	hw		device structure*	rid		config/info record id (host order)*	buf		host side record buffer.  Upon return it will*			contain the body portion of the record (minus the *			RID and len).*	len		buffer length (in bytes, should match record length)*	cbfn		caller supplied callback, called when the command *			is done (successful or not).*	cbfndata	pointer to some caller supplied data that will be*			passed in as an argument to the cbfn.** Returns: *	nothing		the cbfn gets a status argument identifying if*			any errors occur.* Side effects:*	Queues an hfa384x_usbcmd_t for subsequent execution.** Call context:*	Any----------------------------------------------------------------*/inthfa384x_drvr_getconfig_async(	hfa384x_t		*hw, 	UINT16			rid, 	ctlx_usercb_t		usercb, 	void			*usercb_data){	return hfa384x_dorrid(hw, DOASYNC, rid, NULL, 0, usercb, usercb_data);}/*----------------------------------------------------------------* hfa384x_drvr_handover** Sends a handover noti

⌨️ 快捷键说明

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