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

📄 sdla_ppp.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************** sdla_ppp.c	WANPIPE(tm) Multiprotocol WAN Link Driver. PPP module.** Author: 	Jaspreet Singh 	<jaspreet@sangoma.com>** Copyright:	(c) 1995-1997 Sangoma Technologies Inc.**		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.* ============================================================================* Mar 15, 1998  Alan Cox	o 2.1.8x basic port.* Nov 27, 1997	Jaspreet Singh	o Added protection against enabling of irqs *				  while they have been disabled.* Nov 24, 1997  Jaspreet Singh  o Fixed another RACE condition caused by*                                 disabling and enabling of irqs.*                               o Added new counters for stats on disable/enable*                                 IRQs.* Nov 10, 1997	Jaspreet Singh	o Initialized 'skb->mac.raw' to 'skb->data'*				  before every netif_rx().*				o Free up the device structure in del_if().* Nov 07, 1997	Jaspreet Singh	o Changed the delay to zero for Line tracing*				  command.* Oct 20, 1997 	Jaspreet Singh	o Added hooks in for Router UP time.* Oct 16, 1997	Jaspreet Singh  o The critical flag is used to maintain flow*				  control by avoiding RACE conditions.  The *				  cli() and restore_flags() are taken out.*				  A new structure, "ppp_private_area", is added *				  to provide Driver Statistics.   * Jul 21, 1997 	Jaspreet Singh	o Protected calls to sdla_peek() by adding *				  save_flags(), cli() and restore_flags().* Jul 07, 1997	Jaspreet Singh  o Added configurable TTL for UDP packets*				o Added ability to discard mulitcast and*				  broacast source addressed packets.* Jun 27, 1997 	Jaspreet Singh	o Added FT1 monitor capabilities*				  New case (0x25) statement in if_send routine.*				  Added a global variable rCount to keep track*				  of FT1 status enabled on the board.* May 22, 1997	Jaspreet Singh	o Added change in the PPP_SET_CONFIG command for*				508 card to reflect changes in the new *				ppp508.sfm for supporting:continous transmission*				of Configure-Request packets without receiving a*				reply 				*				OR-ed 0x300 to conf_flags *			        o Changed connect_tmout from 900 to 0* May 21, 1997	Jaspreet Singh  o Fixed UDP Management for multiple boards* Apr 25, 1997  Farhan Thawar    o added UDP Management stuff* Mar 11, 1997  Farhan Thawar   Version 3.1.1*                                o fixed (+1) bug in rx_intr()*                                o changed if_send() to return 0 if*                                  wandev.critical() is true*                                o free socket buffer in if_send() if*                                  returning 0 * Jan 15, 1997	Gene Kozin	Version 3.1.0*				 o implemented exec() entry point* Jan 06, 1997	Gene Kozin	Initial version.*****************************************************************************/#include <linux/kernel.h>	/* printk(), and other useful stuff */#include <linux/stddef.h>	/* offsetof(), etc. */#include <linux/errno.h>	/* return codes */#include <linux/string.h>	/* inline memset(), etc. */#include <linux/malloc.h>	/* kmalloc(), kfree() */#include <linux/wanrouter.h>	/* WAN router definitions */#include <linux/wanpipe.h>	/* WANPIPE common user API definitions */#include <linux/if_arp.h>	/* ARPHRD_* defines */#include <asm/byteorder.h>	/* htons(), etc. */#include <asm/uaccess.h>	/* copyto/from user */#define	_GNUC_#include <linux/sdla_ppp.h>	/* PPP firmware API definitions *//****** Defines & Macros ****************************************************/#ifdef	_DEBUG_#define	STATIC#else#define	STATIC		static#endif#define	PPP_DFLT_MTU	1500	/* default MTU */#define	PPP_MAX_MTU	4000	/* maximum MTU */#define PPP_HDR_LEN	1#define	CONNECT_TIMEOUT	(90*HZ)	/* link connection timeout */#define	HOLD_DOWN_TIME	(30*HZ)	/* link hold down time *//* For handle_IPXWAN() */#define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))/******Data Structures*****************************************************//* This structure is placed in the private data area of the device structure. * The card structure used to occupy the private area but now the following  * structure will incorporate the card structure along with PPP specific data */typedef struct ppp_private_area {	sdla_t *card;	unsigned long router_start_time;	/*router start time in sec */	unsigned long tick_counter;	/*used for 5 second counter */	unsigned mc;		/*multicast support on or off */	/* PPP specific statistics */	unsigned long if_send_entry;	unsigned long if_send_skb_null;	unsigned long if_send_broadcast;	unsigned long if_send_multicast;	unsigned long if_send_critical_ISR;	unsigned long if_send_critical_non_ISR;	unsigned long if_send_busy;	unsigned long if_send_busy_timeout;	unsigned long if_send_DRVSTATS_request;	unsigned long if_send_PTPIPE_request;	unsigned long if_send_wan_disconnected;	unsigned long if_send_adptr_bfrs_full;	unsigned long if_send_protocol_error;	unsigned long if_send_tx_int_enabled;	unsigned long if_send_bfr_passed_to_adptr;	unsigned long rx_intr_no_socket;	unsigned long rx_intr_DRVSTATS_request;	unsigned long rx_intr_PTPIPE_request;	unsigned long rx_intr_bfr_not_passed_to_stack;	unsigned long rx_intr_bfr_passed_to_stack;	unsigned long UDP_PTPIPE_mgmt_kmalloc_err;	unsigned long UDP_PTPIPE_mgmt_adptr_type_err;	unsigned long UDP_PTPIPE_mgmt_direction_err;	unsigned long UDP_PTPIPE_mgmt_adptr_cmnd_timeout;	unsigned long UDP_PTPIPE_mgmt_adptr_cmnd_OK;	unsigned long UDP_PTPIPE_mgmt_passed_to_adptr;	unsigned long UDP_PTPIPE_mgmt_passed_to_stack;	unsigned long UDP_PTPIPE_mgmt_no_socket;	unsigned long UDP_DRVSTATS_mgmt_kmalloc_err;	unsigned long UDP_DRVSTATS_mgmt_adptr_type_err;	unsigned long UDP_DRVSTATS_mgmt_direction_err;	unsigned long UDP_DRVSTATS_mgmt_adptr_cmnd_timeout;	unsigned long UDP_DRVSTATS_mgmt_adptr_cmnd_OK;	unsigned long UDP_DRVSTATS_mgmt_passed_to_adptr;	unsigned long UDP_DRVSTATS_mgmt_passed_to_stack;	unsigned long UDP_DRVSTATS_mgmt_no_socket;	unsigned long router_up_time;} ppp_private_area_t;/* variable for keeping track of enabling/disabling FT1 monitor status */static int rCount = 0;extern void disable_irq(unsigned int);extern void enable_irq(unsigned int);/****** Function Prototypes *************************************************//* WAN link driver entry points. These are called by the WAN router module. */static int update(wan_device_t * wandev);static int new_if(wan_device_t * wandev, struct device *dev,		  wanif_conf_t * conf);static int del_if(wan_device_t * wandev, struct device *dev);/* WANPIPE-specific entry points */static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data);/* Network device interface */static int if_init(struct device *dev);static int if_open(struct device *dev);static int if_close(struct device *dev);static int if_header(struct sk_buff *skb, struct device *dev,	    unsigned short type, void *daddr, void *saddr, unsigned len);static int if_rebuild_hdr(struct sk_buff *skb);static int if_send(struct sk_buff *skb, struct device *dev);static struct enet_statistics *if_stats(struct device *dev);/* PPP firmware interface functions */static int ppp_read_version(sdla_t * card, char *str);static int ppp_configure(sdla_t * card, void *data);static int ppp_set_intr_mode(sdla_t * card, unsigned mode);static int ppp_comm_enable(sdla_t * card);static int ppp_comm_disable(sdla_t * card);static int ppp_get_err_stats(sdla_t * card);static int ppp_send(sdla_t * card, void *data, unsigned len, unsigned proto);static int ppp_error(sdla_t * card, int err, ppp_mbox_t * mb);/* Interrupt handlers */STATIC void wpp_isr(sdla_t * card);static void rx_intr(sdla_t * card);static void tx_intr(sdla_t * card);/* Background polling routines */static void wpp_poll(sdla_t * card);static void poll_active(sdla_t * card);static void poll_connecting(sdla_t * card);static void poll_disconnected(sdla_t * card);/* Miscellaneous functions */static int config502(sdla_t * card);static int config508(sdla_t * card);static void show_disc_cause(sdla_t * card, unsigned cause);static unsigned char bps_to_speed_code(unsigned long bps);static int reply_udp(unsigned char *data, unsigned int mbox_len);static int process_udp_mgmt_pkt(char udp_pkt_src, sdla_t * card, struct sk_buff *skb, struct device *dev, ppp_private_area_t * ppp_priv_area);static int process_udp_driver_call(char udp_pkt_src, sdla_t * card, struct sk_buff *skb, struct device *dev, ppp_private_area_t * ppp_priv_area);static void init_ppp_tx_rx_buff(sdla_t * card);static int intr_test(sdla_t * card);static int udp_pkt_type(struct sk_buff *skb, sdla_t * card);static void init_ppp_priv_struct(ppp_private_area_t * ppp_priv_area);static void init_global_statistics(sdla_t * card);static int Intr_test_counter;static char TracingEnabled;static unsigned long curr_trace_addr;static unsigned long start_trace_addr;static unsigned short available_buffer_space;/* IPX functions */static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming);static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto);/****** Public Functions ****************************************************//*============================================================================ * PPP protocol initialization routine. * * This routine is called by the main WANPIPE module during setup.  At this * point adapter is completely initialized and firmware is running. *  o read firmware version (to make sure it's alive) *  o configure adapter *  o initialize protocol-specific fields of the adapter data space. * * Return:	0	o.k. *		< 0	failure. */int wpp_init(sdla_t * card, wandev_conf_t * conf){	union {		char str[80];	} u;	/* Verify configuration ID */	if (conf->config_id != WANCONFIG_PPP) {		printk(KERN_INFO "%s: invalid configuration ID %u!\n",		       card->devname, conf->config_id);		return -EINVAL;	}	/* Initialize protocol-specific fields */	switch (card->hw.fwid) {	case SFID_PPP502:		card->mbox = (void *) (card->hw.dpmbase + PPP502_MB_OFFS);		card->flags = (void *) (card->hw.dpmbase + PPP502_FLG_OFFS);		break;	case SFID_PPP508:		card->mbox = (void *) (card->hw.dpmbase + PPP508_MB_OFFS);		card->flags = (void *) (card->hw.dpmbase + PPP508_FLG_OFFS);		break;	default:		return -EINVAL;	}	/* Read firmware version.  Note that when adapter initializes, it	 * clears the mailbox, so it may appear that the first command was	 * executed successfully when in fact it was merely erased. To work	 * around this, we execute the first command twice.	 */	if (ppp_read_version(card, NULL) || ppp_read_version(card, u.str))		return -EIO;	printk(KERN_INFO "%s: running PPP firmware v%s\n", card->devname, u.str);	/* Adjust configuration and set defaults */	card->wandev.mtu = (conf->mtu) ?	    min(conf->mtu, PPP_MAX_MTU) : PPP_DFLT_MTU;	card->wandev.bps = conf->bps;	card->wandev.interface = conf->interface;	card->wandev.clocking = conf->clocking;	card->wandev.station = conf->station;	card->isr = &wpp_isr;	card->poll = &wpp_poll;	card->exec = &wpp_exec;	card->wandev.update = &update;	card->wandev.new_if = &new_if;	card->wandev.del_if = &del_if;	card->wandev.state = WAN_DISCONNECTED;	card->wandev.udp_port = conf->udp_port;	card->wandev.ttl = conf->ttl;	card->irq_dis_if_send_count = 0;	card->irq_dis_poll_count = 0;	TracingEnabled = 0;	card->wandev.enable_IPX = conf->enable_IPX;	if (conf->network_number)		card->wandev.network_number = conf->network_number;	else		card->wandev.network_number = 0xDEADBEEF;	/* initialize global statistics */	init_global_statistics(card);	return 0;}/******* WAN Device Driver Entry Points *************************************//*============================================================================ * Update device status & statistics. */static int update(wan_device_t * wandev){	sdla_t *card;	/* sanity checks */	if ((wandev == NULL) || (wandev->private == NULL))		return -EFAULT;	if (wandev->state == WAN_UNCONFIGURED)		return -ENODEV;	if (test_and_set_bit(0, (void *) &wandev->critical))		return -EAGAIN;	card = wandev->private;	ppp_get_err_stats(card);	wandev->critical = 0;	return 0;}/*============================================================================ * Create new logical channel. * This routine is called by the router when ROUTER_IFNEW IOCTL is being * handled. * o parse media- and hardware-specific configuration * o make sure that a new channel can be created * o allocate resources, if necessary * o prepare network device structure for registaration. * * Return:	0	o.k. *		< 0	failure (channel will not be created) */static int new_if(wan_device_t * wandev, struct device *dev, wanif_conf_t * conf){	sdla_t *card = wandev->private;	ppp_private_area_t *ppp_priv_area;	if (wandev->ndev)		return -EEXIST;	if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {		printk(KERN_INFO "%s: invalid interface name!\n",		       card->devname);		return -EINVAL;	}	/* allocate and initialize private data */	ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL);	if (ppp_priv_area == NULL)		return -ENOMEM;	memset(ppp_priv_area, 0, sizeof(ppp_private_area_t));	ppp_priv_area->card = card;	/* initialize data */	strcpy(card->u.p.if_name, conf->name);	/* initialize data in ppp_private_area structure */	init_ppp_priv_struct(ppp_priv_area);	ppp_priv_area->mc = conf->mc;	/* prepare network device data space for registration */	dev->name = card->u.p.if_name;	dev->init = &if_init;	dev->priv = ppp_priv_area;	return 0;}/*============================================================================ * Delete logical channel. */static int del_if(wan_device_t * wandev, struct device *dev){	if (dev->priv) {		kfree(dev->priv);		dev->priv = NULL;	}	return 0;}/****** WANPIPE-specific entry points ***************************************//*============================================================================ * Execute adapter interface command. */static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data){	ppp_mbox_t *mbox = card->mbox;	int len;	if(copy_from_user((void *) &mbox->cmd, u_cmd, sizeof(ppp_cmd_t)))		return -EFAULT;	len = mbox->cmd.length;	if (len) {		if(copy_from_user((void *) &mbox->data, u_data, len))			return -EFAULT;	}	/* execute command */	if (!sdla_exec(mbox))		return -EIO;	/* return result */	if(copy_to_user(u_cmd, (void *) &mbox->cmd, sizeof(ppp_cmd_t)))		return -EFAULT;	len = mbox->cmd.length;	if (len && u_data && copy_to_user(u_data, (void *) &mbox->data, len))		return -EFAULT;	return 0;}/****** Network Device Interface ********************************************//*============================================================================ * Initialize Linux network interface. * * This routine is called only once for each interface, during Linux network * interface registration.  Returning anything but zero will fail interface * registration. */static int if_init(struct device *dev){	ppp_private_area_t *ppp_priv_area = dev->priv;	sdla_t *card = ppp_priv_area->card;	wan_device_t *wandev = &card->wandev;	/* Initialize device driver entry points */	dev->open = &if_open;	dev->stop = &if_close;	dev->hard_header = &if_header;	dev->rebuild_header = &if_rebuild_hdr;	dev->hard_start_xmit = &if_send;	dev->get_stats = &if_stats;	/* Initialize media-specific parameters */	dev->type = ARPHRD_PPP;	/* ARP h/w type */	dev->mtu = wandev->mtu;	dev->hard_header_len = PPP_HDR_LEN;	/* media header length */	/* Initialize hardware parameters (just for reference) */	dev->irq = wandev->irq;	dev->dma = wandev->dma;	dev->base_addr = wandev->ioport;

⌨️ 快捷键说明

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