20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/fcntl.h>
27 #include <linux/ptrace.h>
29 #include <linux/nubus.h>
31 #include <linux/string.h>
32 #include <linux/errno.h>
34 #include <linux/netdevice.h>
37 #include <linux/bitops.h>
47 #define EI_SHIFT(x) (ei_local->reg_offset[x])
48 #define ei_inb(port) in_8(port)
49 #define ei_outb(val, port) out_8(port, val)
50 #define ei_inb_p(port) in_8(port)
51 #define ei_outb_p(val, port) out_8(port, val)
55 #define WD_START_PG 0x00
56 #define CABLETRON_RX_START_PG 0x00
57 #define CABLETRON_RX_STOP_PG 0x30
58 #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG
68 #define DAYNA_8390_BASE 0x80000
69 #define DAYNA_8390_MEM 0x00000
71 #define CABLETRON_8390_BASE 0x90000
72 #define CABLETRON_8390_MEM 0x00000
74 #define INTERLAN_8390_BASE 0xE0000
75 #define INTERLAN_8390_MEM 0xD0000
88 static const char *cardname[] = {
98 static const int word16[] = {
109 static const int useresources[] = {
140 const unsigned char *
buf,
const int start_page);
143 static void dayna_memcpy_fromcard(
struct net_device *
dev,
void *to,
145 static void dayna_memcpy_tocard(
struct net_device *
dev,
int to,
154 const unsigned char *
buf,
int start_page);
156 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
157 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
159 #define memcmp_withio(a, b, c) memcmp((a), (void *)(b), (c))
167 const unsigned char *
buf,
int start_page);
168 static void word_memcpy_tocard(
unsigned long tp,
const void *
fp,
int count);
169 static void word_memcpy_fromcard(
void *tp,
unsigned long fp,
int count);
173 switch (dev->
dr_sw) {
175 switch (dev->
dr_hw) {
188 switch (dev->
dr_hw) {
219 switch (dev->
dr_hw) {
246 unsigned long outdata = 0xA5A0B5B0;
247 unsigned long indata = 0x00000000;
254 word_memcpy_tocard(membase, &outdata, 4);
256 word_memcpy_fromcard(&indata, membase, 4);
257 if (outdata == indata)
262 static int __init mac8390_memsize(
unsigned long membase)
269 for (i = 0; i < 8; i++) {
270 volatile unsigned short *
m = (
unsigned short *)(membase + (i * 0x1000));
280 if (*m != (0xA5A0 | i))
284 for (j = 0; j <
i; j++) {
285 volatile unsigned short *
p = (
unsigned short *)(membase + (j * 0x1000));
286 if (*p != (0xA5A0 | j))
304 volatile unsigned short *
i;
311 ((ndev->
board->slot & 0xf) << 20));
319 pr_err(
"%s: Unable to get Nubus functional directory for slot %X!\n",
326 pr_info(
"%s: Couldn't get MAC address!\n", dev->
name);
332 if (useresources[cardtype] == 1) {
336 pr_err(
"%s: Memory offset resource for slot %X not found!\n",
347 pr_info(
"%s: Memory length resource for slot %X not found, probing\n",
349 offset = mac8390_memsize(dev->
mem_start);
391 pr_err(
"Card type %s is unsupported, sorry\n",
406 static unsigned int slots;
425 if (slots & (1 << ndev->
board->slot))
427 slots |= 1 << ndev->
board->slot;
429 cardtype = mac8390_ident(ndev);
433 if (!mac8390_init(dev, ndev, cardtype))
437 if (!mac8390_initdev(dev, ndev, cardtype))
463 for (i = 0; i < 15; i++) {
470 pr_notice(
"No useable cards found, driver NOT installed.\n");
479 for (i = 0; i < 15; i++) {
491 .ndo_open = mac8390_open,
492 .ndo_stop = mac8390_close,
500 #ifdef CONFIG_NET_POLL_CONTROLLER
509 static u32 fwrd4_offsets[16] = {
515 static u32 back4_offsets[16] = {
521 static u32 fwrd2_offsets[16] = {
528 int access_bitmode = 0;
556 switch (mac8390_testio(dev->
mem_start)) {
558 pr_err(
"Don't know how to access card memory!\n");
565 ei_status.block_input = slow_sane_block_input;
566 ei_status.block_output = slow_sane_block_output;
567 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
574 ei_status.block_input = sane_block_input;
575 ei_status.block_output = sane_block_output;
576 ei_status.get_8390_hdr = sane_get_8390_hdr;
589 ei_status.block_input = slow_sane_block_input;
590 ei_status.block_output = slow_sane_block_output;
591 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
598 ei_status.block_input = slow_sane_block_input;
599 ei_status.block_output = slow_sane_block_output;
600 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
609 ei_status.block_input = dayna_block_input;
610 ei_status.block_output = dayna_block_output;
611 ei_status.get_8390_hdr = dayna_get_8390_hdr;
618 ei_status.block_input = slow_sane_block_input;
619 ei_status.block_output = slow_sane_block_output;
620 ei_status.get_8390_hdr = slow_sane_get_8390_hdr;
625 pr_err(
"Card type %s is unsupported, sorry\n",
633 pr_info(
"%s: %s in slot %X (type %s)\n",
636 pr_info(
"MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
639 dev->
mem_start, access_bitmode ? 32 : 16);
643 static int mac8390_open(
struct net_device *dev)
654 static int mac8390_close(
struct net_device *dev)
661 static void mac8390_no_reset(
struct net_device *dev)
665 pr_info(
"reset not supported\n");
668 static void interlan_reset(
struct net_device *dev)
672 pr_info(
"Need to reset the NS8390 t=%lu...", jiffies);
681 static void dayna_memcpy_fromcard(
struct net_device *dev,
void *to,
int from,
684 volatile unsigned char *
ptr;
685 unsigned char *target = to;
687 ptr = (
unsigned char *)(dev->
mem_start+from);
695 *(
unsigned short *)target = *(
unsigned short volatile *)
ptr;
705 static void dayna_memcpy_tocard(
struct net_device *dev,
int to,
706 const void *from,
int count)
708 volatile unsigned short *
ptr;
709 const unsigned char *
src =
from;
711 ptr = (
unsigned short *)(dev->
mem_start+to);
714 ptr[-1] = (ptr[-1]&0xFF00)|*src++;
719 *ptr++ = *(
unsigned short *)src;
727 *ptr = (*ptr & 0x00FF) | (*src << 8);
732 static void sane_get_8390_hdr(
struct net_device *dev,
735 unsigned long hdr_start = (ring_page -
WD_START_PG)<<8;
741 static void sane_block_input(
struct net_device *dev,
int count,
744 unsigned long xfer_base = ring_offset - (
WD_START_PG<<8);
745 unsigned long xfer_start = xfer_base + dev->
mem_start;
747 if (xfer_start + count >
ei_status.rmem_end) {
749 int semi_count =
ei_status.rmem_end - xfer_start;
760 static void sane_block_output(
struct net_device *dev,
int count,
761 const unsigned char *
buf,
int start_page)
769 static void dayna_get_8390_hdr(
struct net_device *dev,
772 unsigned long hdr_start = (ring_page -
WD_START_PG)<<8;
774 dayna_memcpy_fromcard(dev, hdr, hdr_start, 4);
779 static void dayna_block_input(
struct net_device *dev,
int count,
780 struct sk_buff *skb,
int ring_offset)
782 unsigned long xfer_base = ring_offset - (
WD_START_PG<<8);
783 unsigned long xfer_start = xfer_base+dev->
mem_start;
788 if (xfer_start + count >
ei_status.rmem_end) {
790 int semi_count =
ei_status.rmem_end - xfer_start;
791 dayna_memcpy_fromcard(dev, skb->
data, xfer_base, semi_count);
793 dayna_memcpy_fromcard(dev, skb->
data + semi_count,
797 dayna_memcpy_fromcard(dev, skb->
data, xfer_base, count);
801 static void dayna_block_output(
struct net_device *dev,
int count,
802 const unsigned char *
buf,
807 dayna_memcpy_tocard(dev, shmem, buf, count);
811 static void slow_sane_get_8390_hdr(
struct net_device *dev,
815 unsigned long hdr_start = (ring_page -
WD_START_PG)<<8;
816 word_memcpy_fromcard(hdr, dev->
mem_start + hdr_start, 4);
821 static void slow_sane_block_input(
struct net_device *dev,
int count,
822 struct sk_buff *skb,
int ring_offset)
824 unsigned long xfer_base = ring_offset - (
WD_START_PG<<8);
825 unsigned long xfer_start = xfer_base+dev->
mem_start;
827 if (xfer_start + count >
ei_status.rmem_end) {
829 int semi_count =
ei_status.rmem_end - xfer_start;
833 word_memcpy_fromcard(skb->
data + semi_count,
841 static void slow_sane_block_output(
struct net_device *dev,
int count,
842 const unsigned char *
buf,
int start_page)
846 word_memcpy_tocard(dev->
mem_start + shmem, buf, count);
849 static void word_memcpy_tocard(
unsigned long tp,
const void *
fp,
int count)
851 volatile unsigned short *to = (
void *)tp;
852 const unsigned short *from =
fp;
861 static void word_memcpy_fromcard(
void *tp,
unsigned long fp,
int count)
863 unsigned short *to = tp;
864 const volatile unsigned short *from = (
const void *)fp;