45 #include <linux/module.h>
46 #include <linux/types.h>
47 #include <linux/net.h>
50 #include <linux/slab.h>
51 #include <linux/errno.h>
52 #include <linux/bitops.h>
53 #include <linux/random.h>
60 #include <linux/netdevice.h>
61 #include <linux/if_arp.h>
66 #include <linux/kernel.h>
71 #include <asm/uaccess.h>
78 static const char yam_drvname[] =
"yam";
80 "YAM driver version 0.8 by F1OAT/F6FBB\n";
84 #define FIRMWARE_9600 "yam/9600.bin"
85 #define FIRMWARE_1200 "yam/1200.bin"
91 #define YAM_MAGIC 0xF10A7654
102 #define YAM_MAX_FRAME 1024
104 #define DEFAULT_BITRATE 9600
105 #define DEFAULT_HOLDD 10
106 #define DEFAULT_TXD 300
107 #define DEFAULT_TXTAIL 10
108 #define DEFAULT_SLOT 100
109 #define DEFAULT_PERS 64
158 static struct yam_mcs *yam_data;
164 #define RBR(iobase) (iobase+0)
165 #define THR(iobase) (iobase+0)
166 #define IER(iobase) (iobase+1)
167 #define IIR(iobase) (iobase+2)
168 #define FCR(iobase) (iobase+2)
169 #define LCR(iobase) (iobase+3)
170 #define MCR(iobase) (iobase+4)
171 #define LSR(iobase) (iobase+5)
172 #define MSR(iobase) (iobase+6)
173 #define SCR(iobase) (iobase+7)
174 #define DLL(iobase) (iobase+0)
175 #define DLM(iobase) (iobase+1)
185 #define IIR_TIMEOUT 12
187 #define IIR_MASK 0x0F
198 #define MCR_OUT1 0x04
199 #define MCR_OUT2 0x08
200 #define MCR_LOOP 0x10
203 #define MSR_DCTS 0x01
204 #define MSR_DDSR 0x02
205 #define MSR_DRIN 0x04
206 #define MSR_DDCD 0x08
209 #define MSR_RING 0x40
217 #define LSR_BREAK 0x10
218 #define LSR_THRE 0x20
219 #define LSR_TSRE 0x40
222 #define LCR_DLAB 0x80
223 #define LCR_BREAK 0x40
224 #define LCR_PZERO 0x28
225 #define LCR_PEVEN 0x18
226 #define LCR_PODD 0x08
227 #define LCR_STOP1 0x00
228 #define LCR_STOP2 0x04
229 #define LCR_BIT5 0x00
230 #define LCR_BIT6 0x02
231 #define LCR_BIT7 0x01
232 #define LCR_BIT8 0x03
236 #define TX_RDY MSR_DCTS
237 #define RX_DCD MSR_DCD
238 #define RX_FLAG MSR_RING
239 #define FPGA_DONE MSR_DSR
240 #define PTT_ON (MCR_RTS|MCR_OUT2)
241 #define PTT_OFF (MCR_DTR|MCR_OUT2)
243 #define ENABLE_RXINT IER_RX
244 #define ENABLE_TXINT IER_MSR
245 #define ENABLE_RTXINT (IER_RX|IER_MSR)
252 static const unsigned char chktabl[256] =
253 {0x00, 0x89, 0x12, 0x9b, 0x24, 0xad, 0x36, 0xbf, 0x48, 0xc1, 0x5a, 0xd3, 0x6c, 0xe5, 0x7e,
254 0xf7, 0x81, 0x08, 0x93, 0x1a, 0xa5, 0x2c, 0xb7, 0x3e, 0xc9, 0x40, 0xdb, 0x52, 0xed, 0x64,
255 0xff, 0x76, 0x02, 0x8b, 0x10, 0x99, 0x26, 0xaf, 0x34, 0xbd, 0x4a, 0xc3, 0x58, 0xd1, 0x6e,
256 0xe7, 0x7c, 0xf5, 0x83, 0x0a, 0x91, 0x18, 0xa7, 0x2e, 0xb5, 0x3c, 0xcb, 0x42, 0xd9, 0x50,
257 0xef, 0x66, 0xfd, 0x74, 0x04, 0x8d, 0x16, 0x9f, 0x20, 0xa9, 0x32, 0xbb, 0x4c, 0xc5, 0x5e,
258 0xd7, 0x68, 0xe1, 0x7a, 0xf3, 0x85, 0x0c, 0x97, 0x1e, 0xa1, 0x28, 0xb3, 0x3a, 0xcd, 0x44,
259 0xdf, 0x56, 0xe9, 0x60, 0xfb, 0x72, 0x06, 0x8f, 0x14, 0x9d, 0x22, 0xab, 0x30, 0xb9, 0x4e,
260 0xc7, 0x5c, 0xd5, 0x6a, 0xe3, 0x78, 0xf1, 0x87, 0x0e, 0x95, 0x1c, 0xa3, 0x2a, 0xb1, 0x38,
261 0xcf, 0x46, 0xdd, 0x54, 0xeb, 0x62, 0xf9, 0x70, 0x08, 0x81, 0x1a, 0x93, 0x2c, 0xa5, 0x3e,
262 0xb7, 0x40, 0xc9, 0x52, 0xdb, 0x64, 0xed, 0x76, 0xff, 0x89, 0x00, 0x9b, 0x12, 0xad, 0x24,
263 0xbf, 0x36, 0xc1, 0x48, 0xd3, 0x5a, 0xe5, 0x6c, 0xf7, 0x7e, 0x0a, 0x83, 0x18, 0x91, 0x2e,
264 0xa7, 0x3c, 0xb5, 0x42, 0xcb, 0x50, 0xd9, 0x66, 0xef, 0x74, 0xfd, 0x8b, 0x02, 0x99, 0x10,
265 0xaf, 0x26, 0xbd, 0x34, 0xc3, 0x4a, 0xd1, 0x58, 0xe7, 0x6e, 0xf5, 0x7c, 0x0c, 0x85, 0x1e,
266 0x97, 0x28, 0xa1, 0x3a, 0xb3, 0x44, 0xcd, 0x56, 0xdf, 0x60, 0xe9, 0x72, 0xfb, 0x8d, 0x04,
267 0x9f, 0x16, 0xa9, 0x20, 0xbb, 0x32, 0xc5, 0x4c, 0xd7, 0x5e, 0xe1, 0x68, 0xf3, 0x7a, 0x0e,
268 0x87, 0x1c, 0x95, 0x2a, 0xa3, 0x38, 0xb1, 0x46, 0xcf, 0x54, 0xdd, 0x62, 0xeb, 0x70, 0xf9,
269 0x8f, 0x06, 0x9d, 0x14, 0xab, 0x22, 0xb9, 0x30, 0xc7, 0x4e, 0xd5, 0x5c, 0xe3, 0x6a, 0xf1,
271 static const unsigned char chktabh[256] =
272 {0x00, 0x11, 0x23, 0x32, 0x46, 0x57, 0x65, 0x74, 0x8c, 0x9d, 0xaf, 0xbe, 0xca, 0xdb, 0xe9,
273 0xf8, 0x10, 0x01, 0x33, 0x22, 0x56, 0x47, 0x75, 0x64, 0x9c, 0x8d, 0xbf, 0xae, 0xda, 0xcb,
274 0xf9, 0xe8, 0x21, 0x30, 0x02, 0x13, 0x67, 0x76, 0x44, 0x55, 0xad, 0xbc, 0x8e, 0x9f, 0xeb,
275 0xfa, 0xc8, 0xd9, 0x31, 0x20, 0x12, 0x03, 0x77, 0x66, 0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7a, 0x48, 0x59, 0x2d, 0x3c, 0x0e, 0x1f,
288 0xf7, 0xe6, 0xd4, 0xc5, 0xb1, 0xa0, 0x92, 0x83, 0x7b, 0x6a, 0x58, 0x49, 0x3d, 0x2c, 0x1e,
306 static void fpga_reset(
int iobase)
328 static int fpga_write(
int iobase,
unsigned char wrd)
334 for (k = 0; k < 8; k++) {
352 static unsigned char *add_mcs(
unsigned char *
bits,
int bitrate,
368 pdev = platform_device_register_simple(
"yam", 0,
NULL, 0);
382 fw->
size, fw_name[predef]);
386 bits = (
unsigned char *)fw->
data;
417 static unsigned char *get_mcs(
int bitrate)
444 static int fpga_download(
int iobase,
int bitrate)
447 unsigned char *pbits;
449 pbits = get_mcs(bitrate);
467 return (rc &
MSR_DSR) ? 0 : -1;
477 struct yam_port *yp = netdev_priv(dev);
506 static const char *uart_str[] =
507 {
"unknown",
"8250",
"16450",
"16550",
"16550A"};
509 static enum uart yam_check_uart(
unsigned int iobase)
511 unsigned char b1, b2, b3;
513 enum uart uart_tab[] =
520 b3 =
inb(
MSR(iobase)) & 0xf0;
528 u = uart_tab[(
inb(
IIR(iobase)) >> 6) & 3];
534 if ((b1 != 0x5a) || (b2 != 0xa5))
552 if (!(skb = dev_alloc_skb(pkt_len))) {
554 ++dev->
stats.rx_dropped;
560 skb->
protocol = ax25_type_trans(skb, dev);
562 ++dev->
stats.rx_packets;
571 static inline void yam_rx_byte(
struct net_device *dev,
struct yam_port *yp,
unsigned char rxb)
598 struct yam_port *yp = netdev_priv(dev);
615 static void yam_arbitrate(
struct net_device *dev)
617 struct yam_port *yp = netdev_priv(dev);
626 yam_start_tx(dev, yp);
644 yam_start_tx(dev, yp);
647 static void yam_dotimer(
unsigned long dummy)
653 if (dev && netif_running(dev))
663 unsigned char b,
temp;
676 if (skb->
data[0] != 0) {
686 skb_copy_from_linear_data_offset(skb, 1,
725 ++dev->
stats.tx_packets;
751 yp = netdev_priv(dev);
753 if (!netif_running(dev))
764 ++dev->
stats.rx_fifo_errors;
768 if (--counter <= 0) {
775 yam_tx_byte(dev, yp);
781 yam_rx_flag(dev, yp);
783 yam_rx_byte(dev, yp, rxb);
791 #ifdef CONFIG_PROC_FS
793 static void *yam_seq_start(
struct seq_file *seq, loff_t *
pos)
795 return (*pos < NR_PORTS) ? yam_devs[*
pos] :
NULL;
798 static void *yam_seq_next(
struct seq_file *seq,
void *
v, loff_t *pos)
801 return (*pos < NR_PORTS) ? yam_devs[*
pos] :
NULL;
804 static void yam_seq_stop(
struct seq_file *seq,
void *v)
808 static int yam_seq_show(
struct seq_file *seq,
void *v)
811 const struct yam_port *yp = netdev_priv(dev);
814 seq_printf(seq,
" Up %d\n", netif_running(dev));
836 .
start = yam_seq_start,
837 .next = yam_seq_next,
838 .stop = yam_seq_stop,
839 .show = yam_seq_show,
849 .open = yam_info_open,
862 struct yam_port *yp = netdev_priv(dev);
872 dev->
irq < 2 || dev->
irq > 15) {
883 goto out_release_base;
888 goto out_release_base;
894 goto out_release_base;
899 netif_start_queue(dev);
908 yam_dev->
stats.rx_fifo_errors = 0;
925 struct yam_port *yp = netdev_priv(dev);
938 netif_stop_queue(dev);
951 struct yam_port *yp = netdev_priv(dev);
974 if (netif_running(dev))
998 if ((yi.cfg.mask &
YAM_IOBASE) && netif_running(dev))
1000 if ((yi.cfg.mask &
YAM_IRQ) && netif_running(dev))
1002 if ((yi.cfg.mask &
YAM_BITRATE) && netif_running(dev))
1004 if ((yi.cfg.mask &
YAM_BAUDRATE) && netif_running(dev))
1008 yp->
iobase = yi.cfg.iobase;
1012 if (yi.cfg.irq > 15)
1014 yp->
irq = yi.cfg.irq;
1015 dev->
irq = yi.cfg.irq;
1035 yp->
holdd = yi.cfg.holddly;
1040 yp->
txd = yi.cfg.txdelay;
1045 yp->
txtail = yi.cfg.txtail;
1050 yp->
pers = yi.cfg.persist;
1055 yp->
slot = yi.cfg.slottime;
1061 yi.cfg.mask = 0xffffffff;
1062 yi.cfg.iobase = yp->
iobase;
1063 yi.cfg.irq = yp->
irq;
1067 yi.cfg.txdelay = yp->
txd;
1068 yi.cfg.holddly = yp->
holdd;
1069 yi.cfg.txtail = yp->
txtail;
1070 yi.cfg.persist = yp->
pers;
1071 yi.cfg.slottime = yp->
slot;
1086 static int yam_set_mac_address(
struct net_device *dev,
void *
addr)
1098 .ndo_open = yam_open,
1099 .ndo_stop = yam_close,
1100 .ndo_start_xmit = yam_send_packet,
1101 .ndo_do_ioctl = yam_ioctl,
1102 .ndo_set_mac_address = yam_set_mac_address,
1105 static void yam_setup(
struct net_device *dev)
1107 struct yam_port *yp = netdev_priv(dev);
1138 static int __init yam_init_driver(
void)
1152 pr_err(
"yam: cannot allocate net device\n");
1166 yam_timer.function = yam_dotimer;
1182 static void __exit yam_cleanup_driver(
void)
1198 yam_data = yam_data->
next;