Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* drivers/atm/idt77105.c - IDT77105 (PHY) driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) /* Written 1999 by Greg Banks, NEC Australia <gnb@linuxfan.com>. Based on suni.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/atmdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sonet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/atm_idt77105.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "idt77105.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #undef GENERAL_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #ifdef GENERAL_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DPRINTK(format,args...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct idt77105_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct idt77105_stats stats;    /* link diagnostics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct atm_dev *dev;		/* device back-pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct idt77105_priv *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)         int loop_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)         unsigned char old_mcr;          /* storage of MCR reg while signal lost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static DEFINE_SPINLOCK(idt77105_priv_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define PRIV(dev) ((struct idt77105_priv *) dev->phy_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define PUT(val,reg) dev->ops->phy_put(dev,val,IDT77105_##reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define GET(reg) dev->ops->phy_get(dev,IDT77105_##reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static void idt77105_stats_timer_func(struct timer_list *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static void idt77105_restart_timer_func(struct timer_list *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static DEFINE_TIMER(stats_timer, idt77105_stats_timer_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static DEFINE_TIMER(restart_timer, idt77105_restart_timer_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int start_timer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct idt77105_priv *idt77105_all = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * Retrieve the value of one of the IDT77105's counters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * `counter' is one of the IDT77105_CTRSEL_* constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static u16 get_counter(struct atm_dev *dev, int counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)         u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)         /* write the counter bit into PHY register 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)         PUT(counter, CTRSEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)         /* read the low 8 bits from register 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)         val = GET(CTRLO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)         /* read the high 8 bits from register 5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)         val |= GET(CTRHI)<<8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)         return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * Timer function called every second to gather statistics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * from the 77105. This is done because the h/w registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * will overflow if not read at least once per second. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * kernel's stats are much higher precision. Also, having
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * a separate copy of the stats allows implementation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * an ioctl which gathers the stats *without* zero'ing them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static void idt77105_stats_timer_func(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct idt77105_priv *walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct idt77105_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)         DPRINTK("IDT77105 gathering statistics\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	for (walk = idt77105_all; walk; walk = walk->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		dev = walk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		stats = &walk->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)                 stats->symbol_errors += get_counter(dev, IDT77105_CTRSEL_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)                 stats->tx_cells += get_counter(dev, IDT77105_CTRSEL_TCC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)                 stats->rx_cells += get_counter(dev, IDT77105_CTRSEL_RCC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)                 stats->rx_hec_errors += get_counter(dev, IDT77105_CTRSEL_RHEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)         if (!start_timer) mod_timer(&stats_timer,jiffies+IDT77105_STATS_TIMER_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * A separate timer func which handles restarting PHY chips which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * have had the cable re-inserted after being pulled out. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * done by polling the Good Signal Bit in the Interrupt Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * register every 5 seconds. The other technique (checking Good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * Signal Bit in the interrupt handler) cannot be used because PHY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * interrupts need to be disabled when the cable is pulled out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * to avoid lots of spurious cell error interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void idt77105_restart_timer_func(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct idt77105_priv *walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)         unsigned char istat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)         DPRINTK("IDT77105 checking for cable re-insertion\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	for (walk = idt77105_all; walk; walk = walk->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		dev = walk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)                 if (dev->signal != ATM_PHY_SIG_LOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)                     continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)                     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)                 istat = GET(ISTAT); /* side effect: clears all interrupt status bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)                 if (istat & IDT77105_ISTAT_GOODSIG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)                     /* Found signal again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)                     atm_dev_signal_change(dev, ATM_PHY_SIG_FOUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	            printk(KERN_NOTICE "%s(itf %d): signal detected again\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)                         dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)                     /* flush the receive FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)                     PUT( GET(DIAG) | IDT77105_DIAG_RFLUSH, DIAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)                     /* re-enable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	            PUT( walk->old_mcr ,MCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)         if (!start_timer) mod_timer(&restart_timer,jiffies+IDT77105_RESTART_TIMER_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int fetch_stats(struct atm_dev *dev,struct idt77105_stats __user *arg,int zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct idt77105_stats stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	spin_lock_irqsave(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	memcpy(&stats, &PRIV(dev)->stats, sizeof(struct idt77105_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		memset(&PRIV(dev)->stats, 0, sizeof(struct idt77105_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	spin_unlock_irqrestore(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (arg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return copy_to_user(arg, &stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		    sizeof(struct idt77105_stats)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int set_loopback(struct atm_dev *dev,int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int diag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	diag = GET(DIAG) & ~IDT77105_DIAG_LCMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		case ATM_LM_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		case ATM_LM_LOC_ATM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			diag |= IDT77105_DIAG_LC_PHY_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		case ATM_LM_RMT_ATM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			diag |= IDT77105_DIAG_LC_LINE_LOOPBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	PUT(diag,DIAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	printk(KERN_NOTICE "%s(%d) Loopback mode is: %s\n", dev->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	    dev->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	    (mode == ATM_LM_NONE ? "NONE" : 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	      (mode == ATM_LM_LOC_ATM ? "DIAG (local)" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		(mode == IDT77105_DIAG_LC_LINE_LOOPBACK ? "LOOP (remote)" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		  "unknown")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		    );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	PRIV(dev)->loop_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int idt77105_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)         printk(KERN_NOTICE "%s(%d) idt77105_ioctl() called\n",dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		case IDT77105_GETSTATZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			if (!capable(CAP_NET_ADMIN)) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		case IDT77105_GETSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			return fetch_stats(dev, arg, cmd == IDT77105_GETSTATZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		case ATM_SETLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			return set_loopback(dev,(int)(unsigned long) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		case ATM_GETLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			return put_user(PRIV(dev)->loop_mode,(int __user *)arg) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			    -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		case ATM_QUERYLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			return put_user(ATM_LM_LOC_ATM | ATM_LM_RMT_ATM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			    (int __user *) arg) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static void idt77105_int(struct atm_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)         unsigned char istat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)         istat = GET(ISTAT); /* side effect: clears all interrupt status bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)         DPRINTK("IDT77105 generated an interrupt, istat=%02x\n", (unsigned)istat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)         if (istat & IDT77105_ISTAT_RSCC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)             /* Rx Signal Condition Change - line went up or down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)             if (istat & IDT77105_ISTAT_GOODSIG) {   /* signal detected again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)                 /* This should not happen (restart timer does it) but JIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		atm_dev_signal_change(dev, ATM_PHY_SIG_FOUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)             } else {    /* signal lost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)                 /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)                  * Disable interrupts and stop all transmission and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)                  * reception - the restart timer will restore these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)                  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)                 PRIV(dev)->old_mcr = GET(MCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	        PUT(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)                     (PRIV(dev)->old_mcr|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)                     IDT77105_MCR_DREC|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)                     IDT77105_MCR_DRIC|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)                     IDT77105_MCR_HALTTX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)                     ) & ~IDT77105_MCR_EIP, MCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		atm_dev_signal_change(dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	        printk(KERN_NOTICE "%s(itf %d): signal lost\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)                     dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)         if (istat & IDT77105_ISTAT_RFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)             /* Rx FIFO Overrun -- perform a FIFO flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)             PUT( GET(DIAG) | IDT77105_DIAG_RFLUSH, DIAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	    printk(KERN_NOTICE "%s(itf %d): receive FIFO overrun\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)                 dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #ifdef GENERAL_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)         if (istat & (IDT77105_ISTAT_HECERR | IDT77105_ISTAT_SCR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)                      IDT77105_ISTAT_RSE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)             /* normally don't care - just report in stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	    printk(KERN_NOTICE "%s(itf %d): received cell with error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)                 dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int idt77105_start(struct atm_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (!(dev->phy_data = kmalloc(sizeof(struct idt77105_priv),GFP_KERNEL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	PRIV(dev)->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	spin_lock_irqsave(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	PRIV(dev)->next = idt77105_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	idt77105_all = PRIV(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	spin_unlock_irqrestore(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	memset(&PRIV(dev)->stats,0,sizeof(struct idt77105_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)         /* initialise dev->signal from Good Signal Bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	atm_dev_signal_change(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		GET(ISTAT) & IDT77105_ISTAT_GOODSIG ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		ATM_PHY_SIG_FOUND : ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (dev->signal == ATM_PHY_SIG_LOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		printk(KERN_WARNING "%s(itf %d): no signal\n",dev->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		    dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)         /* initialise loop mode from hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)         switch ( GET(DIAG) & IDT77105_DIAG_LCMASK ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)         case IDT77105_DIAG_LC_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)             PRIV(dev)->loop_mode = ATM_LM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)         case IDT77105_DIAG_LC_PHY_LOOPBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)             PRIV(dev)->loop_mode = ATM_LM_LOC_ATM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)         case IDT77105_DIAG_LC_LINE_LOOPBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)             PRIV(dev)->loop_mode = ATM_LM_RMT_ATM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)         /* enable interrupts, e.g. on loss of signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)         PRIV(dev)->old_mcr = GET(MCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)         if (dev->signal == ATM_PHY_SIG_FOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)             PRIV(dev)->old_mcr |= IDT77105_MCR_EIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	    PUT(PRIV(dev)->old_mcr, MCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)                     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	idt77105_stats_timer_func(0); /* clear 77105 counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	(void) fetch_stats(dev,NULL,1); /* clear kernel counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	spin_lock_irqsave(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (start_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		start_timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		stats_timer.expires = jiffies+IDT77105_STATS_TIMER_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		add_timer(&stats_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		restart_timer.expires = jiffies+IDT77105_RESTART_TIMER_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		add_timer(&restart_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	spin_unlock_irqrestore(&idt77105_priv_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int idt77105_stop(struct atm_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct idt77105_priv *walk, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)         DPRINTK("%s(itf %d): stopping IDT77105\n",dev->type,dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)         /* disable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	PUT( GET(MCR) & ~IDT77105_MCR_EIP, MCR );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)         /* detach private struct from atm_dev & free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	for (prev = NULL, walk = idt77105_all ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)              walk != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)              prev = walk, walk = walk->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)             if (walk->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)                 if (prev != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)                     prev->next = walk->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)                 else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)                     idt77105_all = walk->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	        dev->phy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)                 dev->phy_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)                 kfree(walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static const struct atmphy_ops idt77105_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.start = 	idt77105_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	.ioctl =	idt77105_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	.interrupt =	idt77105_int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	.stop =		idt77105_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int idt77105_init(struct atm_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	dev->phy = &idt77105_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) EXPORT_SYMBOL(idt77105_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static void __exit idt77105_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/* turn off timers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	del_timer_sync(&stats_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	del_timer_sync(&restart_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) module_exit(idt77105_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) MODULE_LICENSE("GPL");