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
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>
35 #ifdef CONFIG_NET_POLL_CONTROLLER
40 #define enter(x) printk("Enter: %s, %s line %i\n",x,__FILE__,__LINE__)
41 #define leave(x) printk("Leave: %s, %s line %i\n",x,__FILE__,__LINE__)
43 #define enter(x) do {} while (0)
44 #define leave(x) do {} while (0)
48 MODULE_DESCRIPTION("Xircom Cardbus ethernet driver");
49 MODULE_AUTHOR("Arjan van de Ven <arjanv@redhat.com>");
50 MODULE_LICENSE("GPL");
54 /* IO registers on the card, offsets */
74 #define PCI_POWERMGMT 0x40
76 /* Offsets of the buffers within the descriptor pages, in bytes */
78 #define NUMDESCRIPTORS 4
80 static int bufferoffsets[NUMDESCRIPTORS] = {128,2048,4096,6144};
83 struct xircom_private {
84 /* Send and receive buffers, kernel-addressable and dma addressable forms */
89 dma_addr_t rx_dma_handle;
90 dma_addr_t tx_dma_handle;
92 struct sk_buff *tx_skb[4];
94 unsigned long io_port;
97 /* transmit_used is the rotating counter that indicates which transmit
98 descriptor has to be used next */
101 /* Spinlock to serialize register operations.
102 It must be helt while manipulating the following registers:
103 CSR0, CSR6, CSR7, CSR9, CSR10, CSR15
108 struct pci_dev *pdev;
109 struct net_device *dev;
110 struct net_device_stats stats;
114 /* Function prototypes */
115 static int xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id);
116 static void xircom_remove(struct pci_dev *pdev);
117 static irqreturn_t xircom_interrupt(int irq, void *dev_instance);
118 static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev);
119 static int xircom_open(struct net_device *dev);
120 static int xircom_close(struct net_device *dev);
121 static void xircom_up(struct xircom_private *card);
122 static struct net_device_stats *xircom_get_stats(struct net_device *dev);
123 #ifdef CONFIG_NET_POLL_CONTROLLER
124 static void xircom_poll_controller(struct net_device *dev);
127 static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset);
128 static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset);
129 static void read_mac_address(struct xircom_private *card);
130 static void transceiver_voodoo(struct xircom_private *card);
131 static void initialize_card(struct xircom_private *card);
132 static void trigger_transmit(struct xircom_private *card);
133 static void trigger_receive(struct xircom_private *card);
134 static void setup_descriptors(struct xircom_private *card);
135 static void remove_descriptors(struct xircom_private *card);
136 static int link_status_changed(struct xircom_private *card);
137 static void activate_receiver(struct xircom_private *card);
138 static void deactivate_receiver(struct xircom_private *card);
139 static void activate_transmitter(struct xircom_private *card);
140 static void deactivate_transmitter(struct xircom_private *card);
141 static void enable_transmit_interrupt(struct xircom_private *card);
142 static void enable_receive_interrupt(struct xircom_private *card);
143 static void enable_link_interrupt(struct xircom_private *card);
144 static void disable_all_interrupts(struct xircom_private *card);
145 static int link_status(struct xircom_private *card);
149 static struct pci_device_id xircom_pci_table[] = {
150 {0x115D, 0x0003, PCI_ANY_ID, PCI_ANY_ID,},
153 MODULE_DEVICE_TABLE(pci, xircom_pci_table);
155 static struct pci_driver xircom_ops = {
157 .id_table = xircom_pci_table,
158 .probe = xircom_probe,
159 .remove = xircom_remove,
166 static void print_binary(unsigned int number)
172 for (i=31;i>=0;i--) {
180 printk("%s\n",buffer);
184 static void netdev_get_drvinfo(struct net_device *dev,
185 struct ethtool_drvinfo *info)
187 struct xircom_private *private = netdev_priv(dev);
189 strcpy(info->driver, "xircom_cb");
190 strcpy(info->bus_info, pci_name(private->pdev));
193 static const struct ethtool_ops netdev_ethtool_ops = {
194 .get_drvinfo = netdev_get_drvinfo,
197 /* xircom_probe is the code that gets called on device insertion.
198 it sets up the hardware and registers the device to the networklayer.
200 TODO: Send 1 or 2 "dummy" packets here as the card seems to discard the
201 first two packets that get send, and pump hates that.
204 static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id)
206 struct net_device *dev = NULL;
207 struct xircom_private *private;
209 unsigned short tmp16;
210 enter("xircom_probe");
212 /* First do the PCI initialisation */
214 if (pci_enable_device(pdev))
217 /* disable all powermanagement */
218 pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000);
220 pci_set_master(pdev); /* Why isn't this done by pci_enable_device ?*/
222 /* clear PCI status, if any */
223 pci_read_config_word (pdev,PCI_STATUS, &tmp16);
224 pci_write_config_word (pdev, PCI_STATUS,tmp16);
226 if (!request_region(pci_resource_start(pdev, 0), 128, "xircom_cb")) {
227 printk(KERN_ERR "xircom_probe: failed to allocate io-region\n");
232 Before changing the hardware, allocate the memory.
233 This way, we can fail gracefully if not enough memory
236 dev = alloc_etherdev(sizeof(struct xircom_private));
238 printk(KERN_ERR "xircom_probe: failed to allocate etherdev\n");
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");
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");
255 SET_NETDEV_DEV(dev, &pdev->dev);
259 private->pdev = pdev;
260 private->io_port = pci_resource_start(pdev, 0);
261 spin_lock_init(&private->lock);
262 dev->irq = pdev->irq;
263 dev->base_addr = private->io_port;
265 initialize_card(private);
266 read_mac_address(private);
267 setup_descriptors(private);
269 dev->open = &xircom_open;
270 dev->hard_start_xmit = &xircom_start_xmit;
271 dev->stop = &xircom_close;
272 dev->get_stats = &xircom_get_stats;
273 #ifdef CONFIG_NET_POLL_CONTROLLER
274 dev->poll_controller = &xircom_poll_controller;
276 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
277 pci_set_drvdata(pdev, dev);
279 if (register_netdev(dev)) {
280 printk(KERN_ERR "xircom_probe: netdevice registration failed.\n");
284 printk(KERN_INFO "%s: Xircom cardbus revision %i at irq %i \n", dev->name, pdev->revision, pdev->irq);
285 /* start the transmitter to get a heartbeat */
286 /* TODO: send 2 dummy packets here */
287 transceiver_voodoo(private);
289 spin_lock_irqsave(&private->lock,flags);
290 activate_transmitter(private);
291 activate_receiver(private);
292 spin_unlock_irqrestore(&private->lock,flags);
294 trigger_receive(private);
296 leave("xircom_probe");
300 kfree(private->tx_buffer);
302 kfree(private->rx_buffer);
311 xircom_remove is called on module-unload or on device-eject.
312 it unregisters the irq, io-region and network device.
313 Interrupts and such are already stopped in the "ifconfig ethX down"
316 static void __devexit xircom_remove(struct pci_dev *pdev)
318 struct net_device *dev = pci_get_drvdata(pdev);
319 struct xircom_private *card = netdev_priv(dev);
321 enter("xircom_remove");
322 pci_free_consistent(pdev,8192,card->rx_buffer,card->rx_dma_handle);
323 pci_free_consistent(pdev,8192,card->tx_buffer,card->tx_dma_handle);
325 release_region(dev->base_addr, 128);
326 unregister_netdev(dev);
328 pci_set_drvdata(pdev, NULL);
329 leave("xircom_remove");
332 static irqreturn_t xircom_interrupt(int irq, void *dev_instance)
334 struct net_device *dev = (struct net_device *) dev_instance;
335 struct xircom_private *card = netdev_priv(dev);
339 enter("xircom_interrupt\n");
341 spin_lock(&card->lock);
342 status = inl(card->io_port+CSR5);
345 print_binary(status);
346 printk("tx status 0x%08x 0x%08x \n",card->tx_buffer[0],card->tx_buffer[4]);
347 printk("rx status 0x%08x 0x%08x \n",card->rx_buffer[0],card->rx_buffer[4]);
349 /* Handle shared irq and hotplug */
350 if (status == 0 || status == 0xffffffff) {
351 spin_unlock(&card->lock);
355 if (link_status_changed(card)) {
357 printk(KERN_DEBUG "xircom_cb: Link status has changed \n");
358 newlink = link_status(card);
359 printk(KERN_INFO "xircom_cb: Link is %i mbit \n",newlink);
361 netif_carrier_on(dev);
363 netif_carrier_off(dev);
367 /* Clear all remaining interrupts */
368 status |= 0xffffffff; /* FIXME: make this clear only the
369 real existing bits */
370 outl(status,card->io_port+CSR5);
373 for (i=0;i<NUMDESCRIPTORS;i++)
374 investigate_write_descriptor(dev,card,i,bufferoffsets[i]);
375 for (i=0;i<NUMDESCRIPTORS;i++)
376 investigate_read_descriptor(dev,card,i,bufferoffsets[i]);
379 spin_unlock(&card->lock);
380 leave("xircom_interrupt");
384 static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
386 struct xircom_private *card;
390 enter("xircom_start_xmit");
392 card = netdev_priv(dev);
393 spin_lock_irqsave(&card->lock,flags);
395 /* First see if we can free some descriptors */
396 for (desc=0;desc<NUMDESCRIPTORS;desc++)
397 investigate_write_descriptor(dev,card,desc,bufferoffsets[desc]);
400 nextdescriptor = (card->transmit_used +1) % (NUMDESCRIPTORS);
401 desc = card->transmit_used;
403 /* only send the packet if the descriptor is free */
404 if (card->tx_buffer[4*desc]==0) {
405 /* Copy the packet data; zero the memory first as the card
406 sometimes sends more than you ask it to. */
408 memset(&card->tx_buffer[bufferoffsets[desc]/4],0,1536);
409 skb_copy_from_linear_data(skb,
410 &(card->tx_buffer[bufferoffsets[desc] / 4]),
412 /* FIXME: The specification tells us that the length we send HAS to be a multiple of
415 card->tx_buffer[4*desc+1] = cpu_to_le32(skb->len);
416 if (desc == NUMDESCRIPTORS - 1) /* bit 25: last descriptor of the ring */
417 card->tx_buffer[4*desc+1] |= cpu_to_le32(1<<25);
419 card->tx_buffer[4*desc+1] |= cpu_to_le32(0xF0000000);
420 /* 0xF0... means want interrupts*/
421 card->tx_skb[desc] = skb;
424 /* This gives the descriptor to the card */
425 card->tx_buffer[4*desc] = cpu_to_le32(0x80000000);
426 trigger_transmit(card);
427 if (card->tx_buffer[nextdescriptor*4] & cpu_to_le32(0x8000000)) {
428 /* next descriptor is occupied... */
429 netif_stop_queue(dev);
431 card->transmit_used = nextdescriptor;
432 leave("xircom-start_xmit - sent");
433 spin_unlock_irqrestore(&card->lock,flags);
439 /* Uh oh... no free descriptor... drop the packet */
440 netif_stop_queue(dev);
441 spin_unlock_irqrestore(&card->lock,flags);
442 trigger_transmit(card);
450 static int xircom_open(struct net_device *dev)
452 struct xircom_private *xp = netdev_priv(dev);
454 enter("xircom_open");
455 printk(KERN_INFO "xircom cardbus adaptor found, registering as %s, using irq %i \n",dev->name,dev->irq);
456 retval = request_irq(dev->irq, &xircom_interrupt, IRQF_SHARED, dev->name, dev);
458 leave("xircom_open - No IRQ");
464 leave("xircom_open");
468 static int xircom_close(struct net_device *dev)
470 struct xircom_private *card;
473 enter("xircom_close");
474 card = netdev_priv(dev);
475 netif_stop_queue(dev); /* we don't want new packets */
478 spin_lock_irqsave(&card->lock,flags);
480 disable_all_interrupts(card);
482 /* We can enable this again once we send dummy packets on ifconfig ethX up */
483 deactivate_receiver(card);
484 deactivate_transmitter(card);
486 remove_descriptors(card);
488 spin_unlock_irqrestore(&card->lock,flags);
491 free_irq(dev->irq,dev);
493 leave("xircom_close");
501 static struct net_device_stats *xircom_get_stats(struct net_device *dev)
503 struct xircom_private *card = netdev_priv(dev);
508 #ifdef CONFIG_NET_POLL_CONTROLLER
509 static void xircom_poll_controller(struct net_device *dev)
511 disable_irq(dev->irq);
512 xircom_interrupt(dev->irq, dev);
513 enable_irq(dev->irq);
518 static void initialize_card(struct xircom_private *card)
522 enter("initialize_card");
525 spin_lock_irqsave(&card->lock, flags);
527 /* First: reset the card */
528 val = inl(card->io_port + CSR0);
529 val |= 0x01; /* Software reset */
530 outl(val, card->io_port + CSR0);
532 udelay(100); /* give the card some time to reset */
534 val = inl(card->io_port + CSR0);
535 val &= ~0x01; /* disable Software reset */
536 outl(val, card->io_port + CSR0);
539 val = 0; /* Value 0x00 is a safe and conservative value
540 for the PCI configuration settings */
541 outl(val, card->io_port + CSR0);
544 disable_all_interrupts(card);
545 deactivate_receiver(card);
546 deactivate_transmitter(card);
548 spin_unlock_irqrestore(&card->lock, flags);
550 leave("initialize_card");
554 trigger_transmit causes the card to check for frames to be transmitted.
555 This is accomplished by writing to the CSR1 port. The documentation
556 claims that the act of writing is sufficient and that the value is
557 ignored; I chose zero.
559 static void trigger_transmit(struct xircom_private *card)
562 enter("trigger_transmit");
565 outl(val, card->io_port + CSR1);
567 leave("trigger_transmit");
571 trigger_receive causes the card to check for empty frames in the
572 descriptor list in which packets can be received.
573 This is accomplished by writing to the CSR2 port. The documentation
574 claims that the act of writing is sufficient and that the value is
575 ignored; I chose zero.
577 static void trigger_receive(struct xircom_private *card)
580 enter("trigger_receive");
583 outl(val, card->io_port + CSR2);
585 leave("trigger_receive");
589 setup_descriptors initializes the send and receive buffers to be valid
590 descriptors and programs the addresses into the card.
592 static void setup_descriptors(struct xircom_private *card)
596 enter("setup_descriptors");
599 BUG_ON(card->rx_buffer == NULL);
600 BUG_ON(card->tx_buffer == NULL);
602 /* Receive descriptors */
603 memset(card->rx_buffer, 0, 128); /* clear the descriptors */
604 for (i=0;i<NUMDESCRIPTORS;i++ ) {
606 /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */
607 card->rx_buffer[i*4 + 0] = cpu_to_le32(0x80000000);
608 /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
609 card->rx_buffer[i*4 + 1] = cpu_to_le32(1536);
610 if (i == NUMDESCRIPTORS - 1) /* bit 25 is "last descriptor" */
611 card->rx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25);
613 /* Rx Descr2: address of the buffer
614 we store the buffer at the 2nd half of the page */
616 address = card->rx_dma_handle;
617 card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
618 /* Rx Desc3: address of 2nd buffer -> 0 */
619 card->rx_buffer[i*4 + 3] = 0;
623 /* Write the receive descriptor ring address to the card */
624 address = card->rx_dma_handle;
625 outl(address, card->io_port + CSR3); /* Receive descr list address */
628 /* transmit descriptors */
629 memset(card->tx_buffer, 0, 128); /* clear the descriptors */
631 for (i=0;i<NUMDESCRIPTORS;i++ ) {
632 /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */
633 card->tx_buffer[i*4 + 0] = 0x00000000;
634 /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
635 card->tx_buffer[i*4 + 1] = cpu_to_le32(1536);
636 if (i == NUMDESCRIPTORS - 1) /* bit 25 is "last descriptor" */
637 card->tx_buffer[i*4 + 1] |= cpu_to_le32(1 << 25);
639 /* Tx Descr2: address of the buffer
640 we store the buffer at the 2nd half of the page */
641 address = card->tx_dma_handle;
642 card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
643 /* Tx Desc3: address of 2nd buffer -> 0 */
644 card->tx_buffer[i*4 + 3] = 0;
648 /* wite the transmit descriptor ring to the card */
649 address = card->tx_dma_handle;
650 outl(address, card->io_port + CSR4); /* xmit descr list address */
652 leave("setup_descriptors");
656 remove_descriptors informs the card the descriptors are no longer
657 valid by setting the address in the card to 0x00.
659 static void remove_descriptors(struct xircom_private *card)
662 enter("remove_descriptors");
665 outl(val, card->io_port + CSR3); /* Receive descriptor address */
666 outl(val, card->io_port + CSR4); /* Send descriptor address */
668 leave("remove_descriptors");
672 link_status_changed returns 1 if the card has indicated that
673 the link status has changed. The new link status has to be read from CSR12.
675 This function also clears the status-bit.
677 static int link_status_changed(struct xircom_private *card)
680 enter("link_status_changed");
682 val = inl(card->io_port + CSR5); /* Status register */
684 if ((val & (1 << 27)) == 0) { /* no change */
685 leave("link_status_changed - nochange");
689 /* clear the event by writing a 1 to the bit in the
692 outl(val, card->io_port + CSR5);
694 leave("link_status_changed - changed");
700 transmit_active returns 1 if the transmitter on the card is
701 in a non-stopped state.
703 static int transmit_active(struct xircom_private *card)
706 enter("transmit_active");
708 val = inl(card->io_port + CSR5); /* Status register */
710 if ((val & (7 << 20)) == 0) { /* transmitter disabled */
711 leave("transmit_active - inactive");
715 leave("transmit_active - active");
720 receive_active returns 1 if the receiver on the card is
721 in a non-stopped state.
723 static int receive_active(struct xircom_private *card)
726 enter("receive_active");
729 val = inl(card->io_port + CSR5); /* Status register */
731 if ((val & (7 << 17)) == 0) { /* receiver disabled */
732 leave("receive_active - inactive");
736 leave("receive_active - active");
741 activate_receiver enables the receiver on the card.
742 Before being allowed to active the receiver, the receiver
743 must be completely de-activated. To achieve this,
744 this code actually disables the receiver first; then it waits for the
745 receiver to become inactive, then it activates the receiver and then
746 it waits for the receiver to be active.
748 must be called with the lock held and interrupts disabled.
750 static void activate_receiver(struct xircom_private *card)
754 enter("activate_receiver");
757 val = inl(card->io_port + CSR6); /* Operation mode */
759 /* If the "active" bit is set and the receiver is already
760 active, no need to do the expensive thing */
761 if ((val&2) && (receive_active(card)))
765 val = val & ~2; /* disable the receiver */
766 outl(val, card->io_port + CSR6);
769 while (counter > 0) {
770 if (!receive_active(card))
776 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
779 /* enable the receiver */
780 val = inl(card->io_port + CSR6); /* Operation mode */
781 val = val | 2; /* enable the receiver */
782 outl(val, card->io_port + CSR6);
784 /* now wait for the card to activate again */
786 while (counter > 0) {
787 if (receive_active(card))
793 printk(KERN_ERR "xircom_cb: Receiver failed to re-activate\n");
796 leave("activate_receiver");
800 deactivate_receiver disables the receiver on the card.
801 To achieve this this code disables the receiver first;
802 then it waits for the receiver to become inactive.
804 must be called with the lock held and interrupts disabled.
806 static void deactivate_receiver(struct xircom_private *card)
810 enter("deactivate_receiver");
812 val = inl(card->io_port + CSR6); /* Operation mode */
813 val = val & ~2; /* disable the receiver */
814 outl(val, card->io_port + CSR6);
817 while (counter > 0) {
818 if (!receive_active(card))
824 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
828 leave("deactivate_receiver");
833 activate_transmitter enables the transmitter on the card.
834 Before being allowed to active the transmitter, the transmitter
835 must be completely de-activated. To achieve this,
836 this code actually disables the transmitter first; then it waits for the
837 transmitter to become inactive, then it activates the transmitter and then
838 it waits for the transmitter to be active again.
840 must be called with the lock held and interrupts disabled.
842 static void activate_transmitter(struct xircom_private *card)
846 enter("activate_transmitter");
849 val = inl(card->io_port + CSR6); /* Operation mode */
851 /* If the "active" bit is set and the receiver is already
852 active, no need to do the expensive thing */
853 if ((val&(1<<13)) && (transmit_active(card)))
856 val = val & ~(1 << 13); /* disable the transmitter */
857 outl(val, card->io_port + CSR6);
860 while (counter > 0) {
861 if (!transmit_active(card))
867 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
870 /* enable the transmitter */
871 val = inl(card->io_port + CSR6); /* Operation mode */
872 val = val | (1 << 13); /* enable the transmitter */
873 outl(val, card->io_port + CSR6);
875 /* now wait for the card to activate again */
877 while (counter > 0) {
878 if (transmit_active(card))
884 printk(KERN_ERR "xircom_cb: Transmitter failed to re-activate\n");
887 leave("activate_transmitter");
891 deactivate_transmitter disables the transmitter on the card.
892 To achieve this this code disables the transmitter first;
893 then it waits for the transmitter to become inactive.
895 must be called with the lock held and interrupts disabled.
897 static void deactivate_transmitter(struct xircom_private *card)
901 enter("deactivate_transmitter");
903 val = inl(card->io_port + CSR6); /* Operation mode */
904 val = val & ~2; /* disable the transmitter */
905 outl(val, card->io_port + CSR6);
908 while (counter > 0) {
909 if (!transmit_active(card))
915 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
919 leave("deactivate_transmitter");
924 enable_transmit_interrupt enables the transmit interrupt
926 must be called with the lock held and interrupts disabled.
928 static void enable_transmit_interrupt(struct xircom_private *card)
931 enter("enable_transmit_interrupt");
933 val = inl(card->io_port + CSR7); /* Interrupt enable register */
934 val |= 1; /* enable the transmit interrupt */
935 outl(val, card->io_port + CSR7);
937 leave("enable_transmit_interrupt");
942 enable_receive_interrupt enables the receive interrupt
944 must be called with the lock held and interrupts disabled.
946 static void enable_receive_interrupt(struct xircom_private *card)
949 enter("enable_receive_interrupt");
951 val = inl(card->io_port + CSR7); /* Interrupt enable register */
952 val = val | (1 << 6); /* enable the receive interrupt */
953 outl(val, card->io_port + CSR7);
955 leave("enable_receive_interrupt");
959 enable_link_interrupt enables the link status change interrupt
961 must be called with the lock held and interrupts disabled.
963 static void enable_link_interrupt(struct xircom_private *card)
966 enter("enable_link_interrupt");
968 val = inl(card->io_port + CSR7); /* Interrupt enable register */
969 val = val | (1 << 27); /* enable the link status chage interrupt */
970 outl(val, card->io_port + CSR7);
972 leave("enable_link_interrupt");
978 disable_all_interrupts disables all interrupts
980 must be called with the lock held and interrupts disabled.
982 static void disable_all_interrupts(struct xircom_private *card)
985 enter("enable_all_interrupts");
987 val = 0; /* disable all interrupts */
988 outl(val, card->io_port + CSR7);
990 leave("disable_all_interrupts");
994 enable_common_interrupts enables several weird interrupts
996 must be called with the lock held and interrupts disabled.
998 static void enable_common_interrupts(struct xircom_private *card)
1001 enter("enable_link_interrupt");
1003 val = inl(card->io_port + CSR7); /* Interrupt enable register */
1004 val |= (1<<16); /* Normal Interrupt Summary */
1005 val |= (1<<15); /* Abnormal Interrupt Summary */
1006 val |= (1<<13); /* Fatal bus error */
1007 val |= (1<<8); /* Receive Process Stopped */
1008 val |= (1<<7); /* Receive Buffer Unavailable */
1009 val |= (1<<5); /* Transmit Underflow */
1010 val |= (1<<2); /* Transmit Buffer Unavailable */
1011 val |= (1<<1); /* Transmit Process Stopped */
1012 outl(val, card->io_port + CSR7);
1014 leave("enable_link_interrupt");
1018 enable_promisc starts promisc mode
1020 must be called with the lock held and interrupts disabled.
1022 static int enable_promisc(struct xircom_private *card)
1025 enter("enable_promisc");
1027 val = inl(card->io_port + CSR6);
1028 val = val | (1 << 6);
1029 outl(val, card->io_port + CSR6);
1031 leave("enable_promisc");
1039 link_status() checks the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1041 Must be called in locked state with interrupts disabled
1043 static int link_status(struct xircom_private *card)
1046 enter("link_status");
1048 val = inb(card->io_port + CSR12);
1050 if (!(val&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */
1052 if (!(val&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1055 /* If we get here -> no link at all */
1057 leave("link_status");
1066 read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure.
1068 This function will take the spinlock itself and can, as a result, not be called with the lock helt.
1070 static void read_mac_address(struct xircom_private *card)
1072 unsigned char j, tuple, link, data_id, data_count;
1073 unsigned long flags;
1075 DECLARE_MAC_BUF(mac);
1077 enter("read_mac_address");
1079 spin_lock_irqsave(&card->lock, flags);
1081 outl(1 << 12, card->io_port + CSR9); /* enable boot rom access */
1082 for (i = 0x100; i < 0x1f7; i += link + 2) {
1083 outl(i, card->io_port + CSR10);
1084 tuple = inl(card->io_port + CSR9) & 0xff;
1085 outl(i + 1, card->io_port + CSR10);
1086 link = inl(card->io_port + CSR9) & 0xff;
1087 outl(i + 2, card->io_port + CSR10);
1088 data_id = inl(card->io_port + CSR9) & 0xff;
1089 outl(i + 3, card->io_port + CSR10);
1090 data_count = inl(card->io_port + CSR9) & 0xff;
1091 if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) {
1093 * This is it. We have the data we want.
1095 for (j = 0; j < 6; j++) {
1096 outl(i + j + 4, card->io_port + CSR10);
1097 card->dev->dev_addr[j] = inl(card->io_port + CSR9) & 0xff;
1100 } else if (link == 0) {
1104 spin_unlock_irqrestore(&card->lock, flags);
1105 pr_debug(" %s\n", print_mac(mac, card->dev->dev_addr));
1106 leave("read_mac_address");
1111 transceiver_voodoo() enables the external UTP plug thingy.
1112 it's called voodoo as I stole this code and cannot cross-reference
1113 it with the specification.
1115 static void transceiver_voodoo(struct xircom_private *card)
1117 unsigned long flags;
1119 enter("transceiver_voodoo");
1121 /* disable all powermanagement */
1122 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1124 setup_descriptors(card);
1126 spin_lock_irqsave(&card->lock, flags);
1128 outl(0x0008, card->io_port + CSR15);
1130 outl(0xa8050000, card->io_port + CSR15);
1132 outl(0xa00f0000, card->io_port + CSR15);
1135 spin_unlock_irqrestore(&card->lock, flags);
1137 netif_start_queue(card->dev);
1138 leave("transceiver_voodoo");
1142 static void xircom_up(struct xircom_private *card)
1144 unsigned long flags;
1149 /* disable all powermanagement */
1150 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1152 setup_descriptors(card);
1154 spin_lock_irqsave(&card->lock, flags);
1157 enable_link_interrupt(card);
1158 enable_transmit_interrupt(card);
1159 enable_receive_interrupt(card);
1160 enable_common_interrupts(card);
1161 enable_promisc(card);
1163 /* The card can have received packets already, read them away now */
1164 for (i=0;i<NUMDESCRIPTORS;i++)
1165 investigate_read_descriptor(card->dev,card,i,bufferoffsets[i]);
1168 spin_unlock_irqrestore(&card->lock, flags);
1169 trigger_receive(card);
1170 trigger_transmit(card);
1171 netif_start_queue(card->dev);
1175 /* Bufferoffset is in BYTES */
1176 static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset)
1180 enter("investigate_read_descriptor");
1181 status = le32_to_cpu(card->rx_buffer[4*descnr]);
1183 if ((status > 0)) { /* packet received */
1185 /* TODO: discard error packets */
1187 short pkt_len = ((status >> 16) & 0x7ff) - 4; /* minus 4, we don't want the CRC */
1188 struct sk_buff *skb;
1190 if (pkt_len > 1518) {
1191 printk(KERN_ERR "xircom_cb: Packet length %i is bogus \n",pkt_len);
1195 skb = dev_alloc_skb(pkt_len + 2);
1197 card->stats.rx_dropped++;
1200 skb_reserve(skb, 2);
1201 skb_copy_to_linear_data(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len);
1202 skb_put(skb, pkt_len);
1203 skb->protocol = eth_type_trans(skb, dev);
1205 dev->last_rx = jiffies;
1206 card->stats.rx_packets++;
1207 card->stats.rx_bytes += pkt_len;
1210 /* give the buffer back to the card */
1211 card->rx_buffer[4*descnr] = cpu_to_le32(0x80000000);
1212 trigger_receive(card);
1215 leave("investigate_read_descriptor");
1220 /* Bufferoffset is in BYTES */
1221 static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset)
1225 enter("investigate_write_descriptor");
1227 status = le32_to_cpu(card->tx_buffer[4*descnr]);
1229 if (status & 0x8000) { /* Major error */
1230 printk(KERN_ERR "Major transmit error status %x \n", status);
1231 card->tx_buffer[4*descnr] = 0;
1232 netif_wake_queue (dev);
1235 if (status > 0) { /* bit 31 is 0 when done */
1236 if (card->tx_skb[descnr]!=NULL) {
1237 card->stats.tx_bytes += card->tx_skb[descnr]->len;
1238 dev_kfree_skb_irq(card->tx_skb[descnr]);
1240 card->tx_skb[descnr] = NULL;
1241 /* Bit 8 in the status field is 1 if there was a collision */
1243 card->stats.collisions++;
1244 card->tx_buffer[4*descnr] = 0; /* descriptor is free again */
1245 netif_wake_queue (dev);
1246 card->stats.tx_packets++;
1249 leave("investigate_write_descriptor");
1254 static int __init xircom_init(void)
1256 return pci_register_driver(&xircom_ops);
1259 static void __exit xircom_exit(void)
1261 pci_unregister_driver(&xircom_ops);
1264 module_init(xircom_init)
1265 module_exit(xircom_exit)