2 * tmspci.c: A generic network driver for TMS380-based PCI token ring cards.
4 * Written 1999 by Adam Fritzler
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
9 * This driver module supports the following cards:
10 * - SysKonnect TR4/16(+) PCI (SK-4590)
11 * - SysKonnect TR4/16 PCI (SK-4591)
12 * - Compaq TR 4/16 PCI
13 * - Thomas-Conrad TC4048 4/16 PCI
14 * - 3Com 3C339 Token Link Velocity
19 * Modification History:
20 * 30-Dec-99 AF Split off from the tms380tr driver.
21 * 22-Jan-00 AF Updated to use indirect read/writes
22 * 23-Nov-00 JG New PCI API, cleanups
25 * 1. See if we can use MMIO instead of port accesses
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/pci.h>
33 #include <linux/init.h>
34 #include <linux/netdevice.h>
35 #include <linux/trdevice.h>
37 #include <asm/system.h>
43 static char version
[] __devinitdata
=
44 "tmspci.c: v1.02 23/11/2000 by Adam Fritzler\n";
46 #define TMS_PCI_IO_EXTENT 32
49 unsigned char nselout
[2]; /* NSELOUT vals for 4mb([0]) and 16mb([1]) */
53 static struct card_info card_info_table
[] = {
54 { {0x03, 0x01}, "Compaq 4/16 TR PCI"},
55 { {0x03, 0x01}, "SK NET TR 4/16 PCI"},
56 { {0x03, 0x01}, "Thomas-Conrad TC4048 PCI 4/16"},
57 { {0x03, 0x01}, "3Com Token Link Velocity"},
60 static struct pci_device_id tmspci_pci_tbl
[] = {
61 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_TOKENRING
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
62 { PCI_VENDOR_ID_SYSKONNECT
, PCI_DEVICE_ID_SYSKONNECT_TR
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
63 { PCI_VENDOR_ID_TCONRAD
, PCI_DEVICE_ID_TCONRAD_TOKENRING
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2 },
64 { PCI_VENDOR_ID_3COM
, PCI_DEVICE_ID_3COM_3C339
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3 },
65 { } /* Terminating entry */
67 MODULE_DEVICE_TABLE(pci
, tmspci_pci_tbl
);
69 MODULE_LICENSE("GPL");
71 static void tms_pci_read_eeprom(struct net_device
*dev
);
72 static unsigned short tms_pci_setnselout_pins(struct net_device
*dev
);
74 static unsigned short tms_pci_sifreadb(struct net_device
*dev
, unsigned short reg
)
76 return inb(dev
->base_addr
+ reg
);
79 static unsigned short tms_pci_sifreadw(struct net_device
*dev
, unsigned short reg
)
81 return inw(dev
->base_addr
+ reg
);
84 static void tms_pci_sifwriteb(struct net_device
*dev
, unsigned short val
, unsigned short reg
)
86 outb(val
, dev
->base_addr
+ reg
);
89 static void tms_pci_sifwritew(struct net_device
*dev
, unsigned short val
, unsigned short reg
)
91 outw(val
, dev
->base_addr
+ reg
);
94 static int __devinit
tms_pci_attach(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
96 static int versionprinted
;
97 struct net_device
*dev
;
100 unsigned int pci_irq_line
;
101 unsigned long pci_ioaddr
;
102 struct card_info
*cardinfo
= &card_info_table
[ent
->driver_data
];
103 DECLARE_MAC_BUF(mac
);
105 if (versionprinted
++ == 0)
106 printk("%s", version
);
108 if (pci_enable_device(pdev
))
111 /* Remove I/O space marker in bit 0. */
112 pci_irq_line
= pdev
->irq
;
113 pci_ioaddr
= pci_resource_start (pdev
, 0);
115 /* At this point we have found a valid card. */
116 dev
= alloc_trdev(sizeof(struct net_local
));
120 if (!request_region(pci_ioaddr
, TMS_PCI_IO_EXTENT
, dev
->name
)) {
125 ret
= request_irq(pdev
->irq
, tms380tr_interrupt
, IRQF_SHARED
,
130 dev
->base_addr
= pci_ioaddr
;
131 dev
->irq
= pci_irq_line
;
134 printk("%s: %s\n", dev
->name
, cardinfo
->name
);
135 printk("%s: IO: %#4lx IRQ: %d\n",
136 dev
->name
, dev
->base_addr
, dev
->irq
);
138 tms_pci_read_eeprom(dev
);
140 printk("%s: Ring Station Address: %s\n",
141 dev
->name
, print_mac(mac
, dev
->dev_addr
));
143 ret
= tmsdev_init(dev
, &pdev
->dev
);
145 printk("%s: unable to get memory for dev->priv.\n", dev
->name
);
149 tp
= netdev_priv(dev
);
150 tp
->setnselout
= tms_pci_setnselout_pins
;
152 tp
->sifreadb
= tms_pci_sifreadb
;
153 tp
->sifreadw
= tms_pci_sifreadw
;
154 tp
->sifwriteb
= tms_pci_sifwriteb
;
155 tp
->sifwritew
= tms_pci_sifwritew
;
157 memcpy(tp
->ProductID
, cardinfo
->name
, PROD_ID_SIZE
+ 1);
159 tp
->tmspriv
= cardinfo
;
161 dev
->open
= tms380tr_open
;
162 dev
->stop
= tms380tr_close
;
163 pci_set_drvdata(pdev
, dev
);
164 SET_NETDEV_DEV(dev
, &pdev
->dev
);
166 ret
= register_netdev(dev
);
173 pci_set_drvdata(pdev
, NULL
);
176 free_irq(pdev
->irq
, dev
);
178 release_region(pci_ioaddr
, TMS_PCI_IO_EXTENT
);
185 * Reads MAC address from adapter RAM, which should've read it from
188 * Calling this on a board that does not support it can be a very
189 * dangerous thing. The Madge board, for instance, will lock your
190 * machine hard when this is called. Luckily, its supported in a
191 * separate driver. --ASF
193 static void tms_pci_read_eeprom(struct net_device
*dev
)
197 /* Address: 0000:0000 */
198 tms_pci_sifwritew(dev
, 0, SIFADX
);
199 tms_pci_sifwritew(dev
, 0, SIFADR
);
201 /* Read six byte MAC address data */
203 for(i
= 0; i
< 6; i
++)
204 dev
->dev_addr
[i
] = tms_pci_sifreadw(dev
, SIFINC
) >> 8;
207 static unsigned short tms_pci_setnselout_pins(struct net_device
*dev
)
209 unsigned short val
= 0;
210 struct net_local
*tp
= netdev_priv(dev
);
211 struct card_info
*cardinfo
= tp
->tmspriv
;
213 if(tp
->DataRate
== SPEED_4
)
214 val
|= cardinfo
->nselout
[0]; /* Set 4Mbps */
216 val
|= cardinfo
->nselout
[1]; /* Set 16Mbps */
220 static void __devexit
tms_pci_detach (struct pci_dev
*pdev
)
222 struct net_device
*dev
= pci_get_drvdata(pdev
);
225 unregister_netdev(dev
);
226 release_region(dev
->base_addr
, TMS_PCI_IO_EXTENT
);
227 free_irq(dev
->irq
, dev
);
230 pci_set_drvdata(pdev
, NULL
);
233 static struct pci_driver tms_pci_driver
= {
235 .id_table
= tmspci_pci_tbl
,
236 .probe
= tms_pci_attach
,
237 .remove
= __devexit_p(tms_pci_detach
),
240 static int __init
tms_pci_init (void)
242 return pci_register_driver(&tms_pci_driver
);
245 static void __exit
tms_pci_rmmod (void)
247 pci_unregister_driver (&tms_pci_driver
);
250 module_init(tms_pci_init
);
251 module_exit(tms_pci_rmmod
);