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