Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.4 248 lines 6.3 kB view raw
1/* 2 * tmspci.c: A generic network driver for TMS380-based PCI token ring cards. 3 * 4 * Written 1999 by Adam Fritzler 5 * 6 * This software may be used and distributed according to the terms 7 * of the GNU General Public License, incorporated herein by reference. 8 * 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 15 * 16 * Maintainer(s): 17 * AF Adam Fritzler 18 * 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 23 * 24 * TODO: 25 * 1. See if we can use MMIO instead of port accesses 26 * 27 */ 28 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> 36 37#include <asm/io.h> 38#include <asm/irq.h> 39 40#include "tms380tr.h" 41 42static char version[] __devinitdata = 43"tmspci.c: v1.02 23/11/2000 by Adam Fritzler\n"; 44 45#define TMS_PCI_IO_EXTENT 32 46 47struct card_info { 48 unsigned char nselout[2]; /* NSELOUT vals for 4mb([0]) and 16mb([1]) */ 49 char *name; 50}; 51 52static struct card_info card_info_table[] = { 53 { {0x03, 0x01}, "Compaq 4/16 TR PCI"}, 54 { {0x03, 0x01}, "SK NET TR 4/16 PCI"}, 55 { {0x03, 0x01}, "Thomas-Conrad TC4048 PCI 4/16"}, 56 { {0x03, 0x01}, "3Com Token Link Velocity"}, 57}; 58 59static DEFINE_PCI_DEVICE_TABLE(tmspci_pci_tbl) = { 60 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TOKENRING, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 61 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_TR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, 62 { PCI_VENDOR_ID_TCONRAD, PCI_DEVICE_ID_TCONRAD_TOKENRING, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, 63 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C339, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, 64 { } /* Terminating entry */ 65}; 66MODULE_DEVICE_TABLE(pci, tmspci_pci_tbl); 67 68MODULE_LICENSE("GPL"); 69 70static void tms_pci_read_eeprom(struct net_device *dev); 71static unsigned short tms_pci_setnselout_pins(struct net_device *dev); 72 73static unsigned short tms_pci_sifreadb(struct net_device *dev, unsigned short reg) 74{ 75 return inb(dev->base_addr + reg); 76} 77 78static unsigned short tms_pci_sifreadw(struct net_device *dev, unsigned short reg) 79{ 80 return inw(dev->base_addr + reg); 81} 82 83static void tms_pci_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg) 84{ 85 outb(val, dev->base_addr + reg); 86} 87 88static void tms_pci_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg) 89{ 90 outw(val, dev->base_addr + reg); 91} 92 93static int __devinit tms_pci_attach(struct pci_dev *pdev, const struct pci_device_id *ent) 94{ 95 static int versionprinted; 96 struct net_device *dev; 97 struct net_local *tp; 98 int ret; 99 unsigned int pci_irq_line; 100 unsigned long pci_ioaddr; 101 struct card_info *cardinfo = &card_info_table[ent->driver_data]; 102 103 if (versionprinted++ == 0) 104 printk("%s", version); 105 106 if (pci_enable_device(pdev)) 107 return -EIO; 108 109 /* Remove I/O space marker in bit 0. */ 110 pci_irq_line = pdev->irq; 111 pci_ioaddr = pci_resource_start (pdev, 0); 112 113 /* At this point we have found a valid card. */ 114 dev = alloc_trdev(sizeof(struct net_local)); 115 if (!dev) 116 return -ENOMEM; 117 118 if (!request_region(pci_ioaddr, TMS_PCI_IO_EXTENT, dev->name)) { 119 ret = -EBUSY; 120 goto err_out_trdev; 121 } 122 123 dev->base_addr = pci_ioaddr; 124 dev->irq = pci_irq_line; 125 dev->dma = 0; 126 127 dev_info(&pdev->dev, "%s\n", cardinfo->name); 128 dev_info(&pdev->dev, " IO: %#4lx IRQ: %d\n", dev->base_addr, dev->irq); 129 130 tms_pci_read_eeprom(dev); 131 132 dev_info(&pdev->dev, " Ring Station Address: %pM\n", dev->dev_addr); 133 134 ret = tmsdev_init(dev, &pdev->dev); 135 if (ret) { 136 dev_info(&pdev->dev, "unable to get memory for dev->priv.\n"); 137 goto err_out_region; 138 } 139 140 tp = netdev_priv(dev); 141 tp->setnselout = tms_pci_setnselout_pins; 142 143 tp->sifreadb = tms_pci_sifreadb; 144 tp->sifreadw = tms_pci_sifreadw; 145 tp->sifwriteb = tms_pci_sifwriteb; 146 tp->sifwritew = tms_pci_sifwritew; 147 148 memcpy(tp->ProductID, cardinfo->name, PROD_ID_SIZE + 1); 149 150 tp->tmspriv = cardinfo; 151 152 dev->netdev_ops = &tms380tr_netdev_ops; 153 154 ret = request_irq(pdev->irq, tms380tr_interrupt, IRQF_SHARED, 155 dev->name, dev); 156 if (ret) 157 goto err_out_tmsdev; 158 159 pci_set_drvdata(pdev, dev); 160 SET_NETDEV_DEV(dev, &pdev->dev); 161 162 ret = register_netdev(dev); 163 if (ret) 164 goto err_out_irq; 165 166 return 0; 167 168err_out_irq: 169 free_irq(pdev->irq, dev); 170err_out_tmsdev: 171 pci_set_drvdata(pdev, NULL); 172 tmsdev_term(dev); 173err_out_region: 174 release_region(pci_ioaddr, TMS_PCI_IO_EXTENT); 175err_out_trdev: 176 free_netdev(dev); 177 return ret; 178} 179 180/* 181 * Reads MAC address from adapter RAM, which should've read it from 182 * the onboard ROM. 183 * 184 * Calling this on a board that does not support it can be a very 185 * dangerous thing. The Madge board, for instance, will lock your 186 * machine hard when this is called. Luckily, its supported in a 187 * separate driver. --ASF 188 */ 189static void tms_pci_read_eeprom(struct net_device *dev) 190{ 191 int i; 192 193 /* Address: 0000:0000 */ 194 tms_pci_sifwritew(dev, 0, SIFADX); 195 tms_pci_sifwritew(dev, 0, SIFADR); 196 197 /* Read six byte MAC address data */ 198 dev->addr_len = 6; 199 for(i = 0; i < 6; i++) 200 dev->dev_addr[i] = tms_pci_sifreadw(dev, SIFINC) >> 8; 201} 202 203static unsigned short tms_pci_setnselout_pins(struct net_device *dev) 204{ 205 unsigned short val = 0; 206 struct net_local *tp = netdev_priv(dev); 207 struct card_info *cardinfo = tp->tmspriv; 208 209 if(tp->DataRate == SPEED_4) 210 val |= cardinfo->nselout[0]; /* Set 4Mbps */ 211 else 212 val |= cardinfo->nselout[1]; /* Set 16Mbps */ 213 return val; 214} 215 216static void __devexit tms_pci_detach (struct pci_dev *pdev) 217{ 218 struct net_device *dev = pci_get_drvdata(pdev); 219 220 BUG_ON(!dev); 221 unregister_netdev(dev); 222 release_region(dev->base_addr, TMS_PCI_IO_EXTENT); 223 free_irq(dev->irq, dev); 224 tmsdev_term(dev); 225 free_netdev(dev); 226 pci_set_drvdata(pdev, NULL); 227} 228 229static struct pci_driver tms_pci_driver = { 230 .name = "tmspci", 231 .id_table = tmspci_pci_tbl, 232 .probe = tms_pci_attach, 233 .remove = __devexit_p(tms_pci_detach), 234}; 235 236static int __init tms_pci_init (void) 237{ 238 return pci_register_driver(&tms_pci_driver); 239} 240 241static void __exit tms_pci_rmmod (void) 242{ 243 pci_unregister_driver (&tms_pci_driver); 244} 245 246module_init(tms_pci_init); 247module_exit(tms_pci_rmmod); 248