23 #include <linux/module.h>
24 #include <linux/bitops.h>
26 #include <linux/errno.h>
27 #include <linux/if_arp.h>
32 #include <linux/kernel.h>
34 #include <linux/netdevice.h>
35 #include <linux/slab.h>
36 #include <linux/rtnetlink.h>
43 #include <asm/uaccess.h>
57 #define HW_PI { "Ottawa PI", 0x300, 0x20, 0x10, 8, \
58 0, 8, 1843200, 3686400 }
59 #define HW_PI2 { "Ottawa PI2", 0x300, 0x20, 0x10, 8, \
60 0, 8, 3686400, 7372800 }
61 #define HW_TWIN { "Gracilis PackeTwin", 0x200, 0x10, 0x10, 32, \
62 0, 4, 6144000, 6144000 }
63 #define HW_S5 { "S5SCC/DMA", 0x200, 0x10, 0x10, 32, \
64 0, 8, 4915200, 9830400 }
66 #define HARDWARE { HW_PI, HW_PI2, HW_TWIN, HW_S5 }
68 #define TMR_0_HZ 25600
76 #define MAX_NUM_DEVS 32
85 #define CHIPNAMES { "Z8530", "Z85C30", "Z85230" }
92 #define SCCB_DATA 0x01
94 #define SCCA_DATA 0x03
100 #define TMR_CTRL 0x03
103 #define PI_DREQ_MASK 0x04
106 #define TWIN_INT_REG 0x08
107 #define TWIN_CLR_TMR1 0x09
108 #define TWIN_CLR_TMR2 0x0a
109 #define TWIN_SPARE_1 0x0b
110 #define TWIN_DMA_CFG 0x08
111 #define TWIN_SERIAL_CFG 0x09
112 #define TWIN_DMA_CLR_FF 0x0a
113 #define TWIN_SPARE_2 0x0b
119 #define TWIN_SCC_MSK 0x01
120 #define TWIN_TMR1_MSK 0x02
121 #define TWIN_TMR2_MSK 0x04
122 #define TWIN_INT_MSK 0x07
125 #define TWIN_DTRA_ON 0x01
126 #define TWIN_DTRB_ON 0x02
127 #define TWIN_EXTCLKA 0x04
128 #define TWIN_EXTCLKB 0x08
129 #define TWIN_LOOPA_ON 0x10
130 #define TWIN_LOOPB_ON 0x20
134 #define TWIN_DMA_HDX_T1 0x08
135 #define TWIN_DMA_HDX_R1 0x0a
136 #define TWIN_DMA_HDX_T3 0x14
137 #define TWIN_DMA_HDX_R3 0x16
138 #define TWIN_DMA_FDX_T3R1 0x1b
139 #define TWIN_DMA_FDX_T1R3 0x1d
158 #define SIOCGSCCPARAM SIOCDEVPRIVATE
159 #define SIOCSSCCPARAM (SIOCDEVPRIVATE+1)
232 static int setup_adapter(
int card_base,
int type,
int n)
__init;
249 static inline unsigned char random(
void);
272 static unsigned long rand;
280 static void __exit dmascc_exit(
void)
289 for (i = 0; i < 2; i++)
299 for (i = 0; i < 2; i++)
308 static int __init dmascc_init(
void)
335 if (j >= 0 && j < hw[h].num_devs &&
337 j * hw[h].io_delta == io[i]) {
353 (base[i], hw[h].io_size,
"dmascc"))
392 while (jiffies - time < 13) {
394 if (base[i] && counting[i]) {
398 inb(t1[i]) + (
inb(t1[i]) << 8);
410 if ((delay[i] >= 9 && delay[i] <= 11) &&
412 (setup_adapter(base[i], h, n) == 0))
445 .ndo_open = scc_open,
446 .ndo_stop = scc_close,
447 .ndo_start_xmit = scc_send_packet,
448 .ndo_do_ioctl = scc_ioctl,
449 .ndo_set_mac_address = scc_set_mac_address,
452 static int __init setup_adapter(
int card_base,
int type,
int n)
468 "could not allocate memory for %s at %#3x\n",
469 hw[type].
name, card_base);
477 "could not allocate memory for %s at %#3x\n",
478 hw[type].
name, card_base);
485 "could not allocate memory for %s at %#3x\n",
486 hw[type].
name, card_base);
491 priv = &info->
priv[0];
503 if (!read_scc(priv,
R15)) {
508 write_scc_data(priv, 0, 0);
517 write_scc(priv,
R15, 0);
548 write_scc(priv,
R1, 0);
549 write_scc(priv,
R15, 0);
555 "dmascc: could not find irq of %s at %#3x (irq=%d)\n",
556 hw[type].
name, card_base, irq);
561 for (i = 0; i < 2; i++) {
563 priv = &info->
priv[
i];
578 priv->
param.brg_tc = -1;
580 priv->
param.persist = 256;
581 priv->
param.dma = -1;
605 hw[type].
name, chipnames[chip], card_base, irq);
629 switch (priv->
type) {
653 static void write_scc_data(
struct scc_priv *priv,
int val,
int fast)
656 switch (priv->
type) {
678 static int read_scc(
struct scc_priv *priv,
int reg)
682 switch (priv->
type) {
704 static int read_scc_data(
struct scc_priv *priv)
708 switch (priv->
type) {
739 if (priv->
param.dma >= 0) {
746 clear_dma_ff(priv->
param.dma);
766 write_scc(priv,
R3,
Rx8);
768 write_scc(priv,
R5,
Tx8);
770 write_scc(priv,
R6, 0);
772 write_scc(priv,
R7,
FLAG);
773 switch (priv->
chip) {
779 write_scc(priv,
R15, 0);
803 if (priv->
param.dma >= 0) {
811 write_scc(priv,
R15, 0);
818 if (priv->
param.brg_tc >= 0) {
820 write_scc(priv,
R12, priv->
param.brg_tc & 0xFF);
821 write_scc(priv,
R13, (priv->
param.brg_tc >> 8) & 0xFF);
839 write_scc(priv,
R11, priv->
param.clocks);
856 priv->
rr0 = read_scc(priv,
R0);
860 netif_start_queue(dev);
872 netif_stop_queue(dev);
883 if (priv->
param.dma >= 0) {
902 (ifr->ifr_data, &priv->
param,
909 if (netif_running(dev))
912 (&priv->
param, ifr->ifr_data,
929 netif_stop_queue(dev);
933 skb_copy_from_linear_data_offset(skb, 1, priv->
tx_buf[i], skb->
len - 1);
947 netif_wake_queue(dev);
955 write_scc(priv,
R15, 0);
956 start_timer(priv, priv->
param.txdelay, 0);
960 spin_unlock_irqrestore(&priv->
ring_lock, flags);
967 static int scc_set_mac_address(
struct net_device *dev,
void *
sa)
975 static inline void tx_on(
struct scc_priv *priv)
980 if (priv->
param.dma >= 0) {
985 set_dma_addr(priv->
param.dma,
1003 for (i = 0; i <
n; i++)
1004 write_scc_data(priv,
1020 static inline void rx_on(
struct scc_priv *priv)
1022 unsigned long flags;
1026 read_scc_data(priv);
1028 if (priv->
param.dma >= 0) {
1032 set_dma_addr(priv->
param.dma,
1058 static inline void rx_off(
struct scc_priv *priv)
1061 write_scc(priv,
R3,
Rx8);
1068 if (priv->
param.dma >= 0)
1073 static void start_timer(
struct scc_priv *priv,
int t,
int r15)
1089 static inline unsigned char random(
void)
1092 rand = rand * 1664525
L + 1013904223
L;
1093 return (
unsigned char) (rand >> 24);
1096 static inline void z8530_isr(
struct scc_info *info)
1100 while ((is = read_scc(&info->
priv[0],
R3)) && i--) {
1102 rx_isr(&info->
priv[0]);
1104 tx_isr(&info->
priv[0]);
1105 }
else if (is &
CHAEXT) {
1106 es_isr(&info->
priv[0]);
1108 rx_isr(&info->
priv[1]);
1110 tx_isr(&info->
priv[1]);
1112 es_isr(&info->
priv[1]);
1130 spin_lock(info->
priv[0].register_lock);
1144 int is, card_base = info->
priv[0].card_base;
1151 tm_isr(&info->
priv[0]);
1154 tm_isr(&info->
priv[1]);
1159 spin_unlock(info->
priv[0].register_lock);
1164 static void rx_isr(
struct scc_priv *priv)
1166 if (priv->
param.dma >= 0) {
1168 special_condition(priv, read_scc(priv,
R1));
1174 while (read_scc(priv,
R0) & Rx_CH_AV) {
1175 rc = read_scc(priv,
R1);
1179 read_scc_data(priv);
1182 read_scc_data(priv);
1184 special_condition(priv, rc);
1190 static void special_condition(
struct scc_priv *priv,
int rc)
1193 unsigned long flags;
1200 if (priv->
param.dma < 0)
1202 }
else if (rc &
END_FR) {
1204 if (priv->
param.dma >= 0) {
1214 priv->
dev->stats.rx_errors++;
1216 priv->
dev->stats.rx_length_errors++;
1218 priv->
dev->stats.rx_fifo_errors++;
1223 priv->
dev->stats.rx_errors++;
1224 priv->
dev->stats.rx_crc_errors++;
1237 priv->
dev->stats.rx_errors++;
1238 priv->
dev->stats.rx_over_errors++;
1243 if (priv->
param.dma >= 0) {
1245 set_dma_addr(priv->
param.dma,
1261 unsigned long flags;
1263 unsigned char *
data;
1267 spin_unlock_irqrestore(&priv->
ring_lock, flags);
1270 skb = dev_alloc_skb(cb + 1);
1273 priv->
dev->stats.rx_dropped++;
1281 priv->
dev->stats.rx_packets++;
1282 priv->
dev->stats.rx_bytes += cb;
1289 spin_unlock_irqrestore(&priv->
ring_lock, flags);
1293 static void tx_isr(
struct scc_priv *priv)
1305 while ((read_scc(priv,
R0) &
Tx_BUF_EMP) && p < priv->tx_len[i]) {
1306 write_scc_data(priv, priv->
tx_buf[i][
p++], 0);
1317 static void es_isr(
struct scc_priv *priv)
1319 int i, rr0, drr0,
res;
1320 unsigned long flags;
1323 rr0 = read_scc(priv,
R0);
1325 drr0 = priv->
rr0 ^ rr0;
1333 if (priv->
param.dma >= 0) {
1349 priv->
dev->stats.tx_errors++;
1350 priv->
dev->stats.tx_fifo_errors++;
1356 priv->
dev->stats.tx_packets++;
1357 priv->
dev->stats.tx_bytes += priv->
tx_len[
i];
1362 netif_wake_queue(priv->
dev);
1365 write_scc(priv,
R15, 0);
1369 start_timer(priv, priv->
param.txpause, 0);
1372 start_timer(priv, priv->
param.txtail, 0);
1379 switch (priv->
state) {
1383 write_scc(priv,
R15, 0);
1384 start_timer(priv, priv->
param.dcdon, 0);
1387 switch (priv->
state) {
1391 write_scc(priv,
R15, 0);
1392 start_timer(priv, priv->
param.dcdoff, 0);
1404 static void tm_isr(
struct scc_priv *priv)
1406 switch (priv->
state) {
1416 write_scc(priv,
R15, 0);
1417 start_timer(priv, priv->
param.rtsoff, 0);
1421 priv->
rr0 = read_scc(priv,
R0);
1422 if (priv->
rr0 & DCD) {
1423 priv->
dev->stats.collisions++;
1428 start_timer(priv, priv->
param.waittime,
DCDIE);
1437 write_scc(priv,
R15, 0);
1438 start_timer(priv, priv->
param.txdelay, 0);
1448 priv->
rr0 = read_scc(priv,
R0);
1449 if (priv->
rr0 & DCD) {
1455 random() / priv->
param.persist *