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

📄 sm.c

📁 powerpc内核mpc8241linux系统下net驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
static int sm_ioctl(struct device *dev, struct ifreq *ifr,		    struct hdlcdrv_ioctl *hi, int cmd);/* --------------------------------------------------------------------- */static const struct hdlcdrv_ops sm_ops = {	sm_drvname, sm_drvinfo, sm_open, sm_close, sm_ioctl};/* --------------------------------------------------------------------- */static int sm_open(struct device *dev){	struct sm_state *sm;	int err;	if (!dev || !dev->priv ||	    ((struct sm_state *)dev->priv)->hdrv.magic != HDLCDRV_MAGIC) {		printk(KERN_ERR "sm_open: invalid device struct\n");		return -EINVAL;	}	sm = (struct sm_state *)dev->priv;	if (!sm->mode_tx || !sm->mode_rx || !sm->hwdrv || !sm->hwdrv->open)		return -ENODEV;	sm->hdrv.par.bitrate = sm->mode_rx->bitrate;	err = sm->hwdrv->open(dev, sm);	if (err)		return err;	sm_output_open(sm);	MOD_INC_USE_COUNT;	printk(KERN_INFO "%s: %s mode %s.%s at iobase 0x%lx irq %u dma %u dma2 %u\n",	       sm_drvname, sm->hwdrv->hw_name, sm->mode_tx->name,	       sm->mode_rx->name, dev->base_addr, dev->irq, dev->dma, sm->hdrv.ptt_out.dma2);	return 0;}/* --------------------------------------------------------------------- */static int sm_close(struct device *dev){	struct sm_state *sm;	int err = -ENODEV;	if (!dev || !dev->priv ||	    ((struct sm_state *)dev->priv)->hdrv.magic != HDLCDRV_MAGIC) {		printk(KERN_ERR "sm_close: invalid device struct\n");		return -EINVAL;	}	sm = (struct sm_state *)dev->priv;	if (sm->hwdrv && sm->hwdrv->close)		err = sm->hwdrv && sm->hwdrv->close(dev, sm);	sm_output_close(sm);	MOD_DEC_USE_COUNT;	printk(KERN_INFO "%s: close %s at iobase 0x%lx irq %u dma %u\n",	       sm_drvname, sm->hwdrv->hw_name, dev->base_addr, dev->irq, dev->dma);	return err;}/* --------------------------------------------------------------------- */static int sethw(struct device *dev, struct sm_state *sm, char *mode){	char *cp = strchr(mode, ':');	const struct hardware_info **hwp = sm_hardware_table;	if (!cp)		cp = mode;	else {		*cp++ = '\0';		while (hwp && (*hwp) && (*hwp)->hw_name && strcmp((*hwp)->hw_name, mode))			hwp++;		if (!hwp || !*hwp || !(*hwp)->hw_name)			return -EINVAL;		if ((*hwp)->loc_storage > sizeof(sm->hw)) {			printk(KERN_ERR "%s: insufficient storage for hw driver %s (%d)\n",			       sm_drvname, (*hwp)->hw_name, (*hwp)->loc_storage);			return -EINVAL;		}		sm->hwdrv = *hwp;	}	if (!*cp)		return 0;	if (sm->hwdrv && sm->hwdrv->sethw)		return sm->hwdrv->sethw(dev, sm, cp);	return -EINVAL;}/* --------------------------------------------------------------------- */static int sm_ioctl(struct device *dev, struct ifreq *ifr,		    struct hdlcdrv_ioctl *hi, int cmd){	struct sm_state *sm;	struct sm_ioctl bi;	unsigned long flags;	unsigned int newdiagmode;	unsigned int newdiagflags;	char *cp;	const struct modem_tx_info **mtp = sm_modem_tx_table;	const struct modem_rx_info **mrp = sm_modem_rx_table;	const struct hardware_info **hwp = sm_hardware_table;	if (!dev || !dev->priv ||	    ((struct sm_state *)dev->priv)->hdrv.magic != HDLCDRV_MAGIC) {		printk(KERN_ERR "sm_ioctl: invalid device struct\n");		return -EINVAL;	}	sm = (struct sm_state *)dev->priv;	if (cmd != SIOCDEVPRIVATE) {		if (!sm->hwdrv || !sm->hwdrv->ioctl)			return sm->hwdrv->ioctl(dev, sm, ifr, hi, cmd);		return -ENOIOCTLCMD;	}	switch (hi->cmd) {	default:		if (sm->hwdrv && sm->hwdrv->ioctl)			return sm->hwdrv->ioctl(dev, sm, ifr, hi, cmd);		return -ENOIOCTLCMD;	case HDLCDRVCTL_GETMODE:		cp = hi->data.modename;		if (sm->hwdrv && sm->hwdrv->hw_name)			cp += sprintf(cp, "%s:", sm->hwdrv->hw_name);		else			cp += sprintf(cp, "<unspec>:");		if (sm->mode_tx && sm->mode_tx->name)			cp += sprintf(cp, "%s", sm->mode_tx->name);		else			cp += sprintf(cp, "<unspec>");		if (!sm->mode_rx || !sm->mode_rx ||		    strcmp(sm->mode_rx->name, sm->mode_tx->name)) {			if (sm->mode_rx && sm->mode_rx->name)				cp += sprintf(cp, ",%s", sm->mode_rx->name);			else				cp += sprintf(cp, ",<unspec>");		}		if (copy_to_user(ifr->ifr_data, hi, sizeof(*hi)))			return -EFAULT;		return 0;	case HDLCDRVCTL_SETMODE:		if (dev->start || !suser())			return -EACCES;		hi->data.modename[sizeof(hi->data.modename)-1] = '\0';		return sethw(dev, sm, hi->data.modename);	case HDLCDRVCTL_MODELIST:		cp = hi->data.modename;		while (*hwp) {			if ((*hwp)->hw_name)				cp += sprintf(cp, "%s:,", (*hwp)->hw_name);			hwp++;		}		while (*mtp) {			if ((*mtp)->name)				cp += sprintf(cp, ">%s,", (*mtp)->name);			mtp++;		}		while (*mrp) {			if ((*mrp)->name)				cp += sprintf(cp, "<%s,", (*mrp)->name);			mrp++;		}		cp[-1] = '\0';		if (copy_to_user(ifr->ifr_data, hi, sizeof(*hi)))			return -EFAULT;		return 0;#ifdef SM_DEBUG	case SMCTL_GETDEBUG:		if (copy_from_user(&bi, ifr->ifr_data, sizeof(bi)))			return -EFAULT;		bi.data.dbg.int_rate = sm->debug_vals.last_intcnt;		bi.data.dbg.mod_cycles = sm->debug_vals.mod_cyc;		bi.data.dbg.demod_cycles = sm->debug_vals.demod_cyc;		bi.data.dbg.dma_residue = sm->debug_vals.dma_residue;		sm->debug_vals.mod_cyc = sm->debug_vals.demod_cyc =			sm->debug_vals.dma_residue = 0;		if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))			return -EFAULT;		return 0;#endif /* SM_DEBUG */	case SMCTL_DIAGNOSE:		if (copy_from_user(&bi, ifr->ifr_data, sizeof(bi)))			return -EFAULT;		newdiagmode = bi.data.diag.mode;		newdiagflags = bi.data.diag.flags;		if (newdiagmode > SM_DIAGMODE_CONSTELLATION)			return -EINVAL;		bi.data.diag.mode = sm->diag.mode;		bi.data.diag.flags = sm->diag.flags;		bi.data.diag.samplesperbit = sm->mode_rx->sperbit;		if (sm->diag.mode != newdiagmode) {			save_flags(flags);			cli();			sm->diag.ptr = -1;			sm->diag.flags = newdiagflags & ~SM_DIAGFLAG_VALID;			sm->diag.mode = newdiagmode;			restore_flags(flags);			if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))				return -EFAULT;			return 0;		}		if (sm->diag.ptr < 0 || sm->diag.mode == SM_DIAGMODE_OFF) {			if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))				return -EFAULT;			return 0;		}		if (bi.data.diag.datalen > DIAGDATALEN)			bi.data.diag.datalen = DIAGDATALEN;		if (sm->diag.ptr < bi.data.diag.datalen) {			if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))				return -EFAULT;			return 0;		}		if (copy_to_user(bi.data.diag.data, sm->diag.data,				 bi.data.diag.datalen * sizeof(short)))			return -EFAULT;		bi.data.diag.flags |= SM_DIAGFLAG_VALID;		save_flags(flags);		cli();		sm->diag.ptr = -1;		sm->diag.flags = newdiagflags & ~SM_DIAGFLAG_VALID;		sm->diag.mode = newdiagmode;		restore_flags(flags);		if (copy_to_user(ifr->ifr_data, &bi, sizeof(bi)))			return -EFAULT;		return 0;	}}/* --------------------------------------------------------------------- */#ifdef MODULE__initfunc(static int sm_init(void))#else /* MODULE */__initfunc(int sm_init(void))#endif /* MODULE */{	int i, j, found = 0;	char set_hw = 1;	struct sm_state *sm;	char ifname[HDLCDRV_IFNAMELEN];	printk(sm_drvinfo);	/*	 * register net devices	 */	for (i = 0; i < NR_PORTS; i++) {		struct device *dev = sm_device+i;		sprintf(ifname, "sm%d", i);		if (!sm_ports[i].mode)			set_hw = 0;		if (!set_hw)			sm_ports[i].iobase = sm_ports[i].irq = 0;		j = hdlcdrv_register_hdlcdrv(dev, &sm_ops, sizeof(struct sm_state),					     ifname, sm_ports[i].iobase,					     sm_ports[i].irq, sm_ports[i].dma);		if (!j) {			sm = (struct sm_state *)dev->priv;			sm->hdrv.ptt_out.dma2 = sm_ports[i].dma2;			sm->hdrv.ptt_out.seriobase = sm_ports[i].seriobase;			sm->hdrv.ptt_out.pariobase = sm_ports[i].pariobase;			sm->hdrv.ptt_out.midiiobase = sm_ports[i].midiiobase;			if (set_hw && sethw(dev, sm, sm_ports[i].mode))				set_hw = 0;			found++;		} else {			printk(KERN_WARNING "%s: cannot register net device\n",			       sm_drvname);		}	}	if (!found)		return -ENXIO;	return 0;}/* --------------------------------------------------------------------- */#ifdef MODULE/* * command line settable parameters */static char *mode = NULL;static int iobase = -1;static int irq = -1;static int dma = -1;static int dma2 = -1;static int serio = 0;static int pario = 0;static int midiio = 0;#if LINUX_VERSION_CODE >= 0x20115MODULE_PARM(mode, "s");MODULE_PARM_DESC(mode, "soundmodem operating mode; eg. sbc:afsk1200 or wss:fsk9600");MODULE_PARM(iobase, "i");MODULE_PARM_DESC(iobase, "soundmodem base address");MODULE_PARM(irq, "i");MODULE_PARM_DESC(irq, "soundmodem interrupt");MODULE_PARM(dma, "i");MODULE_PARM_DESC(dma, "soundmodem dma channel");MODULE_PARM(dma2, "i");MODULE_PARM_DESC(dma2, "soundmodem 2nd dma channel; full duplex only");MODULE_PARM(serio, "i");MODULE_PARM_DESC(serio, "soundmodem PTT output on serial port");MODULE_PARM(pario, "i");MODULE_PARM_DESC(pario, "soundmodem PTT output on parallel port");MODULE_PARM(midiio, "i");MODULE_PARM_DESC(midiio, "soundmodem PTT output on midi port");MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");MODULE_DESCRIPTION("Soundcard amateur radio modem driver");#endif__initfunc(int init_module(void)){	if (mode) {		if (iobase == -1)			iobase = (!strncmp(mode, "sbc", 3)) ? 0x220 : 0x530;		if (irq == -1)			irq = (!strncmp(mode, "sbc", 3)) ? 5 : 11;		if (dma == -1)			dma = 1;	}	sm_ports[0].mode = mode;	sm_ports[0].iobase = iobase;	sm_ports[0].irq = irq;	sm_ports[0].dma = dma;	sm_ports[0].dma2 = dma2;	sm_ports[0].seriobase = serio;	sm_ports[0].pariobase = pario;	sm_ports[0].midiiobase = midiio;	sm_ports[1].mode = NULL;	return sm_init();}/* --------------------------------------------------------------------- */void cleanup_module(void){	int i;	printk(KERN_INFO "sm: cleanup_module called\n");	for(i = 0; i < NR_PORTS; i++) {		struct device *dev = sm_device+i;		struct sm_state *sm = (struct sm_state *)dev->priv;		if (sm) {			if (sm->hdrv.magic != HDLCDRV_MAGIC)				printk(KERN_ERR "sm: invalid magic in "				       "cleanup_module\n");			else				hdlcdrv_unregister_hdlcdrv(dev);		}	}}#else /* MODULE *//* --------------------------------------------------------------------- *//* * format: sm=io,irq,dma[,dma2[,serio[,pario]]],mode * mode: hw:modem * hw: sbc, wss, wssfdx * modem: afsk1200, fsk9600 */__initfunc(void sm_setup(char *str, int *ints)){	int i;	for (i = 0; (i < NR_PORTS) && (sm_ports[i].mode); i++);	if ((i >= NR_PORTS) || (ints[0] < 3)) {		printk(KERN_INFO "%s: too many or invalid interface "		       "specifications\n", sm_drvname);		return;	}	sm_ports[i].mode = str;	sm_ports[i].iobase = ints[1];	sm_ports[i].irq = ints[2];	sm_ports[i].dma = ints[3];	sm_ports[i].dma2 = (ints[0] >= 4) ? ints[4] : 0;	sm_ports[i].seriobase = (ints[0] >= 5) ? ints[5] : 0;	sm_ports[i].pariobase = (ints[0] >= 6) ? ints[6] : 0;	sm_ports[i].midiiobase = (ints[0] >= 7) ? ints[7] : 0;	if (i < NR_PORTS-1)		sm_ports[i+1].mode = NULL;}#endif /* MODULE *//* --------------------------------------------------------------------- */

⌨️ 快捷键说明

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