Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 2 | * Copyright (C) 2000, 2005 MIPS Technologies, Inc. All rights reserved. |
| 3 | * Authors: Carsten Langgaard <carstenl@mips.com> |
| 4 | * Maciej W. Rozycki <macro@mips.com> |
| 5 | * Copyright (C) 2004 Ralf Baechle <ralf@linux-mips.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can distribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License (Version 2) as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * SAA9730 ethernet driver. |
| 21 | * |
| 22 | * Changes: |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 23 | * Angelo Dell'Aera <buffer@antifork.org> : Conversion to the new PCI API |
| 24 | * (pci_driver). |
| 25 | * Conversion to spinlocks. |
| 26 | * Error handling fixes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/skbuff.h> |
| 35 | #include <linux/pci.h> |
| 36 | #include <linux/spinlock.h> |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 37 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/addrspace.h> |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 40 | #include <asm/io.h> |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/mips-boards/prom.h> |
| 43 | |
| 44 | #include "saa9730.h" |
| 45 | |
| 46 | #ifdef LAN_SAA9730_DEBUG |
| 47 | int lan_saa9730_debug = LAN_SAA9730_DEBUG; |
| 48 | #else |
| 49 | int lan_saa9730_debug; |
| 50 | #endif |
| 51 | |
| 52 | #define DRV_MODULE_NAME "saa9730" |
| 53 | |
| 54 | static struct pci_device_id saa9730_pci_tbl[] = { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 55 | { PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA9730, |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 56 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { 0, } |
| 58 | }; |
| 59 | |
| 60 | MODULE_DEVICE_TABLE(pci, saa9730_pci_tbl); |
| 61 | |
| 62 | /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */ |
| 63 | static unsigned int pci_irq_line; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static void evm_saa9730_enable_lan_int(struct lan_saa9730_private *lp) |
| 66 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 67 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | &lp->evm_saa9730_regs->InterruptBlock1); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 69 | outl(readl(&lp->evm_saa9730_regs->InterruptStatus1) | EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | &lp->evm_saa9730_regs->InterruptStatus1); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 71 | outl(readl(&lp->evm_saa9730_regs->InterruptEnable1) | EVM_LAN_INT | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | EVM_MASTER_EN, &lp->evm_saa9730_regs->InterruptEnable1); |
| 73 | } |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static void evm_saa9730_disable_lan_int(struct lan_saa9730_private *lp) |
| 76 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 77 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | &lp->evm_saa9730_regs->InterruptBlock1); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 79 | outl(readl(&lp->evm_saa9730_regs->InterruptEnable1) & ~EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | &lp->evm_saa9730_regs->InterruptEnable1); |
| 81 | } |
| 82 | |
| 83 | static void evm_saa9730_clear_lan_int(struct lan_saa9730_private *lp) |
| 84 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 85 | outl(EVM_LAN_INT, &lp->evm_saa9730_regs->InterruptStatus1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void evm_saa9730_block_lan_int(struct lan_saa9730_private *lp) |
| 89 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 90 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) & ~EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | &lp->evm_saa9730_regs->InterruptBlock1); |
| 92 | } |
| 93 | |
| 94 | static void evm_saa9730_unblock_lan_int(struct lan_saa9730_private *lp) |
| 95 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 96 | outl(readl(&lp->evm_saa9730_regs->InterruptBlock1) | EVM_LAN_INT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | &lp->evm_saa9730_regs->InterruptBlock1); |
| 98 | } |
| 99 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 100 | static void __attribute_used__ show_saa9730_regs(struct lan_saa9730_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | int i, j; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 103 | printk("TxmBufferA = %p\n", lp->TxmBuffer[0][0]); |
| 104 | printk("TxmBufferB = %p\n", lp->TxmBuffer[1][0]); |
| 105 | printk("RcvBufferA = %p\n", lp->RcvBuffer[0][0]); |
| 106 | printk("RcvBufferB = %p\n", lp->RcvBuffer[1][0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 108 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { |
| 109 | printk("TxmBuffer[%d][%d] = %x\n", i, j, |
| 110 | le32_to_cpu(*(unsigned int *) |
| 111 | lp->TxmBuffer[i][j])); |
| 112 | } |
| 113 | } |
| 114 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 115 | for (j = 0; j < LAN_SAA9730_RCV_Q_SIZE; j++) { |
| 116 | printk("RcvBuffer[%d][%d] = %x\n", i, j, |
| 117 | le32_to_cpu(*(unsigned int *) |
| 118 | lp->RcvBuffer[i][j])); |
| 119 | } |
| 120 | } |
| 121 | printk("lp->evm_saa9730_regs->InterruptBlock1 = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 122 | readl(&lp->evm_saa9730_regs->InterruptBlock1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | printk("lp->evm_saa9730_regs->InterruptStatus1 = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 124 | readl(&lp->evm_saa9730_regs->InterruptStatus1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | printk("lp->evm_saa9730_regs->InterruptEnable1 = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 126 | readl(&lp->evm_saa9730_regs->InterruptEnable1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | printk("lp->lan_saa9730_regs->Ok2Use = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 128 | readl(&lp->lan_saa9730_regs->Ok2Use)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | printk("lp->NextTxmBufferIndex = %x\n", lp->NextTxmBufferIndex); |
| 130 | printk("lp->NextTxmPacketIndex = %x\n", lp->NextTxmPacketIndex); |
| 131 | printk("lp->PendingTxmBufferIndex = %x\n", |
| 132 | lp->PendingTxmBufferIndex); |
| 133 | printk("lp->PendingTxmPacketIndex = %x\n", |
| 134 | lp->PendingTxmPacketIndex); |
| 135 | printk("lp->lan_saa9730_regs->LanDmaCtl = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 136 | readl(&lp->lan_saa9730_regs->LanDmaCtl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | printk("lp->lan_saa9730_regs->DmaStatus = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 138 | readl(&lp->lan_saa9730_regs->DmaStatus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | printk("lp->lan_saa9730_regs->CamCtl = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 140 | readl(&lp->lan_saa9730_regs->CamCtl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | printk("lp->lan_saa9730_regs->TxCtl = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 142 | readl(&lp->lan_saa9730_regs->TxCtl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | printk("lp->lan_saa9730_regs->TxStatus = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 144 | readl(&lp->lan_saa9730_regs->TxStatus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | printk("lp->lan_saa9730_regs->RxCtl = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 146 | readl(&lp->lan_saa9730_regs->RxCtl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | printk("lp->lan_saa9730_regs->RxStatus = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 148 | readl(&lp->lan_saa9730_regs->RxStatus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 150 | outl(i, &lp->lan_saa9730_regs->CamAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | printk("lp->lan_saa9730_regs->CamData = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 152 | readl(&lp->lan_saa9730_regs->CamData)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | printk("lp->stats.tx_packets = %lx\n", lp->stats.tx_packets); |
| 155 | printk("lp->stats.tx_errors = %lx\n", lp->stats.tx_errors); |
| 156 | printk("lp->stats.tx_aborted_errors = %lx\n", |
| 157 | lp->stats.tx_aborted_errors); |
| 158 | printk("lp->stats.tx_window_errors = %lx\n", |
| 159 | lp->stats.tx_window_errors); |
| 160 | printk("lp->stats.tx_carrier_errors = %lx\n", |
| 161 | lp->stats.tx_carrier_errors); |
| 162 | printk("lp->stats.tx_fifo_errors = %lx\n", |
| 163 | lp->stats.tx_fifo_errors); |
| 164 | printk("lp->stats.tx_heartbeat_errors = %lx\n", |
| 165 | lp->stats.tx_heartbeat_errors); |
| 166 | printk("lp->stats.collisions = %lx\n", lp->stats.collisions); |
| 167 | |
| 168 | printk("lp->stats.rx_packets = %lx\n", lp->stats.rx_packets); |
| 169 | printk("lp->stats.rx_errors = %lx\n", lp->stats.rx_errors); |
| 170 | printk("lp->stats.rx_dropped = %lx\n", lp->stats.rx_dropped); |
| 171 | printk("lp->stats.rx_crc_errors = %lx\n", lp->stats.rx_crc_errors); |
| 172 | printk("lp->stats.rx_frame_errors = %lx\n", |
| 173 | lp->stats.rx_frame_errors); |
| 174 | printk("lp->stats.rx_fifo_errors = %lx\n", |
| 175 | lp->stats.rx_fifo_errors); |
| 176 | printk("lp->stats.rx_length_errors = %lx\n", |
| 177 | lp->stats.rx_length_errors); |
| 178 | |
| 179 | printk("lp->lan_saa9730_regs->DebugPCIMasterAddr = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 180 | readl(&lp->lan_saa9730_regs->DebugPCIMasterAddr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | printk("lp->lan_saa9730_regs->DebugLanTxStateMachine = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 182 | readl(&lp->lan_saa9730_regs->DebugLanTxStateMachine)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | printk("lp->lan_saa9730_regs->DebugLanRxStateMachine = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 184 | readl(&lp->lan_saa9730_regs->DebugLanRxStateMachine)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | printk("lp->lan_saa9730_regs->DebugLanTxFifoPointers = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 186 | readl(&lp->lan_saa9730_regs->DebugLanTxFifoPointers)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | printk("lp->lan_saa9730_regs->DebugLanRxFifoPointers = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 188 | readl(&lp->lan_saa9730_regs->DebugLanRxFifoPointers)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | printk("lp->lan_saa9730_regs->DebugLanCtlStateMachine = %x\n", |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 190 | readl(&lp->lan_saa9730_regs->DebugLanCtlStateMachine)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void lan_saa9730_buffer_init(struct lan_saa9730_private *lp) |
| 194 | { |
| 195 | int i, j; |
| 196 | |
| 197 | /* Init RX buffers */ |
| 198 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 199 | for (j = 0; j < LAN_SAA9730_RCV_Q_SIZE; j++) { |
| 200 | *(unsigned int *) lp->RcvBuffer[i][j] = |
| 201 | cpu_to_le32(RXSF_READY << |
| 202 | RX_STAT_CTL_OWNER_SHF); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /* Init TX buffers */ |
| 207 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 208 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { |
| 209 | *(unsigned int *) lp->TxmBuffer[i][j] = |
| 210 | cpu_to_le32(TXSF_EMPTY << |
| 211 | TX_STAT_CTL_OWNER_SHF); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 216 | static void lan_saa9730_free_buffers(struct pci_dev *pdev, |
| 217 | struct lan_saa9730_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 219 | pci_free_consistent(pdev, lp->buffer_size, lp->buffer_start, |
| 220 | lp->dma_addr); |
| 221 | } |
| 222 | |
| 223 | static int lan_saa9730_allocate_buffers(struct pci_dev *pdev, |
| 224 | struct lan_saa9730_private *lp) |
| 225 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | void *Pa; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 227 | unsigned int i, j, rxoffset, txoffset; |
| 228 | int ret; |
| 229 | |
| 230 | /* Initialize buffer space */ |
| 231 | lp->DmaRcvPackets = LAN_SAA9730_RCV_Q_SIZE; |
| 232 | lp->DmaTxmPackets = LAN_SAA9730_TXM_Q_SIZE; |
| 233 | |
| 234 | /* Initialize Rx Buffer Index */ |
| 235 | lp->NextRcvPacketIndex = 0; |
| 236 | lp->NextRcvBufferIndex = 0; |
| 237 | |
| 238 | /* Set current buffer index & next available packet index */ |
| 239 | lp->NextTxmPacketIndex = 0; |
| 240 | lp->NextTxmBufferIndex = 0; |
| 241 | lp->PendingTxmPacketIndex = 0; |
| 242 | lp->PendingTxmBufferIndex = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 244 | /* |
| 245 | * Allocate all RX and TX packets in one chunk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | * The Rx and Tx packets must be PACKET_SIZE aligned. |
| 247 | */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 248 | lp->buffer_size = ((LAN_SAA9730_RCV_Q_SIZE + LAN_SAA9730_TXM_Q_SIZE) * |
| 249 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS) + |
| 250 | LAN_SAA9730_PACKET_SIZE; |
| 251 | lp->buffer_start = pci_alloc_consistent(pdev, lp->buffer_size, |
| 252 | &lp->dma_addr); |
| 253 | if (!lp->buffer_start) { |
| 254 | ret = -ENOMEM; |
| 255 | goto out; |
| 256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 258 | Pa = (void *)ALIGN((unsigned long)lp->buffer_start, |
| 259 | LAN_SAA9730_PACKET_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 261 | rxoffset = Pa - lp->buffer_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | /* Init RX buffers */ |
| 264 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 265 | for (j = 0; j < LAN_SAA9730_RCV_Q_SIZE; j++) { |
| 266 | *(unsigned int *) Pa = |
| 267 | cpu_to_le32(RXSF_READY << |
| 268 | RX_STAT_CTL_OWNER_SHF); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 269 | lp->RcvBuffer[i][j] = Pa; |
| 270 | Pa += LAN_SAA9730_PACKET_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 274 | txoffset = Pa - lp->buffer_start; |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* Init TX buffers */ |
| 277 | for (i = 0; i < LAN_SAA9730_BUFFERS; i++) { |
| 278 | for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) { |
| 279 | *(unsigned int *) Pa = |
| 280 | cpu_to_le32(TXSF_EMPTY << |
| 281 | TX_STAT_CTL_OWNER_SHF); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 282 | lp->TxmBuffer[i][j] = Pa; |
| 283 | Pa += LAN_SAA9730_PACKET_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 287 | /* |
| 288 | * Set rx buffer A and rx buffer B to point to the first two buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * spaces. |
| 290 | */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 291 | outl(lp->dma_addr + rxoffset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | &lp->lan_saa9730_regs->RxBuffA); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 293 | outl(lp->dma_addr + rxoffset + |
| 294 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_RCV_Q_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | &lp->lan_saa9730_regs->RxBuffB); |
| 296 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 297 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | * Set txm_buf_a and txm_buf_b to point to the first two buffer |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 299 | * space |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 301 | outl(lp->dma_addr + txoffset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | &lp->lan_saa9730_regs->TxBuffA); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 303 | outl(lp->dma_addr + txoffset + |
| 304 | LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_TXM_Q_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | &lp->lan_saa9730_regs->TxBuffB); |
| 306 | |
| 307 | /* Set packet number */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 308 | outl((lp->DmaRcvPackets << PK_COUNT_RX_A_SHF) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | (lp->DmaRcvPackets << PK_COUNT_RX_B_SHF) | |
| 310 | (lp->DmaTxmPackets << PK_COUNT_TX_A_SHF) | |
| 311 | (lp->DmaTxmPackets << PK_COUNT_TX_B_SHF), |
| 312 | &lp->lan_saa9730_regs->PacketCount); |
| 313 | |
| 314 | return 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 315 | |
| 316 | out: |
| 317 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static int lan_saa9730_cam_load(struct lan_saa9730_private *lp) |
| 321 | { |
| 322 | unsigned int i; |
| 323 | unsigned char *NetworkAddress; |
| 324 | |
| 325 | NetworkAddress = (unsigned char *) &lp->PhysicalAddress[0][0]; |
| 326 | |
| 327 | for (i = 0; i < LAN_SAA9730_CAM_DWORDS; i++) { |
| 328 | /* First set address to where data is written */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 329 | outl(i, &lp->lan_saa9730_regs->CamAddress); |
| 330 | outl((NetworkAddress[0] << 24) | (NetworkAddress[1] << 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | | (NetworkAddress[2] << 8) | NetworkAddress[3], |
| 332 | &lp->lan_saa9730_regs->CamData); |
| 333 | NetworkAddress += 4; |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static int lan_saa9730_cam_init(struct net_device *dev) |
| 339 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 340 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | unsigned int i; |
| 342 | |
| 343 | /* Copy MAC-address into all entries. */ |
| 344 | for (i = 0; i < LAN_SAA9730_CAM_ENTRIES; i++) { |
| 345 | memcpy((unsigned char *) lp->PhysicalAddress[i], |
| 346 | (unsigned char *) dev->dev_addr, 6); |
| 347 | } |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int lan_saa9730_mii_init(struct lan_saa9730_private *lp) |
| 353 | { |
| 354 | int i, l; |
| 355 | |
| 356 | /* Check link status, spin here till station is not busy. */ |
| 357 | i = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 358 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | i++; |
| 360 | if (i > 100) { |
| 361 | printk("Error: lan_saa9730_mii_init: timeout\n"); |
| 362 | return -1; |
| 363 | } |
| 364 | mdelay(1); /* wait 1 ms. */ |
| 365 | } |
| 366 | |
| 367 | /* Now set the control and address register. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 368 | outl(MD_CA_BUSY | PHY_STATUS | PHY_ADDRESS << MD_CA_PHY_SHF, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | &lp->lan_saa9730_regs->StationMgmtCtl); |
| 370 | |
| 371 | /* check link status, spin here till station is not busy */ |
| 372 | i = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 373 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & MD_CA_BUSY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | i++; |
| 375 | if (i > 100) { |
| 376 | printk("Error: lan_saa9730_mii_init: timeout\n"); |
| 377 | return -1; |
| 378 | } |
| 379 | mdelay(1); /* wait 1 ms. */ |
| 380 | } |
| 381 | |
| 382 | /* Wait for 1 ms. */ |
| 383 | mdelay(1); |
| 384 | |
| 385 | /* Check the link status. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 386 | if (readl(&lp->lan_saa9730_regs->StationMgmtData) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | PHY_STATUS_LINK_UP) { |
| 388 | /* Link is up. */ |
| 389 | return 0; |
| 390 | } else { |
| 391 | /* Link is down, reset the PHY first. */ |
| 392 | |
| 393 | /* set PHY address = 'CONTROL' */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 394 | outl(PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | PHY_CONTROL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | &lp->lan_saa9730_regs->StationMgmtCtl); |
| 396 | |
| 397 | /* Wait for 1 ms. */ |
| 398 | mdelay(1); |
| 399 | |
| 400 | /* set 'CONTROL' = force reset and renegotiate */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 401 | outl(PHY_CONTROL_RESET | PHY_CONTROL_AUTO_NEG | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | PHY_CONTROL_RESTART_AUTO_NEG, |
| 403 | &lp->lan_saa9730_regs->StationMgmtData); |
| 404 | |
| 405 | /* Wait for 50 ms. */ |
| 406 | mdelay(50); |
| 407 | |
| 408 | /* set 'BUSY' to start operation */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 409 | outl(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | MD_CA_WR | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | PHY_CONTROL, &lp->lan_saa9730_regs->StationMgmtCtl); |
| 411 | |
| 412 | /* await completion */ |
| 413 | i = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 414 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | MD_CA_BUSY) { |
| 416 | i++; |
| 417 | if (i > 100) { |
| 418 | printk |
| 419 | ("Error: lan_saa9730_mii_init: timeout\n"); |
| 420 | return -1; |
| 421 | } |
| 422 | mdelay(1); /* wait 1 ms. */ |
| 423 | } |
| 424 | |
| 425 | /* Wait for 1 ms. */ |
| 426 | mdelay(1); |
| 427 | |
| 428 | for (l = 0; l < 2; l++) { |
| 429 | /* set PHY address = 'STATUS' */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 430 | outl(MD_CA_BUSY | PHY_ADDRESS << MD_CA_PHY_SHF | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | PHY_STATUS, |
| 432 | &lp->lan_saa9730_regs->StationMgmtCtl); |
| 433 | |
| 434 | /* await completion */ |
| 435 | i = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 436 | while (readl(&lp->lan_saa9730_regs->StationMgmtCtl) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | MD_CA_BUSY) { |
| 438 | i++; |
| 439 | if (i > 100) { |
| 440 | printk |
| 441 | ("Error: lan_saa9730_mii_init: timeout\n"); |
| 442 | return -1; |
| 443 | } |
| 444 | mdelay(1); /* wait 1 ms. */ |
| 445 | } |
| 446 | |
| 447 | /* wait for 3 sec. */ |
| 448 | mdelay(3000); |
| 449 | |
| 450 | /* check the link status */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 451 | if (readl(&lp->lan_saa9730_regs->StationMgmtData) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | PHY_STATUS_LINK_UP) { |
| 453 | /* link is up */ |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int lan_saa9730_control_init(struct lan_saa9730_private *lp) |
| 463 | { |
| 464 | /* Initialize DMA control register. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 465 | outl((LANMB_ANY << DMA_CTL_MAX_XFER_SHF) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | (LANEND_LITTLE << DMA_CTL_ENDIAN_SHF) | |
| 467 | (LAN_SAA9730_RCV_Q_INT_THRESHOLD << DMA_CTL_RX_INT_COUNT_SHF) |
| 468 | | DMA_CTL_RX_INT_TO_EN | DMA_CTL_RX_INT_EN | |
| 469 | DMA_CTL_MAC_RX_INT_EN | DMA_CTL_MAC_TX_INT_EN, |
| 470 | &lp->lan_saa9730_regs->LanDmaCtl); |
| 471 | |
| 472 | /* Initial MAC control register. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 473 | outl((MACCM_MII << MAC_CONTROL_CONN_SHF) | MAC_CONTROL_FULL_DUP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | &lp->lan_saa9730_regs->MacCtl); |
| 475 | |
| 476 | /* Initialize CAM control register. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 477 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_BROAD_ACC, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | &lp->lan_saa9730_regs->CamCtl); |
| 479 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 480 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | * Initialize CAM enable register, only turn on first entry, should |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 482 | * contain own addr. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 484 | outl(0x0001, &lp->lan_saa9730_regs->CamEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | /* Initialize Tx control register */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 487 | outl(TX_CTL_EN_COMP, &lp->lan_saa9730_regs->TxCtl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | /* Initialize Rcv control register */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 490 | outl(RX_CTL_STRIP_CRC, &lp->lan_saa9730_regs->RxCtl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | /* Reset DMA engine */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 493 | outl(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int lan_saa9730_stop(struct lan_saa9730_private *lp) |
| 499 | { |
| 500 | int i; |
| 501 | |
| 502 | /* Stop DMA first */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 503 | outl(readl(&lp->lan_saa9730_regs->LanDmaCtl) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | ~(DMA_CTL_EN_TX_DMA | DMA_CTL_EN_RX_DMA), |
| 505 | &lp->lan_saa9730_regs->LanDmaCtl); |
| 506 | |
| 507 | /* Set the SW Reset bits in DMA and MAC control registers */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 508 | outl(DMA_TEST_SW_RESET, &lp->lan_saa9730_regs->DmaTest); |
| 509 | outl(readl(&lp->lan_saa9730_regs->MacCtl) | MAC_CONTROL_RESET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | &lp->lan_saa9730_regs->MacCtl); |
| 511 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 512 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | * Wait for MAC reset to have finished. The reset bit is auto cleared |
| 514 | * when the reset is done. |
| 515 | */ |
| 516 | i = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 517 | while (readl(&lp->lan_saa9730_regs->MacCtl) & MAC_CONTROL_RESET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | i++; |
| 519 | if (i > 100) { |
| 520 | printk |
| 521 | ("Error: lan_sa9730_stop: MAC reset timeout\n"); |
| 522 | return -1; |
| 523 | } |
| 524 | mdelay(1); /* wait 1 ms. */ |
| 525 | } |
| 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int lan_saa9730_dma_init(struct lan_saa9730_private *lp) |
| 531 | { |
| 532 | /* Stop lan controller. */ |
| 533 | lan_saa9730_stop(lp); |
| 534 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 535 | outl(LAN_SAA9730_DEFAULT_TIME_OUT_CNT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | &lp->lan_saa9730_regs->Timeout); |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | static int lan_saa9730_start(struct lan_saa9730_private *lp) |
| 542 | { |
| 543 | lan_saa9730_buffer_init(lp); |
| 544 | |
| 545 | /* Initialize Rx Buffer Index */ |
| 546 | lp->NextRcvPacketIndex = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 547 | lp->NextRcvBufferIndex = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 549 | /* Set current buffer index & next available packet index */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | lp->NextTxmPacketIndex = 0; |
| 551 | lp->NextTxmBufferIndex = 0; |
| 552 | lp->PendingTxmPacketIndex = 0; |
| 553 | lp->PendingTxmBufferIndex = 0; |
| 554 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 555 | outl(readl(&lp->lan_saa9730_regs->LanDmaCtl) | DMA_CTL_EN_TX_DMA | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | DMA_CTL_EN_RX_DMA, &lp->lan_saa9730_regs->LanDmaCtl); |
| 557 | |
| 558 | /* For Tx, turn on MAC then DMA */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 559 | outl(readl(&lp->lan_saa9730_regs->TxCtl) | TX_CTL_TX_EN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | &lp->lan_saa9730_regs->TxCtl); |
| 561 | |
| 562 | /* For Rx, turn on DMA then MAC */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 563 | outl(readl(&lp->lan_saa9730_regs->RxCtl) | RX_CTL_RX_EN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | &lp->lan_saa9730_regs->RxCtl); |
| 565 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 566 | /* Set Ok2Use to let hardware own the buffers. */ |
| 567 | outl(OK2USE_RX_A | OK2USE_RX_B, &lp->lan_saa9730_regs->Ok2Use); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | static int lan_saa9730_restart(struct lan_saa9730_private *lp) |
| 573 | { |
| 574 | lan_saa9730_stop(lp); |
| 575 | lan_saa9730_start(lp); |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int lan_saa9730_tx(struct net_device *dev) |
| 581 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 582 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | unsigned int *pPacket; |
| 584 | unsigned int tx_status; |
| 585 | |
| 586 | if (lan_saa9730_debug > 5) |
| 587 | printk("lan_saa9730_tx interrupt\n"); |
| 588 | |
| 589 | /* Clear interrupt. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 590 | outl(DMA_STATUS_MAC_TX_INT, &lp->lan_saa9730_regs->DmaStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | while (1) { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 593 | pPacket = lp->TxmBuffer[lp->PendingTxmBufferIndex] |
| 594 | [lp->PendingTxmPacketIndex]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | /* Get status of first packet transmitted. */ |
| 597 | tx_status = le32_to_cpu(*pPacket); |
| 598 | |
| 599 | /* Check ownership. */ |
| 600 | if ((tx_status & TX_STAT_CTL_OWNER_MSK) != |
| 601 | (TXSF_HWDONE << TX_STAT_CTL_OWNER_SHF)) break; |
| 602 | |
| 603 | /* Check for error. */ |
| 604 | if (tx_status & TX_STAT_CTL_ERROR_MSK) { |
| 605 | if (lan_saa9730_debug > 1) |
| 606 | printk("lan_saa9730_tx: tx error = %x\n", |
| 607 | tx_status); |
| 608 | |
| 609 | lp->stats.tx_errors++; |
| 610 | if (tx_status & |
| 611 | (TX_STATUS_EX_COLL << TX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 612 | lp->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | if (tx_status & |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 614 | (TX_STATUS_LATE_COLL << TX_STAT_CTL_STATUS_SHF)) |
| 615 | lp->stats.tx_window_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | if (tx_status & |
| 617 | (TX_STATUS_L_CARR << TX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 618 | lp->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | if (tx_status & |
| 620 | (TX_STATUS_UNDER << TX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 621 | lp->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if (tx_status & |
| 623 | (TX_STATUS_SQ_ERR << TX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 624 | lp->stats.tx_heartbeat_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | lp->stats.collisions += |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 627 | tx_status & TX_STATUS_TX_COLL_MSK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* Free buffer. */ |
| 631 | *pPacket = |
| 632 | cpu_to_le32(TXSF_EMPTY << TX_STAT_CTL_OWNER_SHF); |
| 633 | |
| 634 | /* Update pending index pointer. */ |
| 635 | lp->PendingTxmPacketIndex++; |
| 636 | if (lp->PendingTxmPacketIndex >= LAN_SAA9730_TXM_Q_SIZE) { |
| 637 | lp->PendingTxmPacketIndex = 0; |
| 638 | lp->PendingTxmBufferIndex ^= 1; |
| 639 | } |
| 640 | } |
| 641 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 642 | /* The tx buffer is no longer full. */ |
| 643 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static int lan_saa9730_rx(struct net_device *dev) |
| 649 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 650 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | int len = 0; |
| 652 | struct sk_buff *skb = 0; |
| 653 | unsigned int rx_status; |
| 654 | int BufferIndex; |
| 655 | int PacketIndex; |
| 656 | unsigned int *pPacket; |
| 657 | unsigned char *pData; |
| 658 | |
| 659 | if (lan_saa9730_debug > 5) |
| 660 | printk("lan_saa9730_rx interrupt\n"); |
| 661 | |
| 662 | /* Clear receive interrupts. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 663 | outl(DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | DMA_STATUS_RX_TO_INT, &lp->lan_saa9730_regs->DmaStatus); |
| 665 | |
| 666 | /* Address next packet */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 667 | BufferIndex = lp->NextRcvBufferIndex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | PacketIndex = lp->NextRcvPacketIndex; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 669 | pPacket = lp->RcvBuffer[BufferIndex][PacketIndex]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | rx_status = le32_to_cpu(*pPacket); |
| 671 | |
| 672 | /* Process each packet. */ |
| 673 | while ((rx_status & RX_STAT_CTL_OWNER_MSK) == |
| 674 | (RXSF_HWDONE << RX_STAT_CTL_OWNER_SHF)) { |
| 675 | /* Check the rx status. */ |
| 676 | if (rx_status & (RX_STATUS_GOOD << RX_STAT_CTL_STATUS_SHF)) { |
| 677 | /* Received packet is good. */ |
| 678 | len = (rx_status & RX_STAT_CTL_LENGTH_MSK) >> |
| 679 | RX_STAT_CTL_LENGTH_SHF; |
| 680 | |
| 681 | pData = (unsigned char *) pPacket; |
| 682 | pData += 4; |
| 683 | skb = dev_alloc_skb(len + 2); |
| 684 | if (skb == 0) { |
| 685 | printk |
| 686 | ("%s: Memory squeeze, deferring packet.\n", |
| 687 | dev->name); |
| 688 | lp->stats.rx_dropped++; |
| 689 | } else { |
| 690 | lp->stats.rx_bytes += len; |
| 691 | lp->stats.rx_packets++; |
| 692 | skb->dev = dev; |
| 693 | skb_reserve(skb, 2); /* 16 byte align */ |
| 694 | skb_put(skb, len); /* make room */ |
| 695 | eth_copy_and_sum(skb, |
| 696 | (unsigned char *) pData, |
| 697 | len, 0); |
| 698 | skb->protocol = eth_type_trans(skb, dev); |
| 699 | netif_rx(skb); |
| 700 | dev->last_rx = jiffies; |
| 701 | } |
| 702 | } else { |
| 703 | /* We got an error packet. */ |
| 704 | if (lan_saa9730_debug > 2) |
| 705 | printk |
| 706 | ("lan_saa9730_rx: We got an error packet = %x\n", |
| 707 | rx_status); |
| 708 | |
| 709 | lp->stats.rx_errors++; |
| 710 | if (rx_status & |
| 711 | (RX_STATUS_CRC_ERR << RX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 712 | lp->stats.rx_crc_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | if (rx_status & |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 714 | (RX_STATUS_ALIGN_ERR << RX_STAT_CTL_STATUS_SHF)) |
| 715 | lp->stats.rx_frame_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | if (rx_status & |
| 717 | (RX_STATUS_OVERFLOW << RX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 718 | lp->stats.rx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | if (rx_status & |
| 720 | (RX_STATUS_LONG_ERR << RX_STAT_CTL_STATUS_SHF)) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 721 | lp->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /* Indicate we have processed the buffer. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 725 | *pPacket = cpu_to_le32(RXSF_READY << RX_STAT_CTL_OWNER_SHF); |
| 726 | |
| 727 | /* Make sure A or B is available to hardware as appropriate. */ |
| 728 | outl(BufferIndex ? OK2USE_RX_B : OK2USE_RX_A, |
| 729 | &lp->lan_saa9730_regs->Ok2Use); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| 731 | /* Go to next packet in sequence. */ |
| 732 | lp->NextRcvPacketIndex++; |
| 733 | if (lp->NextRcvPacketIndex >= LAN_SAA9730_RCV_Q_SIZE) { |
| 734 | lp->NextRcvPacketIndex = 0; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 735 | lp->NextRcvBufferIndex ^= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | /* Address next packet */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 739 | BufferIndex = lp->NextRcvBufferIndex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | PacketIndex = lp->NextRcvPacketIndex; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 741 | pPacket = lp->RcvBuffer[BufferIndex][PacketIndex]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | rx_status = le32_to_cpu(*pPacket); |
| 743 | } |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 748 | static irqreturn_t lan_saa9730_interrupt(const int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { |
Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 750 | struct net_device *dev = dev_id; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 751 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | if (lan_saa9730_debug > 5) |
| 754 | printk("lan_saa9730_interrupt\n"); |
| 755 | |
| 756 | /* Disable the EVM LAN interrupt. */ |
| 757 | evm_saa9730_block_lan_int(lp); |
| 758 | |
| 759 | /* Clear the EVM LAN interrupt. */ |
| 760 | evm_saa9730_clear_lan_int(lp); |
| 761 | |
| 762 | /* Service pending transmit interrupts. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 763 | if (readl(&lp->lan_saa9730_regs->DmaStatus) & DMA_STATUS_MAC_TX_INT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | lan_saa9730_tx(dev); |
| 765 | |
| 766 | /* Service pending receive interrupts. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 767 | if (readl(&lp->lan_saa9730_regs->DmaStatus) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | (DMA_STATUS_MAC_RX_INT | DMA_STATUS_RX_INT | |
| 769 | DMA_STATUS_RX_TO_INT)) lan_saa9730_rx(dev); |
| 770 | |
| 771 | /* Enable the EVM LAN interrupt. */ |
| 772 | evm_saa9730_unblock_lan_int(lp); |
| 773 | |
| 774 | return IRQ_HANDLED; |
| 775 | } |
| 776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | static int lan_saa9730_open(struct net_device *dev) |
| 778 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 779 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | /* Associate IRQ with lan_saa9730_interrupt */ |
| 782 | if (request_irq(dev->irq, &lan_saa9730_interrupt, 0, "SAA9730 Eth", |
| 783 | dev)) { |
| 784 | printk("lan_saa9730_open: Can't get irq %d\n", dev->irq); |
| 785 | return -EAGAIN; |
| 786 | } |
| 787 | |
| 788 | /* Enable the Lan interrupt in the event manager. */ |
| 789 | evm_saa9730_enable_lan_int(lp); |
| 790 | |
| 791 | /* Start the LAN controller */ |
| 792 | if (lan_saa9730_start(lp)) |
| 793 | return -1; |
| 794 | |
| 795 | netif_start_queue(dev); |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | static int lan_saa9730_write(struct lan_saa9730_private *lp, |
| 801 | struct sk_buff *skb, int skblen) |
| 802 | { |
| 803 | unsigned char *pbData = skb->data; |
| 804 | unsigned int len = skblen; |
| 805 | unsigned char *pbPacketData; |
| 806 | unsigned int tx_status; |
| 807 | int BufferIndex; |
| 808 | int PacketIndex; |
| 809 | |
| 810 | if (lan_saa9730_debug > 5) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 811 | printk("lan_saa9730_write: skb=%p\n", skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
| 813 | BufferIndex = lp->NextTxmBufferIndex; |
| 814 | PacketIndex = lp->NextTxmPacketIndex; |
| 815 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 816 | tx_status = le32_to_cpu(*(unsigned int *)lp->TxmBuffer[BufferIndex] |
| 817 | [PacketIndex]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | if ((tx_status & TX_STAT_CTL_OWNER_MSK) != |
| 819 | (TXSF_EMPTY << TX_STAT_CTL_OWNER_SHF)) { |
| 820 | if (lan_saa9730_debug > 4) |
| 821 | printk |
| 822 | ("lan_saa9730_write: Tx buffer not available: tx_status = %x\n", |
| 823 | tx_status); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | lp->NextTxmPacketIndex++; |
| 828 | if (lp->NextTxmPacketIndex >= LAN_SAA9730_TXM_Q_SIZE) { |
| 829 | lp->NextTxmPacketIndex = 0; |
| 830 | lp->NextTxmBufferIndex ^= 1; |
| 831 | } |
| 832 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 833 | pbPacketData = lp->TxmBuffer[BufferIndex][PacketIndex]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | pbPacketData += 4; |
| 835 | |
| 836 | /* copy the bits */ |
| 837 | memcpy(pbPacketData, pbData, len); |
| 838 | |
| 839 | /* Set transmit status for hardware */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 840 | *(unsigned int *)lp->TxmBuffer[BufferIndex][PacketIndex] = |
| 841 | cpu_to_le32((TXSF_READY << TX_STAT_CTL_OWNER_SHF) | |
| 842 | (TX_STAT_CTL_INT_AFTER_TX << |
| 843 | TX_STAT_CTL_FRAME_SHF) | |
| 844 | (len << TX_STAT_CTL_LENGTH_SHF)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 846 | /* Make sure A or B is available to hardware as appropriate. */ |
| 847 | outl(BufferIndex ? OK2USE_TX_B : OK2USE_TX_A, |
| 848 | &lp->lan_saa9730_regs->Ok2Use); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static void lan_saa9730_tx_timeout(struct net_device *dev) |
| 854 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 855 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | /* Transmitter timeout, serious problems */ |
| 858 | lp->stats.tx_errors++; |
| 859 | printk("%s: transmit timed out, reset\n", dev->name); |
| 860 | /*show_saa9730_regs(lp); */ |
| 861 | lan_saa9730_restart(lp); |
| 862 | |
| 863 | dev->trans_start = jiffies; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 864 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | static int lan_saa9730_start_xmit(struct sk_buff *skb, |
| 868 | struct net_device *dev) |
| 869 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 870 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | unsigned long flags; |
| 872 | int skblen; |
| 873 | int len; |
| 874 | |
| 875 | if (lan_saa9730_debug > 4) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 876 | printk("Send packet: skb=%p\n", skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | skblen = skb->len; |
| 879 | |
| 880 | spin_lock_irqsave(&lp->lock, flags); |
| 881 | |
| 882 | len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen; |
| 883 | |
| 884 | if (lan_saa9730_write(lp, skb, skblen)) { |
| 885 | spin_unlock_irqrestore(&lp->lock, flags); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 886 | printk("Error when writing packet to controller: skb=%p\n", skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | netif_stop_queue(dev); |
| 888 | return -1; |
| 889 | } |
| 890 | |
| 891 | lp->stats.tx_bytes += len; |
| 892 | lp->stats.tx_packets++; |
| 893 | |
| 894 | dev->trans_start = jiffies; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 895 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | dev_kfree_skb(skb); |
| 897 | |
| 898 | spin_unlock_irqrestore(&lp->lock, flags); |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static int lan_saa9730_close(struct net_device *dev) |
| 904 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 905 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | if (lan_saa9730_debug > 1) |
| 908 | printk("lan_saa9730_close:\n"); |
| 909 | |
| 910 | netif_stop_queue(dev); |
| 911 | |
| 912 | /* Disable the Lan interrupt in the event manager. */ |
| 913 | evm_saa9730_disable_lan_int(lp); |
| 914 | |
| 915 | /* Stop the controller */ |
| 916 | if (lan_saa9730_stop(lp)) |
| 917 | return -1; |
| 918 | |
| 919 | free_irq(dev->irq, (void *) dev); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static struct net_device_stats *lan_saa9730_get_stats(struct net_device |
| 925 | *dev) |
| 926 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 927 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | return &lp->stats; |
| 930 | } |
| 931 | |
| 932 | static void lan_saa9730_set_multicast(struct net_device *dev) |
| 933 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 934 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | /* Stop the controller */ |
| 937 | lan_saa9730_stop(lp); |
| 938 | |
| 939 | if (dev->flags & IFF_PROMISC) { |
| 940 | /* accept all packets */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 941 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_STATION_ACC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | CAM_CONTROL_GROUP_ACC | CAM_CONTROL_BROAD_ACC, |
| 943 | &lp->lan_saa9730_regs->CamCtl); |
| 944 | } else { |
| 945 | if (dev->flags & IFF_ALLMULTI) { |
| 946 | /* accept all multicast packets */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 947 | outl(CAM_CONTROL_COMP_EN | CAM_CONTROL_GROUP_ACC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | CAM_CONTROL_BROAD_ACC, |
| 949 | &lp->lan_saa9730_regs->CamCtl); |
| 950 | } else { |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 951 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | * Will handle the multicast stuff later. -carstenl |
| 953 | */ |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | lan_saa9730_restart(lp); |
| 958 | } |
| 959 | |
| 960 | |
| 961 | static void __devexit saa9730_remove_one(struct pci_dev *pdev) |
| 962 | { |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 963 | struct net_device *dev = pci_get_drvdata(pdev); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 964 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 966 | if (dev) { |
| 967 | unregister_netdev(dev); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 968 | lan_saa9730_free_buffers(pdev, lp); |
| 969 | iounmap(lp->lan_saa9730_regs); |
| 970 | iounmap(lp->evm_saa9730_regs); |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 971 | free_netdev(dev); |
| 972 | pci_release_regions(pdev); |
| 973 | pci_disable_device(pdev); |
| 974 | pci_set_drvdata(pdev, NULL); |
| 975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 979 | static int lan_saa9730_init(struct net_device *dev, struct pci_dev *pdev, |
| 980 | unsigned long ioaddr, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 982 | struct lan_saa9730_private *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | unsigned char ethernet_addr[6]; |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 984 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 986 | if (get_ethernet_addr(ethernet_addr)) { |
| 987 | ret = -ENODEV; |
| 988 | goto out; |
| 989 | } |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | memcpy(dev->dev_addr, ethernet_addr, 6); |
| 992 | dev->base_addr = ioaddr; |
| 993 | dev->irq = irq; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 994 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 995 | lp->pci_dev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
| 997 | /* Set SAA9730 LAN base address. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 998 | lp->lan_saa9730_regs = ioremap(ioaddr + SAA9730_LAN_REGS_ADDR, |
| 999 | SAA9730_LAN_REGS_SIZE); |
| 1000 | if (!lp->lan_saa9730_regs) { |
| 1001 | ret = -ENOMEM; |
| 1002 | goto out; |
| 1003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | /* Set SAA9730 EVM base address. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1006 | lp->evm_saa9730_regs = ioremap(ioaddr + SAA9730_EVM_REGS_ADDR, |
| 1007 | SAA9730_EVM_REGS_SIZE); |
| 1008 | if (!lp->evm_saa9730_regs) { |
| 1009 | ret = -ENOMEM; |
| 1010 | goto out_iounmap_lan; |
| 1011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
| 1013 | /* Allocate LAN RX/TX frame buffer space. */ |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1014 | if ((ret = lan_saa9730_allocate_buffers(pdev, lp))) |
| 1015 | goto out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | /* Stop LAN controller. */ |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1018 | if ((ret = lan_saa9730_stop(lp))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1019 | goto out_free_consistent; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | /* Initialize CAM registers. */ |
| 1022 | if ((ret = lan_saa9730_cam_init(dev))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1023 | goto out_free_consistent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | /* Initialize MII registers. */ |
| 1026 | if ((ret = lan_saa9730_mii_init(lp))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1027 | goto out_free_consistent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | /* Initialize control registers. */ |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1030 | if ((ret = lan_saa9730_control_init(lp))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1031 | goto out_free_consistent; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | /* Load CAM registers. */ |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1034 | if ((ret = lan_saa9730_cam_load(lp))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1035 | goto out_free_consistent; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | /* Initialize DMA context registers. */ |
| 1038 | if ((ret = lan_saa9730_dma_init(lp))) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1039 | goto out_free_consistent; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | spin_lock_init(&lp->lock); |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | dev->open = lan_saa9730_open; |
| 1044 | dev->hard_start_xmit = lan_saa9730_start_xmit; |
| 1045 | dev->stop = lan_saa9730_close; |
| 1046 | dev->get_stats = lan_saa9730_get_stats; |
| 1047 | dev->set_multicast_list = lan_saa9730_set_multicast; |
| 1048 | dev->tx_timeout = lan_saa9730_tx_timeout; |
| 1049 | dev->watchdog_timeo = (HZ >> 1); |
| 1050 | dev->dma = 0; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1051 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1052 | ret = register_netdev (dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | if (ret) |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1054 | goto out_free_consistent; |
| 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | return 0; |
| 1057 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1058 | out_free_consistent: |
| 1059 | lan_saa9730_free_buffers(pdev, lp); |
| 1060 | out_iounmap: |
| 1061 | iounmap(lp->evm_saa9730_regs); |
| 1062 | out_iounmap_lan: |
| 1063 | iounmap(lp->lan_saa9730_regs); |
| 1064 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | static int __devinit saa9730_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1070 | { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1071 | struct net_device *dev = NULL; |
| 1072 | unsigned long pci_ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | int err; |
| 1074 | |
| 1075 | if (lan_saa9730_debug > 1) |
| 1076 | printk("saa9730.c: PCI bios is present, checking for devices...\n"); |
| 1077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | err = pci_enable_device(pdev); |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1079 | if (err) { |
| 1080 | printk(KERN_ERR "Cannot enable PCI device, aborting.\n"); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1081 | goto out; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
| 1084 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 1085 | if (err) { |
| 1086 | printk(KERN_ERR "Cannot obtain PCI resources, aborting.\n"); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1087 | goto out_disable_pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | pci_irq_line = pdev->irq; |
| 1091 | /* LAN base address in located at BAR 1. */ |
| 1092 | |
| 1093 | pci_ioaddr = pci_resource_start(pdev, 1); |
| 1094 | pci_set_master(pdev); |
| 1095 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1096 | printk("Found SAA9730 (PCI) at %lx, irq %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | pci_ioaddr, pci_irq_line); |
| 1098 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1099 | dev = alloc_etherdev(sizeof(struct lan_saa9730_private)); |
| 1100 | if (!dev) |
| 1101 | goto out_disable_pdev; |
| 1102 | |
| 1103 | err = lan_saa9730_init(dev, pdev, pci_ioaddr, pci_irq_line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (err) { |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1105 | printk("LAN init failed"); |
| 1106 | goto out_free_netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | pci_set_drvdata(pdev, dev); |
| 1110 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1111 | return 0; |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1112 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1113 | out_free_netdev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | free_netdev(dev); |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1115 | out_disable_pdev: |
| 1116 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | out: |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1118 | pci_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | return err; |
| 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | static struct pci_driver saa9730_driver = { |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1124 | .name = DRV_MODULE_NAME, |
| 1125 | .id_table = saa9730_pci_tbl, |
| 1126 | .probe = saa9730_init_one, |
| 1127 | .remove = __devexit_p(saa9730_remove_one), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | }; |
| 1129 | |
| 1130 | |
| 1131 | static int __init saa9730_init(void) |
| 1132 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 1133 | return pci_register_driver(&saa9730_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | static void __exit saa9730_cleanup(void) |
| 1137 | { |
Ralf Baechle | 62ff0d0 | 2005-11-09 16:44:02 +0000 | [diff] [blame] | 1138 | pci_unregister_driver(&saa9730_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | module_init(saa9730_init); |
| 1142 | module_exit(saa9730_cleanup); |
| 1143 | |
Ralf Baechle | 05d9c84 | 2005-11-09 17:10:05 +0000 | [diff] [blame] | 1144 | MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); |
| 1145 | MODULE_DESCRIPTION("Philips SAA9730 ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | MODULE_LICENSE("GPL"); |