[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / net / tulip / xircom_cb.c
blob26cc4f6378c70011f586e5f5111a1a47843b0adc
1 /*
2 * xircom_cb: A driver for the (tulip-like) Xircom Cardbus ethernet cards
4 * This software is (C) by the respective authors, and licensed under the GPL
5 * License.
7 * Written by Arjan van de Ven for Red Hat, Inc.
8 * Based on work by Jeff Garzik, Doug Ledford and Donald Becker
10 * This software may be used and distributed according to the terms
11 * of the GNU General Public License, incorporated herein by reference.
14 * $Id: xircom_cb.c,v 1.33 2001/03/19 14:02:07 arjanv Exp $
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/ioport.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/pci.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/ethtool.h>
31 #include <linux/bitops.h>
33 #include <asm/uaccess.h>
34 #include <asm/io.h>
36 #ifdef DEBUG
37 #define enter(x) printk("Enter: %s, %s line %i\n",x,__FILE__,__LINE__)
38 #define leave(x) printk("Leave: %s, %s line %i\n",x,__FILE__,__LINE__)
39 #else
40 #define enter(x) do {} while (0)
41 #define leave(x) do {} while (0)
42 #endif
45 MODULE_DESCRIPTION("Xircom Cardbus ethernet driver");
46 MODULE_AUTHOR("Arjan van de Ven <arjanv@redhat.com>");
47 MODULE_LICENSE("GPL");
51 /* IO registers on the card, offsets */
52 #define CSR0 0x00
53 #define CSR1 0x08
54 #define CSR2 0x10
55 #define CSR3 0x18
56 #define CSR4 0x20
57 #define CSR5 0x28
58 #define CSR6 0x30
59 #define CSR7 0x38
60 #define CSR8 0x40
61 #define CSR9 0x48
62 #define CSR10 0x50
63 #define CSR11 0x58
64 #define CSR12 0x60
65 #define CSR13 0x68
66 #define CSR14 0x70
67 #define CSR15 0x78
68 #define CSR16 0x80
70 /* PCI registers */
71 #define PCI_POWERMGMT 0x40
73 /* Offsets of the buffers within the descriptor pages, in bytes */
75 #define NUMDESCRIPTORS 4
77 static int bufferoffsets[NUMDESCRIPTORS] = {128,2048,4096,6144};
80 struct xircom_private {
81 /* Send and receive buffers, kernel-addressable and dma addressable forms */
83 unsigned int *rx_buffer;
84 unsigned int *tx_buffer;
86 dma_addr_t rx_dma_handle;
87 dma_addr_t tx_dma_handle;
89 struct sk_buff *tx_skb[4];
91 unsigned long io_port;
92 int open;
94 /* transmit_used is the rotating counter that indicates which transmit
95 descriptor has to be used next */
96 int transmit_used;
98 /* Spinlock to serialize register operations.
99 It must be helt while manipulating the following registers:
100 CSR0, CSR6, CSR7, CSR9, CSR10, CSR15
102 spinlock_t lock;
105 struct pci_dev *pdev;
106 struct net_device *dev;
107 struct net_device_stats stats;
111 /* Function prototypes */
112 static int xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id);
113 static void xircom_remove(struct pci_dev *pdev);
114 static irqreturn_t xircom_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
115 static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev);
116 static int xircom_open(struct net_device *dev);
117 static int xircom_close(struct net_device *dev);
118 static void xircom_up(struct xircom_private *card);
119 static struct net_device_stats *xircom_get_stats(struct net_device *dev);
120 #if CONFIG_NET_POLL_CONTROLLER
121 static void xircom_poll_controller(struct net_device *dev);
122 #endif
124 static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset);
125 static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset);
126 static void read_mac_address(struct xircom_private *card);
127 static void transceiver_voodoo(struct xircom_private *card);
128 static void initialize_card(struct xircom_private *card);
129 static void trigger_transmit(struct xircom_private *card);
130 static void trigger_receive(struct xircom_private *card);
131 static void setup_descriptors(struct xircom_private *card);
132 static void remove_descriptors(struct xircom_private *card);
133 static int link_status_changed(struct xircom_private *card);
134 static void activate_receiver(struct xircom_private *card);
135 static void deactivate_receiver(struct xircom_private *card);
136 static void activate_transmitter(struct xircom_private *card);
137 static void deactivate_transmitter(struct xircom_private *card);
138 static void enable_transmit_interrupt(struct xircom_private *card);
139 static void enable_receive_interrupt(struct xircom_private *card);
140 static void enable_link_interrupt(struct xircom_private *card);
141 static void disable_all_interrupts(struct xircom_private *card);
142 static int link_status(struct xircom_private *card);
146 static struct pci_device_id xircom_pci_table[] = {
147 {0x115D, 0x0003, PCI_ANY_ID, PCI_ANY_ID,},
148 {0,},
150 MODULE_DEVICE_TABLE(pci, xircom_pci_table);
152 static struct pci_driver xircom_ops = {
153 .name = "xircom_cb",
154 .id_table = xircom_pci_table,
155 .probe = xircom_probe,
156 .remove = xircom_remove,
157 .suspend =NULL,
158 .resume =NULL
162 #ifdef DEBUG
163 static void print_binary(unsigned int number)
165 int i,i2;
166 char buffer[64];
167 memset(buffer,0,64);
168 i2=0;
169 for (i=31;i>=0;i--) {
170 if (number & (1<<i))
171 buffer[i2++]='1';
172 else
173 buffer[i2++]='0';
174 if ((i&3)==0)
175 buffer[i2++]=' ';
177 printk("%s\n",buffer);
179 #endif
181 static void netdev_get_drvinfo(struct net_device *dev,
182 struct ethtool_drvinfo *info)
184 struct xircom_private *private = netdev_priv(dev);
186 strcpy(info->driver, "xircom_cb");
187 strcpy(info->bus_info, pci_name(private->pdev));
190 static struct ethtool_ops netdev_ethtool_ops = {
191 .get_drvinfo = netdev_get_drvinfo,
194 /* xircom_probe is the code that gets called on device insertion.
195 it sets up the hardware and registers the device to the networklayer.
197 TODO: Send 1 or 2 "dummy" packets here as the card seems to discard the
198 first two packets that get send, and pump hates that.
201 static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id)
203 struct net_device *dev = NULL;
204 struct xircom_private *private;
205 unsigned char chip_rev;
206 unsigned long flags;
207 unsigned short tmp16;
208 enter("xircom_probe");
210 /* First do the PCI initialisation */
212 if (pci_enable_device(pdev))
213 return -ENODEV;
215 /* disable all powermanagement */
216 pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000);
218 pci_set_master(pdev); /* Why isn't this done by pci_enable_device ?*/
220 /* clear PCI status, if any */
221 pci_read_config_word (pdev,PCI_STATUS, &tmp16);
222 pci_write_config_word (pdev, PCI_STATUS,tmp16);
224 pci_read_config_byte(pdev, PCI_REVISION_ID, &chip_rev);
226 if (!request_region(pci_resource_start(pdev, 0), 128, "xircom_cb")) {
227 printk(KERN_ERR "xircom_probe: failed to allocate io-region\n");
228 return -ENODEV;
232 Before changing the hardware, allocate the memory.
233 This way, we can fail gracefully if not enough memory
234 is available.
236 dev = alloc_etherdev(sizeof(struct xircom_private));
237 if (!dev) {
238 printk(KERN_ERR "xircom_probe: failed to allocate etherdev\n");
239 goto device_fail;
241 private = netdev_priv(dev);
243 /* Allocate the send/receive buffers */
244 private->rx_buffer = pci_alloc_consistent(pdev,8192,&private->rx_dma_handle);
245 if (private->rx_buffer == NULL) {
246 printk(KERN_ERR "xircom_probe: no memory for rx buffer \n");
247 goto rx_buf_fail;
249 private->tx_buffer = pci_alloc_consistent(pdev,8192,&private->tx_dma_handle);
250 if (private->tx_buffer == NULL) {
251 printk(KERN_ERR "xircom_probe: no memory for tx buffer \n");
252 goto tx_buf_fail;
255 SET_MODULE_OWNER(dev);
256 SET_NETDEV_DEV(dev, &pdev->dev);
259 private->dev = dev;
260 private->pdev = pdev;
261 private->io_port = pci_resource_start(pdev, 0);
262 spin_lock_init(&private->lock);
263 dev->irq = pdev->irq;
264 dev->base_addr = private->io_port;
266 initialize_card(private);
267 read_mac_address(private);
268 setup_descriptors(private);
270 dev->open = &xircom_open;
271 dev->hard_start_xmit = &xircom_start_xmit;
272 dev->stop = &xircom_close;
273 dev->get_stats = &xircom_get_stats;
274 dev->priv = private;
275 #ifdef CONFIG_NET_POLL_CONTROLLER
276 dev->poll_controller = &xircom_poll_controller;
277 #endif
278 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
279 pci_set_drvdata(pdev, dev);
281 if (register_netdev(dev)) {
282 printk(KERN_ERR "xircom_probe: netdevice registration failed.\n");
283 goto reg_fail;
286 printk(KERN_INFO "%s: Xircom cardbus revision %i at irq %i \n", dev->name, chip_rev, pdev->irq);
287 /* start the transmitter to get a heartbeat */
288 /* TODO: send 2 dummy packets here */
289 transceiver_voodoo(private);
291 spin_lock_irqsave(&private->lock,flags);
292 activate_transmitter(private);
293 activate_receiver(private);
294 spin_unlock_irqrestore(&private->lock,flags);
296 trigger_receive(private);
298 leave("xircom_probe");
299 return 0;
301 reg_fail:
302 kfree(private->tx_buffer);
303 tx_buf_fail:
304 kfree(private->rx_buffer);
305 rx_buf_fail:
306 free_netdev(dev);
307 device_fail:
308 return -ENODEV;
313 xircom_remove is called on module-unload or on device-eject.
314 it unregisters the irq, io-region and network device.
315 Interrupts and such are already stopped in the "ifconfig ethX down"
316 code.
318 static void __devexit xircom_remove(struct pci_dev *pdev)
320 struct net_device *dev = pci_get_drvdata(pdev);
321 struct xircom_private *card = netdev_priv(dev);
323 enter("xircom_remove");
324 pci_free_consistent(pdev,8192,card->rx_buffer,card->rx_dma_handle);
325 pci_free_consistent(pdev,8192,card->tx_buffer,card->tx_dma_handle);
327 release_region(dev->base_addr, 128);
328 unregister_netdev(dev);
329 free_netdev(dev);
330 pci_set_drvdata(pdev, NULL);
331 leave("xircom_remove");
334 static irqreturn_t xircom_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
336 struct net_device *dev = (struct net_device *) dev_instance;
337 struct xircom_private *card = netdev_priv(dev);
338 unsigned int status;
339 int i;
341 enter("xircom_interrupt\n");
343 spin_lock(&card->lock);
344 status = inl(card->io_port+CSR5);
346 #ifdef DEBUG
347 print_binary(status);
348 printk("tx status 0x%08x 0x%08x \n",card->tx_buffer[0],card->tx_buffer[4]);
349 printk("rx status 0x%08x 0x%08x \n",card->rx_buffer[0],card->rx_buffer[4]);
350 #endif
351 /* Handle shared irq and hotplug */
352 if (status == 0 || status == 0xffffffff) {
353 spin_unlock(&card->lock);
354 return IRQ_NONE;
357 if (link_status_changed(card)) {
358 int newlink;
359 printk(KERN_DEBUG "xircom_cb: Link status has changed \n");
360 newlink = link_status(card);
361 printk(KERN_INFO "xircom_cb: Link is %i mbit \n",newlink);
362 if (newlink)
363 netif_carrier_on(dev);
364 else
365 netif_carrier_off(dev);
369 /* Clear all remaining interrupts */
370 status |= 0xffffffff; /* FIXME: make this clear only the
371 real existing bits */
372 outl(status,card->io_port+CSR5);
375 for (i=0;i<NUMDESCRIPTORS;i++)
376 investigate_write_descriptor(dev,card,i,bufferoffsets[i]);
377 for (i=0;i<NUMDESCRIPTORS;i++)
378 investigate_read_descriptor(dev,card,i,bufferoffsets[i]);
381 spin_unlock(&card->lock);
382 leave("xircom_interrupt");
383 return IRQ_HANDLED;
386 static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
388 struct xircom_private *card;
389 unsigned long flags;
390 int nextdescriptor;
391 int desc;
392 enter("xircom_start_xmit");
394 card = netdev_priv(dev);
395 spin_lock_irqsave(&card->lock,flags);
397 /* First see if we can free some descriptors */
398 for (desc=0;desc<NUMDESCRIPTORS;desc++)
399 investigate_write_descriptor(dev,card,desc,bufferoffsets[desc]);
402 nextdescriptor = (card->transmit_used +1) % (NUMDESCRIPTORS);
403 desc = card->transmit_used;
405 /* only send the packet if the descriptor is free */
406 if (card->tx_buffer[4*desc]==0) {
407 /* Copy the packet data; zero the memory first as the card
408 sometimes sends more than you ask it to. */
410 memset(&card->tx_buffer[bufferoffsets[desc]/4],0,1536);
411 memcpy(&(card->tx_buffer[bufferoffsets[desc]/4]),skb->data,skb->len);
414 /* FIXME: The specification tells us that the length we send HAS to be a multiple of
415 4 bytes. */
417 card->tx_buffer[4*desc+1] = skb->len;
418 if (desc == NUMDESCRIPTORS-1)
419 card->tx_buffer[4*desc+1] |= (1<<25); /* bit 25: last descriptor of the ring */
421 card->tx_buffer[4*desc+1] |= 0xF0000000;
422 /* 0xF0... means want interrupts*/
423 card->tx_skb[desc] = skb;
425 wmb();
426 /* This gives the descriptor to the card */
427 card->tx_buffer[4*desc] = 0x80000000;
428 trigger_transmit(card);
429 if (((int)card->tx_buffer[nextdescriptor*4])<0) { /* next descriptor is occupied... */
430 netif_stop_queue(dev);
432 card->transmit_used = nextdescriptor;
433 leave("xircom-start_xmit - sent");
434 spin_unlock_irqrestore(&card->lock,flags);
435 return 0;
440 /* Uh oh... no free descriptor... drop the packet */
441 netif_stop_queue(dev);
442 spin_unlock_irqrestore(&card->lock,flags);
443 trigger_transmit(card);
445 return -EIO;
451 static int xircom_open(struct net_device *dev)
453 struct xircom_private *xp = netdev_priv(dev);
454 int retval;
455 enter("xircom_open");
456 printk(KERN_INFO "xircom cardbus adaptor found, registering as %s, using irq %i \n",dev->name,dev->irq);
457 retval = request_irq(dev->irq, &xircom_interrupt, SA_SHIRQ, dev->name, dev);
458 if (retval) {
459 leave("xircom_open - No IRQ");
460 return retval;
463 xircom_up(xp);
464 xp->open = 1;
465 leave("xircom_open");
466 return 0;
469 static int xircom_close(struct net_device *dev)
471 struct xircom_private *card;
472 unsigned long flags;
474 enter("xircom_close");
475 card = netdev_priv(dev);
476 netif_stop_queue(dev); /* we don't want new packets */
479 spin_lock_irqsave(&card->lock,flags);
481 disable_all_interrupts(card);
482 #if 0
483 /* We can enable this again once we send dummy packets on ifconfig ethX up */
484 deactivate_receiver(card);
485 deactivate_transmitter(card);
486 #endif
487 remove_descriptors(card);
489 spin_unlock_irqrestore(&card->lock,flags);
491 card->open = 0;
492 free_irq(dev->irq,dev);
494 leave("xircom_close");
496 return 0;
502 static struct net_device_stats *xircom_get_stats(struct net_device *dev)
504 struct xircom_private *card = netdev_priv(dev);
505 return &card->stats;
509 #ifdef CONFIG_NET_POLL_CONTROLLER
510 static void xircom_poll_controller(struct net_device *dev)
512 disable_irq(dev->irq);
513 xircom_interrupt(dev->irq, dev, NULL);
514 enable_irq(dev->irq);
516 #endif
519 static void initialize_card(struct xircom_private *card)
521 unsigned int val;
522 unsigned long flags;
523 enter("initialize_card");
526 spin_lock_irqsave(&card->lock, flags);
528 /* First: reset the card */
529 val = inl(card->io_port + CSR0);
530 val |= 0x01; /* Software reset */
531 outl(val, card->io_port + CSR0);
533 udelay(100); /* give the card some time to reset */
535 val = inl(card->io_port + CSR0);
536 val &= ~0x01; /* disable Software reset */
537 outl(val, card->io_port + CSR0);
540 val = 0; /* Value 0x00 is a safe and conservative value
541 for the PCI configuration settings */
542 outl(val, card->io_port + CSR0);
545 disable_all_interrupts(card);
546 deactivate_receiver(card);
547 deactivate_transmitter(card);
549 spin_unlock_irqrestore(&card->lock, flags);
551 leave("initialize_card");
555 trigger_transmit causes the card to check for frames to be transmitted.
556 This is accomplished by writing to the CSR1 port. The documentation
557 claims that the act of writing is sufficient and that the value is
558 ignored; I chose zero.
560 static void trigger_transmit(struct xircom_private *card)
562 unsigned int val;
563 enter("trigger_transmit");
565 val = 0;
566 outl(val, card->io_port + CSR1);
568 leave("trigger_transmit");
572 trigger_receive causes the card to check for empty frames in the
573 descriptor list in which packets can be received.
574 This is accomplished by writing to the CSR2 port. The documentation
575 claims that the act of writing is sufficient and that the value is
576 ignored; I chose zero.
578 static void trigger_receive(struct xircom_private *card)
580 unsigned int val;
581 enter("trigger_receive");
583 val = 0;
584 outl(val, card->io_port + CSR2);
586 leave("trigger_receive");
590 setup_descriptors initializes the send and receive buffers to be valid
591 descriptors and programs the addresses into the card.
593 static void setup_descriptors(struct xircom_private *card)
595 unsigned int val;
596 unsigned int address;
597 int i;
598 enter("setup_descriptors");
601 if (card->rx_buffer == NULL)
602 BUG();
603 if (card->tx_buffer == NULL)
604 BUG();
606 /* Receive descriptors */
607 memset(card->rx_buffer, 0, 128); /* clear the descriptors */
608 for (i=0;i<NUMDESCRIPTORS;i++ ) {
610 /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */
611 card->rx_buffer[i*4 + 0] = 0x80000000;
612 /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
613 card->rx_buffer[i*4 + 1] = 1536;
614 if (i==NUMDESCRIPTORS-1)
615 card->rx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
617 /* Rx Descr2: address of the buffer
618 we store the buffer at the 2nd half of the page */
620 address = (unsigned long) card->rx_dma_handle;
621 card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
622 /* Rx Desc3: address of 2nd buffer -> 0 */
623 card->rx_buffer[i*4 + 3] = 0;
626 wmb();
627 /* Write the receive descriptor ring address to the card */
628 address = (unsigned long) card->rx_dma_handle;
629 val = cpu_to_le32(address);
630 outl(val, card->io_port + CSR3); /* Receive descr list address */
633 /* transmit descriptors */
634 memset(card->tx_buffer, 0, 128); /* clear the descriptors */
636 for (i=0;i<NUMDESCRIPTORS;i++ ) {
637 /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */
638 card->tx_buffer[i*4 + 0] = 0x00000000;
639 /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
640 card->tx_buffer[i*4 + 1] = 1536;
641 if (i==NUMDESCRIPTORS-1)
642 card->tx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
644 /* Tx Descr2: address of the buffer
645 we store the buffer at the 2nd half of the page */
646 address = (unsigned long) card->tx_dma_handle;
647 card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
648 /* Tx Desc3: address of 2nd buffer -> 0 */
649 card->tx_buffer[i*4 + 3] = 0;
652 wmb();
653 /* wite the transmit descriptor ring to the card */
654 address = (unsigned long) card->tx_dma_handle;
655 val =cpu_to_le32(address);
656 outl(val, card->io_port + CSR4); /* xmit descr list address */
658 leave("setup_descriptors");
662 remove_descriptors informs the card the descriptors are no longer
663 valid by setting the address in the card to 0x00.
665 static void remove_descriptors(struct xircom_private *card)
667 unsigned int val;
668 enter("remove_descriptors");
670 val = 0;
671 outl(val, card->io_port + CSR3); /* Receive descriptor address */
672 outl(val, card->io_port + CSR4); /* Send descriptor address */
674 leave("remove_descriptors");
678 link_status_changed returns 1 if the card has indicated that
679 the link status has changed. The new link status has to be read from CSR12.
681 This function also clears the status-bit.
683 static int link_status_changed(struct xircom_private *card)
685 unsigned int val;
686 enter("link_status_changed");
688 val = inl(card->io_port + CSR5); /* Status register */
690 if ((val & (1 << 27)) == 0) { /* no change */
691 leave("link_status_changed - nochange");
692 return 0;
695 /* clear the event by writing a 1 to the bit in the
696 status register. */
697 val = (1 << 27);
698 outl(val, card->io_port + CSR5);
700 leave("link_status_changed - changed");
701 return 1;
706 transmit_active returns 1 if the transmitter on the card is
707 in a non-stopped state.
709 static int transmit_active(struct xircom_private *card)
711 unsigned int val;
712 enter("transmit_active");
714 val = inl(card->io_port + CSR5); /* Status register */
716 if ((val & (7 << 20)) == 0) { /* transmitter disabled */
717 leave("transmit_active - inactive");
718 return 0;
721 leave("transmit_active - active");
722 return 1;
726 receive_active returns 1 if the receiver on the card is
727 in a non-stopped state.
729 static int receive_active(struct xircom_private *card)
731 unsigned int val;
732 enter("receive_active");
735 val = inl(card->io_port + CSR5); /* Status register */
737 if ((val & (7 << 17)) == 0) { /* receiver disabled */
738 leave("receive_active - inactive");
739 return 0;
742 leave("receive_active - active");
743 return 1;
747 activate_receiver enables the receiver on the card.
748 Before being allowed to active the receiver, the receiver
749 must be completely de-activated. To achieve this,
750 this code actually disables the receiver first; then it waits for the
751 receiver to become inactive, then it activates the receiver and then
752 it waits for the receiver to be active.
754 must be called with the lock held and interrupts disabled.
756 static void activate_receiver(struct xircom_private *card)
758 unsigned int val;
759 int counter;
760 enter("activate_receiver");
763 val = inl(card->io_port + CSR6); /* Operation mode */
765 /* If the "active" bit is set and the receiver is already
766 active, no need to do the expensive thing */
767 if ((val&2) && (receive_active(card)))
768 return;
771 val = val & ~2; /* disable the receiver */
772 outl(val, card->io_port + CSR6);
774 counter = 10;
775 while (counter > 0) {
776 if (!receive_active(card))
777 break;
778 /* wait a while */
779 udelay(50);
780 counter--;
781 if (counter <= 0)
782 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
785 /* enable the receiver */
786 val = inl(card->io_port + CSR6); /* Operation mode */
787 val = val | 2; /* enable the receiver */
788 outl(val, card->io_port + CSR6);
790 /* now wait for the card to activate again */
791 counter = 10;
792 while (counter > 0) {
793 if (receive_active(card))
794 break;
795 /* wait a while */
796 udelay(50);
797 counter--;
798 if (counter <= 0)
799 printk(KERN_ERR "xircom_cb: Receiver failed to re-activate\n");
802 leave("activate_receiver");
806 deactivate_receiver disables the receiver on the card.
807 To achieve this this code disables the receiver first;
808 then it waits for the receiver to become inactive.
810 must be called with the lock held and interrupts disabled.
812 static void deactivate_receiver(struct xircom_private *card)
814 unsigned int val;
815 int counter;
816 enter("deactivate_receiver");
818 val = inl(card->io_port + CSR6); /* Operation mode */
819 val = val & ~2; /* disable the receiver */
820 outl(val, card->io_port + CSR6);
822 counter = 10;
823 while (counter > 0) {
824 if (!receive_active(card))
825 break;
826 /* wait a while */
827 udelay(50);
828 counter--;
829 if (counter <= 0)
830 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
834 leave("deactivate_receiver");
839 activate_transmitter enables the transmitter on the card.
840 Before being allowed to active the transmitter, the transmitter
841 must be completely de-activated. To achieve this,
842 this code actually disables the transmitter first; then it waits for the
843 transmitter to become inactive, then it activates the transmitter and then
844 it waits for the transmitter to be active again.
846 must be called with the lock held and interrupts disabled.
848 static void activate_transmitter(struct xircom_private *card)
850 unsigned int val;
851 int counter;
852 enter("activate_transmitter");
855 val = inl(card->io_port + CSR6); /* Operation mode */
857 /* If the "active" bit is set and the receiver is already
858 active, no need to do the expensive thing */
859 if ((val&(1<<13)) && (transmit_active(card)))
860 return;
862 val = val & ~(1 << 13); /* disable the transmitter */
863 outl(val, card->io_port + CSR6);
865 counter = 10;
866 while (counter > 0) {
867 if (!transmit_active(card))
868 break;
869 /* wait a while */
870 udelay(50);
871 counter--;
872 if (counter <= 0)
873 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
876 /* enable the transmitter */
877 val = inl(card->io_port + CSR6); /* Operation mode */
878 val = val | (1 << 13); /* enable the transmitter */
879 outl(val, card->io_port + CSR6);
881 /* now wait for the card to activate again */
882 counter = 10;
883 while (counter > 0) {
884 if (transmit_active(card))
885 break;
886 /* wait a while */
887 udelay(50);
888 counter--;
889 if (counter <= 0)
890 printk(KERN_ERR "xircom_cb: Transmitter failed to re-activate\n");
893 leave("activate_transmitter");
897 deactivate_transmitter disables the transmitter on the card.
898 To achieve this this code disables the transmitter first;
899 then it waits for the transmitter to become inactive.
901 must be called with the lock held and interrupts disabled.
903 static void deactivate_transmitter(struct xircom_private *card)
905 unsigned int val;
906 int counter;
907 enter("deactivate_transmitter");
909 val = inl(card->io_port + CSR6); /* Operation mode */
910 val = val & ~2; /* disable the transmitter */
911 outl(val, card->io_port + CSR6);
913 counter = 20;
914 while (counter > 0) {
915 if (!transmit_active(card))
916 break;
917 /* wait a while */
918 udelay(50);
919 counter--;
920 if (counter <= 0)
921 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
925 leave("deactivate_transmitter");
930 enable_transmit_interrupt enables the transmit interrupt
932 must be called with the lock held and interrupts disabled.
934 static void enable_transmit_interrupt(struct xircom_private *card)
936 unsigned int val;
937 enter("enable_transmit_interrupt");
939 val = inl(card->io_port + CSR7); /* Interrupt enable register */
940 val |= 1; /* enable the transmit interrupt */
941 outl(val, card->io_port + CSR7);
943 leave("enable_transmit_interrupt");
948 enable_receive_interrupt enables the receive interrupt
950 must be called with the lock held and interrupts disabled.
952 static void enable_receive_interrupt(struct xircom_private *card)
954 unsigned int val;
955 enter("enable_receive_interrupt");
957 val = inl(card->io_port + CSR7); /* Interrupt enable register */
958 val = val | (1 << 6); /* enable the receive interrupt */
959 outl(val, card->io_port + CSR7);
961 leave("enable_receive_interrupt");
965 enable_link_interrupt enables the link status change interrupt
967 must be called with the lock held and interrupts disabled.
969 static void enable_link_interrupt(struct xircom_private *card)
971 unsigned int val;
972 enter("enable_link_interrupt");
974 val = inl(card->io_port + CSR7); /* Interrupt enable register */
975 val = val | (1 << 27); /* enable the link status chage interrupt */
976 outl(val, card->io_port + CSR7);
978 leave("enable_link_interrupt");
984 disable_all_interrupts disables all interrupts
986 must be called with the lock held and interrupts disabled.
988 static void disable_all_interrupts(struct xircom_private *card)
990 unsigned int val;
991 enter("enable_all_interrupts");
993 val = 0; /* disable all interrupts */
994 outl(val, card->io_port + CSR7);
996 leave("disable_all_interrupts");
1000 enable_common_interrupts enables several weird interrupts
1002 must be called with the lock held and interrupts disabled.
1004 static void enable_common_interrupts(struct xircom_private *card)
1006 unsigned int val;
1007 enter("enable_link_interrupt");
1009 val = inl(card->io_port + CSR7); /* Interrupt enable register */
1010 val |= (1<<16); /* Normal Interrupt Summary */
1011 val |= (1<<15); /* Abnormal Interrupt Summary */
1012 val |= (1<<13); /* Fatal bus error */
1013 val |= (1<<8); /* Receive Process Stopped */
1014 val |= (1<<7); /* Receive Buffer Unavailable */
1015 val |= (1<<5); /* Transmit Underflow */
1016 val |= (1<<2); /* Transmit Buffer Unavailable */
1017 val |= (1<<1); /* Transmit Process Stopped */
1018 outl(val, card->io_port + CSR7);
1020 leave("enable_link_interrupt");
1024 enable_promisc starts promisc mode
1026 must be called with the lock held and interrupts disabled.
1028 static int enable_promisc(struct xircom_private *card)
1030 unsigned int val;
1031 enter("enable_promisc");
1033 val = inl(card->io_port + CSR6);
1034 val = val | (1 << 6);
1035 outl(val, card->io_port + CSR6);
1037 leave("enable_promisc");
1038 return 1;
1045 link_status() checks the the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1047 Must be called in locked state with interrupts disabled
1049 static int link_status(struct xircom_private *card)
1051 unsigned int val;
1052 enter("link_status");
1054 val = inb(card->io_port + CSR12);
1056 if (!(val&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */
1057 return 10;
1058 if (!(val&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1059 return 100;
1061 /* If we get here -> no link at all */
1063 leave("link_status");
1064 return 0;
1072 read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure.
1074 This function will take the spinlock itself and can, as a result, not be called with the lock helt.
1076 static void read_mac_address(struct xircom_private *card)
1078 unsigned char j, tuple, link, data_id, data_count;
1079 unsigned long flags;
1080 int i;
1082 enter("read_mac_address");
1084 spin_lock_irqsave(&card->lock, flags);
1086 outl(1 << 12, card->io_port + CSR9); /* enable boot rom access */
1087 for (i = 0x100; i < 0x1f7; i += link + 2) {
1088 outl(i, card->io_port + CSR10);
1089 tuple = inl(card->io_port + CSR9) & 0xff;
1090 outl(i + 1, card->io_port + CSR10);
1091 link = inl(card->io_port + CSR9) & 0xff;
1092 outl(i + 2, card->io_port + CSR10);
1093 data_id = inl(card->io_port + CSR9) & 0xff;
1094 outl(i + 3, card->io_port + CSR10);
1095 data_count = inl(card->io_port + CSR9) & 0xff;
1096 if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) {
1098 * This is it. We have the data we want.
1100 for (j = 0; j < 6; j++) {
1101 outl(i + j + 4, card->io_port + CSR10);
1102 card->dev->dev_addr[j] = inl(card->io_port + CSR9) & 0xff;
1104 break;
1105 } else if (link == 0) {
1106 break;
1109 spin_unlock_irqrestore(&card->lock, flags);
1110 #ifdef DEBUG
1111 for (i = 0; i < 6; i++)
1112 printk("%c%2.2X", i ? ':' : ' ', card->dev->dev_addr[i]);
1113 printk("\n");
1114 #endif
1115 leave("read_mac_address");
1120 transceiver_voodoo() enables the external UTP plug thingy.
1121 it's called voodoo as I stole this code and cannot cross-reference
1122 it with the specification.
1124 static void transceiver_voodoo(struct xircom_private *card)
1126 unsigned long flags;
1128 enter("transceiver_voodoo");
1130 /* disable all powermanagement */
1131 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1133 setup_descriptors(card);
1135 spin_lock_irqsave(&card->lock, flags);
1137 outl(0x0008, card->io_port + CSR15);
1138 udelay(25);
1139 outl(0xa8050000, card->io_port + CSR15);
1140 udelay(25);
1141 outl(0xa00f0000, card->io_port + CSR15);
1142 udelay(25);
1144 spin_unlock_irqrestore(&card->lock, flags);
1146 netif_start_queue(card->dev);
1147 leave("transceiver_voodoo");
1151 static void xircom_up(struct xircom_private *card)
1153 unsigned long flags;
1154 int i;
1156 enter("xircom_up");
1158 /* disable all powermanagement */
1159 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1161 setup_descriptors(card);
1163 spin_lock_irqsave(&card->lock, flags);
1166 enable_link_interrupt(card);
1167 enable_transmit_interrupt(card);
1168 enable_receive_interrupt(card);
1169 enable_common_interrupts(card);
1170 enable_promisc(card);
1172 /* The card can have received packets already, read them away now */
1173 for (i=0;i<NUMDESCRIPTORS;i++)
1174 investigate_read_descriptor(card->dev,card,i,bufferoffsets[i]);
1177 spin_unlock_irqrestore(&card->lock, flags);
1178 trigger_receive(card);
1179 trigger_transmit(card);
1180 netif_start_queue(card->dev);
1181 leave("xircom_up");
1184 /* Bufferoffset is in BYTES */
1185 static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset)
1187 int status;
1189 enter("investigate_read_descriptor");
1190 status = card->rx_buffer[4*descnr];
1192 if ((status > 0)) { /* packet received */
1194 /* TODO: discard error packets */
1196 short pkt_len = ((status >> 16) & 0x7ff) - 4; /* minus 4, we don't want the CRC */
1197 struct sk_buff *skb;
1199 if (pkt_len > 1518) {
1200 printk(KERN_ERR "xircom_cb: Packet length %i is bogus \n",pkt_len);
1201 pkt_len = 1518;
1204 skb = dev_alloc_skb(pkt_len + 2);
1205 if (skb == NULL) {
1206 card->stats.rx_dropped++;
1207 goto out;
1209 skb->dev = dev;
1210 skb_reserve(skb, 2);
1211 eth_copy_and_sum(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len, 0);
1212 skb_put(skb, pkt_len);
1213 skb->protocol = eth_type_trans(skb, dev);
1214 netif_rx(skb);
1215 dev->last_rx = jiffies;
1216 card->stats.rx_packets++;
1217 card->stats.rx_bytes += pkt_len;
1219 out:
1220 /* give the buffer back to the card */
1221 card->rx_buffer[4*descnr] = 0x80000000;
1222 trigger_receive(card);
1225 leave("investigate_read_descriptor");
1230 /* Bufferoffset is in BYTES */
1231 static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset)
1233 int status;
1235 enter("investigate_write_descriptor");
1237 status = card->tx_buffer[4*descnr];
1238 #if 0
1239 if (status & 0x8000) { /* Major error */
1240 printk(KERN_ERR "Major transmit error status %x \n", status);
1241 card->tx_buffer[4*descnr] = 0;
1242 netif_wake_queue (dev);
1244 #endif
1245 if (status > 0) { /* bit 31 is 0 when done */
1246 if (card->tx_skb[descnr]!=NULL) {
1247 card->stats.tx_bytes += card->tx_skb[descnr]->len;
1248 dev_kfree_skb_irq(card->tx_skb[descnr]);
1250 card->tx_skb[descnr] = NULL;
1251 /* Bit 8 in the status field is 1 if there was a collision */
1252 if (status&(1<<8))
1253 card->stats.collisions++;
1254 card->tx_buffer[4*descnr] = 0; /* descriptor is free again */
1255 netif_wake_queue (dev);
1256 card->stats.tx_packets++;
1259 leave("investigate_write_descriptor");
1264 static int __init xircom_init(void)
1266 pci_register_driver(&xircom_ops);
1267 return 0;
1270 static void __exit xircom_exit(void)
1272 pci_unregister_driver(&xircom_ops);
1275 module_init(xircom_init)
1276 module_exit(xircom_exit)