Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1 | /* |
| 2 | * tc35815.c: A TOSHIBA TC35815CF PCI 10/100Mbps ethernet driver for linux. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Based on skelton.c by Donald Becker. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 6 | * This driver is a replacement of older and less maintained version. |
| 7 | * This is a header of the older version: |
| 8 | * -----<snip>----- |
| 9 | * Copyright 2001 MontaVista Software Inc. |
| 10 | * Author: MontaVista Software, Inc. |
| 11 | * ahennessy@mvista.com |
| 12 | * Copyright (C) 2000-2001 Toshiba Corporation |
| 13 | * static const char *version = |
| 14 | * "tc35815.c:v0.00 26/07/2000 by Toshiba Corporation\n"; |
| 15 | * -----<snip>----- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 17 | * This file is subject to the terms and conditions of the GNU General Public |
| 18 | * License. See the file "COPYING" in the main directory of this archive |
| 19 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 21 | * (C) Copyright TOSHIBA CORPORATION 2004-2005 |
| 22 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
Atsushi Nemoto | b75c6db | 2009-10-26 03:46:22 +0000 | [diff] [blame] | 25 | #define TC35815_NAPI |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 26 | #ifdef TC35815_NAPI |
Atsushi Nemoto | 297713d | 2009-08-06 04:41:45 +0000 | [diff] [blame] | 27 | #define DRV_VERSION "1.38-NAPI" |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 28 | #else |
Atsushi Nemoto | 297713d | 2009-08-06 04:41:45 +0000 | [diff] [blame] | 29 | #define DRV_VERSION "1.38" |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 30 | #endif |
| 31 | static const char *version = "tc35815.c:v" DRV_VERSION "\n"; |
| 32 | #define MODNAME "tc35815" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/fcntl.h> |
| 38 | #include <linux/interrupt.h> |
| 39 | #include <linux/ioport.h> |
| 40 | #include <linux/in.h> |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/slab.h> |
| 43 | #include <linux/string.h> |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 44 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/errno.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/netdevice.h> |
| 48 | #include <linux/etherdevice.h> |
| 49 | #include <linux/skbuff.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/pci.h> |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 52 | #include <linux/phy.h> |
| 53 | #include <linux/workqueue.h> |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 54 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/byteorder.h> |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /* First, a few definitions that the brave might change. */ |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define GATHER_TXINT /* On-Demand Tx Interrupt */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 61 | #define WORKAROUND_LOSTCAR |
| 62 | #define WORKAROUND_100HALF_PROMISC |
| 63 | /* #define TC35815_USE_PACKEDBUFFER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 65 | enum tc35815_chiptype { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 66 | TC35815CF = 0, |
| 67 | TC35815_NWU, |
| 68 | TC35815_TX4939, |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 69 | }; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 70 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 71 | /* indexed by tc35815_chiptype, above */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 72 | static const struct { |
| 73 | const char *name; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 74 | } chip_info[] __devinitdata = { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 75 | { "TOSHIBA TC35815CF 10/100BaseTX" }, |
| 76 | { "TOSHIBA TC35815 with Wake on LAN" }, |
| 77 | { "TOSHIBA TC35815/TX4939" }, |
| 78 | }; |
| 79 | |
| 80 | static const struct pci_device_id tc35815_pci_tbl[] = { |
| 81 | {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC35815CF), .driver_data = TC35815CF }, |
| 82 | {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC35815_NWU), .driver_data = TC35815_NWU }, |
| 83 | {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC35815_TX4939), .driver_data = TC35815_TX4939 }, |
| 84 | {0,} |
| 85 | }; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 86 | MODULE_DEVICE_TABLE(pci, tc35815_pci_tbl); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 87 | |
| 88 | /* see MODULE_PARM_DESC */ |
| 89 | static struct tc35815_options { |
| 90 | int speed; |
| 91 | int duplex; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 92 | } options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Registers |
| 96 | */ |
| 97 | struct tc35815_regs { |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 98 | __u32 DMA_Ctl; /* 0x00 */ |
| 99 | __u32 TxFrmPtr; |
| 100 | __u32 TxThrsh; |
| 101 | __u32 TxPollCtr; |
| 102 | __u32 BLFrmPtr; |
| 103 | __u32 RxFragSize; |
| 104 | __u32 Int_En; |
| 105 | __u32 FDA_Bas; |
| 106 | __u32 FDA_Lim; /* 0x20 */ |
| 107 | __u32 Int_Src; |
| 108 | __u32 unused0[2]; |
| 109 | __u32 PauseCnt; |
| 110 | __u32 RemPauCnt; |
| 111 | __u32 TxCtlFrmStat; |
| 112 | __u32 unused1; |
| 113 | __u32 MAC_Ctl; /* 0x40 */ |
| 114 | __u32 CAM_Ctl; |
| 115 | __u32 Tx_Ctl; |
| 116 | __u32 Tx_Stat; |
| 117 | __u32 Rx_Ctl; |
| 118 | __u32 Rx_Stat; |
| 119 | __u32 MD_Data; |
| 120 | __u32 MD_CA; |
| 121 | __u32 CAM_Adr; /* 0x60 */ |
| 122 | __u32 CAM_Data; |
| 123 | __u32 CAM_Ena; |
| 124 | __u32 PROM_Ctl; |
| 125 | __u32 PROM_Data; |
| 126 | __u32 Algn_Cnt; |
| 127 | __u32 CRC_Cnt; |
| 128 | __u32 Miss_Cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /* |
| 132 | * Bit assignments |
| 133 | */ |
| 134 | /* DMA_Ctl bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 135 | #define DMA_RxAlign 0x00c00000 /* 1:Reception Alignment */ |
| 136 | #define DMA_RxAlign_1 0x00400000 |
| 137 | #define DMA_RxAlign_2 0x00800000 |
| 138 | #define DMA_RxAlign_3 0x00c00000 |
| 139 | #define DMA_M66EnStat 0x00080000 /* 1:66MHz Enable State */ |
| 140 | #define DMA_IntMask 0x00040000 /* 1:Interupt mask */ |
| 141 | #define DMA_SWIntReq 0x00020000 /* 1:Software Interrupt request */ |
| 142 | #define DMA_TxWakeUp 0x00010000 /* 1:Transmit Wake Up */ |
| 143 | #define DMA_RxBigE 0x00008000 /* 1:Receive Big Endian */ |
| 144 | #define DMA_TxBigE 0x00004000 /* 1:Transmit Big Endian */ |
| 145 | #define DMA_TestMode 0x00002000 /* 1:Test Mode */ |
| 146 | #define DMA_PowrMgmnt 0x00001000 /* 1:Power Management */ |
| 147 | #define DMA_DmBurst_Mask 0x000001fc /* DMA Burst size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* RxFragSize bit asign ---------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 150 | #define RxFrag_EnPack 0x00008000 /* 1:Enable Packing */ |
| 151 | #define RxFrag_MinFragMask 0x00000ffc /* Minimum Fragment */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* MAC_Ctl bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 154 | #define MAC_Link10 0x00008000 /* 1:Link Status 10Mbits */ |
| 155 | #define MAC_EnMissRoll 0x00002000 /* 1:Enable Missed Roll */ |
| 156 | #define MAC_MissRoll 0x00000400 /* 1:Missed Roll */ |
| 157 | #define MAC_Loop10 0x00000080 /* 1:Loop 10 Mbps */ |
| 158 | #define MAC_Conn_Auto 0x00000000 /*00:Connection mode (Automatic) */ |
| 159 | #define MAC_Conn_10M 0x00000020 /*01: (10Mbps endec)*/ |
| 160 | #define MAC_Conn_Mll 0x00000040 /*10: (Mll clock) */ |
| 161 | #define MAC_MacLoop 0x00000010 /* 1:MAC Loopback */ |
| 162 | #define MAC_FullDup 0x00000008 /* 1:Full Duplex 0:Half Duplex */ |
| 163 | #define MAC_Reset 0x00000004 /* 1:Software Reset */ |
| 164 | #define MAC_HaltImm 0x00000002 /* 1:Halt Immediate */ |
| 165 | #define MAC_HaltReq 0x00000001 /* 1:Halt request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | /* PROM_Ctl bit asign ------------------------------------------------------ */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 168 | #define PROM_Busy 0x00008000 /* 1:Busy (Start Operation) */ |
| 169 | #define PROM_Read 0x00004000 /*10:Read operation */ |
| 170 | #define PROM_Write 0x00002000 /*01:Write operation */ |
| 171 | #define PROM_Erase 0x00006000 /*11:Erase operation */ |
| 172 | /*00:Enable or Disable Writting, */ |
| 173 | /* as specified in PROM_Addr. */ |
| 174 | #define PROM_Addr_Ena 0x00000030 /*11xxxx:PROM Write enable */ |
| 175 | /*00xxxx: disable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* CAM_Ctl bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 178 | #define CAM_CompEn 0x00000010 /* 1:CAM Compare Enable */ |
| 179 | #define CAM_NegCAM 0x00000008 /* 1:Reject packets CAM recognizes,*/ |
| 180 | /* accept other */ |
| 181 | #define CAM_BroadAcc 0x00000004 /* 1:Broadcast assept */ |
| 182 | #define CAM_GroupAcc 0x00000002 /* 1:Multicast assept */ |
| 183 | #define CAM_StationAcc 0x00000001 /* 1:unicast accept */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | /* CAM_Ena bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 186 | #define CAM_ENTRY_MAX 21 /* CAM Data entry max count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #define CAM_Ena_Mask ((1<<CAM_ENTRY_MAX)-1) /* CAM Enable bits (Max 21bits) */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 188 | #define CAM_Ena_Bit(index) (1 << (index)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #define CAM_ENTRY_DESTINATION 0 |
| 190 | #define CAM_ENTRY_SOURCE 1 |
| 191 | #define CAM_ENTRY_MACCTL 20 |
| 192 | |
| 193 | /* Tx_Ctl bit asign -------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 194 | #define Tx_En 0x00000001 /* 1:Transmit enable */ |
| 195 | #define Tx_TxHalt 0x00000002 /* 1:Transmit Halt Request */ |
| 196 | #define Tx_NoPad 0x00000004 /* 1:Suppress Padding */ |
| 197 | #define Tx_NoCRC 0x00000008 /* 1:Suppress Padding */ |
| 198 | #define Tx_FBack 0x00000010 /* 1:Fast Back-off */ |
| 199 | #define Tx_EnUnder 0x00000100 /* 1:Enable Underrun */ |
| 200 | #define Tx_EnExDefer 0x00000200 /* 1:Enable Excessive Deferral */ |
| 201 | #define Tx_EnLCarr 0x00000400 /* 1:Enable Lost Carrier */ |
| 202 | #define Tx_EnExColl 0x00000800 /* 1:Enable Excessive Collision */ |
| 203 | #define Tx_EnLateColl 0x00001000 /* 1:Enable Late Collision */ |
| 204 | #define Tx_EnTxPar 0x00002000 /* 1:Enable Transmit Parity */ |
| 205 | #define Tx_EnComp 0x00004000 /* 1:Enable Completion */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* Tx_Stat bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 208 | #define Tx_TxColl_MASK 0x0000000F /* Tx Collision Count */ |
| 209 | #define Tx_ExColl 0x00000010 /* Excessive Collision */ |
| 210 | #define Tx_TXDefer 0x00000020 /* Transmit Defered */ |
| 211 | #define Tx_Paused 0x00000040 /* Transmit Paused */ |
| 212 | #define Tx_IntTx 0x00000080 /* Interrupt on Tx */ |
| 213 | #define Tx_Under 0x00000100 /* Underrun */ |
| 214 | #define Tx_Defer 0x00000200 /* Deferral */ |
| 215 | #define Tx_NCarr 0x00000400 /* No Carrier */ |
| 216 | #define Tx_10Stat 0x00000800 /* 10Mbps Status */ |
| 217 | #define Tx_LateColl 0x00001000 /* Late Collision */ |
| 218 | #define Tx_TxPar 0x00002000 /* Tx Parity Error */ |
| 219 | #define Tx_Comp 0x00004000 /* Completion */ |
| 220 | #define Tx_Halted 0x00008000 /* Tx Halted */ |
| 221 | #define Tx_SQErr 0x00010000 /* Signal Quality Error(SQE) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | /* Rx_Ctl bit asign -------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 224 | #define Rx_EnGood 0x00004000 /* 1:Enable Good */ |
| 225 | #define Rx_EnRxPar 0x00002000 /* 1:Enable Receive Parity */ |
| 226 | #define Rx_EnLongErr 0x00000800 /* 1:Enable Long Error */ |
| 227 | #define Rx_EnOver 0x00000400 /* 1:Enable OverFlow */ |
| 228 | #define Rx_EnCRCErr 0x00000200 /* 1:Enable CRC Error */ |
| 229 | #define Rx_EnAlign 0x00000100 /* 1:Enable Alignment */ |
| 230 | #define Rx_IgnoreCRC 0x00000040 /* 1:Ignore CRC Value */ |
| 231 | #define Rx_StripCRC 0x00000010 /* 1:Strip CRC Value */ |
| 232 | #define Rx_ShortEn 0x00000008 /* 1:Short Enable */ |
| 233 | #define Rx_LongEn 0x00000004 /* 1:Long Enable */ |
| 234 | #define Rx_RxHalt 0x00000002 /* 1:Receive Halt Request */ |
| 235 | #define Rx_RxEn 0x00000001 /* 1:Receive Intrrupt Enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | /* Rx_Stat bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 238 | #define Rx_Halted 0x00008000 /* Rx Halted */ |
| 239 | #define Rx_Good 0x00004000 /* Rx Good */ |
| 240 | #define Rx_RxPar 0x00002000 /* Rx Parity Error */ |
Atsushi Nemoto | 842e08b | 2008-10-28 22:30:23 +0900 | [diff] [blame] | 241 | #define Rx_TypePkt 0x00001000 /* Rx Type Packet */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 242 | #define Rx_LongErr 0x00000800 /* Rx Long Error */ |
| 243 | #define Rx_Over 0x00000400 /* Rx Overflow */ |
| 244 | #define Rx_CRCErr 0x00000200 /* Rx CRC Error */ |
| 245 | #define Rx_Align 0x00000100 /* Rx Alignment Error */ |
| 246 | #define Rx_10Stat 0x00000080 /* Rx 10Mbps Status */ |
| 247 | #define Rx_IntRx 0x00000040 /* Rx Interrupt */ |
| 248 | #define Rx_CtlRecd 0x00000020 /* Rx Control Receive */ |
Atsushi Nemoto | 842e08b | 2008-10-28 22:30:23 +0900 | [diff] [blame] | 249 | #define Rx_InLenErr 0x00000010 /* Rx In Range Frame Length Error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Atsushi Nemoto | 842e08b | 2008-10-28 22:30:23 +0900 | [diff] [blame] | 251 | #define Rx_Stat_Mask 0x0000FFF0 /* Rx All Status Mask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* Int_En bit asign -------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 254 | #define Int_NRAbtEn 0x00000800 /* 1:Non-recoverable Abort Enable */ |
| 255 | #define Int_TxCtlCmpEn 0x00000400 /* 1:Transmit Ctl Complete Enable */ |
| 256 | #define Int_DmParErrEn 0x00000200 /* 1:DMA Parity Error Enable */ |
| 257 | #define Int_DParDEn 0x00000100 /* 1:Data Parity Error Enable */ |
| 258 | #define Int_EarNotEn 0x00000080 /* 1:Early Notify Enable */ |
| 259 | #define Int_DParErrEn 0x00000040 /* 1:Detected Parity Error Enable */ |
| 260 | #define Int_SSysErrEn 0x00000020 /* 1:Signalled System Error Enable */ |
| 261 | #define Int_RMasAbtEn 0x00000010 /* 1:Received Master Abort Enable */ |
| 262 | #define Int_RTargAbtEn 0x00000008 /* 1:Received Target Abort Enable */ |
| 263 | #define Int_STargAbtEn 0x00000004 /* 1:Signalled Target Abort Enable */ |
| 264 | #define Int_BLExEn 0x00000002 /* 1:Buffer List Exhausted Enable */ |
| 265 | #define Int_FDAExEn 0x00000001 /* 1:Free Descriptor Area */ |
| 266 | /* Exhausted Enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | /* Int_Src bit asign ------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 269 | #define Int_NRabt 0x00004000 /* 1:Non Recoverable error */ |
| 270 | #define Int_DmParErrStat 0x00002000 /* 1:DMA Parity Error & Clear */ |
| 271 | #define Int_BLEx 0x00001000 /* 1:Buffer List Empty & Clear */ |
| 272 | #define Int_FDAEx 0x00000800 /* 1:FDA Empty & Clear */ |
| 273 | #define Int_IntNRAbt 0x00000400 /* 1:Non Recoverable Abort */ |
| 274 | #define Int_IntCmp 0x00000200 /* 1:MAC control packet complete */ |
| 275 | #define Int_IntExBD 0x00000100 /* 1:Interrupt Extra BD & Clear */ |
| 276 | #define Int_DmParErr 0x00000080 /* 1:DMA Parity Error & Clear */ |
| 277 | #define Int_IntEarNot 0x00000040 /* 1:Receive Data write & Clear */ |
| 278 | #define Int_SWInt 0x00000020 /* 1:Software request & Clear */ |
| 279 | #define Int_IntBLEx 0x00000010 /* 1:Buffer List Empty & Clear */ |
| 280 | #define Int_IntFDAEx 0x00000008 /* 1:FDA Empty & Clear */ |
| 281 | #define Int_IntPCI 0x00000004 /* 1:PCI controller & Clear */ |
| 282 | #define Int_IntMacRx 0x00000002 /* 1:Rx controller & Clear */ |
| 283 | #define Int_IntMacTx 0x00000001 /* 1:Tx controller & Clear */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* MD_CA bit asign --------------------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 286 | #define MD_CA_PreSup 0x00001000 /* 1:Preamble Supress */ |
| 287 | #define MD_CA_Busy 0x00000800 /* 1:Busy (Start Operation) */ |
| 288 | #define MD_CA_Wr 0x00000400 /* 1:Write 0:Read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* |
| 292 | * Descriptors |
| 293 | */ |
| 294 | |
| 295 | /* Frame descripter */ |
| 296 | struct FDesc { |
| 297 | volatile __u32 FDNext; |
| 298 | volatile __u32 FDSystem; |
| 299 | volatile __u32 FDStat; |
| 300 | volatile __u32 FDCtl; |
| 301 | }; |
| 302 | |
| 303 | /* Buffer descripter */ |
| 304 | struct BDesc { |
| 305 | volatile __u32 BuffData; |
| 306 | volatile __u32 BDCtl; |
| 307 | }; |
| 308 | |
| 309 | #define FD_ALIGN 16 |
| 310 | |
| 311 | /* Frame Descripter bit asign ---------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 312 | #define FD_FDLength_MASK 0x0000FFFF /* Length MASK */ |
| 313 | #define FD_BDCnt_MASK 0x001F0000 /* BD count MASK in FD */ |
| 314 | #define FD_FrmOpt_MASK 0x7C000000 /* Frame option MASK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #define FD_FrmOpt_BigEndian 0x40000000 /* Tx/Rx */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 316 | #define FD_FrmOpt_IntTx 0x20000000 /* Tx only */ |
| 317 | #define FD_FrmOpt_NoCRC 0x10000000 /* Tx only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | #define FD_FrmOpt_NoPadding 0x08000000 /* Tx only */ |
| 319 | #define FD_FrmOpt_Packing 0x04000000 /* Rx only */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 320 | #define FD_CownsFD 0x80000000 /* FD Controller owner bit */ |
| 321 | #define FD_Next_EOL 0x00000001 /* FD EOL indicator */ |
| 322 | #define FD_BDCnt_SHIFT 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* Buffer Descripter bit asign --------------------------------------------- */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 325 | #define BD_BuffLength_MASK 0x0000FFFF /* Recieve Data Size */ |
| 326 | #define BD_RxBDID_MASK 0x00FF0000 /* BD ID Number MASK */ |
| 327 | #define BD_RxBDSeqN_MASK 0x7F000000 /* Rx BD Sequence Number */ |
| 328 | #define BD_CownsBD 0x80000000 /* BD Controller owner bit */ |
| 329 | #define BD_RxBDID_SHIFT 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | #define BD_RxBDSeqN_SHIFT 24 |
| 331 | |
| 332 | |
| 333 | /* Some useful constants. */ |
| 334 | #undef NO_CHECK_CARRIER /* Does not check No-Carrier with TP */ |
| 335 | |
| 336 | #ifdef NO_CHECK_CARRIER |
| 337 | #define TX_CTL_CMD (Tx_EnComp | Tx_EnTxPar | Tx_EnLateColl | \ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 338 | Tx_EnExColl | Tx_EnExDefer | Tx_EnUnder | \ |
| 339 | Tx_En) /* maybe 0x7b01 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #else |
| 341 | #define TX_CTL_CMD (Tx_EnComp | Tx_EnTxPar | Tx_EnLateColl | \ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 342 | Tx_EnExColl | Tx_EnLCarr | Tx_EnExDefer | Tx_EnUnder | \ |
| 343 | Tx_En) /* maybe 0x7b01 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #endif |
Atsushi Nemoto | 297713d | 2009-08-06 04:41:45 +0000 | [diff] [blame] | 345 | /* Do not use Rx_StripCRC -- it causes trouble on BLEx/FDAEx condition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #define RX_CTL_CMD (Rx_EnGood | Rx_EnRxPar | Rx_EnLongErr | Rx_EnOver \ |
Atsushi Nemoto | 297713d | 2009-08-06 04:41:45 +0000 | [diff] [blame] | 347 | | Rx_EnCRCErr | Rx_EnAlign | Rx_RxEn) /* maybe 0x6f01 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #define INT_EN_CMD (Int_NRAbtEn | \ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 349 | Int_DmParErrEn | Int_DParDEn | Int_DParErrEn | \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | Int_SSysErrEn | Int_RMasAbtEn | Int_RTargAbtEn | \ |
| 351 | Int_STargAbtEn | \ |
| 352 | Int_BLExEn | Int_FDAExEn) /* maybe 0xb7f*/ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 353 | #define DMA_CTL_CMD DMA_BURST_SIZE |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 354 | #define HAVE_DMA_RXALIGN(lp) likely((lp)->chiptype != TC35815CF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /* Tuning parameters */ |
| 357 | #define DMA_BURST_SIZE 32 |
| 358 | #define TX_THRESHOLD 1024 |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 359 | /* used threshold with packet max byte for low pci transfer ability.*/ |
| 360 | #define TX_THRESHOLD_MAX 1536 |
| 361 | /* setting threshold max value when overrun error occured this count. */ |
| 362 | #define TX_THRESHOLD_KEEP_LIMIT 10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 364 | /* 16 + RX_BUF_NUM * 8 + RX_FD_NUM * 16 + TX_FD_NUM * 32 <= PAGE_SIZE*FD_PAGE_NUM */ |
| 365 | #ifdef TC35815_USE_PACKEDBUFFER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | #define FD_PAGE_NUM 2 |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 367 | #define RX_BUF_NUM 8 /* >= 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | #define RX_FD_NUM 250 /* >= 32 */ |
| 369 | #define TX_FD_NUM 128 |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 370 | #define RX_BUF_SIZE PAGE_SIZE |
| 371 | #else /* TC35815_USE_PACKEDBUFFER */ |
| 372 | #define FD_PAGE_NUM 4 |
| 373 | #define RX_BUF_NUM 128 /* < 256 */ |
| 374 | #define RX_FD_NUM 256 /* >= 32 */ |
| 375 | #define TX_FD_NUM 128 |
| 376 | #if RX_CTL_CMD & Rx_LongEn |
| 377 | #define RX_BUF_SIZE PAGE_SIZE |
| 378 | #elif RX_CTL_CMD & Rx_StripCRC |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 379 | #define RX_BUF_SIZE \ |
| 380 | L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + NET_IP_ALIGN) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 381 | #else |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 382 | #define RX_BUF_SIZE \ |
| 383 | L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN + NET_IP_ALIGN) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 384 | #endif |
| 385 | #endif /* TC35815_USE_PACKEDBUFFER */ |
| 386 | #define RX_FD_RESERVE (2 / 2) /* max 2 BD per RxFD */ |
| 387 | #define NAPI_WEIGHT 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | struct TxFD { |
| 390 | struct FDesc fd; |
| 391 | struct BDesc bd; |
| 392 | struct BDesc unused; |
| 393 | }; |
| 394 | |
| 395 | struct RxFD { |
| 396 | struct FDesc fd; |
| 397 | struct BDesc bd[0]; /* variable length */ |
| 398 | }; |
| 399 | |
| 400 | struct FrFD { |
| 401 | struct FDesc fd; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 402 | struct BDesc bd[RX_BUF_NUM]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 406 | #define tc_readl(addr) ioread32(addr) |
| 407 | #define tc_writel(d, addr) iowrite32(d, addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 409 | #define TC35815_TX_TIMEOUT msecs_to_jiffies(400) |
| 410 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 411 | /* Information that need to be kept for each controller. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | struct tc35815_local { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 413 | struct pci_dev *pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 415 | struct net_device *dev; |
| 416 | struct napi_struct napi; |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* statistics */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | struct { |
| 420 | int max_tx_qlen; |
| 421 | int tx_ints; |
| 422 | int rx_ints; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 423 | int tx_underrun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } lstats; |
| 425 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 426 | /* Tx control lock. This protects the transmit buffer ring |
| 427 | * state along with the "tx full" state of the driver. This |
| 428 | * means all netif_queue flow control actions are protected |
| 429 | * by this lock as well. |
| 430 | */ |
| 431 | spinlock_t lock; |
| 432 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 433 | struct mii_bus *mii_bus; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 434 | struct phy_device *phy_dev; |
| 435 | int duplex; |
| 436 | int speed; |
| 437 | int link; |
| 438 | struct work_struct restart_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | /* |
| 441 | * Transmitting: Batch Mode. |
| 442 | * 1 BD in 1 TxFD. |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 443 | * Receiving: Packing Mode. (TC35815_USE_PACKEDBUFFER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | * 1 circular FD for Free Buffer List. |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 445 | * RX_BUF_NUM BD in Free Buffer FD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | * One Free Buffer BD has PAGE_SIZE data buffer. |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 447 | * Or Non-Packing Mode. |
| 448 | * 1 circular FD for Free Buffer List. |
| 449 | * RX_BUF_NUM BD in Free Buffer FD. |
| 450 | * One Free Buffer BD has ETH_FRAME_LEN data buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 452 | void *fd_buf; /* for TxFD, RxFD, FrFD */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 453 | dma_addr_t fd_buf_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | struct TxFD *tfd_base; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 455 | unsigned int tfd_start; |
| 456 | unsigned int tfd_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | struct RxFD *rfd_base; |
| 458 | struct RxFD *rfd_limit; |
| 459 | struct RxFD *rfd_cur; |
| 460 | struct FrFD *fbl_ptr; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 461 | #ifdef TC35815_USE_PACKEDBUFFER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | unsigned char fbl_curid; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 463 | void *data_buf[RX_BUF_NUM]; /* packing */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 464 | dma_addr_t data_buf_dma[RX_BUF_NUM]; |
| 465 | struct { |
| 466 | struct sk_buff *skb; |
| 467 | dma_addr_t skb_dma; |
| 468 | } tx_skbs[TX_FD_NUM]; |
| 469 | #else |
| 470 | unsigned int fbl_count; |
| 471 | struct { |
| 472 | struct sk_buff *skb; |
| 473 | dma_addr_t skb_dma; |
| 474 | } tx_skbs[TX_FD_NUM], rx_skbs[RX_BUF_NUM]; |
| 475 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 476 | u32 msg_enable; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 477 | enum tc35815_chiptype chiptype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | }; |
| 479 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 480 | static inline dma_addr_t fd_virt_to_bus(struct tc35815_local *lp, void *virt) |
| 481 | { |
| 482 | return lp->fd_buf_dma + ((u8 *)virt - (u8 *)lp->fd_buf); |
| 483 | } |
| 484 | #ifdef DEBUG |
| 485 | static inline void *fd_bus_to_virt(struct tc35815_local *lp, dma_addr_t bus) |
| 486 | { |
| 487 | return (void *)((u8 *)lp->fd_buf + (bus - lp->fd_buf_dma)); |
| 488 | } |
| 489 | #endif |
| 490 | #ifdef TC35815_USE_PACKEDBUFFER |
| 491 | static inline void *rxbuf_bus_to_virt(struct tc35815_local *lp, dma_addr_t bus) |
| 492 | { |
| 493 | int i; |
| 494 | for (i = 0; i < RX_BUF_NUM; i++) { |
| 495 | if (bus >= lp->data_buf_dma[i] && |
| 496 | bus < lp->data_buf_dma[i] + PAGE_SIZE) |
| 497 | return (void *)((u8 *)lp->data_buf[i] + |
| 498 | (bus - lp->data_buf_dma[i])); |
| 499 | } |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | #define TC35815_DMA_SYNC_ONDEMAND |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 504 | static void *alloc_rxbuf_page(struct pci_dev *hwdev, dma_addr_t *dma_handle) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 505 | { |
| 506 | #ifdef TC35815_DMA_SYNC_ONDEMAND |
| 507 | void *buf; |
| 508 | /* pci_map + pci_dma_sync will be more effective than |
| 509 | * pci_alloc_consistent on some archs. */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 510 | buf = (void *)__get_free_page(GFP_ATOMIC); |
| 511 | if (!buf) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 512 | return NULL; |
| 513 | *dma_handle = pci_map_single(hwdev, buf, PAGE_SIZE, |
| 514 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 515 | if (pci_dma_mapping_error(hwdev, *dma_handle)) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 516 | free_page((unsigned long)buf); |
| 517 | return NULL; |
| 518 | } |
| 519 | return buf; |
| 520 | #else |
| 521 | return pci_alloc_consistent(hwdev, PAGE_SIZE, dma_handle); |
| 522 | #endif |
| 523 | } |
| 524 | |
| 525 | static void free_rxbuf_page(struct pci_dev *hwdev, void *buf, dma_addr_t dma_handle) |
| 526 | { |
| 527 | #ifdef TC35815_DMA_SYNC_ONDEMAND |
| 528 | pci_unmap_single(hwdev, dma_handle, PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 529 | free_page((unsigned long)buf); |
| 530 | #else |
| 531 | pci_free_consistent(hwdev, PAGE_SIZE, buf, dma_handle); |
| 532 | #endif |
| 533 | } |
| 534 | #else /* TC35815_USE_PACKEDBUFFER */ |
| 535 | static struct sk_buff *alloc_rxbuf_skb(struct net_device *dev, |
| 536 | struct pci_dev *hwdev, |
| 537 | dma_addr_t *dma_handle) |
| 538 | { |
| 539 | struct sk_buff *skb; |
| 540 | skb = dev_alloc_skb(RX_BUF_SIZE); |
| 541 | if (!skb) |
| 542 | return NULL; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 543 | *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE, |
| 544 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 545 | if (pci_dma_mapping_error(hwdev, *dma_handle)) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 546 | dev_kfree_skb_any(skb); |
| 547 | return NULL; |
| 548 | } |
| 549 | skb_reserve(skb, 2); /* make IP header 4byte aligned */ |
| 550 | return skb; |
| 551 | } |
| 552 | |
| 553 | static void free_rxbuf_skb(struct pci_dev *hwdev, struct sk_buff *skb, dma_addr_t dma_handle) |
| 554 | { |
| 555 | pci_unmap_single(hwdev, dma_handle, RX_BUF_SIZE, |
| 556 | PCI_DMA_FROMDEVICE); |
| 557 | dev_kfree_skb_any(skb); |
| 558 | } |
| 559 | #endif /* TC35815_USE_PACKEDBUFFER */ |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | /* Index to functions, as function prototypes. */ |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | static int tc35815_open(struct net_device *dev); |
| 564 | static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 565 | static irqreturn_t tc35815_interrupt(int irq, void *dev_id); |
| 566 | #ifdef TC35815_NAPI |
| 567 | static int tc35815_rx(struct net_device *dev, int limit); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 568 | static int tc35815_poll(struct napi_struct *napi, int budget); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 569 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | static void tc35815_rx(struct net_device *dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 571 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | static void tc35815_txdone(struct net_device *dev); |
| 573 | static int tc35815_close(struct net_device *dev); |
| 574 | static struct net_device_stats *tc35815_get_stats(struct net_device *dev); |
| 575 | static void tc35815_set_multicast_list(struct net_device *dev); |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 576 | static void tc35815_tx_timeout(struct net_device *dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 577 | static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
| 578 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 579 | static void tc35815_poll_controller(struct net_device *dev); |
| 580 | #endif |
| 581 | static const struct ethtool_ops tc35815_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 583 | /* Example routines you must write ;->. */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 584 | static void tc35815_chip_reset(struct net_device *dev); |
| 585 | static void tc35815_chip_init(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 587 | #ifdef DEBUG |
| 588 | static void panic_queues(struct net_device *dev); |
| 589 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 591 | static void tc35815_restart_work(struct work_struct *work); |
| 592 | |
| 593 | static int tc_mdio_read(struct mii_bus *bus, int mii_id, int regnum) |
| 594 | { |
| 595 | struct net_device *dev = bus->priv; |
| 596 | struct tc35815_regs __iomem *tr = |
| 597 | (struct tc35815_regs __iomem *)dev->base_addr; |
Atsushi Nemoto | c60a5cf | 2009-08-06 04:41:47 +0000 | [diff] [blame] | 598 | unsigned long timeout = jiffies + HZ; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 599 | |
| 600 | tc_writel(MD_CA_Busy | (mii_id << 5) | (regnum & 0x1f), &tr->MD_CA); |
Atsushi Nemoto | c60a5cf | 2009-08-06 04:41:47 +0000 | [diff] [blame] | 601 | udelay(12); /* it takes 32 x 400ns at least */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 602 | while (tc_readl(&tr->MD_CA) & MD_CA_Busy) { |
| 603 | if (time_after(jiffies, timeout)) |
| 604 | return -EIO; |
| 605 | cpu_relax(); |
| 606 | } |
| 607 | return tc_readl(&tr->MD_Data) & 0xffff; |
| 608 | } |
| 609 | |
| 610 | static int tc_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 val) |
| 611 | { |
| 612 | struct net_device *dev = bus->priv; |
| 613 | struct tc35815_regs __iomem *tr = |
| 614 | (struct tc35815_regs __iomem *)dev->base_addr; |
Atsushi Nemoto | c60a5cf | 2009-08-06 04:41:47 +0000 | [diff] [blame] | 615 | unsigned long timeout = jiffies + HZ; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 616 | |
| 617 | tc_writel(val, &tr->MD_Data); |
| 618 | tc_writel(MD_CA_Busy | MD_CA_Wr | (mii_id << 5) | (regnum & 0x1f), |
| 619 | &tr->MD_CA); |
Atsushi Nemoto | c60a5cf | 2009-08-06 04:41:47 +0000 | [diff] [blame] | 620 | udelay(12); /* it takes 32 x 400ns at least */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 621 | while (tc_readl(&tr->MD_CA) & MD_CA_Busy) { |
| 622 | if (time_after(jiffies, timeout)) |
| 623 | return -EIO; |
| 624 | cpu_relax(); |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static void tc_handle_link_change(struct net_device *dev) |
| 630 | { |
| 631 | struct tc35815_local *lp = netdev_priv(dev); |
| 632 | struct phy_device *phydev = lp->phy_dev; |
| 633 | unsigned long flags; |
| 634 | int status_change = 0; |
| 635 | |
| 636 | spin_lock_irqsave(&lp->lock, flags); |
| 637 | if (phydev->link && |
| 638 | (lp->speed != phydev->speed || lp->duplex != phydev->duplex)) { |
| 639 | struct tc35815_regs __iomem *tr = |
| 640 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 641 | u32 reg; |
| 642 | |
| 643 | reg = tc_readl(&tr->MAC_Ctl); |
| 644 | reg |= MAC_HaltReq; |
| 645 | tc_writel(reg, &tr->MAC_Ctl); |
| 646 | if (phydev->duplex == DUPLEX_FULL) |
| 647 | reg |= MAC_FullDup; |
| 648 | else |
| 649 | reg &= ~MAC_FullDup; |
| 650 | tc_writel(reg, &tr->MAC_Ctl); |
| 651 | reg &= ~MAC_HaltReq; |
| 652 | tc_writel(reg, &tr->MAC_Ctl); |
| 653 | |
| 654 | /* |
| 655 | * TX4939 PCFG.SPEEDn bit will be changed on |
| 656 | * NETDEV_CHANGE event. |
| 657 | */ |
| 658 | |
| 659 | #if !defined(NO_CHECK_CARRIER) && defined(WORKAROUND_LOSTCAR) |
| 660 | /* |
| 661 | * WORKAROUND: enable LostCrS only if half duplex |
| 662 | * operation. |
| 663 | * (TX4939 does not have EnLCarr) |
| 664 | */ |
| 665 | if (phydev->duplex == DUPLEX_HALF && |
| 666 | lp->chiptype != TC35815_TX4939) |
| 667 | tc_writel(tc_readl(&tr->Tx_Ctl) | Tx_EnLCarr, |
| 668 | &tr->Tx_Ctl); |
| 669 | #endif |
| 670 | |
| 671 | lp->speed = phydev->speed; |
| 672 | lp->duplex = phydev->duplex; |
| 673 | status_change = 1; |
| 674 | } |
| 675 | |
| 676 | if (phydev->link != lp->link) { |
| 677 | if (phydev->link) { |
| 678 | #ifdef WORKAROUND_100HALF_PROMISC |
| 679 | /* delayed promiscuous enabling */ |
| 680 | if (dev->flags & IFF_PROMISC) |
| 681 | tc35815_set_multicast_list(dev); |
| 682 | #endif |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 683 | } else { |
| 684 | lp->speed = 0; |
| 685 | lp->duplex = -1; |
| 686 | } |
| 687 | lp->link = phydev->link; |
| 688 | |
| 689 | status_change = 1; |
| 690 | } |
| 691 | spin_unlock_irqrestore(&lp->lock, flags); |
| 692 | |
| 693 | if (status_change && netif_msg_link(lp)) { |
| 694 | phy_print_status(phydev); |
Joe Perches | 7290383 | 2009-05-15 07:59:42 +0000 | [diff] [blame] | 695 | pr_debug("%s: MII BMCR %04x BMSR %04x LPA %04x\n", |
| 696 | dev->name, |
| 697 | phy_read(phydev, MII_BMCR), |
| 698 | phy_read(phydev, MII_BMSR), |
| 699 | phy_read(phydev, MII_LPA)); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | static int tc_mii_probe(struct net_device *dev) |
| 704 | { |
| 705 | struct tc35815_local *lp = netdev_priv(dev); |
| 706 | struct phy_device *phydev = NULL; |
| 707 | int phy_addr; |
| 708 | u32 dropmask; |
| 709 | |
| 710 | /* find the first phy */ |
| 711 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 712 | if (lp->mii_bus->phy_map[phy_addr]) { |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 713 | if (phydev) { |
| 714 | printk(KERN_ERR "%s: multiple PHYs found\n", |
| 715 | dev->name); |
| 716 | return -EINVAL; |
| 717 | } |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 718 | phydev = lp->mii_bus->phy_map[phy_addr]; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | if (!phydev) { |
| 724 | printk(KERN_ERR "%s: no PHY found\n", dev->name); |
| 725 | return -ENODEV; |
| 726 | } |
| 727 | |
| 728 | /* attach the mac to the phy */ |
Kay Sievers | db1d7bf | 2009-01-26 21:12:58 -0800 | [diff] [blame] | 729 | phydev = phy_connect(dev, dev_name(&phydev->dev), |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 730 | &tc_handle_link_change, 0, |
| 731 | lp->chiptype == TC35815_TX4939 ? |
| 732 | PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII); |
| 733 | if (IS_ERR(phydev)) { |
| 734 | printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); |
| 735 | return PTR_ERR(phydev); |
| 736 | } |
| 737 | printk(KERN_INFO "%s: attached PHY driver [%s] " |
| 738 | "(mii_bus:phy_addr=%s, id=%x)\n", |
Kay Sievers | db1d7bf | 2009-01-26 21:12:58 -0800 | [diff] [blame] | 739 | dev->name, phydev->drv->name, dev_name(&phydev->dev), |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 740 | phydev->phy_id); |
| 741 | |
| 742 | /* mask with MAC supported features */ |
| 743 | phydev->supported &= PHY_BASIC_FEATURES; |
| 744 | dropmask = 0; |
| 745 | if (options.speed == 10) |
| 746 | dropmask |= SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full; |
| 747 | else if (options.speed == 100) |
| 748 | dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full; |
| 749 | if (options.duplex == 1) |
| 750 | dropmask |= SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Full; |
| 751 | else if (options.duplex == 2) |
| 752 | dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_100baseT_Half; |
| 753 | phydev->supported &= ~dropmask; |
| 754 | phydev->advertising = phydev->supported; |
| 755 | |
| 756 | lp->link = 0; |
| 757 | lp->speed = 0; |
| 758 | lp->duplex = -1; |
| 759 | lp->phy_dev = phydev; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int tc_mii_init(struct net_device *dev) |
| 765 | { |
| 766 | struct tc35815_local *lp = netdev_priv(dev); |
| 767 | int err; |
| 768 | int i; |
| 769 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 770 | lp->mii_bus = mdiobus_alloc(); |
| 771 | if (lp->mii_bus == NULL) { |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 772 | err = -ENOMEM; |
| 773 | goto err_out; |
| 774 | } |
| 775 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 776 | lp->mii_bus->name = "tc35815_mii_bus"; |
| 777 | lp->mii_bus->read = tc_mdio_read; |
| 778 | lp->mii_bus->write = tc_mdio_write; |
| 779 | snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "%x", |
| 780 | (lp->pci_dev->bus->number << 8) | lp->pci_dev->devfn); |
| 781 | lp->mii_bus->priv = dev; |
| 782 | lp->mii_bus->parent = &lp->pci_dev->dev; |
| 783 | lp->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); |
| 784 | if (!lp->mii_bus->irq) { |
| 785 | err = -ENOMEM; |
| 786 | goto err_out_free_mii_bus; |
| 787 | } |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 788 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 789 | for (i = 0; i < PHY_MAX_ADDR; i++) |
| 790 | lp->mii_bus->irq[i] = PHY_POLL; |
| 791 | |
| 792 | err = mdiobus_register(lp->mii_bus); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 793 | if (err) |
| 794 | goto err_out_free_mdio_irq; |
| 795 | err = tc_mii_probe(dev); |
| 796 | if (err) |
| 797 | goto err_out_unregister_bus; |
| 798 | return 0; |
| 799 | |
| 800 | err_out_unregister_bus: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 801 | mdiobus_unregister(lp->mii_bus); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 802 | err_out_free_mdio_irq: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 803 | kfree(lp->mii_bus->irq); |
Adrian Bunk | 51cf756 | 2008-10-12 21:01:53 -0700 | [diff] [blame] | 804 | err_out_free_mii_bus: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 805 | mdiobus_free(lp->mii_bus); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 806 | err_out: |
| 807 | return err; |
| 808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 810 | #ifdef CONFIG_CPU_TX49XX |
| 811 | /* |
| 812 | * Find a platform_device providing a MAC address. The platform code |
| 813 | * should provide a "tc35815-mac" device with a MAC address in its |
| 814 | * platform_data. |
| 815 | */ |
| 816 | static int __devinit tc35815_mac_match(struct device *dev, void *data) |
| 817 | { |
| 818 | struct platform_device *plat_dev = to_platform_device(dev); |
| 819 | struct pci_dev *pci_dev = data; |
Atsushi Nemoto | 06675e6 | 2008-01-19 01:15:52 +0900 | [diff] [blame] | 820 | unsigned int id = pci_dev->irq; |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 821 | return !strcmp(plat_dev->name, "tc35815-mac") && plat_dev->id == id; |
| 822 | } |
| 823 | |
| 824 | static int __devinit tc35815_read_plat_dev_addr(struct net_device *dev) |
| 825 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 826 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 827 | struct device *pd = bus_find_device(&platform_bus_type, NULL, |
| 828 | lp->pci_dev, tc35815_mac_match); |
| 829 | if (pd) { |
| 830 | if (pd->platform_data) |
| 831 | memcpy(dev->dev_addr, pd->platform_data, ETH_ALEN); |
| 832 | put_device(pd); |
| 833 | return is_valid_ether_addr(dev->dev_addr) ? 0 : -ENODEV; |
| 834 | } |
| 835 | return -ENODEV; |
| 836 | } |
| 837 | #else |
Yoichi Yuasa | 308a906 | 2007-07-18 11:13:42 +0900 | [diff] [blame] | 838 | static int __devinit tc35815_read_plat_dev_addr(struct net_device *dev) |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 839 | { |
| 840 | return -ENODEV; |
| 841 | } |
| 842 | #endif |
| 843 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 844 | static int __devinit tc35815_init_dev_addr(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 846 | struct tc35815_regs __iomem *tr = |
| 847 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 848 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | while (tc_readl(&tr->PROM_Ctl) & PROM_Busy) |
| 851 | ; |
| 852 | for (i = 0; i < 6; i += 2) { |
| 853 | unsigned short data; |
| 854 | tc_writel(PROM_Busy | PROM_Read | (i / 2 + 2), &tr->PROM_Ctl); |
| 855 | while (tc_readl(&tr->PROM_Ctl) & PROM_Busy) |
| 856 | ; |
| 857 | data = tc_readl(&tr->PROM_Data); |
| 858 | dev->dev_addr[i] = data & 0xff; |
| 859 | dev->dev_addr[i+1] = data >> 8; |
| 860 | } |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 861 | if (!is_valid_ether_addr(dev->dev_addr)) |
| 862 | return tc35815_read_plat_dev_addr(dev); |
| 863 | return 0; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Alexander Beregalov | 5a1c28b | 2009-04-11 07:38:54 +0000 | [diff] [blame] | 866 | static const struct net_device_ops tc35815_netdev_ops = { |
| 867 | .ndo_open = tc35815_open, |
| 868 | .ndo_stop = tc35815_close, |
| 869 | .ndo_start_xmit = tc35815_send_packet, |
| 870 | .ndo_get_stats = tc35815_get_stats, |
| 871 | .ndo_set_multicast_list = tc35815_set_multicast_list, |
| 872 | .ndo_tx_timeout = tc35815_tx_timeout, |
| 873 | .ndo_do_ioctl = tc35815_ioctl, |
| 874 | .ndo_validate_addr = eth_validate_addr, |
| 875 | .ndo_change_mtu = eth_change_mtu, |
| 876 | .ndo_set_mac_address = eth_mac_addr, |
| 877 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 878 | .ndo_poll_controller = tc35815_poll_controller, |
| 879 | #endif |
| 880 | }; |
| 881 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 882 | static int __devinit tc35815_init_one(struct pci_dev *pdev, |
| 883 | const struct pci_device_id *ent) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 884 | { |
| 885 | void __iomem *ioaddr = NULL; |
| 886 | struct net_device *dev; |
| 887 | struct tc35815_local *lp; |
| 888 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 890 | static int printed_version; |
| 891 | if (!printed_version++) { |
| 892 | printk(version); |
| 893 | dev_printk(KERN_DEBUG, &pdev->dev, |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 894 | "speed:%d duplex:%d\n", |
| 895 | options.speed, options.duplex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 898 | if (!pdev->irq) { |
| 899 | dev_warn(&pdev->dev, "no IRQ assigned.\n"); |
| 900 | return -ENODEV; |
| 901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 903 | /* dev zeroed in alloc_etherdev */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 904 | dev = alloc_etherdev(sizeof(*lp)); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 905 | if (dev == NULL) { |
| 906 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
| 907 | return -ENOMEM; |
| 908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | SET_NETDEV_DEV(dev, &pdev->dev); |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 910 | lp = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 911 | lp->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 913 | /* enable device (incl. PCI PM wakeup), and bus-mastering */ |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 914 | rc = pcim_enable_device(pdev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 915 | if (rc) |
| 916 | goto err_out; |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 917 | rc = pcim_iomap_regions(pdev, 1 << 1, MODNAME); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 918 | if (rc) |
| 919 | goto err_out; |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 920 | pci_set_master(pdev); |
| 921 | ioaddr = pcim_iomap_table(pdev)[1]; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 922 | |
| 923 | /* Initialize the device structure. */ |
Alexander Beregalov | 5a1c28b | 2009-04-11 07:38:54 +0000 | [diff] [blame] | 924 | dev->netdev_ops = &tc35815_netdev_ops; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 925 | dev->ethtool_ops = &tc35815_ethtool_ops; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 926 | dev->watchdog_timeo = TC35815_TX_TIMEOUT; |
| 927 | #ifdef TC35815_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 928 | netif_napi_add(dev, &lp->napi, tc35815_poll, NAPI_WEIGHT); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 929 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 930 | |
| 931 | dev->irq = pdev->irq; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 932 | dev->base_addr = (unsigned long)ioaddr; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 933 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 934 | INIT_WORK(&lp->restart_work, tc35815_restart_work); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 935 | spin_lock_init(&lp->lock); |
| 936 | lp->pci_dev = pdev; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 937 | lp->chiptype = ent->driver_data; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 938 | |
| 939 | lp->msg_enable = NETIF_MSG_TX_ERR | NETIF_MSG_HW | NETIF_MSG_DRV | NETIF_MSG_LINK; |
| 940 | pci_set_drvdata(pdev, dev); |
| 941 | |
| 942 | /* Soft reset the chip. */ |
| 943 | tc35815_chip_reset(dev); |
| 944 | |
| 945 | /* Retrieve the ethernet address. */ |
Atsushi Nemoto | bd43da8 | 2007-06-29 22:34:53 +0900 | [diff] [blame] | 946 | if (tc35815_init_dev_addr(dev)) { |
| 947 | dev_warn(&pdev->dev, "not valid ether addr\n"); |
| 948 | random_ether_addr(dev->dev_addr); |
| 949 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 950 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 951 | rc = register_netdev(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 952 | if (rc) |
Atsushi Nemoto | 22adf7e | 2008-04-11 00:24:45 +0900 | [diff] [blame] | 953 | goto err_out; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 954 | |
| 955 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 956 | printk(KERN_INFO "%s: %s at 0x%lx, %pM, IRQ %d\n", |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 957 | dev->name, |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 958 | chip_info[ent->driver_data].name, |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 959 | dev->base_addr, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 960 | dev->dev_addr, |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 961 | dev->irq); |
| 962 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 963 | rc = tc_mii_init(dev); |
| 964 | if (rc) |
| 965 | goto err_out_unregister; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | return 0; |
| 968 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 969 | err_out_unregister: |
| 970 | unregister_netdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | err_out: |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 972 | free_netdev(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 973 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 977 | static void __devexit tc35815_remove_one(struct pci_dev *pdev) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 978 | { |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 979 | struct net_device *dev = pci_get_drvdata(pdev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 980 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 981 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 982 | phy_disconnect(lp->phy_dev); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 983 | mdiobus_unregister(lp->mii_bus); |
| 984 | kfree(lp->mii_bus->irq); |
| 985 | mdiobus_free(lp->mii_bus); |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 986 | unregister_netdev(dev); |
| 987 | free_netdev(dev); |
| 988 | pci_set_drvdata(pdev, NULL); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 989 | } |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | static int |
| 992 | tc35815_init_queues(struct net_device *dev) |
| 993 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 994 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | int i; |
| 996 | unsigned long fd_addr; |
| 997 | |
| 998 | if (!lp->fd_buf) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 999 | BUG_ON(sizeof(struct FDesc) + |
| 1000 | sizeof(struct BDesc) * RX_BUF_NUM + |
| 1001 | sizeof(struct FDesc) * RX_FD_NUM + |
| 1002 | sizeof(struct TxFD) * TX_FD_NUM > |
| 1003 | PAGE_SIZE * FD_PAGE_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1005 | lp->fd_buf = pci_alloc_consistent(lp->pci_dev, |
| 1006 | PAGE_SIZE * FD_PAGE_NUM, |
| 1007 | &lp->fd_buf_dma); |
| 1008 | if (!lp->fd_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return -ENOMEM; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1010 | for (i = 0; i < RX_BUF_NUM; i++) { |
| 1011 | #ifdef TC35815_USE_PACKEDBUFFER |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1012 | lp->data_buf[i] = |
| 1013 | alloc_rxbuf_page(lp->pci_dev, |
| 1014 | &lp->data_buf_dma[i]); |
| 1015 | if (!lp->data_buf[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | while (--i >= 0) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1017 | free_rxbuf_page(lp->pci_dev, |
| 1018 | lp->data_buf[i], |
| 1019 | lp->data_buf_dma[i]); |
| 1020 | lp->data_buf[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1022 | pci_free_consistent(lp->pci_dev, |
| 1023 | PAGE_SIZE * FD_PAGE_NUM, |
| 1024 | lp->fd_buf, |
| 1025 | lp->fd_buf_dma); |
| 1026 | lp->fd_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return -ENOMEM; |
| 1028 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1029 | #else |
| 1030 | lp->rx_skbs[i].skb = |
| 1031 | alloc_rxbuf_skb(dev, lp->pci_dev, |
| 1032 | &lp->rx_skbs[i].skb_dma); |
| 1033 | if (!lp->rx_skbs[i].skb) { |
| 1034 | while (--i >= 0) { |
| 1035 | free_rxbuf_skb(lp->pci_dev, |
| 1036 | lp->rx_skbs[i].skb, |
| 1037 | lp->rx_skbs[i].skb_dma); |
| 1038 | lp->rx_skbs[i].skb = NULL; |
| 1039 | } |
| 1040 | pci_free_consistent(lp->pci_dev, |
| 1041 | PAGE_SIZE * FD_PAGE_NUM, |
| 1042 | lp->fd_buf, |
| 1043 | lp->fd_buf_dma); |
| 1044 | lp->fd_buf = NULL; |
| 1045 | return -ENOMEM; |
| 1046 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | #endif |
| 1048 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1049 | printk(KERN_DEBUG "%s: FD buf %p DataBuf", |
| 1050 | dev->name, lp->fd_buf); |
| 1051 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1052 | printk(" DataBuf"); |
| 1053 | for (i = 0; i < RX_BUF_NUM; i++) |
| 1054 | printk(" %p", lp->data_buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1056 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } else { |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1058 | for (i = 0; i < FD_PAGE_NUM; i++) |
| 1059 | clear_page((void *)((unsigned long)lp->fd_buf + |
| 1060 | i * PAGE_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | fd_addr = (unsigned long)lp->fd_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
| 1064 | /* Free Descriptors (for Receive) */ |
| 1065 | lp->rfd_base = (struct RxFD *)fd_addr; |
| 1066 | fd_addr += sizeof(struct RxFD) * RX_FD_NUM; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1067 | for (i = 0; i < RX_FD_NUM; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | lp->rfd_base[i].fd.FDCtl = cpu_to_le32(FD_CownsFD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | lp->rfd_cur = lp->rfd_base; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1070 | lp->rfd_limit = (struct RxFD *)fd_addr - (RX_FD_RESERVE + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | /* Transmit Descriptors */ |
| 1073 | lp->tfd_base = (struct TxFD *)fd_addr; |
| 1074 | fd_addr += sizeof(struct TxFD) * TX_FD_NUM; |
| 1075 | for (i = 0; i < TX_FD_NUM; i++) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1076 | lp->tfd_base[i].fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, &lp->tfd_base[i+1])); |
| 1077 | lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | lp->tfd_base[i].fd.FDCtl = cpu_to_le32(0); |
| 1079 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1080 | lp->tfd_base[TX_FD_NUM-1].fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, &lp->tfd_base[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | lp->tfd_start = 0; |
| 1082 | lp->tfd_end = 0; |
| 1083 | |
| 1084 | /* Buffer List (for Receive) */ |
| 1085 | lp->fbl_ptr = (struct FrFD *)fd_addr; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1086 | lp->fbl_ptr->fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, lp->fbl_ptr)); |
| 1087 | lp->fbl_ptr->fd.FDCtl = cpu_to_le32(RX_BUF_NUM | FD_CownsFD); |
| 1088 | #ifndef TC35815_USE_PACKEDBUFFER |
| 1089 | /* |
| 1090 | * move all allocated skbs to head of rx_skbs[] array. |
| 1091 | * fbl_count mighe not be RX_BUF_NUM if alloc_rxbuf_skb() in |
| 1092 | * tc35815_rx() had failed. |
| 1093 | */ |
| 1094 | lp->fbl_count = 0; |
| 1095 | for (i = 0; i < RX_BUF_NUM; i++) { |
| 1096 | if (lp->rx_skbs[i].skb) { |
| 1097 | if (i != lp->fbl_count) { |
| 1098 | lp->rx_skbs[lp->fbl_count].skb = |
| 1099 | lp->rx_skbs[i].skb; |
| 1100 | lp->rx_skbs[lp->fbl_count].skb_dma = |
| 1101 | lp->rx_skbs[i].skb_dma; |
| 1102 | } |
| 1103 | lp->fbl_count++; |
| 1104 | } |
| 1105 | } |
| 1106 | #endif |
| 1107 | for (i = 0; i < RX_BUF_NUM; i++) { |
| 1108 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1109 | lp->fbl_ptr->bd[i].BuffData = cpu_to_le32(lp->data_buf_dma[i]); |
| 1110 | #else |
| 1111 | if (i >= lp->fbl_count) { |
| 1112 | lp->fbl_ptr->bd[i].BuffData = 0; |
| 1113 | lp->fbl_ptr->bd[i].BDCtl = 0; |
| 1114 | continue; |
| 1115 | } |
| 1116 | lp->fbl_ptr->bd[i].BuffData = |
| 1117 | cpu_to_le32(lp->rx_skbs[i].skb_dma); |
| 1118 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | /* BDID is index of FrFD.bd[] */ |
| 1120 | lp->fbl_ptr->bd[i].BDCtl = |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1121 | cpu_to_le32(BD_CownsBD | (i << BD_RxBDID_SHIFT) | |
| 1122 | RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1124 | #ifdef TC35815_USE_PACKEDBUFFER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | lp->fbl_curid = 0; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1126 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1128 | printk(KERN_DEBUG "%s: TxFD %p RxFD %p FrFD %p\n", |
| 1129 | dev->name, lp->tfd_base, lp->rfd_base, lp->fbl_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | return 0; |
| 1131 | } |
| 1132 | |
| 1133 | static void |
| 1134 | tc35815_clear_queues(struct net_device *dev) |
| 1135 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1136 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | int i; |
| 1138 | |
| 1139 | for (i = 0; i < TX_FD_NUM; i++) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1140 | u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem); |
| 1141 | struct sk_buff *skb = |
| 1142 | fdsystem != 0xffffffff ? |
| 1143 | lp->tx_skbs[fdsystem].skb : NULL; |
| 1144 | #ifdef DEBUG |
| 1145 | if (lp->tx_skbs[i].skb != skb) { |
| 1146 | printk("%s: tx_skbs mismatch(%d).\n", dev->name, i); |
| 1147 | panic_queues(dev); |
| 1148 | } |
| 1149 | #else |
| 1150 | BUG_ON(lp->tx_skbs[i].skb != skb); |
| 1151 | #endif |
| 1152 | if (skb) { |
| 1153 | pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE); |
| 1154 | lp->tx_skbs[i].skb = NULL; |
| 1155 | lp->tx_skbs[i].skb_dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | dev_kfree_skb_any(skb); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1157 | } |
| 1158 | lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | tc35815_init_queues(dev); |
| 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | tc35815_free_queues(struct net_device *dev) |
| 1166 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1167 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | int i; |
| 1169 | |
| 1170 | if (lp->tfd_base) { |
| 1171 | for (i = 0; i < TX_FD_NUM; i++) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1172 | u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem); |
| 1173 | struct sk_buff *skb = |
| 1174 | fdsystem != 0xffffffff ? |
| 1175 | lp->tx_skbs[fdsystem].skb : NULL; |
| 1176 | #ifdef DEBUG |
| 1177 | if (lp->tx_skbs[i].skb != skb) { |
| 1178 | printk("%s: tx_skbs mismatch(%d).\n", dev->name, i); |
| 1179 | panic_queues(dev); |
| 1180 | } |
| 1181 | #else |
| 1182 | BUG_ON(lp->tx_skbs[i].skb != skb); |
| 1183 | #endif |
| 1184 | if (skb) { |
| 1185 | dev_kfree_skb(skb); |
| 1186 | pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE); |
| 1187 | lp->tx_skbs[i].skb = NULL; |
| 1188 | lp->tx_skbs[i].skb_dma = 0; |
| 1189 | } |
| 1190 | lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | lp->rfd_base = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | lp->rfd_limit = NULL; |
| 1196 | lp->rfd_cur = NULL; |
| 1197 | lp->fbl_ptr = NULL; |
| 1198 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1199 | for (i = 0; i < RX_BUF_NUM; i++) { |
| 1200 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1201 | if (lp->data_buf[i]) { |
| 1202 | free_rxbuf_page(lp->pci_dev, |
| 1203 | lp->data_buf[i], lp->data_buf_dma[i]); |
| 1204 | lp->data_buf[i] = NULL; |
| 1205 | } |
| 1206 | #else |
| 1207 | if (lp->rx_skbs[i].skb) { |
| 1208 | free_rxbuf_skb(lp->pci_dev, lp->rx_skbs[i].skb, |
| 1209 | lp->rx_skbs[i].skb_dma); |
| 1210 | lp->rx_skbs[i].skb = NULL; |
| 1211 | } |
| 1212 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1214 | if (lp->fd_buf) { |
| 1215 | pci_free_consistent(lp->pci_dev, PAGE_SIZE * FD_PAGE_NUM, |
| 1216 | lp->fd_buf, lp->fd_buf_dma); |
| 1217 | lp->fd_buf = NULL; |
| 1218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | static void |
| 1222 | dump_txfd(struct TxFD *fd) |
| 1223 | { |
| 1224 | printk("TxFD(%p): %08x %08x %08x %08x\n", fd, |
| 1225 | le32_to_cpu(fd->fd.FDNext), |
| 1226 | le32_to_cpu(fd->fd.FDSystem), |
| 1227 | le32_to_cpu(fd->fd.FDStat), |
| 1228 | le32_to_cpu(fd->fd.FDCtl)); |
| 1229 | printk("BD: "); |
| 1230 | printk(" %08x %08x", |
| 1231 | le32_to_cpu(fd->bd.BuffData), |
| 1232 | le32_to_cpu(fd->bd.BDCtl)); |
| 1233 | printk("\n"); |
| 1234 | } |
| 1235 | |
| 1236 | static int |
| 1237 | dump_rxfd(struct RxFD *fd) |
| 1238 | { |
| 1239 | int i, bd_count = (le32_to_cpu(fd->fd.FDCtl) & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT; |
| 1240 | if (bd_count > 8) |
| 1241 | bd_count = 8; |
| 1242 | printk("RxFD(%p): %08x %08x %08x %08x\n", fd, |
| 1243 | le32_to_cpu(fd->fd.FDNext), |
| 1244 | le32_to_cpu(fd->fd.FDSystem), |
| 1245 | le32_to_cpu(fd->fd.FDStat), |
| 1246 | le32_to_cpu(fd->fd.FDCtl)); |
| 1247 | if (le32_to_cpu(fd->fd.FDCtl) & FD_CownsFD) |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1248 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | printk("BD: "); |
| 1250 | for (i = 0; i < bd_count; i++) |
| 1251 | printk(" %08x %08x", |
| 1252 | le32_to_cpu(fd->bd[i].BuffData), |
| 1253 | le32_to_cpu(fd->bd[i].BDCtl)); |
| 1254 | printk("\n"); |
| 1255 | return bd_count; |
| 1256 | } |
| 1257 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1258 | #if defined(DEBUG) || defined(TC35815_USE_PACKEDBUFFER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | static void |
| 1260 | dump_frfd(struct FrFD *fd) |
| 1261 | { |
| 1262 | int i; |
| 1263 | printk("FrFD(%p): %08x %08x %08x %08x\n", fd, |
| 1264 | le32_to_cpu(fd->fd.FDNext), |
| 1265 | le32_to_cpu(fd->fd.FDSystem), |
| 1266 | le32_to_cpu(fd->fd.FDStat), |
| 1267 | le32_to_cpu(fd->fd.FDCtl)); |
| 1268 | printk("BD: "); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1269 | for (i = 0; i < RX_BUF_NUM; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | printk(" %08x %08x", |
| 1271 | le32_to_cpu(fd->bd[i].BuffData), |
| 1272 | le32_to_cpu(fd->bd[i].BDCtl)); |
| 1273 | printk("\n"); |
| 1274 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1275 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1277 | #ifdef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | static void |
| 1279 | panic_queues(struct net_device *dev) |
| 1280 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1281 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | int i; |
| 1283 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1284 | printk("TxFD base %p, start %u, end %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | lp->tfd_base, lp->tfd_start, lp->tfd_end); |
| 1286 | printk("RxFD base %p limit %p cur %p\n", |
| 1287 | lp->rfd_base, lp->rfd_limit, lp->rfd_cur); |
| 1288 | printk("FrFD %p\n", lp->fbl_ptr); |
| 1289 | for (i = 0; i < TX_FD_NUM; i++) |
| 1290 | dump_txfd(&lp->tfd_base[i]); |
| 1291 | for (i = 0; i < RX_FD_NUM; i++) { |
| 1292 | int bd_count = dump_rxfd(&lp->rfd_base[i]); |
| 1293 | i += (bd_count + 1) / 2; /* skip BDs */ |
| 1294 | } |
| 1295 | dump_frfd(lp->fbl_ptr); |
| 1296 | panic("%s: Illegal queue state.", dev->name); |
| 1297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | #endif |
| 1299 | |
Atsushi Nemoto | 958eb80 | 2008-04-11 00:24:24 +0900 | [diff] [blame] | 1300 | static void print_eth(const u8 *add) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | { |
Atsushi Nemoto | 958eb80 | 2008-04-11 00:24:24 +0900 | [diff] [blame] | 1302 | printk(KERN_DEBUG "print_eth(%p)\n", add); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1303 | printk(KERN_DEBUG " %pM => %pM : %02x%02x\n", |
| 1304 | add + 6, add, add[12], add[13]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1307 | static int tc35815_tx_full(struct net_device *dev) |
| 1308 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1309 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1310 | return ((lp->tfd_start + 1) % TX_FD_NUM == lp->tfd_end); |
| 1311 | } |
| 1312 | |
| 1313 | static void tc35815_restart(struct net_device *dev) |
| 1314 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1315 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1316 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1317 | if (lp->phy_dev) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1318 | int timeout; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1319 | |
| 1320 | phy_write(lp->phy_dev, MII_BMCR, BMCR_RESET); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1321 | timeout = 100; |
| 1322 | while (--timeout) { |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1323 | if (!(phy_read(lp->phy_dev, MII_BMCR) & BMCR_RESET)) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1324 | break; |
| 1325 | udelay(1); |
| 1326 | } |
| 1327 | if (!timeout) |
| 1328 | printk(KERN_ERR "%s: BMCR reset failed.\n", dev->name); |
| 1329 | } |
| 1330 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1331 | spin_lock_irq(&lp->lock); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1332 | tc35815_chip_reset(dev); |
| 1333 | tc35815_clear_queues(dev); |
| 1334 | tc35815_chip_init(dev); |
| 1335 | /* Reconfigure CAM again since tc35815_chip_init() initialize it. */ |
| 1336 | tc35815_set_multicast_list(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1337 | spin_unlock_irq(&lp->lock); |
| 1338 | |
| 1339 | netif_wake_queue(dev); |
| 1340 | } |
| 1341 | |
| 1342 | static void tc35815_restart_work(struct work_struct *work) |
| 1343 | { |
| 1344 | struct tc35815_local *lp = |
| 1345 | container_of(work, struct tc35815_local, restart_work); |
| 1346 | struct net_device *dev = lp->dev; |
| 1347 | |
| 1348 | tc35815_restart(dev); |
| 1349 | } |
| 1350 | |
| 1351 | static void tc35815_schedule_restart(struct net_device *dev) |
| 1352 | { |
| 1353 | struct tc35815_local *lp = netdev_priv(dev); |
| 1354 | struct tc35815_regs __iomem *tr = |
| 1355 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 1356 | |
| 1357 | /* disable interrupts */ |
| 1358 | tc_writel(0, &tr->Int_En); |
| 1359 | tc_writel(tc_readl(&tr->DMA_Ctl) | DMA_IntMask, &tr->DMA_Ctl); |
| 1360 | schedule_work(&lp->restart_work); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static void tc35815_tx_timeout(struct net_device *dev) |
| 1364 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1365 | struct tc35815_regs __iomem *tr = |
| 1366 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 1367 | |
| 1368 | printk(KERN_WARNING "%s: transmit timed out, status %#x\n", |
| 1369 | dev->name, tc_readl(&tr->Tx_Stat)); |
| 1370 | |
| 1371 | /* Try to restart the adaptor. */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1372 | tc35815_schedule_restart(dev); |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1373 | dev->stats.tx_errors++; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1374 | } |
| 1375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | /* |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1377 | * Open/initialize the controller. This is called (in the current kernel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | * sometime after booting when the 'ifconfig' program is run. |
| 1379 | * |
| 1380 | * This routine should set everything up anew at each open, even |
| 1381 | * registers that "should" only need to be set once at boot, so that |
| 1382 | * there is non-reboot way to recover if something goes wrong. |
| 1383 | */ |
| 1384 | static int |
| 1385 | tc35815_open(struct net_device *dev) |
| 1386 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1387 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | /* |
| 1390 | * This is used if the interrupt line can turned off (shared). |
| 1391 | * See 3c503.c for an example of selecting the IRQ at config-time. |
| 1392 | */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 1393 | if (request_irq(dev->irq, &tc35815_interrupt, IRQF_SHARED, |
| 1394 | dev->name, dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | tc35815_chip_reset(dev); |
| 1398 | |
| 1399 | if (tc35815_init_queues(dev) != 0) { |
| 1400 | free_irq(dev->irq, dev); |
| 1401 | return -EAGAIN; |
| 1402 | } |
| 1403 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1404 | #ifdef TC35815_NAPI |
| 1405 | napi_enable(&lp->napi); |
| 1406 | #endif |
| 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | /* Reset the hardware here. Don't forget to set the station address. */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1409 | spin_lock_irq(&lp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | tc35815_chip_init(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1411 | spin_unlock_irq(&lp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Atsushi Nemoto | 59524a3 | 2008-06-25 11:41:01 +0900 | [diff] [blame] | 1413 | netif_carrier_off(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1414 | /* schedule a link state check */ |
| 1415 | phy_start(lp->phy_dev); |
| 1416 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1417 | /* We are now ready to accept transmit requeusts from |
| 1418 | * the queueing layer of the networking. |
| 1419 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | netif_start_queue(dev); |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1425 | /* This will only be invoked if your driver is _not_ in XOFF state. |
| 1426 | * What this means is that you need not check it, and that this |
| 1427 | * invariant will hold if you make sure that the netif_*_queue() |
| 1428 | * calls are done at the proper times. |
| 1429 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1431 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1432 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1433 | struct TxFD *txfd; |
| 1434 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1436 | /* If some error occurs while trying to transmit this |
| 1437 | * packet, you should return '1' from this function. |
| 1438 | * In such a case you _may not_ do anything to the |
| 1439 | * SKB, it is still owned by the network queueing |
| 1440 | * layer when an error is returned. This means you |
| 1441 | * may not modify any SKB fields, you may not free |
| 1442 | * the SKB, etc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1445 | /* This is the most common case for modern hardware. |
| 1446 | * The spinlock protects this code from the TX complete |
| 1447 | * hardware interrupt handler. Queue flow control is |
| 1448 | * thus managed under this lock as well. |
| 1449 | */ |
| 1450 | spin_lock_irqsave(&lp->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1452 | /* failsafe... (handle txdone now if half of FDs are used) */ |
| 1453 | if ((lp->tfd_start + TX_FD_NUM - lp->tfd_end) % TX_FD_NUM > |
| 1454 | TX_FD_NUM / 2) |
| 1455 | tc35815_txdone(dev); |
| 1456 | |
| 1457 | if (netif_msg_pktdata(lp)) |
| 1458 | print_eth(skb->data); |
| 1459 | #ifdef DEBUG |
| 1460 | if (lp->tx_skbs[lp->tfd_start].skb) { |
| 1461 | printk("%s: tx_skbs conflict.\n", dev->name); |
| 1462 | panic_queues(dev); |
| 1463 | } |
| 1464 | #else |
| 1465 | BUG_ON(lp->tx_skbs[lp->tfd_start].skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1467 | lp->tx_skbs[lp->tfd_start].skb = skb; |
| 1468 | lp->tx_skbs[lp->tfd_start].skb_dma = pci_map_single(lp->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1470 | /*add to ring */ |
| 1471 | txfd = &lp->tfd_base[lp->tfd_start]; |
| 1472 | txfd->bd.BuffData = cpu_to_le32(lp->tx_skbs[lp->tfd_start].skb_dma); |
| 1473 | txfd->bd.BDCtl = cpu_to_le32(skb->len); |
| 1474 | txfd->fd.FDSystem = cpu_to_le32(lp->tfd_start); |
| 1475 | txfd->fd.FDCtl = cpu_to_le32(FD_CownsFD | (1 << FD_BDCnt_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1477 | if (lp->tfd_start == lp->tfd_end) { |
| 1478 | struct tc35815_regs __iomem *tr = |
| 1479 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 1480 | /* Start DMA Transmitter. */ |
| 1481 | txfd->fd.FDNext |= cpu_to_le32(FD_Next_EOL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | #ifdef GATHER_TXINT |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1483 | txfd->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1485 | if (netif_msg_tx_queued(lp)) { |
| 1486 | printk("%s: starting TxFD.\n", dev->name); |
| 1487 | dump_txfd(txfd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1489 | tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr); |
| 1490 | } else { |
| 1491 | txfd->fd.FDNext &= cpu_to_le32(~FD_Next_EOL); |
| 1492 | if (netif_msg_tx_queued(lp)) { |
| 1493 | printk("%s: queueing TxFD.\n", dev->name); |
| 1494 | dump_txfd(txfd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1496 | } |
| 1497 | lp->tfd_start = (lp->tfd_start + 1) % TX_FD_NUM; |
| 1498 | |
| 1499 | dev->trans_start = jiffies; |
| 1500 | |
| 1501 | /* If we just used up the very last entry in the |
| 1502 | * TX ring on this device, tell the queueing |
| 1503 | * layer to send no more. |
| 1504 | */ |
| 1505 | if (tc35815_tx_full(dev)) { |
| 1506 | if (netif_msg_tx_queued(lp)) |
| 1507 | printk(KERN_WARNING "%s: TxFD Exhausted.\n", dev->name); |
| 1508 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1511 | /* When the TX completion hw interrupt arrives, this |
| 1512 | * is when the transmit statistics are updated. |
| 1513 | */ |
| 1514 | |
| 1515 | spin_unlock_irqrestore(&lp->lock, flags); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1516 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | #define FATAL_ERROR_INT \ |
| 1520 | (Int_IntPCI | Int_DmParErr | Int_IntNRAbt) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1521 | static void tc35815_fatal_error_interrupt(struct net_device *dev, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | { |
| 1523 | static int count; |
| 1524 | printk(KERN_WARNING "%s: Fatal Error Intterrupt (%#x):", |
| 1525 | dev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | if (status & Int_IntPCI) |
| 1527 | printk(" IntPCI"); |
| 1528 | if (status & Int_DmParErr) |
| 1529 | printk(" DmParErr"); |
| 1530 | if (status & Int_IntNRAbt) |
| 1531 | printk(" IntNRAbt"); |
| 1532 | printk("\n"); |
| 1533 | if (count++ > 100) |
| 1534 | panic("%s: Too many fatal errors.", dev->name); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1535 | printk(KERN_WARNING "%s: Resetting ...\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | /* Try to restart the adaptor. */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1537 | tc35815_schedule_restart(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | #ifdef TC35815_NAPI |
| 1541 | static int tc35815_do_interrupt(struct net_device *dev, u32 status, int limit) |
| 1542 | #else |
| 1543 | static int tc35815_do_interrupt(struct net_device *dev, u32 status) |
| 1544 | #endif |
| 1545 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1546 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1547 | int ret = -1; |
| 1548 | |
| 1549 | /* Fatal errors... */ |
| 1550 | if (status & FATAL_ERROR_INT) { |
| 1551 | tc35815_fatal_error_interrupt(dev, status); |
| 1552 | return 0; |
| 1553 | } |
| 1554 | /* recoverable errors */ |
| 1555 | if (status & Int_IntFDAEx) { |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1556 | if (netif_msg_rx_err(lp)) |
| 1557 | dev_warn(&dev->dev, |
| 1558 | "Free Descriptor Area Exhausted (%#x).\n", |
| 1559 | status); |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1560 | dev->stats.rx_dropped++; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1561 | ret = 0; |
| 1562 | } |
| 1563 | if (status & Int_IntBLEx) { |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1564 | if (netif_msg_rx_err(lp)) |
| 1565 | dev_warn(&dev->dev, |
| 1566 | "Buffer List Exhausted (%#x).\n", |
| 1567 | status); |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1568 | dev->stats.rx_dropped++; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1569 | ret = 0; |
| 1570 | } |
| 1571 | if (status & Int_IntExBD) { |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1572 | if (netif_msg_rx_err(lp)) |
| 1573 | dev_warn(&dev->dev, |
| 1574 | "Excessive Buffer Descriptiors (%#x).\n", |
| 1575 | status); |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1576 | dev->stats.rx_length_errors++; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1577 | ret = 0; |
| 1578 | } |
| 1579 | |
| 1580 | /* normal notification */ |
| 1581 | if (status & Int_IntMacRx) { |
| 1582 | /* Got a packet(s). */ |
| 1583 | #ifdef TC35815_NAPI |
| 1584 | ret = tc35815_rx(dev, limit); |
| 1585 | #else |
| 1586 | tc35815_rx(dev); |
| 1587 | ret = 0; |
| 1588 | #endif |
| 1589 | lp->lstats.rx_ints++; |
| 1590 | } |
| 1591 | if (status & Int_IntMacTx) { |
| 1592 | /* Transmit complete. */ |
| 1593 | lp->lstats.tx_ints++; |
| 1594 | tc35815_txdone(dev); |
| 1595 | netif_wake_queue(dev); |
Atsushi Nemoto | 02c5c8e | 2009-10-26 03:46:21 +0000 | [diff] [blame] | 1596 | #ifdef TC35815_NAPI |
| 1597 | if (ret < 0) |
| 1598 | ret = 0; |
| 1599 | #else |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1600 | ret = 0; |
Atsushi Nemoto | 02c5c8e | 2009-10-26 03:46:21 +0000 | [diff] [blame] | 1601 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1602 | } |
| 1603 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * The typical workload of the driver: |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1608 | * Handle the network interface interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1610 | static irqreturn_t tc35815_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | { |
| 1612 | struct net_device *dev = dev_id; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1613 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1614 | struct tc35815_regs __iomem *tr = |
| 1615 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 1616 | #ifdef TC35815_NAPI |
| 1617 | u32 dmactl = tc_readl(&tr->DMA_Ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1619 | if (!(dmactl & DMA_IntMask)) { |
| 1620 | /* disable interrupts */ |
| 1621 | tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1622 | if (napi_schedule_prep(&lp->napi)) |
| 1623 | __napi_schedule(&lp->napi); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1624 | else { |
| 1625 | printk(KERN_ERR "%s: interrupt taken in poll\n", |
| 1626 | dev->name); |
| 1627 | BUG(); |
| 1628 | } |
| 1629 | (void)tc_readl(&tr->Int_Src); /* flush */ |
| 1630 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1632 | return IRQ_NONE; |
| 1633 | #else |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1634 | int handled; |
| 1635 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1637 | spin_lock(&lp->lock); |
| 1638 | status = tc_readl(&tr->Int_Src); |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1639 | /* BLEx, FDAEx will be cleared later */ |
| 1640 | tc_writel(status & ~(Int_BLEx | Int_FDAEx), |
| 1641 | &tr->Int_Src); /* write to clear */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1642 | handled = tc35815_do_interrupt(dev, status); |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1643 | if (status & (Int_BLEx | Int_FDAEx)) |
| 1644 | tc_writel(status & (Int_BLEx | Int_FDAEx), &tr->Int_Src); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1645 | (void)tc_readl(&tr->Int_Src); /* flush */ |
| 1646 | spin_unlock(&lp->lock); |
| 1647 | return IRQ_RETVAL(handled >= 0); |
| 1648 | #endif /* TC35815_NAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1651 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1652 | static void tc35815_poll_controller(struct net_device *dev) |
| 1653 | { |
| 1654 | disable_irq(dev->irq); |
| 1655 | tc35815_interrupt(dev->irq, dev); |
| 1656 | enable_irq(dev->irq); |
| 1657 | } |
| 1658 | #endif |
| 1659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | /* We have a good packet(s), get it/them out of the buffers. */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1661 | #ifdef TC35815_NAPI |
| 1662 | static int |
| 1663 | tc35815_rx(struct net_device *dev, int limit) |
| 1664 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | static void |
| 1666 | tc35815_rx(struct net_device *dev) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1667 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1669 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | unsigned int fdctl; |
| 1671 | int i; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1672 | #ifdef TC35815_NAPI |
| 1673 | int received = 0; |
| 1674 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
| 1676 | while (!((fdctl = le32_to_cpu(lp->rfd_cur->fd.FDCtl)) & FD_CownsFD)) { |
| 1677 | int status = le32_to_cpu(lp->rfd_cur->fd.FDStat); |
| 1678 | int pkt_len = fdctl & FD_FDLength_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | int bd_count = (fdctl & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1680 | #ifdef DEBUG |
| 1681 | struct RxFD *next_rfd; |
| 1682 | #endif |
| 1683 | #if (RX_CTL_CMD & Rx_StripCRC) == 0 |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 1684 | pkt_len -= ETH_FCS_LEN; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1685 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1687 | if (netif_msg_rx_status(lp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | dump_rxfd(lp->rfd_cur); |
| 1689 | if (status & Rx_Good) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | struct sk_buff *skb; |
| 1691 | unsigned char *data; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1692 | int cur_bd; |
| 1693 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1694 | int offset; |
| 1695 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1697 | #ifdef TC35815_NAPI |
| 1698 | if (--limit < 0) |
| 1699 | break; |
| 1700 | #endif |
| 1701 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1702 | BUG_ON(bd_count > 2); |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 1703 | skb = dev_alloc_skb(pkt_len + NET_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | if (skb == NULL) { |
| 1705 | printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", |
| 1706 | dev->name); |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1707 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | break; |
| 1709 | } |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 1710 | skb_reserve(skb, NET_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
| 1712 | data = skb_put(skb, pkt_len); |
| 1713 | |
| 1714 | /* copy from receive buffer */ |
| 1715 | cur_bd = 0; |
| 1716 | offset = 0; |
| 1717 | while (offset < pkt_len && cur_bd < bd_count) { |
| 1718 | int len = le32_to_cpu(lp->rfd_cur->bd[cur_bd].BDCtl) & |
| 1719 | BD_BuffLength_MASK; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1720 | dma_addr_t dma = le32_to_cpu(lp->rfd_cur->bd[cur_bd].BuffData); |
| 1721 | void *rxbuf = rxbuf_bus_to_virt(lp, dma); |
| 1722 | if (offset + len > pkt_len) |
| 1723 | len = pkt_len - offset; |
| 1724 | #ifdef TC35815_DMA_SYNC_ONDEMAND |
| 1725 | pci_dma_sync_single_for_cpu(lp->pci_dev, |
| 1726 | dma, len, |
| 1727 | PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | #endif |
| 1729 | memcpy(data + offset, rxbuf, len); |
Atsushi Nemoto | 793bc0a | 2007-03-14 01:02:20 +0900 | [diff] [blame] | 1730 | #ifdef TC35815_DMA_SYNC_ONDEMAND |
| 1731 | pci_dma_sync_single_for_device(lp->pci_dev, |
| 1732 | dma, len, |
| 1733 | PCI_DMA_FROMDEVICE); |
| 1734 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | offset += len; |
| 1736 | cur_bd++; |
| 1737 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1738 | #else /* TC35815_USE_PACKEDBUFFER */ |
| 1739 | BUG_ON(bd_count > 1); |
| 1740 | cur_bd = (le32_to_cpu(lp->rfd_cur->bd[0].BDCtl) |
| 1741 | & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT; |
| 1742 | #ifdef DEBUG |
| 1743 | if (cur_bd >= RX_BUF_NUM) { |
| 1744 | printk("%s: invalid BDID.\n", dev->name); |
| 1745 | panic_queues(dev); |
| 1746 | } |
| 1747 | BUG_ON(lp->rx_skbs[cur_bd].skb_dma != |
| 1748 | (le32_to_cpu(lp->rfd_cur->bd[0].BuffData) & ~3)); |
| 1749 | if (!lp->rx_skbs[cur_bd].skb) { |
| 1750 | printk("%s: NULL skb.\n", dev->name); |
| 1751 | panic_queues(dev); |
| 1752 | } |
| 1753 | #else |
| 1754 | BUG_ON(cur_bd >= RX_BUF_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1756 | skb = lp->rx_skbs[cur_bd].skb; |
| 1757 | prefetch(skb->data); |
| 1758 | lp->rx_skbs[cur_bd].skb = NULL; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1759 | pci_unmap_single(lp->pci_dev, |
| 1760 | lp->rx_skbs[cur_bd].skb_dma, |
| 1761 | RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
Atsushi Nemoto | 82a9928 | 2008-12-11 20:58:04 -0800 | [diff] [blame] | 1762 | if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN) |
| 1763 | memmove(skb->data, skb->data - NET_IP_ALIGN, |
| 1764 | pkt_len); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1765 | data = skb_put(skb, pkt_len); |
| 1766 | #endif /* TC35815_USE_PACKEDBUFFER */ |
| 1767 | if (netif_msg_pktdata(lp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | print_eth(data); |
| 1769 | skb->protocol = eth_type_trans(skb, dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1770 | #ifdef TC35815_NAPI |
| 1771 | netif_receive_skb(skb); |
| 1772 | received++; |
| 1773 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | netif_rx(skb); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1775 | #endif |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1776 | dev->stats.rx_packets++; |
| 1777 | dev->stats.rx_bytes += pkt_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | } else { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1779 | dev->stats.rx_errors++; |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1780 | if (netif_msg_rx_err(lp)) |
| 1781 | dev_info(&dev->dev, "Rx error (status %x)\n", |
| 1782 | status & Rx_Stat_Mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | /* WORKAROUND: LongErr and CRCErr means Overflow. */ |
| 1784 | if ((status & Rx_LongErr) && (status & Rx_CRCErr)) { |
| 1785 | status &= ~(Rx_LongErr|Rx_CRCErr); |
| 1786 | status |= Rx_Over; |
| 1787 | } |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1788 | if (status & Rx_LongErr) |
| 1789 | dev->stats.rx_length_errors++; |
| 1790 | if (status & Rx_Over) |
| 1791 | dev->stats.rx_fifo_errors++; |
| 1792 | if (status & Rx_CRCErr) |
| 1793 | dev->stats.rx_crc_errors++; |
| 1794 | if (status & Rx_Align) |
| 1795 | dev->stats.rx_frame_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | if (bd_count > 0) { |
| 1799 | /* put Free Buffer back to controller */ |
| 1800 | int bdctl = le32_to_cpu(lp->rfd_cur->bd[bd_count - 1].BDCtl); |
| 1801 | unsigned char id = |
| 1802 | (bdctl & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1803 | #ifdef DEBUG |
| 1804 | if (id >= RX_BUF_NUM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | printk("%s: invalid BDID.\n", dev->name); |
| 1806 | panic_queues(dev); |
| 1807 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1808 | #else |
| 1809 | BUG_ON(id >= RX_BUF_NUM); |
| 1810 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | /* free old buffers */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1812 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1813 | while (lp->fbl_curid != id) |
| 1814 | #else |
Atsushi Nemoto | ccc57aa | 2008-06-26 17:14:15 +0900 | [diff] [blame] | 1815 | lp->fbl_count--; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1816 | while (lp->fbl_count < RX_BUF_NUM) |
| 1817 | #endif |
| 1818 | { |
| 1819 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1820 | unsigned char curid = lp->fbl_curid; |
| 1821 | #else |
| 1822 | unsigned char curid = |
| 1823 | (id + 1 + lp->fbl_count) % RX_BUF_NUM; |
| 1824 | #endif |
| 1825 | struct BDesc *bd = &lp->fbl_ptr->bd[curid]; |
| 1826 | #ifdef DEBUG |
| 1827 | bdctl = le32_to_cpu(bd->BDCtl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | if (bdctl & BD_CownsBD) { |
| 1829 | printk("%s: Freeing invalid BD.\n", |
| 1830 | dev->name); |
| 1831 | panic_queues(dev); |
| 1832 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1833 | #endif |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 1834 | /* pass BD to controller */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1835 | #ifndef TC35815_USE_PACKEDBUFFER |
| 1836 | if (!lp->rx_skbs[curid].skb) { |
| 1837 | lp->rx_skbs[curid].skb = |
| 1838 | alloc_rxbuf_skb(dev, |
| 1839 | lp->pci_dev, |
| 1840 | &lp->rx_skbs[curid].skb_dma); |
| 1841 | if (!lp->rx_skbs[curid].skb) |
| 1842 | break; /* try on next reception */ |
| 1843 | bd->BuffData = cpu_to_le32(lp->rx_skbs[curid].skb_dma); |
| 1844 | } |
| 1845 | #endif /* TC35815_USE_PACKEDBUFFER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | /* Note: BDLength was modified by chip. */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1847 | bd->BDCtl = cpu_to_le32(BD_CownsBD | |
| 1848 | (curid << BD_RxBDID_SHIFT) | |
| 1849 | RX_BUF_SIZE); |
| 1850 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1851 | lp->fbl_curid = (curid + 1) % RX_BUF_NUM; |
| 1852 | if (netif_msg_rx_status(lp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | printk("%s: Entering new FBD %d\n", |
| 1854 | dev->name, lp->fbl_curid); |
| 1855 | dump_frfd(lp->fbl_ptr); |
| 1856 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1857 | #else |
| 1858 | lp->fbl_count++; |
| 1859 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | /* put RxFD back to controller */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1864 | #ifdef DEBUG |
| 1865 | next_rfd = fd_bus_to_virt(lp, |
| 1866 | le32_to_cpu(lp->rfd_cur->fd.FDNext)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | if (next_rfd < lp->rfd_base || next_rfd > lp->rfd_limit) { |
| 1868 | printk("%s: RxFD FDNext invalid.\n", dev->name); |
| 1869 | panic_queues(dev); |
| 1870 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1871 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | for (i = 0; i < (bd_count + 1) / 2 + 1; i++) { |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 1873 | /* pass FD to controller */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1874 | #ifdef DEBUG |
| 1875 | lp->rfd_cur->fd.FDNext = cpu_to_le32(0xdeaddead); |
| 1876 | #else |
| 1877 | lp->rfd_cur->fd.FDNext = cpu_to_le32(FD_Next_EOL); |
| 1878 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | lp->rfd_cur->fd.FDCtl = cpu_to_le32(FD_CownsFD); |
| 1880 | lp->rfd_cur++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1882 | if (lp->rfd_cur > lp->rfd_limit) |
| 1883 | lp->rfd_cur = lp->rfd_base; |
| 1884 | #ifdef DEBUG |
| 1885 | if (lp->rfd_cur != next_rfd) |
| 1886 | printk("rfd_cur = %p, next_rfd %p\n", |
| 1887 | lp->rfd_cur, next_rfd); |
| 1888 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1891 | #ifdef TC35815_NAPI |
| 1892 | return received; |
| 1893 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1896 | #ifdef TC35815_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1897 | static int tc35815_poll(struct napi_struct *napi, int budget) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1898 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1899 | struct tc35815_local *lp = container_of(napi, struct tc35815_local, napi); |
| 1900 | struct net_device *dev = lp->dev; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1901 | struct tc35815_regs __iomem *tr = |
| 1902 | (struct tc35815_regs __iomem *)dev->base_addr; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1903 | int received = 0, handled; |
| 1904 | u32 status; |
| 1905 | |
| 1906 | spin_lock(&lp->lock); |
| 1907 | status = tc_readl(&tr->Int_Src); |
| 1908 | do { |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1909 | /* BLEx, FDAEx will be cleared later */ |
| 1910 | tc_writel(status & ~(Int_BLEx | Int_FDAEx), |
| 1911 | &tr->Int_Src); /* write to clear */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1912 | |
Atsushi Nemoto | a2c465d | 2009-04-02 01:17:36 -0700 | [diff] [blame] | 1913 | handled = tc35815_do_interrupt(dev, status, budget - received); |
Atsushi Nemoto | db30f5e | 2009-08-06 04:41:46 +0000 | [diff] [blame] | 1914 | if (status & (Int_BLEx | Int_FDAEx)) |
| 1915 | tc_writel(status & (Int_BLEx | Int_FDAEx), |
| 1916 | &tr->Int_Src); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1917 | if (handled >= 0) { |
| 1918 | received += handled; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1919 | if (received >= budget) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | status = tc_readl(&tr->Int_Src); |
| 1923 | } while (status); |
| 1924 | spin_unlock(&lp->lock); |
| 1925 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1926 | if (received < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1927 | napi_complete(napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1928 | /* enable interrupts */ |
| 1929 | tc_writel(tc_readl(&tr->DMA_Ctl) & ~DMA_IntMask, &tr->DMA_Ctl); |
| 1930 | } |
| 1931 | return received; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1932 | } |
| 1933 | #endif |
| 1934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | #ifdef NO_CHECK_CARRIER |
| 1936 | #define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_LateColl|Tx_TxPar|Tx_SQErr) |
| 1937 | #else |
| 1938 | #define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_NCarr|Tx_LateColl|Tx_TxPar|Tx_SQErr) |
| 1939 | #endif |
| 1940 | |
| 1941 | static void |
| 1942 | tc35815_check_tx_stat(struct net_device *dev, int status) |
| 1943 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 1944 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | const char *msg = NULL; |
| 1946 | |
| 1947 | /* count collisions */ |
| 1948 | if (status & Tx_ExColl) |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1949 | dev->stats.collisions += 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | if (status & Tx_TxColl_MASK) |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1951 | dev->stats.collisions += status & Tx_TxColl_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1953 | #ifndef NO_CHECK_CARRIER |
| 1954 | /* TX4939 does not have NCarr */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1955 | if (lp->chiptype == TC35815_TX4939) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | status &= ~Tx_NCarr; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1957 | #ifdef WORKAROUND_LOSTCAR |
| 1958 | /* WORKAROUND: ignore LostCrS in full duplex operation */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 1959 | if (!lp->link || lp->duplex == DUPLEX_FULL) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1960 | status &= ~Tx_NCarr; |
| 1961 | #endif |
| 1962 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | |
| 1964 | if (!(status & TX_STA_ERR)) { |
| 1965 | /* no error. */ |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1966 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | return; |
| 1968 | } |
| 1969 | |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1970 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | if (status & Tx_ExColl) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1972 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | msg = "Excessive Collision."; |
| 1974 | } |
| 1975 | if (status & Tx_Under) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1976 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | msg = "Tx FIFO Underrun."; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 1978 | if (lp->lstats.tx_underrun < TX_THRESHOLD_KEEP_LIMIT) { |
| 1979 | lp->lstats.tx_underrun++; |
| 1980 | if (lp->lstats.tx_underrun >= TX_THRESHOLD_KEEP_LIMIT) { |
| 1981 | struct tc35815_regs __iomem *tr = |
| 1982 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 1983 | tc_writel(TX_THRESHOLD_MAX, &tr->TxThrsh); |
| 1984 | msg = "Tx FIFO Underrun.Change Tx threshold to max."; |
| 1985 | } |
| 1986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | if (status & Tx_Defer) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1989 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | msg = "Excessive Deferral."; |
| 1991 | } |
| 1992 | #ifndef NO_CHECK_CARRIER |
| 1993 | if (status & Tx_NCarr) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1994 | dev->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | msg = "Lost Carrier Sense."; |
| 1996 | } |
| 1997 | #endif |
| 1998 | if (status & Tx_LateColl) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 1999 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | msg = "Late Collision."; |
| 2001 | } |
| 2002 | if (status & Tx_TxPar) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 2003 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | msg = "Transmit Parity Error."; |
| 2005 | } |
| 2006 | if (status & Tx_SQErr) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 2007 | dev->stats.tx_heartbeat_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | msg = "Signal Quality Error."; |
| 2009 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2010 | if (msg && netif_msg_tx_err(lp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | printk(KERN_WARNING "%s: %s (%#x)\n", dev->name, msg, status); |
| 2012 | } |
| 2013 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2014 | /* This handles TX complete events posted by the device |
| 2015 | * via interrupts. |
| 2016 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | static void |
| 2018 | tc35815_txdone(struct net_device *dev) |
| 2019 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2020 | struct tc35815_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | struct TxFD *txfd; |
| 2022 | unsigned int fdctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
| 2024 | txfd = &lp->tfd_base[lp->tfd_end]; |
| 2025 | while (lp->tfd_start != lp->tfd_end && |
| 2026 | !((fdctl = le32_to_cpu(txfd->fd.FDCtl)) & FD_CownsFD)) { |
| 2027 | int status = le32_to_cpu(txfd->fd.FDStat); |
| 2028 | struct sk_buff *skb; |
| 2029 | unsigned long fdnext = le32_to_cpu(txfd->fd.FDNext); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2030 | u32 fdsystem = le32_to_cpu(txfd->fd.FDSystem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2032 | if (netif_msg_tx_done(lp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | printk("%s: complete TxFD.\n", dev->name); |
| 2034 | dump_txfd(txfd); |
| 2035 | } |
| 2036 | tc35815_check_tx_stat(dev, status); |
| 2037 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2038 | skb = fdsystem != 0xffffffff ? |
| 2039 | lp->tx_skbs[fdsystem].skb : NULL; |
| 2040 | #ifdef DEBUG |
| 2041 | if (lp->tx_skbs[lp->tfd_end].skb != skb) { |
| 2042 | printk("%s: tx_skbs mismatch.\n", dev->name); |
| 2043 | panic_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2045 | #else |
| 2046 | BUG_ON(lp->tx_skbs[lp->tfd_end].skb != skb); |
| 2047 | #endif |
| 2048 | if (skb) { |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 2049 | dev->stats.tx_bytes += skb->len; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2050 | pci_unmap_single(lp->pci_dev, lp->tx_skbs[lp->tfd_end].skb_dma, skb->len, PCI_DMA_TODEVICE); |
| 2051 | lp->tx_skbs[lp->tfd_end].skb = NULL; |
| 2052 | lp->tx_skbs[lp->tfd_end].skb_dma = 0; |
| 2053 | #ifdef TC35815_NAPI |
| 2054 | dev_kfree_skb_any(skb); |
| 2055 | #else |
| 2056 | dev_kfree_skb_irq(skb); |
| 2057 | #endif |
| 2058 | } |
| 2059 | txfd->fd.FDSystem = cpu_to_le32(0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | lp->tfd_end = (lp->tfd_end + 1) % TX_FD_NUM; |
| 2062 | txfd = &lp->tfd_base[lp->tfd_end]; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2063 | #ifdef DEBUG |
| 2064 | if ((fdnext & ~FD_Next_EOL) != fd_virt_to_bus(lp, txfd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | printk("%s: TxFD FDNext invalid.\n", dev->name); |
| 2066 | panic_queues(dev); |
| 2067 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2068 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | if (fdnext & FD_Next_EOL) { |
| 2070 | /* DMA Transmitter has been stopping... */ |
| 2071 | if (lp->tfd_end != lp->tfd_start) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2072 | struct tc35815_regs __iomem *tr = |
| 2073 | (struct tc35815_regs __iomem *)dev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | int head = (lp->tfd_start + TX_FD_NUM - 1) % TX_FD_NUM; |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2075 | struct TxFD *txhead = &lp->tfd_base[head]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | int qlen = (lp->tfd_start + TX_FD_NUM |
| 2077 | - lp->tfd_end) % TX_FD_NUM; |
| 2078 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2079 | #ifdef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | if (!(le32_to_cpu(txfd->fd.FDCtl) & FD_CownsFD)) { |
| 2081 | printk("%s: TxFD FDCtl invalid.\n", dev->name); |
| 2082 | panic_queues(dev); |
| 2083 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2084 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | /* log max queue length */ |
| 2086 | if (lp->lstats.max_tx_qlen < qlen) |
| 2087 | lp->lstats.max_tx_qlen = qlen; |
| 2088 | |
| 2089 | |
| 2090 | /* start DMA Transmitter again */ |
| 2091 | txhead->fd.FDNext |= cpu_to_le32(FD_Next_EOL); |
| 2092 | #ifdef GATHER_TXINT |
| 2093 | txhead->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx); |
| 2094 | #endif |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2095 | if (netif_msg_tx_queued(lp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | printk("%s: start TxFD on queue.\n", |
| 2097 | dev->name); |
| 2098 | dump_txfd(txfd); |
| 2099 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2100 | tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | } |
| 2102 | break; |
| 2103 | } |
| 2104 | } |
| 2105 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2106 | /* If we had stopped the queue due to a "tx full" |
| 2107 | * condition, and space has now been made available, |
| 2108 | * wake up the queue. |
| 2109 | */ |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2110 | if (netif_queue_stopped(dev) && !tc35815_tx_full(dev)) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2111 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | /* The inverse routine to tc35815_open(). */ |
| 2115 | static int |
| 2116 | tc35815_close(struct net_device *dev) |
| 2117 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2118 | struct tc35815_local *lp = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | netif_stop_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2121 | #ifdef TC35815_NAPI |
| 2122 | napi_disable(&lp->napi); |
| 2123 | #endif |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2124 | if (lp->phy_dev) |
| 2125 | phy_stop(lp->phy_dev); |
| 2126 | cancel_work_sync(&lp->restart_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | |
| 2128 | /* Flush the Tx and disable Rx here. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | tc35815_chip_reset(dev); |
| 2130 | free_irq(dev->irq, dev); |
| 2131 | |
| 2132 | tc35815_free_queues(dev); |
| 2133 | |
| 2134 | return 0; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | /* |
| 2139 | * Get the current statistics. |
| 2140 | * This may be called with the card open or closed. |
| 2141 | */ |
| 2142 | static struct net_device_stats *tc35815_get_stats(struct net_device *dev) |
| 2143 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2144 | struct tc35815_regs __iomem *tr = |
| 2145 | (struct tc35815_regs __iomem *)dev->base_addr; |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 2146 | if (netif_running(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | /* Update the statistics from the device registers. */ |
Atsushi Nemoto | 7bb82e8 | 2009-08-06 04:41:48 +0000 | [diff] [blame] | 2148 | dev->stats.rx_missed_errors += tc_readl(&tr->Miss_Cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | |
Atsushi Nemoto | c201abd9 | 2008-04-11 00:24:12 +0900 | [diff] [blame] | 2150 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2153 | static void tc35815_set_cam_entry(struct net_device *dev, int index, unsigned char *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2155 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2156 | struct tc35815_regs __iomem *tr = |
| 2157 | (struct tc35815_regs __iomem *)dev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | int cam_index = index * 6; |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2159 | u32 cam_data; |
| 2160 | u32 saved_addr; |
Atsushi Nemoto | 958eb80 | 2008-04-11 00:24:24 +0900 | [diff] [blame] | 2161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | saved_addr = tc_readl(&tr->CAM_Adr); |
| 2163 | |
Atsushi Nemoto | 958eb80 | 2008-04-11 00:24:24 +0900 | [diff] [blame] | 2164 | if (netif_msg_hw(lp)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2165 | printk(KERN_DEBUG "%s: CAM %d: %pM\n", |
| 2166 | dev->name, index, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | if (index & 1) { |
| 2168 | /* read modify write */ |
| 2169 | tc_writel(cam_index - 2, &tr->CAM_Adr); |
| 2170 | cam_data = tc_readl(&tr->CAM_Data) & 0xffff0000; |
| 2171 | cam_data |= addr[0] << 8 | addr[1]; |
| 2172 | tc_writel(cam_data, &tr->CAM_Data); |
| 2173 | /* write whole word */ |
| 2174 | tc_writel(cam_index + 2, &tr->CAM_Adr); |
| 2175 | cam_data = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) | addr[5]; |
| 2176 | tc_writel(cam_data, &tr->CAM_Data); |
| 2177 | } else { |
| 2178 | /* write whole word */ |
| 2179 | tc_writel(cam_index, &tr->CAM_Adr); |
| 2180 | cam_data = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]; |
| 2181 | tc_writel(cam_data, &tr->CAM_Data); |
| 2182 | /* read modify write */ |
| 2183 | tc_writel(cam_index + 4, &tr->CAM_Adr); |
| 2184 | cam_data = tc_readl(&tr->CAM_Data) & 0x0000ffff; |
| 2185 | cam_data |= addr[4] << 24 | (addr[5] << 16); |
| 2186 | tc_writel(cam_data, &tr->CAM_Data); |
| 2187 | } |
| 2188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | tc_writel(saved_addr, &tr->CAM_Adr); |
| 2190 | } |
| 2191 | |
| 2192 | |
| 2193 | /* |
| 2194 | * Set or clear the multicast filter for this adaptor. |
| 2195 | * num_addrs == -1 Promiscuous mode, receive all packets |
| 2196 | * num_addrs == 0 Normal mode, clear multicast list |
| 2197 | * num_addrs > 0 Multicast mode, receive normal and MC packets, |
| 2198 | * and do best-effort filtering. |
| 2199 | */ |
| 2200 | static void |
| 2201 | tc35815_set_multicast_list(struct net_device *dev) |
| 2202 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2203 | struct tc35815_regs __iomem *tr = |
| 2204 | (struct tc35815_regs __iomem *)dev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2206 | if (dev->flags & IFF_PROMISC) { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2207 | #ifdef WORKAROUND_100HALF_PROMISC |
| 2208 | /* With some (all?) 100MHalf HUB, controller will hang |
| 2209 | * if we enabled promiscuous mode before linkup... */ |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2210 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2211 | |
| 2212 | if (!lp->link) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2213 | return; |
| 2214 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | /* Enable promiscuous mode */ |
| 2216 | tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc | CAM_StationAcc, &tr->CAM_Ctl); |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2217 | } else if ((dev->flags & IFF_ALLMULTI) || |
| 2218 | dev->mc_count > CAM_ENTRY_MAX - 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | /* CAM 0, 1, 20 are reserved. */ |
| 2220 | /* Disable promiscuous mode, use normal mode. */ |
| 2221 | tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc, &tr->CAM_Ctl); |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2222 | } else if (dev->mc_count) { |
| 2223 | struct dev_mc_list *cur_addr = dev->mc_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | int i; |
| 2225 | int ena_bits = CAM_Ena_Bit(CAM_ENTRY_SOURCE); |
| 2226 | |
| 2227 | tc_writel(0, &tr->CAM_Ctl); |
| 2228 | /* Walk the address list, and load the filter */ |
| 2229 | for (i = 0; i < dev->mc_count; i++, cur_addr = cur_addr->next) { |
| 2230 | if (!cur_addr) |
| 2231 | break; |
| 2232 | /* entry 0,1 is reserved. */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2233 | tc35815_set_cam_entry(dev, i + 2, cur_addr->dmi_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | ena_bits |= CAM_Ena_Bit(i + 2); |
| 2235 | } |
| 2236 | tc_writel(ena_bits, &tr->CAM_Ena); |
| 2237 | tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl); |
Atsushi Nemoto | 7f225b4 | 2008-04-11 00:25:31 +0900 | [diff] [blame] | 2238 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena); |
| 2240 | tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl); |
| 2241 | } |
| 2242 | } |
| 2243 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2244 | static void tc35815_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2246 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2247 | strcpy(info->driver, MODNAME); |
| 2248 | strcpy(info->version, DRV_VERSION); |
| 2249 | strcpy(info->bus_info, pci_name(lp->pci_dev)); |
| 2250 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2251 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2252 | static int tc35815_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 2253 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2254 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2255 | |
| 2256 | if (!lp->phy_dev) |
| 2257 | return -ENODEV; |
| 2258 | return phy_ethtool_gset(lp->phy_dev, cmd); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2261 | static int tc35815_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 2262 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2263 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2264 | |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2265 | if (!lp->phy_dev) |
| 2266 | return -ENODEV; |
| 2267 | return phy_ethtool_sset(lp->phy_dev, cmd); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | static u32 tc35815_get_msglevel(struct net_device *dev) |
| 2271 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2272 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2273 | return lp->msg_enable; |
| 2274 | } |
| 2275 | |
| 2276 | static void tc35815_set_msglevel(struct net_device *dev, u32 datum) |
| 2277 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2278 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2279 | lp->msg_enable = datum; |
| 2280 | } |
| 2281 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2282 | static int tc35815_get_sset_count(struct net_device *dev, int sset) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2283 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2284 | struct tc35815_local *lp = netdev_priv(dev); |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2285 | |
| 2286 | switch (sset) { |
| 2287 | case ETH_SS_STATS: |
| 2288 | return sizeof(lp->lstats) / sizeof(int); |
| 2289 | default: |
| 2290 | return -EOPNOTSUPP; |
| 2291 | } |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | static void tc35815_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data) |
| 2295 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2296 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2297 | data[0] = lp->lstats.max_tx_qlen; |
| 2298 | data[1] = lp->lstats.tx_ints; |
| 2299 | data[2] = lp->lstats.rx_ints; |
| 2300 | data[3] = lp->lstats.tx_underrun; |
| 2301 | } |
| 2302 | |
| 2303 | static struct { |
| 2304 | const char str[ETH_GSTRING_LEN]; |
| 2305 | } ethtool_stats_keys[] = { |
| 2306 | { "max_tx_qlen" }, |
| 2307 | { "tx_ints" }, |
| 2308 | { "rx_ints" }, |
| 2309 | { "tx_underrun" }, |
| 2310 | }; |
| 2311 | |
| 2312 | static void tc35815_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2313 | { |
| 2314 | memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 2315 | } |
| 2316 | |
| 2317 | static const struct ethtool_ops tc35815_ethtool_ops = { |
| 2318 | .get_drvinfo = tc35815_get_drvinfo, |
| 2319 | .get_settings = tc35815_get_settings, |
| 2320 | .set_settings = tc35815_set_settings, |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2321 | .get_link = ethtool_op_get_link, |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2322 | .get_msglevel = tc35815_get_msglevel, |
| 2323 | .set_msglevel = tc35815_set_msglevel, |
| 2324 | .get_strings = tc35815_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2325 | .get_sset_count = tc35815_get_sset_count, |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2326 | .get_ethtool_stats = tc35815_get_ethtool_stats, |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2327 | }; |
| 2328 | |
| 2329 | static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2330 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2331 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2332 | |
| 2333 | if (!netif_running(dev)) |
| 2334 | return -EINVAL; |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2335 | if (!lp->phy_dev) |
| 2336 | return -ENODEV; |
| 2337 | return phy_mii_ioctl(lp->phy_dev, if_mii(rq), cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | static void tc35815_chip_reset(struct net_device *dev) |
| 2341 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2342 | struct tc35815_regs __iomem *tr = |
| 2343 | (struct tc35815_regs __iomem *)dev->base_addr; |
| 2344 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | /* reset the controller */ |
| 2346 | tc_writel(MAC_Reset, &tr->MAC_Ctl); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2347 | udelay(4); /* 3200ns */ |
| 2348 | i = 0; |
| 2349 | while (tc_readl(&tr->MAC_Ctl) & MAC_Reset) { |
| 2350 | if (i++ > 100) { |
| 2351 | printk(KERN_ERR "%s: MAC reset failed.\n", dev->name); |
| 2352 | break; |
| 2353 | } |
| 2354 | mdelay(1); |
| 2355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | tc_writel(0, &tr->MAC_Ctl); |
| 2357 | |
| 2358 | /* initialize registers to default value */ |
| 2359 | tc_writel(0, &tr->DMA_Ctl); |
| 2360 | tc_writel(0, &tr->TxThrsh); |
| 2361 | tc_writel(0, &tr->TxPollCtr); |
| 2362 | tc_writel(0, &tr->RxFragSize); |
| 2363 | tc_writel(0, &tr->Int_En); |
| 2364 | tc_writel(0, &tr->FDA_Bas); |
| 2365 | tc_writel(0, &tr->FDA_Lim); |
| 2366 | tc_writel(0xffffffff, &tr->Int_Src); /* Write 1 to clear */ |
| 2367 | tc_writel(0, &tr->CAM_Ctl); |
| 2368 | tc_writel(0, &tr->Tx_Ctl); |
| 2369 | tc_writel(0, &tr->Rx_Ctl); |
| 2370 | tc_writel(0, &tr->CAM_Ena); |
| 2371 | (void)tc_readl(&tr->Miss_Cnt); /* Read to clear */ |
| 2372 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2373 | /* initialize internal SRAM */ |
| 2374 | tc_writel(DMA_TestMode, &tr->DMA_Ctl); |
| 2375 | for (i = 0; i < 0x1000; i += 4) { |
| 2376 | tc_writel(i, &tr->CAM_Adr); |
| 2377 | tc_writel(0, &tr->CAM_Data); |
| 2378 | } |
| 2379 | tc_writel(0, &tr->DMA_Ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | static void tc35815_chip_init(struct net_device *dev) |
| 2383 | { |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2384 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2385 | struct tc35815_regs __iomem *tr = |
| 2386 | (struct tc35815_regs __iomem *)dev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | unsigned long txctl = TX_CTL_CMD; |
| 2388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | /* load station address to CAM */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2390 | tc35815_set_cam_entry(dev, CAM_ENTRY_SOURCE, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
| 2392 | /* Enable CAM (broadcast and unicast) */ |
| 2393 | tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena); |
| 2394 | tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl); |
| 2395 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2396 | /* Use DMA_RxAlign_2 to make IP header 4-byte aligned. */ |
| 2397 | if (HAVE_DMA_RXALIGN(lp)) |
| 2398 | tc_writel(DMA_BURST_SIZE | DMA_RxAlign_2, &tr->DMA_Ctl); |
| 2399 | else |
| 2400 | tc_writel(DMA_BURST_SIZE, &tr->DMA_Ctl); |
| 2401 | #ifdef TC35815_USE_PACKEDBUFFER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | tc_writel(RxFrag_EnPack | ETH_ZLEN, &tr->RxFragSize); /* Packing */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2403 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | tc_writel(0, &tr->TxPollCtr); /* Batch mode */ |
| 2405 | tc_writel(TX_THRESHOLD, &tr->TxThrsh); |
| 2406 | tc_writel(INT_EN_CMD, &tr->Int_En); |
| 2407 | |
| 2408 | /* set queues */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2409 | tc_writel(fd_virt_to_bus(lp, lp->rfd_base), &tr->FDA_Bas); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | tc_writel((unsigned long)lp->rfd_limit - (unsigned long)lp->rfd_base, |
| 2411 | &tr->FDA_Lim); |
| 2412 | /* |
| 2413 | * Activation method: |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2414 | * First, enable the MAC Transmitter and the DMA Receive circuits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | * Then enable the DMA Transmitter and the MAC Receive circuits. |
| 2416 | */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2417 | tc_writel(fd_virt_to_bus(lp, lp->fbl_ptr), &tr->BLFrmPtr); /* start DMA receiver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | tc_writel(RX_CTL_CMD, &tr->Rx_Ctl); /* start MAC receiver */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | /* start MAC transmitter */ |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2421 | #ifndef NO_CHECK_CARRIER |
| 2422 | /* TX4939 does not have EnLCarr */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2423 | if (lp->chiptype == TC35815_TX4939) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2424 | txctl &= ~Tx_EnLCarr; |
| 2425 | #ifdef WORKAROUND_LOSTCAR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | /* WORKAROUND: ignore LostCrS in full duplex operation */ |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2427 | if (!lp->phy_dev || !lp->link || lp->duplex == DUPLEX_FULL) |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2428 | txctl &= ~Tx_EnLCarr; |
| 2429 | #endif |
| 2430 | #endif /* !NO_CHECK_CARRIER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | #ifdef GATHER_TXINT |
| 2432 | txctl &= ~Tx_EnComp; /* disable global tx completion int. */ |
| 2433 | #endif |
| 2434 | tc_writel(txctl, &tr->Tx_Ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2437 | #ifdef CONFIG_PM |
| 2438 | static int tc35815_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2439 | { |
| 2440 | struct net_device *dev = pci_get_drvdata(pdev); |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2441 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2442 | unsigned long flags; |
| 2443 | |
| 2444 | pci_save_state(pdev); |
| 2445 | if (!netif_running(dev)) |
| 2446 | return 0; |
| 2447 | netif_device_detach(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2448 | if (lp->phy_dev) |
| 2449 | phy_stop(lp->phy_dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2450 | spin_lock_irqsave(&lp->lock, flags); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2451 | tc35815_chip_reset(dev); |
| 2452 | spin_unlock_irqrestore(&lp->lock, flags); |
| 2453 | pci_set_power_state(pdev, PCI_D3hot); |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | static int tc35815_resume(struct pci_dev *pdev) |
| 2458 | { |
| 2459 | struct net_device *dev = pci_get_drvdata(pdev); |
Atsushi Nemoto | ee79b7f | 2008-04-11 00:24:36 +0900 | [diff] [blame] | 2460 | struct tc35815_local *lp = netdev_priv(dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2461 | |
| 2462 | pci_restore_state(pdev); |
| 2463 | if (!netif_running(dev)) |
| 2464 | return 0; |
| 2465 | pci_set_power_state(pdev, PCI_D0); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2466 | tc35815_restart(dev); |
Atsushi Nemoto | 59524a3 | 2008-06-25 11:41:01 +0900 | [diff] [blame] | 2467 | netif_carrier_off(dev); |
Atsushi Nemoto | c6686fe | 2008-04-12 00:47:46 +0900 | [diff] [blame] | 2468 | if (lp->phy_dev) |
| 2469 | phy_start(lp->phy_dev); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2470 | netif_device_attach(dev); |
| 2471 | return 0; |
| 2472 | } |
| 2473 | #endif /* CONFIG_PM */ |
| 2474 | |
| 2475 | static struct pci_driver tc35815_pci_driver = { |
| 2476 | .name = MODNAME, |
| 2477 | .id_table = tc35815_pci_tbl, |
| 2478 | .probe = tc35815_init_one, |
| 2479 | .remove = __devexit_p(tc35815_remove_one), |
| 2480 | #ifdef CONFIG_PM |
| 2481 | .suspend = tc35815_suspend, |
| 2482 | .resume = tc35815_resume, |
| 2483 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | }; |
| 2485 | |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2486 | module_param_named(speed, options.speed, int, 0); |
| 2487 | MODULE_PARM_DESC(speed, "0:auto, 10:10Mbps, 100:100Mbps"); |
| 2488 | module_param_named(duplex, options.duplex, int, 0); |
| 2489 | MODULE_PARM_DESC(duplex, "0:auto, 1:half, 2:full"); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | static int __init tc35815_init_module(void) |
| 2492 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2493 | return pci_register_driver(&tc35815_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | static void __exit tc35815_cleanup_module(void) |
| 2497 | { |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2498 | pci_unregister_driver(&tc35815_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | } |
Jeff Garzik | 420e852 | 2007-02-24 17:02:16 -0500 | [diff] [blame] | 2500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | module_init(tc35815_init_module); |
| 2502 | module_exit(tc35815_cleanup_module); |
Atsushi Nemoto | eea221c | 2007-03-03 23:54:59 +0900 | [diff] [blame] | 2503 | |
| 2504 | MODULE_DESCRIPTION("TOSHIBA TC35815 PCI 10M/100M Ethernet driver"); |
| 2505 | MODULE_LICENSE("GPL"); |