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 */
86 unsigned int *rx_buffer
;
87 unsigned int *tx_buffer
;
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
, struct pt_regs
*regs
);
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 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;
208 unsigned char chip_rev
;
210 unsigned short tmp16
;
211 enter("xircom_probe");
213 /* First do the PCI initialisation */
215 if (pci_enable_device(pdev
))
218 /* disable all powermanagement */
219 pci_write_config_dword(pdev
, PCI_POWERMGMT
, 0x0000);
221 pci_set_master(pdev
); /* Why isn't this done by pci_enable_device ?*/
223 /* clear PCI status, if any */
224 pci_read_config_word (pdev
,PCI_STATUS
, &tmp16
);
225 pci_write_config_word (pdev
, PCI_STATUS
,tmp16
);
227 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &chip_rev
);
229 if (!request_region(pci_resource_start(pdev
, 0), 128, "xircom_cb")) {
230 printk(KERN_ERR
"xircom_probe: failed to allocate io-region\n");
235 Before changing the hardware, allocate the memory.
236 This way, we can fail gracefully if not enough memory
239 dev
= alloc_etherdev(sizeof(struct xircom_private
));
241 printk(KERN_ERR
"xircom_probe: failed to allocate etherdev\n");
244 private = netdev_priv(dev
);
246 /* Allocate the send/receive buffers */
247 private->rx_buffer
= pci_alloc_consistent(pdev
,8192,&private->rx_dma_handle
);
248 if (private->rx_buffer
== NULL
) {
249 printk(KERN_ERR
"xircom_probe: no memory for rx buffer \n");
252 private->tx_buffer
= pci_alloc_consistent(pdev
,8192,&private->tx_dma_handle
);
253 if (private->tx_buffer
== NULL
) {
254 printk(KERN_ERR
"xircom_probe: no memory for tx buffer \n");
258 SET_MODULE_OWNER(dev
);
259 SET_NETDEV_DEV(dev
, &pdev
->dev
);
263 private->pdev
= pdev
;
264 private->io_port
= pci_resource_start(pdev
, 0);
265 spin_lock_init(&private->lock
);
266 dev
->irq
= pdev
->irq
;
267 dev
->base_addr
= private->io_port
;
269 initialize_card(private);
270 read_mac_address(private);
271 setup_descriptors(private);
273 dev
->open
= &xircom_open
;
274 dev
->hard_start_xmit
= &xircom_start_xmit
;
275 dev
->stop
= &xircom_close
;
276 dev
->get_stats
= &xircom_get_stats
;
278 #ifdef CONFIG_NET_POLL_CONTROLLER
279 dev
->poll_controller
= &xircom_poll_controller
;
281 SET_ETHTOOL_OPS(dev
, &netdev_ethtool_ops
);
282 pci_set_drvdata(pdev
, dev
);
284 if (register_netdev(dev
)) {
285 printk(KERN_ERR
"xircom_probe: netdevice registration failed.\n");
289 printk(KERN_INFO
"%s: Xircom cardbus revision %i at irq %i \n", dev
->name
, chip_rev
, pdev
->irq
);
290 /* start the transmitter to get a heartbeat */
291 /* TODO: send 2 dummy packets here */
292 transceiver_voodoo(private);
294 spin_lock_irqsave(&private->lock
,flags
);
295 activate_transmitter(private);
296 activate_receiver(private);
297 spin_unlock_irqrestore(&private->lock
,flags
);
299 trigger_receive(private);
301 leave("xircom_probe");
305 kfree(private->tx_buffer
);
307 kfree(private->rx_buffer
);
316 xircom_remove is called on module-unload or on device-eject.
317 it unregisters the irq, io-region and network device.
318 Interrupts and such are already stopped in the "ifconfig ethX down"
321 static void __devexit
xircom_remove(struct pci_dev
*pdev
)
323 struct net_device
*dev
= pci_get_drvdata(pdev
);
324 struct xircom_private
*card
= netdev_priv(dev
);
326 enter("xircom_remove");
327 pci_free_consistent(pdev
,8192,card
->rx_buffer
,card
->rx_dma_handle
);
328 pci_free_consistent(pdev
,8192,card
->tx_buffer
,card
->tx_dma_handle
);
330 release_region(dev
->base_addr
, 128);
331 unregister_netdev(dev
);
333 pci_set_drvdata(pdev
, NULL
);
334 leave("xircom_remove");
337 static irqreturn_t
xircom_interrupt(int irq
, void *dev_instance
, struct pt_regs
*regs
)
339 struct net_device
*dev
= (struct net_device
*) dev_instance
;
340 struct xircom_private
*card
= netdev_priv(dev
);
344 enter("xircom_interrupt\n");
346 spin_lock(&card
->lock
);
347 status
= inl(card
->io_port
+CSR5
);
350 print_binary(status
);
351 printk("tx status 0x%08x 0x%08x \n",card
->tx_buffer
[0],card
->tx_buffer
[4]);
352 printk("rx status 0x%08x 0x%08x \n",card
->rx_buffer
[0],card
->rx_buffer
[4]);
354 /* Handle shared irq and hotplug */
355 if (status
== 0 || status
== 0xffffffff) {
356 spin_unlock(&card
->lock
);
360 if (link_status_changed(card
)) {
362 printk(KERN_DEBUG
"xircom_cb: Link status has changed \n");
363 newlink
= link_status(card
);
364 printk(KERN_INFO
"xircom_cb: Link is %i mbit \n",newlink
);
366 netif_carrier_on(dev
);
368 netif_carrier_off(dev
);
372 /* Clear all remaining interrupts */
373 status
|= 0xffffffff; /* FIXME: make this clear only the
374 real existing bits */
375 outl(status
,card
->io_port
+CSR5
);
378 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
379 investigate_write_descriptor(dev
,card
,i
,bufferoffsets
[i
]);
380 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
381 investigate_read_descriptor(dev
,card
,i
,bufferoffsets
[i
]);
384 spin_unlock(&card
->lock
);
385 leave("xircom_interrupt");
389 static int xircom_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
391 struct xircom_private
*card
;
395 enter("xircom_start_xmit");
397 card
= netdev_priv(dev
);
398 spin_lock_irqsave(&card
->lock
,flags
);
400 /* First see if we can free some descriptors */
401 for (desc
=0;desc
<NUMDESCRIPTORS
;desc
++)
402 investigate_write_descriptor(dev
,card
,desc
,bufferoffsets
[desc
]);
405 nextdescriptor
= (card
->transmit_used
+1) % (NUMDESCRIPTORS
);
406 desc
= card
->transmit_used
;
408 /* only send the packet if the descriptor is free */
409 if (card
->tx_buffer
[4*desc
]==0) {
410 /* Copy the packet data; zero the memory first as the card
411 sometimes sends more than you ask it to. */
413 memset(&card
->tx_buffer
[bufferoffsets
[desc
]/4],0,1536);
414 memcpy(&(card
->tx_buffer
[bufferoffsets
[desc
]/4]),skb
->data
,skb
->len
);
417 /* FIXME: The specification tells us that the length we send HAS to be a multiple of
420 card
->tx_buffer
[4*desc
+1] = skb
->len
;
421 if (desc
== NUMDESCRIPTORS
-1)
422 card
->tx_buffer
[4*desc
+1] |= (1<<25); /* bit 25: last descriptor of the ring */
424 card
->tx_buffer
[4*desc
+1] |= 0xF0000000;
425 /* 0xF0... means want interrupts*/
426 card
->tx_skb
[desc
] = skb
;
429 /* This gives the descriptor to the card */
430 card
->tx_buffer
[4*desc
] = 0x80000000;
431 trigger_transmit(card
);
432 if (((int)card
->tx_buffer
[nextdescriptor
*4])<0) { /* next descriptor is occupied... */
433 netif_stop_queue(dev
);
435 card
->transmit_used
= nextdescriptor
;
436 leave("xircom-start_xmit - sent");
437 spin_unlock_irqrestore(&card
->lock
,flags
);
443 /* Uh oh... no free descriptor... drop the packet */
444 netif_stop_queue(dev
);
445 spin_unlock_irqrestore(&card
->lock
,flags
);
446 trigger_transmit(card
);
454 static int xircom_open(struct net_device
*dev
)
456 struct xircom_private
*xp
= netdev_priv(dev
);
458 enter("xircom_open");
459 printk(KERN_INFO
"xircom cardbus adaptor found, registering as %s, using irq %i \n",dev
->name
,dev
->irq
);
460 retval
= request_irq(dev
->irq
, &xircom_interrupt
, SA_SHIRQ
, dev
->name
, dev
);
462 leave("xircom_open - No IRQ");
468 leave("xircom_open");
472 static int xircom_close(struct net_device
*dev
)
474 struct xircom_private
*card
;
477 enter("xircom_close");
478 card
= netdev_priv(dev
);
479 netif_stop_queue(dev
); /* we don't want new packets */
482 spin_lock_irqsave(&card
->lock
,flags
);
484 disable_all_interrupts(card
);
486 /* We can enable this again once we send dummy packets on ifconfig ethX up */
487 deactivate_receiver(card
);
488 deactivate_transmitter(card
);
490 remove_descriptors(card
);
492 spin_unlock_irqrestore(&card
->lock
,flags
);
495 free_irq(dev
->irq
,dev
);
497 leave("xircom_close");
505 static struct net_device_stats
*xircom_get_stats(struct net_device
*dev
)
507 struct xircom_private
*card
= netdev_priv(dev
);
512 #ifdef CONFIG_NET_POLL_CONTROLLER
513 static void xircom_poll_controller(struct net_device
*dev
)
515 disable_irq(dev
->irq
);
516 xircom_interrupt(dev
->irq
, dev
, NULL
);
517 enable_irq(dev
->irq
);
522 static void initialize_card(struct xircom_private
*card
)
526 enter("initialize_card");
529 spin_lock_irqsave(&card
->lock
, flags
);
531 /* First: reset the card */
532 val
= inl(card
->io_port
+ CSR0
);
533 val
|= 0x01; /* Software reset */
534 outl(val
, card
->io_port
+ CSR0
);
536 udelay(100); /* give the card some time to reset */
538 val
= inl(card
->io_port
+ CSR0
);
539 val
&= ~0x01; /* disable Software reset */
540 outl(val
, card
->io_port
+ CSR0
);
543 val
= 0; /* Value 0x00 is a safe and conservative value
544 for the PCI configuration settings */
545 outl(val
, card
->io_port
+ CSR0
);
548 disable_all_interrupts(card
);
549 deactivate_receiver(card
);
550 deactivate_transmitter(card
);
552 spin_unlock_irqrestore(&card
->lock
, flags
);
554 leave("initialize_card");
558 trigger_transmit causes the card to check for frames to be transmitted.
559 This is accomplished by writing to the CSR1 port. The documentation
560 claims that the act of writing is sufficient and that the value is
561 ignored; I chose zero.
563 static void trigger_transmit(struct xircom_private
*card
)
566 enter("trigger_transmit");
569 outl(val
, card
->io_port
+ CSR1
);
571 leave("trigger_transmit");
575 trigger_receive causes the card to check for empty frames in the
576 descriptor list in which packets can be received.
577 This is accomplished by writing to the CSR2 port. The documentation
578 claims that the act of writing is sufficient and that the value is
579 ignored; I chose zero.
581 static void trigger_receive(struct xircom_private
*card
)
584 enter("trigger_receive");
587 outl(val
, card
->io_port
+ CSR2
);
589 leave("trigger_receive");
593 setup_descriptors initializes the send and receive buffers to be valid
594 descriptors and programs the addresses into the card.
596 static void setup_descriptors(struct xircom_private
*card
)
599 unsigned int address
;
601 enter("setup_descriptors");
604 if (card
->rx_buffer
== NULL
)
606 if (card
->tx_buffer
== NULL
)
609 /* Receive descriptors */
610 memset(card
->rx_buffer
, 0, 128); /* clear the descriptors */
611 for (i
=0;i
<NUMDESCRIPTORS
;i
++ ) {
613 /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */
614 card
->rx_buffer
[i
*4 + 0] = 0x80000000;
615 /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
616 card
->rx_buffer
[i
*4 + 1] = 1536;
617 if (i
==NUMDESCRIPTORS
-1)
618 card
->rx_buffer
[i
*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
620 /* Rx Descr2: address of the buffer
621 we store the buffer at the 2nd half of the page */
623 address
= (unsigned long) card
->rx_dma_handle
;
624 card
->rx_buffer
[i
*4 + 2] = cpu_to_le32(address
+ bufferoffsets
[i
]);
625 /* Rx Desc3: address of 2nd buffer -> 0 */
626 card
->rx_buffer
[i
*4 + 3] = 0;
630 /* Write the receive descriptor ring address to the card */
631 address
= (unsigned long) card
->rx_dma_handle
;
632 val
= cpu_to_le32(address
);
633 outl(val
, card
->io_port
+ CSR3
); /* Receive descr list address */
636 /* transmit descriptors */
637 memset(card
->tx_buffer
, 0, 128); /* clear the descriptors */
639 for (i
=0;i
<NUMDESCRIPTORS
;i
++ ) {
640 /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */
641 card
->tx_buffer
[i
*4 + 0] = 0x00000000;
642 /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
643 card
->tx_buffer
[i
*4 + 1] = 1536;
644 if (i
==NUMDESCRIPTORS
-1)
645 card
->tx_buffer
[i
*4 + 1] |= (1 << 25); /* bit 25 is "last descriptor" */
647 /* Tx Descr2: address of the buffer
648 we store the buffer at the 2nd half of the page */
649 address
= (unsigned long) card
->tx_dma_handle
;
650 card
->tx_buffer
[i
*4 + 2] = cpu_to_le32(address
+ bufferoffsets
[i
]);
651 /* Tx Desc3: address of 2nd buffer -> 0 */
652 card
->tx_buffer
[i
*4 + 3] = 0;
656 /* wite the transmit descriptor ring to the card */
657 address
= (unsigned long) card
->tx_dma_handle
;
658 val
=cpu_to_le32(address
);
659 outl(val
, card
->io_port
+ CSR4
); /* xmit descr list address */
661 leave("setup_descriptors");
665 remove_descriptors informs the card the descriptors are no longer
666 valid by setting the address in the card to 0x00.
668 static void remove_descriptors(struct xircom_private
*card
)
671 enter("remove_descriptors");
674 outl(val
, card
->io_port
+ CSR3
); /* Receive descriptor address */
675 outl(val
, card
->io_port
+ CSR4
); /* Send descriptor address */
677 leave("remove_descriptors");
681 link_status_changed returns 1 if the card has indicated that
682 the link status has changed. The new link status has to be read from CSR12.
684 This function also clears the status-bit.
686 static int link_status_changed(struct xircom_private
*card
)
689 enter("link_status_changed");
691 val
= inl(card
->io_port
+ CSR5
); /* Status register */
693 if ((val
& (1 << 27)) == 0) { /* no change */
694 leave("link_status_changed - nochange");
698 /* clear the event by writing a 1 to the bit in the
701 outl(val
, card
->io_port
+ CSR5
);
703 leave("link_status_changed - changed");
709 transmit_active returns 1 if the transmitter on the card is
710 in a non-stopped state.
712 static int transmit_active(struct xircom_private
*card
)
715 enter("transmit_active");
717 val
= inl(card
->io_port
+ CSR5
); /* Status register */
719 if ((val
& (7 << 20)) == 0) { /* transmitter disabled */
720 leave("transmit_active - inactive");
724 leave("transmit_active - active");
729 receive_active returns 1 if the receiver on the card is
730 in a non-stopped state.
732 static int receive_active(struct xircom_private
*card
)
735 enter("receive_active");
738 val
= inl(card
->io_port
+ CSR5
); /* Status register */
740 if ((val
& (7 << 17)) == 0) { /* receiver disabled */
741 leave("receive_active - inactive");
745 leave("receive_active - active");
750 activate_receiver enables the receiver on the card.
751 Before being allowed to active the receiver, the receiver
752 must be completely de-activated. To achieve this,
753 this code actually disables the receiver first; then it waits for the
754 receiver to become inactive, then it activates the receiver and then
755 it waits for the receiver to be active.
757 must be called with the lock held and interrupts disabled.
759 static void activate_receiver(struct xircom_private
*card
)
763 enter("activate_receiver");
766 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
768 /* If the "active" bit is set and the receiver is already
769 active, no need to do the expensive thing */
770 if ((val
&2) && (receive_active(card
)))
774 val
= val
& ~2; /* disable the receiver */
775 outl(val
, card
->io_port
+ CSR6
);
778 while (counter
> 0) {
779 if (!receive_active(card
))
785 printk(KERN_ERR
"xircom_cb: Receiver failed to deactivate\n");
788 /* enable the receiver */
789 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
790 val
= val
| 2; /* enable the receiver */
791 outl(val
, card
->io_port
+ CSR6
);
793 /* now wait for the card to activate again */
795 while (counter
> 0) {
796 if (receive_active(card
))
802 printk(KERN_ERR
"xircom_cb: Receiver failed to re-activate\n");
805 leave("activate_receiver");
809 deactivate_receiver disables the receiver on the card.
810 To achieve this this code disables the receiver first;
811 then it waits for the receiver to become inactive.
813 must be called with the lock held and interrupts disabled.
815 static void deactivate_receiver(struct xircom_private
*card
)
819 enter("deactivate_receiver");
821 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
822 val
= val
& ~2; /* disable the receiver */
823 outl(val
, card
->io_port
+ CSR6
);
826 while (counter
> 0) {
827 if (!receive_active(card
))
833 printk(KERN_ERR
"xircom_cb: Receiver failed to deactivate\n");
837 leave("deactivate_receiver");
842 activate_transmitter enables the transmitter on the card.
843 Before being allowed to active the transmitter, the transmitter
844 must be completely de-activated. To achieve this,
845 this code actually disables the transmitter first; then it waits for the
846 transmitter to become inactive, then it activates the transmitter and then
847 it waits for the transmitter to be active again.
849 must be called with the lock held and interrupts disabled.
851 static void activate_transmitter(struct xircom_private
*card
)
855 enter("activate_transmitter");
858 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
860 /* If the "active" bit is set and the receiver is already
861 active, no need to do the expensive thing */
862 if ((val
&(1<<13)) && (transmit_active(card
)))
865 val
= val
& ~(1 << 13); /* disable the transmitter */
866 outl(val
, card
->io_port
+ CSR6
);
869 while (counter
> 0) {
870 if (!transmit_active(card
))
876 printk(KERN_ERR
"xircom_cb: Transmitter failed to deactivate\n");
879 /* enable the transmitter */
880 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
881 val
= val
| (1 << 13); /* enable the transmitter */
882 outl(val
, card
->io_port
+ CSR6
);
884 /* now wait for the card to activate again */
886 while (counter
> 0) {
887 if (transmit_active(card
))
893 printk(KERN_ERR
"xircom_cb: Transmitter failed to re-activate\n");
896 leave("activate_transmitter");
900 deactivate_transmitter disables the transmitter on the card.
901 To achieve this this code disables the transmitter first;
902 then it waits for the transmitter to become inactive.
904 must be called with the lock held and interrupts disabled.
906 static void deactivate_transmitter(struct xircom_private
*card
)
910 enter("deactivate_transmitter");
912 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
913 val
= val
& ~2; /* disable the transmitter */
914 outl(val
, card
->io_port
+ CSR6
);
917 while (counter
> 0) {
918 if (!transmit_active(card
))
924 printk(KERN_ERR
"xircom_cb: Transmitter failed to deactivate\n");
928 leave("deactivate_transmitter");
933 enable_transmit_interrupt enables the transmit interrupt
935 must be called with the lock held and interrupts disabled.
937 static void enable_transmit_interrupt(struct xircom_private
*card
)
940 enter("enable_transmit_interrupt");
942 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
943 val
|= 1; /* enable the transmit interrupt */
944 outl(val
, card
->io_port
+ CSR7
);
946 leave("enable_transmit_interrupt");
951 enable_receive_interrupt enables the receive interrupt
953 must be called with the lock held and interrupts disabled.
955 static void enable_receive_interrupt(struct xircom_private
*card
)
958 enter("enable_receive_interrupt");
960 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
961 val
= val
| (1 << 6); /* enable the receive interrupt */
962 outl(val
, card
->io_port
+ CSR7
);
964 leave("enable_receive_interrupt");
968 enable_link_interrupt enables the link status change interrupt
970 must be called with the lock held and interrupts disabled.
972 static void enable_link_interrupt(struct xircom_private
*card
)
975 enter("enable_link_interrupt");
977 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
978 val
= val
| (1 << 27); /* enable the link status chage interrupt */
979 outl(val
, card
->io_port
+ CSR7
);
981 leave("enable_link_interrupt");
987 disable_all_interrupts disables all interrupts
989 must be called with the lock held and interrupts disabled.
991 static void disable_all_interrupts(struct xircom_private
*card
)
994 enter("enable_all_interrupts");
996 val
= 0; /* disable all interrupts */
997 outl(val
, card
->io_port
+ CSR7
);
999 leave("disable_all_interrupts");
1003 enable_common_interrupts enables several weird interrupts
1005 must be called with the lock held and interrupts disabled.
1007 static void enable_common_interrupts(struct xircom_private
*card
)
1010 enter("enable_link_interrupt");
1012 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
1013 val
|= (1<<16); /* Normal Interrupt Summary */
1014 val
|= (1<<15); /* Abnormal Interrupt Summary */
1015 val
|= (1<<13); /* Fatal bus error */
1016 val
|= (1<<8); /* Receive Process Stopped */
1017 val
|= (1<<7); /* Receive Buffer Unavailable */
1018 val
|= (1<<5); /* Transmit Underflow */
1019 val
|= (1<<2); /* Transmit Buffer Unavailable */
1020 val
|= (1<<1); /* Transmit Process Stopped */
1021 outl(val
, card
->io_port
+ CSR7
);
1023 leave("enable_link_interrupt");
1027 enable_promisc starts promisc mode
1029 must be called with the lock held and interrupts disabled.
1031 static int enable_promisc(struct xircom_private
*card
)
1034 enter("enable_promisc");
1036 val
= inl(card
->io_port
+ CSR6
);
1037 val
= val
| (1 << 6);
1038 outl(val
, card
->io_port
+ CSR6
);
1040 leave("enable_promisc");
1048 link_status() checks the the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1050 Must be called in locked state with interrupts disabled
1052 static int link_status(struct xircom_private
*card
)
1055 enter("link_status");
1057 val
= inb(card
->io_port
+ CSR12
);
1059 if (!(val
&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */
1061 if (!(val
&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1064 /* If we get here -> no link at all */
1066 leave("link_status");
1075 read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure.
1077 This function will take the spinlock itself and can, as a result, not be called with the lock helt.
1079 static void read_mac_address(struct xircom_private
*card
)
1081 unsigned char j
, tuple
, link
, data_id
, data_count
;
1082 unsigned long flags
;
1085 enter("read_mac_address");
1087 spin_lock_irqsave(&card
->lock
, flags
);
1089 outl(1 << 12, card
->io_port
+ CSR9
); /* enable boot rom access */
1090 for (i
= 0x100; i
< 0x1f7; i
+= link
+ 2) {
1091 outl(i
, card
->io_port
+ CSR10
);
1092 tuple
= inl(card
->io_port
+ CSR9
) & 0xff;
1093 outl(i
+ 1, card
->io_port
+ CSR10
);
1094 link
= inl(card
->io_port
+ CSR9
) & 0xff;
1095 outl(i
+ 2, card
->io_port
+ CSR10
);
1096 data_id
= inl(card
->io_port
+ CSR9
) & 0xff;
1097 outl(i
+ 3, card
->io_port
+ CSR10
);
1098 data_count
= inl(card
->io_port
+ CSR9
) & 0xff;
1099 if ((tuple
== 0x22) && (data_id
== 0x04) && (data_count
== 0x06)) {
1101 * This is it. We have the data we want.
1103 for (j
= 0; j
< 6; j
++) {
1104 outl(i
+ j
+ 4, card
->io_port
+ CSR10
);
1105 card
->dev
->dev_addr
[j
] = inl(card
->io_port
+ CSR9
) & 0xff;
1108 } else if (link
== 0) {
1112 spin_unlock_irqrestore(&card
->lock
, flags
);
1114 for (i
= 0; i
< 6; i
++)
1115 printk("%c%2.2X", i
? ':' : ' ', card
->dev
->dev_addr
[i
]);
1118 leave("read_mac_address");
1123 transceiver_voodoo() enables the external UTP plug thingy.
1124 it's called voodoo as I stole this code and cannot cross-reference
1125 it with the specification.
1127 static void transceiver_voodoo(struct xircom_private
*card
)
1129 unsigned long flags
;
1131 enter("transceiver_voodoo");
1133 /* disable all powermanagement */
1134 pci_write_config_dword(card
->pdev
, PCI_POWERMGMT
, 0x0000);
1136 setup_descriptors(card
);
1138 spin_lock_irqsave(&card
->lock
, flags
);
1140 outl(0x0008, card
->io_port
+ CSR15
);
1142 outl(0xa8050000, card
->io_port
+ CSR15
);
1144 outl(0xa00f0000, card
->io_port
+ CSR15
);
1147 spin_unlock_irqrestore(&card
->lock
, flags
);
1149 netif_start_queue(card
->dev
);
1150 leave("transceiver_voodoo");
1154 static void xircom_up(struct xircom_private
*card
)
1156 unsigned long flags
;
1161 /* disable all powermanagement */
1162 pci_write_config_dword(card
->pdev
, PCI_POWERMGMT
, 0x0000);
1164 setup_descriptors(card
);
1166 spin_lock_irqsave(&card
->lock
, flags
);
1169 enable_link_interrupt(card
);
1170 enable_transmit_interrupt(card
);
1171 enable_receive_interrupt(card
);
1172 enable_common_interrupts(card
);
1173 enable_promisc(card
);
1175 /* The card can have received packets already, read them away now */
1176 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
1177 investigate_read_descriptor(card
->dev
,card
,i
,bufferoffsets
[i
]);
1180 spin_unlock_irqrestore(&card
->lock
, flags
);
1181 trigger_receive(card
);
1182 trigger_transmit(card
);
1183 netif_start_queue(card
->dev
);
1187 /* Bufferoffset is in BYTES */
1188 static void investigate_read_descriptor(struct net_device
*dev
,struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
)
1192 enter("investigate_read_descriptor");
1193 status
= card
->rx_buffer
[4*descnr
];
1195 if ((status
> 0)) { /* packet received */
1197 /* TODO: discard error packets */
1199 short pkt_len
= ((status
>> 16) & 0x7ff) - 4; /* minus 4, we don't want the CRC */
1200 struct sk_buff
*skb
;
1202 if (pkt_len
> 1518) {
1203 printk(KERN_ERR
"xircom_cb: Packet length %i is bogus \n",pkt_len
);
1207 skb
= dev_alloc_skb(pkt_len
+ 2);
1209 card
->stats
.rx_dropped
++;
1213 skb_reserve(skb
, 2);
1214 eth_copy_and_sum(skb
, (unsigned char*)&card
->rx_buffer
[bufferoffset
/ 4], pkt_len
, 0);
1215 skb_put(skb
, pkt_len
);
1216 skb
->protocol
= eth_type_trans(skb
, dev
);
1218 dev
->last_rx
= jiffies
;
1219 card
->stats
.rx_packets
++;
1220 card
->stats
.rx_bytes
+= pkt_len
;
1223 /* give the buffer back to the card */
1224 card
->rx_buffer
[4*descnr
] = 0x80000000;
1225 trigger_receive(card
);
1228 leave("investigate_read_descriptor");
1233 /* Bufferoffset is in BYTES */
1234 static void investigate_write_descriptor(struct net_device
*dev
, struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
)
1238 enter("investigate_write_descriptor");
1240 status
= card
->tx_buffer
[4*descnr
];
1242 if (status
& 0x8000) { /* Major error */
1243 printk(KERN_ERR
"Major transmit error status %x \n", status
);
1244 card
->tx_buffer
[4*descnr
] = 0;
1245 netif_wake_queue (dev
);
1248 if (status
> 0) { /* bit 31 is 0 when done */
1249 if (card
->tx_skb
[descnr
]!=NULL
) {
1250 card
->stats
.tx_bytes
+= card
->tx_skb
[descnr
]->len
;
1251 dev_kfree_skb_irq(card
->tx_skb
[descnr
]);
1253 card
->tx_skb
[descnr
] = NULL
;
1254 /* Bit 8 in the status field is 1 if there was a collision */
1256 card
->stats
.collisions
++;
1257 card
->tx_buffer
[4*descnr
] = 0; /* descriptor is free again */
1258 netif_wake_queue (dev
);
1259 card
->stats
.tx_packets
++;
1262 leave("investigate_write_descriptor");
1267 static int __init
xircom_init(void)
1269 pci_register_driver(&xircom_ops
);
1273 static void __exit
xircom_exit(void)
1275 pci_unregister_driver(&xircom_ops
);
1278 module_init(xircom_init
)
1279 module_exit(xircom_exit
)