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>
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__)
40 #define enter(x) do {} while (0)
41 #define leave(x) do {} while (0)
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 */
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;
94 /* transmit_used is the rotating counter that indicates which transmit
95 descriptor has to be used next */
98 /* Spinlock to serialize register operations.
99 It must be helt while manipulating the following registers:
100 CSR0, CSR6, CSR7, CSR9, CSR10, CSR15
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 #ifdef CONFIG_NET_POLL_CONTROLLER
121 static void xircom_poll_controller(struct net_device *dev);
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,},
150 MODULE_DEVICE_TABLE(pci, xircom_pci_table);
152 static struct pci_driver xircom_ops = {
154 .id_table = xircom_pci_table,
155 .probe = xircom_probe,
156 .remove = xircom_remove,
163 static void print_binary(unsigned int number)
169 for (i=31;i>=0;i--) {
177 printk("%s\n",buffer);
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;
207 unsigned short tmp16;
208 enter("xircom_probe");
210 /* First do the PCI initialisation */
212 if (pci_enable_device(pdev))
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");
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_MODULE_OWNER(dev);
256 SET_NETDEV_DEV(dev, &pdev->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;
275 #ifdef CONFIG_NET_POLL_CONTROLLER
276 dev->poll_controller = &xircom_poll_controller;
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");
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");
302 kfree(private->tx_buffer);
304 kfree(private->rx_buffer);
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"
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);
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);
341 enter("xircom_interrupt\n");
343 spin_lock(&card->lock);
344 status = inl(card->io_port+CSR5);
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]);
351 /* Handle shared irq and hotplug */
352 if (status == 0 || status == 0xffffffff) {
353 spin_unlock(&card->lock);
357 if (link_status_changed(card)) {
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);
363 netif_carrier_on(dev);
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");
386 static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
388 struct xircom_private *card;
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
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;
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);
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);
451 static int xircom_open(struct net_device *dev)
453 struct xircom_private *xp = netdev_priv(dev);
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);
459 leave("xircom_open - No IRQ");
465 leave("xircom_open");
469 static int xircom_close(struct net_device *dev)
471 struct xircom_private *card;
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);
483 /* We can enable this again once we send dummy packets on ifconfig ethX up */
484 deactivate_receiver(card);
485 deactivate_transmitter(card);
487 remove_descriptors(card);
489 spin_unlock_irqrestore(&card->lock,flags);
492 free_irq(dev->irq,dev);
494 leave("xircom_close");
502 static struct net_device_stats *xircom_get_stats(struct net_device *dev)
504 struct xircom_private *card = netdev_priv(dev);
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);
519 static void initialize_card(struct xircom_private *card)
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)
563 enter("trigger_transmit");
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)
581 enter("trigger_receive");
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)
596 unsigned int address;
598 enter("setup_descriptors");
601 BUG_ON(card->rx_buffer == NULL);
602 BUG_ON(card->tx_buffer == NULL);
604 /* Receive descriptors */
605 memset(card->rx_buffer, 0, 128); /* clear the descriptors */
606 for (i=0;i<NUMDESCRIPTORS;i++ ) {
608 /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */
609 card->rx_buffer[i*4 + 0] = 0x80000000;
610 /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
611 card->rx_buffer[i*4 + 1] = 1536;
612 if (i==NUMDESCRIPTORS-1)
613 card->rx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
615 /* Rx Descr2: address of the buffer
616 we store the buffer at the 2nd half of the page */
618 address = (unsigned long) card->rx_dma_handle;
619 card->rx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
620 /* Rx Desc3: address of 2nd buffer -> 0 */
621 card->rx_buffer[i*4 + 3] = 0;
625 /* Write the receive descriptor ring address to the card */
626 address = (unsigned long) card->rx_dma_handle;
627 val = cpu_to_le32(address);
628 outl(val, card->io_port + CSR3); /* Receive descr list address */
631 /* transmit descriptors */
632 memset(card->tx_buffer, 0, 128); /* clear the descriptors */
634 for (i=0;i<NUMDESCRIPTORS;i++ ) {
635 /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */
636 card->tx_buffer[i*4 + 0] = 0x00000000;
637 /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
638 card->tx_buffer[i*4 + 1] = 1536;
639 if (i==NUMDESCRIPTORS-1)
640 card->tx_buffer[i*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
642 /* Tx Descr2: address of the buffer
643 we store the buffer at the 2nd half of the page */
644 address = (unsigned long) card->tx_dma_handle;
645 card->tx_buffer[i*4 + 2] = cpu_to_le32(address + bufferoffsets[i]);
646 /* Tx Desc3: address of 2nd buffer -> 0 */
647 card->tx_buffer[i*4 + 3] = 0;
651 /* wite the transmit descriptor ring to the card */
652 address = (unsigned long) card->tx_dma_handle;
653 val =cpu_to_le32(address);
654 outl(val, card->io_port + CSR4); /* xmit descr list address */
656 leave("setup_descriptors");
660 remove_descriptors informs the card the descriptors are no longer
661 valid by setting the address in the card to 0x00.
663 static void remove_descriptors(struct xircom_private *card)
666 enter("remove_descriptors");
669 outl(val, card->io_port + CSR3); /* Receive descriptor address */
670 outl(val, card->io_port + CSR4); /* Send descriptor address */
672 leave("remove_descriptors");
676 link_status_changed returns 1 if the card has indicated that
677 the link status has changed. The new link status has to be read from CSR12.
679 This function also clears the status-bit.
681 static int link_status_changed(struct xircom_private *card)
684 enter("link_status_changed");
686 val = inl(card->io_port + CSR5); /* Status register */
688 if ((val & (1 << 27)) == 0) { /* no change */
689 leave("link_status_changed - nochange");
693 /* clear the event by writing a 1 to the bit in the
696 outl(val, card->io_port + CSR5);
698 leave("link_status_changed - changed");
704 transmit_active returns 1 if the transmitter on the card is
705 in a non-stopped state.
707 static int transmit_active(struct xircom_private *card)
710 enter("transmit_active");
712 val = inl(card->io_port + CSR5); /* Status register */
714 if ((val & (7 << 20)) == 0) { /* transmitter disabled */
715 leave("transmit_active - inactive");
719 leave("transmit_active - active");
724 receive_active returns 1 if the receiver on the card is
725 in a non-stopped state.
727 static int receive_active(struct xircom_private *card)
730 enter("receive_active");
733 val = inl(card->io_port + CSR5); /* Status register */
735 if ((val & (7 << 17)) == 0) { /* receiver disabled */
736 leave("receive_active - inactive");
740 leave("receive_active - active");
745 activate_receiver enables the receiver on the card.
746 Before being allowed to active the receiver, the receiver
747 must be completely de-activated. To achieve this,
748 this code actually disables the receiver first; then it waits for the
749 receiver to become inactive, then it activates the receiver and then
750 it waits for the receiver to be active.
752 must be called with the lock held and interrupts disabled.
754 static void activate_receiver(struct xircom_private *card)
758 enter("activate_receiver");
761 val = inl(card->io_port + CSR6); /* Operation mode */
763 /* If the "active" bit is set and the receiver is already
764 active, no need to do the expensive thing */
765 if ((val&2) && (receive_active(card)))
769 val = val & ~2; /* disable the receiver */
770 outl(val, card->io_port + CSR6);
773 while (counter > 0) {
774 if (!receive_active(card))
780 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
783 /* enable the receiver */
784 val = inl(card->io_port + CSR6); /* Operation mode */
785 val = val | 2; /* enable the receiver */
786 outl(val, card->io_port + CSR6);
788 /* now wait for the card to activate again */
790 while (counter > 0) {
791 if (receive_active(card))
797 printk(KERN_ERR "xircom_cb: Receiver failed to re-activate\n");
800 leave("activate_receiver");
804 deactivate_receiver disables the receiver on the card.
805 To achieve this this code disables the receiver first;
806 then it waits for the receiver to become inactive.
808 must be called with the lock held and interrupts disabled.
810 static void deactivate_receiver(struct xircom_private *card)
814 enter("deactivate_receiver");
816 val = inl(card->io_port + CSR6); /* Operation mode */
817 val = val & ~2; /* disable the receiver */
818 outl(val, card->io_port + CSR6);
821 while (counter > 0) {
822 if (!receive_active(card))
828 printk(KERN_ERR "xircom_cb: Receiver failed to deactivate\n");
832 leave("deactivate_receiver");
837 activate_transmitter enables the transmitter on the card.
838 Before being allowed to active the transmitter, the transmitter
839 must be completely de-activated. To achieve this,
840 this code actually disables the transmitter first; then it waits for the
841 transmitter to become inactive, then it activates the transmitter and then
842 it waits for the transmitter to be active again.
844 must be called with the lock held and interrupts disabled.
846 static void activate_transmitter(struct xircom_private *card)
850 enter("activate_transmitter");
853 val = inl(card->io_port + CSR6); /* Operation mode */
855 /* If the "active" bit is set and the receiver is already
856 active, no need to do the expensive thing */
857 if ((val&(1<<13)) && (transmit_active(card)))
860 val = val & ~(1 << 13); /* disable the transmitter */
861 outl(val, card->io_port + CSR6);
864 while (counter > 0) {
865 if (!transmit_active(card))
871 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
874 /* enable the transmitter */
875 val = inl(card->io_port + CSR6); /* Operation mode */
876 val = val | (1 << 13); /* enable the transmitter */
877 outl(val, card->io_port + CSR6);
879 /* now wait for the card to activate again */
881 while (counter > 0) {
882 if (transmit_active(card))
888 printk(KERN_ERR "xircom_cb: Transmitter failed to re-activate\n");
891 leave("activate_transmitter");
895 deactivate_transmitter disables the transmitter on the card.
896 To achieve this this code disables the transmitter first;
897 then it waits for the transmitter to become inactive.
899 must be called with the lock held and interrupts disabled.
901 static void deactivate_transmitter(struct xircom_private *card)
905 enter("deactivate_transmitter");
907 val = inl(card->io_port + CSR6); /* Operation mode */
908 val = val & ~2; /* disable the transmitter */
909 outl(val, card->io_port + CSR6);
912 while (counter > 0) {
913 if (!transmit_active(card))
919 printk(KERN_ERR "xircom_cb: Transmitter failed to deactivate\n");
923 leave("deactivate_transmitter");
928 enable_transmit_interrupt enables the transmit interrupt
930 must be called with the lock held and interrupts disabled.
932 static void enable_transmit_interrupt(struct xircom_private *card)
935 enter("enable_transmit_interrupt");
937 val = inl(card->io_port + CSR7); /* Interrupt enable register */
938 val |= 1; /* enable the transmit interrupt */
939 outl(val, card->io_port + CSR7);
941 leave("enable_transmit_interrupt");
946 enable_receive_interrupt enables the receive interrupt
948 must be called with the lock held and interrupts disabled.
950 static void enable_receive_interrupt(struct xircom_private *card)
953 enter("enable_receive_interrupt");
955 val = inl(card->io_port + CSR7); /* Interrupt enable register */
956 val = val | (1 << 6); /* enable the receive interrupt */
957 outl(val, card->io_port + CSR7);
959 leave("enable_receive_interrupt");
963 enable_link_interrupt enables the link status change interrupt
965 must be called with the lock held and interrupts disabled.
967 static void enable_link_interrupt(struct xircom_private *card)
970 enter("enable_link_interrupt");
972 val = inl(card->io_port + CSR7); /* Interrupt enable register */
973 val = val | (1 << 27); /* enable the link status chage interrupt */
974 outl(val, card->io_port + CSR7);
976 leave("enable_link_interrupt");
982 disable_all_interrupts disables all interrupts
984 must be called with the lock held and interrupts disabled.
986 static void disable_all_interrupts(struct xircom_private *card)
989 enter("enable_all_interrupts");
991 val = 0; /* disable all interrupts */
992 outl(val, card->io_port + CSR7);
994 leave("disable_all_interrupts");
998 enable_common_interrupts enables several weird interrupts
1000 must be called with the lock held and interrupts disabled.
1002 static void enable_common_interrupts(struct xircom_private *card)
1005 enter("enable_link_interrupt");
1007 val = inl(card->io_port + CSR7); /* Interrupt enable register */
1008 val |= (1<<16); /* Normal Interrupt Summary */
1009 val |= (1<<15); /* Abnormal Interrupt Summary */
1010 val |= (1<<13); /* Fatal bus error */
1011 val |= (1<<8); /* Receive Process Stopped */
1012 val |= (1<<7); /* Receive Buffer Unavailable */
1013 val |= (1<<5); /* Transmit Underflow */
1014 val |= (1<<2); /* Transmit Buffer Unavailable */
1015 val |= (1<<1); /* Transmit Process Stopped */
1016 outl(val, card->io_port + CSR7);
1018 leave("enable_link_interrupt");
1022 enable_promisc starts promisc mode
1024 must be called with the lock held and interrupts disabled.
1026 static int enable_promisc(struct xircom_private *card)
1029 enter("enable_promisc");
1031 val = inl(card->io_port + CSR6);
1032 val = val | (1 << 6);
1033 outl(val, card->io_port + CSR6);
1035 leave("enable_promisc");
1043 link_status() checks the the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1045 Must be called in locked state with interrupts disabled
1047 static int link_status(struct xircom_private *card)
1050 enter("link_status");
1052 val = inb(card->io_port + CSR12);
1054 if (!(val&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */
1056 if (!(val&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1059 /* If we get here -> no link at all */
1061 leave("link_status");
1070 read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure.
1072 This function will take the spinlock itself and can, as a result, not be called with the lock helt.
1074 static void read_mac_address(struct xircom_private *card)
1076 unsigned char j, tuple, link, data_id, data_count;
1077 unsigned long flags;
1080 enter("read_mac_address");
1082 spin_lock_irqsave(&card->lock, flags);
1084 outl(1 << 12, card->io_port + CSR9); /* enable boot rom access */
1085 for (i = 0x100; i < 0x1f7; i += link + 2) {
1086 outl(i, card->io_port + CSR10);
1087 tuple = inl(card->io_port + CSR9) & 0xff;
1088 outl(i + 1, card->io_port + CSR10);
1089 link = inl(card->io_port + CSR9) & 0xff;
1090 outl(i + 2, card->io_port + CSR10);
1091 data_id = inl(card->io_port + CSR9) & 0xff;
1092 outl(i + 3, card->io_port + CSR10);
1093 data_count = inl(card->io_port + CSR9) & 0xff;
1094 if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) {
1096 * This is it. We have the data we want.
1098 for (j = 0; j < 6; j++) {
1099 outl(i + j + 4, card->io_port + CSR10);
1100 card->dev->dev_addr[j] = inl(card->io_port + CSR9) & 0xff;
1103 } else if (link == 0) {
1107 spin_unlock_irqrestore(&card->lock, flags);
1109 for (i = 0; i < 6; i++)
1110 printk("%c%2.2X", i ? ':' : ' ', card->dev->dev_addr[i]);
1113 leave("read_mac_address");
1118 transceiver_voodoo() enables the external UTP plug thingy.
1119 it's called voodoo as I stole this code and cannot cross-reference
1120 it with the specification.
1122 static void transceiver_voodoo(struct xircom_private *card)
1124 unsigned long flags;
1126 enter("transceiver_voodoo");
1128 /* disable all powermanagement */
1129 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1131 setup_descriptors(card);
1133 spin_lock_irqsave(&card->lock, flags);
1135 outl(0x0008, card->io_port + CSR15);
1137 outl(0xa8050000, card->io_port + CSR15);
1139 outl(0xa00f0000, card->io_port + CSR15);
1142 spin_unlock_irqrestore(&card->lock, flags);
1144 netif_start_queue(card->dev);
1145 leave("transceiver_voodoo");
1149 static void xircom_up(struct xircom_private *card)
1151 unsigned long flags;
1156 /* disable all powermanagement */
1157 pci_write_config_dword(card->pdev, PCI_POWERMGMT, 0x0000);
1159 setup_descriptors(card);
1161 spin_lock_irqsave(&card->lock, flags);
1164 enable_link_interrupt(card);
1165 enable_transmit_interrupt(card);
1166 enable_receive_interrupt(card);
1167 enable_common_interrupts(card);
1168 enable_promisc(card);
1170 /* The card can have received packets already, read them away now */
1171 for (i=0;i<NUMDESCRIPTORS;i++)
1172 investigate_read_descriptor(card->dev,card,i,bufferoffsets[i]);
1175 spin_unlock_irqrestore(&card->lock, flags);
1176 trigger_receive(card);
1177 trigger_transmit(card);
1178 netif_start_queue(card->dev);
1182 /* Bufferoffset is in BYTES */
1183 static void investigate_read_descriptor(struct net_device *dev,struct xircom_private *card, int descnr, unsigned int bufferoffset)
1187 enter("investigate_read_descriptor");
1188 status = card->rx_buffer[4*descnr];
1190 if ((status > 0)) { /* packet received */
1192 /* TODO: discard error packets */
1194 short pkt_len = ((status >> 16) & 0x7ff) - 4; /* minus 4, we don't want the CRC */
1195 struct sk_buff *skb;
1197 if (pkt_len > 1518) {
1198 printk(KERN_ERR "xircom_cb: Packet length %i is bogus \n",pkt_len);
1202 skb = dev_alloc_skb(pkt_len + 2);
1204 card->stats.rx_dropped++;
1208 skb_reserve(skb, 2);
1209 eth_copy_and_sum(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len, 0);
1210 skb_put(skb, pkt_len);
1211 skb->protocol = eth_type_trans(skb, dev);
1213 dev->last_rx = jiffies;
1214 card->stats.rx_packets++;
1215 card->stats.rx_bytes += pkt_len;
1218 /* give the buffer back to the card */
1219 card->rx_buffer[4*descnr] = 0x80000000;
1220 trigger_receive(card);
1223 leave("investigate_read_descriptor");
1228 /* Bufferoffset is in BYTES */
1229 static void investigate_write_descriptor(struct net_device *dev, struct xircom_private *card, int descnr, unsigned int bufferoffset)
1233 enter("investigate_write_descriptor");
1235 status = card->tx_buffer[4*descnr];
1237 if (status & 0x8000) { /* Major error */
1238 printk(KERN_ERR "Major transmit error status %x \n", status);
1239 card->tx_buffer[4*descnr] = 0;
1240 netif_wake_queue (dev);
1243 if (status > 0) { /* bit 31 is 0 when done */
1244 if (card->tx_skb[descnr]!=NULL) {
1245 card->stats.tx_bytes += card->tx_skb[descnr]->len;
1246 dev_kfree_skb_irq(card->tx_skb[descnr]);
1248 card->tx_skb[descnr] = NULL;
1249 /* Bit 8 in the status field is 1 if there was a collision */
1251 card->stats.collisions++;
1252 card->tx_buffer[4*descnr] = 0; /* descriptor is free again */
1253 netif_wake_queue (dev);
1254 card->stats.tx_packets++;
1257 leave("investigate_write_descriptor");
1262 static int __init xircom_init(void)
1264 pci_register_driver(&xircom_ops);
1268 static void __exit xircom_exit(void)
1270 pci_unregister_driver(&xircom_ops);
1273 module_init(xircom_init)
1274 module_exit(xircom_exit)