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 if (card
->rx_buffer
== NULL
)
603 if (card
->tx_buffer
== NULL
)
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;
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;
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
)
668 enter("remove_descriptors");
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
)
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");
695 /* clear the event by writing a 1 to the bit in the
698 outl(val
, card
->io_port
+ CSR5
);
700 leave("link_status_changed - changed");
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
)
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");
721 leave("transmit_active - active");
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
)
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");
742 leave("receive_active - active");
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
)
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
)))
771 val
= val
& ~2; /* disable the receiver */
772 outl(val
, card
->io_port
+ CSR6
);
775 while (counter
> 0) {
776 if (!receive_active(card
))
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 */
792 while (counter
> 0) {
793 if (receive_active(card
))
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
)
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
);
823 while (counter
> 0) {
824 if (!receive_active(card
))
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
)
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
)))
862 val
= val
& ~(1 << 13); /* disable the transmitter */
863 outl(val
, card
->io_port
+ CSR6
);
866 while (counter
> 0) {
867 if (!transmit_active(card
))
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 */
883 while (counter
> 0) {
884 if (transmit_active(card
))
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
)
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
);
914 while (counter
> 0) {
915 if (!transmit_active(card
))
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
)
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
)
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
)
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
)
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
)
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
)
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");
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
)
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 */
1058 if (!(val
&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1061 /* If we get here -> no link at all */
1063 leave("link_status");
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
;
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;
1105 } else if (link
== 0) {
1109 spin_unlock_irqrestore(&card
->lock
, flags
);
1111 for (i
= 0; i
< 6; i
++)
1112 printk("%c%2.2X", i
? ':' : ' ', card
->dev
->dev_addr
[i
]);
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
);
1139 outl(0xa8050000, card
->io_port
+ CSR15
);
1141 outl(0xa00f0000, card
->io_port
+ CSR15
);
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
;
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
);
1184 /* Bufferoffset is in BYTES */
1185 static void investigate_read_descriptor(struct net_device
*dev
,struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
)
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
);
1204 skb
= dev_alloc_skb(pkt_len
+ 2);
1206 card
->stats
.rx_dropped
++;
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
);
1215 dev
->last_rx
= jiffies
;
1216 card
->stats
.rx_packets
++;
1217 card
->stats
.rx_bytes
+= pkt_len
;
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
)
1235 enter("investigate_write_descriptor");
1237 status
= card
->tx_buffer
[4*descnr
];
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
);
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 */
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
);
1270 static void __exit
xircom_exit(void)
1272 pci_unregister_driver(&xircom_ops
);
1275 module_init(xircom_init
)
1276 module_exit(xircom_exit
)