2 * xircom_cb: A driver for the (tulip-like) Xircom Cardbus ethernet cards
4 * This software is (C) by the respective authors, and licensed under the GPL
7 * Written by Arjan van de Ven for Red Hat, Inc.
8 * Based on work by Jeff Garzik, Doug Ledford and Donald Becker
10 * This software may be used and distributed according to the terms
11 * of the GNU General Public License, incorporated herein by reference.
14 * $Id: xircom_cb.c,v 1.33 2001/03/19 14:02:07 arjanv Exp $
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/ioport.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/pci.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/delay.h>
29 #include <linux/init.h>
30 #include <linux/ethtool.h>
31 #include <linux/bitops.h>
33 #include <asm/uaccess.h>
35 #ifdef CONFIG_NET_POLL_CONTROLLER
40 #define enter(x) printk("Enter: %s, %s line %i\n",x,__FILE__,__LINE__)
41 #define leave(x) printk("Leave: %s, %s line %i\n",x,__FILE__,__LINE__)
43 #define enter(x) do {} while (0)
44 #define leave(x) do {} while (0)
48 MODULE_DESCRIPTION("Xircom Cardbus ethernet driver");
49 MODULE_AUTHOR("Arjan van de Ven <arjanv@redhat.com>");
50 MODULE_LICENSE("GPL");
54 /* IO registers on the card, offsets */
74 #define PCI_POWERMGMT 0x40
76 /* Offsets of the buffers within the descriptor pages, in bytes */
78 #define NUMDESCRIPTORS 4
80 static int bufferoffsets
[NUMDESCRIPTORS
] = {128,2048,4096,6144};
83 struct xircom_private
{
84 /* Send and receive buffers, kernel-addressable and dma addressable forms */
89 dma_addr_t rx_dma_handle
;
90 dma_addr_t tx_dma_handle
;
92 struct sk_buff
*tx_skb
[4];
94 unsigned long io_port
;
97 /* transmit_used is the rotating counter that indicates which transmit
98 descriptor has to be used next */
101 /* Spinlock to serialize register operations.
102 It must be helt while manipulating the following registers:
103 CSR0, CSR6, CSR7, CSR9, CSR10, CSR15
107 struct pci_dev
*pdev
;
108 struct net_device
*dev
;
112 /* Function prototypes */
113 static int xircom_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
);
114 static void xircom_remove(struct pci_dev
*pdev
);
115 static irqreturn_t
xircom_interrupt(int irq
, void *dev_instance
);
116 static netdev_tx_t
xircom_start_xmit(struct sk_buff
*skb
,
117 struct net_device
*dev
);
118 static int xircom_open(struct net_device
*dev
);
119 static int xircom_close(struct net_device
*dev
);
120 static void xircom_up(struct xircom_private
*card
);
121 #ifdef CONFIG_NET_POLL_CONTROLLER
122 static void xircom_poll_controller(struct net_device
*dev
);
125 static void investigate_read_descriptor(struct net_device
*dev
,struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
);
126 static void investigate_write_descriptor(struct net_device
*dev
, struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
);
127 static void read_mac_address(struct xircom_private
*card
);
128 static void transceiver_voodoo(struct xircom_private
*card
);
129 static void initialize_card(struct xircom_private
*card
);
130 static void trigger_transmit(struct xircom_private
*card
);
131 static void trigger_receive(struct xircom_private
*card
);
132 static void setup_descriptors(struct xircom_private
*card
);
133 static void remove_descriptors(struct xircom_private
*card
);
134 static int link_status_changed(struct xircom_private
*card
);
135 static void activate_receiver(struct xircom_private
*card
);
136 static void deactivate_receiver(struct xircom_private
*card
);
137 static void activate_transmitter(struct xircom_private
*card
);
138 static void deactivate_transmitter(struct xircom_private
*card
);
139 static void enable_transmit_interrupt(struct xircom_private
*card
);
140 static void enable_receive_interrupt(struct xircom_private
*card
);
141 static void enable_link_interrupt(struct xircom_private
*card
);
142 static void disable_all_interrupts(struct xircom_private
*card
);
143 static int link_status(struct xircom_private
*card
);
147 static struct pci_device_id xircom_pci_table
[] = {
148 {0x115D, 0x0003, PCI_ANY_ID
, PCI_ANY_ID
,},
151 MODULE_DEVICE_TABLE(pci
, xircom_pci_table
);
153 static struct pci_driver xircom_ops
= {
155 .id_table
= xircom_pci_table
,
156 .probe
= xircom_probe
,
157 .remove
= xircom_remove
,
164 static void print_binary(unsigned int number
)
170 for (i
=31;i
>=0;i
--) {
178 printk("%s\n",buffer
);
182 static void netdev_get_drvinfo(struct net_device
*dev
,
183 struct ethtool_drvinfo
*info
)
185 struct xircom_private
*private = netdev_priv(dev
);
187 strcpy(info
->driver
, "xircom_cb");
188 strcpy(info
->bus_info
, pci_name(private->pdev
));
191 static const struct ethtool_ops netdev_ethtool_ops
= {
192 .get_drvinfo
= netdev_get_drvinfo
,
195 static const struct net_device_ops netdev_ops
= {
196 .ndo_open
= xircom_open
,
197 .ndo_stop
= xircom_close
,
198 .ndo_start_xmit
= xircom_start_xmit
,
199 .ndo_change_mtu
= eth_change_mtu
,
200 .ndo_set_mac_address
= eth_mac_addr
,
201 .ndo_validate_addr
= eth_validate_addr
,
202 #ifdef CONFIG_NET_POLL_CONTROLLER
203 .ndo_poll_controller
= xircom_poll_controller
,
207 /* xircom_probe is the code that gets called on device insertion.
208 it sets up the hardware and registers the device to the networklayer.
210 TODO: Send 1 or 2 "dummy" packets here as the card seems to discard the
211 first two packets that get send, and pump hates that.
214 static int __devinit
xircom_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
216 struct net_device
*dev
= NULL
;
217 struct xircom_private
*private;
219 unsigned short tmp16
;
220 enter("xircom_probe");
222 /* First do the PCI initialisation */
224 if (pci_enable_device(pdev
))
227 /* disable all powermanagement */
228 pci_write_config_dword(pdev
, PCI_POWERMGMT
, 0x0000);
230 pci_set_master(pdev
); /* Why isn't this done by pci_enable_device ?*/
232 /* clear PCI status, if any */
233 pci_read_config_word (pdev
,PCI_STATUS
, &tmp16
);
234 pci_write_config_word (pdev
, PCI_STATUS
,tmp16
);
236 if (!request_region(pci_resource_start(pdev
, 0), 128, "xircom_cb")) {
237 printk(KERN_ERR
"xircom_probe: failed to allocate io-region\n");
242 Before changing the hardware, allocate the memory.
243 This way, we can fail gracefully if not enough memory
246 dev
= alloc_etherdev(sizeof(struct xircom_private
));
248 printk(KERN_ERR
"xircom_probe: failed to allocate etherdev\n");
251 private = netdev_priv(dev
);
253 /* Allocate the send/receive buffers */
254 private->rx_buffer
= pci_alloc_consistent(pdev
,8192,&private->rx_dma_handle
);
255 if (private->rx_buffer
== NULL
) {
256 printk(KERN_ERR
"xircom_probe: no memory for rx buffer \n");
259 private->tx_buffer
= pci_alloc_consistent(pdev
,8192,&private->tx_dma_handle
);
260 if (private->tx_buffer
== NULL
) {
261 printk(KERN_ERR
"xircom_probe: no memory for tx buffer \n");
265 SET_NETDEV_DEV(dev
, &pdev
->dev
);
269 private->pdev
= pdev
;
270 private->io_port
= pci_resource_start(pdev
, 0);
271 spin_lock_init(&private->lock
);
272 dev
->irq
= pdev
->irq
;
273 dev
->base_addr
= private->io_port
;
275 initialize_card(private);
276 read_mac_address(private);
277 setup_descriptors(private);
279 dev
->netdev_ops
= &netdev_ops
;
280 SET_ETHTOOL_OPS(dev
, &netdev_ethtool_ops
);
281 pci_set_drvdata(pdev
, dev
);
283 if (register_netdev(dev
)) {
284 printk(KERN_ERR
"xircom_probe: netdevice registration failed.\n");
288 printk(KERN_INFO
"%s: Xircom cardbus revision %i at irq %i \n", dev
->name
, pdev
->revision
, pdev
->irq
);
289 /* start the transmitter to get a heartbeat */
290 /* TODO: send 2 dummy packets here */
291 transceiver_voodoo(private);
293 spin_lock_irqsave(&private->lock
,flags
);
294 activate_transmitter(private);
295 activate_receiver(private);
296 spin_unlock_irqrestore(&private->lock
,flags
);
298 trigger_receive(private);
300 leave("xircom_probe");
304 kfree(private->tx_buffer
);
306 kfree(private->rx_buffer
);
315 xircom_remove is called on module-unload or on device-eject.
316 it unregisters the irq, io-region and network device.
317 Interrupts and such are already stopped in the "ifconfig ethX down"
320 static void __devexit
xircom_remove(struct pci_dev
*pdev
)
322 struct net_device
*dev
= pci_get_drvdata(pdev
);
323 struct xircom_private
*card
= netdev_priv(dev
);
325 enter("xircom_remove");
326 pci_free_consistent(pdev
,8192,card
->rx_buffer
,card
->rx_dma_handle
);
327 pci_free_consistent(pdev
,8192,card
->tx_buffer
,card
->tx_dma_handle
);
329 release_region(dev
->base_addr
, 128);
330 unregister_netdev(dev
);
332 pci_set_drvdata(pdev
, NULL
);
333 leave("xircom_remove");
336 static irqreturn_t
xircom_interrupt(int irq
, void *dev_instance
)
338 struct net_device
*dev
= (struct net_device
*) dev_instance
;
339 struct xircom_private
*card
= netdev_priv(dev
);
343 enter("xircom_interrupt\n");
345 spin_lock(&card
->lock
);
346 status
= inl(card
->io_port
+CSR5
);
349 print_binary(status
);
350 printk("tx status 0x%08x 0x%08x \n",card
->tx_buffer
[0],card
->tx_buffer
[4]);
351 printk("rx status 0x%08x 0x%08x \n",card
->rx_buffer
[0],card
->rx_buffer
[4]);
353 /* Handle shared irq and hotplug */
354 if (status
== 0 || status
== 0xffffffff) {
355 spin_unlock(&card
->lock
);
359 if (link_status_changed(card
)) {
361 printk(KERN_DEBUG
"xircom_cb: Link status has changed \n");
362 newlink
= link_status(card
);
363 printk(KERN_INFO
"xircom_cb: Link is %i mbit \n",newlink
);
365 netif_carrier_on(dev
);
367 netif_carrier_off(dev
);
371 /* Clear all remaining interrupts */
372 status
|= 0xffffffff; /* FIXME: make this clear only the
373 real existing bits */
374 outl(status
,card
->io_port
+CSR5
);
377 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
378 investigate_write_descriptor(dev
,card
,i
,bufferoffsets
[i
]);
379 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
380 investigate_read_descriptor(dev
,card
,i
,bufferoffsets
[i
]);
383 spin_unlock(&card
->lock
);
384 leave("xircom_interrupt");
388 static netdev_tx_t
xircom_start_xmit(struct sk_buff
*skb
,
389 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 skb_copy_from_linear_data(skb
,
415 &(card
->tx_buffer
[bufferoffsets
[desc
] / 4]),
417 /* FIXME: The specification tells us that the length we send HAS to be a multiple of
420 card
->tx_buffer
[4*desc
+1] = cpu_to_le32(skb
->len
);
421 if (desc
== NUMDESCRIPTORS
- 1) /* bit 25: last descriptor of the ring */
422 card
->tx_buffer
[4*desc
+1] |= cpu_to_le32(1<<25);
424 card
->tx_buffer
[4*desc
+1] |= cpu_to_le32(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
] = cpu_to_le32(0x80000000);
431 trigger_transmit(card
);
432 if (card
->tx_buffer
[nextdescriptor
*4] & cpu_to_le32(0x8000000)) {
433 /* next descriptor is occupied... */
434 netif_stop_queue(dev
);
436 card
->transmit_used
= nextdescriptor
;
437 leave("xircom-start_xmit - sent");
438 spin_unlock_irqrestore(&card
->lock
,flags
);
444 /* Uh oh... no free descriptor... drop the packet */
445 netif_stop_queue(dev
);
446 spin_unlock_irqrestore(&card
->lock
,flags
);
447 trigger_transmit(card
);
449 return NETDEV_TX_BUSY
;
455 static int xircom_open(struct net_device
*dev
)
457 struct xircom_private
*xp
= netdev_priv(dev
);
459 enter("xircom_open");
460 printk(KERN_INFO
"xircom cardbus adaptor found, registering as %s, using irq %i \n",dev
->name
,dev
->irq
);
461 retval
= request_irq(dev
->irq
, &xircom_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
463 leave("xircom_open - No IRQ");
469 leave("xircom_open");
473 static int xircom_close(struct net_device
*dev
)
475 struct xircom_private
*card
;
478 enter("xircom_close");
479 card
= netdev_priv(dev
);
480 netif_stop_queue(dev
); /* we don't want new packets */
483 spin_lock_irqsave(&card
->lock
,flags
);
485 disable_all_interrupts(card
);
487 /* We can enable this again once we send dummy packets on ifconfig ethX up */
488 deactivate_receiver(card
);
489 deactivate_transmitter(card
);
491 remove_descriptors(card
);
493 spin_unlock_irqrestore(&card
->lock
,flags
);
496 free_irq(dev
->irq
,dev
);
498 leave("xircom_close");
505 #ifdef CONFIG_NET_POLL_CONTROLLER
506 static void xircom_poll_controller(struct net_device
*dev
)
508 disable_irq(dev
->irq
);
509 xircom_interrupt(dev
->irq
, dev
);
510 enable_irq(dev
->irq
);
515 static void initialize_card(struct xircom_private
*card
)
519 enter("initialize_card");
522 spin_lock_irqsave(&card
->lock
, flags
);
524 /* First: reset the card */
525 val
= inl(card
->io_port
+ CSR0
);
526 val
|= 0x01; /* Software reset */
527 outl(val
, card
->io_port
+ CSR0
);
529 udelay(100); /* give the card some time to reset */
531 val
= inl(card
->io_port
+ CSR0
);
532 val
&= ~0x01; /* disable Software reset */
533 outl(val
, card
->io_port
+ CSR0
);
536 val
= 0; /* Value 0x00 is a safe and conservative value
537 for the PCI configuration settings */
538 outl(val
, card
->io_port
+ CSR0
);
541 disable_all_interrupts(card
);
542 deactivate_receiver(card
);
543 deactivate_transmitter(card
);
545 spin_unlock_irqrestore(&card
->lock
, flags
);
547 leave("initialize_card");
551 trigger_transmit causes the card to check for frames to be transmitted.
552 This is accomplished by writing to the CSR1 port. The documentation
553 claims that the act of writing is sufficient and that the value is
554 ignored; I chose zero.
556 static void trigger_transmit(struct xircom_private
*card
)
559 enter("trigger_transmit");
562 outl(val
, card
->io_port
+ CSR1
);
564 leave("trigger_transmit");
568 trigger_receive causes the card to check for empty frames in the
569 descriptor list in which packets can be received.
570 This is accomplished by writing to the CSR2 port. The documentation
571 claims that the act of writing is sufficient and that the value is
572 ignored; I chose zero.
574 static void trigger_receive(struct xircom_private
*card
)
577 enter("trigger_receive");
580 outl(val
, card
->io_port
+ CSR2
);
582 leave("trigger_receive");
586 setup_descriptors initializes the send and receive buffers to be valid
587 descriptors and programs the addresses into the card.
589 static void setup_descriptors(struct xircom_private
*card
)
593 enter("setup_descriptors");
596 BUG_ON(card
->rx_buffer
== NULL
);
597 BUG_ON(card
->tx_buffer
== NULL
);
599 /* Receive descriptors */
600 memset(card
->rx_buffer
, 0, 128); /* clear the descriptors */
601 for (i
=0;i
<NUMDESCRIPTORS
;i
++ ) {
603 /* Rx Descr0: It's empty, let the card own it, no errors -> 0x80000000 */
604 card
->rx_buffer
[i
*4 + 0] = cpu_to_le32(0x80000000);
605 /* Rx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
606 card
->rx_buffer
[i
*4 + 1] = cpu_to_le32(1536);
607 if (i
== NUMDESCRIPTORS
- 1) /* bit 25 is "last descriptor" */
608 card
->rx_buffer
[i
*4 + 1] |= cpu_to_le32(1 << 25);
610 /* Rx Descr2: address of the buffer
611 we store the buffer at the 2nd half of the page */
613 address
= card
->rx_dma_handle
;
614 card
->rx_buffer
[i
*4 + 2] = cpu_to_le32(address
+ bufferoffsets
[i
]);
615 /* Rx Desc3: address of 2nd buffer -> 0 */
616 card
->rx_buffer
[i
*4 + 3] = 0;
620 /* Write the receive descriptor ring address to the card */
621 address
= card
->rx_dma_handle
;
622 outl(address
, card
->io_port
+ CSR3
); /* Receive descr list address */
625 /* transmit descriptors */
626 memset(card
->tx_buffer
, 0, 128); /* clear the descriptors */
628 for (i
=0;i
<NUMDESCRIPTORS
;i
++ ) {
629 /* Tx Descr0: Empty, we own it, no errors -> 0x00000000 */
630 card
->tx_buffer
[i
*4 + 0] = 0x00000000;
631 /* Tx Descr1: buffer 1 is 1536 bytes, buffer 2 is 0 bytes */
632 card
->tx_buffer
[i
*4 + 1] = cpu_to_le32(1536);
633 if (i
== NUMDESCRIPTORS
- 1) /* bit 25 is "last descriptor" */
634 card
->tx_buffer
[i
*4 + 1] |= cpu_to_le32(1 << 25);
636 /* Tx Descr2: address of the buffer
637 we store the buffer at the 2nd half of the page */
638 address
= card
->tx_dma_handle
;
639 card
->tx_buffer
[i
*4 + 2] = cpu_to_le32(address
+ bufferoffsets
[i
]);
640 /* Tx Desc3: address of 2nd buffer -> 0 */
641 card
->tx_buffer
[i
*4 + 3] = 0;
645 /* wite the transmit descriptor ring to the card */
646 address
= card
->tx_dma_handle
;
647 outl(address
, card
->io_port
+ CSR4
); /* xmit descr list address */
649 leave("setup_descriptors");
653 remove_descriptors informs the card the descriptors are no longer
654 valid by setting the address in the card to 0x00.
656 static void remove_descriptors(struct xircom_private
*card
)
659 enter("remove_descriptors");
662 outl(val
, card
->io_port
+ CSR3
); /* Receive descriptor address */
663 outl(val
, card
->io_port
+ CSR4
); /* Send descriptor address */
665 leave("remove_descriptors");
669 link_status_changed returns 1 if the card has indicated that
670 the link status has changed. The new link status has to be read from CSR12.
672 This function also clears the status-bit.
674 static int link_status_changed(struct xircom_private
*card
)
677 enter("link_status_changed");
679 val
= inl(card
->io_port
+ CSR5
); /* Status register */
681 if ((val
& (1 << 27)) == 0) { /* no change */
682 leave("link_status_changed - nochange");
686 /* clear the event by writing a 1 to the bit in the
689 outl(val
, card
->io_port
+ CSR5
);
691 leave("link_status_changed - changed");
697 transmit_active returns 1 if the transmitter on the card is
698 in a non-stopped state.
700 static int transmit_active(struct xircom_private
*card
)
703 enter("transmit_active");
705 val
= inl(card
->io_port
+ CSR5
); /* Status register */
707 if ((val
& (7 << 20)) == 0) { /* transmitter disabled */
708 leave("transmit_active - inactive");
712 leave("transmit_active - active");
717 receive_active returns 1 if the receiver on the card is
718 in a non-stopped state.
720 static int receive_active(struct xircom_private
*card
)
723 enter("receive_active");
726 val
= inl(card
->io_port
+ CSR5
); /* Status register */
728 if ((val
& (7 << 17)) == 0) { /* receiver disabled */
729 leave("receive_active - inactive");
733 leave("receive_active - active");
738 activate_receiver enables the receiver on the card.
739 Before being allowed to active the receiver, the receiver
740 must be completely de-activated. To achieve this,
741 this code actually disables the receiver first; then it waits for the
742 receiver to become inactive, then it activates the receiver and then
743 it waits for the receiver to be active.
745 must be called with the lock held and interrupts disabled.
747 static void activate_receiver(struct xircom_private
*card
)
751 enter("activate_receiver");
754 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
756 /* If the "active" bit is set and the receiver is already
757 active, no need to do the expensive thing */
758 if ((val
&2) && (receive_active(card
)))
762 val
= val
& ~2; /* disable the receiver */
763 outl(val
, card
->io_port
+ CSR6
);
766 while (counter
> 0) {
767 if (!receive_active(card
))
773 printk(KERN_ERR
"xircom_cb: Receiver failed to deactivate\n");
776 /* enable the receiver */
777 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
778 val
= val
| 2; /* enable the receiver */
779 outl(val
, card
->io_port
+ CSR6
);
781 /* now wait for the card to activate again */
783 while (counter
> 0) {
784 if (receive_active(card
))
790 printk(KERN_ERR
"xircom_cb: Receiver failed to re-activate\n");
793 leave("activate_receiver");
797 deactivate_receiver disables the receiver on the card.
798 To achieve this this code disables the receiver first;
799 then it waits for the receiver to become inactive.
801 must be called with the lock held and interrupts disabled.
803 static void deactivate_receiver(struct xircom_private
*card
)
807 enter("deactivate_receiver");
809 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
810 val
= val
& ~2; /* disable the receiver */
811 outl(val
, card
->io_port
+ CSR6
);
814 while (counter
> 0) {
815 if (!receive_active(card
))
821 printk(KERN_ERR
"xircom_cb: Receiver failed to deactivate\n");
825 leave("deactivate_receiver");
830 activate_transmitter enables the transmitter on the card.
831 Before being allowed to active the transmitter, the transmitter
832 must be completely de-activated. To achieve this,
833 this code actually disables the transmitter first; then it waits for the
834 transmitter to become inactive, then it activates the transmitter and then
835 it waits for the transmitter to be active again.
837 must be called with the lock held and interrupts disabled.
839 static void activate_transmitter(struct xircom_private
*card
)
843 enter("activate_transmitter");
846 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
848 /* If the "active" bit is set and the receiver is already
849 active, no need to do the expensive thing */
850 if ((val
&(1<<13)) && (transmit_active(card
)))
853 val
= val
& ~(1 << 13); /* disable the transmitter */
854 outl(val
, card
->io_port
+ CSR6
);
857 while (counter
> 0) {
858 if (!transmit_active(card
))
864 printk(KERN_ERR
"xircom_cb: Transmitter failed to deactivate\n");
867 /* enable the transmitter */
868 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
869 val
= val
| (1 << 13); /* enable the transmitter */
870 outl(val
, card
->io_port
+ CSR6
);
872 /* now wait for the card to activate again */
874 while (counter
> 0) {
875 if (transmit_active(card
))
881 printk(KERN_ERR
"xircom_cb: Transmitter failed to re-activate\n");
884 leave("activate_transmitter");
888 deactivate_transmitter disables the transmitter on the card.
889 To achieve this this code disables the transmitter first;
890 then it waits for the transmitter to become inactive.
892 must be called with the lock held and interrupts disabled.
894 static void deactivate_transmitter(struct xircom_private
*card
)
898 enter("deactivate_transmitter");
900 val
= inl(card
->io_port
+ CSR6
); /* Operation mode */
901 val
= val
& ~2; /* disable the transmitter */
902 outl(val
, card
->io_port
+ CSR6
);
905 while (counter
> 0) {
906 if (!transmit_active(card
))
912 printk(KERN_ERR
"xircom_cb: Transmitter failed to deactivate\n");
916 leave("deactivate_transmitter");
921 enable_transmit_interrupt enables the transmit interrupt
923 must be called with the lock held and interrupts disabled.
925 static void enable_transmit_interrupt(struct xircom_private
*card
)
928 enter("enable_transmit_interrupt");
930 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
931 val
|= 1; /* enable the transmit interrupt */
932 outl(val
, card
->io_port
+ CSR7
);
934 leave("enable_transmit_interrupt");
939 enable_receive_interrupt enables the receive interrupt
941 must be called with the lock held and interrupts disabled.
943 static void enable_receive_interrupt(struct xircom_private
*card
)
946 enter("enable_receive_interrupt");
948 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
949 val
= val
| (1 << 6); /* enable the receive interrupt */
950 outl(val
, card
->io_port
+ CSR7
);
952 leave("enable_receive_interrupt");
956 enable_link_interrupt enables the link status change interrupt
958 must be called with the lock held and interrupts disabled.
960 static void enable_link_interrupt(struct xircom_private
*card
)
963 enter("enable_link_interrupt");
965 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
966 val
= val
| (1 << 27); /* enable the link status chage interrupt */
967 outl(val
, card
->io_port
+ CSR7
);
969 leave("enable_link_interrupt");
975 disable_all_interrupts disables all interrupts
977 must be called with the lock held and interrupts disabled.
979 static void disable_all_interrupts(struct xircom_private
*card
)
982 enter("enable_all_interrupts");
984 val
= 0; /* disable all interrupts */
985 outl(val
, card
->io_port
+ CSR7
);
987 leave("disable_all_interrupts");
991 enable_common_interrupts enables several weird interrupts
993 must be called with the lock held and interrupts disabled.
995 static void enable_common_interrupts(struct xircom_private
*card
)
998 enter("enable_link_interrupt");
1000 val
= inl(card
->io_port
+ CSR7
); /* Interrupt enable register */
1001 val
|= (1<<16); /* Normal Interrupt Summary */
1002 val
|= (1<<15); /* Abnormal Interrupt Summary */
1003 val
|= (1<<13); /* Fatal bus error */
1004 val
|= (1<<8); /* Receive Process Stopped */
1005 val
|= (1<<7); /* Receive Buffer Unavailable */
1006 val
|= (1<<5); /* Transmit Underflow */
1007 val
|= (1<<2); /* Transmit Buffer Unavailable */
1008 val
|= (1<<1); /* Transmit Process Stopped */
1009 outl(val
, card
->io_port
+ CSR7
);
1011 leave("enable_link_interrupt");
1015 enable_promisc starts promisc mode
1017 must be called with the lock held and interrupts disabled.
1019 static int enable_promisc(struct xircom_private
*card
)
1022 enter("enable_promisc");
1024 val
= inl(card
->io_port
+ CSR6
);
1025 val
= val
| (1 << 6);
1026 outl(val
, card
->io_port
+ CSR6
);
1028 leave("enable_promisc");
1036 link_status() checks the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1038 Must be called in locked state with interrupts disabled
1040 static int link_status(struct xircom_private
*card
)
1043 enter("link_status");
1045 val
= inb(card
->io_port
+ CSR12
);
1047 if (!(val
&(1<<2))) /* bit 2 is 0 for 10mbit link, 1 for not an 10mbit link */
1049 if (!(val
&(1<<1))) /* bit 1 is 0 for 100mbit link, 1 for not an 100mbit link */
1052 /* If we get here -> no link at all */
1054 leave("link_status");
1063 read_mac_address() reads the MAC address from the NIC and stores it in the "dev" structure.
1065 This function will take the spinlock itself and can, as a result, not be called with the lock helt.
1067 static void read_mac_address(struct xircom_private
*card
)
1069 unsigned char j
, tuple
, link
, data_id
, data_count
;
1070 unsigned long flags
;
1073 enter("read_mac_address");
1075 spin_lock_irqsave(&card
->lock
, flags
);
1077 outl(1 << 12, card
->io_port
+ CSR9
); /* enable boot rom access */
1078 for (i
= 0x100; i
< 0x1f7; i
+= link
+ 2) {
1079 outl(i
, card
->io_port
+ CSR10
);
1080 tuple
= inl(card
->io_port
+ CSR9
) & 0xff;
1081 outl(i
+ 1, card
->io_port
+ CSR10
);
1082 link
= inl(card
->io_port
+ CSR9
) & 0xff;
1083 outl(i
+ 2, card
->io_port
+ CSR10
);
1084 data_id
= inl(card
->io_port
+ CSR9
) & 0xff;
1085 outl(i
+ 3, card
->io_port
+ CSR10
);
1086 data_count
= inl(card
->io_port
+ CSR9
) & 0xff;
1087 if ((tuple
== 0x22) && (data_id
== 0x04) && (data_count
== 0x06)) {
1089 * This is it. We have the data we want.
1091 for (j
= 0; j
< 6; j
++) {
1092 outl(i
+ j
+ 4, card
->io_port
+ CSR10
);
1093 card
->dev
->dev_addr
[j
] = inl(card
->io_port
+ CSR9
) & 0xff;
1096 } else if (link
== 0) {
1100 spin_unlock_irqrestore(&card
->lock
, flags
);
1101 pr_debug(" %pM\n", card
->dev
->dev_addr
);
1102 leave("read_mac_address");
1107 transceiver_voodoo() enables the external UTP plug thingy.
1108 it's called voodoo as I stole this code and cannot cross-reference
1109 it with the specification.
1111 static void transceiver_voodoo(struct xircom_private
*card
)
1113 unsigned long flags
;
1115 enter("transceiver_voodoo");
1117 /* disable all powermanagement */
1118 pci_write_config_dword(card
->pdev
, PCI_POWERMGMT
, 0x0000);
1120 setup_descriptors(card
);
1122 spin_lock_irqsave(&card
->lock
, flags
);
1124 outl(0x0008, card
->io_port
+ CSR15
);
1126 outl(0xa8050000, card
->io_port
+ CSR15
);
1128 outl(0xa00f0000, card
->io_port
+ CSR15
);
1131 spin_unlock_irqrestore(&card
->lock
, flags
);
1133 netif_start_queue(card
->dev
);
1134 leave("transceiver_voodoo");
1138 static void xircom_up(struct xircom_private
*card
)
1140 unsigned long flags
;
1145 /* disable all powermanagement */
1146 pci_write_config_dword(card
->pdev
, PCI_POWERMGMT
, 0x0000);
1148 setup_descriptors(card
);
1150 spin_lock_irqsave(&card
->lock
, flags
);
1153 enable_link_interrupt(card
);
1154 enable_transmit_interrupt(card
);
1155 enable_receive_interrupt(card
);
1156 enable_common_interrupts(card
);
1157 enable_promisc(card
);
1159 /* The card can have received packets already, read them away now */
1160 for (i
=0;i
<NUMDESCRIPTORS
;i
++)
1161 investigate_read_descriptor(card
->dev
,card
,i
,bufferoffsets
[i
]);
1164 spin_unlock_irqrestore(&card
->lock
, flags
);
1165 trigger_receive(card
);
1166 trigger_transmit(card
);
1167 netif_start_queue(card
->dev
);
1171 /* Bufferoffset is in BYTES */
1172 static void investigate_read_descriptor(struct net_device
*dev
,struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
)
1176 enter("investigate_read_descriptor");
1177 status
= le32_to_cpu(card
->rx_buffer
[4*descnr
]);
1179 if ((status
> 0)) { /* packet received */
1181 /* TODO: discard error packets */
1183 short pkt_len
= ((status
>> 16) & 0x7ff) - 4; /* minus 4, we don't want the CRC */
1184 struct sk_buff
*skb
;
1186 if (pkt_len
> 1518) {
1187 printk(KERN_ERR
"xircom_cb: Packet length %i is bogus \n",pkt_len
);
1191 skb
= dev_alloc_skb(pkt_len
+ 2);
1193 dev
->stats
.rx_dropped
++;
1196 skb_reserve(skb
, 2);
1197 skb_copy_to_linear_data(skb
, (unsigned char*)&card
->rx_buffer
[bufferoffset
/ 4], pkt_len
);
1198 skb_put(skb
, pkt_len
);
1199 skb
->protocol
= eth_type_trans(skb
, dev
);
1201 dev
->stats
.rx_packets
++;
1202 dev
->stats
.rx_bytes
+= pkt_len
;
1205 /* give the buffer back to the card */
1206 card
->rx_buffer
[4*descnr
] = cpu_to_le32(0x80000000);
1207 trigger_receive(card
);
1210 leave("investigate_read_descriptor");
1215 /* Bufferoffset is in BYTES */
1216 static void investigate_write_descriptor(struct net_device
*dev
, struct xircom_private
*card
, int descnr
, unsigned int bufferoffset
)
1220 enter("investigate_write_descriptor");
1222 status
= le32_to_cpu(card
->tx_buffer
[4*descnr
]);
1224 if (status
& 0x8000) { /* Major error */
1225 printk(KERN_ERR
"Major transmit error status %x \n", status
);
1226 card
->tx_buffer
[4*descnr
] = 0;
1227 netif_wake_queue (dev
);
1230 if (status
> 0) { /* bit 31 is 0 when done */
1231 if (card
->tx_skb
[descnr
]!=NULL
) {
1232 dev
->stats
.tx_bytes
+= card
->tx_skb
[descnr
]->len
;
1233 dev_kfree_skb_irq(card
->tx_skb
[descnr
]);
1235 card
->tx_skb
[descnr
] = NULL
;
1236 /* Bit 8 in the status field is 1 if there was a collision */
1238 dev
->stats
.collisions
++;
1239 card
->tx_buffer
[4*descnr
] = 0; /* descriptor is free again */
1240 netif_wake_queue (dev
);
1241 dev
->stats
.tx_packets
++;
1244 leave("investigate_write_descriptor");
1249 static int __init
xircom_init(void)
1251 return pci_register_driver(&xircom_ops
);
1254 static void __exit
xircom_exit(void)
1256 pci_unregister_driver(&xircom_ops
);
1259 module_init(xircom_init
)
1260 module_exit(xircom_exit
)