More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / hp100.c
blobc8f1751d0ebfa860ac08f981d6ec7c169a2ddff3
1 /*
2 ** hp100.c
3 ** HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters
4 **
5 ** $Id: hp100.c,v 1.58 2001/09/24 18:03:01 perex Exp perex $
6 **
7 ** Based on the HP100 driver written by Jaroslav Kysela <perex@jcu.cz>
8 ** Extended for new busmaster capable chipsets by
9 ** Siegfried "Frieder" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>
11 ** Maintained by: Jaroslav Kysela <perex@suse.cz>
12 **
13 ** This driver has only been tested with
14 ** -- HP J2585B 10/100 Mbit/s PCI Busmaster
15 ** -- HP J2585A 10/100 Mbit/s PCI
16 ** -- HP J2970 10 Mbit/s PCI Combo 10base-T/BNC
17 ** -- HP J2973 10 Mbit/s PCI 10base-T
18 ** -- HP J2573 10/100 ISA
19 ** -- Compex ReadyLink ENET100-VG4 10/100 Mbit/s PCI / EISA
20 ** -- Compex FreedomLine 100/VG 10/100 Mbit/s ISA / EISA / PCI
21 **
22 ** but it should also work with the other CASCADE based adapters.
24 ** TODO:
25 ** - J2573 seems to hang sometimes when in shared memory mode.
26 ** - Mode for Priority TX
27 ** - Check PCI registers, performance might be improved?
28 ** - To reduce interrupt load in busmaster, one could switch off
29 ** the interrupts that are used to refill the queues whenever the
30 ** queues are filled up to more than a certain threshold.
31 ** - some updates for EISA version of card
34 ** This code is free software; you can redistribute it and/or modify
35 ** it under the terms of the GNU General Public License as published by
36 ** the Free Software Foundation; either version 2 of the License, or
37 ** (at your option) any later version.
39 ** This code is distributed in the hope that it will be useful,
40 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
41 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 ** GNU General Public License for more details.
44 ** You should have received a copy of the GNU General Public License
45 ** along with this program; if not, write to the Free Software
46 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48 ** 1.57c -> 1.58
49 ** - used indent to change coding-style
50 ** - added KTI DP-200 EISA ID
51 ** - ioremap is also used for low (<1MB) memory (multi-architecture support)
53 ** 1.57b -> 1.57c - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
54 ** - release resources on failure in init_module
56 ** 1.57 -> 1.57b - Jean II
57 ** - fix spinlocks, SMP is now working !
59 ** 1.56 -> 1.57
60 ** - updates for new PCI interface for 2.1 kernels
62 ** 1.55 -> 1.56
63 ** - removed printk in misc. interrupt and update statistics to allow
64 ** monitoring of card status
65 ** - timing changes in xmit routines, relogin to 100VG hub added when
66 ** driver does reset
67 ** - included fix for Compex FreedomLine PCI adapter
68 **
69 ** 1.54 -> 1.55
70 ** - fixed bad initialization in init_module
71 ** - added Compex FreedomLine adapter
72 ** - some fixes in card initialization
74 ** 1.53 -> 1.54
75 ** - added hardware multicast filter support (doesn't work)
76 ** - little changes in hp100_sense_lan routine
77 ** - added support for Coax and AUI (J2970)
78 ** - fix for multiple cards and hp100_mode parameter (insmod)
79 ** - fix for shared IRQ
81 ** 1.52 -> 1.53
82 ** - fixed bug in multicast support
86 #define HP100_DEFAULT_PRIORITY_TX 0
88 #undef HP100_DEBUG
89 #undef HP100_DEBUG_B /* Trace */
90 #undef HP100_DEBUG_BM /* Debug busmaster code (PDL stuff) */
92 #undef HP100_DEBUG_TRAINING /* Debug login-to-hub procedure */
93 #undef HP100_DEBUG_TX
94 #undef HP100_DEBUG_IRQ
95 #undef HP100_DEBUG_RX
97 #undef HP100_MULTICAST_FILTER /* Need to be debugged... */
99 #include <linux/version.h>
100 #include <linux/module.h>
101 #include <linux/kernel.h>
102 #include <linux/string.h>
103 #include <linux/errno.h>
104 #include <linux/ioport.h>
105 #include <linux/slab.h>
106 #include <linux/interrupt.h>
107 #include <linux/pci.h>
108 #include <linux/spinlock.h>
109 #include <linux/netdevice.h>
110 #include <linux/etherdevice.h>
111 #include <linux/skbuff.h>
112 #include <linux/types.h>
113 #include <linux/config.h> /* for CONFIG_PCI */
114 #include <linux/delay.h>
115 #include <linux/init.h>
117 #include <asm/bitops.h>
118 #include <asm/io.h>
120 typedef struct net_device_stats hp100_stats_t;
122 #include "hp100.h"
125 * defines
128 #define HP100_BUS_ISA 0
129 #define HP100_BUS_EISA 1
130 #define HP100_BUS_PCI 2
132 #ifndef PCI_DEVICE_ID_HP_J2585B
133 #define PCI_DEVICE_ID_HP_J2585B 0x1031
134 #endif
135 #ifndef PCI_VENDOR_ID_COMPEX
136 #define PCI_VENDOR_ID_COMPEX 0x11f6
137 #endif
138 #ifndef PCI_DEVICE_ID_COMPEX_ENET100VG4
139 #define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112
140 #endif
141 #ifndef PCI_VENDOR_ID_COMPEX2
142 #define PCI_VENDOR_ID_COMPEX2 0x101a
143 #endif
144 #ifndef PCI_DEVICE_ID_COMPEX2_100VG
145 #define PCI_DEVICE_ID_COMPEX2_100VG 0x0005
146 #endif
148 #define HP100_REGION_SIZE 0x20 /* for ioports */
150 #define HP100_MAX_PACKET_SIZE (1536+4)
151 #define HP100_MIN_PACKET_SIZE 60
153 #ifndef HP100_DEFAULT_RX_RATIO
154 /* default - 75% onboard memory on the card are used for RX packets */
155 #define HP100_DEFAULT_RX_RATIO 75
156 #endif
158 #ifndef HP100_DEFAULT_PRIORITY_TX
159 /* default - don't enable transmit outgoing packets as priority */
160 #define HP100_DEFAULT_PRIORITY_TX 0
161 #endif
164 * structures
167 struct hp100_eisa_id {
168 u_int id;
169 const char *name;
170 u_char bus;
173 struct hp100_pci_id {
174 u_short vendor;
175 u_short device;
178 struct hp100_private {
179 struct hp100_eisa_id *id;
180 spinlock_t lock;
181 u_short chip;
182 u_short soft_model;
183 u_int memory_size;
184 u_int virt_memory_size;
185 u_short rx_ratio; /* 1 - 99 */
186 u_short priority_tx; /* != 0 - priority tx */
187 u_short mode; /* PIO, Shared Mem or Busmaster */
188 u_char bus;
189 struct pci_dev *pci_dev;
190 short mem_mapped; /* memory mapped access */
191 void *mem_ptr_virt; /* virtual memory mapped area, maybe NULL */
192 unsigned long mem_ptr_phys; /* physical memory mapped area */
193 short lan_type; /* 10Mb/s, 100Mb/s or -1 (error) */
194 int hub_status; /* was login to hub successful? */
195 u_char mac1_mode;
196 u_char mac2_mode;
197 u_char hash_bytes[8];
198 hp100_stats_t stats;
200 /* Rings for busmaster mode: */
201 hp100_ring_t *rxrhead; /* Head (oldest) index into rxring */
202 hp100_ring_t *rxrtail; /* Tail (newest) index into rxring */
203 hp100_ring_t *txrhead; /* Head (oldest) index into txring */
204 hp100_ring_t *txrtail; /* Tail (newest) index into txring */
206 hp100_ring_t rxring[MAX_RX_PDL];
207 hp100_ring_t txring[MAX_TX_PDL];
209 u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */
210 u_long whatever_offset; /* Offset to bus/phys/dma address */
211 int rxrcommit; /* # Rx PDLs commited to adapter */
212 int txrcommit; /* # Tx PDLs commited to adapter */
216 * variables
219 static struct hp100_eisa_id hp100_eisa_ids[] = {
221 /* 10/100 EISA card with revision A Cascade chip */
222 {0x80F1F022, "HP J2577 rev A", HP100_BUS_EISA},
224 /* 10/100 ISA card with revision A Cascade chip */
225 {0x50F1F022, "HP J2573 rev A", HP100_BUS_ISA},
227 /* 10 only EISA card with Cascade chip */
228 {0x2019F022, "HP 27248B", HP100_BUS_EISA},
230 /* 10/100 EISA card with Cascade chip */
231 {0x4019F022, "HP J2577", HP100_BUS_EISA},
233 /* 10/100 ISA card with Cascade chip */
234 {0x5019F022, "HP J2573", HP100_BUS_ISA},
236 /* 10/100 EISA card with AT&T chip */
237 {0x9019f022, "HP J2577", HP100_BUS_EISA },
239 /* 10/100 PCI card - old J2585A */
240 {0x1030103c, "HP J2585A", HP100_BUS_PCI},
242 /* 10/100 PCI card - new J2585B - master capable */
243 {0x1041103c, "HP J2585B", HP100_BUS_PCI},
245 /* 10 Mbit Combo Adapter */
246 {0x1042103c, "HP J2970", HP100_BUS_PCI},
248 /* 10 Mbit 10baseT Adapter */
249 {0x1040103c, "HP J2973", HP100_BUS_PCI},
251 /* 10/100 EISA card from Compex */
252 {0x0103180e, "ReadyLink ENET100-VG4", HP100_BUS_EISA},
254 /* 10/100 EISA card from Compex - FreedomLine (sq5bpf) */
255 /* Note: plhbrod@mbox.vol.cz reported that same ID have ISA */
256 /* version of adapter, too... */
257 {0x0104180e, "FreedomLine 100/VG", HP100_BUS_EISA},
259 /* 10/100 PCI card from Compex - FreedomLine
261 * I think this card doesn't like aic7178 scsi controller, but
262 * I haven't tested this much. It works fine on diskless machines.
263 * Jacek Lipkowski <sq5bpf@acid.ch.pw.edu.pl>
265 {0x021211f6, "FreedomLine 100/VG", HP100_BUS_PCI},
267 /* 10/100 PCI card from Compex (J2585A compatible) */
268 {0x011211f6, "ReadyLink ENET100-VG4", HP100_BUS_PCI},
270 /* 10/100 PCI card from KTI */
271 {0x40008e2e, "KTI DP-200", HP100_BUS_PCI }
274 #define HP100_EISA_IDS_SIZE (sizeof(hp100_eisa_ids)/sizeof(struct hp100_eisa_id))
276 #ifdef CONFIG_PCI
277 static struct hp100_pci_id hp100_pci_ids[] = {
278 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A},
279 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B},
280 {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4},
281 {PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG}
283 #endif
285 #define HP100_PCI_IDS_SIZE (sizeof(hp100_pci_ids)/sizeof(struct hp100_pci_id))
287 static struct pci_device_id hp100_pci_tbl[] __initdata = {
288 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A, PCI_ANY_ID, PCI_ANY_ID,},
289 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B, PCI_ANY_ID, PCI_ANY_ID,},
290 {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4, PCI_ANY_ID, PCI_ANY_ID,},
291 {PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG, PCI_ANY_ID, PCI_ANY_ID,},
292 {} /* Terminating entry */
294 MODULE_DEVICE_TABLE(pci, hp100_pci_tbl);
296 static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
297 static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
298 static int hp100_mode = 1;
300 MODULE_PARM(hp100_rx_ratio, "1i");
301 MODULE_PARM(hp100_priority_tx, "1i");
302 MODULE_PARM(hp100_mode, "1i");
305 * prototypes
308 static int hp100_probe1(struct net_device *dev, int ioaddr, u_char bus,
309 struct pci_dev *pci_dev);
312 static int hp100_open(struct net_device *dev);
313 static int hp100_close(struct net_device *dev);
314 static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev);
315 static int hp100_start_xmit_bm(struct sk_buff *skb,
316 struct net_device *dev);
317 static void hp100_rx(struct net_device *dev);
318 static hp100_stats_t *hp100_get_stats(struct net_device *dev);
319 static void hp100_misc_interrupt(struct net_device *dev);
320 static void hp100_update_stats(struct net_device *dev);
321 static void hp100_clear_stats(struct hp100_private *lp, int ioaddr);
322 static void hp100_set_multicast_list(struct net_device *dev);
323 static irqreturn_t hp100_interrupt(int irq, void *dev_id, struct pt_regs *regs);
324 static void hp100_start_interface(struct net_device *dev);
325 static void hp100_stop_interface(struct net_device *dev);
326 static void hp100_load_eeprom(struct net_device *dev, u_short ioaddr);
327 static int hp100_sense_lan(struct net_device *dev);
328 static int hp100_login_to_vg_hub(struct net_device *dev,
329 u_short force_relogin);
330 static int hp100_down_vg_link(struct net_device *dev);
331 static void hp100_cascade_reset(struct net_device *dev, u_short enable);
332 static void hp100_BM_shutdown(struct net_device *dev);
333 static void hp100_mmuinit(struct net_device *dev);
334 static void hp100_init_pdls(struct net_device *dev);
335 static int hp100_init_rxpdl(struct net_device *dev,
336 register hp100_ring_t * ringptr,
337 register u_int * pdlptr);
338 static int hp100_init_txpdl(struct net_device *dev,
339 register hp100_ring_t * ringptr,
340 register u_int * pdlptr);
341 static void hp100_rxfill(struct net_device *dev);
342 static void hp100_hwinit(struct net_device *dev);
343 static void hp100_clean_txring(struct net_device *dev);
344 #ifdef HP100_DEBUG
345 static void hp100_RegisterDump(struct net_device *dev);
346 #endif
348 /* Conversion to new PCI API :
349 * Convert an address in a kernel buffer to a bus/phys/dma address.
350 * This work *only* for memory fragments part of lp->page_vaddr,
351 * because it was properly DMA allocated via pci_alloc_consistent(),
352 * so we just need to "retreive" the original mapping to bus/phys/dma
353 * address - Jean II */
354 static inline dma_addr_t virt_to_whatever(struct net_device *dev, u32 * ptr)
356 return ((u_long) ptr) +
357 ((struct hp100_private *) (dev->priv))->whatever_offset;
360 /* TODO: This function should not really be needed in a good design... */
361 static void wait(void)
363 mdelay(1);
367 * probe functions
368 * These functions should - if possible - avoid doing write operations
369 * since this could cause problems when the card is not installed.
372 int __init hp100_probe(struct net_device *dev)
374 int base_addr = dev ? dev->base_addr : 0;
375 int ioaddr = 0;
376 int pci_start_index = 0;
378 #ifdef HP100_DEBUG_B
379 hp100_outw(0x4200, TRACE);
380 printk("hp100: %s: probe\n", dev->name);
381 #endif
383 if (base_addr > 0xff) { /* Check a single specified location. */
384 if (check_region(base_addr, HP100_REGION_SIZE))
385 return -EINVAL;
386 if (base_addr < 0x400)
387 return hp100_probe1(dev, base_addr, HP100_BUS_ISA,
388 NULL);
389 if (EISA_bus && base_addr >= 0x1c38 && ((base_addr - 0x1c38) & 0x3ff) == 0)
390 return hp100_probe1(dev, base_addr, HP100_BUS_EISA, NULL);
391 #ifdef CONFIG_PCI
392 printk("hp100: %s: You must specify card # in i/o address parameter for PCI bus...", dev->name);
393 #else
394 return -ENODEV;
395 #endif
396 } else
397 #ifdef CONFIG_PCI
398 if (base_addr > 0 && base_addr < 8 + 1)
399 pci_start_index = 0x100 | (base_addr - 1);
400 else
401 #endif
402 if (base_addr != 0)
403 return -ENXIO;
405 /* First: scan PCI bus(es) */
407 #ifdef CONFIG_PCI
409 int pci_index;
410 struct pci_dev *pci_dev = NULL;
411 int pci_id_index;
412 u_short pci_command;
414 #ifdef HP100_DEBUG_PCI
415 printk("hp100: %s: PCI BIOS is present, checking for devices..\n", dev->name);
416 #endif
417 pci_index = 0;
418 for (pci_id_index = 0; pci_id_index < HP100_PCI_IDS_SIZE;
419 pci_id_index++) {
420 while ((pci_dev = pci_find_device(hp100_pci_ids[pci_id_index].vendor,
421 hp100_pci_ids[pci_id_index].device,
422 pci_dev)) != NULL) {
423 if (pci_index < (pci_start_index & 7)) {
424 pci_index++;
425 continue;
427 if (pci_enable_device(pci_dev))
428 continue;
429 /* found... */
430 ioaddr = pci_resource_start(pci_dev, 0);
431 if (check_region(ioaddr, HP100_REGION_SIZE))
432 continue;
433 pci_read_config_word(pci_dev, PCI_COMMAND, &pci_command);
434 if (!(pci_command & PCI_COMMAND_IO)) {
435 #ifdef HP100_DEBUG
436 printk("hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name);
437 #endif
438 pci_command |= PCI_COMMAND_IO;
439 pci_write_config_word(pci_dev, PCI_COMMAND, pci_command);
441 if (!(pci_command & PCI_COMMAND_MASTER)) {
442 #ifdef HP100_DEBUG
443 printk("hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name);
444 #endif
445 pci_command |= PCI_COMMAND_MASTER;
446 pci_write_config_word(pci_dev, PCI_COMMAND, pci_command);
448 #ifdef HP100_DEBUG
449 printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr);
450 #endif
451 if (hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pci_dev) == 0)
452 return 0;
456 if (pci_start_index > 0)
457 return -ENODEV;
458 #endif /* CONFIG_PCI */
460 /* Second: Probe all EISA possible port regions (if EISA bus present) */
461 for (ioaddr = 0x1c38; EISA_bus && ioaddr < 0x10000; ioaddr += 0x400) {
462 if (check_region(ioaddr, HP100_REGION_SIZE))
463 continue;
464 if (hp100_probe1(dev, ioaddr, HP100_BUS_EISA, NULL) == 0)
465 return 0;
468 /* Third: Probe all ISA possible port regions */
469 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20) {
470 if (check_region(ioaddr, HP100_REGION_SIZE))
471 continue;
472 if (hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL) == 0)
473 return 0;
476 return -ENODEV;
479 static int __init hp100_probe1(struct net_device *dev, int ioaddr,
480 u_char bus, struct pci_dev *pci_dev)
482 int i;
484 u_char uc, uc_1;
485 u_int eisa_id;
486 u_int chip;
487 u_int memory_size = 0, virt_memory_size = 0;
488 u_short local_mode, lsw;
489 short mem_mapped;
490 unsigned long mem_ptr_phys;
491 void **mem_ptr_virt;
492 struct hp100_private *lp;
493 struct hp100_eisa_id *eid;
495 #ifdef HP100_DEBUG_B
496 hp100_outw(0x4201, TRACE);
497 printk("hp100: %s: probe1\n", dev->name);
498 #endif
500 if (dev == NULL) {
501 #ifdef HP100_DEBUG
502 printk("hp100_probe1: %s: dev == NULL ?\n", dev->name);
503 #endif
504 return -EIO;
507 if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) {
508 return -ENODEV;
509 } else {
510 chip = hp100_inw(PAGING) & HP100_CHIPID_MASK;
511 #ifdef HP100_DEBUG
512 if (chip == HP100_CHIPID_SHASTA)
513 printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name);
514 else if (chip == HP100_CHIPID_RAINIER)
515 printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name);
516 else if (chip == HP100_CHIPID_LASSEN)
517 printk("hp100: %s: Lassen Chip detected.\n", dev->name);
518 else
519 printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n", dev->name, chip);
520 #endif
523 dev->base_addr = ioaddr;
525 hp100_page(ID_MAC_ADDR);
526 for (i = uc = eisa_id = 0; i < 4; i++) {
527 eisa_id >>= 8;
528 uc_1 = hp100_inb(BOARD_ID + i);
529 eisa_id |= uc_1 << 24;
530 uc += uc_1;
532 uc += hp100_inb(BOARD_ID + 4);
534 if (uc != 0xff) { /* bad checksum? */
535 printk("hp100_probe: %s: bad EISA ID checksum at base port 0x%x\n", dev->name, ioaddr);
536 return -ENODEV;
539 for (i = 0; i < HP100_EISA_IDS_SIZE; i++)
540 if (hp100_eisa_ids[i].id == eisa_id)
541 break;
542 if (i >= HP100_EISA_IDS_SIZE) {
543 for (i = 0; i < HP100_EISA_IDS_SIZE; i++)
544 if ((hp100_eisa_ids[i].id & 0xf0ffffff) == (eisa_id & 0xf0ffffff))
545 break;
546 if (i >= HP100_EISA_IDS_SIZE) {
547 printk ("hp100_probe: %s: card at port 0x%x isn't known (id = 0x%x)\n", dev->name, ioaddr, eisa_id);
548 return -ENODEV;
551 eid = &hp100_eisa_ids[i];
552 if ((eid->id & 0x0f000000) < (eisa_id & 0x0f000000)) {
553 printk("hp100_probe: %s: newer version of card %s at port 0x%x - unsupported\n", dev->name, eid->name, ioaddr);
554 return -ENODEV;
557 for (i = uc = 0; i < 7; i++)
558 uc += hp100_inb(LAN_ADDR + i);
559 if (uc != 0xff) {
560 printk("hp100_probe: %s: bad lan address checksum (card %s at port 0x%x)\n", dev->name, eid->name, ioaddr);
561 return -EIO;
564 /* Make sure, that all registers are correctly updated... */
566 hp100_load_eeprom(dev, ioaddr);
567 wait();
570 * Determine driver operation mode
572 * Use the variable "hp100_mode" upon insmod or as kernel parameter to
573 * force driver modes:
574 * hp100_mode=1 -> default, use busmaster mode if configured.
575 * hp100_mode=2 -> enable shared memory mode
576 * hp100_mode=3 -> force use of i/o mapped mode.
577 * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.
581 * LSW values:
582 * 0x2278 -> J2585B, PnP shared memory mode
583 * 0x2270 -> J2585B, shared memory mode, 0xdc000
584 * 0xa23c -> J2585B, I/O mapped mode
585 * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)
586 * 0x2220 -> EISA HP, I/O (Shasta Chip)
587 * 0x2260 -> EISA HP, BusMaster (Shasta Chip)
590 #if 0
591 local_mode = 0x2270;
592 hp100_outw(0xfefe, OPTION_LSW);
593 hp100_outw(local_mode | HP100_SET_LB | HP100_SET_HB, OPTION_LSW);
594 #endif
596 /* hp100_mode value maybe used in future by another card */
597 local_mode = hp100_mode;
598 if (local_mode < 1 || local_mode > 4)
599 local_mode = 1; /* default */
600 #ifdef HP100_DEBUG
601 printk("hp100: %s: original LSW = 0x%x\n", dev->name,
602 hp100_inw(OPTION_LSW));
603 #endif
605 if (local_mode == 3) {
606 hp100_outw(HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);
607 hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
608 hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
609 printk("hp100: %s: IO mapped mode forced.\n", dev->name);
610 } else if (local_mode == 2) {
611 hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
612 hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
613 hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
614 printk("hp100: %s: Shared memory mode requested.\n", dev->name);
615 } else if (local_mode == 4) {
616 if (chip == HP100_CHIPID_LASSEN) {
617 hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_SET_HB, OPTION_LSW);
618 hp100_outw(HP100_IO_EN | HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);
619 printk("hp100: %s: Busmaster mode requested.\n", dev->name);
621 local_mode = 1;
624 if (local_mode == 1) { /* default behaviour */
625 lsw = hp100_inw(OPTION_LSW);
627 if ((lsw & HP100_IO_EN) && (~lsw & HP100_MEM_EN) &&
628 (~lsw & (HP100_BM_WRITE | HP100_BM_READ))) {
629 #ifdef HP100_DEBUG
630 printk("hp100: %s: IO_EN bit is set on card.\n", dev->name);
631 #endif
632 local_mode = 3;
633 } else if (chip == HP100_CHIPID_LASSEN &&
634 (lsw & (HP100_BM_WRITE | HP100_BM_READ)) == (HP100_BM_WRITE | HP100_BM_READ)) {
635 /* Conversion to new PCI API :
636 * I don't have the doc, but I assume that the card
637 * can map the full 32bit address space.
638 * Also, we can have EISA Busmaster cards (not tested),
639 * so beware !!! - Jean II */
640 if((bus == HP100_BUS_PCI) &&
641 (pci_set_dma_mask(pci_dev, 0xffffffff))) {
642 /* Gracefully fallback to shared memory */
643 goto busmasterfail;
645 printk("hp100: %s: Busmaster mode enabled.\n", dev->name);
646 hp100_outw(HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);
647 } else {
648 busmasterfail:
649 #ifdef HP100_DEBUG
650 printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name);
651 printk("hp100: %s: Trying shared memory mode.\n", dev->name);
652 #endif
653 /* In this case, try shared memory mode */
654 local_mode = 2;
655 hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
656 /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */
659 #ifdef HP100_DEBUG
660 printk("hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW));
661 #endif
663 /* Check for shared memory on the card, eventually remap it */
664 hp100_page(HW_MAP);
665 mem_mapped = ((hp100_inw(OPTION_LSW) & (HP100_MEM_EN)) != 0);
666 mem_ptr_phys = 0UL;
667 mem_ptr_virt = NULL;
668 memory_size = (8192 << ((hp100_inb(SRAM) >> 5) & 0x07));
669 virt_memory_size = 0;
671 /* For memory mapped or busmaster mode, we want the memory address */
672 if (mem_mapped || (local_mode == 1)) {
673 mem_ptr_phys = (hp100_inw(MEM_MAP_LSW) | (hp100_inw(MEM_MAP_MSW) << 16));
674 mem_ptr_phys &= ~0x1fff; /* 8k alignment */
676 if (bus == HP100_BUS_ISA && (mem_ptr_phys & ~0xfffff) != 0) {
677 printk("hp100: %s: Can only use programmed i/o mode.\n", dev->name);
678 mem_ptr_phys = 0;
679 mem_mapped = 0;
680 local_mode = 3; /* Use programmed i/o */
683 /* We do not need access to shared memory in busmaster mode */
684 /* However in slave mode we need to remap high (>1GB) card memory */
685 if (local_mode != 1) { /* = not busmaster */
686 /* We try with smaller memory sizes, if ioremap fails */
687 for (virt_memory_size = memory_size; virt_memory_size > 16383; virt_memory_size >>= 1) {
688 if ((mem_ptr_virt = ioremap((u_long) mem_ptr_phys, virt_memory_size)) == NULL) {
689 #ifdef HP100_DEBUG
690 printk("hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, mem_ptr_phys);
691 #endif
692 } else {
693 #ifdef HP100_DEBUG
694 printk("hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to %p.\n", dev->name, virt_memory_size, mem_ptr_phys, mem_ptr_virt);
695 #endif
696 break;
700 if (mem_ptr_virt == NULL) { /* all ioremap tries failed */
701 printk("hp100: %s: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n", dev->name);
702 local_mode = 3;
703 virt_memory_size = 0;
708 if (local_mode == 3) { /* io mapped forced */
709 mem_mapped = 0;
710 mem_ptr_phys = 0;
711 mem_ptr_virt = NULL;
712 printk("hp100: %s: Using (slow) programmed i/o mode.\n", dev->name);
715 /* Initialise the "private" data structure for this card. */
716 if ((dev->priv = kmalloc(sizeof(struct hp100_private), GFP_KERNEL)) == NULL)
717 return -ENOMEM;
719 lp = (struct hp100_private *) dev->priv;
720 memset(lp, 0, sizeof(struct hp100_private));
721 spin_lock_init(&lp->lock);
722 lp->id = eid;
723 lp->chip = chip;
724 lp->mode = local_mode;
725 lp->bus = bus;
726 lp->pci_dev = pci_dev;
727 lp->priority_tx = hp100_priority_tx;
728 lp->rx_ratio = hp100_rx_ratio;
729 lp->mem_ptr_phys = mem_ptr_phys;
730 lp->mem_ptr_virt = mem_ptr_virt;
731 hp100_page(ID_MAC_ADDR);
732 lp->soft_model = hp100_inb(SOFT_MODEL);
733 lp->mac1_mode = HP100_MAC1MODE3;
734 lp->mac2_mode = HP100_MAC2MODE3;
735 memset(&lp->hash_bytes, 0x00, 8);
737 dev->base_addr = ioaddr;
739 lp->memory_size = memory_size;
740 lp->virt_memory_size = virt_memory_size;
741 lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */
743 /* memory region for programmed i/o */
744 request_region(dev->base_addr, HP100_REGION_SIZE, eid->name);
746 dev->open = hp100_open;
747 dev->stop = hp100_close;
749 if (lp->mode == 1) /* busmaster */
750 dev->hard_start_xmit = hp100_start_xmit_bm;
751 else
752 dev->hard_start_xmit = hp100_start_xmit;
754 dev->get_stats = hp100_get_stats;
755 dev->set_multicast_list = &hp100_set_multicast_list;
757 /* Ask the card for which IRQ line it is configured */
758 if (bus == HP100_BUS_PCI) {
759 dev->irq = pci_dev->irq;
760 } else {
761 hp100_page(HW_MAP);
762 dev->irq = hp100_inb(IRQ_CHANNEL) & HP100_IRQMASK;
763 if (dev->irq == 2)
764 dev->irq = 9;
767 if (lp->mode == 1) /* busmaster */
768 dev->dma = 4;
770 /* Ask the card for its MAC address and store it for later use. */
771 hp100_page(ID_MAC_ADDR);
772 for (i = uc = 0; i < 6; i++)
773 dev->dev_addr[i] = hp100_inb(LAN_ADDR + i);
775 /* Reset statistics (counters) */
776 hp100_clear_stats(lp, ioaddr);
778 SET_MODULE_OWNER(dev);
779 SET_NETDEV_DEV(dev, &pci_dev->dev);
780 ether_setup(dev);
782 /* If busmaster mode is wanted, a dma-capable memory area is needed for
783 * the rx and tx PDLs
784 * PCI cards can access the whole PC memory. Therefore GFP_DMA is not
785 * needed for the allocation of the memory area.
788 /* TODO: We do not need this with old cards, where PDLs are stored
789 * in the cards shared memory area. But currently, busmaster has been
790 * implemented/tested only with the lassen chip anyway... */
791 if (lp->mode == 1) { /* busmaster */
792 dma_addr_t page_baddr;
793 /* Get physically continous memory for TX & RX PDLs */
794 /* Conversion to new PCI API :
795 * Pages are always aligned and zeroed, no need to it ourself.
796 * Doc says should be OK for EISA bus as well - Jean II */
797 if ((lp->page_vaddr_algn = pci_alloc_consistent(lp->pci_dev, MAX_RINGSIZE, &page_baddr)) == NULL)
798 return -ENOMEM;
799 lp->whatever_offset = ((u_long) page_baddr) - ((u_long) lp->page_vaddr_algn);
801 #ifdef HP100_DEBUG_BM
802 printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n", dev->name, (u_int) lp->page_vaddr_algn, (u_int) lp->page_vaddr_algn + MAX_RINGSIZE);
803 #endif
804 lp->rxrcommit = lp->txrcommit = 0;
805 lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);
806 lp->txrhead = lp->txrtail = &(lp->txring[0]);
809 /* Initialise the card. */
810 /* (I'm not really sure if it's a good idea to do this during probing, but
811 * like this it's assured that the lan connection type can be sensed
812 * correctly)
814 hp100_hwinit(dev);
816 /* Try to find out which kind of LAN the card is connected to. */
817 lp->lan_type = hp100_sense_lan(dev);
819 /* Print out a message what about what we think we have probed. */
820 printk("hp100: %s: %s at 0x%x, IRQ %d, ", dev->name, lp->id->name, ioaddr, dev->irq);
821 switch (bus) {
822 case HP100_BUS_EISA:
823 printk("EISA");
824 break;
825 case HP100_BUS_PCI:
826 printk("PCI");
827 break;
828 default:
829 printk("ISA");
830 break;
832 printk(" bus, %dk SRAM (rx/tx %d%%).\n", lp->memory_size >> 10, lp->rx_ratio);
834 if (lp->mode == 2) { /* memory mapped */
835 printk("hp100: %s: Memory area at 0x%lx-0x%lx", dev->name, mem_ptr_phys,
836 (mem_ptr_phys + (mem_ptr_phys > 0x100000 ? (u_long) lp->memory_size : 16 * 1024)) - 1);
837 if (mem_ptr_virt)
838 printk(" (virtual base %p)", mem_ptr_virt);
839 printk(".\n");
841 /* Set for info when doing ifconfig */
842 dev->mem_start = mem_ptr_phys;
843 dev->mem_end = mem_ptr_phys + lp->memory_size;
845 printk("hp100: %s: ", dev->name);
846 if (lp->lan_type != HP100_LAN_ERR)
847 printk("Adapter is attached to ");
848 switch (lp->lan_type) {
849 case HP100_LAN_100:
850 printk("100Mb/s Voice Grade AnyLAN network.\n");
851 break;
852 case HP100_LAN_10:
853 printk("10Mb/s network (10baseT).\n");
854 break;
855 case HP100_LAN_COAX:
856 printk("10Mb/s network (coax).\n");
857 break;
858 default:
859 printk("Warning! Link down.\n");
862 return 0;
865 /* This procedure puts the card into a stable init state */
866 static void hp100_hwinit(struct net_device *dev)
868 int ioaddr = dev->base_addr;
869 struct hp100_private *lp = (struct hp100_private *) dev->priv;
871 #ifdef HP100_DEBUG_B
872 hp100_outw(0x4202, TRACE);
873 printk("hp100: %s: hwinit\n", dev->name);
874 #endif
876 /* Initialise the card. -------------------------------------------- */
878 /* Clear all pending Ints and disable Ints */
879 hp100_page(PERFORMANCE);
880 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
881 hp100_outw(0xffff, IRQ_STATUS); /* clear all pending ints */
883 hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
884 hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
886 if (lp->mode == 1) {
887 hp100_BM_shutdown(dev); /* disables BM, puts cascade in reset */
888 wait();
889 } else {
890 hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
891 hp100_cascade_reset(dev, 1);
892 hp100_page(MAC_CTRL);
893 hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);
896 /* Initiate EEPROM reload */
897 hp100_load_eeprom(dev, 0);
899 wait();
901 /* Go into reset again. */
902 hp100_cascade_reset(dev, 1);
904 /* Set Option Registers to a safe state */
905 hp100_outw(HP100_DEBUG_EN |
906 HP100_RX_HDR |
907 HP100_EE_EN |
908 HP100_BM_WRITE |
909 HP100_BM_READ | HP100_RESET_HB |
910 HP100_FAKE_INT |
911 HP100_INT_EN |
912 HP100_MEM_EN |
913 HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);
915 hp100_outw(HP100_TRI_INT |
916 HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW);
918 hp100_outb(HP100_PRIORITY_TX |
919 HP100_ADV_NXT_PKT |
920 HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW);
922 /* TODO: Configure MMU for Ram Test. */
923 /* TODO: Ram Test. */
925 /* Re-check if adapter is still at same i/o location */
926 /* (If the base i/o in eeprom has been changed but the */
927 /* registers had not been changed, a reload of the eeprom */
928 /* would move the adapter to the address stored in eeprom */
930 /* TODO: Code to implement. */
932 /* Until here it was code from HWdiscover procedure. */
933 /* Next comes code from mmuinit procedure of SCO BM driver which is
934 * called from HWconfigure in the SCO driver. */
936 /* Initialise MMU, eventually switch on Busmaster Mode, initialise
937 * multicast filter...
939 hp100_mmuinit(dev);
941 /* We don't turn the interrupts on here - this is done by start_interface. */
942 wait(); /* TODO: Do we really need this? */
944 /* Enable Hardware (e.g. unreset) */
945 hp100_cascade_reset(dev, 0);
947 /* ------- initialisation complete ----------- */
949 /* Finally try to log in the Hub if there may be a VG connection. */
950 if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR))
951 hp100_login_to_vg_hub(dev, 0); /* relogin */
956 * mmuinit - Reinitialise Cascade MMU and MAC settings.
957 * Note: Must already be in reset and leaves card in reset.
959 static void hp100_mmuinit(struct net_device *dev)
961 int ioaddr = dev->base_addr;
962 struct hp100_private *lp = (struct hp100_private *) dev->priv;
963 int i;
965 #ifdef HP100_DEBUG_B
966 hp100_outw(0x4203, TRACE);
967 printk("hp100: %s: mmuinit\n", dev->name);
968 #endif
970 #ifdef HP100_DEBUG
971 if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) {
972 printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n", dev->name);
973 return;
975 #endif
977 /* Make sure IRQs are masked off and ack'ed. */
978 hp100_page(PERFORMANCE);
979 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
980 hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
983 * Enable Hardware
984 * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En
985 * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable
986 * - Clear Priority, Advance Pkt and Xmit Cmd
989 hp100_outw(HP100_DEBUG_EN |
990 HP100_RX_HDR |
991 HP100_EE_EN | HP100_RESET_HB |
992 HP100_IO_EN |
993 HP100_FAKE_INT |
994 HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
996 hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
998 if (lp->mode == 1) { /* busmaster */
999 hp100_outw(HP100_BM_WRITE |
1000 HP100_BM_READ |
1001 HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW);
1002 } else if (lp->mode == 2) { /* memory mapped */
1003 hp100_outw(HP100_BM_WRITE |
1004 HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
1005 hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW);
1006 hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
1007 hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
1008 } else if (lp->mode == 3) { /* i/o mapped mode */
1009 hp100_outw(HP100_MMAP_DIS | HP100_SET_HB |
1010 HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
1013 hp100_page(HW_MAP);
1014 hp100_outb(0, EARLYRXCFG);
1015 hp100_outw(0, EARLYTXCFG);
1018 * Enable Bus Master mode
1020 if (lp->mode == 1) { /* busmaster */
1021 /* Experimental: Set some PCI configuration bits */
1022 hp100_page(HW_MAP);
1023 hp100_andb(~HP100_PDL_USE3, MODECTRL1); /* BM engine read maximum */
1024 hp100_andb(~HP100_TX_DUALQ, MODECTRL1); /* No Queue for Priority TX */
1026 /* PCI Bus failures should result in a Misc. Interrupt */
1027 hp100_orb(HP100_EN_BUS_FAIL, MODECTRL2);
1029 hp100_outw(HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW);
1030 hp100_page(HW_MAP);
1031 /* Use Burst Mode and switch on PAGE_CK */
1032 hp100_orb(HP100_BM_BURST_RD | HP100_BM_BURST_WR, BM);
1033 if ((lp->chip == HP100_CHIPID_RAINIER) || (lp->chip == HP100_CHIPID_SHASTA))
1034 hp100_orb(HP100_BM_PAGE_CK, BM);
1035 hp100_orb(HP100_BM_MASTER, BM);
1036 } else { /* not busmaster */
1038 hp100_page(HW_MAP);
1039 hp100_andb(~HP100_BM_MASTER, BM);
1043 * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs
1045 hp100_page(MMU_CFG);
1046 if (lp->mode == 1) { /* only needed for Busmaster */
1047 int xmit_stop, recv_stop;
1049 if ((lp->chip == HP100_CHIPID_RAINIER)
1050 || (lp->chip == HP100_CHIPID_SHASTA)) {
1051 int pdl_stop;
1054 * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and
1055 * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded
1056 * to the next higher 1k boundary) bytes for the rx-pdl's
1057 * Note: For non-etr chips the transmit stop register must be
1058 * programmed on a 1k boundary, i.e. bits 9:0 must be zero.
1060 pdl_stop = lp->memory_size;
1061 xmit_stop = (pdl_stop - 508 * (MAX_RX_PDL) - 16) & ~(0x03ff);
1062 recv_stop = (xmit_stop * (lp->rx_ratio) / 100) & ~(0x03ff);
1063 hp100_outw((pdl_stop >> 4) - 1, PDL_MEM_STOP);
1064 #ifdef HP100_DEBUG_BM
1065 printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop);
1066 #endif
1067 } else {
1068 /* ETR chip (Lassen) in busmaster mode */
1069 xmit_stop = (lp->memory_size) - 1;
1070 recv_stop = ((lp->memory_size * lp->rx_ratio) / 100) & ~(0x03ff);
1073 hp100_outw(xmit_stop >> 4, TX_MEM_STOP);
1074 hp100_outw(recv_stop >> 4, RX_MEM_STOP);
1075 #ifdef HP100_DEBUG_BM
1076 printk("hp100: %s: TX_STOP = 0x%x\n", dev->name, xmit_stop >> 4);
1077 printk("hp100: %s: RX_STOP = 0x%x\n", dev->name, recv_stop >> 4);
1078 #endif
1079 } else {
1080 /* Slave modes (memory mapped and programmed io) */
1081 hp100_outw((((lp->memory_size * lp->rx_ratio) / 100) >> 4), RX_MEM_STOP);
1082 hp100_outw(((lp->memory_size - 1) >> 4), TX_MEM_STOP);
1083 #ifdef HP100_DEBUG
1084 printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(TX_MEM_STOP));
1085 printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(RX_MEM_STOP));
1086 #endif
1089 /* Write MAC address into page 1 */
1090 hp100_page(MAC_ADDRESS);
1091 for (i = 0; i < 6; i++)
1092 hp100_outb(dev->dev_addr[i], MAC_ADDR + i);
1094 /* Zero the multicast hash registers */
1095 for (i = 0; i < 8; i++)
1096 hp100_outb(0x0, HASH_BYTE0 + i);
1098 /* Set up MAC defaults */
1099 hp100_page(MAC_CTRL);
1101 /* Go to LAN Page and zero all filter bits */
1102 /* Zero accept error, accept multicast, accept broadcast and accept */
1103 /* all directed packet bits */
1104 hp100_andb(~(HP100_RX_EN |
1105 HP100_TX_EN |
1106 HP100_ACC_ERRORED |
1107 HP100_ACC_MC |
1108 HP100_ACC_BC | HP100_ACC_PHY), MAC_CFG_1);
1110 hp100_outb(0x00, MAC_CFG_2);
1112 /* Zero the frame format bit. This works around a training bug in the */
1113 /* new hubs. */
1114 hp100_outb(0x00, VG_LAN_CFG_2); /* (use 802.3) */
1116 if (lp->priority_tx)
1117 hp100_outb(HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW);
1118 else
1119 hp100_outb(HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW);
1121 hp100_outb(HP100_ADV_NXT_PKT |
1122 HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW);
1124 /* If busmaster, initialize the PDLs */
1125 if (lp->mode == 1)
1126 hp100_init_pdls(dev);
1128 /* Go to performance page and initalize isr and imr registers */
1129 hp100_page(PERFORMANCE);
1130 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
1131 hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
1135 * open/close functions
1138 static int hp100_open(struct net_device *dev)
1140 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1141 #ifdef HP100_DEBUG_B
1142 int ioaddr = dev->base_addr;
1143 #endif
1145 #ifdef HP100_DEBUG_B
1146 hp100_outw(0x4204, TRACE);
1147 printk("hp100: %s: open\n", dev->name);
1148 #endif
1150 /* New: if bus is PCI or EISA, interrupts might be shared interrupts */
1151 if (request_irq(dev->irq, hp100_interrupt,
1152 lp->bus == HP100_BUS_PCI || lp->bus ==
1153 HP100_BUS_EISA ? SA_SHIRQ : SA_INTERRUPT,
1154 lp->id->name, dev)) {
1155 printk("hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq);
1156 return -EAGAIN;
1159 dev->trans_start = jiffies;
1160 netif_start_queue(dev);
1162 lp->lan_type = hp100_sense_lan(dev);
1163 lp->mac1_mode = HP100_MAC1MODE3;
1164 lp->mac2_mode = HP100_MAC2MODE3;
1165 memset(&lp->hash_bytes, 0x00, 8);
1167 hp100_stop_interface(dev);
1169 hp100_hwinit(dev);
1171 hp100_start_interface(dev); /* sets mac modes, enables interrupts */
1173 return 0;
1176 /* The close function is called when the interface is to be brought down */
1177 static int hp100_close(struct net_device *dev)
1179 int ioaddr = dev->base_addr;
1180 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1182 #ifdef HP100_DEBUG_B
1183 hp100_outw(0x4205, TRACE);
1184 printk("hp100: %s: close\n", dev->name);
1185 #endif
1187 hp100_page(PERFORMANCE);
1188 hp100_outw(0xfefe, IRQ_MASK); /* mask off all IRQs */
1190 hp100_stop_interface(dev);
1192 if (lp->lan_type == HP100_LAN_100)
1193 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1195 netif_stop_queue(dev);
1197 free_irq(dev->irq, dev);
1199 #ifdef HP100_DEBUG
1200 printk("hp100: %s: close LSW = 0x%x\n", dev->name,
1201 hp100_inw(OPTION_LSW));
1202 #endif
1204 return 0;
1209 * Configure the PDL Rx rings and LAN
1211 static void hp100_init_pdls(struct net_device *dev)
1213 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1214 hp100_ring_t *ringptr;
1215 u_int *pageptr; /* Warning : increment by 4 - Jean II */
1216 int i;
1218 #ifdef HP100_DEBUG_B
1219 int ioaddr = dev->base_addr;
1220 #endif
1222 #ifdef HP100_DEBUG_B
1223 hp100_outw(0x4206, TRACE);
1224 printk("hp100: %s: init pdls\n", dev->name);
1225 #endif
1227 if (0 == lp->page_vaddr_algn)
1228 printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n", dev->name);
1229 else {
1230 /* pageptr shall point into the DMA accessible memory region */
1231 /* we use this pointer to status the upper limit of allocated */
1232 /* memory in the allocated page. */
1233 /* note: align the pointers to the pci cache line size */
1234 memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero Rx/Tx ring page */
1235 pageptr = lp->page_vaddr_algn;
1237 lp->rxrcommit = 0;
1238 ringptr = lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);
1240 /* Initialise Rx Ring */
1241 for (i = MAX_RX_PDL - 1; i >= 0; i--) {
1242 lp->rxring[i].next = ringptr;
1243 ringptr = &(lp->rxring[i]);
1244 pageptr += hp100_init_rxpdl(dev, ringptr, pageptr);
1247 /* Initialise Tx Ring */
1248 lp->txrcommit = 0;
1249 ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]);
1250 for (i = MAX_TX_PDL - 1; i >= 0; i--) {
1251 lp->txring[i].next = ringptr;
1252 ringptr = &(lp->txring[i]);
1253 pageptr += hp100_init_txpdl(dev, ringptr, pageptr);
1259 /* These functions "format" the entries in the pdl structure */
1260 /* They return how much memory the fragments need. */
1261 static int hp100_init_rxpdl(struct net_device *dev,
1262 register hp100_ring_t * ringptr,
1263 register u32 * pdlptr)
1265 /* pdlptr is starting address for this pdl */
1267 if (0 != (((unsigned) pdlptr) & 0xf))
1268 printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%x.\n",
1269 dev->name, (unsigned) pdlptr);
1271 ringptr->pdl = pdlptr + 1;
1272 ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr + 1);
1273 ringptr->skb = (void *) NULL;
1276 * Write address and length of first PDL Fragment (which is used for
1277 * storing the RX-Header
1278 * We use the 4 bytes _before_ the PDH in the pdl memory area to
1279 * store this information. (PDH is at offset 0x04)
1281 /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */
1283 *(pdlptr + 2) = (u_int) virt_to_whatever(dev, pdlptr); /* Address Frag 1 */
1284 *(pdlptr + 3) = 4; /* Length Frag 1 */
1286 return ((((MAX_RX_FRAG * 2 + 2) + 3) / 4) * 4);
1290 static int hp100_init_txpdl(struct net_device *dev,
1291 register hp100_ring_t * ringptr,
1292 register u32 * pdlptr)
1294 if (0 != (((unsigned) pdlptr) & 0xf))
1295 printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%x.\n", dev->name, (unsigned) pdlptr);
1297 ringptr->pdl = pdlptr; /* +1; */
1298 ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr); /* +1 */
1299 ringptr->skb = (void *) NULL;
1301 return ((((MAX_TX_FRAG * 2 + 2) + 3) / 4) * 4);
1305 * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes
1306 * for possible odd word alignment rounding up to next dword and set PDL
1307 * address for fragment#2
1308 * Returns: 0 if unable to allocate skb_buff
1309 * 1 if successful
1311 static int hp100_build_rx_pdl(hp100_ring_t * ringptr,
1312 struct net_device *dev)
1314 #ifdef HP100_DEBUG_B
1315 int ioaddr = dev->base_addr;
1316 #endif
1317 #ifdef HP100_DEBUG_BM
1318 u_int *p;
1319 #endif
1321 #ifdef HP100_DEBUG_B
1322 hp100_outw(0x4207, TRACE);
1323 printk("hp100: %s: build rx pdl\n", dev->name);
1324 #endif
1326 /* Allocate skb buffer of maximum size */
1327 /* Note: This depends on the alloc_skb functions allocating more
1328 * space than requested, i.e. aligning to 16bytes */
1330 ringptr->skb = dev_alloc_skb(((MAX_ETHER_SIZE + 2 + 3) / 4) * 4);
1332 if (NULL != ringptr->skb) {
1334 * Reserve 2 bytes at the head of the buffer to land the IP header
1335 * on a long word boundary (According to the Network Driver section
1336 * in the Linux KHG, this should help to increase performance.)
1338 skb_reserve(ringptr->skb, 2);
1340 ringptr->skb->dev = dev;
1341 ringptr->skb->data = (u_char *) skb_put(ringptr->skb, MAX_ETHER_SIZE);
1343 /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */
1344 /* Note: 1st Fragment is used for the 4 byte packet status
1345 * (receive header). Its PDL entries are set up by init_rxpdl. So
1346 * here we only have to set up the PDL fragment entries for the data
1347 * part. Those 4 bytes will be stored in the DMA memory region
1348 * directly before the PDL.
1350 #ifdef HP100_DEBUG_BM
1351 printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n",
1352 dev->name, (u_int) ringptr->pdl,
1353 ((MAX_ETHER_SIZE + 2 + 3) / 4) * 4,
1354 (unsigned int) ringptr->skb->data);
1355 #endif
1357 /* Conversion to new PCI API : map skbuf data to PCI bus.
1358 * Doc says it's OK for EISA as well - Jean II */
1359 ringptr->pdl[0] = 0x00020000; /* Write PDH */
1360 ringptr->pdl[3] = ((u_int) pci_map_single(((struct hp100_private *) (dev->priv))->pci_dev, ringptr->skb->data, MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE));
1361 ringptr->pdl[4] = MAX_ETHER_SIZE; /* Length of Data */
1363 #ifdef HP100_DEBUG_BM
1364 for (p = (ringptr->pdl); p < (ringptr->pdl + 5); p++)
1365 printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n", dev->name, (u_int) p, (u_int) * p);
1366 #endif
1367 return (1);
1369 /* else: */
1370 /* alloc_skb failed (no memory) -> still can receive the header
1371 * fragment into PDL memory. make PDL safe by clearing msgptr and
1372 * making the PDL only 1 fragment (i.e. the 4 byte packet status)
1374 #ifdef HP100_DEBUG_BM
1375 printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n", dev->name, (u_int) ringptr->pdl);
1376 #endif
1378 ringptr->pdl[0] = 0x00010000; /* PDH: Count=1 Fragment */
1380 return (0);
1384 * hp100_rxfill - attempt to fill the Rx Ring will empty skb's
1386 * Makes assumption that skb's are always contiguous memory areas and
1387 * therefore PDLs contain only 2 physical fragments.
1388 * - While the number of Rx PDLs with buffers is less than maximum
1389 * a. Get a maximum packet size skb
1390 * b. Put the physical address of the buffer into the PDL.
1391 * c. Output physical address of PDL to adapter.
1393 static void hp100_rxfill(struct net_device *dev)
1395 int ioaddr = dev->base_addr;
1397 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1398 hp100_ring_t *ringptr;
1400 #ifdef HP100_DEBUG_B
1401 hp100_outw(0x4208, TRACE);
1402 printk("hp100: %s: rxfill\n", dev->name);
1403 #endif
1405 hp100_page(PERFORMANCE);
1407 while (lp->rxrcommit < MAX_RX_PDL) {
1409 ** Attempt to get a buffer and build a Rx PDL.
1411 ringptr = lp->rxrtail;
1412 if (0 == hp100_build_rx_pdl(ringptr, dev)) {
1413 return; /* None available, return */
1416 /* Hand this PDL over to the card */
1417 /* Note: This needs performance page selected! */
1418 #ifdef HP100_DEBUG_BM
1419 printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n",
1420 dev->name, lp->rxrcommit, (u_int) ringptr->pdl,
1421 (u_int) ringptr->pdl_paddr, (u_int) ringptr->pdl[3]);
1422 #endif
1424 hp100_outl((u32) ringptr->pdl_paddr, RX_PDA);
1426 lp->rxrcommit += 1;
1427 lp->rxrtail = ringptr->next;
1432 * BM_shutdown - shutdown bus mastering and leave chip in reset state
1435 static void hp100_BM_shutdown(struct net_device *dev)
1437 int ioaddr = dev->base_addr;
1438 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1439 unsigned long time;
1441 #ifdef HP100_DEBUG_B
1442 hp100_outw(0x4209, TRACE);
1443 printk("hp100: %s: bm shutdown\n", dev->name);
1444 #endif
1446 hp100_page(PERFORMANCE);
1447 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
1448 hp100_outw(0xffff, IRQ_STATUS); /* Ack all ints */
1450 /* Ensure Interrupts are off */
1451 hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
1453 /* Disable all MAC activity */
1454 hp100_page(MAC_CTRL);
1455 hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */
1457 /* If cascade MMU is not already in reset */
1458 if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) {
1459 /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so
1460 * MMU pointers will not be reset out from underneath
1462 hp100_page(MAC_CTRL);
1463 for (time = 0; time < 5000; time++) {
1464 if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE))
1465 break;
1468 /* Shutdown algorithm depends on the generation of Cascade */
1469 if (lp->chip == HP100_CHIPID_LASSEN) { /* ETR shutdown/reset */
1470 /* Disable Busmaster mode and wait for bit to go to zero. */
1471 hp100_page(HW_MAP);
1472 hp100_andb(~HP100_BM_MASTER, BM);
1473 /* 100 ms timeout */
1474 for (time = 0; time < 32000; time++) {
1475 if (0 == (hp100_inb(BM) & HP100_BM_MASTER))
1476 break;
1478 } else { /* Shasta or Rainier Shutdown/Reset */
1479 /* To ensure all bus master inloading activity has ceased,
1480 * wait for no Rx PDAs or no Rx packets on card.
1482 hp100_page(PERFORMANCE);
1483 /* 100 ms timeout */
1484 for (time = 0; time < 10000; time++) {
1485 /* RX_PDL: PDLs not executed. */
1486 /* RX_PKT_CNT: RX'd packets on card. */
1487 if ((hp100_inb(RX_PDL) == 0) && (hp100_inb(RX_PKT_CNT) == 0))
1488 break;
1491 if (time >= 10000)
1492 printk("hp100: %s: BM shutdown error.\n", dev->name);
1494 /* To ensure all bus master outloading activity has ceased,
1495 * wait until the Tx PDA count goes to zero or no more Tx space
1496 * available in the Tx region of the card.
1498 /* 100 ms timeout */
1499 for (time = 0; time < 10000; time++) {
1500 if ((0 == hp100_inb(TX_PKT_CNT)) &&
1501 (0 != (hp100_inb(TX_MEM_FREE) & HP100_AUTO_COMPARE)))
1502 break;
1505 /* Disable Busmaster mode */
1506 hp100_page(HW_MAP);
1507 hp100_andb(~HP100_BM_MASTER, BM);
1508 } /* end of shutdown procedure for non-etr parts */
1510 hp100_cascade_reset(dev, 1);
1512 hp100_page(PERFORMANCE);
1513 /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
1514 /* Busmaster mode should be shut down now. */
1517 static int hp100_check_lan(struct net_device *dev)
1519 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1521 if (lp->lan_type < 0) { /* no LAN type detected yet? */
1522 hp100_stop_interface(dev);
1523 if ((lp->lan_type = hp100_sense_lan(dev)) < 0) {
1524 printk("hp100: %s: no connection found - check wire\n", dev->name);
1525 hp100_start_interface(dev); /* 10Mb/s RX packets maybe handled */
1526 return -EIO;
1528 if (lp->lan_type == HP100_LAN_100)
1529 lp->hub_status = hp100_login_to_vg_hub(dev, 0); /* relogin */
1530 hp100_start_interface(dev);
1532 return 0;
1536 * transmit functions
1539 /* tx function for busmaster mode */
1540 static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev)
1542 unsigned long flags;
1543 int i, ok_flag;
1544 int ioaddr = dev->base_addr;
1545 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1546 hp100_ring_t *ringptr;
1548 #ifdef HP100_DEBUG_B
1549 hp100_outw(0x4210, TRACE);
1550 printk("hp100: %s: start_xmit_bm\n", dev->name);
1551 #endif
1553 if (skb == NULL) {
1554 return 0;
1557 if (skb->len <= 0)
1558 return 0;
1560 if (skb->len < ETH_ZLEN && lp->chip == HP100_CHIPID_SHASTA) {
1561 skb = skb_padto(skb, ETH_ZLEN);
1562 if (skb == NULL)
1563 return 0;
1566 /* Get Tx ring tail pointer */
1567 if (lp->txrtail->next == lp->txrhead) {
1568 /* No memory. */
1569 #ifdef HP100_DEBUG
1570 printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name);
1571 #endif
1572 /* not waited long enough since last tx? */
1573 if (jiffies - dev->trans_start < HZ)
1574 return -EAGAIN;
1576 if (hp100_check_lan(dev))
1577 return -EIO;
1579 if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) {
1580 /* we have a 100Mb/s adapter but it isn't connected to hub */
1581 printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
1582 hp100_stop_interface(dev);
1583 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1584 hp100_start_interface(dev);
1585 } else {
1586 spin_lock_irqsave(&lp->lock, flags);
1587 hp100_ints_off(); /* Useful ? Jean II */
1588 i = hp100_sense_lan(dev);
1589 hp100_ints_on();
1590 spin_unlock_irqrestore(&lp->lock, flags);
1591 if (i == HP100_LAN_ERR)
1592 printk("hp100: %s: link down detected\n", dev->name);
1593 else if (lp->lan_type != i) { /* cable change! */
1594 /* it's very hard - all network settings must be changed!!! */
1595 printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name);
1596 lp->lan_type = i;
1597 hp100_stop_interface(dev);
1598 if (lp->lan_type == HP100_LAN_100)
1599 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1600 hp100_start_interface(dev);
1601 } else {
1602 printk("hp100: %s: interface reset\n", dev->name);
1603 hp100_stop_interface(dev);
1604 if (lp->lan_type == HP100_LAN_100)
1605 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1606 hp100_start_interface(dev);
1610 dev->trans_start = jiffies;
1611 return -EAGAIN;
1615 * we have to turn int's off before modifying this, otherwise
1616 * a tx_pdl_cleanup could occur at the same time
1618 spin_lock_irqsave(&lp->lock, flags);
1619 ringptr = lp->txrtail;
1620 lp->txrtail = ringptr->next;
1622 /* Check whether packet has minimal packet size */
1623 ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
1624 i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
1626 ringptr->skb = skb;
1627 ringptr->pdl[0] = ((1 << 16) | i); /* PDH: 1 Fragment & length */
1628 if (lp->chip == HP100_CHIPID_SHASTA) {
1629 /* TODO:Could someone who has the EISA card please check if this works? */
1630 ringptr->pdl[2] = i;
1631 } else { /* Lassen */
1632 /* In the PDL, don't use the padded size but the real packet size: */
1633 ringptr->pdl[2] = skb->len; /* 1st Frag: Length of frag */
1635 /* Conversion to new PCI API : map skbuf data to PCI bus.
1636 * Doc says it's OK for EISA as well - Jean II */
1637 ringptr->pdl[1] = ((u32) pci_map_single(lp->pci_dev, skb->data, ringptr->pdl[2], PCI_DMA_TODEVICE)); /* 1st Frag: Adr. of data */
1639 /* Hand this PDL to the card. */
1640 hp100_outl(ringptr->pdl_paddr, TX_PDA_L); /* Low Prio. Queue */
1642 lp->txrcommit++;
1643 spin_unlock_irqrestore(&lp->lock, flags);
1645 /* Update statistics */
1646 lp->stats.tx_packets++;
1647 lp->stats.tx_bytes += skb->len;
1648 dev->trans_start = jiffies;
1650 return 0;
1654 /* clean_txring checks if packets have been sent by the card by reading
1655 * the TX_PDL register from the performance page and comparing it to the
1656 * number of commited packets. It then frees the skb's of the packets that
1657 * obviously have been sent to the network.
1659 * Needs the PERFORMANCE page selected.
1661 static void hp100_clean_txring(struct net_device *dev)
1663 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1664 int ioaddr = dev->base_addr;
1665 int donecount;
1667 #ifdef HP100_DEBUG_B
1668 hp100_outw(0x4211, TRACE);
1669 printk("hp100: %s: clean txring\n", dev->name);
1670 #endif
1672 /* How many PDLs have been transmitted? */
1673 donecount = (lp->txrcommit) - hp100_inb(TX_PDL);
1675 #ifdef HP100_DEBUG
1676 if (donecount > MAX_TX_PDL)
1677 printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n", dev->name);
1678 #endif
1680 for (; 0 != donecount; donecount--) {
1681 #ifdef HP100_DEBUG_BM
1682 printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n",
1683 dev->name, (u_int) lp->txrhead->skb->data,
1684 lp->txrcommit, hp100_inb(TX_PDL), donecount);
1685 #endif
1686 /* Conversion to new PCI API : NOP */
1687 pci_unmap_single(lp->pci_dev, (dma_addr_t) lp->txrhead->pdl[1], lp->txrhead->pdl[2], PCI_DMA_TODEVICE);
1688 dev_kfree_skb_any(lp->txrhead->skb);
1689 lp->txrhead->skb = (void *) NULL;
1690 lp->txrhead = lp->txrhead->next;
1691 lp->txrcommit--;
1695 /* tx function for slave modes */
1696 static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev)
1698 unsigned long flags;
1699 int i, ok_flag;
1700 int ioaddr = dev->base_addr;
1701 u_short val;
1702 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1704 #ifdef HP100_DEBUG_B
1705 hp100_outw(0x4212, TRACE);
1706 printk("hp100: %s: start_xmit\n", dev->name);
1707 #endif
1709 if (skb == NULL) {
1710 return 0;
1713 if (skb->len <= 0)
1714 return 0;
1716 if (hp100_check_lan(dev))
1717 return -EIO;
1719 /* If there is not enough free memory on the card... */
1720 i = hp100_inl(TX_MEM_FREE) & 0x7fffffff;
1721 if (!(((i / 2) - 539) > (skb->len + 16) && (hp100_inb(TX_PKT_CNT) < 255))) {
1722 #ifdef HP100_DEBUG
1723 printk("hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i);
1724 #endif
1725 /* not waited long enough since last failed tx try? */
1726 if (jiffies - dev->trans_start < HZ) {
1727 #ifdef HP100_DEBUG
1728 printk("hp100: %s: trans_start timing problem\n",
1729 dev->name);
1730 #endif
1731 return -EAGAIN;
1733 if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) {
1734 /* we have a 100Mb/s adapter but it isn't connected to hub */
1735 printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
1736 hp100_stop_interface(dev);
1737 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1738 hp100_start_interface(dev);
1739 } else {
1740 spin_lock_irqsave(&lp->lock, flags);
1741 hp100_ints_off(); /* Useful ? Jean II */
1742 i = hp100_sense_lan(dev);
1743 hp100_ints_on();
1744 spin_unlock_irqrestore(&lp->lock, flags);
1745 if (i == HP100_LAN_ERR)
1746 printk("hp100: %s: link down detected\n", dev->name);
1747 else if (lp->lan_type != i) { /* cable change! */
1748 /* it's very hard - all network setting must be changed!!! */
1749 printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name);
1750 lp->lan_type = i;
1751 hp100_stop_interface(dev);
1752 if (lp->lan_type == HP100_LAN_100)
1753 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1754 hp100_start_interface(dev);
1755 } else {
1756 printk("hp100: %s: interface reset\n", dev->name);
1757 hp100_stop_interface(dev);
1758 if (lp->lan_type == HP100_LAN_100)
1759 lp->hub_status = hp100_login_to_vg_hub(dev, 0);
1760 hp100_start_interface(dev);
1761 mdelay(1);
1764 dev->trans_start = jiffies;
1765 return -EAGAIN;
1768 for (i = 0; i < 6000 && (hp100_inb(OPTION_MSW) & HP100_TX_CMD); i++) {
1769 #ifdef HP100_DEBUG_TX
1770 printk("hp100: %s: start_xmit: busy\n", dev->name);
1771 #endif
1774 spin_lock_irqsave(&lp->lock, flags);
1775 hp100_ints_off();
1776 val = hp100_inw(IRQ_STATUS);
1777 /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set
1778 * when the current packet being transmitted on the wire is completed. */
1779 hp100_outw(HP100_TX_COMPLETE, IRQ_STATUS);
1780 #ifdef HP100_DEBUG_TX
1781 printk("hp100: %s: start_xmit: irq_status=0x%.4x, irqmask=0x%.4x, len=%d\n",
1782 dev->name, val, hp100_inw(IRQ_MASK), (int) skb->len);
1783 #endif
1785 ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
1786 i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
1788 hp100_outw(i, DATA32); /* tell card the total packet length */
1789 hp100_outw(i, FRAGMENT_LEN); /* and first/only fragment length */
1791 if (lp->mode == 2) { /* memory mapped */
1792 if (lp->mem_ptr_virt) { /* high pci memory was remapped */
1793 /* Note: The J2585B needs alignment to 32bits here! */
1794 memcpy_toio(lp->mem_ptr_virt, skb->data, (skb->len + 3) & ~3);
1795 if (!ok_flag)
1796 memset_io(lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len);
1797 } else {
1798 /* Note: The J2585B needs alignment to 32bits here! */
1799 isa_memcpy_toio(lp->mem_ptr_phys, skb->data, (skb->len + 3) & ~3);
1800 if (!ok_flag)
1801 isa_memset_io(lp->mem_ptr_phys, 0, HP100_MIN_PACKET_SIZE - skb->len);
1803 } else { /* programmed i/o */
1804 outsl(ioaddr + HP100_REG_DATA32, skb->data,
1805 (skb->len + 3) >> 2);
1806 if (!ok_flag)
1807 for (i = (skb->len + 3) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4)
1808 hp100_outl(0, DATA32);
1811 hp100_outb(HP100_TX_CMD | HP100_SET_LB, OPTION_MSW); /* send packet */
1813 lp->stats.tx_packets++;
1814 lp->stats.tx_bytes += skb->len;
1815 dev->trans_start = jiffies;
1816 hp100_ints_on();
1817 spin_unlock_irqrestore(&lp->lock, flags);
1819 dev_kfree_skb_any(skb);
1821 #ifdef HP100_DEBUG_TX
1822 printk("hp100: %s: start_xmit: end\n", dev->name);
1823 #endif
1825 return 0;
1830 * Receive Function (Non-Busmaster mode)
1831 * Called when an "Receive Packet" interrupt occurs, i.e. the receive
1832 * packet counter is non-zero.
1833 * For non-busmaster, this function does the whole work of transfering
1834 * the packet to the host memory and then up to higher layers via skb
1835 * and netif_rx.
1838 static void hp100_rx(struct net_device *dev)
1840 int packets, pkt_len;
1841 int ioaddr = dev->base_addr;
1842 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1843 u_int header;
1844 struct sk_buff *skb;
1846 #ifdef DEBUG_B
1847 hp100_outw(0x4213, TRACE);
1848 printk("hp100: %s: rx\n", dev->name);
1849 #endif
1851 /* First get indication of received lan packet */
1852 /* RX_PKT_CND indicates the number of packets which have been fully */
1853 /* received onto the card but have not been fully transferred of the card */
1854 packets = hp100_inb(RX_PKT_CNT);
1855 #ifdef HP100_DEBUG_RX
1856 if (packets > 1)
1857 printk("hp100: %s: rx: waiting packets = %d\n", dev->name, packets);
1858 #endif
1860 while (packets-- > 0) {
1861 /* If ADV_NXT_PKT is still set, we have to wait until the card has */
1862 /* really advanced to the next packet. */
1863 for (pkt_len = 0; pkt_len < 6000 && (hp100_inb(OPTION_MSW) & HP100_ADV_NXT_PKT); pkt_len++) {
1864 #ifdef HP100_DEBUG_RX
1865 printk ("hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets);
1866 #endif
1869 /* First we get the header, which contains information about the */
1870 /* actual length of the received packet. */
1871 if (lp->mode == 2) { /* memory mapped mode */
1872 if (lp->mem_ptr_virt) /* if memory was remapped */
1873 header = readl(lp->mem_ptr_virt);
1874 else
1875 header = isa_readl(lp->mem_ptr_phys);
1876 } else /* programmed i/o */
1877 header = hp100_inl(DATA32);
1879 pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3;
1881 #ifdef HP100_DEBUG_RX
1882 printk("hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n",
1883 dev->name, header & HP100_PKT_LEN_MASK,
1884 (header >> 16) & 0xfff8, (header >> 16) & 7);
1885 #endif
1887 /* Now we allocate the skb and transfer the data into it. */
1888 skb = dev_alloc_skb(pkt_len+2);
1889 if (skb == NULL) { /* Not enough memory->drop packet */
1890 #ifdef HP100_DEBUG
1891 printk("hp100: %s: rx: couldn't allocate a sk_buff of size %d\n",
1892 dev->name, pkt_len);
1893 #endif
1894 lp->stats.rx_dropped++;
1895 } else { /* skb successfully allocated */
1897 u_char *ptr;
1899 skb_reserve(skb,2);
1900 skb->dev = dev;
1902 /* ptr to start of the sk_buff data area */
1903 skb_put(skb, pkt_len);
1904 ptr = skb->data;
1906 /* Now transfer the data from the card into that area */
1907 if (lp->mode == 2) {
1908 if (lp->mem_ptr_virt)
1909 memcpy_fromio(ptr, lp->mem_ptr_virt,pkt_len);
1910 /* Note alignment to 32bit transfers */
1911 else
1912 isa_memcpy_fromio(ptr, lp->mem_ptr_phys, pkt_len);
1913 } else /* io mapped */
1914 insl(ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2);
1916 skb->protocol = eth_type_trans(skb, dev);
1918 #ifdef HP100_DEBUG_RX
1919 printk("hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1920 dev->name, ptr[0], ptr[1], ptr[2], ptr[3],
1921 ptr[4], ptr[5], ptr[6], ptr[7], ptr[8],
1922 ptr[9], ptr[10], ptr[11]);
1923 #endif
1924 netif_rx(skb);
1925 dev->last_rx = jiffies;
1926 lp->stats.rx_packets++;
1927 lp->stats.rx_bytes += pkt_len;
1930 /* Indicate the card that we have got the packet */
1931 hp100_outb(HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW);
1933 switch (header & 0x00070000) {
1934 case (HP100_MULTI_ADDR_HASH << 16):
1935 case (HP100_MULTI_ADDR_NO_HASH << 16):
1936 lp->stats.multicast++;
1937 break;
1939 } /* end of while(there are packets) loop */
1940 #ifdef HP100_DEBUG_RX
1941 printk("hp100_rx: %s: end\n", dev->name);
1942 #endif
1946 * Receive Function for Busmaster Mode
1948 static void hp100_rx_bm(struct net_device *dev)
1950 int ioaddr = dev->base_addr;
1951 struct hp100_private *lp = (struct hp100_private *) dev->priv;
1952 hp100_ring_t *ptr;
1953 u_int header;
1954 int pkt_len;
1956 #ifdef HP100_DEBUG_B
1957 hp100_outw(0x4214, TRACE);
1958 printk("hp100: %s: rx_bm\n", dev->name);
1959 #endif
1961 #ifdef HP100_DEBUG
1962 if (0 == lp->rxrcommit) {
1963 printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name);
1964 return;
1965 } else
1966 /* RX_PKT_CNT states how many PDLs are currently formatted and available to
1967 * the cards BM engine */
1968 if ((hp100_inw(RX_PKT_CNT) & 0x00ff) >= lp->rxrcommit) {
1969 printk("hp100: %s: More packets received than commited? RX_PKT_CNT=0x%x, commit=0x%x\n",
1970 dev->name, hp100_inw(RX_PKT_CNT) & 0x00ff,
1971 lp->rxrcommit);
1972 return;
1974 #endif
1976 while ((lp->rxrcommit > hp100_inb(RX_PDL))) {
1978 * The packet was received into the pdl pointed to by lp->rxrhead (
1979 * the oldest pdl in the ring
1982 /* First we get the header, which contains information about the */
1983 /* actual length of the received packet. */
1985 ptr = lp->rxrhead;
1987 header = *(ptr->pdl - 1);
1988 pkt_len = (header & HP100_PKT_LEN_MASK);
1990 /* Conversion to new PCI API : NOP */
1991 pci_unmap_single(lp->pci_dev, (dma_addr_t) ptr->pdl[3], MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE);
1993 #ifdef HP100_DEBUG_BM
1994 printk("hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n",
1995 dev->name, (u_int) (ptr->pdl - 1), (u_int) header,
1996 pkt_len, (header >> 16) & 0xfff8, (header >> 16) & 7);
1997 printk("hp100: %s: RX_PDL_COUNT:0x%x TX_PDL_COUNT:0x%x, RX_PKT_CNT=0x%x PDH=0x%x, Data@0x%x len=0x%x\n",
1998 dev->name, hp100_inb(RX_PDL), hp100_inb(TX_PDL),
1999 hp100_inb(RX_PKT_CNT), (u_int) * (ptr->pdl),
2000 (u_int) * (ptr->pdl + 3), (u_int) * (ptr->pdl + 4));
2001 #endif
2003 if ((pkt_len >= MIN_ETHER_SIZE) &&
2004 (pkt_len <= MAX_ETHER_SIZE)) {
2005 if (ptr->skb == NULL) {
2006 printk("hp100: %s: rx_bm: skb null\n", dev->name);
2007 /* can happen if we only allocated room for the pdh due to memory shortage. */
2008 lp->stats.rx_dropped++;
2009 } else {
2010 skb_trim(ptr->skb, pkt_len); /* Shorten it */
2011 ptr->skb->protocol =
2012 eth_type_trans(ptr->skb, dev);
2014 netif_rx(ptr->skb); /* Up and away... */
2016 dev->last_rx = jiffies;
2017 lp->stats.rx_packets++;
2018 lp->stats.rx_bytes += pkt_len;
2021 switch (header & 0x00070000) {
2022 case (HP100_MULTI_ADDR_HASH << 16):
2023 case (HP100_MULTI_ADDR_NO_HASH << 16):
2024 lp->stats.multicast++;
2025 break;
2027 } else {
2028 #ifdef HP100_DEBUG
2029 printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n", dev->name, pkt_len);
2030 #endif
2031 if (ptr->skb != NULL)
2032 dev_kfree_skb_any(ptr->skb);
2033 lp->stats.rx_errors++;
2036 lp->rxrhead = lp->rxrhead->next;
2038 /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */
2039 if (0 == hp100_build_rx_pdl(lp->rxrtail, dev)) {
2040 /* No space for skb, header can still be received. */
2041 #ifdef HP100_DEBUG
2042 printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name);
2043 #endif
2044 return;
2045 } else { /* successfully allocated new PDL - put it in ringlist at tail. */
2046 hp100_outl((u32) lp->rxrtail->pdl_paddr, RX_PDA);
2047 lp->rxrtail = lp->rxrtail->next;
2054 * statistics
2056 static hp100_stats_t *hp100_get_stats(struct net_device *dev)
2058 unsigned long flags;
2059 int ioaddr = dev->base_addr;
2060 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2062 #ifdef HP100_DEBUG_B
2063 hp100_outw(0x4215, TRACE);
2064 #endif
2066 spin_lock_irqsave(&lp->lock, flags);
2067 hp100_ints_off(); /* Useful ? Jean II */
2068 hp100_update_stats(dev);
2069 hp100_ints_on();
2070 spin_unlock_irqrestore(&lp->lock, flags);
2071 return &(lp->stats);
2074 static void hp100_update_stats(struct net_device *dev)
2076 int ioaddr = dev->base_addr;
2077 u_short val;
2078 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2080 #ifdef HP100_DEBUG_B
2081 hp100_outw(0x4216, TRACE);
2082 printk("hp100: %s: update-stats\n", dev->name);
2083 #endif
2085 /* Note: Statistics counters clear when read. */
2086 hp100_page(MAC_CTRL);
2087 val = hp100_inw(DROPPED) & 0x0fff;
2088 lp->stats.rx_errors += val;
2089 lp->stats.rx_over_errors += val;
2090 val = hp100_inb(CRC);
2091 lp->stats.rx_errors += val;
2092 lp->stats.rx_crc_errors += val;
2093 val = hp100_inb(ABORT);
2094 lp->stats.tx_errors += val;
2095 lp->stats.tx_aborted_errors += val;
2096 hp100_page(PERFORMANCE);
2099 static void hp100_misc_interrupt(struct net_device *dev)
2101 #ifdef HP100_DEBUG_B
2102 int ioaddr = dev->base_addr;
2103 #endif
2104 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2106 #ifdef HP100_DEBUG_B
2107 int ioaddr = dev->base_addr;
2108 hp100_outw(0x4216, TRACE);
2109 printk("hp100: %s: misc_interrupt\n", dev->name);
2110 #endif
2112 /* Note: Statistics counters clear when read. */
2113 lp->stats.rx_errors++;
2114 lp->stats.tx_errors++;
2117 static void hp100_clear_stats(struct hp100_private *lp, int ioaddr)
2119 unsigned long flags;
2121 #ifdef HP100_DEBUG_B
2122 hp100_outw(0x4217, TRACE);
2123 printk("hp100: %s: clear_stats\n", dev->name);
2124 #endif
2126 spin_lock_irqsave(&lp->lock, flags);
2127 hp100_page(MAC_CTRL); /* get all statistics bytes */
2128 hp100_inw(DROPPED);
2129 hp100_inb(CRC);
2130 hp100_inb(ABORT);
2131 hp100_page(PERFORMANCE);
2132 spin_unlock_irqrestore(&lp->lock, flags);
2137 * multicast setup
2141 * Set or clear the multicast filter for this adapter.
2144 static void hp100_set_multicast_list(struct net_device *dev)
2146 unsigned long flags;
2147 int ioaddr = dev->base_addr;
2148 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2150 #ifdef HP100_DEBUG_B
2151 hp100_outw(0x4218, TRACE);
2152 printk("hp100: %s: set_mc_list\n", dev->name);
2153 #endif
2155 spin_lock_irqsave(&lp->lock, flags);
2156 hp100_ints_off();
2157 hp100_page(MAC_CTRL);
2158 hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */
2160 if (dev->flags & IFF_PROMISC) {
2161 lp->mac2_mode = HP100_MAC2MODE6; /* promiscuous mode = get all good */
2162 lp->mac1_mode = HP100_MAC1MODE6; /* packets on the net */
2163 memset(&lp->hash_bytes, 0xff, 8);
2164 } else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
2165 lp->mac2_mode = HP100_MAC2MODE5; /* multicast mode = get packets for */
2166 lp->mac1_mode = HP100_MAC1MODE5; /* me, broadcasts and all multicasts */
2167 #ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */
2168 if (dev->flags & IFF_ALLMULTI) {
2169 /* set hash filter to receive all multicast packets */
2170 memset(&lp->hash_bytes, 0xff, 8);
2171 } else {
2172 int i, j, idx;
2173 u_char *addrs;
2174 struct dev_mc_list *dmi;
2176 memset(&lp->hash_bytes, 0x00, 8);
2177 #ifdef HP100_DEBUG
2178 printk("hp100: %s: computing hash filter - mc_count = %i\n", dev->name, dev->mc_count);
2179 #endif
2180 for (i = 0, dmi = dev->mc_list; i < dev->mc_count; i++, dmi = dmi->next) {
2181 addrs = dmi->dmi_addr;
2182 if ((*addrs & 0x01) == 0x01) { /* multicast address? */
2183 #ifdef HP100_DEBUG
2184 printk("hp100: %s: multicast = %02x:%02x:%02x:%02x:%02x:%02x, ",
2185 dev->name, addrs[0], addrs[1], addrs[2],
2186 addrs[3], addrs[4], addrs[5]);
2187 #endif
2188 for (j = idx = 0; j < 6; j++) {
2189 idx ^= *addrs++ & 0x3f;
2190 printk(":%02x:", idx);
2192 #ifdef HP100_DEBUG
2193 printk("idx = %i\n", idx);
2194 #endif
2195 lp->hash_bytes[idx >> 3] |= (1 << (idx & 7));
2199 #else
2200 memset(&lp->hash_bytes, 0xff, 8);
2201 #endif
2202 } else {
2203 lp->mac2_mode = HP100_MAC2MODE3; /* normal mode = get packets for me */
2204 lp->mac1_mode = HP100_MAC1MODE3; /* and broadcasts */
2205 memset(&lp->hash_bytes, 0x00, 8);
2208 if (((hp100_inb(MAC_CFG_1) & 0x0f) != lp->mac1_mode) ||
2209 (hp100_inb(MAC_CFG_2) != lp->mac2_mode)) {
2210 int i;
2212 hp100_outb(lp->mac2_mode, MAC_CFG_2);
2213 hp100_andb(HP100_MAC1MODEMASK, MAC_CFG_1); /* clear mac1 mode bits */
2214 hp100_orb(lp->mac1_mode, MAC_CFG_1); /* and set the new mode */
2216 hp100_page(MAC_ADDRESS);
2217 for (i = 0; i < 8; i++)
2218 hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i);
2219 #ifdef HP100_DEBUG
2220 printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2221 dev->name, lp->mac1_mode, lp->mac2_mode,
2222 lp->hash_bytes[0], lp->hash_bytes[1],
2223 lp->hash_bytes[2], lp->hash_bytes[3],
2224 lp->hash_bytes[4], lp->hash_bytes[5],
2225 lp->hash_bytes[6], lp->hash_bytes[7]);
2226 #endif
2228 if (lp->lan_type == HP100_LAN_100) {
2229 #ifdef HP100_DEBUG
2230 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
2231 #endif
2232 lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */
2234 } else {
2235 int i;
2236 u_char old_hash_bytes[8];
2238 hp100_page(MAC_ADDRESS);
2239 for (i = 0; i < 8; i++)
2240 old_hash_bytes[i] = hp100_inb(HASH_BYTE0 + i);
2241 if (memcmp(old_hash_bytes, &lp->hash_bytes, 8)) {
2242 for (i = 0; i < 8; i++)
2243 hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i);
2244 #ifdef HP100_DEBUG
2245 printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2246 dev->name, lp->hash_bytes[0],
2247 lp->hash_bytes[1], lp->hash_bytes[2],
2248 lp->hash_bytes[3], lp->hash_bytes[4],
2249 lp->hash_bytes[5], lp->hash_bytes[6],
2250 lp->hash_bytes[7]);
2251 #endif
2253 if (lp->lan_type == HP100_LAN_100) {
2254 #ifdef HP100_DEBUG
2255 printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
2256 #endif
2257 lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */
2262 hp100_page(MAC_CTRL);
2263 hp100_orb(HP100_RX_EN | HP100_RX_IDLE | /* enable rx */
2264 HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1); /* enable tx */
2266 hp100_page(PERFORMANCE);
2267 hp100_ints_on();
2268 spin_unlock_irqrestore(&lp->lock, flags);
2272 * hardware interrupt handling
2275 static irqreturn_t hp100_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2277 struct net_device *dev = (struct net_device *) dev_id;
2278 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2280 int ioaddr;
2281 u_int val;
2283 if (dev == NULL)
2284 return IRQ_NONE;
2285 ioaddr = dev->base_addr;
2287 spin_lock(&lp->lock);
2289 hp100_ints_off();
2291 #ifdef HP100_DEBUG_B
2292 hp100_outw(0x4219, TRACE);
2293 #endif
2295 /* hp100_page( PERFORMANCE ); */
2296 val = hp100_inw(IRQ_STATUS);
2297 #ifdef HP100_DEBUG_IRQ
2298 printk("hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n",
2299 dev->name, lp->mode, (u_int) val, hp100_inb(RX_PKT_CNT),
2300 hp100_inb(RX_PDL), hp100_inb(TX_PKT_CNT), hp100_inb(TX_PDL));
2301 #endif
2303 if (val == 0) { /* might be a shared interrupt */
2304 spin_unlock(&lp->lock);
2305 hp100_ints_on();
2306 return IRQ_NONE;
2308 /* We're only interested in those interrupts we really enabled. */
2309 /* val &= hp100_inw( IRQ_MASK ); */
2312 * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL
2313 * is considered executed whenever the RX_PDL data structure is no longer
2314 * needed.
2316 if (val & HP100_RX_PDL_FILL_COMPL) {
2317 if (lp->mode == 1)
2318 hp100_rx_bm(dev);
2319 else {
2320 printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name);
2325 * The RX_PACKET interrupt is set, when the receive packet counter is
2326 * non zero. We use this interrupt for receiving in slave mode. In
2327 * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill
2328 * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then
2329 * we somehow have missed a rx_pdl_fill_compl interrupt.
2332 if (val & HP100_RX_PACKET) { /* Receive Packet Counter is non zero */
2333 if (lp->mode != 1) /* non busmaster */
2334 hp100_rx(dev);
2335 else if (!(val & HP100_RX_PDL_FILL_COMPL)) {
2336 /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt? */
2337 hp100_rx_bm(dev);
2342 * Ack. that we have noticed the interrupt and thereby allow next one.
2343 * Note that this is now done after the slave rx function, since first
2344 * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt
2345 * on the J2573.
2347 hp100_outw(val, IRQ_STATUS);
2350 * RX_ERROR is set when a packet is dropped due to no memory resources on
2351 * the card or when a RCV_ERR occurs.
2352 * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists
2353 * only in the 802.3 MAC and happens when 16 collisions occur during a TX
2355 if (val & (HP100_TX_ERROR | HP100_RX_ERROR)) {
2356 #ifdef HP100_DEBUG_IRQ
2357 printk("hp100: %s: TX/RX Error IRQ\n", dev->name);
2358 #endif
2359 hp100_update_stats(dev);
2360 if (lp->mode == 1) {
2361 hp100_rxfill(dev);
2362 hp100_clean_txring(dev);
2367 * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero.
2369 if ((lp->mode == 1) && (val & (HP100_RX_PDA_ZERO)))
2370 hp100_rxfill(dev);
2373 * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire
2374 * is completed
2376 if ((lp->mode == 1) && (val & (HP100_TX_COMPLETE)))
2377 hp100_clean_txring(dev);
2380 * MISC_ERROR is set when either the LAN link goes down or a detected
2381 * bus error occurs.
2383 if (val & HP100_MISC_ERROR) { /* New for J2585B */
2384 #ifdef HP100_DEBUG_IRQ
2385 printk
2386 ("hp100: %s: Misc. Error Interrupt - Check cabling.\n",
2387 dev->name);
2388 #endif
2389 if (lp->mode == 1) {
2390 hp100_clean_txring(dev);
2391 hp100_rxfill(dev);
2393 hp100_misc_interrupt(dev);
2396 spin_unlock(&lp->lock);
2397 hp100_ints_on();
2398 return IRQ_HANDLED;
2402 * some misc functions
2405 static void hp100_start_interface(struct net_device *dev)
2407 unsigned long flags;
2408 int ioaddr = dev->base_addr;
2409 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2411 #ifdef HP100_DEBUG_B
2412 hp100_outw(0x4220, TRACE);
2413 printk("hp100: %s: hp100_start_interface\n", dev->name);
2414 #endif
2416 spin_lock_irqsave(&lp->lock, flags);
2418 /* Ensure the adapter does not want to request an interrupt when */
2419 /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */
2420 hp100_page(PERFORMANCE);
2421 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
2422 hp100_outw(0xffff, IRQ_STATUS); /* ack all IRQs */
2423 hp100_outw(HP100_FAKE_INT | HP100_INT_EN | HP100_RESET_LB,
2424 OPTION_LSW);
2425 /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */
2426 hp100_outw(HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW);
2428 if (lp->mode == 1) {
2429 /* Make sure BM bit is set... */
2430 hp100_page(HW_MAP);
2431 hp100_orb(HP100_BM_MASTER, BM);
2432 hp100_rxfill(dev);
2433 } else if (lp->mode == 2) {
2434 /* Enable memory mapping. Note: Don't do this when busmaster. */
2435 hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW);
2438 hp100_page(PERFORMANCE);
2439 hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
2440 hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
2442 /* enable a few interrupts: */
2443 if (lp->mode == 1) { /* busmaster mode */
2444 hp100_outw(HP100_RX_PDL_FILL_COMPL |
2445 HP100_RX_PDA_ZERO | HP100_RX_ERROR |
2446 /* HP100_RX_PACKET | */
2447 /* HP100_RX_EARLY_INT | */ HP100_SET_HB |
2448 /* HP100_TX_PDA_ZERO | */
2449 HP100_TX_COMPLETE |
2450 /* HP100_MISC_ERROR | */
2451 HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK);
2452 } else {
2453 hp100_outw(HP100_RX_PACKET |
2454 HP100_RX_ERROR | HP100_SET_HB |
2455 HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK);
2458 /* Note : before hp100_set_multicast_list(), because it will play with
2459 * spinlock itself... Jean II */
2460 spin_unlock_irqrestore(&lp->lock, flags);
2462 /* Enable MAC Tx and RX, set MAC modes, ... */
2463 hp100_set_multicast_list(dev);
2466 static void hp100_stop_interface(struct net_device *dev)
2468 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2469 int ioaddr = dev->base_addr;
2470 u_int val;
2472 #ifdef HP100_DEBUG_B
2473 printk("hp100: %s: hp100_stop_interface\n", dev->name);
2474 hp100_outw(0x4221, TRACE);
2475 #endif
2477 if (lp->mode == 1)
2478 hp100_BM_shutdown(dev);
2479 else {
2480 /* Note: MMAP_DIS will be reenabled by start_interface */
2481 hp100_outw(HP100_INT_EN | HP100_RESET_LB |
2482 HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB,
2483 OPTION_LSW);
2484 val = hp100_inw(OPTION_LSW);
2486 hp100_page(MAC_CTRL);
2487 hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);
2489 if (!(val & HP100_HW_RST))
2490 return; /* If reset, imm. return ... */
2491 /* ... else: busy wait until idle */
2492 for (val = 0; val < 6000; val++)
2493 if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) {
2494 hp100_page(PERFORMANCE);
2495 return;
2497 printk("hp100: %s: hp100_stop_interface - timeout\n", dev->name);
2498 hp100_page(PERFORMANCE);
2502 static void hp100_load_eeprom(struct net_device *dev, u_short probe_ioaddr)
2504 int i;
2505 int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr;
2507 #ifdef HP100_DEBUG_B
2508 hp100_outw(0x4222, TRACE);
2509 #endif
2511 hp100_page(EEPROM_CTRL);
2512 hp100_andw(~HP100_EEPROM_LOAD, EEPROM_CTRL);
2513 hp100_orw(HP100_EEPROM_LOAD, EEPROM_CTRL);
2514 for (i = 0; i < 10000; i++)
2515 if (!(hp100_inb(OPTION_MSW) & HP100_EE_LOAD))
2516 return;
2517 printk("hp100: %s: hp100_load_eeprom - timeout\n", dev->name);
2520 /* Sense connection status.
2521 * return values: LAN_10 - Connected to 10Mbit/s network
2522 * LAN_100 - Connected to 100Mbit/s network
2523 * LAN_ERR - not connected or 100Mbit/s Hub down
2525 static int hp100_sense_lan(struct net_device *dev)
2527 int ioaddr = dev->base_addr;
2528 u_short val_VG, val_10;
2529 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2531 #ifdef HP100_DEBUG_B
2532 hp100_outw(0x4223, TRACE);
2533 #endif
2535 hp100_page(MAC_CTRL);
2536 val_10 = hp100_inb(10_LAN_CFG_1);
2537 val_VG = hp100_inb(VG_LAN_CFG_1);
2538 hp100_page(PERFORMANCE);
2539 #ifdef HP100_DEBUG
2540 printk("hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n",
2541 dev->name, val_VG, val_10);
2542 #endif
2544 if (val_10 & HP100_LINK_BEAT_ST) /* 10Mb connection is active */
2545 return HP100_LAN_10;
2547 if (val_10 & HP100_AUI_ST) { /* have we BNC or AUI onboard? */
2549 * This can be overriden by dos utility, so if this has no effect,
2550 * perhaps you need to download that utility from HP and set card
2551 * back to "auto detect".
2553 val_10 |= HP100_AUI_SEL | HP100_LOW_TH;
2554 hp100_page(MAC_CTRL);
2555 hp100_outb(val_10, 10_LAN_CFG_1);
2556 hp100_page(PERFORMANCE);
2557 return HP100_LAN_COAX;
2560 if ((lp->id->id == 0x02019F022) ||
2561 (lp->id->id == 0x01042103c) || (lp->id->id == 0x01040103c))
2562 return HP100_LAN_ERR; /* Those cards don't have a 100 Mbit connector */
2564 if (val_VG & HP100_LINK_CABLE_ST) /* Can hear the HUBs tone. */
2565 return HP100_LAN_100;
2566 return HP100_LAN_ERR;
2569 static int hp100_down_vg_link(struct net_device *dev)
2571 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2572 int ioaddr = dev->base_addr;
2573 unsigned long time;
2574 long savelan, newlan;
2576 #ifdef HP100_DEBUG_B
2577 hp100_outw(0x4224, TRACE);
2578 printk("hp100: %s: down_vg_link\n", dev->name);
2579 #endif
2581 hp100_page(MAC_CTRL);
2582 time = jiffies + (HZ / 4);
2583 do {
2584 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
2585 break;
2586 if (!in_interrupt()) {
2587 set_current_state(TASK_INTERRUPTIBLE);
2588 schedule_timeout(1);
2590 } while (time_after(time, jiffies));
2592 if (time_after_eq(jiffies, time)) /* no signal->no logout */
2593 return 0;
2595 /* Drop the VG Link by clearing the link up cmd and load addr. */
2597 hp100_andb(~(HP100_LOAD_ADDR | HP100_LINK_CMD), VG_LAN_CFG_1);
2598 hp100_orb(HP100_VG_SEL, VG_LAN_CFG_1);
2600 /* Conditionally stall for >250ms on Link-Up Status (to go down) */
2601 time = jiffies + (HZ / 2);
2602 do {
2603 if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
2604 break;
2605 if (!in_interrupt()) {
2606 set_current_state(TASK_INTERRUPTIBLE);
2607 schedule_timeout(1);
2609 } while (time_after(time, jiffies));
2611 #ifdef HP100_DEBUG
2612 if (time_after_eq(jiffies, time))
2613 printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name);
2614 #endif
2616 /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */
2617 /* logout under traffic (even though all the status bits are cleared), */
2618 /* do this workaround to get the Rev 1 MAC in its idle state */
2619 if (lp->chip == HP100_CHIPID_LASSEN) {
2620 /* Reset VG MAC to insure it leaves the logoff state even if */
2621 /* the Hub is still emitting tones */
2622 hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1);
2623 udelay(1500); /* wait for >1ms */
2624 hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */
2625 udelay(1500);
2628 /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */
2629 /* to get the VG mac to full reset. This is not req.d with later chips */
2630 /* Note: It will take the between 1 and 2 seconds for the VG mac to be */
2631 /* selected again! This will be left to the connect hub function to */
2632 /* perform if desired. */
2633 if (lp->chip == HP100_CHIPID_LASSEN) {
2634 /* Have to write to 10 and 100VG control registers simultaneously */
2635 savelan = newlan = hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */
2636 newlan &= ~(HP100_VG_SEL << 16);
2637 newlan |= (HP100_DOT3_MAC) << 8;
2638 hp100_andb(~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */
2639 hp100_outl(newlan, 10_LAN_CFG_1);
2641 /* Conditionally stall for 5sec on VG selected. */
2642 time = jiffies + (HZ * 5);
2643 do {
2644 if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST))
2645 break;
2646 if (!in_interrupt()) {
2647 set_current_state(TASK_INTERRUPTIBLE);
2648 schedule_timeout(1);
2650 } while (time_after(time, jiffies));
2652 hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */
2653 hp100_outl(savelan, 10_LAN_CFG_1);
2656 time = jiffies + (3 * HZ); /* Timeout 3s */
2657 do {
2658 if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0)
2659 break;
2660 if (!in_interrupt()) {
2661 set_current_state(TASK_INTERRUPTIBLE);
2662 schedule_timeout(1);
2664 } while (time_after(time, jiffies));
2666 if (time_before_eq(time, jiffies)) {
2667 #ifdef HP100_DEBUG
2668 printk("hp100: %s: down_vg_link: timeout\n", dev->name);
2669 #endif
2670 return -EIO;
2673 time = jiffies + (2 * HZ); /* This seems to take a while.... */
2674 do {
2675 if (!in_interrupt()) {
2676 set_current_state(TASK_INTERRUPTIBLE);
2677 schedule_timeout(1);
2679 } while (time_after(time, jiffies));
2681 return 0;
2684 static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin)
2686 int ioaddr = dev->base_addr;
2687 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2688 u_short val = 0;
2689 unsigned long time;
2690 int startst;
2692 #ifdef HP100_DEBUG_B
2693 hp100_outw(0x4225, TRACE);
2694 printk("hp100: %s: login_to_vg_hub\n", dev->name);
2695 #endif
2697 /* Initiate a login sequence iff VG MAC is enabled and either Load Address
2698 * bit is zero or the force relogin flag is set (e.g. due to MAC address or
2699 * promiscuous mode change)
2701 hp100_page(MAC_CTRL);
2702 startst = hp100_inb(VG_LAN_CFG_1);
2703 if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) {
2704 #ifdef HP100_DEBUG_TRAINING
2705 printk("hp100: %s: Start training\n", dev->name);
2706 #endif
2708 /* Ensure VG Reset bit is 1 (i.e., do not reset) */
2709 hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1);
2711 /* If Lassen AND auto-select-mode AND VG tones were sensed on */
2712 /* entry then temporarily put them into force 100Mbit mode */
2713 if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST))
2714 hp100_andb(~HP100_DOT3_MAC, 10_LAN_CFG_2);
2716 /* Drop the VG link by zeroing Link Up Command and Load Address */
2717 hp100_andb(~(HP100_LINK_CMD /* |HP100_LOAD_ADDR */ ), VG_LAN_CFG_1);
2719 #ifdef HP100_DEBUG_TRAINING
2720 printk("hp100: %s: Bring down the link\n", dev->name);
2721 #endif
2723 /* Wait for link to drop */
2724 time = jiffies + (HZ / 10);
2725 do {
2726 if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
2727 break;
2728 if (!in_interrupt()) {
2729 set_current_state(TASK_INTERRUPTIBLE);
2730 schedule_timeout(1);
2732 } while (time_after(time, jiffies));
2734 /* Start an addressed training and optionally request promiscuous port */
2735 if ((dev->flags) & IFF_PROMISC) {
2736 hp100_orb(HP100_PROM_MODE, VG_LAN_CFG_2);
2737 if (lp->chip == HP100_CHIPID_LASSEN)
2738 hp100_orw(HP100_MACRQ_PROMSC, TRAIN_REQUEST);
2739 } else {
2740 hp100_andb(~HP100_PROM_MODE, VG_LAN_CFG_2);
2741 /* For ETR parts we need to reset the prom. bit in the training
2742 * register, otherwise promiscious mode won't be disabled.
2744 if (lp->chip == HP100_CHIPID_LASSEN) {
2745 hp100_andw(~HP100_MACRQ_PROMSC, TRAIN_REQUEST);
2749 /* With ETR parts, frame format request bits can be set. */
2750 if (lp->chip == HP100_CHIPID_LASSEN)
2751 hp100_orb(HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST);
2753 hp100_orb(HP100_LINK_CMD | HP100_LOAD_ADDR | HP100_VG_RESET, VG_LAN_CFG_1);
2755 /* Note: Next wait could be omitted for Hood and earlier chips under */
2756 /* certain circumstances */
2757 /* TODO: check if hood/earlier and skip wait. */
2759 /* Wait for either short timeout for VG tones or long for login */
2760 /* Wait for the card hardware to signalise link cable status ok... */
2761 hp100_page(MAC_CTRL);
2762 time = jiffies + (1 * HZ); /* 1 sec timeout for cable st */
2763 do {
2764 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
2765 break;
2766 if (!in_interrupt()) {
2767 set_current_state(TASK_INTERRUPTIBLE);
2768 schedule_timeout(1);
2770 } while (time_before(jiffies, time));
2772 if (time_after_eq(jiffies, time)) {
2773 #ifdef HP100_DEBUG_TRAINING
2774 printk("hp100: %s: Link cable status not ok? Training aborted.\n", dev->name);
2775 #endif
2776 } else {
2777 #ifdef HP100_DEBUG_TRAINING
2778 printk
2779 ("hp100: %s: HUB tones detected. Trying to train.\n",
2780 dev->name);
2781 #endif
2783 time = jiffies + (2 * HZ); /* again a timeout */
2784 do {
2785 val = hp100_inb(VG_LAN_CFG_1);
2786 if ((val & (HP100_LINK_UP_ST))) {
2787 #ifdef HP100_DEBUG_TRAINING
2788 printk("hp100: %s: Passed training.\n", dev->name);
2789 #endif
2790 break;
2792 if (!in_interrupt()) {
2793 set_current_state(TASK_INTERRUPTIBLE);
2794 schedule_timeout(1);
2796 } while (time_after(time, jiffies));
2799 /* If LINK_UP_ST is set, then we are logged into the hub. */
2800 if (time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST)) {
2801 #ifdef HP100_DEBUG_TRAINING
2802 printk("hp100: %s: Successfully logged into the HUB.\n", dev->name);
2803 if (lp->chip == HP100_CHIPID_LASSEN) {
2804 val = hp100_inw(TRAIN_ALLOW);
2805 printk("hp100: %s: Card supports 100VG MAC Version \"%s\" ",
2806 dev->name, (hp100_inw(TRAIN_REQUEST) & HP100_CARD_MACVER) ? "802.12" : "Pre");
2807 printk("Driver will use MAC Version \"%s\"\n", (val & HP100_HUB_MACVER) ? "802.12" : "Pre");
2808 printk("hp100: %s: Frame format is %s.\n", dev->name, (val & HP100_MALLOW_FRAMEFMT) ? "802.5" : "802.3");
2810 #endif
2811 } else {
2812 /* If LINK_UP_ST is not set, login was not successful */
2813 printk("hp100: %s: Problem logging into the HUB.\n", dev->name);
2814 if (lp->chip == HP100_CHIPID_LASSEN) {
2815 /* Check allowed Register to find out why there is a problem. */
2816 val = hp100_inw(TRAIN_ALLOW); /* won't work on non-ETR card */
2817 #ifdef HP100_DEBUG_TRAINING
2818 printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val);
2819 #endif
2820 if (val & HP100_MALLOW_ACCDENIED)
2821 printk("hp100: %s: HUB access denied.\n", dev->name);
2822 if (val & HP100_MALLOW_CONFIGURE)
2823 printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name);
2824 if (val & HP100_MALLOW_DUPADDR)
2825 printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name);
2829 /* If we have put the chip into forced 100 Mbit mode earlier, go back */
2830 /* to auto-select mode */
2832 if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) {
2833 hp100_page(MAC_CTRL);
2834 hp100_orb(HP100_DOT3_MAC, 10_LAN_CFG_2);
2837 val = hp100_inb(VG_LAN_CFG_1);
2839 /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */
2840 hp100_page(PERFORMANCE);
2841 hp100_outw(HP100_MISC_ERROR, IRQ_STATUS);
2843 if (val & HP100_LINK_UP_ST)
2844 return (0); /* login was ok */
2845 else {
2846 printk("hp100: %s: Training failed.\n", dev->name);
2847 hp100_down_vg_link(dev);
2848 return -EIO;
2851 /* no forced relogin & already link there->no training. */
2852 return -EIO;
2855 static void hp100_cascade_reset(struct net_device *dev, u_short enable)
2857 int ioaddr = dev->base_addr;
2858 struct hp100_private *lp = (struct hp100_private *) dev->priv;
2860 #ifdef HP100_DEBUG_B
2861 hp100_outw(0x4226, TRACE);
2862 printk("hp100: %s: cascade_reset\n", dev->name);
2863 #endif
2865 if (enable) {
2866 hp100_outw(HP100_HW_RST | HP100_RESET_LB, OPTION_LSW);
2867 if (lp->chip == HP100_CHIPID_LASSEN) {
2868 /* Lassen requires a PCI transmit fifo reset */
2869 hp100_page(HW_MAP);
2870 hp100_andb(~HP100_PCI_RESET, PCICTRL2);
2871 hp100_orb(HP100_PCI_RESET, PCICTRL2);
2872 /* Wait for min. 300 ns */
2873 /* we can't use jiffies here, because it may be */
2874 /* that we have disabled the timer... */
2875 udelay(400);
2876 hp100_andb(~HP100_PCI_RESET, PCICTRL2);
2877 hp100_page(PERFORMANCE);
2879 } else { /* bring out of reset */
2880 hp100_outw(HP100_HW_RST | HP100_SET_LB, OPTION_LSW);
2881 udelay(400);
2882 hp100_page(PERFORMANCE);
2886 #ifdef HP100_DEBUG
2887 void hp100_RegisterDump(struct net_device *dev)
2889 int ioaddr = dev->base_addr;
2890 int Page;
2891 int Register;
2893 /* Dump common registers */
2894 printk("hp100: %s: Cascade Register Dump\n", dev->name);
2895 printk("hardware id #1: 0x%.2x\n", hp100_inb(HW_ID));
2896 printk("hardware id #2/paging: 0x%.2x\n", hp100_inb(PAGING));
2897 printk("option #1: 0x%.4x\n", hp100_inw(OPTION_LSW));
2898 printk("option #2: 0x%.4x\n", hp100_inw(OPTION_MSW));
2900 /* Dump paged registers */
2901 for (Page = 0; Page < 8; Page++) {
2902 /* Dump registers */
2903 printk("page: 0x%.2x\n", Page);
2904 outw(Page, ioaddr + 0x02);
2905 for (Register = 0x8; Register < 0x22; Register += 2) {
2906 /* Display Register contents except data port */
2907 if (((Register != 0x10) && (Register != 0x12)) || (Page > 0)) {
2908 printk("0x%.2x = 0x%.4x\n", Register, inw(ioaddr + Register));
2912 hp100_page(PERFORMANCE);
2914 #endif
2918 * module section
2921 #ifdef MODULE
2923 MODULE_LICENSE("GPL");
2924 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, "
2925 "Siegfried \"Frieder\" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>");
2926 MODULE_DESCRIPTION("HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters");
2929 * Note: if you have more than five 100vg cards in your pc, feel free to
2930 * increase this value
2933 #define HP100_DEVICES 5
2936 * Note: to register three eisa or pci devices, use:
2937 * option hp100 hp100_port=0,0,0
2938 * to register one card at io 0x280 as eth239, use:
2939 * option hp100 hp100_port=0x280 hp100_name=eth239
2942 /* Parameters set by insmod */
2943 static int hp100_port[HP100_DEVICES] = { 0, [1 ... (HP100_DEVICES-1)] = -1 };
2944 MODULE_PARM(hp100_port, "1-" __MODULE_STRING(HP100_DEVICES) "i");
2946 /* Allocate HP100_DEVICES strings of length IFNAMSIZ, one string for each device */
2947 static char hp100_name[HP100_DEVICES][IFNAMSIZ] = { "", "", "", "", "" };
2948 /* Allow insmod to write those HP100_DEVICES strings individually */
2949 MODULE_PARM(hp100_name, "1-" __MODULE_STRING(HP100_DEVICES) "c" __MODULE_STRING(IFNAMSIZ));
2951 /* List of devices */
2952 static struct net_device *hp100_devlist[HP100_DEVICES];
2954 static void release_dev(int i)
2956 struct net_device *d = hp100_devlist[i];
2957 struct hp100_private *p = (struct hp100_private *) d->priv;
2959 unregister_netdev(d);
2960 release_region(d->base_addr, HP100_REGION_SIZE);
2962 if (p->mode == 1) /* busmaster */
2963 pci_free_consistent(p->pci_dev, MAX_RINGSIZE + 0x0f, p->page_vaddr_algn, virt_to_whatever(d, p->page_vaddr_algn));
2964 if (p->mem_ptr_virt)
2965 iounmap(p->mem_ptr_virt);
2966 kfree(d->priv);
2967 d->priv = NULL;
2968 kfree(d);
2969 hp100_devlist[i] = NULL;
2972 static int __init hp100_module_init(void)
2974 int i, cards;
2976 #ifndef CONFIG_PCI
2977 if (hp100_port == 0 && !EISA_bus)
2978 printk("hp100: You should not use auto-probing with insmod!\n");
2979 #endif
2981 /* Loop on all possible base addresses */
2982 i = -1;
2983 cards = 0;
2984 while ((hp100_port[++i] != -1) && (i < HP100_DEVICES)) {
2985 /* Create device and set basics args */
2986 hp100_devlist[i] = kmalloc(sizeof(struct net_device), GFP_KERNEL);
2987 if (!hp100_devlist[i])
2988 goto fail;
2989 memset(hp100_devlist[i], 0x00, sizeof(struct net_device));
2990 #if LINUX_VERSION_CODE >= 0x020362 /* 2.3.99-pre7 */
2991 memcpy(hp100_devlist[i]->name, hp100_name[i], IFNAMSIZ); /* Copy name */
2992 #else
2993 hp100_devlist[i]->name = hp100_name[i];
2994 #endif /* LINUX_VERSION_CODE >= 0x020362 */
2995 hp100_devlist[i]->base_addr = hp100_port[i];
2996 hp100_devlist[i]->init = &hp100_probe;
2998 /* Try to create the device */
2999 if (register_netdev(hp100_devlist[i]) != 0) {
3000 /* DeAllocate everything */
3001 /* Note: if dev->priv is mallocated, there is no way to fail */
3002 kfree(hp100_devlist[i]);
3003 hp100_devlist[i] = (struct net_device *) NULL;
3004 } else
3005 cards++;
3006 } /* Loop over all devices */
3008 return cards > 0 ? 0 : -ENODEV;
3009 fail:
3010 while (cards && --i)
3011 if (hp100_devlist[i]) {
3012 release_dev(i);
3013 --cards;
3015 return -ENOMEM;
3018 static void __exit hp100_module_exit(void)
3020 int i;
3022 /* TODO: Check if all skb's are released/freed. */
3023 for (i = 0; i < HP100_DEVICES; i++)
3024 if (hp100_devlist[i] != (struct net_device *) NULL)
3025 release_dev(i);
3028 module_init(hp100_module_init)
3029 module_exit(hp100_module_exit)
3031 #endif /* MODULE */
3035 * Local variables:
3036 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp100.c"
3037 * c-indent-level: 2
3038 * tab-width: 8
3039 * End: